wx1-lorenzo
Lossless 2-D Lorenzo spatial predictor as a native Zarr v3 ArrayArrayCodec (wx1.lorenzo2d) for integer-quantised meteorological grids (e.g. regular lat/lon GRIB-style R, E, D lattices).
- Native Zarr v3 codec (
zarr.abc.codec.ArrayArrayCodec, not anumcodecs.abc.Codec; requireszarr >= 3.1). - Auto-registration: Registered automatically via
import wx1_lorenzoand the[project.entry-points."zarr.codecs"]Python entry point. - Bit-exact integer reconstruction: Uses modular $2^b$ arithmetic for
uint8anduint16chunks on regular rectangular(y, x)grids. - License: Apache-2.0.
Installation
pip install wx1-lorenzo
# With GRIB / shuffle example dependencies:
pip install "wx1-lorenzo[grib]"
Or from source:
pip install -e ".[grib]"
How It Works
For each chunk of shape (..., ny, nx) (uint8 or uint16), Lorenzo2DCodec treats the last two dimensions (axis -2, axis -1) as the 2-D spatial grid (y, x) while keeping any leading dimensions independent.
-
Forward transform (encode): $$d_{y,x} = X_{y,x} - X_{y,x-1} - X_{y-1,x} + X_{y-1,x-1} \pmod{2^b}$$ with boundary conditions $d_{0,0} = X_{0,0}$, $d_{0,x} = X_{0,x} - X_{0,x-1} \pmod{2^b}$, and $d_{y,0} = X_{y,0} - X_{y-1,0} \pmod{2^b}$. Signed differences (reinterpreted as
int8/int16) are ZigZag-mapped back to unsigned integers of the same dtype: $$z = (d_{\text{signed}} \ll 1) \oplus (d_{\text{signed}} \gg (b - 1))$$ -
Inverse transform (decode): Inverse ZigZag mapping followed by two exact modular prefix sums (
numpy.cumsum) alongaxis=-1andaxis=-2in the native unsigned dtype.
Chain Lorenzo2DCodec with BytesCodec(), byte-shuffle (zarr.codecs.numcodecs.Shuffle(elementsize=2)), and ZstdCodec(level=3) to match the benchmark pipeline.
Quickstart (Zarr v3)
import numpy as np
import zarr
from zarr.codecs import BytesCodec, ZstdCodec
from zarr.codecs.numcodecs import Shuffle
import wx1_lorenzo as wl # registers "wx1.lorenzo2d"
data = np.cumsum(np.cumsum(np.ones((2, 721, 1440), dtype=np.uint16), axis=1), axis=2).astype(np.uint16)
z = zarr.create_array(
"sample.zarr",
shape=data.shape,
chunks=(1, 721, 1440),
dtype="uint16",
zarr_format=3,
filters=[wl.Lorenzo2DCodec()],
serializer=BytesCodec(),
compressors=[Shuffle(elementsize=2), ZstdCodec(level=3)],
overwrite=True,
)
z[:] = data
z_read = zarr.open_array("sample.zarr", mode="r")
assert np.array_equal(z_read[:], data)
End-to-End GRIB2 Example
See examples/grib_to_zarr_e2e.py for extracting (R, E, D) affine lattice parameters from a regular lat/lon GRIB2 file, compressing with wx1.lorenzo2d -> bytes -> numcodecs.shuffle -> zstd, verifying double-precision bit-exactness against eccodes, and comparing disk usage against GRIB2-AEC:
python examples/grib_to_zarr_e2e.py FILE.grib2 gh out.zarr
Limitations
- Supports
uint8anduint16chunks with rank $\ge 2$. - Regular rectangular grids only; does not directly apply to reduced Gaussian grids (e.g. O1280) or spectral coefficients.
Development & Tests
pip install -e ".[grib]" pytest
pytest -v
Metadata
Release files for wx1-lorenzo 0.1.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 |
|---|---|---|---|---|
| wx1_lorenzo-0.1.0.tar.gz | 9.2 kB | Without provenance | Details for wx1_lorenzo-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wx1_lorenzo-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for wx1_lorenzo-0.1.0-py3-none-any.whl |
Total release size: 18.5 kB
Release files / wx1_lorenzo-0.1.0.tar.gz
| Download URL | wx1_lorenzo-0.1.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cbcd2a9537d456b36da5e53e2ad23fcb905cc403c2ab06022a8d7a5adbcbd6b9
|
|
BLAKE2b-256 checksum How to use checksums |
4c5afcdc2b9e73f3f07893ff90bbb43c844a341fff7b5f88a61f6017ab39d20f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / wx1_lorenzo-0.1.0-py3-none-any.whl
| Download URL | wx1_lorenzo-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea5cb77fec683fce63f7acf7777adffd91a10d5e98af24b4e427f95830b9ecbb
|
|
BLAKE2b-256 checksum How to use checksums |
ebc422bb244fcd4567b1ffd6787d8b585637e5a466673e0d052af38f4828d12e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for wx1-lorenzo 0.1.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.