Skip to content

Commit

Permalink
add method to convert ScheduledObs to regular ObsArray
Browse files Browse the repository at this point in the history
s
  • Loading branch information
yoachim committed Dec 13, 2024
1 parent a25fd6d commit 9f2572a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions rubin_scheduler/scheduler/detailers/detailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion rubin_scheduler/scheduler/detailers/dither_detailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion rubin_scheduler/scheduler/detailers/vary_exptime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions rubin_scheduler/scheduler/surveys/scripted_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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.
Expand Down

0 comments on commit 9f2572a

Please sign in to comment.