-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaerdat.py
37 lines (31 loc) · 919 Bytes
/
aerdat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import struct
import numpy as np
import scipy as sp
def loadaerdat(datafile='/tmp/aerout.dat', stas=None, nEvents=None, datatype="II"):
aerdatafh = open(datafile, 'rb')
k = 0
while aerdatafh.readline()[0] == "#":
k += 1
continue
tmp = aerdatafh.read()
n = len(tmp) / struct.calcsize('>' + datatype)
tmad = struct.unpack_from('>' + datatype * n, tmp)
dat = np.array(tmad)
dat = dat.reshape(dat.shape[0] / 2, 2)
if nEvents == None:
nEvents = n
if stas == None:
return dat
else:
tm = np.concatenate([[0], sp.diff(dat[:nEvents, 1])])
ad = stas.STAddrPhysicalExtract(dat[:nEvents, 0]).transpose()
return [tm, ad]
def saveaerdat(tmadEvents, datafile=None, stas=None, nEvents=None, datatype="HH"):
tmp = struct.pack('>' + datatype, *stas.STAddrPhysicalConstruct(tmadEvents))
if datafile == None:
return tmp
else:
fh = open(datafile, 'w')
fh.write(tmp)
fh.close()
return None