basecoat is the Layer 1 core plumbing library for the BASE Laboratory image-based modelling ecosystem (ECOSYSTEM.md). It provides a single-array Volume container, co-registered VolumeSet, non-materialising LazyVolume region I/O (OME-Zarr v0.4, HDF5, TIFF, .npy, and raw binary), pullback 3-D coordinate transforms (AffineTransform3D, SimilarityTransform3D), cell-centred resampling, and SHA-256 dataset fetching—with lightweight scientific dependencies (numpy, scipy, h5py, tifffile, zarr<3, numcodecs).
Maintainer: James Le Houx (james.lehoux@gre.ac.uk)
pip install basecoatOptional extras:
pip install "basecoat[sitk]" # SimpleITK transform bridge (.to_sitk() / .from_sitk())
pip install "basecoat[dev]" # pytest, ruff, mypy, SimpleITK, ome-zarr validatorimport numpy as np
import basecoat as bc
raw = np.random.default_rng(0).normal(size=(64, 64, 64)).astype(np.float32)
labels = (raw > 0.25).astype(np.int32)
img = bc.Volume.from_array(raw, voxel_size_um=0.8125, space="i13_4x")
seg = bc.Volume.from_array(
labels,
voxel_size_um=0.8125,
space="i13_4x",
label_names={0: "pore", 1: "solid"},
)
# Convert physical spacing explicitly at solver boundaries (metres)
dz_m, dy_m, dx_m = img.spacing_in("m")
# Write co-registered OME-Zarr v0.4 multiscale store (mode-downsampled label pyramid)
vset = bc.VolumeSet(img, labels={"phase": seg})
bc.write_ome_zarr(vset, "sample.ome.zarr", overwrite=True)
# Lazy region read (never loads the full volume into RAM)
with bc.open_volume("sample.ome.zarr") as lv:
roi = lv.read_region((slice(16, 48), slice(16, 48), slice(16, 48)))- Index-0 cell-centre coordinates:
AxisSpec.offsetis the physical coordinate of the centre of voxel0, so voxelihas its centre atoffset + i * scale. Coarsening a spatial axis by factorkviacoarsen_axesshifts the coarse level's index-0centre tooffset + 0.5 * (k - 1) * scale, preserving outer voxel faces. - Pullback transforms (
fixed -> moving):AffineTransform3DandSimilarityTransform3Dmap physical points fromfrom_space(the target/output grid) toto_space(the moving/input grid) in('z', 'y', 'x')order, matchingscipy.ndimage.affine_transformandSimpleITK.ResampleImageFilter. - Zero silent unit guessing: Uncalibrated volumes have
unit="voxel"; callingvol.spacing_in("m")raisesUnitConversionErrorexplaining how to attach spacing.
See ECOSYSTEM.md for the canonical four-layer dependency rules, data contract, two-consumer admission rule, and repository registry across BASE Laboratory.
BSD 3-Clause. See LICENSE and CITATION.cff.