Skip to content

Commit

Permalink
Add no-filter version of slewtime basis function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonlynne committed Jan 25, 2025
1 parent c044f1b commit 69e1167
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions rubin_scheduler/scheduler/basis_functions/basis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"BandChangeBasisFunction",
"FilterChangeBasisFunction",
"SlewtimeBasisFunction",
"SlewtimeNoBandBasisFunction",
"CadenceEnhanceBasisFunction",
"CadenceEnhanceTrapezoidBasisFunction",
"AzimuthBasisFunction",
Expand Down Expand Up @@ -970,6 +971,47 @@ def _calc_value(self, conditions, indx=None):
return result


class SlewtimeNoBandBasisFunction(BaseBasisFunction):
"""Reward slews that take little time - but do not consider bandpass.
This is appropriate for some surveys, within some scheduler
environments - but note that the predicted slewtime will be
incorrect if a filter change was required.
Parameters
----------
max_time : `float`
The estimated maximum slewtime (seconds).
Used to normalize so the basis function spans ~ -1-0
in reward units. Default 135 seconds corresponds to just
slightly less than a band change.
nside : `int`, optional
Nside for the basis function.
Default None will use `set_default_nside()`.
"""

def __init__(self, max_time=135.0, nside=DEFAULT_NSIDE):
super().__init__(nside=nside)

self.maxtime = max_time
self.nside = nside

def _calc_value(self, conditions, indx=None):
# Just calculate slewtime ignoring bandpass change requirement.
# Need to make sure smaller slewtime is larger reward.
if np.size(conditions.slewtime) > 1:
# Slewtime map can contain nans and/or
# infs - mask these with nans
result = np.where(
np.isfinite(conditions.slewtime),
-conditions.slewtime / self.maxtime,
np.nan,
)
else:
result = -conditions.slewtime / self.maxtime
return result


class CadenceEnhanceBasisFunction(BaseBasisFunction):
"""Drive a certain cadence
Expand Down Expand Up @@ -1437,6 +1479,7 @@ class RewardNObsSequence(BaseBasisFunction):
This basis function is useful when a survey is composed of more than
one observation (e.g. in different bands) and one wants to make sure
they are all taken together.
If the sequence is programmed into the FieldSurvey, this isn't necessary.
"""

def __init__(self, n_obs_survey, note_survey, nside=DEFAULT_NSIDE):
Expand Down
1 change: 1 addition & 0 deletions tests/scheduler/test_basisfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def test_basics(self):
basis_functions.StrictBandBasisFunction,
basis_functions.BandChangeBasisFunction,
basis_functions.SlewtimeBasisFunction,
basis_functions.SlewtimeNoBandBasisFunction,
basis_functions.AzModuloBasisFunction,
basis_functions.DecModuloBasisFunction,
basis_functions.NearSunHighAirmassBasisFunction,
Expand Down

0 comments on commit 69e1167

Please sign in to comment.