Skip to content

Commit

Permalink
Merge pull request #286 from Subaru-PFS/u/wanqqq/user_ppc_code_fix
Browse files Browse the repository at this point in the history
fix user ppc_code bug & enable to download target list from admin page
  • Loading branch information
monodera authored Aug 22, 2024
2 parents 9dfa411 + d9fc7f0 commit 89dae05
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/pfs_target_uploader/pn_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ def Table_files_tgt_psl(column_checkbox_):
frozen_columns=["index"],
pagination="remote",
header_filters=True,
buttons={"magnify": "<i class='fa-solid fa-magnifying-glass'></i>"},
buttons={"magnify": "<i class='fa-solid fa-magnifying-glass'></i>", "download": "<i class='fa-solid fa-download'></i>"},
layout="fit_data_table",
hidden_columns=_hidden_columns,
disabled=True,
Expand All @@ -711,6 +711,21 @@ def Table_files_tgt_psl(column_checkbox_):
_table_files_tgt_psl.add_filter(slider_rot_l, "Time_tot_L (h)")
_table_files_tgt_psl.add_filter(slider_rot_m, "Time_tot_M (h)")

# Open a file by clicking the download buttons
# https://discourse.holoviz.org/t/how-to-make-a-dynamic-link-in-panel/2137

def execute_javascript(script):
script = f'<script type="text/javascript">{script}</script>'
js_panel.object = script
js_panel.object = ""

def open_panel_download(event):
if event.column == "download":
href = df_files_tgt_psl["fullpath_tgt"][event.row]
# c.f. https://www.w3schools.com/jsref/met_win_open.asp
script = f"window.open('{href}', '_blank')"
execute_javascript(script)

def open_panel_magnify(event):
row_target = event.row
if event.column == "magnify":
Expand Down Expand Up @@ -912,6 +927,7 @@ def tab_ppc_save(event):
)

_table_files_tgt_psl.on_click(open_panel_magnify)
_table_files_tgt_psl.on_click(open_panel_download)

return _table_files_tgt_psl

Expand Down Expand Up @@ -951,6 +967,7 @@ def tab_ppc_save(event):
table_ppc = pn.Column()

# -------------------------------------------------------------------
js_panel = pn.pane.HTML(width=0, height=0, margin=0, sizing_mode="fixed")

sidebar_column = pn.Column(
psl_info,
Expand All @@ -972,6 +989,7 @@ def tab_ppc_save(event):
),
column_checkbox,
table_files_tgt_psl,
js_panel,
),
),
("PPC details", table_ppc),
Expand Down
7 changes: 7 additions & 0 deletions src/pfs_target_uploader/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
tac_rot_l = np.zeros(n_files, dtype=float)
tac_rot_m = np.zeros(n_files, dtype=float)
single_exptime = np.full(n_files, 900, dtype=int)
observation_type = np.full(n_files, None, dtype=object)

for i, d in enumerate(dirs):
uid = d[-n_uid:]
Expand Down Expand Up @@ -391,6 +392,11 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
except KeyError:
upload_ids[i] = None

try:
observation_type[i] = tb_target.meta["observation_type"]
except KeyError:
observation_type[i] = None

try:
if isinstance(tb_target.meta["upload_at"], str):
timestamps[i] = datetime.fromisoformat(tb_target.meta["upload_at"])
Expand Down Expand Up @@ -467,6 +473,7 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
"fullpath_tgt": fullpath_target,
"fullpath_psl": fullpath_psl,
"single_exptime": single_exptime,
"observation_type": observation_type,
}
)

Expand Down
7 changes: 7 additions & 0 deletions src/pfs_target_uploader/utils/ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,7 @@ def ppp_plotFig(RESmode, cR, sub, obj_allo, uS):

obj_allo1 = obj_allo[obj_allo.argsort(keys="ppc_priority")]
obj_allo1["PPC_id"] = np.arange(0, len(obj_allo), 1) + 1
"""
if len(uPPC) > 0:
if "ppc_priority" in uPPC.colnames:
uPPC.remove_column("ppc_priority")
Expand All @@ -1193,6 +1194,12 @@ def ppp_plotFig(RESmode, cR, sub, obj_allo, uS):
"Point_" + RESmode + "_" + str(count)
for count in (np.arange(0, len(obj_allo), 1) + 1)
]
#"""
obj_allo1["ppc_code"] = [
"Point_" + RESmode + "_" + str(count)
for count in (np.arange(0, len(obj_allo), 1) + 1)
]

obj_allo1 = obj_allo1.group_by("ppc_code")
obj_allo1.rename_column("tel_fiber_usage_frac", "Fiber usage fraction (%)")
obj_allo2 = Table.to_pandas(obj_allo1)
Expand Down

0 comments on commit 89dae05

Please sign in to comment.