xarray data structures in Biology

Ian Hunt-Isaak · SciPy 2026

▶Talk was presented at SciPy 2026 - watch it on YouTube here:youtube.com/watch?v=AvdASvcOn1M
supported by Earthmover Chan Zuckerberg Initiative

outline

  • Introduction
  • Power of Xarray for Biology
    • Ergonomics
    • Indexes
  • OME/NGFF and Xarray
    • Premade Indexes
    • Data Container
  • OMICS
  • Getting Data into Xarray (when you can’t use ngff-zarr)
    • Virtualization
  • Conclusion

introducing the data

idr0062A · Blin et al. 2019 · LaminB1 + Dapi z-stack 2 channels · z 236 × y 275 × x 271 · uint16 idr.github.io/ome-ngff-samples · idr0062

the loaded dataset

Selection in Physical Coords

No Xarray

img[1, 30]

With Xarray

img.sel(c="Dapi", z=59.0)

Selection in Physical Coords

No Xarray

y0 = np.argmin(np.abs(y_um - 58))
y1 = np.argmin(np.abs(y_um - 80))
x0 = np.argmin(np.abs(x_um - 80))
x1 = np.argmin(np.abs(x_um - 98))
img[1, 30, y0:y1, x0:x1]

With Xarray

img.sel(c="Dapi", z=59.0,
        y=slice(58, 80), x=slice(80, 98))

per-object analysis

ds.ngff.groupby_labels().mean()

what’s an index?

encode knowledge of the structure of our data

  • select in physical coordinates (even complex ones)
  • efficiently — a precomputed lookup, not a full scan

many parts, each with an offset

reconstruct from the translations

tiles  = [Tile(arr, translation={"y": ty, "x": tx}) for ...]
mosaic = place_tiles(tiles)
mosaic.sel(x=256, y=320)

deskew

(synthetic)

lens distortion

(synthetic)

fish = xr.DataArray(
    photo,
    dims=("y_pixel", "x_pixel"),
    coords=Coordinates.from_xindex(
        CoordinateTransformIndex(lens)),
)

select in world space

fish.sel(x_world=line, y_world=0.2,
         method="nearest")

fish.isel(y_pixel=512)

But Wait!

  • I don’t know how to load my OME-Zarr into Xarray
  • Writing a custom Index is a mystery to me
  • Where on the Xarray object should I put the metadata

xarray-ome

  • loads OME-Zarr via ngff-zarr
  • metadata in consistent places — CF conventions
  • a structured .ngff accessor for downstream tools

Goals

  • Thoughtful translation from OME<-> Xarray
  • Prototype implementation
  • Cross Package metadata container

Non-Goals

  • Do this alone
  • Grow endless features

pip install xarray-ngff · xarray-ome.readthedocs.io

supported transform (coordinate system/indexes)

  • scale · translation — physical units
  • affine — rotation, shear, deskew
  • displacement field — per-pixel warp (lens)

XDGGS — xarray-indexes.readthedocs.io/earth/xdggs.html

everything so far assumes the data is already loaded

OMICS

anndata + spatial data

How to load the data in?

  • BIG DATASETS
  • not cloud native

https://apps.allenimmunology.org/aifi/insights/dynamics-imm-health-age/downloads/scrna/

Legacy Data Formats

  • h5ad
  • ndpi
  • many others…

read them without converting

Converting?

  • Compliance
  • Storage
  • Drift

Virtualization

the prerequisite for loading data into Xarray

What is it?

read the file where it lives — no copy

image: Tom Nicholas · earthmover.io/blog

Go to visual: https://earth-mover.github.io/icechunk-illustrated/virtual/slide/

ndpi

ndpi

h5ad

  • I can select across multiple files without downloading both!
repo   = Client().get_repo("earthmover-public/virtual-omics")
immune = open_anndata(repo, group="allen/immune_health_atlas")
ocular = open_anndata(repo, group="ocular_surface_atlas")
immune
AnnData object with n_obs × n_vars = 1821725 × 32357
    obs: 'AIFI_L1', 'AIFI_L3', 'subject.cmv', 'subject.ageGroup',
         'sex', 'donor_id', 'cohort.cohortGuid', 'sample.visitName'
    var: 'mito', 'highly_variable', 'means', …
one_immune = immune[immune.obs.donor_id == d1].to_memory()
one_ocular = ocular[ocular.obs.donor_id == d2].to_memory()

xarray and virtualization

conclusion

OME — try out the prototype · collaborate

Indexes — let’s build them together

Virtualization — what would you do with this?

Collaborate

ossci.zulipchat.com
napari.zulipchat.com
imagesc.zulipchat.com
scverse.zulipchat.com

ian@earthmover.io · ianhuntisaak@gmail.com

linked indexes

one selection across two linked coordinates

absolute ⇄ relative

epoch() / de_epoch() — same data, per-trial or wall-clock

ianhuntisaak.com/xarray-linked-indexes