lstosa 0.10.11__py3-none-any.whl → 0.10.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lstosa
3
- Version: 0.10.11
3
+ Version: 0.10.12
4
4
  Summary: Onsite analysis pipeline for the CTA LST-1
5
5
  Author: María Láinez, José Enrique Ruiz, Lab Saha, Andrés Baquero, José Luis Contreras, Maximilian Linhoff
6
6
  Author-email: Daniel Morcuende <dmorcuen@ucm.es>
@@ -1,6 +1,6 @@
1
1
  osa/__init__.py,sha256=crotf1NMTfNdZuCua_5T_jk3kvZrAAwVw4FPrfxv994,193
2
- osa/_version.py,sha256=BHIdn73vwwgskUs3cpzDgJte1GN_HGZgzXDzfpJ_m6c,415
3
- osa/conftest.py,sha256=_NERtB9t-Oi7ykW4QDYy9ZbgsrYxXMmQ3QkDScH5JyE,19601
2
+ osa/_version.py,sha256=iptzZkijfZOuLJEgzcWGVRKqYSdbRz1HyJHUd9sgNhw,415
3
+ osa/conftest.py,sha256=NBeGqTUBRqCPirDSDPny4bf1e_OJXbiePazHwaoQPY4,20072
4
4
  osa/job.py,sha256=OnjF88kTVdURcrIR9iPenATNx2HteDFlAKtOX4fD144,26603
5
5
  osa/osadb.py,sha256=pkCuYbEG-moHG0uQHxwB7giQAv2XTld4HJ5gdn1F1hA,2422
6
6
  osa/paths.py,sha256=R-LwBlyoIJ-PuTJ8vcSYWMwzQY7YrgXq7gan0zhVzPY,14399
@@ -12,7 +12,7 @@ osa/configs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  osa/configs/config.py,sha256=cX0Vr4sorBVQ2KRqPIRSEGENKH_uC5lrgVHx1hp6YTk,1148
13
13
  osa/configs/datamodel.py,sha256=L_WRM91PBlMrtuE30akh7YR-56P0g9D994qzKSfhNJc,1950
14
14
  osa/configs/options.py,sha256=CyL7WnHiC_pvB3mnjRF7Wg43uPzQgmwlbvIqkRzlDLA,524
15
- osa/configs/sequencer.cfg,sha256=cysPy6q8vShh0V0LiEBfip-rUmwyNlNVDKhGPMiKH5g,4784
15
+ osa/configs/sequencer.cfg,sha256=vG-6VS2osCccEsY58JgaqqADUDz-k8-9tD3NDitscR4,4871
16
16
  osa/high_level/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  osa/high_level/selection_cuts.toml,sha256=ReSmcKtOPZY5JsZ9ExnxYdz7OrJEB8gghCbzHmeOyFg,128
18
18
  osa/high_level/significance.py,sha256=Y1jokkHCo-D_qSqxKiQzc6KJSmivznaJRS2xY-txNIo,9039
@@ -34,22 +34,22 @@ osa/provenance/config/definition.yaml,sha256=DSwqNln1jEXV8aUh7ca2r7ArMkpaMJi1xbH
34
34
  osa/provenance/config/environment.yaml,sha256=kPM6ucPyLZLDFzkwFWoY0C6vmAArG98U-P1UAl89bgE,246
35
35
  osa/provenance/config/logger.yaml,sha256=hy_lH3DfbRFh2VM_iawI-c-3wE0cjTRHy465C2eFfnQ,510
36
36
  osa/scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
- osa/scripts/autocloser.py,sha256=j7nRvglIv_Ol_GJzbcfqPHquBIWwQU515GkDRfc6_ho,14540
37
+ osa/scripts/autocloser.py,sha256=Z4x4yfDA2Xkr-6ld57L4VjWcVse-sLqkGuE6ZFgSXps,14716
38
38
  osa/scripts/calibration_pipeline.py,sha256=g9o1chqCRRSo7GNuQZRABjGnJYjZyfhkPgRLPmuV994,5703
39
39
  osa/scripts/closer.py,sha256=p11tq2YJLwsRK_CBWXU1465ArzLJ0qWlUCnubGqLPUo,18277
40
40
  osa/scripts/copy_datacheck.py,sha256=tfDs6oTdPbii4BOXp6bTHuED0xNJeqaPFrv6Ed7ZnWc,3104
41
41
  osa/scripts/datasequence.py,sha256=gXAp8arbLPEK-sca9VnME6-2XfUzBFIoEFchlUZYrXI,9260
42
- osa/scripts/gain_selection.py,sha256=yaz2fKicuCDgLbD3fhb3l9LBlXLEEO3yuZO-oDc2IPo,8084
42
+ osa/scripts/gain_selection.py,sha256=0ZOFgX-ZaJFoe_B0UI5NYRr7CmeHL1_bxjlB0n8E5hs,13775
43
43
  osa/scripts/provprocess.py,sha256=mufkZe6_qwH3DGqTFxINIc01hciF5RMpw3n_Mp7vwXU,18629
