astropy / astroplan

Observation planning package for astronomers – maintainer @bmorris3
https://astroplan.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
199 stars 109 forks source link

Looking ofr dusks/dawns along a year : TargetNeverUpWarning lead to crash #508

Open tstolarczyk opened 3 years ago

tstolarczyk commented 3 years ago

Hello,

Astroplan v0.8

I am making the list of dusks and dawns along the year 2021 with the code below. It returns Nan (and crashes because of year -4713) on June the 14th because of a too-short night it seems, which is likely to happen every year :-)

I realize this can happen at Pole, i.e. a day without night, but the search within 24 hours is a strange limitation (although it is mentioned in the doc). I guess that I have to check that dusk or dawn is not Nan and rewind to continue, but that's a bit tricky... Any known workaround to suggest? Thanks !!!

from astropy.time import Time
import astropy.units as u

from astropy.coordinates import EarthLocation
from astroplan import Observer
twindow = [Time("2021-06-01 00:00:00.0",scale="utc"),
           Time("2021-12-31 23:59:59.0",scale="utc")]
tstart = twindow[0]
tstop = twindow[1]
location = EarthLocation.of_address("Paris")

obs   = Observer(location  = location, name = location, timezone ="utc")
night = obs.is_night(tstart, horizon = -18*u.deg)

if (night): search = "previous" # Will search start of that night
else:       search = "next"     # Will search next night

t_night=[]

t_dawn = tstart # First dawwn cannot be before start
while(t_dawn < tstop):
        t_dusk = obs.twilight_evening_astronomical(t_dawn, which = search)
        print(" dusk :",t_dusk.datetime)
        search="next"
        t_dawn = obs.twilight_morning_astronomical(t_dusk, which="next")
        print(" dawn :",t_dawn.datetime)
        t_night.append([t_dusk, t_dawn])

Here is the sequence:

 dusk : 2021-06-12 23:35:46.674107
 dawn : 2021-06-13 00:07:07.888164
 dusk : 2021-06-13 23:42:10.162592
 dawn : 2021-06-14 00:02:01.176933
WARNING: TargetNeverUpWarning: Target with index 0 does not cross horizon=-18.0 deg within 24 hours [astroplan.observer]
bmorris3 commented 3 years ago

Hi @tstolarczyk,

As I just wrote in #511, I think this won't be a problem if the time you use as a reference time is centered closer to local noon. As you suggest, this occurs when the querying time is very close to a rise/set, and can be avoided if you start your tstart variable at a time further from dawn/dusk.

Does that help?