##// END OF EJS Templates
formatting y int()
José Chávez -
r1124:383e5ee91f88
parent child
Show More
@@ -1,905 +1,905
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import inspect
10 import inspect
11
11
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
13 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
14
14
15 BASIC_STRUCTURE = numpy.dtype([
15 BASIC_STRUCTURE = numpy.dtype([
16 ('nSize', '<u4'),
16 ('nSize', '<u4'),
17 ('nVersion', '<u2'),
17 ('nVersion', '<u2'),
18 ('nDataBlockId', '<u4'),
18 ('nDataBlockId', '<u4'),
19 ('nUtime', '<u4'),
19 ('nUtime', '<u4'),
20 ('nMilsec', '<u2'),
20 ('nMilsec', '<u2'),
21 ('nTimezone', '<i2'),
21 ('nTimezone', '<i2'),
22 ('nDstflag', '<i2'),
22 ('nDstflag', '<i2'),
23 ('nErrorCount', '<u4')
23 ('nErrorCount', '<u4')
24 ])
24 ])
25
25
26 SYSTEM_STRUCTURE = numpy.dtype([
26 SYSTEM_STRUCTURE = numpy.dtype([
27 ('nSize', '<u4'),
27 ('nSize', '<u4'),
28 ('nNumSamples', '<u4'),
28 ('nNumSamples', '<u4'),
29 ('nNumProfiles', '<u4'),
29 ('nNumProfiles', '<u4'),
30 ('nNumChannels', '<u4'),
30 ('nNumChannels', '<u4'),
31 ('nADCResolution', '<u4'),
31 ('nADCResolution', '<u4'),
32 ('nPCDIOBusWidth', '<u4'),
32 ('nPCDIOBusWidth', '<u4'),
33 ])
33 ])
34
34
35 RADAR_STRUCTURE = numpy.dtype([
35 RADAR_STRUCTURE = numpy.dtype([
36 ('nSize', '<u4'),
36 ('nSize', '<u4'),
37 ('nExpType', '<u4'),
37 ('nExpType', '<u4'),
38 ('nNTx', '<u4'),
38 ('nNTx', '<u4'),
39 ('fIpp', '<f4'),
39 ('fIpp', '<f4'),
40 ('fTxA', '<f4'),
40 ('fTxA', '<f4'),
41 ('fTxB', '<f4'),
41 ('fTxB', '<f4'),
42 ('nNumWindows', '<u4'),
42 ('nNumWindows', '<u4'),
43 ('nNumTaus', '<u4'),
43 ('nNumTaus', '<u4'),
44 ('nCodeType', '<u4'),
44 ('nCodeType', '<u4'),
45 ('nLine6Function', '<u4'),
45 ('nLine6Function', '<u4'),
46 ('nLine5Function', '<u4'),
46 ('nLine5Function', '<u4'),
47 ('fClock', '<f4'),
47 ('fClock', '<f4'),
48 ('nPrePulseBefore', '<u4'),
48 ('nPrePulseBefore', '<u4'),
49 ('nPrePulseAfter', '<u4'),
49 ('nPrePulseAfter', '<u4'),
50 ('sRangeIPP', '<a20'),
50 ('sRangeIPP', '<a20'),
51 ('sRangeTxA', '<a20'),
51 ('sRangeTxA', '<a20'),
52 ('sRangeTxB', '<a20'),
52 ('sRangeTxB', '<a20'),
53 ])
53 ])
54
54
55 SAMPLING_STRUCTURE = numpy.dtype(
55 SAMPLING_STRUCTURE = numpy.dtype(
56 [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')])
56 [('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')])
57
57
58
58
59 PROCESSING_STRUCTURE = numpy.dtype([
59 PROCESSING_STRUCTURE = numpy.dtype([
60 ('nSize', '<u4'),
60 ('nSize', '<u4'),
61 ('nDataType', '<u4'),
61 ('nDataType', '<u4'),
62 ('nSizeOfDataBlock', '<u4'),
62 ('nSizeOfDataBlock', '<u4'),
63 ('nProfilesperBlock', '<u4'),
63 ('nProfilesperBlock', '<u4'),
64 ('nDataBlocksperFile', '<u4'),
64 ('nDataBlocksperFile', '<u4'),
65 ('nNumWindows', '<u4'),
65 ('nNumWindows', '<u4'),
66 ('nProcessFlags', '<u4'),
66 ('nProcessFlags', '<u4'),
67 ('nCoherentIntegrations', '<u4'),
67 ('nCoherentIntegrations', '<u4'),
68 ('nIncoherentIntegrations', '<u4'),
68 ('nIncoherentIntegrations', '<u4'),
69 ('nTotalSpectra', '<u4')
69 ('nTotalSpectra', '<u4')
70 ])
70 ])
71
71
72
72
73 class Header(object):
73 class Header(object):
74
74
75 def __init__(self):
75 def __init__(self):
76 raise NotImplementedError
76 raise NotImplementedError
77
77
78 def copy(self):
78 def copy(self):
79 return copy.deepcopy(self)
79 return copy.deepcopy(self)
80
80
81 def read(self):
81 def read(self):
82
82
83 raise NotImplementedError
83 raise NotImplementedError
84
84
85 def write(self):
85 def write(self):
86
86
87 raise NotImplementedError
87 raise NotImplementedError
88
88
89 def getAllowedArgs(self):
89 def getAllowedArgs(self):
90 args = inspect.getargspec(self.__init__).args
90 args = inspect.getargspec(self.__init__).args
91 try:
91 try:
92 args.remove('self')
92 args.remove('self')
93 except:
93 except:
94 pass
94 pass
95 return args
95 return args
96
96
97 def getAsDict(self):
97 def getAsDict(self):
98 args = self.getAllowedArgs()
98 args = self.getAllowedArgs()
99 asDict = {}
99 asDict = {}
100 for x in args:
100 for x in args:
101 asDict[x] = self[x]
101 asDict[x] = self[x]
102 return asDict
102 return asDict
103
103
104 def __getitem__(self, name):
104 def __getitem__(self, name):
105 return getattr(self, name)
105 return getattr(self, name)
106
106
107 def printInfo(self):
107 def printInfo(self):
108
108
109 message = "#" * 50 + "\n"
109 message = "#" * 50 + "\n"
110 message += self.__class__.__name__.upper() + "\n"
110 message += self.__class__.__name__.upper() + "\n"
111 message += "#" * 50 + "\n"
111 message += "#" * 50 + "\n"
112
112
113 keyList = self.__dict__.keys()
113 keyList = self.__dict__.keys()
114 keyList.sort()
114 keyList.sort()
115
115
116 for key in keyList:
116 for key in keyList:
117 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
117 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
118
118
119 if "size" not in keyList:
119 if "size" not in keyList:
120 attr = getattr(self, "size")
120 attr = getattr(self, "size")
121
121
122 if attr:
122 if attr:
123 message += "%s = %s" % ("size", attr) + "\n"
123 message += "%s = %s" % ("size", attr) + "\n"
124
124
125 print message
125 print message
126
126
127
127
128 class BasicHeader(Header):
128 class BasicHeader(Header):
129
129
130 size = None
130 size = None
131 version = None
131 version = None
132 dataBlock = None
132 dataBlock = None
133 utc = None
133 utc = None
134 ltc = None
134 ltc = None
135 miliSecond = None
135 miliSecond = None
136 timeZone = None
136 timeZone = None
137 dstFlag = None
137 dstFlag = None
138 errorCount = None
138 errorCount = None
139 datatime = None
139 datatime = None
140 structure = BASIC_STRUCTURE
140 structure = BASIC_STRUCTURE
141 __LOCALTIME = None
141 __LOCALTIME = None
142
142
143 def __init__(self, useLocalTime=True):
143 def __init__(self, useLocalTime=True):
144
144
145 self.size = 24
145 self.size = 24
146 self.version = 0
146 self.version = 0
147 self.dataBlock = 0
147 self.dataBlock = 0
148 self.utc = 0
148 self.utc = 0
149 self.miliSecond = 0
149 self.miliSecond = 0
150 self.timeZone = 0
150 self.timeZone = 0
151 self.dstFlag = 0
151 self.dstFlag = 0
152 self.errorCount = 0
152 self.errorCount = 0
153
153
154 self.useLocalTime = useLocalTime
154 self.useLocalTime = useLocalTime
155
155
156 def read(self, fp):
156 def read(self, fp):
157
157
158 self.length = 0
158 self.length = 0
159 try:
159 try:
160 if hasattr(fp, 'read'):
160 if hasattr(fp, 'read'):
161 header = numpy.fromfile(fp, BASIC_STRUCTURE, 1)
161 header = numpy.fromfile(fp, BASIC_STRUCTURE, 1)
162 else:
162 else:
163 header = numpy.fromstring(fp, BASIC_STRUCTURE, 1)
163 header = numpy.fromstring(fp, BASIC_STRUCTURE, 1)
164 except Exception, e:
164 except Exception, e:
165 print "BasicHeader: "
165 print "BasicHeader: "
166 print e
166 print e
167 return 0
167 return 0
168
168
169 self.size = int(header['nSize'][0])
169 self.size = int(header['nSize'][0])
170 self.version = int(header['nVersion'][0])
170 self.version = int(header['nVersion'][0])
171 self.dataBlock = int(header['nDataBlockId'][0])
171 self.dataBlock = int(header['nDataBlockId'][0])
172 self.utc = int(header['nUtime'][0])
172 self.utc = int(header['nUtime'][0])
173 self.miliSecond = int(header['nMilsec'][0])
173 self.miliSecond = int(header['nMilsec'][0])
174 self.timeZone = int(header['nTimezone'][0])
174 self.timeZone = int(header['nTimezone'][0])
175 self.dstFlag = int(header['nDstflag'][0])
175 self.dstFlag = int(header['nDstflag'][0])
176 self.errorCount = int(header['nErrorCount'][0])
176 self.errorCount = int(header['nErrorCount'][0])
177
177
178 if self.size < 24:
178 if self.size < 24:
179 return 0
179 return 0
180
180
181 self.length = header.nbytes
181 self.length = header.nbytes
182 return 1
182 return 1
183
183
184 def write(self, fp):
184 def write(self, fp):
185
185
186 headerTuple = (self.size, self.version, self.dataBlock, self.utc,
186 headerTuple = (self.size, self.version, self.dataBlock, self.utc,
187 self.miliSecond, self.timeZone, self.dstFlag, self.errorCount)
187 self.miliSecond, self.timeZone, self.dstFlag, self.errorCount)
188 header = numpy.array(headerTuple, BASIC_STRUCTURE)
188 header = numpy.array(headerTuple, BASIC_STRUCTURE)
189 header.tofile(fp)
189 header.tofile(fp)
190
190
191 return 1
191 return 1
192
192
193 def get_ltc(self):
193 def get_ltc(self):
194
194
195 return self.utc - self.timeZone * 60
195 return self.utc - self.timeZone * 60
196
196
197 def set_ltc(self, value):
197 def set_ltc(self, value):
198
198
199 self.utc = value + self.timeZone * 60
199 self.utc = value + self.timeZone * 60
200
200
201 def get_datatime(self):
201 def get_datatime(self):
202
202
203 return datetime.datetime.utcfromtimestamp(self.ltc)
203 return datetime.datetime.utcfromtimestamp(self.ltc)
204
204
205 ltc = property(get_ltc, set_ltc)
205 ltc = property(get_ltc, set_ltc)
206 datatime = property(get_datatime)
206 datatime = property(get_datatime)
207
207
208
208
209 class SystemHeader(Header):
209 class SystemHeader(Header):
210
210
211 size = None
211 size = None
212 nSamples = None
212 nSamples = None
213 nProfiles = None
213 nProfiles = None
214 nChannels = None
214 nChannels = None
215 adcResolution = None
215 adcResolution = None
216 pciDioBusWidth = None
216 pciDioBusWidth = None
217 structure = SYSTEM_STRUCTURE
217 structure = SYSTEM_STRUCTURE
218
218
219 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
219 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
220
220
221 self.size = 24
221 self.size = 24
222 self.nSamples = nSamples
222 self.nSamples = nSamples
223 self.nProfiles = nProfiles
223 self.nProfiles = nProfiles
224 self.nChannels = nChannels
224 self.nChannels = nChannels
225 self.adcResolution = adcResolution
225 self.adcResolution = adcResolution
226 self.pciDioBusWidth = pciDioBusWidth
226 self.pciDioBusWidth = pciDioBusWidth
227
227
228 def read(self, fp):
228 def read(self, fp):
229 self.length = 0
229 self.length = 0
230 try:
230 try:
231 startFp = fp.tell()
231 startFp = fp.tell()
232 except Exception, e:
232 except Exception, e:
233 startFp = None
233 startFp = None
234 pass
234 pass
235
235
236 try:
236 try:
237 if hasattr(fp, 'read'):
237 if hasattr(fp, 'read'):
238 header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1)
238 header = numpy.fromfile(fp, SYSTEM_STRUCTURE, 1)
239 else:
239 else:
240 header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1)
240 header = numpy.fromstring(fp, SYSTEM_STRUCTURE, 1)
241 except Exception, e:
241 except Exception, e:
242 print "System Header: " + str(e)
242 print "System Header: " + str(e)
243 return 0
243 return 0
244
244
245 self.size = header['nSize'][0]
245 self.size = header['nSize'][0]
246 self.nSamples = header['nNumSamples'][0]
246 self.nSamples = header['nNumSamples'][0]
247 self.nProfiles = header['nNumProfiles'][0]
247 self.nProfiles = header['nNumProfiles'][0]
248 self.nChannels = header['nNumChannels'][0]
248 self.nChannels = header['nNumChannels'][0]
249 self.adcResolution = header['nADCResolution'][0]
249 self.adcResolution = header['nADCResolution'][0]
250 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
250 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
251
251
252 if startFp is not None:
252 if startFp is not None:
253 endFp = self.size + startFp
253 endFp = self.size + startFp
254
254
255 if fp.tell() > endFp:
255 if fp.tell() > endFp:
256 sys.stderr.write(
256 sys.stderr.write(
257 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name)
257 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp.name)
258 return 0
258 return 0
259
259
260 if fp.tell() < endFp:
260 if fp.tell() < endFp:
261 sys.stderr.write(
261 sys.stderr.write(
262 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name)
262 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp.name)
263 return 0
263 return 0
264
264
265 self.length = header.nbytes
265 self.length = header.nbytes
266 return 1
266 return 1
267
267
268 def write(self, fp):
268 def write(self, fp):
269
269
270 headerTuple = (self.size, self.nSamples, self.nProfiles,
270 headerTuple = (self.size, self.nSamples, self.nProfiles,
271 self.nChannels, self.adcResolution, self.pciDioBusWidth)
271 self.nChannels, self.adcResolution, self.pciDioBusWidth)
272 header = numpy.array(headerTuple, SYSTEM_STRUCTURE)
272 header = numpy.array(headerTuple, SYSTEM_STRUCTURE)
273 header.tofile(fp)
273 header.tofile(fp)
274
274
275 return 1
275 return 1
276
276
277
277
278 class RadarControllerHeader(Header):
278 class RadarControllerHeader(Header):
279
279
280 expType = None
280 expType = None
281 nTx = None
281 nTx = None
282 ipp = None
282 ipp = None
283 txA = None
283 txA = None
284 txB = None
284 txB = None
285 nWindows = None
285 nWindows = None
286 numTaus = None
286 numTaus = None
287 codeType = None
287 codeType = None
288 line6Function = None
288 line6Function = None
289 line5Function = None
289 line5Function = None
290 fClock = None
290 fClock = None
291 prePulseBefore = None
291 prePulseBefore = None
292 prePulseAfter = None
292 prePulseAfter = None
293 rangeIpp = None
293 rangeIpp = None
294 rangeTxA = None
294 rangeTxA = None
295 rangeTxB = None
295 rangeTxB = None
296 structure = RADAR_STRUCTURE
296 structure = RADAR_STRUCTURE
297 __size = None
297 __size = None
298
298
299 def __init__(self, expType=2, nTx=1,
299 def __init__(self, expType=2, nTx=1,
300 ipp=None, txA=0, txB=0,
300 ipp=None, txA=0, txB=0,
301 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
301 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
302 numTaus=0, line6Function=0, line5Function=0, fClock=None,
302 numTaus=0, line6Function=0, line5Function=0, fClock=None,
303 prePulseBefore=0, prePulseAfter=0,
303 prePulseBefore=0, prePulseAfter=0,
304 codeType=0, nCode=0, nBaud=0, code=None,
304 codeType=0, nCode=0, nBaud=0, code=None,
305 flip1=0, flip2=0):
305 flip1=0, flip2=0):
306
306
307 # self.size = 116
307 # self.size = 116
308 self.expType = expType
308 self.expType = expType
309 self.nTx = nTx
309 self.nTx = nTx
310 self.ipp = ipp
310 self.ipp = ipp
311 self.txA = txA
311 self.txA = txA
312 self.txB = txB
312 self.txB = txB
313 self.rangeIpp = ipp
313 self.rangeIpp = ipp
314 self.rangeTxA = txA
314 self.rangeTxA = txA
315 self.rangeTxB = txB
315 self.rangeTxB = txB
316
316
317 self.nWindows = nWindows
317 self.nWindows = nWindows
318 self.numTaus = numTaus
318 self.numTaus = numTaus
319 self.codeType = codeType
319 self.codeType = codeType
320 self.line6Function = line6Function
320 self.line6Function = line6Function
321 self.line5Function = line5Function
321 self.line5Function = line5Function
322 self.fClock = fClock
322 self.fClock = fClock
323 self.prePulseBefore = prePulseBefore
323 self.prePulseBefore = prePulseBefore
324 self.prePulseAfter = prePulseAfter
324 self.prePulseAfter = prePulseAfter
325
325
326 self.nHeights = nHeights
326 self.nHeights = nHeights
327 self.firstHeight = firstHeight
327 self.firstHeight = firstHeight
328 self.deltaHeight = deltaHeight
328 self.deltaHeight = deltaHeight
329 self.samplesWin = nHeights
329 self.samplesWin = nHeights
330
330
331 self.nCode = nCode
331 self.nCode = nCode
332 self.nBaud = nBaud
332 self.nBaud = nBaud
333 self.code = code
333 self.code = code
334 self.flip1 = flip1
334 self.flip1 = flip1
335 self.flip2 = flip2
335 self.flip2 = flip2
336
336
337 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
337 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
338 # self.dynamic = numpy.array([],numpy.dtype('byte'))
338 # self.dynamic = numpy.array([],numpy.dtype('byte'))
339
339
340 if self.fClock is None and self.deltaHeight is not None:
340 if self.fClock is None and self.deltaHeight is not None:
341 self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u)
341 self.fClock = 0.15 / (deltaHeight * 1e-6) # 0.15Km / (height * 1u)
342
342
343 def read(self, fp):
343 def read(self, fp):
344 self.length = 0
344 self.length = 0
345 try:
345 try:
346 startFp = fp.tell()
346 startFp = fp.tell()
347 except Exception, e:
347 except Exception, e:
348 startFp = None
348 startFp = None
349 pass
349 pass
350
350
351 try:
351 try:
352 if hasattr(fp, 'read'):
352 if hasattr(fp, 'read'):
353 header = numpy.fromfile(fp, RADAR_STRUCTURE, 1)
353 header = numpy.fromfile(fp, RADAR_STRUCTURE, 1)
354 else:
354 else:
355 header = numpy.fromstring(fp, RADAR_STRUCTURE, 1)
355 header = numpy.fromstring(fp, RADAR_STRUCTURE, 1)
356 self.length += header.nbytes
356 self.length += header.nbytes
357 except Exception, e:
357 except Exception, e:
358 print "RadarControllerHeader: " + str(e)
358 print "RadarControllerHeader: " + str(e)
359 return 0
359 return 0
360
360
361 size = int(header['nSize'][0])
361 size = int(header['nSize'][0])
362 self.expType = int(header['nExpType'][0])
362 self.expType = int(header['nExpType'][0])
363 self.nTx = int(header['nNTx'][0])
363 self.nTx = int(header['nNTx'][0])
364 self.ipp = float(header['fIpp'][0])
364 self.ipp = float(header['fIpp'][0])
365 self.txA = float(header['fTxA'][0])
365 self.txA = float(header['fTxA'][0])
366 self.txB = float(header['fTxB'][0])
366 self.txB = float(header['fTxB'][0])
367 self.nWindows = int(header['nNumWindows'][0])
367 self.nWindows = int(header['nNumWindows'][0])
368 self.numTaus = int(header['nNumTaus'][0])
368 self.numTaus = int(header['nNumTaus'][0])
369 self.codeType = int(header['nCodeType'][0])
369 self.codeType = int(header['nCodeType'][0])
370 self.line6Function = int(header['nLine6Function'][0])
370 self.line6Function = int(header['nLine6Function'][0])
371 self.line5Function = int(header['nLine5Function'][0])
371 self.line5Function = int(header['nLine5Function'][0])
372 self.fClock = float(header['fClock'][0])
372 self.fClock = float(header['fClock'][0])
373 self.prePulseBefore = int(header['nPrePulseBefore'][0])
373 self.prePulseBefore = int(header['nPrePulseBefore'][0])
374 self.prePulseAfter = int(header['nPrePulseAfter'][0])
374 self.prePulseAfter = int(header['nPrePulseAfter'][0])
375 self.rangeIpp = header['sRangeIPP'][0]
375 self.rangeIpp = header['sRangeIPP'][0]
376 self.rangeTxA = header['sRangeTxA'][0]
376 self.rangeTxA = header['sRangeTxA'][0]
377 self.rangeTxB = header['sRangeTxB'][0]
377 self.rangeTxB = header['sRangeTxB'][0]
378
378
379 try:
379 try:
380 if hasattr(fp, 'read'):
380 if hasattr(fp, 'read'):
381 samplingWindow = numpy.fromfile(
381 samplingWindow = numpy.fromfile(
382 fp, SAMPLING_STRUCTURE, self.nWindows)
382 fp, SAMPLING_STRUCTURE, self.nWindows)
383 else:
383 else:
384 samplingWindow = numpy.fromstring(
384 samplingWindow = numpy.fromstring(
385 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
385 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
386 self.length += samplingWindow.nbytes
386 self.length += samplingWindow.nbytes
387 except Exception, e:
387 except Exception, e:
388 print "RadarControllerHeader: " + str(e)
388 print "RadarControllerHeader: " + str(e)
389 return 0
389 return 0
390 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
390 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
391 self.firstHeight = samplingWindow['h0']
391 self.firstHeight = samplingWindow['h0']
392 self.deltaHeight = samplingWindow['dh']
392 self.deltaHeight = samplingWindow['dh']
393 self.samplesWin = samplingWindow['nsa']
393 self.samplesWin = samplingWindow['nsa']
394
394
395 try:
395 try:
396 if hasattr(fp, 'read'):
396 if hasattr(fp, 'read'):
397 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
397 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
398 else:
398 else:
399 self.Taus = numpy.fromstring(
399 self.Taus = numpy.fromstring(
400 fp[self.length:], '<f4', self.numTaus)
400 fp[self.length:], '<f4', self.numTaus)
401 self.length += self.Taus.nbytes
401 self.length += self.Taus.nbytes
402 except Exception, e:
402 except Exception, e:
403 print "RadarControllerHeader: " + str(e)
403 print "RadarControllerHeader: " + str(e)
404 return 0
404 return 0
405
405
406 self.code_size = 0
406 self.code_size = 0
407 if self.codeType != 0:
407 if self.codeType != 0:
408
408
409 try:
409 try:
410 if hasattr(fp, 'read'):
410 if hasattr(fp, 'read'):
411 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
411 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
412 self.length += self.nCode.nbytes
412 self.length += self.nCode.nbytes
413 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
413 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
414 self.length += self.nBaud.nbytes
414 self.length += self.nBaud.nbytes
415 else:
415 else:
416 self.nCode = numpy.fromstring(
416 self.nCode = numpy.fromstring(
417 fp[self.length:], '<u4', 1)[0]
417 fp[self.length:], '<u4', 1)[0]
418 self.length += self.nCode.nbytes
418 self.length += self.nCode.nbytes
419 self.nBaud = numpy.fromstring(
419 self.nBaud = numpy.fromstring(
420 fp[self.length:], '<u4', 1)[0]
420 fp[self.length:], '<u4', 1)[0]
421 self.length += self.nBaud.nbytes
421 self.length += self.nBaud.nbytes
422 except Exception, e:
422 except Exception, e:
423 print "RadarControllerHeader: " + str(e)
423 print "RadarControllerHeader: " + str(e)
424 return 0
424 return 0
425 code = numpy.empty([self.nCode, self.nBaud], dtype='i1')
425 code = numpy.empty([self.nCode, self.nBaud], dtype='i1')
426
426
427 for ic in range(self.nCode):
427 for ic in range(self.nCode):
428 try:
428 try:
429 if hasattr(fp, 'read'):
429 if hasattr(fp, 'read'):
430 temp = numpy.fromfile(fp, 'u4', int(
430 temp = numpy.fromfile(fp, 'u4', int(
431 numpy.ceil(self.nBaud / 32.)))
431 numpy.ceil(self.nBaud / 32.)))
432 else:
432 else:
433 temp = numpy.fromstring(
433 temp = numpy.fromstring(
434 fp, 'u4', int(numpy.ceil(self.nBaud / 32.)))
434 fp, 'u4', int(numpy.ceil(self.nBaud / 32.)))
435 self.length += temp.nbytes
435 self.length += temp.nbytes
436 except Exception, e:
436 except Exception, e:
437 print "RadarControllerHeader: " + str(e)
437 print "RadarControllerHeader: " + str(e)
438 return 0
438 return 0
439
439
440 for ib in range(self.nBaud - 1, -1, -1):
440 for ib in range(self.nBaud - 1, -1, -1):
441 code[ic, ib] = temp[ib / 32] % 2
441 code[ic, ib] = temp[ib / 32] % 2
442 temp[ib / 32] = temp[ib / 32] / 2
442 temp[ib / 32] = temp[ib / 32] / 2
443
443
444 self.code = 2.0 * code - 1.0
444 self.code = 2.0 * code - 1.0
445 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
445 self.code_size = int(numpy.ceil(self.nBaud / 32.)) * self.nCode * 4
446
446
447 # if self.line5Function == RCfunction.FLIP:
447 # if self.line5Function == RCfunction.FLIP:
448 # self.flip1 = numpy.fromfile(fp,'<u4',1)
448 # self.flip1 = numpy.fromfile(fp,'<u4',1)
449 #
449 #
450 # if self.line6Function == RCfunction.FLIP:
450 # if self.line6Function == RCfunction.FLIP:
451 # self.flip2 = numpy.fromfile(fp,'<u4',1)
451 # self.flip2 = numpy.fromfile(fp,'<u4',1)
452 if startFp is not None:
452 if startFp is not None:
453 endFp = size + startFp
453 endFp = size + startFp
454
454
455 if fp.tell() != endFp:
455 if fp.tell() != endFp:
456 # fp.seek(endFp)
456 # fp.seek(endFp)
457 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size)
457 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" % (fp.name, fp.tell() - startFp, size)
458 # return 0
458 # return 0
459
459
460 if fp.tell() > endFp:
460 if fp.tell() > endFp:
461 sys.stderr.write(
461 sys.stderr.write(
462 "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name)
462 "Warning %s: Size value read from Radar Controller header is lower than it has to be\n" % fp.name)
463 # return 0
463 # return 0
464
464
465 if fp.tell() < endFp:
465 if fp.tell() < endFp:
466 sys.stderr.write(
466 sys.stderr.write(
467 "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name)
467 "Warning %s: Size value read from Radar Controller header is greater than it has to be\n" % fp.name)
468
468
469 return 1
469 return 1
470
470
471 def write(self, fp):
471 def write(self, fp):
472
472
473 headerTuple = (self.size,
473 headerTuple = (self.size,
474 self.expType,
474 self.expType,
475 self.nTx,
475 self.nTx,
476 self.ipp,
476 self.ipp,
477 self.txA,
477 self.txA,
478 self.txB,
478 self.txB,
479 self.nWindows,
479 self.nWindows,
480 self.numTaus,
480 self.numTaus,
481 self.codeType,
481 self.codeType,
482 self.line6Function,
482 self.line6Function,
483 self.line5Function,
483 self.line5Function,
484 self.fClock,
484 self.fClock,
485 self.prePulseBefore,
485 self.prePulseBefore,
486 self.prePulseAfter,
486 self.prePulseAfter,
487 self.rangeIpp,
487 self.rangeIpp,
488 self.rangeTxA,
488 self.rangeTxA,
489 self.rangeTxB)
489 self.rangeTxB)
490
490
491 header = numpy.array(headerTuple, RADAR_STRUCTURE)
491 header = numpy.array(headerTuple, RADAR_STRUCTURE)
492 header.tofile(fp)
492 header.tofile(fp)
493
493
494 sampleWindowTuple = (
494 sampleWindowTuple = (
495 self.firstHeight, self.deltaHeight, self.samplesWin)
495 self.firstHeight, self.deltaHeight, self.samplesWin)
496 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
496 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
497 samplingWindow.tofile(fp)
497 samplingWindow.tofile(fp)
498
498
499 if self.numTaus > 0:
499 if self.numTaus > 0:
500 self.Taus.tofile(fp)
500 self.Taus.tofile(fp)
501
501
502 if self.codeType != 0:
502 if self.codeType != 0:
503 nCode = numpy.array(self.nCode, '<u4')
503 nCode = numpy.array(self.nCode, '<u4')
504 nCode.tofile(fp)
504 nCode.tofile(fp)
505 nBaud = numpy.array(self.nBaud, '<u4')
505 nBaud = numpy.array(self.nBaud, '<u4')
506 nBaud.tofile(fp)
506 nBaud.tofile(fp)
507 code1 = (self.code + 1.0) / 2.
507 code1 = (self.code + 1.0) / 2.
508
508
509 for ic in range(self.nCode):
509 for ic in range(self.nCode):
510 tempx = numpy.zeros(numpy.ceil(self.nBaud / 32.))
510 tempx = numpy.zeros(int(self.nBaud / 32.))
511 start = 0
511 start = 0
512 end = 32
512 end = 32
513 for i in range(len(tempx)):
513 for i in range(len(tempx)):
514 code_selected = code1[ic, start:end]
514 code_selected = code1[ic, start:end]
515 for j in range(len(code_selected) - 1, -1, -1):
515 for j in range(len(code_selected) - 1, -1, -1):
516 if code_selected[j] == 1:
516 if code_selected[j] == 1:
517 tempx[i] = tempx[i] + \
517 tempx[i] = tempx[i] + \
518 2**(len(code_selected) - 1 - j)
518 2**(len(code_selected) - 1 - j)
519 start = start + 32
519 start = start + 32
520 end = end + 32
520 end = end + 32
521
521
522 tempx = tempx.astype('u4')
522 tempx = tempx.astype('u4')
523 tempx.tofile(fp)
523 tempx.tofile(fp)
524
524
525 # if self.line5Function == RCfunction.FLIP:
525 # if self.line5Function == RCfunction.FLIP:
526 # self.flip1.tofile(fp)
526 # self.flip1.tofile(fp)
527 #
527 #
528 # if self.line6Function == RCfunction.FLIP:
528 # if self.line6Function == RCfunction.FLIP:
529 # self.flip2.tofile(fp)
529 # self.flip2.tofile(fp)
530
530
531 return 1
531 return 1
532
532
533 def get_ippSeconds(self):
533 def get_ippSeconds(self):
534 '''
534 '''
535 '''
535 '''
536 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
536 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
537
537
538 return ippSeconds
538 return ippSeconds
539
539
540 def set_ippSeconds(self, ippSeconds):
540 def set_ippSeconds(self, ippSeconds):
541 '''
541 '''
542 '''
542 '''
543
543
544 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000)
544 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0 * 1000)
545
545
546 return
546 return
547
547
548 def get_size(self):
548 def get_size(self):
549
549
550 self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus
550 self.__size = 116 + 12 * self.nWindows + 4 * self.numTaus
551
551
552 if self.codeType != 0:
552 if self.codeType != 0:
553 self.__size += 4 + 4 + 4 * self.nCode * \
553 self.__size += 4 + 4 + 4 * self.nCode * \
554 numpy.ceil(self.nBaud / 32.)
554 numpy.ceil(self.nBaud / 32.)
555
555
556 return self.__size
556 return self.__size
557
557
558 def set_size(self, value):
558 def set_size(self, value):
559
559
560 raise IOError, "size is a property and it cannot be set, just read"
560 raise IOError, "size is a property and it cannot be set, just read"
561
561
562 return
562 return
563
563
564 ippSeconds = property(get_ippSeconds, set_ippSeconds)
564 ippSeconds = property(get_ippSeconds, set_ippSeconds)
565 size = property(get_size, set_size)
565 size = property(get_size, set_size)
566
566
567
567
568 class ProcessingHeader(Header):
568 class ProcessingHeader(Header):
569
569
570 # size = None
570 # size = None
571 dtype = None
571 dtype = None
572 blockSize = None
572 blockSize = None
573 profilesPerBlock = None
573 profilesPerBlock = None
574 dataBlocksPerFile = None
574 dataBlocksPerFile = None
575 nWindows = None
575 nWindows = None
576 processFlags = None
576 processFlags = None
577 nCohInt = None
577 nCohInt = None
578 nIncohInt = None
578 nIncohInt = None
579 totalSpectra = None
579 totalSpectra = None
580 structure = PROCESSING_STRUCTURE
580 structure = PROCESSING_STRUCTURE
581 flag_dc = None
581 flag_dc = None
582 flag_cspc = None
582 flag_cspc = None
583
583
584 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
584 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0, processFlags=0, nCohInt=0,
585 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
585 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
586 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
586 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
587 ):
587 ):
588
588
589 # self.size = 0
589 # self.size = 0
590 self.dtype = dtype
590 self.dtype = dtype
591 self.blockSize = blockSize
591 self.blockSize = blockSize
592 self.profilesPerBlock = 0
592 self.profilesPerBlock = 0
593 self.dataBlocksPerFile = 0
593 self.dataBlocksPerFile = 0
594 self.nWindows = 0
594 self.nWindows = 0
595 self.processFlags = 0
595 self.processFlags = 0
596 self.nCohInt = 0
596 self.nCohInt = 0
597 self.nIncohInt = 0
597 self.nIncohInt = 0
598 self.totalSpectra = 0
598 self.totalSpectra = 0
599
599
600 self.nHeights = 0
600 self.nHeights = 0
601 self.firstHeight = 0
601 self.firstHeight = 0
602 self.deltaHeight = 0
602 self.deltaHeight = 0
603 self.samplesWin = 0
603 self.samplesWin = 0
604 self.spectraComb = 0
604 self.spectraComb = 0
605 self.nCode = None
605 self.nCode = None
606 self.code = None
606 self.code = None
607 self.nBaud = None
607 self.nBaud = None
608
608
609 self.shif_fft = False
609 self.shif_fft = False
610 self.flag_dc = False
610 self.flag_dc = False
611 self.flag_cspc = False
611 self.flag_cspc = False
612 self.flag_decode = False
612 self.flag_decode = False
613 self.flag_deflip = False
613 self.flag_deflip = False
614 self.length = 0
614 self.length = 0
615
615
616 def read(self, fp):
616 def read(self, fp):
617 self.length = 0
617 self.length = 0
618 try:
618 try:
619 startFp = fp.tell()
619 startFp = fp.tell()
620 except Exception, e:
620 except Exception, e:
621 startFp = None
621 startFp = None
622 pass
622 pass
623
623
624 try:
624 try:
625 if hasattr(fp, 'read'):
625 if hasattr(fp, 'read'):
626 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
626 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
627 else:
627 else:
628 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
628 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
629 self.length += header.nbytes
629 self.length += header.nbytes
630 except Exception, e:
630 except Exception, e:
631 print "ProcessingHeader: " + str(e)
631 print "ProcessingHeader: " + str(e)
632 return 0
632 return 0
633
633
634 size = int(header['nSize'][0])
634 size = int(header['nSize'][0])
635 self.dtype = int(header['nDataType'][0])
635 self.dtype = int(header['nDataType'][0])
636 self.blockSize = int(header['nSizeOfDataBlock'][0])
636 self.blockSize = int(header['nSizeOfDataBlock'][0])
637 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
637 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
638 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
638 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
639 self.nWindows = int(header['nNumWindows'][0])
639 self.nWindows = int(header['nNumWindows'][0])
640 self.processFlags = header['nProcessFlags']
640 self.processFlags = header['nProcessFlags']
641 self.nCohInt = int(header['nCoherentIntegrations'][0])
641 self.nCohInt = int(header['nCoherentIntegrations'][0])
642 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
642 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
643 self.totalSpectra = int(header['nTotalSpectra'][0])
643 self.totalSpectra = int(header['nTotalSpectra'][0])
644
644
645 try:
645 try:
646 if hasattr(fp, 'read'):
646 if hasattr(fp, 'read'):
647 samplingWindow = numpy.fromfile(
647 samplingWindow = numpy.fromfile(
648 fp, SAMPLING_STRUCTURE, self.nWindows)
648 fp, SAMPLING_STRUCTURE, self.nWindows)
649 else:
649 else:
650 samplingWindow = numpy.fromstring(
650 samplingWindow = numpy.fromstring(
651 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
651 fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
652 self.length += samplingWindow.nbytes
652 self.length += samplingWindow.nbytes
653 except Exception, e:
653 except Exception, e:
654 print "ProcessingHeader: " + str(e)
654 print "ProcessingHeader: " + str(e)
655 return 0
655 return 0
656
656
657 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
657 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
658 self.firstHeight = float(samplingWindow['h0'][0])
658 self.firstHeight = float(samplingWindow['h0'][0])
659 self.deltaHeight = float(samplingWindow['dh'][0])
659 self.deltaHeight = float(samplingWindow['dh'][0])
660 self.samplesWin = samplingWindow['nsa'][0]
660 self.samplesWin = samplingWindow['nsa'][0]
661
661
662 try:
662 try:
663 if hasattr(fp, 'read'):
663 if hasattr(fp, 'read'):
664 self.spectraComb = numpy.fromfile(
664 self.spectraComb = numpy.fromfile(
665 fp, 'u1', 2 * self.totalSpectra)
665 fp, 'u1', 2 * self.totalSpectra)
666 else:
666 else:
667 self.spectraComb = numpy.fromstring(
667 self.spectraComb = numpy.fromstring(
668 fp[self.length:], 'u1', 2 * self.totalSpectra)
668 fp[self.length:], 'u1', 2 * self.totalSpectra)
669 self.length += self.spectraComb.nbytes
669 self.length += self.spectraComb.nbytes
670 except Exception, e:
670 except Exception, e:
671 print "ProcessingHeader: " + str(e)
671 print "ProcessingHeader: " + str(e)
672 return 0
672 return 0
673
673
674 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
674 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
675 self.nCode = int(numpy.fromfile(fp, '<u4', 1))
675 self.nCode = int(numpy.fromfile(fp, '<u4', 1))
676 self.nBaud = int(numpy.fromfile(fp, '<u4', 1))
676 self.nBaud = int(numpy.fromfile(fp, '<u4', 1))
677 self.code = numpy.fromfile(
677 self.code = numpy.fromfile(
678 fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud)
678 fp, '<f4', self.nCode * self.nBaud).reshape(self.nCode, self.nBaud)
679
679
680 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
680 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
681 exp_name_len = int(numpy.fromfile(fp, '<u4', 1))
681 exp_name_len = int(numpy.fromfile(fp, '<u4', 1))
682 exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1)
682 exp_name = numpy.fromfile(fp, 'u1', exp_name_len + 1)
683
683
684 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
684 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
685 self.shif_fft = True
685 self.shif_fft = True
686 else:
686 else:
687 self.shif_fft = False
687 self.shif_fft = False
688
688
689 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
689 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
690 self.flag_dc = True
690 self.flag_dc = True
691 else:
691 else:
692 self.flag_dc = False
692 self.flag_dc = False
693
693
694 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
694 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
695 self.flag_decode = True
695 self.flag_decode = True
696 else:
696 else:
697 self.flag_decode = False
697 self.flag_decode = False
698
698
699 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
699 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
700 self.flag_deflip = True
700 self.flag_deflip = True
701 else:
701 else:
702 self.flag_deflip = False
702 self.flag_deflip = False
703
703
704 nChannels = 0
704 nChannels = 0
705 nPairs = 0
705 nPairs = 0
706 pairList = []
706 pairList = []
707
707
708 for i in range(0, self.totalSpectra * 2, 2):
708 for i in range(0, self.totalSpectra * 2, 2):
709 if self.spectraComb[i] == self.spectraComb[i + 1]:
709 if self.spectraComb[i] == self.spectraComb[i + 1]:
710 nChannels = nChannels + 1 # par de canales iguales
710 nChannels = nChannels + 1 # par de canales iguales
711 else:
711 else:
712 nPairs = nPairs + 1 # par de canales diferentes
712 nPairs = nPairs + 1 # par de canales diferentes
713 pairList.append((self.spectraComb[i], self.spectraComb[i + 1]))
713 pairList.append((self.spectraComb[i], self.spectraComb[i + 1]))
714
714
715 self.flag_cspc = False
715 self.flag_cspc = False
716 if nPairs > 0:
716 if nPairs > 0:
717 self.flag_cspc = True
717 self.flag_cspc = True
718
718
719 if startFp is not None:
719 if startFp is not None:
720 endFp = size + startFp
720 endFp = size + startFp
721 if fp.tell() > endFp:
721 if fp.tell() > endFp:
722 sys.stderr.write(
722 sys.stderr.write(
723 "Warning: Processing header size is lower than it has to be")
723 "Warning: Processing header size is lower than it has to be")
724 return 0
724 return 0
725
725
726 if fp.tell() < endFp:
726 if fp.tell() < endFp:
727 sys.stderr.write(
727 sys.stderr.write(
728 "Warning: Processing header size is greater than it is considered")
728 "Warning: Processing header size is greater than it is considered")
729
729
730 return 1
730 return 1
731
731
732 def write(self, fp):
732 def write(self, fp):
733 # Clear DEFINE_PROCESS_CODE
733 # Clear DEFINE_PROCESS_CODE
734 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
734 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
735
735
736 headerTuple = (self.size,
736 headerTuple = (self.size,
737 self.dtype,
737 self.dtype,
738 self.blockSize,
738 self.blockSize,
739 self.profilesPerBlock,
739 self.profilesPerBlock,
740 self.dataBlocksPerFile,
740 self.dataBlocksPerFile,
741 self.nWindows,
741 self.nWindows,
742 self.processFlags,
742 self.processFlags,
743 self.nCohInt,
743 self.nCohInt,
744 self.nIncohInt,
744 self.nIncohInt,
745 self.totalSpectra)
745 self.totalSpectra)
746
746
747 header = numpy.array(headerTuple, PROCESSING_STRUCTURE)
747 header = numpy.array(headerTuple, PROCESSING_STRUCTURE)
748 header.tofile(fp)
748 header.tofile(fp)
749
749
750 if self.nWindows != 0:
750 if self.nWindows != 0:
751 sampleWindowTuple = (
751 sampleWindowTuple = (
752 self.firstHeight, self.deltaHeight, self.samplesWin)
752 self.firstHeight, self.deltaHeight, self.samplesWin)
753 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
753 samplingWindow = numpy.array(sampleWindowTuple, SAMPLING_STRUCTURE)
754 samplingWindow.tofile(fp)
754 samplingWindow.tofile(fp)
755
755
756 if self.totalSpectra != 0:
756 if self.totalSpectra != 0:
757 # spectraComb = numpy.array([],numpy.dtype('u1'))
757 # spectraComb = numpy.array([],numpy.dtype('u1'))
758 spectraComb = self.spectraComb
758 spectraComb = self.spectraComb
759 spectraComb.tofile(fp)
759 spectraComb.tofile(fp)
760
760
761 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
761 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
762 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
762 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
763 # nCode.tofile(fp)
763 # nCode.tofile(fp)
764 #
764 #
765 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
765 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
766 # nBaud.tofile(fp)
766 # nBaud.tofile(fp)
767 #
767 #
768 # code = self.code.reshape(self.nCode*self.nBaud)
768 # code = self.code.reshape(self.nCode*self.nBaud)
769 # code = code.astype(numpy.dtype('<f4'))
769 # code = code.astype(numpy.dtype('<f4'))
770 # code.tofile(fp)
770 # code.tofile(fp)
771
771
772 return 1
772 return 1
773
773
774 def get_size(self):
774 def get_size(self):
775
775
776 self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra
776 self.__size = 40 + 12 * self.nWindows + 2 * self.totalSpectra
777
777
778 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
778 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
779 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
779 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
780 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
780 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
781
781
782 return self.__size
782 return self.__size
783
783
784 def set_size(self, value):
784 def set_size(self, value):
785
785
786 raise IOError, "size is a property and it cannot be set, just read"
786 raise IOError, "size is a property and it cannot be set, just read"
787
787
788 return
788 return
789
789
790 size = property(get_size, set_size)
790 size = property(get_size, set_size)
791
791
792
792
793 class RCfunction:
793 class RCfunction:
794 NONE = 0
794 NONE = 0
795 FLIP = 1
795 FLIP = 1
796 CODE = 2
796 CODE = 2
797 SAMPLING = 3
797 SAMPLING = 3
798 LIN6DIV256 = 4
798 LIN6DIV256 = 4
799 SYNCHRO = 5
799 SYNCHRO = 5
800
800
801
801
802 class nCodeType:
802 class nCodeType:
803 NONE = 0
803 NONE = 0
804 USERDEFINE = 1
804 USERDEFINE = 1
805 BARKER2 = 2
805 BARKER2 = 2
806 BARKER3 = 3
806 BARKER3 = 3
807 BARKER4 = 4
807 BARKER4 = 4
808 BARKER5 = 5
808 BARKER5 = 5
809 BARKER7 = 6
809 BARKER7 = 6
810 BARKER11 = 7
810 BARKER11 = 7
811 BARKER13 = 8
811 BARKER13 = 8
812 AC128 = 9
812 AC128 = 9
813 COMPLEMENTARYCODE2 = 10
813 COMPLEMENTARYCODE2 = 10
814 COMPLEMENTARYCODE4 = 11
814 COMPLEMENTARYCODE4 = 11
815 COMPLEMENTARYCODE8 = 12
815 COMPLEMENTARYCODE8 = 12
816 COMPLEMENTARYCODE16 = 13
816 COMPLEMENTARYCODE16 = 13
817 COMPLEMENTARYCODE32 = 14
817 COMPLEMENTARYCODE32 = 14
818 COMPLEMENTARYCODE64 = 15
818 COMPLEMENTARYCODE64 = 15
819 COMPLEMENTARYCODE128 = 16
819 COMPLEMENTARYCODE128 = 16
820 CODE_BINARY28 = 17
820 CODE_BINARY28 = 17
821
821
822
822
823 class PROCFLAG:
823 class PROCFLAG:
824
824
825 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
825 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
826 DECODE_DATA = numpy.uint32(0x00000002)
826 DECODE_DATA = numpy.uint32(0x00000002)
827 SPECTRA_CALC = numpy.uint32(0x00000004)
827 SPECTRA_CALC = numpy.uint32(0x00000004)
828 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
828 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
829 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
829 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
830 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
830 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
831
831
832 DATATYPE_CHAR = numpy.uint32(0x00000040)
832 DATATYPE_CHAR = numpy.uint32(0x00000040)
833 DATATYPE_SHORT = numpy.uint32(0x00000080)
833 DATATYPE_SHORT = numpy.uint32(0x00000080)
834 DATATYPE_LONG = numpy.uint32(0x00000100)
834 DATATYPE_LONG = numpy.uint32(0x00000100)
835 DATATYPE_INT64 = numpy.uint32(0x00000200)
835 DATATYPE_INT64 = numpy.uint32(0x00000200)
836 DATATYPE_FLOAT = numpy.uint32(0x00000400)
836 DATATYPE_FLOAT = numpy.uint32(0x00000400)
837 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
837 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
838
838
839 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
839 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
840 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
840 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
841 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
841 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
842
842
843 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
843 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
844 DEFLIP_DATA = numpy.uint32(0x00010000)
844 DEFLIP_DATA = numpy.uint32(0x00010000)
845 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
845 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
846
846
847 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
847 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
848 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
848 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
849 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
849 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
850 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
850 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
851 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
851 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
852
852
853 EXP_NAME_ESP = numpy.uint32(0x00200000)
853 EXP_NAME_ESP = numpy.uint32(0x00200000)
854 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
854 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
855
855
856 OPERATION_MASK = numpy.uint32(0x0000003F)
856 OPERATION_MASK = numpy.uint32(0x0000003F)
857 DATATYPE_MASK = numpy.uint32(0x00000FC0)
857 DATATYPE_MASK = numpy.uint32(0x00000FC0)
858 DATAARRANGE_MASK = numpy.uint32(0x00007000)
858 DATAARRANGE_MASK = numpy.uint32(0x00007000)
859 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
859 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
860
860
861
861
862 dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
862 dtype0 = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
863 dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
863 dtype1 = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
864 dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
864 dtype2 = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
865 dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
865 dtype3 = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
866 dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
866 dtype4 = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
867 dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
867 dtype5 = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
868
868
869 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
869 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
870
870
871 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
871 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
872 PROCFLAG.DATATYPE_SHORT,
872 PROCFLAG.DATATYPE_SHORT,
873 PROCFLAG.DATATYPE_LONG,
873 PROCFLAG.DATATYPE_LONG,
874 PROCFLAG.DATATYPE_INT64,
874 PROCFLAG.DATATYPE_INT64,
875 PROCFLAG.DATATYPE_FLOAT,
875 PROCFLAG.DATATYPE_FLOAT,
876 PROCFLAG.DATATYPE_DOUBLE]
876 PROCFLAG.DATATYPE_DOUBLE]
877
877
878 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
878 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
879
879
880
880
881 def get_dtype_index(numpy_dtype):
881 def get_dtype_index(numpy_dtype):
882
882
883 index = None
883 index = None
884
884
885 for i in range(len(NUMPY_DTYPE_LIST)):
885 for i in range(len(NUMPY_DTYPE_LIST)):
886 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
886 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
887 index = i
887 index = i
888 break
888 break
889
889
890 return index
890 return index
891
891
892
892
893 def get_numpy_dtype(index):
893 def get_numpy_dtype(index):
894
894
895 return NUMPY_DTYPE_LIST[index]
895 return NUMPY_DTYPE_LIST[index]
896
896
897
897
898 def get_procflag_dtype(index):
898 def get_procflag_dtype(index):
899
899
900 return PROCFLAG_DTYPE_LIST[index]
900 return PROCFLAG_DTYPE_LIST[index]
901
901
902
902
903 def get_dtype_width(index):
903 def get_dtype_width(index):
904
904
905 return DTYPE_WIDTH[index]
905 return DTYPE_WIDTH[index]
1 NO CONTENT: modified file
NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now