Skip to main content

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 a numcodecs.abc.Codec; requires zarr >= 3.1).
  • Auto-registration: Registered automatically via import wx1_lorenzo and the [project.entry-points."zarr.codecs"] Python entry point.
  • Bit-exact integer reconstruction: Uses modular $2^b$ arithmetic for uint8 and uint16 chunks 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.

  1. 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))$$

  2. Inverse transform (decode): Inverse ZigZag mapping followed by two exact modular prefix sums (numpy.cumsum) along axis=-1 and axis=-2 in 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 uint8 and uint16 chunks 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.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 wx1-lorenzo 0.1.1
File Size Uploaded Provenance Actions
wx1_lorenzo-0.1.1.tar.gz 9.2 kB With provenance Details for wx1_lorenzo-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wx1-lorenzo 0.1.1
File Interpreter ABI Platform Actions
wx1_lorenzo-0.1.1-py3-none-any.whl Python 3 none any Details for wx1_lorenzo-0.1.1-py3-none-any.whl

Total release size: 18.5 kB

Release files / wx1_lorenzo-0.1.1.tar.gz

Download URL wx1_lorenzo-0.1.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d10bcf148e3dbc46d50209a8430d92bd0a9d42c2d1b570a73ab7e9ec2137e207
BLAKE2b-256 checksum
How to use checksums
1adb683f4907e96b75bd4916fea49117c2b20368e5c667be48b16e223dc78d5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 18, 2026.

Transparency log

Release files / wx1_lorenzo-0.1.1-py3-none-any.whl

Download URL wx1_lorenzo-0.1.1-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
006b85c06a2697986fb6f62777f2962c6788db474984bec09c8cc0b9f5eea218
BLAKE2b-256 checksum
How to use checksums
2c8588151e82ef62a1f5a63069945047b114cbbd4e1578499f70b02952fad903
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 18, 2026.

Transparency log

Security for wx1-lorenzo 0.1.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 wx1_lorenzo-0.1.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 Nov 18, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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