##// END OF EJS Templates
jrodata.py: el atributo ippFactor se inicia en 1...
Daniel Valdez -
r448:318977a743a9
parent child
Show More
@@ -1,723 +1,725
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import copy
8 import copy
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11
11
12 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from jroheaderIO import SystemHeader, RadarControllerHeader
13
13
14 def hildebrand_sekhon(data, navg):
14 def hildebrand_sekhon(data, navg):
15 """
15 """
16 This method is for the objective determination of de noise level in Doppler spectra. This
16 This method is for the objective determination of de noise level in Doppler spectra. This
17 implementation technique is based on the fact that the standard deviation of the spectral
17 implementation technique is based on the fact that the standard deviation of the spectral
18 densities is equal to the mean spectral density for white Gaussian noise
18 densities is equal to the mean spectral density for white Gaussian noise
19
19
20 Inputs:
20 Inputs:
21 Data : heights
21 Data : heights
22 navg : numbers of averages
22 navg : numbers of averages
23
23
24 Return:
24 Return:
25 -1 : any error
25 -1 : any error
26 anoise : noise's level
26 anoise : noise's level
27 """
27 """
28
28
29 dataflat = data.copy().reshape(-1)
29 dataflat = data.copy().reshape(-1)
30 dataflat.sort()
30 dataflat.sort()
31 npts = dataflat.size #numbers of points of the data
31 npts = dataflat.size #numbers of points of the data
32 npts_noise = 0.2*npts
32 npts_noise = 0.2*npts
33
33
34 if npts < 32:
34 if npts < 32:
35 print "error in noise - requires at least 32 points"
35 print "error in noise - requires at least 32 points"
36 return -1.0
36 return -1.0
37
37
38 dataflat2 = numpy.power(dataflat,2)
38 dataflat2 = numpy.power(dataflat,2)
39
39
40 cs = numpy.cumsum(dataflat)
40 cs = numpy.cumsum(dataflat)
41 cs2 = numpy.cumsum(dataflat2)
41 cs2 = numpy.cumsum(dataflat2)
42
42
43 # data sorted in ascending order
43 # data sorted in ascending order
44 nmin = int((npts + 7.)/8)
44 nmin = int((npts + 7.)/8)
45
45
46 for i in range(nmin, npts):
46 for i in range(nmin, npts):
47 s = cs[i]
47 s = cs[i]
48 s2 = cs2[i]
48 s2 = cs2[i]
49 p = s / float(i);
49 p = s / float(i);
50 p2 = p**2;
50 p2 = p**2;
51 q = s2 / float(i) - p2;
51 q = s2 / float(i) - p2;
52 leftc = p2;
52 leftc = p2;
53 rightc = q * float(navg);
53 rightc = q * float(navg);
54 R2 = leftc/rightc
54 R2 = leftc/rightc
55
55
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
57 if R2 < 1:
57 if R2 < 1:
58 npts_noise = i
58 npts_noise = i
59 break
59 break
60
60
61
61
62 anoise = numpy.average(dataflat[0:npts_noise])
62 anoise = numpy.average(dataflat[0:npts_noise])
63
63
64 return anoise;
64 return anoise;
65
65
66 def sorting_bruce(data, navg):
66 def sorting_bruce(data, navg):
67
67
68 data = data.copy()
68 data = data.copy()
69
69
70 sortdata = numpy.sort(data)
70 sortdata = numpy.sort(data)
71 lenOfData = len(data)
71 lenOfData = len(data)
72 nums_min = lenOfData/10
72 nums_min = lenOfData/10
73
73
74 if (lenOfData/10) > 0:
74 if (lenOfData/10) > 0:
75 nums_min = lenOfData/10
75 nums_min = lenOfData/10
76 else:
76 else:
77 nums_min = 0
77 nums_min = 0
78
78
79 rtest = 1.0 + 1.0/navg
79 rtest = 1.0 + 1.0/navg
80
80
81 sump = 0.
81 sump = 0.
82
82
83 sumq = 0.
83 sumq = 0.
84
84
85 j = 0
85 j = 0
86
86
87 cont = 1
87 cont = 1
88
88
89 while((cont==1)and(j<lenOfData)):
89 while((cont==1)and(j<lenOfData)):
90
90
91 sump += sortdata[j]
91 sump += sortdata[j]
92
92
93 sumq += sortdata[j]**2
93 sumq += sortdata[j]**2
94
94
95 j += 1
95 j += 1
96
96
97 if j > nums_min:
97 if j > nums_min:
98 if ((sumq*j) <= (rtest*sump**2)):
98 if ((sumq*j) <= (rtest*sump**2)):
99 lnoise = sump / j
99 lnoise = sump / j
100 else:
100 else:
101 j = j - 1
101 j = j - 1
102 sump = sump - sortdata[j]
102 sump = sump - sortdata[j]
103 sumq = sumq - sortdata[j]**2
103 sumq = sumq - sortdata[j]**2
104 cont = 0
104 cont = 0
105
105
106 if j == nums_min:
106 if j == nums_min:
107 lnoise = sump /j
107 lnoise = sump /j
108
108
109 return lnoise
109 return lnoise
110
110
111 class JROData:
111 class JROData:
112
112
113 # m_BasicHeader = BasicHeader()
113 # m_BasicHeader = BasicHeader()
114 # m_ProcessingHeader = ProcessingHeader()
114 # m_ProcessingHeader = ProcessingHeader()
115
115
116 systemHeaderObj = SystemHeader()
116 systemHeaderObj = SystemHeader()
117
117
118 radarControllerHeaderObj = RadarControllerHeader()
118 radarControllerHeaderObj = RadarControllerHeader()
119
119
120 # data = None
120 # data = None
121
121
122 type = None
122 type = None
123
123
124 dtype = None
124 dtype = None
125
125
126 # nChannels = None
126 # nChannels = None
127
127
128 # nHeights = None
128 # nHeights = None
129
129
130 nProfiles = None
130 nProfiles = None
131
131
132 heightList = None
132 heightList = None
133
133
134 channelList = None
134 channelList = None
135
135
136 flagNoData = True
136 flagNoData = True
137
137
138 flagTimeBlock = False
138 flagTimeBlock = False
139
139
140 useLocalTime = False
140 useLocalTime = False
141
141
142 utctime = None
142 utctime = None
143
143
144 timeZone = None
144 timeZone = None
145
145
146 dstFlag = None
146 dstFlag = None
147
147
148 errorCount = None
148 errorCount = None
149
149
150 blocksize = None
150 blocksize = None
151
151
152 nCode = None
152 nCode = None
153
153
154 nBaud = None
154 nBaud = None
155
155
156 code = None
156 code = None
157
157
158 flagDecodeData = False #asumo q la data no esta decodificada
158 flagDecodeData = False #asumo q la data no esta decodificada
159
159
160 flagDeflipData = False #asumo q la data no esta sin flip
160 flagDeflipData = False #asumo q la data no esta sin flip
161
161
162 flagShiftFFT = False
162 flagShiftFFT = False
163
163
164 ippSeconds = None
164 ippSeconds = None
165
165
166 timeInterval = None
166 timeInterval = None
167
167
168 nCohInt = None
168 nCohInt = None
169
169
170 noise = None
170 noise = None
171
171
172 windowOfFilter = 1
172 windowOfFilter = 1
173
173
174 #Speed of ligth
174 #Speed of ligth
175 C = 3e8
175 C = 3e8
176
176
177 frequency = 49.92e6
177 frequency = 49.92e6
178
178
179 realtime = False
179 realtime = False
180
180
181 def __init__(self):
181 def __init__(self):
182
182
183 raise ValueError, "This class has not been implemented"
183 raise ValueError, "This class has not been implemented"
184
184
185 def copy(self, inputObj=None):
185 def copy(self, inputObj=None):
186
186
187 if inputObj == None:
187 if inputObj == None:
188 return copy.deepcopy(self)
188 return copy.deepcopy(self)
189
189
190 for key in inputObj.__dict__.keys():
190 for key in inputObj.__dict__.keys():
191 self.__dict__[key] = inputObj.__dict__[key]
191 self.__dict__[key] = inputObj.__dict__[key]
192
192
193 def deepcopy(self):
193 def deepcopy(self):
194
194
195 return copy.deepcopy(self)
195 return copy.deepcopy(self)
196
196
197 def isEmpty(self):
197 def isEmpty(self):
198
198
199 return self.flagNoData
199 return self.flagNoData
200
200
201 def getNoise(self):
201 def getNoise(self):
202
202
203 raise ValueError, "Not implemented"
203 raise ValueError, "Not implemented"
204
204
205 def getNChannels(self):
205 def getNChannels(self):
206
206
207 return len(self.channelList)
207 return len(self.channelList)
208
208
209 def getChannelIndexList(self):
209 def getChannelIndexList(self):
210
210
211 return range(self.nChannels)
211 return range(self.nChannels)
212
212
213 def getNHeights(self):
213 def getNHeights(self):
214
214
215 return len(self.heightList)
215 return len(self.heightList)
216
216
217 def getHeiRange(self, extrapoints=0):
217 def getHeiRange(self, extrapoints=0):
218
218
219 heis = self.heightList
219 heis = self.heightList
220 # deltah = self.heightList[1] - self.heightList[0]
220 # deltah = self.heightList[1] - self.heightList[0]
221 #
221 #
222 # heis.append(self.heightList[-1])
222 # heis.append(self.heightList[-1])
223
223
224 return heis
224 return heis
225
225
226 def getltctime(self):
226 def getltctime(self):
227
227
228 if self.useLocalTime:
228 if self.useLocalTime:
229 return self.utctime - self.timeZone*60
229 return self.utctime - self.timeZone*60
230
230
231 return self.utctime
231 return self.utctime
232
232
233 def getDatatime(self):
233 def getDatatime(self):
234
234
235 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
235 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
236 return datatime
236 return datatime
237
237
238 def getTimeRange(self):
238 def getTimeRange(self):
239
239
240 datatime = []
240 datatime = []
241
241
242 datatime.append(self.ltctime)
242 datatime.append(self.ltctime)
243 datatime.append(self.ltctime + self.timeInterval)
243 datatime.append(self.ltctime + self.timeInterval)
244
244
245 datatime = numpy.array(datatime)
245 datatime = numpy.array(datatime)
246
246
247 return datatime
247 return datatime
248
248
249 def getFmax(self):
249 def getFmax(self):
250
250
251 PRF = 1./(self.ippSeconds * self.nCohInt)
251 PRF = 1./(self.ippSeconds * self.nCohInt)
252
252
253 fmax = PRF/2.
253 fmax = PRF/2.
254
254
255 return fmax
255 return fmax
256
256
257 def getVmax(self):
257 def getVmax(self):
258
258
259 _lambda = self.C/self.frequency
259 _lambda = self.C/self.frequency
260
260
261 vmax = self.getFmax() * _lambda
261 vmax = self.getFmax() * _lambda
262
262
263 return vmax
263 return vmax
264
264
265 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
265 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
266 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
266 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
267 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
267 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
268 noise = property(getNoise, "I'm the 'nHeights' property.")
268 noise = property(getNoise, "I'm the 'nHeights' property.")
269 datatime = property(getDatatime, "I'm the 'datatime' property")
269 datatime = property(getDatatime, "I'm the 'datatime' property")
270 ltctime = property(getltctime, "I'm the 'ltctime' property")
270 ltctime = property(getltctime, "I'm the 'ltctime' property")
271
271
272 class Voltage(JROData):
272 class Voltage(JROData):
273
273
274 #data es un numpy array de 2 dmensiones (canales, alturas)
274 #data es un numpy array de 2 dmensiones (canales, alturas)
275 data = None
275 data = None
276
276
277 def __init__(self):
277 def __init__(self):
278 '''
278 '''
279 Constructor
279 Constructor
280 '''
280 '''
281
281
282 self.radarControllerHeaderObj = RadarControllerHeader()
282 self.radarControllerHeaderObj = RadarControllerHeader()
283
283
284 self.systemHeaderObj = SystemHeader()
284 self.systemHeaderObj = SystemHeader()
285
285
286 self.type = "Voltage"
286 self.type = "Voltage"
287
287
288 self.data = None
288 self.data = None
289
289
290 self.dtype = None
290 self.dtype = None
291
291
292 # self.nChannels = 0
292 # self.nChannels = 0
293
293
294 # self.nHeights = 0
294 # self.nHeights = 0
295
295
296 self.nProfiles = None
296 self.nProfiles = None
297
297
298 self.heightList = None
298 self.heightList = None
299
299
300 self.channelList = None
300 self.channelList = None
301
301
302 # self.channelIndexList = None
302 # self.channelIndexList = None
303
303
304 self.flagNoData = True
304 self.flagNoData = True
305
305
306 self.flagTimeBlock = False
306 self.flagTimeBlock = False
307
307
308 self.utctime = None
308 self.utctime = None
309
309
310 self.timeZone = None
310 self.timeZone = None
311
311
312 self.dstFlag = None
312 self.dstFlag = None
313
313
314 self.errorCount = None
314 self.errorCount = None
315
315
316 self.nCohInt = None
316 self.nCohInt = None
317
317
318 self.blocksize = None
318 self.blocksize = None
319
319
320 self.flagDecodeData = False #asumo q la data no esta decodificada
320 self.flagDecodeData = False #asumo q la data no esta decodificada
321
321
322 self.flagDeflipData = False #asumo q la data no esta sin flip
322 self.flagDeflipData = False #asumo q la data no esta sin flip
323
323
324 self.flagShiftFFT = False
324 self.flagShiftFFT = False
325
325
326
326
327 def getNoisebyHildebrand(self):
327 def getNoisebyHildebrand(self):
328 """
328 """
329 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
329 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
330
330
331 Return:
331 Return:
332 noiselevel
332 noiselevel
333 """
333 """
334
334
335 for channel in range(self.nChannels):
335 for channel in range(self.nChannels):
336 daux = self.data_spc[channel,:,:]
336 daux = self.data_spc[channel,:,:]
337 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
337 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
338
338
339 return self.noise
339 return self.noise
340
340
341 def getNoise(self, type = 1):
341 def getNoise(self, type = 1):
342
342
343 self.noise = numpy.zeros(self.nChannels)
343 self.noise = numpy.zeros(self.nChannels)
344
344
345 if type == 1:
345 if type == 1:
346 noise = self.getNoisebyHildebrand()
346 noise = self.getNoisebyHildebrand()
347
347
348 return 10*numpy.log10(noise)
348 return 10*numpy.log10(noise)
349
349
350 class Spectra(JROData):
350 class Spectra(JROData):
351
351
352 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
352 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
353 data_spc = None
353 data_spc = None
354
354
355 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
355 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
356 data_cspc = None
356 data_cspc = None
357
357
358 #data es un numpy array de 2 dmensiones (canales, alturas)
358 #data es un numpy array de 2 dmensiones (canales, alturas)
359 data_dc = None
359 data_dc = None
360
360
361 nFFTPoints = None
361 nFFTPoints = None
362
362
363 nPairs = None
363 nPairs = None
364
364
365 pairsList = None
365 pairsList = None
366
366
367 nIncohInt = None
367 nIncohInt = None
368
368
369 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
369 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
370
370
371 nCohInt = None #se requiere para determinar el valor de timeInterval
371 nCohInt = None #se requiere para determinar el valor de timeInterval
372
372
373 ippFactor = None
373 ippFactor = None
374
374
375 def __init__(self):
375 def __init__(self):
376 '''
376 '''
377 Constructor
377 Constructor
378 '''
378 '''
379
379
380 self.radarControllerHeaderObj = RadarControllerHeader()
380 self.radarControllerHeaderObj = RadarControllerHeader()
381
381
382 self.systemHeaderObj = SystemHeader()
382 self.systemHeaderObj = SystemHeader()
383
383
384 self.type = "Spectra"
384 self.type = "Spectra"
385
385
386 # self.data = None
386 # self.data = None
387
387
388 self.dtype = None
388 self.dtype = None
389
389
390 # self.nChannels = 0
390 # self.nChannels = 0
391
391
392 # self.nHeights = 0
392 # self.nHeights = 0
393
393
394 self.nProfiles = None
394 self.nProfiles = None
395
395
396 self.heightList = None
396 self.heightList = None
397
397
398 self.channelList = None
398 self.channelList = None
399
399
400 # self.channelIndexList = None
400 # self.channelIndexList = None
401
401
402 self.flagNoData = True
402 self.flagNoData = True
403
403
404 self.flagTimeBlock = False
404 self.flagTimeBlock = False
405
405
406 self.utctime = None
406 self.utctime = None
407
407
408 self.nCohInt = None
408 self.nCohInt = None
409
409
410 self.nIncohInt = None
410 self.nIncohInt = None
411
411
412 self.blocksize = None
412 self.blocksize = None
413
413
414 self.nFFTPoints = None
414 self.nFFTPoints = None
415
415
416 self.wavelength = None
416 self.wavelength = None
417
417
418 self.flagDecodeData = False #asumo q la data no esta decodificada
418 self.flagDecodeData = False #asumo q la data no esta decodificada
419
419
420 self.flagDeflipData = False #asumo q la data no esta sin flip
420 self.flagDeflipData = False #asumo q la data no esta sin flip
421
421
422 self.flagShiftFFT = False
422 self.flagShiftFFT = False
423
424 self.ippFactor = 1
423
425
424 def getNoisebyHildebrand(self):
426 def getNoisebyHildebrand(self):
425 """
427 """
426 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
428 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
427
429
428 Return:
430 Return:
429 noiselevel
431 noiselevel
430 """
432 """
431
433
432 for channel in range(self.nChannels):
434 for channel in range(self.nChannels):
433 daux = self.data_spc[channel,:,:]
435 daux = self.data_spc[channel,:,:]
434 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
436 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
435
437
436 return self.noise
438 return self.noise
437
439
438 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
440 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
439 """
441 """
440 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
442 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
441 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
443 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
442
444
443 Inputs:
445 Inputs:
444 heiIndexMin: Limite inferior del eje de alturas
446 heiIndexMin: Limite inferior del eje de alturas
445 heiIndexMax: Limite superior del eje de alturas
447 heiIndexMax: Limite superior del eje de alturas
446 freqIndexMin: Limite inferior del eje de frecuencia
448 freqIndexMin: Limite inferior del eje de frecuencia
447 freqIndexMax: Limite supoerior del eje de frecuencia
449 freqIndexMax: Limite supoerior del eje de frecuencia
448 """
450 """
449
451
450 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
452 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
451
453
452 for channel in range(self.nChannels):
454 for channel in range(self.nChannels):
453 daux = data[channel,:,:]
455 daux = data[channel,:,:]
454 self.noise[channel] = numpy.average(daux)
456 self.noise[channel] = numpy.average(daux)
455
457
456 return self.noise
458 return self.noise
457
459
458 def getNoisebySort(self):
460 def getNoisebySort(self):
459
461
460 for channel in range(self.nChannels):
462 for channel in range(self.nChannels):
461 daux = self.data_spc[channel,:,:]
463 daux = self.data_spc[channel,:,:]
462 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
464 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
463
465
464 return self.noise
466 return self.noise
465
467
466 def getNoise(self, type = 1):
468 def getNoise(self, type = 1):
469 if self.noise == None:
470 self.noise = numpy.zeros(self.nChannels)
471
472 if type == 1:
473 self.noise = self.getNoisebyHildebrand()
474
475 if type == 2:
476 self.noise = self.getNoisebySort()
477
478 if type == 3:
479 self.noise = self.getNoisebyWindow()
467
480
468 self.noise = numpy.zeros(self.nChannels)
481 return self.noise
469
470 if type == 1:
471 noise = self.getNoisebyHildebrand()
472
473 if type == 2:
474 noise = self.getNoisebySort()
475
476 if type == 3:
477 noise = self.getNoisebyWindow()
478
479 return noise
480
482
481
483
482 def getFreqRange(self, extrapoints=0):
484 def getFreqRange(self, extrapoints=0):
483
485
484 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
486 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
485 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
487 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
486
488
487 return freqrange
489 return freqrange
488
490
489 def getVelRange(self, extrapoints=0):
491 def getVelRange(self, extrapoints=0):
490
492
491 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
493 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
492 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
494 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
493
495
494 return velrange
496 return velrange
495
497
496 def getNPairs(self):
498 def getNPairs(self):
497
499
498 return len(self.pairsList)
500 return len(self.pairsList)
499
501
500 def getPairsIndexList(self):
502 def getPairsIndexList(self):
501
503
502 return range(self.nPairs)
504 return range(self.nPairs)
503
505
504 def getNormFactor(self):
506 def getNormFactor(self):
505 pwcode = 1
507 pwcode = 1
506 if self.flagDecodeData:
508 if self.flagDecodeData:
507 pwcode = numpy.sum(self.code[0]**2)
509 pwcode = numpy.sum(self.code[0]**2)
508 normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode
510 normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode
509
511
510 return normFactor
512 return normFactor
511
513
512 def getFlagCspc(self):
514 def getFlagCspc(self):
513
515
514 if self.data_cspc == None:
516 if self.data_cspc == None:
515 return True
517 return True
516
518
517 return False
519 return False
518
520
519 def getFlagDc(self):
521 def getFlagDc(self):
520
522
521 if self.data_dc == None:
523 if self.data_dc == None:
522 return True
524 return True
523
525
524 return False
526 return False
525
527
526 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
528 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
527 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
529 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
528 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
530 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
529 flag_cspc = property(getFlagCspc)
531 flag_cspc = property(getFlagCspc)
530 flag_dc = property(getFlagDc)
532 flag_dc = property(getFlagDc)
531
533
532 class SpectraHeis(JROData):
534 class SpectraHeis(JROData):
533
535
534 data_spc = None
536 data_spc = None
535
537
536 data_cspc = None
538 data_cspc = None
537
539
538 data_dc = None
540 data_dc = None
539
541
540 nFFTPoints = None
542 nFFTPoints = None
541
543
542 nPairs = None
544 nPairs = None
543
545
544 pairsList = None
546 pairsList = None
545
547
546 nIncohInt = None
548 nIncohInt = None
547
549
548 def __init__(self):
550 def __init__(self):
549
551
550 self.radarControllerHeaderObj = RadarControllerHeader()
552 self.radarControllerHeaderObj = RadarControllerHeader()
551
553
552 self.systemHeaderObj = SystemHeader()
554 self.systemHeaderObj = SystemHeader()
553
555
554 self.type = "SpectraHeis"
556 self.type = "SpectraHeis"
555
557
556 self.dtype = None
558 self.dtype = None
557
559
558 # self.nChannels = 0
560 # self.nChannels = 0
559
561
560 # self.nHeights = 0
562 # self.nHeights = 0
561
563
562 self.nProfiles = None
564 self.nProfiles = None
563
565
564 self.heightList = None
566 self.heightList = None
565
567
566 self.channelList = None
568 self.channelList = None
567
569
568 # self.channelIndexList = None
570 # self.channelIndexList = None
569
571
570 self.flagNoData = True
572 self.flagNoData = True
571
573
572 self.flagTimeBlock = False
574 self.flagTimeBlock = False
573
575
574 self.nPairs = 0
576 self.nPairs = 0
575
577
576 self.utctime = None
578 self.utctime = None
577
579
578 self.blocksize = None
580 self.blocksize = None
579
581
580 class Fits:
582 class Fits:
581
583
582 heightList = None
584 heightList = None
583
585
584 channelList = None
586 channelList = None
585
587
586 flagNoData = True
588 flagNoData = True
587
589
588 flagTimeBlock = False
590 flagTimeBlock = False
589
591
590 useLocalTime = False
592 useLocalTime = False
591
593
592 utctime = None
594 utctime = None
593
595
594 timeZone = None
596 timeZone = None
595
597
596 ippSeconds = None
598 ippSeconds = None
597
599
598 timeInterval = None
600 timeInterval = None
599
601
600 nCohInt = None
602 nCohInt = None
601
603
602 nIncohInt = None
604 nIncohInt = None
603
605
604 noise = None
606 noise = None
605
607
606 windowOfFilter = 1
608 windowOfFilter = 1
607
609
608 #Speed of ligth
610 #Speed of ligth
609 C = 3e8
611 C = 3e8
610
612
611 frequency = 49.92e6
613 frequency = 49.92e6
612
614
613 realtime = False
615 realtime = False
614
616
615
617
616 def __init__(self):
618 def __init__(self):
617
619
618 self.type = "Fits"
620 self.type = "Fits"
619
621
620 self.nProfiles = None
622 self.nProfiles = None
621
623
622 self.heightList = None
624 self.heightList = None
623
625
624 self.channelList = None
626 self.channelList = None
625
627
626 # self.channelIndexList = None
628 # self.channelIndexList = None
627
629
628 self.flagNoData = True
630 self.flagNoData = True
629
631
630 self.utctime = None
632 self.utctime = None
631
633
632 self.nCohInt = None
634 self.nCohInt = None
633
635
634 self.nIncohInt = None
636 self.nIncohInt = None
635
637
636 self.useLocalTime = True
638 self.useLocalTime = True
637
639
638 # self.utctime = None
640 # self.utctime = None
639 # self.timeZone = None
641 # self.timeZone = None
640 # self.ltctime = None
642 # self.ltctime = None
641 # self.timeInterval = None
643 # self.timeInterval = None
642 # self.header = None
644 # self.header = None
643 # self.data_header = None
645 # self.data_header = None
644 # self.data = None
646 # self.data = None
645 # self.datatime = None
647 # self.datatime = None
646 # self.flagNoData = False
648 # self.flagNoData = False
647 # self.expName = ''
649 # self.expName = ''
648 # self.nChannels = None
650 # self.nChannels = None
649 # self.nSamples = None
651 # self.nSamples = None
650 # self.dataBlocksPerFile = None
652 # self.dataBlocksPerFile = None
651 # self.comments = ''
653 # self.comments = ''
652 #
654 #
653
655
654
656
655 def getltctime(self):
657 def getltctime(self):
656
658
657 if self.useLocalTime:
659 if self.useLocalTime:
658 return self.utctime - self.timeZone*60
660 return self.utctime - self.timeZone*60
659
661
660 return self.utctime
662 return self.utctime
661
663
662 def getDatatime(self):
664 def getDatatime(self):
663
665
664 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
666 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
665 return datatime
667 return datatime
666
668
667 def getTimeRange(self):
669 def getTimeRange(self):
668
670
669 datatime = []
671 datatime = []
670
672
671 datatime.append(self.ltctime)
673 datatime.append(self.ltctime)
672 datatime.append(self.ltctime + self.timeInterval)
674 datatime.append(self.ltctime + self.timeInterval)
673
675
674 datatime = numpy.array(datatime)
676 datatime = numpy.array(datatime)
675
677
676 return datatime
678 return datatime
677
679
678 def getHeiRange(self):
680 def getHeiRange(self):
679
681
680 heis = self.heightList
682 heis = self.heightList
681
683
682 return heis
684 return heis
683
685
684 def isEmpty(self):
686 def isEmpty(self):
685
687
686 return self.flagNoData
688 return self.flagNoData
687
689
688 def getNHeights(self):
690 def getNHeights(self):
689
691
690 return len(self.heightList)
692 return len(self.heightList)
691
693
692 def getNChannels(self):
694 def getNChannels(self):
693
695
694 return len(self.channelList)
696 return len(self.channelList)
695
697
696 def getChannelIndexList(self):
698 def getChannelIndexList(self):
697
699
698 return range(self.nChannels)
700 return range(self.nChannels)
699
701
700 def getNoise(self, type = 1):
702 def getNoise(self, type = 1):
701
703
702 self.noise = numpy.zeros(self.nChannels)
704 self.noise = numpy.zeros(self.nChannels)
703
705
704 if type == 1:
706 if type == 1:
705 noise = self.getNoisebyHildebrand()
707 noise = self.getNoisebyHildebrand()
706
708
707 if type == 2:
709 if type == 2:
708 noise = self.getNoisebySort()
710 noise = self.getNoisebySort()
709
711
710 if type == 3:
712 if type == 3:
711 noise = self.getNoisebyWindow()
713 noise = self.getNoisebyWindow()
712
714
713 return noise
715 return noise
714
716
715 datatime = property(getDatatime, "I'm the 'datatime' property")
717 datatime = property(getDatatime, "I'm the 'datatime' property")
716 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
718 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
717 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
719 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
718 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
720 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
719 noise = property(getNoise, "I'm the 'nHeights' property.")
721 noise = property(getNoise, "I'm the 'nHeights' property.")
720 datatime = property(getDatatime, "I'm the 'datatime' property")
722 datatime = property(getDatatime, "I'm the 'datatime' property")
721 ltctime = property(getltctime, "I'm the 'ltctime' property")
723 ltctime = property(getltctime, "I'm the 'ltctime' property")
722
724
723 ltctime = property(getltctime, "I'm the 'ltctime' property") No newline at end of file
725 ltctime = property(getltctime, "I'm the 'ltctime' property")
@@ -1,1515 +1,1515
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(time.localtime())
5 utcnow = time.mktime(time.localtime())
6 delta = abs(utcnow - utcdatatime) # abs
6 delta = abs(utcnow - utcdatatime) # abs
7 if delta >= 30.:
7 if delta >= 30.:
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 self.counter_imagwr = 0
26 self.counter_imagwr = 0
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 self.PLOT_CODE = 1
32 self.PLOT_CODE = 1
33 self.FTP_WEI = None
33 self.FTP_WEI = None
34 self.EXP_CODE = None
34 self.EXP_CODE = None
35 self.SUB_EXP_CODE = None
35 self.SUB_EXP_CODE = None
36 self.PLOT_POS = None
36 self.PLOT_POS = None
37
37
38 def getSubplots(self):
38 def getSubplots(self):
39
39
40 ncol = 4
40 ncol = 4
41 nrow = self.nplots
41 nrow = self.nplots
42
42
43 return nrow, ncol
43 return nrow, ncol
44
44
45 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
45 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46
46
47 self.__showprofile = showprofile
47 self.__showprofile = showprofile
48 self.nplots = nplots
48 self.nplots = nplots
49
49
50 ncolspan = 1
50 ncolspan = 1
51 colspan = 1
51 colspan = 1
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show=True)
57 show=True)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
64 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
65
65
66 counter += 1
66 counter += 1
67
67
68 def run(self, dataOut, id, wintitle="", pairsList=None,
68 def run(self, dataOut, id, wintitle="", pairsList=None,
69 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
69 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
70 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
70 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
71 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
71 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
72 server=None, folder=None, username=None, password=None,
72 server=None, folder=None, username=None, password=None,
73 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
73 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
74
74
75 """
75 """
76
76
77 Input:
77 Input:
78 dataOut :
78 dataOut :
79 id :
79 id :
80 wintitle :
80 wintitle :
81 channelList :
81 channelList :
82 showProfile :
82 showProfile :
83 xmin : None,
83 xmin : None,
84 xmax : None,
84 xmax : None,
85 ymin : None,
85 ymin : None,
86 ymax : None,
86 ymax : None,
87 zmin : None,
87 zmin : None,
88 zmax : None
88 zmax : None
89 """
89 """
90
90
91 if pairsList == None:
91 if pairsList == None:
92 pairsIndexList = dataOut.pairsIndexList
92 pairsIndexList = dataOut.pairsIndexList
93 else:
93 else:
94 pairsIndexList = []
94 pairsIndexList = []
95 for pair in pairsList:
95 for pair in pairsList:
96 if pair not in dataOut.pairsList:
96 if pair not in dataOut.pairsList:
97 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
97 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
98 pairsIndexList.append(dataOut.pairsList.index(pair))
98 pairsIndexList.append(dataOut.pairsList.index(pair))
99
99
100 if pairsIndexList == []:
100 if pairsIndexList == []:
101 return
101 return
102
102
103 if len(pairsIndexList) > 4:
103 if len(pairsIndexList) > 4:
104 pairsIndexList = pairsIndexList[0:4]
104 pairsIndexList = pairsIndexList[0:4]
105 factor = dataOut.normFactor
105 #factor = dataOut.normFactor
106 x = dataOut.getVelRange(1)
106 x = dataOut.getVelRange(1)
107 y = dataOut.getHeiRange()
107 y = dataOut.getHeiRange()
108 z = dataOut.data_spc[:,:,:]/factor
108 z = dataOut.data_spc[:,:,:]#/factor
109 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
109 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
110 avg = numpy.abs(numpy.average(z, axis=1))
110 avg = numpy.abs(numpy.average(z, axis=1))
111 noise = dataOut.getNoise()/factor
111 noise = dataOut.getNoise()#/factor
112
112
113 zdB = 10*numpy.log10(z)
113 zdB = 10*numpy.log10(z)
114 avgdB = 10*numpy.log10(avg)
114 avgdB = 10*numpy.log10(avg)
115 noisedB = 10*numpy.log10(noise)
115 noisedB = 10*numpy.log10(noise)
116
116
117
117
118 #thisDatetime = dataOut.datatime
118 #thisDatetime = dataOut.datatime
119 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
119 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
120 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
120 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
121 xlabel = "Velocity (m/s)"
121 xlabel = "Velocity (m/s)"
122 ylabel = "Range (Km)"
122 ylabel = "Range (Km)"
123
123
124 if not self.__isConfig:
124 if not self.__isConfig:
125
125
126 nplots = len(pairsIndexList)
126 nplots = len(pairsIndexList)
127
127
128 self.setup(id=id,
128 self.setup(id=id,
129 nplots=nplots,
129 nplots=nplots,
130 wintitle=wintitle,
130 wintitle=wintitle,
131 showprofile=False,
131 showprofile=False,
132 show=show)
132 show=show)
133
133
134 if xmin == None: xmin = numpy.nanmin(x)
134 if xmin == None: xmin = numpy.nanmin(x)
135 if xmax == None: xmax = numpy.nanmax(x)
135 if xmax == None: xmax = numpy.nanmax(x)
136 if ymin == None: ymin = numpy.nanmin(y)
136 if ymin == None: ymin = numpy.nanmin(y)
137 if ymax == None: ymax = numpy.nanmax(y)
137 if ymax == None: ymax = numpy.nanmax(y)
138 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
138 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
139 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
139 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
140
140
141 self.FTP_WEI = ftp_wei
141 self.FTP_WEI = ftp_wei
142 self.EXP_CODE = exp_code
142 self.EXP_CODE = exp_code
143 self.SUB_EXP_CODE = sub_exp_code
143 self.SUB_EXP_CODE = sub_exp_code
144 self.PLOT_POS = plot_pos
144 self.PLOT_POS = plot_pos
145
145
146 self.__isConfig = True
146 self.__isConfig = True
147
147
148 self.setWinTitle(title)
148 self.setWinTitle(title)
149
149
150 for i in range(self.nplots):
150 for i in range(self.nplots):
151 pair = dataOut.pairsList[pairsIndexList[i]]
151 pair = dataOut.pairsList[pairsIndexList[i]]
152 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
152 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
153 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
153 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime)
154 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
154 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
155 axes0 = self.axesList[i*self.__nsubplots]
155 axes0 = self.axesList[i*self.__nsubplots]
156 axes0.pcolor(x, y, zdB,
156 axes0.pcolor(x, y, zdB,
157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
158 xlabel=xlabel, ylabel=ylabel, title=title,
158 xlabel=xlabel, ylabel=ylabel, title=title,
159 ticksize=9, colormap=power_cmap, cblabel='')
159 ticksize=9, colormap=power_cmap, cblabel='')
160
160
161 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
161 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime)
162 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
162 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
163 axes0 = self.axesList[i*self.__nsubplots+1]
163 axes0 = self.axesList[i*self.__nsubplots+1]
164 axes0.pcolor(x, y, zdB,
164 axes0.pcolor(x, y, zdB,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, colormap=power_cmap, cblabel='')
167 ticksize=9, colormap=power_cmap, cblabel='')
168
168
169 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
169 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
170 coherence = numpy.abs(coherenceComplex)
170 coherence = numpy.abs(coherenceComplex)
171 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
171 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
172 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
172 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
173
173
174 title = "Coherence %d%d" %(pair[0], pair[1])
174 title = "Coherence %d%d" %(pair[0], pair[1])
175 axes0 = self.axesList[i*self.__nsubplots+2]
175 axes0 = self.axesList[i*self.__nsubplots+2]
176 axes0.pcolor(x, y, coherence,
176 axes0.pcolor(x, y, coherence,
177 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
177 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
178 xlabel=xlabel, ylabel=ylabel, title=title,
178 xlabel=xlabel, ylabel=ylabel, title=title,
179 ticksize=9, colormap=coherence_cmap, cblabel='')
179 ticksize=9, colormap=coherence_cmap, cblabel='')
180
180
181 title = "Phase %d%d" %(pair[0], pair[1])
181 title = "Phase %d%d" %(pair[0], pair[1])
182 axes0 = self.axesList[i*self.__nsubplots+3]
182 axes0 = self.axesList[i*self.__nsubplots+3]
183 axes0.pcolor(x, y, phase,
183 axes0.pcolor(x, y, phase,
184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
184 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
185 xlabel=xlabel, ylabel=ylabel, title=title,
185 xlabel=xlabel, ylabel=ylabel, title=title,
186 ticksize=9, colormap=phase_cmap, cblabel='')
186 ticksize=9, colormap=phase_cmap, cblabel='')
187
187
188
188
189
189
190 self.draw()
190 self.draw()
191
191
192 if save:
192 if save:
193
193
194 self.counter_imagwr += 1
194 self.counter_imagwr += 1
195 if (self.counter_imagwr==wr_period):
195 if (self.counter_imagwr==wr_period):
196 if figfile == None:
196 if figfile == None:
197 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
197 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
198 figfile = self.getFilename(name = str_datetime)
198 figfile = self.getFilename(name = str_datetime)
199
199
200 self.saveFigure(figpath, figfile)
200 self.saveFigure(figpath, figfile)
201
201
202 if ftp:
202 if ftp:
203 #provisionalmente envia archivos en el formato de la web en tiempo real
203 #provisionalmente envia archivos en el formato de la web en tiempo real
204 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
204 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
205 path = '%s%03d' %(self.PREFIX, self.id)
205 path = '%s%03d' %(self.PREFIX, self.id)
206 ftp_file = os.path.join(path,'ftp','%s.png'%name)
206 ftp_file = os.path.join(path,'ftp','%s.png'%name)
207 self.saveFigure(figpath, ftp_file)
207 self.saveFigure(figpath, ftp_file)
208 ftp_filename = os.path.join(figpath,ftp_file)
208 ftp_filename = os.path.join(figpath,ftp_file)
209
209
210 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
210 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
211 self.counter_imagwr = 0
211 self.counter_imagwr = 0
212
212
213 self.counter_imagwr = 0
213 self.counter_imagwr = 0
214
214
215
215
216 class RTIPlot(Figure):
216 class RTIPlot(Figure):
217
217
218 __isConfig = None
218 __isConfig = None
219 __nsubplots = None
219 __nsubplots = None
220
220
221 WIDTHPROF = None
221 WIDTHPROF = None
222 HEIGHTPROF = None
222 HEIGHTPROF = None
223 PREFIX = 'rti'
223 PREFIX = 'rti'
224
224
225 def __init__(self):
225 def __init__(self):
226
226
227 self.timerange = 2*60*60
227 self.timerange = 2*60*60
228 self.__isConfig = False
228 self.__isConfig = False
229 self.__nsubplots = 1
229 self.__nsubplots = 1
230
230
231 self.WIDTH = 800
231 self.WIDTH = 800
232 self.HEIGHT = 150
232 self.HEIGHT = 150
233 self.WIDTHPROF = 120
233 self.WIDTHPROF = 120
234 self.HEIGHTPROF = 0
234 self.HEIGHTPROF = 0
235 self.counter_imagwr = 0
235 self.counter_imagwr = 0
236
236
237 self.PLOT_CODE = 0
237 self.PLOT_CODE = 0
238 self.FTP_WEI = None
238 self.FTP_WEI = None
239 self.EXP_CODE = None
239 self.EXP_CODE = None
240 self.SUB_EXP_CODE = None
240 self.SUB_EXP_CODE = None
241 self.PLOT_POS = None
241 self.PLOT_POS = None
242
242
243 def getSubplots(self):
243 def getSubplots(self):
244
244
245 ncol = 1
245 ncol = 1
246 nrow = self.nplots
246 nrow = self.nplots
247
247
248 return nrow, ncol
248 return nrow, ncol
249
249
250 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
250 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
251
251
252 self.__showprofile = showprofile
252 self.__showprofile = showprofile
253 self.nplots = nplots
253 self.nplots = nplots
254
254
255 ncolspan = 1
255 ncolspan = 1
256 colspan = 1
256 colspan = 1
257 if showprofile:
257 if showprofile:
258 ncolspan = 7
258 ncolspan = 7
259 colspan = 6
259 colspan = 6
260 self.__nsubplots = 2
260 self.__nsubplots = 2
261
261
262 self.createFigure(id = id,
262 self.createFigure(id = id,
263 wintitle = wintitle,
263 wintitle = wintitle,
264 widthplot = self.WIDTH + self.WIDTHPROF,
264 widthplot = self.WIDTH + self.WIDTHPROF,
265 heightplot = self.HEIGHT + self.HEIGHTPROF,
265 heightplot = self.HEIGHT + self.HEIGHTPROF,
266 show=show)
266 show=show)
267
267
268 nrow, ncol = self.getSubplots()
268 nrow, ncol = self.getSubplots()
269
269
270 counter = 0
270 counter = 0
271 for y in range(nrow):
271 for y in range(nrow):
272 for x in range(ncol):
272 for x in range(ncol):
273
273
274 if counter >= self.nplots:
274 if counter >= self.nplots:
275 break
275 break
276
276
277 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
277 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
278
278
279 if showprofile:
279 if showprofile:
280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
280 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
281
281
282 counter += 1
282 counter += 1
283
283
284 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
284 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
285 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
285 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
286 timerange=None,
286 timerange=None,
287 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
287 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
288 server=None, folder=None, username=None, password=None,
288 server=None, folder=None, username=None, password=None,
289 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
289 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
290
290
291 """
291 """
292
292
293 Input:
293 Input:
294 dataOut :
294 dataOut :
295 id :
295 id :
296 wintitle :
296 wintitle :
297 channelList :
297 channelList :
298 showProfile :
298 showProfile :
299 xmin : None,
299 xmin : None,
300 xmax : None,
300 xmax : None,
301 ymin : None,
301 ymin : None,
302 ymax : None,
302 ymax : None,
303 zmin : None,
303 zmin : None,
304 zmax : None
304 zmax : None
305 """
305 """
306
306
307 if channelList == None:
307 if channelList == None:
308 channelIndexList = dataOut.channelIndexList
308 channelIndexList = dataOut.channelIndexList
309 else:
309 else:
310 channelIndexList = []
310 channelIndexList = []
311 for channel in channelList:
311 for channel in channelList:
312 if channel not in dataOut.channelList:
312 if channel not in dataOut.channelList:
313 raise ValueError, "Channel %d is not in dataOut.channelList"
313 raise ValueError, "Channel %d is not in dataOut.channelList"
314 channelIndexList.append(dataOut.channelList.index(channel))
314 channelIndexList.append(dataOut.channelList.index(channel))
315
315
316 if timerange != None:
316 if timerange != None:
317 self.timerange = timerange
317 self.timerange = timerange
318
318
319 tmin = None
319 tmin = None
320 tmax = None
320 tmax = None
321 factor = dataOut.normFactor
321 #factor = dataOut.normFactor
322 x = dataOut.getTimeRange()
322 x = dataOut.getTimeRange()
323 y = dataOut.getHeiRange()
323 y = dataOut.getHeiRange()
324
324
325 z = dataOut.data_spc[channelIndexList,:,:]/factor
325 z = dataOut.data_spc[channelIndexList,:,:]#/factor
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327 avg = numpy.average(z, axis=1)
327 avg = numpy.average(z, axis=1)
328
328
329 avgdB = 10.*numpy.log10(avg)
329 avgdB = 10.*numpy.log10(avg)
330
330
331
331
332 # thisDatetime = dataOut.datatime
332 # thisDatetime = dataOut.datatime
333 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
333 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
334 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
334 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
335 xlabel = ""
335 xlabel = ""
336 ylabel = "Range (Km)"
336 ylabel = "Range (Km)"
337
337
338 if not self.__isConfig:
338 if not self.__isConfig:
339
339
340 nplots = len(channelIndexList)
340 nplots = len(channelIndexList)
341
341
342 self.setup(id=id,
342 self.setup(id=id,
343 nplots=nplots,
343 nplots=nplots,
344 wintitle=wintitle,
344 wintitle=wintitle,
345 showprofile=showprofile,
345 showprofile=showprofile,
346 show=show)
346 show=show)
347
347
348 tmin, tmax = self.getTimeLim(x, xmin, xmax)
348 tmin, tmax = self.getTimeLim(x, xmin, xmax)
349 if ymin == None: ymin = numpy.nanmin(y)
349 if ymin == None: ymin = numpy.nanmin(y)
350 if ymax == None: ymax = numpy.nanmax(y)
350 if ymax == None: ymax = numpy.nanmax(y)
351 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
351 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
352 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
352 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
353
353
354 self.FTP_WEI = ftp_wei
354 self.FTP_WEI = ftp_wei
355 self.EXP_CODE = exp_code
355 self.EXP_CODE = exp_code
356 self.SUB_EXP_CODE = sub_exp_code
356 self.SUB_EXP_CODE = sub_exp_code
357 self.PLOT_POS = plot_pos
357 self.PLOT_POS = plot_pos
358
358
359 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
359 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
360 self.__isConfig = True
360 self.__isConfig = True
361
361
362
362
363 self.setWinTitle(title)
363 self.setWinTitle(title)
364
364
365 for i in range(self.nplots):
365 for i in range(self.nplots):
366 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
366 title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
367 axes = self.axesList[i*self.__nsubplots]
367 axes = self.axesList[i*self.__nsubplots]
368 zdB = avgdB[i].reshape((1,-1))
368 zdB = avgdB[i].reshape((1,-1))
369 axes.pcolorbuffer(x, y, zdB,
369 axes.pcolorbuffer(x, y, zdB,
370 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
370 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
371 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
371 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
372 ticksize=9, cblabel='', cbsize="1%")
372 ticksize=9, cblabel='', cbsize="1%")
373
373
374 if self.__showprofile:
374 if self.__showprofile:
375 axes = self.axesList[i*self.__nsubplots +1]
375 axes = self.axesList[i*self.__nsubplots +1]
376 axes.pline(avgdB[i], y,
376 axes.pline(avgdB[i], y,
377 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
377 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
378 xlabel='dB', ylabel='', title='',
378 xlabel='dB', ylabel='', title='',
379 ytick_visible=False,
379 ytick_visible=False,
380 grid='x')
380 grid='x')
381
381
382 self.draw()
382 self.draw()
383
383
384 if save:
384 if save:
385
385
386 self.counter_imagwr += 1
386 self.counter_imagwr += 1
387 if (self.counter_imagwr==wr_period):
387 if (self.counter_imagwr==wr_period):
388 if figfile == None:
388 if figfile == None:
389 figfile = self.getFilename(name = self.name)
389 figfile = self.getFilename(name = self.name)
390 self.saveFigure(figpath, figfile)
390 self.saveFigure(figpath, figfile)
391
391
392 if ftp:
392 if ftp:
393 #provisionalmente envia archivos en el formato de la web en tiempo real
393 #provisionalmente envia archivos en el formato de la web en tiempo real
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
394 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
395 path = '%s%03d' %(self.PREFIX, self.id)
395 path = '%s%03d' %(self.PREFIX, self.id)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
396 ftp_file = os.path.join(path,'ftp','%s.png'%name)
397 self.saveFigure(figpath, ftp_file)
397 self.saveFigure(figpath, ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
398 ftp_filename = os.path.join(figpath,ftp_file)
399 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
399 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
400 self.counter_imagwr = 0
400 self.counter_imagwr = 0
401
401
402 self.counter_imagwr = 0
402 self.counter_imagwr = 0
403
403
404 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
404 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
405 self.__isConfig = False
405 self.__isConfig = False
406
406
407 class SpectraPlot(Figure):
407 class SpectraPlot(Figure):
408
408
409 __isConfig = None
409 __isConfig = None
410 __nsubplots = None
410 __nsubplots = None
411
411
412 WIDTHPROF = None
412 WIDTHPROF = None
413 HEIGHTPROF = None
413 HEIGHTPROF = None
414 PREFIX = 'spc'
414 PREFIX = 'spc'
415
415
416 def __init__(self):
416 def __init__(self):
417
417
418 self.__isConfig = False
418 self.__isConfig = False
419 self.__nsubplots = 1
419 self.__nsubplots = 1
420
420
421 self.WIDTH = 280
421 self.WIDTH = 280
422 self.HEIGHT = 250
422 self.HEIGHT = 250
423 self.WIDTHPROF = 120
423 self.WIDTHPROF = 120
424 self.HEIGHTPROF = 0
424 self.HEIGHTPROF = 0
425 self.counter_imagwr = 0
425 self.counter_imagwr = 0
426
426
427 self.PLOT_CODE = 1
427 self.PLOT_CODE = 1
428 self.FTP_WEI = None
428 self.FTP_WEI = None
429 self.EXP_CODE = None
429 self.EXP_CODE = None
430 self.SUB_EXP_CODE = None
430 self.SUB_EXP_CODE = None
431 self.PLOT_POS = None
431 self.PLOT_POS = None
432
432
433 def getSubplots(self):
433 def getSubplots(self):
434
434
435 ncol = int(numpy.sqrt(self.nplots)+0.9)
435 ncol = int(numpy.sqrt(self.nplots)+0.9)
436 nrow = int(self.nplots*1./ncol + 0.9)
436 nrow = int(self.nplots*1./ncol + 0.9)
437
437
438 return nrow, ncol
438 return nrow, ncol
439
439
440 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
440 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
441
441
442 self.__showprofile = showprofile
442 self.__showprofile = showprofile
443 self.nplots = nplots
443 self.nplots = nplots
444
444
445 ncolspan = 1
445 ncolspan = 1
446 colspan = 1
446 colspan = 1
447 if showprofile:
447 if showprofile:
448 ncolspan = 3
448 ncolspan = 3
449 colspan = 2
449 colspan = 2
450 self.__nsubplots = 2
450 self.__nsubplots = 2
451
451
452 self.createFigure(id = id,
452 self.createFigure(id = id,
453 wintitle = wintitle,
453 wintitle = wintitle,
454 widthplot = self.WIDTH + self.WIDTHPROF,
454 widthplot = self.WIDTH + self.WIDTHPROF,
455 heightplot = self.HEIGHT + self.HEIGHTPROF,
455 heightplot = self.HEIGHT + self.HEIGHTPROF,
456 show=show)
456 show=show)
457
457
458 nrow, ncol = self.getSubplots()
458 nrow, ncol = self.getSubplots()
459
459
460 counter = 0
460 counter = 0
461 for y in range(nrow):
461 for y in range(nrow):
462 for x in range(ncol):
462 for x in range(ncol):
463
463
464 if counter >= self.nplots:
464 if counter >= self.nplots:
465 break
465 break
466
466
467 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
467 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
468
468
469 if showprofile:
469 if showprofile:
470 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
470 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
471
471
472 counter += 1
472 counter += 1
473
473
474 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
474 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
475 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
475 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
476 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
476 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
477 server=None, folder=None, username=None, password=None,
477 server=None, folder=None, username=None, password=None,
478 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
478 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
479
479
480 """
480 """
481
481
482 Input:
482 Input:
483 dataOut :
483 dataOut :
484 id :
484 id :
485 wintitle :
485 wintitle :
486 channelList :
486 channelList :
487 showProfile :
487 showProfile :
488 xmin : None,
488 xmin : None,
489 xmax : None,
489 xmax : None,
490 ymin : None,
490 ymin : None,
491 ymax : None,
491 ymax : None,
492 zmin : None,
492 zmin : None,
493 zmax : None
493 zmax : None
494 """
494 """
495
495
496 if realtime:
496 if realtime:
497 if not(isRealtime(utcdatatime = dataOut.utctime)):
497 if not(isRealtime(utcdatatime = dataOut.utctime)):
498 print 'Skipping this plot function'
498 print 'Skipping this plot function'
499 return
499 return
500
500
501 if channelList == None:
501 if channelList == None:
502 channelIndexList = dataOut.channelIndexList
502 channelIndexList = dataOut.channelIndexList
503 else:
503 else:
504 channelIndexList = []
504 channelIndexList = []
505 for channel in channelList:
505 for channel in channelList:
506 if channel not in dataOut.channelList:
506 if channel not in dataOut.channelList:
507 raise ValueError, "Channel %d is not in dataOut.channelList"
507 raise ValueError, "Channel %d is not in dataOut.channelList"
508 channelIndexList.append(dataOut.channelList.index(channel))
508 channelIndexList.append(dataOut.channelList.index(channel))
509 factor = dataOut.normFactor
509 #factor = dataOut.normFactor
510 x = dataOut.getVelRange(1)
510 x = dataOut.getVelRange(1)
511 y = dataOut.getHeiRange()
511 y = dataOut.getHeiRange()
512
512
513 z = dataOut.data_spc[channelIndexList,:,:]/factor
513 z = dataOut.data_spc[channelIndexList,:,:]#/factor
514 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
514 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
515 avg = numpy.average(z, axis=1)
515 avg = numpy.average(z, axis=1)
516 noise = dataOut.getNoise()/factor
516 noise = dataOut.getNoise()#/factor
517
517
518 zdB = 10*numpy.log10(z)
518 zdB = 10*numpy.log10(z)
519 avgdB = 10*numpy.log10(avg)
519 avgdB = 10*numpy.log10(avg)
520 noisedB = 10*numpy.log10(noise)
520 noisedB = 10*numpy.log10(noise)
521
521
522 #thisDatetime = dataOut.datatime
522 #thisDatetime = dataOut.datatime
523 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
523 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
524 title = wintitle + " Spectra"
524 title = wintitle + " Spectra"
525 xlabel = "Velocity (m/s)"
525 xlabel = "Velocity (m/s)"
526 ylabel = "Range (Km)"
526 ylabel = "Range (Km)"
527
527
528 if not self.__isConfig:
528 if not self.__isConfig:
529
529
530 nplots = len(channelIndexList)
530 nplots = len(channelIndexList)
531
531
532 self.setup(id=id,
532 self.setup(id=id,
533 nplots=nplots,
533 nplots=nplots,
534 wintitle=wintitle,
534 wintitle=wintitle,
535 showprofile=showprofile,
535 showprofile=showprofile,
536 show=show)
536 show=show)
537
537
538 if xmin == None: xmin = numpy.nanmin(x)
538 if xmin == None: xmin = numpy.nanmin(x)
539 if xmax == None: xmax = numpy.nanmax(x)
539 if xmax == None: xmax = numpy.nanmax(x)
540 if ymin == None: ymin = numpy.nanmin(y)
540 if ymin == None: ymin = numpy.nanmin(y)
541 if ymax == None: ymax = numpy.nanmax(y)
541 if ymax == None: ymax = numpy.nanmax(y)
542 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
542 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
543 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
543 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
544
544
545 self.FTP_WEI = ftp_wei
545 self.FTP_WEI = ftp_wei
546 self.EXP_CODE = exp_code
546 self.EXP_CODE = exp_code
547 self.SUB_EXP_CODE = sub_exp_code
547 self.SUB_EXP_CODE = sub_exp_code
548 self.PLOT_POS = plot_pos
548 self.PLOT_POS = plot_pos
549
549
550 self.__isConfig = True
550 self.__isConfig = True
551
551
552 self.setWinTitle(title)
552 self.setWinTitle(title)
553
553
554 for i in range(self.nplots):
554 for i in range(self.nplots):
555 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
555 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
556 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
556 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
557 axes = self.axesList[i*self.__nsubplots]
557 axes = self.axesList[i*self.__nsubplots]
558 axes.pcolor(x, y, zdB[i,:,:],
558 axes.pcolor(x, y, zdB[i,:,:],
559 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
559 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
560 xlabel=xlabel, ylabel=ylabel, title=title,
560 xlabel=xlabel, ylabel=ylabel, title=title,
561 ticksize=9, cblabel='')
561 ticksize=9, cblabel='')
562
562
563 if self.__showprofile:
563 if self.__showprofile:
564 axes = self.axesList[i*self.__nsubplots +1]
564 axes = self.axesList[i*self.__nsubplots +1]
565 axes.pline(avgdB[i], y,
565 axes.pline(avgdB[i], y,
566 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
566 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
567 xlabel='dB', ylabel='', title='',
567 xlabel='dB', ylabel='', title='',
568 ytick_visible=False,
568 ytick_visible=False,
569 grid='x')
569 grid='x')
570
570
571 noiseline = numpy.repeat(noisedB[i], len(y))
571 noiseline = numpy.repeat(noisedB[i], len(y))
572 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
572 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
573
573
574 self.draw()
574 self.draw()
575
575
576 if save:
576 if save:
577
577
578 self.counter_imagwr += 1
578 self.counter_imagwr += 1
579 if (self.counter_imagwr==wr_period):
579 if (self.counter_imagwr==wr_period):
580 if figfile == None:
580 if figfile == None:
581 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
581 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
582 figfile = self.getFilename(name = str_datetime)
582 figfile = self.getFilename(name = str_datetime)
583
583
584 self.saveFigure(figpath, figfile)
584 self.saveFigure(figpath, figfile)
585
585
586 if ftp:
586 if ftp:
587 #provisionalmente envia archivos en el formato de la web en tiempo real
587 #provisionalmente envia archivos en el formato de la web en tiempo real
588 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
588 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
589 path = '%s%03d' %(self.PREFIX, self.id)
589 path = '%s%03d' %(self.PREFIX, self.id)
590 ftp_file = os.path.join(path,'ftp','%s.png'%name)
590 ftp_file = os.path.join(path,'ftp','%s.png'%name)
591 self.saveFigure(figpath, ftp_file)
591 self.saveFigure(figpath, ftp_file)
592 ftp_filename = os.path.join(figpath,ftp_file)
592 ftp_filename = os.path.join(figpath,ftp_file)
593 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
593 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
594 self.counter_imagwr = 0
594 self.counter_imagwr = 0
595
595
596
596
597 self.counter_imagwr = 0
597 self.counter_imagwr = 0
598
598
599
599
600 class Scope(Figure):
600 class Scope(Figure):
601
601
602 __isConfig = None
602 __isConfig = None
603
603
604 def __init__(self):
604 def __init__(self):
605
605
606 self.__isConfig = False
606 self.__isConfig = False
607 self.WIDTH = 600
607 self.WIDTH = 600
608 self.HEIGHT = 200
608 self.HEIGHT = 200
609 self.counter_imagwr = 0
609 self.counter_imagwr = 0
610
610
611 def getSubplots(self):
611 def getSubplots(self):
612
612
613 nrow = self.nplots
613 nrow = self.nplots
614 ncol = 3
614 ncol = 3
615 return nrow, ncol
615 return nrow, ncol
616
616
617 def setup(self, id, nplots, wintitle, show):
617 def setup(self, id, nplots, wintitle, show):
618
618
619 self.nplots = nplots
619 self.nplots = nplots
620
620
621 self.createFigure(id=id,
621 self.createFigure(id=id,
622 wintitle=wintitle,
622 wintitle=wintitle,
623 show=show)
623 show=show)
624
624
625 nrow,ncol = self.getSubplots()
625 nrow,ncol = self.getSubplots()
626 colspan = 3
626 colspan = 3
627 rowspan = 1
627 rowspan = 1
628
628
629 for i in range(nplots):
629 for i in range(nplots):
630 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
630 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
631
631
632
632
633
633
634 def run(self, dataOut, id, wintitle="", channelList=None,
634 def run(self, dataOut, id, wintitle="", channelList=None,
635 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
635 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
636 figpath='./', figfile=None, show=True, wr_period=1,
636 figpath='./', figfile=None, show=True, wr_period=1,
637 server=None, folder=None, username=None, password=None):
637 server=None, folder=None, username=None, password=None):
638
638
639 """
639 """
640
640
641 Input:
641 Input:
642 dataOut :
642 dataOut :
643 id :
643 id :
644 wintitle :
644 wintitle :
645 channelList :
645 channelList :
646 xmin : None,
646 xmin : None,
647 xmax : None,
647 xmax : None,
648 ymin : None,
648 ymin : None,
649 ymax : None,
649 ymax : None,
650 """
650 """
651
651
652 if channelList == None:
652 if channelList == None:
653 channelIndexList = dataOut.channelIndexList
653 channelIndexList = dataOut.channelIndexList
654 else:
654 else:
655 channelIndexList = []
655 channelIndexList = []
656 for channel in channelList:
656 for channel in channelList:
657 if channel not in dataOut.channelList:
657 if channel not in dataOut.channelList:
658 raise ValueError, "Channel %d is not in dataOut.channelList"
658 raise ValueError, "Channel %d is not in dataOut.channelList"
659 channelIndexList.append(dataOut.channelList.index(channel))
659 channelIndexList.append(dataOut.channelList.index(channel))
660
660
661 x = dataOut.heightList
661 x = dataOut.heightList
662 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
662 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
663 y = y.real
663 y = y.real
664
664
665 #thisDatetime = dataOut.datatime
665 #thisDatetime = dataOut.datatime
666 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
666 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
667 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
667 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
668 xlabel = "Range (Km)"
668 xlabel = "Range (Km)"
669 ylabel = "Intensity"
669 ylabel = "Intensity"
670
670
671 if not self.__isConfig:
671 if not self.__isConfig:
672 nplots = len(channelIndexList)
672 nplots = len(channelIndexList)
673
673
674 self.setup(id=id,
674 self.setup(id=id,
675 nplots=nplots,
675 nplots=nplots,
676 wintitle=wintitle,
676 wintitle=wintitle,
677 show=show)
677 show=show)
678
678
679 if xmin == None: xmin = numpy.nanmin(x)
679 if xmin == None: xmin = numpy.nanmin(x)
680 if xmax == None: xmax = numpy.nanmax(x)
680 if xmax == None: xmax = numpy.nanmax(x)
681 if ymin == None: ymin = numpy.nanmin(y)
681 if ymin == None: ymin = numpy.nanmin(y)
682 if ymax == None: ymax = numpy.nanmax(y)
682 if ymax == None: ymax = numpy.nanmax(y)
683
683
684 self.__isConfig = True
684 self.__isConfig = True
685
685
686 self.setWinTitle(title)
686 self.setWinTitle(title)
687
687
688 for i in range(len(self.axesList)):
688 for i in range(len(self.axesList)):
689 title = "Channel %d" %(i)
689 title = "Channel %d" %(i)
690 axes = self.axesList[i]
690 axes = self.axesList[i]
691 ychannel = y[i,:]
691 ychannel = y[i,:]
692 axes.pline(x, ychannel,
692 axes.pline(x, ychannel,
693 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
693 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
694 xlabel=xlabel, ylabel=ylabel, title=title)
694 xlabel=xlabel, ylabel=ylabel, title=title)
695
695
696 self.draw()
696 self.draw()
697
697
698 if save:
698 if save:
699 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
699 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
700 if figfile == None:
700 if figfile == None:
701 figfile = self.getFilename(name = date)
701 figfile = self.getFilename(name = date)
702
702
703 self.saveFigure(figpath, figfile)
703 self.saveFigure(figpath, figfile)
704
704
705 self.counter_imagwr += 1
705 self.counter_imagwr += 1
706 if (ftp and (self.counter_imagwr==wr_period)):
706 if (ftp and (self.counter_imagwr==wr_period)):
707 ftp_filename = os.path.join(figpath,figfile)
707 ftp_filename = os.path.join(figpath,figfile)
708 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
708 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
709 self.counter_imagwr = 0
709 self.counter_imagwr = 0
710
710
711 class PowerProfilePlot(Figure):
711 class PowerProfilePlot(Figure):
712 __isConfig = None
712 __isConfig = None
713 __nsubplots = None
713 __nsubplots = None
714
714
715 WIDTHPROF = None
715 WIDTHPROF = None
716 HEIGHTPROF = None
716 HEIGHTPROF = None
717 PREFIX = 'spcprofile'
717 PREFIX = 'spcprofile'
718
718
719 def __init__(self):
719 def __init__(self):
720 self.__isConfig = False
720 self.__isConfig = False
721 self.__nsubplots = 1
721 self.__nsubplots = 1
722
722
723 self.WIDTH = 300
723 self.WIDTH = 300
724 self.HEIGHT = 500
724 self.HEIGHT = 500
725 self.counter_imagwr = 0
725 self.counter_imagwr = 0
726
726
727 def getSubplots(self):
727 def getSubplots(self):
728 ncol = 1
728 ncol = 1
729 nrow = 1
729 nrow = 1
730
730
731 return nrow, ncol
731 return nrow, ncol
732
732
733 def setup(self, id, nplots, wintitle, show):
733 def setup(self, id, nplots, wintitle, show):
734
734
735 self.nplots = nplots
735 self.nplots = nplots
736
736
737 ncolspan = 1
737 ncolspan = 1
738 colspan = 1
738 colspan = 1
739
739
740 self.createFigure(id = id,
740 self.createFigure(id = id,
741 wintitle = wintitle,
741 wintitle = wintitle,
742 widthplot = self.WIDTH,
742 widthplot = self.WIDTH,
743 heightplot = self.HEIGHT,
743 heightplot = self.HEIGHT,
744 show=show)
744 show=show)
745
745
746 nrow, ncol = self.getSubplots()
746 nrow, ncol = self.getSubplots()
747
747
748 counter = 0
748 counter = 0
749 for y in range(nrow):
749 for y in range(nrow):
750 for x in range(ncol):
750 for x in range(ncol):
751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
752
752
753 def run(self, dataOut, id, wintitle="", channelList=None,
753 def run(self, dataOut, id, wintitle="", channelList=None,
754 xmin=None, xmax=None, ymin=None, ymax=None,
754 xmin=None, xmax=None, ymin=None, ymax=None,
755 save=False, figpath='./', figfile=None, show=True, wr_period=1,
755 save=False, figpath='./', figfile=None, show=True, wr_period=1,
756 server=None, folder=None, username=None, password=None,):
756 server=None, folder=None, username=None, password=None,):
757
757
758 if channelList == None:
758 if channelList == None:
759 channelIndexList = dataOut.channelIndexList
759 channelIndexList = dataOut.channelIndexList
760 channelList = dataOut.channelList
760 channelList = dataOut.channelList
761 else:
761 else:
762 channelIndexList = []
762 channelIndexList = []
763 for channel in channelList:
763 for channel in channelList:
764 if channel not in dataOut.channelList:
764 if channel not in dataOut.channelList:
765 raise ValueError, "Channel %d is not in dataOut.channelList"
765 raise ValueError, "Channel %d is not in dataOut.channelList"
766 channelIndexList.append(dataOut.channelList.index(channel))
766 channelIndexList.append(dataOut.channelList.index(channel))
767
767
768 factor = dataOut.normFactor
768 #factor = dataOut.normFactor
769 y = dataOut.getHeiRange()
769 y = dataOut.getHeiRange()
770 x = dataOut.data_spc[channelIndexList,:,:]/factor
770 x = dataOut.data_spc[channelIndexList,:,:]#/factor
771 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
771 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
772 avg = numpy.average(x, axis=1)
772 avg = numpy.average(x, axis=1)
773
773
774 avgdB = 10*numpy.log10(avg)
774 avgdB = 10*numpy.log10(avg)
775
775
776 #thisDatetime = dataOut.datatime
776 #thisDatetime = dataOut.datatime
777 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
777 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
778 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
778 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
779 xlabel = "dB"
779 xlabel = "dB"
780 ylabel = "Range (Km)"
780 ylabel = "Range (Km)"
781
781
782 if not self.__isConfig:
782 if not self.__isConfig:
783
783
784 nplots = 1
784 nplots = 1
785
785
786 self.setup(id=id,
786 self.setup(id=id,
787 nplots=nplots,
787 nplots=nplots,
788 wintitle=wintitle,
788 wintitle=wintitle,
789 show=show)
789 show=show)
790
790
791 if ymin == None: ymin = numpy.nanmin(y)
791 if ymin == None: ymin = numpy.nanmin(y)
792 if ymax == None: ymax = numpy.nanmax(y)
792 if ymax == None: ymax = numpy.nanmax(y)
793 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
793 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
794 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
794 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
795
795
796 self.__isConfig = True
796 self.__isConfig = True
797
797
798 self.setWinTitle(title)
798 self.setWinTitle(title)
799
799
800
800
801 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
801 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
802 axes = self.axesList[0]
802 axes = self.axesList[0]
803
803
804 legendlabels = ["channel %d"%x for x in channelList]
804 legendlabels = ["channel %d"%x for x in channelList]
805 axes.pmultiline(avgdB, y,
805 axes.pmultiline(avgdB, y,
806 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
806 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
807 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
807 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
808 ytick_visible=True, nxticks=5,
808 ytick_visible=True, nxticks=5,
809 grid='x')
809 grid='x')
810
810
811 self.draw()
811 self.draw()
812
812
813 if save:
813 if save:
814 date = thisDatetime.strftime("%Y%m%d")
814 date = thisDatetime.strftime("%Y%m%d")
815 if figfile == None:
815 if figfile == None:
816 figfile = self.getFilename(name = date)
816 figfile = self.getFilename(name = date)
817
817
818 self.saveFigure(figpath, figfile)
818 self.saveFigure(figpath, figfile)
819
819
820 self.counter_imagwr += 1
820 self.counter_imagwr += 1
821 if (ftp and (self.counter_imagwr==wr_period)):
821 if (ftp and (self.counter_imagwr==wr_period)):
822 ftp_filename = os.path.join(figpath,figfile)
822 ftp_filename = os.path.join(figpath,figfile)
823 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
823 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
824 self.counter_imagwr = 0
824 self.counter_imagwr = 0
825
825
826 class CoherenceMap(Figure):
826 class CoherenceMap(Figure):
827 __isConfig = None
827 __isConfig = None
828 __nsubplots = None
828 __nsubplots = None
829
829
830 WIDTHPROF = None
830 WIDTHPROF = None
831 HEIGHTPROF = None
831 HEIGHTPROF = None
832 PREFIX = 'cmap'
832 PREFIX = 'cmap'
833
833
834 def __init__(self):
834 def __init__(self):
835 self.timerange = 2*60*60
835 self.timerange = 2*60*60
836 self.__isConfig = False
836 self.__isConfig = False
837 self.__nsubplots = 1
837 self.__nsubplots = 1
838
838
839 self.WIDTH = 800
839 self.WIDTH = 800
840 self.HEIGHT = 150
840 self.HEIGHT = 150
841 self.WIDTHPROF = 120
841 self.WIDTHPROF = 120
842 self.HEIGHTPROF = 0
842 self.HEIGHTPROF = 0
843 self.counter_imagwr = 0
843 self.counter_imagwr = 0
844
844
845 self.PLOT_CODE = 3
845 self.PLOT_CODE = 3
846 self.FTP_WEI = None
846 self.FTP_WEI = None
847 self.EXP_CODE = None
847 self.EXP_CODE = None
848 self.SUB_EXP_CODE = None
848 self.SUB_EXP_CODE = None
849 self.PLOT_POS = None
849 self.PLOT_POS = None
850 self.counter_imagwr = 0
850 self.counter_imagwr = 0
851
851
852 def getSubplots(self):
852 def getSubplots(self):
853 ncol = 1
853 ncol = 1
854 nrow = self.nplots*2
854 nrow = self.nplots*2
855
855
856 return nrow, ncol
856 return nrow, ncol
857
857
858 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
858 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
859 self.__showprofile = showprofile
859 self.__showprofile = showprofile
860 self.nplots = nplots
860 self.nplots = nplots
861
861
862 ncolspan = 1
862 ncolspan = 1
863 colspan = 1
863 colspan = 1
864 if showprofile:
864 if showprofile:
865 ncolspan = 7
865 ncolspan = 7
866 colspan = 6
866 colspan = 6
867 self.__nsubplots = 2
867 self.__nsubplots = 2
868
868
869 self.createFigure(id = id,
869 self.createFigure(id = id,
870 wintitle = wintitle,
870 wintitle = wintitle,
871 widthplot = self.WIDTH + self.WIDTHPROF,
871 widthplot = self.WIDTH + self.WIDTHPROF,
872 heightplot = self.HEIGHT + self.HEIGHTPROF,
872 heightplot = self.HEIGHT + self.HEIGHTPROF,
873 show=True)
873 show=True)
874
874
875 nrow, ncol = self.getSubplots()
875 nrow, ncol = self.getSubplots()
876
876
877 for y in range(nrow):
877 for y in range(nrow):
878 for x in range(ncol):
878 for x in range(ncol):
879
879
880 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
880 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
881
881
882 if showprofile:
882 if showprofile:
883 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
883 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
884
884
885 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
885 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
886 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
886 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
887 timerange=None,
887 timerange=None,
888 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
888 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
889 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
889 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
890 server=None, folder=None, username=None, password=None,
890 server=None, folder=None, username=None, password=None,
891 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
891 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
892
892
893 if pairsList == None:
893 if pairsList == None:
894 pairsIndexList = dataOut.pairsIndexList
894 pairsIndexList = dataOut.pairsIndexList
895 else:
895 else:
896 pairsIndexList = []
896 pairsIndexList = []
897 for pair in pairsList:
897 for pair in pairsList:
898 if pair not in dataOut.pairsList:
898 if pair not in dataOut.pairsList:
899 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
899 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
900 pairsIndexList.append(dataOut.pairsList.index(pair))
900 pairsIndexList.append(dataOut.pairsList.index(pair))
901
901
902 if timerange != None:
902 if timerange != None:
903 self.timerange = timerange
903 self.timerange = timerange
904
904
905 if pairsIndexList == []:
905 if pairsIndexList == []:
906 return
906 return
907
907
908 if len(pairsIndexList) > 4:
908 if len(pairsIndexList) > 4:
909 pairsIndexList = pairsIndexList[0:4]
909 pairsIndexList = pairsIndexList[0:4]
910
910
911 tmin = None
911 tmin = None
912 tmax = None
912 tmax = None
913 x = dataOut.getTimeRange()
913 x = dataOut.getTimeRange()
914 y = dataOut.getHeiRange()
914 y = dataOut.getHeiRange()
915
915
916 #thisDatetime = dataOut.datatime
916 #thisDatetime = dataOut.datatime
917 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
917 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
918 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
918 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
919 xlabel = ""
919 xlabel = ""
920 ylabel = "Range (Km)"
920 ylabel = "Range (Km)"
921
921
922 if not self.__isConfig:
922 if not self.__isConfig:
923 nplots = len(pairsIndexList)
923 nplots = len(pairsIndexList)
924 self.setup(id=id,
924 self.setup(id=id,
925 nplots=nplots,
925 nplots=nplots,
926 wintitle=wintitle,
926 wintitle=wintitle,
927 showprofile=showprofile,
927 showprofile=showprofile,
928 show=show)
928 show=show)
929
929
930 tmin, tmax = self.getTimeLim(x, xmin, xmax)
930 tmin, tmax = self.getTimeLim(x, xmin, xmax)
931 if ymin == None: ymin = numpy.nanmin(y)
931 if ymin == None: ymin = numpy.nanmin(y)
932 if ymax == None: ymax = numpy.nanmax(y)
932 if ymax == None: ymax = numpy.nanmax(y)
933 if zmin == None: zmin = 0.
933 if zmin == None: zmin = 0.
934 if zmax == None: zmax = 1.
934 if zmax == None: zmax = 1.
935
935
936 self.FTP_WEI = ftp_wei
936 self.FTP_WEI = ftp_wei
937 self.EXP_CODE = exp_code
937 self.EXP_CODE = exp_code
938 self.SUB_EXP_CODE = sub_exp_code
938 self.SUB_EXP_CODE = sub_exp_code
939 self.PLOT_POS = plot_pos
939 self.PLOT_POS = plot_pos
940
940
941 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
941 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
942
942
943 self.__isConfig = True
943 self.__isConfig = True
944
944
945 self.setWinTitle(title)
945 self.setWinTitle(title)
946
946
947 for i in range(self.nplots):
947 for i in range(self.nplots):
948
948
949 pair = dataOut.pairsList[pairsIndexList[i]]
949 pair = dataOut.pairsList[pairsIndexList[i]]
950 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
950 # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
951 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
951 # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
952 # coherence = numpy.abs(avgcoherenceComplex)
952 # coherence = numpy.abs(avgcoherenceComplex)
953
953
954 ## coherence = numpy.abs(coherenceComplex)
954 ## coherence = numpy.abs(coherenceComplex)
955 ## avg = numpy.average(coherence, axis=0)
955 ## avg = numpy.average(coherence, axis=0)
956
956
957 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
957 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
958 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
958 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
959 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
959 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
960
960
961
961
962 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
962 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
963 coherence = numpy.abs(avgcoherenceComplex)
963 coherence = numpy.abs(avgcoherenceComplex)
964
964
965 z = coherence.reshape((1,-1))
965 z = coherence.reshape((1,-1))
966
966
967 counter = 0
967 counter = 0
968
968
969 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
969 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
970 axes = self.axesList[i*self.__nsubplots*2]
970 axes = self.axesList[i*self.__nsubplots*2]
971 axes.pcolorbuffer(x, y, z,
971 axes.pcolorbuffer(x, y, z,
972 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
972 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
973 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
973 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
974 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
974 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
975
975
976 if self.__showprofile:
976 if self.__showprofile:
977 counter += 1
977 counter += 1
978 axes = self.axesList[i*self.__nsubplots*2 + counter]
978 axes = self.axesList[i*self.__nsubplots*2 + counter]
979 axes.pline(coherence, y,
979 axes.pline(coherence, y,
980 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
980 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
981 xlabel='', ylabel='', title='', ticksize=7,
981 xlabel='', ylabel='', title='', ticksize=7,
982 ytick_visible=False, nxticks=5,
982 ytick_visible=False, nxticks=5,
983 grid='x')
983 grid='x')
984
984
985 counter += 1
985 counter += 1
986 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
986 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
987 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
987 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
988 # avg = numpy.average(phase, axis=0)
988 # avg = numpy.average(phase, axis=0)
989 z = phase.reshape((1,-1))
989 z = phase.reshape((1,-1))
990
990
991 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
991 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
992 axes = self.axesList[i*self.__nsubplots*2 + counter]
992 axes = self.axesList[i*self.__nsubplots*2 + counter]
993 axes.pcolorbuffer(x, y, z,
993 axes.pcolorbuffer(x, y, z,
994 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
994 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
996 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
996 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
997
997
998 if self.__showprofile:
998 if self.__showprofile:
999 counter += 1
999 counter += 1
1000 axes = self.axesList[i*self.__nsubplots*2 + counter]
1000 axes = self.axesList[i*self.__nsubplots*2 + counter]
1001 axes.pline(phase, y,
1001 axes.pline(phase, y,
1002 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1002 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
1003 xlabel='', ylabel='', title='', ticksize=7,
1003 xlabel='', ylabel='', title='', ticksize=7,
1004 ytick_visible=False, nxticks=4,
1004 ytick_visible=False, nxticks=4,
1005 grid='x')
1005 grid='x')
1006
1006
1007 self.draw()
1007 self.draw()
1008
1008
1009 if save:
1009 if save:
1010
1010
1011 self.counter_imagwr += 1
1011 self.counter_imagwr += 1
1012 if (self.counter_imagwr==wr_period):
1012 if (self.counter_imagwr==wr_period):
1013 if figfile == None:
1013 if figfile == None:
1014 figfile = self.getFilename(name = self.name)
1014 figfile = self.getFilename(name = self.name)
1015 self.saveFigure(figpath, figfile)
1015 self.saveFigure(figpath, figfile)
1016
1016
1017 if ftp:
1017 if ftp:
1018 #provisionalmente envia archivos en el formato de la web en tiempo real
1018 #provisionalmente envia archivos en el formato de la web en tiempo real
1019 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1019 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1020 path = '%s%03d' %(self.PREFIX, self.id)
1020 path = '%s%03d' %(self.PREFIX, self.id)
1021 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1021 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1022 self.saveFigure(figpath, ftp_file)
1022 self.saveFigure(figpath, ftp_file)
1023 ftp_filename = os.path.join(figpath,ftp_file)
1023 ftp_filename = os.path.join(figpath,ftp_file)
1024 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1024 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1025 self.counter_imagwr = 0
1025 self.counter_imagwr = 0
1026
1026
1027 self.counter_imagwr = 0
1027 self.counter_imagwr = 0
1028
1028
1029
1029
1030 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1030 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1031 self.__isConfig = False
1031 self.__isConfig = False
1032
1032
1033 class Noise(Figure):
1033 class Noise(Figure):
1034
1034
1035 __isConfig = None
1035 __isConfig = None
1036 __nsubplots = None
1036 __nsubplots = None
1037
1037
1038 PREFIX = 'noise'
1038 PREFIX = 'noise'
1039
1039
1040 def __init__(self):
1040 def __init__(self):
1041
1041
1042 self.timerange = 24*60*60
1042 self.timerange = 24*60*60
1043 self.__isConfig = False
1043 self.__isConfig = False
1044 self.__nsubplots = 1
1044 self.__nsubplots = 1
1045 self.counter_imagwr = 0
1045 self.counter_imagwr = 0
1046 self.WIDTH = 600
1046 self.WIDTH = 600
1047 self.HEIGHT = 300
1047 self.HEIGHT = 300
1048 self.WIDTHPROF = 120
1048 self.WIDTHPROF = 120
1049 self.HEIGHTPROF = 0
1049 self.HEIGHTPROF = 0
1050 self.xdata = None
1050 self.xdata = None
1051 self.ydata = None
1051 self.ydata = None
1052
1052
1053 self.PLOT_CODE = 77
1053 self.PLOT_CODE = 77
1054 self.FTP_WEI = None
1054 self.FTP_WEI = None
1055 self.EXP_CODE = None
1055 self.EXP_CODE = None
1056 self.SUB_EXP_CODE = None
1056 self.SUB_EXP_CODE = None
1057 self.PLOT_POS = None
1057 self.PLOT_POS = None
1058
1058
1059 def getSubplots(self):
1059 def getSubplots(self):
1060
1060
1061 ncol = 1
1061 ncol = 1
1062 nrow = 1
1062 nrow = 1
1063
1063
1064 return nrow, ncol
1064 return nrow, ncol
1065
1065
1066 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1066 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1067
1067
1068 self.__showprofile = showprofile
1068 self.__showprofile = showprofile
1069 self.nplots = nplots
1069 self.nplots = nplots
1070
1070
1071 ncolspan = 7
1071 ncolspan = 7
1072 colspan = 6
1072 colspan = 6
1073 self.__nsubplots = 2
1073 self.__nsubplots = 2
1074
1074
1075 self.createFigure(id = id,
1075 self.createFigure(id = id,
1076 wintitle = wintitle,
1076 wintitle = wintitle,
1077 widthplot = self.WIDTH+self.WIDTHPROF,
1077 widthplot = self.WIDTH+self.WIDTHPROF,
1078 heightplot = self.HEIGHT+self.HEIGHTPROF,
1078 heightplot = self.HEIGHT+self.HEIGHTPROF,
1079 show=show)
1079 show=show)
1080
1080
1081 nrow, ncol = self.getSubplots()
1081 nrow, ncol = self.getSubplots()
1082
1082
1083 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1083 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1084
1084
1085
1085
1086 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1086 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1087 xmin=None, xmax=None, ymin=None, ymax=None,
1087 xmin=None, xmax=None, ymin=None, ymax=None,
1088 timerange=None,
1088 timerange=None,
1089 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1089 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1090 server=None, folder=None, username=None, password=None,
1090 server=None, folder=None, username=None, password=None,
1091 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1091 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1092
1092
1093 if channelList == None:
1093 if channelList == None:
1094 channelIndexList = dataOut.channelIndexList
1094 channelIndexList = dataOut.channelIndexList
1095 channelList = dataOut.channelList
1095 channelList = dataOut.channelList
1096 else:
1096 else:
1097 channelIndexList = []
1097 channelIndexList = []
1098 for channel in channelList:
1098 for channel in channelList:
1099 if channel not in dataOut.channelList:
1099 if channel not in dataOut.channelList:
1100 raise ValueError, "Channel %d is not in dataOut.channelList"
1100 raise ValueError, "Channel %d is not in dataOut.channelList"
1101 channelIndexList.append(dataOut.channelList.index(channel))
1101 channelIndexList.append(dataOut.channelList.index(channel))
1102
1102
1103 if timerange != None:
1103 if timerange != None:
1104 self.timerange = timerange
1104 self.timerange = timerange
1105
1105
1106 tmin = None
1106 tmin = None
1107 tmax = None
1107 tmax = None
1108 x = dataOut.getTimeRange()
1108 x = dataOut.getTimeRange()
1109 y = dataOut.getHeiRange()
1109 y = dataOut.getHeiRange()
1110 factor = dataOut.normFactor
1110 #factor = dataOut.normFactor
1111 noise = dataOut.getNoise()/factor
1111 noise = dataOut.getNoise()#/factor
1112 noisedB = 10*numpy.log10(noise)
1112 noisedB = 10*numpy.log10(noise)
1113
1113
1114 #thisDatetime = dataOut.datatime
1114 #thisDatetime = dataOut.datatime
1115 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1115 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1116 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1116 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1117 xlabel = ""
1117 xlabel = ""
1118 ylabel = "Intensity (dB)"
1118 ylabel = "Intensity (dB)"
1119
1119
1120 if not self.__isConfig:
1120 if not self.__isConfig:
1121
1121
1122 nplots = 1
1122 nplots = 1
1123
1123
1124 self.setup(id=id,
1124 self.setup(id=id,
1125 nplots=nplots,
1125 nplots=nplots,
1126 wintitle=wintitle,
1126 wintitle=wintitle,
1127 showprofile=showprofile,
1127 showprofile=showprofile,
1128 show=show)
1128 show=show)
1129
1129
1130 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1130 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1131 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1131 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1132 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1132 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1133
1133
1134 self.FTP_WEI = ftp_wei
1134 self.FTP_WEI = ftp_wei
1135 self.EXP_CODE = exp_code
1135 self.EXP_CODE = exp_code
1136 self.SUB_EXP_CODE = sub_exp_code
1136 self.SUB_EXP_CODE = sub_exp_code
1137 self.PLOT_POS = plot_pos
1137 self.PLOT_POS = plot_pos
1138
1138
1139 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1139 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1140
1140
1141
1141
1142 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1142 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1143 self.__isConfig = True
1143 self.__isConfig = True
1144
1144
1145 self.xdata = numpy.array([])
1145 self.xdata = numpy.array([])
1146 self.ydata = numpy.array([])
1146 self.ydata = numpy.array([])
1147
1147
1148 self.setWinTitle(title)
1148 self.setWinTitle(title)
1149
1149
1150
1150
1151 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1151 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1152
1152
1153 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1153 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1154 axes = self.axesList[0]
1154 axes = self.axesList[0]
1155
1155
1156 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1156 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1157
1157
1158 if len(self.ydata)==0:
1158 if len(self.ydata)==0:
1159 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1159 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1160 else:
1160 else:
1161 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1161 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1162
1162
1163
1163
1164 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1164 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1165 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1165 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1166 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1166 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1167 XAxisAsTime=True, grid='both'
1167 XAxisAsTime=True, grid='both'
1168 )
1168 )
1169
1169
1170 self.draw()
1170 self.draw()
1171
1171
1172 # if save:
1172 # if save:
1173 #
1173 #
1174 # if figfile == None:
1174 # if figfile == None:
1175 # figfile = self.getFilename(name = self.name)
1175 # figfile = self.getFilename(name = self.name)
1176 #
1176 #
1177 # self.saveFigure(figpath, figfile)
1177 # self.saveFigure(figpath, figfile)
1178
1178
1179 if save:
1179 if save:
1180
1180
1181 self.counter_imagwr += 1
1181 self.counter_imagwr += 1
1182 if (self.counter_imagwr==wr_period):
1182 if (self.counter_imagwr==wr_period):
1183 if figfile == None:
1183 if figfile == None:
1184 figfile = self.getFilename(name = self.name)
1184 figfile = self.getFilename(name = self.name)
1185 self.saveFigure(figpath, figfile)
1185 self.saveFigure(figpath, figfile)
1186
1186
1187 if ftp:
1187 if ftp:
1188 #provisionalmente envia archivos en el formato de la web en tiempo real
1188 #provisionalmente envia archivos en el formato de la web en tiempo real
1189 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1189 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1190 path = '%s%03d' %(self.PREFIX, self.id)
1190 path = '%s%03d' %(self.PREFIX, self.id)
1191 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1191 ftp_file = os.path.join(path,'ftp','%s.png'%name)
1192 self.saveFigure(figpath, ftp_file)
1192 self.saveFigure(figpath, ftp_file)
1193 ftp_filename = os.path.join(figpath,ftp_file)
1193 ftp_filename = os.path.join(figpath,ftp_file)
1194 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1194 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1195 self.counter_imagwr = 0
1195 self.counter_imagwr = 0
1196
1196
1197 self.counter_imagwr = 0
1197 self.counter_imagwr = 0
1198
1198
1199 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1199 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1200 self.__isConfig = False
1200 self.__isConfig = False
1201 del self.xdata
1201 del self.xdata
1202 del self.ydata
1202 del self.ydata
1203
1203
1204
1204
1205 class SpectraHeisScope(Figure):
1205 class SpectraHeisScope(Figure):
1206
1206
1207
1207
1208 __isConfig = None
1208 __isConfig = None
1209 __nsubplots = None
1209 __nsubplots = None
1210
1210
1211 WIDTHPROF = None
1211 WIDTHPROF = None
1212 HEIGHTPROF = None
1212 HEIGHTPROF = None
1213 PREFIX = 'spc'
1213 PREFIX = 'spc'
1214
1214
1215 def __init__(self):
1215 def __init__(self):
1216
1216
1217 self.__isConfig = False
1217 self.__isConfig = False
1218 self.__nsubplots = 1
1218 self.__nsubplots = 1
1219
1219
1220 self.WIDTH = 230
1220 self.WIDTH = 230
1221 self.HEIGHT = 250
1221 self.HEIGHT = 250
1222 self.WIDTHPROF = 120
1222 self.WIDTHPROF = 120
1223 self.HEIGHTPROF = 0
1223 self.HEIGHTPROF = 0
1224 self.counter_imagwr = 0
1224 self.counter_imagwr = 0
1225
1225
1226 def getSubplots(self):
1226 def getSubplots(self):
1227
1227
1228 ncol = int(numpy.sqrt(self.nplots)+0.9)
1228 ncol = int(numpy.sqrt(self.nplots)+0.9)
1229 nrow = int(self.nplots*1./ncol + 0.9)
1229 nrow = int(self.nplots*1./ncol + 0.9)
1230
1230
1231 return nrow, ncol
1231 return nrow, ncol
1232
1232
1233 def setup(self, id, nplots, wintitle, show):
1233 def setup(self, id, nplots, wintitle, show):
1234
1234
1235 showprofile = False
1235 showprofile = False
1236 self.__showprofile = showprofile
1236 self.__showprofile = showprofile
1237 self.nplots = nplots
1237 self.nplots = nplots
1238
1238
1239 ncolspan = 1
1239 ncolspan = 1
1240 colspan = 1
1240 colspan = 1
1241 if showprofile:
1241 if showprofile:
1242 ncolspan = 3
1242 ncolspan = 3
1243 colspan = 2
1243 colspan = 2
1244 self.__nsubplots = 2
1244 self.__nsubplots = 2
1245
1245
1246 self.createFigure(id = id,
1246 self.createFigure(id = id,
1247 wintitle = wintitle,
1247 wintitle = wintitle,
1248 widthplot = self.WIDTH + self.WIDTHPROF,
1248 widthplot = self.WIDTH + self.WIDTHPROF,
1249 heightplot = self.HEIGHT + self.HEIGHTPROF,
1249 heightplot = self.HEIGHT + self.HEIGHTPROF,
1250 show = show)
1250 show = show)
1251
1251
1252 nrow, ncol = self.getSubplots()
1252 nrow, ncol = self.getSubplots()
1253
1253
1254 counter = 0
1254 counter = 0
1255 for y in range(nrow):
1255 for y in range(nrow):
1256 for x in range(ncol):
1256 for x in range(ncol):
1257
1257
1258 if counter >= self.nplots:
1258 if counter >= self.nplots:
1259 break
1259 break
1260
1260
1261 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1261 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1262
1262
1263 if showprofile:
1263 if showprofile:
1264 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1264 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1265
1265
1266 counter += 1
1266 counter += 1
1267
1267
1268
1268
1269 def run(self, dataOut, id, wintitle="", channelList=None,
1269 def run(self, dataOut, id, wintitle="", channelList=None,
1270 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1270 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1271 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1271 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1272 server=None, folder=None, username=None, password=None):
1272 server=None, folder=None, username=None, password=None):
1273
1273
1274 """
1274 """
1275
1275
1276 Input:
1276 Input:
1277 dataOut :
1277 dataOut :
1278 id :
1278 id :
1279 wintitle :
1279 wintitle :
1280 channelList :
1280 channelList :
1281 xmin : None,
1281 xmin : None,
1282 xmax : None,
1282 xmax : None,
1283 ymin : None,
1283 ymin : None,
1284 ymax : None,
1284 ymax : None,
1285 """
1285 """
1286
1286
1287 if dataOut.realtime:
1287 if dataOut.realtime:
1288 if not(isRealtime(utcdatatime = dataOut.utctime)):
1288 if not(isRealtime(utcdatatime = dataOut.utctime)):
1289 print 'Skipping this plot function'
1289 print 'Skipping this plot function'
1290 return
1290 return
1291
1291
1292 if channelList == None:
1292 if channelList == None:
1293 channelIndexList = dataOut.channelIndexList
1293 channelIndexList = dataOut.channelIndexList
1294 else:
1294 else:
1295 channelIndexList = []
1295 channelIndexList = []
1296 for channel in channelList:
1296 for channel in channelList:
1297 if channel not in dataOut.channelList:
1297 if channel not in dataOut.channelList:
1298 raise ValueError, "Channel %d is not in dataOut.channelList"
1298 raise ValueError, "Channel %d is not in dataOut.channelList"
1299 channelIndexList.append(dataOut.channelList.index(channel))
1299 channelIndexList.append(dataOut.channelList.index(channel))
1300
1300
1301 # x = dataOut.heightList
1301 # x = dataOut.heightList
1302 c = 3E8
1302 c = 3E8
1303 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1303 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1304 #deberia cambiar para el caso de 1Mhz y 100KHz
1304 #deberia cambiar para el caso de 1Mhz y 100KHz
1305 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1305 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1306 #para 1Mhz descomentar la siguiente linea
1306 #para 1Mhz descomentar la siguiente linea
1307 #x= x/(10000.0)
1307 #x= x/(10000.0)
1308 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1308 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1309 # y = y.real
1309 # y = y.real
1310 datadB = 10.*numpy.log10(dataOut.data_spc)
1310 datadB = 10.*numpy.log10(dataOut.data_spc)
1311 y = datadB
1311 y = datadB
1312
1312
1313 #thisDatetime = dataOut.datatime
1313 #thisDatetime = dataOut.datatime
1314 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1314 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1315 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1315 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1316 xlabel = ""
1316 xlabel = ""
1317 #para 1Mhz descomentar la siguiente linea
1317 #para 1Mhz descomentar la siguiente linea
1318 #xlabel = "Frequency x 10000"
1318 #xlabel = "Frequency x 10000"
1319 ylabel = "Intensity (dB)"
1319 ylabel = "Intensity (dB)"
1320
1320
1321 if not self.__isConfig:
1321 if not self.__isConfig:
1322 nplots = len(channelIndexList)
1322 nplots = len(channelIndexList)
1323
1323
1324 self.setup(id=id,
1324 self.setup(id=id,
1325 nplots=nplots,
1325 nplots=nplots,
1326 wintitle=wintitle,
1326 wintitle=wintitle,
1327 show=show)
1327 show=show)
1328
1328
1329 if xmin == None: xmin = numpy.nanmin(x)
1329 if xmin == None: xmin = numpy.nanmin(x)
1330 if xmax == None: xmax = numpy.nanmax(x)
1330 if xmax == None: xmax = numpy.nanmax(x)
1331 if ymin == None: ymin = numpy.nanmin(y)
1331 if ymin == None: ymin = numpy.nanmin(y)
1332 if ymax == None: ymax = numpy.nanmax(y)
1332 if ymax == None: ymax = numpy.nanmax(y)
1333
1333
1334 self.__isConfig = True
1334 self.__isConfig = True
1335
1335
1336 self.setWinTitle(title)
1336 self.setWinTitle(title)
1337
1337
1338 for i in range(len(self.axesList)):
1338 for i in range(len(self.axesList)):
1339 ychannel = y[i,:]
1339 ychannel = y[i,:]
1340 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1340 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1341 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1341 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
1342 axes = self.axesList[i]
1342 axes = self.axesList[i]
1343 axes.pline(x, ychannel,
1343 axes.pline(x, ychannel,
1344 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1344 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1345 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1345 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1346
1346
1347
1347
1348 self.draw()
1348 self.draw()
1349
1349
1350 if save:
1350 if save:
1351 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1351 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1352 if figfile == None:
1352 if figfile == None:
1353 figfile = self.getFilename(name = date)
1353 figfile = self.getFilename(name = date)
1354
1354
1355 self.saveFigure(figpath, figfile)
1355 self.saveFigure(figpath, figfile)
1356
1356
1357 self.counter_imagwr += 1
1357 self.counter_imagwr += 1
1358 if (ftp and (self.counter_imagwr==wr_period)):
1358 if (ftp and (self.counter_imagwr==wr_period)):
1359 ftp_filename = os.path.join(figpath,figfile)
1359 ftp_filename = os.path.join(figpath,figfile)
1360 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1360 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1361 self.counter_imagwr = 0
1361 self.counter_imagwr = 0
1362
1362
1363
1363
1364 class RTIfromSpectraHeis(Figure):
1364 class RTIfromSpectraHeis(Figure):
1365
1365
1366 __isConfig = None
1366 __isConfig = None
1367 __nsubplots = None
1367 __nsubplots = None
1368
1368
1369 PREFIX = 'rtinoise'
1369 PREFIX = 'rtinoise'
1370
1370
1371 def __init__(self):
1371 def __init__(self):
1372
1372
1373 self.timerange = 24*60*60
1373 self.timerange = 24*60*60
1374 self.__isConfig = False
1374 self.__isConfig = False
1375 self.__nsubplots = 1
1375 self.__nsubplots = 1
1376
1376
1377 self.WIDTH = 820
1377 self.WIDTH = 820
1378 self.HEIGHT = 200
1378 self.HEIGHT = 200
1379 self.WIDTHPROF = 120
1379 self.WIDTHPROF = 120
1380 self.HEIGHTPROF = 0
1380 self.HEIGHTPROF = 0
1381 self.counter_imagwr = 0
1381 self.counter_imagwr = 0
1382 self.xdata = None
1382 self.xdata = None
1383 self.ydata = None
1383 self.ydata = None
1384
1384
1385 def getSubplots(self):
1385 def getSubplots(self):
1386
1386
1387 ncol = 1
1387 ncol = 1
1388 nrow = 1
1388 nrow = 1
1389
1389
1390 return nrow, ncol
1390 return nrow, ncol
1391
1391
1392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1392 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1393
1393
1394 self.__showprofile = showprofile
1394 self.__showprofile = showprofile
1395 self.nplots = nplots
1395 self.nplots = nplots
1396
1396
1397 ncolspan = 7
1397 ncolspan = 7
1398 colspan = 6
1398 colspan = 6
1399 self.__nsubplots = 2
1399 self.__nsubplots = 2
1400
1400
1401 self.createFigure(id = id,
1401 self.createFigure(id = id,
1402 wintitle = wintitle,
1402 wintitle = wintitle,
1403 widthplot = self.WIDTH+self.WIDTHPROF,
1403 widthplot = self.WIDTH+self.WIDTHPROF,
1404 heightplot = self.HEIGHT+self.HEIGHTPROF,
1404 heightplot = self.HEIGHT+self.HEIGHTPROF,
1405 show = show)
1405 show = show)
1406
1406
1407 nrow, ncol = self.getSubplots()
1407 nrow, ncol = self.getSubplots()
1408
1408
1409 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1409 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1410
1410
1411
1411
1412 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1412 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1413 xmin=None, xmax=None, ymin=None, ymax=None,
1413 xmin=None, xmax=None, ymin=None, ymax=None,
1414 timerange=None,
1414 timerange=None,
1415 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1415 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
1416 server=None, folder=None, username=None, password=None):
1416 server=None, folder=None, username=None, password=None):
1417
1417
1418 if channelList == None:
1418 if channelList == None:
1419 channelIndexList = dataOut.channelIndexList
1419 channelIndexList = dataOut.channelIndexList
1420 channelList = dataOut.channelList
1420 channelList = dataOut.channelList
1421 else:
1421 else:
1422 channelIndexList = []
1422 channelIndexList = []
1423 for channel in channelList:
1423 for channel in channelList:
1424 if channel not in dataOut.channelList:
1424 if channel not in dataOut.channelList:
1425 raise ValueError, "Channel %d is not in dataOut.channelList"
1425 raise ValueError, "Channel %d is not in dataOut.channelList"
1426 channelIndexList.append(dataOut.channelList.index(channel))
1426 channelIndexList.append(dataOut.channelList.index(channel))
1427
1427
1428 if timerange != None:
1428 if timerange != None:
1429 self.timerange = timerange
1429 self.timerange = timerange
1430
1430
1431 tmin = None
1431 tmin = None
1432 tmax = None
1432 tmax = None
1433 x = dataOut.getTimeRange()
1433 x = dataOut.getTimeRange()
1434 y = dataOut.getHeiRange()
1434 y = dataOut.getHeiRange()
1435
1435
1436 factor = 1
1436 #factor = 1
1437 data = dataOut.data_spc/factor
1437 data = dataOut.data_spc#/factor
1438 data = numpy.average(data,axis=1)
1438 data = numpy.average(data,axis=1)
1439 datadB = 10*numpy.log10(data)
1439 datadB = 10*numpy.log10(data)
1440
1440
1441 # factor = dataOut.normFactor
1441 # factor = dataOut.normFactor
1442 # noise = dataOut.getNoise()/factor
1442 # noise = dataOut.getNoise()/factor
1443 # noisedB = 10*numpy.log10(noise)
1443 # noisedB = 10*numpy.log10(noise)
1444
1444
1445 #thisDatetime = dataOut.datatime
1445 #thisDatetime = dataOut.datatime
1446 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1446 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1447 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1447 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1448 xlabel = "Local Time"
1448 xlabel = "Local Time"
1449 ylabel = "Intensity (dB)"
1449 ylabel = "Intensity (dB)"
1450
1450
1451 if not self.__isConfig:
1451 if not self.__isConfig:
1452
1452
1453 nplots = 1
1453 nplots = 1
1454
1454
1455 self.setup(id=id,
1455 self.setup(id=id,
1456 nplots=nplots,
1456 nplots=nplots,
1457 wintitle=wintitle,
1457 wintitle=wintitle,
1458 showprofile=showprofile,
1458 showprofile=showprofile,
1459 show=show)
1459 show=show)
1460
1460
1461 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1461 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1462 if ymin == None: ymin = numpy.nanmin(datadB)
1462 if ymin == None: ymin = numpy.nanmin(datadB)
1463 if ymax == None: ymax = numpy.nanmax(datadB)
1463 if ymax == None: ymax = numpy.nanmax(datadB)
1464
1464
1465 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1465 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1466 self.__isConfig = True
1466 self.__isConfig = True
1467
1467
1468 self.xdata = numpy.array([])
1468 self.xdata = numpy.array([])
1469 self.ydata = numpy.array([])
1469 self.ydata = numpy.array([])
1470
1470
1471 self.setWinTitle(title)
1471 self.setWinTitle(title)
1472
1472
1473
1473
1474 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1474 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1475 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1475 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1476
1476
1477 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1477 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1478 axes = self.axesList[0]
1478 axes = self.axesList[0]
1479
1479
1480 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1480 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1481
1481
1482 if len(self.ydata)==0:
1482 if len(self.ydata)==0:
1483 self.ydata = datadB[channelIndexList].reshape(-1,1)
1483 self.ydata = datadB[channelIndexList].reshape(-1,1)
1484 else:
1484 else:
1485 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1485 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1486
1486
1487
1487
1488 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1488 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1489 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1489 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1490 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1490 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1491 XAxisAsTime=True
1491 XAxisAsTime=True
1492 )
1492 )
1493
1493
1494 self.draw()
1494 self.draw()
1495
1495
1496 if save:
1496 if save:
1497
1497
1498 if figfile == None:
1498 if figfile == None:
1499 figfile = self.getFilename(name = self.name)
1499 figfile = self.getFilename(name = self.name)
1500
1500
1501 self.saveFigure(figpath, figfile)
1501 self.saveFigure(figpath, figfile)
1502
1502
1503 self.counter_imagwr += 1
1503 self.counter_imagwr += 1
1504 if (ftp and (self.counter_imagwr==wr_period)):
1504 if (ftp and (self.counter_imagwr==wr_period)):
1505 ftp_filename = os.path.join(figpath,figfile)
1505 ftp_filename = os.path.join(figpath,figfile)
1506 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1506 self.sendByFTP_Thread(ftp_filename, server, folder, username, password)
1507 self.counter_imagwr = 0
1507 self.counter_imagwr = 0
1508
1508
1509 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1509 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1510 self.__isConfig = False
1510 self.__isConfig = False
1511 del self.xdata
1511 del self.xdata
1512 del self.ydata
1512 del self.ydata
1513
1513
1514
1514
1515 No newline at end of file
1515
@@ -1,1917 +1,1960
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 import math
10 import math
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=None, maxHei=None):
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
291
292 if minHei == None:
292 if minHei == None:
293 minHei = self.dataOut.heightList[0]
293 minHei = self.dataOut.heightList[0]
294
294
295 if maxHei == None:
295 if maxHei == None:
296 maxHei = self.dataOut.heightList[-1]
296 maxHei = self.dataOut.heightList[-1]
297
297
298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
298 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
299 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)
300
300
301
301
302 if (maxHei > self.dataOut.heightList[-1]):
302 if (maxHei > self.dataOut.heightList[-1]):
303 maxHei = self.dataOut.heightList[-1]
303 maxHei = self.dataOut.heightList[-1]
304 # 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)
305
305
306 minIndex = 0
306 minIndex = 0
307 maxIndex = 0
307 maxIndex = 0
308 heights = self.dataOut.heightList
308 heights = self.dataOut.heightList
309
309
310 inda = numpy.where(heights >= minHei)
310 inda = numpy.where(heights >= minHei)
311 indb = numpy.where(heights <= maxHei)
311 indb = numpy.where(heights <= maxHei)
312
312
313 try:
313 try:
314 minIndex = inda[0][0]
314 minIndex = inda[0][0]
315 except:
315 except:
316 minIndex = 0
316 minIndex = 0
317
317
318 try:
318 try:
319 maxIndex = indb[0][-1]
319 maxIndex = indb[0][-1]
320 except:
320 except:
321 maxIndex = len(heights)
321 maxIndex = len(heights)
322
322
323 self.selectHeightsByIndex(minIndex, maxIndex)
323 self.selectHeightsByIndex(minIndex, maxIndex)
324
324
325 return 1
325 return 1
326
326
327
327
328 def selectHeightsByIndex(self, minIndex, maxIndex):
328 def selectHeightsByIndex(self, minIndex, maxIndex):
329 """
329 """
330 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
331 minIndex <= index <= maxIndex
331 minIndex <= index <= maxIndex
332
332
333 Input:
333 Input:
334 minIndex : valor de indice minimo de altura a considerar
334 minIndex : valor de indice minimo de altura a considerar
335 maxIndex : valor de indice maximo de altura a considerar
335 maxIndex : valor de indice maximo de altura a considerar
336
336
337 Affected:
337 Affected:
338 self.dataOut.data
338 self.dataOut.data
339 self.dataOut.heightList
339 self.dataOut.heightList
340
340
341 Return:
341 Return:
342 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
343 """
343 """
344
344
345 if (minIndex < 0) or (minIndex > maxIndex):
345 if (minIndex < 0) or (minIndex > maxIndex):
346 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)
347
347
348 if (maxIndex >= self.dataOut.nHeights):
348 if (maxIndex >= self.dataOut.nHeights):
349 maxIndex = self.dataOut.nHeights-1
349 maxIndex = self.dataOut.nHeights-1
350 # 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)
351
351
352 nHeights = maxIndex - minIndex + 1
352 nHeights = maxIndex - minIndex + 1
353
353
354 #voltage
354 #voltage
355 data = self.dataOut.data[:,minIndex:maxIndex+1]
355 data = self.dataOut.data[:,minIndex:maxIndex+1]
356
356
357 firstHeight = self.dataOut.heightList[minIndex]
357 firstHeight = self.dataOut.heightList[minIndex]
358
358
359 self.dataOut.data = data
359 self.dataOut.data = data
360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
360 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
361
361
362 return 1
362 return 1
363
363
364
364
365 def filterByHeights(self, window):
365 def filterByHeights(self, window):
366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
366 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
367
367
368 if window == None:
368 if window == None:
369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
369 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
370
370
371 newdelta = deltaHeight * window
371 newdelta = deltaHeight * window
372 r = self.dataOut.data.shape[1] % window
372 r = self.dataOut.data.shape[1] % window
373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
373 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
374 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)
375 buffer = numpy.sum(buffer,2)
375 buffer = numpy.sum(buffer,2)
376 self.dataOut.data = buffer
376 self.dataOut.data = buffer
377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
377 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta)
378 self.dataOut.windowOfFilter = window
378 self.dataOut.windowOfFilter = window
379
379
380 def deFlip(self):
380 def deFlip(self):
381 self.dataOut.data *= self.flip
381 self.dataOut.data *= self.flip
382 self.flip *= -1.
382 self.flip *= -1.
383
383
384 def setRadarFrequency(self, frequency=None):
384 def setRadarFrequency(self, frequency=None):
385 if frequency != None:
385 if frequency != None:
386 self.dataOut.frequency = frequency
386 self.dataOut.frequency = frequency
387
387
388 return 1
388 return 1
389
389
390 class CohInt(Operation):
390 class CohInt(Operation):
391
391
392 __isConfig = False
392 __isConfig = False
393
393
394 __profIndex = 0
394 __profIndex = 0
395 __withOverapping = False
395 __withOverapping = False
396
396
397 __byTime = False
397 __byTime = False
398 __initime = None
398 __initime = None
399 __lastdatatime = None
399 __lastdatatime = None
400 __integrationtime = None
400 __integrationtime = None
401
401
402 __buffer = None
402 __buffer = None
403
403
404 __dataReady = False
404 __dataReady = False
405
405
406 n = None
406 n = None
407
407
408
408
409 def __init__(self):
409 def __init__(self):
410
410
411 self.__isConfig = False
411 self.__isConfig = False
412
412
413 def setup(self, n=None, timeInterval=None, overlapping=False):
413 def setup(self, n=None, timeInterval=None, overlapping=False):
414 """
414 """
415 Set the parameters of the integration class.
415 Set the parameters of the integration class.
416
416
417 Inputs:
417 Inputs:
418
418
419 n : Number of coherent integrations
419 n : Number of coherent integrations
420 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
420 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
421 overlapping :
421 overlapping :
422
422
423 """
423 """
424
424
425 self.__initime = None
425 self.__initime = None
426 self.__lastdatatime = 0
426 self.__lastdatatime = 0
427 self.__buffer = None
427 self.__buffer = None
428 self.__dataReady = False
428 self.__dataReady = False
429
429
430
430
431 if n == None and timeInterval == None:
431 if n == None and timeInterval == None:
432 raise ValueError, "n or timeInterval should be specified ..."
432 raise ValueError, "n or timeInterval should be specified ..."
433
433
434 if n != None:
434 if n != None:
435 self.n = n
435 self.n = n
436 self.__byTime = False
436 self.__byTime = False
437 else:
437 else:
438 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
438 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
439 self.n = 9999
439 self.n = 9999
440 self.__byTime = True
440 self.__byTime = True
441
441
442 if overlapping:
442 if overlapping:
443 self.__withOverapping = True
443 self.__withOverapping = True
444 self.__buffer = None
444 self.__buffer = None
445 else:
445 else:
446 self.__withOverapping = False
446 self.__withOverapping = False
447 self.__buffer = 0
447 self.__buffer = 0
448
448
449 self.__profIndex = 0
449 self.__profIndex = 0
450
450
451 def putData(self, data):
451 def putData(self, data):
452
452
453 """
453 """
454 Add a profile to the __buffer and increase in one the __profileIndex
454 Add a profile to the __buffer and increase in one the __profileIndex
455
455
456 """
456 """
457
457
458 if not self.__withOverapping:
458 if not self.__withOverapping:
459 self.__buffer += data.copy()
459 self.__buffer += data.copy()
460 self.__profIndex += 1
460 self.__profIndex += 1
461 return
461 return
462
462
463 #Overlapping data
463 #Overlapping data
464 nChannels, nHeis = data.shape
464 nChannels, nHeis = data.shape
465 data = numpy.reshape(data, (1, nChannels, nHeis))
465 data = numpy.reshape(data, (1, nChannels, nHeis))
466
466
467 #If the buffer is empty then it takes the data value
467 #If the buffer is empty then it takes the data value
468 if self.__buffer == None:
468 if self.__buffer == None:
469 self.__buffer = data
469 self.__buffer = data
470 self.__profIndex += 1
470 self.__profIndex += 1
471 return
471 return
472
472
473 #If the buffer length is lower than n then stakcing the data value
473 #If the buffer length is lower than n then stakcing the data value
474 if self.__profIndex < self.n:
474 if self.__profIndex < self.n:
475 self.__buffer = numpy.vstack((self.__buffer, data))
475 self.__buffer = numpy.vstack((self.__buffer, data))
476 self.__profIndex += 1
476 self.__profIndex += 1
477 return
477 return
478
478
479 #If the buffer length is equal to n then replacing the last buffer value with the data value
479 #If the buffer length is equal to n then replacing the last buffer value with the data value
480 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
480 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
481 self.__buffer[self.n-1] = data
481 self.__buffer[self.n-1] = data
482 self.__profIndex = self.n
482 self.__profIndex = self.n
483 return
483 return
484
484
485
485
486 def pushData(self):
486 def pushData(self):
487 """
487 """
488 Return the sum of the last profiles and the profiles used in the sum.
488 Return the sum of the last profiles and the profiles used in the sum.
489
489
490 Affected:
490 Affected:
491
491
492 self.__profileIndex
492 self.__profileIndex
493
493
494 """
494 """
495
495
496 if not self.__withOverapping:
496 if not self.__withOverapping:
497 data = self.__buffer
497 data = self.__buffer
498 n = self.__profIndex
498 n = self.__profIndex
499
499
500 self.__buffer = 0
500 self.__buffer = 0
501 self.__profIndex = 0
501 self.__profIndex = 0
502
502
503 return data, n
503 return data, n
504
504
505 #Integration with Overlapping
505 #Integration with Overlapping
506 data = numpy.sum(self.__buffer, axis=0)
506 data = numpy.sum(self.__buffer, axis=0)
507 n = self.__profIndex
507 n = self.__profIndex
508
508
509 return data, n
509 return data, n
510
510
511 def byProfiles(self, data):
511 def byProfiles(self, data):
512
512
513 self.__dataReady = False
513 self.__dataReady = False
514 avgdata = None
514 avgdata = None
515 n = None
515 n = None
516
516
517 self.putData(data)
517 self.putData(data)
518
518
519 if self.__profIndex == self.n:
519 if self.__profIndex == self.n:
520
520
521 avgdata, n = self.pushData()
521 avgdata, n = self.pushData()
522 self.__dataReady = True
522 self.__dataReady = True
523
523
524 return avgdata
524 return avgdata
525
525
526 def byTime(self, data, datatime):
526 def byTime(self, data, datatime):
527
527
528 self.__dataReady = False
528 self.__dataReady = False
529 avgdata = None
529 avgdata = None
530 n = None
530 n = None
531
531
532 self.putData(data)
532 self.putData(data)
533
533
534 if (datatime - self.__initime) >= self.__integrationtime:
534 if (datatime - self.__initime) >= self.__integrationtime:
535 avgdata, n = self.pushData()
535 avgdata, n = self.pushData()
536 self.n = n
536 self.n = n
537 self.__dataReady = True
537 self.__dataReady = True
538
538
539 return avgdata
539 return avgdata
540
540
541 def integrate(self, data, datatime=None):
541 def integrate(self, data, datatime=None):
542
542
543 if self.__initime == None:
543 if self.__initime == None:
544 self.__initime = datatime
544 self.__initime = datatime
545
545
546 if self.__byTime:
546 if self.__byTime:
547 avgdata = self.byTime(data, datatime)
547 avgdata = self.byTime(data, datatime)
548 else:
548 else:
549 avgdata = self.byProfiles(data)
549 avgdata = self.byProfiles(data)
550
550
551
551
552 self.__lastdatatime = datatime
552 self.__lastdatatime = datatime
553
553
554 if avgdata == None:
554 if avgdata == None:
555 return None, None
555 return None, None
556
556
557 avgdatatime = self.__initime
557 avgdatatime = self.__initime
558
558
559 deltatime = datatime -self.__lastdatatime
559 deltatime = datatime -self.__lastdatatime
560
560
561 if not self.__withOverapping:
561 if not self.__withOverapping:
562 self.__initime = datatime
562 self.__initime = datatime
563 else:
563 else:
564 self.__initime += deltatime
564 self.__initime += deltatime
565
565
566 return avgdata, avgdatatime
566 return avgdata, avgdatatime
567
567
568 def run(self, dataOut, **kwargs):
568 def run(self, dataOut, **kwargs):
569
569
570 if not self.__isConfig:
570 if not self.__isConfig:
571 self.setup(**kwargs)
571 self.setup(**kwargs)
572 self.__isConfig = True
572 self.__isConfig = True
573
573
574 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
574 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
575
575
576 # dataOut.timeInterval *= n
576 # dataOut.timeInterval *= n
577 dataOut.flagNoData = True
577 dataOut.flagNoData = True
578
578
579 if self.__dataReady:
579 if self.__dataReady:
580 dataOut.data = avgdata
580 dataOut.data = avgdata
581 dataOut.nCohInt *= self.n
581 dataOut.nCohInt *= self.n
582 dataOut.utctime = avgdatatime
582 dataOut.utctime = avgdatatime
583 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
583 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
584 dataOut.flagNoData = False
584 dataOut.flagNoData = False
585
585
586
586
587 class Decoder(Operation):
587 class Decoder(Operation):
588
588
589 __isConfig = False
589 __isConfig = False
590 __profIndex = 0
590 __profIndex = 0
591
591
592 code = None
592 code = None
593
593
594 nCode = None
594 nCode = None
595 nBaud = None
595 nBaud = None
596
596
597 def __init__(self):
597 def __init__(self):
598
598
599 self.__isConfig = False
599 self.__isConfig = False
600
600
601 def setup(self, code, shape):
601 def setup(self, code, shape):
602
602
603 self.__profIndex = 0
603 self.__profIndex = 0
604
604
605 self.code = code
605 self.code = code
606
606
607 self.nCode = len(code)
607 self.nCode = len(code)
608 self.nBaud = len(code[0])
608 self.nBaud = len(code[0])
609
609
610 self.__nChannels, self.__nHeis = shape
610 self.__nChannels, self.__nHeis = shape
611
611
612 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
612 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
613
613
614 __codeBuffer[:,0:self.nBaud] = self.code
614 __codeBuffer[:,0:self.nBaud] = self.code
615
615
616 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
616 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
617
617
618 self.ndatadec = self.__nHeis - self.nBaud + 1
618 self.ndatadec = self.__nHeis - self.nBaud + 1
619
619
620 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
620 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
621
621
622 def convolutionInFreq(self, data):
622 def convolutionInFreq(self, data):
623
623
624 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
624 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625
625
626 fft_data = numpy.fft.fft(data, axis=1)
626 fft_data = numpy.fft.fft(data, axis=1)
627
627
628 conv = fft_data*fft_code
628 conv = fft_data*fft_code
629
629
630 data = numpy.fft.ifft(conv,axis=1)
630 data = numpy.fft.ifft(conv,axis=1)
631
631
632 datadec = data[:,:-self.nBaud+1]
632 datadec = data[:,:-self.nBaud+1]
633
633
634 return datadec
634 return datadec
635
635
636 def convolutionInFreqOpt(self, data):
636 def convolutionInFreqOpt(self, data):
637
637
638 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
638 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
639
639
640 data = cfunctions.decoder(fft_code, data)
640 data = cfunctions.decoder(fft_code, data)
641
641
642 datadec = data[:,:-self.nBaud+1]
642 datadec = data[:,:-self.nBaud+1]
643
643
644 return datadec
644 return datadec
645
645
646 def convolutionInTime(self, data):
646 def convolutionInTime(self, data):
647
647
648 code = self.code[self.__profIndex]
648 code = self.code[self.__profIndex]
649
649
650 for i in range(self.__nChannels):
650 for i in range(self.__nChannels):
651 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
651 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
652
652
653 return self.datadecTime
653 return self.datadecTime
654
654
655 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
655 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
656
656
657 if not self.__isConfig:
657 if not self.__isConfig:
658
658
659 if code == None:
659 if code == None:
660 code = dataOut.code
660 code = dataOut.code
661 else:
661 else:
662 code = numpy.array(code).reshape(nCode,nBaud)
662 code = numpy.array(code).reshape(nCode,nBaud)
663 dataOut.code = code
663 dataOut.code = code
664 dataOut.nCode = nCode
664 dataOut.nCode = nCode
665 dataOut.nBaud = nBaud
665 dataOut.nBaud = nBaud
666
666
667 if code == None:
667 if code == None:
668 return 1
668 return 1
669
669
670 self.setup(code, dataOut.data.shape)
670 self.setup(code, dataOut.data.shape)
671 self.__isConfig = True
671 self.__isConfig = True
672
672
673 if mode == 0:
673 if mode == 0:
674 datadec = self.convolutionInTime(dataOut.data)
674 datadec = self.convolutionInTime(dataOut.data)
675
675
676 if mode == 1:
676 if mode == 1:
677 datadec = self.convolutionInFreq(dataOut.data)
677 datadec = self.convolutionInFreq(dataOut.data)
678
678
679 if mode == 2:
679 if mode == 2:
680 datadec = self.convolutionInFreqOpt(dataOut.data)
680 datadec = self.convolutionInFreqOpt(dataOut.data)
681
681
682 dataOut.data = datadec
682 dataOut.data = datadec
683
683
684 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
684 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
685
685
686 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
686 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
687
687
688 if self.__profIndex == self.nCode-1:
688 if self.__profIndex == self.nCode-1:
689 self.__profIndex = 0
689 self.__profIndex = 0
690 return 1
690 return 1
691
691
692 self.__profIndex += 1
692 self.__profIndex += 1
693
693
694 return 1
694 return 1
695 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
695 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
696
696
697
697
698
698
699 class SpectraProc(ProcessingUnit):
699 class SpectraProc(ProcessingUnit):
700
700
701 def __init__(self):
701 def __init__(self):
702
702
703 self.objectDict = {}
703 self.objectDict = {}
704 self.buffer = None
704 self.buffer = None
705 self.firstdatatime = None
705 self.firstdatatime = None
706 self.profIndex = 0
706 self.profIndex = 0
707 self.dataOut = Spectra()
707 self.dataOut = Spectra()
708
708
709 def __updateObjFromInput(self):
709 def __updateObjFromInput(self):
710
710
711 self.dataOut.timeZone = self.dataIn.timeZone
711 self.dataOut.timeZone = self.dataIn.timeZone
712 self.dataOut.dstFlag = self.dataIn.dstFlag
712 self.dataOut.dstFlag = self.dataIn.dstFlag
713 self.dataOut.errorCount = self.dataIn.errorCount
713 self.dataOut.errorCount = self.dataIn.errorCount
714 self.dataOut.useLocalTime = self.dataIn.useLocalTime
714 self.dataOut.useLocalTime = self.dataIn.useLocalTime
715
715
716 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
716 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
717 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
717 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
718 self.dataOut.channelList = self.dataIn.channelList
718 self.dataOut.channelList = self.dataIn.channelList
719 self.dataOut.heightList = self.dataIn.heightList
719 self.dataOut.heightList = self.dataIn.heightList
720 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
720 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
721 # self.dataOut.nHeights = self.dataIn.nHeights
721 # self.dataOut.nHeights = self.dataIn.nHeights
722 # self.dataOut.nChannels = self.dataIn.nChannels
722 # self.dataOut.nChannels = self.dataIn.nChannels
723 self.dataOut.nBaud = self.dataIn.nBaud
723 self.dataOut.nBaud = self.dataIn.nBaud
724 self.dataOut.nCode = self.dataIn.nCode
724 self.dataOut.nCode = self.dataIn.nCode
725 self.dataOut.code = self.dataIn.code
725 self.dataOut.code = self.dataIn.code
726 self.dataOut.nProfiles = self.dataOut.nFFTPoints
726 self.dataOut.nProfiles = self.dataOut.nFFTPoints
727 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
727 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
728 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
728 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
729 self.dataOut.utctime = self.firstdatatime
729 self.dataOut.utctime = self.firstdatatime
730 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
730 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
731 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
731 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
732 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
732 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
733 self.dataOut.nCohInt = self.dataIn.nCohInt
733 self.dataOut.nCohInt = self.dataIn.nCohInt
734 self.dataOut.nIncohInt = 1
734 self.dataOut.nIncohInt = 1
735 self.dataOut.ippSeconds = self.dataIn.ippSeconds
735 self.dataOut.ippSeconds = self.dataIn.ippSeconds
736 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
736 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
737
737
738 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
738 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
739 self.dataOut.frequency = self.dataIn.frequency
739 self.dataOut.frequency = self.dataIn.frequency
740 self.dataOut.realtime = self.dataIn.realtime
740 self.dataOut.realtime = self.dataIn.realtime
741
741
742 def __getFft(self):
742 def __getFft(self):
743 """
743 """
744 Convierte valores de Voltaje a Spectra
744 Convierte valores de Voltaje a Spectra
745
745
746 Affected:
746 Affected:
747 self.dataOut.data_spc
747 self.dataOut.data_spc
748 self.dataOut.data_cspc
748 self.dataOut.data_cspc
749 self.dataOut.data_dc
749 self.dataOut.data_dc
750 self.dataOut.heightList
750 self.dataOut.heightList
751 self.profIndex
751 self.profIndex
752 self.buffer
752 self.buffer
753 self.dataOut.flagNoData
753 self.dataOut.flagNoData
754 """
754 """
755 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
755 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
756 fft_volt = fft_volt.astype(numpy.dtype('complex'))
756 fft_volt = fft_volt.astype(numpy.dtype('complex'))
757 dc = fft_volt[:,0,:]
757 dc = fft_volt[:,0,:]
758
758
759 #calculo de self-spectra
759 #calculo de self-spectra
760 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
760 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
761 spc = fft_volt * numpy.conjugate(fft_volt)
761 spc = fft_volt * numpy.conjugate(fft_volt)
762 spc = spc.real
762 spc = spc.real
763
763
764 blocksize = 0
764 blocksize = 0
765 blocksize += dc.size
765 blocksize += dc.size
766 blocksize += spc.size
766 blocksize += spc.size
767
767
768 cspc = None
768 cspc = None
769 pairIndex = 0
769 pairIndex = 0
770 if self.dataOut.pairsList != None:
770 if self.dataOut.pairsList != None:
771 #calculo de cross-spectra
771 #calculo de cross-spectra
772 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
772 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
773 for pair in self.dataOut.pairsList:
773 for pair in self.dataOut.pairsList:
774 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
774 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
775 pairIndex += 1
775 pairIndex += 1
776 blocksize += cspc.size
776 blocksize += cspc.size
777
777
778 self.dataOut.data_spc = spc
778 self.dataOut.data_spc = spc
779 self.dataOut.data_cspc = cspc
779 self.dataOut.data_cspc = cspc
780 self.dataOut.data_dc = dc
780 self.dataOut.data_dc = dc
781 self.dataOut.blockSize = blocksize
781 self.dataOut.blockSize = blocksize
782 self.dataOut.flagShiftFFT = False
782 self.dataOut.flagShiftFFT = False
783
783
784 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None):
784 def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None):
785
785
786 self.dataOut.flagNoData = True
786 self.dataOut.flagNoData = True
787
787
788 if self.dataIn.type == "Spectra":
788 if self.dataIn.type == "Spectra":
789 self.dataOut.copy(self.dataIn)
789 self.dataOut.copy(self.dataIn)
790 return
790 return
791
791
792 if self.dataIn.type == "Voltage":
792 if self.dataIn.type == "Voltage":
793
793
794 if nFFTPoints == None:
794 if nFFTPoints == None:
795 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
795 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
796
796
797 if pairsList == None:
797 if pairsList == None:
798 nPairs = 0
798 nPairs = 0
799 else:
799 else:
800 nPairs = len(pairsList)
800 nPairs = len(pairsList)
801
801
802 if ippFactor == None:
802 if ippFactor == None:
803 ippFactor = 1
803 ippFactor = 1
804 self.dataOut.ippFactor = ippFactor
804 self.dataOut.ippFactor = ippFactor
805
805
806 self.dataOut.nFFTPoints = nFFTPoints
806 self.dataOut.nFFTPoints = nFFTPoints
807 self.dataOut.pairsList = pairsList
807 self.dataOut.pairsList = pairsList
808 self.dataOut.nPairs = nPairs
808 self.dataOut.nPairs = nPairs
809
809
810 if self.buffer == None:
810 if self.buffer == None:
811 self.buffer = numpy.zeros((self.dataIn.nChannels,
811 self.buffer = numpy.zeros((self.dataIn.nChannels,
812 nProfiles,
812 nProfiles,
813 self.dataIn.nHeights),
813 self.dataIn.nHeights),
814 dtype='complex')
814 dtype='complex')
815
815
816
816
817 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
817 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
818 self.profIndex += 1
818 self.profIndex += 1
819
819
820 if self.firstdatatime == None:
820 if self.firstdatatime == None:
821 self.firstdatatime = self.dataIn.utctime
821 self.firstdatatime = self.dataIn.utctime
822
822
823 if self.profIndex == nProfiles:
823 if self.profIndex == nProfiles:
824 self.__updateObjFromInput()
824 self.__updateObjFromInput()
825 self.__getFft()
825 self.__getFft()
826
826
827 self.dataOut.flagNoData = False
827 self.dataOut.flagNoData = False
828
828
829 self.buffer = None
829 self.buffer = None
830 self.firstdatatime = None
830 self.firstdatatime = None
831 self.profIndex = 0
831 self.profIndex = 0
832
832
833 return
833 return
834
834
835 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
835 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
836
836
837 def selectChannels(self, channelList):
837 def selectChannels(self, channelList):
838
838
839 channelIndexList = []
839 channelIndexList = []
840
840
841 for channel in channelList:
841 for channel in channelList:
842 index = self.dataOut.channelList.index(channel)
842 index = self.dataOut.channelList.index(channel)
843 channelIndexList.append(index)
843 channelIndexList.append(index)
844
844
845 self.selectChannelsByIndex(channelIndexList)
845 self.selectChannelsByIndex(channelIndexList)
846
846
847 def selectChannelsByIndex(self, channelIndexList):
847 def selectChannelsByIndex(self, channelIndexList):
848 """
848 """
849 Selecciona un bloque de datos en base a canales segun el channelIndexList
849 Selecciona un bloque de datos en base a canales segun el channelIndexList
850
850
851 Input:
851 Input:
852 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
852 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
853
853
854 Affected:
854 Affected:
855 self.dataOut.data_spc
855 self.dataOut.data_spc
856 self.dataOut.channelIndexList
856 self.dataOut.channelIndexList
857 self.dataOut.nChannels
857 self.dataOut.nChannels
858
858
859 Return:
859 Return:
860 None
860 None
861 """
861 """
862
862
863 for channelIndex in channelIndexList:
863 for channelIndex in channelIndexList:
864 if channelIndex not in self.dataOut.channelIndexList:
864 if channelIndex not in self.dataOut.channelIndexList:
865 print channelIndexList
865 print channelIndexList
866 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
866 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
867
867
868 nChannels = len(channelIndexList)
868 nChannels = len(channelIndexList)
869
869
870 data_spc = self.dataOut.data_spc[channelIndexList,:]
870 data_spc = self.dataOut.data_spc[channelIndexList,:]
871
871
872 self.dataOut.data_spc = data_spc
872 self.dataOut.data_spc = data_spc
873 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
873 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
874 # self.dataOut.nChannels = nChannels
874 # self.dataOut.nChannels = nChannels
875
875
876 return 1
876 return 1
877
877
878 def selectHeights(self, minHei, maxHei):
878 def selectHeights(self, minHei, maxHei):
879 """
879 """
880 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
880 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
881 minHei <= height <= maxHei
881 minHei <= height <= maxHei
882
882
883 Input:
883 Input:
884 minHei : valor minimo de altura a considerar
884 minHei : valor minimo de altura a considerar
885 maxHei : valor maximo de altura a considerar
885 maxHei : valor maximo de altura a considerar
886
886
887 Affected:
887 Affected:
888 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
888 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
889
889
890 Return:
890 Return:
891 1 si el metodo se ejecuto con exito caso contrario devuelve 0
891 1 si el metodo se ejecuto con exito caso contrario devuelve 0
892 """
892 """
893 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
893 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
894 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
894 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
895
895
896 if (maxHei > self.dataOut.heightList[-1]):
896 if (maxHei > self.dataOut.heightList[-1]):
897 maxHei = self.dataOut.heightList[-1]
897 maxHei = self.dataOut.heightList[-1]
898 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
898 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
899
899
900 minIndex = 0
900 minIndex = 0
901 maxIndex = 0
901 maxIndex = 0
902 heights = self.dataOut.heightList
902 heights = self.dataOut.heightList
903
903
904 inda = numpy.where(heights >= minHei)
904 inda = numpy.where(heights >= minHei)
905 indb = numpy.where(heights <= maxHei)
905 indb = numpy.where(heights <= maxHei)
906
906
907 try:
907 try:
908 minIndex = inda[0][0]
908 minIndex = inda[0][0]
909 except:
909 except:
910 minIndex = 0
910 minIndex = 0
911
911
912 try:
912 try:
913 maxIndex = indb[0][-1]
913 maxIndex = indb[0][-1]
914 except:
914 except:
915 maxIndex = len(heights)
915 maxIndex = len(heights)
916
916
917 self.selectHeightsByIndex(minIndex, maxIndex)
917 self.selectHeightsByIndex(minIndex, maxIndex)
918
918
919 return 1
919 return 1
920
920
921
921
922 def selectHeightsByIndex(self, minIndex, maxIndex):
922 def selectHeightsByIndex(self, minIndex, maxIndex):
923 """
923 """
924 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
924 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
925 minIndex <= index <= maxIndex
925 minIndex <= index <= maxIndex
926
926
927 Input:
927 Input:
928 minIndex : valor de indice minimo de altura a considerar
928 minIndex : valor de indice minimo de altura a considerar
929 maxIndex : valor de indice maximo de altura a considerar
929 maxIndex : valor de indice maximo de altura a considerar
930
930
931 Affected:
931 Affected:
932 self.dataOut.data_spc
932 self.dataOut.data_spc
933 self.dataOut.data_cspc
933 self.dataOut.data_cspc
934 self.dataOut.data_dc
934 self.dataOut.data_dc
935 self.dataOut.heightList
935 self.dataOut.heightList
936
936
937 Return:
937 Return:
938 1 si el metodo se ejecuto con exito caso contrario devuelve 0
938 1 si el metodo se ejecuto con exito caso contrario devuelve 0
939 """
939 """
940
940
941 if (minIndex < 0) or (minIndex > maxIndex):
941 if (minIndex < 0) or (minIndex > maxIndex):
942 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
942 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
943
943
944 if (maxIndex >= self.dataOut.nHeights):
944 if (maxIndex >= self.dataOut.nHeights):
945 maxIndex = self.dataOut.nHeights-1
945 maxIndex = self.dataOut.nHeights-1
946 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
946 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
947
947
948 nHeights = maxIndex - minIndex + 1
948 nHeights = maxIndex - minIndex + 1
949
949
950 #Spectra
950 #Spectra
951 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
951 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
952
952
953 data_cspc = None
953 data_cspc = None
954 if self.dataOut.data_cspc != None:
954 if self.dataOut.data_cspc != None:
955 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
955 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
956
956
957 data_dc = None
957 data_dc = None
958 if self.dataOut.data_dc != None:
958 if self.dataOut.data_dc != None:
959 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
959 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
960
960
961 self.dataOut.data_spc = data_spc
961 self.dataOut.data_spc = data_spc
962 self.dataOut.data_cspc = data_cspc
962 self.dataOut.data_cspc = data_cspc
963 self.dataOut.data_dc = data_dc
963 self.dataOut.data_dc = data_dc
964
964
965 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
965 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
966
966
967 return 1
967 return 1
968
968
969 def removeDC(self, mode = 2):
969 def removeDC(self, mode = 2):
970 jspectra = self.dataOut.data_spc
970 jspectra = self.dataOut.data_spc
971 jcspectra = self.dataOut.data_cspc
971 jcspectra = self.dataOut.data_cspc
972
972
973
973
974 num_chan = jspectra.shape[0]
974 num_chan = jspectra.shape[0]
975 num_hei = jspectra.shape[2]
975 num_hei = jspectra.shape[2]
976
976
977 if jcspectra != None:
977 if jcspectra != None:
978 jcspectraExist = True
978 jcspectraExist = True
979 num_pairs = jcspectra.shape[0]
979 num_pairs = jcspectra.shape[0]
980 else: jcspectraExist = False
980 else: jcspectraExist = False
981
981
982 freq_dc = jspectra.shape[1]/2
982 freq_dc = jspectra.shape[1]/2
983 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
983 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
984
984
985 if ind_vel[0]<0:
985 if ind_vel[0]<0:
986 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
986 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
987
987
988 if mode == 1:
988 if mode == 1:
989 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
989 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
990
990
991 if jcspectraExist:
991 if jcspectraExist:
992 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
992 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
993
993
994 if mode == 2:
994 if mode == 2:
995
995
996 vel = numpy.array([-2,-1,1,2])
996 vel = numpy.array([-2,-1,1,2])
997 xx = numpy.zeros([4,4])
997 xx = numpy.zeros([4,4])
998
998
999 for fil in range(4):
999 for fil in range(4):
1000 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1000 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1001
1001
1002 xx_inv = numpy.linalg.inv(xx)
1002 xx_inv = numpy.linalg.inv(xx)
1003 xx_aux = xx_inv[0,:]
1003 xx_aux = xx_inv[0,:]
1004
1004
1005 for ich in range(num_chan):
1005 for ich in range(num_chan):
1006 yy = jspectra[ich,ind_vel,:]
1006 yy = jspectra[ich,ind_vel,:]
1007 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1007 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1008
1008
1009 junkid = jspectra[ich,freq_dc,:]<=0
1009 junkid = jspectra[ich,freq_dc,:]<=0
1010 cjunkid = sum(junkid)
1010 cjunkid = sum(junkid)
1011
1011
1012 if cjunkid.any():
1012 if cjunkid.any():
1013 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1013 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1014
1014
1015 if jcspectraExist:
1015 if jcspectraExist:
1016 for ip in range(num_pairs):
1016 for ip in range(num_pairs):
1017 yy = jcspectra[ip,ind_vel,:]
1017 yy = jcspectra[ip,ind_vel,:]
1018 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
1018 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
1019
1019
1020
1020
1021 self.dataOut.data_spc = jspectra
1021 self.dataOut.data_spc = jspectra
1022 self.dataOut.data_cspc = jcspectra
1022 self.dataOut.data_cspc = jcspectra
1023
1023
1024 return 1
1024 return 1
1025
1025
1026 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
1026 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
1027
1027
1028 jspectra = self.dataOut.data_spc
1028 jspectra = self.dataOut.data_spc
1029 jcspectra = self.dataOut.data_cspc
1029 jcspectra = self.dataOut.data_cspc
1030 jnoise = self.dataOut.getNoise()
1030 jnoise = self.dataOut.getNoise()
1031 num_incoh = self.dataOut.nIncohInt
1031 num_incoh = self.dataOut.nIncohInt
1032
1032
1033 num_channel = jspectra.shape[0]
1033 num_channel = jspectra.shape[0]
1034 num_prof = jspectra.shape[1]
1034 num_prof = jspectra.shape[1]
1035 num_hei = jspectra.shape[2]
1035 num_hei = jspectra.shape[2]
1036
1036
1037 #hei_interf
1037 #hei_interf
1038 if hei_interf == None:
1038 if hei_interf == None:
1039 count_hei = num_hei/2 #Como es entero no importa
1039 count_hei = num_hei/2 #Como es entero no importa
1040 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
1040 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
1041 hei_interf = numpy.asarray(hei_interf)[0]
1041 hei_interf = numpy.asarray(hei_interf)[0]
1042 #nhei_interf
1042 #nhei_interf
1043 if (nhei_interf == None):
1043 if (nhei_interf == None):
1044 nhei_interf = 5
1044 nhei_interf = 5
1045 if (nhei_interf < 1):
1045 if (nhei_interf < 1):
1046 nhei_interf = 1
1046 nhei_interf = 1
1047 if (nhei_interf > count_hei):
1047 if (nhei_interf > count_hei):
1048 nhei_interf = count_hei
1048 nhei_interf = count_hei
1049 if (offhei_interf == None):
1049 if (offhei_interf == None):
1050 offhei_interf = 0
1050 offhei_interf = 0
1051
1051
1052 ind_hei = range(num_hei)
1052 ind_hei = range(num_hei)
1053 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
1053 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
1054 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
1054 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
1055 mask_prof = numpy.asarray(range(num_prof))
1055 mask_prof = numpy.asarray(range(num_prof))
1056 num_mask_prof = mask_prof.size
1056 num_mask_prof = mask_prof.size
1057 comp_mask_prof = [0, num_prof/2]
1057 comp_mask_prof = [0, num_prof/2]
1058
1058
1059
1059
1060 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
1060 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
1061 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
1061 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
1062 jnoise = numpy.nan
1062 jnoise = numpy.nan
1063 noise_exist = jnoise[0] < numpy.Inf
1063 noise_exist = jnoise[0] < numpy.Inf
1064
1064
1065 #Subrutina de Remocion de la Interferencia
1065 #Subrutina de Remocion de la Interferencia
1066 for ich in range(num_channel):
1066 for ich in range(num_channel):
1067 #Se ordena los espectros segun su potencia (menor a mayor)
1067 #Se ordena los espectros segun su potencia (menor a mayor)
1068 power = jspectra[ich,mask_prof,:]
1068 power = jspectra[ich,mask_prof,:]
1069 power = power[:,hei_interf]
1069 power = power[:,hei_interf]
1070 power = power.sum(axis = 0)
1070 power = power.sum(axis = 0)
1071 psort = power.ravel().argsort()
1071 psort = power.ravel().argsort()
1072
1072
1073 #Se estima la interferencia promedio en los Espectros de Potencia empleando
1073 #Se estima la interferencia promedio en los Espectros de Potencia empleando
1074 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1074 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1075
1075
1076 if noise_exist:
1076 if noise_exist:
1077 # tmp_noise = jnoise[ich] / num_prof
1077 # tmp_noise = jnoise[ich] / num_prof
1078 tmp_noise = jnoise[ich]
1078 tmp_noise = jnoise[ich]
1079 junkspc_interf = junkspc_interf - tmp_noise
1079 junkspc_interf = junkspc_interf - tmp_noise
1080 #junkspc_interf[:,comp_mask_prof] = 0
1080 #junkspc_interf[:,comp_mask_prof] = 0
1081
1081
1082 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
1082 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
1083 jspc_interf = jspc_interf.transpose()
1083 jspc_interf = jspc_interf.transpose()
1084 #Calculando el espectro de interferencia promedio
1084 #Calculando el espectro de interferencia promedio
1085 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
1085 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
1086 noiseid = noiseid[0]
1086 noiseid = noiseid[0]
1087 cnoiseid = noiseid.size
1087 cnoiseid = noiseid.size
1088 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
1088 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
1089 interfid = interfid[0]
1089 interfid = interfid[0]
1090 cinterfid = interfid.size
1090 cinterfid = interfid.size
1091
1091
1092 if (cnoiseid > 0): jspc_interf[noiseid] = 0
1092 if (cnoiseid > 0): jspc_interf[noiseid] = 0
1093
1093
1094 #Expandiendo los perfiles a limpiar
1094 #Expandiendo los perfiles a limpiar
1095 if (cinterfid > 0):
1095 if (cinterfid > 0):
1096 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
1096 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
1097 new_interfid = numpy.asarray(new_interfid)
1097 new_interfid = numpy.asarray(new_interfid)
1098 new_interfid = {x for x in new_interfid}
1098 new_interfid = {x for x in new_interfid}
1099 new_interfid = numpy.array(list(new_interfid))
1099 new_interfid = numpy.array(list(new_interfid))
1100 new_cinterfid = new_interfid.size
1100 new_cinterfid = new_interfid.size
1101 else: new_cinterfid = 0
1101 else: new_cinterfid = 0
1102
1102
1103 for ip in range(new_cinterfid):
1103 for ip in range(new_cinterfid):
1104 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
1104 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
1105 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
1105 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
1106
1106
1107
1107
1108 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
1108 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
1109
1109
1110 #Removiendo la interferencia del punto de mayor interferencia
1110 #Removiendo la interferencia del punto de mayor interferencia
1111 ListAux = jspc_interf[mask_prof].tolist()
1111 ListAux = jspc_interf[mask_prof].tolist()
1112 maxid = ListAux.index(max(ListAux))
1112 maxid = ListAux.index(max(ListAux))
1113
1113
1114
1114
1115 if cinterfid > 0:
1115 if cinterfid > 0:
1116 for ip in range(cinterfid*(interf == 2) - 1):
1116 for ip in range(cinterfid*(interf == 2) - 1):
1117 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
1117 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
1118 cind = len(ind)
1118 cind = len(ind)
1119
1119
1120 if (cind > 0):
1120 if (cind > 0):
1121 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
1121 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
1122
1122
1123 ind = numpy.array([-2,-1,1,2])
1123 ind = numpy.array([-2,-1,1,2])
1124 xx = numpy.zeros([4,4])
1124 xx = numpy.zeros([4,4])
1125
1125
1126 for id1 in range(4):
1126 for id1 in range(4):
1127 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1127 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1128
1128
1129 xx_inv = numpy.linalg.inv(xx)
1129 xx_inv = numpy.linalg.inv(xx)
1130 xx = xx_inv[:,0]
1130 xx = xx_inv[:,0]
1131 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1131 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1132 yy = jspectra[ich,mask_prof[ind],:]
1132 yy = jspectra[ich,mask_prof[ind],:]
1133 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1133 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1134
1134
1135
1135
1136 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
1136 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
1137 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
1137 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
1138
1138
1139 #Remocion de Interferencia en el Cross Spectra
1139 #Remocion de Interferencia en el Cross Spectra
1140 if jcspectra == None: return jspectra, jcspectra
1140 if jcspectra == None: return jspectra, jcspectra
1141 num_pairs = jcspectra.size/(num_prof*num_hei)
1141 num_pairs = jcspectra.size/(num_prof*num_hei)
1142 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
1142 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
1143
1143
1144 for ip in range(num_pairs):
1144 for ip in range(num_pairs):
1145
1145
1146 #-------------------------------------------
1146 #-------------------------------------------
1147
1147
1148 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
1148 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
1149 cspower = cspower[:,hei_interf]
1149 cspower = cspower[:,hei_interf]
1150 cspower = cspower.sum(axis = 0)
1150 cspower = cspower.sum(axis = 0)
1151
1151
1152 cspsort = cspower.ravel().argsort()
1152 cspsort = cspower.ravel().argsort()
1153 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1153 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
1154 junkcspc_interf = junkcspc_interf.transpose()
1154 junkcspc_interf = junkcspc_interf.transpose()
1155 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
1155 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
1156
1156
1157 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
1157 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
1158
1158
1159 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1159 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1160 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1160 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
1161 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
1161 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
1162
1162
1163 for iprof in range(num_prof):
1163 for iprof in range(num_prof):
1164 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
1164 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
1165 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
1165 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
1166
1166
1167 #Removiendo la Interferencia
1167 #Removiendo la Interferencia
1168 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
1168 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
1169
1169
1170 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
1170 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
1171 maxid = ListAux.index(max(ListAux))
1171 maxid = ListAux.index(max(ListAux))
1172
1172
1173 ind = numpy.array([-2,-1,1,2])
1173 ind = numpy.array([-2,-1,1,2])
1174 xx = numpy.zeros([4,4])
1174 xx = numpy.zeros([4,4])
1175
1175
1176 for id1 in range(4):
1176 for id1 in range(4):
1177 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1177 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
1178
1178
1179 xx_inv = numpy.linalg.inv(xx)
1179 xx_inv = numpy.linalg.inv(xx)
1180 xx = xx_inv[:,0]
1180 xx = xx_inv[:,0]
1181
1181
1182 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1182 ind = (ind + maxid + num_mask_prof)%num_mask_prof
1183 yy = jcspectra[ip,mask_prof[ind],:]
1183 yy = jcspectra[ip,mask_prof[ind],:]
1184 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1184 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
1185
1185
1186 #Guardar Resultados
1186 #Guardar Resultados
1187 self.dataOut.data_spc = jspectra
1187 self.dataOut.data_spc = jspectra
1188 self.dataOut.data_cspc = jcspectra
1188 self.dataOut.data_cspc = jcspectra
1189
1189
1190 return 1
1190 return 1
1191
1191
1192 def setRadarFrequency(self, frequency=None):
1192 def setRadarFrequency(self, frequency=None):
1193 if frequency != None:
1193 if frequency != None:
1194 self.dataOut.frequency = frequency
1194 self.dataOut.frequency = frequency
1195
1195
1196 return 1
1196 return 1
1197
1198 def getNoise(self, minHei, maxHei):
1199
1200 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
1201 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
1202
1203 if (maxHei > self.dataOut.heightList[-1]):
1204 maxHei = self.dataOut.heightList[-1]
1205
1206 minIndex = 0
1207 maxIndex = 0
1208 heights = self.dataOut.heightList
1209
1210 inda = numpy.where(heights >= minHei)
1211 indb = numpy.where(heights <= maxHei)
1212
1213 try:
1214 minIndex = inda[0][0]
1215 except:
1216 minIndex = 0
1217
1218 try:
1219 maxIndex = indb[0][-1]
1220 except:
1221 maxIndex = len(heights)
1222
1223 if (minIndex < 0) or (minIndex > maxIndex):
1224 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
1225
1226 if (maxIndex >= self.dataOut.nHeights):
1227 maxIndex = self.dataOut.nHeights-1
1228
1229 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
1230
1231 noise = numpy.zeros(self.dataOut.nChannels)
1232
1233 for channel in range(self.dataOut.nChannels):
1234 daux = data_spc[channel,:,:]
1235 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
1236
1237 self.dataOut.noise = noise.copy()
1238
1239 return 1
1197
1240
1198
1241
1199 class IncohInt(Operation):
1242 class IncohInt(Operation):
1200
1243
1201
1244
1202 __profIndex = 0
1245 __profIndex = 0
1203 __withOverapping = False
1246 __withOverapping = False
1204
1247
1205 __byTime = False
1248 __byTime = False
1206 __initime = None
1249 __initime = None
1207 __lastdatatime = None
1250 __lastdatatime = None
1208 __integrationtime = None
1251 __integrationtime = None
1209
1252
1210 __buffer_spc = None
1253 __buffer_spc = None
1211 __buffer_cspc = None
1254 __buffer_cspc = None
1212 __buffer_dc = None
1255 __buffer_dc = None
1213
1256
1214 __dataReady = False
1257 __dataReady = False
1215
1258
1216 __timeInterval = None
1259 __timeInterval = None
1217
1260
1218 n = None
1261 n = None
1219
1262
1220
1263
1221
1264
1222 def __init__(self):
1265 def __init__(self):
1223
1266
1224 self.__isConfig = False
1267 self.__isConfig = False
1225
1268
1226 def setup(self, n=None, timeInterval=None, overlapping=False):
1269 def setup(self, n=None, timeInterval=None, overlapping=False):
1227 """
1270 """
1228 Set the parameters of the integration class.
1271 Set the parameters of the integration class.
1229
1272
1230 Inputs:
1273 Inputs:
1231
1274
1232 n : Number of coherent integrations
1275 n : Number of coherent integrations
1233 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1276 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1234 overlapping :
1277 overlapping :
1235
1278
1236 """
1279 """
1237
1280
1238 self.__initime = None
1281 self.__initime = None
1239 self.__lastdatatime = 0
1282 self.__lastdatatime = 0
1240 self.__buffer_spc = None
1283 self.__buffer_spc = None
1241 self.__buffer_cspc = None
1284 self.__buffer_cspc = None
1242 self.__buffer_dc = None
1285 self.__buffer_dc = None
1243 self.__dataReady = False
1286 self.__dataReady = False
1244
1287
1245
1288
1246 if n == None and timeInterval == None:
1289 if n == None and timeInterval == None:
1247 raise ValueError, "n or timeInterval should be specified ..."
1290 raise ValueError, "n or timeInterval should be specified ..."
1248
1291
1249 if n != None:
1292 if n != None:
1250 self.n = n
1293 self.n = n
1251 self.__byTime = False
1294 self.__byTime = False
1252 else:
1295 else:
1253 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1296 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
1254 self.n = 9999
1297 self.n = 9999
1255 self.__byTime = True
1298 self.__byTime = True
1256
1299
1257 if overlapping:
1300 if overlapping:
1258 self.__withOverapping = True
1301 self.__withOverapping = True
1259 else:
1302 else:
1260 self.__withOverapping = False
1303 self.__withOverapping = False
1261 self.__buffer_spc = 0
1304 self.__buffer_spc = 0
1262 self.__buffer_cspc = 0
1305 self.__buffer_cspc = 0
1263 self.__buffer_dc = 0
1306 self.__buffer_dc = 0
1264
1307
1265 self.__profIndex = 0
1308 self.__profIndex = 0
1266
1309
1267 def putData(self, data_spc, data_cspc, data_dc):
1310 def putData(self, data_spc, data_cspc, data_dc):
1268
1311
1269 """
1312 """
1270 Add a profile to the __buffer_spc and increase in one the __profileIndex
1313 Add a profile to the __buffer_spc and increase in one the __profileIndex
1271
1314
1272 """
1315 """
1273
1316
1274 if not self.__withOverapping:
1317 if not self.__withOverapping:
1275 self.__buffer_spc += data_spc
1318 self.__buffer_spc += data_spc
1276
1319
1277 if data_cspc == None:
1320 if data_cspc == None:
1278 self.__buffer_cspc = None
1321 self.__buffer_cspc = None
1279 else:
1322 else:
1280 self.__buffer_cspc += data_cspc
1323 self.__buffer_cspc += data_cspc
1281
1324
1282 if data_dc == None:
1325 if data_dc == None:
1283 self.__buffer_dc = None
1326 self.__buffer_dc = None
1284 else:
1327 else:
1285 self.__buffer_dc += data_dc
1328 self.__buffer_dc += data_dc
1286
1329
1287 self.__profIndex += 1
1330 self.__profIndex += 1
1288 return
1331 return
1289
1332
1290 #Overlapping data
1333 #Overlapping data
1291 nChannels, nFFTPoints, nHeis = data_spc.shape
1334 nChannels, nFFTPoints, nHeis = data_spc.shape
1292 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1335 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1293 if data_cspc != None:
1336 if data_cspc != None:
1294 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1337 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1295 if data_dc != None:
1338 if data_dc != None:
1296 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1339 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1297
1340
1298 #If the buffer is empty then it takes the data value
1341 #If the buffer is empty then it takes the data value
1299 if self.__buffer_spc == None:
1342 if self.__buffer_spc == None:
1300 self.__buffer_spc = data_spc
1343 self.__buffer_spc = data_spc
1301
1344
1302 if data_cspc == None:
1345 if data_cspc == None:
1303 self.__buffer_cspc = None
1346 self.__buffer_cspc = None
1304 else:
1347 else:
1305 self.__buffer_cspc += data_cspc
1348 self.__buffer_cspc += data_cspc
1306
1349
1307 if data_dc == None:
1350 if data_dc == None:
1308 self.__buffer_dc = None
1351 self.__buffer_dc = None
1309 else:
1352 else:
1310 self.__buffer_dc += data_dc
1353 self.__buffer_dc += data_dc
1311
1354
1312 self.__profIndex += 1
1355 self.__profIndex += 1
1313 return
1356 return
1314
1357
1315 #If the buffer length is lower than n then stakcing the data value
1358 #If the buffer length is lower than n then stakcing the data value
1316 if self.__profIndex < self.n:
1359 if self.__profIndex < self.n:
1317 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1360 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1318
1361
1319 if data_cspc != None:
1362 if data_cspc != None:
1320 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1363 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1321
1364
1322 if data_dc != None:
1365 if data_dc != None:
1323 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1366 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1324
1367
1325 self.__profIndex += 1
1368 self.__profIndex += 1
1326 return
1369 return
1327
1370
1328 #If the buffer length is equal to n then replacing the last buffer value with the data value
1371 #If the buffer length is equal to n then replacing the last buffer value with the data value
1329 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1372 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1330 self.__buffer_spc[self.n-1] = data_spc
1373 self.__buffer_spc[self.n-1] = data_spc
1331
1374
1332 if data_cspc != None:
1375 if data_cspc != None:
1333 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1376 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1334 self.__buffer_cspc[self.n-1] = data_cspc
1377 self.__buffer_cspc[self.n-1] = data_cspc
1335
1378
1336 if data_dc != None:
1379 if data_dc != None:
1337 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1380 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1338 self.__buffer_dc[self.n-1] = data_dc
1381 self.__buffer_dc[self.n-1] = data_dc
1339
1382
1340 self.__profIndex = self.n
1383 self.__profIndex = self.n
1341 return
1384 return
1342
1385
1343
1386
1344 def pushData(self):
1387 def pushData(self):
1345 """
1388 """
1346 Return the sum of the last profiles and the profiles used in the sum.
1389 Return the sum of the last profiles and the profiles used in the sum.
1347
1390
1348 Affected:
1391 Affected:
1349
1392
1350 self.__profileIndex
1393 self.__profileIndex
1351
1394
1352 """
1395 """
1353 data_spc = None
1396 data_spc = None
1354 data_cspc = None
1397 data_cspc = None
1355 data_dc = None
1398 data_dc = None
1356
1399
1357 if not self.__withOverapping:
1400 if not self.__withOverapping:
1358 data_spc = self.__buffer_spc
1401 data_spc = self.__buffer_spc
1359 data_cspc = self.__buffer_cspc
1402 data_cspc = self.__buffer_cspc
1360 data_dc = self.__buffer_dc
1403 data_dc = self.__buffer_dc
1361
1404
1362 n = self.__profIndex
1405 n = self.__profIndex
1363
1406
1364 self.__buffer_spc = 0
1407 self.__buffer_spc = 0
1365 self.__buffer_cspc = 0
1408 self.__buffer_cspc = 0
1366 self.__buffer_dc = 0
1409 self.__buffer_dc = 0
1367 self.__profIndex = 0
1410 self.__profIndex = 0
1368
1411
1369 return data_spc, data_cspc, data_dc, n
1412 return data_spc, data_cspc, data_dc, n
1370
1413
1371 #Integration with Overlapping
1414 #Integration with Overlapping
1372 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1415 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1373
1416
1374 if self.__buffer_cspc != None:
1417 if self.__buffer_cspc != None:
1375 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1418 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1376
1419
1377 if self.__buffer_dc != None:
1420 if self.__buffer_dc != None:
1378 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1421 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1379
1422
1380 n = self.__profIndex
1423 n = self.__profIndex
1381
1424
1382 return data_spc, data_cspc, data_dc, n
1425 return data_spc, data_cspc, data_dc, n
1383
1426
1384 def byProfiles(self, *args):
1427 def byProfiles(self, *args):
1385
1428
1386 self.__dataReady = False
1429 self.__dataReady = False
1387 avgdata_spc = None
1430 avgdata_spc = None
1388 avgdata_cspc = None
1431 avgdata_cspc = None
1389 avgdata_dc = None
1432 avgdata_dc = None
1390 n = None
1433 n = None
1391
1434
1392 self.putData(*args)
1435 self.putData(*args)
1393
1436
1394 if self.__profIndex == self.n:
1437 if self.__profIndex == self.n:
1395
1438
1396 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1439 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1397 self.__dataReady = True
1440 self.__dataReady = True
1398
1441
1399 return avgdata_spc, avgdata_cspc, avgdata_dc
1442 return avgdata_spc, avgdata_cspc, avgdata_dc
1400
1443
1401 def byTime(self, datatime, *args):
1444 def byTime(self, datatime, *args):
1402
1445
1403 self.__dataReady = False
1446 self.__dataReady = False
1404 avgdata_spc = None
1447 avgdata_spc = None
1405 avgdata_cspc = None
1448 avgdata_cspc = None
1406 avgdata_dc = None
1449 avgdata_dc = None
1407 n = None
1450 n = None
1408
1451
1409 self.putData(*args)
1452 self.putData(*args)
1410
1453
1411 if (datatime - self.__initime) >= self.__integrationtime:
1454 if (datatime - self.__initime) >= self.__integrationtime:
1412 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1455 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1413 self.n = n
1456 self.n = n
1414 self.__dataReady = True
1457 self.__dataReady = True
1415
1458
1416 return avgdata_spc, avgdata_cspc, avgdata_dc
1459 return avgdata_spc, avgdata_cspc, avgdata_dc
1417
1460
1418 def integrate(self, datatime, *args):
1461 def integrate(self, datatime, *args):
1419
1462
1420 if self.__initime == None:
1463 if self.__initime == None:
1421 self.__initime = datatime
1464 self.__initime = datatime
1422
1465
1423 if self.__byTime:
1466 if self.__byTime:
1424 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1467 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1425 else:
1468 else:
1426 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1469 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1427
1470
1428 self.__lastdatatime = datatime
1471 self.__lastdatatime = datatime
1429
1472
1430 if avgdata_spc == None:
1473 if avgdata_spc == None:
1431 return None, None, None, None
1474 return None, None, None, None
1432
1475
1433 avgdatatime = self.__initime
1476 avgdatatime = self.__initime
1434 try:
1477 try:
1435 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1478 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1436 except:
1479 except:
1437 self.__timeInterval = self.__lastdatatime - self.__initime
1480 self.__timeInterval = self.__lastdatatime - self.__initime
1438
1481
1439 deltatime = datatime -self.__lastdatatime
1482 deltatime = datatime -self.__lastdatatime
1440
1483
1441 if not self.__withOverapping:
1484 if not self.__withOverapping:
1442 self.__initime = datatime
1485 self.__initime = datatime
1443 else:
1486 else:
1444 self.__initime += deltatime
1487 self.__initime += deltatime
1445
1488
1446 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1489 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1447
1490
1448 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1491 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1449
1492
1450 if n==1:
1493 if n==1:
1451 dataOut.flagNoData = False
1494 dataOut.flagNoData = False
1452 return
1495 return
1453
1496
1454 if not self.__isConfig:
1497 if not self.__isConfig:
1455 self.setup(n, timeInterval, overlapping)
1498 self.setup(n, timeInterval, overlapping)
1456 self.__isConfig = True
1499 self.__isConfig = True
1457
1500
1458 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1501 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1459 dataOut.data_spc,
1502 dataOut.data_spc,
1460 dataOut.data_cspc,
1503 dataOut.data_cspc,
1461 dataOut.data_dc)
1504 dataOut.data_dc)
1462
1505
1463 # dataOut.timeInterval *= n
1506 # dataOut.timeInterval *= n
1464 dataOut.flagNoData = True
1507 dataOut.flagNoData = True
1465
1508
1466 if self.__dataReady:
1509 if self.__dataReady:
1467
1510
1468 dataOut.data_spc = avgdata_spc
1511 dataOut.data_spc = avgdata_spc
1469 dataOut.data_cspc = avgdata_cspc
1512 dataOut.data_cspc = avgdata_cspc
1470 dataOut.data_dc = avgdata_dc
1513 dataOut.data_dc = avgdata_dc
1471
1514
1472 dataOut.nIncohInt *= self.n
1515 dataOut.nIncohInt *= self.n
1473 dataOut.utctime = avgdatatime
1516 dataOut.utctime = avgdatatime
1474 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1517 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1475 dataOut.timeInterval = self.__timeInterval*self.n
1518 dataOut.timeInterval = self.__timeInterval*self.n
1476 dataOut.flagNoData = False
1519 dataOut.flagNoData = False
1477
1520
1478 class ProfileConcat(Operation):
1521 class ProfileConcat(Operation):
1479
1522
1480 __isConfig = False
1523 __isConfig = False
1481 buffer = None
1524 buffer = None
1482
1525
1483 def __init__(self):
1526 def __init__(self):
1484
1527
1485 self.profileIndex = 0
1528 self.profileIndex = 0
1486
1529
1487 def reset(self):
1530 def reset(self):
1488 self.buffer = numpy.zeros_like(self.buffer)
1531 self.buffer = numpy.zeros_like(self.buffer)
1489 self.start_index = 0
1532 self.start_index = 0
1490 self.times = 1
1533 self.times = 1
1491
1534
1492 def setup(self, data, m, n=1):
1535 def setup(self, data, m, n=1):
1493 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1536 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1494 self.profiles = data.shape[1]
1537 self.profiles = data.shape[1]
1495 self.start_index = 0
1538 self.start_index = 0
1496 self.times = 1
1539 self.times = 1
1497
1540
1498 def concat(self, data):
1541 def concat(self, data):
1499
1542
1500 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
1543 self.buffer[:,self.start_index:self.profiles*self.times] = data.copy()
1501 self.start_index = self.start_index + self.profiles
1544 self.start_index = self.start_index + self.profiles
1502
1545
1503 def run(self, dataOut, m):
1546 def run(self, dataOut, m):
1504
1547
1505 dataOut.flagNoData = True
1548 dataOut.flagNoData = True
1506
1549
1507 if not self.__isConfig:
1550 if not self.__isConfig:
1508 self.setup(dataOut.data, m, 1)
1551 self.setup(dataOut.data, m, 1)
1509 self.__isConfig = True
1552 self.__isConfig = True
1510
1553
1511 self.concat(dataOut.data)
1554 self.concat(dataOut.data)
1512 self.times += 1
1555 self.times += 1
1513 if self.times > m:
1556 if self.times > m:
1514 dataOut.data = self.buffer
1557 dataOut.data = self.buffer
1515 self.reset()
1558 self.reset()
1516 dataOut.flagNoData = False
1559 dataOut.flagNoData = False
1517 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1560 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1518 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1561 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1519 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
1562 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5
1520 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1563 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1521
1564
1522
1565
1523
1566
1524 class ProfileSelector(Operation):
1567 class ProfileSelector(Operation):
1525
1568
1526 profileIndex = None
1569 profileIndex = None
1527 # Tamanho total de los perfiles
1570 # Tamanho total de los perfiles
1528 nProfiles = None
1571 nProfiles = None
1529
1572
1530 def __init__(self):
1573 def __init__(self):
1531
1574
1532 self.profileIndex = 0
1575 self.profileIndex = 0
1533
1576
1534 def incIndex(self):
1577 def incIndex(self):
1535 self.profileIndex += 1
1578 self.profileIndex += 1
1536
1579
1537 if self.profileIndex >= self.nProfiles:
1580 if self.profileIndex >= self.nProfiles:
1538 self.profileIndex = 0
1581 self.profileIndex = 0
1539
1582
1540 def isProfileInRange(self, minIndex, maxIndex):
1583 def isProfileInRange(self, minIndex, maxIndex):
1541
1584
1542 if self.profileIndex < minIndex:
1585 if self.profileIndex < minIndex:
1543 return False
1586 return False
1544
1587
1545 if self.profileIndex > maxIndex:
1588 if self.profileIndex > maxIndex:
1546 return False
1589 return False
1547
1590
1548 return True
1591 return True
1549
1592
1550 def isProfileInList(self, profileList):
1593 def isProfileInList(self, profileList):
1551
1594
1552 if self.profileIndex not in profileList:
1595 if self.profileIndex not in profileList:
1553 return False
1596 return False
1554
1597
1555 return True
1598 return True
1556
1599
1557 def run(self, dataOut, profileList=None, profileRangeList=None):
1600 def run(self, dataOut, profileList=None, profileRangeList=None):
1558
1601
1559 dataOut.flagNoData = True
1602 dataOut.flagNoData = True
1560 self.nProfiles = dataOut.nProfiles
1603 self.nProfiles = dataOut.nProfiles
1561
1604
1562 if profileList != None:
1605 if profileList != None:
1563 if self.isProfileInList(profileList):
1606 if self.isProfileInList(profileList):
1564 dataOut.flagNoData = False
1607 dataOut.flagNoData = False
1565
1608
1566 self.incIndex()
1609 self.incIndex()
1567 return 1
1610 return 1
1568
1611
1569
1612
1570 elif profileRangeList != None:
1613 elif profileRangeList != None:
1571 minIndex = profileRangeList[0]
1614 minIndex = profileRangeList[0]
1572 maxIndex = profileRangeList[1]
1615 maxIndex = profileRangeList[1]
1573 if self.isProfileInRange(minIndex, maxIndex):
1616 if self.isProfileInRange(minIndex, maxIndex):
1574 dataOut.flagNoData = False
1617 dataOut.flagNoData = False
1575
1618
1576 self.incIndex()
1619 self.incIndex()
1577 return 1
1620 return 1
1578
1621
1579 else:
1622 else:
1580 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1623 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1581
1624
1582 return 0
1625 return 0
1583
1626
1584 class SpectraHeisProc(ProcessingUnit):
1627 class SpectraHeisProc(ProcessingUnit):
1585 def __init__(self):
1628 def __init__(self):
1586 self.objectDict = {}
1629 self.objectDict = {}
1587 # self.buffer = None
1630 # self.buffer = None
1588 # self.firstdatatime = None
1631 # self.firstdatatime = None
1589 # self.profIndex = 0
1632 # self.profIndex = 0
1590 self.dataOut = SpectraHeis()
1633 self.dataOut = SpectraHeis()
1591
1634
1592 def __updateObjFromInput(self):
1635 def __updateObjFromInput(self):
1593 self.dataOut.timeZone = self.dataIn.timeZone
1636 self.dataOut.timeZone = self.dataIn.timeZone
1594 self.dataOut.dstFlag = self.dataIn.dstFlag
1637 self.dataOut.dstFlag = self.dataIn.dstFlag
1595 self.dataOut.errorCount = self.dataIn.errorCount
1638 self.dataOut.errorCount = self.dataIn.errorCount
1596 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1639 self.dataOut.useLocalTime = self.dataIn.useLocalTime
1597
1640
1598 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1641 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1599 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1642 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1600 self.dataOut.channelList = self.dataIn.channelList
1643 self.dataOut.channelList = self.dataIn.channelList
1601 self.dataOut.heightList = self.dataIn.heightList
1644 self.dataOut.heightList = self.dataIn.heightList
1602 # self.dataOut.dtype = self.dataIn.dtype
1645 # self.dataOut.dtype = self.dataIn.dtype
1603 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1646 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1604 # self.dataOut.nHeights = self.dataIn.nHeights
1647 # self.dataOut.nHeights = self.dataIn.nHeights
1605 # self.dataOut.nChannels = self.dataIn.nChannels
1648 # self.dataOut.nChannels = self.dataIn.nChannels
1606 self.dataOut.nBaud = self.dataIn.nBaud
1649 self.dataOut.nBaud = self.dataIn.nBaud
1607 self.dataOut.nCode = self.dataIn.nCode
1650 self.dataOut.nCode = self.dataIn.nCode
1608 self.dataOut.code = self.dataIn.code
1651 self.dataOut.code = self.dataIn.code
1609 # self.dataOut.nProfiles = 1
1652 # self.dataOut.nProfiles = 1
1610 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1653 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1611 self.dataOut.nFFTPoints = self.dataIn.nHeights
1654 self.dataOut.nFFTPoints = self.dataIn.nHeights
1612 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1655 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1613 # self.dataOut.flagNoData = self.dataIn.flagNoData
1656 # self.dataOut.flagNoData = self.dataIn.flagNoData
1614 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1657 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1615 self.dataOut.utctime = self.dataIn.utctime
1658 self.dataOut.utctime = self.dataIn.utctime
1616 # self.dataOut.utctime = self.firstdatatime
1659 # self.dataOut.utctime = self.firstdatatime
1617 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1660 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1618 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1661 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1619 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1662 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1620 self.dataOut.nCohInt = self.dataIn.nCohInt
1663 self.dataOut.nCohInt = self.dataIn.nCohInt
1621 self.dataOut.nIncohInt = 1
1664 self.dataOut.nIncohInt = 1
1622 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1665 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1623 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1666 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1624
1667
1625 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1668 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1626 # self.dataOut.set=self.dataIn.set
1669 # self.dataOut.set=self.dataIn.set
1627 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1670 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1628
1671
1629
1672
1630 def __updateObjFromFits(self):
1673 def __updateObjFromFits(self):
1631 self.dataOut.utctime = self.dataIn.utctime
1674 self.dataOut.utctime = self.dataIn.utctime
1632 self.dataOut.channelIndexList = self.dataIn.channelIndexList
1675 self.dataOut.channelIndexList = self.dataIn.channelIndexList
1633
1676
1634 self.dataOut.channelList = self.dataIn.channelList
1677 self.dataOut.channelList = self.dataIn.channelList
1635 self.dataOut.heightList = self.dataIn.heightList
1678 self.dataOut.heightList = self.dataIn.heightList
1636 self.dataOut.data_spc = self.dataIn.data
1679 self.dataOut.data_spc = self.dataIn.data
1637 self.dataOut.timeInterval = self.dataIn.timeInterval
1680 self.dataOut.timeInterval = self.dataIn.timeInterval
1638 self.dataOut.timeZone = self.dataIn.timeZone
1681 self.dataOut.timeZone = self.dataIn.timeZone
1639 self.dataOut.useLocalTime = True
1682 self.dataOut.useLocalTime = True
1640 # self.dataOut.
1683 # self.dataOut.
1641 # self.dataOut.
1684 # self.dataOut.
1642
1685
1643 def __getFft(self):
1686 def __getFft(self):
1644
1687
1645 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1688 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1646 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1689 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1647 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1690 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1648 self.dataOut.data_spc = spc
1691 self.dataOut.data_spc = spc
1649
1692
1650 def init(self):
1693 def init(self):
1651
1694
1652 self.dataOut.flagNoData = True
1695 self.dataOut.flagNoData = True
1653
1696
1654 if self.dataIn.type == "Fits":
1697 if self.dataIn.type == "Fits":
1655 self.__updateObjFromFits()
1698 self.__updateObjFromFits()
1656 self.dataOut.flagNoData = False
1699 self.dataOut.flagNoData = False
1657 return
1700 return
1658
1701
1659 if self.dataIn.type == "SpectraHeis":
1702 if self.dataIn.type == "SpectraHeis":
1660 self.dataOut.copy(self.dataIn)
1703 self.dataOut.copy(self.dataIn)
1661 return
1704 return
1662
1705
1663 if self.dataIn.type == "Voltage":
1706 if self.dataIn.type == "Voltage":
1664 self.__updateObjFromInput()
1707 self.__updateObjFromInput()
1665 self.__getFft()
1708 self.__getFft()
1666 self.dataOut.flagNoData = False
1709 self.dataOut.flagNoData = False
1667
1710
1668 return
1711 return
1669
1712
1670 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
1713 raise ValueError, "The type object %s is not valid"%(self.dataIn.type)
1671
1714
1672
1715
1673 def selectChannels(self, channelList):
1716 def selectChannels(self, channelList):
1674
1717
1675 channelIndexList = []
1718 channelIndexList = []
1676
1719
1677 for channel in channelList:
1720 for channel in channelList:
1678 index = self.dataOut.channelList.index(channel)
1721 index = self.dataOut.channelList.index(channel)
1679 channelIndexList.append(index)
1722 channelIndexList.append(index)
1680
1723
1681 self.selectChannelsByIndex(channelIndexList)
1724 self.selectChannelsByIndex(channelIndexList)
1682
1725
1683 def selectChannelsByIndex(self, channelIndexList):
1726 def selectChannelsByIndex(self, channelIndexList):
1684 """
1727 """
1685 Selecciona un bloque de datos en base a canales segun el channelIndexList
1728 Selecciona un bloque de datos en base a canales segun el channelIndexList
1686
1729
1687 Input:
1730 Input:
1688 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1731 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1689
1732
1690 Affected:
1733 Affected:
1691 self.dataOut.data
1734 self.dataOut.data
1692 self.dataOut.channelIndexList
1735 self.dataOut.channelIndexList
1693 self.dataOut.nChannels
1736 self.dataOut.nChannels
1694 self.dataOut.m_ProcessingHeader.totalSpectra
1737 self.dataOut.m_ProcessingHeader.totalSpectra
1695 self.dataOut.systemHeaderObj.numChannels
1738 self.dataOut.systemHeaderObj.numChannels
1696 self.dataOut.m_ProcessingHeader.blockSize
1739 self.dataOut.m_ProcessingHeader.blockSize
1697
1740
1698 Return:
1741 Return:
1699 None
1742 None
1700 """
1743 """
1701
1744
1702 for channelIndex in channelIndexList:
1745 for channelIndex in channelIndexList:
1703 if channelIndex not in self.dataOut.channelIndexList:
1746 if channelIndex not in self.dataOut.channelIndexList:
1704 print channelIndexList
1747 print channelIndexList
1705 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1748 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1706
1749
1707 nChannels = len(channelIndexList)
1750 nChannels = len(channelIndexList)
1708
1751
1709 data_spc = self.dataOut.data_spc[channelIndexList,:]
1752 data_spc = self.dataOut.data_spc[channelIndexList,:]
1710
1753
1711 self.dataOut.data_spc = data_spc
1754 self.dataOut.data_spc = data_spc
1712 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1755 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1713
1756
1714 return 1
1757 return 1
1715
1758
1716 class IncohInt4SpectraHeis(Operation):
1759 class IncohInt4SpectraHeis(Operation):
1717
1760
1718 __isConfig = False
1761 __isConfig = False
1719
1762
1720 __profIndex = 0
1763 __profIndex = 0
1721 __withOverapping = False
1764 __withOverapping = False
1722
1765
1723 __byTime = False
1766 __byTime = False
1724 __initime = None
1767 __initime = None
1725 __lastdatatime = None
1768 __lastdatatime = None
1726 __integrationtime = None
1769 __integrationtime = None
1727
1770
1728 __buffer = None
1771 __buffer = None
1729
1772
1730 __dataReady = False
1773 __dataReady = False
1731
1774
1732 n = None
1775 n = None
1733
1776
1734
1777
1735 def __init__(self):
1778 def __init__(self):
1736
1779
1737 self.__isConfig = False
1780 self.__isConfig = False
1738
1781
1739 def setup(self, n=None, timeInterval=None, overlapping=False):
1782 def setup(self, n=None, timeInterval=None, overlapping=False):
1740 """
1783 """
1741 Set the parameters of the integration class.
1784 Set the parameters of the integration class.
1742
1785
1743 Inputs:
1786 Inputs:
1744
1787
1745 n : Number of coherent integrations
1788 n : Number of coherent integrations
1746 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1789 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1747 overlapping :
1790 overlapping :
1748
1791
1749 """
1792 """
1750
1793
1751 self.__initime = None
1794 self.__initime = None
1752 self.__lastdatatime = 0
1795 self.__lastdatatime = 0
1753 self.__buffer = None
1796 self.__buffer = None
1754 self.__dataReady = False
1797 self.__dataReady = False
1755
1798
1756
1799
1757 if n == None and timeInterval == None:
1800 if n == None and timeInterval == None:
1758 raise ValueError, "n or timeInterval should be specified ..."
1801 raise ValueError, "n or timeInterval should be specified ..."
1759
1802
1760 if n != None:
1803 if n != None:
1761 self.n = n
1804 self.n = n
1762 self.__byTime = False
1805 self.__byTime = False
1763 else:
1806 else:
1764 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1807 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1765 self.n = 9999
1808 self.n = 9999
1766 self.__byTime = True
1809 self.__byTime = True
1767
1810
1768 if overlapping:
1811 if overlapping:
1769 self.__withOverapping = True
1812 self.__withOverapping = True
1770 self.__buffer = None
1813 self.__buffer = None
1771 else:
1814 else:
1772 self.__withOverapping = False
1815 self.__withOverapping = False
1773 self.__buffer = 0
1816 self.__buffer = 0
1774
1817
1775 self.__profIndex = 0
1818 self.__profIndex = 0
1776
1819
1777 def putData(self, data):
1820 def putData(self, data):
1778
1821
1779 """
1822 """
1780 Add a profile to the __buffer and increase in one the __profileIndex
1823 Add a profile to the __buffer and increase in one the __profileIndex
1781
1824
1782 """
1825 """
1783
1826
1784 if not self.__withOverapping:
1827 if not self.__withOverapping:
1785 self.__buffer += data.copy()
1828 self.__buffer += data.copy()
1786 self.__profIndex += 1
1829 self.__profIndex += 1
1787 return
1830 return
1788
1831
1789 #Overlapping data
1832 #Overlapping data
1790 nChannels, nHeis = data.shape
1833 nChannels, nHeis = data.shape
1791 data = numpy.reshape(data, (1, nChannels, nHeis))
1834 data = numpy.reshape(data, (1, nChannels, nHeis))
1792
1835
1793 #If the buffer is empty then it takes the data value
1836 #If the buffer is empty then it takes the data value
1794 if self.__buffer == None:
1837 if self.__buffer == None:
1795 self.__buffer = data
1838 self.__buffer = data
1796 self.__profIndex += 1
1839 self.__profIndex += 1
1797 return
1840 return
1798
1841
1799 #If the buffer length is lower than n then stakcing the data value
1842 #If the buffer length is lower than n then stakcing the data value
1800 if self.__profIndex < self.n:
1843 if self.__profIndex < self.n:
1801 self.__buffer = numpy.vstack((self.__buffer, data))
1844 self.__buffer = numpy.vstack((self.__buffer, data))
1802 self.__profIndex += 1
1845 self.__profIndex += 1
1803 return
1846 return
1804
1847
1805 #If the buffer length is equal to n then replacing the last buffer value with the data value
1848 #If the buffer length is equal to n then replacing the last buffer value with the data value
1806 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1849 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1807 self.__buffer[self.n-1] = data
1850 self.__buffer[self.n-1] = data
1808 self.__profIndex = self.n
1851 self.__profIndex = self.n
1809 return
1852 return
1810
1853
1811
1854
1812 def pushData(self):
1855 def pushData(self):
1813 """
1856 """
1814 Return the sum of the last profiles and the profiles used in the sum.
1857 Return the sum of the last profiles and the profiles used in the sum.
1815
1858
1816 Affected:
1859 Affected:
1817
1860
1818 self.__profileIndex
1861 self.__profileIndex
1819
1862
1820 """
1863 """
1821
1864
1822 if not self.__withOverapping:
1865 if not self.__withOverapping:
1823 data = self.__buffer
1866 data = self.__buffer
1824 n = self.__profIndex
1867 n = self.__profIndex
1825
1868
1826 self.__buffer = 0
1869 self.__buffer = 0
1827 self.__profIndex = 0
1870 self.__profIndex = 0
1828
1871
1829 return data, n
1872 return data, n
1830
1873
1831 #Integration with Overlapping
1874 #Integration with Overlapping
1832 data = numpy.sum(self.__buffer, axis=0)
1875 data = numpy.sum(self.__buffer, axis=0)
1833 n = self.__profIndex
1876 n = self.__profIndex
1834
1877
1835 return data, n
1878 return data, n
1836
1879
1837 def byProfiles(self, data):
1880 def byProfiles(self, data):
1838
1881
1839 self.__dataReady = False
1882 self.__dataReady = False
1840 avgdata = None
1883 avgdata = None
1841 n = None
1884 n = None
1842
1885
1843 self.putData(data)
1886 self.putData(data)
1844
1887
1845 if self.__profIndex == self.n:
1888 if self.__profIndex == self.n:
1846
1889
1847 avgdata, n = self.pushData()
1890 avgdata, n = self.pushData()
1848 self.__dataReady = True
1891 self.__dataReady = True
1849
1892
1850 return avgdata
1893 return avgdata
1851
1894
1852 def byTime(self, data, datatime):
1895 def byTime(self, data, datatime):
1853
1896
1854 self.__dataReady = False
1897 self.__dataReady = False
1855 avgdata = None
1898 avgdata = None
1856 n = None
1899 n = None
1857
1900
1858 self.putData(data)
1901 self.putData(data)
1859
1902
1860 if (datatime - self.__initime) >= self.__integrationtime:
1903 if (datatime - self.__initime) >= self.__integrationtime:
1861 avgdata, n = self.pushData()
1904 avgdata, n = self.pushData()
1862 self.n = n
1905 self.n = n
1863 self.__dataReady = True
1906 self.__dataReady = True
1864
1907
1865 return avgdata
1908 return avgdata
1866
1909
1867 def integrate(self, data, datatime=None):
1910 def integrate(self, data, datatime=None):
1868
1911
1869 if self.__initime == None:
1912 if self.__initime == None:
1870 self.__initime = datatime
1913 self.__initime = datatime
1871
1914
1872 if self.__byTime:
1915 if self.__byTime:
1873 avgdata = self.byTime(data, datatime)
1916 avgdata = self.byTime(data, datatime)
1874 else:
1917 else:
1875 avgdata = self.byProfiles(data)
1918 avgdata = self.byProfiles(data)
1876
1919
1877
1920
1878 self.__lastdatatime = datatime
1921 self.__lastdatatime = datatime
1879
1922
1880 if avgdata == None:
1923 if avgdata == None:
1881 return None, None
1924 return None, None
1882
1925
1883 avgdatatime = self.__initime
1926 avgdatatime = self.__initime
1884
1927
1885 deltatime = datatime -self.__lastdatatime
1928 deltatime = datatime -self.__lastdatatime
1886
1929
1887 if not self.__withOverapping:
1930 if not self.__withOverapping:
1888 self.__initime = datatime
1931 self.__initime = datatime
1889 else:
1932 else:
1890 self.__initime += deltatime
1933 self.__initime += deltatime
1891
1934
1892 return avgdata, avgdatatime
1935 return avgdata, avgdatatime
1893
1936
1894 def run(self, dataOut, **kwargs):
1937 def run(self, dataOut, **kwargs):
1895
1938
1896 if not self.__isConfig:
1939 if not self.__isConfig:
1897 self.setup(**kwargs)
1940 self.setup(**kwargs)
1898 self.__isConfig = True
1941 self.__isConfig = True
1899
1942
1900 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1943 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1901
1944
1902 # dataOut.timeInterval *= n
1945 # dataOut.timeInterval *= n
1903 dataOut.flagNoData = True
1946 dataOut.flagNoData = True
1904
1947
1905 if self.__dataReady:
1948 if self.__dataReady:
1906 dataOut.data_spc = avgdata
1949 dataOut.data_spc = avgdata
1907 dataOut.nIncohInt *= self.n
1950 dataOut.nIncohInt *= self.n
1908 # dataOut.nCohInt *= self.n
1951 # dataOut.nCohInt *= self.n
1909 dataOut.utctime = avgdatatime
1952 dataOut.utctime = avgdatatime
1910 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1953 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1911 # dataOut.timeInterval = self.__timeInterval*self.n
1954 # dataOut.timeInterval = self.__timeInterval*self.n
1912 dataOut.flagNoData = False
1955 dataOut.flagNoData = False
1913
1956
1914
1957
1915
1958
1916
1959
1917 No newline at end of file
1960
General Comments 0
You need to be logged in to leave comments. Login now