Transformations#

The transformations that can be defined between elements and coordinate systems in SpatialData.

class spatialdata.transformations.BaseTransformation[source]#

Bases: ABC

Base class for all transformations.

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

abstractmethod inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

abstractmethod to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.Identity[source]#

Bases: BaseTransformation

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.MapAxis(map_axis)[source]#

Bases: BaseTransformation

Transformation that maps input axes to output axes.

Parameters:

map_axis (dict[str, str]) – Dictionary with keys being the input axes and values the output axes.

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.Translation(translation, axes)[source]#

Bases: BaseTransformation

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.Scale(scale, axes)[source]#

Bases: BaseTransformation

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.Affine(matrix, input_axes, output_axes)[source]#

Bases: BaseTransformation

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).

class spatialdata.transformations.Sequence(transformations)[source]#

Bases: BaseTransformation

static validate_axes(axes)[source]#

Validate the axes.

This function is to allow to call validate_axes() from this file in multiple places while avoiding circular imports.

Return type:

None

inverse()[source]#

Return the inverse of the transformation.

Return type:

BaseTransformation

Returns:

: BaseTransformation

A new transformation that is the inverse of this one, such that applying both in sequence yields the identity transformation.

to_affine_matrix(input_axes, output_axes, _nested_sequence=False)[source]#

Return the affine matrix representation of the transformation.

Parameters:
  • input_axes (tuple[str, ...]) – The axes of the input coordinate system, e.g. ("x", "y") or ("c", "z", "y", "x").

  • output_axes (tuple[str, ...]) – The axes of the output coordinate system.

Return type:

NDArray[floating[Any]]

Returns:

: ArrayLike

A homogeneous affine matrix of shape (len(output_axes) + 1, len(input_axes) + 1). The last row is always [0, 0, ..., 1] (homogeneity).