clearscale is a dependency-free Python library for reading, transforming, and writing multiscale image metadata.
It provides an abstraction layer between image-processing code and metadata formats such as OME-Zarr. Work with named axes, shapes, pixel sizes, and spatial relations; clearscale handles the format-specific parsing and serialization. Your application keeps control of array storage, image processing, and the user interface.
Requires Python 3.10 or newer.
pip install clearscale==0.9.0Or:
conda install -c conda-forge clearscale==0.9.0The 0.9 series is in beta; the public API may change before 1.0.
The documentation includes the full API reference and practical guides such as:
- OME-Zarr integration: read, inspect, and write metadata across versions.
- Scaling methods: match metadata to the behavior of your processing code.
- Coordinate systems and scenes: describe spatial context and relationships between images.
- Axis-aware metadata: Immutable, ordered mappings keep axis names attached to their shapes, pixel size, unit and translation values through reordering, insertions and drops.
- Multiscale planning: Shape and factor blueprints describe resolution levels and can drive your processing code. Scaling method characterization helps you calculate the corresponding pixel sizes and translations.
- OME-Zarr support: Read versions 0.1–0.6 through a common API and write versions 0.4, 0.5, and 0.6, with validation on read and construction.
- Spatial relationships: Describe alternate coordinate systems, affine transformations, and relations between images, including OME-Zarr 0.6 scenes.
- A small integration footprint: Pure Python, no runtime dependencies, and typed APIs designed to work with ordinary Python mappings and your choice of array and storage libraries.
Suppose your application has written an image array with axes zyx at path s0 within a Zarr group.
Here is how to describe its shape and physical pixel sizes, and prepare OME-Zarr metadata:
import clearscale as cs
shape = cs.Shape(z=16, y=64, x=64)
pixel_size = cs.PixelSize(z=0.5, y=0.25, x=0.25)
unit = cs.Unit(z="micrometer", y="micrometer", x="micrometer")
# A Scale describes one array
scale = cs.Scale(shape=shape, pixel_size=pixel_size, unit=unit)
# A Multiscale describes the image the Scale belongs to
multiscale = cs.Multiscale.from_single(scale, scale_key="s0")
# An OmeZarrGroup prepares the metadata for a Zarr group's attributes
ome_attrs = cs.OmeZarrGroup.from_single(multiscale).to_attrs(version="0.5")Attach ome_attrs to the group using your Zarr library.
Typically:
zarr_group.attrs.update(ome_attrs).
Your code retains full ownership of data processing, but also the responsibility for keeping data and metadata in sync. See documentation for suggested approaches, including complete data+metadata examples.
The OME-Zarr ecosystem benefits from the work of projects such as bioio, ngff-zarr, ngio, ome-zarr-py, and yaozarrs. The NGFF tools directory is a useful overview of the wider ecosystem.
clearscale focuses on the metadata layer for applications, libraries, and scripts that already have their own storage and processing choices. This narrow scope keeps it easy to integrate into an existing environment. It works only with metadata, aiming to provide a unified API across different metadata formats and versions. This leaves data access, resampling, chunking and compression to the tools you choose for those jobs.
Questions, bug reports, and contributions are welcome. If something is awkward to express in your application, please let us know!
See CONTRIBUTING.md for development instructions and project scope, or open an issue.
Licensed under either the MIT license or the Apache License, Version 2.0, at your option.