snake.core.transform#

Mathematical transformations of data.

Module Contents#

Functions#

effective_affine

Compute the effective affine transformation between two affine matrices.

_validate_gpu_affine

Check if we can use the affine_transform from cupy.

apply_affine

Apply the new affine on the data.

__apply_affine

apply_affine4d

Apply the new affine on 4D data.

serialize_array

Serialize the array for mrd compatible format.

unserialize_array

Unserialize the array for mrd compatible format.

Data#

log

API#

snake.core.transform.log = 'getLogger(...)'[source]#
snake.core.transform.effective_affine(old: numpy.typing.NDArray, new: numpy.typing.NDArray) numpy.typing.NDArray[source]#

Compute the effective affine transformation between two affine matrices.

snake.core.transform._validate_gpu_affine(use_gpu: bool = True) tuple[bool, collections.abc.Callable, types.ModuleType][source]#

Check if we can use the affine_transform from cupy.

snake.core.transform.apply_affine(data: numpy.typing.NDArray[numpy.float32], old_affine: numpy.typing.NDArray[numpy.float32], new_affine: numpy.typing.NDArray[numpy.float32], new_shape: snake._meta.ThreeInts, output: numpy.typing.NDArray[numpy.float32] = None, transform_affine: numpy.typing.NDArray[numpy.float32] = None, use_gpu: bool = True, **kwargs: Any) numpy.typing.NDArray[numpy.float32][source]#

Apply the new affine on the data.

Parameters:
  • data (NDArray) – Data to be transformed. 3D Array.

  • old_affine (NDArray) – Affine of the original data

  • new_affine (NDArray) – Affine of the new data

  • new_shape (ThreeInts) – Shape of the new data

  • transform_affine (NDArray, optional) – Transformation affine, by default None

  • use_gpu (bool, optional) – Try to use GPU, by default True

  • output (NDArray, optional) – Output array, by default None

Returns:

  • NDArray

  • Resampled data with new_affine orientation and new_shape shape.

snake.core.transform.__apply_affine(x: numpy.typing.NDArray, output: numpy.typing.NDArray, i: int, *args: Any, **kwargs: Any) numpy.typing.NDArray[source]#
snake.core.transform.apply_affine4d(data: numpy.typing.NDArray, old_affine: numpy.typing.NDArray, new_affine: numpy.typing.NDArray, new_shape: snake._meta.ThreeInts, use_gpu: bool = False, n_jobs: int = -1, axis: int = 0, **kwargs: Any) numpy.typing.NDArray[source]#

Apply the new affine on 4D data.

Parameters:
  • data (NDArray) – Data to be transformed. 3D Array.

  • old_affine (NDArray) – Affine of the original data

  • new_affine (NDArray) – Affine of the new data

  • new_shape (ThreeInts) – Shape of the new data

  • transform_affine (NDArray, optional) – Transformation affine, by default None

  • use_gpu (bool, optional)

Returns:

Resampled data with new_affine orientation and new_shape shape.

Return type:

NDArray

See also

apply_affine

snake.core.transform.serialize_array(arr: numpy.typing.NDArray) str[source]#

Serialize the array for mrd compatible format.

snake.core.transform.unserialize_array(s: str) numpy.typing.NDArray[source]#

Unserialize the array for mrd compatible format.