Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Elisa-Visentin committed May 16, 2024
1 parent 91c1e5f commit 87423b3
Showing 1 changed file with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
logger.setLevel(logging.INFO)


def nsb(run_list, simtel, lst_config, run_number):
def nsb(run_list, simtel, lst_config, run_number, denominator):

"""
Here we compute the NSB value for a run based on a subset of subruns.
Expand All @@ -42,7 +42,7 @@ def nsb(run_list, simtel, lst_config, run_number):
"""

noise = []
denominator = 25

if len(run_list) == 0:
logger.warning(
"There is no subrun matching the provided run number. Check the list of the LST runs (LST_runs.txt)"
Expand All @@ -51,7 +51,7 @@ def nsb(run_list, simtel, lst_config, run_number):
if len(run_list) < denominator:
mod = 1
else:
mod = int(len(run_list) / denominator)
mod = len(run_list) // denominator
failed = 0
for ii in range(0, len(run_list)):
subrun = run_list[ii].split(".")[-2]
Expand All @@ -65,7 +65,7 @@ def nsb(run_list, simtel, lst_config, run_number):
except IndexError:
failed = failed + 1
if len(run_list) > denominator:
mod = int(len(run_list) / (denominator + failed))
mod = (len(run_list) - ii) // (denominator -len(noise))
logger.warning(
f"Subrun {subrun} caused an error in the NSB level evaluation for run {run_number}. Check reports before using it"
)
Expand Down Expand Up @@ -101,7 +101,14 @@ def main():
type=str,
help="Day of the run to be processed",
)

parser.add_argument(
"--denominator",
"-s",
dest="denominator",
type=int,
default=25,
help="Number of subruns to be processed",
)
args = parser.parse_args()
with open(
args.config_file, "rb"
Expand All @@ -110,6 +117,7 @@ def main():
NSB_match = config["general"]["NSB_matching"]
run_number = args.run
date = args.day
denominator = args.denominator
simtel = "/fefs/aswg/data/mc/DL0/LSTProd2/TestDataset/sim_telarray/node_theta_14.984_az_355.158_/output_v1.4/simtel_corsika_theta_14.984_az_355.158_run10.simtel.gz"

nsb_list = config["general"]["nsb"]
Expand All @@ -130,35 +138,21 @@ def main():
print(lst_config)
if NSB_match:
LST_files = np.sort(glob.glob(f"nsb_LST_[0-9]*_{run_number}.txt"))

if len(LST_files) > 1:
logger.info(
f"Run {run_number} classified in more than one NSB bin. Removing all these files and evaluating it again"
)
for kk in LST_files:
os.remove(kk)
LST_files = []

if len(LST_files) == 1:
logger.info(f"Run {run_number} already processed")
return
else:
LST_files = np.sort(glob.glob(f"nsb_LST_nsb_*{run_number}*.txt"))

if len(LST_files) > 1:
logger.warning(
f"More than one files exists for run {run_number}. Removing all these files and evaluating it again."
)
for repeated_files in LST_files:
os.remove(repeated_files)
LST_files = []
elif len(LST_files) == 1:

if len(LST_files) == 1:
logger.info(f"Run {run_number} already processed.")
return

# date_lst = date.split("_")[0] + date.split("_")[1] + date.split("_")[2]
inputdir = f"/fefs/aswg/data/real/DL1/{date}/{lst_version}/{lst_tailcut}"
run_list = np.sort(glob.glob(f"{inputdir}/dl1*Run*{run_number}.*.h5"))
noise = nsb(run_list, simtel, lst_config, run_number)
noise = nsb(run_list, simtel, lst_config, run_number, denominator)
if len(noise) == 0:
logger.warning(
"No NSB value could be evaluated: check the observation logs (observation problems, car flashes...)"
Expand Down

0 comments on commit 87423b3

Please sign in to comment.