pynbody.transformation

pynbody.transformation#

Module for describing, applying and reverting Galilean transformations on simulations.

Generally it is not necessary to access this module directly, but it is used by SimSnap class to implement e.g. rotate_x() etc, and also by analysis transformations such as center() and faceon() etc.

The main feature of this module is the Transformation class, which performs transformations of various kinds on simulations then reverts them. You can use these objects as context managers, which means you can write code like this:

>>> with f.translate(fshift) :
>>>     print(f['pos'][0])

which is equivalent to

>>> try:
>>>     f['pos']+=shift
>>>     print(f['pos'][0])
>>> finally:
>>>     f['pos']-=shift

You can also chain transformations together, like this:

>>> with f.translate(fshift).rotate_x(45):
>>>    print(f['pos'][0])

This implies a translation followed by a rotation. When reverting the transformation, they are of course undone in the opposite order.

Changed in version 2.0: The transformation system has been changed in version 2.0. While transformations are active they are now applied to newly loaded data. In particular, if a simulation is rotated and then a 3d array is loaded, the array will be rotated to match the simulation. This is a change from previous versions where transformations were only applied to arrays instantaneously in RAM, which could lead to inconsistent behaviour.

As a consequence of this change, the system is also more strict about the order in which transformations are reverted. One cannot revert a transformation when another transformation has been applied after it (and not yet reverted).

Functions

inverse_translate(f, shift)

Deprecated alias for f.translate(-shift)

inverse_v_translate(f, shift)

Deprecated alias for f.offset_velocity(-shift)

inverse_xv_translate(f, x_shift, v_shift)

Deprecated alias for f.translate(-x_shift).offset_velocity(-v_shift)

null(f)

Deprecated alias for NullTransformation(f)

transform(f, matrix)

Deprecated alias for f.rotate(matrix)

translate(f, shift)

Deprecated alias for f.translate(shift)

v_translate(f, shift)

Deprecated alias for f.offset_velocity(shift)

xv_translate(f, x_shift, v_shift)

Deprecated alias for f.translate(x_shift).offset_velocity(v_shift)

Classes

GenericRotation

alias of Rotation

GenericTranslation(f, arname, shift[, ...])

A translation on a specified array of a simulation

NullTransformation(f)

A transformation that does nothing, provided for convenience where a transformation is expected.

Rotation(f, matrix[, ortho_tol, description])

A rotation on all 3d vectors in a simulation, by a given orthogonal 3x3 matrix

Transformable()

A mixin class for objects that can generate a Transformation object

Transformation(f[, description])

The base class for all transformations.

Exceptions

TransformationException

Exception raised when a transformation fails