[AstroPy] RA/Dec to Alt/Az

Richard Moffat richard.moffat at gmail.com
Fri Apr 21 21:19:28 EDT 2023


Hi

I am trying to convert RA/Dec to Alt/Az. The results I'm getting are a few
minutes out in both directions, but less than one degree.

I've verified this with an online calculator (
https://astrogreg.com/convert_ra_dec_to_alt_az.html), and also with results
from Stellarium - both those two match, unless they are both out and I'm
actually correct!

I've looked through the documentation and searched quite a bit online. I'm
still missing something. Any help would be really appreciated.

(First-time poster here - no flames please if I'm out of order somewhere :-)

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

# lat, lon obviously changed to not give my home address; no, that's
not the problem
lat, lon = -43.5, 172.5
observing_location = EarthLocation(lat=lat, lon=lon, height=10 * u.m)

# gmt_time_str below is actually calculated from real-time in the
script; please assume it's correct
# gmt_time_str = local_time - time_zone_diff

gmt_time_str = '2023-04-22 00:57:00'
observing_time = Time(gmt_time_str)

aa = AltAz(location=observing_location, obstime=observing_time)

# Alpha Centuri
ra = '14h41m13.3s'
# 14.68669
dec = '-60d55m52.3s'
# -60.9311944

coord = SkyCoord(ra, dec, unit=(u.hourangle, u.deg))
azalt_coord = coord.transform_to(aa)

az = azalt_coord.az.to_string(unit=u.deg, sep=':', precision=2, pad=True)
alt = azalt_coord.alt.to_string(unit=u.deg, sep=':', precision=2, pad=True)

print('az alt', az, alt)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20230422/200b157f/attachment.html>


More information about the AstroPy mailing list