diff --git a/pyproject.toml b/pyproject.toml index 79a2f1d..6992b06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,11 +10,13 @@ dependencies = [ "numcodecs>=0.13.0,<0.16", "numcodecs-combinators[xarray]~=0.2.4", "numcodecs-observers~=0.1.1", - "numcodecs-wasm~=0.1.1", + "numcodecs-wasm~=0.1.3", "numcodecs-wasm-bit-round~=0.2.0", + "numcodecs-wasm-fixed-offset-scale~=0.2.1", + "numcodecs-wasm-jpeg2000~=0.1.1", "numcodecs-wasm-pco~=0.1.0", "numcodecs-wasm-round~=0.2.0", - "numcodecs-wasm-sz3~=0.4.0", + "numcodecs-wasm-sz3~=0.5.0", "numcodecs-wasm-tthresh~=0.1.0", "numcodecs-wasm-uniform-noise~=0.2.0", "numcodecs-wasm-zfp~=0.4.0", diff --git a/src/climatebenchpress/compressor/compressors/__init__.py b/src/climatebenchpress/compressor/compressors/__init__.py index 9ecd244..f3e899c 100644 --- a/src/climatebenchpress/compressor/compressors/__init__.py +++ b/src/climatebenchpress/compressor/compressors/__init__.py @@ -1,8 +1,9 @@ -__all__ = ["BitRound", "BitRoundPco", "StochRound", "Sz3", "Tthresh", "Zfp"] +__all__ = ["BitRound", "BitRoundPco", "Jpeg2000", "StochRound", "Sz3", "Tthresh", "Zfp"] from . import abc as abc from .bitround import BitRound from .bitround_pco import BitRoundPco +from .jpeg2000 import Jpeg2000 from .stochround import StochRound from .sz3 import Sz3 from .tthresh import Tthresh diff --git a/src/climatebenchpress/compressor/compressors/jpeg2000.py b/src/climatebenchpress/compressor/compressors/jpeg2000.py new file mode 100644 index 0000000..9e0e950 --- /dev/null +++ b/src/climatebenchpress/compressor/compressors/jpeg2000.py @@ -0,0 +1,33 @@ +__all__ = ["Jpeg2000"] + +import numcodecs.astype +import numcodecs_wasm_fixed_offset_scale +import numcodecs_wasm_jpeg2000 +import numcodecs_wasm_round +from numcodecs.abc import Codec +from numcodecs_combinators.stack import CodecStack + +from .abc import Compressor + + +class Jpeg2000(Compressor): + name = "jpeg2000" + description = "JPEG 2000" + + @staticmethod + def build() -> Codec: + precision = 0.01 + rate = 10.0 # x10 factor compression + + return CodecStack( + numcodecs_wasm_fixed_offset_scale.FixedOffsetScale( + offset=0, + scale=precision, + ), + numcodecs_wasm_round.Round(precision=1), + numcodecs.astype.AsType( + encode_dtype="int32", + decode_dtype="float32", + ), + numcodecs_wasm_jpeg2000.Jpeg2000(mode="rate", rate=rate), + )