Skip to content

Commit

Permalink
Merge pull request #328 from adrn/v21-frame
Browse files Browse the repository at this point in the history
V21 frame
  • Loading branch information
adrn authored Aug 5, 2023
2 parents 5c5e8fc + 6439fcd commit 524ca6a
Show file tree
Hide file tree
Showing 5 changed files with 1,106 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ New Features

- Added the ability to use leapfrog integration within the ``DirectNBody`` integrator.

- Added a new coordinate frame for the Vasiliev+2021 Sagittarius stream coordinate
system, ``SagittariusVasiliev21``.

Bug fixes
---------
Expand Down
90 changes: 89 additions & 1 deletion gala/coordinates/sgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import astropy.units as u
from astropy.coordinates.matrix_utilities import rotation_matrix

__all__ = ["SagittariusLaw10"]
__all__ = ["SagittariusLaw10", "SagittariusVasiliev21"]


class SagittariusLaw10(coord.BaseCoordinateFrame):
Expand Down Expand Up @@ -108,3 +108,91 @@ def sgr_to_galactic():
spherical Galactic.
"""
return galactic_to_sgr().T


# -------------------------------------------------------------------------------------


class SagittariusVasiliev21(coord.BaseCoordinateFrame):
"""
A Heliocentric, right-handed spherical coordinate system defined by the orbit of the
Sagittarius dwarf galaxy, as described in Vasiliev et al. 2021,
https://ui.adsabs.harvard.edu/abs/2021MNRAS.501.2279V/abstract
Parameters
----------
representation : `BaseRepresentation` or None
A representation object or None to have no data (or use the other
keywords).
Lambda : `Angle`, optional, must be keyword
The longitude-like angle corresponding to Sagittarius' orbit.
Beta : `Angle`, optional, must be keyword
The latitude-like angle corresponding to Sagittarius' orbit.
distance : `Quantity`, optional, must be keyword
The Distance for this object along the line-of-sight.
pm_Lambda_cosBeta : :class:`~astropy.units.Quantity`, optional, must be keyword
The proper motion along the stream in ``Lambda`` (including the
``cos(Beta)`` factor) for this object (``pm_Beta`` must also be given).
pm_Beta : :class:`~astropy.units.Quantity`, optional, must be keyword
The proper motion in Declination for this object (``pm_ra_cosdec`` must
also be given).
radial_velocity : :class:`~astropy.units.Quantity`, optional, must be keyword
The radial velocity of this object.
"""

default_representation = coord.SphericalRepresentation
default_differential = coord.SphericalCosLatDifferential

frame_specific_representation_info = {
coord.SphericalRepresentation: [
coord.RepresentationMapping("lon", "Lambda"),
coord.RepresentationMapping("lat", "Beta"),
coord.RepresentationMapping("distance", "distance"),
]
}

_default_wrap_angle = 180 * u.deg

def __init__(self, *args, **kwargs):
wrap = kwargs.pop("wrap_longitude", True)
super().__init__(*args, **kwargs)
if wrap and isinstance(
self._data,
(coord.UnitSphericalRepresentation, coord.SphericalRepresentation),
):
self._data.lon.wrap_angle = self._default_wrap_angle

# TODO: remove this. This is a hack required as of astropy v3.1 in order
# to have the longitude components wrap at the desired angle
def represent_as(self, base, s="base", in_frame_units=False):
r = super().represent_as(base, s=s, in_frame_units=in_frame_units)
if hasattr(r, "lon"):
r.lon.wrap_angle = self._default_wrap_angle
return r

represent_as.__doc__ = coord.BaseCoordinateFrame.represent_as.__doc__


# Galactic to Sgr coordinates
@frame_transform_graph.transform(
coord.StaticMatrixTransform, coord.Galactic, SagittariusVasiliev21
)
def galactic_to_sgr_v21():
"""Compute the transformation from ICRS to Sagittarius coordinates"""
if not hasattr(SagittariusVasiliev21, "_R"):
R = np.diag([1.0, -1.0, -1.0]) @ B @ C @ D
SagittariusVasiliev21._R = R

return SagittariusVasiliev21._R


# Sgr to Galactic coordinates
@frame_transform_graph.transform(
coord.StaticMatrixTransform, SagittariusVasiliev21, coord.Galactic
)
def sgr_to_galactic_v21():
"""Compute the inverse transformation from Sagittarius coordinates to ICRS"""
return galactic_to_sgr_v21().T
Loading

0 comments on commit 524ca6a

Please sign in to comment.