PhaseSpacePosition¶

class gala.dynamics.core.PhaseSpacePosition(pos, vel=None, frame=None)[source]

Bases: object

Represents phase-space positions, i.e. positions and conjugate momenta (velocities).

The class can be instantiated with Astropy representation objects (e.g., CartesianRepresentation), Astropy Quantity objects, or plain Numpy arrays.

If passing in representation objects, the default representation is taken to be the class that is passed in.

If passing in Quantity or Numpy array instances for both position and velocity, they are assumed to be Cartesian. Array inputs are interpreted as dimensionless quantities. The input position and velocity objects can have an arbitrary number of (broadcastable) dimensions. For Quantity or array inputs, the first axis (0) has special meaning:

- axis=0 is the coordinate dimension (e.g., x, y, z for Cartesian)


So if the input position array, pos, has shape pos.shape = (3, 100), this would represent 100 3D positions (pos is x, pos is y, etc.). The same is true for velocity.

Parameters
posBaseRepresentation, Quantity, array_like

Positions. If a numpy array (e.g., has no units), this will be stored as a dimensionless Quantity. See the note above about the assumed meaning of the axes of this object.

velBaseDifferential, Quantity, array_like

Velocities. If a numpy array (e.g., has no units), this will be stored as a dimensionless Quantity. See the note above about the assumed meaning of the axes of this object.

frameFrameBase (optional)

The reference frame of the input phase-space positions.

Attributes Summary

 data pos_components representation_mappings shape This is not the shape of the position or velocity arrays. vel_components

Methods Summary

 Compute the angular momentum for the phase-space positions contained in this object. energy(self, hamiltonian) The total energy per unit mass (e.g., kinetic + potential): Load an object from an HDF5 file. from_w(w[, units]) get_components(self, which) Get the component name dictionary for the desired object. kinetic_energy(self) The kinetic energy per unit mass: plot(self[, components, units, auto_aspect]) Plot the positions in all projections. potential_energy(self, potential) The potential energy per unit mass: represent_as(self, new_pos[, new_vel]) Represent the position and velocity of the orbit in an alternate coordinate system. to_coord_frame(self, frame[, …]) Transform the orbit from Galactocentric, cartesian coordinates to Heliocentric coordinates in the specified Astropy coordinate frame. to_frame(self, frame[, current_frame]) Transform to a new reference frame. to_hdf5(self, f) Serialize this object to an HDF5 file. w(self[, units]) This returns a single array containing the phase-space positions.

Attributes Documentation

data
pos_components
representation_mappings = {<class 'astropy.coordinates.representation.CartesianRepresentation'>: [RepresentationMapping(repr_name='xyz', new_name='xyz', default_unit='recommended')], <class 'astropy.coordinates.representation.SphericalCosLatDifferential'>: [RepresentationMapping(repr_name='d_lon_coslat', new_name='pm_lon_coslat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_lat', new_name='pm_lat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_distance', new_name='radial_velocity', default_unit='recommended')], <class 'astropy.coordinates.representation.SphericalDifferential'>: [RepresentationMapping(repr_name='d_lon', new_name='pm_lon', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_lat', new_name='pm_lat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_distance', new_name='radial_velocity', default_unit='recommended')], <class 'astropy.coordinates.representation.PhysicsSphericalDifferential'>: [RepresentationMapping(repr_name='d_phi', new_name='pm_phi', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_theta', new_name='pm_theta', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_r', new_name='radial_velocity', default_unit='recommended')], <class 'astropy.coordinates.representation.CartesianDifferential'>: [RepresentationMapping(repr_name='d_x', new_name='v_x', default_unit='recommended'), RepresentationMapping(repr_name='d_y', new_name='v_y', default_unit='recommended'), RepresentationMapping(repr_name='d_z', new_name='v_z', default_unit='recommended'), RepresentationMapping(repr_name='d_xyz', new_name='v_xyz', default_unit='recommended')], <class 'astropy.coordinates.representation.CylindricalDifferential'>: [RepresentationMapping(repr_name='d_rho', new_name='v_rho', default_unit='recommended'), RepresentationMapping(repr_name='d_phi', new_name='pm_phi', default_unit='recommended'), RepresentationMapping(repr_name='d_z', new_name='v_z', default_unit='recommended')], <class 'gala.dynamics.representation_nd.NDCartesianRepresentation'>: [RepresentationMapping(repr_name='xyz', new_name='xyz', default_unit='recommended')], <class 'gala.dynamics.representation_nd.NDCartesianDifferential'>: [RepresentationMapping(repr_name='d_xyz', new_name='v_xyz', default_unit='recommended'), RegexRepresentationMapping(repr_name='d_x([0-9])', new_name='v_x{0}', default_unit='recommended')], <class 'astropy.coordinates.representation.UnitSphericalCosLatDifferential'>: [RepresentationMapping(repr_name='d_lon_coslat', new_name='pm_lon_coslat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_lat', new_name='pm_lat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_distance', new_name='radial_velocity', default_unit='recommended')], <class 'astropy.coordinates.representation.UnitSphericalDifferential'>: [RepresentationMapping(repr_name='d_lon', new_name='pm_lon', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_lat', new_name='pm_lat', default_unit=Unit("mas / yr")), RepresentationMapping(repr_name='d_distance', new_name='radial_velocity', default_unit='recommended')]}
shape

