6 convert numpy structured array to dict of scalars and numpy arrays
10 for key
in structured_array.dtype.names:
11 if ( key.upper().startswith(
'PADDING')
or
12 key.upper().startswith(
'SPARE') ):
14 myDict[key] = structured_array[key][0]
20 return np.unpackbits(var[i,np.newaxis].view(dtype=
'|u1'))
26 result = (result << 1) | bit
31 packet = bytearray(length)
32 if len(data) > length:
33 packet[:] = data[0:length]
35 packet[0:len(data)] = data
40 cfeHeaderFields = np.dtype([
46 (
'processorid',
'>u4'),
47 (
'fileopen_seconds',
'>u4'),
48 (
'fileopen_subseconds',
'>u4'),
49 (
'description',
'S32'),
52 dsfHeaderFields = np.dtype([
53 (
'fileclose_seconds',
'>u4'),
54 (
'fileclose_subseconds',
'>u4'),
55 (
'filetable_index',
'>u2'),
56 (
'filename_type',
'>u2'),
60 def readFileHeader(filehandle):
63 pos = filehandle.tell()
64 fourchars = filehandle.read(4)
66 if fourchars != b
'cFE1':
70 data = filehandle.read(cfeHeaderFields.itemsize)
71 tmp = np.frombuffer(data, dtype=cfeHeaderFields, count=1)
73 myDict[
'fileopen_ts'] =
decode_timestamp(myDict[
'fileopen_seconds'],myDict[
'fileopen_subseconds'])
77 if myDict[
'description'].startswith(b
'DS'):
78 data = filehandle.read(dsfHeaderFields.itemsize)
79 tmp = np.frombuffer(data, dtype=dsfHeaderFields, count=1)
81 myDict[
'fileclose_ts'] =
decode_timestamp(myDict[
'fileclose_seconds'],myDict[
'fileclose_subseconds'])
88 primaryHeaderFields = np.dtype([
92 def primaryHeader(data):
95 tmp = np.frombuffer(data, dtype=primaryHeaderFields, count=1)
96 words = tmp[
'words'][0]
101 myDict[
'version'] =
as_int(bits[0:0+3])
102 myDict[
'ptype'] = bits[3]
103 myDict[
'secondary'] = bits[4]
104 myDict[
'APID'] =
as_int(bits[5:5+11])
108 myDict[
'grouping'] =
as_int(bits[0:0+2])
109 myDict[
'sequence'] =
as_int(bits[2:2+11])
112 myDict[
'length'] = words[2]
119 def readPacket(filehandle):
123 rawhdr = filehandle.read(primaryHeaderFields.itemsize)
124 header = primaryHeader(rawhdr)
125 datalen = header[
'length']
128 return None,
None,
None
131 data = filehandle.read(datalen+1)
133 return header, data, rawhdr