Dealing with astronomical coordinates: SkyCoord class from Astropy

ESOpy 3.0 @ Vitacura - 15-17 April 2019 - fvogt@eso.org

Before we start:

Premise: the sky is not flat ... => Dealing with R.A & Dec. can be "frustrating", i.e.:

  • $\alpha\cdot\cos(\delta)$
  • $^s\,\equiv\, ^{\prime\prime}\cdot\frac{24}{360}$
  • B1950 vs J2000
  • what's proper motion ?

SkyCoord class:

  • an elgant & powerful way to deal with all of this

Cost:

  • 2 astropy sub-packages
  • requires to use "units"

Benefits:

  • Never screw up your Dec again! -00$^{\circ}$00$^{\prime}$01$^{\prime\prime}$ $\neq$ 00$^{\circ}$00$^{\prime}$01$^{\prime\prime}$

1) Getting started

In [2]:
# Import the packages
from astropy import units as u
from astropy.coordinates import SkyCoord

2) Creating some coordinates

In [3]:
# Lots of flexibility to define coordinates ...
a = SkyCoord('00h42m30s', '+41d12m00s', frame='icrs')
b = SkyCoord('00 42 30 +41 12 00', unit=(u.hourangle, u.deg))
c = SkyCoord(ra=10.625*u.degree, dec=41.2*u.degree, frame='icrs')

# ... that are all equivalent
print('a:',a.to_string('hmsdms'))
print('b:',b.to_string('hmsdms'))
print('c:',c.to_string('hmsdms'))
a: 00h42m30s +41d12m00s
b: 00h42m30s +41d12m00s
c: 00h42m30s +41d12m00s
In [4]:
# It's then easy to access the different class parameters
print(type(a.ra), a.ra.deg, a.ra.hour)
print(type(a.dec), a.dec.deg)
<class 'astropy.coordinates.angles.Longitude'> 10.624999999999998 0.7083333333333334
<class 'astropy.coordinates.angles.Latitude'> 41.2

3) Some useful functions

In [5]:
# Create 2 different coordinates
a = SkyCoord('00h42m30s', '+41d12m00s', frame='icrs')
b = SkyCoord('00h42m30s', '+41d11m00s', frame='icrs')

# Get the separationg between the two
sep = a.separation(b)
print(sep.to(u.arcsec))
60arcsec
In [6]:
# Blind offset
c = a.directional_offset_by(180*u.deg,1*u.arcmin)
print(c.to_string('hmsdms'))
00h42m30s +41d11m00s
In [14]:
# Change between galactic and sky coordinates 
a = SkyCoord('00h00m00s', '+00d00m00s', frame='galactic', equinox='J2000')

print('ICRS:',a.icrs.to_string('hmsdms'))
ICRS: 17h45m37.1972s -28d56m10.2399s
In [7]:
# Deal with "proper motions"
from astropy.time import Time

a = SkyCoord('00h00m00s', '00d00m00s', frame='icrs', 
             pm_ra_cosdec=0*u.mas/u.yr, pm_dec=5*u.arcsec/u.yr,
             distance=100*u.pc, 
             obstime=Time('2000-01-01 00:00:00.0'))

b = a.apply_space_motion(new_obstime = Time('2010-01-01 00:00:00.0'))

print(b.to_string('hmsdms'))
sep = a.separation(b)
print('Angular offset:', sep.to(u.arcsec)/10)
00h00m00s +00d00m50.0052s
Angular offset: 5.00052arcsec

4) Just for fun

In [33]:
from astropy.coordinates import EarthLocation
VLT = EarthLocation.of_site('Paranal Observatory') 
print(VLT.lat,VLT.lon,VLT.height)
-24d37m30.72s -70d24m10.8s 2635.0000000009704 m
In [ ]: