Coordinate transformation¶
-
class
arepy.coord.
transf
(show=False, **opt)¶ Coordinate transformations
- Parameters
show (bool) – Print out transformation information
region (
arepy.coord.regionBox
orarepy.coord.regionSphere
orarepy.coord.regionCone
) – Coordinate regionorigin ([float]*3) – New coordinate origin
align ([float]*3) – Vector of a new z-axis
flip ([int]) – New order of the axis
rotate ([float]) – Euler rotation angles
There is a standard sequence of transformations that can be used during the initialization of this class:
select - Select an initial spherical region from coordinates
translate - Set a new origin of the selected coordinates (e.g. center of the sphere)
align - Align the z-axis with some given vector (e.g. angular momentum)
flip - Flip axes (e.g. exchange y and z axes)
rotate - Add some additional rotation to the region
crop - Select a final region shape (e.g. box)
A simple initialization will look like:
import arepy as apy import numpy as np transf = apy.coord.transf( region = apy.coord.regionBox([0.2,0.8,0.2,0.8,0.2,0.8]), origin = [0.5,0.5,0.5], align = [0.3,0.5,0.0], flip = [0,2,1], rotate = [0,0,np.pi/5], )
However, it is always possible to set an arbitrary list of transformations:
transf = apy.coord.transf() transf.addSelection('sphere', apy.coord.regionSphere([0.2,0.8,0.2],0.8) ) transf.addTranslation('shift', [0.2,0.8,0.2])
-
convert
(name, coord, **opt)¶ Perform selected transformations
- Parameters
name (str or list[str]) – Name or names of the transformations
coord (list[[float]*len(dims)]) – List of coordinates/vectors
dims (list[int]) – Dimensions of the vectors (default is [0,1,2])
- Returns
Transformed coordinates
Initialized transformations can be applied on the set of coordinates:
coord = np.random.rand(20,3) coord = transf.convert(['select','flip','crop'], coord)
It is also possible to convert vectors with an arbitrary set of dimensions. In the following case we are transforming the limits of a box region, where the vector dimensions are [x,x,y,y,z,z]:
limits = [0.2,0.8,0.2,0.8,0.2,0.8] limits = transf.convert(['select','flip','crop'], limits, dim=[0,0,1,1,2,2])
-
select
(name, data)¶ Select data corresponding to the coordinate region
- Parameters
name (str) – Name of the region transformation
data – Data with the same length as the initial array with the coordinates
- Returns
Data selected for the particles within the region
This function is used in the case when we have an additional dataset that corresponds to the coordinates (e.g. masses of the particles) and we want to additionally select its corresponding values:
coord = np.random.rand(20,3) masses = np.random.rand(20) coord = transf.convert(['select','flip','crop'], coord) masses = transf.select('crop',masses)
-
addSelection
(name, **opt)¶ Add selection
- Parameters
name (str) – Name of the transformation
region (
arepy.coord.regionBox
orarepy.coord.regionSphere
orarepy.coord.regionCone
) – Coordinate region
-
addTranslation
(name, origin)¶ Add a translation
- Parameters
name (str) – Name of the transformation
origin ([float]*3) – Coordinates of the new origin
-
addAlignment
(name, vector)¶ Add an alignment
- Parameters
name (str) – Name of the transformation
vector ([float]*3) – Vector of a new z-axis
-
addRotation
(name, angles)¶ Add a rotation
- Parameters
name (str) – Name of the transformation
angles ([float]) – Euler rotation angles
-
addFlip
(name, axes)¶ Flip axes
- Parameters
name (str) – Name of the transformation
axes ([int]*3) – New order of the axes
-
show
()¶ Print out all transformation into the command line