|
| 1 | +"""Astropy coordinate class for the GD-1 coordinate system""" |
| 2 | + |
| 3 | +import astropy.coordinates as coord |
| 4 | +import astropy.units as u |
| 5 | +import numpy as np |
| 6 | +from astropy.coordinates import frame_transform_graph |
| 7 | + |
| 8 | +__all__ = ["GD1Koposov10"] |
| 9 | + |
| 10 | + |
| 11 | +class GD1Koposov10(coord.BaseCoordinateFrame): |
| 12 | + """ |
| 13 | + A Heliocentric spherical coordinate system defined by the orbit of the GD1 stream, |
| 14 | + as described in Koposov et al. 2010 (see: `<http://arxiv.org/abs/0907.1085>`_). |
| 15 | +
|
| 16 | + For more information about this class, see the Astropy documentation on coordinate |
| 17 | + frames in :mod:`~astropy.coordinates`. |
| 18 | +
|
| 19 | + Parameters |
| 20 | + ---------- |
| 21 | + representation : :class:`~astropy.coordinates.BaseRepresentation` or None |
| 22 | + A representation object or None to have no data (or use the other keywords) |
| 23 | + phi1 : angle_like, optional, must be keyword |
| 24 | + The longitude-like angle corresponding to GD-1's orbit. |
| 25 | + phi2 : angle_like, optional, must be keyword |
| 26 | + The latitude-like angle corresponding to GD-1's orbit. |
| 27 | + distance : :class:`~astropy.units.Quantity`, optional, must be keyword |
| 28 | + The Distance for this object along the line-of-sight. |
| 29 | + pm_phi1_cosphi2 : :class:`~astropy.units.Quantity`, optional, must be keyword |
| 30 | + The proper motion in the longitude-like direction corresponding to |
| 31 | + the GD-1 stream's orbit. |
| 32 | + pm_phi2 : :class:`~astropy.units.Quantity`, optional, must be keyword |
| 33 | + The proper motion in the latitude-like direction perpendicular to the |
| 34 | + GD-1 stream's orbit. |
| 35 | + radial_velocity : :class:`~astropy.units.Quantity`, optional, must be keyword |
| 36 | + The radial velocity for this object along the line-of-sight. |
| 37 | +
|
| 38 | + """ |
| 39 | + |
| 40 | + default_representation = coord.SphericalRepresentation |
| 41 | + default_differential = coord.SphericalCosLatDifferential |
| 42 | + |
| 43 | + frame_specific_representation_info = { |
| 44 | + coord.SphericalRepresentation: [ |
| 45 | + coord.RepresentationMapping("lon", "phi1"), |
| 46 | + coord.RepresentationMapping("lat", "phi2"), |
| 47 | + coord.RepresentationMapping("distance", "distance"), |
| 48 | + ], |
| 49 | + } |
| 50 | + |
| 51 | + _default_wrap_angle = 180 * u.deg |
| 52 | + |
| 53 | + def __init__(self, *args, **kwargs): |
| 54 | + wrap = kwargs.pop("wrap_longitude", True) |
| 55 | + super().__init__(*args, **kwargs) |
| 56 | + if wrap and isinstance( |
| 57 | + self._data, |
| 58 | + coord.UnitSphericalRepresentation | coord.SphericalRepresentation, |
| 59 | + ): |
| 60 | + self._data.lon.wrap_angle = self._default_wrap_angle |
| 61 | + |
| 62 | + # TODO: remove this. This is a hack required as of astropy v3.1 in order |
| 63 | + # to have the longitude components wrap at the desired angle |
| 64 | + def represent_as(self, base, s="base", in_frame_units=False): |
| 65 | + r = super().represent_as(base, s=s, in_frame_units=in_frame_units) |
| 66 | + if hasattr(r, "lon"): |
| 67 | + r.lon.wrap_angle = self._default_wrap_angle |
| 68 | + return r |
| 69 | + |
| 70 | + represent_as.__doc__ = coord.BaseCoordinateFrame.represent_as.__doc__ |
| 71 | + |
| 72 | + |
| 73 | +# Rotation matrix as defined in the Appendix of Koposov et al. (2010) |
| 74 | +R = np.array( |
| 75 | + [ |
| 76 | + [-0.4776303088, -0.1738432154, 0.8611897727], |
| 77 | + [0.510844589, -0.8524449229, 0.111245042], |
| 78 | + [0.7147776536, 0.4930681392, 0.4959603976], |
| 79 | + ] |
| 80 | +) |
| 81 | + |
| 82 | + |
| 83 | +@frame_transform_graph.transform(coord.StaticMatrixTransform, coord.ICRS, GD1Koposov10) |
| 84 | +def icrs_to_gd1(): |
| 85 | + """ |
| 86 | + Compute the transformation from ICRS spherical to heliocentric GD-1 coordinates. |
| 87 | + """ |
| 88 | + return R |
| 89 | + |
| 90 | + |
| 91 | +@frame_transform_graph.transform(coord.StaticMatrixTransform, GD1Koposov10, coord.ICRS) |
| 92 | +def gd1_to_icrs(): |
| 93 | + """ |
| 94 | + Compute the transformation from heliocentric GD-1 coordinates to ICRS spherical. |
| 95 | + """ |
| 96 | + return icrs_to_gd1().T |
0 commit comments