Skip to content

Commit

Permalink
Merge pull request #17 from lsst/u/yoachim/to_sunrise
Browse files Browse the repository at this point in the history
modelobservatory can run all the way to sunrise and set
  • Loading branch information
yoachim authored Dec 21, 2023
2 parents ca1c175 + 380dee7 commit 7f6e0bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions rubin_scheduler/scheduler/model_observatory/model_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def __init__(
downtimes=None,
no_sky=False,
wind_data=None,
starting_time_key="sun_n12_setting",
ending_time_key="sun_n12_rising",
):
"""
Parameters
Expand Down Expand Up @@ -106,6 +108,14 @@ def __init__(
object with a __call__ method that takes the time and returns a
tuple with the wind speed (m/s) and originating direction (radians
east of north)
starting_time_key : str
What key in the almanac to use to determine the start of observing on a night.
Default "sun_n12_setting", e.g., sun at -12 degrees and setting. Other
options are "sun_n18_setting" and "sunset"
ending_time_key : str
What key in the almanac to use to signify it is time to skip to the next night.
Default "sun_n12_rising", e.g., sun at -12 degrees and rising. Other
options are "sun_n18_rising" and "sunrise"
"""

if nside is None:
Expand All @@ -120,6 +130,8 @@ def __init__(
self.alt_min = np.radians(alt_min)
self.lax_dome = lax_dome
self.mjd_start = survey_start_mjd() if mjd_start is None else mjd_start
self.starting_time_key = starting_time_key
self.ending_time_key = ending_time_key

self.sim__to_o = sim_to_o

Expand Down Expand Up @@ -486,18 +498,18 @@ def check_mjd(self, mjd, cloud_skip=20.0):
while clouds > self.cloud_limit:
new_mjd = new_mjd + cloud_skip / 60.0 / 24.0
clouds = self.cloud_data(Time(new_mjd, format="mjd"))
alm_indx = np.searchsorted(self.almanac.sunsets["sunset"], mjd) - 1
alm_indx = np.searchsorted(self.almanac.sunsets["sunset"], mjd, side="right") - 1
# at the end of the night, advance to the next setting twilight
if mjd > self.almanac.sunsets["sun_n12_rising"][alm_indx]:
if mjd > self.almanac.sunsets[self.ending_time_key][alm_indx]:
passed = False
new_mjd = self.almanac.sunsets["sun_n12_setting"][alm_indx + 1]
if mjd < self.almanac.sunsets["sun_n12_setting"][alm_indx]:
new_mjd = self.almanac.sunsets[self.starting_time_key][alm_indx + 1]
if mjd < self.almanac.sunsets[self.starting_time_key][alm_indx]:
passed = False
new_mjd = self.almanac.sunsets["sun_n12_setting"][alm_indx + 1]
new_mjd = self.almanac.sunsets[self.starting_time_key][alm_indx + 1]
# We're in a down night, advance to next night
if not self.check_up(mjd):
passed = False
new_mjd = self.almanac.sunsets["sun_n12_setting"][alm_indx + 1]
new_mjd = self.almanac.sunsets[self.starting_time_key][alm_indx + 1]
# recursive call to make sure we skip far enough ahead
if not passed:
while not passed:
Expand Down
4 changes: 2 additions & 2 deletions rubin_scheduler/site_models/almanac.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def get_sunset_info(self, mjd):
Returns a numpy array with mjds for various events (sunset, moonrise, sun at -12 degrees alt, etc.).
Also the integer night number.
"""
indx = np.searchsorted(self.sunsets["sunset"], mjd) - 1
indx = np.searchsorted(self.sunsets["sunset"], mjd, side="right") - 1
return self.sunsets[indx]

def mjd_indx(self, mjd):
indx = np.searchsorted(self.sunsets["sunset"], mjd) - 1
indx = np.searchsorted(self.sunsets["sunset"], mjd, side="right") - 1
return indx

def get_sun_moon_positions(self, mjd):
Expand Down

0 comments on commit 7f6e0bd

Please sign in to comment.