From 9f2572a61fabb915b0c7c390d0bee5b89fce13bd Mon Sep 17 00:00:00 2001 From: Peter Yoachim Date: Fri, 6 Dec 2024 11:40:18 -0800 Subject: [PATCH] add method to convert ScheduledObs to regular ObsArray s --- rubin_scheduler/scheduler/detailers/detailer.py | 6 +++--- rubin_scheduler/scheduler/detailers/dither_detailer.py | 2 +- rubin_scheduler/scheduler/detailers/vary_exptime.py | 1 - rubin_scheduler/scheduler/surveys/scripted_surveys.py | 7 ++++--- rubin_scheduler/scheduler/utils/utils.py | 10 ++++++++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/rubin_scheduler/scheduler/detailers/detailer.py b/rubin_scheduler/scheduler/detailers/detailer.py index b7fd89ea..f7c452fd 100644 --- a/rubin_scheduler/scheduler/detailers/detailer.py +++ b/rubin_scheduler/scheduler/detailers/detailer.py @@ -103,7 +103,7 @@ def __init__(self, target_name=None, science_program=None, observation_reason=No def __call__(self, observation_array, conditions): for key in self.keys: - indx = np.where((observation_array[key] == "") | (observation_array[key] == None))[0] + indx = np.where((observation_array[key] == "") | (observation_array[key] is None))[0] observation_array[key][indx] = getattr(self, key) return observation_array @@ -498,9 +498,9 @@ def __init__(self, filtername="u", nexp=1, exptime=None): def __call__(self, observation_array, conditions): indx = np.where(observation_array["filter"] == self.filtername)[0] - observation_array[indx]["nexp"] = self.nexp + observation_array["nexp"][indx] = self.nexp if self.exptime is not None: - observation_array[indx]["exptime"] = self.exptime + observation_array["exptime"][indx] = self.exptime return observation_array diff --git a/rubin_scheduler/scheduler/detailers/dither_detailer.py b/rubin_scheduler/scheduler/detailers/dither_detailer.py index f73041f2..9a5b92f7 100644 --- a/rubin_scheduler/scheduler/detailers/dither_detailer.py +++ b/rubin_scheduler/scheduler/detailers/dither_detailer.py @@ -9,7 +9,7 @@ import numpy as np from rubin_scheduler.scheduler.detailers import BaseDetailer -from rubin_scheduler.scheduler.utils import obsarray_concat, wrap_ra_dec +from rubin_scheduler.scheduler.utils import wrap_ra_dec from rubin_scheduler.utils import ( _approx_altaz2pa, _approx_ra_dec2_alt_az, diff --git a/rubin_scheduler/scheduler/detailers/vary_exptime.py b/rubin_scheduler/scheduler/detailers/vary_exptime.py index 57ef3077..d5719523 100644 --- a/rubin_scheduler/scheduler/detailers/vary_exptime.py +++ b/rubin_scheduler/scheduler/detailers/vary_exptime.py @@ -5,7 +5,6 @@ from scipy.stats import binned_statistic from rubin_scheduler.scheduler.detailers import BaseDetailer -from rubin_scheduler.scheduler.utils import obsarray_concat from rubin_scheduler.skybrightness_pre import dark_sky from rubin_scheduler.utils import DEFAULT_NSIDE, Site, _ra_dec2_hpid, hpid2_ra_dec, m5_flat_sed diff --git a/rubin_scheduler/scheduler/surveys/scripted_surveys.py b/rubin_scheduler/scheduler/surveys/scripted_surveys.py index 2dd01f75..bfd28323 100644 --- a/rubin_scheduler/scheduler/surveys/scripted_surveys.py +++ b/rubin_scheduler/scheduler/surveys/scripted_surveys.py @@ -6,7 +6,7 @@ import numpy as np from rubin_scheduler.scheduler.surveys import BaseSurvey -from rubin_scheduler.scheduler.utils import ObservationArray, ScheduledObservationArray +from rubin_scheduler.scheduler.utils import ScheduledObservationArray, obsarray_concat from rubin_scheduler.utils import DEFAULT_NSIDE, _angular_separation, _approx_ra_dec2_alt_az log = logging.getLogger(__name__) @@ -318,7 +318,7 @@ def set_script(self, obs_wanted, append=True, add_index=True): self.id_start = self.script_id_array.max() + 1 if append & (self.obs_wanted is not None): - self.obs_wanted = np.concatenate([self.obs_wanted, obs_wanted]) + self.obs_wanted = obsarray_concat([self.obs_wanted, obs_wanted]) self.obs_wanted.sort(order=["mjd", "filter"]) else: self.obs_wanted = obs_wanted @@ -373,5 +373,6 @@ def generate_observations_rough(self, conditions): return self.observations self.last_mjd = conditions.mjd - + # Cache results, convert to ObservationArray + self.observations = observations.to_observation_array() return self.observations diff --git a/rubin_scheduler/scheduler/utils/utils.py b/rubin_scheduler/scheduler/utils/utils.py index 9c53f659..66274b23 100644 --- a/rubin_scheduler/scheduler/utils/utils.py +++ b/rubin_scheduler/scheduler/utils/utils.py @@ -793,6 +793,16 @@ def __new__(cls, n=1): obj = np.zeros(n, dtype=dtypes1 + dtype2).view(cls) return obj + def to_observation_array(self): + """Convert the scheduled observation to a + Regular ObservationArray + """ + result = ObservationArray(n=self.size) + in_common = np.intersect1d(self.dtype.names, result.dtype.names) + for key in in_common: + result[key] = self[key] + return result + def obsarray_concat(in_arrays): """Concatenate ObservationArray objects.