Skip to content

Commit

Permalink
move from note to scheduler_note in opsim db schema where applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
ehneilsen committed Sep 19, 2024
1 parent 38c18ce commit 9b8068d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
2 changes: 2 additions & 0 deletions schedview/compute/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def _make_observation_from_record(record):
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"]
Expand Down
10 changes: 5 additions & 5 deletions schedview/data/sample_prenight_custom_hvplots.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "Airmass histogram",
"settings": {
"by": "note",
"by": "scheduler_note",
"kind": "hist",
"y": "airmass",
"bins": 15,
Expand All @@ -15,7 +15,7 @@
{
"name": "Slew time histogram",
"settings": {
"by": "note",
"by": "scheduler_note",
"kind": "hist",
"y": "slewTime",
"bins": 15,
Expand All @@ -28,7 +28,7 @@
{
"name": "Airmass vs. H.A.",
"settings": {
"by": "note",
"by": "scheduler_note",
"kind": "scatter",
"x": "HA",
"y": "airmass",
Expand All @@ -44,7 +44,7 @@
"moonAlt",
"moonDistance",
"moonPhase",
"note"
"scheduler_note"
],
"height": 512
}
Expand All @@ -62,7 +62,7 @@
"sunAlt",
"moonAlt",
"moonPhase",
"note"
"scheduler_note"
],
"height": 512
}
Expand Down
37 changes: 28 additions & 9 deletions schedview/plot/nightly.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def plot_alt_vs_time(
event_labels=DEFAULT_EVENT_LABELS,
event_colors=DEFAULT_EVENT_COLORS,
figure=None,
note_column=None,
):
"""Plot airmass vs. time for a set of visits
Expand All @@ -181,12 +182,24 @@ def plot_alt_vs_time(
Default is `DEFAULT_EVENT_COLORS`.
figure : `bokeh.plotting.Figure`
Bokeh figure object to plot on. If None, a new figure will be created.
note_column : `str` or None
The column to use as the note to map to color.
Defaults to None, which defaults `scheduler_note` if it is present
in the visit datasource, otherwise `note`.
Returns
-------
fig : `bokeh.plotting.Figure`
Bokeh figure object
"""

if note_column is None:
if isinstance(visits, bokeh.models.ColumnDataSource):
scheduler_note_present = "scheduler_note" in visits.data
else:
scheduler_note_present = "scheduler_note" in visits
note_column = "scheduler_note" if scheduler_note_present else "note"

for time_column in "start_date", "observationStartDatetime64":
if isinstance(visits, bokeh.models.ColumnDataSource):
if time_column in visits.data:
Expand All @@ -211,17 +224,17 @@ def plot_alt_vs_time(
else:
visits_ds = bokeh.models.ColumnDataSource(visits)

note_values = np.unique(visits_ds.data["note"])
note_values = np.unique(visits_ds.data[note_column])
too_many_note_values = len(note_values) > len(colorcet.palette["glasbey"])

if not too_many_note_values:
note_color_mapper = bokeh.models.CategoricalColorMapper(
factors=note_values, palette=colorcet.palette["glasbey"][: len(note_values)], name="note"
factors=note_values, palette=colorcet.palette["glasbey"][: len(note_values)], name=note_column
)

if "note_and_filter" not in visits_ds.column_names:
note_and_filter = tuple(
[f"{n} in {f}" for n, f in zip(visits_ds.data["note"], visits_ds.data["filter"])]
[f"{n} in {f}" for n, f in zip(visits_ds.data[note_column], visits_ds.data["filter"])]
)
visits_ds.add(note_and_filter, "note_and_filter")

Expand All @@ -247,7 +260,7 @@ def plot_alt_vs_time(
time_column,
"altitude",
source=visits_ds,
color={"field": "note", "transform": note_color_mapper},
color={"field": note_column, "transform": note_color_mapper},
marker={"field": "filter", "transform": filter_marker_mapper},
size=5,
legend_field="note_and_filter",
Expand Down Expand Up @@ -366,7 +379,7 @@ def _add_az_graticules(fig, transform, min_alt=0, min_az=0, max_az=360, az_step=
)


def plot_polar_alt_az(visits, band_shapes=BAND_SHAPES, figure=None, legend=True):
def plot_polar_alt_az(visits, band_shapes=BAND_SHAPES, figure=None, legend=True, note_column=None):
"""Plot airmass vs. time for a set of visits
Parameters
Expand All @@ -387,6 +400,12 @@ def plot_polar_alt_az(visits, band_shapes=BAND_SHAPES, figure=None, legend=True)
fig : `bokeh.plotting.Figure`
Bokeh figure object
"""
if note_column is None:
if isinstance(visits, bokeh.models.ColumnDataSource):
scheduler_note_present = "scheduler_note" in visits.data
else:
scheduler_note_present = "scheduler_note" in visits
note_column = "scheduler_note" if scheduler_note_present else "note"

if figure is None:
fig = bokeh.plotting.figure(
Expand Down Expand Up @@ -416,17 +435,17 @@ def plot_polar_alt_az(visits, band_shapes=BAND_SHAPES, figure=None, legend=True)
if "zd" not in visits_ds.column_names:
visits_ds.add(90 - np.array(visits_ds.data["altitude"]), "zd")

note_values = np.unique(visits_ds.data["note"])
note_values = np.unique(visits_ds.data[note_column])
too_many_note_values = len(note_values) > len(colorcet.palette["glasbey"])

if not too_many_note_values:
note_color_mapper = bokeh.models.CategoricalColorMapper(
factors=note_values, palette=colorcet.palette["glasbey"][: len(note_values)], name="note"
factors=note_values, palette=colorcet.palette["glasbey"][: len(note_values)], name=note_column
)

if "note_and_filter" not in visits_ds.column_names:
note_and_filter = tuple(
[f"{n} in {f}" for n, f in zip(visits_ds.data["note"], visits_ds.data["filter"])]
[f"{n} in {f}" for n, f in zip(visits_ds.data[note_column], visits_ds.data["filter"])]
)
visits_ds.add(note_and_filter, "note_and_filter")

Expand Down Expand Up @@ -456,7 +475,7 @@ def plot_polar_alt_az(visits, band_shapes=BAND_SHAPES, figure=None, legend=True)
polar_transform.y,
polar_transform.x,
source=visits_ds,
color={"field": "note", "transform": note_color_mapper},
color={"field": note_column, "transform": note_color_mapper},
marker={"field": "filter", "transform": filter_marker_mapper},
size=5,
legend_field="note_and_filter",
Expand Down
3 changes: 1 addition & 2 deletions schedview/plot/visitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
VISIT_TOOLTIPS = (
"@observationId: @start_date{%F %T} UTC (mjd=@observationStartMJD{00000.0000}, "
+ "LST=@observationStartLST\u00b0), band=@filter, RA=@fieldRA\u00b0, Decl=@fieldDec\u00b0, "
+ "PA=@paraAngle\u00b0, Az=@azimuth\u00b0, Alt=@altitude\u00b0, @note"
+ "PA=@paraAngle\u00b0, Az=@azimuth\u00b0, Alt=@altitude\u00b0"
)
VISIT_COLUMNS = [
"observationId",
Expand All @@ -42,7 +42,6 @@
"paraAngle",
"azimuth",
"altitude",
"note",
]

NSIDE_LOW = 8
Expand Down
6 changes: 4 additions & 2 deletions schedview/plot/visits.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def visits_tooltips(weather: bool = False) -> list:
+ ")",
),
("flush by mjd", "@flush_by_mjd{00000.00}"),
("Note", "@note"),
("Scheduler note", "@scheduler_note"),
("Filter", "@filter"),
(
"Field coordinates",
Expand Down Expand Up @@ -104,7 +104,9 @@ def plot_visits(visits):
figure : `hvplot.ui.hvDataFrameExplorer`
The figure itself.
"""
visit_explorer = hvplot.explorer(visits, kind="scatter", x="start_date", y="airmass", by=["note"])
visit_explorer = hvplot.explorer(
visits, kind="scatter", x="start_date", y="airmass", by=["scheduler_note"]
)
return visit_explorer


Expand Down

0 comments on commit 9b8068d

Please sign in to comment.