44
44
  osa/scripts/reprocess_longterm.py,sha256=wMfc3UVwickkGFiviIhOlB9ebMIqQPWoUrgg8hQ78Lg,2138
45
45
  osa/scripts/reprocessing.py,sha256=D-J8Rl3GrkWpxYkk6ci79oJOMewgGdxLkQgaHCAZuqs,3417
46
- osa/scripts/sequencer.py,sha256=6Cg-eIExk0eN8-HXkO6DBeFEWOI-FznDueqJEpbEzos,8163
46
+ osa/scripts/sequencer.py,sha256=GM6B17YQNJfBOosWx0gpXBy4fIwga3DC4T2nGapGQEU,8763
47
47
  osa/scripts/sequencer_webmaker.py,sha256=99P1rJiBlvNidDeppvtw4kOoAfsOxSMJ2sm4xlgKCE8,4640
48
48
  osa/scripts/show_run_summary.py,sha256=SoDLVKdQHOJkfenFguBOfXf10Gyv7heXSQAFnDVZqMs,2468
49
49
  osa/scripts/simulate_processing.py,sha256=NiRVYiwZENt_mnKncytgJT23_-tJMb1B5PswM12nnX4,6941
50
50
  osa/scripts/update_source_catalog.py,sha256=GHwWFc-y6S4KkUJxUVM5drdAnVDD0-n3D-Tv3CCmh4E,7218
51
51
  osa/scripts/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
- osa/scripts/tests/test_osa_scripts.py,sha256=1B2UFc3idLGSyqeuzf4IEvb6sEbtfaV8ogj1LoEoEyQ,12851
52
+ osa/scripts/tests/test_osa_scripts.py,sha256=7xms2Jq2ZalU5kiHBBbtFOxBzXhrybsNlT16nEtFTxU,12926
53
53
  osa/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
54
54
  osa/tests/test_jobs.py,sha256=F0jsHZ9BYB_cCHHxlXyO9v1E5_-mBJhuFtshtsAtnXo,15260
55
55
  osa/tests/test_osa.py,sha256=QCOsjUgPuNMHoef3Ym2sDXVjun2LaBrfKyroAIH-os8,415
@@ -59,7 +59,7 @@ osa/tests/test_raw.py,sha256=WkgwEc_vY0D6nREo-BSm6F-5xDpqidMC0DkS86pXlRU,1058
59
59
  osa/tests/test_report.py,sha256=OY-EsrXytoS6esfjUeLnIAmCMIw9EzoGD-elySafyhE,1365
60
60
  osa/tests/test_veto.py,sha256=UIsooji_5Z8TtAhc0UlD2VqheVd9DBufuMxinJ3e0w8,1066
61
61
  osa/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
62
- osa/utils/cliopts.py,sha256=Xqh-9w2o1iSHfwO0jHEW0AXQ9VeEw6X6IGLNAPKoNyc,13699
62
+ osa/utils/cliopts.py,sha256=XeVu6TjrIEoqQEqf4meIKSiRyobMqYTLuggj-iGU4SQ,14126
63
63
  osa/utils/iofile.py,sha256=kJ7KB1suynhS2cTf7EeHwhMXq3delC_ls2HFpCzvsZo,2021
64
64
  osa/utils/logging.py,sha256=1WcNPjjslo3y25jcEY_fe0yXOeJ6frZrGLAy1GJpu_k,1491
65
65
  osa/utils/mail.py,sha256=uQfqPQdiOVHTvEAXr9H15a7-g9DtYVNKjMEb9GnI0oY,554
@@ -74,9 +74,9 @@ osa/workflow/dl3.py,sha256=kz7L5jcKHFJ--UdQ8HQKLzWO6nxc2LLOTz42ExcqzTk,9921
74
74
  osa/workflow/stages.py,sha256=WYgUM2XDIaUjCc4_Zs_VSGW6gk73EaKcHk6ZMnPds74,6692
75
75
  osa/workflow/tests/test_dl3.py,sha256=aY5bb-8OcZGAXG3JPCZihChzkA_GsWjRIa31BHZn3Dg,299
76
76
  osa/workflow/tests/test_stages.py,sha256=TmC00XFACWZp740TQeFaokWi3C50ovj_XGiySWrrdZk,3944
