[AstroPy] Convert from AltAz to ICRS

Eric Jensen ejensen1 at swarthmore.edu
Sat Nov 23 15:20:59 EST 2019


Hi Franco, 

You can use the same transform_to method that is given in the example docs, just in the other direction, e.g. 

object_radec = object_altaz.transform_to(‘icrs')

Referring to the example here:  
https://docs.astropy.org/en/stable/generated/examples/coordinates/plot_obs-planning.html#sphx-glr-generated-examples-coordinates-plot-obs-planning-py

Here is some code based on that example, that extends it to show a transformation back to RA and Dec: 

import astropy.units as u
from astropy.time import Time
from astropy.coordinates import SkyCoord, EarthLocation, AltAz

# Get M33's coordinates
m33 = SkyCoord.from_name('M33')

# Define a location for observation: 
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-07-12 23:00:00') - utcoffset

# Find the alt/az at that time:
m33altaz = m33.transform_to(AltAz(obstime=time,location=bear_mountain))
print("M33's Altitude = {0.alt:.2f}, Azimuth = {0.az:.1f}".format(m33altaz))

# prints:  M33's Altitude = 0.13 deg, Azimuth = 47.3 deg

# Look at the same alt/az, 
# but half a sidereal day later: 
new_altaz = SkyCoord(AltAz(obstime=time + 0.5*u.sday,
                     az=m33altaz.az,
                     alt=m33altaz.alt,
                    location=bear_mountain))

# Transform back to RA, Dec;
# should get the same Dec as before but RA 12 hours different:
newradec = new_altaz.transform_to('icrs')
print(m33.to_string('hmsdms'))
print(newradec.to_string('hmsdms’))

# Prints 
# 01h33m50.904s +30d39m35.79s
# 13h33m59.1873s +30d47m03.8071s

Interestingly, the declination isn’t *exactly* the same and the RA doesn’t differ by exactly 12 hours - I wonder why?   But overall you can see the idea for doing what you want. 

Best,

Eric
 

> On Nov 23, 2019, at 2:00 PM, franco basti <franco.basti at gmail.com> wrote:
> 
> 
> Can anyone help me converting from a alt az to ra,dec ?
> all I can find are examples that convert from ra,dec to alt,az
> 
> Thx
> Franco
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3952 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20191123/03eb76b2/attachment.bin>


More information about the AstroPy mailing list