Skip to content

Commit

Permalink
updating empty_observation to ObservationArray
Browse files Browse the repository at this point in the history
  • Loading branch information
yoachim committed Sep 13, 2024
1 parent 5eb42df commit d15c6c5
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def add_observations_array(self, observations_array, observations_hpid):
----------
observations_array_in : `np.array`
An array of completed observations (with columns like
rubin_scheduler.scheduler.utils.empty_observation).
rubin_scheduler.scheduler.utils.ObservationArray).
Should be sorted by MJD.
observations_hpid_in : `np.array`
Same as observations_array_in, but larger and with an
Expand Down
2 changes: 0 additions & 2 deletions rubin_scheduler/scheduler/example/example_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,6 @@ def generate_twilight_near_sun(
shadow_minutes=60.0,
max_alt=76.0,
max_elong=60.0,
az_range=180.0,
ignore_obs=["DD", "pair", "long", "blob", "greedy"],
filter_dist_weight=0.3,
time_to_12deg=25.0,
Expand Down Expand Up @@ -1323,7 +1322,6 @@ def generate_twilight_near_sun(
dither=True,
nexp=nexp,
detailers=detailer_list,
az_range=az_range,
twilight_scale=False,
area_required=area_required,
)
Expand Down
8 changes: 4 additions & 4 deletions rubin_scheduler/scheduler/features/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def add_observation(self, observation, indx=None, **kwargs):
observation : `np.array`, (1,N)
Array of observation information, containing
`mjd` for the time. See
`rubin_scheduler.scheduler.utils.empty_observation`.
`rubin_scheduler.scheduler.utils.ObservationArray`.
indx : `list`-like of [`int`]
The healpixel indices that the observation overlaps.
See `rubin_scheduler.utils.HpInLsstFov`.
Expand Down Expand Up @@ -366,7 +366,7 @@ def __init__(self, scheduler_note=None, survey_name=None):
else:
self.scheduler_note = scheduler_note
# Start out with an empty observation
self.feature = utils.empty_observation()
self.feature = utils.ObservationArray()

def add_observations_array(self, observations_array, observations_hpid):
if self.scheduler_note is not None:
Expand Down Expand Up @@ -394,7 +394,7 @@ def __init__(self, sequence_ids=""):
self.sequence_ids = sequence_ids # The ids of all sequence
# observations...
# Start out with an empty observation
self.feature = utils.empty_observation()
self.feature = utils.ObservationArray()

Check warning on line 397 in rubin_scheduler/scheduler/features/features.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/features/features.py#L397

Added line #L397 was not covered by tests
send_unused_deprecation_warning(self.__class__.__name__)

def add_observation(self, observation, indx=None):
Expand Down Expand Up @@ -672,7 +672,7 @@ def season_update(self, observation=None, conditions=None):
observation : `np.array`, (1,N)
Array of observation information, containing
`mjd` for the time. See
`rubin_scheduler.scheduler.utils.empty_observation`.
`rubin_scheduler.scheduler.utils.ObservationArray`.
conditions : `rubin_scheduler.scheduler.Conditions`, optional
A conditions object, containing `mjd`.
Expand Down
4 changes: 2 additions & 2 deletions rubin_scheduler/scheduler/schedulers/core_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
HpInComcamFov,
HpInLsstFov,
IntRounded,
empty_observation,
ObservationArray,
set_default_nside,
)
from rubin_scheduler.utils import _approx_altaz2pa, _approx_ra_dec2_alt_az, _hpid2_ra_dec, rotation_converter
Expand Down Expand Up @@ -155,7 +155,7 @@ def add_observation(self, observation):
# Catch if someone passed in a slice of an observation
# rather than a full observation array
if len(observation.shape) == 0:
full_obs = empty_observation()
full_obs = ObservationArray()
full_obs[0] = observation
observation = full_obs

Expand Down
6 changes: 3 additions & 3 deletions rubin_scheduler/scheduler/sim_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas as pd

from rubin_scheduler.scheduler.schedulers import SimpleFilterSched
from rubin_scheduler.scheduler.utils import SchemaConverter, empty_observation, run_info_table
from rubin_scheduler.scheduler.utils import ObservationArray, SchemaConverter, run_info_table
from rubin_scheduler.utils import Site, _approx_altaz2pa, pseudo_parallactic_angle, rotation_converter


