Celestial Coordinates

Documentation

For more information about the features presented below, you can read the astropy.coordinates docs.

About

Astropy includes a framework to represent celestial coordinates and transform between them. Astropy 0.4 only includes a few common coordinate systems (ICRS, FK4, FK5, and Galactic), but future versions will include more built-in coordinate systems, and users can already define their own systems.

Creating coordinate objects

Creating coordinate objects is straightforward:

In [1]:
from astropy.coordinates import SkyCoord
from astropy import units as u
In [2]:
SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg, frame='icrs')
Out[2]:
<SkyCoord (ICRS): ra=10.68458 deg, dec=41.26917 deg>

In addition to passing angular Quantity objects, the SkyCoord class can parse coordinate strings:

In [3]:
SkyCoord('00h42m44.3s +41d16m9s', frame='icrs')
Out[3]:
<SkyCoord (ICRS): ra=10.6845833333 deg, dec=41.2691666667 deg>

Accessing angles

The individual components of a coordinate are Angle objects, and their values are accessed using special attributes:

In [4]:
c = SkyCoord('00h42m44.3s +41d16m9s', frame='icrs')
In [5]:
c.ra
Out[5]:
$10^\circ41{}^\prime04.5{}^{\prime\prime}$
In [6]:
c.ra.hour
Out[6]:
0.7123055555555556
In [7]:
c.ra.hms
Out[7]:
hms_tuple(h=0.0, m=42.0, s=44.30000000000021)
In [8]:
c.dec
Out[8]:
$41^\circ16{}^\prime09{}^{\prime\prime}$
In [9]:
c.dec.radian
Out[9]:
0.7202828378876265

Converting to other systems

To convert to some other coordinate system (or 'frame' in Astropy terminology), the easiest method is to use attribute-style access with short names for the built-in systems:

In [10]:
c.galactic
Out[10]:
<SkyCoord (Galactic): l=121.174305193 deg, b=-21.5728034839 deg>
In [11]:
c.fk5
Out[11]:
<SkyCoord (FK5): equinox=J2000.000, ra=10.6845948726 deg, dec=41.2691681258 deg>

While these conveniences allow fast conversion to common coordinate systems, they do not allow any customization of the parameters of the new frame, such as the equinox. The more general way of transforming coordinates is via the transform_to method. In addition to taking convenience strings:

In [12]:
c.transform_to('galactic')
Out[12]:
<SkyCoord (Galactic): l=121.174305193 deg, b=-21.5728034839 deg>

this method can also take frame objects that can be customized:

In [13]:
from astropy.coordinates import FK5
In [14]:
frame = FK5(equinox='J2010')
In [15]:
c.transform_to(frame)
Out[15]:
<SkyCoord (FK5): equinox=J2010.000, ra=10.8218390257 deg, dec=41.3238612021 deg>

Name resolution

The astropy.coordinates subpackage also provides a quick way to get coordinates for named objects (with an internet connection). All coordinate classes have a special class method, from_name(), that accepts a string and queries Sesame to retrieve coordinates for that object:

In [16]:
SkyCoord.from_name("M16")
Out[16]:
<SkyCoord (ICRS): ra=274.7 deg, dec=-13.8067 deg>

Using arrays in coordinates

Numpy arrays can be used inside coordinate objects instead of scalar floating point values (this is much more efficient that creating one coordinate object for each source). The following example demonstrates how one can combine the Table class with coordinate objects (you can download the data from here).

