Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPSIM-1157: Add ObservationsArray - change observations to proper numpy subclass #102

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _calc_value(self, conditions, indx=None):
# so the results are cached and can be used by other surveys is
# needed. Technically this could fail if the masked region is
# very narrow or shadow time is very large.
future_alt, future_az = conditions.future_alt_az(np.max(conditions.mjd + self.shadow_time))
future_alt, future_az = conditions.future_alt_az(float(np.max(conditions.mjd)) + self.shadow_time)
r_future_alt = IntRounded(future_alt)
r_current_alt = IntRounded(conditions.alt)

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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@

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 @@
# 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 @@
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 @@
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
10 changes: 4 additions & 6 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 @@ -482,7 +482,6 @@ def generate_ddf_scheduled_obs(
obs["target_name"] = "DD:%s" % ddf_name.replace("_a", "_b")
obs["science_program"] = "DD"
obs["observation_reason"] = "FBS"
obs["json_block"] = "Imaging"

obs["mjd_tol"] = mjd_tol
obs["dist_tol"] = dist_tol
Expand All @@ -496,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 All @@ -508,7 +507,6 @@ def generate_ddf_scheduled_obs(
obs["target_name"] = "DD:%s" % ddf_name
obs["science_program"] = "DD"
obs["observation_reason"] = "FBS"
obs["json_block"] = "Imaging"

obs["mjd_tol"] = mjd_tol
obs["dist_tol"] = dist_tol
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 @@
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
5 changes: 2 additions & 3 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 Expand Up @@ -193,7 +193,6 @@ def _schedule_obs(self, observations):
sched_array["scheduler_note"] = self.long_name
sched_array["target_name"] = ""
sched_array["observation_reason"] = "FBS"
sched_array["json_block"] = "Imaging"
# Don't let the desired rotSkyPos block the observation.
sched_array["rotSkyPos_desired"] = sched_array["rotSkyPos"]
sched_array["rotSkyPos"] = np.nan
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 @@
"""
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 @@
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
Loading
Loading