8 __version__ =
'1.4.3_2023-01-26'
13 from datetime
import datetime
14 from l0info_utils
import read_packet, read_apid, get_anc_packet_time, is_bad_packet
17 hex_imhead =
"48415250"
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.hex().find(hex_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
92 if fh.tell() >= file_size:
93 print(
'No image headers found in file.')
96 pctr = (fpacket[2] % 64)*256 + fpacket[3]
97 print(f
"Image pointer {imhp}, detector {detn} in packet {pctr}")
99 print(
"No science packets found in file.")
102 if fh.tell() >= file_size:
104 etime = datetime(2000,1,1)
105 stime = datetime(3000,1,1)
111 while ((fh.tell() < file_size)
and (apid != 750)
and (packetLength > 7))
or (ccsec < 2000000000):
117 ccsec = int.from_bytes(fpacket[6:10],
'big')
127 except Exception
as e:
131 while fpacket
and (packetLength > 7):
134 if apid == 750: mpacket = fpacket
145 print(
"start_time=%s" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
147 output.write(
"start_time=%s\n" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
148 print(
"stop_time=%s" % etime.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 except Exception
as e:
154 print(f
"status={status}")
160 detnum = (fpacket[12] & 48)>>4
169 while fh.tell() < file_size:
173 while (fh.tell() < file_size)
and (apid != 751)
and (packetLength > 7):
180 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
184 while (imh == -1)
and fh.tell() < file_size:
186 imh_pct =
int(fh.tell()/file_size*100)
187 if imh_pct - last_pct > 9:
188 print(
"%d%% of packets read." % imh_pct)
190 imh = fpacket.hex().find(hex_imhead)
194 while (fh.tell() < file_size)
and (apid != 751)
and (packetLength > 7):
198 if (fh.tell() < file_size):
200 isFillImage, firstfill =
is_fill_image(fpacket,packetLength,fh,firstfill)
205 if fpacket
and (imh > -1):
207 detn = (fpacket[12] & 48)>>4
208 if detn != detnum: detnum = 999
212 pctr = (fpacket[2] % 64)*256 + fpacket[3]
213 print(f
"Image pointer {imhp}, detector {detn} in packet {pctr}")
223 print(
"100% of packets read.")
228 print(
"start_time=%s" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
229 print(
"stop_time=%s" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
231 output.write(
"start_time=%s\n" % stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
232 output.write(
"stop_time=%s\n" % etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f'))
233 except Exception
as e:
238 print(
"detector=all")
240 output.write(
"detector=all\n")
242 print(
"detector=%d"%detnum)
244 output.write(
"detector=%d\n"%detnum)