I'm trying to fix this code which used astlib
to convert coordinates to use the astropy
coordinate modules. Here's a copy of the code:
from astLib import astCoords as coords
#Convert B1950 coordinates (as given)
clra=zeros(3)
cldec=zeros(3)
for i in range(len(clra)):
clra[i], cldec[i] = coords.convertCoords(
'B1950', 'J2000', clra1950[i],
cldec1950[i], 1950
)
#Convert input coords to Galactic coords
lgal,bgal = radians(coords.convertCoords(
'J2000', 'GALACTIC', ra,
dec,2000
))
I need help with 2 things.
What are the proper imports for astropy
if I want to change from B1950
to J2000
, and the proper imports to go from J2000
to galactic coordinates?
in the areas that start with coords.convertCoords()
, What are the functions and arguments from astropy that go in its place. In other words, what do I replace it with?
Also, I had done some research into this issue. I found this link here: http://docs.astropy.org/en/v0.2.1/coordinates/
It describes the notation for astropy's
coordinate related functions. However, there is a lot there, and I'm not sure what to use and how to use it.
This is one way to do it:
In [1]: import numpy as np
In [2]: from astropy import units as u
In [3]: from astropy.coordinates import SkyCoord, FK4, FK5, Galactic
In [4]: clra = np.zeros(3)
In [5]: cldec = np.zeros(3)
In [6]: c1 = SkyCoord(clra * u.deg, cldec * u.deg, frame=FK4)
In [7]: c2 = c1.transform_to(FK5(equinox='J2000'))
In [8]: c3 = c2.transform_to(Galactic)
In [9]: print(c3.l.degree)
[ 97.74220094 97.74220094 97.74220094]
In [10]: print(c3.b.degree)
[-60.18102359 -60.18102359 -60.18102359]
Note that you can convert c1
to Galactic directly too.