For more information about the features presented below, you can read the astropy.coordinates docs.
Astropy includes a framework to represent celestial coordinates and transform between them. Astropy includes common coordinate systems (ICRS, FK4, FK5, Galactic, and AltAz).
Creating coordinate objects is straightforward:
from astropy.coordinates import SkyCoord
from astropy import units as u
SkyCoord(ra=10.68458 * u.deg, dec=41.26917 * u.deg)
SkyCoord('00h42m44.3s +41d16m9s')
The individual components of a coordinate are Angle
objects, and their
values are accessed using special attributes:
c = SkyCoord('00h42m44.3s +41d16m9s')
c.ra
c.ra.hour
c.ra.hms
c.dec
c.dec.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
but explicit transformations via the transform_to
method are also available:
c.transform_to('galactic')
The astropy.coordinates
subpackage also provides a quick way to get coordinates for
named objects (with an internet connection). The SkyCoord class has a method from_name()
, that accepts a string and queries Sesame to retrieve coordinates for that
object:
c_eq = SkyCoord.from_name("M16")
c_eq
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).
from astropy.table import Table
t = Table.read('data/2mass.tbl', format='ascii.ipac')
t
c = SkyCoord(t['ra'], t['dec'])
Note that we didn't have to give the units because these are contained in the table metadata!
c.ra.degree[:10]
We can also pass string columns:
c = SkyCoord(t['clon'], t['clat'])
import numpy as np
from astropy import units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation, AltAz
m33 = SkyCoord.from_name('M33')
bear_mountain = EarthLocation(lat=41.3*u.deg, lon=-74*u.deg, height=390*u.m)
utcoffset = -4 * u.hour # Eastern Daylight Time
time = Time('2012-7-12 23:00:00') - utcoffset
m33altaz = m33.transform_to(AltAz(obstime=time,location=bear_mountain))
m33altaz.alt
m33altaz.az
We now want to make a plot of the altitude vs time to plan observations
midnight = Time('2012-7-13 00:00:00') - utcoffset
delta_midnight = np.linspace(-7, 7, 100) * u.hour
m33altazs = m33.transform_to(AltAz(obstime=midnight+delta_midnight, location=bear_mountain))
We can now plot the results:
%matplotlib inline
import matplotlib.pyplot as plt
plt.plot(delta_midnight, m33altazs.alt)
plt.xlim(-2, 7)
plt.ylim(-30, 90)
plt.axhline(0, color='k', ls='dashed')
plt.xlabel('Hours from EDT Midnight')
plt.ylabel('Airmass [Sec(z)]')
plt.show()
Astropy includes functions that can help with catalog matching. Let's start from the 2MASS catalog used above and also use the WISE catalog for the same area of sky:
t_2mass = Table.read('data/2mass.tbl', format='ascii.ipac')['ra', 'dec', 'j_m', 'h_m', 'k_m']
t_2mass
t_wise = Table.read('data/wise.tbl', format='ascii.ipac')['designation', 'ra', 'dec', 'w1mpro', 'w2mpro', 'w3mpro', 'w4mpro']
t_wise
c_2mass = SkyCoord(t_2mass['ra'], t_2mass['dec'])
c_wise = SkyCoord(t_wise['ra'], t_wise['dec'])
idx_wise, idx_2mass, d2d, d3d = c_2mass.search_around_sky(c_wise, 5 * u.arcsec)
t_2mass[idx_2mass]
t_wise[idx_wise]
from astropy.table import hstack
t_merged = hstack([t_2mass[idx_2mass], t_wise[idx_wise]])
plt.scatter(t_merged['k_m'] - t_merged['w4mpro'],
t_merged['j_m'] - t_merged['k_m'])
plt.xlabel("K - W4")
plt.ylabel("J - K")
Find the coordinates of the Crab Nebula in ICRS coordinates, and convert them to Galactic Coordinates.
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.
Once you have done Level 2, make an Aitoff projection map of the sources in Galactic coordinates. Then, try and match the ROSAT catalog with other catalogs that you have access to.