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]'

For faster local writes, add the zarrs extra. Pyramid.write then uses the Rust zarrs codec pipeline automatically for local stores:

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

Remote stores keep zarr-python's pipeline until zarrs-python#139 lands. To opt in anyway, set it yourself; write leaves an explicitly configured pipeline alone:

import zarr
import zarrs

zarr.config.set({"codec_pipeline.path": "zarrs.ZarrsCodecPipeline"})

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

Building from source requires a Rust toolchain for the topozarr-core kernel. See the contributing docs for setup, tests, 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

Metadata

Release files for topozarr 0.1.11

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

Source distribution (sdist)

Source distribution for topozarr 0.1.11
File Size Uploaded
topozarr-0.1.11.tar.gz 28.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for topozarr 0.1.11
File Interpreter ABI Platform
topozarr-0.1.11-py3-none-any.whl Python 3 none any Details

Total release size: 59.0 kB

Release files / topozarr-0.1.11.tar.gz

Download URL topozarr-0.1.11.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
6da0e756daa99d846ea05b55053929947446b692c5ef0eeaa97af8d97b43178a
BLAKE2b-256 checksum
How to use checksums
facff529ed7bf2adc20010802fae87fb6efb960a62a0117937a9b03e3c38b98b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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}

Release files / topozarr-0.1.11-py3-none-any.whl

Download URL topozarr-0.1.11-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8728e2165bae8c51beaa286ad345f524e508cfc90a0513221ff2814a67f2404a
BLAKE2b-256 checksum
How to use checksums
cf2b9f97ee45c5d8ae8439bac5d130666788e5c392219fd37f9d9847f0b9a660
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","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}

Release history Release notifications | RSS feed

0.2.0

2 release files

This release

0.1.11 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.0.93

2 release files

0.0.92

2 release files

0.0.91

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release 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