Skip to content

Commit

Permalink
Source in bash scripts names
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisa-Visentin committed Sep 19, 2023
1 parent ff159f5 commit 5ddc02f
Show file tree
Hide file tree
Showing 8 changed files with 35 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(f"Run n. {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(f"Run n. {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
8 changes: 4 additions & 4 deletions nsb_scripts/nsb_coincident_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def configfile_coincidence(ids, target_dir):
f.close()


def linking_bash_lst(scripts_dir, target_dir, LST_runs, nsb, date):
def linking_bash_lst(scripts_dir, target_dir, LST_runs, nsb, date, source):
"""
This function links the LST data paths to the working directory and creates bash scripts.
Parameters
Expand Down Expand Up @@ -203,7 +203,7 @@ def linking_bash_lst(scripts_dir, target_dir, LST_runs, nsb, date):

if process_size < 0:
continue
f = open(f"LST_coincident_{nsb}_{outputdir.split('/')[-1]}.sh", "w")
f = open(f"{source}_LST_coincident_{nsb}_{outputdir.split('/')[-1]}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write(
Expand Down Expand Up @@ -280,7 +280,7 @@ def main():
print("***** Generating the bashscript...")
# bash_coincident(scripts_dir, target_dir, nsblvl)
linking_bash_lst(
scripts_dir, target_dir, LST_runs, nsblvl, date
scripts_dir, target_dir, LST_runs, nsblvl, date, source
) # linking the data paths to current working directory

print("***** Submitting processess to the cluster...")
Expand All @@ -299,7 +299,7 @@ def main():

# Below we run the bash scripts to find the coincident events
list_of_coincidence_scripts = np.sort(
glob.glob(f"LST_coincident_{nsblvl}*.sh")
glob.glob(f"{source}_LST_coincident_{nsblvl}*.sh")
)
if len(list_of_coincidence_scripts) < 1:
continue
Expand Down
4 changes: 2 additions & 2 deletions nsb_scripts/nsb_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

def bash_scripts(run, config, source):

f = open(f"run_{run}.sh", "w")
f = open(f"{source}_run_{run}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p long\n")
f.write("#SBATCH -J " + "nsb" + "\n")
Expand Down Expand Up @@ -61,7 +61,7 @@ def main():
print(
"To check the jobs submitted to the cluster, type: squeue -n nsb"
)
list_of_bash_scripts = np.sort(glob.glob("run_*.sh"))
list_of_bash_scripts = np.sort(glob.glob(f"{source}_run_*.sh"))

if len(list_of_bash_scripts) < 1:
return
Expand Down
9 changes: 5 additions & 4 deletions nsb_scripts/nsb_merge_M1_M2_night.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger.setLevel(logging.INFO)


def merge(scripts_dir, target_dir):
def merge(scripts_dir, target_dir, source):
"""
This function creates the bash scripts to run merge_hdf_files.py
Expand All @@ -43,7 +43,7 @@ def merge(scripts_dir, target_dir):
MAGIC_DL1_dir = target_dir + f"/v{__version__}" + "/DL1/" + p


f = open(f"Merge_2_{p}.sh", "w")
f = open(f"{source}_Merge_2_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -93,11 +93,12 @@ def main():
Path(config["directories"]["workspace_dir"])
/ config["directories"]["target_name"]
)
source=config["directories"]["target_name"]
scripts_dir = str(Path(config["directories"]["scripts_dir"]))

print("***** Generating merge bashscripts...")
merge(
scripts_dir, target_dir
scripts_dir, target_dir, source
)

print("***** Running merge_hdf_files.py in the MAGIC data files...")
Expand All @@ -108,7 +109,7 @@ def main():
)

# Below we run the bash scripts to merge the MAGIC files
list_of_merging_scripts = np.sort(glob.glob("Merge_2_*.sh"))
list_of_merging_scripts = np.sort(glob.glob(f"{source}_Merge_2_*.sh"))
if len(list_of_merging_scripts) < 1:
return
for n, run in enumerate(list_of_merging_scripts):
Expand Down
9 changes: 5 additions & 4 deletions nsb_scripts/nsb_merge_M1_M2_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger.setLevel(logging.INFO)


def merge(scripts_dir, target_dir):
def merge(scripts_dir, target_dir, source):
"""
This function creates the bash scripts to run merge_hdf_files.py
Expand All @@ -43,7 +43,7 @@ def merge(scripts_dir, target_dir):
MAGIC_DL1_dir = target_dir + f"/v{__version__}" + "/DL1/" + p


f = open(f"Merge_1_{p}.sh", "w")
f = open(f"{source}_Merge_1_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -107,11 +107,12 @@ def main():
Path(config["directories"]["workspace_dir"])
/ config["directories"]["target_name"]
)
source=config["directories"]["target_name"]
scripts_dir = str(Path(config["directories"]["scripts_dir"]))

print("***** Generating merge bashscripts...")
merge(
scripts_dir, target_dir
scripts_dir, target_dir, source
)

print("***** Running merge_hdf_files.py in the MAGIC data files...")
Expand All @@ -122,7 +123,7 @@ def main():
)

# Below we run the bash scripts to merge the MAGIC files
list_of_merging_scripts = np.sort(glob.glob("Merge_1_*.sh"))
list_of_merging_scripts = np.sort(glob.glob(f"{source}_Merge_1_*.sh"))
if len(list_of_merging_scripts) < 1:
return
for n, run in enumerate(list_of_merging_scripts):
Expand Down
9 changes: 5 additions & 4 deletions nsb_scripts/nsb_merge_subruns.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger.setLevel(logging.INFO)


def merge(scripts_dir, target_dir):
def merge(scripts_dir, target_dir, source):
"""
This function creates the bash scripts to run merge_hdf_files.py
Expand All @@ -47,7 +47,7 @@ def merge(scripts_dir, target_dir):
):
if not os.path.exists(MAGIC_DL1_dir + "/Merged"):
os.mkdir(MAGIC_DL1_dir + "/Merged")
f = open(f"Merge_0_{p}.sh", "w")
f = open(f"{source}_Merge_0_{p}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -143,11 +143,12 @@ def main():
Path(config["directories"]["workspace_dir"])
/ config["directories"]["target_name"]
)
source=config["directories"]["target_name"]
scripts_dir = str(Path(config["directories"]["scripts_dir"]))

