diff --git a/pyproject.toml b/pyproject.toml index 9f91171..a1b05c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,6 +23,7 @@ dependencies = [ "numcodecs-wasm-round~=0.4.0", "numcodecs-wasm-sperr~=0.1.0", "numcodecs-wasm-stochastic-rounding~=0.1.1", + "numcodecs-wasm-swizzle-reshape~=0.3.0", "numcodecs-wasm-sz3~=0.6.0", "numcodecs-wasm-tthresh~=0.2.0", "numcodecs-wasm-zfp~=0.5.3", diff --git a/src/climatebenchpress/compressor/compressors/__init__.py b/src/climatebenchpress/compressor/compressors/__init__.py index b523c75..7ae1bda 100644 --- a/src/climatebenchpress/compressor/compressors/__init__.py +++ b/src/climatebenchpress/compressor/compressors/__init__.py @@ -2,6 +2,8 @@ "BitRound", "BitRoundPco", "Jpeg2000", + "RP", + "RPDct", "Sperr", "StochRound", "StochRoundPco", @@ -15,6 +17,8 @@ from .bitround import BitRound from .bitround_pco import BitRoundPco from .jpeg2000 import Jpeg2000 +from .rp import RP +from .rp_dct import RPDct from .sperr import Sperr from .stochround import StochRound from .stochround_pco import StochRoundPco diff --git a/src/climatebenchpress/compressor/compressors/rp.py b/src/climatebenchpress/compressor/compressors/rp.py new file mode 100644 index 0000000..dfa942b --- /dev/null +++ b/src/climatebenchpress/compressor/compressors/rp.py @@ -0,0 +1,21 @@ +__all__ = ["RP"] + +import numcodecs_random_projection +import numcodecs_wasm_swizzle_reshape +from numcodecs_combinators.stack import CodecStack + +from .abc import Compressor + + +class RP(Compressor): + name = "rp" + description = "Random Projection (Gaussian)" + + @staticmethod + def abs_bound_codec(error_bound, **kwargs): + return CodecStack( + numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), + numcodecs_random_projection.RPCodec( + mae=error_bound, method="gaussian", seed=42, debug=True + ), + ) diff --git a/src/climatebenchpress/compressor/compressors/rp_dct.py b/src/climatebenchpress/compressor/compressors/rp_dct.py new file mode 100644 index 0000000..9a8d771 --- /dev/null +++ b/src/climatebenchpress/compressor/compressors/rp_dct.py @@ -0,0 +1,21 @@ +__all__ = ["RPDct"] + +import numcodecs_random_projection +import numcodecs_wasm_swizzle_reshape +from numcodecs_combinators.stack import CodecStack + +from .abc import Compressor + + +class RPDct(Compressor): + name = "rp-dct" + description = "Random Projection (DCT)" + + @staticmethod + def abs_bound_codec(error_bound, **kwargs): + return CodecStack( + numcodecs_wasm_swizzle_reshape.SwizzleReshape(axes=[[0, 1, 2], [3, 4]]), + numcodecs_random_projection.RPCodec( + mae=error_bound, method="dct", seed=0, debug=True + ), + )