Skip to content

Commit

Permalink
Fixed bugs and minor refactoring (multi-source analysis, scripts dire…
Browse files Browse the repository at this point in the history
…ctory)
  • Loading branch information
Elisa-Visentin committed Sep 7, 2023
1 parent db5f69e commit 156174f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 25 deletions.
6 changes: 3 additions & 3 deletions nsb_scripts/LSTnsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ def main():
runs = config["general"]["LST_runs"]
nsb = config["general"]["nsb"]
width=[a/2 - b/2 for a, b in zip(nsb[1:], nsb[:-1])]

source= config["directories"]['target_name']
width.append(0.25)
nsb_limit=[a + b for a, b in zip(nsb[:], width[:])]
nsb_limit.insert(0,0)
print(nsb_limit)
lst_config='lstchain_standard_config.json'
LST_files=np.sort(glob.glob('LST_[1-4]*.txt'))
LST_files=np.sort(glob.glob(f'{source}_LST_[0-9]*.txt'))
with open(runs) as LSTfile:
LST_runs = np.genfromtxt(LSTfile,dtype=str,delimiter=',')
if (len(LST_runs)==2) and (len(LST_runs[0])==10):
Expand Down Expand Up @@ -82,7 +82,7 @@ def main():
print('nsb average', a)
for j in range (0,len(nsb)):
if (a<nsb_limit[j+1])&(a>nsb_limit[j]):
with open(f"LST_{nsb[j]}_.txt", "a+") as f:
with open(f"{source}_LST_{nsb[j]}_.txt", "a+") as f:

f.write(str(i[0])+","+str(i[1])+"\n")

Expand Down
2 changes: 1 addition & 1 deletion nsb_scripts/nsb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ulimit -s unlimited
ulimit -a

start_time=`date +%s`
conda run -n magic-lst python LSTnsb.py > nsblog.log 2>&1
conda run -n magic-lst python LSTnsb.py -c PG1553_config_general.yaml > nsblog.log 2>&1
end_time=`date +%s`
echo execution time was `expr $end_time - $start_time` s.

11 changes: 6 additions & 5 deletions nsb_scripts/nsb_DL1_to_DL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.INFO)

def DL1_to_2(scripts_dir,target_dir, nsb):
def DL1_to_2(scripts_dir,target_dir, nsb, config):

