[AstroPy] RA/Dec to Alt/Az

Mohammad Shameoni Niaei m.shemuni at gmail.com
Sat Apr 22 04:19:47 EDT 2023


Hello Richard

The online calculator you used has no input for height from sea level. So
it would assume the Earth is a perfect sphere?

For the Stellarium, I don't know if you set the location correctly or not.

But this kind of very small difference mostly occurs due to the different
heights. You can change the height of EarthLocation and you will see how it
changes.
So please,

   1. Check your Stellarium's location settings. See if it matches with
   astropy (10 m).
   2. Set your EarthLocation's height to 0m and see if it matches.


My best


On Sat, Apr 22, 2023 at 6:38 AM Richard Moffat <richard.moffat at gmail.com>
wrote:

> 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
>>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>


-- 
Mohammad Shameoni Niaei
Astronomer
Atatürk University, Astrophysics Research and Application Center.
ERZURUM-TURKEY
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20230422/78780763/attachment.html>


More information about the AstroPy mailing list