# [AstroPy] Convert from AltAz to ICRS

Eric Jensen ejensen1 at swarthmore.edu
Tue Nov 26 07:58:58 EST 2019

```> On Nov 26, 2019, at 12:06 AM, keithmclaurin at gmail.com wrote:
>
> The RA and dec changes mostly due to precession is my understanding.

Thanks for responding.  A quick back-of-the-envelope calculation shows that precession (360 degrees in 26,000 years) should be less than 0.1 arcsecond over 12 hours, whereas the difference here is quite a bit bigger, about 7.5 arcminutes.  So it must be something else - maybe some internal rounding or (more likely) some more subtle misunderstanding by me of some conversion / reference frame issue.  In any case, it’s not really germane to the original query, but still has my curiosity piqued.

Eric

>
>> On Nov 23, 2019, at 15:20, Eric Jensen <ejensen1 at swarthmore.edu> wrote:
>>
>> Hi Franco,
>>
>> You can use the same transform_to method that is given in the example docs, just in the other direction, e.g.
>>
>>
>> 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:
>> print(m33.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
>>
>> _______________________________________________
>> AstroPy mailing list
>> AstroPy at python.org
>> https://mail.python.org/mailman/listinfo/astropy
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
```