77
- lstosa-0.10.11.dist-info/LICENSE,sha256=h6iWot11EtMvaDaS_AvCHKLTNByO5wEbMyNj1c90y1c,1519
78
- lstosa-0.10.11.dist-info/METADATA,sha256=X6RF9uQOjldNtXq3Fn6yOTSaiXpxqdQmIrtg0HDdat0,7349
79
- lstosa-0.10.11.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
80
- lstosa-0.10.11.dist-info/entry_points.txt,sha256=e5x7xddaqZhfdZPsErhHInqR4UGHsxXIlylEbTie0_8,928
81
- lstosa-0.10.11.dist-info/top_level.txt,sha256=_Tj8zVHdrOoWZuuWTHbDpNofxW0imUmKdlXhnxsXJek,4
82
- lstosa-0.10.11.dist-info/RECORD,,
77
+ lstosa-0.10.12.dist-info/LICENSE,sha256=h6iWot11EtMvaDaS_AvCHKLTNByO5wEbMyNj1c90y1c,1519
78
+ lstosa-0.10.12.dist-info/METADATA,sha256=HmGZoRfvvKndHKpKPPxBbsC85Rj7Eel1Q9lQhbZyJoM,7349
79
+ lstosa-0.10.12.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
80
+ lstosa-0.10.12.dist-info/entry_points.txt,sha256=e5x7xddaqZhfdZPsErhHInqR4UGHsxXIlylEbTie0_8,928
81
+ lstosa-0.10.12.dist-info/top_level.txt,sha256=_Tj8zVHdrOoWZuuWTHbDpNofxW0imUmKdlXhnxsXJek,4
82
+ lstosa-0.10.12.dist-info/RECORD,,
osa/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.10.11'
16
- __version_tuple__ = version_tuple = (0, 10, 11)
15
+ __version__ = version = '0.10.12'
16
+ __version_tuple__ = version_tuple = (0, 10, 12)
osa/configs/sequencer.cfg CHANGED
@@ -28,6 +28,7 @@ HIGH_LEVEL_DIR: %(OSA_DIR)s/HighLevel
28
28
  LONGTERM_DIR: %(OSA_DIR)s/DL1DataCheck_LongTerm
29
29
  MERGED_SUMMARY: %(OSA_DIR)s/Catalog/merged_RunSummary.ecsv
30
30
  SEQUENCER_WEB_DIR: %(OSA_DIR)s/SequencerWeb
31
+ GAIN_SELECTION_FLAG_DIR: %(OSA_DIR)s/GainSel
31
32
 
32
33
  # To be set by the user. Using PROD-ID will overcome the automatic
33
34
  # fetching of lstchain version. Otherwise leave it empty (and without the colon symbol).
@@ -138,6 +139,7 @@ WORKFLOWPREFIX: Workflow
138
139
  GRAPHSUFFIX: .dot
139
140
  SVGSUFFIX: .svg
140
141
  end_of_activity: NightFinished.txt
142
+ gain_selection_check: GainSelFinished.txt
141
143
 
142
144
  [OUTPUT]
143
145
  # REPORTWIDTH is the width in characters of the heading frame for the output
osa/conftest.py CHANGED
@@ -48,6 +48,13 @@ def monitoring_dir(base_test_dir):
48
48
  return monitoring_dir
49
49
 
50
50
 
51
+ @pytest.fixture(scope="session")
52
+ def osa_dir(base_test_dir):
53
+ osa_dir = base_test_dir / "OSA"
54
+ osa_dir.mkdir(parents=True, exist_ok=True)
55
+ return osa_dir
56
+
57
+
51
58
  @pytest.fixture(scope="session")
52
59
  def run_summary_dir(monitoring_dir):
53
60
  summary_dir = monitoring_dir / "RunSummary"
@@ -436,6 +443,8 @@ def sequence_file_list(
436
443
  drs4_time_calibration_files,
437
444
  systematic_correction_files,
438
445
  r0_data,
446
+ gain_selection_flag_file,
447
+ merged_run_summary,
439
448
  ):
440
449
  for r0_file in r0_data:
441
450
  assert r0_file.exists()
@@ -448,6 +457,8 @@ def sequence_file_list(
448
457
 
449
458
  assert run_summary_file.exists()
450
459
  assert run_catalog.exists()
460
+ assert gain_selection_flag_file.exists()
461
+ assert merged_run_summary.exists()
451
462
 
452
463
  run_program("sequencer", "-d", "2020-01-17", "--no-submit", "-t", "LST1")
453
464
  # First sequence in the list corresponds to the calibration run 1809
@@ -548,11 +559,9 @@ def run_catalog(run_catalog_dir):
548
559
 
549
560
 
550
561
  @pytest.fixture(scope="session")
551
- def database(base_test_dir):
562
+ def database(osa_dir):
552
563
  import sqlite3
553
564
 
554
- osa_dir = base_test_dir / "OSA"
555
- osa_dir.mkdir(parents=True, exist_ok=True)
556
565
  db_file = osa_dir / "osa.db"
557
566
  with sqlite3.connect(db_file) as connection:
558
567
  cursor = connection.cursor()
@@ -562,3 +571,13 @@ def database(base_test_dir):
562
571
  )
