Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add method to convert ScheduledObs to regular ObsArray
Browse files Browse the repository at this point in the history
yoachim committed Dec 6, 2024
1 parent a25fd6d commit 135d696
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rubin_scheduler/scheduler/surveys/scripted_surveys.py
Original file line number Diff line number Diff line change
@@ -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 obsarray_concat, ScheduledObservationArray
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
10 changes: 10 additions & 0 deletions rubin_scheduler/scheduler/utils/utils.py
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 135d696

Please sign in to comment.