ngff_zarr.declare_field_transform

Declare a field image as an RFC-5 displacements or coordinates transform.

A field store that only types its component axis is labelled, not applicable: a reader sees what the channels are, but no transformation says between which coordinate systems the field maps, so nothing can apply it. The declaration is the displacements (or coordinates) entry on the multiscales’ coordinateTransformations; building it by hand means reaching into the version metadata model and validating axis order, component count and system references oneself. This function is that composition, validated, in one call.

Two layouts use it. A standalone field store – the artifact a registration emits – declares the transform on its own multiscales, mapping a spatial coordinate system onto itself through its own level-0 array; the default arguments produce exactly that. A field written beside the image it displaces declares the transform on the image’s multiscales instead, with path naming the field’s array and input_system/output_system referencing the image’s own coordinate systems.

Declared and written at 0.6, the store is applicable by this package’s own reader: :func:~ngff_zarr.ngff_displacement_field_to_itk_transform rebuilds an ITK transform from it with no other information.

Module Contents

Classes

FieldTransformType

Which RFC-5 field transformation a field image declares.

Functions

declare_field_transform

Return multiscales with the field transform declared on it.

_check_field_image

The standalone checks – the multiscales is the field, so its shape is here to check: one component axis of the right type first, then the spatial axes, one component per spatial axis. Returns the spatial dims.

_with_spatial_system

The systems with a spatial one named name, declared from the field’s own axes if absent; an existing one must already carry those axes in order, or the declaration would reference a system the field does not match.

Data

API

class ngff_zarr.declare_field_transform.FieldTransformType

Bases: enum.StrEnum

Which RFC-5 field transformation a field image declares.

Displacements holds offsets from each point, Coordinates the output positions themselves. The members are the values, so FieldTransformType.Displacements == "displacements" and a plain string still passes.

Initialization

Initialize self. See help(type(self)) for accurate signature.

Displacements

‘displacements’

Coordinates

‘coordinates’

ngff_zarr.declare_field_transform._COMPONENT_TYPES

None

ngff_zarr.declare_field_transform.declare_field_transform(
multiscales: ngff_zarr.multiscales.NgffMultiscales,
*,
transform_type: ngff_zarr.declare_field_transform.FieldTransformType | str = FieldTransformType.Displacements,
path: str | None = None,
input_system: str | None = None,
output_system: str | None = None,
coordinate_system: str = 'physical',
interpolation: str = 'linear',
) → ngff_zarr.multiscales.NgffMultiscales

Return multiscales with the field transform declared on it.

Functional and additive: the argument is not mutated, and the entry is appended to any coordinateTransformations already declared. The result must be written at OME-Zarr 0.6 or later; earlier versions cannot carry multiscale-level transformations and :func:~ngff_zarr.to_ome_zarr refuses them.

Parameters:
  • multiscales (NgffMultiscales) – The multiscales to declare the transform on: the field itself (standalone, the default), or the image the field displaces (with path naming the field’s array).

  • transform_type (FieldTransformType | str, optional) – Which field transformation the declaration is, as a :class:FieldTransformType member or its string value: Displacements (the field holds offsets from each point) or Coordinates (it holds the output positions themselves). The choice fixes the component axis type the field must carry.

  • path (str, optional) – The zarr path of the field’s array. Default: the multiscales’ own finest dataset – the standalone store. When given, the field is elsewhere and its shape cannot be checked here; the references still are.

  • input_system (str, optional) – Name of the declared coordinate system the transform maps from. Pass both input_system and output_system, or neither: with neither, a spatial system named coordinate_system is declared from the field’s own axes and the transform maps it onto itself, which is the standalone total field.

  • output_system (str, optional) – Name of the declared coordinate system the transform maps onto. See input_system.

  • coordinate_system (str, optional) – Name of the spatial coordinate system to declare when input_system/output_system are not given.

  • interpolation (str, optional) – How a reader interpolates the field between grid points.

Returns:

A new multiscales carrying the declaration.

Return type:

NgffMultiscales

Raises:

ValueError – If the field’s axes are not one component axis of the type the transform calls for followed by the spatial axes, if it holds a number of components other than the number of spatial axes, if a named system is not declared, or if the entry does not validate against the systems it references.

ngff_zarr.declare_field_transform._check_field_image(
multiscales: ngff_zarr.multiscales.NgffMultiscales,
component_type: str,
) → list

The standalone checks – the multiscales is the field, so its shape is here to check: one component axis of the right type first, then the spatial axes, one component per spatial axis. Returns the spatial dims.

ngff_zarr.declare_field_transform._with_spatial_system(systems: list, name: str, spatial: list, units) → list

The systems with a spatial one named name, declared from the field’s own axes if absent; an existing one must already carry those axes in order, or the declaration would reference a system the field does not match.