A new coordinate class (for the Sagittarius stream

import numpy as np
import matplotlib.pyplot as plt
from astropy.visualization import astropy_mpl_style
plt.style.use(astropy_mpl_style)
In [2]:
from astropy.coordinates import frame_transform_graph
from astropy.coordinates.matrix_utilities import rotation_matrix, matrix_product, matrix_transpose
import astropy.coordinates as coord
import astropy.units as u
In [3]:
class Sagittarius(coord.BaseCoordinateFrame):
    """
    A Heliocentric spherical coordinate system defined by the orbit
    of the Sagittarius dwarf galaxy, as described in
        https://ui.adsabs.harvard.edu/abs/2003ApJ...599.1082M
    and further explained in
        https://www.stsci.edu/~dlaw/Sgr/.

    Parameters
    ----------
    representation : `~astropy.coordinates.BaseRepresentation` or None
        A representation object or None to have no data (or use the other keywords)
    Lambda : `~astropy.coordinates.Angle`, optional, must be keyword
        The longitude-like angle corresponding to Sagittarius' orbit.
    Beta : `~astropy.coordinates.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')]
    }
In [4]:
SGR_PHI = (180 + 3.75) * u.degree # Euler angles (from Law & Majewski 2010)
SGR_THETA = (90 - 13.46) * u.degree
SGR_PSI = (180 + 14.111534) * u.degree

# Generate the rotation matrix using the x-convention (see Goldstein)
D = rotation_matrix(SGR_PHI, "z")
C = rotation_matrix(SGR_THETA, "x")
B = rotation_matrix(SGR_PSI, "z")
A = np.diag([1.,1.,-1.])
SGR_MATRIX = matrix_product(A, B, C, D)
In [5]:
@frame_transform_graph.transform(coord.StaticMatrixTransform, coord.Galactic, Sagittarius)
def galactic_to_sgr():
    """ Compute the transformation matrix from Galactic spherical to
        heliocentric Sgr coordinates.
    """
    return SGR_MATRIX
In [6]:
@frame_transform_graph.transform(coord.StaticMatrixTransform, Sagittarius, coord.Galactic)
def sgr_to_galactic():
    """ Compute the transformation matrix from heliocentric Sgr coordinates to
        spherical Galactic.
    """
    return matrix_transpose(SGR_MATRIX)
In [7]:
icrs = coord.SkyCoord(280.161732*u.degree, 11.91934*u.degree, frame='icrs')
sgr = icrs.transform_to(Sagittarius)
print(sgr)
<SkyCoord (Sagittarius): (Lambda, Beta) in deg
    (346.81830652, -39.28360407)>
In [8]:
sgr = coord.SkyCoord(Lambda=np.linspace(0, 2*np.pi, 128)*u.radian,
                     Beta=np.zeros(128)*u.radian, frame='sagittarius')
icrs = sgr.transform_to(coord.ICRS)
print(icrs)
<SkyCoord (ICRS): (ra, dec) in deg
    [(284.03876751, -29.00408353), (287.24685769, -29.44848352),
     (290.48068369, -29.81535572), (293.7357366 , -30.1029631 ),
     (297.00711066, -30.30991693), (300.28958688, -30.43520293),
     (303.57772919, -30.47820084), (306.86598944, -30.43869669),
     (310.14881715, -30.31688708), (313.42076929, -30.11337526),
     (316.67661568, -29.82915917), (319.91143548, -29.46561215),
     (323.12070147, -29.02445708), (326.30034928, -28.50773532),
     (329.44683007, -27.9177717 ), (332.55714589, -27.257137  ),
     (335.62886847, -26.52860943), (338.66014233, -25.73513624),
     (341.64967439, -24.87979679), (344.59671212, -23.96576781),
     (347.50101283, -22.99629167), (350.36280652, -21.97464811),
     (353.18275454, -20.90412969), (355.96190618, -19.78802107),
     (358.70165491, -18.62958199), (  1.40369557, -17.43203397),
     (  4.06998374, -16.19855028), (  6.70269788, -14.93224899),
     (  9.30420479, -13.63618882), ( 11.87702861, -12.31336727),
     ( 14.42382347, -10.96672102), ( 16.94734952,  -9.59912794),
     ( 19.45045241,  -8.21341071), ( 21.93604568,  -6.81234162),
     ( 24.40709589,  -5.39864845), ( 26.86661004,  -3.97502106),
     ( 29.31762493,  -2.54411871), ( 31.76319801,  -1.10857781),
     ( 34.20639942,   0.32898001), ( 36.65030466,   1.76593955),
     ( 39.09798768,   3.19968374), ( 41.55251374,   4.6275852 ),
     ( 44.01693189,   6.04699804), ( 46.49426651,   7.45524993),
     ( 48.98750752,   8.84963453), ( 51.4995989 ,  10.22740448),
     ( 54.03342512,  11.58576509), ( 56.59179508,  12.92186896),
     ( 59.17742314,  14.23281165), ( 61.79290712,  15.51562883),
     ( 64.44070278,  16.76729487), ( 67.12309478,  17.98472356),
     ( 69.84216409,  19.16477088), ( 72.59975183,  20.30424045),
     ( 75.39742013,  21.3998918 ), ( 78.23641033,  22.44845192),
     ( 81.11759966,  23.44663022), ( 84.04145735,  24.39113719),
     ( 87.00800203,  25.27870692), ( 90.01676196,  26.10612335),
     ( 93.06674057,  26.87025019), ( 96.15638947,  27.56806406),
     ( 99.28359159,  28.19669038), (102.44565666,  28.75344107),
     (105.63933131,  29.23585315), (108.86082534,  29.64172698),
     (112.105855  ,  29.96916281), (115.36970341,  30.21659414),
     (118.64729687,  30.38281659), (121.93329519,  30.46701088),
     (125.22219273,  30.46875885), (128.50842634,  30.38805179),
     (131.78648572,  30.22529063), (135.05102157,  29.98127794),
     (138.29694697,  29.6572022 ), (141.51952827,  29.2546151 ),
     (144.71446203,  28.77540295), (147.87793614,  28.22175338),
     (151.00667382,  27.59611901), (154.09796066,  26.90117914),
     (157.14965528,  26.13980125), (160.16018547,  25.31500315),
     (163.12853176,  24.42991703), (166.05420084,  23.48775622),
     (168.93719133,  22.49178507), (171.77795423,  21.44529257),
     (174.57735037,  20.35156967), (177.33660656,  19.21389046),
     (180.05727218,  18.03549704), (182.74117737,  16.81958784),
     (185.39039367,  15.56930924), (188.00719783,  14.28774998),
     (190.59403895,  12.97793826), (193.15350938,  11.64284103),
     (195.68831902,  10.28536518), (198.20127316,   8.90836046),
     (200.69525342,   7.51462369), (203.17320154,   6.10690412),
     (205.63810576,   4.6879097 ), (208.09298919,   3.26031403),
     (210.54090002,   1.82676397), (212.984903  ,   0.38988751),
     (215.42807182,  -1.04769799), (217.87348209,  -2.48337744),
     (220.32420429,  -3.91452965), (222.7832966 ,  -5.338519  ),
     (225.25379684,  -6.75268736), (227.73871349,  -8.15434631),
     (230.24101506,  -9.54076983), (232.76361762, -10.90918763),
     (235.30937003, -12.25677927), (237.88103647, -13.58066929),
     (240.48127601, -14.87792359), (243.11261883, -16.14554723),
     (245.777439  , -17.38048408), (248.47792364, -18.57961852),
     (251.2160385 , -19.7397795 ), (253.9934903 , -20.85774736),
     (256.81168612, -21.93026371), (259.67169071, -22.95404466),
     (262.57418275, -23.92579758), (265.51941137, -24.84224172),
     (268.50715471, -25.70013256), (271.53668252, -26.49628998),
     (274.6067251 , -27.22762983), (277.71545113, -27.89119849),
     (280.86045662, -28.48420985), (284.03876751, -29.00408353)]>
In [9]:
fig, axes = plt.subplots(2, 1, figsize=(8, 10),
                         subplot_kw={'projection': 'aitoff'})

axes[0].set_title("Sagittarius")
axes[0].plot(sgr.Lambda.wrap_at(180*u.deg).radian, sgr.Beta.radian,
             linestyle='none', marker='.')

axes[1].set_title("ICRS")
axes[1].plot(icrs.ra.wrap_at(180*u.deg).radian, icrs.dec.radian,
             linestyle='none', marker='.')

plt.show()
In [10]:
sgr = coord.SkyCoord(Lambda=np.linspace(0, 2*np.pi, 128)*u.radian,
                     Beta=np.zeros(128)*u.radian,
                     pm_Lambda_cosBeta=np.random.uniform(-5, 5, 128)*u.mas/u.yr,
                     pm_Beta=np.zeros(128)*u.mas/u.yr,
                     frame='sagittarius')
icrs = sgr.transform_to(coord.ICRS)
print(icrs)

fig, axes = plt.subplots(3, 1, figsize=(8, 10), sharex=True)

axes[0].set_title("Sagittarius")
axes[0].plot(sgr.Lambda.degree,
             sgr.pm_Lambda_cosBeta.value,
             linestyle='none', marker='.')
axes[0].set_xlabel(r"$\Lambda$ [deg]")
axes[0].set_ylabel(r"$\mu_\Lambda \, \cos B$ [{0}]"
                   .format(sgr.pm_Lambda_cosBeta.unit.to_string('latex_inline')))

axes[1].set_title("ICRS")
axes[1].plot(icrs.ra.degree, icrs.pm_ra_cosdec.value,
             linestyle='none', marker='.')
axes[1].set_ylabel(r"$\mu_\alpha \, \cos\delta$ [{0}]"
                   .format(icrs.pm_ra_cosdec.unit.to_string('latex_inline')))

axes[2].set_title("ICRS")
axes[2].plot(icrs.ra.degree, icrs.pm_dec.value,
             linestyle='none', marker='.')
axes[2].set_xlabel("RA [deg]")
axes[2].set_ylabel(r"$\mu_\delta$ [{0}]"
                   .format(icrs.pm_dec.unit.to_string('latex_inline')))

plt.show()
<SkyCoord (ICRS): (ra, dec) in deg
    [(284.03876751, -29.00408353), (287.24685769, -29.44848352),
     (290.48068369, -29.81535572), (293.7357366 , -30.1029631 ),
     (297.00711066, -30.30991693), (300.28958688, -30.43520293),
     (303.57772919, -30.47820084), (306.86598944, -30.43869669),
     (310.14881715, -30.31688708), (313.42076929, -30.11337526),
     (316.67661568, -29.82915917), (319.91143548, -29.46561215),
     (323.12070147, -29.02445708), (326.30034928, -28.50773532),
     (329.44683007, -27.9177717 ), (332.55714589, -27.257137  ),
     (335.62886847, -26.52860943), (338.66014233, -25.73513624),
     (341.64967439, -24.87979679), (344.59671212, -23.96576781),
     (347.50101283, -22.99629167), (350.36280652, -21.97464811),
     (353.18275454, -20.90412969), (355.96190618, -19.78802107),
     (358.70165491, -18.62958199), (  1.40369557, -17.43203397),
     (  4.06998374, -16.19855028), (  6.70269788, -14.93224899),
     (  9.30420479, -13.63618882), ( 11.87702861, -12.31336727),
     ( 14.42382347, -10.96672102), ( 16.94734952,  -9.59912794),
     ( 19.45045241,  -8.21341071), ( 21.93604568,  -6.81234162),
     ( 24.40709589,  -5.39864845), ( 26.86661004,  -3.97502106),
     ( 29.31762493,  -2.54411871), ( 31.76319801,  -1.10857781),
     ( 34.20639942,   0.32898001), ( 36.65030466,   1.76593955),
     ( 39.09798768,   3.19968374), ( 41.55251374,   4.6275852 ),
     ( 44.01693189,   6.04699804), ( 46.49426651,   7.45524993),
     ( 48.98750752,   8.84963453), ( 51.4995989 ,  10.22740448),
     ( 54.03342512,  11.58576509), ( 56.59179508,  12.92186896),
     ( 59.17742314,  14.23281165), ( 61.79290712,  15.51562883),
     ( 64.44070278,  16.76729487), ( 67.12309478,  17.98472356),
     ( 69.84216409,  19.16477088), ( 72.59975183,  20.30424045),
     ( 75.39742013,  21.3998918 ), ( 78.23641033,  22.44845192),
     ( 81.11759966,  23.44663022), ( 84.04145735,  24.39113719),
     ( 87.00800203,  25.27870692), ( 90.01676196,  26.10612335),
     ( 93.06674057,  26.87025019), ( 96.15638947,  27.56806406),
     ( 99.28359159,  28.19669038), (102.44565666,  28.75344107),
     (105.63933131,  29.23585315), (108.86082534,  29.64172698),
     (112.105855  ,  29.96916281), (115.36970341,  30.21659414),
     (118.64729687,  30.38281659), (121.93329519,  30.46701088),
     (125.22219273,  30.46875885), (128.50842634,  30.38805179),
     (131.78648572,  30.22529063), (135.05102157,  29.98127794),
     (138.29694697,  29.6572022 ), (141.51952827,  29.2546151 ),
     (144.71446203,  28.77540295), (147.87793614,  28.22175338),
     (151.00667382,  27.59611901), (154.09796066,  26.90117914),
     (157.14965528,  26.13980125), (160.16018547,  25.31500315),
     (163.12853176,  24.42991703), (166.05420084,  23.48775622),
     (168.93719133,  22.49178507), (171.77795423,  21.44529257),
     (174.57735037,  20.35156967), (177.33660656,  19.21389046),
     (180.05727218,  18.03549704), (182.74117737,  16.81958784),
     (185.39039367,  15.56930924), (188.00719783,  14.28774998),
     (190.59403895,  12.97793826), (193.15350938,  11.64284103),
     (195.68831902,  10.28536518), (198.20127316,   8.90836046),
     (200.69525342,   7.51462369), (203.17320154,   6.10690412),
     (205.63810576,   4.6879097 ), (208.09298919,   3.26031403),
     (210.54090002,   1.82676397), (212.984903  ,   0.38988751),
     (215.42807182,  -1.04769799), (217.87348209,  -2.48337744),
     (220.32420429,  -3.91452965), (222.7832966 ,  -5.338519  ),
     (225.25379684,  -6.75268736), (227.73871349,  -8.15434631),
     (230.24101506,  -9.54076983), (232.76361762, -10.90918763),
     (235.30937003, -12.25677927), (237.88103647, -13.58066929),
     (240.48127601, -14.87792359), (243.11261883, -16.14554723),
     (245.777439  , -17.38048408), (248.47792364, -18.57961852),
     (251.2160385 , -19.7397795 ), (253.9934903 , -20.85774736),
     (256.81168612, -21.93026371), (259.67169071, -22.95404466),
     (262.57418275, -23.92579758), (265.51941137, -24.84224172),
     (268.50715471, -25.70013256), (271.53668252, -26.49628998),
     (274.6067251 , -27.22762983), (277.71545113, -27.89119849),
     (280.86045662, -28.48420985), (284.03876751, -29.00408353)]
 (pm_ra_cosdec, pm_dec) in mas / yr
    [( 0.03744352, -6.46789916e-03), ( 4.60082227, -6.65751978e-01),
     ( 0.91325149, -1.06223994e-01), ( 4.90446748, -4.29830811e-01),
     ( 0.88912178, -5.22383938e-02), ( 2.28272206, -6.78451308e-02),
     (-3.27794997,  2.02175058e-03), (-2.94630304, -8.39375700e-02),
     (-0.49400179, -2.84175949e-02), ( 2.00591314,  1.73352388e-01),
     (-4.90986296, -5.65147796e-01), ( 1.53064201,  2.19657581e-01),
     ( 1.05276641,  1.80610368e-01), ( 1.67858523,  3.34355864e-01),
     ( 2.15520013,  4.87792600e-01), ( 1.33050984,  3.36516205e-01),
     ( 0.31193305,  8.69961616e-02), (-2.33353052, -7.09818314e-01),
     (-1.77593595, -5.83796686e-01), (-0.97329095, -3.43051794e-01),
     (-4.625925  , -1.73630807e+00), ( 1.84507947,  7.33052726e-01),
     (-0.83654457, -3.49916320e-01), (-4.53465092, -1.98731250e+00),
     (-3.50275017, -1.60124921e+00), (-1.50118372, -7.12930254e-01),
     (-0.10992385, -5.40299183e-02), ( 2.64879985,  1.34275035e+00),
     (-1.65712646, -8.63518252e-01), (-0.68819912, -3.67487652e-01),
     (-1.64193691, -8.95788983e-01), (-2.93134545, -1.62929261e+00),
     ( 0.78245725,  4.41858327e-01), (-1.81785046, -1.04019730e+00),
     (-3.10610363, -1.79631958e+00), (-4.05169833, -2.36218264e+00),
     (-1.03908509, -6.09189603e-01), (-0.21388869, -1.25788962e-01),
     ( 2.48858711,  1.46452201e+00), (-0.49000014, -2.87848534e-01),
     (-3.05862351, -1.78916842e+00), (-1.32330321, -7.68892194e-01),
     ( 0.92537596,  5.32738522e-01), ( 2.09385884,  1.19130139e+00),
     (-0.30045718, -1.68498949e-01), ( 4.22052743,  2.32675337e+00),
     ( 0.56345427,  3.04508310e-01), (-0.32567273, -1.72035181e-01),
     (-4.15685783, -2.13981394e+00), (-0.88375709, -4.41904213e-01),
     (-0.22468359, -1.08761967e-01), ( 2.74310848,  1.28081463e+00),
     (-1.72264487, -7.72833387e-01), (-3.17619214, -1.36336453e+00),
     (-3.66956187, -1.50014500e+00), ( 2.39289499,  9.26935529e-01),
     ( 2.96983043,  1.08394122e+00), ( 1.0512775 ,  3.59227128e-01),
     ( 4.02840887,  1.27938335e+00), ( 1.61726506,  4.73370175e-01),
     ( 4.61765171,  1.23332577e+00), (-4.79570747, -1.15493684e+00),
     ( 4.23009633,  9.05137750e-01), ( 2.60817695,  4.86687184e-01),
     (-4.52215238, -7.17976353e-01), ( 1.98946286,  2.59721166e-01),
     ( 2.03927001,  2.08023032e-01), (-0.84587693, -6.19343770e-02),
     (-3.84917667, -1.70328047e-01), ( 2.45973381,  3.73230292e-02),
     (-0.23922514,  3.33490289e-03), (-2.05716287,  8.84998952e-02),
     ( 4.46015944, -3.21109236e-01), (-3.49523021,  3.52296410e-01),
     (-3.93178521,  5.08557878e-01), ( 0.61318216, -9.66255890e-02),
     ( 4.23411579, -7.85132993e-01), ( 3.30389838, -7.03155759e-01),
     (-1.06901987,  2.56245277e-01), ( 2.82079173, -7.50301260e-01),
     ( 2.48582247, -7.24933297e-01), ( 2.44866821, -7.75128422e-01),
     ( 0.08151762, -2.77730741e-02), ( 3.67975858, -1.33948999e+00),
     (-0.58918881,  2.27686357e-01), ( 3.03272015, -1.23710532e+00),
     (-3.23594468,  1.38627908e+00), ( 4.41486903, -1.97712178e+00),
     (-0.10238803,  4.77301207e-02), (-0.400146  ,  1.93416407e-01),
     ( 2.35828167, -1.17767251e+00), ( 2.91710023, -1.49987988e+00),
     ( 0.95232152, -5.02540601e-01), ( 3.85063454, -2.07911800e+00),
     ( 2.41127994, -1.32828110e+00), ( 0.85817714, -4.80950912e-01),
     (-4.13694847,  2.35240701e+00), ( 1.85428559, -1.06703397e+00),
     (-1.21878571,  7.07922644e-01), ( 1.52710324, -8.93083063e-01),
     ( 4.16412845, -2.44588241e+00), ( 0.54576408, -3.21171309e-01),
     ( 4.23137967, -2.48868824e+00), ( 2.82052249, -1.65390266e+00),
     (-2.37275991,  1.38374091e+00), (-1.35279847,  7.82657246e-01),
     (-2.90013191,  1.66032559e+00), ( 0.87913446, -4.96756886e-01),
     (-3.97491343,  2.21093294e+00), ( 3.88601589, -2.12188095e+00),
     (-3.19605681,  1.70829861e+00), (-4.22022769,  2.20154918e+00),
     (-0.67855168,  3.44401202e-01), ( 1.08022646, -5.31686097e-01),
     ( 2.89186843, -1.37548711e+00), ( 0.71149479, -3.25805182e-01),
     (-3.17201697,  1.39274624e+00), ( 2.11526592, -8.86623349e-01),
     ( 1.14146126, -4.54541992e-01), ( 2.16471477, -8.14565256e-01),
     ( 3.23335017, -1.14283702e+00), (-3.15089542,  1.03900358e+00),
     (-3.3197784 ,  1.01332081e+00), (-1.6427036 ,  4.59923052e-01),
     ( 0.17134076, -4.35267255e-02), (-1.57449564,  3.58152158e-01),
     (-2.16258153,  4.33271909e-01), ( 1.42528906, -2.46200827e-01)]>

Comments

Popular posts from this blog

Generate-a-compressed-approximation-of-an-image-using-matrix-decomposition-from-linear-algebra

JAVA: final, finally, finalize

Photon: The particle in your eye