##// END OF EJS Templates
Bugs Fixed
Daniel Valdez -
r392:5ce42ab4da33
parent child
Show More
@@ -1,534 +1,534
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
10
11 class Header:
11 class Header:
12
12
13 def __init__(self):
13 def __init__(self):
14 raise
14 raise
15
15
16 def copy(self):
16 def copy(self):
17 return copy.deepcopy(self)
17 return copy.deepcopy(self)
18
18
19 def read():
19 def read():
20 pass
20 pass
21
21
22 def write():
22 def write():
23 pass
23 pass
24
24
25 def printInfo(self):
25 def printInfo(self):
26
26
27 print "#"*100
27 print "#"*100
28 print self.__class__.__name__.upper()
28 print self.__class__.__name__.upper()
29 print "#"*100
29 print "#"*100
30 for key in self.__dict__.keys():
30 for key in self.__dict__.keys():
31 print "%s = %s" %(key, self.__dict__[key])
31 print "%s = %s" %(key, self.__dict__[key])
32
32
33 class BasicHeader(Header):
33 class BasicHeader(Header):
34
34
35 size = None
35 size = None
36 version = None
36 version = None
37 dataBlock = None
37 dataBlock = None
38 utc = None
38 utc = None
39 ltc = None
39 ltc = None
40 miliSecond = None
40 miliSecond = None
41 timeZone = None
41 timeZone = None
42 dstFlag = None
42 dstFlag = None
43 errorCount = None
43 errorCount = None
44 struct = None
44 struct = None
45 datatime = None
45 datatime = None
46
46
47 __LOCALTIME = None
47 __LOCALTIME = None
48
48
49 def __init__(self, useLocalTime=True):
49 def __init__(self, useLocalTime=True):
50
50
51 self.size = 0
51 self.size = 0
52 self.version = 0
52 self.version = 0
53 self.dataBlock = 0
53 self.dataBlock = 0
54 self.utc = 0
54 self.utc = 0
55 self.miliSecond = 0
55 self.miliSecond = 0
56 self.timeZone = 0
56 self.timeZone = 0
57 self.dstFlag = 0
57 self.dstFlag = 0
58 self.errorCount = 0
58 self.errorCount = 0
59 self.struct = numpy.dtype([
59 self.struct = numpy.dtype([
60 ('nSize','<u4'),
60 ('nSize','<u4'),
61 ('nVersion','<u2'),
61 ('nVersion','<u2'),
62 ('nDataBlockId','<u4'),
62 ('nDataBlockId','<u4'),
63 ('nUtime','<u4'),
63 ('nUtime','<u4'),
64 ('nMilsec','<u2'),
64 ('nMilsec','<u2'),
65 ('nTimezone','<i2'),
65 ('nTimezone','<i2'),
66 ('nDstflag','<i2'),
66 ('nDstflag','<i2'),
67 ('nErrorCount','<u4')
67 ('nErrorCount','<u4')
68 ])
68 ])
69
69
70 self.useLocalTime = useLocalTime
70 self.useLocalTime = useLocalTime
71
71
72 def read(self, fp):
72 def read(self, fp):
73 try:
73 try:
74 header = numpy.fromfile(fp, self.struct,1)
74 header = numpy.fromfile(fp, self.struct,1)
75 self.size = int(header['nSize'][0])
75 self.size = int(header['nSize'][0])
76 self.version = int(header['nVersion'][0])
76 self.version = int(header['nVersion'][0])
77 self.dataBlock = int(header['nDataBlockId'][0])
77 self.dataBlock = int(header['nDataBlockId'][0])
78 self.utc = int(header['nUtime'][0])
78 self.utc = int(header['nUtime'][0])
79 self.miliSecond = int(header['nMilsec'][0])
79 self.miliSecond = int(header['nMilsec'][0])
80 self.timeZone = int(header['nTimezone'][0])
80 self.timeZone = int(header['nTimezone'][0])
81 self.dstFlag = int(header['nDstflag'][0])
81 self.dstFlag = int(header['nDstflag'][0])
82 self.errorCount = int(header['nErrorCount'][0])
82 self.errorCount = int(header['nErrorCount'][0])
83
83
84 self.ltc = self.utc
84 self.ltc = self.utc
85
85
86 if self.useLocalTime:
86 if self.useLocalTime:
87 self.ltc -= self.timeZone*60
87 self.ltc -= self.timeZone*60
88
88
89 self.datatime = datetime.datetime.utcfromtimestamp(self.ltc)
89 self.datatime = datetime.datetime.utcfromtimestamp(self.ltc)
90
90
91 except Exception, e:
91 except Exception, e:
92 print "BasicHeader: "
92 print "BasicHeader: "
93 print e
93 print e
94 return 0
94 return 0
95
95
96 return 1
96 return 1
97
97
98 def write(self, fp):
98 def write(self, fp):
99
99
100 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
100 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
101 header = numpy.array(headerTuple,self.struct)
101 header = numpy.array(headerTuple,self.struct)
102 header.tofile(fp)
102 header.tofile(fp)
103
103
104 return 1
104 return 1
105
105
106 class SystemHeader(Header):
106 class SystemHeader(Header):
107
107
108 size = None
108 size = None
109 nSamples = None
109 nSamples = None
110 nProfiles = None
110 nProfiles = None
111 nChannels = None
111 nChannels = None
112 adcResolution = None
112 adcResolution = None
113 pciDioBusWidth = None
113 pciDioBusWidth = None
114 struct = None
114 struct = None
115
115
116 def __init__(self):
116 def __init__(self):
117 self.size = 0
117 self.size = 0
118 self.nSamples = 0
118 self.nSamples = 0
119 self.nProfiles = 0
119 self.nProfiles = 0
120 self.nChannels = 0
120 self.nChannels = 0
121 self.adcResolution = 0
121 self.adcResolution = 0
122 self.pciDioBusWidth = 0
122 self.pciDioBusWidth = 0
123 self.struct = numpy.dtype([
123 self.struct = numpy.dtype([
124 ('nSize','<u4'),
124 ('nSize','<u4'),
125 ('nNumSamples','<u4'),
125 ('nNumSamples','<u4'),
126 ('nNumProfiles','<u4'),
126 ('nNumProfiles','<u4'),
127 ('nNumChannels','<u4'),
127 ('nNumChannels','<u4'),
128 ('nADCResolution','<u4'),
128 ('nADCResolution','<u4'),
129 ('nPCDIOBusWidth','<u4'),
129 ('nPCDIOBusWidth','<u4'),
130 ])
130 ])
131
131
132
132
133 def read(self, fp):
133 def read(self, fp):
134 try:
134 try:
135 header = numpy.fromfile(fp,self.struct,1)
135 header = numpy.fromfile(fp,self.struct,1)
136 self.size = header['nSize'][0]
136 self.size = header['nSize'][0]
137 self.nSamples = header['nNumSamples'][0]
137 self.nSamples = header['nNumSamples'][0]
138 self.nProfiles = header['nNumProfiles'][0]
138 self.nProfiles = header['nNumProfiles'][0]
139 self.nChannels = header['nNumChannels'][0]
139 self.nChannels = header['nNumChannels'][0]
140 self.adcResolution = header['nADCResolution'][0]
140 self.adcResolution = header['nADCResolution'][0]
141 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
141 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
142
142
143 except Exception, e:
143 except Exception, e:
144 print "SystemHeader: " + e
144 print "SystemHeader: " + e
145 return 0
145 return 0
146
146
147 return 1
147 return 1
148
148
149 def write(self, fp):
149 def write(self, fp):
150 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
150 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
151 header = numpy.array(headerTuple,self.struct)
151 header = numpy.array(headerTuple,self.struct)
152 header.tofile(fp)
152 header.tofile(fp)
153
153
154 return 1
154 return 1
155
155
156 class RadarControllerHeader(Header):
156 class RadarControllerHeader(Header):
157
157
158 size = None
158 size = None
159 expType = None
159 expType = None
160 nTx = None
160 nTx = None
161 ipp = None
161 ipp = None
162 txA = None
162 txA = None
163 txB = None
163 txB = None
164 nWindows = None
164 nWindows = None
165 numTaus = None
165 numTaus = None
166 codeType = None
166 codeType = None
167 line6Function = None
167 line6Function = None
168 line5Function = None
168 line5Function = None
169 fClock = None
169 fClock = None
170 prePulseBefore = None
170 prePulseBefore = None
171 prePulserAfter = None
171 prePulserAfter = None
172 rangeIpp = None
172 rangeIpp = None
173 rangeTxA = None
173 rangeTxA = None
174 rangeTxB = None
174 rangeTxB = None
175 struct = None
175 struct = None
176
176
177 def __init__(self):
177 def __init__(self):
178 self.size = 0
178 self.size = 0
179 self.expType = 0
179 self.expType = 0
180 self.nTx = 0
180 self.nTx = 0
181 self.ipp = 0
181 self.ipp = 0
182 self.txA = 0
182 self.txA = 0
183 self.txB = 0
183 self.txB = 0
184 self.nWindows = 0
184 self.nWindows = 0
185 self.numTaus = 0
185 self.numTaus = 0
186 self.codeType = 0
186 self.codeType = 0
187 self.line6Function = 0
187 self.line6Function = 0
188 self.line5Function = 0
188 self.line5Function = 0
189 self.fClock = 0
189 self.fClock = 0
190 self.prePulseBefore = 0
190 self.prePulseBefore = 0
191 self.prePulserAfter = 0
191 self.prePulserAfter = 0
192 self.rangeIpp = 0
192 self.rangeIpp = 0
193 self.rangeTxA = 0
193 self.rangeTxA = 0
194 self.rangeTxB = 0
194 self.rangeTxB = 0
195 self.struct = numpy.dtype([
195 self.struct = numpy.dtype([
196 ('nSize','<u4'),
196 ('nSize','<u4'),
197 ('nExpType','<u4'),
197 ('nExpType','<u4'),
198 ('nNTx','<u4'),
198 ('nNTx','<u4'),
199 ('fIpp','<f4'),
199 ('fIpp','<f4'),
200 ('fTxA','<f4'),
200 ('fTxA','<f4'),
201 ('fTxB','<f4'),
201 ('fTxB','<f4'),
202 ('nNumWindows','<u4'),
202 ('nNumWindows','<u4'),
203 ('nNumTaus','<u4'),
203 ('nNumTaus','<u4'),
204 ('nCodeType','<u4'),
204 ('nCodeType','<u4'),
205 ('nLine6Function','<u4'),
205 ('nLine6Function','<u4'),
206 ('nLine5Function','<u4'),
206 ('nLine5Function','<u4'),
207 ('fClock','<f4'),
207 ('fClock','<f4'),
208 ('nPrePulseBefore','<u4'),
208 ('nPrePulseBefore','<u4'),
209 ('nPrePulseAfter','<u4'),
209 ('nPrePulseAfter','<u4'),
210 ('sRangeIPP','<a20'),
210 ('sRangeIPP','<a20'),
211 ('sRangeTxA','<a20'),
211 ('sRangeTxA','<a20'),
212 ('sRangeTxB','<a20'),
212 ('sRangeTxB','<a20'),
213 ])
213 ])
214
214
215 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
215 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
216
216
217 self.samplingWindow = None
217 self.samplingWindow = None
218 self.nHeights = None
218 self.nHeights = None
219 self.firstHeight = None
219 self.firstHeight = None
220 self.deltaHeight = None
220 self.deltaHeight = None
221 self.samplesWin = None
221 self.samplesWin = None
222
222
223 self.nCode = None
223 self.nCode = None
224 self.nBaud = None
224 self.nBaud = None
225 self.code = None
225 self.code = None
226 self.flip1 = None
226 self.flip1 = None
227 self.flip2 = None
227 self.flip2 = None
228
228
229 self.dynamic = numpy.array([],numpy.dtype('byte'))
229 self.dynamic = numpy.array([],numpy.dtype('byte'))
230
230
231
231
232 def read(self, fp):
232 def read(self, fp):
233 try:
233 try:
234 startFp = fp.tell()
234 startFp = fp.tell()
235 header = numpy.fromfile(fp,self.struct,1)
235 header = numpy.fromfile(fp,self.struct,1)
236 self.size = int(header['nSize'][0])
236 self.size = int(header['nSize'][0])
237 self.expType = int(header['nExpType'][0])
237 self.expType = int(header['nExpType'][0])
238 self.nTx = int(header['nNTx'][0])
238 self.nTx = int(header['nNTx'][0])
239 self.ipp = float(header['fIpp'][0])
239 self.ipp = float(header['fIpp'][0])
240 self.txA = float(header['fTxA'][0])
240 self.txA = float(header['fTxA'][0])
241 self.txB = float(header['fTxB'][0])
241 self.txB = float(header['fTxB'][0])
242 self.nWindows = int(header['nNumWindows'][0])
242 self.nWindows = int(header['nNumWindows'][0])
243 self.numTaus = int(header['nNumTaus'][0])
243 self.numTaus = int(header['nNumTaus'][0])
244 self.codeType = int(header['nCodeType'][0])
244 self.codeType = int(header['nCodeType'][0])
245 self.line6Function = int(header['nLine6Function'][0])
245 self.line6Function = int(header['nLine6Function'][0])
246 self.line5Function = int(header['nLine5Function'][0])
246 self.line5Function = int(header['nLine5Function'][0])
247 self.fClock = float(header['fClock'][0])
247 self.fClock = float(header['fClock'][0])
248 self.prePulseBefore = int(header['nPrePulseBefore'][0])
248 self.prePulseBefore = int(header['nPrePulseBefore'][0])
249 self.prePulserAfter = int(header['nPrePulseAfter'][0])
249 self.prePulserAfter = int(header['nPrePulseAfter'][0])
250 self.rangeIpp = header['sRangeIPP'][0]
250 self.rangeIpp = header['sRangeIPP'][0]
251 self.rangeTxA = header['sRangeTxA'][0]
251 self.rangeTxA = header['sRangeTxA'][0]
252 self.rangeTxB = header['sRangeTxB'][0]
252 self.rangeTxB = header['sRangeTxB'][0]
253 # jump Dynamic Radar Controller Header
253 # jump Dynamic Radar Controller Header
254 jumpFp = self.size - 116
254 jumpFp = self.size - 116
255 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
255 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
256 #pointer backward to dynamic header and read
256 #pointer backward to dynamic header and read
257 backFp = fp.tell() - jumpFp
257 backFp = fp.tell() - jumpFp
258 fp.seek(backFp)
258 fp.seek(backFp)
259
259
260 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
260 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
261 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
261 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
262 self.firstHeight = self.samplingWindow['h0']
262 self.firstHeight = self.samplingWindow['h0']
263 self.deltaHeight = self.samplingWindow['dh']
263 self.deltaHeight = self.samplingWindow['dh']
264 self.samplesWin = self.samplingWindow['nsa']
264 self.samplesWin = self.samplingWindow['nsa']
265
265
266 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
266 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
267
267
268 if self.codeType != 0:
268 if self.codeType != 0:
269 self.nCode = int(numpy.fromfile(fp,'<u4',1))
269 self.nCode = int(numpy.fromfile(fp,'<u4',1))
270 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
270 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
271 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
271 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
272 tempList = []
272 tempList = []
273 for ic in range(self.nCode):
273 for ic in range(self.nCode):
274 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
274 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
275 tempList.append(temp)
275 tempList.append(temp)
276 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
276 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
277 self.code = 2.0*self.code - 1.0
277 self.code = 2.0*self.code - 1.0
278
278
279 if self.line5Function == RCfunction.FLIP:
279 if self.line5Function == RCfunction.FLIP:
280 self.flip1 = numpy.fromfile(fp,'<u4',1)
280 self.flip1 = numpy.fromfile(fp,'<u4',1)
281
281
282 if self.line6Function == RCfunction.FLIP:
282 if self.line6Function == RCfunction.FLIP:
283 self.flip2 = numpy.fromfile(fp,'<u4',1)
283 self.flip2 = numpy.fromfile(fp,'<u4',1)
284
284
285 endFp = self.size + startFp
285 endFp = self.size + startFp
286 jumpFp = endFp - fp.tell()
286 jumpFp = endFp - fp.tell()
287 if jumpFp > 0:
287 if jumpFp > 0:
288 fp.seek(jumpFp)
288 fp.seek(jumpFp)
289
289
290 except Exception, e:
290 except Exception, e:
291 print "RadarControllerHeader: " + e
291 print "RadarControllerHeader: " + e
292 return 0
292 return 0
293
293
294 return 1
294 return 1
295
295
296 def write(self, fp):
296 def write(self, fp):
297 headerTuple = (self.size,
297 headerTuple = (self.size,
298 self.expType,
298 self.expType,
299 self.nTx,
299 self.nTx,
300 self.ipp,
300 self.ipp,
301 self.txA,
301 self.txA,
302 self.txB,
302 self.txB,
303 self.nWindows,
303 self.nWindows,
304 self.numTaus,
304 self.numTaus,
305 self.codeType,
305 self.codeType,
306 self.line6Function,
306 self.line6Function,
307 self.line5Function,
307 self.line5Function,
308 self.fClock,
308 self.fClock,
309 self.prePulseBefore,
309 self.prePulseBefore,
310 self.prePulserAfter,
310 self.prePulserAfter,
311 self.rangeIpp,
311 self.rangeIpp,
312 self.rangeTxA,
312 self.rangeTxA,
313 self.rangeTxB)
313 self.rangeTxB)
314
314
315 header = numpy.array(headerTuple,self.struct)
315 header = numpy.array(headerTuple,self.struct)
316 header.tofile(fp)
316 header.tofile(fp)
317
317
318 dynamic = self.dynamic
318 dynamic = self.dynamic
319 dynamic.tofile(fp)
319 dynamic.tofile(fp)
320
320
321 return 1
321 return 1
322
322
323
323
324
324
325 class ProcessingHeader(Header):
325 class ProcessingHeader(Header):
326
326
327 size = None
327 size = None
328 dtype = None
328 dtype = None
329 blockSize = None
329 blockSize = None
330 profilesPerBlock = None
330 profilesPerBlock = None
331 dataBlocksPerFile = None
331 dataBlocksPerFile = None
332 nWindows = None
332 nWindows = None
333 processFlags = None
333 processFlags = None
334 nCohInt = None
334 nCohInt = None
335 nIncohInt = None
335 nIncohInt = None
336 totalSpectra = None
336 totalSpectra = None
337 struct = None
337 struct = None
338 flag_dc = None
338 flag_dc = None
339 flag_cspc = None
339 flag_cspc = None
340
340
341 def __init__(self):
341 def __init__(self):
342 self.size = 0
342 self.size = 0
343 self.dtype = 0
343 self.dtype = 0
344 self.blockSize = 0
344 self.blockSize = 0
345 self.profilesPerBlock = 0
345 self.profilesPerBlock = 0
346 self.dataBlocksPerFile = 0
346 self.dataBlocksPerFile = 0
347 self.nWindows = 0
347 self.nWindows = 0
348 self.processFlags = 0
348 self.processFlags = 0
349 self.nCohInt = 0
349 self.nCohInt = 0
350 self.nIncohInt = 0
350 self.nIncohInt = 0
351 self.totalSpectra = 0
351 self.totalSpectra = 0
352 self.struct = numpy.dtype([
352 self.struct = numpy.dtype([
353 ('nSize','<u4'),
353 ('nSize','<u4'),
354 ('nDataType','<u4'),
354 ('nDataType','<u4'),
355 ('nSizeOfDataBlock','<u4'),
355 ('nSizeOfDataBlock','<u4'),
356 ('nProfilesperBlock','<u4'),
356 ('nProfilesperBlock','<u4'),
357 ('nDataBlocksperFile','<u4'),
357 ('nDataBlocksperFile','<u4'),
358 ('nNumWindows','<u4'),
358 ('nNumWindows','<u4'),
359 ('nProcessFlags','<u4'),
359 ('nProcessFlags','<u4'),
360 ('nCoherentIntegrations','<u4'),
360 ('nCoherentIntegrations','<u4'),
361 ('nIncoherentIntegrations','<u4'),
361 ('nIncoherentIntegrations','<u4'),
362 ('nTotalSpectra','<u4')
362 ('nTotalSpectra','<u4')
363 ])
363 ])
364 self.samplingWindow = 0
364 self.samplingWindow = 0
365 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
365 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
366 self.nHeights = 0
366 self.nHeights = 0
367 self.firstHeight = 0
367 self.firstHeight = 0
368 self.deltaHeight = 0
368 self.deltaHeight = 0
369 self.samplesWin = 0
369 self.samplesWin = 0
370 self.spectraComb = 0
370 self.spectraComb = 0
371 self.nCode = None
371 self.nCode = None
372 self.code = None
372 self.code = None
373 self.nBaud = None
373 self.nBaud = None
374 self.shif_fft = False
374 self.shif_fft = False
375 self.flag_dc = False
375 self.flag_dc = False
376 self.flag_cspc = False
376 self.flag_cspc = False
377
377
378 def read(self, fp):
378 def read(self, fp):
379 try:
379 # try:
380 header = numpy.fromfile(fp,self.struct,1)
380 header = numpy.fromfile(fp,self.struct,1)
381 self.size = int(header['nSize'][0])
381 self.size = int(header['nSize'][0])
382 self.dtype = int(header['nDataType'][0])
382 self.dtype = int(header['nDataType'][0])
383 self.blockSize = int(header['nSizeOfDataBlock'][0])
383 self.blockSize = int(header['nSizeOfDataBlock'][0])
384 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
384 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
385 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
385 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
386 self.nWindows = int(header['nNumWindows'][0])
386 self.nWindows = int(header['nNumWindows'][0])
387 self.processFlags = header['nProcessFlags']
387 self.processFlags = header['nProcessFlags']
388 self.nCohInt = int(header['nCoherentIntegrations'][0])
388 self.nCohInt = int(header['nCoherentIntegrations'][0])
389 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
389 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
390 self.totalSpectra = int(header['nTotalSpectra'][0])
390 self.totalSpectra = int(header['nTotalSpectra'][0])
391 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
391 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
392 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
392 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
393 self.firstHeight = float(self.samplingWindow['h0'][0])
393 self.firstHeight = float(self.samplingWindow['h0'][0])
394 self.deltaHeight = float(self.samplingWindow['dh'][0])
394 self.deltaHeight = float(self.samplingWindow['dh'][0])
395 self.samplesWin = self.samplingWindow['nsa']
395 self.samplesWin = self.samplingWindow['nsa']
396 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
396 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
397
397
398 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
398 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
399 self.nCode = int(numpy.fromfile(fp,'<u4',1))
399 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
400 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
400 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
401 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
401 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
402
403 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
404 self.shif_fft = True
405 else:
406 self.shif_fft = False
402
407
403 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
408 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
404 self.shif_fft = True
409 self.flag_dc = True
410
411 nChannels = 0
412 nPairs = 0
413 pairList = []
414
415 for i in range( 0, self.totalSpectra*2, 2 ):
416 if self.spectraComb[i] == self.spectraComb[i+1]:
417 nChannels = nChannels + 1 #par de canales iguales
405 else:
418 else:
406 self.shif_fft = False
419 nPairs = nPairs + 1 #par de canales diferentes
407
420 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
408 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
421
409 self.flag_dc = True
422 self.flag_cspc = False
410
423 if nPairs > 0:
411 nChannels = 0
424 self.flag_cspc = True
412 nPairs = 0
413 pairList = []
414
415 for i in range( 0, self.totalSpectra*2, 2 ):
416 if self.spectraComb[i] == self.spectraComb[i+1]:
417 nChannels = nChannels + 1 #par de canales iguales
418 else:
419 nPairs = nPairs + 1 #par de canales diferentes
420 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
421
422 self.flag_cspc = False
423 if nPairs > 0:
424 self.flag_cspc = True
425
425
426 except Exception, e:
426 # except Exception, e:
427 print "ProcessingHeader: " + e
427 # print "Error ProcessingHeader: "
428 return 0
428 # return 0
429
429
430 return 1
430 return 1
431
431
432 def write(self, fp):
432 def write(self, fp):
433 headerTuple = (self.size,
433 headerTuple = (self.size,
434 self.dtype,
434 self.dtype,
435 self.blockSize,
435 self.blockSize,
436 self.profilesPerBlock,
436 self.profilesPerBlock,
437 self.dataBlocksPerFile,
437 self.dataBlocksPerFile,
438 self.nWindows,
438 self.nWindows,
439 self.processFlags,
439 self.processFlags,
440 self.nCohInt,
440 self.nCohInt,
441 self.nIncohInt,
441 self.nIncohInt,
442 self.totalSpectra)
442 self.totalSpectra)
443
443
444 header = numpy.array(headerTuple,self.struct)
444 header = numpy.array(headerTuple,self.struct)
445 header.tofile(fp)
445 header.tofile(fp)
446
446
447 if self.nWindows != 0:
447 if self.nWindows != 0:
448 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
448 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
449 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
449 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
450 samplingWindow.tofile(fp)
450 samplingWindow.tofile(fp)
451
451
452
452
453 if self.totalSpectra != 0:
453 if self.totalSpectra != 0:
454 spectraComb = numpy.array([],numpy.dtype('u1'))
454 spectraComb = numpy.array([],numpy.dtype('u1'))
455 spectraComb = self.spectraComb
455 spectraComb = self.spectraComb
456 spectraComb.tofile(fp)
456 spectraComb.tofile(fp)
457
457
458 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
458 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
459 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
459 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
460 # nCode.tofile(fp)
460 # nCode.tofile(fp)
461 #
461 #
462 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
462 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
463 # nBaud.tofile(fp)
463 # nBaud.tofile(fp)
464 #
464 #
465 # code = self.code.reshape(self.nCode*self.nBaud)
465 # code = self.code.reshape(self.nCode*self.nBaud)
466 # code = code.astype(numpy.dtype('<f4'))
466 # code = code.astype(numpy.dtype('<f4'))
467 # code.tofile(fp)
467 # code.tofile(fp)
468
468
469 return 1
469 return 1
470
470
471 class RCfunction:
471 class RCfunction:
472 NONE=0
472 NONE=0
473 FLIP=1
473 FLIP=1
474 CODE=2
474 CODE=2
475 SAMPLING=3
475 SAMPLING=3
476 LIN6DIV256=4
476 LIN6DIV256=4
477 SYNCHRO=5
477 SYNCHRO=5
478
478
479 class nCodeType:
479 class nCodeType:
480 NONE=0
480 NONE=0
481 USERDEFINE=1
481 USERDEFINE=1
482 BARKER2=2
482 BARKER2=2
483 BARKER3=3
483 BARKER3=3
484 BARKER4=4
484 BARKER4=4
485 BARKER5=5
485 BARKER5=5
486 BARKER7=6
486 BARKER7=6
487 BARKER11=7
487 BARKER11=7
488 BARKER13=8
488 BARKER13=8
489 AC128=9
489 AC128=9
490 COMPLEMENTARYCODE2=10
490 COMPLEMENTARYCODE2=10
491 COMPLEMENTARYCODE4=11
491 COMPLEMENTARYCODE4=11
492 COMPLEMENTARYCODE8=12
492 COMPLEMENTARYCODE8=12
493 COMPLEMENTARYCODE16=13
493 COMPLEMENTARYCODE16=13
494 COMPLEMENTARYCODE32=14
494 COMPLEMENTARYCODE32=14
495 COMPLEMENTARYCODE64=15
495 COMPLEMENTARYCODE64=15
496 COMPLEMENTARYCODE128=16
496 COMPLEMENTARYCODE128=16
497 CODE_BINARY28=17
497 CODE_BINARY28=17
498
498
499 class PROCFLAG:
499 class PROCFLAG:
500 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
500 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
501 DECODE_DATA = numpy.uint32(0x00000002)
501 DECODE_DATA = numpy.uint32(0x00000002)
502 SPECTRA_CALC = numpy.uint32(0x00000004)
502 SPECTRA_CALC = numpy.uint32(0x00000004)
503 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
503 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
504 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
504 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
505 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
505 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
506
506
507 DATATYPE_CHAR = numpy.uint32(0x00000040)
507 DATATYPE_CHAR = numpy.uint32(0x00000040)
508 DATATYPE_SHORT = numpy.uint32(0x00000080)
508 DATATYPE_SHORT = numpy.uint32(0x00000080)
509 DATATYPE_LONG = numpy.uint32(0x00000100)
509 DATATYPE_LONG = numpy.uint32(0x00000100)
510 DATATYPE_INT64 = numpy.uint32(0x00000200)
510 DATATYPE_INT64 = numpy.uint32(0x00000200)
511 DATATYPE_FLOAT = numpy.uint32(0x00000400)
511 DATATYPE_FLOAT = numpy.uint32(0x00000400)
512 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
512 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
513
513
514 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
514 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
515 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
515 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
516 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
516 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
517
517
518 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
518 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
519 DEFLIP_DATA = numpy.uint32(0x00010000)
519 DEFLIP_DATA = numpy.uint32(0x00010000)
520 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
520 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
521
521
522 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
522 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
523 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
523 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
524 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
524 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
525 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
525 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
526 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
526 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
527
527
528 EXP_NAME_ESP = numpy.uint32(0x00200000)
528 EXP_NAME_ESP = numpy.uint32(0x00200000)
529 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
529 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
530
530
531 OPERATION_MASK = numpy.uint32(0x0000003F)
531 OPERATION_MASK = numpy.uint32(0x0000003F)
532 DATATYPE_MASK = numpy.uint32(0x00000FC0)
532 DATATYPE_MASK = numpy.uint32(0x00000FC0)
533 DATAARRANGE_MASK = numpy.uint32(0x00007000)
533 DATAARRANGE_MASK = numpy.uint32(0x00007000)
534 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
534 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,1355 +1,1363
1 import numpy
1 import numpy
2 import time, datetime, os
2 import time, datetime, os
3 from graphics.figure import *
3 from graphics.figure import *
4 def isRealtime(utcdatatime):
4 def isRealtime(utcdatatime):
5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
6 delta = utcnow - utcdatatime # abs
6 delta = utcnow - utcdatatime # abs
7 if delta >= 5*60.:
7 if delta >= 5*60.:
8 return False
8 return False
9 return True
9 return True
10
10
11 class CrossSpectraPlot(Figure):
11 class CrossSpectraPlot(Figure):
12
12
13 __isConfig = None
13 __isConfig = None
14 __nsubplots = None
14 __nsubplots = None
15
15
16 WIDTH = None
16 WIDTH = None
17 HEIGHT = None
17 HEIGHT = None
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'cspc'
20 PREFIX = 'cspc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.__isConfig = False
24 self.__isConfig = False
25 self.__nsubplots = 4
25 self.__nsubplots = 4
26
26
27 self.WIDTH = 250
27 self.WIDTH = 250
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 0
29 self.WIDTHPROF = 0
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31
31
32 def getSubplots(self):
32 def getSubplots(self):
33
33
34 ncol = 4
34 ncol = 4
35 nrow = self.nplots
35 nrow = self.nplots
36
36
37 return nrow, ncol
37 return nrow, ncol
38
38
39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
40
40
41 self.__showprofile = showprofile
41 self.__showprofile = showprofile
42 self.nplots = nplots
42 self.nplots = nplots
43
43
44 ncolspan = 1
44 ncolspan = 1
45 colspan = 1
45 colspan = 1
46
46
47 self.createFigure(idfigure = idfigure,
47 self.createFigure(idfigure = idfigure,
48 wintitle = wintitle,
48 wintitle = wintitle,
49 widthplot = self.WIDTH + self.WIDTHPROF,
49 widthplot = self.WIDTH + self.WIDTHPROF,
50 heightplot = self.HEIGHT + self.HEIGHTPROF,
50 heightplot = self.HEIGHT + self.HEIGHTPROF,
51 show=True)
51 show=True)
52
52
53 nrow, ncol = self.getSubplots()
53 nrow, ncol = self.getSubplots()
54
54
55 counter = 0
55 counter = 0
56 for y in range(nrow):
56 for y in range(nrow):
57 for x in range(ncol):
57 for x in range(ncol):
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
59
59
60 counter += 1
60 counter += 1
61
61
62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
64 save=False, figpath='./', figfile=None,
64 save=False, figpath='./', figfile=None,
65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
66
66
67 """
67 """
68
68
69 Input:
69 Input:
70 dataOut :
70 dataOut :
71 idfigure :
71 idfigure :
72 wintitle :
72 wintitle :
73 channelList :
73 channelList :
74 showProfile :
74 showProfile :
75 xmin : None,
75 xmin : None,
76 xmax : None,
76 xmax : None,
77 ymin : None,
77 ymin : None,
78 ymax : None,
78 ymax : None,
79 zmin : None,
79 zmin : None,
80 zmax : None
80 zmax : None
81 """
81 """
82
82
83 if pairsList == None:
83 if pairsList == None:
84 pairsIndexList = dataOut.pairsIndexList
84 pairsIndexList = dataOut.pairsIndexList
85 else:
85 else:
86 pairsIndexList = []
86 pairsIndexList = []
87 for pair in pairsList:
87 for pair in pairsList:
88 if pair not in dataOut.pairsList:
88 if pair not in dataOut.pairsList:
89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
90 pairsIndexList.append(dataOut.pairsList.index(pair))
90 pairsIndexList.append(dataOut.pairsList.index(pair))
91
91
92 if pairsIndexList == []:
92 if pairsIndexList == []:
93 return
93 return
94
94
95 if len(pairsIndexList) > 4:
95 if len(pairsIndexList) > 4:
96 pairsIndexList = pairsIndexList[0:4]
96 pairsIndexList = pairsIndexList[0:4]
97 factor = dataOut.normFactor
97 factor = dataOut.normFactor
98 x = dataOut.getVelRange(1)
98 x = dataOut.getVelRange(1)
99 y = dataOut.getHeiRange()
99 y = dataOut.getHeiRange()
100 z = dataOut.data_spc[:,:,:]/factor
100 z = dataOut.data_spc[:,:,:]/factor
101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
102 avg = numpy.abs(numpy.average(z, axis=1))
102 avg = numpy.abs(numpy.average(z, axis=1))
103 noise = dataOut.getNoise()/factor
103 noise = dataOut.getNoise()/factor
104
104
105 zdB = 10*numpy.log10(z)
105 zdB = 10*numpy.log10(z)
106 avgdB = 10*numpy.log10(avg)
106 avgdB = 10*numpy.log10(avg)
107 noisedB = 10*numpy.log10(noise)
107 noisedB = 10*numpy.log10(noise)
108
108
109
109
110 thisDatetime = dataOut.datatime
110 #thisDatetime = dataOut.datatime
111 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
111 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
112 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
112 xlabel = "Velocity (m/s)"
113 xlabel = "Velocity (m/s)"
113 ylabel = "Range (Km)"
114 ylabel = "Range (Km)"
114
115
115 if not self.__isConfig:
116 if not self.__isConfig:
116
117
117 nplots = len(pairsIndexList)
118 nplots = len(pairsIndexList)
118
119
119 self.setup(idfigure=idfigure,
120 self.setup(idfigure=idfigure,
120 nplots=nplots,
121 nplots=nplots,
121 wintitle=wintitle,
122 wintitle=wintitle,
122 showprofile=showprofile,
123 showprofile=showprofile,
123 show=show)
124 show=show)
124
125
125 if xmin == None: xmin = numpy.nanmin(x)
126 if xmin == None: xmin = numpy.nanmin(x)
126 if xmax == None: xmax = numpy.nanmax(x)
127 if xmax == None: xmax = numpy.nanmax(x)
127 if ymin == None: ymin = numpy.nanmin(y)
128 if ymin == None: ymin = numpy.nanmin(y)
128 if ymax == None: ymax = numpy.nanmax(y)
129 if ymax == None: ymax = numpy.nanmax(y)
129 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
130 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
130 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
131 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
131
132
132 self.__isConfig = True
133 self.__isConfig = True
133
134
134 self.setWinTitle(title)
135 self.setWinTitle(title)
135
136
136 for i in range(self.nplots):
137 for i in range(self.nplots):
137 pair = dataOut.pairsList[pairsIndexList[i]]
138 pair = dataOut.pairsList[pairsIndexList[i]]
138
139
139 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
140 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
141 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
141 axes0 = self.axesList[i*self.__nsubplots]
142 axes0 = self.axesList[i*self.__nsubplots]
142 axes0.pcolor(x, y, zdB,
143 axes0.pcolor(x, y, zdB,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
144 xlabel=xlabel, ylabel=ylabel, title=title,
145 xlabel=xlabel, ylabel=ylabel, title=title,
145 ticksize=9, colormap=power_cmap, cblabel='')
146 ticksize=9, colormap=power_cmap, cblabel='')
146
147
147 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
148 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
148 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
149 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
149 axes0 = self.axesList[i*self.__nsubplots+1]
150 axes0 = self.axesList[i*self.__nsubplots+1]
150 axes0.pcolor(x, y, zdB,
151 axes0.pcolor(x, y, zdB,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
152 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
152 xlabel=xlabel, ylabel=ylabel, title=title,
153 xlabel=xlabel, ylabel=ylabel, title=title,
153 ticksize=9, colormap=power_cmap, cblabel='')
154 ticksize=9, colormap=power_cmap, cblabel='')
154
155
155 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
156 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
156 coherence = numpy.abs(coherenceComplex)
157 coherence = numpy.abs(coherenceComplex)
157 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
158 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
158 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
159 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
159
160
160 title = "Coherence %d%d" %(pair[0], pair[1])
161 title = "Coherence %d%d" %(pair[0], pair[1])
161 axes0 = self.axesList[i*self.__nsubplots+2]
162 axes0 = self.axesList[i*self.__nsubplots+2]
162 axes0.pcolor(x, y, coherence,
163 axes0.pcolor(x, y, coherence,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
164 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
164 xlabel=xlabel, ylabel=ylabel, title=title,
165 xlabel=xlabel, ylabel=ylabel, title=title,
165 ticksize=9, colormap=coherence_cmap, cblabel='')
166 ticksize=9, colormap=coherence_cmap, cblabel='')
166
167
167 title = "Phase %d%d" %(pair[0], pair[1])
168 title = "Phase %d%d" %(pair[0], pair[1])
168 axes0 = self.axesList[i*self.__nsubplots+3]
169 axes0 = self.axesList[i*self.__nsubplots+3]
169 axes0.pcolor(x, y, phase,
170 axes0.pcolor(x, y, phase,
170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
171 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
171 xlabel=xlabel, ylabel=ylabel, title=title,
172 xlabel=xlabel, ylabel=ylabel, title=title,
172 ticksize=9, colormap=phase_cmap, cblabel='')
173 ticksize=9, colormap=phase_cmap, cblabel='')
173
174
174
175
175
176
176 self.draw()
177 self.draw()
177
178
178 if save:
179 if save:
179 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
180 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
180 if figfile == None:
181 if figfile == None:
181 figfile = self.getFilename(name = date)
182 figfile = self.getFilename(name = date)
182
183
183 self.saveFigure(figpath, figfile)
184 self.saveFigure(figpath, figfile)
184
185
185
186
186 class RTIPlot(Figure):
187 class RTIPlot(Figure):
187
188
188 __isConfig = None
189 __isConfig = None
189 __nsubplots = None
190 __nsubplots = None
190
191
191 WIDTHPROF = None
192 WIDTHPROF = None
192 HEIGHTPROF = None
193 HEIGHTPROF = None
193 PREFIX = 'rti'
194 PREFIX = 'rti'
194
195
195 def __init__(self):
196 def __init__(self):
196
197
197 self.timerange = 2*60*60
198 self.timerange = 2*60*60
198 self.__isConfig = False
199 self.__isConfig = False
199 self.__nsubplots = 1
200 self.__nsubplots = 1
200
201
201 self.WIDTH = 800
202 self.WIDTH = 800
202 self.HEIGHT = 150
203 self.HEIGHT = 150
203 self.WIDTHPROF = 120
204 self.WIDTHPROF = 120
204 self.HEIGHTPROF = 0
205 self.HEIGHTPROF = 0
205 self.counterftp = 0
206 self.counterftp = 0
206
207
207 def getSubplots(self):
208 def getSubplots(self):
208
209
209 ncol = 1
210 ncol = 1
210 nrow = self.nplots
211 nrow = self.nplots
211
212
212 return nrow, ncol
213 return nrow, ncol
213
214
214 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
215 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
215
216
216 self.__showprofile = showprofile
217 self.__showprofile = showprofile
217 self.nplots = nplots
218 self.nplots = nplots
218
219
219 ncolspan = 1
220 ncolspan = 1
220 colspan = 1
221 colspan = 1
221 if showprofile:
222 if showprofile:
222 ncolspan = 7
223 ncolspan = 7
223 colspan = 6
224 colspan = 6
224 self.__nsubplots = 2
225 self.__nsubplots = 2
225
226
226 self.createFigure(idfigure = idfigure,
227 self.createFigure(idfigure = idfigure,
227 wintitle = wintitle,
228 wintitle = wintitle,
228 widthplot = self.WIDTH + self.WIDTHPROF,
229 widthplot = self.WIDTH + self.WIDTHPROF,
229 heightplot = self.HEIGHT + self.HEIGHTPROF,
230 heightplot = self.HEIGHT + self.HEIGHTPROF,
230 show=show)
231 show=show)
231
232
232 nrow, ncol = self.getSubplots()
233 nrow, ncol = self.getSubplots()
233
234
234 counter = 0
235 counter = 0
235 for y in range(nrow):
236 for y in range(nrow):
236 for x in range(ncol):
237 for x in range(ncol):
237
238
238 if counter >= self.nplots:
239 if counter >= self.nplots:
239 break
240 break
240
241
241 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
242 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
242
243
243 if showprofile:
244 if showprofile:
244 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
245 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
245
246
246 counter += 1
247 counter += 1
247
248
248 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
249 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
249 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
250 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
250 timerange=None,
251 timerange=None,
251 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
252 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
252
253
253 """
254 """
254
255
255 Input:
256 Input:
256 dataOut :
257 dataOut :
257 idfigure :
258 idfigure :
258 wintitle :
259 wintitle :
259 channelList :
260 channelList :
260 showProfile :
261 showProfile :
261 xmin : None,
262 xmin : None,
262 xmax : None,
263 xmax : None,
263 ymin : None,
264 ymin : None,
264 ymax : None,
265 ymax : None,
265 zmin : None,
266 zmin : None,
266 zmax : None
267 zmax : None
267 """
268 """
268
269
269 if channelList == None:
270 if channelList == None:
270 channelIndexList = dataOut.channelIndexList
271 channelIndexList = dataOut.channelIndexList
271 else:
272 else:
272 channelIndexList = []
273 channelIndexList = []
273 for channel in channelList:
274 for channel in channelList:
274 if channel not in dataOut.channelList:
275 if channel not in dataOut.channelList:
275 raise ValueError, "Channel %d is not in dataOut.channelList"
276 raise ValueError, "Channel %d is not in dataOut.channelList"
276 channelIndexList.append(dataOut.channelList.index(channel))
277 channelIndexList.append(dataOut.channelList.index(channel))
277
278
278 if timerange != None:
279 if timerange != None:
279 self.timerange = timerange
280 self.timerange = timerange
280
281
281 tmin = None
282 tmin = None
282 tmax = None
283 tmax = None
283 factor = dataOut.normFactor
284 factor = dataOut.normFactor
284 x = dataOut.getTimeRange()
285 x = dataOut.getTimeRange()
285 y = dataOut.getHeiRange()
286 y = dataOut.getHeiRange()
286
287
287 z = dataOut.data_spc[channelIndexList,:,:]/factor
288 z = dataOut.data_spc[channelIndexList,:,:]/factor
288 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
289 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
289 avg = numpy.average(z, axis=1)
290 avg = numpy.average(z, axis=1)
290
291
291 avgdB = 10.*numpy.log10(avg)
292 avgdB = 10.*numpy.log10(avg)
292
293
293
294
294 # thisDatetime = dataOut.datatime
295 # thisDatetime = dataOut.datatime
295 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
296 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
296 title = wintitle+' ' + "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
297 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
297 xlabel = ""
298 xlabel = ""
298 ylabel = "Range (Km)"
299 ylabel = "Range (Km)"
299
300
300 if not self.__isConfig:
301 if not self.__isConfig:
301
302
302 nplots = len(channelIndexList)
303 nplots = len(channelIndexList)
303
304
304 self.setup(idfigure=idfigure,
305 self.setup(idfigure=idfigure,
305 nplots=nplots,
306 nplots=nplots,
306 wintitle=wintitle,
307 wintitle=wintitle,
307 showprofile=showprofile,
308 showprofile=showprofile,
308 show=show)
309 show=show)
309
310
310 tmin, tmax = self.getTimeLim(x, xmin, xmax)
311 tmin, tmax = self.getTimeLim(x, xmin, xmax)
311 if ymin == None: ymin = numpy.nanmin(y)
312 if ymin == None: ymin = numpy.nanmin(y)
312 if ymax == None: ymax = numpy.nanmax(y)
313 if ymax == None: ymax = numpy.nanmax(y)
313 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
314 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
314 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
315 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
315
316
316 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
317 self.__isConfig = True
318 self.__isConfig = True
318
319
319
320
320 self.setWinTitle(title)
321 self.setWinTitle(title)
321
322
322 for i in range(self.nplots):
323 for i in range(self.nplots):
323 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
324 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
324 axes = self.axesList[i*self.__nsubplots]
325 axes = self.axesList[i*self.__nsubplots]
325 zdB = avgdB[i].reshape((1,-1))
326 zdB = avgdB[i].reshape((1,-1))
326 axes.pcolorbuffer(x, y, zdB,
327 axes.pcolorbuffer(x, y, zdB,
327 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
328 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
328 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
329 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
329 ticksize=9, cblabel='', cbsize="1%")
330 ticksize=9, cblabel='', cbsize="1%")
330
331
331 if self.__showprofile:
332 if self.__showprofile:
332 axes = self.axesList[i*self.__nsubplots +1]
333 axes = self.axesList[i*self.__nsubplots +1]
333 axes.pline(avgdB[i], y,
334 axes.pline(avgdB[i], y,
334 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
335 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
335 xlabel='dB', ylabel='', title='',
336 xlabel='dB', ylabel='', title='',
336 ytick_visible=False,
337 ytick_visible=False,
337 grid='x')
338 grid='x')
338
339
339 self.draw()
340 self.draw()
340
341
341 if save:
342 if save:
342
343
343 if figfile == None:
344 if figfile == None:
344 figfile = self.getFilename(name = self.name)
345 figfile = self.getFilename(name = self.name)
345
346
346 self.saveFigure(figpath, figfile)
347 self.saveFigure(figpath, figfile)
347
348
348 self.counterftp += 1
349 self.counterftp += 1
349 if (ftp and (self.counterftp==ftpratio)):
350 if (ftp and (self.counterftp==ftpratio)):
350 figfilename = os.path.join(figpath,figfile)
351 figfilename = os.path.join(figpath,figfile)
351 self.sendByFTP(figfilename)
352 self.sendByFTP(figfilename)
352 self.counterftp = 0
353 self.counterftp = 0
353
354
354 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
355 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
355 self.__isConfig = False
356 self.__isConfig = False
356
357
357 class SpectraPlot(Figure):
358 class SpectraPlot(Figure):
358
359
359 __isConfig = None
360 __isConfig = None
360 __nsubplots = None
361 __nsubplots = None
361
362
362 WIDTHPROF = None
363 WIDTHPROF = None
363 HEIGHTPROF = None
364 HEIGHTPROF = None
364 PREFIX = 'spc'
365 PREFIX = 'spc'
365
366
366 def __init__(self):
367 def __init__(self):
367
368
368 self.__isConfig = False
369 self.__isConfig = False
369 self.__nsubplots = 1
370 self.__nsubplots = 1
370
371
371 self.WIDTH = 230
372 self.WIDTH = 230
372 self.HEIGHT = 250
373 self.HEIGHT = 250
373 self.WIDTHPROF = 120
374 self.WIDTHPROF = 120
374 self.HEIGHTPROF = 0
375 self.HEIGHTPROF = 0
375
376
376 def getSubplots(self):
377 def getSubplots(self):
377
378
378 ncol = int(numpy.sqrt(self.nplots)+0.9)
379 ncol = int(numpy.sqrt(self.nplots)+0.9)
379 nrow = int(self.nplots*1./ncol + 0.9)
380 nrow = int(self.nplots*1./ncol + 0.9)
380
381
381 return nrow, ncol
382 return nrow, ncol
382
383
383 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
384 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
384
385
385 self.__showprofile = showprofile
386 self.__showprofile = showprofile
386 self.nplots = nplots
387 self.nplots = nplots
387
388
388 ncolspan = 1
389 ncolspan = 1
389 colspan = 1
390 colspan = 1
390 if showprofile:
391 if showprofile:
391 ncolspan = 3
392 ncolspan = 3
392 colspan = 2
393 colspan = 2
393 self.__nsubplots = 2
394 self.__nsubplots = 2
394
395
395 self.createFigure(idfigure = idfigure,
396 self.createFigure(idfigure = idfigure,
396 wintitle = wintitle,
397 wintitle = wintitle,
397 widthplot = self.WIDTH + self.WIDTHPROF,
398 widthplot = self.WIDTH + self.WIDTHPROF,
398 heightplot = self.HEIGHT + self.HEIGHTPROF,
399 heightplot = self.HEIGHT + self.HEIGHTPROF,
399 show=show)
400 show=show)
400
401
401 nrow, ncol = self.getSubplots()
402 nrow, ncol = self.getSubplots()
402
403
403 counter = 0
404 counter = 0
404 for y in range(nrow):
405 for y in range(nrow):
405 for x in range(ncol):
406 for x in range(ncol):
406
407
407 if counter >= self.nplots:
408 if counter >= self.nplots:
408 break
409 break
409
410
410 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
411 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
411
412
412 if showprofile:
413 if showprofile:
413 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
414 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
414
415
415 counter += 1
416 counter += 1
416
417
417 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
418 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
418 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
419 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
419 save=False, figpath='./', figfile=None, show=True):
420 save=False, figpath='./', figfile=None, show=True):
420
421
421 """
422 """
422
423
423 Input:
424 Input:
424 dataOut :
425 dataOut :
425 idfigure :
426 idfigure :
426 wintitle :
427 wintitle :
427 channelList :
428 channelList :
428 showProfile :
429 showProfile :
429 xmin : None,
430 xmin : None,
430 xmax : None,
431 xmax : None,
431 ymin : None,
432 ymin : None,
432 ymax : None,
433 ymax : None,
433 zmin : None,
434 zmin : None,
434 zmax : None
435 zmax : None
435 """
436 """
436
437
437 if channelList == None:
438 if channelList == None:
438 channelIndexList = dataOut.channelIndexList
439 channelIndexList = dataOut.channelIndexList
439 else:
440 else:
440 channelIndexList = []
441 channelIndexList = []
441 for channel in channelList:
442 for channel in channelList:
442 if channel not in dataOut.channelList:
443 if channel not in dataOut.channelList:
443 raise ValueError, "Channel %d is not in dataOut.channelList"
444 raise ValueError, "Channel %d is not in dataOut.channelList"
444 channelIndexList.append(dataOut.channelList.index(channel))
445 channelIndexList.append(dataOut.channelList.index(channel))
445 factor = dataOut.normFactor
446 factor = dataOut.normFactor
446 x = dataOut.getVelRange(1)
447 x = dataOut.getVelRange(1)
447 y = dataOut.getHeiRange()
448 y = dataOut.getHeiRange()
448
449
449 z = dataOut.data_spc[channelIndexList,:,:]/factor
450 z = dataOut.data_spc[channelIndexList,:,:]/factor
450 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
451 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
451 avg = numpy.average(z, axis=1)
452 avg = numpy.average(z, axis=1)
452 noise = dataOut.getNoise()/factor
453 noise = dataOut.getNoise()/factor
453
454
454 zdB = 10*numpy.log10(z)
455 zdB = 10*numpy.log10(z)
455 avgdB = 10*numpy.log10(avg)
456 avgdB = 10*numpy.log10(avg)
456 noisedB = 10*numpy.log10(noise)
457 noisedB = 10*numpy.log10(noise)
457
458
458 thisDatetime = dataOut.datatime
459 #thisDatetime = dataOut.datatime
459 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
460 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
461 title = wintitle + " Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
460 xlabel = "Velocity (m/s)"
462 xlabel = "Velocity (m/s)"
461 ylabel = "Range (Km)"
463 ylabel = "Range (Km)"
462
464
463 if not self.__isConfig:
465 if not self.__isConfig:
464
466
465 nplots = len(channelIndexList)
467 nplots = len(channelIndexList)
466
468
467 self.setup(idfigure=idfigure,
469 self.setup(idfigure=idfigure,
468 nplots=nplots,
470 nplots=nplots,
469 wintitle=wintitle,
471 wintitle=wintitle,
470 showprofile=showprofile,
472 showprofile=showprofile,
471 show=show)
473 show=show)
472
474
473 if xmin == None: xmin = numpy.nanmin(x)
475 if xmin == None: xmin = numpy.nanmin(x)
474 if xmax == None: xmax = numpy.nanmax(x)
476 if xmax == None: xmax = numpy.nanmax(x)
475 if ymin == None: ymin = numpy.nanmin(y)
477 if ymin == None: ymin = numpy.nanmin(y)
476 if ymax == None: ymax = numpy.nanmax(y)
478 if ymax == None: ymax = numpy.nanmax(y)
477 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
479 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
478 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
480 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
479
481
480 self.__isConfig = True
482 self.__isConfig = True
481
483
482 self.setWinTitle(title)
484 self.setWinTitle(title)
483
485
484 for i in range(self.nplots):
486 for i in range(self.nplots):
485 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
487 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
486 axes = self.axesList[i*self.__nsubplots]
488 axes = self.axesList[i*self.__nsubplots]
487 axes.pcolor(x, y, zdB[i,:,:],
489 axes.pcolor(x, y, zdB[i,:,:],
488 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
490 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
489 xlabel=xlabel, ylabel=ylabel, title=title,
491 xlabel=xlabel, ylabel=ylabel, title=title,
490 ticksize=9, cblabel='')
492 ticksize=9, cblabel='')
491
493
492 if self.__showprofile:
494 if self.__showprofile:
493 axes = self.axesList[i*self.__nsubplots +1]
495 axes = self.axesList[i*self.__nsubplots +1]
494 axes.pline(avgdB[i], y,
496 axes.pline(avgdB[i], y,
495 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
497 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
496 xlabel='dB', ylabel='', title='',
498 xlabel='dB', ylabel='', title='',
497 ytick_visible=False,
499 ytick_visible=False,
498 grid='x')
500 grid='x')
499
501
500 noiseline = numpy.repeat(noisedB[i], len(y))
502 noiseline = numpy.repeat(noisedB[i], len(y))
501 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
503 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
502
504
503 self.draw()
505 self.draw()
504
506
505 if save:
507 if save:
506 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
508 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
507 if figfile == None:
509 if figfile == None:
508 figfile = self.getFilename(name = date)
510 figfile = self.getFilename(name = date)
509
511
510 self.saveFigure(figpath, figfile)
512 self.saveFigure(figpath, figfile)
511
513
512 class Scope(Figure):
514 class Scope(Figure):
513
515
514 __isConfig = None
516 __isConfig = None
515
517
516 def __init__(self):
518 def __init__(self):
517
519
518 self.__isConfig = False
520 self.__isConfig = False
519 self.WIDTH = 600
521 self.WIDTH = 600
520 self.HEIGHT = 200
522 self.HEIGHT = 200
521
523
522 def getSubplots(self):
524 def getSubplots(self):
523
525
524 nrow = self.nplots
526 nrow = self.nplots
525 ncol = 3
527 ncol = 3
526 return nrow, ncol
528 return nrow, ncol
527
529
528 def setup(self, idfigure, nplots, wintitle, show):
530 def setup(self, idfigure, nplots, wintitle, show):
529
531
530 self.nplots = nplots
532 self.nplots = nplots
531
533
532 self.createFigure(idfigure=idfigure,
534 self.createFigure(idfigure=idfigure,
533 wintitle=wintitle,
535 wintitle=wintitle,
534 show=show)
536 show=show)
535
537
536 nrow,ncol = self.getSubplots()
538 nrow,ncol = self.getSubplots()
537 colspan = 3
539 colspan = 3
538 rowspan = 1
540 rowspan = 1
539
541
540 for i in range(nplots):
542 for i in range(nplots):
541 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
543 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
542
544
543
545
544
546
545 def run(self, dataOut, idfigure, wintitle="", channelList=None,
547 def run(self, dataOut, idfigure, wintitle="", channelList=None,
546 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
548 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
547 figpath='./', figfile=None, show=True):
549 figpath='./', figfile=None, show=True):
548
550
549 """
551 """
550
552
551 Input:
553 Input:
552 dataOut :
554 dataOut :
553 idfigure :
555 idfigure :
554 wintitle :
556 wintitle :
555 channelList :
557 channelList :
556 xmin : None,
558 xmin : None,
557 xmax : None,
559 xmax : None,
558 ymin : None,
560 ymin : None,
559 ymax : None,
561 ymax : None,
560 """
562 """
561
563
562 if channelList == None:
564 if channelList == None:
563 channelIndexList = dataOut.channelIndexList
565 channelIndexList = dataOut.channelIndexList
564 else:
566 else:
565 channelIndexList = []
567 channelIndexList = []
566 for channel in channelList:
568 for channel in channelList:
567 if channel not in dataOut.channelList:
569 if channel not in dataOut.channelList:
568 raise ValueError, "Channel %d is not in dataOut.channelList"
570 raise ValueError, "Channel %d is not in dataOut.channelList"
569 channelIndexList.append(dataOut.channelList.index(channel))
571 channelIndexList.append(dataOut.channelList.index(channel))
570
572
571 x = dataOut.heightList
573 x = dataOut.heightList
572 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
574 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
573 y = y.real
575 y = y.real
574
576
575 thisDatetime = dataOut.datatime
577 #thisDatetime = dataOut.datatime
576 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
578 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
579 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
577 xlabel = "Range (Km)"
580 xlabel = "Range (Km)"
578 ylabel = "Intensity"
581 ylabel = "Intensity"
579
582
580 if not self.__isConfig:
583 if not self.__isConfig:
581 nplots = len(channelIndexList)
584 nplots = len(channelIndexList)
582
585
583 self.setup(idfigure=idfigure,
586 self.setup(idfigure=idfigure,
584 nplots=nplots,
587 nplots=nplots,
585 wintitle=wintitle,
588 wintitle=wintitle,
586 show=show)
589 show=show)
587
590
588 if xmin == None: xmin = numpy.nanmin(x)
591 if xmin == None: xmin = numpy.nanmin(x)
589 if xmax == None: xmax = numpy.nanmax(x)
592 if xmax == None: xmax = numpy.nanmax(x)
590 if ymin == None: ymin = numpy.nanmin(y)
593 if ymin == None: ymin = numpy.nanmin(y)
591 if ymax == None: ymax = numpy.nanmax(y)
594 if ymax == None: ymax = numpy.nanmax(y)
592
595
593 self.__isConfig = True
596 self.__isConfig = True
594
597
595 self.setWinTitle(title)
598 self.setWinTitle(title)
596
599
597 for i in range(len(self.axesList)):
600 for i in range(len(self.axesList)):
598 title = "Channel %d" %(i)
601 title = "Channel %d" %(i)
599 axes = self.axesList[i]
602 axes = self.axesList[i]
600 ychannel = y[i,:]
603 ychannel = y[i,:]
601 axes.pline(x, ychannel,
604 axes.pline(x, ychannel,
602 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
605 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
603 xlabel=xlabel, ylabel=ylabel, title=title)
606 xlabel=xlabel, ylabel=ylabel, title=title)
604
607
605 self.draw()
608 self.draw()
606
609
607 if save:
610 if save:
608 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
611 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
609 if figfile == None:
612 if figfile == None:
610 figfile = self.getFilename(name = date)
613 figfile = self.getFilename(name = date)
611
614
612 self.saveFigure(figpath, figfile)
615 self.saveFigure(figpath, figfile)
613
616
614 class PowerProfilePlot(Figure):
617 class PowerProfilePlot(Figure):
615 __isConfig = None
618 __isConfig = None
616 __nsubplots = None
619 __nsubplots = None
617
620
618 WIDTHPROF = None
621 WIDTHPROF = None
619 HEIGHTPROF = None
622 HEIGHTPROF = None
620 PREFIX = 'spcprofile'
623 PREFIX = 'spcprofile'
621
624
622 def __init__(self):
625 def __init__(self):
623 self.__isConfig = False
626 self.__isConfig = False
624 self.__nsubplots = 1
627 self.__nsubplots = 1
625
628
626 self.WIDTH = 300
629 self.WIDTH = 300
627 self.HEIGHT = 500
630 self.HEIGHT = 500
628
631
629 def getSubplots(self):
632 def getSubplots(self):
630 ncol = 1
633 ncol = 1
631 nrow = 1
634 nrow = 1
632
635
633 return nrow, ncol
636 return nrow, ncol
634
637
635 def setup(self, idfigure, nplots, wintitle, show):
638 def setup(self, idfigure, nplots, wintitle, show):
636
639
637 self.nplots = nplots
640 self.nplots = nplots
638
641
639 ncolspan = 1
642 ncolspan = 1
640 colspan = 1
643 colspan = 1
641
644
642 self.createFigure(idfigure = idfigure,
645 self.createFigure(idfigure = idfigure,
643 wintitle = wintitle,
646 wintitle = wintitle,
644 widthplot = self.WIDTH,
647 widthplot = self.WIDTH,
645 heightplot = self.HEIGHT,
648 heightplot = self.HEIGHT,
646 show=show)
649 show=show)
647
650
648 nrow, ncol = self.getSubplots()
651 nrow, ncol = self.getSubplots()
649
652
650 counter = 0
653 counter = 0
651 for y in range(nrow):
654 for y in range(nrow):
652 for x in range(ncol):
655 for x in range(ncol):
653 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
656 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
654
657
655 def run(self, dataOut, idfigure, wintitle="", channelList=None,
658 def run(self, dataOut, idfigure, wintitle="", channelList=None,
656 xmin=None, xmax=None, ymin=None, ymax=None,
659 xmin=None, xmax=None, ymin=None, ymax=None,
657 save=False, figpath='./', figfile=None, show=True):
660 save=False, figpath='./', figfile=None, show=True):
658
661
659 if channelList == None:
662 if channelList == None:
660 channelIndexList = dataOut.channelIndexList
663 channelIndexList = dataOut.channelIndexList
661 channelList = dataOut.channelList
664 channelList = dataOut.channelList
662 else:
665 else:
663 channelIndexList = []
666 channelIndexList = []
664 for channel in channelList:
667 for channel in channelList:
665 if channel not in dataOut.channelList:
668 if channel not in dataOut.channelList:
666 raise ValueError, "Channel %d is not in dataOut.channelList"
669 raise ValueError, "Channel %d is not in dataOut.channelList"
667 channelIndexList.append(dataOut.channelList.index(channel))
670 channelIndexList.append(dataOut.channelList.index(channel))
668
671
669 factor = dataOut.normFactor
672 factor = dataOut.normFactor
670 y = dataOut.getHeiRange()
673 y = dataOut.getHeiRange()
671 x = dataOut.data_spc[channelIndexList,:,:]/factor
674 x = dataOut.data_spc[channelIndexList,:,:]/factor
672 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
675 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
673 avg = numpy.average(x, axis=1)
676 avg = numpy.average(x, axis=1)
674
677
675 avgdB = 10*numpy.log10(avg)
678 avgdB = 10*numpy.log10(avg)
676
679
677 thisDatetime = dataOut.datatime
680 #thisDatetime = dataOut.datatime
678 title = "Power Profile"
681 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
682 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
679 xlabel = "dB"
683 xlabel = "dB"
680 ylabel = "Range (Km)"
684 ylabel = "Range (Km)"
681
685
682 if not self.__isConfig:
686 if not self.__isConfig:
683
687
684 nplots = 1
688 nplots = 1
685
689
686 self.setup(idfigure=idfigure,
690 self.setup(idfigure=idfigure,
687 nplots=nplots,
691 nplots=nplots,
688 wintitle=wintitle,
692 wintitle=wintitle,
689 show=show)
693 show=show)
690
694
691 if ymin == None: ymin = numpy.nanmin(y)
695 if ymin == None: ymin = numpy.nanmin(y)
692 if ymax == None: ymax = numpy.nanmax(y)
696 if ymax == None: ymax = numpy.nanmax(y)
693 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
697 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
694 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
698 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
695
699
696 self.__isConfig = True
700 self.__isConfig = True
697
701
698 self.setWinTitle(title)
702 self.setWinTitle(title)
699
703
700
704
701 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
705 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
702 axes = self.axesList[0]
706 axes = self.axesList[0]
703
707
704 legendlabels = ["channel %d"%x for x in channelList]
708 legendlabels = ["channel %d"%x for x in channelList]
705 axes.pmultiline(avgdB, y,
709 axes.pmultiline(avgdB, y,
706 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
710 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
707 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
711 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
708 ytick_visible=True, nxticks=5,
712 ytick_visible=True, nxticks=5,
709 grid='x')
713 grid='x')
710
714
711 self.draw()
715 self.draw()
712
716
713 if save:
717 if save:
714 date = thisDatetime.strftime("%Y%m%d")
718 date = thisDatetime.strftime("%Y%m%d")
715 if figfile == None:
719 if figfile == None:
716 figfile = self.getFilename(name = date)
720 figfile = self.getFilename(name = date)
717
721
718 self.saveFigure(figpath, figfile)
722 self.saveFigure(figpath, figfile)
719
723
720 class CoherenceMap(Figure):
724 class CoherenceMap(Figure):
721 __isConfig = None
725 __isConfig = None
722 __nsubplots = None
726 __nsubplots = None
723
727
724 WIDTHPROF = None
728 WIDTHPROF = None
725 HEIGHTPROF = None
729 HEIGHTPROF = None
726 PREFIX = 'cmap'
730 PREFIX = 'cmap'
727
731
728 def __init__(self):
732 def __init__(self):
729 self.timerange = 2*60*60
733 self.timerange = 2*60*60
730 self.__isConfig = False
734 self.__isConfig = False
731 self.__nsubplots = 1
735 self.__nsubplots = 1
732
736
733 self.WIDTH = 800
737 self.WIDTH = 800
734 self.HEIGHT = 150
738 self.HEIGHT = 150
735 self.WIDTHPROF = 120
739 self.WIDTHPROF = 120
736 self.HEIGHTPROF = 0
740 self.HEIGHTPROF = 0
737 self.counterftp = 0
741 self.counterftp = 0
738
742
739 def getSubplots(self):
743 def getSubplots(self):
740 ncol = 1
744 ncol = 1
741 nrow = self.nplots*2
745 nrow = self.nplots*2
742
746
743 return nrow, ncol
747 return nrow, ncol
744
748
745 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
749 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
746 self.__showprofile = showprofile
750 self.__showprofile = showprofile
747 self.nplots = nplots
751 self.nplots = nplots
748
752
749 ncolspan = 1
753 ncolspan = 1
750 colspan = 1
754 colspan = 1
751 if showprofile:
755 if showprofile:
752 ncolspan = 7
756 ncolspan = 7
753 colspan = 6
757 colspan = 6
754 self.__nsubplots = 2
758 self.__nsubplots = 2
755
759
756 self.createFigure(idfigure = idfigure,
760 self.createFigure(idfigure = idfigure,
757 wintitle = wintitle,
761 wintitle = wintitle,
758 widthplot = self.WIDTH + self.WIDTHPROF,
762 widthplot = self.WIDTH + self.WIDTHPROF,
759 heightplot = self.HEIGHT + self.HEIGHTPROF,
763 heightplot = self.HEIGHT + self.HEIGHTPROF,
760 show=True)
764 show=True)
761
765
762 nrow, ncol = self.getSubplots()
766 nrow, ncol = self.getSubplots()
763
767
764 for y in range(nrow):
768 for y in range(nrow):
765 for x in range(ncol):
769 for x in range(ncol):
766
770
767 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
771 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
768
772
769 if showprofile:
773 if showprofile:
770 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
774 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
771
775
772 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
776 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
773 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
777 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
774 timerange=None,
778 timerange=None,
775 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
779 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
776 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
780 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
777
781
778 if pairsList == None:
782 if pairsList == None:
779 pairsIndexList = dataOut.pairsIndexList
783 pairsIndexList = dataOut.pairsIndexList
780 else:
784 else:
781 pairsIndexList = []
785 pairsIndexList = []
782 for pair in pairsList:
786 for pair in pairsList:
783 if pair not in dataOut.pairsList:
787 if pair not in dataOut.pairsList:
784 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
788 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
785 pairsIndexList.append(dataOut.pairsList.index(pair))
789 pairsIndexList.append(dataOut.pairsList.index(pair))
786
790
787 if timerange != None:
791 if timerange != None:
788 self.timerange = timerange
792 self.timerange = timerange
789
793
790 if pairsIndexList == []:
794 if pairsIndexList == []:
791 return
795 return
792
796
793 if len(pairsIndexList) > 4:
797 if len(pairsIndexList) > 4:
794 pairsIndexList = pairsIndexList[0:4]
798 pairsIndexList = pairsIndexList[0:4]
795
799
796 tmin = None
800 tmin = None
797 tmax = None
801 tmax = None
798 x = dataOut.getTimeRange()
802 x = dataOut.getTimeRange()
799 y = dataOut.getHeiRange()
803 y = dataOut.getHeiRange()
800
804
801 thisDatetime = dataOut.datatime
805 #thisDatetime = dataOut.datatime
802 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
806 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
807 title = wintitle + " CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
803 xlabel = ""
808 xlabel = ""
804 ylabel = "Range (Km)"
809 ylabel = "Range (Km)"
805
810
806 if not self.__isConfig:
811 if not self.__isConfig:
807 nplots = len(pairsIndexList)
812 nplots = len(pairsIndexList)
808 self.setup(idfigure=idfigure,
813 self.setup(idfigure=idfigure,
809 nplots=nplots,
814 nplots=nplots,
810 wintitle=wintitle,
815 wintitle=wintitle,
811 showprofile=showprofile,
816 showprofile=showprofile,
812 show=show)
817 show=show)
813
818
814 tmin, tmax = self.getTimeLim(x, xmin, xmax)
819 tmin, tmax = self.getTimeLim(x, xmin, xmax)
815 if ymin == None: ymin = numpy.nanmin(y)
820 if ymin == None: ymin = numpy.nanmin(y)
816 if ymax == None: ymax = numpy.nanmax(y)
821 if ymax == None: ymax = numpy.nanmax(y)
817
822
818 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
823 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
819
824
820 self.__isConfig = True
825 self.__isConfig = True
821
826
822 self.setWinTitle(title)
827 self.setWinTitle(title)
823
828
824 for i in range(self.nplots):
829 for i in range(self.nplots):
825
830
826 pair = dataOut.pairsList[pairsIndexList[i]]
831 pair = dataOut.pairsList[pairsIndexList[i]]
827 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
832 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
828 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
833 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
829 coherence = numpy.abs(avgcoherenceComplex)
834 coherence = numpy.abs(avgcoherenceComplex)
830 # coherence = numpy.abs(coherenceComplex)
835 # coherence = numpy.abs(coherenceComplex)
831 # avg = numpy.average(coherence, axis=0)
836 # avg = numpy.average(coherence, axis=0)
832
837
833 z = coherence.reshape((1,-1))
838 z = coherence.reshape((1,-1))
834
839
835 counter = 0
840 counter = 0
836
841
837 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
842 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
838 axes = self.axesList[i*self.__nsubplots*2]
843 axes = self.axesList[i*self.__nsubplots*2]
839 axes.pcolorbuffer(x, y, z,
844 axes.pcolorbuffer(x, y, z,
840 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
845 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
841 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
846 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
842 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
847 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
843
848
844 if self.__showprofile:
849 if self.__showprofile:
845 counter += 1
850 counter += 1
846 axes = self.axesList[i*self.__nsubplots*2 + counter]
851 axes = self.axesList[i*self.__nsubplots*2 + counter]
847 axes.pline(coherence, y,
852 axes.pline(coherence, y,
848 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
853 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
849 xlabel='', ylabel='', title='', ticksize=7,
854 xlabel='', ylabel='', title='', ticksize=7,
850 ytick_visible=False, nxticks=5,
855 ytick_visible=False, nxticks=5,
851 grid='x')
856 grid='x')
852
857
853 counter += 1
858 counter += 1
854 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
859 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
855 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
860 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
856 # avg = numpy.average(phase, axis=0)
861 # avg = numpy.average(phase, axis=0)
857 z = phase.reshape((1,-1))
862 z = phase.reshape((1,-1))
858
863
859 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
864 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
860 axes = self.axesList[i*self.__nsubplots*2 + counter]
865 axes = self.axesList[i*self.__nsubplots*2 + counter]
861 axes.pcolorbuffer(x, y, z,
866 axes.pcolorbuffer(x, y, z,
862 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
867 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
863 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
868 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
864 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
869 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
865
870
866 if self.__showprofile:
871 if self.__showprofile:
867 counter += 1
872 counter += 1
868 axes = self.axesList[i*self.__nsubplots*2 + counter]
873 axes = self.axesList[i*self.__nsubplots*2 + counter]
869 axes.pline(phase, y,
874 axes.pline(phase, y,
870 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
875 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
871 xlabel='', ylabel='', title='', ticksize=7,
876 xlabel='', ylabel='', title='', ticksize=7,
872 ytick_visible=False, nxticks=4,
877 ytick_visible=False, nxticks=4,
873 grid='x')
878 grid='x')
874
879
875 self.draw()
880 self.draw()
876
881
877 if save:
882 if save:
878
883
879 if figfile == None:
884 if figfile == None:
880 figfile = self.getFilename(name = self.name)
885 figfile = self.getFilename(name = self.name)
881
886
882 self.saveFigure(figpath, figfile)
887 self.saveFigure(figpath, figfile)
883
888
884 self.counterftp += 1
889 self.counterftp += 1
885 if (ftp and (self.counterftp==ftpratio)):
890 if (ftp and (self.counterftp==ftpratio)):
886 figfilename = os.path.join(figpath,figfile)
891 figfilename = os.path.join(figpath,figfile)
887 self.sendByFTP(figfilename)
892 self.sendByFTP(figfilename)
888 self.counterftp = 0
893 self.counterftp = 0
889
894
890 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
895 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
891 self.__isConfig = False
896 self.__isConfig = False
892
897
893 class RTIfromNoise(Figure):
898 class RTIfromNoise(Figure):
894
899
895 __isConfig = None
900 __isConfig = None
896 __nsubplots = None
901 __nsubplots = None
897
902
898 PREFIX = 'rtinoise'
903 PREFIX = 'rtinoise'
899
904
900 def __init__(self):
905 def __init__(self):
901
906
902 self.timerange = 24*60*60
907 self.timerange = 24*60*60
903 self.__isConfig = False
908 self.__isConfig = False
904 self.__nsubplots = 1
909 self.__nsubplots = 1
905
910
906 self.WIDTH = 820
911 self.WIDTH = 820
907 self.HEIGHT = 200
912 self.HEIGHT = 200
908 self.WIDTHPROF = 120
913 self.WIDTHPROF = 120
909 self.HEIGHTPROF = 0
914 self.HEIGHTPROF = 0
910 self.xdata = None
915 self.xdata = None
911 self.ydata = None
916 self.ydata = None
912
917
913 def getSubplots(self):
918 def getSubplots(self):
914
919
915 ncol = 1
920 ncol = 1
916 nrow = 1
921 nrow = 1
917
922
918 return nrow, ncol
923 return nrow, ncol
919
924
920 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
925 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
921
926
922 self.__showprofile = showprofile
927 self.__showprofile = showprofile
923 self.nplots = nplots
928 self.nplots = nplots
924
929
925 ncolspan = 7
930 ncolspan = 7
926 colspan = 6
931 colspan = 6
927 self.__nsubplots = 2
932 self.__nsubplots = 2
928
933
929 self.createFigure(idfigure = idfigure,
934 self.createFigure(idfigure = idfigure,
930 wintitle = wintitle,
935 wintitle = wintitle,
931 widthplot = self.WIDTH+self.WIDTHPROF,
936 widthplot = self.WIDTH+self.WIDTHPROF,
932 heightplot = self.HEIGHT+self.HEIGHTPROF,
937 heightplot = self.HEIGHT+self.HEIGHTPROF,
933 show=show)
938 show=show)
934
939
935 nrow, ncol = self.getSubplots()
940 nrow, ncol = self.getSubplots()
936
941
937 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
942 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
938
943
939
944
940 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
945 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
941 xmin=None, xmax=None, ymin=None, ymax=None,
946 xmin=None, xmax=None, ymin=None, ymax=None,
942 timerange=None,
947 timerange=None,
943 save=False, figpath='./', figfile=None, show=True):
948 save=False, figpath='./', figfile=None, show=True):
944
949
945 if channelList == None:
950 if channelList == None:
946 channelIndexList = dataOut.channelIndexList
951 channelIndexList = dataOut.channelIndexList
947 channelList = dataOut.channelList
952 channelList = dataOut.channelList
948 else:
953 else:
949 channelIndexList = []
954 channelIndexList = []
950 for channel in channelList:
955 for channel in channelList:
951 if channel not in dataOut.channelList:
956 if channel not in dataOut.channelList:
952 raise ValueError, "Channel %d is not in dataOut.channelList"
957 raise ValueError, "Channel %d is not in dataOut.channelList"
953 channelIndexList.append(dataOut.channelList.index(channel))
958 channelIndexList.append(dataOut.channelList.index(channel))
954
959
955 if timerange != None:
960 if timerange != None:
956 self.timerange = timerange
961 self.timerange = timerange
957
962
958 tmin = None
963 tmin = None
959 tmax = None
964 tmax = None
960 x = dataOut.getTimeRange()
965 x = dataOut.getTimeRange()
961 y = dataOut.getHeiRange()
966 y = dataOut.getHeiRange()
962 factor = dataOut.normFactor
967 factor = dataOut.normFactor
963 noise = dataOut.getNoise()/factor
968 noise = dataOut.getNoise()/factor
964 noisedB = 10*numpy.log10(noise)
969 noisedB = 10*numpy.log10(noise)
965
970
966 thisDatetime = dataOut.datatime
971 #thisDatetime = dataOut.datatime
967 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
972 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
973 title = wintitle + " RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
968 xlabel = ""
974 xlabel = ""
969 ylabel = "Range (Km)"
975 ylabel = "Range (Km)"
970
976
971 if not self.__isConfig:
977 if not self.__isConfig:
972
978
973 nplots = 1
979 nplots = 1
974
980
975 self.setup(idfigure=idfigure,
981 self.setup(idfigure=idfigure,
976 nplots=nplots,
982 nplots=nplots,
977 wintitle=wintitle,
983 wintitle=wintitle,
978 showprofile=showprofile,
984 showprofile=showprofile,
979 show=show)
985 show=show)
980
986
981 tmin, tmax = self.getTimeLim(x, xmin, xmax)
987 tmin, tmax = self.getTimeLim(x, xmin, xmax)
982 if ymin == None: ymin = numpy.nanmin(noisedB)
988 if ymin == None: ymin = numpy.nanmin(noisedB)
983 if ymax == None: ymax = numpy.nanmax(noisedB)
989 if ymax == None: ymax = numpy.nanmax(noisedB)
984
990
985 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
991 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
986 self.__isConfig = True
992 self.__isConfig = True
987
993
988 self.xdata = numpy.array([])
994 self.xdata = numpy.array([])
989 self.ydata = numpy.array([])
995 self.ydata = numpy.array([])
990
996
991 self.setWinTitle(title)
997 self.setWinTitle(title)
992
998
993
999
994 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
1000 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
995
1001
996 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1002 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
997 axes = self.axesList[0]
1003 axes = self.axesList[0]
998
1004
999 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1005 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1000
1006
1001 if len(self.ydata)==0:
1007 if len(self.ydata)==0:
1002 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1008 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1003 else:
1009 else:
1004 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1010 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1005
1011
1006
1012
1007 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1013 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1008 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1014 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1009 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1015 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1010 XAxisAsTime=True
1016 XAxisAsTime=True
1011 )
1017 )
1012
1018
1013 self.draw()
1019 self.draw()
1014
1020
1015 if save:
1021 if save:
1016
1022
1017 if figfile == None:
1023 if figfile == None:
1018 figfile = self.getFilename(name = self.name)
1024 figfile = self.getFilename(name = self.name)
1019
1025
1020 self.saveFigure(figpath, figfile)
1026 self.saveFigure(figpath, figfile)
1021
1027
1022 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1028 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1023 self.__isConfig = False
1029 self.__isConfig = False
1024 del self.xdata
1030 del self.xdata
1025 del self.ydata
1031 del self.ydata
1026
1032
1027
1033
1028 class SpectraHeisScope(Figure):
1034 class SpectraHeisScope(Figure):
1029
1035
1030
1036
1031 __isConfig = None
1037 __isConfig = None
1032 __nsubplots = None
1038 __nsubplots = None
1033
1039
1034 WIDTHPROF = None
1040 WIDTHPROF = None
1035 HEIGHTPROF = None
1041 HEIGHTPROF = None
1036 PREFIX = 'spc'
1042 PREFIX = 'spc'
1037
1043
1038 def __init__(self):
1044 def __init__(self):
1039
1045
1040 self.__isConfig = False
1046 self.__isConfig = False
1041 self.__nsubplots = 1
1047 self.__nsubplots = 1
1042
1048
1043 self.WIDTH = 230
1049 self.WIDTH = 230
1044 self.HEIGHT = 250
1050 self.HEIGHT = 250
1045 self.WIDTHPROF = 120
1051 self.WIDTHPROF = 120
1046 self.HEIGHTPROF = 0
1052 self.HEIGHTPROF = 0
1047 self.counterftp = 0
1053 self.counterftp = 0
1048
1054
1049 def getSubplots(self):
1055 def getSubplots(self):
1050
1056
1051 ncol = int(numpy.sqrt(self.nplots)+0.9)
1057 ncol = int(numpy.sqrt(self.nplots)+0.9)
1052 nrow = int(self.nplots*1./ncol + 0.9)
1058 nrow = int(self.nplots*1./ncol + 0.9)
1053
1059
1054 return nrow, ncol
1060 return nrow, ncol
1055
1061
1056 def setup(self, idfigure, nplots, wintitle, show):
1062 def setup(self, idfigure, nplots, wintitle, show):
1057
1063
1058 showprofile = False
1064 showprofile = False
1059 self.__showprofile = showprofile
1065 self.__showprofile = showprofile
1060 self.nplots = nplots
1066 self.nplots = nplots
1061
1067
1062 ncolspan = 1
1068 ncolspan = 1
1063 colspan = 1
1069 colspan = 1
1064 if showprofile:
1070 if showprofile:
1065 ncolspan = 3
1071 ncolspan = 3
1066 colspan = 2
1072 colspan = 2
1067 self.__nsubplots = 2
1073 self.__nsubplots = 2
1068
1074
1069 self.createFigure(idfigure = idfigure,
1075 self.createFigure(idfigure = idfigure,
1070 wintitle = wintitle,
1076 wintitle = wintitle,
1071 widthplot = self.WIDTH + self.WIDTHPROF,
1077 widthplot = self.WIDTH + self.WIDTHPROF,
1072 heightplot = self.HEIGHT + self.HEIGHTPROF,
1078 heightplot = self.HEIGHT + self.HEIGHTPROF,
1073 show = show)
1079 show = show)
1074
1080
1075 nrow, ncol = self.getSubplots()
1081 nrow, ncol = self.getSubplots()
1076
1082
1077 counter = 0
1083 counter = 0
1078 for y in range(nrow):
1084 for y in range(nrow):
1079 for x in range(ncol):
1085 for x in range(ncol):
1080
1086
1081 if counter >= self.nplots:
1087 if counter >= self.nplots:
1082 break
1088 break
1083
1089
1084 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1090 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1085
1091
1086 if showprofile:
1092 if showprofile:
1087 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1088
1094
1089 counter += 1
1095 counter += 1
1090
1096
1091 # __isConfig = None
1097 # __isConfig = None
1092 # def __init__(self):
1098 # def __init__(self):
1093 #
1099 #
1094 # self.__isConfig = False
1100 # self.__isConfig = False
1095 # self.WIDTH = 600
1101 # self.WIDTH = 600
1096 # self.HEIGHT = 200
1102 # self.HEIGHT = 200
1097 #
1103 #
1098 # def getSubplots(self):
1104 # def getSubplots(self):
1099 #
1105 #
1100 # nrow = self.nplots
1106 # nrow = self.nplots
1101 # ncol = 3
1107 # ncol = 3
1102 # return nrow, ncol
1108 # return nrow, ncol
1103 #
1109 #
1104 # def setup(self, idfigure, nplots, wintitle):
1110 # def setup(self, idfigure, nplots, wintitle):
1105 #
1111 #
1106 # self.nplots = nplots
1112 # self.nplots = nplots
1107 #
1113 #
1108 # self.createFigure(idfigure, wintitle)
1114 # self.createFigure(idfigure, wintitle)
1109 #
1115 #
1110 # nrow,ncol = self.getSubplots()
1116 # nrow,ncol = self.getSubplots()
1111 # colspan = 3
1117 # colspan = 3
1112 # rowspan = 1
1118 # rowspan = 1
1113 #
1119 #
1114 # for i in range(nplots):
1120 # for i in range(nplots):
1115 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1121 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1116
1122
1117 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1123 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1118 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1124 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1119 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1125 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1120
1126
1121 """
1127 """
1122
1128
1123 Input:
1129 Input:
1124 dataOut :
1130 dataOut :
1125 idfigure :
1131 idfigure :
1126 wintitle :
1132 wintitle :
1127 channelList :
1133 channelList :
1128 xmin : None,
1134 xmin : None,
1129 xmax : None,
1135 xmax : None,
1130 ymin : None,
1136 ymin : None,
1131 ymax : None,
1137 ymax : None,
1132 """
1138 """
1133
1139
1134 if dataOut.realtime:
1140 if dataOut.realtime:
1135 if not(isRealtime(utcdatatime = dataOut.utctime)):
1141 if not(isRealtime(utcdatatime = dataOut.utctime)):
1136 print 'Skipping this plot function'
1142 print 'Skipping this plot function'
1137 return
1143 return
1138
1144
1139 if channelList == None:
1145 if channelList == None:
1140 channelIndexList = dataOut.channelIndexList
1146 channelIndexList = dataOut.channelIndexList
1141 else:
1147 else:
1142 channelIndexList = []
1148 channelIndexList = []
1143 for channel in channelList:
1149 for channel in channelList:
1144 if channel not in dataOut.channelList:
1150 if channel not in dataOut.channelList:
1145 raise ValueError, "Channel %d is not in dataOut.channelList"
1151 raise ValueError, "Channel %d is not in dataOut.channelList"
1146 channelIndexList.append(dataOut.channelList.index(channel))
1152 channelIndexList.append(dataOut.channelList.index(channel))
1147
1153
1148 # x = dataOut.heightList
1154 # x = dataOut.heightList
1149 c = 3E8
1155 c = 3E8
1150 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1156 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1151 #deberia cambiar para el caso de 1Mhz y 100KHz
1157 #deberia cambiar para el caso de 1Mhz y 100KHz
1152 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1158 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1153 x= x/(10000.0)
1159 x= x/(10000.0)
1154 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1160 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1155 # y = y.real
1161 # y = y.real
1156 datadB = 10.*numpy.log10(dataOut.data_spc)
1162 datadB = 10.*numpy.log10(dataOut.data_spc)
1157 y = datadB
1163 y = datadB
1158
1164
1159 thisDatetime = dataOut.datatime
1165 #thisDatetime = dataOut.datatime
1160 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1166 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1167 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1161 xlabel = "Frequency x 10000"
1168 xlabel = "Frequency x 10000"
1162 ylabel = "Intensity (dB)"
1169 ylabel = "Intensity (dB)"
1163
1170
1164 if not self.__isConfig:
1171 if not self.__isConfig:
1165 nplots = len(channelIndexList)
1172 nplots = len(channelIndexList)
1166
1173
1167 self.setup(idfigure=idfigure,
1174 self.setup(idfigure=idfigure,
1168 nplots=nplots,
1175 nplots=nplots,
1169 wintitle=wintitle,
1176 wintitle=wintitle,
1170 show=show)
1177 show=show)
1171
1178
1172 if xmin == None: xmin = numpy.nanmin(x)
1179 if xmin == None: xmin = numpy.nanmin(x)
1173 if xmax == None: xmax = numpy.nanmax(x)
1180 if xmax == None: xmax = numpy.nanmax(x)
1174 if ymin == None: ymin = numpy.nanmin(y)
1181 if ymin == None: ymin = numpy.nanmin(y)
1175 if ymax == None: ymax = numpy.nanmax(y)
1182 if ymax == None: ymax = numpy.nanmax(y)
1176
1183
1177 self.__isConfig = True
1184 self.__isConfig = True
1178
1185
1179 self.setWinTitle(title)
1186 self.setWinTitle(title)
1180
1187
1181 for i in range(len(self.axesList)):
1188 for i in range(len(self.axesList)):
1182 ychannel = y[i,:]
1189 ychannel = y[i,:]
1183 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1190 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1184 axes = self.axesList[i]
1191 axes = self.axesList[i]
1185 axes.pline(x, ychannel,
1192 axes.pline(x, ychannel,
1186 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1193 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1187 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1194 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1188
1195
1189
1196
1190 self.draw()
1197 self.draw()
1191
1198
1192 if save:
1199 if save:
1193 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1200 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1194 if figfile == None:
1201 if figfile == None:
1195 figfile = self.getFilename(name = date)
1202 figfile = self.getFilename(name = date)
1196
1203
1197 self.saveFigure(figpath, figfile)
1204 self.saveFigure(figpath, figfile)
1198
1205
1199 self.counterftp += 1
1206 self.counterftp += 1
1200 if (ftp and (self.counterftp==ftpratio)):
1207 if (ftp and (self.counterftp==ftpratio)):
1201 figfilename = os.path.join(figpath,figfile)
1208 figfilename = os.path.join(figpath,figfile)
1202 self.sendByFTP(figfilename)
1209 self.sendByFTP(figfilename)
1203 self.counterftp = 0
1210 self.counterftp = 0
1204
1211
1205
1212
1206 class RTIfromSpectraHeis(Figure):
1213 class RTIfromSpectraHeis(Figure):
1207
1214
1208 __isConfig = None
1215 __isConfig = None
1209 __nsubplots = None
1216 __nsubplots = None
1210
1217
1211 PREFIX = 'rtinoise'
1218 PREFIX = 'rtinoise'
1212
1219
1213 def __init__(self):
1220 def __init__(self):
1214
1221
1215 self.timerange = 24*60*60
1222 self.timerange = 24*60*60
1216 self.__isConfig = False
1223 self.__isConfig = False
1217 self.__nsubplots = 1
1224 self.__nsubplots = 1
1218
1225
1219 self.WIDTH = 820
1226 self.WIDTH = 820
1220 self.HEIGHT = 200
1227 self.HEIGHT = 200
1221 self.WIDTHPROF = 120
1228 self.WIDTHPROF = 120
1222 self.HEIGHTPROF = 0
1229 self.HEIGHTPROF = 0
1223 self.counterftp = 0
1230 self.counterftp = 0
1224 self.xdata = None
1231 self.xdata = None
1225 self.ydata = None
1232 self.ydata = None
1226
1233
1227 def getSubplots(self):
1234 def getSubplots(self):
1228
1235
1229 ncol = 1
1236 ncol = 1
1230 nrow = 1
1237 nrow = 1
1231
1238
1232 return nrow, ncol
1239 return nrow, ncol
1233
1240
1234 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1241 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1235
1242
1236 self.__showprofile = showprofile
1243 self.__showprofile = showprofile
1237 self.nplots = nplots
1244 self.nplots = nplots
1238
1245
1239 ncolspan = 7
1246 ncolspan = 7
1240 colspan = 6
1247 colspan = 6
1241 self.__nsubplots = 2
1248 self.__nsubplots = 2
1242
1249
1243 self.createFigure(idfigure = idfigure,
1250 self.createFigure(idfigure = idfigure,
1244 wintitle = wintitle,
1251 wintitle = wintitle,
1245 widthplot = self.WIDTH+self.WIDTHPROF,
1252 widthplot = self.WIDTH+self.WIDTHPROF,
1246 heightplot = self.HEIGHT+self.HEIGHTPROF,
1253 heightplot = self.HEIGHT+self.HEIGHTPROF,
1247 show = show)
1254 show = show)
1248
1255
1249 nrow, ncol = self.getSubplots()
1256 nrow, ncol = self.getSubplots()
1250
1257
1251 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1258 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1252
1259
1253
1260
1254 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1261 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1255 xmin=None, xmax=None, ymin=None, ymax=None,
1262 xmin=None, xmax=None, ymin=None, ymax=None,
1256 timerange=None,
1263 timerange=None,
1257 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1264 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1258
1265
1259 if channelList == None:
1266 if channelList == None:
1260 channelIndexList = dataOut.channelIndexList
1267 channelIndexList = dataOut.channelIndexList
1261 channelList = dataOut.channelList
1268 channelList = dataOut.channelList
1262 else:
1269 else:
1263 channelIndexList = []
1270 channelIndexList = []
1264 for channel in channelList:
1271 for channel in channelList:
1265 if channel not in dataOut.channelList:
1272 if channel not in dataOut.channelList:
1266 raise ValueError, "Channel %d is not in dataOut.channelList"
1273 raise ValueError, "Channel %d is not in dataOut.channelList"
1267 channelIndexList.append(dataOut.channelList.index(channel))
1274 channelIndexList.append(dataOut.channelList.index(channel))
1268
1275
1269 if timerange != None:
1276 if timerange != None:
1270 self.timerange = timerange
1277 self.timerange = timerange
1271
1278
1272 tmin = None
1279 tmin = None
1273 tmax = None
1280 tmax = None
1274 x = dataOut.getTimeRange()
1281 x = dataOut.getTimeRange()
1275 y = dataOut.getHeiRange()
1282 y = dataOut.getHeiRange()
1276
1283
1277 factor = 1
1284 factor = 1
1278 data = dataOut.data_spc/factor
1285 data = dataOut.data_spc/factor
1279 data = numpy.average(data,axis=1)
1286 data = numpy.average(data,axis=1)
1280 datadB = 10*numpy.log10(data)
1287 datadB = 10*numpy.log10(data)
1281
1288
1282 # factor = dataOut.normFactor
1289 # factor = dataOut.normFactor
1283 # noise = dataOut.getNoise()/factor
1290 # noise = dataOut.getNoise()/factor
1284 # noisedB = 10*numpy.log10(noise)
1291 # noisedB = 10*numpy.log10(noise)
1285
1292
1286 thisDatetime = dataOut.datatime
1293 #thisDatetime = dataOut.datatime
1287 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1294 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1295 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1288 xlabel = "Local Time"
1296 xlabel = "Local Time"
1289 ylabel = "Intensity (dB)"
1297 ylabel = "Intensity (dB)"
1290
1298
1291 if not self.__isConfig:
1299 if not self.__isConfig:
1292
1300
1293 nplots = 1
1301 nplots = 1
1294
1302
1295 self.setup(idfigure=idfigure,
1303 self.setup(idfigure=idfigure,
1296 nplots=nplots,
1304 nplots=nplots,
1297 wintitle=wintitle,
1305 wintitle=wintitle,
1298 showprofile=showprofile,
1306 showprofile=showprofile,
1299 show=show)
1307 show=show)
1300
1308
1301 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1309 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1302 if ymin == None: ymin = numpy.nanmin(datadB)
1310 if ymin == None: ymin = numpy.nanmin(datadB)
1303 if ymax == None: ymax = numpy.nanmax(datadB)
1311 if ymax == None: ymax = numpy.nanmax(datadB)
1304
1312
1305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1313 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1306 self.__isConfig = True
1314 self.__isConfig = True
1307
1315
1308 self.xdata = numpy.array([])
1316 self.xdata = numpy.array([])
1309 self.ydata = numpy.array([])
1317 self.ydata = numpy.array([])
1310
1318
1311 self.setWinTitle(title)
1319 self.setWinTitle(title)
1312
1320
1313
1321
1314 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1322 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1315 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1323 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1316
1324
1317 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1325 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1318 axes = self.axesList[0]
1326 axes = self.axesList[0]
1319
1327
1320 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1328 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1321
1329
1322 if len(self.ydata)==0:
1330 if len(self.ydata)==0:
1323 self.ydata = datadB[channelIndexList].reshape(-1,1)
1331 self.ydata = datadB[channelIndexList].reshape(-1,1)
1324 else:
1332 else:
1325 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1333 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1326
1334
1327
1335
1328 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1336 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1329 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1337 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1330 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1338 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1331 XAxisAsTime=True
1339 XAxisAsTime=True
1332 )
1340 )
1333
1341
1334 self.draw()
1342 self.draw()
1335
1343
1336 if save:
1344 if save:
1337
1345
1338 if figfile == None:
1346 if figfile == None:
1339 figfile = self.getFilename(name = self.name)
1347 figfile = self.getFilename(name = self.name)
1340
1348
1341 self.saveFigure(figpath, figfile)
1349 self.saveFigure(figpath, figfile)
1342
1350
1343 self.counterftp += 1
1351 self.counterftp += 1
1344 if (ftp and (self.counterftp==ftpratio)):
1352 if (ftp and (self.counterftp==ftpratio)):
1345 figfilename = os.path.join(figpath,figfile)
1353 figfilename = os.path.join(figpath,figfile)
1346 self.sendByFTP(figfilename)
1354 self.sendByFTP(figfilename)
1347 self.counterftp = 0
1355 self.counterftp = 0
1348
1356
1349 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1357 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1350 self.__isConfig = False
1358 self.__isConfig = False
1351 del self.xdata
1359 del self.xdata
1352 del self.ydata
1360 del self.ydata
1353
1361
1354
1362
1355 No newline at end of file
1363
@@ -1,1635 +1,1643
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 try:
15 try:
16 import cfunctions
16 import cfunctions
17 except:
17 except:
18 pass
18 pass
19
19
20 class ProcessingUnit:
20 class ProcessingUnit:
21
21
22 """
22 """
23 Esta es la clase base para el procesamiento de datos.
23 Esta es la clase base para el procesamiento de datos.
24
24
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 - Metodos internos (callMethod)
26 - Metodos internos (callMethod)
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 tienen que ser agreagados con el metodo "add".
28 tienen que ser agreagados con el metodo "add".
29
29
30 """
30 """
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 dataIn = None
32 dataIn = None
33
33
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 dataOut = None
35 dataOut = None
36
36
37
37
38 objectDict = None
38 objectDict = None
39
39
40 def __init__(self):
40 def __init__(self):
41
41
42 self.objectDict = {}
42 self.objectDict = {}
43
43
44 def init(self):
44 def init(self):
45
45
46 raise ValueError, "Not implemented"
46 raise ValueError, "Not implemented"
47
47
48 def addOperation(self, object, objId):
48 def addOperation(self, object, objId):
49
49
50 """
50 """
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 identificador asociado a este objeto.
52 identificador asociado a este objeto.
53
53
54 Input:
54 Input:
55
55
56 object : objeto de la clase "Operation"
56 object : objeto de la clase "Operation"
57
57
58 Return:
58 Return:
59
59
60 objId : identificador del objeto, necesario para ejecutar la operacion
60 objId : identificador del objeto, necesario para ejecutar la operacion
61 """
61 """
62
62
63 self.objectDict[objId] = object
63 self.objectDict[objId] = object
64
64
65 return objId
65 return objId
66
66
67 def operation(self, **kwargs):
67 def operation(self, **kwargs):
68
68
69 """
69 """
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 atributos del objeto dataOut
71 atributos del objeto dataOut
72
72
73 Input:
73 Input:
74
74
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 """
76 """
77
77
78 raise ValueError, "ImplementedError"
78 raise ValueError, "ImplementedError"
79
79
80 def callMethod(self, name, **kwargs):
80 def callMethod(self, name, **kwargs):
81
81
82 """
82 """
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 Input:
85 Input:
86 name : nombre del metodo a ejecutar
86 name : nombre del metodo a ejecutar
87
87
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 """
90 """
91 if name != 'run':
91 if name != 'run':
92
92
93 if name == 'init' and self.dataIn.isEmpty():
93 if name == 'init' and self.dataIn.isEmpty():
94 self.dataOut.flagNoData = True
94 self.dataOut.flagNoData = True
95 return False
95 return False
96
96
97 if name != 'init' and self.dataOut.isEmpty():
97 if name != 'init' and self.dataOut.isEmpty():
98 return False
98 return False
99
99
100 methodToCall = getattr(self, name)
100 methodToCall = getattr(self, name)
101
101
102 methodToCall(**kwargs)
102 methodToCall(**kwargs)
103
103
104 if name != 'run':
104 if name != 'run':
105 return True
105 return True
106
106
107 if self.dataOut.isEmpty():
107 if self.dataOut.isEmpty():
108 return False
108 return False
109
109
110 return True
110 return True
111
111
112 def callObject(self, objId, **kwargs):
112 def callObject(self, objId, **kwargs):
113
113
114 """
114 """
115 Ejecuta la operacion asociada al identificador del objeto "objId"
115 Ejecuta la operacion asociada al identificador del objeto "objId"
116
116
117 Input:
117 Input:
118
118
119 objId : identificador del objeto a ejecutar
119 objId : identificador del objeto a ejecutar
120
120
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122
122
123 Return:
123 Return:
124
124
125 None
125 None
126 """
126 """
127
127
128 if self.dataOut.isEmpty():
128 if self.dataOut.isEmpty():
129 return False
129 return False
130
130
131 object = self.objectDict[objId]
131 object = self.objectDict[objId]
132
132
133 object.run(self.dataOut, **kwargs)
133 object.run(self.dataOut, **kwargs)
134
134
135 return True
135 return True
136
136
137 def call(self, operationConf, **kwargs):
137 def call(self, operationConf, **kwargs):
138
138
139 """
139 """
140 Return True si ejecuta la operacion "operationConf.name" con los
140 Return True si ejecuta la operacion "operationConf.name" con los
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 La operacion puede ser de dos tipos:
142 La operacion puede ser de dos tipos:
143
143
144 1. Un metodo propio de esta clase:
144 1. Un metodo propio de esta clase:
145
145
146 operation.type = "self"
146 operation.type = "self"
147
147
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 operation.type = "other".
149 operation.type = "other".
150
150
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 "addOperation" e identificado con el operation.id
152 "addOperation" e identificado con el operation.id
153
153
154
154
155 con el id de la operacion.
155 con el id de la operacion.
156
156
157 Input:
157 Input:
158
158
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160
160
161 """
161 """
162
162
163 if operationConf.type == 'self':
163 if operationConf.type == 'self':
164 sts = self.callMethod(operationConf.name, **kwargs)
164 sts = self.callMethod(operationConf.name, **kwargs)
165
165
166 if operationConf.type == 'other':
166 if operationConf.type == 'other':
167 sts = self.callObject(operationConf.id, **kwargs)
167 sts = self.callObject(operationConf.id, **kwargs)
168
168
169 return sts
169 return sts
170
170
171 def setInput(self, dataIn):
171 def setInput(self, dataIn):
172
172
173 self.dataIn = dataIn
173 self.dataIn = dataIn
174
174
175 def getOutput(self):
175 def getOutput(self):
176
176
177 return self.dataOut
177 return self.dataOut
178
178
179 class Operation():
179 class Operation():
180
180
181 """
181 """
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 acumulacion dentro de esta clase
184 acumulacion dentro de esta clase
185
185
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187
187
188 """
188 """
189
189
190 __buffer = None
190 __buffer = None
191 __isConfig = False
191 __isConfig = False
192
192
193 def __init__(self):
193 def __init__(self):
194
194
195 pass
195 pass
196
196
197 def run(self, dataIn, **kwargs):
197 def run(self, dataIn, **kwargs):
198
198
199 """
199 """
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201
201
202 Input:
202 Input:
203
203
204 dataIn : objeto del tipo JROData
204 dataIn : objeto del tipo JROData
205
205
206 Return:
206 Return:
207
207
208 None
208 None
209
209
210 Affected:
210 Affected:
211 __buffer : buffer de recepcion de datos.
211 __buffer : buffer de recepcion de datos.
212
212
213 """
213 """
214
214
215 raise ValueError, "ImplementedError"
215 raise ValueError, "ImplementedError"
216
216
217 class VoltageProc(ProcessingUnit):
217 class VoltageProc(ProcessingUnit):
218
218
219
219
220 def __init__(self):
220 def __init__(self):
221
221
222 self.objectDict = {}
222 self.objectDict = {}
223 self.dataOut = Voltage()
223 self.dataOut = Voltage()
224 self.flip = 1
224 self.flip = 1
225
225
226 def init(self):
226 def init(self):
227
227
228 self.dataOut.copy(self.dataIn)
228 self.dataOut.copy(self.dataIn)
229 # No necesita copiar en cada init() los atributos de dataIn
229 # No necesita copiar en cada init() los atributos de dataIn
230 # la copia deberia hacerse por cada nuevo bloque de datos
230 # la copia deberia hacerse por cada nuevo bloque de datos
231
231
232 def selectChannels(self, channelList):
232 def selectChannels(self, channelList):
233
233
234 channelIndexList = []
234 channelIndexList = []
235
235
236 for channel in channelList:
236 for channel in channelList:
237 index = self.dataOut.channelList.index(channel)
237 index = self.dataOut.channelList.index(channel)
238 channelIndexList.append(index)
238 channelIndexList.append(index)
239
239
240 self.selectChannelsByIndex(channelIndexList)
240 self.selectChannelsByIndex(channelIndexList)
241
241
242 def selectChannelsByIndex(self, channelIndexList):
242 def selectChannelsByIndex(self, channelIndexList):
243 """
243 """
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
245
245
246 Input:
246 Input:
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
248
248
249 Affected:
249 Affected:
250 self.dataOut.data
250 self.dataOut.data
251 self.dataOut.channelIndexList
251 self.dataOut.channelIndexList
252 self.dataOut.nChannels
252 self.dataOut.nChannels
253 self.dataOut.m_ProcessingHeader.totalSpectra
253 self.dataOut.m_ProcessingHeader.totalSpectra
254 self.dataOut.systemHeaderObj.numChannels
254 self.dataOut.systemHeaderObj.numChannels
255 self.dataOut.m_ProcessingHeader.blockSize
255 self.dataOut.m_ProcessingHeader.blockSize
256
256
257 Return:
257 Return:
258 None
258 None
259 """
259 """
260
260
261 for channelIndex in channelIndexList:
261 for channelIndex in channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
263 print channelIndexList
263 print channelIndexList
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
265
265
266 nChannels = len(channelIndexList)
266 nChannels = len(channelIndexList)
267
267
268 data = self.dataOut.data[channelIndexList,:]
268 data = self.dataOut.data[channelIndexList,:]
269
269
270 self.dataOut.data = data
270 self.dataOut.data = data
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 # self.dataOut.nChannels = nChannels
272 # self.dataOut.nChannels = nChannels
273
273
274 return 1
274 return 1
275
275
276 def selectHeights(self, minHei, maxHei):
276 def selectHeights(self, minHei=None, maxHei=None):
277 """
277 """
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
279 minHei <= height <= maxHei
279 minHei <= height <= maxHei
280
280
281 Input:
281 Input:
282 minHei : valor minimo de altura a considerar
282 minHei : valor minimo de altura a considerar
283 maxHei : valor maximo de altura a considerar
283 maxHei : valor maximo de altura a considerar
284
284
285 Affected:
285 Affected:
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
287
287
288 Return:
288 Return:
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
290 """
290 """
291
292 if minHei == None:
293 minHei = self.dataOut.heightList[0]
294
295 if maxHei == None:
296 maxHei = self.dataOut.heightList[-1]
297
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
299 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
293
300
301
294 if (maxHei > self.dataOut.heightList[-1]):
302 if (maxHei > self.dataOut.heightList[-1]):
295 maxHei = self.dataOut.heightList[-1]
303 maxHei = self.dataOut.heightList[-1]
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
304 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
297
305
298 minIndex = 0
306 minIndex = 0
299 maxIndex = 0
307 maxIndex = 0
300 heights = self.dataOut.heightList
308 heights = self.dataOut.heightList
301
309
302 inda = numpy.where(heights >= minHei)
310 inda = numpy.where(heights >= minHei)
303 indb = numpy.where(heights <= maxHei)
311 indb = numpy.where(heights <= maxHei)
304
312
305 try:
313 try:
306 minIndex = inda[0][0]
314 minIndex = inda[0][0]
307 except:
315 except:
308 minIndex = 0
316 minIndex = 0
309
317
310 try:
318 try:
311 maxIndex = indb[0][-1]
319 maxIndex = indb[0][-1]
312 except:
320 except:
313 maxIndex = len(heights)
321 maxIndex = len(heights)
314
322
315 self.selectHeightsByIndex(minIndex, maxIndex)
323 self.selectHeightsByIndex(minIndex, maxIndex)
316
324
317 return 1
325 return 1
318
326
319
327
320 def selectHeightsByIndex(self, minIndex, maxIndex):
328 def selectHeightsByIndex(self, minIndex, maxIndex):
321 """
329 """
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
330 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
323 minIndex <= index <= maxIndex
331 minIndex <= index <= maxIndex
324
332
325 Input:
333 Input:
326 minIndex : valor de indice minimo de altura a considerar
334 minIndex : valor de indice minimo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
335 maxIndex : valor de indice maximo de altura a considerar
328
336
329 Affected:
337 Affected:
330 self.dataOut.data
338 self.dataOut.data
331 self.dataOut.heightList
339 self.dataOut.heightList
332
340
333 Return:
341 Return:
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
342 1 si el metodo se ejecuto con exito caso contrario devuelve 0
335 """
343 """
336
344
337 if (minIndex < 0) or (minIndex > maxIndex):
345 if (minIndex < 0) or (minIndex > maxIndex):
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
346 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
339
347
340 if (maxIndex >= self.dataOut.nHeights):
348 if (maxIndex >= self.dataOut.nHeights):
341 maxIndex = self.dataOut.nHeights-1
349 maxIndex = self.dataOut.nHeights-1
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
350 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
343
351
344 nHeights = maxIndex - minIndex + 1
352 nHeights = maxIndex - minIndex + 1
345
353
346 #voltage
354 #voltage
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
355 data = self.dataOut.data[:,minIndex:maxIndex+1]
348
356
349 firstHeight = self.dataOut.heightList[minIndex]
357 firstHeight = self.dataOut.heightList[minIndex]
350
358
351 self.dataOut.data = data
359 self.dataOut.data = data
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
353
361
354 return 1
362 return 1
355
363
356
364
357 def filterByHeights(self, window):
365 def filterByHeights(self, window):
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
359
367
360 if window == None:
368 if window == None:
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
362
370
363 newdelta = deltaHeight * window
371 newdelta = deltaHeight * window
364 r = self.dataOut.data.shape[1] % window
372 r = self.dataOut.data.shape[1] % window
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
374 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
367 buffer = numpy.sum(buffer,2)
375 buffer = numpy.sum(buffer,2)
368 self.dataOut.data = buffer
376 self.dataOut.data = buffer
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
370 self.dataOut.windowOfFilter = window
378 self.dataOut.windowOfFilter = window
371
379
372 def deFlip(self):
380 def deFlip(self):
373 self.dataOut.data *= self.flip
381 self.dataOut.data *= self.flip
374 self.flip *= -1.
382 self.flip *= -1.
375
383
376
384
377 class CohInt(Operation):
385 class CohInt(Operation):
378
386
379 __isConfig = False
387 __isConfig = False
380
388
381 __profIndex = 0
389 __profIndex = 0
382 __withOverapping = False
390 __withOverapping = False
383
391
384 __byTime = False
392 __byTime = False
385 __initime = None
393 __initime = None
386 __lastdatatime = None
394 __lastdatatime = None
387 __integrationtime = None
395 __integrationtime = None
388
396
389 __buffer = None
397 __buffer = None
390
398
391 __dataReady = False
399 __dataReady = False
392
400
393 n = None
401 n = None
394
402
395
403
396 def __init__(self):
404 def __init__(self):
397
405
398 self.__isConfig = False
406 self.__isConfig = False
399
407
400 def setup(self, n=None, timeInterval=None, overlapping=False):
408 def setup(self, n=None, timeInterval=None, overlapping=False):
401 """
409 """
402 Set the parameters of the integration class.
410 Set the parameters of the integration class.
403
411
404 Inputs:
412 Inputs:
405
413
406 n : Number of coherent integrations
414 n : Number of coherent integrations
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
415 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
408 overlapping :
416 overlapping :
409
417
410 """
418 """
411
419
412 self.__initime = None
420 self.__initime = None
413 self.__lastdatatime = 0
421 self.__lastdatatime = 0
414 self.__buffer = None
422 self.__buffer = None
415 self.__dataReady = False
423 self.__dataReady = False
416
424
417
425
418 if n == None and timeInterval == None:
426 if n == None and timeInterval == None:
419 raise ValueError, "n or timeInterval should be specified ..."
427 raise ValueError, "n or timeInterval should be specified ..."
420
428
421 if n != None:
429 if n != None:
422 self.n = n
430 self.n = n
423 self.__byTime = False
431 self.__byTime = False
424 else:
432 else:
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
433 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
426 self.n = 9999
434 self.n = 9999
427 self.__byTime = True
435 self.__byTime = True
428
436
429 if overlapping:
437 if overlapping:
430 self.__withOverapping = True
438 self.__withOverapping = True
431 self.__buffer = None
439 self.__buffer = None
432 else:
440 else:
433 self.__withOverapping = False
441 self.__withOverapping = False
434 self.__buffer = 0
442 self.__buffer = 0
435
443
436 self.__profIndex = 0
444 self.__profIndex = 0
437
445
438 def putData(self, data):
446 def putData(self, data):
439
447
440 """
448 """
441 Add a profile to the __buffer and increase in one the __profileIndex
449 Add a profile to the __buffer and increase in one the __profileIndex
442
450
443 """
451 """
444
452
445 if not self.__withOverapping:
453 if not self.__withOverapping:
446 self.__buffer += data.copy()
454 self.__buffer += data.copy()
447 self.__profIndex += 1
455 self.__profIndex += 1
448 return
456 return
449
457
450 #Overlapping data
458 #Overlapping data
451 nChannels, nHeis = data.shape
459 nChannels, nHeis = data.shape
452 data = numpy.reshape(data, (1, nChannels, nHeis))
460 data = numpy.reshape(data, (1, nChannels, nHeis))
453
461
454 #If the buffer is empty then it takes the data value
462 #If the buffer is empty then it takes the data value
455 if self.__buffer == None:
463 if self.__buffer == None:
456 self.__buffer = data
464 self.__buffer = data
457 self.__profIndex += 1
465 self.__profIndex += 1
458 return
466 return
459
467
460 #If the buffer length is lower than n then stakcing the data value
468 #If the buffer length is lower than n then stakcing the data value
461 if self.__profIndex < self.n:
469 if self.__profIndex < self.n:
462 self.__buffer = numpy.vstack((self.__buffer, data))
470 self.__buffer = numpy.vstack((self.__buffer, data))
463 self.__profIndex += 1
471 self.__profIndex += 1
464 return
472 return
465
473
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
474 #If the buffer length is equal to n then replacing the last buffer value with the data value
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
475 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
468 self.__buffer[self.n-1] = data
476 self.__buffer[self.n-1] = data
469 self.__profIndex = self.n
477 self.__profIndex = self.n
470 return
478 return
471
479
472
480
473 def pushData(self):
481 def pushData(self):
474 """
482 """
475 Return the sum of the last profiles and the profiles used in the sum.
483 Return the sum of the last profiles and the profiles used in the sum.
476
484
477 Affected:
485 Affected:
478
486
479 self.__profileIndex
487 self.__profileIndex
480
488
481 """
489 """
482
490
483 if not self.__withOverapping:
491 if not self.__withOverapping:
484 data = self.__buffer
492 data = self.__buffer
485 n = self.__profIndex
493 n = self.__profIndex
486
494
487 self.__buffer = 0
495 self.__buffer = 0
488 self.__profIndex = 0
496 self.__profIndex = 0
489
497
490 return data, n
498 return data, n
491
499
492 #Integration with Overlapping
500 #Integration with Overlapping
493 data = numpy.sum(self.__buffer, axis=0)
501 data = numpy.sum(self.__buffer, axis=0)
494 n = self.__profIndex
502 n = self.__profIndex
495
503
496 return data, n
504 return data, n
497
505
498 def byProfiles(self, data):
506 def byProfiles(self, data):
499
507
500 self.__dataReady = False
508 self.__dataReady = False
501 avgdata = None
509 avgdata = None
502 n = None
510 n = None
503
511
504 self.putData(data)
512 self.putData(data)
505
513
506 if self.__profIndex == self.n:
514 if self.__profIndex == self.n:
507
515
508 avgdata, n = self.pushData()
516 avgdata, n = self.pushData()
509 self.__dataReady = True
517 self.__dataReady = True
510
518
511 return avgdata
519 return avgdata
512
520
513 def byTime(self, data, datatime):
521 def byTime(self, data, datatime):
514
522
515 self.__dataReady = False
523 self.__dataReady = False
516 avgdata = None
524 avgdata = None
517 n = None
525 n = None
518
526
519 self.putData(data)
527 self.putData(data)
520
528
521 if (datatime - self.__initime) >= self.__integrationtime:
529 if (datatime - self.__initime) >= self.__integrationtime:
522 avgdata, n = self.pushData()
530 avgdata, n = self.pushData()
523 self.n = n
531 self.n = n
524 self.__dataReady = True
532 self.__dataReady = True
525
533
526 return avgdata
534 return avgdata
527
535
528 def integrate(self, data, datatime=None):
536 def integrate(self, data, datatime=None):
529
537
530 if self.__initime == None:
538 if self.__initime == None:
531 self.__initime = datatime
539 self.__initime = datatime
532
540
533 if self.__byTime:
541 if self.__byTime:
534 avgdata = self.byTime(data, datatime)
542 avgdata = self.byTime(data, datatime)
535 else:
543 else:
536 avgdata = self.byProfiles(data)
544 avgdata = self.byProfiles(data)
537
545
538
546
539 self.__lastdatatime = datatime
547 self.__lastdatatime = datatime
540
548
541 if avgdata == None:
549 if avgdata == None:
542 return None, None
550 return None, None
543
551
544 avgdatatime = self.__initime
552 avgdatatime = self.__initime
545
553
546 deltatime = datatime -self.__lastdatatime
554 deltatime = datatime -self.__lastdatatime
547
555
548 if not self.__withOverapping:
556 if not self.__withOverapping:
549 self.__initime = datatime
557 self.__initime = datatime
550 else:
558 else:
551 self.__initime += deltatime
559 self.__initime += deltatime
552
560
553 return avgdata, avgdatatime
561 return avgdata, avgdatatime
554
562
555 def run(self, dataOut, **kwargs):
563 def run(self, dataOut, **kwargs):
556
564
557 if not self.__isConfig:
565 if not self.__isConfig:
558 self.setup(**kwargs)
566 self.setup(**kwargs)
559 self.__isConfig = True
567 self.__isConfig = True
560
568
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
569 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562
570
563 # dataOut.timeInterval *= n
571 # dataOut.timeInterval *= n
564 dataOut.flagNoData = True
572 dataOut.flagNoData = True
565
573
566 if self.__dataReady:
574 if self.__dataReady:
567 dataOut.data = avgdata
575 dataOut.data = avgdata
568 dataOut.nCohInt *= self.n
576 dataOut.nCohInt *= self.n
569 dataOut.utctime = avgdatatime
577 dataOut.utctime = avgdatatime
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
578 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
571 dataOut.flagNoData = False
579 dataOut.flagNoData = False
572
580
573
581
574 class Decoder(Operation):
582 class Decoder(Operation):
575
583
576 __isConfig = False
584 __isConfig = False
577 __profIndex = 0
585 __profIndex = 0
578
586
579 code = None
587 code = None
580
588
581 nCode = None
589 nCode = None
582 nBaud = None
590 nBaud = None
583
591
584 def __init__(self):
592 def __init__(self):
585
593
586 self.__isConfig = False
594 self.__isConfig = False
587
595
588 def setup(self, code, shape):
596 def setup(self, code, shape):
589
597
590 self.__profIndex = 0
598 self.__profIndex = 0
591
599
592 self.code = code
600 self.code = code
593
601
594 self.nCode = len(code)
602 self.nCode = len(code)
595 self.nBaud = len(code[0])
603 self.nBaud = len(code[0])
596
604
597 self.__nChannels, self.__nHeis = shape
605 self.__nChannels, self.__nHeis = shape
598
606
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
607 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
600
608
601 __codeBuffer[:,0:self.nBaud] = self.code
609 __codeBuffer[:,0:self.nBaud] = self.code
602
610
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
611 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
604
612
605 self.ndatadec = self.__nHeis - self.nBaud + 1
613 self.ndatadec = self.__nHeis - self.nBaud + 1
606
614
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
615 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
608
616
609 def convolutionInFreq(self, data):
617 def convolutionInFreq(self, data):
610
618
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
619 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
612
620
613 fft_data = numpy.fft.fft(data, axis=1)
621 fft_data = numpy.fft.fft(data, axis=1)
614
622
615 conv = fft_data*fft_code
623 conv = fft_data*fft_code
616
624
617 data = numpy.fft.ifft(conv,axis=1)
625 data = numpy.fft.ifft(conv,axis=1)
618
626
619 datadec = data[:,:-self.nBaud+1]
627 datadec = data[:,:-self.nBaud+1]
620
628
621 return datadec
629 return datadec
622
630
623 def convolutionInFreqOpt(self, data):
631 def convolutionInFreqOpt(self, data):
624
632
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
633 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
626
634
627 data = cfunctions.decoder(fft_code, data)
635 data = cfunctions.decoder(fft_code, data)
628
636
629 datadec = data[:,:-self.nBaud+1]
637 datadec = data[:,:-self.nBaud+1]
630
638
631 return datadec
639 return datadec
632
640
633 def convolutionInTime(self, data):
641 def convolutionInTime(self, data):
634
642
635 code = self.code[self.__profIndex]
643 code = self.code[self.__profIndex]
636
644
637 for i in range(self.__nChannels):
645 for i in range(self.__nChannels):
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
646 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
639
647
640 return self.datadecTime
648 return self.datadecTime
641
649
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
650 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
643
651
644 if not self.__isConfig:
652 if not self.__isConfig:
645
653
646 if code == None:
654 if code == None:
647 code = dataOut.code
655 code = dataOut.code
648 else:
656 else:
649 code = numpy.array(code).reshape(nCode,nBaud)
657 code = numpy.array(code).reshape(nCode,nBaud)
650 dataOut.code = code
658 dataOut.code = code
651 dataOut.nCode = nCode
659 dataOut.nCode = nCode
652 dataOut.nBaud = nBaud
660 dataOut.nBaud = nBaud
653
661
654 if code == None:
662 if code == None:
655 return 1
663 return 1
656
664
657 self.setup(code, dataOut.data.shape)
665 self.setup(code, dataOut.data.shape)
658 self.__isConfig = True
666 self.__isConfig = True
659
667
660 if mode == 0:
668 if mode == 0:
661 datadec = self.convolutionInTime(dataOut.data)
669 datadec = self.convolutionInTime(dataOut.data)
662
670
663 if mode == 1:
671 if mode == 1:
664 datadec = self.convolutionInFreq(dataOut.data)
672 datadec = self.convolutionInFreq(dataOut.data)
665
673
666 if mode == 2:
674 if mode == 2:
667 datadec = self.convolutionInFreqOpt(dataOut.data)
675 datadec = self.convolutionInFreqOpt(dataOut.data)
668
676
669 dataOut.data = datadec
677 dataOut.data = datadec
670
678
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
679 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
672
680
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
681 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
674
682
675 if self.__profIndex == self.nCode-1:
683 if self.__profIndex == self.nCode-1:
676 self.__profIndex = 0
684 self.__profIndex = 0
677 return 1
685 return 1
678
686
679 self.__profIndex += 1
687 self.__profIndex += 1
680
688
681 return 1
689 return 1
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
690 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
683
691
684
692
685
693
686 class SpectraProc(ProcessingUnit):
694 class SpectraProc(ProcessingUnit):
687
695
688 def __init__(self):
696 def __init__(self):
689
697
690 self.objectDict = {}
698 self.objectDict = {}
691 self.buffer = None
699 self.buffer = None
692 self.firstdatatime = None
700 self.firstdatatime = None
693 self.profIndex = 0
701 self.profIndex = 0
694 self.dataOut = Spectra()
702 self.dataOut = Spectra()
695
703
696 def __updateObjFromInput(self):
704 def __updateObjFromInput(self):
697
705
698 self.dataOut.timeZone = self.dataIn.timeZone
706 self.dataOut.timeZone = self.dataIn.timeZone
699 self.dataOut.dstFlag = self.dataIn.dstFlag
707 self.dataOut.dstFlag = self.dataIn.dstFlag
700 self.dataOut.errorCount = self.dataIn.errorCount
708 self.dataOut.errorCount = self.dataIn.errorCount
701 self.dataOut.useLocalTime = self.dataIn.useLocalTime
709 self.dataOut.useLocalTime = self.dataIn.useLocalTime
702
710
703 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
711 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
704 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
712 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
705 self.dataOut.channelList = self.dataIn.channelList
713 self.dataOut.channelList = self.dataIn.channelList
706 self.dataOut.heightList = self.dataIn.heightList
714 self.dataOut.heightList = self.dataIn.heightList
707 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
715 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
708 # self.dataOut.nHeights = self.dataIn.nHeights
716 # self.dataOut.nHeights = self.dataIn.nHeights
709 # self.dataOut.nChannels = self.dataIn.nChannels
717 # self.dataOut.nChannels = self.dataIn.nChannels
710 self.dataOut.nBaud = self.dataIn.nBaud
718 self.dataOut.nBaud = self.dataIn.nBaud
711 self.dataOut.nCode = self.dataIn.nCode
719 self.dataOut.nCode = self.dataIn.nCode
712 self.dataOut.code = self.dataIn.code
720 self.dataOut.code = self.dataIn.code
713 self.dataOut.nProfiles = self.dataOut.nFFTPoints
721 self.dataOut.nProfiles = self.dataOut.nFFTPoints
714 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
722 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
715 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
723 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
716 self.dataOut.utctime = self.firstdatatime
724 self.dataOut.utctime = self.firstdatatime
717 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
725 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
718 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
726 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
719 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
727 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
720 self.dataOut.nCohInt = self.dataIn.nCohInt
728 self.dataOut.nCohInt = self.dataIn.nCohInt
721 self.dataOut.nIncohInt = 1
729 self.dataOut.nIncohInt = 1
722 self.dataOut.ippSeconds = self.dataIn.ippSeconds
730 self.dataOut.ippSeconds = self.dataIn.ippSeconds
723 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
731 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
724
732
725 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
733 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
726
734
727 def __getFft(self):
735 def __getFft(self):
728 """
736 """
729 Convierte valores de Voltaje a Spectra
737 Convierte valores de Voltaje a Spectra
730
738
731 Affected:
739 Affected:
732 self.dataOut.data_spc
740 self.dataOut.data_spc
733 self.dataOut.data_cspc
741 self.dataOut.data_cspc
734 self.dataOut.data_dc
742 self.dataOut.data_dc
735 self.dataOut.heightList
743 self.dataOut.heightList
736 self.profIndex
744 self.profIndex
737 self.buffer
745 self.buffer
738 self.dataOut.flagNoData
746 self.dataOut.flagNoData
739 """
747 """
740 fft_volt = numpy.fft.fft(self.buffer,axis=1)
748 fft_volt = numpy.fft.fft(self.buffer,axis=1)
741 fft_volt = fft_volt.astype(numpy.dtype('complex'))
749 fft_volt = fft_volt.astype(numpy.dtype('complex'))
742 dc = fft_volt[:,0,:]
750 dc = fft_volt[:,0,:]
743
751
744 #calculo de self-spectra
752 #calculo de self-spectra
745 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
753 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
746 spc = fft_volt * numpy.conjugate(fft_volt)
754 spc = fft_volt * numpy.conjugate(fft_volt)
747 spc = spc.real
755 spc = spc.real
748
756
749 blocksize = 0
757 blocksize = 0
750 blocksize += dc.size
758 blocksize += dc.size
751 blocksize += spc.size
759 blocksize += spc.size
752
760
753 cspc = None
761 cspc = None
754 pairIndex = 0
762 pairIndex = 0
755 if self.dataOut.pairsList != None:
763 if self.dataOut.pairsList != None:
756 #calculo de cross-spectra
764 #calculo de cross-spectra
757 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
765 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
758 for pair in self.dataOut.pairsList:
766 for pair in self.dataOut.pairsList:
759 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
767 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
760 pairIndex += 1
768 pairIndex += 1
761 blocksize += cspc.size
769 blocksize += cspc.size
762
770
763 self.dataOut.data_spc = spc
771 self.dataOut.data_spc = spc
764 self.dataOut.data_cspc = cspc
772 self.dataOut.data_cspc = cspc
765 self.dataOut.data_dc = dc
773 self.dataOut.data_dc = dc
766 self.dataOut.blockSize = blocksize
774 self.dataOut.blockSize = blocksize
767 self.dataOut.flagShiftFFT = False
775 self.dataOut.flagShiftFFT = False
768
776
769 def init(self, nFFTPoints=None, pairsList=None):
777 def init(self, nFFTPoints=None, pairsList=None):
770
778
771 self.dataOut.flagNoData = True
779 self.dataOut.flagNoData = True
772
780
773 if self.dataIn.type == "Spectra":
781 if self.dataIn.type == "Spectra":
774 self.dataOut.copy(self.dataIn)
782 self.dataOut.copy(self.dataIn)
775 return
783 return
776
784
777 if self.dataIn.type == "Voltage":
785 if self.dataIn.type == "Voltage":
778
786
779 if nFFTPoints == None:
787 if nFFTPoints == None:
780 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
788 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
781
789
782 if pairsList == None:
790 if pairsList == None:
783 nPairs = 0
791 nPairs = 0
784 else:
792 else:
785 nPairs = len(pairsList)
793 nPairs = len(pairsList)
786
794
787 self.dataOut.nFFTPoints = nFFTPoints
795 self.dataOut.nFFTPoints = nFFTPoints
788 self.dataOut.pairsList = pairsList
796 self.dataOut.pairsList = pairsList
789 self.dataOut.nPairs = nPairs
797 self.dataOut.nPairs = nPairs
790
798
791 if self.buffer == None:
799 if self.buffer == None:
792 self.buffer = numpy.zeros((self.dataIn.nChannels,
800 self.buffer = numpy.zeros((self.dataIn.nChannels,
793 self.dataOut.nFFTPoints,
801 self.dataOut.nFFTPoints,
794 self.dataIn.nHeights),
802 self.dataIn.nHeights),
795 dtype='complex')
803 dtype='complex')
796
804
797
805
798 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
806 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
799 self.profIndex += 1
807 self.profIndex += 1
800
808
801 if self.firstdatatime == None:
809 if self.firstdatatime == None:
802 self.firstdatatime = self.dataIn.utctime
810 self.firstdatatime = self.dataIn.utctime
803
811
804 if self.profIndex == self.dataOut.nFFTPoints:
812 if self.profIndex == self.dataOut.nFFTPoints:
805 self.__updateObjFromInput()
813 self.__updateObjFromInput()
806 self.__getFft()
814 self.__getFft()
807
815
808 self.dataOut.flagNoData = False
816 self.dataOut.flagNoData = False
809
817
810 self.buffer = None
818 self.buffer = None
811 self.firstdatatime = None
819 self.firstdatatime = None
812 self.profIndex = 0
820 self.profIndex = 0
813
821
814 return
822 return
815
823
816 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
824 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
817
825
818 def selectChannels(self, channelList):
826 def selectChannels(self, channelList):
819
827
820 channelIndexList = []
828 channelIndexList = []
821
829
822 for channel in channelList:
830 for channel in channelList:
823 index = self.dataOut.channelList.index(channel)
831 index = self.dataOut.channelList.index(channel)
824 channelIndexList.append(index)
832 channelIndexList.append(index)
825
833
826 self.selectChannelsByIndex(channelIndexList)
834 self.selectChannelsByIndex(channelIndexList)
827
835
828 def selectChannelsByIndex(self, channelIndexList):
836 def selectChannelsByIndex(self, channelIndexList):
829 """
837 """
830 Selecciona un bloque de datos en base a canales segun el channelIndexList
838 Selecciona un bloque de datos en base a canales segun el channelIndexList
831
839
832 Input:
840 Input:
833 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
841 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
834
842
835 Affected:
843 Affected:
836 self.dataOut.data_spc
844 self.dataOut.data_spc
837 self.dataOut.channelIndexList
845 self.dataOut.channelIndexList
838 self.dataOut.nChannels
846 self.dataOut.nChannels
839
847
840 Return:
848 Return:
841 None
849 None
842 """
850 """
843
851
844 for channelIndex in channelIndexList:
852 for channelIndex in channelIndexList:
845 if channelIndex not in self.dataOut.channelIndexList:
853 if channelIndex not in self.dataOut.channelIndexList:
846 print channelIndexList
854 print channelIndexList
847 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
855 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
848
856
849 nChannels = len(channelIndexList)
857 nChannels = len(channelIndexList)
850
858
851 data_spc = self.dataOut.data_spc[channelIndexList,:]
859 data_spc = self.dataOut.data_spc[channelIndexList,:]
852
860
853 self.dataOut.data_spc = data_spc
861 self.dataOut.data_spc = data_spc
854 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
862 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
855 # self.dataOut.nChannels = nChannels
863 # self.dataOut.nChannels = nChannels
856
864
857 return 1
865 return 1
858
866
859 def selectHeights(self, minHei, maxHei):
867 def selectHeights(self, minHei, maxHei):
860 """
868 """
861 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
869 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
862 minHei <= height <= maxHei
870 minHei <= height <= maxHei
863
871
864 Input:
872 Input:
865 minHei : valor minimo de altura a considerar
873 minHei : valor minimo de altura a considerar
866 maxHei : valor maximo de altura a considerar
874 maxHei : valor maximo de altura a considerar
867
875
868 Affected:
876 Affected:
869 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
877 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
870
878
871 Return:
879 Return:
872 1 si el metodo se ejecuto con exito caso contrario devuelve 0
880 1 si el metodo se ejecuto con exito caso contrario devuelve 0
873 """
881 """
874 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
882 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
875 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
883 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
876
884
877 if (maxHei > self.dataOut.heightList[-1]):
885 if (maxHei > self.dataOut.heightList[-1]):
878 maxHei = self.dataOut.heightList[-1]
886 maxHei = self.dataOut.heightList[-1]
879 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
887 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
880
888
881 minIndex = 0
889 minIndex = 0
882 maxIndex = 0
890 maxIndex = 0
883 heights = self.dataOut.heightList
891 heights = self.dataOut.heightList
884
892
885 inda = numpy.where(heights >= minHei)
893 inda = numpy.where(heights >= minHei)
886 indb = numpy.where(heights <= maxHei)
894 indb = numpy.where(heights <= maxHei)
887
895
888 try:
896 try:
889 minIndex = inda[0][0]
897 minIndex = inda[0][0]
890 except:
898 except:
891 minIndex = 0
899 minIndex = 0
892
900
893 try:
901 try:
894 maxIndex = indb[0][-1]
902 maxIndex = indb[0][-1]
895 except:
903 except:
896 maxIndex = len(heights)
904 maxIndex = len(heights)
897
905
898 self.selectHeightsByIndex(minIndex, maxIndex)
906 self.selectHeightsByIndex(minIndex, maxIndex)
899
907
900 return 1
908 return 1
901
909
902
910
903 def selectHeightsByIndex(self, minIndex, maxIndex):
911 def selectHeightsByIndex(self, minIndex, maxIndex):
904 """
912 """
905 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
913 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
906 minIndex <= index <= maxIndex
914 minIndex <= index <= maxIndex
907
915
908 Input:
916 Input:
909 minIndex : valor de indice minimo de altura a considerar
917 minIndex : valor de indice minimo de altura a considerar
910 maxIndex : valor de indice maximo de altura a considerar
918 maxIndex : valor de indice maximo de altura a considerar
911
919
912 Affected:
920 Affected:
913 self.dataOut.data_spc
921 self.dataOut.data_spc
914 self.dataOut.data_cspc
922 self.dataOut.data_cspc
915 self.dataOut.data_dc
923 self.dataOut.data_dc
916 self.dataOut.heightList
924 self.dataOut.heightList
917
925
918 Return:
926 Return:
919 1 si el metodo se ejecuto con exito caso contrario devuelve 0
927 1 si el metodo se ejecuto con exito caso contrario devuelve 0
920 """
928 """
921
929
922 if (minIndex < 0) or (minIndex > maxIndex):
930 if (minIndex < 0) or (minIndex > maxIndex):
923 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
931 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
924
932
925 if (maxIndex >= self.dataOut.nHeights):
933 if (maxIndex >= self.dataOut.nHeights):
926 maxIndex = self.dataOut.nHeights-1
934 maxIndex = self.dataOut.nHeights-1
927 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
935 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
928
936
929 nHeights = maxIndex - minIndex + 1
937 nHeights = maxIndex - minIndex + 1
930
938
931 #Spectra
939 #Spectra
932 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
940 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
933
941
934 data_cspc = None
942 data_cspc = None
935 if self.dataOut.data_cspc != None:
943 if self.dataOut.data_cspc != None:
936 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
944 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
937
945
938 data_dc = None
946 data_dc = None
939 if self.dataOut.data_dc != None:
947 if self.dataOut.data_dc != None:
940 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
948 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
941
949
942 self.dataOut.data_spc = data_spc
950 self.dataOut.data_spc = data_spc
943 self.dataOut.data_cspc = data_cspc
951 self.dataOut.data_cspc = data_cspc
944 self.dataOut.data_dc = data_dc
952 self.dataOut.data_dc = data_dc
945
953
946 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
954 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
947
955
948 return 1
956 return 1
949
957
950 def removeDC(self, mode = 1):
958 def removeDC(self, mode = 1):
951
959
952 dc_index = 0
960 dc_index = 0
953 freq_index = numpy.array([-2,-1,1,2])
961 freq_index = numpy.array([-2,-1,1,2])
954 data_spc = self.dataOut.data_spc
962 data_spc = self.dataOut.data_spc
955 data_cspc = self.dataOut.data_cspc
963 data_cspc = self.dataOut.data_cspc
956 data_dc = self.dataOut.data_dc
964 data_dc = self.dataOut.data_dc
957
965
958 if self.dataOut.flagShiftFFT:
966 if self.dataOut.flagShiftFFT:
959 dc_index += self.dataOut.nFFTPoints/2
967 dc_index += self.dataOut.nFFTPoints/2
960 freq_index += self.dataOut.nFFTPoints/2
968 freq_index += self.dataOut.nFFTPoints/2
961
969
962 if mode == 1:
970 if mode == 1:
963 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
971 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
964 if data_cspc != None:
972 if data_cspc != None:
965 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
973 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
966 return 1
974 return 1
967
975
968 if mode == 2:
976 if mode == 2:
969 pass
977 pass
970
978
971 if mode == 3:
979 if mode == 3:
972 pass
980 pass
973
981
974 raise ValueError, "mode parameter has to be 1, 2 or 3"
982 raise ValueError, "mode parameter has to be 1, 2 or 3"
975
983
976 def removeInterference(self):
984 def removeInterference(self):
977
985
978 pass
986 pass
979
987
980
988
981 class IncohInt(Operation):
989 class IncohInt(Operation):
982
990
983
991
984 __profIndex = 0
992 __profIndex = 0
985 __withOverapping = False
993 __withOverapping = False
986
994
987 __byTime = False
995 __byTime = False
988 __initime = None
996 __initime = None
989 __lastdatatime = None
997 __lastdatatime = None
990 __integrationtime = None
998 __integrationtime = None
991
999
992 __buffer_spc = None
1000 __buffer_spc = None
993 __buffer_cspc = None
1001 __buffer_cspc = None
994 __buffer_dc = None
1002 __buffer_dc = None
995
1003
996 __dataReady = False
1004 __dataReady = False
997
1005
998 __timeInterval = None
1006 __timeInterval = None
999
1007
1000 n = None
1008 n = None
1001
1009
1002
1010
1003
1011
1004 def __init__(self):
1012 def __init__(self):
1005
1013
1006 self.__isConfig = False
1014 self.__isConfig = False
1007
1015
1008 def setup(self, n=None, timeInterval=None, overlapping=False):
1016 def setup(self, n=None, timeInterval=None, overlapping=False):
1009 """
1017 """
1010 Set the parameters of the integration class.
1018 Set the parameters of the integration class.
1011
1019
1012 Inputs:
1020 Inputs:
1013
1021
1014 n : Number of coherent integrations
1022 n : Number of coherent integrations
1015 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1023 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1016 overlapping :
1024 overlapping :
1017
1025
1018 """
1026 """
1019
1027
1020 self.__initime = None
1028 self.__initime = None
1021 self.__lastdatatime = 0
1029 self.__lastdatatime = 0
1022 self.__buffer_spc = None
1030 self.__buffer_spc = None
1023 self.__buffer_cspc = None
1031 self.__buffer_cspc = None
1024 self.__buffer_dc = None
1032 self.__buffer_dc = None
1025 self.__dataReady = False
1033 self.__dataReady = False
1026
1034
1027
1035
1028 if n == None and timeInterval == None:
1036 if n == None and timeInterval == None:
1029 raise ValueError, "n or timeInterval should be specified ..."
1037 raise ValueError, "n or timeInterval should be specified ..."
1030
1038
1031 if n != None:
1039 if n != None:
1032 self.n = n
1040 self.n = n
1033 self.__byTime = False
1041 self.__byTime = False
1034 else:
1042 else:
1035 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1043 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1036 self.n = 9999
1044 self.n = 9999
1037 self.__byTime = True
1045 self.__byTime = True
1038
1046
1039 if overlapping:
1047 if overlapping:
1040 self.__withOverapping = True
1048 self.__withOverapping = True
1041 else:
1049 else:
1042 self.__withOverapping = False
1050 self.__withOverapping = False
1043 self.__buffer_spc = 0
1051 self.__buffer_spc = 0
1044 self.__buffer_cspc = 0
1052 self.__buffer_cspc = 0
1045 self.__buffer_dc = 0
1053 self.__buffer_dc = 0
1046
1054
1047 self.__profIndex = 0
1055 self.__profIndex = 0
1048
1056
1049 def putData(self, data_spc, data_cspc, data_dc):
1057 def putData(self, data_spc, data_cspc, data_dc):
1050
1058
1051 """
1059 """
1052 Add a profile to the __buffer_spc and increase in one the __profileIndex
1060 Add a profile to the __buffer_spc and increase in one the __profileIndex
1053
1061
1054 """
1062 """
1055
1063
1056 if not self.__withOverapping:
1064 if not self.__withOverapping:
1057 self.__buffer_spc += data_spc
1065 self.__buffer_spc += data_spc
1058
1066
1059 if data_cspc == None:
1067 if data_cspc == None:
1060 self.__buffer_cspc = None
1068 self.__buffer_cspc = None
1061 else:
1069 else:
1062 self.__buffer_cspc += data_cspc
1070 self.__buffer_cspc += data_cspc
1063
1071
1064 if data_dc == None:
1072 if data_dc == None:
1065 self.__buffer_dc = None
1073 self.__buffer_dc = None
1066 else:
1074 else:
1067 self.__buffer_dc += data_dc
1075 self.__buffer_dc += data_dc
1068
1076
1069 self.__profIndex += 1
1077 self.__profIndex += 1
1070 return
1078 return
1071
1079
1072 #Overlapping data
1080 #Overlapping data
1073 nChannels, nFFTPoints, nHeis = data_spc.shape
1081 nChannels, nFFTPoints, nHeis = data_spc.shape
1074 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1082 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1075 if data_cspc != None:
1083 if data_cspc != None:
1076 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1084 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1077 if data_dc != None:
1085 if data_dc != None:
1078 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1086 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1079
1087
1080 #If the buffer is empty then it takes the data value
1088 #If the buffer is empty then it takes the data value
1081 if self.__buffer_spc == None:
1089 if self.__buffer_spc == None:
1082 self.__buffer_spc = data_spc
1090 self.__buffer_spc = data_spc
1083
1091
1084 if data_cspc == None:
1092 if data_cspc == None:
1085 self.__buffer_cspc = None
1093 self.__buffer_cspc = None
1086 else:
1094 else:
1087 self.__buffer_cspc += data_cspc
1095 self.__buffer_cspc += data_cspc
1088
1096
1089 if data_dc == None:
1097 if data_dc == None:
1090 self.__buffer_dc = None
1098 self.__buffer_dc = None
1091 else:
1099 else:
1092 self.__buffer_dc += data_dc
1100 self.__buffer_dc += data_dc
1093
1101
1094 self.__profIndex += 1
1102 self.__profIndex += 1
1095 return
1103 return
1096
1104
1097 #If the buffer length is lower than n then stakcing the data value
1105 #If the buffer length is lower than n then stakcing the data value
1098 if self.__profIndex < self.n:
1106 if self.__profIndex < self.n:
1099 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1107 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1100
1108
1101 if data_cspc != None:
1109 if data_cspc != None:
1102 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1110 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1103
1111
1104 if data_dc != None:
1112 if data_dc != None:
1105 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1113 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1106
1114
1107 self.__profIndex += 1
1115 self.__profIndex += 1
1108 return
1116 return
1109
1117
1110 #If the buffer length is equal to n then replacing the last buffer value with the data value
1118 #If the buffer length is equal to n then replacing the last buffer value with the data value
1111 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1119 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1112 self.__buffer_spc[self.n-1] = data_spc
1120 self.__buffer_spc[self.n-1] = data_spc
1113
1121
1114 if data_cspc != None:
1122 if data_cspc != None:
1115 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1123 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1116 self.__buffer_cspc[self.n-1] = data_cspc
1124 self.__buffer_cspc[self.n-1] = data_cspc
1117
1125
1118 if data_dc != None:
1126 if data_dc != None:
1119 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1127 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1120 self.__buffer_dc[self.n-1] = data_dc
1128 self.__buffer_dc[self.n-1] = data_dc
1121
1129
1122 self.__profIndex = self.n
1130 self.__profIndex = self.n
1123 return
1131 return
1124
1132
1125
1133
1126 def pushData(self):
1134 def pushData(self):
1127 """
1135 """
1128 Return the sum of the last profiles and the profiles used in the sum.
1136 Return the sum of the last profiles and the profiles used in the sum.
1129
1137
1130 Affected:
1138 Affected:
1131
1139
1132 self.__profileIndex
1140 self.__profileIndex
1133
1141
1134 """
1142 """
1135 data_spc = None
1143 data_spc = None
1136 data_cspc = None
1144 data_cspc = None
1137 data_dc = None
1145 data_dc = None
1138
1146
1139 if not self.__withOverapping:
1147 if not self.__withOverapping:
1140 data_spc = self.__buffer_spc
1148 data_spc = self.__buffer_spc
1141 data_cspc = self.__buffer_cspc
1149 data_cspc = self.__buffer_cspc
1142 data_dc = self.__buffer_dc
1150 data_dc = self.__buffer_dc
1143
1151
1144 n = self.__profIndex
1152 n = self.__profIndex
1145
1153
1146 self.__buffer_spc = 0
1154 self.__buffer_spc = 0
1147 self.__buffer_cspc = 0
1155 self.__buffer_cspc = 0
1148 self.__buffer_dc = 0
1156 self.__buffer_dc = 0
1149 self.__profIndex = 0
1157 self.__profIndex = 0
1150
1158
1151 return data_spc, data_cspc, data_dc, n
1159 return data_spc, data_cspc, data_dc, n
1152
1160
1153 #Integration with Overlapping
1161 #Integration with Overlapping
1154 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1162 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1155
1163
1156 if self.__buffer_cspc != None:
1164 if self.__buffer_cspc != None:
1157 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1165 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1158
1166
1159 if self.__buffer_dc != None:
1167 if self.__buffer_dc != None:
1160 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1168 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1161
1169
1162 n = self.__profIndex
1170 n = self.__profIndex
1163
1171
1164 return data_spc, data_cspc, data_dc, n
1172 return data_spc, data_cspc, data_dc, n
1165
1173
1166 def byProfiles(self, *args):
1174 def byProfiles(self, *args):
1167
1175
1168 self.__dataReady = False
1176 self.__dataReady = False
1169 avgdata_spc = None
1177 avgdata_spc = None
1170 avgdata_cspc = None
1178 avgdata_cspc = None
1171 avgdata_dc = None
1179 avgdata_dc = None
1172 n = None
1180 n = None
1173
1181
1174 self.putData(*args)
1182 self.putData(*args)
1175
1183
1176 if self.__profIndex == self.n:
1184 if self.__profIndex == self.n:
1177
1185
1178 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1186 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1179 self.__dataReady = True
1187 self.__dataReady = True
1180
1188
1181 return avgdata_spc, avgdata_cspc, avgdata_dc
1189 return avgdata_spc, avgdata_cspc, avgdata_dc
1182
1190
1183 def byTime(self, datatime, *args):
1191 def byTime(self, datatime, *args):
1184
1192
1185 self.__dataReady = False
1193 self.__dataReady = False
1186 avgdata_spc = None
1194 avgdata_spc = None
1187 avgdata_cspc = None
1195 avgdata_cspc = None
1188 avgdata_dc = None
1196 avgdata_dc = None
1189 n = None
1197 n = None
1190
1198
1191 self.putData(*args)
1199 self.putData(*args)
1192
1200
1193 if (datatime - self.__initime) >= self.__integrationtime:
1201 if (datatime - self.__initime) >= self.__integrationtime:
1194 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1202 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1195 self.n = n
1203 self.n = n
1196 self.__dataReady = True
1204 self.__dataReady = True
1197
1205
1198 return avgdata_spc, avgdata_cspc, avgdata_dc
1206 return avgdata_spc, avgdata_cspc, avgdata_dc
1199
1207
1200 def integrate(self, datatime, *args):
1208 def integrate(self, datatime, *args):
1201
1209
1202 if self.__initime == None:
1210 if self.__initime == None:
1203 self.__initime = datatime
1211 self.__initime = datatime
1204
1212
1205 if self.__byTime:
1213 if self.__byTime:
1206 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1214 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1207 else:
1215 else:
1208 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1216 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1209
1217
1210 self.__lastdatatime = datatime
1218 self.__lastdatatime = datatime
1211
1219
1212 if avgdata_spc == None:
1220 if avgdata_spc == None:
1213 return None, None, None, None
1221 return None, None, None, None
1214
1222
1215 avgdatatime = self.__initime
1223 avgdatatime = self.__initime
1216 try:
1224 try:
1217 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1225 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1218 except:
1226 except:
1219 self.__timeInterval = self.__lastdatatime - self.__initime
1227 self.__timeInterval = self.__lastdatatime - self.__initime
1220
1228
1221 deltatime = datatime -self.__lastdatatime
1229 deltatime = datatime -self.__lastdatatime
1222
1230
1223 if not self.__withOverapping:
1231 if not self.__withOverapping:
1224 self.__initime = datatime
1232 self.__initime = datatime
1225 else:
1233 else:
1226 self.__initime += deltatime
1234 self.__initime += deltatime
1227
1235
1228 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1236 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1229
1237
1230 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1238 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1231
1239
1232 if n==1:
1240 if n==1:
1233 dataOut.flagNoData = False
1241 dataOut.flagNoData = False
1234 return
1242 return
1235
1243
1236 if not self.__isConfig:
1244 if not self.__isConfig:
1237 self.setup(n, timeInterval, overlapping)
1245 self.setup(n, timeInterval, overlapping)
1238 self.__isConfig = True
1246 self.__isConfig = True
1239
1247
1240 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1248 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1241 dataOut.data_spc,
1249 dataOut.data_spc,
1242 dataOut.data_cspc,
1250 dataOut.data_cspc,
1243 dataOut.data_dc)
1251 dataOut.data_dc)
1244
1252
1245 # dataOut.timeInterval *= n
1253 # dataOut.timeInterval *= n
1246 dataOut.flagNoData = True
1254 dataOut.flagNoData = True
1247
1255
1248 if self.__dataReady:
1256 if self.__dataReady:
1249
1257
1250 dataOut.data_spc = avgdata_spc
1258 dataOut.data_spc = avgdata_spc
1251 dataOut.data_cspc = avgdata_cspc
1259 dataOut.data_cspc = avgdata_cspc
1252 dataOut.data_dc = avgdata_dc
1260 dataOut.data_dc = avgdata_dc
1253
1261
1254 dataOut.nIncohInt *= self.n
1262 dataOut.nIncohInt *= self.n
1255 dataOut.utctime = avgdatatime
1263 dataOut.utctime = avgdatatime
1256 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1264 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1257 dataOut.timeInterval = self.__timeInterval*self.n
1265 dataOut.timeInterval = self.__timeInterval*self.n
1258 dataOut.flagNoData = False
1266 dataOut.flagNoData = False
1259
1267
1260 class ProfileSelector(Operation):
1268 class ProfileSelector(Operation):
1261
1269
1262 profileIndex = None
1270 profileIndex = None
1263 # Tamanho total de los perfiles
1271 # Tamanho total de los perfiles
1264 nProfiles = None
1272 nProfiles = None
1265
1273
1266 def __init__(self):
1274 def __init__(self):
1267
1275
1268 self.profileIndex = 0
1276 self.profileIndex = 0
1269
1277
1270 def incIndex(self):
1278 def incIndex(self):
1271 self.profileIndex += 1
1279 self.profileIndex += 1
1272
1280
1273 if self.profileIndex >= self.nProfiles:
1281 if self.profileIndex >= self.nProfiles:
1274 self.profileIndex = 0
1282 self.profileIndex = 0
1275
1283
1276 def isProfileInRange(self, minIndex, maxIndex):
1284 def isProfileInRange(self, minIndex, maxIndex):
1277
1285
1278 if self.profileIndex < minIndex:
1286 if self.profileIndex < minIndex:
1279 return False
1287 return False
1280
1288
1281 if self.profileIndex > maxIndex:
1289 if self.profileIndex > maxIndex:
1282 return False
1290 return False
1283
1291
1284 return True
1292 return True
1285
1293
1286 def isProfileInList(self, profileList):
1294 def isProfileInList(self, profileList):
1287
1295
1288 if self.profileIndex not in profileList:
1296 if self.profileIndex not in profileList:
1289 return False
1297 return False
1290
1298
1291 return True
1299 return True
1292
1300
1293 def run(self, dataOut, profileList=None, profileRangeList=None):
1301 def run(self, dataOut, profileList=None, profileRangeList=None):
1294
1302
1295 dataOut.flagNoData = True
1303 dataOut.flagNoData = True
1296 self.nProfiles = dataOut.nProfiles
1304 self.nProfiles = dataOut.nProfiles
1297
1305
1298 if profileList != None:
1306 if profileList != None:
1299 if self.isProfileInList(profileList):
1307 if self.isProfileInList(profileList):
1300 dataOut.flagNoData = False
1308 dataOut.flagNoData = False
1301
1309
1302 self.incIndex()
1310 self.incIndex()
1303 return 1
1311 return 1
1304
1312
1305
1313
1306 elif profileRangeList != None:
1314 elif profileRangeList != None:
1307 minIndex = profileRangeList[0]
1315 minIndex = profileRangeList[0]
1308 maxIndex = profileRangeList[1]
1316 maxIndex = profileRangeList[1]
1309 if self.isProfileInRange(minIndex, maxIndex):
1317 if self.isProfileInRange(minIndex, maxIndex):
1310 dataOut.flagNoData = False
1318 dataOut.flagNoData = False
1311
1319
1312 self.incIndex()
1320 self.incIndex()
1313 return 1
1321 return 1
1314
1322
1315 else:
1323 else:
1316 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1324 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1317
1325
1318 return 0
1326 return 0
1319
1327
1320 class SpectraHeisProc(ProcessingUnit):
1328 class SpectraHeisProc(ProcessingUnit):
1321 def __init__(self):
1329 def __init__(self):
1322 self.objectDict = {}
1330 self.objectDict = {}
1323 # self.buffer = None
1331 # self.buffer = None
1324 # self.firstdatatime = None
1332 # self.firstdatatime = None
1325 # self.profIndex = 0
1333 # self.profIndex = 0
1326 self.dataOut = SpectraHeis()
1334 self.dataOut = SpectraHeis()
1327
1335
1328 def __updateObjFromInput(self):
1336 def __updateObjFromInput(self):
1329 self.dataOut.timeZone = self.dataIn.timeZone
1337 self.dataOut.timeZone = self.dataIn.timeZone
1330 self.dataOut.dstFlag = self.dataIn.dstFlag
1338 self.dataOut.dstFlag = self.dataIn.dstFlag
1331 self.dataOut.errorCount = self.dataIn.errorCount
1339 self.dataOut.errorCount = self.dataIn.errorCount
1332 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1340 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1333
1341
1334 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1342 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1335 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1343 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1336 self.dataOut.channelList = self.dataIn.channelList
1344 self.dataOut.channelList = self.dataIn.channelList
1337 self.dataOut.heightList = self.dataIn.heightList
1345 self.dataOut.heightList = self.dataIn.heightList
1338 # self.dataOut.dtype = self.dataIn.dtype
1346 # self.dataOut.dtype = self.dataIn.dtype
1339 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1347 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1340 # self.dataOut.nHeights = self.dataIn.nHeights
1348 # self.dataOut.nHeights = self.dataIn.nHeights
1341 # self.dataOut.nChannels = self.dataIn.nChannels
1349 # self.dataOut.nChannels = self.dataIn.nChannels
1342 self.dataOut.nBaud = self.dataIn.nBaud
1350 self.dataOut.nBaud = self.dataIn.nBaud
1343 self.dataOut.nCode = self.dataIn.nCode
1351 self.dataOut.nCode = self.dataIn.nCode
1344 self.dataOut.code = self.dataIn.code
1352 self.dataOut.code = self.dataIn.code
1345 # self.dataOut.nProfiles = 1
1353 # self.dataOut.nProfiles = 1
1346 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1354 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1347 self.dataOut.nFFTPoints = self.dataIn.nHeights
1355 self.dataOut.nFFTPoints = self.dataIn.nHeights
1348 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1356 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1349 # self.dataOut.flagNoData = self.dataIn.flagNoData
1357 # self.dataOut.flagNoData = self.dataIn.flagNoData
1350 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1358 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1351 self.dataOut.utctime = self.dataIn.utctime
1359 self.dataOut.utctime = self.dataIn.utctime
1352 # self.dataOut.utctime = self.firstdatatime
1360 # self.dataOut.utctime = self.firstdatatime
1353 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1361 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1354 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1362 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1355 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1363 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1356 self.dataOut.nCohInt = self.dataIn.nCohInt
1364 self.dataOut.nCohInt = self.dataIn.nCohInt
1357 self.dataOut.nIncohInt = 1
1365 self.dataOut.nIncohInt = 1
1358 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1366 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1359 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1367 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1360
1368
1361 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1369 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1362 # self.dataOut.set=self.dataIn.set
1370 # self.dataOut.set=self.dataIn.set
1363 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1371 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1364
1372
1365
1373
1366 def __getFft(self):
1374 def __getFft(self):
1367
1375
1368 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1376 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1369 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1377 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1370 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1378 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1371 self.dataOut.data_spc = spc
1379 self.dataOut.data_spc = spc
1372
1380
1373 def init(self):
1381 def init(self):
1374
1382
1375 self.dataOut.flagNoData = True
1383 self.dataOut.flagNoData = True
1376
1384
1377 if self.dataIn.type == "SpectraHeis":
1385 if self.dataIn.type == "SpectraHeis":
1378 self.dataOut.copy(self.dataIn)
1386 self.dataOut.copy(self.dataIn)
1379 return
1387 return
1380
1388
1381 if self.dataIn.type == "Voltage":
1389 if self.dataIn.type == "Voltage":
1382 self.__updateObjFromInput()
1390 self.__updateObjFromInput()
1383 self.__getFft()
1391 self.__getFft()
1384 self.dataOut.flagNoData = False
1392 self.dataOut.flagNoData = False
1385
1393
1386 return
1394 return
1387
1395
1388 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1396 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1389
1397
1390
1398
1391 def selectChannels(self, channelList):
1399 def selectChannels(self, channelList):
1392
1400
1393 channelIndexList = []
1401 channelIndexList = []
1394
1402
1395 for channel in channelList:
1403 for channel in channelList:
1396 index = self.dataOut.channelList.index(channel)
1404 index = self.dataOut.channelList.index(channel)
1397 channelIndexList.append(index)
1405 channelIndexList.append(index)
1398
1406
1399 self.selectChannelsByIndex(channelIndexList)
1407 self.selectChannelsByIndex(channelIndexList)
1400
1408
1401 def selectChannelsByIndex(self, channelIndexList):
1409 def selectChannelsByIndex(self, channelIndexList):
1402 """
1410 """
1403 Selecciona un bloque de datos en base a canales segun el channelIndexList
1411 Selecciona un bloque de datos en base a canales segun el channelIndexList
1404
1412
1405 Input:
1413 Input:
1406 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1414 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1407
1415
1408 Affected:
1416 Affected:
1409 self.dataOut.data
1417 self.dataOut.data
1410 self.dataOut.channelIndexList
1418 self.dataOut.channelIndexList
1411 self.dataOut.nChannels
1419 self.dataOut.nChannels
1412 self.dataOut.m_ProcessingHeader.totalSpectra
1420 self.dataOut.m_ProcessingHeader.totalSpectra
1413 self.dataOut.systemHeaderObj.numChannels
1421 self.dataOut.systemHeaderObj.numChannels
1414 self.dataOut.m_ProcessingHeader.blockSize
1422 self.dataOut.m_ProcessingHeader.blockSize
1415
1423
1416 Return:
1424 Return:
1417 None
1425 None
1418 """
1426 """
1419
1427
1420 for channelIndex in channelIndexList:
1428 for channelIndex in channelIndexList:
1421 if channelIndex not in self.dataOut.channelIndexList:
1429 if channelIndex not in self.dataOut.channelIndexList:
1422 print channelIndexList
1430 print channelIndexList
1423 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1431 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1424
1432
1425 nChannels = len(channelIndexList)
1433 nChannels = len(channelIndexList)
1426
1434
1427 data_spc = self.dataOut.data_spc[channelIndexList,:]
1435 data_spc = self.dataOut.data_spc[channelIndexList,:]
1428
1436
1429 self.dataOut.data_spc = data_spc
1437 self.dataOut.data_spc = data_spc
1430 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1438 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1431
1439
1432 return 1
1440 return 1
1433
1441
1434 class IncohInt4SpectraHeis(Operation):
1442 class IncohInt4SpectraHeis(Operation):
1435
1443
1436 __isConfig = False
1444 __isConfig = False
1437
1445
1438 __profIndex = 0
1446 __profIndex = 0
1439 __withOverapping = False
1447 __withOverapping = False
1440
1448
1441 __byTime = False
1449 __byTime = False
1442 __initime = None
1450 __initime = None
1443 __lastdatatime = None
1451 __lastdatatime = None
1444 __integrationtime = None
1452 __integrationtime = None
1445
1453
1446 __buffer = None
1454 __buffer = None
1447
1455
1448 __dataReady = False
1456 __dataReady = False
1449
1457
1450 n = None
1458 n = None
1451
1459
1452
1460
1453 def __init__(self):
1461 def __init__(self):
1454
1462
1455 self.__isConfig = False
1463 self.__isConfig = False
1456
1464
1457 def setup(self, n=None, timeInterval=None, overlapping=False):
1465 def setup(self, n=None, timeInterval=None, overlapping=False):
1458 """
1466 """
1459 Set the parameters of the integration class.
1467 Set the parameters of the integration class.
1460
1468
1461 Inputs:
1469 Inputs:
1462
1470
1463 n : Number of coherent integrations
1471 n : Number of coherent integrations
1464 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1472 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1465 overlapping :
1473 overlapping :
1466
1474
1467 """
1475 """
1468
1476
1469 self.__initime = None
1477 self.__initime = None
1470 self.__lastdatatime = 0
1478 self.__lastdatatime = 0
1471 self.__buffer = None
1479 self.__buffer = None
1472 self.__dataReady = False
1480 self.__dataReady = False
1473
1481
1474
1482
1475 if n == None and timeInterval == None:
1483 if n == None and timeInterval == None:
1476 raise ValueError, "n or timeInterval should be specified ..."
1484 raise ValueError, "n or timeInterval should be specified ..."
1477
1485
1478 if n != None:
1486 if n != None:
1479 self.n = n
1487 self.n = n
1480 self.__byTime = False
1488 self.__byTime = False
1481 else:
1489 else:
1482 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1490 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1483 self.n = 9999
1491 self.n = 9999
1484 self.__byTime = True
1492 self.__byTime = True
1485
1493
1486 if overlapping:
1494 if overlapping:
1487 self.__withOverapping = True
1495 self.__withOverapping = True
1488 self.__buffer = None
1496 self.__buffer = None
1489 else:
1497 else:
1490 self.__withOverapping = False
1498 self.__withOverapping = False
1491 self.__buffer = 0
1499 self.__buffer = 0
1492
1500
1493 self.__profIndex = 0
1501 self.__profIndex = 0
1494
1502
1495 def putData(self, data):
1503 def putData(self, data):
1496
1504
1497 """
1505 """
1498 Add a profile to the __buffer and increase in one the __profileIndex
1506 Add a profile to the __buffer and increase in one the __profileIndex
1499
1507
1500 """
1508 """
1501
1509
1502 if not self.__withOverapping:
1510 if not self.__withOverapping:
1503 self.__buffer += data.copy()
1511 self.__buffer += data.copy()
1504 self.__profIndex += 1
1512 self.__profIndex += 1
1505 return
1513 return
1506
1514
1507 #Overlapping data
1515 #Overlapping data
1508 nChannels, nHeis = data.shape
1516 nChannels, nHeis = data.shape
1509 data = numpy.reshape(data, (1, nChannels, nHeis))
1517 data = numpy.reshape(data, (1, nChannels, nHeis))
1510
1518
1511 #If the buffer is empty then it takes the data value
1519 #If the buffer is empty then it takes the data value
1512 if self.__buffer == None:
1520 if self.__buffer == None:
1513 self.__buffer = data
1521 self.__buffer = data
1514 self.__profIndex += 1
1522 self.__profIndex += 1
1515 return
1523 return
1516
1524
1517 #If the buffer length is lower than n then stakcing the data value
1525 #If the buffer length is lower than n then stakcing the data value
1518 if self.__profIndex < self.n:
1526 if self.__profIndex < self.n:
1519 self.__buffer = numpy.vstack((self.__buffer, data))
1527 self.__buffer = numpy.vstack((self.__buffer, data))
1520 self.__profIndex += 1
1528 self.__profIndex += 1
1521 return
1529 return
1522
1530
1523 #If the buffer length is equal to n then replacing the last buffer value with the data value
1531 #If the buffer length is equal to n then replacing the last buffer value with the data value
1524 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1532 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1525 self.__buffer[self.n-1] = data
1533 self.__buffer[self.n-1] = data
1526 self.__profIndex = self.n
1534 self.__profIndex = self.n
1527 return
1535 return
1528
1536
1529
1537
1530 def pushData(self):
1538 def pushData(self):
1531 """
1539 """
1532 Return the sum of the last profiles and the profiles used in the sum.
1540 Return the sum of the last profiles and the profiles used in the sum.
1533
1541
1534 Affected:
1542 Affected:
1535
1543
1536 self.__profileIndex
1544 self.__profileIndex
1537
1545
1538 """
1546 """
1539
1547
1540 if not self.__withOverapping:
1548 if not self.__withOverapping:
1541 data = self.__buffer
1549 data = self.__buffer
1542 n = self.__profIndex
1550 n = self.__profIndex
1543
1551
1544 self.__buffer = 0
1552 self.__buffer = 0
1545 self.__profIndex = 0
1553 self.__profIndex = 0
1546
1554
1547 return data, n
1555 return data, n
1548
1556
1549 #Integration with Overlapping
1557 #Integration with Overlapping
1550 data = numpy.sum(self.__buffer, axis=0)
1558 data = numpy.sum(self.__buffer, axis=0)
1551 n = self.__profIndex
1559 n = self.__profIndex
1552
1560
1553 return data, n
1561 return data, n
1554
1562
1555 def byProfiles(self, data):
1563 def byProfiles(self, data):
1556
1564
1557 self.__dataReady = False
1565 self.__dataReady = False
1558 avgdata = None
1566 avgdata = None
1559 n = None
1567 n = None
1560
1568
1561 self.putData(data)
1569 self.putData(data)
1562
1570
1563 if self.__profIndex == self.n:
1571 if self.__profIndex == self.n:
1564
1572
1565 avgdata, n = self.pushData()
1573 avgdata, n = self.pushData()
1566 self.__dataReady = True
1574 self.__dataReady = True
1567
1575
1568 return avgdata
1576 return avgdata
1569
1577
1570 def byTime(self, data, datatime):
1578 def byTime(self, data, datatime):
1571
1579
1572 self.__dataReady = False
1580 self.__dataReady = False
1573 avgdata = None
1581 avgdata = None
1574 n = None
1582 n = None
1575
1583
1576 self.putData(data)
1584 self.putData(data)
1577
1585
1578 if (datatime - self.__initime) >= self.__integrationtime:
1586 if (datatime - self.__initime) >= self.__integrationtime:
1579 avgdata, n = self.pushData()
1587 avgdata, n = self.pushData()
1580 self.n = n
1588 self.n = n
1581 self.__dataReady = True
1589 self.__dataReady = True
1582
1590
1583 return avgdata
1591 return avgdata
1584
1592
1585 def integrate(self, data, datatime=None):
1593 def integrate(self, data, datatime=None):
1586
1594
1587 if self.__initime == None:
1595 if self.__initime == None:
1588 self.__initime = datatime
1596 self.__initime = datatime
1589
1597
1590 if self.__byTime:
1598 if self.__byTime:
1591 avgdata = self.byTime(data, datatime)
1599 avgdata = self.byTime(data, datatime)
1592 else:
1600 else:
1593 avgdata = self.byProfiles(data)
1601 avgdata = self.byProfiles(data)
1594
1602
1595
1603
1596 self.__lastdatatime = datatime
1604 self.__lastdatatime = datatime
1597
1605
1598 if avgdata == None:
1606 if avgdata == None:
1599 return None, None
1607 return None, None
1600
1608
1601 avgdatatime = self.__initime
1609 avgdatatime = self.__initime
1602
1610
1603 deltatime = datatime -self.__lastdatatime
1611 deltatime = datatime -self.__lastdatatime
1604
1612
1605 if not self.__withOverapping:
1613 if not self.__withOverapping:
1606 self.__initime = datatime
1614 self.__initime = datatime
1607 else:
1615 else:
1608 self.__initime += deltatime
1616 self.__initime += deltatime
1609
1617
1610 return avgdata, avgdatatime
1618 return avgdata, avgdatatime
1611
1619
1612 def run(self, dataOut, **kwargs):
1620 def run(self, dataOut, **kwargs):
1613
1621
1614 if not self.__isConfig:
1622 if not self.__isConfig:
1615 self.setup(**kwargs)
1623 self.setup(**kwargs)
1616 self.__isConfig = True
1624 self.__isConfig = True
1617
1625
1618 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1626 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1619
1627
1620 # dataOut.timeInterval *= n
1628 # dataOut.timeInterval *= n
1621 dataOut.flagNoData = True
1629 dataOut.flagNoData = True
1622
1630
1623 if self.__dataReady:
1631 if self.__dataReady:
1624 dataOut.data_spc = avgdata
1632 dataOut.data_spc = avgdata
1625 dataOut.nIncohInt *= self.n
1633 dataOut.nIncohInt *= self.n
1626 # dataOut.nCohInt *= self.n
1634 # dataOut.nCohInt *= self.n
1627 dataOut.utctime = avgdatatime
1635 dataOut.utctime = avgdatatime
1628 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1636 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1629 # dataOut.timeInterval = self.__timeInterval*self.n
1637 # dataOut.timeInterval = self.__timeInterval*self.n
1630 dataOut.flagNoData = False
1638 dataOut.flagNoData = False
1631
1639
1632
1640
1633
1641
1634
1642
1635 No newline at end of file
1643
General Comments 0
You need to be logged in to leave comments. Login now