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

tickets/SP-1624: Update schedview to work with rubin_scheduler v3.0.0rc0 #112

Merged
merged 2 commits into from
Oct 16, 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
4 changes: 2 additions & 2 deletions schedview/collect/opsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def read_opsim(
warn("No visits match constraints.")
visits = (
SchemaConverter()
.obs2opsim(rubin_scheduler.scheduler.utils.empty_observation())
.drop(index=0)
.obs2opsim(rubin_scheduler.scheduler.utils.ObservationArray())
.iloc[0:-1]
)
if "observationId" not in visits.columns and "ID" in visits.columns:
visits.rename(columns={"ID": "observationId"}, inplace=True)
Expand Down
74 changes: 7 additions & 67 deletions schedview/compute/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,69 +12,7 @@
from rubin_scheduler.scheduler import sim_runner, surveys
from rubin_scheduler.scheduler.example import example_scheduler
from rubin_scheduler.scheduler.model_observatory import ModelObservatory
from rubin_scheduler.scheduler.utils import SchemaConverter, empty_observation


def _make_observation_from_record(record):
"""Convert an opsim visit record to a scheduler observation

Parameters
----------
record : `dict`
A row from an opsim output table

Returns
-------
observation : `numpy.ndarray`
A numpy recarray with data understood by the scheduler
"""
observation = empty_observation()
observation["RA"] = np.radians(record["fieldRA"])
observation["dec"] = np.radians(record["fieldDec"])
observation["mjd"] = record["observationStartMJD"]
observation["flush_by_mjd"] = record["flush_by_mjd"]
observation["exptime"] = record["visitExposureTime"]
observation["filter"] = record["filter"]
observation["rotSkyPos"] = np.radians(record["rotSkyPos"])
observation["rotSkyPos_desired"] = np.radians(record["rotSkyPos_desired"])
observation["nexp"] = record["numExposures"]
observation["airmass"] = record["airmass"]
observation["FWHM_500"] = record["seeingFwhm500"]
observation["FWHMeff"] = record["seeingFwhmEff"]
observation["FWHM_geometric"] = record["seeingFwhmGeom"]
observation["skybrightness"] = record["skyBrightness"]
observation["night"] = record["night"]
observation["slewtime"] = record["slewTime"]
observation["visittime"] = record["visitTime"]
observation["slewdist"] = np.radians(record["slewDistance"])
observation["fivesigmadepth"] = record["fiveSigmaDepth"]
observation["alt"] = np.radians(record["altitude"])
observation["az"] = np.radians(record["azimuth"])
observation["pa"] = np.radians(record["paraAngle"])
observation["clouds"] = record["cloud"]
observation["moonAlt"] = np.radians(record["moonAlt"])
observation["sunAlt"] = np.radians(record["sunAlt"])
observation["note"] = record["note"]
if "scheduler_note" in record:
observation["scheduler_note"] = record["scheduler_note"]
observation["field_id"] = record["fieldId"]
observation["survey_id"] = record["proposalId"]
observation["block_id"] = record["block_id"]
observation["lmst"] = record["observationStartLST"] / 15
observation["rotTelPos"] = np.radians(record["rotTelPos"])
observation["rotTelPos_backup"] = np.radians(record["rotTelPos_backup"])
observation["moonAz"] = np.radians(record["moonAz"])
observation["sunAz"] = np.radians(record["sunAz"])
observation["sunRA"] = np.radians(record["sunRA"])
observation["sunDec"] = np.radians(record["sunDec"])
observation["moonRA"] = np.radians(record["moonRA"])
observation["moonDec"] = np.radians(record["moonDec"])
observation["moonDist"] = np.radians(record["moonDistance"])
observation["solarElong"] = np.radians(record["solarElong"])
observation["moonPhase"] = record["moonPhase"]
observation["cummTelAz"] = np.radians(record["cummTelAz"])
observation["scripted_id"] = record["scripted_id"]
return observation
from rubin_scheduler.scheduler.utils import SchemaConverter


def replay_visits(scheduler, visits):
Expand All @@ -87,11 +25,13 @@ def replay_visits(scheduler, visits):
visits : `pandas.DataFrame`
A table of visits to add.
"""
for visit_id, visit_record in visits.iterrows():
obs = _make_observation_from_record(visit_record)
scheduler.add_observation(obs)
obs = SchemaConverter().opsimdf2obs(visits)
for this_obs in obs:
scheduler.add_observation(this_obs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting to check that if you just add them all in an array (i.e.
scheduler.add_observation_array(obs))
that this all works as expected. It should, and it should be faster.


scheduler.conditions.mjd = float(obs["mjd"] + (obs["slewtime"] + obs["visittime"]) / (24 * 60 * 60))
scheduler.conditions.mjd = float(
this_obs["mjd"] + (this_obs["slewtime"] + this_obs["visittime"]) / (24 * 60 * 60)
)


def compute_basis_function_reward_at_time(scheduler, time, observatory=None):
Expand Down
Binary file modified schedview/data/sample_opsim.db
Binary file not shown.
Binary file modified schedview/data/sample_rewards.h5
Binary file not shown.
Binary file modified schedview/data/sample_scheduler.pickle.xz
Binary file not shown.
Loading