Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 983
Dean Avatar asked Jan 22 '16 17:01

Dean


2 Answers

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.

like image 128
Christoph Avatar answered Oct 06 '22 01:10

Christoph


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.

like image 34
James McCormac Avatar answered Oct 06 '22 00:10

James McCormac