Skip to content

Commit

Permalink
Merge pull request #357 from lsst/tickets/OPSIM-1073
Browse files Browse the repository at this point in the history
OPSIM-1073: Modify filter scheduler (u/y swap default) and update twilight survey feasibility function
  • Loading branch information
yoachim authored Sep 9, 2023
2 parents ba43a4d + 13a903c commit f76f5e0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
22 changes: 22 additions & 0 deletions rubin_sim/scheduler/basis_functions/basis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"AvoidDirectWind",
"BalanceVisits",
"RewardNObsSequence",
"FilterDistBasisFunction",
)

import warnings
Expand Down Expand Up @@ -194,6 +195,27 @@ def check_feasibility(self, conditions):
return result


class FilterDistBasisFunction(BaseBasisFunction):
"""Track filter distribution, increase reward as fraction of observations in
specified filter drops.
"""

def __init__(self, filtername="r"):
super(FilterDistBasisFunction, self).__init__(filtername=filtername)

self.survey_features = {}
# Count of all the observations
self.survey_features["n_obs_count_all"] = features.NObsCount(filtername=None)
# Count in filter
self.survey_features["n_obs_count_in_filt"] = features.NObsCount(filtername=filtername)

def _calc_value(self, conditions, indx=None):
result = self.survey_features["n_obs_count_all"].feature / (
self.survey_features["n_obs_count_in_filt"].feature + 1
)
return result


class NObsPerYearBasisFunction(BaseBasisFunction):
"""Reward areas that have not been observed N-times in the last year
Expand Down
40 changes: 40 additions & 0 deletions rubin_sim/scheduler/basis_functions/feasibility_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"EndOfEveningBasisFunction",
"TimeToScheduledBasisFunction",
"LimitObsPnightBasisFunction",
"SunHighLimitBasisFunction",
)

import matplotlib.pylab as plt
Expand Down Expand Up @@ -52,6 +53,45 @@ def check_feasibility(self, conditions):
return result


class SunHighLimitBasisFunction(BaseBasisFunction):
"""Only execute if the sun is high. Have a sum alt limit for sunset, and a time
until 12 degree twilight for sun rise.
Parameters
----------
sun_alt_limit : `float`
The sun altitude limit (degrees). Sun must be higher than this at sunset to execute
time_to_12deg : `float`
How much time must be remaining before 12 degree twilight in the morning (minutes)
time_remaining : `float`
Minimum about of time that must be available before trying to execute (minutes)
"""

def __init__(self, sun_alt_limit=-14.8, time_to_12deg=21.0, time_remaining=15.0):
super(SunHighLimitBasisFunction, self).__init__()
if time_to_12deg < time_remaining:
raise ValueError(
"time_to_12deg value of %f is less than time_remaining value of %f."
% (time_to_12deg, time_remaining)
)
self.sun_alt_limit = np.radians(sun_alt_limit)
self.time_to_12deg = time_to_12deg / 60.0 / 24.0
self.time_remaining = time_remaining / 60.0 / 24.0

def check_feasibility(self, conditions):
result = False

# If the sun is high, it's ok to execute
if conditions.sun_alt > self.sun_alt_limit:
result = True
time_left = conditions.sun_n12_rising - conditions.mjd
if time_left < self.time_to_12deg:
result = True
if time_left < self.time_remaining:
result = False
return result


class OnceInNightBasisFunction(BaseBasisFunction):
"""Stop observing if something has been executed already in the night
Expand Down
2 changes: 1 addition & 1 deletion rubin_sim/scheduler/schedulers/filter_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def __call__(self, conditions):
if IntRounded(conditions.moon_phase) > self.illum_limit_ir:
result = ["g", "r", "i", "z", "y"]
else:
result = ["u", "g", "r", "i", "y"]
result = ["u", "g", "r", "i", "z"]
return result


Expand Down

0 comments on commit f76f5e0

Please sign in to comment.