Skip to content

Commit

Permalink
add pointing simulation status & show target list on admin
Browse files Browse the repository at this point in the history
  • Loading branch information
wanqqq31 committed Aug 23, 2024
1 parent d9fc7f0 commit 90212d2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 33 deletions.
44 changes: 22 additions & 22 deletions src/pfs_target_uploader/pn_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ def cb_PPP(event):

try:
panel_ppp.origname = panel_input.file_input.filename
panel_ppp.origname_ppc = panel_ppcinput.file_input.filename
panel_ppp.origdata = panel_input.file_input.value
panel_ppp.df_summary = panel_status.df_summary

Expand Down Expand Up @@ -496,14 +497,23 @@ def cb_submit(event):
panel_ppp.df_input = df_validated
panel_ppp.df_summary = panel_status.df_summary
panel_ppp.origname = panel_input.file_input.filename
panel_ppp.origname_ppc = panel_ppcinput.file_input.filename
panel_ppp.origdata = panel_input.file_input.value
panel_ppp.upload_time = datetime.now(timezone.utc)
panel_ppp.secret_token = panel_input.secret_token

if panel_ppp.status_ == 2:
ppc_status_ = "user"
elif panel_ppp.status_ == 0:
ppc_status_ = "skip"
else:
ppc_status_ = "auto"

outdir, outfile_zip, _ = panel_ppp.upload(
outdir_prefix=config["OUTPUT_DIR"],
single_exptime=panel_obs_type.single_exptime.value,
observation_type=panel_obs_type.obs_type.value,
ppc_status=ppc_status_,
)

try:
Expand Down Expand Up @@ -578,6 +588,8 @@ def list_files_app(use_panel_cli=False):

logger.info(f"config params from dotenv: {config}")

panel_targets = TargetWidgets()

if not os.path.exists(config["OUTPUT_DIR"]):
logger.error(f"{config['OUTPUT_DIR']} not found")
raise ValueError
Expand Down Expand Up @@ -642,24 +654,7 @@ def list_files_app(use_panel_cli=False):
step=1,
)

# setup panel components

# Target & psl summary table

"""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":
p_href = df_files_tgt["fullpath"][event.row].replace(
config["OUTPUT_DIR"], "data", 1
)
# c.f. https://www.w3schools.com/jsref/met_win_open.asp
script = f"window.open('{p_href}', '_blank')"
execute_javascript(script)#"""

def Table_files_tgt_psl(column_checkbox_):
if psl_info_input.value is not None:
df_psl_info = load_input(
Expand Down Expand Up @@ -687,7 +682,10 @@ 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>", "download": "<i class='fa-solid fa-download'></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 Down Expand Up @@ -732,7 +730,7 @@ def open_panel_magnify(event):
table_ppc.clear()

# move to "PPC details" tab
tab_panels.active = 1
tab_panels.active = 2

u_id = _df_files_tgt_psl["Upload ID"][row_target]
p_ppc = os.path.split(_df_files_tgt_psl["fullpath_psl"][row_target])[0]
Expand All @@ -751,6 +749,8 @@ def open_panel_magnify(event):
except FileNotFoundError:
table_tac_t = Table()

panel_targets.show_results(Table.to_pandas(table_tgt_t))

(
nppc_fin,
p_result_fig_fin,
Expand All @@ -772,7 +772,6 @@ def open_panel_magnify(event):
raise ValueError

path_t_server = path_t_all[0]
tac_ppc_list_file_server = f"{path_t_server}/TAC_ppc_{u_id}.ecsv"

path_t = path_t_server.replace(config["OUTPUT_DIR"], "data", 1)
tac_ppc_list_file = f"{path_t}/TAC_ppc_{u_id}.ecsv"
Expand Down Expand Up @@ -941,8 +940,8 @@ def tab_ppc_save(event):
"timestamp",
"TAC_FH_L",
"TAC_FH_M",
"TAC_nppc_L",
"TAC_nppc_M",
"observation_type",
"pointing_status",
],
options=list(df_files_tgt_psl.columns)
+ ["proposal ID", "PI name", "rank", "grade"],
Expand Down Expand Up @@ -992,6 +991,7 @@ def tab_ppc_save(event):
js_panel,
),
),
("Target list", panel_targets.pane),
("PPC details", table_ppc),
)

