8 __version__ =
'1.5.6_2024-03-06'
13 from datetime
import datetime, timedelta
14 from l0info_utils
import read_packet, read_apid, get_anc_packet_time, is_bad_packet
20 if not np.any(np.frombuffer(fpacket[22:packetLength-1],dtype=np.uint8)-255):
24 print(
"Image fill data at byte %d."%fh.tell())
25 return True, firstfill
27 return False, firstfill
32 if (apid < 750)
or (apid > 799):
33 print(
"Invalid packet or header at byte %d."%fh.tell())
39 print(
"Running l0info_harp (version: %s) \n" % __version__)
43 print(
"Reading HARP2 science data file.")
45 file_size = os.fstat(fh.fileno()).st_size
57 while (apid != 751)
and (packetLength > 7):
64 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
67 detnum = (fpacket[12] & 48)>>4
71 while (imhp == -1)
and (fh.tell() < file_size):
72 imhp = fpacket.find(b_imhead)
77 while (apid != 751)
and (packetLength > 7):
84 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
87 detn = (fpacket[12] & 48)>>4
88 if detn != detnum: detnum = 999
90 if fh.tell() >= file_size:
91 print(
'No image headers found in file.')
94 pctr = (fpacket[2] % 64)*256 + fpacket[3]
95 print(f
"Image pointer {imhp}, detector {detnum} in packet {pctr}")
97 print(
"No stored science packets found in file.")
100 if fh.tell() >= file_size:
102 etime = datetime(2000,1,1)
103 stime = datetime(3000,1,1)
108 while (fh.tell() < file_size)
and (apid != 757)
and (packetLength > 7):
122 except Exception
as e:
126 while fpacket
and (packetLength > 7):
145 print(
"detector=REAL\n")
146 print(
"start_time=%s" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
147 print(
"stop_time=%s" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
149 output.write(
"start_time=%s\n" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
150 output.write(
"stop_time=%s\n" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
151 output.write(
"detector=REAL\n")
152 except Exception
as e:
159 if fh.tell() >= file_size:
161 etime = datetime(2000,1,1)
162 stime = datetime(3000,1,1)
168 while ((fh.tell() < file_size)
and (apid != 750)
and (packetLength > 7))
or (ccsec < 2000000000):
174 ccsec = int.from_bytes(fpacket[6:10],
'big')
184 except Exception
as e:
188 while fpacket
and (packetLength > 7):
191 if apid == 750: mpacket = fpacket
202 print(
"start_time=%s" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
204 output.write(
"start_time=%s\n" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
205 print(
"stop_time=%s" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
207 output.write(
"stop_time=%s\n" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
208 except Exception
as e:
217 detnum = (fpacket[12] & 48)>>4
231 MAX_TIME_DIFF = timedelta(days=1.0)
233 while fh.tell() < file_size:
237 while (fh.tell() < file_size)
and (apid != 751)
and (packetLength > 7):
244 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
248 while (imh == -1)
and fh.tell() < file_size:
250 imh_pct =
int(fh.tell()/file_size*100)
251 if imh_pct - last_pct > 9:
252 print(
"%d%% of packets read." % imh_pct)
254 imh = fpacket.find(b_imhead)
258 while (fh.tell() < file_size)
and (apid != 751)
and (packetLength > 7):
262 if (fh.tell() < file_size):
264 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
267 if fpacket
and (imh > -1):
269 detn = (fpacket[12] & 48)>>4
270 if detn != detnum: detnum = 999
274 pctr = (fpacket[2] % 64)*256 + fpacket[3]
275 print(f
"Image pointer {imhp}, detector {detn} in packet {pctr}")
281 if ctime>etime
and (ctime - etime) < MAX_TIME_DIFF:
287 print(
"100% of packets read.")
292 print(
"start_time=%s" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
293 print(
"stop_time=%s" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
295 output.write(
"start_time=%s\n" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
296 output.write(
"stop_time=%s\n" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
297 except Exception
as e:
302 print(
"detector=all")
304 output.write(
"detector=all\n")
306 print(
"detector=%d"%detnum)
308 output.write(
"detector=%d\n"%detnum)