Skip to main content

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 of original_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 Sentinel-2 B04 resampled with the PSF settings of legacy-converters, 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)

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.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for healpix-compress 0.3.1
File Size Uploaded Provenance Actions
healpix_compress-0.3.1.tar.gz 59.7 kB With provenance Details for healpix_compress-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for healpix-compress 0.3.1
File Interpreter ABI Platform Actions
healpix_compress-0.3.1-py3-none-any.whl Python 3 none any Details for healpix_compress-0.3.1-py3-none-any.whl

Total release size: 127.5 kB

Release files / healpix_compress-0.3.1.tar.gz

Download URL healpix_compress-0.3.1.tar.gz
Size 59.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7e3ec34fb4f27f7018262ebb0e715e432817d8f98479ff7fa813c0234cad7106
BLAKE2b-256 checksum
How to use checksums
82572f1e2d476ec297dfe8bc88254d347819fe343d0e5a05356d25988a3d2db5
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 Oct 20, 2026.

Transparency log

Release files / healpix_compress-0.3.1-py3-none-any.whl

Download URL healpix_compress-0.3.1-py3-none-any.whl
Size 67.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e169fc603fdfd0708f9e0cfbc844829d1b166909226128caa5ea9b36ebfc88c
BLAKE2b-256 checksum
How to use checksums
28f2bd8e5046c64c71fb6859df5a393c560605b5bfd020fa6a0ab9297b0140ea
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 Oct 20, 2026.

Transparency log

Security for healpix-compress 0.3.1

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.

Select from 2 files

Attestation for healpix_compress-0.3.1.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 Oct 20, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page