def test_get_compression(): assert _get_compressor("lz4") == numcodecs.LZ4(numcodecs.lz4.DEFAULT_ACCELERATION) assert _get_compressor(None) is None assert _get_compressor("default") == "default" assert _get_compressor("zstd") == numcodecs.Zstd(numcodecs.zstd.DEFAULT_CLEVEL) assert _get_compressor("png") == PngCodec(solo_channel=True) with pytest.raises(ValueError): _get_compressor("abcd")
def main(): numcodecs.register_codec(PngCodec, "png") with Timer("Compress"): arr = zarr.create( shape=(10, 10, 1920, 1080, 7), dtype="uint8", compressor=PngCodec(solo_channel=True), store=zarr.MemoryStore(), ) arr[:] = np.ones((10, 10, 1920, 1080, 7), dtype="uint8") print(arr[:].shape)
def _get_compressor(self, compressor: str): if compressor.lower() == "lz4": return numcodecs.LZ4(numcodecs.lz4.DEFAULT_ACCELERATION) elif compressor.lower() == "zstd": return numcodecs.Zstd(numcodecs.zstd.DEFAULT_CLEVEL) elif compressor.lower() == "default": return "default" elif compressor.lower() == "png": return PngCodec(solo_channel=True) else: raise ValueError( f"Wrong compressor: {compressor}, only LZ4 and ZSTD are supported" )