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.

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[, defer, description])

The base class for all transformations.