NDCartesianRepresentation¶

class
gala.dynamics.
NDCartesianRepresentation
(x, differentials=None, unit=None, copy=True)[source]¶ Bases:
gala.dynamics.representation_nd.NDMixin
,astropy.coordinates.CartesianRepresentation
Representation of points in ND cartesian coordinates.
 Parameters
 x
Quantity
or array The Cartesian coordinates of the point(s). If not quantity,
unit
should be set. differentialsdict,
NDCartesianDifferential
(optional) Any differential classes that should be associated with this representation.
 unit
Unit
or str If given, the coordinates will be converted to this unit (or taken to be in this unit if not given.
 copybool, optional
If
True
(default), arrays will be copied rather than referenced.
 x
Attributes Summary
Return an instance with the data transposed.
A tuple with the inorder names of the coordinate components.
A dictionary of differential class instances.
The number of dimensions of the instance and underlying arrays.
Deprecated since version 3.0.
The shape of the instance and underlying arrays.
The size of the object, as calculated from its shape.
The ‘x’ component of the points(s).
Return a vector array of the x, y, and z coordinates.
The ‘y’ component of the points(s).
The ‘z’ component of the points(s).
Methods Summary
copy
(self, \*args, \*\*kwargs)Return an instance containing copies of the internal data.
cross
(self, other)Cross product of two representations.
diagonal
(self, \*args, \*\*kwargs)Return an instance with the specified diagonals.
dot
(self, other)Dot product of two representations.
flatten
(self, \*args, \*\*kwargs)Return a copy with the array collapsed into one dimension.
from_cartesian
(other)Create a representation of this class from a supplied Cartesian one.
from_representation
(representation)Create a new instance of this representation from another one.
get_name
()Name of the representation or differential.
get_xyz
(self[, xyz_axis])Return a vector array of the x, y, and z coordinates.
mean
(self, \*args, \*\*kwargs)Vector mean.
norm
(self)Vector norm.
ravel
(self, \*args, \*\*kwargs)Return an instance with the array collapsed into one dimension.
represent_as
(self, other_class[, …])Convert coordinates to another representation.
reshape
(self, \*args, \*\*kwargs)Returns an instance containing the same data with a new shape.
scale_factors
(self)Scale factors for each component’s direction.
squeeze
(self, \*args, \*\*kwargs)Return an instance with singledimensional shape entries removed
sum
(self, \*args, \*\*kwargs)Vector sum.
swapaxes
(self, \*args, \*\*kwargs)Return an instance with the given axes interchanged.
take
(self, indices[, axis, mode])Return a new instance formed from the elements at the given indices.
to_cartesian
(self)Convert the representation to its Cartesian form.
transform
(self, matrix)Transform the cartesian coordinates using a 3x3 matrix.
transpose
(self, \*args, \*\*kwargs)Return an instance with the data transposed.
unit_vectors
(self)Cartesian unit vectors in the direction of each component.
with_differentials
(self, differentials)Create a new representation with the same positions as this representation, but with these new differentials.
without_differentials
(self)Return a copy of the representation without attached differentials.
Attributes Documentation

T
¶ Return an instance with the data transposed.
Parameters are as for
T
. All internal data are views of the data of the original.

attr_classes
= {}¶

components
¶ A tuple with the inorder names of the coordinate components.

differentials
¶ A dictionary of differential class instances.
The keys of this dictionary must be a string representation of the SI unit with which the differential (derivative) is taken. For example, for a velocity differential on a positional representation, the key would be
's'
for seconds, indicating that the derivative is a time derivative.

isscalar
¶

ndim
¶ The number of dimensions of the instance and underlying arrays.

recommended_units
¶ Deprecated since version 3.0: The recommended_units attribute is deprecated and may be removed in a future version.

shape
¶ The shape of the instance and underlying arrays.
Like
shape
, can be set to a new shape by assigning a tuple. Note that if different instances share some but not all underlying data, setting the shape of one instance can make the other instance unusable. Hence, it is strongly recommended to get new, reshaped instances with thereshape
method. Raises
 AttributeError
If the shape of any of the components cannot be changed without the arrays being copied. For these cases, use the
reshape
method (which copies any arrays that cannot be reshaped inplace).

size
¶ The size of the object, as calculated from its shape.

x
¶ The ‘x’ component of the points(s).

xyz
¶ Return a vector array of the x, y, and z coordinates.
 Parameters
 xyz_axisint, optional
The axis in the final array along which the x, y, z components should be stored (default: 0).
 Returns
 xs
Quantity
With dimension 3 along
xyz_axis
.
 xs

y
¶ The ‘y’ component of the points(s).

z
¶ The ‘z’ component of the points(s).
Methods Documentation

copy
(self, *args, **kwargs)¶ Return an instance containing copies of the internal data.
Parameters are as for
copy()
.

cross
(self, other)¶ Cross product of two representations.
 Parameters
 otherrepresentation
If not already cartesian, it is converted.
 Returns
 cross_product
CartesianRepresentation
With vectors perpendicular to both
self
andother
.
 cross_product

diagonal
(self, *args, **kwargs)¶ Return an instance with the specified diagonals.
Parameters are as for
diagonal()
. All internal data are views of the data of the original.

dot
(self, other)¶ Dot product of two representations.
Note that any associated differentials will be dropped during this operation.
 Parameters
 otherrepresentation
If not already cartesian, it is converted.
 Returns
 dot_product
Quantity
The sum of the product of the x, y, and z components of
self
andother
.
 dot_product

flatten
(self, *args, **kwargs)¶ Return a copy with the array collapsed into one dimension.
Parameters are as for
flatten()
.

classmethod
from_cartesian
(other)¶ Create a representation of this class from a supplied Cartesian one.
 Parameters
 other
CartesianRepresentation
The representation to turn into this class
 other
 Returns
 representationobject of this class
A new representation of this class’s type.

classmethod
from_representation
(representation)¶ Create a new instance of this representation from another one.
 Parameters
 representation
BaseRepresentation
instance The presentation that should be converted to this class.
 representation

classmethod
get_name
()¶ Name of the representation or differential.
In lower case, with any trailing ‘representation’ or ‘differential’ removed. (E.g., ‘spherical’ for
SphericalRepresentation
orSphericalDifferential
.)

get_xyz
(self, xyz_axis=0)[source]¶ Return a vector array of the x, y, and z coordinates.
 Parameters
 xyz_axisint, optional
The axis in the final array along which the x, y, z components should be stored (default: 0).
 Returns
 xs
Quantity
With dimension 3 along
xyz_axis
.
 xs

mean
(self, *args, **kwargs)¶ Vector mean.
Returns a new CartesianRepresentation instance with the means of the x, y, and z components.
Refer to
mean
for full documentation of the arguments, noting thataxis
is the entry in theshape
of the representation, and that theout
argument cannot be used.

norm
(self)¶ Vector norm.
The norm is the standard Frobenius norm, i.e., the square root of the sum of the squares of all components with nonangular units.
Note that any associated differentials will be dropped during this operation.
 Returns
 norm
astropy.units.Quantity
Vector norm, with the same shape as the representation.
 norm

ravel
(self, *args, **kwargs)¶ Return an instance with the array collapsed into one dimension.
Parameters are as for
ravel()
. Note that it is not always possible to unravel an array without copying the data. If you want an error to be raise if the data is copied, you should should assign shape(1,)
to the shape attribute.

represent_as
(self, other_class, differential_class=None)¶ Convert coordinates to another representation.
If the instance is of the requested class, it is returned unmodified. By default, conversion is done via cartesian coordinates.
 Parameters
 other_class
BaseRepresentation
subclass The type of representation to turn the coordinates into.
 differential_classdict of
BaseDifferential
, optional Classes in which the differentials should be represented. Can be a single class if only a single differential is attached, otherwise it should be a
dict
keyed by the same keys as the differentials.
 other_class

reshape
(self, *args, **kwargs)¶ Returns an instance containing the same data with a new shape.
Parameters are as for
reshape()
. Note that it is not always possible to change the shape of an array without copying the data (seereshape()
documentation). If you want an error to be raise if the data is copied, you should assign the new shape to the shape attribute (note: this may not be implemented for all classes usingShapedLikeNDArray
).

scale_factors
(self)¶ Scale factors for each component’s direction.
Given unit vectors \(\hat{e}_c\) and scale factors \(f_c\), a change in one component of \(\delta c\) corresponds to a change in representation of \(\delta c \times f_c \times \hat{e}_c\).
 Returns
 scale_factorsdict of
Quantity
The keys are the component names.
 scale_factorsdict of

squeeze
(self, *args, **kwargs)¶ Return an instance with singledimensional shape entries removed
Parameters are as for
squeeze()
. All internal data are views of the data of the original.

sum
(self, *args, **kwargs)¶ Vector sum.
Returns a new CartesianRepresentation instance with the sums of the x, y, and z components.
Refer to
sum
for full documentation of the arguments, noting thataxis
is the entry in theshape
of the representation, and that theout
argument cannot be used.

swapaxes
(self, *args, **kwargs)¶ Return an instance with the given axes interchanged.
Parameters are as for
swapaxes()
:axis1, axis2
. All internal data are views of the data of the original.

take
(self, indices, axis=None, mode='raise')¶ Return a new instance formed from the elements at the given indices.
Parameters are as for
take()
, except that, obviously, no output array can be given.

to_cartesian
(self)¶ Convert the representation to its Cartesian form.
Note that any differentials get dropped.
 Returns
 cartrepr
CartesianRepresentation
The representation in Cartesian form.
 cartrepr

transform
(self, matrix)¶ Transform the cartesian coordinates using a 3x3 matrix.
This returns a new representation and does not modify the original one. Any differentials attached to this representation will also be transformed.
 Parameters
 matrix
ndarray
A 3x3 transformation matrix, such as a rotation matrix.
 matrix
Examples
We can start off by creating a cartesian representation object:
>>> from astropy import units as u >>> from astropy.coordinates import CartesianRepresentation >>> rep = CartesianRepresentation([1, 2] * u.pc, ... [2, 3] * u.pc, ... [3, 4] * u.pc)
We now create a rotation matrix around the z axis:
>>> from astropy.coordinates.matrix_utilities import rotation_matrix >>> rotation = rotation_matrix(30 * u.deg, axis='z')
Finally, we can apply this transformation:
>>> rep_new = rep.transform(rotation) >>> rep_new.xyz # doctest: +FLOAT_CMP <Quantity [[ 1.8660254 , 3.23205081], [ 1.23205081, 1.59807621], [ 3. , 4. ]] pc>

transpose
(self, *args, **kwargs)¶ Return an instance with the data transposed.
Parameters are as for
transpose()
. All internal data are views of the data of the original.

unit_vectors
(self)¶ Cartesian unit vectors in the direction of each component.
Given unit vectors \(\hat{e}_c\) and scale factors \(f_c\), a change in one component of \(\delta c\) corresponds to a change in representation of \(\delta c \times f_c \times \hat{e}_c\).
 Returns
 unit_vectorsdict of
CartesianRepresentation
The keys are the component names.
 unit_vectorsdict of

with_differentials
(self, differentials)¶ Create a new representation with the same positions as this representation, but with these new differentials.
Differential keys that already exist in this object’s differential dict are overwritten.
 Parameters
 differentialsSequence of
BaseDifferential
The differentials for the new representation to have.
 differentialsSequence of
 Returns
 newrepr
A copy of this representation, but with the
differentials
as its differentials.

without_differentials
(self)¶ Return a copy of the representation without attached differentials.
 Returns
 newrepr
A shallow copy of this representation, without any differentials. If no differentials were present, no copy is made.