acia.segm.nd2_source#
Lazy, memory-bounded image source for Nikon ND2 files.
An ND2 file may contain several stage positions; the ROI workflow processes a
single position, which itself is a time series. ND2SequenceSource
selects one position and exposes that position’s (T, H, W, C) time series
through the standard ImageSequenceSource contract.
The ND2 file is opened lazily on first access and read one frame at a time
via the nd2 dask interface, so peak memory stays at a single frame
regardless of file size (ND2 files may be tens of gigabytes). nd2 is an
optional dependency, imported lazily inside ND2SequenceSource._ensure_reader().
- class acia.segm.nd2_source.ND2SequenceSource[source]#
Bases:
ImageSequenceSource,JupyterVisualizationMixinA single ND2 position exposed as a lazy
(T, H, W, C)time series.Axis mapping is done by name (using the file’s
sizesdict), never by a fixed axis order. For each frame the source selectsP == positionandT == frame, moves the channel axis last, and adds a trailing channel axis for grayscale planes so every frame is shaped(H, W, C).The reader is opened lazily and only a single frame is materialized at a time via
nd2’s dask interface; the whole array is never loaded.- Parameters:
path – Path to the
.nd2file.position – Index of the stage position to expose. A file with no
Paxis is treated as a single position (only0is valid).pixel_size – Optional pint length per pixel that overrides the file’s voxel size. Strings like
"0.5 um"are accepted.frame_interval – Optional scalar time between frames (pint or string) that overrides metadata-derived timing.
timepoints – Optional explicit per-frame pint
Quantityarray that overrides metadata-derived timing.
- property pixel_size#
Pint length per pixel, resolved from the file (or override).
- property timepoints#
Per-frame pint timepoints, or
Noneif uncalibrated.
- property channel_names: list[str]#
Channel names from ND2 metadata (best-effort; empty if unavailable).
- get_frame(frame)[source]#
Read a single
(H, W, C)plane for(position, frame).Only the requested frame is materialized (via the dask interface); the whole array is never loaded.
- Parameters:
frame (int) – Time index of the frame to read.
- Returns:
BaseImage – A
LocalImagewrapping the(H, W, C)plane.- Return type: