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
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
|
Deprecated alias for |
Classes
alias of |
|
|
A translation on a specified array of a simulation |
A transformation that does nothing, provided for convenience where a transformation is expected. |
|
|
A rotation on all 3d vectors in a simulation, by a given orthogonal 3x3 matrix |
A mixin class for objects that can generate a Transformation object |
|
|
The base class for all transformations. |
Exceptions
|
Exception raised when a transformation fails |