anu_ctlab_io

python I/O for the ANU CTLab array storage format(s).

Submodules

Package Contents

class anu_ctlab_io.Dataset(data, *, dimension_names, voxel_unit, voxel_size, datatype, history=None)

Bases: AbstractDataset

A Dataset, containing the data and metadata read from one of the ANU CTLab file formats.

Datasets are the primary interface to the anu_ctlab_io package, and should generally be constructed by users via the Dataset.from_path classmethod. Note that the relevant extra (netcdf or zarr) must be installed.

The initializer of this class should only be used when manually constructing a Dataset, which is not the primary usage of this library.

Parameters:
  • data (dask.array.Array)

  • dimension_names (tuple[str, Ellipsis])

  • voxel_unit (anu_ctlab_io._voxel_properties.VoxelUnit)

  • voxel_size (tuple[numpy.float32, numpy.float32, numpy.float32])

  • datatype (anu_ctlab_io._datatype.DataType)

  • history (dict[str, Any] | None)

classmethod from_path(path, *, filetype='auto', parse_history=True, **kwargs)

Creates a Dataset from the data at the given path.

The data at path must be in one of the ANU mass data storage formats, and the optional extras required for the specific file format must be installed.

Parameters:
  • path (pathlib.Path | str) – The path to read data from.

  • filetype (str)

  • parse_history (bool)

  • kwargs (Any)

Return type:

Dataset

property voxel_size: tuple[numpy.float32, numpy.float32, numpy.float32]

The voxel size of the data.

Return type:

tuple[numpy.float32, numpy.float32, numpy.float32]

property voxel_unit: anu_ctlab_io._voxel_properties.VoxelUnit

The unit the data’s voxel size is in.

Return type:

anu_ctlab_io._voxel_properties.VoxelUnit

property dimension_names: tuple[str, Ellipsis]

The names of the data’s dimensions. Usually ("z", "y", "x").

Return type:

tuple[str, Ellipsis]

property history: dict[Any, Any] | str

The history metadata associated with the Dataset.

If parsing is enabled this will be a nested dict, otherwise it will be a dictionary without any guaranteed structure.

Return type:

dict[Any, Any] | str

property mask_value: anu_ctlab_io._datatype.StorageDType | None

The mask value being used by the data.

Return type:

anu_ctlab_io._datatype.StorageDType | None

property data: dask.array.Array

The data contained within the Dataset.

This is a Dask Array.

Return type:

dask.array.Array

class anu_ctlab_io.DataType(*args, **kwds)

Bases: enum.Enum

An Enum representing the datatypes produced by MANGO.

This is used when parsing metadata to construct a Dataset, and generally should not need to be constructed by a user (use the Dataset.from_path classmethod instead).

When needed, DataTypes should be constructed via either the infer_from_path or the from_basename classmethods.

PROJU16 = 'proju16'
PROJF32 = 'projf32'
TOMO_FLOAT = 'tomo_float'
TOMO = 'tomo'
FLOAT16 = 'float16'
FLOAT64 = 'float64'
SEGMENTED = 'segmented'
DISTANCE_MAP = 'distance_map'
LABELS = 'labels'
RGBA8 = 'rgba8'
property is_discrete: bool

Whether the DataType is discrete.

Return type:

bool

property dtype: numpy.typing.DTypeLike

The numpy dtype appropriate for storing data of the DataType.

Because of a historical decision in MANGO, the datatype listed in ANU CTLab NetCDFs is not guaranteed to have the correct signed/unsigned type – for some MANGO datatypes, data recorded in the NetCDF as an integer type is really an unsigned integer stored in an integer. The dtype is the real datatype of the data, regardless of whether a loaded NetCDF exhibits this behaviour (trust this value, not the NetCDF header).

Return type:

numpy.typing.DTypeLike

property mask_value: StorageDType | None

The mask value of the DataType.

This value is corrected for signedness if required (see dtype).

Return type:

StorageDType | None

classmethod infer_from_path(path)

Create a DataType object by inferring it from the path to the data being loaded.

Relies on MANGO’s standardised file naming.

Return type:

DataType

Parameters:

path (str | pathlib.Path)

classmethod from_basename(basename)

Create a DataType object from it’s name as a string.

E.g., DataType.from_basename("tomo")

Return type:

DataType

Parameters:

basename (str)

type anu_ctlab_io.StorageDType = np.uint8 | np.uint16 | np.uint32 | np.uint64 | np.float16 | np.float32 | np.float64
class anu_ctlab_io.VoxelUnit(*args, **kwds)

Bases: enum.Enum

The unit of size of a voxel.

M = 'm'
CM = 'cm'
MM = 'mm'
UM = 'um'
NM = 'nm'
ANGSTROM = 'angstrom'
VOXEL = 'voxel'
classmethod from_str(string)

Create a VoxelUnit from the string name of the unit.

Accepts a wide range of standard representations of each unit, and is case insensitive.

Parameters:

string (str)

Return type:

VoxelUnit