Author: Eduardo Martín Calleja
The purpose of this post is to show how you can work with the various astronomical coordinate systems using appropriate Python libraries.
Converting between various types of astronomical coordinates will be useful in future posts.This entry, as most of the following, will be fully written with the IPython Notebook
%matplotlib inline
from __future__ import division
# Import of the PyEphem package
import ephem
from astropy.coordinates import SkyCoord
#This removes some nasty deprecation warnings that do not interfere with the execution
import warnings
warnings.filterwarnings('ignore')
# This IPython magic generates a table with version information
#https://github.com/jrjohansson/version_information
%load_ext version_information
%version_information ephem, astropy
Software | Version |
---|---|
Python | 2.7.9 64bit [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] |
IPython | 2.3.1 |
OS | Linux 3.13.0 45 generic x86_64 with debian jessie sid |
ephem | 3.7.5.3 |
astropy | 0.4.3 |
Fri Feb 20 12:51:19 2015 CET |
They are defined by Right Ascension (ra), Declination (dec) and an epoch.
The ra is normally represented as a string of the form "hh: mm: ss"
The dec is usually represented as a string of the form "/ - °: ':''"
The default is epoch J2000.0
Its elements are:
By convention the ra is measured positively to the east and north.
The equatorial coordinates of an object are represented in ephem as instances of the Equatorial class. ra, dec and epoch are object attributes
# Let's define the equatorial coordinates of an object
eq=ephem.Equatorial('13:24:42.5','-60:15:59.4')
# The values are internally stored in radians
eq.ra, eq.dec, eq.epoch
(3.511202483725676, -1.0518488536531627, 36524.5)
# However they are printed as strings
print eq.ra, '\t', eq.dec, '\t', eq.epoch
13:24:42.50 -60:15:59.4 2000/1/1 00:00:00
# We can get a tuple (ra,dec) by using the get() method
print eq.get()
(3.511202483725676, -1.0518488536531627)
# To find the constellation corresponding to a coordinate tuple:
ephem.constellation((eq.ra,eq.dec))
('Cen', 'Centaurus')
We may also use other epoch different of J2000:
eq50=ephem.Equatorial('13:24:42.5','-60:15:59.4',epoch=ephem.B1950)
print eq50.ra, '\t', eq50.dec, '\t', eq50.epoch
13:24:42.50 -60:15:59.4 1949/12/31 22:09:50
This is another spherical coordinate system. Its elements are:
The coordinates are longitude (lon / l) and latitude (lat / b), both expressed in degrees, not hours
# Definition of the galactic coordinates of an object
ga=ephem.Galactic('1:59:55.9','+89:59:59.9')
print ga.lon, ga.lat
# Longitude and latitude are returned by the get() method. They are shown in radians
print ga.get()
1:59:55.9 89:59:59.9 (0.0348867076789611, 1.5707958419812156)
The coordinates can be converted from one system to another giving an object of the first type as an input to a class of the second type:
# Conversion of equatorial coordinates between epochs
eq1 = eq=ephem.Equatorial('13:24:42.5','-60:15:59.4')
eq2 = ephem.Equatorial(eq1,epoch=ephem.B1950)
print eq1.get()
print eq2.get()
(3.511202483725676, -1.0518488536531627) (3.49702212460356, -1.04730555904456)
# Conversióo from galactic to equatorial coordinates
# (we can in fact omit to declare the epoch, J2000 by default)
ga1 = ephem.Galactic('0','90',epoch=ephem.J2000)
eq1 = ephem.Equatorial(ga1)
print eq1.ra, eq1.dec
12:51:26.28 27:07:41.7
For this we'll use the SkyCoord module from the astropy library, which gets the coordinates from the SESAME server
The "International Celestial Reference System" (ICRS) is the celestial reference system adopted as standard today by the International Astronomical Union (IAU). These coordinates coincide very nearly with the J2000.0 equatorial coordinates. ICRS coordinates can be obtained by giving the name of the object in any of the catalogs used by the service SESAME
# Whirlpool Galaxy
SkyCoord.from_name("M51") # "icrs" es la opción por defecto
<SkyCoord (ICRS): ra=202.469575 deg, dec=47.1952583 deg>
# We can as well use other names for the same galaxy
SkyCoord.from_name('NGC 5194')
<SkyCoord (ICRS): ra=202.469575 deg, dec=47.1952583 deg>
# The same object in galactic coordinates
SkyCoord.from_name("M51", frame='galactic')
<SkyCoord (Galactic): l=104.851584722 deg, b=68.5607018112 deg>
To get the values of the angles (longitude and latitude in this case) there are several options:
c = SkyCoord.from_name("M51", frame='galactic')
# longitude and latitude can be accessed internally with c.l y c.b
# The internal representation of the angles is in degrees
# However, these values can not be operated directly
c.l, c.b
(<Longitude 104.85158472198123 deg>, <Latitude 68.5607018112399 deg>)
To obtain numerical values of the angles at which to operate, proceed as follows:
# angles in radians
print c.l.radian, c.b.radian
# Angles in degrees
print c.l.degree, c.b.degree
# Arithmetic operation example
c.l.degree + 90
1.83000537933 1.19660998408 104.851584722 68.5607018112
194.85158472198123
In the case of ICRS coordinates, the coordinate angles are ra and dec
c = SkyCoord.from_name("M51", frame='icrs')
# Prints a string representation unfit to operate with
print c
# provides a tuple "hours", "minutes", "seconds"
print c.ra.hms
# Values in degrees
print c.dec.degree
# Of course they can be expressed in other types of units
print c.ra.radian, c.dec.radian
<SkyCoord (ICRS): ra=202.469575 deg, dec=47.1952583 deg> hms_tuple(h=13.0, m=29.0, s=52.69800000000572) 47.1952583 3.53376071886 0.823712648664
Another coordinate system provided by the astropy package is FK5. It is an equatorial coordinate system based on the Epoch J2000, which practically coincides with the coordinates ICRS
# ICRS coordinates
c = SkyCoord.from_name("M51", frame='icrs')
# FK5 coordinates
c5 = SkyCoord.from_name("M51", frame='fk5')
# In this example you can see the similarity between the two
print 'ICRS coordinates: ',c.ra.hms, c.dec.degree
print 'FK5 coordinates: ', c5.ra.hms, c5.dec.degree
ICRS coordinates: hms_tuple(h=13.0, m=29.0, s=52.69800000000572) 47.1952583 FK5 coordinates: hms_tuple(h=13.0, m=29.0, s=52.697952632941849) 47.1952580768
# Let's obtain the galactic coordinates of a star
# We chose a southern hemisphere star
c = SkyCoord.from_name('Achernar', frame='galactic')
c
<SkyCoord (Galactic): l=290.841241695 deg, b=-58.7920097022 deg>
# Let's turn to FK5 equatorial coordinates:
c.fk5
<SkyCoord (FK5): equinox=J2000.000, ra=24.4285197401 deg, dec=-57.2367527786 deg>
# Conversely, from the ICRS obtain the galactic coordinates:
c = SkyCoord.from_name('Achernar', frame='icrs')
c.galactic
<SkyCoord (Galactic): l=290.841241695 deg, b=-58.7920097022 deg>