Astropy: Celestial Coordinates - Solutions

In [1]:
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
In [2]:
from astropy import units as u
from astropy.coordinates import SkyCoord
from astropy.table import Table

Level 1

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

In [3]:
crab = SkyCoord.from_name('M1')
In [4]:
crab
Out[4]:
<SkyCoord (ICRS): (ra, dec) in deg
    (83.633083, 22.0145)>
In [5]:
crab_gal = crab.transform_to('galactic')
In [6]:
crab_gal
Out[6]:
<SkyCoord (Galactic): (l, b) in deg
    (184.55745771, -5.78435696)>

Level 2

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.

In [7]:
t = Table.read('data/rosat.vot')
WARNING: W49: None:924:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:924:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:2170:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:2170:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:22470:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:22470:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:23884:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:23884:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:27160:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:27160:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:47362:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:47362:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:48580:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:48580:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:56322:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:56322:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:56784:6: W49: Empty cell illegal for integer fields. [astropy.io.votable.converters]
WARNING:astropy:W49: None:56784:6: W49: Empty cell illegal for integer fields.
WARNING: W49: None:58086:6: W49: Empty cell illegal for integer fields. (suppressing further warnings of this type...) [astropy.io.votable.converters]
WARNING:astropy:W49: None:58086:6: W49: Empty cell illegal for integer fields. (suppressing further warnings of this type...)

In [8]:
t.columns
Out[8]:
<TableColumns names=('_1RXS','RAJ2000','DEJ2000','PosErr','NewFlag','Count','e_Count','HR1','e_HR1','HR2','e_HR2','Extent')>
In [9]:
c = SkyCoord(t['RAJ2000'], t['DEJ2000'], unit=(u.deg, u.deg))
In [10]:
c_gal = c.galactic
In [11]:
c_gal.l.degree
Out[11]:
array([ 340.56214636,  101.78662367,  312.27862175, ...,  121.29248372,
        107.38870299,  101.88656375])
In [12]:
c_gal.b.degree
Out[12]:
array([-73.66010239, -52.47046199, -52.59260607, ...,  20.41553086,
       -39.30259234, -52.19145549])
In [13]:
fig = plt.figure()
ax = fig.add_subplot(1,1,1, aspect='equal')
ax.scatter(c_gal.l.degree, c_gal.b.degree, s=1, color='black', alpha=0.1)
ax.set_xlim(360., 0.)
ax.set_ylim(-90., 90.)
ax.set_xlabel("Galactic Longitude")
ax.set_ylabel("Galactic Latitude")
plt.show()

Level 3

Make an Aitoff projection map of the sources in Galactic coordinates

In [14]:
l_rad = c_gal.l.radian
l_rad[l_rad > np.pi] -= 2. * np.pi
b_rad = c_gal.b.radian
In [15]:
fig = plt.figure()
ax = fig.add_subplot(1,1,1, projection='aitoff')
ax.scatter(l_rad, b_rad, s=1, color='black', alpha=0.05)
ax.grid()
plt.show()