zarr-ext-jpeg
Warning: the jpeg codec is not yet stable and may change.
The jpeg extension codec for zarr-python.
The JPEG codec is an array-to-bytes codec (aka "serializer") for compressing 2D data with 1 or 3 channels, where the channel axis must come last.
Use the reshape and/or transpose codecs to rearrange any arrays which do not fit this pattern.
You may also be interested in the template chunk key encoding,
to give all chunks the .jpeg extension so that they can be previewed by extension-sensitive browsers.
Note that the repository is called zarr-python-jpeg;
the package is called zarr-ext-jpeg;
and the import name is zarr_ext_jpeg.
Usage
Simply installing zarr-ext-jpeg (e.g. with pip or uv) will allow you to decode JPEG-encoded chunks when using zarr-python.
To create JPEG-encoded arrays, use the builder pattern to ensure that your codec is valid:
import zarr
from zarr.storage import MemoryStore
from zarr_ext_jpeg import JpegCodec
import numpy as np
my_codec = (
JpegCodec
# encoded color space:
# determines which other parameters are valid
.builder("ycbcr")
# 2 horizontal and 2 vertical luminance pixels
# per chrominance pixel
.chroma_subsampling(2, 2)
# defaults to 95 if not given
.quality(75)
.build()
)
rng = np.random.default_rng(1991)
data = rng.integers(0, 256, (10, 20, 3), "uint8")
store = MemoryStore()
my_array = zarr.create_array(
store,
data=data,
serializer=my_codec,
# skip adding the default bytes-to-bytes codec(s)
compressors=[],
)
data2 = np.asarray(my_array[:])
assert data.shape == data2.shape
assert data.dtype == data2.dtype
# codec is lossy
assert not np.array_equal(data, data2)
Lossy encoding warning
JPEG encoding is lossy.
Decoding and then re-encoding the same chunks will introduce more and more artifacts.
The jpeg codec should only be used for write-once data when whole chunks can be written at once.
Parameter selection
Quality
The default is 95, on a scale of 0-100. Values above 95 lead to significantly larger files with very little perceptual gain. Lower values introduce more artifacts.
Channels
If your data doesn't have exactly 1 or 3 channels, consider using the chunk configuration or sharding to make the chunk's channel axis length 1, and then using grayscale encoding.
If you have 3 channels but they are not the red/green/blue (or YCbCr) of a natural scene, use RGB->RGB encoding. The default RGB->YCbCr color transform may introduce additional artifacts.
Chunk/ shard shape
JPEGs are encoded in Minimum Coded Units whose shape depends on the chroma subsampling used.
MCUs are 8x8 pixels, multiplied by the chroma subsampling ratio: e.g. for a subsampling ratio of [4, 1], the MCU would have shape (32, 8).
The first two elements of your chunk shape SHOULD be a multiple of this MCU shape.
Additional compression
At time of writing, by default zarr-python applies an additional bytes-to-bytes codec ("compressor") if none is specified.
As JPEG compresses quite effectively, this will likely not reduce your data size much and cost processing time;
explicitly set compressors=[] on array creation.
Difference between jpeg and imagecodecs_jpeg codecs
jpeg is a registered zarr extension with implementations in multiple languages, targeting a minimal common API surface.
imagecodecs_jpeg supports more features, but is specified only by the details of a single implementation.
Difference between zarr-ext-jpeg and zarr-jpeg packages
zarr-jpeg is a Zarr v2-era package which predates the current jpeg extension codec specification,
and indeed the Zarr v3 extension concept.
It is non-standard and defined only by the one implementation.
Metadata
Release files for zarr-ext-jpeg 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| zarr_ext_jpeg-0.2.0.tar.gz | 8.2 kB | Without provenance | Details for zarr_ext_jpeg-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| zarr_ext_jpeg-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for zarr_ext_jpeg-0.2.0-py3-none-any.whl |
Total release size: 18.2 kB
Release files / zarr_ext_jpeg-0.2.0.tar.gz
| Download URL | zarr_ext_jpeg-0.2.0.tar.gz |
|---|---|
| Size | 8.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
14b328b7e689e5c2370457cff24b832aea52fda10351cf482063673f34ac36ca
|
|
BLAKE2b-256 checksum How to use checksums |
03d142c7b6d3d7a2ef680d4a23fb89ec88c71c0907b2ffc753983d6a35d00502
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / zarr_ext_jpeg-0.2.0-py3-none-any.whl
| Download URL | zarr_ext_jpeg-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2345b51d6a2bc7ac4a93d93e53f2958441b8e01ebe4a602747d8fd109718701a
|
|
BLAKE2b-256 checksum How to use checksums |
f80dbe1929ead6037a36b3fab85d5b910e27678ac77e29f36ce3292dc04eed3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for zarr-ext-jpeg 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.