"""
This function creates the bash scripts to run lst1_magic_dl1_stereo_to_dl2.py.
Expand Down Expand Up @@ -68,7 +68,7 @@ def DL1_to_2(scripts_dir,target_dir, nsb):
f.write(f"SAMPLE_LIST=($(<{night}/list_of_DL1_stereo_files.txt))\n")
f.write("SAMPLE=${SAMPLE_LIST[${SLURM_ARRAY_TASK_ID}]}\n")
f.write(f'export LOG={output}'+'/DL1_to_DL2_${SLURM_ARRAY_TASK_ID}.log\n')
f.write(f'conda run -n magic-lst python {scripts_dir}/lst1_magic_dl1_stereo_to_dl2.py --input-file-dl1 $SAMPLE --input-dir-rfs {RFs_dir} --output-dir {output} --config-file {target_dir}/../config_general.yaml >$LOG 2>&1\n\n')
f.write(f'conda run -n magic-lst python {scripts_dir}/lst1_magic_dl1_stereo_to_dl2.py --input-file-dl1 $SAMPLE --input-dir-rfs {RFs_dir} --output-dir {output} --config-file {scripts_dir}/{config} >$LOG 2>&1\n\n')
f.close()


Expand Down Expand Up @@ -100,16 +100,17 @@ def main():

target_dir = config["directories"]["workspace_dir"]+config["directories"]["target_name"]
scripts_dir=config["directories"]["scripts_dir"]
listnsb = np.sort(glob.glob("LST_*_.txt"))
source=config['directories']['target_name']
listnsb = np.sort(glob.glob(f"{source}_LST_*_.txt"))
nsb=[]
for f in listnsb:
nsb.append(f.split('_')[1])
nsb.append(f.split('_')[2])

print('nsb', nsb)
for nsblvl in nsb:

print("***** Generating bashscripts for DL2...")
DL1_to_2(scripts_dir,target_dir, nsblvl)
DL1_to_2(scripts_dir,target_dir, nsblvl, args.config_file)



Expand Down
5 changes: 3 additions & 2 deletions nsb_scripts/nsb_DL2_to_DL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ def main():
print("***** Generating file config_DL3.yaml...")
print("***** This file can be found in ",target_dir)
configuration_DL3(telescope_ids, target_dir, target_coords)
listnsb = np.sort(glob.glob("LST_*_.txt"))
source=config['directories']['target_name']
listnsb = np.sort(glob.glob(f"{source}_LST_*_.txt"))
nsb=[]
for f in listnsb:
nsb.append(f.split('_')[1])
nsb.append(f.split('_')[2])

print('nsb', nsb)
for nsblvl in nsb:
Expand Down
24 changes: 18 additions & 6 deletions nsb_scripts/nsb_coincident_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,28 @@ def linking_lst(target_dir, LST_runs, nsb, date):

if not os.path.exists(coincidence_DL1_dir+"/Coincident/"+str(nsb)):
os.mkdir(f"{coincidence_DL1_dir}/Coincident/{nsb}")

print('date', date)
if (len(LST_runs)==2) and (len(LST_runs[0])==10):

LST=LST_runs
print(LST)
LST_runs=[]
LST_runs.append(LST)
print(LST_runs)



if (len(date)==2) and (len(date[0])==10):






dt=date
date=[]
date.append(dt)


for i in LST_runs:

Expand All @@ -95,9 +105,9 @@ def linking_lst(target_dir, LST_runs, nsb, date):
for subrun in list_of_subruns:
f.write(subrun+"\n")
f.close()

print('date',date)
for i in date:

print(i)
LSTdir = i[0].split("_")[0]+i[0].split("_")[1]+i[0].split("_")[2]
outputdir = f'{coincidence_DL1_dir}/Coincident/{nsb}/{LSTdir}'

Expand Down Expand Up @@ -170,14 +180,16 @@ def main():
telescope_ids = list(config["mc_tel_ids"].values())
target_dir = config["directories"]["workspace_dir"]+config["directories"]["target_name"]
scripts_dir=config["directories"]["scripts_dir"]
source=config['directories']['target_name']
print("***** Generating file config_coincidence.yaml...")
print("***** This file can be found in ",target_dir)
configfile_coincidence(telescope_ids,target_dir)
nsb= config["general"]["nsb"]
date = np.genfromtxt('LST_runs.txt', dtype=str, delimiter=',')
runs_all = config["general"]["LST_runs"]
date = np.genfromtxt(runs_all, dtype=str, delimiter=',')
for nsblvl in nsb:
try:
LST_runs = np.genfromtxt(f'LST_{nsblvl}_.txt',dtype=str,delimiter=',')
LST_runs = np.genfromtxt(f'{source}_LST_{nsblvl}_.txt',dtype=str,delimiter=',')

print("***** Linking the paths to LST data files...")
linking_lst(target_dir, LST_runs, nsblvl, date) #linking the data paths to current working directory
Expand Down
6 changes: 3 additions & 3 deletions nsb_scripts/nsb_merge_DL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ def main():
target_dir = str(Path(config["directories"]["workspace_dir"]))+"/"+config["directories"]["target_name"]

scripts_dir=config["directories"]["scripts_dir"]
source=config['directories']['target_name']


listnsb = np.sort(glob.glob("LST_*_.txt"))
listnsb = np.sort(glob.glob(f"{source}_LST_*_.txt"))
nsb=[]
for f in listnsb:
nsb.append(f.split('_')[1])
nsb.append(f.split('_')[2])

print('nsb', nsb)
for nsblvl in nsb:
Expand Down
11 changes: 9 additions & 2 deletions nsb_scripts/nsb_merging_runs_and_spliting_training_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def merge(scripts_dir, target_dir, identification, MAGIC_runs):
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")

print('directory',MAGIC_DL1_dir)
f = open(f"Merge_{identification}.sh","w")
f.write('#!/bin/sh\n\n')
f.write('#SBATCH -p short\n')
Expand Down Expand Up @@ -125,7 +125,14 @@ def main():
MAGIC_runs_and_dates = config["general"]["MAGIC_runs"]
MAGIC_runs = np.genfromtxt(MAGIC_runs_and_dates,dtype=str,delimiter=',')


if (len(MAGIC_runs)==2) and (len(MAGIC_runs[0])==10):

MAGIC=MAGIC_runs

MAGIC_runs=[]
MAGIC_runs.append(MAGIC)



print("***** Generating merge bashscripts...")
merge(scripts_dir,target_dir, "0_subruns", MAGIC_runs) #generating the bash script to merge the subruns
Expand Down
6 changes: 3 additions & 3 deletions nsb_scripts/nsb_stereo_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ def main():
target_dir = config["directories"]["workspace_dir"]+config["directories"]["target_name"]
scripts_dir=config["directories"]["scripts_dir"]
telescope_ids = list(config["mc_tel_ids"].values())

source=config['directories']['target_name']
print("***** Generating file config_stereo.yaml...")
print("***** This file can be found in ",target_dir)
configfile_stereo(telescope_ids, target_dir)
listnsb = np.sort(glob.glob("LST_*_.txt"))
listnsb = np.sort(glob.glob(f"{source}_LST_*_.txt"))
nsb=[]
for f in listnsb:
nsb.append(f.split('_')[1])
nsb.append(f.split('_')[2])

print('nsb', nsb)
for nsblvl in nsb:
Expand Down

0 comments on commit 156174f

Please sign in to comment.