Is there a sunset/sunrise function built into Astropy yet?
Asked Answered
E

2

7

I have seen a couple of answers referring to PyEphem on here and how that can produce sunset/sunrise times, however it would be more useful to me if I could find a solution using solely Astropy packages. At the moment the closest I have found is the (get_sun) function in the astropy.coordinates package. Is this sunset/sunrise functionality built into Astropy anywhere yet?

Eisenstein answered 22/1, 2016 at 17:23 Comment(1)
Short answer: no. astroplan is perhaps the closest, but I think that also uses PyEphem under the hood (and PyEphem is being replaced by Skyfield nowadays; same author).Nasal
I
19

The Astroplan package has an Observer class with a Observer.sun_rise_time and a Observer.sun_set_time method.

Astroplan is an Astropy affiliated package.

Whether this functionality is going to be put into the core Astropy package in the future or remain in Astroplan isn't clear. But with pip install astroplan or conda install -c astropy astroplan you can easily install Astroplan and use this.

Isopod answered 22/1, 2016 at 20:19 Comment(0)
M
2

It is easy to work out the current position of the sun with get_sun, this could be expanded to determine the next sunrise or sunset time is.

I use the following to check if close to sunrise for an automatic closure of my telescope.

def almostSunrise():                                                                                
    now = Time(datetime.utcnow(), format='datetime', scale='utc')                                  
    altazframe = AltAz(obstime=now, location=lapalma)                                               
    sunaltaz = get_sun(now).transform_to(altazframe)                                                
    if sunaltaz.alt.value >= -5 and sunaltaz.alt.value <= 5:                                         
        return True                                                                                 
    else:                                                                                           
        return False 

where lapalma is an EarthLocation that I've set up.

Marcosmarcotte answered 3/7, 2016 at 1:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.