[AstroPy] RA/Dec to Alt/Az

Richard Moffat richard.moffat at gmail.com
Fri Apr 21 23:37:45 EDT 2023


Hi Eric, Et .al,

Thanks for your prompt reply. Here's the exact piece of code I'm running.
(Note I've again fixed the time to a set time, not a Python-generated
current time).

Note that the Time for the value in the Python script is GMT, which I'm
assuming is what it needs. (A local time, which is 12 hours added, gives a
result that is miles out.) For context, I'm in New Zealand, which you may
have guessed something like that by now :-0

The local sidereal time on the website calculator, mentioned below, gives
4:39:41 (for 15:10, 172 long)

I've run out of ideas.

Expected result:  (verified from yet another calculator at
http://www.stargazing.net/mas/al_az.htm )
Az   165d 26m 39s
Alt   17d 10m 24s

Calculated from the code below
Az   165d 41m 45.97s
Alt   17d 11m 02.40s


Input for the website mentioned above, giving the expected results:
  Date: April 22 2023
  User time: 15 10 00
  Time Zone Offset: 12h east
  Daylight saving time 0
  Lat     -43 30 0
  Long  172 30 0
  Epoch year  2000


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

lat, lon = -43.5, 172.5

observing_location = EarthLocation(lat=lat, lon=lon, height=10 * u.m)

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

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

ra = '14h41m13.3s'
dec = '-60d55m52.3s'

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)






On Sat, 22 Apr 2023 at 13:41, Eric Jensen <ejensen1 at swarthmore.edu> wrote:

> Hi Richard,
>
> Welcome!  This will be easier to troubleshoot if you can give some
> specific input and output.  Can you put in whatever latitude, longitude,
> and time you want, and then show the output from your script, and do the
> same for the other calculators you’re comparing to?  That will help see
> where any problem might lie.
>
> Thanks,
>
> Eric
>
>
> On Apr 21, 2023, at 9:19 PM, Richard Moffat <richard.moffat at gmail.com>
> wrote:
>
> 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)
>
> _______________________________________________
> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20230422/aaeaf0a0/attachment-0001.html>


More information about the AstroPy mailing list