Expand Down
26 changes: 22 additions & 4 deletions src/pfs_target_uploader/utils/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def upload_file(
ppp_fig,
outdir_prefix=".",
origname="example.csv",
origname_ppc=None,
origdata=None,
secret_token=None,
upload_time=None,
Expand All @@ -137,6 +138,7 @@ def upload_file(
skip_subdirectories=False,
single_exptime=900,
observation_type="queue",
ppc_status="auto",
):
# use the current UTC time and random hash string to construct an output filename
if upload_time is None:
Expand Down Expand Up @@ -238,11 +240,13 @@ def upload_file(
# add metadata
obj.meta["original_filename"] = origname
if not export:
obj.meta["original_filename_ppc"] = origname_ppc
obj.meta["upload_id"] = secret_token
obj.meta["upload_at"] = upload_time
obj.meta["ppp_status"] = ppp_status
obj.meta["single_exptime"] = single_exptime
obj.meta["observation_type"] = observation_type
obj.meta["ppc_status"] = ppc_status
filename = f"{file_prefix}_{secret_token}.ecsv"
elif type == "figure":
filename = f"{file_prefix}_{secret_token}.html"
Expand Down Expand Up @@ -329,6 +333,7 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
n_files = len(dirs)

orignames = np.full(n_files, None, dtype=object)
orignames_ppc = np.full(n_files, None, dtype=object)
upload_ids = np.full(n_files, None, dtype=object)
timestamps = np.full(n_files, None, dtype="datetime64[s]")
filesizes = np.zeros(n_files, dtype=float)
Expand All @@ -353,6 +358,7 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
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)
ppc_status = np.full(n_files, None, dtype=object)

for i, d in enumerate(dirs):
uid = d[-n_uid:]
Expand Down Expand Up @@ -388,14 +394,14 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
orignames[i] = None

try:
upload_ids[i] = tb_target.meta["upload_id"]
orignames_ppc[i] = tb_target.meta["original_filename_ppc"]
except KeyError:
upload_ids[i] = None
orignames_ppc[i] = None

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

try:
if isinstance(tb_target.meta["upload_at"], str):
Expand All @@ -410,6 +416,16 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
except KeyError:
pass

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

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

n_obj[i] = tb_target["ob_code"].size
t_exp[i] = np.sum(tb_target["exptime"]) / 3600.0

Expand Down Expand Up @@ -474,6 +490,8 @@ def load_file_properties(datadir, ext="ecsv", n_uid=16):
"fullpath_psl": fullpath_psl,
"single_exptime": single_exptime,
"observation_type": observation_type,
"pointing_status": ppc_status,
"Filename_pointing": orignames_ppc,
}
)