This is not the shape of the position or velocity arrays. That is accessed by doing, e.g., obj.x.shape.

vel_components

Methods Documentation

angular_momentum(self)[source]

Compute the angular momentum for the phase-space positions contained in this object:

.. math::


boldsymbol{{L}} = boldsymbol{{q}} times boldsymbol{{p}}

Returns
LQuantity

Array of angular momentum vectors.

Examples

>>> import numpy as np
>>> import astropy.units as u
>>> pos = np.array([1., 0, 0]) * u.au
>>> vel = np.array([0, 2*np.pi, 0]) * u.au/u.yr
>>> w = PhaseSpacePosition(pos, vel)
>>> w.angular_momentum() # doctest: +FLOAT_CMP
<Quantity [0.        ,0.        ,6.28318531] AU2 / yr>

energy(self, hamiltonian)[source]

The total energy per unit mass (e.g., kinetic + potential):

Parameters
hamiltoniangala.potential.Hamiltonian

The Hamiltonian object to evaluate the energy.

Returns
EQuantity

The total energy.

classmethod from_hdf5(f)[source]

Load an object from an HDF5 file.

Requires h5py.

Parameters
fstr, h5py.File

Either the filename or an open HDF5 file.

classmethod from_w(w, units=None, **kwargs)[source]
get_components(self, which)[source]

Get the component name dictionary for the desired object.

The returned dictionary maps component names on this class to component names on the desired object.

Parameters
whichstr

Can either be 'pos' or 'vel' to get the components for the position or velocity object.

kinetic_energy(self)[source]

The kinetic energy per unit mass:

$E_K = \frac{1}{2} \, |\boldsymbol{v}|^2$
Returns
EQuantity

The kinetic energy.

plot(self, components=None, units=None, auto_aspect=True, **kwargs)[source]

Plot the positions in all projections. This is a wrapper around plot_projections for fast access and quick visualization. All extra keyword arguments are passed to that function (the docstring for this function is included here for convenience).

Parameters
componentsiterable (optional)

A list of component names (strings) to plot. By default, this is the Cartesian positions ['x', 'y', 'z']. To plot Cartesian velocities, pass in the velocity component names ['d_x', 'd_y', 'd_z'].

unitsUnitBase, iterable (optional)

A single unit or list of units to display the components in.

auto_aspectbool (optional)

Automatically enforce an equal aspect ratio.

relative_tobool (optional)

Plot the values relative to this value or values.

autolimbool (optional)

Automatically set the plot limits to be something sensible.

axesarray_like (optional)

Array of matplotlib Axes objects.

subplots_kwargsdict (optional)

Dictionary of kwargs passed to subplots().

labelsiterable (optional)

List or iterable of axis labels as strings. They should correspond to the dimensions of the input orbit.

plot_functioncallable (optional)

The matplotlib plot function to use. By default, this is scatter(), but can also be, e.g., plot().

**kwargs

All other keyword arguments are passed to the plot_function. You can pass in any of the usual style kwargs like color=..., marker=..., etc.

Returns
figFigure
potential_energy(self, potential)[source]

The potential energy per unit mass:

$E_\Phi = \Phi(\boldsymbol{q})$
Parameters
potentialgala.potential.PotentialBase

The potential object to compute the energy from.

Returns
EQuantity

The potential energy.

represent_as(self, new_pos, new_vel=None)[source]

Represent the position and velocity of the orbit in an alternate coordinate system. Supports any of the Astropy coordinates representation classes.

Parameters
new_posBaseRepresentation

The type of representation to generate. Must be a class (not an instance), or the string name of the representation class.

new_velBaseDifferential (optional)

Class in which any velocities should be represented. Must be a class (not an instance), or the string name of the differential class. If None, uses the default differential for the new position class.

Returns
new_pspgala.dynamics.PhaseSpacePosition
to_coord_frame(self, frame, galactocentric_frame=None, **kwargs)[source]

Transform the orbit from Galactocentric, cartesian coordinates to Heliocentric coordinates in the specified Astropy coordinate frame.

Parameters
frameBaseCoordinateFrame

The class or frame instance specifying the desired output frame. For example, ICRS.

galactocentric_frameGalactocentric

This is the assumed frame that the position and velocity of this object are in. The Galactocentric instand should have parameters specifying the position and motion of the sun in the Galactocentric frame, but no data.

Returns
cBaseCoordinateFrame

An instantiated coordinate frame containing the positions and velocities from this object transformed to the specified coordinate frame.

to_frame(self, frame, current_frame=None, **kwargs)[source]

Transform to a new reference frame.

Parameters
frameFrameBase

The frame to transform to.

current_framegala.potential.CFrameBase

The current frame the phase-space position is in.

**kwargs

Any additional arguments are passed through to the individual frame transformation functions (see: transformations).

Returns
pspgala.dynamics.CartesianPhaseSpacePosition

The phase-space position in the new reference frame.

to_hdf5(self, f)[source]

Serialize this object to an HDF5 file.

Requires h5py.

Parameters
fstr, h5py.File

Either the filename or an open HDF5 file.

w(self, units=None)[source]

This returns a single array containing the phase-space positions.

Parameters
unitsUnitSystem (optional)

The unit system to represent the position and velocity in before combining into the full array.

Returns
wndarray

A numpy array of all positions and velocities, without units. Will have shape (2*ndim,...).