Skip to content

Commit

Permalink
Merge branch 'u/emanehab99/restructure-codebase' into tickets/PREOPS-…
Browse files Browse the repository at this point in the history
…5505
  • Loading branch information
emanehab99 committed Aug 27, 2024
2 parents f8fc072 + 218b837 commit ff1dfd5
Show file tree
Hide file tree
Showing 9 changed files with 681 additions and 552 deletions.
12 changes: 10 additions & 2 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Begin by activating the conda environment::

$ conda activate schedview

There are two ways to start the dashboard, depending on what you want to use
There are three ways to start the dashboard, depending on what you want to use
as the source of data.
One way is for users to enter arbitrary URLs or file paths from which to load
the data. **This is insecure,** because users can point the dashboard to malicious
Expand All @@ -21,7 +21,15 @@ load data from a pre-specified directory on the host running the dashboard::

$ scheduler_dashboard --data_dir /where/the/snapshot/pickles/are

In either case, the app will then give you the URL at which you can find the app.
Finally, if the dashboard is running at the USDF or another LFA facility, data can
be loaded from an S3 bucket that is already preset in the dashboard. The dashboard
will retrieve a list of snapshots for a selected night.

To start the dashbaord in LFA mode::

$ scheduler_dashboard --lfa

In each case, the app will then give you the URL at which you can find the app.

Running ``prenight``
--------------------
Expand Down
2 changes: 1 addition & 1 deletion schedview/app/scheduler_dashboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"scheduler_app",
]

from .scheduler_dashboard import scheduler_app
from .scheduler_dashboard_app import scheduler_app
39 changes: 39 additions & 0 deletions schedview/app/scheduler_dashboard/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import importlib.resources

import bokeh
from astropy.time import Time

# Change styles using CSS variables.
h1_stylesheet = """
:host {
--mono-font: Helvetica;
color: white;
font-size: 16pt;
font-weight: 500;
}
"""
h2_stylesheet = """
:host {
--mono-font: Helvetica;
color: white;
font-size: 14pt;
font-weight: 300;
}
"""
h3_stylesheet = """
:host {
--mono-font: Helvetica;
color: white;
font-size: 13pt;
font-weight: 300;
}
"""

DEFAULT_CURRENT_TIME = Time.now()
DEFAULT_TIMEZONE = "UTC" # "America/Santiago"
LOGO = "/schedview-snapshot/assets/lsst_white_logo.png"
COLOR_PALETTES = [color for color in bokeh.palettes.__palettes__ if "256" in color]
DEFAULT_COLOR_PALETTE = "Viridis256"
DEFAULT_NSIDE = 16
PACKAGE_DATA_DIR = importlib.resources.files("schedview.data").as_posix()
LFA_DATA_DIR = "s3://rubin:"
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from datetime import datetime
from zoneinfo import ZoneInfo

import panel as pn
import param
from astropy.time import Time
from pandas import Timestamp

from schedview.app.scheduler_dashboard.constants import DEFAULT_TIMEZONE
from schedview.app.scheduler_dashboard.unrestricted_scheduler_snapshot_dashboard import (
SchedulerSnapshotDashboard,
)
from schedview.app.scheduler_dashboard.utils import query_night_schedulers


class LFASchedulerSnapshotDashboard(SchedulerSnapshotDashboard):
"""A Parametrized container for parameters, data, and panel objects for the
scheduler dashboard working in LFA mode where data files are loaded from
a certain S3 bucket.
"""

scheduler_fname_doc = """Recent pickles from LFA
"""

# Precedence is used to make sure fields are displayed
# in the right order regardless of the dashboard mode.
scheduler_fname = param.Selector(
default="",
objects=[],
doc=scheduler_fname_doc,
precedence=3,
)

pickles_date = param.Date(
default=datetime.now(),
label="Snapshot selection cutoff date and time",
doc="Show snapshots that are recent as of this date and time in the scheduler snapshot file dropdown",
precedence=1,
)

telescope = param.Selector(
default=None, objects={"All": None, "Simonyi": 1, "Auxtel": 2}, doc="Source Telescope", precedence=2
)

# Summary widget and Reward widget heights are different in this mode
# because there are more data loading parameters.
_summary_widget_height = 310
_reward_widget_height = 350

data_loading_parameters = [
"scheduler_fname",
"pickles_date",
"telescope",
"widget_datetime",
"widget_tier",
]
# Set specific widget props for data loading parameters
# in LFA mode.
data_loading_widgets = {
"pickles_date": pn.widgets.DatetimePicker,
"widget_datetime": pn.widgets.DatetimePicker,
}
# Set the data loading parameter section height in LFA mode.
data_params_grid_height = 42

def __init__(self):
super().__init__()

async def query_schedulers(self, selected_time, selected_tel):
"""Query snapshots that have a timestamp between the start of the
night and selected datetime and generated by selected telescope
"""
selected_time = Time(
Timestamp(
selected_time,
tzinfo=ZoneInfo(DEFAULT_TIMEZONE),
)
)
self.show_loading_indicator = True
self._debugging_message = "Starting retrieving snapshots"
self.logger.debug("Starting retrieving snapshots")
scheduler_urls = await query_night_schedulers(selected_time, selected_tel)
self.logger.debug("Finished retrieving snapshots")
self._debugging_message = "Finished retrieving snapshots"
self.show_loading_indicator = False
return scheduler_urls
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import panel as pn

import schedview
import schedview.param
from schedview.app.scheduler_dashboard.constants import PACKAGE_DATA_DIR
from schedview.app.scheduler_dashboard.unrestricted_scheduler_snapshot_dashboard import (
SchedulerSnapshotDashboard,
)


class RestrictedSchedulerSnapshotDashboard(SchedulerSnapshotDashboard):
"""A Parametrized container for parameters, data, and panel objects for the
scheduler dashboard working in restricted more where data files can only
be loaded from a certain data directory that is set through constructor.
"""

scheduler_fname_doc = """URL or file name of the scheduler pickle file.
Such a pickle file can either be of an instance of a subclass of
rubin_scheduler.scheduler.schedulers.CoreScheduler, or a tuple of the form
(scheduler, conditions), where scheduler is an instance of a subclass of
rubin_scheduler.scheduler.schedulers.CoreScheduler, and conditions is an
instance of rubin_scheduler.scheduler.conditions.Conditions.
"""
scheduler_fname = schedview.param.FileSelectorWithEmptyOption(
path=f"{PACKAGE_DATA_DIR}/*scheduler*.p*",
doc=scheduler_fname_doc,
default=None,
allow_None=True,
)

data_loading_widgets = {
"widget_datetime": pn.widgets.DatetimePicker,
}

def __init__(self, data_dir=None):
super().__init__()

if data_dir is not None:
self.param["scheduler_fname"].update(path=f"{data_dir}/*scheduler*.p*")
Loading

0 comments on commit ff1dfd5

Please sign in to comment.