Dataset
The SpatialDataset is the root container for a spatial omics experiment. See The data model for a conceptual overview.
Container types
SpatialOmics.SpatialDataset — Type
SpatialDataset(; path=nothing, spill_threshold=64_000_000, metadata=Dict())Root container for a spatial omics experiment.
Holds named collections of spatial elements (SpatialPoints, SpatialShapes, SpatialImage, SpatialLabels), a graph of CoordinateSystem nodes connected by AbstractTransformation edges, named SpatialRelation objects, and free-form metadata. Follows the SpatialData specification.
All data is backed by a BackingStore Zarr directory. When path is nothing, a temporary directory is used and cleaned up automatically. Supply path to write directly to a persistent location.
ds = SpatialDataset() # temp-backed
ds = SpatialDataset(path="/data/exp.zarr") # persistent-backedSee also
BackingStore, with_dataset, keep!, elements, coord_systems, relations
SpatialOmics.BackingStore — Type
BackingStore(; path=nothing, spill_threshold=64_000_000)Disk location for a dataset's Zarr storage, with ownership tracking.
When path is nothing, a temporary directory is created and owned by this store (deleted automatically when the parent SpatialDataset is garbage collected or closed). When path is supplied, the directory is used as-is and the store is not owned — no automatic cleanup occurs.
spill_threshold (bytes) controls when large arrays are written to disk immediately on element attachment rather than held in memory.
See also
Lifecycle
SpatialOmics.with_dataset — Function
with_dataset(f; path=nothing, kw...)Open a dataset, run f(ds), then close and clean up the backing store.
The dataset is always closed in a finally block, making this safe for temporary analysis workflows that should not leave stale Zarr directories on disk.
result = with_dataset() do ds
ds["cells"] = cells
analyze(Expression(), transcripts, cells)
endSee also
SpatialOmics.keep! — Function
keep!(ds, path=ds.backing.path) → dsMark the dataset's backing store as permanent, preventing automatic cleanup.
If path differs from the current backing path, the store is copied there first. After keep!, the dataset no longer owns its backing directory — it will not be deleted when ds is garbage collected or closed.
See also
Accessors
SpatialOmics.elements — Function
elements(ds) → OrderedDict{String, Any}Return the ordered dictionary of all named spatial elements in ds.
Values are concrete element types (SpatialPoints, SpatialShapes, SpatialImage, SpatialLabels). Use the typed accessors points, shapes, images, labels to retrieve a specific element with type checking.
SpatialOmics.coord_systems — Function
coord_systems(ds) → Vector{String}Return the names of all coordinate systems registered in ds.
SpatialOmics.transform — Function
transform(ds, src, dst) → AbstractTransformationResolve a composed transformation from coordinate system src to dst using the dataset's registered transforms. Delegates to resolve.
SpatialOmics.relations — Function
relations(ds) → Dict{String, SpatialRelation}
relations(ds, name) → SpatialRelationReturn the dictionary of all named relations, or a specific relation by name.
See also
Typed element retrieval
These functions retrieve a specific named element from a dataset (or dataset view) and verify its type. Prefer them over elements(ds)[name] to catch element-type mismatches early.
SpatialOmics.images — Function
SpatialOmics.labels — Function
labels(ds, name) → SpatialLabelsRetrieve the named SpatialLabels from a dataset or dataset view. Raises an error if the element is not a SpatialLabels.
See also