Skip to content

Commit b8c5f62

Browse files
authored
Merge pull request #162 from cta-observatory/use_lstchain_functions
Use lstchain functions to find the time calibration and systematic co…
2 parents dc2c092 + 345ff70 commit b8c5f62

File tree

3 files changed

+7
-98
lines changed

3 files changed

+7
-98
lines changed

Diff for: osa/configs/sequencer.cfg

-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ ANALYSIS_DIR: %(BASE)s/running_analysis
1818
CALIB_BASE_DIR: %(MONITORING)s/PixelCalibration/Cat-A
1919
CALIB_DIR: %(CALIB_BASE_DIR)s/calibration
2020
PEDESTAL_DIR: %(CALIB_BASE_DIR)s/drs4_baseline
21-
TIMECALIB_DIR: %(CALIB_BASE_DIR)s/drs4_time_sampling_from_FF
22-
SYSTEMATIC_DIR: %(CALIB_BASE_DIR)s/ffactor_systematics
2321
DL1_DIR: %(BASE)s/DL1
2422
DL1AB_DIR: %(BASE)s/DL1
2523
MUON_DIR: %(BASE)s/DL1

Diff for: osa/paths.py

+7-62
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import logging
44
from pathlib import Path
55
from astropy.table import Table
6+
from lstchain.onsite import (
7+
find_systematics_correction_file,
8+
find_time_calibration_file
9+
)
610

711
from osa.configs import options
812
from osa.configs.config import cfg
@@ -13,10 +17,8 @@
1317
log = myLogger(logging.getLogger(__name__))
1418

1519
__all__ = [
16-
"get_time_calibration_file",
1720
"get_calibration_file",
1821
"get_drs4_pedestal_file",
19-
"get_systematic_correction_file",
2022
"pedestal_ids_file_exists",
2123
"get_run_date",
2224
"drs4_pedestal_exists",
@@ -82,64 +84,6 @@ def get_run_date(run_id: int) -> str:
8284
return date_string.replace("-", "")
8385

8486

85-
def get_time_calibration_file(run_id: int) -> Path:
86-
"""
87-
Return the time calibration file corresponding to a calibration run taken before
88-
the run id given. If run_id is smaller than the first run id from the time
89-
calibration files, return the first time calibration file available, which
90-
corresponds to 1625.
91-
"""
92-
time_calibration_dir = Path(cfg.get("LST1", "TIMECALIB_DIR"))
93-
file_list = sorted(time_calibration_dir.rglob("pro/time_calibration.Run*.h5"))
94-
95-
if not file_list:
96-
raise IOError("No time calibration file found")
97-
98-
for file in file_list:
99-
run_in_list = int(file.name.split(".")[1].strip("Run"))
100-
if run_id < 1625:
101-
time_calibration_file = file_list[0]
102-
elif run_in_list <= run_id:
103-
time_calibration_file = file
104-
else:
105-
break
106-
107-
return time_calibration_file.resolve()
108-
109-
110-
def get_systematic_correction_file(date: str) -> Path:
111-
"""
112-
Return the systematic correction file for a given date.
113-
114-
Parameters
115-
----------
116-
date : str
117-
Date in the format YYYYMMDD.
118-
119-
Notes
120-
-----
121-
The search for the proper systematic correction file is based on
122-
lstchain/scripts/onsite/onsite_create_calibration_file.py
123-
"""
124-
sys_dir = Path(cfg.get("LST1", "SYSTEMATIC_DIR"))
125-
126-
# Search for the first sys correction file before the run, if nothing before,
127-
# use the first found
128-
dir_list = sorted(sys_dir.rglob('*/pro/ffactor_systematics*'))
129-
if not dir_list:
130-
raise IOError(
131-
f"No systematic correction file found for production pro in {sys_dir}\n"
132-
)
133-
sys_date_list = sorted([file.parts[-3] for file in dir_list], reverse=True)
134-
selected_date = next(
135-
(day for day in sys_date_list if day <= date), sys_date_list[-1]
136-
)
137-
138-
return Path(
139-
f"{sys_dir}/{selected_date}/pro/ffactor_systematics_{selected_date}.h5"
140-
).resolve()
141-
142-
14387
def get_drs4_pedestal_file(run_id: int) -> Path:
14488
"""
14589
Return the drs4 pedestal file corresponding to a given run id
@@ -207,6 +151,7 @@ def get_pedestal_ids_file(run_id: int, date: str) -> Path:
207151
def sequence_calibration_files(sequence_list):
208152
"""Build names of the calibration files for each sequence in the list."""
209153
flat_date = utils.date_to_dir(options.date)
154+
base_dir = Path(cfg.get("LST1", "BASE"))
210155

211156
for sequence in sequence_list:
212157

@@ -220,8 +165,8 @@ def sequence_calibration_files(sequence_list):
220165
# Assign the calibration files to the sequence object
221166
sequence.pedestal = get_drs4_pedestal_file(drs4_pedestal_run_id)
222167
sequence.calibration = get_calibration_file(pedcal_run_id)
223-
sequence.time_calibration = get_time_calibration_file(pedcal_run_id)
224-
sequence.systematic_correction = get_systematic_correction_file(flat_date)
168+
sequence.time_calibration = find_time_calibration_file("pro", pedcal_run_id, base_dir=base_dir)
169+
sequence.systematic_correction = find_systematics_correction_file("pro", flat_date, base_dir=base_dir)
225170

226171

227172
def get_datacheck_files(pattern: str, directory: Path) -> list:

Diff for: osa/tests/test_paths.py

-34
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,6 @@ def test_get_drs4_pedestal_file(r0_data, merged_run_summary):
2323
file.exists()
2424

2525

26-
def test_get_time_calibration_file(drs4_time_calibration_files):
27-
from osa.paths import get_time_calibration_file
28-
for file in drs4_time_calibration_files:
29-
assert file.exists()
30-
31-
run = 1616
32-
time_file = get_time_calibration_file(run)
33-
assert time_file == drs4_time_calibration_files[0]
34-
35-
run = 1625
36-
time_file = get_time_calibration_file(run)
37-
assert time_file == drs4_time_calibration_files[0]
38-
39-
run = 1900
40-
time_file = get_time_calibration_file(run)
41-
assert time_file == drs4_time_calibration_files[0]
42-
43-
run = 4211
44-
time_file = get_time_calibration_file(run)
45-
assert time_file == drs4_time_calibration_files[1]
46-
47-
run = 5000
48-
time_file = get_time_calibration_file(run)
49-
assert time_file == drs4_time_calibration_files[1]
50-
51-
run = 5979
52-
time_file = get_time_calibration_file(run)
53-
assert time_file == drs4_time_calibration_files[2]
54-
55-
run = 6000
56-
time_file = get_time_calibration_file(run)
57-
assert time_file == drs4_time_calibration_files[2]
58-
59-
6026
def test_pedestal_ids_file_exists(pedestal_ids_file):
6127
from osa.paths import pedestal_ids_file_exists
6228
pedestal_ids_file.exists()

0 commit comments

Comments
 (0)