[AstroPy] Question on the coordinates of the sun: Hour angle instead of RA, how?

Michael Brewer brewer at astro.umass.edu
Tue Jan 2 13:20:15 EST 2024


Paolo,

  Not quite. The RA/Dec coordinates returned by get_body('sun', obs_time,
location) are in the GCRS reference frame. In order to calculate the
apparent hour angle, you need to transform these coordinates to be with
respect to the true equator and equinox of date. This consists of adding
precession and nutation and can be done thusly:

from astropy.coordinates import TETE

apparent_radec = sun.transform_to(TETE(obstime=obs_time, location=location))
RA_Sun = apparent_radec.ra

Regards,

  Michael Brewer


On Tue, Jan 2, 2024 at 1:01 PM Paolo Sereni via AstroPy <astropy at python.org>
wrote:

> Hi Erich,
>
> thank you so much. This is the perfect answer.
>
> Cheers, Paolo
>
> On Tuesday, January 2, 2024 at 06:57:16 PM GMT+1, Eric LN Jensen <
> ejensen1 at swarthmore.edu> wrote:
>
>
> Hi Paolo,
>
> Michael has already given a good answer about how to get hour angle
> directly with astropy routines, but as you’re hoping to teach some of this
> material, it might also be helpful to point out that it’s straightforward
> to calculate HA from the RA you’re already getting from the examples you
> show, plus the related concept of local sidereal time (LST).
>
> LST at any given location gives the RA that is currently on the meridian,
> whereas the hour angle of an object is the amount of time until (or since)
> the object crosses the meridian.  Thus, if you calculate LST from astropy
> routines (e.g.
> https://docs.astropy.org/en/stable/api/astropy.time.Time.html#astropy.time.Time.sidereal_time),
> you can easily find HA from
>
> HA_Sun = LST – RA_Sun
>
> Hope this helps,
>
> Eric
>
>
> On Jan 2, 2024, at 11:23 AM, Paolo Sereni via AstroPy <astropy at python.org>
> wrote:
>
> Hello everyone,
>
> first a couple of words about myself: I am a hobby astronomer and I'm
> presently teaching to future physics school-teachers. In my lesson I would
> like to introduce some very basics concepts of astronomy and I use
> Stellarium as additional tool. My goal is to develop enough material to be
> able to understand and build a sun dial. Since I'm also giving an
> introductory course in python programming, astropy seems to be the perfect
> library to perform some calculations.
>
> Specifically, I would like to be able to calculate for any given day an
> time the *Hour Angle* and Declination of the Sun as seen from Salzburg,
> where I live and teach.
>
> Looking at the impressive documentation of astropy I found two very
> promising examples, however both of them calculate RA (right ascension) and
> DEC instead of HA (Hour Angle) and DEC. I do not know how to solve this
> problem.
>
> I do not know whether I have to use another "frame" (?) or if I have to
> "manually" correct using the Hour Angle of the first point of Aries
> (something like HA = HA_Aries + RA)...???? ( in this case where/how can I
> find HA_Aries?)
>
> Here the code of the two examples:
> -------------------------------------------
> #Variant 1
> import astropy.units as u
> from astropy.coordinates import AltAz, EarthLocation, SkyCoord
> from astropy.time import Time
> from astropy import coordinates
>
> Salzburg = EarthLocation(lat=13.03333*u.deg, lon=47.8*u.deg,
> height=424*u.m)
> #Salzburg time is UTC +1 we need to correct is
> my_time = "2023-12-30T12:00:00"
> my_t = Time(my_time)
> sun_coordinates = coordinates.get_sun(my_t)
> print(type(sun_coordinates))
> print(sun_coordinates)
> print("\n\nCoordinates of the sun:")
> print("\tright ascension:  " + str(sun_coordinates.ra))
> print("\tdeclination:     " + str(sun_coordinates.dec))
> print("\tdistance:         " + str(sun_coordinates.distance))
>
> ---------------------------------------------------
> #Variant 2
> from astropy.coordinates import EarthLocation, Longitude, SkyCoord,
> get_body, solar_system_ephemeris
> from astropy.time import Time
> import astropy.units as u
>
> obs_time = Time('2023-12-30T12:00:00', format='isot', scale='utc')
> location=EarthLocation(lat=13.03333*u.deg, lon=47.8*u.deg, height=424*u.m)
> solar_system_ephemeris.set('de432s')
> sun = get_body('sun', obs_time, location)
> print("sun: " + str(sun))
> print("\n\n")
> aries = SkyCoord(0*u.deg, 0*u.deg, frame='geocentrictrueecliptic',
> obstime=obs_time, equinox=obs_time)
> RA = Longitude(sun.itrs.spherical.lon - aries.itrs.spherical.lon)
> print("RA ="  + str(RA))
> dec = sun.itrs.spherical.lat
> print("DEC = " + str(dec))
>
> -------
>
> Which variant would you recommend me? Any help for obtaining HA will be
> greatly appreciated.
>
> Thank you very much and happy 2024!
>
> Cheers, Paolo Sereni
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
>
> ––––
> Eric Jensen (he/him)
> Professor of Astronomy
> Walter Kemp Professor of the Natural Sciences
> Interim Dean of Academic Success
> Swarthmore College
> Parrish E108, 610-328-8249
>
>
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
> <https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fastropy&data=05%7C02%7Cbrewer%40astro.umass.edu%7C248f0a9c24274d7ecee708dc0bbccca5%7C7bd08b0b33954dc194bbd0b2e56a497f%7C0%7C0%7C638398152719490618%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dT1v4%2BVwHhRFANdZ%2BwYBtiaydGsCZQDRD2pgeOTt1Yw%3D&reserved=0>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
>
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fastropy&data=05%7C02%7Cbrewer%40astro.umass.edu%7C248f0a9c24274d7ecee708dc0bbccca5%7C7bd08b0b33954dc194bbd0b2e56a497f%7C0%7C0%7C638398152719490618%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dT1v4%2BVwHhRFANdZ%2BwYBtiaydGsCZQDRD2pgeOTt1Yw%3D&reserved=0
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20240102/e5a0f11d/attachment.html>


More information about the AstroPy mailing list