cgohlke / imagecodecs

Image transformation, compression, and decompression codecs
https://pypi.org/project/imagecodecs
BSD 3-Clause "New" or "Revised" License
111 stars 21 forks source link

ValueError: codec not available: 'imagecodecs_jpegxl' #74

Closed Karol-G closed 1 year ago

Karol-G commented 1 year ago

Hey,

I want to use JpegXl as compressor for a Zarr file:

from imagecodecs.numcodecs import JpegXl
import numpy as np
import zarr

image = np.ones((100, 100, 3))
image_zarr = zarr.open("image.zarr", shape=(100, 100, 3), compressor=JpegXl())
image_zarr[...] = image

However, I get the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[40], line 6
      3 import zarr
      5 image = np.ones((100, 100, 3))
----> 6 image_zarr = zarr.open("image.zarr", shape=(100, 100, 3), compressor=JpegXl())
      7 image_zarr[...] = image

File /opt/conda/lib/python3.10/site-packages/zarr/convenience.py:112, in open(store, mode, zarr_version, path, **kwargs)
    110 elif mode == "a":
    111     if "shape" in kwargs or contains_array(_store, path):
--> 112         return open_array(_store, mode=mode, **kwargs)
    113     else:
    114         return open_group(_store, mode=mode, **kwargs)

File /opt/conda/lib/python3.10/site-packages/zarr/creation.py:608, in open_array(store, mode, shape, chunks, dtype, compressor, fill_value, order, synchronizer, filters, cache_metadata, cache_attrs, path, object_codec, chunk_store, storage_options, partial_decompress, write_empty_chunks, zarr_version, dimension_separator, **kwargs)
    605 read_only = mode == 'r'
    607 # instantiate array
--> 608 z = Array(store, read_only=read_only, synchronizer=synchronizer,
    609           cache_metadata=cache_metadata, cache_attrs=cache_attrs, path=path,
    610           chunk_store=chunk_store, write_empty_chunks=write_empty_chunks)
    612 return z

File /opt/conda/lib/python3.10/site-packages/zarr/core.py:217, in Array.__init__(self, store, path, read_only, chunk_store, synchronizer, cache_metadata, cache_attrs, partial_decompress, write_empty_chunks, zarr_version, meta_array)
    214     self._metadata_key_suffix = self._hierarchy_metadata['metadata_key_suffix']
    216 # initialize metadata
--> 217 self._load_metadata()
    219 # initialize attributes
    220 akey = _prefix_to_attrs_key(self._store, self._key_prefix)

File /opt/conda/lib/python3.10/site-packages/zarr/core.py:234, in Array._load_metadata(self)
    232 """(Re)load metadata from store."""
    233 if self._synchronizer is None:
--> 234     self._load_metadata_nosync()
    235 else:
    236     mkey = _prefix_to_array_key(self._store, self._key_prefix)

File /opt/conda/lib/python3.10/site-packages/zarr/core.py:282, in Array._load_metadata_nosync(self)
    280     self._compressor = None
    281 elif self._version == 2:
--> 282     self._compressor = get_codec(compressor)
    283 else:
    284     self._compressor = compressor

File /opt/conda/lib/python3.10/site-packages/numcodecs/registry.py:52, in get_codec(config)
     50 if cls:
     51     return cls.from_config(config)
---> 52 raise ValueError('codec not available: %r' % codec_id)

ValueError: codec not available: 'imagecodecs_jpegxl'

I am using version 2023.3.16 of imagecodecs and version 0.11.0 of numcodecs. What am I doing wrong?

Best, Karol

cgohlke commented 1 year ago

This is a duplicate of #29. The error message is just different for the numcodecs codecs.

The JPEGXL codec is still not available in the conda-forge builds. See https://github.com/conda-forge/imagecodecs-feedstock/issues/48.

Try to install the wheels from PyPI instead.

Also, register the codec with numcodecs like shown in the JPEG2K example:

https://github.com/cgohlke/imagecodecs/blob/57ea74b0e1d8bf78f10a74d0ee896eee36eaf65c/imagecodecs/imagecodecs.py#L464-L476