print("***** Generating merge bashscripts...")
merge(
scripts_dir, target_dir
scripts_dir, target_dir, source
) # generating the bash script to merge the subruns

print("***** Running merge_hdf_files.py in the MAGIC data files...")
Expand All @@ -158,7 +159,7 @@ def main():
)

# Below we run the bash scripts to merge the MAGIC files
list_of_merging_scripts = np.sort(glob.glob("Merge_0_*.sh"))
list_of_merging_scripts = np.sort(glob.glob(f"{source}_Merge_0_*.sh"))
if len(list_of_merging_scripts) < 1:
return
for n, run in enumerate(list_of_merging_scripts):
Expand Down
15 changes: 8 additions & 7 deletions nsb_scripts/nsb_setting_up_config_and_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ def config_file_gen(ids, target_dir):
f.close()


def lists_and_bash_gen_MAGIC(scripts_dir, target_dir, telescope_ids, MAGIC_runs):
def lists_and_bash_gen_MAGIC(scripts_dir, target_dir, telescope_ids, MAGIC_runs, source):
"""
Below we create a bash script that links the MAGIC data paths to each subdirectory.
"""

process_name = target_dir.split("/")[-2:][0] + target_dir.split("/")[-2:][1]

f = open("linking_MAGIC_data_paths.sh", "w")
f = open(f"{source}_linking_MAGIC_data_paths.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -199,7 +199,7 @@ def lists_and_bash_gen_MAGIC(scripts_dir, target_dir, telescope_ids, MAGIC_runs)
number_of_nodes = len(number_of_nodes) - 1
if number_of_nodes < 0:
continue
f = open(f"MAGIC-II_dl0_to_dl1_run_{i[1]}.sh", "w")
f = open(f"{source}_MAGIC-II_dl0_to_dl1_run_{i[1]}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p long\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -248,7 +248,7 @@ def lists_and_bash_gen_MAGIC(scripts_dir, target_dir, telescope_ids, MAGIC_runs)
number_of_nodes = len(number_of_nodes) - 1
if number_of_nodes < 0:
continue
f = open(f"MAGIC-I_dl0_to_dl1_run_{i[1]}.sh", "w")
f = open(f"{source}_MAGIC-I_dl0_to_dl1_run_{i[1]}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p long\n")
f.write("#SBATCH -J " + process_name + "\n")
Expand Down Expand Up @@ -383,6 +383,7 @@ def main():
Path(config["directories"]["workspace_dir"])
/ config["directories"]["target_name"]
)
source=config["directories"]["target_name"]
scripts_dir = str(Path(config["directories"]["scripts_dir"]))

print("*** Reducing DL0 to DL1 data***")
Expand All @@ -400,16 +401,16 @@ def main():
config_file_gen(telescope_ids, target_dir)

lists_and_bash_gen_MAGIC(
scripts_dir, target_dir, telescope_ids, MAGIC_runs
scripts_dir, target_dir, telescope_ids, MAGIC_runs, source
) # MAGIC real data
# If there are MAGIC data, we convert them from DL0 to DL1 here:
if (telescope_ids[-2] > 0) or (telescope_ids[-1] > 0):
list_of_MAGIC_runs = glob.glob("MAGIC-*.sh")
list_of_MAGIC_runs = glob.glob(f"{source}_MAGIC-*.sh")
if len(list_of_MAGIC_runs) < 1:
return
for n, run in enumerate(list_of_MAGIC_runs):
if n == 0:
launch_jobs = f"linking=$(sbatch --parsable linking_MAGIC_data_paths.sh) && RES{n}=$(sbatch --parsable --dependency=afterany:$linking {run})"
launch_jobs = f"linking=$(sbatch --parsable {source}_linking_MAGIC_data_paths.sh) && RES{n}=$(sbatch --parsable --dependency=afterany:$linking {run})"
else:
launch_jobs = launch_jobs + f" && RES{n}=$(sbatch --parsable {run})"

Expand Down
8 changes: 4 additions & 4 deletions nsb_scripts/nsb_stereo_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def configfile_stereo(ids, target_dir):
f.close()


def bash_stereo(scripts_dir, target_dir, nsb):
def bash_stereo(scripts_dir, target_dir, nsb, source):
"""
This function generates the bashscript for running the stereo analysis.
Expand Down Expand Up @@ -139,7 +139,7 @@ def bash_stereo(scripts_dir, target_dir, nsb):
if process_size < 0:
continue

f = open(f"StereoEvents_{nsb}_{nightLST.split('/')[-1]}.sh", "w")
f = open(f"{source}_StereoEvents_{nsb}_{nightLST.split('/')[-1]}.sh", "w")
f.write("#!/bin/sh\n\n")
f.write("#SBATCH -p short\n")
f.write("#SBATCH -J " + process_name + "_stereo" + str(nsb) + "\n")
Expand Down Expand Up @@ -198,7 +198,7 @@ def main():

for nsblvl in nsb:
print("***** Generating the bashscript...")
bash_stereo(scripts_dir, target_dir, nsblvl)
bash_stereo(scripts_dir, target_dir, nsblvl, source)

print("***** Submitting processess to the cluster...")
print(
Expand All @@ -212,7 +212,7 @@ def main():
)

# Below we run the bash scripts to find the stereo events
list_of_stereo_scripts = np.sort(glob.glob(f"StereoEvents_{nsblvl}*.sh"))
list_of_stereo_scripts = np.sort(glob.glob(f"{source}_StereoEvents_{nsblvl}*.sh"))
if len(list_of_stereo_scripts) < 1:
continue
for n, run in enumerate(list_of_stereo_scripts):
Expand Down

0 comments on commit 5ddc02f

Please sign in to comment.