Expand Down Expand Up @@ -81,7 +81,7 @@ def sim_runner(
observatory.mjd = mjd

end_mjd = mjd + survey_length
observations = empty_observation(n=start_result_size)
observations = ObservationArray(n=start_result_size)
mjd_track = mjd + 0
step = 1.0 / 24.0
step_none = step_none / 60.0 / 24.0 # to days
Expand Down Expand Up @@ -132,7 +132,7 @@ def sim_runner(
filter_scheduler.add_observation(completed_obs)
counter += 1
if counter == observations.size:
add_observations = empty_observation(n=append_result_size)
add_observations = ObservationArray(n=append_result_size)

Check warning on line 135 in rubin_scheduler/scheduler/sim_runner.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/sim_runner.py#L135

Added line #L135 was not covered by tests
observations = np.concatenate([observations, add_observations])

if record_rewards:
Expand Down
11 changes: 5 additions & 6 deletions rubin_scheduler/scheduler/surveys/base_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from rubin_scheduler.scheduler.detailers import TrackingInfoDetailer, ZeroRotDetailer
from rubin_scheduler.scheduler.utils import (
HpInLsstFov,
ObservationArray,
comcam_tessellate,
empty_observation,
set_default_nside,
thetaphi2xyz,
xyz2thetaphi,
Expand Down Expand Up @@ -151,10 +151,9 @@ def add_observations_array(self, observations_array_in, observations_hpid_in):
Parameters
----------
observations_array_in : np.array
An array of completed observations
(with columns like
rubin_scheduler.scheduler.utils.empty_observation).
observations_array_in : ObservationArray
An array of completed observations,
rubin_scheduler.scheduler.utils.ObservationArray
observations_hpid_in : np.array
Same as observations_array_in, but larger and with an
additional column for HEALpix id. Each observation is
Expand Down Expand Up @@ -249,7 +248,7 @@ def generate_observations_rough(self, conditions):
# latest info, calculate it
if not self.reward_checked:
self.reward = self.calc_reward_function(conditions)
obs = empty_observation()
obs = ObservationArray()

Check warning on line 251 in rubin_scheduler/scheduler/surveys/base_survey.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/surveys/base_survey.py#L251

Added line #L251 was not covered by tests
return [obs]

def generate_observations(self, conditions):
Expand Down
6 changes: 3 additions & 3 deletions rubin_scheduler/scheduler/surveys/dd_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import rubin_scheduler.scheduler.basis_functions as basis_functions
from rubin_scheduler.scheduler import features
from rubin_scheduler.scheduler.surveys import BaseSurvey
from rubin_scheduler.scheduler.utils import empty_observation
from rubin_scheduler.scheduler.utils import ObservationArray
from rubin_scheduler.utils import ddf_locations, ra_dec2_hpid

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -84,7 +84,7 @@ def __init__(
self.observations = []
for num, filtername in zip(nvis, sequence):
for j in range(num):
obs = empty_observation()
obs = ObservationArray()

Check warning on line 87 in rubin_scheduler/scheduler/surveys/dd_surveys.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/surveys/dd_surveys.py#L87

Added line #L87 was not covered by tests
obs["filter"] = filtername
if filtername == "u":
obs["exptime"] = u_exptime
Expand Down Expand Up @@ -401,7 +401,7 @@ def generate_dd_surveys(
for filtername, nvis in zip(filters, nviss):
for ra, dec, suffix in zip(r_as, decs, suffixes):
for num in range(nvis):
obs = empty_observation()
obs = ObservationArray()

Check warning on line 404 in rubin_scheduler/scheduler/surveys/dd_surveys.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/surveys/dd_surveys.py#L404

Added line #L404 was not covered by tests
obs["filter"] = filtername
if filtername == "u":
obs["exptime"] = u_exptime
Expand Down
8 changes: 4 additions & 4 deletions rubin_scheduler/scheduler/surveys/ddf_presched.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np

from rubin_scheduler.data import get_data_dir
from rubin_scheduler.scheduler.utils import scheduled_observation
from rubin_scheduler.scheduler.utils import ScheduledObservationArray
from rubin_scheduler.site_models import Almanac
from rubin_scheduler.utils import calc_season, ddf_locations, survey_start_mjd

Expand Down Expand Up @@ -449,7 +449,7 @@ def generate_ddf_scheduled_obs(
for mjd in mjds:
for filtername, nvis, nexp in zip(filters, nvis_master, nsnaps):
if "EDFS" in ddf_name:
obs = scheduled_observation(n=int(nvis / 2))
obs = ScheduledObservationArray(n=int(nvis / 2))
obs["RA"] = np.radians(ddfs[ddf_name][0])
obs["dec"] = np.radians(ddfs[ddf_name][1])
obs["mjd"] = mjd
Expand All @@ -470,7 +470,7 @@ def generate_ddf_scheduled_obs(
obs["sun_alt_max"] = sun_alt_max
all_scheduled_obs.append(obs)

obs = scheduled_observation(n=int(nvis / 2))
obs = ScheduledObservationArray(n=int(nvis / 2))
obs["RA"] = np.radians(ddfs[ddf_name.replace("_a", "_b")][0])
obs["dec"] = np.radians(ddfs[ddf_name.replace("_a", "_b")][1])
obs["mjd"] = mjd
Expand All @@ -495,7 +495,7 @@ def generate_ddf_scheduled_obs(
all_scheduled_obs.append(obs)

else:
obs = scheduled_observation(n=nvis)
obs = ScheduledObservationArray(n=nvis)
obs["RA"] = np.radians(ddfs[ddf_name][0])
obs["dec"] = np.radians(ddfs[ddf_name][1])
obs["mjd"] = mjd
Expand Down
4 changes: 2 additions & 2 deletions rubin_scheduler/scheduler/surveys/desc_ddf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import rubin_scheduler.scheduler.basis_functions as basis_functions
from rubin_scheduler.scheduler.surveys import BaseSurvey
from rubin_scheduler.scheduler.utils import empty_observation
from rubin_scheduler.scheduler.utils import ObservationArray


class DescDdf(BaseSurvey):
Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(
self.reward_value = reward_value
self.flush_pad = flush_pad / 60.0 / 24.0 # To days

self.simple_obs = empty_observation()
self.simple_obs = ObservationArray()

Check warning on line 45 in rubin_scheduler/scheduler/surveys/desc_ddf.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/surveys/desc_ddf.py#L45

Added line #L45 was not covered by tests
self.simple_obs["RA"] = np.radians(RA)
self.simple_obs["dec"] = np.radians(dec)
self.simple_obs["exptime"] = exptime
Expand Down
11 changes: 5 additions & 6 deletions rubin_scheduler/scheduler/surveys/field_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from rubin_scheduler.utils import ra_dec2_hpid

from ..features import LastObservation, NObsSurvey
from ..utils import empty_observation
from ..utils import ObservationArray
from . import BaseSurvey


Expand Down Expand Up @@ -176,7 +176,7 @@ def __init__(
self.observations = []
for filtername in sequence:
for j in range(nvisits[filtername]):
obs = empty_observation()
obs = ObservationArray()
obs["filter"] = filtername
obs["exptime"] = exptimes[filtername]
obs["RA"] = self.ra
Expand Down Expand Up @@ -266,10 +266,9 @@ def add_observations_array(self, observations_array_in, observations_hpid_in):
Parameters
----------
observations_array_in : np.array
An array of completed observations
(with columns like
rubin_scheduler.scheduler.utils.empty_observation).
observations_array_in : ObservationArray
An array of completed observations,
rubin_scheduler.scheduler.utils.ObservationArray
observations_hpid_in : np.array
Same as observations_array_in, but larger and with an
additional column for HEALpix id. Each observation is
Expand Down
4 changes: 2 additions & 2 deletions rubin_scheduler/scheduler/surveys/long_gap_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pandas as pd

from rubin_scheduler.scheduler.surveys import BaseSurvey
from rubin_scheduler.scheduler.utils import scheduled_observation
from rubin_scheduler.scheduler.utils import ScheduledObservationArray
from rubin_scheduler.utils import Site, _approx_ra_dec2_alt_az

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -125,7 +125,7 @@ def _schedule_obs(self, observations):
# If the incoming observation needs to have something
# scheduled later
if np.size(need_to_observe) > 0:
sched_array = scheduled_observation(n=need_to_observe.size)
sched_array = ScheduledObservationArray(n=need_to_observe.size)
for dt in np.intersect1d(observations.dtype.names, sched_array.dtype.names):
if np.size(observations) == 1:
sched_array[dt] = observations[dt]
Expand Down
2 changes: 1 addition & 1 deletion rubin_scheduler/scheduler/surveys/pointings_survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PointingsSurvey(BaseSurvey):
----------
observations : `np.array`
An array of observations, from e.g.,
rubin_scheduler.scheduler.utils.empty_observation
rubin_scheduler.scheduler.utils.ObservationArray
expect "RA", "dec", and "note" to be filled, other columns ignored.
gap_min : `float`
The minimum gap to force between observations of the same
Expand Down
4 changes: 2 additions & 2 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 empty_observation, set_default_nside
from rubin_scheduler.scheduler.utils import ObservationArray, set_default_nside
from rubin_scheduler.utils import _angular_separation, _approx_ra_dec2_alt_az

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -164,7 +164,7 @@ def calc_reward_function(self, conditions):

def _slice2obs(self, obs_row):
"""take a slice and return a full observation object"""
observation = empty_observation()
observation = ObservationArray()
for key in [
"RA",
"dec",
Expand Down
6 changes: 3 additions & 3 deletions rubin_scheduler/scheduler/surveys/surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

from rubin_scheduler.scheduler.surveys import BaseMarkovSurvey
from rubin_scheduler.scheduler.utils import empty_observation, int_binned_stat, order_observations
from rubin_scheduler.scheduler.utils import ObservationArray, int_binned_stat, order_observations
from rubin_scheduler.utils import _angular_separation, _hpid2_ra_dec, hp_grow_argsort


Expand Down Expand Up @@ -87,7 +87,7 @@ def generate_observations_rough(self, conditions):
best_fields = np.unique(self.hp2fields[best_hp])
observations = []
for field in best_fields:
obs = empty_observation()
obs = ObservationArray()
obs["RA"] = self.fields["RA"][field]
obs["dec"] = self.fields["dec"][field]
obs["rotSkyPos"] = 0.0
Expand Down Expand Up @@ -505,7 +505,7 @@ def generate_observations_rough(self, conditions):

for i, indx in enumerate(better_order):
field = self.best_fields[indx]
obs = empty_observation()
obs = ObservationArray()
obs["RA"] = self.fields["RA"][field]
obs["dec"] = self.fields["dec"][field]
obs["rotSkyPos"] = 0.0
Expand Down
10 changes: 4 additions & 6 deletions rubin_scheduler/scheduler/surveys/too_scripted_surveys.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from rubin_scheduler.scheduler.surveys import BaseMarkovSurvey, ScriptedSurvey
from rubin_scheduler.scheduler.utils import (
ScheduledObservationArray,
comcam_tessellate,
order_observations,
scheduled_observation,
thetaphi2xyz,
xyz2thetaphi,
)
Expand Down Expand Up @@ -169,10 +169,8 @@ def set_script(self, obs_wanted, append=True):
"""
Parameters
----------
obs_wanted : np.array
The observations that should be executed. Needs to have
columns with dtype names:
Should be from lsst.sim.scheduler.utils.scheduled_observation
obs_wanted : rubin_scheduler.scheduler.utils.ScheduledObservationArray
The observations that should be executed.
append : bool
Should the obs_wanted be appended to any script already set?
"""
Expand Down Expand Up @@ -363,7 +361,7 @@ def _new_event(self, target_o_o, conditions):
if exptime > 119:
nexp = int(np.round(exptime / 30.0))

obs = scheduled_observation(ras.size)
obs = ScheduledObservationArray(ras.size)

Check warning on line 364 in rubin_scheduler/scheduler/surveys/too_scripted_surveys.py

View check run for this annotation

Codecov / codecov/patch

rubin_scheduler/scheduler/surveys/too_scripted_surveys.py#L364

Added line #L364 was not covered by tests
obs["RA"] = ras
obs["dec"] = decs
obs["mjd"] = mjd0 + time
Expand Down
9 changes: 2 additions & 7 deletions rubin_scheduler/scheduler/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def restore_scheduler(observation_id, scheduler, observatory, in_obs, filter_sch
The observaotry object
in_obs : np.array or str
Array of observations (formated like
rubin_scheduler.scheduler.empty_observation). If a string,
rubin_scheduler.scheduler.ObservationArray). If a string,
assumed to be a file and SchemaConverter is used to load it.
filter_sched : rubin_scheduler.scheduler.scheduler object
The filter scheduler. Note that we don't look up the official
Expand All @@ -214,10 +214,6 @@ def restore_scheduler(observation_id, scheduler, observatory, in_obs, filter_sch
good_obs = np.where(observations["ID"] <= observation_id)[0]
observations = observations[good_obs]

# replay the observations back into the scheduler
# In the future, may be able to replace this with a
# faster .add_observations_array method.

if fast:
scheduler.add_observations_array(observations)
obs = observations[-1]
Expand Down Expand Up @@ -422,7 +418,6 @@ def __init__(self):
"target_name": "target_name",
"science_program": "science_program",
"observation_reason": "observation_reason",
"json_block": "json_block",
}
# For backwards compatibility
self.backwards = {"target": "target_name"}
Expand Down Expand Up @@ -535,7 +530,7 @@ def opsimdf2obs(self, df) -> np.recarray:

df = df.rename(index=str, columns=self.convert_dict)

blank = empty_observation()
blank = ObservationArray()
final_result = np.empty(df.shape[0], dtype=blank.dtype)
# XXX-ugh, there has to be a better way.
for key in final_result.dtype.names:
Expand Down
Loading

0 comments on commit d15c6c5

Please sign in to comment.