iaf.io.readers

Custom image readers.

class iaf.io.readers.HuygensHDF5Reader(filename: Path | str = None)[source]

Bases: object

Huygens HDF5 Reader.

Example:

from iaf.io.readers import HuygensHDF5Reader

# Initialize the reader
reader = HuygensHDF5Reader("file.h5")

# To load a specific (timepoint, channel) image or stack:
stack = reader.load(timepoint=0, channel=0)

Stacks are lazily loaded only on access.

The reader exposes metadata information via properties:

Property

Explanation

reader.channel_names

Tuple of names for each of the acquisition channels.

reader.filename

Full file name of the opened file.

reader.num_channels

Number of channels.

reader.num_planes

Number of planes (z levels).

reader.num_timepoints

Number of time points.

reader.voxel_sizes

Voxel sizes in units (nm) (x, y, z).

reader.metadata

Dictionary of microscopy parameters.

reader.hdf5_dataset

HDF5 dataset for advanced use.

property channel_names: tuple

Return the names of the channels.

Returns:

channel_names – Names of the channels

Return type:

tuple

property filename: str

Return the file name with full path.

Returns:

filename – Full file name, or empty string if not set.

Return type:

str

property hdf5_dataset: Dataset | None

Return the underlying HDF5 dataset.

Returns:

hdf5_dataset – HD5 dataset if a file is open, or None otherwise.

Return type:

h5py.Dataset

load(timepoint: int = 0, channel: int = 0)[source]

Load specific timepoint and channel.

Parameters:
  • timepoint (int) – Index of the timepoint to load, 0-based. (Optional, default 0).

  • channel (int) – Index of the channel to load, 0-based. (Optional, default 0).

Returns:

dataset – Dataset at the requested timepoint and channel.

Return type:

Union[None, DataSet, np.ndarray]

property metadata: dict

Return the metadata dictionary.

Returns:

metadata – Metadata dictionary.

Return type:

dict

property num_channels: int

Return the number of channels.

Returns:

num_channels – Number of channels per series in the file. If no file is open, num_channels is 0.

Return type:

int

property num_planes: int

Return the number of planes.

Returns:

num_planes – Number of planes per series in the file. If no file is open, num_planes is 0.

Return type:

int

property num_timepoints: int

Return the number of timepoints.

Returns:

num_timepoints – Number of timepoints per series in the file. If no file is open, num_timepoints is 0.

Return type:

int

property size: tuple

Return the XYZ size of the dataset.

Returns:

size – Size (x, y, z)

Return type:

tuple

property voxel_sizes: tuple

Return the global voxel sizes for the acquisition.

Returns:

voxel_sizes – Voxel sizes (vx, vy, vz)

Return type:

tuple

class iaf.io.readers.ImarisReader(filename: Path | str = None)[source]

Bases: object

Imaris Reader.

Example:

from iaf.io.readers import ImarisReader

# Initialize the reader
reader = ImarisReader("file.ims")

# To load a specific (timepoint, channel) image or stack:
stack = reader.load(timepoint=0, channel=0)

Stacks are lazily loaded only on access.

The reader exposes metadata information via properties:

Property

Explanation

reader.channel_names

Tuple of names for each of the acquisition channels.

reader.filename

Full file name of the opened file.

reader.num_channels

Number of channels.

reader.num_planes

Number of planes (z levels).

reader.num_timepoints

Number of time points.

reader.voxel_sizes

Voxel sizes in units (µm) (x, y, z).

reader.extends

Extents in units (µm) (minX, maxX, minY, maxY, minZ, maxZ).

property channel_names: tuple

Return the names of the channels.

Returns:

channel_names – Names of the channels

Return type:

tuple

property extends: tuple

Return the dataset extends.

Returns:

extends – Dataset extends: (extMinX, extMaxX, extMinY, extMaxY, extMinZ, extMaxZ)

Return type:

tuple

property filename: str

Return the file name with full path.

Returns:

filename – Full file name, or empty string if not set.

Return type:

str

load(timepoint: int = 0, channel: int = 0, resolution_level: int = 0)[source]

Load specific timepoint and channel.

Parameters:
  • timepoint (int) – Index of the timepoint to load, 0-based. (Optional, default 0).

  • channel (int) – Index of the channel to load, 0-based. (Optional, default 0).

  • resolution_level (int) – Resolution level to load, with 0 being full resolution. (Optional, default 0).

