Skip to content

Commit

Permalink
move band to filter mapping to CoreScheduler (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim authored Feb 27, 2025
2 parents fc9efff + c1a1709 commit f36e8d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
21 changes: 20 additions & 1 deletion rubin_scheduler/scheduler/schedulers/core_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ class CoreScheduler:
telescope : `str`
Which telescope model to use for rotTelPos/rotSkyPos conversions.
Default "rubin".
target_id_counter : int
target_id_counter : `int`
Starting value for the target_id. If restarting observations, could
be useful to set to whatever value the scheduler was at previously.
Default 0.
band2filter : `dict`
Dict for mapping band name to filter name if filter has not been
specified. Default of None maps 'ugrizy' to the same. Empty dict
will do no mapping for missing "filter" values.
"""

def __init__(
Expand All @@ -56,6 +60,7 @@ def __init__(
keep_rewards=False,
telescope="rubin",
target_id_counter=0,
band_to_filter=None,
):
self.keep_rewards = keep_rewards
# Use integer ns just to be sure there are no rounding issues.
Expand Down Expand Up @@ -101,6 +106,14 @@ def __init__(
self.queue_fill_mjd_ns = -1
self.queue_reward_df = None

# Set mapping of band to filter if filter is missing
if band_to_filter is None:
self.band_to_filter_dict = {}
for bandname in "ugrizy":
self.band_to_filter_dict[bandname] = bandname
else:
self.band_to_filter_dict = band_to_filter

def flush_queue(self):
"""Like it sounds, clear any currently queued desired observations."""
self.queue = []
Expand Down Expand Up @@ -341,6 +354,12 @@ def _fill_queue(self):
result["target_id"] = np.arange(self.target_id_counter, self.target_id_counter + result.size)
self.target_id_counter += result.size

# Check that filter has been set
need_filtername_indx = np.where((result["filter"] == "") | (result["filter"] is None))[0]
if len(self.band_to_filter_dict) > 0:
for indx in need_filtername_indx:
result[indx]["filter"] = self.band_to_filter_dict[result[indx]["band"]]

# Convert to a list for the queue
self.queue = result.tolist()
self.queue_filled = self.conditions.mjd
Expand Down
15 changes: 1 addition & 14 deletions 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 BandToFilterDetailer, TrackingInfoDetailer, ZeroRotDetailer
from rubin_scheduler.scheduler.detailers import TrackingInfoDetailer, ZeroRotDetailer
from rubin_scheduler.scheduler.utils import (
HpInLsstFov,
ObservationArray,
Expand Down Expand Up @@ -131,19 +131,6 @@ 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
4 changes: 4 additions & 0 deletions rubin_scheduler/scheduler/surveys/too_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class TooMaster(BaseSurvey):
"""

def __init__(self, example__to_o_survey):
message = "TooMaster unused and planned to be deprecated."
warnings.warn(message, FutureWarning)
self.example__to_o_survey = example__to_o_survey
self.surveys = []
self.highest_reward = -np.inf
Expand Down Expand Up @@ -124,6 +126,8 @@ def __init__(
filtername2=None,
filter_change_approx=None,
):
message = "TooSurvey unused and planned to be deprecated."
warnings.warn(message, FutureWarning)
if filtername1 is not None:
warnings.warn("filtername1 deprecated in favor of bandname1", FutureWarning)
bandname1 = filtername1
Expand Down

0 comments on commit f36e8d2

Please sign in to comment.