Skip to content

Commit

Permalink
SP-1865: Additional changes for use with ts_scheduler v2.3 (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonlynne authored Feb 21, 2025
2 parents 0d7a712 + 2a6f2e4 commit 71f6824
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
11 changes: 4 additions & 7 deletions rubin_scheduler/scheduler/detailers/detailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,10 @@ def __init__(self, band_to_filter_dict=None):
def __call__(self, observation_array, conditions):
u_bands = np.unique(observation_array["band"])
for band in u_bands:
indx = np.where(observation_array["band"] == band)[0]
if band not in self.band_to_filter_dict.keys():
warnings.warn(
"No mapping of band %s to a filter name. Using %s as filter name" % (band, band)
)
observation_array[indx]["filter"] = band
observation_array[indx]["filter"] = self.band_to_filter_dict[band]
indx = np.where(observation_array["band"] == band)
# Fetch the dictionary value or just continue to use band
filtername = self.band_to_filter_dict.get(band, band)
observation_array["filter"][indx] = filtername

return observation_array

Expand Down
12 changes: 0 additions & 12 deletions rubin_scheduler/scheduler/model_observatory/model_observatory.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ class ModelObservatory:
will allow altitudes anywhere between 20-86 degrees.
telescope : `str`
Telescope name for rotation computations. Default "rubin".
band2filter : `dict`
Dictionary for converting band names to filter names.
Default of none will use band names for filter names.
"""

def __init__(
Expand Down Expand Up @@ -171,7 +168,6 @@ def __init__(
sky_alt_limits=None,
sky_az_limits=None,
telescope="rubin",
band2filter=None,
):
self.nside = nside

Expand All @@ -183,12 +179,6 @@ def __init__(
mjd = mjd_start

self.bandlist = ["u", "g", "r", "i", "z", "y"]
if band2filter is None:
self.band2filter = {}
for bandname in self.bandlist:
self.band2filter[bandname] = bandname
else:
self.band2filter = band2filter

self.cloud_limit = cloud_limit
self.no_sky = no_sky
Expand Down Expand Up @@ -566,8 +556,6 @@ def observation_add_data(self, observation):
)
observation["moonPhase"] = sun_moon_info["moon_phase"]

observation["filter"] = self.band2filter[observation["band"][0]]

observation["ID"] = self.obs_id_counter
self.obs_id_counter += 1

Expand Down
4 changes: 4 additions & 0 deletions rubin_scheduler/scheduler/schedulers/core_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ def request_observation(self, mjd=None, whole_queue=False):
else:
result = self.queue.pop(0)

# TODO : Remove this hack which is for use with ts_scheduler
# version <=v2.3 .. remove ts_scheduler actually drops "note".
for obs in result:
obs["note"] = obs["scheduler_note"]
return result

def _fill_queue(self):
Expand Down
15 changes: 14 additions & 1 deletion rubin_scheduler/scheduler/surveys/base_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np
import pandas as pd

from rubin_scheduler.scheduler.detailers import TrackingInfoDetailer, ZeroRotDetailer
from rubin_scheduler.scheduler.detailers import BandToFilterDetailer, TrackingInfoDetailer, ZeroRotDetailer
from rubin_scheduler.scheduler.utils import (
HpInLsstFov,
ObservationArray,
Expand Down Expand Up @@ -131,6 +131,19 @@ def __init__(
observation_reason=observation_reason,
)
)
# There always needs to be a BandToFilterDetailer, to fill in
# 'filter' information for ts_scheduler.
# Check if one exists, add a default if it doesn't.
existing_band_to_filter = False
for detailer in self.detailers:
if isinstance(detailer, BandToFilterDetailer):
existing_band_to_filter = True
if not existing_band_to_filter:
self.detailers.append(
# Set up a detailer that just uses the survey configuration
# band information (which could be band or physical filtername)
BandToFilterDetailer(band_to_filter_dict={})
)

@cached_property
def roi_hpid(self):
Expand Down
3 changes: 3 additions & 0 deletions rubin_scheduler/scheduler/utils/observation_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def __new__(cls, n=1):
("cummTelAz", float),
("observation_reason", "U40"),
("science_program", "U40"),
# TODO : Remove this hack which is for use with ts_scheduler
# version <=v2.3 .. remove ts_scheduler actually drops "note".
("note", "U40"),
]
obj = np.zeros(n, dtype=dtypes).view(cls)
return obj
Expand Down
3 changes: 3 additions & 0 deletions rubin_scheduler/scheduler/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ def obs2opsim(self, obs_array, filename=None, info=None, delete_past=False, if_e
pass

df = pd.DataFrame(obs_array)
# TODO : Remove this hack which is for use with ts_scheduler
# version <=v2.3 .. remove ts_scheduler actually drops "note".
df.drop("note", axis=1, inplace=True)
df = df.rename(index=str, columns=self.inv_map)
for colname in self.angles_rad2deg:
df[colname] = np.degrees(df[colname])
Expand Down
3 changes: 2 additions & 1 deletion rubin_scheduler/site_models/seeing_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ def __init__(
):
if filter_list is not None:
warnings.warn("filter_list deprecated in favor of band_list", FutureWarning)
self.filter_list = filter_list
band_list = filter_list
self.band_list = band_list
# Setting self.filter_list for backward compatibility with ts_scheduler
self.filter_list = band_list
if eff_wavelens is None:
sev = SysEngVals()
eff_wavelens = [sev.eff_wavelengths[f] for f in band_list]
Expand Down
17 changes: 17 additions & 0 deletions tests/scheduler/test_detailers.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ def test_random_band(self):

assert out_obs["band"] == "y"

def test_bandtofilter(self):
obs = ObservationArray(3)
obs["band"][0] = "r"
obs["band"][1] = "g"
obs["band"][2] = "g"

detailer = detailers.BandToFilterDetailer({})
output = detailer(obs, [])
assert np.all(output["band"] == output["filter"])

filtername_dict = {"r": "r_03", "g": "g_01"}
detailer = detailers.BandToFilterDetailer(filtername_dict)
output = detailer(obs, [])

for out in output:
assert out["filter"] == filtername_dict[out["band"]]


if __name__ == "__main__":
unittest.main()

0 comments on commit 71f6824

Please sign in to comment.