Skip to content

Commit

Permalink
Merge pull request #289 from cta-observatory/gainsel
Browse files Browse the repository at this point in the history
Add argument to allow the selection of the tool for the gain selection
  • Loading branch information
morcuended authored May 9, 2024
2 parents 5ffc014 + acb75c3 commit 284a1d2
Showing 1 changed file with 38 additions and 14 deletions.
52 changes: 38 additions & 14 deletions src/osa/scripts/gain_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

PATH = "PATH=/fefs/aswg/software/offline_dvr/bin:$PATH"

parser = argparse.ArgumentParser(add_help=False)
parser = argparse.ArgumentParser()
parser.add_argument(
"--check",
action="store_true",
Expand All @@ -50,13 +50,14 @@
"--date",
default=None,
type=str,
help="Night to apply the gain selection",
help="Night to apply the gain selection in YYYYMMDD format",
)
parser.add_argument(
"-l",
"--dates-file",
default=None,
help="List of dates to apply the gain selection",
help="List of dates to apply the gain selection. The input file should list"
"the dates in the format YYYYMMDD, one date per line.",
)
parser.add_argument(
"-o",
Expand All @@ -79,12 +80,20 @@
default=18,
help="Time to stop gain selection in HH format. Default is 18.",
)
parser.add_argument(
"-t",
"--tool",
type=str,
default=None,
help="Choose tool to apply the gain selection regardless the date. Possible options are: lst_dvr (by default used for dates "
"previous to 20231205) and lstchain_r0_to_r0g (by default used for dates later than 20231205).",
)

def get_sbatch_script(
run_id, subrun, input_file, output_dir, log_dir, log_file, ref_time, ref_counter, module, ref_source, script
run_id, subrun, input_file, output_dir, log_dir, log_file, ref_time, ref_counter, module, ref_source, tool
):
"""Build the sbatch job pilot script for running the gain selection."""
if script=="old":
if tool == "lst_dvr":
return dedent(
f"""\
#!/bin/bash
Expand All @@ -98,7 +107,7 @@ def get_sbatch_script(
lst_dvr {input_file} {output_dir} {ref_time} {ref_counter} {module} {ref_source}
"""
)
elif script=="new":
elif tool == "lstchain_r0_to_r0g":
return dedent(
f"""\
#!/bin/bash
Expand All @@ -113,16 +122,17 @@ def get_sbatch_script(
"""
)

def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path = None, no_queue_check: bool = False):
def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path = None, tool: str = None, no_queue_check: bool = False):
"""
Submit the jobs to apply the gain selection to the data for a given date
on a subrun-by-subrun basis.
"""

if date < "20231205":
script = "old"
else:
script = "new"
if not tool:
if date < "20231205":
tool = "lst_dvr"
else:
tool = "lstchain_r0_to_r0g"

run_summary_dir = Path("/fefs/aswg/data/real/monitoring/RunSummary")
run_summary_file = run_summary_dir / f"RunSummary_{date}.ecsv"
Expand Down Expand Up @@ -199,7 +209,7 @@ def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path =
ref_counter,
module,
ref_source,
script,
tool,
)
)
sp.run(["sbatch", job_file], check=True)
Expand Down Expand Up @@ -328,7 +338,14 @@ def main():
check_failed_jobs(args.date, args.output_basedir)
else:
log.info(f"Applying gain selection to date {args.date}")
apply_gain_selection(args.date, args.start_time, args.end_time, args.output_basedir, no_queue_check=args.no_queue_check)
apply_gain_selection(
args.date,
args.start_time,
args.end_time,
args.output_basedir,
args.tool,
no_queue_check=args.no_queue_check,
)


elif args.dates_file:
Expand All @@ -342,7 +359,14 @@ def main():
else:
for date in list_of_dates:
log.info(f"Applying gain selection to date {date}")
apply_gain_selection(date, args.start_time, args.end_time, args.output_basedir, no_queue_check=args.no_queue_check)
apply_gain_selection(
date,
args.start_time,
args.end_time,
args.output_basedir,
args.tool,
no_queue_check=args.no_queue_check,
)
log.info("Done! No more dates to process.")


Expand Down

0 comments on commit 284a1d2

Please sign in to comment.