Skip to content

Commit

Permalink
remove exetime
Browse files Browse the repository at this point in the history
  • Loading branch information
wanqqq31 committed Oct 1, 2024
1 parent 00a168c commit 2418ec6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 113 deletions.
2 changes: 1 addition & 1 deletion src/pfs_target_uploader/pn_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def target_uploader_app(use_panel_cli=False):

panel_results = ValidationResultWidgets()
panel_targets = TargetWidgets()
panel_ppp = PppResultWidgets(exetime=max_exetime, max_nppc=max_nppc)
panel_ppp = PppResultWidgets(max_nppc=max_nppc)

panel_input.reset()
panel_input.db_path = db_path
Expand Down
71 changes: 11 additions & 60 deletions src/pfs_target_uploader/utils/ppp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def PPPrunStart(
uS,
uPPC,
weight_para,
exetime: int,
single_exptime: int = 900,
max_nppc: int = 200,
d_pfi=1.38,
Expand All @@ -65,14 +64,8 @@ def PPPrunStart(
if weight_para is None:
weight_para = [2.02, 0.01, 0.01]

is_exetime = (exetime is not None) and (exetime > 0)
is_nppc = (max_nppc is not None) and (max_nppc > 0)

if is_exetime:
logger.info(f"PPP iteration will be terminated after {exetime} seconds")
else:
logger.info("PPP calculation will be run until completion")

def count_N(sample):
"""calculate local count of targets
Expand Down Expand Up @@ -366,7 +359,7 @@ def KDE(sample, multiProcesing):

return X_, Y_, obj_dis_sig_, peak_x, peak_y

def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime, exetime: int):
def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime):

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Argument name "mutiPro" doesn't conform to snake_case naming style Warning

Argument name "mutiPro" doesn't conform to snake_case naming style

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Unused argument 'starttime' Note

Unused argument 'starttime'

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Too many local variables (21/15) Warning

Too many local variables (21/15)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Function name "PPP_centers" doesn't conform to snake_case naming style Warning

Function name "PPP_centers" doesn't conform to snake_case naming style
"""determine pointing centers
Parameters
Expand Down Expand Up @@ -402,38 +395,18 @@ def PPP_centers(sample_f, ppc_f, mutiPro, weight_para, starttime, exetime: int):
logger.info("PPC determined from the user input [PPP_centers s1]")
return sample_f, status

if is_exetime and ((time.time() - starttime) > exetime):
sample_f.meta["PPC"] = []
status = 1
logger.info("PPP stopped since the time is running out [PPP_centers s1]")
return sample_f, status

peak = []

for sample in target_clustering(
sample_f, d_pfi, algorithm=clustering_algorithm
):
if is_exetime and ((time.time() - starttime) > exetime):
status = 1
logger.info(
"PPP stopped since the time is running out [PPP_centers s2]"
)
break

sample_s = sample[sample["exptime_PPP"] > 0] # targets not finished

while any(sample_s["exptime_PPP"] > 0):
# NOTE: need a crors-check with He-san, probably.
if is_nppc and (len(peak) > max_nppc):
break

if is_exetime and ((time.time() - starttime) > exetime):
status = 1
logger.info(
"PPP stopped since the time is running out [PPP_centers s2_1]"
)
break

# -------------------------------
# ### peak_xy from KDE peak with weights
X_, Y_, obj_dis_sig_, peak_x, peak_y = KDE(sample_s, mutiPro)
Expand Down Expand Up @@ -925,7 +898,7 @@ def complete_ppc(sample, point_l):
sub_l,
)

def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
def netflow_iter(uS, obj_allo, weight_para, starttime, status):

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Argument name "uS" doesn't conform to snake_case naming style Warning

Argument name "uS" doesn't conform to snake_case naming style
"""iterate the total procedure to re-assign fibers to targets which have not been assigned
in the previous/first iteration
Expand Down Expand Up @@ -955,31 +928,17 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
obj_allo.remove_rows(np.where(obj_allo["tel_fiber_usage_frac"] == 0)[0])
return obj_allo, status

elif is_exetime and ((time.time() - starttime) > exetime):
status = 1
logger.info("PPP stopped since the time is running out [netflow_iter s1]")
return obj_allo, status

else:
# select non-assigned targets --> PPC determination --> netflow --> if no fibre assigned: shift PPC
iter_m2 = 0

while any(uS["exptime_assign"] < uS["exptime_PPP"]) and iter_m2 < 10:
if is_exetime and ((time.time() - starttime) > exetime):
status = 1
logger.info(
"PPP stopped since the time is running out [netflow_iter s2]"
)
break

uS_t1 = uS[uS["exptime_assign"] < uS["exptime_PPP"]]
uS_t1["exptime_PPP"] = (
uS_t1["exptime_PPP"] - uS_t1["exptime_assign"]
) # remained exposure time

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

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_t2" doesn't conform to snake_case naming style Warning

Variable name "uS_t2" doesn't conform to snake_case naming style

obj_allo_t = netflowRun(uS_t2)

Expand Down Expand Up @@ -1026,15 +985,13 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
out_obj_allo_M_fin = []

if len(uS_L) > 0 and len(uS_M) == 0:
uS_L_s2, status_ = PPP_centers(
uS_L, uPPC_L, True, weight_para, t_ppp_start, exetime
)
uS_L_s2, status_ = PPP_centers(uS_L, uPPC_L, True, weight_para, t_ppp_start)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_L_s2" doesn't conform to snake_case naming style Warning

Variable name "uS_L_s2" doesn't conform to snake_case naming style
obj_allo_L = netflowRun(uS_L_s2)

if len(uPPC_L) == 0:
uS_L2 = complete_ppc(uS_L_s2, obj_allo_L)[0]
obj_allo_L_fin, status_ = netflow_iter(
uS_L2, obj_allo_L, weight_para, t_ppp_start, exetime, status_
uS_L2, obj_allo_L, weight_para, t_ppp_start, status_
)
uS_L2, cR_L_fh, cR_L_fh_, cR_L_n, cR_L_n_, sub_l = complete_ppc(
uS_L_s2, obj_allo_L_fin
Expand All @@ -1053,15 +1010,13 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
out_sub_l = sub_l

if len(uS_M) > 0 and len(uS_L) == 0:
uS_M_s2, status_ = PPP_centers(
uS_M, uPPC_M, True, weight_para, t_ppp_start, exetime
)
uS_M_s2, status_ = PPP_centers(uS_M, uPPC_M, True, weight_para, t_ppp_start)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_M_s2" doesn't conform to snake_case naming style Warning

Variable name "uS_M_s2" doesn't conform to snake_case naming style
obj_allo_M = netflowRun(uS_M_s2)

if len(uPPC_M) == 0:
uS_M2 = complete_ppc(uS_M_s2, obj_allo_M)[0]
obj_allo_M_fin, status_ = netflow_iter(
uS_M2, obj_allo_M, weight_para, t_ppp_start, exetime, status_
uS_M2, obj_allo_M, weight_para, t_ppp_start, status_
)
uS_M2, cR_M_fh, cR_M_fh_, cR_M_n, cR_M_n_, sub_m = complete_ppc(
uS_M_s2, obj_allo_M_fin
Expand All @@ -1079,14 +1034,12 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
out_sub_m = sub_m

if len(uS_L) > 0 and len(uS_M) > 0:
uS_L_s2, status_ = PPP_centers(
uS_L, uPPC_L, True, weight_para, t_ppp_start, exetime
)
uS_L_s2, status_ = PPP_centers(uS_L, uPPC_L, True, weight_para, t_ppp_start)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_L_s2" doesn't conform to snake_case naming style Warning

Variable name "uS_L_s2" doesn't conform to snake_case naming style
obj_allo_L = netflowRun(uS_L_s2)
if len(uPPC_L) == 0:
uS_L2 = complete_ppc(uS_L_s2, obj_allo_L)[0]
obj_allo_L_fin, status_ = netflow_iter(
uS_L2, obj_allo_L, weight_para, t_ppp_start, exetime, status_
uS_L2, obj_allo_L, weight_para, t_ppp_start, status_
)
uS_L2, cR_L_fh, cR_L_fh_, cR_L_n, cR_L_n_, sub_l = complete_ppc(
uS_L_s2, obj_allo_L_fin
Expand All @@ -1098,14 +1051,12 @@ def netflow_iter(uS, obj_allo, weight_para, starttime, exetime, status):
)
out_obj_allo_L_fin = obj_allo_L

uS_M_s2, status_ = PPP_centers(
uS_M, uPPC_M, True, weight_para, t_ppp_start, exetime
)
uS_M_s2, status_ = PPP_centers(uS_M, uPPC_M, True, weight_para, t_ppp_start)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_M_s2" doesn't conform to snake_case naming style Warning

Variable name "uS_M_s2" doesn't conform to snake_case naming style
obj_allo_M = netflowRun(uS_M_s2)
if len(uPPC_M) == 0:
uS_M2 = complete_ppc(uS_M_s2, obj_allo_M)[0]
obj_allo_M_fin, status_ = netflow_iter(
uS_M2, obj_allo_M, weight_para, t_ppp_start, exetime, status_
uS_M2, obj_allo_M, weight_para, t_ppp_start, status_
)
uS_M2, cR_M_fh, cR_M_fh_, cR_M_n, cR_M_n_, sub_m = complete_ppc(
uS_M_s2, obj_allo_M_fin
Expand Down
77 changes: 25 additions & 52 deletions src/pfs_target_uploader/widgets/PppResultWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import sys

import multiprocessing as mp
import numpy as np
import panel as pn
import multiprocessing as mp
from astropy import units as u
from astropy.table import Table
from loguru import logger
Expand All @@ -21,7 +21,6 @@ class PppResultWidgets:

def __init__(
self,
exetime: int = 15 * 60, # [s] tentatively set to 15 min
max_nppc: int = 200, # max number of PPCs
):
# PPP status
Expand All @@ -36,7 +35,6 @@ def __init__(
self.origdata_ppc = None
self.upload_time = None
self.secret_token = None
self.exetime: int = exetime
self.max_nppc = max_nppc
self.status_ = 0

Expand All @@ -52,26 +50,17 @@ def __init__(
"Note that targets observable in the input observing period are considered.</font>"
)

self.ppp_warning_text_2 = (
"<font size=5>⚠️ **Warnings**</font>\n\n"
f"<font size=3>Calculation stops because time ({int(self.exetime/60):d} min) is running out. "
"If you would get the complete outputs, please modify the input list or consult with the observatory. </font>"
)

self.ppp_warning_text_3 = (
"<font size=5>⚠️ **Warnings**</font>\n\n"
f"<font size=3>1. The total requested time exceeds {int(self.max_reqtime_normal)} hours (maximum for a normal program). "
"Please make sure to adjust it to your requirement before proceeding to the submission. "
"Note that targets observable in the input observing period are considered."
f"\n 2. Calculation stops because time ({int(self.exetime/60):d} min) is running out."
"If you would get the complete outputs, please modify the input list or consult with the observatory. </font>"
)

self.ppp_error_text_1 = (
"<font size=5>⚠️ **Error**</font>\n\n"
"<font size=3>No fiber can be assigned. Please check the input pointing list, or the single exposure time.</font>"
)

self.ppp_error_text_2 = (
"<font size=5>⚠️ **Error**</font>\n\n"

Check warning

Code scanning / Prospector (reported by Codacy)

Using an f-string that does not have any interpolated variables (f-string-without-interpolation) Warning

Using an f-string that does not have any interpolated variables (f-string-without-interpolation)

Check notice

Code scanning / Pylintpython3 (reported by Codacy)

Using an f-string that does not have any interpolated variables Note

Using an f-string that does not have any interpolated variables
f"<font size=3>Calculation stops because time is running out. "
"If you would get the complete outputs, please modify the input list or consult with the observatory. </font>"

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (122/100) Warning

Line too long (122/100)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (122/100) Warning

Line too long (122/100)
)

self.ppp_success_text = (
"<font size=5>✅ **Success**</font>\n\n"
"<font size=3>The total requested time is reasonable for normal program. "
Expand Down Expand Up @@ -117,12 +106,9 @@ def update_alert(df):
if self.status_ == 999 and rot > self.max_reqtime_normal:
text = self.ppp_warning_text_1
type = "warning"
elif self.status_ == 1 and rot > self.max_reqtime_normal:
text = self.ppp_warning_text_3
type = "warning"
elif self.status_ == 1 and rot <= self.max_reqtime_normal:
text = self.ppp_warning_text_2
type = "warning"
elif self.status_ == 1:
text = self.ppp_error_text_2
type = "danger"
elif self.status_ == 2 and df is None:
text = self.ppp_error_text_1
type = "danger"
Expand Down Expand Up @@ -315,7 +301,6 @@ def run_ppp(
tb_visible,
tb_ppc,
weights,
self.exetime,
self.single_exptime,
self.max_nppc,
1.38,
Expand All @@ -331,9 +316,10 @@ def run_ppp(
ppp_run.join(max_exetime)

if ppp_run.is_alive():
# if ppp is still running after max_exetime, kill it
logger.error("Pointing simulation failed (runout time)")
pn.state.notifications.error(
f"Pointing simulation stops because time ({int(max_exetime):d} sec) is running out.",
f"Simulation stops because time ({int(max_exetime):d} sec) is running out.",
duration=0, # ever
)

Expand All @@ -355,7 +341,19 @@ def run_ppp(
sub_m,
obj_allo_M_fin,

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "obj_allo_M_fin" doesn't conform to snake_case naming style Warning

Variable name "obj_allo_M_fin" doesn't conform to snake_case naming style

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "obj_allo_M_fin" doesn't conform to snake_case naming style Warning

Variable name "obj_allo_M_fin" doesn't conform to snake_case naming style
self.status_,
) = (Table(), [], [], [], Table(), Table(), [], [], [], Table(), False)
) = (
Table(),
[],
[],
[],
Table(),
Table(),
[],
[],
[],
Table(),
1,
) # ppc_status=1 in case of runout time
else:
(
uS_L2,

Check warning

Code scanning / Pylint (reported by Codacy)

Variable name "uS_L2" doesn't conform to snake_case naming style Warning

Variable name "uS_L2" doesn't conform to snake_case naming style

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Variable name "uS_L2" doesn't conform to snake_case naming style Warning

Variable name "uS_L2" doesn't conform to snake_case naming style
Expand All @@ -371,31 +369,6 @@ def run_ppp(
self.status_,
) = ppp_run_results.get()

"""
(
uS_L2,
cR_L,
cR_L_,
sub_l,
obj_allo_L_fin,
uS_M2,
cR_M,
cR_M_,
sub_m,
obj_allo_M_fin,
self.status_,
) = PPPrunStart(
tb_visible,
tb_ppc,
weights,
self.exetime,
single_exptime=self.single_exptime,
max_nppc=self.max_nppc,
quiet=quiet,
clustering_algorithm=clustering_algorithm,
)
#"""

(
self.nppc,
self.p_result_fig,
Expand Down

0 comments on commit 2418ec6

Please sign in to comment.