Returns:

dataset – Dataset at the requested timepoint and channel.

Return type:

Union[None, DataSet, np.ndarray]

property num_channels: int

Return the number of channels.

Returns:

num_channels – Number of channels per series in the file. If no file is open, num_channels is 0.

Return type:

int

property num_planes: int

Return the number of planes.

Returns:

num_planes – Number of planes per series in the file. If no file is open, num_planes is 0.

Return type:

int

property num_timepoints: int

Return the number of timepoints.

Returns:

num_timepoints – Number of timepoints per series in the file. If no file is open, num_timepoints is 0.

Return type:

int

property size: tuple

Return the XYZ size of the dataset.

Returns:

size – Size (x, y, z)

Return type:

tuple

property voxel_sizes: tuple

Return the global voxel sizes for the acquisition.

Returns:

voxel_sizes – Voxel sizes (vx, vy, vz)

Return type:

tuple

class iaf.io.readers.NikonND2Reader(filename: Path | str = None)[source]

Bases: object

Nikon ND2 reader that internally uses [nd2reader](https://open-science-tools.github.io/nd2reader/) by

Ruben Verweij.

Example:

from iaf.io.readers import NikonND2Reader

# Initialize the reader
reader = NikonND2Reader("file.nd2")

# To iterate over all series (or timepoints):
for img in reader:
    pass

# To access a specific series (or timepoint):
stack = reader[0]

Series (or timepoints) are lazily loaded only on access.

The reader exposes metadata information via properties:

Property

Explanation

reader.channel_names

Tuple of names for each of the acquisition channels.

reader.filename

Full file name of the opened file.

reader.geometry

Geometry for each series.

reader.iter_axis

Axis over which the iteration occurs (one of "v" or "t").

reader.metadata

Processed file metadata (dictionary).

reader.num_channels

Number of channels.

reader.num_planes

Number of planes (z levels).

reader.num_series

Number of series (acquisitions) in the file.

reader.num_timepoints

Number of time points.

reader.voxel_sizes

Voxel sizes in units (µm) (x, y, z).

If a file contains several series, iter_axis will be "v": that is, the iterator will return one series at a time. If there is only one series, however, iter_axis will point to the next dimension, that is "t". In this case, the iterator will return one time point at a time. No more granularity is supported. In all cases, the geometry property will indicate the dimensionality of the array returned by the iterator (e.g., "czyx").

property channel_names: tuple

Return the names of the channels.

Returns:

channel_names – Voxel sizes (x, y, z)

Return type:

tuple

property filename: str

Return the file name with full path.

Returns:

filename – Full file name, or empty string if not set.

Return type:

str

property geometry: str

Return the geometry of the individual image or stack.

Returns:

geometry – Geometry of the individual image or stack. If no file is open, geometry is “”.

Return type:

str

property iter_axis: str

Return the axis used for iterating over individual images or stacks.

Returns:

iter_axis – Axis used for iterating over individual images of stacks. If no file is open, iter_axis is “”.

Return type:

str

property metadata: dict

Return the processed file metadata.

Returns:

matadata – Metadata dictionary. If no file is open, metadata is {}.

Return type:

dict

property num_channels: int

Return the number of channels.

Returns:

num_channels – Number of channels per series in the file. If no file is open, num_channels is 0.

Return type:

int

property num_planes: int

Return the number of planes.

Returns:

num_planes – Number of planes per series in the file. If no file is open, num_planes is 0.

Return type:

int

property num_series: int

Return the number of series.

Returns:

num_series – Number of series in the file. If no file is open, num_series is 0.

Return type:

int

property num_timepoints: int

Return the number of timepoints.

Returns:

num_timepoints – Number of timepoints per series in the file. If no file is open, num_timepoints is 0.

Return type:

int

property raw_metadata: None | dict

Return the raw file metadata.

Returns:

raw_metadata – If no file is open, raw_metadata is None.

Return type:

object of type [RawMetadata](https://open-science-tools.github.io/nd2reader/nd2reader.html#module-nd2reader.raw_metadata).

property voxel_sizes: tuple

Return the global voxel sizes for the acquisition.

Returns:

voxel_sizes – Voxel sizes (vx, vy, vz)

Return type:

tuple