Skip to main content

zarrchive

Schema driven definition of a Zarr archive, with easy python API and CLI tools to append to it, including support of image codecs.

Install

Requires Python 3.12 or newer.

uv add zarrchive                 # or: pip install zarrchive

Python API

import xarray as xr
from zarrchive import Zarrchive, load_template

load_template("cam.yaml")                        # validate without opening a store

with Zarrchive("out.zarr", "cam.yaml") as store:  # create or open
    store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})

Zarrchive(path, template) creates the store if it is absent, and restores the metadata on exit. frame is an xarray.DataArray, or a numpy array with dims=. loc names the axes the payload does not carry, by label.

Main methods :

Method Effect
write(name, data, loc=...) One observation, or a whole batch when the payload carries a time coordinate.
bulk_write(name=[blocks], workers=...) Chunk-aligned blocks written shard by shard, without holding a shard in memory.
reserve_time(labels) Grow the time axis before the data arrives.
delete_before(cutoff) / delete_after(cutoff) Drop from one end of the time axis.
finalize() Write the global attributes and consolidate metadata. Done for you on exit from a with block.

Details in Writing and the Python API.

CLI

See Command line for more details.

Command create

zarrchive create <out.zarr> -s <template.yaml> [-a <meta.yml>] [-n/--dry-run]

create builds a store from a template, or updates one that already exists. An array's layout is fixed when the array is created.

-a reads placeholder values from a YAML, JSON or INI file. -n prints the plan without touching the store.

Command import

zarrchive import <out.zarr> -v <var_name> -b <input_dir> -p './images/{yyyy}-{mm}-{dd}T{HH}:{MM}.jpg'

import fills one variable from image files.

-p provides the patterns of input images.

By default, this command only allows lossless storage : JPG images are copied as is in jpeg chunks (passthrough).

Quickstart

1. Describe the store.

A template define the dimensions, variables, encoding and metadata of the Zarr store.

It can contain "{placeholders}" that are replaced at runtime using the -a option of the create command.

dimensions:

    time: # Full definition of a dimension, with attributes and type
        size: expand # This dimensions expands as data is appended
        type: uint64
        grid: {frequency: PT15M, grid_tolerance: PT1S}
        attributes: {units: seconds since 1970-01-01 00:00:00} # CF conventions

    band: #  Bands of the images. Static. size and type inferred from the labels
        values: [R, G1, B, G2]
        
    # Short defitions of dimensions
    y: auto  # Infered from the first frame written, fixed after that
    x: auto

chunks: {time: 1, band: -1, y: -1, x: -1}    # one frame per chunk; -1 = whole axis
shards: {time: 96, band: -1, y: -1, x: -1}   # 96 chunks (=one day) per file on disk

variables:
    radiance:
        dimensions: [time, band, y, x]
        type: float32

        # JPG codec : passthrough of the input images
        encoding: {name: imagecodecs_jpegxl, args: {lossless: true}}

        attributes: {units: W m-2 sr-1, _FillValue: .nan}

# Extra matadata, should follow the recommendations of ACDD and "Climate and Forecast" conventions
attributes:

    Conventions: CF-1.13, ACDD-1.3
    title: All-sky camera radiance

See a full example here

2. Write to it.

frame should be a chunk of DataArray or numpy array of the proper size. loc provides the coordinates of the chunk : the dimensions that are not provided in the DataArray

from zarrchive import Zarrchive

with Zarrchive("out.zarr", "cam.yaml") as store:
    store.write("radiance", frame, loc={"time": "2020-01-01T00:15:00"})

3. Read it back.

The output Zarr arichive doesn't require zarrchive.

It can be opened with vanilla xarray (+imagecodecs)

import imagecodecs.zarr
import xarray as xr

# The arrays name image codecs (JPEG here); register them before opening.
imagecodecs.zarr.register_codecs()

# A store is a hierarchy of groups
tree = xr.open_datatree("out.zarr", zarr_format=3, consolidated=False)
tree

See the full notebook here

Example

A small, runnable dataset lives in examples/: a colour image variable, a boolean calibration mask, four JPEG captures in images/2024-08-13/, and the metadata file that fills the template's placeholders.

# 1. Create the store. -a fills the template's {placeholders}.
zarrchive create examples/out.zarr -s examples/template.yml -a examples/meta.yml

# 2. Fill the image variable from the four captures.
zarrchive import examples/out.zarr -v captures -b examples

# 3. Import the single calibration mask, a PNG with no time axis.
zarrchive import examples/out.zarr -v mask -b examples

Read it back with plain xarray, as any reader would:

import imagecodecs.zarr, xarray as xr
imagecodecs.zarr.register_codecs()

xr.open_zarr("examples/out.zarr").sizes
# Frozen({'time': 4, 'y': 212, 'x': 221, 'band': 3})

xr.open_zarr("examples/out.zarr", group="calibration")["mask"]
# <xarray.DataArray 'mask' (y: 212, x: 221)> bool

Documentation

Detailed documentation is available here :

Page What it covers
Command line zarrchive create and zarrchive import: building a store from a shell, filling a variable from image files, and what a re-run can and cannot change.
Template YAML Every field of the template: dimensions, chunks and shards, variables, groups, encodings, quantization, the time axis, placeholders.
Writing The two time models, append-only rules, reserving, single vs. batch vs. bulk writes, metadata edits, locking.
Reading Opening a store with xarray, codec registration, consolidated metadata, what a reader needs.
Deleting delete_before / delete_after, why two mechanisms, and how shard size becomes a retention decision.
Upload client and server Shipping a day from a camera to an archive and reclaiming it, with authentication and Docker.
Python API Every member of Zarrchive and the module map.
Storage layout Chunks, shards, and where the write cost goes.
Example notebook Loading the example store with xarray: its groups and variables, one capture, an animation, the mask. Outputs saved, so it reads without running.

The template format has its own versioned contract in schema/schema.yml, kept in step with the code by a test.

Authors

License

MIT

Metadata

Release files for zarrchive 0.3.0

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

Source distribution (sdist)

Source distribution for zarrchive 0.3.0
File Size Uploaded Provenance Actions
zarrchive-0.3.0.tar.gz 130.7 kB Without provenance Details for zarrchive-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 284.4 kB

Release files / zarrchive-0.3.0.tar.gz

Download URL zarrchive-0.3.0.tar.gz
Size 130.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a3c4bf557c80431f45af727b84b53a4c7c917e1b77b005d8c169a8bb2dbea410
BLAKE2b-256 checksum
How to use checksums
7f0dec4e40980a56610a129d587ec45fa11f36c44cfd2ed7f6ea62a90d6e5130
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"LMDE","version":"7","id":"gigi","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / zarrchive-0.3.0-py3-none-any.whl

Download URL zarrchive-0.3.0-py3-none-any.whl
Size 153.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9fcb3cce9f35631979609fc3c54f8238fb28922e517ddbc915b3cfb78b95d26e
BLAKE2b-256 checksum
How to use checksums
a5f770bb16ad929dadca57e50623f825a49db3301290146ce055fda754e0edb9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.29 {"installer":{"name":"uv","version":"0.9.29","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"LMDE","version":"7","id":"gigi","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for zarrchive 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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