Skip to main content

Lightweight multiscale zarr

Project description

topozarr

Python library to create multiscale Zarr stores for usage with zarr-layer.

Tries to match the GeoZarr spec, which is composed of these zarr-conventions:

  • multiscales — pyramid structure and resolution levels
  • proj: — coordinate reference system (CRS)
  • spatial: — affine transform, bounding box, and dimension names

Warning: experimental

Usage

Installation

uv add topozarr
# or
pip install topozarr

Multiscales are computed by topozarr-core, a small Rust kernel (installed automatically as a wheel), and written with zarr-python. For Dask-distributed workflows, pyramid.as_datatree() returns a lazy xr.DataTree you can write yourself. The tutorial extra should include everything needed to run the examples below:

uv add 'topozarr[tutorial]'
# or
pip install 'topozarr[tutorial]'

Example

import xarray as xr
import xproj # for crs assignment
from topozarr import create_pyramid

# Load the air_temperature Xarray tutorial dataset
ds = xr.tutorial.open_dataset('air_temperature').drop_encoding()

# Assign a CRS
ds = ds.proj.assign_crs(spatial_ref="EPSG:4326")
print(ds)
pyramid = create_pyramid(
    ds,
    levels=2,
    x_dim="lon",
    y_dim="lat",
    method="mean",  # "mean" (default) | "max" | "min" | "sum"
)
print(pyramid.encoding)

# write
pyramid.write("pyramid.zarr")

levels is the total number of resolution levels, including the original. Level 0 is the original (highest) resolution; by default each subsequent level is coarsened by a factor of 2 per spatial dimension, so the last level is the coarsest.

create_pyramid returns a write plan; pyramid.write(store) does the work.

Documentation

Full docs at carbonplan.github.io/topozarr:

  • Usage — sparse pyramids (factors), visualization hints (layer_hints), chunking and sharding (and why sharding rules), object-storage / Icechunk backends, and the experimental io="rust" write path.
  • Design — the plan/execute split, chunk and shard heuristics, streaming memory model, and Rust kernel semantics.

Contributing

Clone the repo and install with the test dependency group.

git clone https://github.com/carbonplan/topozarr
cd topozarr
uv sync --group test

Run tests:

uv run pytest -n auto

Run conformance tests against the GeoZarr spec (requires the conformance group):

uv sync --group conformance
uv run pytest -n auto -m conformance

Lint and format:

uv run pre-commit run --all-files

To regenerate the demo datasets in S3 (requires AWS credentials), install the tutorial extra and run the build script:

uv sync --extra tutorial
uv run python scripts/build_demo_data.py --help

License

[!IMPORTANT] This code is licensed under the MIT License - see the LICENSE file for details.

About Us

CarbonPlan is a nonprofit organization that uses data and science for climate action. We aim to improve the transparency and scientific integrity of climate solutions through open data and tools. Find out more at carbonplan.org or get in touch by opening an issue or sending us an email

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topozarr-0.1.2.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topozarr-0.1.2-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

Details for the file topozarr-0.1.2.tar.gz.

File metadata

  • Download URL: topozarr-0.1.2.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for topozarr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ada5cf326e99c9112a75bea6f891bd2319bd231d34e9e017402606b7004bd7ad
MD5 25f18d4c7d1a195ee54d785a0e4d7397
BLAKE2b-256 f5a7d98b2fe79ef41c83e2c8f6ea496bfc33a65721f1ae49db4e4cbf2b594699

See more details on using hashes here.

File details

Details for the file topozarr-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: topozarr-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for topozarr-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e41abf5822fbb8508c4f83f2ee5ff96c4440dad31e8f4ecf92c1d7c711e8a6e2
MD5 ffbd0a536e011732e5dc6049242c13b0
BLAKE2b-256 a9c29578a88b94d83116f4de5b28043ca43c849970994e69708ddaa9888f480b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page