Skip to content

Commit

Permalink
accomodate band/filter when users set sequences for surveys
Browse files Browse the repository at this point in the history
  • Loading branch information
rhiannonlynne committed Jan 25, 2025
1 parent 30257e1 commit c044f1b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
25 changes: 17 additions & 8 deletions rubin_scheduler/scheduler/surveys/field_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FieldSurvey(BaseSurvey):
Parameters
----------
basis_functions : `list` [`rubin_scheduler.scheduler.basis_function`]
List of basis_function objects
List of basis_function objects.
detailers : `list` [`rubin_scheduler.scheduler.detailer`] objects
The detailers to apply to the list of observations.
RA : `float`
Expand Down Expand Up @@ -148,18 +148,20 @@ def __init__(
if nexps is None:
nexps = default_nexps

# Do a little shuffling if this was not configured quite as expected
if isinstance(sequence, str):
# Were we passed something like an ObservationArray or list[ObsArray]
if isinstance(sequence, ObservationArray) | isinstance(sequence[0], ObservationArray):
self.observations = sequence

# Or was the sequence specified by filters, nvisits, exptimes, nexps
else:
# Do a little shuffling if we had the simplest config
if isinstance(nvisits, (float, int)):
nvisits = dict([(bandname, nvisits) for bandname in sequence])
if isinstance(exptimes, (float, int)):
exptimes = dict([(bandname, exptimes) for bandname in sequence])
if isinstance(nexps, (float, int)):
nexps = dict([(bandname, nexps) for bandname in sequence])

if isinstance(sequence, ObservationArray) | isinstance(sequence[0], ObservationArray):
self.observations = sequence
else:
self.observations = []
for bandname in sequence:
for j in range(nvisits[bandname]):
Expand All @@ -172,8 +174,15 @@ def __init__(
obs["scheduler_note"] = self.scheduler_note
self.observations.append(obs)

# Let's just make this an array for ease of use
self.observations = np.concatenate(self.observations)
# Let's just make this an array for ease of use if not already
if not isinstance(self.observations, ObservationArray):
self.observations = np.concatenate(self.observations)
# and backfill "band" if it was set by the user in "filter"
# Need to add "band" here if it wasn't populated
missing_band = np.where(self.observations["band"] == "")
band = np.char.rstrip(self.observations["filter"][missing_band], chars="_0123456789")
self.observations["band"][missing_band] = band

order = np.argsort(self.observations["band"])
self.observations = self.observations[order]

Expand Down
6 changes: 5 additions & 1 deletion rubin_scheduler/scheduler/surveys/scripted_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def set_script(self, obs_wanted, append=True, add_index=True):
columns with dtype names:
Should be from lsst.sim.scheduler.utils.scheduled_observation
mjds : np.array
The MJDs for the observaitons, should be same length as
The MJDs for the observations, should be same length as
obs_list
mjd_tol : float (15.)
The tolerance to consider an observation as still good to
Expand All @@ -305,6 +305,10 @@ def set_script(self, obs_wanted, append=True, add_index=True):
Should the scheduler_note be modified to include a unique
index value. Default True.
"""
# Backfill band if filter was set instead
missing_band = np.where(obs_wanted["band"] == "")
band = np.char.rstrip(obs_wanted["filter"][missing_band], chars="_0123456789")
obs_wanted["band"][missing_band] = band

obs_wanted.sort(order=["mjd", "band"])

Expand Down

0 comments on commit c044f1b

Please sign in to comment.