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

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.9

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.9
File Size Uploaded
topozarr-0.1.9.tar.gz 26.7 kB Details

Built distribution (wheel)

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

Total release size: 57.2 kB

Release files / topozarr-0.1.9.tar.gz

Download URL topozarr-0.1.9.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2ab005b34f1a8747c679949dbc030ed9bb95006f45fece9aaf7ad93b2c49cda7
BLAKE2b-256 checksum
How to use checksums
d24018984caf90b57512904c29c414652dc9e730f009548e4f0993993f7dc156
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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.9-py3-none-any.whl

Download URL topozarr-0.1.9-py3-none-any.whl
Size 30.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62e3848bd3d1a2a6b1fb6eb135f7e98e2f3a624f073043e1216c1fcb15b4ed12
BLAKE2b-256 checksum
How to use checksums
0a30023a00f732a939f30e0ab017cdd0e6aa3807afc3bb81865f40726221ea35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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

0.1.11

2 release files

0.1.10

2 release files

This release

0.1.9 This release

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