Skip to main content

topozarr

Create Multiscale Zarr stores

Python library companion to the TypeScript web mapping tool zarr-layer. Use it to create GeoZarr-compliant multiscales / pyramids / overviews for Zarr stores for use with web mapping.

Follows the zarr-conventions:

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

Warning: experimental

Installation

uv add topozarr
# or
pip install topozarr

Multiscales are computed by topozarr-core, a small Rust kernel installed automatically as a wheel. The tutorial extra includes 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" | "nearest"
)
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.

Not every dataset needs overviews! For lower resolution Zarr stores use attach_geozarr_metadata to add GeoZarr attrs and recommend_encoding for chunking/sharding heuristics for web mapping.

from topozarr import attach_geozarr_metadata, recommend_encoding

ds = attach_geozarr_metadata(ds, x_dim="lon", y_dim="lat")
ds.to_zarr(
    "flat.zarr",
    zarr_format=3,
    consolidated=False,
    encoding=recommend_encoding(ds, x_dim="lon", y_dim="lat"),
)

Coming from ndpyramid

The library ndpyramid also builds multiscale Zarr stores. However, it was built as a companion for carbonplan-maps, which requires the source data to be reprojected to EPSG:3857, square (e.g. 128x128), slippy-map-tile-compliant shapes. The newer mapping library, zarr-layer, relaxes these requirements significantly, which simplifies multiscales creation and allows topozarr to be much simpler and more flexible. This project is essentially a coarsen call and some metadata in a trenchcoat.

ndpyramid topozarr
pyramid_coarsen create_pyramid(ds, levels=...)
pyramid_reproject no equivalent — reproject upstream, then create_pyramid
pyramid_regrid no equivalent — regrid upstream, then create_pyramid

If you need a different grid, do it before and hand the result to create_pyramid.

Contributing

Clone the repo, install with the test dependency group, and run the tests:

git clone https://github.com/carbonplan/topozarr
cd topozarr
uv sync --group test
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 prek run --all-files

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

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

Building from source requires a Rust toolchain for the topozarr-core kernel. See the contributing docs for conformance tests, linting, and demo-data scripts.

License

MIT — 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

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.8.tar.gz (26.5 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.8-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: topozarr-0.1.8.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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.8.tar.gz
Algorithm Hash digest
SHA256 78df6835cacc39f4bc7c8382dfadd73da5de872a6953136e3a831f06e1421463
MD5 25ffcf7bb35f484c1e2a10f3a3d8ae86
BLAKE2b-256 300ce8a4723999380f7a086ad693e557bf2fb2c4546304d10f041d0abf256512

See more details on using hashes here.

File details

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

File metadata

  • Download URL: topozarr-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 30.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 ea979a3b1bc483769339a6fb5721cafa61c584c252b438f85c32cb79a6e365e0
MD5 27a020c593ea5743a5d7a78d55189430
BLAKE2b-256 7d83a778a9eead86bda7d52ab60f60a1b0b380fdc20568edc3d238709f622183

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.0.93

2 files

0.0.92

2 files

0.0.91

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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