Celestial Coordinates ===================== Documentation ------------- For more information about the features presented below, you can read the `astropy.coordinates `_ docs. Representing and converting coordinates --------------------------------------- Astropy includes a framework to represent celestial coordinates and transform between them. Astropy most of the common coordinate systems (ICRS, FK4, FK5, and Galactic, AltAz) and users can define their own systems if needed. Transformation of both individual scalar coordinates and arrays of coordinates is supported. Coordinate objects are instantiated with a flexible and natural approach that supports both numeric angle values and (limited) string parsing:: >>> from astropy.coordinates import SkyCoord >>> from astropy import units as u >>> SkyCoord(ra=10.68458, dec=41.26917, unit=(u.degree, u.degree)) >>> SkyCoord('00h42m44.3s +41d16m9s') The individual components of a coordinate are ``Angle`` objects, and their values are accessed using special attributes:: >>> c = SkyCoord(ra=10.68458, dec=41.26917, unit=(u.degree, u.degree)) >>> c.ra < >>> c.ra.to('hourangle') >>> c.ra.hms hms_tuple(h=0.0, m=42.0, s=44.299200000000525) >>> c.dec < >>> c.dec.to('radian') To convert to some other coordinate system, the easiest method is to use attribute-style access with short names for the built-in systems:: >>> c.galactic 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:: >>> c_eq = SkyCoord.from_name("M16") >>> c_eq .. note:: This is intended to be a convenience, and is very simple. If you need precise coordinates for an object you should find the appropriate reference for that measurement and input the coordinates manually. Practical Exercises ------------------- .. admonition:: Excercise 1 Find the coordinates of the Crab Nebula in ICRS coordinates, and convert them to Galactic Coordinates .. raw:: html

Click to Show/Hide Solution

:: >>> from astropy import coordinates as coord >>> crab = SkyCoord.from_name('M1') >>> print(crab) >>> crab_gal = crab.galactic >>> print(crab_gal) .. raw:: html
.. admonition:: Excercise 2 Using the ROSAT Point source catalog (from excercise 1 in :doc:`tables`), convert all the equatorial coordinates to Galactic coordinates, and make a new plot (but don't worry about the bright sources). .. raw:: html

Click to Show/Hide Solution

:: from astropy import units as u from astropy.coordinates import SkyCoord from astropy.table import QTable from matplotlib import pyplot as plt t = QTable.read('rosat.vot', format='votable') eq = SkyCoord(t['RAJ2000'], t['DEJ2000']) gal = eq.galactic fig = plt.figure() ax = fig.add_subplot(1,1,1, aspect='equal') ax.scatter(gal.l, gal.b, s=1, color='black') ax.set_xlim(0., 360.) ax.set_ylim(-90., 90.) ax.set_xlabel("Galactic Longitude") ax.set_ylabel("Galactic Latitude") fig.savefig('coord_level2.png', bbox_inches='tight') .. image:: coord_level2.png .. raw:: html