pynbody.transformation.Transformation#

class pynbody.transformation.Transformation(f, description=None)[source]#

Bases: Transformable, ABC

The base class for all transformations.

Note that this class inherits from Transformable, so all transformations are themselves transformable. This means that you can chain transformations together, e.g. for a SimSnap object f:

>>> with f.translate(fshift).rotate_x(45):
>>>    ...

Methods

apply_inverse_to(f)

Apply the inverse of this transformation to a specified simulation.

apply_to(f)

Apply this transformation to a specified simulation.

apply_transformation_to_array(array_name, family)

Apply the current transformation to an array.

current_transformation()

Return the transformation that has been applied to this object, if any.

offset_velocity(offset)

Shift the velocity by the given offset.

revert()

Revert the transformation.

rotate(matrix[, description])

Rotates using a specified matrix.

rotate_x(angle)

Rotates about the current x-axis by 'angle' degrees.

rotate_y(angle)

Rotates about the current y-axis by 'angle' degrees.

rotate_z(angle)

Rotates about the current z-axis by 'angle' degrees.

set_description(description)

Set a description for this transformation, including any chained transformations.

transform(matrix)

Deprecated alias for rotate().

translate(offset)

Translate by the given offset.

__init__(f, description=None)[source]#

Initialise a transformation, and apply it if not explicitly deferred

Parameters:
  • f (Transformable) – The simulation or transformation to act on. If a transformation is given, this transformation will be chained to it, i.e. the result will represent the composed transformation.

  • description (str) – A description of the transformation to be returned from str() and repr()

apply_inverse_to(f)[source]#

Apply the inverse of this transformation to a specified simulation.

Chained transformations are applied recursively.

Parameters:

f (SimSnap) – The simulation to apply the transformation to

Returns:

The input simulation (not a copy)

Return type:

SimSnap

apply_to(f: snapshot.SimSnap) snapshot.SimSnap[source]#

Apply this transformation to a specified simulation.

Chained transformations are applied recursively.

Parameters:

f (SimSnap) – The simulation to apply the transformation to. Any simulation reference stored within the transformation itself is ignored

Returns:

The input simulation (not a copy)

Return type:

SimSnap

apply_transformation_to_array(array_name, family)[source]#

Apply the current transformation to an array.

This is used internally by the snapshot class to ensure that arrays are transformed when they are loaded.

Parameters:
  • array_name (str) – The name of the array to transform

  • family (pynbody.family.Family | None) – The family to which the array belongs, or None if it is a snapshot-level array (default)

current_transformation() Transformation | None#

Return the transformation that has been applied to this object, if any.

offset_velocity(offset)#

Shift the velocity by the given offset.

Returns a pynbody.transformation.GenericTranslation object which can be used as a context manager to ensure that the velocity shift is undone.

For more information, see the pynbody.transformation documentation.

revert()[source]#

Revert the transformation. If it has not been applied, a TransformationException is raised.

rotate(matrix, description=None)#

Rotates using a specified matrix.

Returns a pynbody.transformation.Rotation object which can be used as a context manager to ensure that the translation is undone.

For more information, see the pynbody.transformation documentation.

Parameters:
  • matrix (array_like) – The 3x3 orthogonal matrix to rotate by

  • description (str) – A description of the rotation to be returned from str() and repr()

rotate_x(angle)#

Rotates about the current x-axis by ‘angle’ degrees.

Returns a pynbody.transformation.Rotation object which can be used as a context manager to ensure that the rotation is undone.

For more information, see the pynbody.transformation documentation.

rotate_y(angle)#

Rotates about the current y-axis by ‘angle’ degrees.

Returns a pynbody.transformation.Rotation object which can be used as a context manager to ensure that the rotation is undone.

For more information, see the pynbody.transformation documentation.

rotate_z(angle)#

Rotates about the current z-axis by ‘angle’ degrees.

Returns a pynbody.transformation.Rotation object which can be used as a context manager to ensure that the rotation is undone.

For more information, see the pynbody.transformation documentation.

set_description(description: str)[source]#

Set a description for this transformation, including any chained transformations.

Parameters:

description (str) – The description to set

transform(matrix)#

Deprecated alias for rotate().

translate(offset)#

Translate by the given offset.

Returns a pynbody.transformation.GenericTranslation object which can be used as a context manager to ensure that the translation is undone.

For more information, see the pynbody.transformation documentation.