Skip to content

Commit

Permalink
changes to make the dashboard work with param v2
Browse files Browse the repository at this point in the history
  • Loading branch information
emanehab99 committed Nov 17, 2023
1 parent 974c75d commit e14304e
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions schedview/app/scheduler_dashboard/scheduler_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import os
import traceback

# Filter the astropy warnings swamping the terminal.
# Filter the astropy warnings swamping the terminal
import warnings

Check warning on line 33 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L33

Added line #L33 was not covered by tests
from datetime import datetime
from glob import glob

Check warning on line 35 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L35

Added line #L35 was not covered by tests
Expand All @@ -48,7 +48,7 @@
from panel.io.loading import start_loading_spinner, stop_loading_spinner
from pytz import timezone

# For the conditions.mjd bugfix.
# For the conditions.mjd bugfix
from rubin_sim.scheduler.model_observatory import ModelObservatory

import schedview
Expand All @@ -58,7 +58,7 @@
import schedview.param

Check warning on line 58 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L58

Added line #L58 was not covered by tests
import schedview.plot.survey

# filter astropy warning that's filling the terminal with every update.
# Filter astropy warning that's filling the terminal with every update.
warnings.filterwarnings("ignore", category=AstropyWarning)

Check warning on line 62 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L62

Added line #L62 was not covered by tests

DEFAULT_CURRENT_TIME = Time.now()
Expand All @@ -68,6 +68,7 @@
PACKAGE_DATA_DIR = importlib.resources.files("schedview.data").as_posix()
USDF_DATA_DIR = "/sdf/group/rubin/web_data/sim-data/schedview"

Check warning on line 69 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L68-L69

Added lines #L68 - L69 were not covered by tests


pn.extension(
"tabulator",
sizing_mode="stretch_width",
Expand Down Expand Up @@ -1287,7 +1288,7 @@ def map_title(self):

class RestrictedFilesScheduler(Scheduler):

Check warning on line 1289 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1289

Added line #L1289 was not covered by tests
"""A Parametrized container for parameters, data, and panel objects for the
scheduler dashboard with restricted pickle file selection.
scheduler dashboard.
"""

# Param parameters that are modifiable by user actions.
Expand All @@ -1299,16 +1300,17 @@ class RestrictedFilesScheduler(Scheduler):
instance of rubin_sim.scheduler.conditions.Conditions.
"""
scheduler_fname = schedview.param.FileSelectorWithEmptyOption(

Check warning on line 1302 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1302

Added line #L1302 was not covered by tests
path=f"{PACKAGE_DATA_DIR}/*scheduler*.p*",
doc=scheduler_fname_doc,
default="",
default=None,
allow_None=True,
)

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

Check warning on line 1310 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1309-L1310

Added lines #L1309 - L1310 were not covered by tests

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

Check warning on line 1313 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1313

Added line #L1313 was not covered by tests


# --------------------------------------------------------------- Key functions
Expand Down Expand Up @@ -1508,20 +1510,28 @@ def scheduler_app(date_time=None, scheduler_pickle=None, **kwargs):
max_height=1000,
).servable()

scheduler = Scheduler()
# read scheduler_pickle if provided to the function in a notebook.
# it will be overriden if the dashboard runs in an app.
if scheduler_pickle is not None:
scheduler.scheduler_fname = scheduler_pickle
from_urls = False
data_dir = None

Check warning on line 1514 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1513-L1514

Added lines #L1513 - L1514 were not covered by tests

from_urls = kwargs["data_from_urls"] if "data_from_urls" in kwargs.keys() else False
data_dir = kwargs["data_dir"] if "data_dir" in kwargs.keys() else ""
if "data_from_urls" in kwargs.keys():
from_urls = kwargs["data_from_urls"]
del kwargs["data_from_urls"]

Check warning on line 1518 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1517-L1518

Added lines #L1517 - L1518 were not covered by tests

if "data_dir" in kwargs.keys():
data_dir = kwargs["data_dir"]
del kwargs["data_dir"]

Check warning on line 1522 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1521-L1522

Added lines #L1521 - L1522 were not covered by tests

scheduler = None

Check warning on line 1524 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1524

Added line #L1524 was not covered by tests
# Accept pickle files from url or any path.
if from_urls:
# Add placeholder text if the widget is a text input.
# This cannot be done for a FileSelector parameter.
pn.Param(scheduler, widgets={"scheduler_fname": {"placeholder": "filepath or URL of pickle"}})
scheduler = Scheduler()

Check warning on line 1527 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1527

Added line #L1527 was not covered by tests
# read pickle and time if provided to the function in a notebook
# it will be overriden if the dashboard runs in an app
if date_time is not None:
scheduler.widget_datetime = date_time

Check warning on line 1531 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1531

Added line #L1531 was not covered by tests

if scheduler_pickle is not None:
scheduler.scheduler_fname = scheduler_pickle

Check warning on line 1534 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1534

Added line #L1534 was not covered by tests

# Sync url parameters only if the files aren't restricted.
if pn.state.location is not None:
Expand All @@ -1536,12 +1546,6 @@ def scheduler_app(date_time=None, scheduler_pickle=None, **kwargs):
# Restrict files to data_directory.
else:
scheduler = RestrictedFilesScheduler(data_dir=data_dir)

Check warning on line 1548 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1548

Added line #L1548 was not covered by tests
# This line is already in RestrictedFilesScheduler.__init__
# but the selector path doesn't update without calling it here.
scheduler.param.scheduler_fname.path = data_dir

if date_time is not None:
scheduler.widget_datetime = date_time

# Show dashboard as busy when scheduler.show_loading_spinner is True.
@pn.depends(loading=scheduler.param.show_loading_indicator, watch=True)
Expand Down Expand Up @@ -1575,6 +1579,10 @@ def update_loading(loading):
scheduler,
parameters=["scheduler_fname", "widget_datetime", "widget_tier"],
widgets={
# "scheduler_fname": {
# # "widget_type": pn.widgets.TextInput,
# "placeholder": "filepath or URL of pickle",
# },
"widget_datetime": pn.widgets.DatetimePicker,
},
name="Select pickle file, date and tier.",
Expand Down Expand Up @@ -1643,7 +1651,9 @@ def update_loading(loading):


def parse_arguments():

Check warning on line 1653 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1653

Added line #L1653 was not covered by tests
"""Parse commandline arguments to read data directory if provided."""
"""
Parse commandline arguments to read data directory if provided
"""
parser = argparse.ArgumentParser(description="On-the-fly Rubin Scheduler dashboard")
default_data_dir = f"{USDF_DATA_DIR}/*" if os.path.exists(USDF_DATA_DIR) else PACKAGE_DATA_DIR

Check warning on line 1658 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1657-L1658

Added lines #L1657 - L1658 were not covered by tests

Expand Down Expand Up @@ -1672,8 +1682,8 @@ def parse_arguments():


def main():
commandline_args = parse_arguments()
print("Starting scheduler dashboard.")
commandline_args = parse_arguments()

Check warning on line 1686 in schedview/app/scheduler_dashboard/scheduler_dashboard.py

View check run for this annotation

Codecov / codecov/patch

schedview/app/scheduler_dashboard/scheduler_dashboard.py#L1686

Added line #L1686 was not covered by tests

if "SCHEDULER_PORT" in os.environ:
scheduler_port = int(os.environ["SCHEDULER_PORT"])
Expand Down

0 comments on commit e14304e

Please sign in to comment.