xarray-ome#

Seamless integration between OME-Zarr and xarray#

xarray-ome provides an xarray backend for reading OME-Zarr (OME-NGFF) files, enabling efficient access to multiscale bioimaging data with lazy loading and physical coordinates.

Note

Powered by ngff-zarr

xarray-ome is built on top of ngff-zarr, which handles all OME-NGFF specification parsing and Zarr I/O. We focus on providing seamless xarray integration and coordinate transformations.

Features#

🚀 Easy to Use

Open OME-Zarr files with a single function call

from xarray_ome import open_ome_datatree
dt = open_ome_datatree("image.ome.zarr")
📊 Multiscale Support

Access entire multiscale pyramids as DataTree structures

high_res = dt["scale0"]
low_res = dt["scale2"]
🌍 Remote Access

Work with remote data without downloading

# Try with real IDR sample data!
url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
ds = open_ome_dataset(url)
⚡ Lazy Loading

Efficient processing with Dask integration

# Only loads what you need
subset = ds.isel(z=0).compute()

Quick Start#

Installation#

pip install xarray-ome

Basic Usage#

Try it with real data from the Image Data Resource:

import xarray as xr

# Load remote OME-Zarr data (no download needed!)
url = "https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.4/idr0062A/6001240.zarr"
ds = xr.open_dataset(url, engine="ome-zarr")

# View the dataset
ds
<xarray.Dataset> Size: 70MB
Dimensions:  (c: 2, z: 236, y: 275, x: 271)
Coordinates:
  * c        (c) <U7 56B 'LaminB1' 'Dapi'
  * z        (z) float64 2kB 0.0 0.5002 1.0 1.501 ... 116.0 116.5 117.0 117.5
  * y        (y) float64 2kB 0.0 0.3604 0.7208 1.081 ... 97.67 98.03 98.39 98.75
  * x        (x) float64 2kB 0.0 0.3604 0.7208 1.081 ... 96.23 96.59 96.95 97.31
Data variables:
    image    (c, z, y, x) uint16 70MB ...
Attributes:
    ome_scale:             {'c': 1.0, 'z': 0.5002025531914894, 'y': 0.3603981...
    ome_translation:       {'c': 0.0, 'z': 0.0, 'y': 0.0, 'x': 0.0}
    ome_ngff_resolution:   0
    ome_name:              image
    ome_version:           0.4
    ome_axes_types:        ['channel', 'space', 'space', 'space']
    ome_axes_units:        {'z': 'micrometer', 'y': 'micrometer', 'x': 'micro...
    ome_multiscale_paths:  ['0', '1', '2']
    ome_num_resolutions:   3
    ome_channel_colors:    ['0000FF', 'FFFF00']
    ome_channel_windows:   [{'min': 0.0, 'max': 65535.0, 'start': 0.0, 'end':...
    ome_ngff_metadata:     {'axes': [{'name': 'c', 'type': 'channel', 'unit':...

Notice the xarray Dataset with physical coordinates and channel labels:

  • Channel coordinates use labels from metadata ('LaminB1', 'Dapi') instead of indices

  • Physical coordinates in micrometers for spatial dimensions (z, y, x)

  • Lazy loading with Dask - data is only loaded when needed

  • OME metadata preserved in attributes for round-tripping

Now work with the data using familiar xarray operations:

# Select by channel name
lamin = ds.sel(c='LaminB1')
print(f"LaminB1 channel shape: {lamin['image'].shape}")

# Create maximum intensity projection
mip = ds['image'].sel(c='Dapi').max(dim='z')
print(f"MIP shape: {mip.shape}")

# Process a subset (only downloads what you need!)
subset = ds.sel(c='Dapi').isel(z=slice(0, 10))
print(f"Subset shape: {subset['image'].shape}")
print(f"Subset size: {subset['image'].nbytes / 1e6:.1f} MB")
LaminB1 channel shape: (236, 275, 271)
MIP shape: (275, 271)
Subset shape: (10, 275, 271)
Subset size: 1.5 MB

Architecture#

xarray-ome uses ngff-zarr for OME-Zarr I/O and focuses on the xarray integration:

        graph LR
    A[User Code] --> B[xarray-ome API]
    B --> C[Coordinate Translation]
    C --> D[ngff-zarr]
    D --> E[zarr]
    E --> F[Storage]
    
  • ngff-zarr: Handles OME-Zarr specification compliance and I/O

  • xarray-ome: Converts coordinate transformations and builds xarray structures

  • zarr: Provides chunked array storage with lazy loading

Contents#

Specification Support#

OME-NGFF Versions:

  • Reading: v0.1 through v0.5 (via ngff-zarr)

  • Writing: v0.4 and v0.5 (via ngff-zarr)

Data Structures:

  • ✅ Simple multiscale images

  • ❌ HCS plate structures (not yet supported)

Contributing#

Contributions are welcome! See our contributing guide for details.

License#

MIT License. See LICENSE file for details.

Acknowledgments#

  • Built on ngff-zarr for OME-Zarr handling

  • Inspired by xarray-ome-ngff for coordinate transformation patterns

  • Part of the OME-NGFF ecosystem