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

Allow prenight data files to be set on command line even if arbitrary… #36

Merged
merged 1 commit into from
Oct 9, 2023
Merged
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
32 changes: 28 additions & 4 deletions schedview/app/prenight/prenight.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import sys
from glob import glob
from pathlib import Path

import astropy.utils.iers
import bokeh
Expand Down Expand Up @@ -909,10 +910,24 @@ class RestrictedInputPrenight(Prenight):
def __init__(self, *args, data_dir=None, **kwargs):
super().__init__(*args, **kwargs)

path_for_kwargs = {
"opsim_db": self.param["opsim_output_fname"].path,
"scheduler": self.param["scheduler_fname"].path,
"reward": self.param["rewards_fname"].path,
}

if data_dir is not None:
self.param["opsim_output_fname"].path = f"{data_dir}/*opsim*.db"
self.param["scheduler_fname"].path = f"{data_dir}/*scheduler*.p*"
self.param["rewards_fname"].path = f"{data_dir}/*rewards*.h5"
fname_glob = {
"opsim_db": f"{data_dir}/*opsim*.db",
"scheduler": f"{data_dir}/*scheduler*.p*",
"reward": f"{data_dir}/*rewards*.h5",
}

for arg_name in path_for_kwargs:
if arg_name in kwargs:
path_for_kwargs[arg_name] = kwargs[arg_name]
elif data_dir is not None:
path_for_kwargs[arg_name] = fname_glob[arg_name]


def prenight_app(*args, **kwargs):
Expand All @@ -932,7 +947,16 @@ def prenight_app(*args, **kwargs):
except KeyError:
data_dir = None

prenight = RestrictedInputPrenight(data_dir=data_dir)
specified_data_files = {}
data_args = set(["opsim_db", "scheduler", "rewards"]) & set(kwargs.keys())
for data_arg in data_args:
# Fully resolve the path to the file.
file_path = Path(kwargs[data_arg]).resolve()
kwargs[data_arg] = str(file_path)
if data_arg in kwargs:
specified_data_files[data_arg] = str(file_path)

prenight = RestrictedInputPrenight(data_dir=data_dir, **specified_data_files)
Copy link
Member

Choose a reason for hiding this comment

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

Oh interesting .. so I think this means that if you do not allow arbitrary data urls (which I thought meant uploading files only, rather than files from the filesystem), that you have to pre-specify which data directories should be allowed?
So the choices are -- data files from paths that are specified at startup vs. any data file + URL uploads?
(I'm not sure if that would be clear to other people, but wasn't clear to me, if that's how it works)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's right.


try:
del kwargs["data_dir"]
Expand Down
Loading