4 __version__ =
'2.6.0_2023-02-09'
6 __dtypes__ = [
'',
'',
'_DARK',
'_SOL-D',
'_SOL-M',
'_LIN',
'_LUN',
'_DIAG',
'_STAT',
7 '_SPEC',
'',
'_SNAP-X',
'_SNAP-I',
'_SPCA',
'_LUN-ST']
10 from l0info_utils
import read_packet, read_apid, get_anc_packet_time, is_bad_packet
34 itable = np.zeros(10, dtype={
'names':(
'dtype',
'iagg',
'lines'),
'formats':(
'i4',
'i4',
'i4')})
44 itable[
'dtype'][i] = apacket[ioff+3]%16
45 itable[
'iagg'][i] = apacket[ioff+2]%4
46 itable[
'lines'][i] = apacket[ioff]*256 + apacket[ioff+1]
48 if ((itable[
'dtype'][i] > 0)
and (itable[
'dtype'][i] <= 12)
and (itable[
'dtype'][i] != 10)):
49 if (itable[
'dtype'][i] == 2):
50 ndc = ndc + itable[
'lines'][i]/nagg[itable[
'iagg'][i]]
51 nds = nds + itable[
'lines'][i]/8
52 ncp = ncp + itable[
'lines'][i]/nagg[itable[
'iagg'][i]]
53 nsp = nsp + itable[
'lines'][i]/8
66 btap = apacket[ioff+2]*256 + apacket[ioff+3]
67 rtap = apacket[ioff]*256 + apacket[ioff+1]
72 bagg = int.from_bytes(apacket[ioff+8:ioff+12],
'big')
73 ragg = int.from_bytes(apacket[ioff+4:ioff+8],
'big')
85 for i
in range(15,-1,-1):
86 btaps[i] = np.bitwise_and(btap, ken)/ken
88 baggs[i] = nagg[
int(np.bitwise_and(bagg, kag)/lag)]
89 nbb = nbb + 32/baggs[i]
91 rtaps[i] = np.bitwise_and(rtap, ken)/ken
93 raggs[i] = nagg[
int(np.bitwise_and(ragg, kag)/lag)]
94 nrb = nrb + 32/raggs[i]
100 return ncp,nbb,nrb,nsp,ndc,nds,btaps,rtaps,itable,baggs,raggs
121 if apacket[ioff:ioff+ilen] != apacket0[ioff:ioff+ilen]:
123 strmsg +=
"\nSpatial table change at %s" % c_time.strftime(
'%Y-%m-%dT%H:%M:%S.%f')
129 if apacket[joff:joff+jlen] != apacket0[joff:joff+jlen]:
131 strmsg +=
"\nSpectral table change at %s" % c_time.strftime(
'%Y-%m-%dT%H:%M:%S.%f')
134 return anc_compare, strmsg
139 if (apid < 550)
or (apid > 749):
140 print(
"Invalid packet header at byte %d."%fh.tell())
151 if (apid != 636):
return -1
153 dtypes = np.zeros(10)-1
155 for i
in range(0,10):
156 dtypes[i] = fpacket[ioff+3] % 16
158 kd = np.argwhere((dtypes != 2) & (dtypes != 10))
159 dtype = np.max(dtypes[kd])
166 print(
"Running l0info_oci (version: %s) \n" % __version__)
174 print(
"Reading OCI science data file.")
187 while (apid != 636)
and (packetLength > 7):
198 print(
'No science packets found in file.')
206 while (ccsec < 1900000000)
and (packetLength>7):
212 ccsec = int.from_bytes(fpacket[6:10],
'big')
218 str_stime = stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f')
219 print(
"start_time=%s" % str_stime)
223 while fpacket
and (packetLength>7):
229 if (apid >= 550)
and (apid < 750): mpacket = fpacket
235 output.write(
"datatype=OCI\n")
241 if (dtype<1)
or (dtype>12):
242 print(
"Invalid data type %d."%dtype)
248 str_stime = stime.strftime(
'%Y-%m-%dT%H:%M:%S.%f')
249 print(
"start_time=%s" % str_stime)
258 nagg = np.array([1,2,4,8])
259 spnp = int.from_bytes(apacket[24:28],
'big')
265 spnum = int.from_bytes(apacket[24:28],
'big')
267 if ((spnum-spnp) > 10):
268 tmpstr +=
"\nSpin number gap: %d, %d" % (spnp, spnum)
271 tmpstr +=
"\n\nInstrument configuration change at spin %d, %s" % (spnum,etime)
272 ncp,nbb,nrb,nsp,ndc,nds,btaps,rtaps,itable,baggs,raggs =
get_band_dims(apacket)
273 iz = np.where((itable[
'dtype'] != 0) & (itable[
'dtype'] != 10))[0]
274 tmpstr +=
"\nData Type %s" %
str(itable[
'dtype'][iz])
275 iagg = nagg[itable[
'iagg'][iz]]
276 tmpstr +=
"\nNumber of pixels %s" %
str(itable[
'lines'][iz]/iagg)
277 tmpstr +=
"\nAggregation %s" %
str(iagg)
278 tmpstr +=
"\nBlue bands: %d Red bands: %d" %(nbb, nrb)
279 tmpstr +=
"\nBlue aggregation per tap: %s" %
str(baggs)
280 tmpstr +=
"\nRed aggregation per tap: %s\n" %
str(raggs)
286 while (apid != 636)
and (packetLength>0):
292 if fpacket: epacket = fpacket
299 str_etime = etime.strftime(
'%Y-%m-%dT%H:%M:%S.%f')
300 print(
"stop_time=%s" % str_etime)
305 datatype_name =
'OCI' + __dtypes__[dtype]
306 if (datatype_name==
"OCI_SPCA")
or (datatype_name==
"OCI_LUN-ST"):
307 print(
"Unexpected datatype [%s] is detected." % datatype_name)
310 print(
"OCI data type name reading error.")
313 if datatype_name==
'':
314 datatype_name =
'OCI'
316 print(
"datatype=%s" % datatype_name)
318 output.write(
"datatype=%s\n" % datatype_name)
320 output.write(
"start_time=%s\n" % str_stime)
322 output.write(
"stop_time=%s\n" % str_etime)