Skip to content

Commit 962b09a

Browse files
committed
adding stand alone gala files
1 parent 6e8aa7a commit 962b09a

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

student_download/gd1.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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

student_download/reflex.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import astropy.coordinates as coord
2+
3+
__all__ = ["reflex_correct"]
4+
5+
6+
def reflex_correct(coords, galactocentric_frame=None):
7+
"""Correct the input Astropy coordinate object for solar reflex motion.
8+
9+
The input coordinate instance must have distance and radial velocity information.
10+
So, if the radial velocity is not known, fill the radial velocity values with zeros
11+
to reflex-correct the proper motions.
12+
13+
Parameters
14+
----------
15+
coords : `~astropy.coordinates.SkyCoord`
16+
The Astropy coordinate object with position and velocity information.
17+
galactocentric_frame : `~astropy.coordinates.Galactocentric` (optional)
18+
To change properties of the Galactocentric frame, like the height of the
19+
sun above the midplane, or the velocity of the sun in a Galactocentric
20+
intertial frame, set arguments of the
21+
`~astropy.coordinates.Galactocentric` object and pass in to this
22+
function with your coordinates.
23+
24+
Returns
25+
-------
26+
coords : `~astropy.coordinates.SkyCoord`
27+
The coordinates in the same frame as input, but with solar motion
28+
removed.
29+
30+
"""
31+
c = coord.SkyCoord(coords)
32+
33+
# If not specified, use the Astropy default Galactocentric frame
34+
if galactocentric_frame is None:
35+
galactocentric_frame = coord.Galactocentric()
36+
37+
v_sun = galactocentric_frame.galcen_v_sun
38+
39+
observed = c.transform_to(galactocentric_frame)
40+
rep = observed.cartesian.without_differentials()
41+
rep = rep.with_differentials(observed.cartesian.differentials["s"] + v_sun)
42+
fr = galactocentric_frame.realize_frame(rep).transform_to(c.frame)
43+
return coord.SkyCoord(fr)

0 commit comments

Comments
 (0)