healpix-based chunk compression
This module contains compression algorithms and codecs to compress / uncompress chunks that are aligned with healpix cells.
The idea is that we can downscale the input chunk by a given amount of refinement levels using a simple aggregation (mean), then compute the residuals between input data and aggregation result, and apply a lossy compression algorithm to the residuals.
The result is multiple arrays (one array for the result of the aggregation, and at least one array of potentially different shape for the residuals), which for the zarr codec are converted to bytes and packed into a single binary blob.
Parameters
The codec has two parameters:
delta: how many refinement levels to average over. The averages will then have a refinement level oforiginal_level - delta.top_k: how many parameters to keep. This is equivalent to a low-pass filter. The details depend on the actual compression algorithm.
Sentinel-2 chain: digital numbers and lossless JPEG XL
The hcc-sentinel2 serializer stores a chunk of reflectances the way a Sentinel-2 product stores a band: the cells are rounded to 16-bit digital numbers, DN = round(Q * reflectance - O) with DN = 0 for no-data, de-interleaved into a square raster and compressed with lossless JPEG XL. Decoding restores the quantised reflectances exactly, (DN + O) / Q; the rounding to the DN lattice is the only error. The last axis of a chunk must have a power-of-four size (one nested parent cell); leading axes (time, band, ...) are allowed, each row being coded on its own.
It needs the optional dependency imagecodecs (pip install healpix-compress[jpegxl]).
import zarr
import hcc
z = root.create_array(
"reflectance",
data=data,
fill_value=float("nan"),
chunks=(4**10,),
serializer=hcc.codecs.sentinel2.HccSentinel2Codec(
quantification_value=10000.0, add_offset=-1000.0
),
filters=None,
compressors=None,
dimension_names=["cells"],
)
Two-layer variant: lossless parents, quantised children
hcc-sentinel2-pyramid keeps the parent level (the mean of each group of four children) lossless on the DN lattice, predicts the children from it with a least-squares filter over the 5 x 5 parent neighbourhood, and quantises the difference with a step proportional to that difference's standard deviation in the chunk (relative_step). Rough chunks get a coarse step and smooth chunks a fine one. For a 10 m reflectance band resampled with a point-spread-function kernel, relative_step=0.36 (the transfer-floor preset) puts the error it adds on the native pixels at the error the transfer itself leaves there; relative_step=0 keeps the children on the DN lattice.
serializer = hcc.codecs.sentinel2_pyramid.HccSentinel2PyramidCodec(relative_step=0.36)
The JPEG XL layers are lossless, so effort and decoding_speed change the size and the speed of the chunks, not the decoded cells. On 10 m reflectance chunks at effort 7, the default decoding_speed=2 makes the chunks about 3 % larger than decoding_speed=0 (the only setting of earlier versions) for half the JPEG XL encoding and decoding times; decoding_speed=1 keeps the size of 0 and saves about a third.
Native kernels
The optional package in rust/ (healpix-compress-native, module hcc_native, Rust and pyo3) runs everything but the JPEG XL and zlib streams and the least-squares fit natively, without holding the GIL. It gives the same codestreams and the same decoded cells as the Python implementation, bit for bit; the codec uses it when it is installed, unless HCC_NATIVE=0. It is built with a Rust toolchain and maturin:
pip install ./rust
Wavelet residuals: hcc-grad-dwt
hcc-grad-dwt codes the residual of hcc-decompose with a multi-level 2-D wavelet transform: the approximation subband is kept lossless (float32), each detail subband is quantised to int8 or int16 with its own scale. It needs the optional dependency PyWavelets (pip install healpix-compress[wavelets]).
from hcc.codecs.presets import preset
[serializer] = preset("hcc-grad-dwt", "medium")
Usage of the zarr codec
Direct use with zarr-python
To write the data:
import zarr
import hcc
data = ...
chunks = ...
store = ...
root = zarr.api.synchronous.create_group(store, zarr_format=3)
z = root.create_array(
"array1",
data=data,
fill_value=float("nan"),
chunks=chunks,
serializer=hcc.codecs.dct.HccDctCodec(delta=delta, top_k=top_k),
filters=None,
compressors=None,
dimension_names=["cells"],
)
print(z[:])
To read the data back into memory, all we have to do is import the package:
import zarr
import hcc
store = ...
root = zarr.open_group(store, mode="r")
z = root["z"]
print(z[:])
Through xarray
Writing:
import xarray as xr
import hcc
ds = ...
store = ...
chunks = ...
ds.to_zarr(
store,
encoding={
"array1": {
"serializer": {
"name": "hcc-dct",
"configuration": {"delta": delta, "top_k": top_k},
},
"chunks": chunks,
}
},
)
Reading:
import xarray as xr
import hcc
ds = xr.open_dataset(store, engine="zarr", chunks={})
ds
Metadata
Release files for healpix-compress 0.4.2
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 |
|---|---|---|---|---|
| healpix_compress-0.4.2.tar.gz | 83.1 kB | With provenance | Details for healpix_compress-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| healpix_compress-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for healpix_compress-0.4.2-py3-none-any.whl |
Total release size: 159.9 kB
Release files / healpix_compress-0.4.2.tar.gz
| Download URL | healpix_compress-0.4.2.tar.gz |
|---|---|
| Size | 83.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97fd594cd99fe21f39fdd9c782fc98b16d0fcaabaecb131e1cfc81f2e19e801f
|
|
BLAKE2b-256 checksum How to use checksums |
2a7947f1d77b34c4c3e471c10f3b38714e1605f56a43e2cb8cc9464f25a0a699
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logRelease files / healpix_compress-0.4.2-py3-none-any.whl
| Download URL | healpix_compress-0.4.2-py3-none-any.whl |
|---|---|
| Size | 76.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6bda8a0422f3348f5b5fa5383640ca58333d5328c4a4820ef7917e4465c8e8dc
|
|
BLAKE2b-256 checksum How to use checksums |
6b69ca8ea49ebb3e605dab460460c54cac9be4ec030254c874e2167fcf248d4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logSecurity for healpix-compress 0.4.2
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for healpix_compress-0.4.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 8, 2026.
Transparency logA 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.