Skip to content

Commit

Permalink
Bugs + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisa-Visentin committed Sep 18, 2023
1 parent 0b097b9 commit ff159f5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
4 changes: 2 additions & 2 deletions nsb_scripts/LSTnsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def main():
noise.append(a)
a = sum(noise) / len(noise)
std = np.std(noise)
logger.info("run", run_number, "nsb average (all)", a, "std", std)
logger.info(f"Run n. {run_number}", "nsb average (all)", a, "std", std)
subrun_ok = []
for sr in range(0, len(noise)):
if np.abs(noise[sr] - a) < 3 * std:
subrun_ok.append(noise[sr])
a = sum(subrun_ok) / len(subrun_ok)
logger.info("run", run_number, "nsb average (w/o outliers)", a)
logger.info(f"Run n. {run_number}", "nsb average (w/o outliers)", a)
for j in range(0, len(nsb)):
if (a < nsb_limit[j + 1]) & (a > nsb_limit[j]):
with open(f"{source}_LST_{nsb[j]}_{run_number}.txt", "a+") as f:
Expand Down
4 changes: 2 additions & 2 deletions nsb_scripts/nsb_coincident_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def configfile_coincidence(ids, target_dir):
+ "\n\n"
)
f.write(
'event_coincidence:\n timestamp_type_lst: "dragon_time" # select "dragon_time", "tib_time" or "ucts_time"\n window_half_width: "300 ns"\n'
'event_coincidence:\n timestamp_type_lst: "dragon_time" # select "dragon_time", "tib_time" or "ucts_time"\n pre_offset_search: true\n n_pre_offset_search_events: 100\n window_half_width: "300 ns"\n'
)
f.write(' time_offset:\n start: "-10 us"\n stop: "0 us"\n')
f.close()
Expand Down Expand Up @@ -213,7 +213,7 @@ def linking_bash_lst(scripts_dir, target_dir, LST_runs, nsb, date):
+ str(nsb)
+ "\n"
)
f.write(f"#SBATCH --array=0-{process_size}%50\n")
f.write(f"#SBATCH --array=0-{process_size}\n")
f.write("#SBATCH --mem=30g\n")
f.write("#SBATCH -N 1\n\n")
f.write("ulimit -l unlimited\n")
Expand Down
11 changes: 6 additions & 5 deletions nsb_scripts/nsb_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
logger.setLevel(logging.INFO)


def bash_scripts(run, config):
def bash_scripts(run, config, source):

f = open(f"run_{run}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p long\n")
Expand All @@ -26,7 +27,7 @@ def bash_scripts(run, config):
f.write("ulimit -a\n\n")

f.write(
f"conda run -n magic-lst python LSTnsb.py -c {config} -i {run} > nsblog_{run}.log 2>&1 \n\n"
f"conda run -n magic-lst python LSTnsb.py -c {config} -i {run} > {source}_nsblog_{run}.log 2>&1 \n\n"
)
f.close()

Expand All @@ -47,15 +48,15 @@ def main():
args.config_file, "rb"
) as f: # "rb" mode opens the file in binary format for reading
config = yaml.safe_load(f)

source=config["directories"]["target_name"]
runs = config["general"]["LST_runs"]

