##// END OF EJS Templates
new changes to indentify and select beams
Daniel Valdez -
r477:9729744d0cb2
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

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