3
3
import logging
4
4
from pathlib import Path
5
5
from astropy .table import Table
6
+ from lstchain .onsite import (
7
+ find_systematics_correction_file ,
8
+ find_time_calibration_file
9
+ )
6
10
7
11
from osa .configs import options
8
12
from osa .configs .config import cfg
13
17
log = myLogger (logging .getLogger (__name__ ))
14
18
15
19
__all__ = [
16
- "get_time_calibration_file" ,
17
20
"get_calibration_file" ,
18
21
"get_drs4_pedestal_file" ,
19
- "get_systematic_correction_file" ,
20
22
"pedestal_ids_file_exists" ,
21
23
"get_run_date" ,
22
24
"drs4_pedestal_exists" ,
@@ -82,64 +84,6 @@ def get_run_date(run_id: int) -> str:
82
84
return date_string .replace ("-" , "" )
83
85
84
86
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
-
143
87
def get_drs4_pedestal_file (run_id : int ) -> Path :
144
88
"""
145
89
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:
207
151
def sequence_calibration_files (sequence_list ):
208
152
"""Build names of the calibration files for each sequence in the list."""
209
153
flat_date = utils .date_to_dir (options .date )
154
+ base_dir = Path (cfg .get ("LST1" , "BASE" ))
210
155
211
156
for sequence in sequence_list :
212
157
@@ -220,8 +165,8 @@ def sequence_calibration_files(sequence_list):
220
165
# Assign the calibration files to the sequence object
221
166
sequence .pedestal = get_drs4_pedestal_file (drs4_pedestal_run_id )
222
167
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 )
225
170
226
171
227
172
def get_datacheck_files (pattern : str , directory : Path ) -> list :
0 commit comments