Coverage for src / lstautorta / High_Level_analysis.py: 0%
84 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-10 11:56 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-10 11:56 +0000
1#!/usr/bin/env python
3import datetime
4import logging
5import os
6import time
8from lstautorta.shared_observation import DEFAULT_SHARED_OBS_PATH, wait_for_shared_obs
11def wait_for_directory(directory, interval=5):
12 """
13 Wait for the directory to exist
15 :param directory: directory path
16 :param interval: Time interval between verification
17 """
18 while not os.path.exists(directory):
19 print(f"{directory} does not exist yet. let's wait {interval} seconds...")
20 time.sleep(interval)
21 print(f"The directory {directory} finally exist !!!")
24def now():
25 """
26 Returns the current timestamp in seconds, relative to the Unix epoch.
28 :return: float
29 """
30 return datetime.datetime.timestamp(datetime.datetime.now())
33def get_current_obs_info(
34 db_hostname: str = "lst101",
35 obs_target_query_timeout_s: int = 10,
36):
37 """
38 Retrieve current observation info from the shared observation file.
39 Waits until the file is available.
40 """
41 logging.info("Waiting for shared observation file at %s", DEFAULT_SHARED_OBS_PATH)
42 return wait_for_shared_obs(DEFAULT_SHARED_OBS_PATH)
45def get_night_timestamp(today):
46 """
47 Get current timestamp (YYYYMMDD) with respect to the night.
48 It will consider a same night everything run between 08h00 until 07h59 of the next day.
50 Ex: An observation launched at 04h00 (local time) will refer to the previous day.
52 :param today: datetime object
53 datetime object with current local time
55 :return:
56 timestamp: str
57 """
58 # TODO check that today is a datetime object ?
59 if today.hour < 8: # script launched between
60 yesterday = today - datetime.timedelta(days=1)
61 timestamp = f"{yesterday.year:04d}{yesterday.month:02d}{yesterday.day:02d}"
62 else:
63 timestamp = f"{today.year:04d}{today.month:02d}{today.day:02d}"
65 return timestamp
68def get_source_ra_dec(obs_info):
69 if obs_info is None:
70 return 0, 0
71 if obs_info.source_RA is None or obs_info.source_DEC is None:
72 return 0, 0
73 return obs_info.source_RA, obs_info.source_DEC
76def today_to_directory(today):
77 return today[0:4] + "/" + today[4:6] + "/" + today[6:8]
80def main():
81 """
82 Initialize current_run_is and quit variables and get the current timestamp with Start_time = now()
83 Initialize the logging system by setting the log file name and logging level
84 Change the current working directory to /fefs/onsite/pipeline/rta/data
85 Find the current reservations for nodes using the scontrol command and parse the output to find the individual node names
86 Modify a configuration file with sed commands, replacing placeholders with the node names found in step 4
87 Check if the ib0 network interface is in connected mode for each of the nodes and log the results
88 """
89 current_run_is = -1
90 quit = False
92 Start_time = now()
94 # today = str(datetime.datetime.now().year) + str(datetime.datetime.now().month) + str(datetime.datetime.now().day)
95 today = get_night_timestamp(datetime.datetime.now())
97 wait_for_directory("/fefs/onsite/pipeline/rta/data/" + today_to_directory(today))
98 logging.basicConfig(
99 filename="/fefs/onsite/pipeline/rta/data/" + today_to_directory(today) + "/log_High_Level_" + today + ".txt",
100 level=logging.INFO,
101 )
102 logging.info("Start RTA High Level for the day " + today)
104 RTA_ready = True
106 loop_id = 0
107 data_directory = "/fefs/onsite/pipeline/rta/data/"
108 while quit == False and RTA_ready:
109 time.sleep(10)
110 obs_info = get_current_obs_info()
111 if obs_info is None or obs_info.obs_id is None:
112 logging.info("None")
113 current_run_is = -1
114 continue
115 if current_run_is == -1:
116 current_run_is = obs_info.obs_id
117 if current_run_is != obs_info.obs_id:
118 time.sleep(1)
119 obs_info = get_current_obs_info()
120 if obs_info is None or obs_info.obs_id is None:
121 logging.info("None")
122 current_run_is = -1
123 continue
124 current_run_is = obs_info.obs_id
125 if current_run_is != -1:
126 logging.info("Start RTA check for run " + str(current_run_is))
127 time.sleep(2)
128 source_ra, source_dec = get_source_ra_dec(obs_info)
129 logging.info(
130 # ~ "srun --reservation=rta_one_node ./Theta_square.py -da "
131 "./Theta_square.py -da "
132 + today_to_directory(today)
133 + " -r "
134 + str(current_run_is)
135 + " -RA "
136 + str(source_ra)
137 + " -DEC "
138 + str(source_dec)
139 )
140 os.system(
141 # ~ "srun --reservation=rta_one_node ./Theta_square.py -da "
142 "./Theta_square.py -da "
143 + today_to_directory(today)
144 + " -r "
145 + str(current_run_is)
146 + " -RA "
147 + str(source_ra)
148 + " -DEC "
149 + str(source_dec)
150 )
151 logging.info(
152 # ~ "srun --reservation=rta_one_node ./Spectra.py -da "
153 "./Spectra.py -da "
154 + today_to_directory(today)
155 + " -r "
156 + str(current_run_is)
157 + " -RA "
158 + str(source_ra)
159 + " -DEC "
160 + str(source_dec)
161 )
162 os.system(
163 # ~ "srun --reservation=rta_one_node ./Spectra.py -da "
164 "./Spectra.py -da "
165 + today_to_directory(today)
166 + " -r "
167 + str(current_run_is)
168 + " -RA "
169 + str(source_ra)
170 + " -DEC "
171 + str(source_dec)
172 )
173 logging.info(
174 # ~ "srun --reservation=rta_one_node ./rta_var.py --dl3_folder "
175 "./rta_var.py --dl3_folder "
176 + data_directory
177 + today_to_directory(today)
178 + "/"
179 + str(current_run_is)
180 + "/DL3 -ra "
181 + str(source_ra)
182 + " -dec "
183 + str(source_dec)
184 + " --output_dir "
185 + data_directory
186 + today_to_directory(today)
187 + "/"
188 + str(current_run_is)
189 + "/plots --date "
190 + today
191 )
192 os.system(
193 # ~ "srun --reservation=rta_one_node ./rta_var.py --dl3_folder "
194 "./rta_var.py --dl3_folder "
195 + data_directory
196 + today_to_directory(today)
197 + "/"
198 + str(current_run_is)
199 + "/DL3 -ra "
200 + str(source_ra)
201 + " -dec "
202 + str(source_dec)
203 + " --output_dir "
204 + data_directory
205 + today_to_directory(today)
206 + "/"
207 + str(current_run_is)
208 + "/plots --date "
209 + today
210 )
212 if loop_id % 1 == 0:
213 logging.info("Start RTA check for run " + str(current_run_is))
214 time.sleep(2)
215 logging.info(datetime.datetime.now())
216 source_ra, source_dec = get_source_ra_dec(obs_info)
217 logging.info(
218 "./Theta_square.py -da "
219 + today_to_directory(today)
220 + " -r "
221 + str(current_run_is)
222 + " -RA "
223 + str(source_ra)
224 + " -DEC "
225 + str(source_dec)
226 )
227 os.system(
228 "./Theta_square.py -da "
229 + today_to_directory(today)
230 + " -r "
231 + str(current_run_is)
232 + " -RA "
233 + str(source_ra)
234 + " -DEC "
235 + str(source_dec)
236 )
237 logging.info(
238 "./Spectra.py -da "
239 + today_to_directory(today)
240 + " -r "
241 + str(current_run_is)
242 + " -RA "
243 + str(source_ra)
244 + " -DEC "
245 + str(source_dec)
246 )
247 os.system(
248 "./Spectra.py -da "
249 + today_to_directory(today)
250 + " -r "
251 + str(current_run_is)
252 + " -RA "
253 + str(source_ra)
254 + " -DEC "
255 + str(source_dec)
256 )
257 logging.info(
258 "./rta_var.py --dl3_folder "
259 + data_directory
260 + today_to_directory(today)
261 + "/"
262 + str(current_run_is)
263 + "/DL3 -ra "
264 + str(source_ra)
265 + " -dec "
266 + str(source_dec)
267 + " --output_dir "
268 + data_directory
269 + today_to_directory(today)
270 + "/"
271 + str(current_run_is)
272 + "/plots --date "
273 + today
274 )
275 os.system(
276 "./rta_var.py --dl3_folder "
277 + data_directory
278 + today_to_directory(today)
279 + "/"
280 + str(current_run_is)
281 + "/DL3 -ra "
282 + str(source_ra)
283 + " -dec "
284 + str(source_dec)
285 + " --output_dir "
286 + data_directory
287 + today_to_directory(today)
288 + "/"
289 + str(current_run_is)
290 + "/plots --date "
291 + today
292 )
294 loop_id = loop_id + 1
295 if (datetime.datetime.timestamp(datetime.datetime.now()) - Start_time) > 14 * 3600:
296 quit = True
297 logging.info("End of the night, Stop the RTA check")
300if __name__ == "__main__":
301 main()