Taping Module#

Module: pyradise.data.taping

General#

The taping module provides the abstract Tape mechanism for recording and playback arbitrary data and an implementation for recording and playback transformations applied to images (see TransformTape).

Class Overview#

The following classes are provided by the taping module:

Class

Description

Tape

Base class for all Tape subclasses.

TransformTape

Tape class to record physical property changes and transformations of an Image instance.

TransformInfo

Class to store and handle information about the modification / transformation of an Image instance.

Details#

class Tape[source]#

Bases: ABC

An abstract class for a tape which records defined elements and can replay them upon request.

abstract record(value)[source]#

Record a value on the Tape.

Parameters:

value (Any) – The value to be recorded.

Return type:

None

Returns:

None

abstract static playback(data, **kwargs)[source]#

Playback the recorded elements of the Tape on the data object.

Parameters:
  • data (Any) – The data on which the playback should take place. This object need to contain also the tape.

  • **kwargs – Additional keyword arguments.

Returns:

The back played data.

Return type:

Any

get_recorded_elements(reverse=False)[source]#

Get the recorded elements on the Tape.

Parameters:

reverse (bool) – Indicates if the recordings should be returned in reverse order.

Returns:

The recorded elements of the Tape.

Return type:

Tuple[Any, …]

reset()[source]#

Reset the Tape.

Return type:

None

Returns:

None

class TransformTape[source]#

Bases: Tape

A class to keep track of the TransformInfo instances such that they can be played back on appropriate data. This class provides the basic functionality to render invertibility and reproducibility feasible.

record(value)[source]#

Record a TransformInfo instance on the tape.

Parameters:

value (TransformInfo) – The TransformInfo instance to record.

Return type:

None

Returns:

None

get_recorded_elements(reverse=False)[source]#

Get the recorded TransformInfo instances.

Parameters:

reverse (bool) – Indicates if the recorded elements should be returned in reverse order (default: False).

Returns:

The recorded TransformInfo instances.

Return type:

Tuple[TransformInfo, …]

static playback(data, **kwargs)[source]#

Play back the recorded TransformInfo instances on the provided data.

Parameters:
  • data (Image) – The data to play back the recorded TransformInfo instances on.

  • **kwargs – Additional keyword arguments.

Returns:

The Image instance after the playback of the recorded TransformInfo instances.

Return type:

Image

reset()#

Reset the Tape.

Return type:

None

Returns:

None

class TransformInfo(name, params, pre_transform_image_properties, post_transform_image_properties, filter_args=None, additional_data=None, transform=None)[source]#

Bases: object

A class to store information about a data transformation performed via a Filter. This class is used in combination with a TransformTape instance to keep track of data transformations and to render invertibility feasible for invertible filters operations.

Parameters:
  • name (str) – The name of the filter which performed the data transformation.

  • params (Optional[FilterParameters]) – The filter parameters which parameterize the data transformation.

  • pre_transform_image_properties (ImageProperties) – The image properties before the data transformation.

  • post_transform_image_properties (ImageProperties) – The image properties after the data transformation.

  • filter_args (Optional[Dict[str, Any]]) – The filter arguments passed via the constructor of the filter (default: None).

  • additional_data (Optional[Dict[str, Any]]) – Additional data which is required the data transformation or to inverse it (default: None).

  • transform (Optional[sitk.Transform]) – A SimpleITK transform which may be used for the data transformation (default: None).

get_filter()[source]#

Get the Filter instance which performed the data transformation.

Returns:

The filter used for the data transformation.

Return type:

Filter

get_params()[source]#

Get the FilterParams instance which was used to parameterize the data transformation.

Returns:

The filter parameters used for the data transformation.

Return type:

FilterParameters

get_image_properties(pre_transform)[source]#

Get the pre-transform or post-transform ImageProperties instance.

Parameters:

pre_transform (bool) – If True returns the pre-transform image properties, otherwise the post-transform image properties.

Returns:

The pre-transform or post-transform image properties.

Return type:

ImageProperties

add_data(key, value)[source]#

Add additional data to the TransformInfo instance.

Note

If the provided key already exists, the value will be overwritten.

Parameters:
  • key (str) – The key of the additional data.

  • value (Any) – The value of the additional data.

Return type:

None

Returns:

None

get_data(key)[source]#

Get additional data from the TransformInfo instance by key.

Parameters:

key (str) – The key of the additional data entry to get.

Returns:

The value of the additional data entry. If the key is not existing None is returned.

Return type:

Any

get_transform(inverse=False)[source]#

Get the SimpleITK.Transform instance which was used to perform the data transformation.

Parameters:

inverse (bool) – Indicates if the inverse transform should be returned (default: False).

Returns:

The transform used for the data transformation or the identity transform if origin and direction did not change during data transformation.

Return type:

sitk.Transform