Expand Down
18 changes: 12 additions & 6 deletions src/pfs_target_uploader/utils/ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,6 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime):
# if total number of ppc > max_nppc (~5 nights), then directly stop
"""

status = 999

if sum(uS["exptime_assign"] == uS["exptime_PPP"]) == len(uS):
# remove ppc with no fiber assignment
obj_allo.remove_rows(np.where(obj_allo["tel_fiber_usage_frac"] == 0)[0])
Expand Down Expand Up @@ -924,7 +922,9 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime):
uS_t1["exptime_PPP"] - uS_t1["exptime_assign"]
) # remained exposure time

uS_t2 = PPP_centers(uS_t1, [], True, weight_para, starttime, exetime)[0]
uS_t2, status = PPP_centers(
uS_t1, [], True, weight_para, starttime, exetime
)

obj_allo_t = netflowRun(uS_t2)

Expand Down Expand Up @@ -1100,7 +1100,6 @@ def ppp_result(
sub_m,
obj_allo_m,
uS_M2,
uPPC,
single_exptime=900,
d_pfi=1.38,
box_width=1200.0,
Expand Down Expand Up @@ -1130,7 +1129,6 @@ def ppp_result(
)

def overheads(n_sci_frame):

t_night_hours: float = 10.0 # [h] total observing time per night

# in seconds
Expand Down Expand Up @@ -1199,7 +1197,7 @@ 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 = 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 Expand Up @@ -1750,6 +1748,8 @@ def rot2nppc(rot):
else:
admin_slider_ini_value = nppc_usr.data[0]

legend_cols = 2 if len(sub) >= 6 else 1

nppc = pn.widgets.EditableFloatSlider(
name=(f"{RESmode.capitalize()}-resolution mode (ROT / hour)"),
format="1[.]000",
Expand Down Expand Up @@ -1913,6 +1913,7 @@ def update_ppp_figures(nppc_fin):
show_grid=True,
shared_axes=False,
height=int(plot_height * 0.5),
legend_cols=legend_cols,
)
else:
p_ppc_tot = (p_tgt).opts(
Expand All @@ -1926,6 +1927,7 @@ def update_ppp_figures(nppc_fin):
show_grid=True,
shared_axes=False,
height=plot_height,
legend_cols=legend_cols,
)

# update completion rates as a function of PPC ID
Expand All @@ -1949,6 +1951,8 @@ def update_ppp_figures(nppc_fin):
toolbar="left",
active_tools=["box_zoom"],
height=int(plot_height * 0.5),
legend_cols=legend_cols,
legend_offset=(10, -30),
)

p_comp_tot_n = (
Expand All @@ -1961,6 +1965,8 @@ def update_ppp_figures(nppc_fin):
toolbar="left",
active_tools=["box_zoom"],
height=int(plot_height * 0.5),
legend_cols=legend_cols,
legend_offset=(10, -30),
)

"""
Expand Down
10 changes: 9 additions & 1 deletion src/pfs_target_uploader/widgets/PppResultWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def __init__(
self.df_input = None
self.df_summary = None
self.origname = None
self.origname_ppc = None
self.origdata = None
self.upload_time = None
self.secret_token = None
self.exetime: int = exetime
self.max_nppc = max_nppc
self.status_ = 0

self.ppp_title = pn.pane.Markdown(
"""# Results of PFS pointing simulation""",
Expand Down Expand Up @@ -91,9 +93,11 @@ def reset(self):
self.df_input = None
self.df_summary = None
self.origname = None
self.origname_ppc = None
self.origdata = None
self.upload_time = None
self.secret_token = None
self.status_ = 0

def show_results(self):
logger.info("showing PPP results")
Expand Down Expand Up @@ -184,9 +188,11 @@ def stream_export_files(df_psl, df_ppc, p_fig):
self.df_summary,
p_fig,
origname=self.origname,
origname_ppc=self.origname_ppc,
origdata=self.origdata,
export=True,
)

self.export_button.filename = outfile_zip
return sio

Expand Down Expand Up @@ -333,7 +339,6 @@ def run_ppp(
sub_m,
obj_allo_M_fin,
uS_M2,
tb_ppc,
single_exptime=self.single_exptime,
box_width=self.box_width,
)
Expand All @@ -346,6 +351,7 @@ def upload(
export=False,
single_exptime=None,
observation_type="queue",
ppc_status="auto",
):
if single_exptime is None:
single_exptime = self.single_exptime
Expand All @@ -369,12 +375,14 @@ def upload(
ppp_fig,
outdir_prefix=outdir_prefix,
origname=self.origname,
origname_ppc=self.origname_ppc,
origdata=self.origdata,
secret_token=self.secret_token,
upload_time=self.upload_time,
ppp_status=self.ppp_status,
single_exptime=single_exptime,
observation_type=observation_type,
ppc_status=ppc_status,
)

return outdir, outfile_zip, None

0 comments on commit 90212d2

Please sign in to comment.