563
572
  cursor.connection.commit()
564
573
  yield cursor
574
+
575
+
576
+ @pytest.fixture(scope="session")
577
+ def gain_selection_flag_file(osa_dir):
578
+
579
+ GainSel_dir = osa_dir / "GainSel" / "20200117"
580
+ GainSel_dir.mkdir(parents=True, exist_ok=True)
581
+ file = GainSel_dir / "GainSelFinished.txt"
582
+ file.touch()
583
+ return file
osa/scripts/autocloser.py CHANGED
@@ -41,6 +41,7 @@ class Telescope:
41
41
  config_file: Path,
42
42
  ignore_cronlock: bool = False,
43
43
  test: bool = False,
44
+ no_gainsel: bool = False,
44
45
  ):
45
46
  """
46
47
  Parameters
@@ -82,7 +83,7 @@ class Telescope:
82
83
  if not self.lock_automatic_sequencer() and not ignore_cronlock:
83
84
  log.warning(f"{self.telescope} already locked! Ignoring {self.telescope}")
84
85
  return
85
- if not self.simulate_sequencer(date, config_file, test):
86
+ if not self.simulate_sequencer(date, config_file, test, no_gainsel):
86
87
  log.warning(
87
88
  f"Simulation of the sequencer failed "
88
89
  f"for {self.telescope}! Ignoring {self.telescope}"
@@ -121,7 +122,7 @@ class Telescope:
121
122
  self.locked = True
122
123
  return True
123
124
 
124
- def simulate_sequencer(self, date: str, config_file: Path, test: bool):
125
+ def simulate_sequencer(self, date: str, config_file: Path, test: bool, no_gainsel: bool):
125
126
  """Launch the sequencer in simulation mode."""
126
127
  if test:
127
128
  self.read_file()
@@ -135,6 +136,9 @@ class Telescope:
135
136
  date,
136
137
  self.telescope,
137
138
  ]
139
+ if no_gainsel:
140
+ sequencer_cmd.insert(1, "--no-gainsel")
141
+
138
142
  log.debug(f"Executing {' '.join(sequencer_cmd)}")
139
143
  sequencer = subprocess.Popen(
140
144
  sequencer_cmd,
@@ -445,7 +449,7 @@ def main():
445
449
  # create telescope and sequence objects
446
450
  log.info("Simulating sequencer...")
447
451
 
448
- telescope = Telescope(args.tel_id, date, args.config)
452
+ telescope = Telescope(args.tel_id, date, args.config, no_gainsel=args.no_gainsel)
449
453
 
450
454
  log.info(f"Processing {args.tel_id}...")
451
455
 
@@ -8,8 +8,8 @@ import subprocess as sp
8
8
  from pathlib import Path
9
9
  from textwrap import dedent
10
10
  from io import StringIO
11
+ import argparse
11
12
 
12
- import click
13
13
  from astropy.table import Table
14
14
  from lstchain.paths import run_info_from_filename, parse_r0_filename
15
15
 
@@ -17,51 +17,131 @@ from osa.scripts.reprocessing import get_list_of_dates, check_job_status_and_wai
17
17
  from osa.utils.utils import wait_for_daytime
18
18
  from osa.utils.logging import myLogger
19
19
  from osa.job import get_sacct_output, FORMAT_SLURM
20
+ from osa.configs.config import cfg
21
+ from osa.paths import DEFAULT_CFG
20
22
 
21
23
  log = myLogger(logging.getLogger(__name__))
22
24
 
23
25
  PATH = "PATH=/fefs/aswg/software/offline_dvr/bin:$PATH"
24
26
 
27
+ parser = argparse.ArgumentParser(add_help=False)
28
+ parser.add_argument(
29
+ "--check",
30
+ action="store_true",
31
+ default=False,
32
+ help="Check if any job failed",
33
+ )
34
+ parser.add_argument(
35
+ "--no-queue-check",
36
+ action="store_true",
37
+ default=False,
38
+ help="Do not wait until the number of jobs in the slurm queue is < 1500",
39
+ )
40
+ parser.add_argument(
41
+ "-c",
42
+ "--config",
43
+ action="store",
44
+ type=Path,
45
+ default=DEFAULT_CFG,
46
+ help="Configuration file",
47
+ )
48
+ parser.add_argument(
49
+ "-d",
50
+ "--date",
51
+ default=None,
52
+ type=str,
53
+ help="Night to apply the gain selection",
54
+ )
55
+ parser.add_argument(
56
+ "-l",
57
+ "--dates-file",
58
+ default=None,
59
+ help="List of dates to apply the gain selection",
60
+ )
61
+ parser.add_argument(
62
+ "-o",
63
+ "--output-basedir",
64
+ type=Path,
65
+ default=Path("/fefs/aswg/data/real/R0G"),
66
+ help="Output directory of the gain selected files. Default is /fefs/aswg/data/real/R0G."
67
+ )
68
+ parser.add_argument(
69
+ "-s",
70
+ "--start-time",
71
+ type=int,
72
+ default=10,
73
+ help="Time to (re)start gain selection in HH format. Default is 10.",
74
+ )
75
+ parser.add_argument(
76
+ "-e",
77
+ "--end-time",
78
+ type=int,
79
+ default=18,
80
+ help="Time to stop gain selection in HH format. Default is 18.",
81
+ )
25
82
 
26
83
  def get_sbatch_script(
27
- run_id, subrun, input_file, output_dir, log_dir, ref_time, ref_counter, module, ref_source
84
+ run_id, subrun, input_file, output_dir, log_dir, log_file, ref_time, ref_counter, module, ref_source, script
28
85
  ):
29
86
  """Build the sbatch job pilot script for running the gain selection."""
30
- return dedent(
31
- f"""\
32
- #!/bin/bash
33
-
34
- #SBATCH -D {log_dir}
35
- #SBATCH -o "gain_selection_{run_id:05d}_{subrun:04d}_%j.log"
36
- #SBATCH --job-name "gain_selection_{run_id:05d}"
37
- #SBATCH --export {PATH}
38
-
39
- lst_dvr {input_file} {output_dir} {ref_time} {ref_counter} {module} {ref_source}
40
- """
41
- )
42
-
87
+ if script=="old":
88
+ return dedent(
89
+ f"""\
90
+ #!/bin/bash
91
+
92
+ #SBATCH -D {log_dir}
93
+ #SBATCH -o "gain_selection_{run_id:05d}_{subrun:04d}_%j.log"
94
+ #SBATCH --job-name "gain_selection_{run_id:05d}"
95
+ #SBATCH --export {PATH}
96
+ #SBATCH --partition=short,long
97
+
98
+ lst_dvr {input_file} {output_dir} {ref_time} {ref_counter} {module} {ref_source}
99
+ """
100
+ )
101
+ elif script=="new":
102
+ return dedent(
103
+ f"""\
104
+ #!/bin/bash
105
+
106
+ #SBATCH -D {log_dir}
107
+ #SBATCH -o "gain_selection_{run_id:05d}_{subrun:04d}_%j.log"
108
+ #SBATCH --job-name "gain_selection_{run_id:05d}"
109
+ #SBATCH --mem=40GB
110
+ #SBATCH --partition=short,long
111
+
112
+ lstchain_r0_to_r0g --R0-file={input_file} --output-dir={output_dir} --log={log_file} --no-flatfield-heuristic
113
+ """
114
+ )
43
115
 
44
- def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path = None):
116
+ def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path = None, no_queue_check: bool = False):
45
117
  """