In [17]:
from astropy.table import Table
In [18]:
t = Table.read('data/2mass.tbl', format='ascii.ipac')
In [19]:
t
Out[19]:
radecclonclaterr_majerr_minerr_angdesignationj_mj_cmsigj_msigcomj_snrh_mh_cmsigh_msigcomh_snrk_mk_cmsigk_msigcomk_snrph_qualrd_flgbl_flgcc_flgndetgal_contammp_flgdistanglej_hh_kj_k
degdegarcsecarcsecdegmagmagmagmagmagmagmagmagmag
274.429506-13.87054718h17m43.08s-13d52m13.97s0.080.084518174308-135213916.3050.1420.1436.714.0480.1070.10813.613.2570.0660.06616.5CAA2221110ss06665500975.080151256.4482.2570.7913.048
274.423821-13.8697418h17m41.72s-13d52m11.06s0.060.069018174171-135211014.8020.0580.05926.712.6350.0590.0650.111.7680.0450.04665.2AAA2221110ss66666600993.752042256.8782.1670.8673.034
274.424587-13.73962918h17m41.90s-13d44m22.66s0.080.084518174190-134422616.328------14.3450.0590.0610.413.4050.0460.04714.4UAA0220110cc00366600995.726698284.113--0.94--
274.433933-13.76950218h17m44.14s-13d46m10.21s0.080.084518174414-134610216.2810.0980.0996.814.0570.0350.03613.512.9560.0320.03321.8CAA22211100006556600942.627418278.2522.2241.1013.325
274.437013-13.88569818h17m44.88s-13d53m08.51s0.090.094518174488-135308515.171------14.4120.1520.1529.813.7420.0950.09510.6UBA6220220cc00556600964.105389252.93--0.67--
274.433996-13.75244618h17m44.16s-13d45m08.81s0.080.089018174415-134508816.54------14.5190.0830.0838.813.6040.0430.04412.0UBA0220110cc00566600953.230532281.908--0.915--
274.418138-13.7721518h17m40.35s-13d46m19.74s0.080.089018174035-134619717.98------14.610.0430.0448.113.4560.0560.05713.8UBA02201100000164500996.047248277.25--1.154--
274.433695-13.89904918h17m44.09s-13d53m56.58s0.060.069018174408-135356513.0110.0210.024139.010.9170.020.021243.810.0130.0170.019328.3AAA22211100066666600990.166399250.4662.0940.9042.998
274.425482-13.7714918h17m42.12s-13d46m17.36s0.080.0813518174211-134617316.086------13.7090.0650.06618.612.5030.0440.04533.1UAA62201200c00555500970.896919277.582--1.206--
274.433057-13.78486618h17m43.93s-13d47m05.52s0.110.114518174393-134705518.027------15.332------14.1220.070.0717.5UUB00200100000000600939.279823274.885------
274.435762-13.80101518h17m44.58s-13d48m03.65s0.110.114518174458-134803617.148------14.585------13.810.060.0619.9UUB00200100000006600926.604021271.351------
................................................................................................
274.81801-14.00124518h19m16.32s-14d00m04.48s0.180.16118191632-140004416.240.1130.1135.615.5310.1640.1642.515.252------CDU22011000006060000809.817146149.610.709----
274.822709-14.03725418h19m17.45s-14d02m14.11s0.070.074518191745-140214115.9990.0970.0987.014.0090.0320.03310.013.0770.0350.03616.4CAA22211100006265600931.339773152.7791.990.9322.922
274.880758-13.9995618h19m31.38s-13d59m58.42s0.060.069018193138-135958414.1630.0350.03737.811.1790.020.021135.69.7650.0170.019347.1AAA22211100055666600935.512452137.7622.9841.4144.398
274.652526-14.05510618h18m36.61s-14d03m18.38s0.060.069018183660-140318315.0350.0520.05419.413.0990.040.04127.512.2540.0410.04141.7AAA222111c0056666600908.109808190.6821.9360.8452.781
274.760586-13.99992718h19m02.54s-13d59m59.74s0.080.089018190254-135959716.3290.1220.1235.514.4880.0670.0676.413.6170.0510.05211.1CCA22211100006061600724.557553163.2271.8410.8712.712
274.831132-14.02002718h19m19.47s-14d01m12.10s0.080.084518191947-140112016.203------13.2380.020.02120.412.0160.0230.02443.6UAA02201100000666600891.347132149.27--1.222--
274.972435-13.76037418h19m53.38s-13d45m37.35s0.120.111018195338-134537317.472------16.755------14.4130.0840.0844.8UUD00200100000000600964.82893379.963------
274.870009-13.81777518h19m28.80s-13d49m03.99s0.080.084518192880-134903916.933------14.5140.0640.0656.312.9570.0410.04118.4UCA02201100000266600592.99805893.69--1.557--
274.735323-13.94157518h18m56.48s-13d56m29.67s0.140.144518185647-135629616.643------14.88------14.2910.1160.1176.0UUC00200100000000400498.524438165.968------
274.866294-13.84177818h19m27.91s-13d50m30.40s0.080.084518192791-135030415.615------13.9110.0750.07510.912.7650.1340.13421.9UAE0220110cc00554500591.97725102.147--1.146--
In [20]:
c = SkyCoord(t['ra'] * u.deg, t['dec'] * u.deg, frame='fk5')
In [21]:
c.ra.degree
Out[21]:
array([ 274.429506,  274.423821,  274.424587,  274.433933,  274.437013,
        274.433996,  274.418138,  274.433695,  274.425482,  274.433057,
        274.435762,  274.438109,  274.425594,  274.431318,  274.42949 ,
        274.428117,  274.425499,  274.431606,  274.431202,  274.433361,
        274.426056,  274.425066,  274.420529,  274.426694,  274.421593,
        274.427483,  274.43155 ,  274.4263  ,  274.426193,  274.432195,
        274.435515,  274.429849,  274.431399,  274.431675,  274.427993,
        274.432066,  274.438921,  274.426778,  274.427573,  274.435009,
        274.418314,  274.425618,  274.425325,  274.435291,  274.422565,
        274.430995,  274.434654,  274.423689,  274.43087 ,  274.43241 ,
        274.675641,  274.437325,  274.435197,  274.434291,  274.429439,
        274.425616,  274.4244  ,  274.435142,  274.433826,  274.433514,
        274.435348,  274.437104,  274.426803,  274.434892,  274.430584,
        274.433654,  274.433872,  274.436504,  274.419325,  274.423378,
        274.431121,  274.434871,  274.427022,  274.436195,  274.430074,
        274.431994,  274.428505,  274.434618,  274.43626 ,  274.422354,
        274.431783,  274.420349,  274.43062 ,  274.416126,  274.420833,
        274.433188,  274.426632,  274.430197,  274.433299,  274.425391,
        274.432256,  274.421227,  274.417932,  274.433165,  274.437103,
        274.426517,  274.433143,  274.42379 ,  274.429845,  274.439001,
        274.426876,  274.684921,  274.422397,  274.426321,  274.428059,
        274.424496,  274.424921,  274.435195,  274.436233,  274.423425,
        274.435134,  274.43309 ,  274.434715,  274.43069 ,  274.420853,
        274.427487,  274.42894 ,  274.421415,  274.421796,  274.436391,
        274.432871,  274.432704,  274.4391  ,  274.424646,  274.436838,
        274.434745,  274.422162,  274.420229,  274.424251,  274.416506,
        274.430705,  274.436654,  274.422484,  274.430689,  274.429727,
        274.423746,  274.425183,  274.427657,  274.432041,  274.432324,
        274.435255,  274.43645 ,  274.436822,  274.430214,  274.434539,
        274.422138,  274.431213,  274.435242,  274.433842,  274.428585,
        274.432612,  274.621263,  274.662   ,  274.682343,  274.733087,
        274.660462,  274.812007,  274.686772,  274.861217,  274.91445 ,
        274.888808,  274.739657,  274.742897,  274.778029,  274.845423,
        274.718495,  274.754966,  274.741165,  274.812436,  274.810159,
        274.929367,  274.846621,  274.8915  ,  274.918428,  274.918871,
        274.875346,  274.791926,  274.836011,  274.77716 ,  274.800745,
        274.877501,  274.870855,  274.730373,  274.842726,  274.907218,
        274.887363,  274.814087,  274.873038,  274.814816,  274.922142,
        274.951663,  274.966815,  274.965917,  274.972769,  274.605645,
        274.789562,  274.804721,  274.812328,  274.901685,  274.721547,
        274.920591,  274.712037,  274.894153,  274.938795,  274.668337,
        274.717516,  274.684752,  274.79291 ,  274.928264,  274.708399,
        274.813541,  274.674387,  274.934293,  274.775099,  274.79971 ,
        274.898508,  274.911322,  274.832424,  274.830842,  274.736572,
        274.814625,  274.710335,  274.775841,  274.875919,  274.755355,
        274.849234,  274.910838,  274.823899,  274.730861,  274.742749,
        274.793592,  274.798888,  274.904878,  274.808319,  274.832478,
        274.806833,  274.802163,  274.840332,  274.761657,  274.860068,
        274.849763,  274.877017,  274.948162,  274.972886,  274.968786,
        274.638825,  274.923411,  274.694521,  274.727242,  274.917554,
        274.794504,  274.828669,  274.868335,  274.917553,  274.676758,
        274.685002,  274.69785 ,  274.749193,  274.632227,  274.88426 ,
        274.744103,  274.811589,  274.774544,  274.773173,  274.835721,
        274.870142,  274.804915,  274.869053,  274.705457,  274.833596,
        274.800454,  274.917991,  274.755938,  274.755625,  274.846472,
        274.814804,  274.878528,  274.917855,  274.9136  ,  274.69452 ,
        274.883611,  274.8981  ,  274.805705,  274.850565,  274.931569,
        274.837564,  274.925328,  274.802783,  274.852203,  274.91132 ,
        274.930641,  274.812804,  274.963013,  274.942399,  274.981071,
        274.660924,  274.781789,  274.926546,  274.786041,  274.815752,
        274.732612,  274.721699,  274.880689,  274.902776,  274.956665,
        274.641091,  274.435794,  274.432692,  274.421207,  274.425784,
        274.415975,  274.43387 ,  274.434321,  274.425781,  274.430312,
        274.426784,  274.427016,  274.434116,  274.421115,  274.427547,
        274.436062,  274.432949,  274.433058,  274.425653,  274.424333,
        274.420432,  274.429983,  274.418668,  274.435624,  274.432799,
        274.428138,  274.43453 ,  274.428285,  274.436297,  274.431649,
        274.436577,  274.415589,  274.432446,  274.422013,  274.43785 ,
        274.423952,  274.438914,  274.428008,  274.429083,  274.425648,
        274.427786,  274.417064,  274.419802,  274.432839,  274.436571,
        274.425382,  274.423951,  274.433489,  274.427059,  274.428671,
        274.639484,  274.673333,  274.654852,  274.685224,  274.724783,
        274.642639,  274.870783,  274.871646,  274.868186,  274.713304,
        274.71664 ,  274.703003,  274.743386,  274.858871,  274.766825,
        274.749374,  274.919319,  274.733073,  274.866822,  274.745985,
        274.775743,  274.727968,  274.869083,  274.934442,  274.913466,
        274.90195 ,  274.774088,  274.899947,  274.881449,  274.907317,
        274.870428,  274.935527,  274.852728,  274.918726,  274.700945,
        274.847027,  274.926888,  274.907458,  274.879833,  274.959289,
        274.943379,  274.973808,  274.678696,  274.783087,  274.880234,
        274.790396,  274.898414,  274.798285,  274.76586 ,  274.892421,
        274.921276,  274.974219,  274.648755,  274.424269,  274.42912 ,
        274.438158,  274.432045,  274.429344,  274.423726,  274.419512,
        274.435406,  274.417292,  274.419345,  274.417812,  274.433143,
        274.433125,  274.432457,  274.418244,  274.422977,  274.435921,
        274.423288,  274.429972,  274.431866,  274.427932,  274.437041,
        274.438098,  274.429876,  274.431927,  274.421202,  274.427553,
        274.431967,  274.433271,  274.436631,  274.435766,  274.424878,
        274.423936,  274.432652,  274.4238  ,  274.434058,  274.423889,
        274.416641,  274.427601,  274.428668,  274.421147,  274.432598,
        274.43655 ,  274.419997,  274.436975,  274.430671,  274.43495 ,
        274.437159,  274.421547,  274.437636,  274.675231,  274.42625 ,
        274.435326,  274.433783,  274.418938,  274.434973,  274.433754,
        274.43453 ,  274.437265,  274.41924 ,  274.434642,  274.429546,
        274.418112,  274.423589,  274.419872,  274.423352,  274.420732,
        274.437666,  274.425445,  274.432794,  274.437962,  274.434439,
        274.428501,  274.43257 ,  274.431746,  274.426016,  274.431029,
        274.427313,  274.418545,  274.43706 ,  274.426604,  274.426905,
        274.42386 ,  274.437547,  274.437816,  274.431596,  274.430619,
        274.429104,  274.424225,  274.429969,  274.429442,  274.429776,
        274.433493,  274.424236,  274.417171,  274.435405,  274.43393 ,
        274.41871 ,  274.429321,  274.436946,  274.679362,  274.672469,
        274.679654,  274.803903,  274.674241,  274.664341,  274.894301,
        274.787882,  274.922272,  274.727095,  274.731652,  274.748976,
        274.749418,  274.911245,  274.935328,  274.782615,  274.889153,
        274.762499,  274.72074 ,  274.711522,  274.763438,  274.754516,
        274.724349,  274.915827,  274.875462,  274.836351,  274.767134,
        274.779886,  274.783627,  274.789868,  274.816198,  274.882042,
        274.898203,  274.705959,  274.691639,  274.893767,  274.871026,
        274.913282,  274.93395 ,  274.936975,  274.952674,  274.940017,
        274.978107,  274.645004,  274.798187,  274.747088,  274.791502,
        274.867756,  274.912617,  274.863687,  274.812742,  274.875639,
        274.675901,  274.7455  ,  274.741013,  274.744804,  274.687262,
        274.623156,  274.893046,  274.668363,  274.712694,  274.701964,
        274.760507,  274.827389,  274.818194,  274.758179,  274.923668,
        274.717728,  274.896492,  274.951394,  274.931368,  274.873959,
        274.709578,  274.85841 ,  274.878535,  274.755915,  274.899405,
        274.828739,  274.773111,  274.805438,  274.79194 ,  274.815212,
        274.904514,  274.823498,  274.852093,  274.932421,  274.835866,
        274.974139,  274.803835,  274.855288,  274.815889,  274.806862,
        274.902472,  274.956783,  274.669319,  274.882145,  274.967315,
        274.742104,  274.665888,  274.721132,  274.927288,  274.936517,
        274.850078,  274.795117,  274.708873,  274.708522,  274.883327,
        274.878627,  274.92945 ,  274.733392,  274.933025,  274.786076,
        274.743087,  274.805511,  274.84981 ,  274.865511,  274.806511,
        274.922018,  274.743493,  274.821065,  274.925352,  274.932982,
        274.837379,  274.935661,  274.782654,  274.929466,  274.811397,
        274.766058,  274.841991,  274.714258,  274.811333,  274.738349,
        274.900449,  274.831057,  274.820249,  274.87522 ,  274.757072,
        274.850539,  274.98267 ,  274.859999,  274.920205,  274.953432,
        274.880883,  274.970579,  274.957743,  274.808186,  274.870733,
        274.798783,  274.659823,  274.782542,  274.767692,  274.980788,
        274.714675,  274.660029,  274.972606,  274.624839,  274.68664 ,
        274.67802 ,  274.768868,  274.864261,  274.730719,  274.731901,
        274.784462,  274.72286 ,  274.721252,  274.775264,  274.895335,
        274.867012,  274.790967,  274.897357,  274.799943,  274.738945,
        274.810928,  274.764042,  274.889511,  274.734799,  274.92983 ,
        274.840941,  274.821702,  274.693113,  274.763614,  274.887889,
        274.777282,  274.934779,  274.834288,  274.917696,  274.696122,
        274.944906,  274.853347,  274.820799,  274.921715,  274.846498,
        274.926011,  274.970393,  274.94131 ,  274.945591,  274.648691,
        274.748444,  274.753018,  274.689065,  274.729584,  274.823624,
        274.883099,  274.87894 ,  274.968576,  274.644587,  274.686273,
        274.741992,  274.840569,  274.835433,  274.836924,  274.895252,
        274.654052,  274.800395,  274.758048,  274.729411,  274.763506,
        274.870033,  274.823758,  274.885961,  274.8811  ,  274.759363,
        274.84985 ,  274.827936,  274.84378 ,  274.974707,  274.679768,
        274.928901,  274.800286,  274.678175,  274.772161,  274.965494,
        274.847524,  274.798154,  274.738029,  274.913793,  274.865187,
        274.92792 ,  274.933494,  274.857259,  274.800912,  274.70779 ,
        274.94229 ,  274.922202,  274.9533  ,  274.858591,  274.937299,
        274.623998,  274.897223,  274.938287,  274.74044 ,  274.670534,
        274.96227 ,  274.823579,  274.931563,  274.687655,  274.774043,
        274.794135,  274.895238,  274.981976,  274.986131,  274.767323,
        274.78907 ,  274.785763,  274.846023,  274.94426 ,  274.747493,
        274.853587,  274.819037,  274.941377,  274.656239,  274.661726,
        274.699747,  274.705149,  274.978126,  274.893473,  274.926148,
        274.938271,  274.772337,  274.819818,  274.698419,  274.845544,
        274.650326,  274.857291,  274.848245,  274.916722,  274.841637,
        274.860076,  274.753949,  274.768894,  274.59968 ,  274.945602,
        274.767606,  274.866331,  274.787032,  274.897499,  274.955934,
        274.796028,  274.69627 ,  274.694867,  274.83377 ,  274.842506,
        274.861735,  274.899742,  274.976467,  274.872379,  274.828855,
        274.902586,  274.710435,  274.804986,  274.775672,  274.87601 ,
        274.896136,  274.804224,  274.863644,  274.723283,  274.807442,
        274.764548,  274.821629,  274.89034 ,  274.877991,  274.894602,
        274.715311,  274.86543 ,  274.847414,  274.864022,  274.896635,
        274.921856,  274.749885,  274.81803 ,  274.750759,  274.73477 ,
        274.942369,  274.767548,  274.760305,  274.7417  ,  274.821048,
        274.908869,  274.83319 ,  274.914763,  274.753326,  274.921663,
        274.780912,  274.828743,  274.973604,  274.969052,  274.856785,
        274.960272,  274.720743,  274.875225,  274.96312 ,  274.705671,
        274.674976,  274.965253,  274.730373,  274.947295,  274.808323,
        274.760953,  274.796084,  274.616166,  274.916209,  274.852408,
        274.604995,  274.762428,  274.90609 ,  274.64499 ,  274.774448,
        274.84531 ,  274.711188,  274.848557,  274.762958,  274.724127,
        274.881807,  274.795499,  274.907772,  274.707194,  274.892143,
        274.850276,  274.692327,  274.879222,  274.912836,  274.788401,
        274.894894,  274.6045  ,  274.797491,  274.804877,  274.922051,
        274.900945,  274.836101,  274.944569,  274.899343,  274.877738,
        274.884929,  274.936921,  274.747992,  274.869489,  274.862392,
        274.922971,  274.967759,  274.858201,  274.83525 ,  274.855786,
        274.788212,  274.63957 ,  274.611341,  274.752605,  274.863976,
        274.903251,  274.886033,  274.737456,  274.830178,  274.81801 ,
        274.822709,  274.880758,  274.652526,  274.760586,  274.831132,
        274.972435,  274.870009,  274.735323,  274.866294])
In [22]:
c = SkyCoord(t['clon'], t['clat'], frame='fk5')

Practical Exercises

Level 1

Find the coordinates of the Crab Nebula in ICRS coordinates, and convert them to Galactic Coordinates.

Level 2

Starting from this table in VO table format (this is the ROSAT all-sky catalog), read in the sources, use the RA and Dec columns to instantiate a coordinate object, then convert to Galactic coordinates. Make a plot of latitude versus longitude.

Level 3

Once you have done Level 2, make an Aitoff projection map of the sources in Galactic coordinates.