with open(str(runs), "r") as LSTfile:
run = LSTfile.readlines()
print("***** Generating merge bashscripts...")
print("***** Generating bashscripts...")
for i in run:
i = i.rstrip()
bash_scripts(i, args.config_file)
bash_scripts(i, args.config_file, source)
print("Process name: nsb")
print(
"To check the jobs submitted to the cluster, type: squeue -n nsb"
Expand Down
6 changes: 1 addition & 5 deletions nsb_scripts/nsb_merge_M1_M2_night.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ def merge(scripts_dir, target_dir):
process_name = "merging_" + target_dir.split("/")[-2:][1]

MAGIC_DL1_dir = target_dir + f"/v{__version__}" + "/DL1/" + p
if os.path.exists(MAGIC_DL1_dir + "/M1") & os.path.exists(
MAGIC_DL1_dir + "/M2"
):
if not os.path.exists(MAGIC_DL1_dir + "/Merged"):
os.mkdir(MAGIC_DL1_dir + "/Merged")


f = open(f"Merge_2_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
Expand Down
27 changes: 13 additions & 14 deletions nsb_scripts/nsb_merge_M1_M2_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ def merge(scripts_dir, target_dir):
process_name = "merging_" + target_dir.split("/")[-2:][1]

MAGIC_DL1_dir = target_dir + f"/v{__version__}" + "/DL1/" + p
if os.path.exists(MAGIC_DL1_dir + "/M1") & os.path.exists(
MAGIC_DL1_dir + "/M2"
):
if not os.path.exists(MAGIC_DL1_dir + "/Merged"):
os.mkdir(MAGIC_DL1_dir + "/Merged")


f = open(f"Merge_1_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
Expand All @@ -69,15 +65,18 @@ def merge(scripts_dir, target_dir):
for x in glob.glob(f"{MAGIC_DL1_dir}/M2/{i}/*")
]
for r in runs:
if not os.path.exists(MAGIC_DL1_dir + f"/Merged/{i}/Merged"):
os.mkdir(f"{MAGIC_DL1_dir}/Merged/{i}/Merged")
if not os.path.exists(
MAGIC_DL1_dir + f"/Merged/{i}/Merged/logs"
):
os.mkdir(f"{MAGIC_DL1_dir}/Merged/{i}/Merged/logs")
f.write(
f"conda run -n magic-lst python {scripts_dir}/merge_hdf_files.py --input-dir {MAGIC_DL1_dir}/Merged/{i}/{r} --output-dir {MAGIC_DL1_dir}/Merged/{i}/Merged --run-wise >{MAGIC_DL1_dir}/Merged/{i}/Merged/logs/merge_{i}.log \n"
)

if (len(os.listdir(MAGIC_DL1_dir + f"/M1/{i}/{r}"))>1) and (len(os.listdir(MAGIC_DL1_dir + f"/M2/{i}/{r}")))>1:

if not os.path.exists(MAGIC_DL1_dir + f"/Merged/{i}/Merged"):
os.mkdir(f"{MAGIC_DL1_dir}/Merged/{i}/Merged")
if not os.path.exists(
MAGIC_DL1_dir + f"/Merged/{i}/Merged/logs"
):
os.mkdir(f"{MAGIC_DL1_dir}/Merged/{i}/Merged/logs")
f.write(
f"conda run -n magic-lst python {scripts_dir}/merge_hdf_files.py --input-dir {MAGIC_DL1_dir}/Merged/{i}/{r} --output-dir {MAGIC_DL1_dir}/Merged/{i}/Merged --run-wise >{MAGIC_DL1_dir}/Merged/{i}/Merged/logs/merge_{i}.log \n"
)


f.close()
Expand Down
2 changes: 1 addition & 1 deletion nsb_scripts/nsb_merge_subruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def merge(scripts_dir, target_dir):
process_name = "merging_" + target_dir.split("/")[-2:][1]

MAGIC_DL1_dir = target_dir + f"/v{__version__}" + "/DL1/" + p

if os.path.exists(MAGIC_DL1_dir + "/M1") & os.path.exists(
MAGIC_DL1_dir + "/M2"
):
if not os.path.exists(MAGIC_DL1_dir + "/Merged"):
os.mkdir(MAGIC_DL1_dir + "/Merged")

f = open(f"Merge_0_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
Expand Down
5 changes: 3 additions & 2 deletions nsb_scripts/nsb_stereo_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def bash_stereo(scripts_dir, target_dir, nsb):
os.mkdir(stereoDir + "/logs")
if not os.listdir(f"{nightLST}"):
continue

if len(os.listdir(nightLST ))<2:
continue
os.system(
f"ls {nightLST}/*LST*.h5 > {stereoDir}/logs/list_coin_{nsb}.txt"
) # generating a list with the DL1 coincident data files.
Expand All @@ -142,7 +143,7 @@ def bash_stereo(scripts_dir, target_dir, nsb):
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "_stereo" + str(nsb) + "\n")
f.write(f"#SBATCH --array=0-{process_size}%100\n")
f.write(f"#SBATCH --array=0-{process_size}\n")
f.write("#SBATCH -N 1\n\n")
f.write("ulimit -l unlimited\n")
f.write("ulimit -s unlimited\n")
Expand Down

0 comments on commit ff159f5

Please sign in to comment.