46
118
  Submit the jobs to apply the gain selection to the data for a given date
47
119
  on a subrun-by-subrun basis.
48
120
  """
49
121
 
122
+ if date < "20231205":
123
+ script = "old"
124
+ else:
125
+ script = "new"
126
+
50
127
  run_summary_dir = Path("/fefs/aswg/data/real/monitoring/RunSummary")
51
128
  run_summary_file = run_summary_dir / f"RunSummary_{date}.ecsv"
52
129
  summary_table = Table.read(run_summary_file)
53
130
  # Apply gain selection only to DATA runs
54
131
  data_runs = summary_table[summary_table["run_type"] == "DATA"]
132
+ log.info(f"Found {len(data_runs)} DATA runs to which apply the gain selection")
55
133
 
56
134
  output_dir = output_basedir / date
57
135
  log_dir = output_basedir / "log" / date
58
136
  output_dir.mkdir(parents=True, exist_ok=True)
59
137
  log_dir.mkdir(parents=True, exist_ok=True)
138
+ log_file = log_dir / f"r0_to_r0g_{date}.log"
60
139
  r0_dir = Path(f"/fefs/aswg/data/real/R0/{date}")
61
140
 
62
141
  for run in data_runs:
63
- # Check slurm queue status and sleep for a while to avoid overwhelming the queue
64
- check_job_status_and_wait(max_jobs=1500)
142
+ if not no_queue_check:
143
+ # Check slurm queue status and sleep for a while to avoid overwhelming the queue
144
+ check_job_status_and_wait(max_jobs=1500)
65
145
 
66
146
  # Avoid running jobs while it is still night time
67
147
  wait_for_daytime(start, end)
@@ -76,14 +156,25 @@ def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path =
76
156
  subrun_numbers = [int(file[-12:-8]) for file in files]
77
157
  input_files = []
78
158
 
79
- if ref_source in ["UCTS", "TIB"]:
159
+ if date < "20231205" and ref_source not in ["UCTS", "TIB"]:
160
+ input_files = r0_dir.glob(f"LST-1.?.Run{run_id:05d}.????.fits.fz")
161
+ log.info(
162
+ f"Run {run_id} does not have UCTS or TIB info, so gain selection cannot"
163
+ f"be applied. Copying directly the R0 files to {output_dir}."
164
+ )
165
+ for file in input_files:
166
+ sp.run(["cp", file, output_dir])
80
167
 
168
+ else:
81
169
  n_subruns = max(subrun_numbers)
82
170
 
83
171
  for subrun in range(n_subruns + 1):
84
172
  new_files = glob.glob(f"{r0_dir}/LST-1.?.Run{run_id:05d}.{subrun:04d}.fits.fz")
85
173
 
86
174
  if len(new_files) != 4:
175
+ log.info(f"Run {run_id}.{subrun:05d} does not have 4 streams of R0 files, so gain"
176
+ f"selection cannot be applied. Copying directly the R0 files to {output_dir}."
177
+ )
87
178
  for file in new_files:
88
179
  sp.run(["cp", file, output_dir])
89
180
 
@@ -91,6 +182,7 @@ def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path =
91
182
  new_files.sort()
92
183
  input_files.append(new_files[0])
93
184
 
185
+ log.info("Creating and launching the sbatch scripts for the rest of the runs to apply gain selection")
94
186
  for file in input_files:
95
187
  run_info = run_info_from_filename(file)
96
188
  job_file = log_dir / f"gain_selection_{run_info.run:05d}.{run_info.subrun:04d}.sh"
@@ -102,24 +194,21 @@ def apply_gain_selection(date: str, start: int, end: int, output_basedir: Path =
102
194
  file,
103
195
  output_dir,
104
196
  log_dir,
197
+ log_file,
105
198
  ref_time,
106
199
  ref_counter,
107
200
  module,
108
201
  ref_source,
202
+ script,
109
203
  )
110
204
  )
111
205
  sp.run(["sbatch", job_file], check=True)
112
206
 
113
- else:
114
-
115
- input_files = r0_dir.glob(f"LST-1.?.Run{run_id:05d}.????.fits.fz")
116
-
117
- for file in input_files:
118
- sp.run(["cp", file, output_dir])
119
-
120
207
  calib_runs = summary_table[summary_table["run_type"] != "DATA"]
208
+ log.info(f"Found {len(calib_runs)} NO-DATA runs")
121
209
 
122
210
  for run in calib_runs:
211
+ log.info(f"Copying R0 files corresponding to run {run} directly to {output_dir}")
123
212
  # Avoid copying files while it is still night time
124
213
  wait_for_daytime(start, end)
125
214
 
@@ -150,6 +239,19 @@ def run_sacct_j(job) -> StringIO:
150
239
  return StringIO(sp.check_output(sacct_cmd).decode())
151
240
 
152
241
 
242
+ def GainSel_flag_file(date: str) -> Path:
243
+ filename = cfg.get("LSTOSA", "gain_selection_check")
244
+ GainSel_dir = Path(cfg.get("LST1", "GAIN_SELECTION_FLAG_DIR"))
245
+ flagfile = GainSel_dir / date / filename
246
+ return flagfile.resolve()
247
+
248
+
249
+ def GainSel_finished(date: str) -> bool:
250
+ """Check if gain selection finished successfully."""
251
+ flagfile = GainSel_flag_file(date)
252
+ return flagfile.exists()
253
+
254
+
153
255
  def check_failed_jobs(date: str, output_basedir: Path = None):
154
256
  """Search for failed jobs in the log directory."""
155
257
  failed_jobs = []
@@ -165,72 +267,82 @@ def check_failed_jobs(date: str, output_basedir: Path = None):
165
267
  log.warning(f"Job {job} did not finish successfully")
166
268
  failed_jobs.append(job)
167
269
 
168
- if not failed_jobs:
169
- log.info(f"{date}: all jobs finished successfully")
170
- else:
270
+ if failed_jobs:
171
271
  log.warning(f"{date}: some jobs did not finish successfully")
172
272
 
173
-
174
- run_summary_dir = Path("/fefs/aswg/data/real/monitoring/RunSummary")
175
- run_summary_file = run_summary_dir / f"RunSummary_{date}.ecsv"
176
- summary_table = Table.read(run_summary_file)
177
- runs = summary_table["run_id"]
178
- missing_runs = []
179
-
180
- r0_files = glob.glob(f"/fefs/aswg/data/real/R0/{date}/LST-1.?.Run?????.????.fits.fz")
181
- r0g_files = glob.glob(f"/fefs/aswg/data/real/R0G/{date}/LST-1.?.Run?????.????.fits.fz")
182
- all_r0_runs = [parse_r0_filename(i).run for i in r0_files]
183
- all_r0g_runs = [parse_r0_filename(i).run for i in r0g_files]
184
-
185
- for run in all_r0_runs:
186
- if run not in runs:
187
- if run not in all_r0g_runs:
188
- missing_runs.append(run)
189
-
190
- missing_runs.sort()
191
- if missing_runs:
192
- log.info(
193
- f"Some runs are missing. Copying R0 files of runs {pd.Series(missing_runs).unique()} "
194
- f"directly to /fefs/aswg/data/real/R0G/{date}"
195
- )
196
-
197
- for run in missing_runs:
198
- output_dir = Path(f"/fefs/aswg/data/real/R0G/{date}/")
199
- files = glob.glob(f"/fefs/aswg/data/real/R0/{date}/LST-1.?.Run{run:05d}.????.fits.fz")
200
- for file in files:
201
- sp.run(["cp", file, output_dir])
202
-
273
+ else:
274
+ log.info(f"{date}: all jobs finished successfully")
203
275
 
204
276
 
205
- @click.command()
206
- @click.option("--check", is_flag=True, default=False, help="Check for failed jobs.")
207
- @click.argument("dates-file", type=click.Path(exists=True, path_type=Path))
208
- @click.argument("output-basedir", type=click.Path(path_type=Path))
209
- @click.option("-s", "--start-time", type=int, default=10, help="Time to (re)start gain selection in HH format.")
210
- @click.option("-e", "--end-time", type=int, default=18, help="Time to stop gain selection in HH format.")
211
- def main(
212
- dates_file: Path = None,
213
- output_basedir: Path = None,
214
- check: bool = False,
215
- start_time: int = 10,
216
- end_time: int = 18
217
- ):
277
+ run_summary_dir = Path("/fefs/aswg/data/real/monitoring/RunSummary")
278
+ run_summary_file = run_summary_dir / f"RunSummary_{date}.ecsv"
279
+ summary_table = Table.read(run_summary_file)
280
+ runs = summary_table["run_id"]
281
+ missing_runs = []
282
+
283
+ r0_files = glob.glob(f"/fefs/aswg/data/real/R0/{date}/LST-1.?.Run?????.????.fits.fz")
284
+ r0g_files = glob.glob(f"/fefs/aswg/data/real/R0G/{date}/LST-1.?.Run?????.????.fits.fz")
285
+ all_r0_runs = [parse_r0_filename(i).run for i in r0_files]
286
+ all_r0g_runs = [parse_r0_filename(i).run for i in r0g_files]
287
+
288
+ for run in all_r0_runs:
289
+ if run not in runs:
290
+ if run not in all_r0g_runs:
291
+ missing_runs.append(run)
292
+
293
+ missing_runs.sort()
294
+ if missing_runs:
295
+ log.info(
296
+ f"Some runs are missing. Copying R0 files of runs {pd.Series(missing_runs).unique()} "
297
+ f"directly to /fefs/aswg/data/real/R0G/{date}"
298
+ )
299
+
300
+ for run in missing_runs:
301
+ output_dir = Path(f"/fefs/aswg/data/real/R0G/{date}/")
302
+ files = glob.glob(f"/fefs/aswg/data/real/R0/{date}/LST-1.?.Run{run:05d}.????.fits.fz")
303
+ for file in files:
304
+ sp.run(["cp", file, output_dir])
305
+
306
+ GainSel_dir = Path(cfg.get("LST1", "GAIN_SELECTION_FLAG_DIR"))
307
+ flagfile_dir = GainSel_dir / date
308
+ flagfile_dir.mkdir(parents=True, exist_ok=True)
309
+
310
+ flagfile = GainSel_flag_file(date)
311
+ log.info(f"Gain selection finished successfully, creating flag file for date {date} ({flagfile})")
312
+ flagfile.touch()
313
+
314
+
315
+ def main():
218
316
  """
219
317
  Loop over the dates listed in the input file and launch the gain selection
220
318
  script for each of them. The input file should list the dates in the format
221
319
  YYYYMMDD one date per line.
222
320
  """
223
321
  log.setLevel(logging.INFO)
322
+ args = parser.parse_args()
224
323
 
225
- list_of_dates = get_list_of_dates(dates_file)
324
+ if args.date:
325
+ if args.check:
326
+ log.info(f"Checking gain selection status for date {args.date}")
327
+ check_failed_jobs(args.date, args.output_basedir)
328
+ else:
329
+ log.info(f"Applying gain selection to date {args.date}")
330
+ apply_gain_selection(args.date, args.start_time, args.end_time, args.output_basedir, no_queue_check=args.no_queue_check)
226
331
 
227
- if check:
228
- for date in list_of_dates:
229
- check_failed_jobs(date, output_basedir)
230
- else:
231
- for date in list_of_dates:
232
- apply_gain_selection(date, start_time, end_time, output_basedir)
233
- log.info("Done! No more dates to process.")
332
+
333
+ elif args.dates_file:
334
+ list_of_dates = get_list_of_dates(args.dates_file)
335
+ log.info(f"Found {len(list_of_dates)} dates to apply or check gain selection")
336
+
337
+ if args.check:
338
+ for date in list_of_dates:
339
+ log.info(f"Checking gain selection status for date {date}")
340
+ check_failed_jobs(date, args.output_basedir)
341
+ else:
342
+ for date in list_of_dates:
343
+ log.info(f"Applying gain selection to date {date}")
344
+ apply_gain_selection(date, args.start_time, args.end_time, args.output_basedir, no_queue_check=args.no_queue_check)
345
+ log.info("Done! No more dates to process.")
234
346
 
235
347
 
236
348
  if __name__ == "__main__":
osa/scripts/sequencer.py CHANGED
@@ -7,6 +7,7 @@ prepares a SLURM job array which launches the data sequences for every subrun.
7
7
 
8
8
  import logging
9
9
  import os
10
+ import sys
10
11
  from decimal import Decimal
11
12
 
12
13
  from osa import osadb
@@ -22,12 +23,14 @@ from osa.job import (
22
23
  run_squeue,
23
24
  )
24
25
  from osa.nightsummary.extract import build_sequences
26
+ from osa.nightsummary.nightsummary import run_summary_table
25
27
  from osa.paths import analysis_path
26
28
  from osa.report import start
27
29
  from osa.utils.cliopts import sequencer_cli_parsing
28
30
  from osa.utils.logging import myLogger
29
- from osa.utils.utils import is_day_closed, gettag, date_to_iso
31
+ from osa.utils.utils import is_day_closed, gettag, date_to_iso, date_to_dir
30
32
  from osa.veto import get_closed_list, get_veto_list
33
+ from osa.scripts.gain_selection import GainSel_finished
31
34
 
32
35
  __all__ = [
33
36
  "single_process",
@@ -90,6 +93,18 @@ def single_process(telescope):
90
93
  if not options.simulate:
91
94
  os.makedirs(options.log_directory, exist_ok=True)
92
95
 
96
+ summary_table = run_summary_table(options.date)
97
+ if len(summary_table) == 0:
98
+ log.warning("No runs found for this date. Nothing to do. Exiting.")
99
+ sys.exit(0)
100
+
101
+ if not options.no_gainsel and not GainSel_finished(date_to_dir(options.date)):
102
+ log.info(
103
+ f"Gain selection did not finish successfully for date {options.date}."
104
+ "Try again later, once gain selection has finished."
105
+ )
106
+ sys.exit()
107
+
93
108
  if is_day_closed():
94
109
  log.info(f"Date {date_to_iso(options.date)} is already closed for {options.tel_id}")
95
110
  return sequence_list
@@ -126,9 +126,11 @@ def test_simulated_sequencer(
126
126
  run_catalog,
127
127
  r0_data,
128
128
  merged_run_summary,
129
+ gain_selection_flag_file,
129
130
  ):
130
131
  assert run_summary_file.exists()
131
132
  assert run_catalog.exists()
133
+ assert gain_selection_flag_file.exists()
132
134
 
133
135
  for r0_file in r0_data:
134
136
  assert r0_file.exists()
osa/utils/cliopts.py CHANGED
@@ -274,6 +274,12 @@ def sequencer_argparser():
274
274
  default=False,
275
275
  help="Do not produce DL2 files (default False)",
276
276
  )
277
+ parser.add_argument(
278
+ "--no-gainsel",
279
+ action="store_true",
280
+ default=False,
281
+ help="Do not check if the gain selection finished correctly (default False)",
282
+ )
277
283
  parser.add_argument(
278
284
  "tel_id",
279
285
  choices=["ST", "LST1", "LST2", "all"],
@@ -292,6 +298,7 @@ def sequencer_cli_parsing():
292
298
  options.no_submit = opts.no_submit
293
299
  options.no_calib = opts.no_calib
294
300
  options.no_dl2 = opts.no_dl2
301
+ options.no_gainsel = opts.no_gainsel
295
302
 
296
303
  log.debug(f"the options are {opts}")
297
304
 
@@ -476,6 +483,12 @@ def autocloser_cli_parser():
476
483
  default=False,
477
484
  help="Disregard the production of DL2 files",
478
485
  )
486
+ parser.add_argument(
487
+ "--no-gainsel",
488
+ action="store_true",
489
+ default=False,
490
+ help="Do not check if the gain selection finished correctly (default False)",
491
+ )
479
492
  parser.add_argument("-r", "--runwise", action="store_true", help="Close the day run-wise.")
480
493
  parser.add_argument("-l", "--log", type=Path, default=None, help="Write log to a file.")
481
494
  parser.add_argument("tel_id", type=str, choices=["LST1"])