##// END OF EJS Templates
Correcion de plot eje, graficos centrados, seleccion de ploteo real,imag, abs por defecto, pruebas integrando5 min
avaldez -
r1244:464f48b8a1f9
parent child
Show More
@@ -1,1255 +1,1251
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 copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
12 from schainpy import cSchain
13
13
14
14
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
18 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
20 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
22 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
24 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
26 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
28 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError, 'dataTypeCode was not defined'
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34
34
35 def getDataTypeCode(numpyDtype):
35 def getDataTypeCode(numpyDtype):
36
36
37 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
37 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
38 datatype = 0
38 datatype = 0
39 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
39 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
40 datatype = 1
40 datatype = 1
41 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
41 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
42 datatype = 2
42 datatype = 2
43 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
43 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
44 datatype = 3
44 datatype = 3
45 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
45 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
46 datatype = 4
46 datatype = 4
47 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
47 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
48 datatype = 5
48 datatype = 5
49 else:
49 else:
50 datatype = None
50 datatype = None
51
51
52 return datatype
52 return datatype
53
53
54
54
55 def hildebrand_sekhon(data, navg):
55 def hildebrand_sekhon(data, navg):
56 """
56 """
57 This method is for the objective determination of the noise level in Doppler spectra. This
57 This method is for the objective determination of the noise level in Doppler spectra. This
58 implementation technique is based on the fact that the standard deviation of the spectral
58 implementation technique is based on the fact that the standard deviation of the spectral
59 densities is equal to the mean spectral density for white Gaussian noise
59 densities is equal to the mean spectral density for white Gaussian noise
60
60
61 Inputs:
61 Inputs:
62 Data : heights
62 Data : heights
63 navg : numbers of averages
63 navg : numbers of averages
64
64
65 Return:
65 Return:
66 -1 : any error
66 -1 : any error
67 anoise : noise's level
67 anoise : noise's level
68 """
68 """
69
69
70 sortdata = numpy.sort(data, axis=None)
70 sortdata = numpy.sort(data, axis=None)
71 # lenOfData = len(sortdata)
71 # lenOfData = len(sortdata)
72 # nums_min = lenOfData*0.2
72 # nums_min = lenOfData*0.2
73 #
73 #
74 # if nums_min <= 5:
74 # if nums_min <= 5:
75 # nums_min = 5
75 # nums_min = 5
76 #
76 #
77 # sump = 0.
77 # sump = 0.
78 #
78 #
79 # sumq = 0.
79 # sumq = 0.
80 #
80 #
81 # j = 0
81 # j = 0
82 #
82 #
83 # cont = 1
83 # cont = 1
84 #
84 #
85 # while((cont==1)and(j<lenOfData)):
85 # while((cont==1)and(j<lenOfData)):
86 #
86 #
87 # sump += sortdata[j]
87 # sump += sortdata[j]
88 #
88 #
89 # sumq += sortdata[j]**2
89 # sumq += sortdata[j]**2
90 #
90 #
91 # if j > nums_min:
91 # if j > nums_min:
92 # rtest = float(j)/(j-1) + 1.0/navg
92 # rtest = float(j)/(j-1) + 1.0/navg
93 # if ((sumq*j) > (rtest*sump**2)):
93 # if ((sumq*j) > (rtest*sump**2)):
94 # j = j - 1
94 # j = j - 1
95 # sump = sump - sortdata[j]
95 # sump = sump - sortdata[j]
96 # sumq = sumq - sortdata[j]**2
96 # sumq = sumq - sortdata[j]**2
97 # cont = 0
97 # cont = 0
98 #
98 #
99 # j += 1
99 # j += 1
100 #
100 #
101 # lnoise = sump /j
101 # lnoise = sump /j
102 #
102 #
103 # return lnoise
103 # return lnoise
104
104
105 return cSchain.hildebrand_sekhon(sortdata, navg)
105 return cSchain.hildebrand_sekhon(sortdata, navg)
106
106
107
107
108 class Beam:
108 class Beam:
109
109
110 def __init__(self):
110 def __init__(self):
111 self.codeList = []
111 self.codeList = []
112 self.azimuthList = []
112 self.azimuthList = []
113 self.zenithList = []
113 self.zenithList = []
114
114
115
115
116 class GenericData(object):
116 class GenericData(object):
117
117
118 flagNoData = True
118 flagNoData = True
119
119
120 def copy(self, inputObj=None):
120 def copy(self, inputObj=None):
121
121
122 if inputObj == None:
122 if inputObj == None:
123 return copy.deepcopy(self)
123 return copy.deepcopy(self)
124
124
125 for key in inputObj.__dict__.keys():
125 for key in inputObj.__dict__.keys():
126
126
127 attribute = inputObj.__dict__[key]
127 attribute = inputObj.__dict__[key]
128
128
129 # If this attribute is a tuple or list
129 # If this attribute is a tuple or list
130 if type(inputObj.__dict__[key]) in (tuple, list):
130 if type(inputObj.__dict__[key]) in (tuple, list):
131 self.__dict__[key] = attribute[:]
131 self.__dict__[key] = attribute[:]
132 continue
132 continue
133
133
134 # If this attribute is another object or instance
134 # If this attribute is another object or instance
135 if hasattr(attribute, '__dict__'):
135 if hasattr(attribute, '__dict__'):
136 self.__dict__[key] = attribute.copy()
136 self.__dict__[key] = attribute.copy()
137 continue
137 continue
138
138
139 self.__dict__[key] = inputObj.__dict__[key]
139 self.__dict__[key] = inputObj.__dict__[key]
140
140
141 def deepcopy(self):
141 def deepcopy(self):
142
142
143 return copy.deepcopy(self)
143 return copy.deepcopy(self)
144
144
145 def isEmpty(self):
145 def isEmpty(self):
146
146
147 return self.flagNoData
147 return self.flagNoData
148
148
149
149
150 class JROData(GenericData):
150 class JROData(GenericData):
151
151
152 # m_BasicHeader = BasicHeader()
152 # m_BasicHeader = BasicHeader()
153 # m_ProcessingHeader = ProcessingHeader()
153 # m_ProcessingHeader = ProcessingHeader()
154
154
155 systemHeaderObj = SystemHeader()
155 systemHeaderObj = SystemHeader()
156
156
157 radarControllerHeaderObj = RadarControllerHeader()
157 radarControllerHeaderObj = RadarControllerHeader()
158
158
159 # data = None
159 # data = None
160
160
161 type = None
161 type = None
162
162
163 datatype = None # dtype but in string
163 datatype = None # dtype but in string
164
164
165 # dtype = None
165 # dtype = None
166
166
167 # nChannels = None
167 # nChannels = None
168
168
169 # nHeights = None
169 # nHeights = None
170
170
171 nProfiles = None
171 nProfiles = None
172
172
173 heightList = None
173 heightList = None
174
174
175 channelList = None
175 channelList = None
176
176
177 flagDiscontinuousBlock = False
177 flagDiscontinuousBlock = False
178
178
179 useLocalTime = False
179 useLocalTime = False
180
180
181 utctime = None
181 utctime = None
182
182
183 timeZone = None
183 timeZone = None
184
184
185 dstFlag = None
185 dstFlag = None
186
186
187 errorCount = None
187 errorCount = None
188
188
189 blocksize = None
189 blocksize = None
190
190
191 # nCode = None
191 # nCode = None
192 #
192 #
193 # nBaud = None
193 # nBaud = None
194 #
194 #
195 # code = None
195 # code = None
196
196
197 flagDecodeData = False # asumo q la data no esta decodificada
197 flagDecodeData = False # asumo q la data no esta decodificada
198
198
199 flagDeflipData = False # asumo q la data no esta sin flip
199 flagDeflipData = False # asumo q la data no esta sin flip
200
200
201 flagShiftFFT = False
201 flagShiftFFT = False
202
202
203 # ippSeconds = None
203 # ippSeconds = None
204
204
205 # timeInterval = None
205 # timeInterval = None
206
206
207 nCohInt = None
207 nCohInt = None
208
208
209 # noise = None
209 # noise = None
210
210
211 windowOfFilter = 1
211 windowOfFilter = 1
212
212
213 # Speed of ligth
213 # Speed of ligth
214 C = 3e8
214 C = 3e8
215
215
216 frequency = 49.92e6
216 frequency = 49.92e6
217
217
218 realtime = False
218 realtime = False
219
219
220 beacon_heiIndexList = None
220 beacon_heiIndexList = None
221
221
222 last_block = None
222 last_block = None
223
223
224 blocknow = None
224 blocknow = None
225
225
226 azimuth = None
226 azimuth = None
227
227
228 zenith = None
228 zenith = None
229
229
230 beam = Beam()
230 beam = Beam()
231
231
232 profileIndex = None
232 profileIndex = None
233
233
234 def getNoise(self):
234 def getNoise(self):
235
235
236 raise NotImplementedError
236 raise NotImplementedError
237
237
238 def getNChannels(self):
238 def getNChannels(self):
239
239
240 return len(self.channelList)
240 return len(self.channelList)
241
241
242 def getChannelIndexList(self):
242 def getChannelIndexList(self):
243
243
244 return range(self.nChannels)
244 return range(self.nChannels)
245
245
246 def getNHeights(self):
246 def getNHeights(self):
247
247
248 return len(self.heightList)
248 return len(self.heightList)
249
249
250 def getHeiRange(self, extrapoints=0):
250 def getHeiRange(self, extrapoints=0):
251
251
252 heis = self.heightList
252 heis = self.heightList
253 # deltah = self.heightList[1] - self.heightList[0]
253 # deltah = self.heightList[1] - self.heightList[0]
254 #
254 #
255 # heis.append(self.heightList[-1])
255 # heis.append(self.heightList[-1])
256
256
257 return heis
257 return heis
258
258
259 def getDeltaH(self):
259 def getDeltaH(self):
260
260
261 delta = self.heightList[1] - self.heightList[0]
261 delta = self.heightList[1] - self.heightList[0]
262
262
263 return delta
263 return delta
264
264
265 def getltctime(self):
265 def getltctime(self):
266
266
267 if self.useLocalTime:
267 if self.useLocalTime:
268 return self.utctime - self.timeZone * 60
268 return self.utctime - self.timeZone * 60
269
269
270 return self.utctime
270 return self.utctime
271
271
272 def getDatatime(self):
272 def getDatatime(self):
273
273
274 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
274 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
275 return datatimeValue
275 return datatimeValue
276
276
277 def getTimeRange(self):
277 def getTimeRange(self):
278
278
279 datatime = []
279 datatime = []
280
280
281 datatime.append(self.ltctime)
281 datatime.append(self.ltctime)
282 datatime.append(self.ltctime + self.timeInterval + 1)
282 datatime.append(self.ltctime + self.timeInterval + 1)
283
283
284 datatime = numpy.array(datatime)
284 datatime = numpy.array(datatime)
285
285
286 return datatime
286 return datatime
287
287
288 def getFmaxTimeResponse(self):
288 def getFmaxTimeResponse(self):
289
289
290 period = (10**-6) * self.getDeltaH() / (0.15)
290 period = (10**-6) * self.getDeltaH() / (0.15)
291
291
292 PRF = 1. / (period * self.nCohInt)
292 PRF = 1. / (period * self.nCohInt)
293
293
294 fmax = PRF
294 fmax = PRF
295
295
296 return fmax
296 return fmax
297
297
298 def getFmax(self):
298 def getFmax(self):
299 PRF = 1. / (self.ippSeconds * self.nCohInt)
299 PRF = 1. / (self.ippSeconds * self.nCohInt)
300
301 fmax = PRF
300 fmax = PRF
302 return fmax
301 return fmax
303
302
304 def getVmax(self):
303 def getVmax(self):
305
304
306 _lambda = self.C / self.frequency
305 _lambda = self.C / self.frequency
307
306
308 vmax = self.getFmax() * _lambda / 2
307 vmax = self.getFmax() * _lambda / 2
309
308
310 return vmax
309 return vmax
311
310
312 def get_ippSeconds(self):
311 def get_ippSeconds(self):
313 '''
312 '''
314 '''
313 '''
315 return self.radarControllerHeaderObj.ippSeconds
314 return self.radarControllerHeaderObj.ippSeconds
316
315
317 def set_ippSeconds(self, ippSeconds):
316 def set_ippSeconds(self, ippSeconds):
318 '''
317 '''
319 '''
318 '''
320
319
321 self.radarControllerHeaderObj.ippSeconds = ippSeconds
320 self.radarControllerHeaderObj.ippSeconds = ippSeconds
322
321
323 return
322 return
324
323
325 def get_dtype(self):
324 def get_dtype(self):
326 '''
325 '''
327 '''
326 '''
328 return getNumpyDtype(self.datatype)
327 return getNumpyDtype(self.datatype)
329
328
330 def set_dtype(self, numpyDtype):
329 def set_dtype(self, numpyDtype):
331 '''
330 '''
332 '''
331 '''
333
332
334 self.datatype = getDataTypeCode(numpyDtype)
333 self.datatype = getDataTypeCode(numpyDtype)
335
334
336 def get_code(self):
335 def get_code(self):
337 '''
336 '''
338 '''
337 '''
339 return self.radarControllerHeaderObj.code
338 return self.radarControllerHeaderObj.code
340
339
341 def set_code(self, code):
340 def set_code(self, code):
342 '''
341 '''
343 '''
342 '''
344 self.radarControllerHeaderObj.code = code
343 self.radarControllerHeaderObj.code = code
345
344
346 return
345 return
347
346
348 def get_ncode(self):
347 def get_ncode(self):
349 '''
348 '''
350 '''
349 '''
351 return self.radarControllerHeaderObj.nCode
350 return self.radarControllerHeaderObj.nCode
352
351
353 def set_ncode(self, nCode):
352 def set_ncode(self, nCode):
354 '''
353 '''
355 '''
354 '''
356 self.radarControllerHeaderObj.nCode = nCode
355 self.radarControllerHeaderObj.nCode = nCode
357
356
358 return
357 return
359
358
360 def get_nbaud(self):
359 def get_nbaud(self):
361 '''
360 '''
362 '''
361 '''
363 return self.radarControllerHeaderObj.nBaud
362 return self.radarControllerHeaderObj.nBaud
364
363
365 def set_nbaud(self, nBaud):
364 def set_nbaud(self, nBaud):
366 '''
365 '''
367 '''
366 '''
368 self.radarControllerHeaderObj.nBaud = nBaud
367 self.radarControllerHeaderObj.nBaud = nBaud
369
368
370 return
369 return
371
370
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
371 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
373 channelIndexList = property(
372 channelIndexList = property(
374 getChannelIndexList, "I'm the 'channelIndexList' property.")
373 getChannelIndexList, "I'm the 'channelIndexList' property.")
375 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
374 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
376 #noise = property(getNoise, "I'm the 'nHeights' property.")
375 #noise = property(getNoise, "I'm the 'nHeights' property.")
377 datatime = property(getDatatime, "I'm the 'datatime' property")
376 datatime = property(getDatatime, "I'm the 'datatime' property")
378 ltctime = property(getltctime, "I'm the 'ltctime' property")
377 ltctime = property(getltctime, "I'm the 'ltctime' property")
379 ippSeconds = property(get_ippSeconds, set_ippSeconds)
378 ippSeconds = property(get_ippSeconds, set_ippSeconds)
380 dtype = property(get_dtype, set_dtype)
379 dtype = property(get_dtype, set_dtype)
381 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
380 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
382 code = property(get_code, set_code)
381 code = property(get_code, set_code)
383 nCode = property(get_ncode, set_ncode)
382 nCode = property(get_ncode, set_ncode)
384 nBaud = property(get_nbaud, set_nbaud)
383 nBaud = property(get_nbaud, set_nbaud)
385
384
386
385
387 class Voltage(JROData):
386 class Voltage(JROData):
388
387
389 # data es un numpy array de 2 dmensiones (canales, alturas)
388 # data es un numpy array de 2 dmensiones (canales, alturas)
390 data = None
389 data = None
391
390
392 def __init__(self):
391 def __init__(self):
393 '''
392 '''
394 Constructor
393 Constructor
395 '''
394 '''
396
395
397 self.useLocalTime = True
396 self.useLocalTime = True
398
397
399 self.radarControllerHeaderObj = RadarControllerHeader()
398 self.radarControllerHeaderObj = RadarControllerHeader()
400
399
401 self.systemHeaderObj = SystemHeader()
400 self.systemHeaderObj = SystemHeader()
402
401
403 self.type = "Voltage"
402 self.type = "Voltage"
404
403
405 self.data = None
404 self.data = None
406
405
407 # self.dtype = None
406 # self.dtype = None
408
407
409 # self.nChannels = 0
408 # self.nChannels = 0
410
409
411 # self.nHeights = 0
410 # self.nHeights = 0
412
411
413 self.nProfiles = None
412 self.nProfiles = None
414
413
415 self.heightList = None
414 self.heightList = None
416
415
417 self.channelList = None
416 self.channelList = None
418
417
419 # self.channelIndexList = None
418 # self.channelIndexList = None
420
419
421 self.flagNoData = True
420 self.flagNoData = True
422
421
423 self.flagDiscontinuousBlock = False
422 self.flagDiscontinuousBlock = False
424
423
425 self.utctime = None
424 self.utctime = None
426
425
427 self.timeZone = None
426 self.timeZone = None
428
427
429 self.dstFlag = None
428 self.dstFlag = None
430
429
431 self.errorCount = None
430 self.errorCount = None
432
431
433 self.nCohInt = None
432 self.nCohInt = None
434
433
435 self.blocksize = None
434 self.blocksize = None
436
435
437 self.flagDecodeData = False # asumo q la data no esta decodificada
436 self.flagDecodeData = False # asumo q la data no esta decodificada
438
437
439 self.flagDeflipData = False # asumo q la data no esta sin flip
438 self.flagDeflipData = False # asumo q la data no esta sin flip
440
439
441 self.flagShiftFFT = False
440 self.flagShiftFFT = False
442
441
443 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
442 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
444
443
445 self.profileIndex = 0
444 self.profileIndex = 0
446
445
447 def getNoisebyHildebrand(self, channel=None):
446 def getNoisebyHildebrand(self, channel=None):
448 """
447 """
449 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
448 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
450
449
451 Return:
450 Return:
452 noiselevel
451 noiselevel
453 """
452 """
454
453
455 if channel != None:
454 if channel != None:
456 data = self.data[channel]
455 data = self.data[channel]
457 nChannels = 1
456 nChannels = 1
458 else:
457 else:
459 data = self.data
458 data = self.data
460 nChannels = self.nChannels
459 nChannels = self.nChannels
461
460
462 noise = numpy.zeros(nChannels)
461 noise = numpy.zeros(nChannels)
463 power = data * numpy.conjugate(data)
462 power = data * numpy.conjugate(data)
464
463
465 for thisChannel in range(nChannels):
464 for thisChannel in range(nChannels):
466 if nChannels == 1:
465 if nChannels == 1:
467 daux = power[:].real
466 daux = power[:].real
468 else:
467 else:
469 daux = power[thisChannel, :].real
468 daux = power[thisChannel, :].real
470 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
469 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
471
470
472 return noise
471 return noise
473
472
474 def getNoise(self, type=1, channel=None):
473 def getNoise(self, type=1, channel=None):
475
474
476 if type == 1:
475 if type == 1:
477 noise = self.getNoisebyHildebrand(channel)
476 noise = self.getNoisebyHildebrand(channel)
478
477
479 return noise
478 return noise
480
479
481 def getPower(self, channel=None):
480 def getPower(self, channel=None):
482
481
483 if channel != None:
482 if channel != None:
484 data = self.data[channel]
483 data = self.data[channel]
485 else:
484 else:
486 data = self.data
485 data = self.data
487
486
488 power = data * numpy.conjugate(data)
487 power = data * numpy.conjugate(data)
489 powerdB = 10 * numpy.log10(power.real)
488 powerdB = 10 * numpy.log10(power.real)
490 powerdB = numpy.squeeze(powerdB)
489 powerdB = numpy.squeeze(powerdB)
491
490
492 return powerdB
491 return powerdB
493
492
494 def getTimeInterval(self):
493 def getTimeInterval(self):
495
494
496 timeInterval = self.ippSeconds * self.nCohInt
495 timeInterval = self.ippSeconds * self.nCohInt
497
496
498 return timeInterval
497 return timeInterval
499
498
500 noise = property(getNoise, "I'm the 'nHeights' property.")
499 noise = property(getNoise, "I'm the 'nHeights' property.")
501 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
500 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
502
501
503
502
504 class Spectra(JROData):
503 class Spectra(JROData):
505
504
506 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
505 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
507 data_spc = None
506 data_spc = None
508
507
509 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
508 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
510 data_cspc = None
509 data_cspc = None
511
510
512 # data dc es un numpy array de 2 dmensiones (canales, alturas)
511 # data dc es un numpy array de 2 dmensiones (canales, alturas)
513 data_dc = None
512 data_dc = None
514
513
515 # data power
514 # data power
516 data_pwr = None
515 data_pwr = None
517
516
518 nFFTPoints = None
517 nFFTPoints = None
519
518
520 # nPairs = None
519 # nPairs = None
521
520
522 pairsList = None
521 pairsList = None
523
522
524 nIncohInt = None
523 nIncohInt = None
525
524
526 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
525 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
527
526
528 nCohInt = None # se requiere para determinar el valor de timeInterval
527 nCohInt = None # se requiere para determinar el valor de timeInterval
529
528
530 ippFactor = None
529 ippFactor = None
531
530
532 profileIndex = 0
531 profileIndex = 0
533
532
534 plotting = "spectra"
533 plotting = "spectra"
535
534
536 def __init__(self):
535 def __init__(self):
537 '''
536 '''
538 Constructor
537 Constructor
539 '''
538 '''
540
539
541 self.useLocalTime = True
540 self.useLocalTime = True
542
541
543 self.radarControllerHeaderObj = RadarControllerHeader()
542 self.radarControllerHeaderObj = RadarControllerHeader()
544
543
545 self.systemHeaderObj = SystemHeader()
544 self.systemHeaderObj = SystemHeader()
546
545
547 self.type = "Spectra"
546 self.type = "Spectra"
548
547
549 # self.data = None
548 # self.data = None
550
549
551 # self.dtype = None
550 # self.dtype = None
552
551
553 # self.nChannels = 0
552 # self.nChannels = 0
554
553
555 # self.nHeights = 0
554 # self.nHeights = 0
556
555
557 self.nProfiles = None
556 self.nProfiles = None
558
557
559 self.heightList = None
558 self.heightList = None
560
559
561 self.channelList = None
560 self.channelList = None
562
561
563 # self.channelIndexList = None
562 # self.channelIndexList = None
564
563
565 self.pairsList = None
564 self.pairsList = None
566
565
567 self.flagNoData = True
566 self.flagNoData = True
568
567
569 self.flagDiscontinuousBlock = False
568 self.flagDiscontinuousBlock = False
570
569
571 self.utctime = None
570 self.utctime = None
572
571
573 self.nCohInt = None
572 self.nCohInt = None
574
573
575 self.nIncohInt = None
574 self.nIncohInt = None
576
575
577 self.blocksize = None
576 self.blocksize = None
578
577
579 self.nFFTPoints = None
578 self.nFFTPoints = None
580
579
581 self.wavelength = None
580 self.wavelength = None
582
581
583 self.flagDecodeData = False # asumo q la data no esta decodificada
582 self.flagDecodeData = False # asumo q la data no esta decodificada
584
583
585 self.flagDeflipData = False # asumo q la data no esta sin flip
584 self.flagDeflipData = False # asumo q la data no esta sin flip
586
585
587 self.flagShiftFFT = False
586 self.flagShiftFFT = False
588
587
589 self.ippFactor = 1
588 self.ippFactor = 1
590
589
591 #self.noise = None
590 #self.noise = None
592
591
593 self.beacon_heiIndexList = []
592 self.beacon_heiIndexList = []
594
593
595 self.noise_estimation = None
594 self.noise_estimation = None
596
595
597 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
596 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
598 """
597 """
599 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
598 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
600
599
601 Return:
600 Return:
602 noiselevel
601 noiselevel
603 """
602 """
604
603
605 noise = numpy.zeros(self.nChannels)
604 noise = numpy.zeros(self.nChannels)
606
605
607 for channel in range(self.nChannels):
606 for channel in range(self.nChannels):
608 #print "confuse",self.data_spc.dtype
609 daux = self.data_spc[channel,
607 daux = self.data_spc[channel,
610 xmin_index:xmax_index, ymin_index:ymax_index]
608 xmin_index:xmax_index, ymin_index:ymax_index]
611
609
612 #print "HI3.0",(daux.dtype),daux.shape
613 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
610 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
614
611
615 return noise
612 return noise
616
613
617 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
614 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
618
615
619 if self.noise_estimation is not None:
616 if self.noise_estimation is not None:
620 # this was estimated by getNoise Operation defined in jroproc_spectra.py
617 # this was estimated by getNoise Operation defined in jroproc_spectra.py
621 return self.noise_estimation
618 return self.noise_estimation
622 else:
619 else:
623 noise = self.getNoisebyHildebrand(
620 noise = self.getNoisebyHildebrand(
624 xmin_index, xmax_index, ymin_index, ymax_index)
621 xmin_index, xmax_index, ymin_index, ymax_index)
625 return noise
622 return noise
626
623
627 def getFreqRangeTimeResponse(self, extrapoints=0):
624 def getFreqRangeTimeResponse(self, extrapoints=0):
628
625
629 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
626 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
630 freqrange = deltafreq * \
627 freqrange = deltafreq * \
631 (numpy.arange(self.nFFTPoints + extrapoints) -
628 (numpy.arange(self.nFFTPoints + extrapoints) -
632 self.nFFTPoints / 2.) - deltafreq / 2
629 self.nFFTPoints / 2.) - deltafreq / 2
633
630
634 return freqrange
631 return freqrange
635
632
636 def getAcfRange(self, extrapoints=0):
633 def getAcfRange(self, extrapoints=0):
637 #print "miay",self.ippFactor
634 deltafreq = 10. / ( self.getFmax() / (self.nFFTPoints * self.ippFactor) )
638 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
639 #print deltafreq
640 freqrange = deltafreq * \
635 freqrange = deltafreq * \
641 (numpy.arange(self.nFFTPoints + extrapoints) -
636 (numpy.arange(self.nFFTPoints + extrapoints) -
642 self.nFFTPoints / 2.) - deltafreq / 2
637 self.nFFTPoints / 2.) - deltafreq / 2
643
638
644 return freqrange
639 return freqrange
645
640
646 def getFreqRange(self, extrapoints=0):
641 def getFreqRange(self, extrapoints=0):
647
642
648 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
643 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
644 #print "deltafreq", deltafreq
649 freqrange = deltafreq * \
645 freqrange = deltafreq * \
650 (numpy.arange(self.nFFTPoints + extrapoints) -
646 (numpy.arange(self.nFFTPoints + extrapoints) -
651 self.nFFTPoints / 2.) - deltafreq / 2
647 self.nFFTPoints / 2.) - deltafreq / 2
652
648 #print "freqrange",freqrange
653 return freqrange
649 return freqrange
654
650
655 def getVelRange(self, extrapoints=0):
651 def getVelRange(self, extrapoints=0):
656
652
657 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
653 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
658 velrange = deltav * (numpy.arange(self.nFFTPoints +
654 velrange = deltav * (numpy.arange(self.nFFTPoints +
659 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
655 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
660
656
661 return velrange
657 return velrange
662
658
663 def getNPairs(self):
659 def getNPairs(self):
664
660
665 return len(self.pairsList)
661 return len(self.pairsList)
666
662
667 def getPairsIndexList(self):
663 def getPairsIndexList(self):
668
664
669 return range(self.nPairs)
665 return range(self.nPairs)
670
666
671 def getNormFactor(self):
667 def getNormFactor(self):
672
668
673 pwcode = 1
669 pwcode = 1
674
670
675 if self.flagDecodeData:
671 if self.flagDecodeData:
676 pwcode = numpy.sum(self.code[0]**2)
672 pwcode = numpy.sum(self.code[0]**2)
677 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
673 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
678 normFactor = self.nProfiles * self.nIncohInt * \
674 normFactor = self.nProfiles * self.nIncohInt * \
679 self.nCohInt * pwcode * self.windowOfFilter
675 self.nCohInt * pwcode * self.windowOfFilter
680
676
681 return normFactor
677 return normFactor
682
678
683 def getFlagCspc(self):
679 def getFlagCspc(self):
684
680
685 if self.data_cspc is None:
681 if self.data_cspc is None:
686 return True
682 return True
687
683
688 return False
684 return False
689
685
690 def getFlagDc(self):
686 def getFlagDc(self):
691
687
692 if self.data_dc is None:
688 if self.data_dc is None:
693 return True
689 return True
694
690
695 return False
691 return False
696
692
697 def getTimeInterval(self):
693 def getTimeInterval(self):
698
694
699 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
695 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
700
696
701 return timeInterval
697 return timeInterval
702
698
703 def getPower(self):
699 def getPower(self):
704
700
705 factor = self.normFactor
701 factor = self.normFactor
706 z = self.data_spc / factor
702 z = self.data_spc / factor
707 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
703 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
708 avg = numpy.average(z, axis=1)
704 avg = numpy.average(z, axis=1)
709
705
710 return 10 * numpy.log10(avg)
706 return 10 * numpy.log10(avg)
711
707
712 def getCoherence(self, pairsList=None, phase=False):
708 def getCoherence(self, pairsList=None, phase=False):
713
709
714 z = []
710 z = []
715 if pairsList is None:
711 if pairsList is None:
716 pairsIndexList = self.pairsIndexList
712 pairsIndexList = self.pairsIndexList
717 else:
713 else:
718 pairsIndexList = []
714 pairsIndexList = []
719 for pair in pairsList:
715 for pair in pairsList:
720 if pair not in self.pairsList:
716 if pair not in self.pairsList:
721 raise ValueError, "Pair %s is not in dataOut.pairsList" % (
717 raise ValueError, "Pair %s is not in dataOut.pairsList" % (
722 pair)
718 pair)
723 pairsIndexList.append(self.pairsList.index(pair))
719 pairsIndexList.append(self.pairsList.index(pair))
724 for i in range(len(pairsIndexList)):
720 for i in range(len(pairsIndexList)):
725 pair = self.pairsList[pairsIndexList[i]]
721 pair = self.pairsList[pairsIndexList[i]]
726 ccf = numpy.average(
722 ccf = numpy.average(
727 self.data_cspc[pairsIndexList[i], :, :], axis=0)
723 self.data_cspc[pairsIndexList[i], :, :], axis=0)
728 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
724 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
729 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
725 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
730 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
726 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
731 if phase:
727 if phase:
732 data = numpy.arctan2(avgcoherenceComplex.imag,
728 data = numpy.arctan2(avgcoherenceComplex.imag,
733 avgcoherenceComplex.real) * 180 / numpy.pi
729 avgcoherenceComplex.real) * 180 / numpy.pi
734 else:
730 else:
735 data = numpy.abs(avgcoherenceComplex)
731 data = numpy.abs(avgcoherenceComplex)
736
732
737 z.append(data)
733 z.append(data)
738
734
739 return numpy.array(z)
735 return numpy.array(z)
740
736
741 def setValue(self, value):
737 def setValue(self, value):
742
738
743 print "This property should not be initialized"
739 print "This property should not be initialized"
744
740
745 return
741 return
746
742
747 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
743 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
748 pairsIndexList = property(
744 pairsIndexList = property(
749 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
745 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
750 normFactor = property(getNormFactor, setValue,
746 normFactor = property(getNormFactor, setValue,
751 "I'm the 'getNormFactor' property.")
747 "I'm the 'getNormFactor' property.")
752 flag_cspc = property(getFlagCspc, setValue)
748 flag_cspc = property(getFlagCspc, setValue)
753 flag_dc = property(getFlagDc, setValue)
749 flag_dc = property(getFlagDc, setValue)
754 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
750 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
755 timeInterval = property(getTimeInterval, setValue,
751 timeInterval = property(getTimeInterval, setValue,
756 "I'm the 'timeInterval' property")
752 "I'm the 'timeInterval' property")
757
753
758
754
759 class SpectraHeis(Spectra):
755 class SpectraHeis(Spectra):
760
756
761 data_spc = None
757 data_spc = None
762
758
763 data_cspc = None
759 data_cspc = None
764
760
765 data_dc = None
761 data_dc = None
766
762
767 nFFTPoints = None
763 nFFTPoints = None
768
764
769 # nPairs = None
765 # nPairs = None
770
766
771 pairsList = None
767 pairsList = None
772
768
773 nCohInt = None
769 nCohInt = None
774
770
775 nIncohInt = None
771 nIncohInt = None
776
772
777 def __init__(self):
773 def __init__(self):
778
774
779 self.radarControllerHeaderObj = RadarControllerHeader()
775 self.radarControllerHeaderObj = RadarControllerHeader()
780
776
781 self.systemHeaderObj = SystemHeader()
777 self.systemHeaderObj = SystemHeader()
782
778
783 self.type = "SpectraHeis"
779 self.type = "SpectraHeis"
784
780
785 # self.dtype = None
781 # self.dtype = None
786
782
787 # self.nChannels = 0
783 # self.nChannels = 0
788
784
789 # self.nHeights = 0
785 # self.nHeights = 0
790
786
791 self.nProfiles = None
787 self.nProfiles = None
792
788
793 self.heightList = None
789 self.heightList = None
794
790
795 self.channelList = None
791 self.channelList = None
796
792
797 # self.channelIndexList = None
793 # self.channelIndexList = None
798
794
799 self.flagNoData = True
795 self.flagNoData = True
800
796
801 self.flagDiscontinuousBlock = False
797 self.flagDiscontinuousBlock = False
802
798
803 # self.nPairs = 0
799 # self.nPairs = 0
804
800
805 self.utctime = None
801 self.utctime = None
806
802
807 self.blocksize = None
803 self.blocksize = None
808
804
809 self.profileIndex = 0
805 self.profileIndex = 0
810
806
811 self.nCohInt = 1
807 self.nCohInt = 1
812
808
813 self.nIncohInt = 1
809 self.nIncohInt = 1
814
810
815 def getNormFactor(self):
811 def getNormFactor(self):
816 pwcode = 1
812 pwcode = 1
817 if self.flagDecodeData:
813 if self.flagDecodeData:
818 pwcode = numpy.sum(self.code[0]**2)
814 pwcode = numpy.sum(self.code[0]**2)
819
815
820 normFactor = self.nIncohInt * self.nCohInt * pwcode
816 normFactor = self.nIncohInt * self.nCohInt * pwcode
821
817
822 return normFactor
818 return normFactor
823
819
824 def getTimeInterval(self):
820 def getTimeInterval(self):
825
821
826 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
822 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
827
823
828 return timeInterval
824 return timeInterval
829
825
830 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
826 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
831 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
827 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
832
828
833
829
834 class Fits(JROData):
830 class Fits(JROData):
835
831
836 heightList = None
832 heightList = None
837
833
838 channelList = None
834 channelList = None
839
835
840 flagNoData = True
836 flagNoData = True
841
837
842 flagDiscontinuousBlock = False
838 flagDiscontinuousBlock = False
843
839
844 useLocalTime = False
840 useLocalTime = False
845
841
846 utctime = None
842 utctime = None
847
843
848 timeZone = None
844 timeZone = None
849
845
850 # ippSeconds = None
846 # ippSeconds = None
851
847
852 # timeInterval = None
848 # timeInterval = None
853
849
854 nCohInt = None
850 nCohInt = None
855
851
856 nIncohInt = None
852 nIncohInt = None
857
853
858 noise = None
854 noise = None
859
855
860 windowOfFilter = 1
856 windowOfFilter = 1
861
857
862 # Speed of ligth
858 # Speed of ligth
863 C = 3e8
859 C = 3e8
864
860
865 frequency = 49.92e6
861 frequency = 49.92e6
866
862
867 realtime = False
863 realtime = False
868
864
869 def __init__(self):
865 def __init__(self):
870
866
871 self.type = "Fits"
867 self.type = "Fits"
872
868
873 self.nProfiles = None
869 self.nProfiles = None
874
870
875 self.heightList = None
871 self.heightList = None
876
872
877 self.channelList = None
873 self.channelList = None
878
874
879 # self.channelIndexList = None
875 # self.channelIndexList = None
880
876
881 self.flagNoData = True
877 self.flagNoData = True
882
878
883 self.utctime = None
879 self.utctime = None
884
880
885 self.nCohInt = 1
881 self.nCohInt = 1
886
882
887 self.nIncohInt = 1
883 self.nIncohInt = 1
888
884
889 self.useLocalTime = True
885 self.useLocalTime = True
890
886
891 self.profileIndex = 0
887 self.profileIndex = 0
892
888
893 # self.utctime = None
889 # self.utctime = None
894 # self.timeZone = None
890 # self.timeZone = None
895 # self.ltctime = None
891 # self.ltctime = None
896 # self.timeInterval = None
892 # self.timeInterval = None
897 # self.header = None
893 # self.header = None
898 # self.data_header = None
894 # self.data_header = None
899 # self.data = None
895 # self.data = None
900 # self.datatime = None
896 # self.datatime = None
901 # self.flagNoData = False
897 # self.flagNoData = False
902 # self.expName = ''
898 # self.expName = ''
903 # self.nChannels = None
899 # self.nChannels = None
904 # self.nSamples = None
900 # self.nSamples = None
905 # self.dataBlocksPerFile = None
901 # self.dataBlocksPerFile = None
906 # self.comments = ''
902 # self.comments = ''
907 #
903 #
908
904
909 def getltctime(self):
905 def getltctime(self):
910
906
911 if self.useLocalTime:
907 if self.useLocalTime:
912 return self.utctime - self.timeZone * 60
908 return self.utctime - self.timeZone * 60
913
909
914 return self.utctime
910 return self.utctime
915
911
916 def getDatatime(self):
912 def getDatatime(self):
917
913
918 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
914 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
919 return datatime
915 return datatime
920
916
921 def getTimeRange(self):
917 def getTimeRange(self):
922
918
923 datatime = []
919 datatime = []
924
920
925 datatime.append(self.ltctime)
921 datatime.append(self.ltctime)
926 datatime.append(self.ltctime + self.timeInterval)
922 datatime.append(self.ltctime + self.timeInterval)
927
923
928 datatime = numpy.array(datatime)
924 datatime = numpy.array(datatime)
929
925
930 return datatime
926 return datatime
931
927
932 def getHeiRange(self):
928 def getHeiRange(self):
933
929
934 heis = self.heightList
930 heis = self.heightList
935
931
936 return heis
932 return heis
937
933
938 def getNHeights(self):
934 def getNHeights(self):
939
935
940 return len(self.heightList)
936 return len(self.heightList)
941
937
942 def getNChannels(self):
938 def getNChannels(self):
943
939
944 return len(self.channelList)
940 return len(self.channelList)
945
941
946 def getChannelIndexList(self):
942 def getChannelIndexList(self):
947
943
948 return range(self.nChannels)
944 return range(self.nChannels)
949
945
950 def getNoise(self, type=1):
946 def getNoise(self, type=1):
951
947
952 #noise = numpy.zeros(self.nChannels)
948 #noise = numpy.zeros(self.nChannels)
953
949
954 if type == 1:
950 if type == 1:
955 noise = self.getNoisebyHildebrand()
951 noise = self.getNoisebyHildebrand()
956
952
957 if type == 2:
953 if type == 2:
958 noise = self.getNoisebySort()
954 noise = self.getNoisebySort()
959
955
960 if type == 3:
956 if type == 3:
961 noise = self.getNoisebyWindow()
957 noise = self.getNoisebyWindow()
962
958
963 return noise
959 return noise
964
960
965 def getTimeInterval(self):
961 def getTimeInterval(self):
966
962
967 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
963 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
968
964
969 return timeInterval
965 return timeInterval
970
966
971 datatime = property(getDatatime, "I'm the 'datatime' property")
967 datatime = property(getDatatime, "I'm the 'datatime' property")
972 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
968 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
973 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
969 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
974 channelIndexList = property(
970 channelIndexList = property(
975 getChannelIndexList, "I'm the 'channelIndexList' property.")
971 getChannelIndexList, "I'm the 'channelIndexList' property.")
976 noise = property(getNoise, "I'm the 'nHeights' property.")
972 noise = property(getNoise, "I'm the 'nHeights' property.")
977
973
978 ltctime = property(getltctime, "I'm the 'ltctime' property")
974 ltctime = property(getltctime, "I'm the 'ltctime' property")
979 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
975 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
980
976
981
977
982 class Correlation(JROData):
978 class Correlation(JROData):
983
979
984 noise = None
980 noise = None
985
981
986 SNR = None
982 SNR = None
987
983
988 #--------------------------------------------------
984 #--------------------------------------------------
989
985
990 mode = None
986 mode = None
991
987
992 split = False
988 split = False
993
989
994 data_cf = None
990 data_cf = None
995
991
996 lags = None
992 lags = None
997
993
998 lagRange = None
994 lagRange = None
999
995
1000 pairsList = None
996 pairsList = None
1001
997
1002 normFactor = None
998 normFactor = None
1003
999
1004 #--------------------------------------------------
1000 #--------------------------------------------------
1005
1001
1006 # calculateVelocity = None
1002 # calculateVelocity = None
1007
1003
1008 nLags = None
1004 nLags = None
1009
1005
1010 nPairs = None
1006 nPairs = None
1011
1007
1012 nAvg = None
1008 nAvg = None
1013
1009
1014 def __init__(self):
1010 def __init__(self):
1015 '''
1011 '''
1016 Constructor
1012 Constructor
1017 '''
1013 '''
1018 self.radarControllerHeaderObj = RadarControllerHeader()
1014 self.radarControllerHeaderObj = RadarControllerHeader()
1019
1015
1020 self.systemHeaderObj = SystemHeader()
1016 self.systemHeaderObj = SystemHeader()
1021
1017
1022 self.type = "Correlation"
1018 self.type = "Correlation"
1023
1019
1024 self.data = None
1020 self.data = None
1025
1021
1026 self.dtype = None
1022 self.dtype = None
1027
1023
1028 self.nProfiles = None
1024 self.nProfiles = None
1029
1025
1030 self.heightList = None
1026 self.heightList = None
1031
1027
1032 self.channelList = None
1028 self.channelList = None
1033
1029
1034 self.flagNoData = True
1030 self.flagNoData = True
1035
1031
1036 self.flagDiscontinuousBlock = False
1032 self.flagDiscontinuousBlock = False
1037
1033
1038 self.utctime = None
1034 self.utctime = None
1039
1035
1040 self.timeZone = None
1036 self.timeZone = None
1041
1037
1042 self.dstFlag = None
1038 self.dstFlag = None
1043
1039
1044 self.errorCount = None
1040 self.errorCount = None
1045
1041
1046 self.blocksize = None
1042 self.blocksize = None
1047
1043
1048 self.flagDecodeData = False # asumo q la data no esta decodificada
1044 self.flagDecodeData = False # asumo q la data no esta decodificada
1049
1045
1050 self.flagDeflipData = False # asumo q la data no esta sin flip
1046 self.flagDeflipData = False # asumo q la data no esta sin flip
1051
1047
1052 self.pairsList = None
1048 self.pairsList = None
1053
1049
1054 self.nPoints = None
1050 self.nPoints = None
1055
1051
1056 def getPairsList(self):
1052 def getPairsList(self):
1057
1053
1058 return self.pairsList
1054 return self.pairsList
1059
1055
1060 def getNoise(self, mode=2):
1056 def getNoise(self, mode=2):
1061
1057
1062 indR = numpy.where(self.lagR == 0)[0][0]
1058 indR = numpy.where(self.lagR == 0)[0][0]
1063 indT = numpy.where(self.lagT == 0)[0][0]
1059 indT = numpy.where(self.lagT == 0)[0][0]
1064
1060
1065 jspectra0 = self.data_corr[:, :, indR, :]
1061 jspectra0 = self.data_corr[:, :, indR, :]
1066 jspectra = copy.copy(jspectra0)
1062 jspectra = copy.copy(jspectra0)
1067
1063
1068 num_chan = jspectra.shape[0]
1064 num_chan = jspectra.shape[0]
1069 num_hei = jspectra.shape[2]
1065 num_hei = jspectra.shape[2]
1070
1066
1071 freq_dc = jspectra.shape[1] / 2
1067 freq_dc = jspectra.shape[1] / 2
1072 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
1068 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
1073
1069
1074 if ind_vel[0] < 0:
1070 if ind_vel[0] < 0:
1075 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
1071 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
1076
1072
1077 if mode == 1:
1073 if mode == 1:
1078 jspectra[:, freq_dc, :] = (
1074 jspectra[:, freq_dc, :] = (
1079 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
1075 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
1080
1076
1081 if mode == 2:
1077 if mode == 2:
1082
1078
1083 vel = numpy.array([-2, -1, 1, 2])
1079 vel = numpy.array([-2, -1, 1, 2])
1084 xx = numpy.zeros([4, 4])
1080 xx = numpy.zeros([4, 4])
1085
1081
1086 for fil in range(4):
1082 for fil in range(4):
1087 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
1083 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
1088
1084
1089 xx_inv = numpy.linalg.inv(xx)
1085 xx_inv = numpy.linalg.inv(xx)
1090 xx_aux = xx_inv[0, :]
1086 xx_aux = xx_inv[0, :]
1091
1087
1092 for ich in range(num_chan):
1088 for ich in range(num_chan):
1093 yy = jspectra[ich, ind_vel, :]
1089 yy = jspectra[ich, ind_vel, :]
1094 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
1090 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
1095
1091
1096 junkid = jspectra[ich, freq_dc, :] <= 0
1092 junkid = jspectra[ich, freq_dc, :] <= 0
1097 cjunkid = sum(junkid)
1093 cjunkid = sum(junkid)
1098
1094
1099 if cjunkid.any():
1095 if cjunkid.any():
1100 jspectra[ich, freq_dc, junkid.nonzero()] = (
1096 jspectra[ich, freq_dc, junkid.nonzero()] = (
1101 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
1097 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
1102
1098
1103 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
1099 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
1104
1100
1105 return noise
1101 return noise
1106
1102
1107 def getTimeInterval(self):
1103 def getTimeInterval(self):
1108
1104
1109 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1105 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1110
1106
1111 return timeInterval
1107 return timeInterval
1112
1108
1113 def splitFunctions(self):
1109 def splitFunctions(self):
1114
1110
1115 pairsList = self.pairsList
1111 pairsList = self.pairsList
1116 ccf_pairs = []
1112 ccf_pairs = []
1117 acf_pairs = []
1113 acf_pairs = []
1118 ccf_ind = []
1114 ccf_ind = []
1119 acf_ind = []
1115 acf_ind = []
1120 for l in range(len(pairsList)):
1116 for l in range(len(pairsList)):
1121 chan0 = pairsList[l][0]
1117 chan0 = pairsList[l][0]
1122 chan1 = pairsList[l][1]
1118 chan1 = pairsList[l][1]
1123
1119
1124 # Obteniendo pares de Autocorrelacion
1120 # Obteniendo pares de Autocorrelacion
1125 if chan0 == chan1:
1121 if chan0 == chan1:
1126 acf_pairs.append(chan0)
1122 acf_pairs.append(chan0)
1127 acf_ind.append(l)
1123 acf_ind.append(l)
1128 else:
1124 else:
1129 ccf_pairs.append(pairsList[l])
1125 ccf_pairs.append(pairsList[l])
1130 ccf_ind.append(l)
1126 ccf_ind.append(l)
1131
1127
1132 data_acf = self.data_cf[acf_ind]
1128 data_acf = self.data_cf[acf_ind]
1133 data_ccf = self.data_cf[ccf_ind]
1129 data_ccf = self.data_cf[ccf_ind]
1134
1130
1135 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1131 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1136
1132
1137 def getNormFactor(self):
1133 def getNormFactor(self):
1138 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1134 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1139 acf_pairs = numpy.array(acf_pairs)
1135 acf_pairs = numpy.array(acf_pairs)
1140 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1136 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1141
1137
1142 for p in range(self.nPairs):
1138 for p in range(self.nPairs):
1143 pair = self.pairsList[p]
1139 pair = self.pairsList[p]
1144
1140
1145 ch0 = pair[0]
1141 ch0 = pair[0]
1146 ch1 = pair[1]
1142 ch1 = pair[1]
1147
1143
1148 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1144 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1149 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1145 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1150 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1146 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1151
1147
1152 return normFactor
1148 return normFactor
1153
1149
1154 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1150 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1155 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1151 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1156
1152
1157
1153
1158 class Parameters(Spectra):
1154 class Parameters(Spectra):
1159
1155
1160 experimentInfo = None # Information about the experiment
1156 experimentInfo = None # Information about the experiment
1161
1157
1162 # Information from previous data
1158 # Information from previous data
1163
1159
1164 inputUnit = None # Type of data to be processed
1160 inputUnit = None # Type of data to be processed
1165
1161
1166 operation = None # Type of operation to parametrize
1162 operation = None # Type of operation to parametrize
1167
1163
1168 # normFactor = None #Normalization Factor
1164 # normFactor = None #Normalization Factor
1169
1165
1170 groupList = None # List of Pairs, Groups, etc
1166 groupList = None # List of Pairs, Groups, etc
1171
1167
1172 # Parameters
1168 # Parameters
1173
1169
1174 data_param = None # Parameters obtained
1170 data_param = None # Parameters obtained
1175
1171
1176 data_pre = None # Data Pre Parametrization
1172 data_pre = None # Data Pre Parametrization
1177
1173
1178 data_SNR = None # Signal to Noise Ratio
1174 data_SNR = None # Signal to Noise Ratio
1179
1175
1180 # heightRange = None #Heights
1176 # heightRange = None #Heights
1181
1177
1182 abscissaList = None # Abscissa, can be velocities, lags or time
1178 abscissaList = None # Abscissa, can be velocities, lags or time
1183
1179
1184 # noise = None #Noise Potency
1180 # noise = None #Noise Potency
1185
1181
1186 utctimeInit = None # Initial UTC time
1182 utctimeInit = None # Initial UTC time
1187
1183
1188 paramInterval = None # Time interval to calculate Parameters in seconds
1184 paramInterval = None # Time interval to calculate Parameters in seconds
1189
1185
1190 useLocalTime = True
1186 useLocalTime = True
1191
1187
1192 # Fitting
1188 # Fitting
1193
1189
1194 data_error = None # Error of the estimation
1190 data_error = None # Error of the estimation
1195
1191
1196 constants = None
1192 constants = None
1197
1193
1198 library = None
1194 library = None
1199
1195
1200 # Output signal
1196 # Output signal
1201
1197
1202 outputInterval = None # Time interval to calculate output signal in seconds
1198 outputInterval = None # Time interval to calculate output signal in seconds
1203
1199
1204 data_output = None # Out signal
1200 data_output = None # Out signal
1205
1201
1206 nAvg = None
1202 nAvg = None
1207
1203
1208 noise_estimation = None
1204 noise_estimation = None
1209
1205
1210 GauSPC = None # Fit gaussian SPC
1206 GauSPC = None # Fit gaussian SPC
1211
1207
1212 def __init__(self):
1208 def __init__(self):
1213 '''
1209 '''
1214 Constructor
1210 Constructor
1215 '''
1211 '''
1216 self.radarControllerHeaderObj = RadarControllerHeader()
1212 self.radarControllerHeaderObj = RadarControllerHeader()
1217
1213
1218 self.systemHeaderObj = SystemHeader()
1214 self.systemHeaderObj = SystemHeader()
1219
1215
1220 self.type = "Parameters"
1216 self.type = "Parameters"
1221
1217
1222 def getTimeRange1(self, interval):
1218 def getTimeRange1(self, interval):
1223
1219
1224 datatime = []
1220 datatime = []
1225
1221
1226 if self.useLocalTime:
1222 if self.useLocalTime:
1227 time1 = self.utctimeInit - self.timeZone * 60
1223 time1 = self.utctimeInit - self.timeZone * 60
1228 else:
1224 else:
1229 time1 = self.utctimeInit
1225 time1 = self.utctimeInit
1230
1226
1231 datatime.append(time1)
1227 datatime.append(time1)
1232 datatime.append(time1 + interval)
1228 datatime.append(time1 + interval)
1233 datatime = numpy.array(datatime)
1229 datatime = numpy.array(datatime)
1234
1230
1235 return datatime
1231 return datatime
1236
1232
1237 def getTimeInterval(self):
1233 def getTimeInterval(self):
1238
1234
1239 if hasattr(self, 'timeInterval1'):
1235 if hasattr(self, 'timeInterval1'):
1240 return self.timeInterval1
1236 return self.timeInterval1
1241 else:
1237 else:
1242 return self.paramInterval
1238 return self.paramInterval
1243
1239
1244 def setValue(self, value):
1240 def setValue(self, value):
1245
1241
1246 print "This property should not be initialized"
1242 print "This property should not be initialized"
1247
1243
1248 return
1244 return
1249
1245
1250 def getNoise(self):
1246 def getNoise(self):
1251
1247
1252 return self.spc_noise
1248 return self.spc_noise
1253
1249
1254 timeInterval = property(getTimeInterval)
1250 timeInterval = property(getTimeInterval)
1255 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1251 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -1,1743 +1,1728
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13
13
14 class SpectraPlot(Figure):
14 class SpectraPlot(Figure):
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
24 Figure.__init__(self, **kwargs)
24 Figure.__init__(self, **kwargs)
25 self.isConfig = False
25 self.isConfig = False
26 self.__nsubplots = 1
26 self.__nsubplots = 1
27
27
28 self.WIDTH = 250
28 self.WIDTH = 250
29 self.HEIGHT = 250
29 self.HEIGHT = 250
30 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
31 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
32 self.counter_imagwr = 0
32 self.counter_imagwr = 0
33
33
34 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
35
35
36 self.FTP_WEI = None
36 self.FTP_WEI = None
37 self.EXP_CODE = None
37 self.EXP_CODE = None
38 self.SUB_EXP_CODE = None
38 self.SUB_EXP_CODE = None
39 self.PLOT_POS = None
39 self.PLOT_POS = None
40
40
41 self.__xfilter_ena = False
41 self.__xfilter_ena = False
42 self.__yfilter_ena = False
42 self.__yfilter_ena = False
43
43
44 def getSubplots(self):
44 def getSubplots(self):
45
45
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
48
48
49 return nrow, ncol
49 return nrow, ncol
50
50
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
52
52
53 self.__showprofile = showprofile
53 self.__showprofile = showprofile
54 self.nplots = nplots
54 self.nplots = nplots
55
55
56 ncolspan = 1
56 ncolspan = 1
57 colspan = 1
57 colspan = 1
58 if showprofile:
58 if showprofile:
59 ncolspan = 3
59 ncolspan = 3
60 colspan = 2
60 colspan = 2
61 self.__nsubplots = 2
61 self.__nsubplots = 2
62
62
63 self.createFigure(id = id,
63 self.createFigure(id = id,
64 wintitle = wintitle,
64 wintitle = wintitle,
65 widthplot = self.WIDTH + self.WIDTHPROF,
65 widthplot = self.WIDTH + self.WIDTHPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
67 show=show)
67 show=show)
68
68
69 nrow, ncol = self.getSubplots()
69 nrow, ncol = self.getSubplots()
70
70
71 counter = 0
71 counter = 0
72 for y in range(nrow):
72 for y in range(nrow):
73 for x in range(ncol):
73 for x in range(ncol):
74
74
75 if counter >= self.nplots:
75 if counter >= self.nplots:
76 break
76 break
77
77
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
79
79
80 if showprofile:
80 if showprofile:
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
82
82
83 counter += 1
83 counter += 1
84
84
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
88 server=None, folder=None, username=None, password=None,
88 server=None, folder=None, username=None, password=None,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
90 xaxis="frequency", colormap='jet', normFactor=None):
90 xaxis="frequency", colormap='jet', normFactor=None):
91
91
92 """
92 """
93
93
94 Input:
94 Input:
95 dataOut :
95 dataOut :
96 id :
96 id :
97 wintitle :
97 wintitle :
98 channelList :
98 channelList :
99 showProfile :
99 showProfile :
100 xmin : None,
100 xmin : None,
101 xmax : None,
101 xmax : None,
102 ymin : None,
102 ymin : None,
103 ymax : None,
103 ymax : None,
104 zmin : None,
104 zmin : None,
105 zmax : None
105 zmax : None
106 """
106 """
107 if realtime:
107 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
109 print 'Skipping this plot function'
110 return
110 return
111
111
112 if channelList == None:
112 if channelList == None:
113 channelIndexList = dataOut.channelIndexList
113 channelIndexList = dataOut.channelIndexList
114 else:
114 else:
115 channelIndexList = []
115 channelIndexList = []
116 for channel in channelList:
116 for channel in channelList:
117 if channel not in dataOut.channelList:
117 if channel not in dataOut.channelList:
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 channelIndexList.append(dataOut.channelList.index(channel))
119 channelIndexList.append(dataOut.channelList.index(channel))
120
120
121 if normFactor is None:
121 if normFactor is None:
122 factor = dataOut.normFactor
122 factor = dataOut.normFactor
123 else:
123 else:
124 factor = normFactor
124 factor = normFactor
125 if xaxis == "frequency":
125 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
126 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
127 xlabel = "Frequency (kHz)"
128
128
129 elif xaxis == "time":
129 elif xaxis == "time":
130 x = dataOut.getAcfRange(1)
130 x = dataOut.getAcfRange(1)
131 xlabel = "Time (ms)"
131 xlabel = "Time (ms)"
132
132
133 else:
133 else:
134 x = dataOut.getVelRange(1)
134 x = dataOut.getVelRange(1)
135 xlabel = "Velocity (m/s)"
135 xlabel = "Velocity (m/s)"
136
136
137 ylabel = "Range (Km)"
137 ylabel = "Range (Km)"
138
138
139 y = dataOut.getHeiRange()
139 y = dataOut.getHeiRange()
140
140
141 z = dataOut.data_spc/factor
141 z = dataOut.data_spc/factor
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 zdB = 10*numpy.log10(z)
143 zdB = 10*numpy.log10(z)
144
144
145 #print "a000",dataOut.data_spc.dtype
145 #print "a000",dataOut.data_spc.dtype
146 avg = numpy.average(z, axis=1)
146 avg = numpy.average(z, axis=1)
147 avgdB = 10*numpy.log10(avg)
147 avgdB = 10*numpy.log10(avg)
148 #print "before plot"
148 #print "before plot"
149 noise = dataOut.getNoise()/factor
149 noise = dataOut.getNoise()/factor
150 noisedB = 10*numpy.log10(noise)
150 noisedB = 10*numpy.log10(noise)
151
151
152 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
153 title = wintitle + " Spectra"
153 title = wintitle + " Spectra"
154 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
155 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
156
156
157 if not self.isConfig:
157 if not self.isConfig:
158
158
159 nplots = len(channelIndexList)
159 nplots = len(channelIndexList)
160
160
161 self.setup(id=id,
161 self.setup(id=id,
162 nplots=nplots,
162 nplots=nplots,
163 wintitle=wintitle,
163 wintitle=wintitle,
164 showprofile=showprofile,
164 showprofile=showprofile,
165 show=show)
165 show=show)
166
166
167 if xmin == None: xmin = numpy.nanmin(x)
167 if xmin == None: xmin = numpy.nanmin(x)
168 if xmax == None: xmax = numpy.nanmax(x)
168 if xmax == None: xmax = numpy.nanmax(x)
169 if ymin == None: ymin = numpy.nanmin(y)
169 if ymin == None: ymin = numpy.nanmin(y)
170 if ymax == None: ymax = numpy.nanmax(y)
170 if ymax == None: ymax = numpy.nanmax(y)
171 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
172 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
173
173
174 self.FTP_WEI = ftp_wei
174 self.FTP_WEI = ftp_wei
175 self.EXP_CODE = exp_code
175 self.EXP_CODE = exp_code
176 self.SUB_EXP_CODE = sub_exp_code
176 self.SUB_EXP_CODE = sub_exp_code
177 self.PLOT_POS = plot_pos
177 self.PLOT_POS = plot_pos
178
178
179 self.isConfig = True
179 self.isConfig = True
180
180
181 self.setWinTitle(title)
181 self.setWinTitle(title)
182
182
183 for i in range(self.nplots):
183 for i in range(self.nplots):
184 index = channelIndexList[i]
184 index = channelIndexList[i]
185 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
186 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
187 if len(dataOut.beam.codeList) != 0:
187 if len(dataOut.beam.codeList) != 0:
188 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
189
189
190 axes = self.axesList[i*self.__nsubplots]
190 axes = self.axesList[i*self.__nsubplots]
191 axes.pcolor(x, y, zdB[index,:,:],
191 axes.pcolor(x, y, zdB[index,:,:],
192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
193 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
194 ticksize=9, cblabel='')
194 ticksize=9, cblabel='')
195
195
196 if self.__showprofile:
196 if self.__showprofile:
197 axes = self.axesList[i*self.__nsubplots +1]
197 axes = self.axesList[i*self.__nsubplots +1]
198 axes.pline(avgdB[index,:], y,
198 axes.pline(avgdB[index,:], y,
199 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
200 xlabel='dB', ylabel='', title='',
200 xlabel='dB', ylabel='', title='',
201 ytick_visible=False,
201 ytick_visible=False,
202 grid='x')
202 grid='x')
203
203
204 noiseline = numpy.repeat(noisedB[index], len(y))
204 noiseline = numpy.repeat(noisedB[index], len(y))
205 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
206
206
207 self.draw()
207 self.draw()
208
208
209 if figfile == None:
209 if figfile == None:
210 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
211 name = str_datetime
211 name = str_datetime
212 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
213 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
214 figfile = self.getFilename(name)
214 figfile = self.getFilename(name)
215
215
216 self.save(figpath=figpath,
216 self.save(figpath=figpath,
217 figfile=figfile,
217 figfile=figfile,
218 save=save,
218 save=save,
219 ftp=ftp,
219 ftp=ftp,
220 wr_period=wr_period,
220 wr_period=wr_period,
221 thisDatetime=thisDatetime)
221 thisDatetime=thisDatetime)
222
222
223 class ACFPlot(Figure):
223 class ACFPlot(Figure):
224
224
225 isConfig = None
225 isConfig = None
226 __nsubplots = None
226 __nsubplots = None
227
227
228 WIDTHPROF = None
228 WIDTHPROF = None
229 HEIGHTPROF = None
229 HEIGHTPROF = None
230 PREFIX = 'acf'
230 PREFIX = 'acf'
231
231
232 def __init__(self, **kwargs):
232 def __init__(self, **kwargs):
233 Figure.__init__(self, **kwargs)
233 Figure.__init__(self, **kwargs)
234 self.isConfig = False
234 self.isConfig = False
235 self.__nsubplots = 1
235 self.__nsubplots = 1
236
236
237 self.PLOT_CODE = ACF_CODE
237 self.PLOT_CODE = ACF_CODE
238
238
239 self.WIDTH = 900
239 self.WIDTH = 900
240 self.HEIGHT = 700
240 self.HEIGHT = 700
241 self.counter_imagwr = 0
241 self.counter_imagwr = 0
242
242
243 def getSubplots(self):
243 def getSubplots(self):
244 ncol = 1
244 ncol = 1
245 nrow = 1
245 nrow = 1
246
246
247 return nrow, ncol
247 return nrow, ncol
248
248
249 def setup(self, id, nplots, wintitle, show):
249 def setup(self, id, nplots, wintitle, show):
250
250
251 self.nplots = nplots
251 self.nplots = nplots
252
252
253 ncolspan = 1
253 ncolspan = 1
254 colspan = 1
254 colspan = 1
255
255
256 self.createFigure(id = id,
256 self.createFigure(id = id,
257 wintitle = wintitle,
257 wintitle = wintitle,
258 widthplot = self.WIDTH,
258 widthplot = self.WIDTH,
259 heightplot = self.HEIGHT,
259 heightplot = self.HEIGHT,
260 show=show)
260 show=show)
261
261
262 nrow, ncol = self.getSubplots()
262 nrow, ncol = self.getSubplots()
263
263
264 counter = 0
264 counter = 0
265 for y in range(nrow):
265 for y in range(nrow):
266 for x in range(ncol):
266 for x in range(ncol):
267 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
267 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
268
268
269 def run(self, dataOut, id, wintitle="", channelList=None,channel=None,nSamples=None,
269 def run(self, dataOut, id, wintitle="", channelList=None,channel=None,nSamples=None,
270 nSampleList= None,resolutionFactor=None,
270 nSampleList= None,resolutionFactor=None,
271 xmin=None, xmax=None, ymin=None, ymax=None,
271 xmin=None, xmax=None, ymin=None, ymax=None,
272 save=False, figpath='./', figfile=None, show=True,
272 save=False, figpath='./', figfile=None, show=True,
273 ftp=False, wr_period=1, server=None,
273 ftp=False, wr_period=1, server=None,
274 folder=None, username=None, password=None,
274 folder=None, username=None, password=None,
275 xaxis="frequency"):
275 xaxis="frequency"):
276
276
277
278 channel0 = channel
277 channel0 = channel
279 nSamples = nSamples
278 nSamples = nSamples
280 resFactor = resolutionFactor
279 resFactor = resolutionFactor
281
280
282 if nSamples == None:
281 if nSamples == None:
283 nSamples = 20
282 nSamples = 20
284
283
285 if resFactor == None:
284 if resFactor == None:
286 resFactor = 5
285 resFactor = 5
287 #else:
286 #else:
288 # if nSamples not in dataOut.channelList:
287 # if nSamples not in dataOut.channelList:
289 # raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
288 # raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
290
289
291 if channel0 == None:
290 if channel0 == None:
292 channel0 = 0
291 channel0 = 0
293 else:
292 else:
294 if channel0 not in dataOut.channelList:
293 if channel0 not in dataOut.channelList:
295 raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
294 raise ValueError, "Channel %d is not in %s dataOut.channelList"%(channel0, dataOut.channelList)
296
295
297 if channelList == None:
296 if channelList == None:
298 channelIndexList = dataOut.channelIndexList
297 channelIndexList = dataOut.channelIndexList
299 channelList = dataOut.channelList
298 channelList = dataOut.channelList
300 else:
299 else:
301 channelIndexList = []
300 channelIndexList = []
302 for channel in channelList:
301 for channel in channelList:
303 if channel not in dataOut.channelList:
302 if channel not in dataOut.channelList:
304 raise ValueError, "Channel %d is not in dataOut.channelList"
303 raise ValueError, "Channel %d is not in dataOut.channelList"
305 channelIndexList.append(dataOut.channelList.index(channel))
304 channelIndexList.append(dataOut.channelList.index(channel))
306
305
307 #z = dataOut.data_spc/factor
306 #z = dataOut.data_spc/factor
308 factor = dataOut.normFactor
307 factor = dataOut.normFactor
309 y = dataOut.getHeiRange()
308 y = dataOut.getHeiRange()
310 deltaHeight = dataOut.heightList[1]-dataOut.heightList[0]
309 deltaHeight = dataOut.heightList[1]-dataOut.heightList[0]
311 z = dataOut.data_acf
310 z = dataOut.data_acf
312 #z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
311 #z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
313 shape = dataOut.data_acf.shape
312 shape = dataOut.data_acf.shape
314 hei_index = numpy.arange(shape[2])
313 hei_index = numpy.arange(shape[2])
315 hei_plot = numpy.arange(nSamples)*resFactor
314 hei_plot = numpy.arange(nSamples)*resFactor
316 #print hei_plot
317 #import matplotlib.pyplot as plt
318 #c=z[0,:,0]*15+15
319 #plt.plot(c)
320 #plt.show()
321 #print "HOLA#
322
315
323 if nSampleList is not None:
316 if nSampleList is not None:
324 for nsample in nSampleList:
317 for nsample in nSampleList:
325 if nsample not in dataOut.heightList/deltaHeight:
318 if nsample not in dataOut.heightList/deltaHeight:
326 raise ValueError, "nsample %d is not in %s dataOut.heightList"%(nsample,dataOut.heightList)
319 raise ValueError, "nsample %d is not in %s dataOut.heightList"%(nsample,dataOut.heightList)
327
320
328 if nSampleList is not None:
321 if nSampleList is not None:
329 hei_plot = numpy.array(nSampleList)*resFactor
322 hei_plot = numpy.array(nSampleList)*resFactor
330
323
331 if hei_plot[-1] >= hei_index[-1]:
324 if hei_plot[-1] >= hei_index[-1]:
332 print ("La cantidad de puntos en altura es %d y la resolucion es %d Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
325 print ("La cantidad de puntos en altura es %d y la resolucion es %d Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
333 raise ValueError, "resFactor %d multiplicado por el valor de %d nSamples es mayor a %d cantidad total de puntos"%(resFactor,nSamples,hei_index[-1])
326 raise ValueError, "resFactor %d multiplicado por el valor de %d nSamples es mayor a %d cantidad total de puntos"%(resFactor,nSamples,hei_index[-1])
334
327
335 #escalamiento -1 a 1 a resolucion (factor de resolucion en altura)* deltaHeight
328 #escalamiento -1 a 1 a resolucion (factor de resolucion en altura)* deltaHeight
336 min = numpy.min(z[0,:,0])
329 min = numpy.min(z[0,:,0])
337 max =numpy.max(z[0,:,0])
330 max =numpy.max(z[0,:,0])
338
339 for i in range(shape[0]):
331 for i in range(shape[0]):
340 for j in range(shape[2]):
332 for j in range(shape[2]):
341 z[i,:,j]= (((z[i,:,j]-min)/(max-min))*deltaHeight*resFactor + j*deltaHeight)
333 z[i,:,j]= (((z[i,:,j]-min)/(max-min))*deltaHeight*resFactor + j*deltaHeight)
342 #z[i,:,j]= (z[i,:,j]+1.0)*deltaHeight*dataOut.step/2.0 + j*deltaHeight*dataOut.step
343
344 #print deltaHeight
345 #print resFactor
346 #print numpy.max(z[0,:,0])
347 #import matplotlib.pyplot as plt
348 #plt.plot((z[0,:,0])*deltaHeight)
349 #plt.show()
350
334
351 if xaxis == "frequency":
335 if xaxis == "frequency":
352 x = dataOut.getFreqRange()/1000.
336 x = dataOut.getFreqRange()/1000.
353 zdB = 10*numpy.log10(z[channel0,:,hei_plot])
337 zdB = 10*numpy.log10(z[channel0,:,hei_plot])
354 xlabel = "Frequency (kHz)"
338 xlabel = "Frequency (kHz)"
355 ylabel = "Power (dB)"
339 ylabel = "Power (dB)"
356
340
357 elif xaxis == "time":
341 elif xaxis == "time":
358 x = dataOut.getAcfRange()
342 delta= dataOut.getAcfRange()[1]-dataOut.getAcfRange()[0]
343 x = dataOut.getAcfRange()+delta/2.0
359 zdB = z[channel0,:,hei_plot]
344 zdB = z[channel0,:,hei_plot]
360 xlabel = "Time (ms)"
345 xlabel = "Time (ms)"
361 ylabel = "ACF"
346 ylabel = "ACF"
362
347
363 else:
348 else:
364 x = dataOut.getVelRange()
349 x = dataOut.getVelRange()
365 zdB = 10*numpy.log10(z[channel0,:,hei_plot])
350 zdB = 10*numpy.log10(z[channel0,:,hei_plot])
366 xlabel = "Velocity (m/s)"
351 xlabel = "Velocity (m/s)"
367 ylabel = "Power (dB)"
352 ylabel = "Power (dB)"
368
353
369 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
354 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
370 title = wintitle + " ACF Plot Ch %s %s" %(channel0,thisDatetime.strftime("%d-%b-%Y"))
355 title = wintitle + " ACF Plot Ch %s %s" %(channel0,thisDatetime.strftime("%d-%b-%Y"))
371
356
372 if not self.isConfig:
357 if not self.isConfig:
373
358
374 nplots = 1
359 nplots = 1
375
360
376 self.setup(id=id,
361 self.setup(id=id,
377 nplots=nplots,
362 nplots=nplots,
378 wintitle=wintitle,
363 wintitle=wintitle,
379 show=show)
364 show=show)
380
365
381 if xmin == None: xmin = numpy.nanmin(x)*0.9
366 if xmin == None: xmin = numpy.nanmin(x)*0.9
382 if xmax == None: xmax = numpy.nanmax(x)*1.1
367 if xmax == None: xmax = numpy.nanmax(x)*1.1
383 if ymin == None: ymin = numpy.nanmin(zdB)
368 if ymin == None: ymin = numpy.nanmin(zdB)
384 if ymax == None: ymax = numpy.nanmax(zdB)
369 if ymax == None: ymax = numpy.nanmax(zdB)
385
370
386 print ("El parametro resFactor es %d y la resolucion en altura es %d"%(resFactor,deltaHeight ))
371 print ("El parametro resFactor es %d y la resolucion en altura es %d"%(resFactor,deltaHeight ))
387 print ("La cantidad de puntos en altura es %d y la nueva resolucion es %d Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
372 print ("La cantidad de puntos en altura es %d y la nueva resolucion es %d Km"%(hei_plot.shape[0],deltaHeight*resFactor ))
388 print ("La altura maxima es %d Km"%(hei_plot[-1]*deltaHeight ))
373 print ("La altura maxima es %d Km"%(hei_plot[-1]*deltaHeight ))
389
374
390 self.isConfig = True
375 self.isConfig = True
391
376
392 self.setWinTitle(title)
377 self.setWinTitle(title)
393
378
394 title = "ACF Plot: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
379 title = "ACF Plot: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
395 axes = self.axesList[0]
380 axes = self.axesList[0]
396
381
397 legendlabels = ["Range = %dKm" %y[i] for i in hei_plot]
382 legendlabels = ["Range = %dKm" %y[i] for i in hei_plot]
398
383
399 axes.pmultilineyaxis( x, zdB,
384 axes.pmultilineyaxis( x, zdB,
400 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
385 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
401 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
386 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
402 ytick_visible=True, nxticks=5,
387 ytick_visible=True, nxticks=5,
403 grid='x')
388 grid='x')
404
389
405 self.draw()
390 self.draw()
406
391
407 if figfile == None:
392 if figfile == None:
408 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
393 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
409 name = str_datetime
394 name = str_datetime
410 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
395 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
411 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
396 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
412 figfile = self.getFilename(name)
397 figfile = self.getFilename(name)
413
398
414 self.save(figpath=figpath,
399 self.save(figpath=figpath,
415 figfile=figfile,
400 figfile=figfile,
416 save=save,
401 save=save,
417 ftp=ftp,
402 ftp=ftp,
418 wr_period=wr_period,
403 wr_period=wr_period,
419 thisDatetime=thisDatetime)
404 thisDatetime=thisDatetime)
420
405
421
406
422
407
423 class CrossSpectraPlot(Figure):
408 class CrossSpectraPlot(Figure):
424
409
425 isConfig = None
410 isConfig = None
426 __nsubplots = None
411 __nsubplots = None
427
412
428 WIDTH = None
413 WIDTH = None
429 HEIGHT = None
414 HEIGHT = None
430 WIDTHPROF = None
415 WIDTHPROF = None
431 HEIGHTPROF = None
416 HEIGHTPROF = None
432 PREFIX = 'cspc'
417 PREFIX = 'cspc'
433
418
434 def __init__(self, **kwargs):
419 def __init__(self, **kwargs):
435 Figure.__init__(self, **kwargs)
420 Figure.__init__(self, **kwargs)
436 self.isConfig = False
421 self.isConfig = False
437 self.__nsubplots = 4
422 self.__nsubplots = 4
438 self.counter_imagwr = 0
423 self.counter_imagwr = 0
439 self.WIDTH = 250
424 self.WIDTH = 250
440 self.HEIGHT = 250
425 self.HEIGHT = 250
441 self.WIDTHPROF = 0
426 self.WIDTHPROF = 0
442 self.HEIGHTPROF = 0
427 self.HEIGHTPROF = 0
443
428
444 self.PLOT_CODE = CROSS_CODE
429 self.PLOT_CODE = CROSS_CODE
445 self.FTP_WEI = None
430 self.FTP_WEI = None
446 self.EXP_CODE = None
431 self.EXP_CODE = None
447 self.SUB_EXP_CODE = None
432 self.SUB_EXP_CODE = None
448 self.PLOT_POS = None
433 self.PLOT_POS = None
449
434
450 def getSubplots(self):
435 def getSubplots(self):
451
436
452 ncol = 4
437 ncol = 4
453 nrow = self.nplots
438 nrow = self.nplots
454
439
455 return nrow, ncol
440 return nrow, ncol
456
441
457 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
442 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
458
443
459 self.__showprofile = showprofile
444 self.__showprofile = showprofile
460 self.nplots = nplots
445 self.nplots = nplots
461
446
462 ncolspan = 1
447 ncolspan = 1
463 colspan = 1
448 colspan = 1
464
449
465 self.createFigure(id = id,
450 self.createFigure(id = id,
466 wintitle = wintitle,
451 wintitle = wintitle,
467 widthplot = self.WIDTH + self.WIDTHPROF,
452 widthplot = self.WIDTH + self.WIDTHPROF,
468 heightplot = self.HEIGHT + self.HEIGHTPROF,
453 heightplot = self.HEIGHT + self.HEIGHTPROF,
469 show=True)
454 show=True)
470
455
471 nrow, ncol = self.getSubplots()
456 nrow, ncol = self.getSubplots()
472
457
473 counter = 0
458 counter = 0
474 for y in range(nrow):
459 for y in range(nrow):
475 for x in range(ncol):
460 for x in range(ncol):
476 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
461 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
477
462
478 counter += 1
463 counter += 1
479
464
480 def run(self, dataOut, id, wintitle="", pairsList=None,
465 def run(self, dataOut, id, wintitle="", pairsList=None,
481 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
466 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
482 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
467 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
483 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
468 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
484 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
469 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
485 server=None, folder=None, username=None, password=None,
470 server=None, folder=None, username=None, password=None,
486 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
471 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
487 xaxis='frequency'):
472 xaxis='frequency'):
488
473
489 """
474 """
490
475
491 Input:
476 Input:
492 dataOut :
477 dataOut :
493 id :
478 id :
494 wintitle :
479 wintitle :
495 channelList :
480 channelList :
496 showProfile :
481 showProfile :
497 xmin : None,
482 xmin : None,
498 xmax : None,
483 xmax : None,
499 ymin : None,
484 ymin : None,
500 ymax : None,
485 ymax : None,
501 zmin : None,
486 zmin : None,
502 zmax : None
487 zmax : None
503 """
488 """
504
489
505 if pairsList == None:
490 if pairsList == None:
506 pairsIndexList = dataOut.pairsIndexList
491 pairsIndexList = dataOut.pairsIndexList
507 else:
492 else:
508 pairsIndexList = []
493 pairsIndexList = []
509 for pair in pairsList:
494 for pair in pairsList:
510 if pair not in dataOut.pairsList:
495 if pair not in dataOut.pairsList:
511 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
496 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
512 pairsIndexList.append(dataOut.pairsList.index(pair))
497 pairsIndexList.append(dataOut.pairsList.index(pair))
513
498
514 if not pairsIndexList:
499 if not pairsIndexList:
515 return
500 return
516
501
517 if len(pairsIndexList) > 4:
502 if len(pairsIndexList) > 4:
518 pairsIndexList = pairsIndexList[0:4]
503 pairsIndexList = pairsIndexList[0:4]
519
504
520 if normFactor is None:
505 if normFactor is None:
521 factor = dataOut.normFactor
506 factor = dataOut.normFactor
522 else:
507 else:
523 factor = normFactor
508 factor = normFactor
524 x = dataOut.getVelRange(1)
509 x = dataOut.getVelRange(1)
525 y = dataOut.getHeiRange()
510 y = dataOut.getHeiRange()
526 z = dataOut.data_spc[:,:,:]/factor
511 z = dataOut.data_spc[:,:,:]/factor
527 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
512 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
528
513
529 noise = dataOut.noise/factor
514 noise = dataOut.noise/factor
530
515
531 zdB = 10*numpy.log10(z)
516 zdB = 10*numpy.log10(z)
532 noisedB = 10*numpy.log10(noise)
517 noisedB = 10*numpy.log10(noise)
533
518
534 if coh_min == None:
519 if coh_min == None:
535 coh_min = 0.0
520 coh_min = 0.0
536 if coh_max == None:
521 if coh_max == None:
537 coh_max = 1.0
522 coh_max = 1.0
538
523
539 if phase_min == None:
524 if phase_min == None:
540 phase_min = -180
525 phase_min = -180
541 if phase_max == None:
526 if phase_max == None:
542 phase_max = 180
527 phase_max = 180
543
528
544 #thisDatetime = dataOut.datatime
529 #thisDatetime = dataOut.datatime
545 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
530 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
546 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
531 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
547 # xlabel = "Velocity (m/s)"
532 # xlabel = "Velocity (m/s)"
548 ylabel = "Range (Km)"
533 ylabel = "Range (Km)"
549
534
550 if xaxis == "frequency":
535 if xaxis == "frequency":
551 x = dataOut.getFreqRange(1)/1000.
536 x = dataOut.getFreqRange(1)/1000.
552 xlabel = "Frequency (kHz)"
537 xlabel = "Frequency (kHz)"
553
538
554 elif xaxis == "time":
539 elif xaxis == "time":
555 x = dataOut.getAcfRange(1)
540 x = dataOut.getAcfRange(1)
556 xlabel = "Time (ms)"
541 xlabel = "Time (ms)"
557
542
558 else:
543 else:
559 x = dataOut.getVelRange(1)
544 x = dataOut.getVelRange(1)
560 xlabel = "Velocity (m/s)"
545 xlabel = "Velocity (m/s)"
561
546
562 if not self.isConfig:
547 if not self.isConfig:
563
548
564 nplots = len(pairsIndexList)
549 nplots = len(pairsIndexList)
565
550
566 self.setup(id=id,
551 self.setup(id=id,
567 nplots=nplots,
552 nplots=nplots,
568 wintitle=wintitle,
553 wintitle=wintitle,
569 showprofile=False,
554 showprofile=False,
570 show=show)
555 show=show)
571
556
572 avg = numpy.abs(numpy.average(z, axis=1))
557 avg = numpy.abs(numpy.average(z, axis=1))
573 avgdB = 10*numpy.log10(avg)
558 avgdB = 10*numpy.log10(avg)
574
559
575 if xmin == None: xmin = numpy.nanmin(x)
560 if xmin == None: xmin = numpy.nanmin(x)
576 if xmax == None: xmax = numpy.nanmax(x)
561 if xmax == None: xmax = numpy.nanmax(x)
577 if ymin == None: ymin = numpy.nanmin(y)
562 if ymin == None: ymin = numpy.nanmin(y)
578 if ymax == None: ymax = numpy.nanmax(y)
563 if ymax == None: ymax = numpy.nanmax(y)
579 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
564 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
580 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
565 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
581
566
582 self.FTP_WEI = ftp_wei
567 self.FTP_WEI = ftp_wei
583 self.EXP_CODE = exp_code
568 self.EXP_CODE = exp_code
584 self.SUB_EXP_CODE = sub_exp_code
569 self.SUB_EXP_CODE = sub_exp_code
585 self.PLOT_POS = plot_pos
570 self.PLOT_POS = plot_pos
586
571
587 self.isConfig = True
572 self.isConfig = True
588
573
589 self.setWinTitle(title)
574 self.setWinTitle(title)
590
575
591 for i in range(self.nplots):
576 for i in range(self.nplots):
592 pair = dataOut.pairsList[pairsIndexList[i]]
577 pair = dataOut.pairsList[pairsIndexList[i]]
593
578
594 chan_index0 = dataOut.channelList.index(pair[0])
579 chan_index0 = dataOut.channelList.index(pair[0])
595 chan_index1 = dataOut.channelList.index(pair[1])
580 chan_index1 = dataOut.channelList.index(pair[1])
596
581
597 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
582 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
598 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
583 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
599 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
584 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
600 axes0 = self.axesList[i*self.__nsubplots]
585 axes0 = self.axesList[i*self.__nsubplots]
601 axes0.pcolor(x, y, zdB,
586 axes0.pcolor(x, y, zdB,
602 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
587 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
603 xlabel=xlabel, ylabel=ylabel, title=title,
588 xlabel=xlabel, ylabel=ylabel, title=title,
604 ticksize=9, colormap=power_cmap, cblabel='')
589 ticksize=9, colormap=power_cmap, cblabel='')
605
590
606 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
591 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
607 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
592 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
608 axes0 = self.axesList[i*self.__nsubplots+1]
593 axes0 = self.axesList[i*self.__nsubplots+1]
609 axes0.pcolor(x, y, zdB,
594 axes0.pcolor(x, y, zdB,
610 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
595 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
611 xlabel=xlabel, ylabel=ylabel, title=title,
596 xlabel=xlabel, ylabel=ylabel, title=title,
612 ticksize=9, colormap=power_cmap, cblabel='')
597 ticksize=9, colormap=power_cmap, cblabel='')
613
598
614 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
599 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
615 coherence = numpy.abs(coherenceComplex)
600 coherence = numpy.abs(coherenceComplex)
616 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
601 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
617 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
602 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
618
603
619 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
604 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
620 axes0 = self.axesList[i*self.__nsubplots+2]
605 axes0 = self.axesList[i*self.__nsubplots+2]
621 axes0.pcolor(x, y, coherence,
606 axes0.pcolor(x, y, coherence,
622 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
607 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
623 xlabel=xlabel, ylabel=ylabel, title=title,
608 xlabel=xlabel, ylabel=ylabel, title=title,
624 ticksize=9, colormap=coherence_cmap, cblabel='')
609 ticksize=9, colormap=coherence_cmap, cblabel='')
625
610
626 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
611 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
627 axes0 = self.axesList[i*self.__nsubplots+3]
612 axes0 = self.axesList[i*self.__nsubplots+3]
628 axes0.pcolor(x, y, phase,
613 axes0.pcolor(x, y, phase,
629 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
614 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
630 xlabel=xlabel, ylabel=ylabel, title=title,
615 xlabel=xlabel, ylabel=ylabel, title=title,
631 ticksize=9, colormap=phase_cmap, cblabel='')
616 ticksize=9, colormap=phase_cmap, cblabel='')
632
617
633
618
634
619
635 self.draw()
620 self.draw()
636
621
637 self.save(figpath=figpath,
622 self.save(figpath=figpath,
638 figfile=figfile,
623 figfile=figfile,
639 save=save,
624 save=save,
640 ftp=ftp,
625 ftp=ftp,
641 wr_period=wr_period,
626 wr_period=wr_period,
642 thisDatetime=thisDatetime)
627 thisDatetime=thisDatetime)
643
628
644
629
645 class RTIPlot(Figure):
630 class RTIPlot(Figure):
646
631
647 __isConfig = None
632 __isConfig = None
648 __nsubplots = None
633 __nsubplots = None
649
634
650 WIDTHPROF = None
635 WIDTHPROF = None
651 HEIGHTPROF = None
636 HEIGHTPROF = None
652 PREFIX = 'rti'
637 PREFIX = 'rti'
653
638
654 def __init__(self, **kwargs):
639 def __init__(self, **kwargs):
655
640
656 Figure.__init__(self, **kwargs)
641 Figure.__init__(self, **kwargs)
657 self.timerange = None
642 self.timerange = None
658 self.isConfig = False
643 self.isConfig = False
659 self.__nsubplots = 1
644 self.__nsubplots = 1
660
645
661 self.WIDTH = 800
646 self.WIDTH = 800
662 self.HEIGHT = 180
647 self.HEIGHT = 180
663 self.WIDTHPROF = 120
648 self.WIDTHPROF = 120
664 self.HEIGHTPROF = 0
649 self.HEIGHTPROF = 0
665 self.counter_imagwr = 0
650 self.counter_imagwr = 0
666
651
667 self.PLOT_CODE = RTI_CODE
652 self.PLOT_CODE = RTI_CODE
668
653
669 self.FTP_WEI = None
654 self.FTP_WEI = None
670 self.EXP_CODE = None
655 self.EXP_CODE = None
671 self.SUB_EXP_CODE = None
656 self.SUB_EXP_CODE = None
672 self.PLOT_POS = None
657 self.PLOT_POS = None
673 self.tmin = None
658 self.tmin = None
674 self.tmax = None
659 self.tmax = None
675
660
676 self.xmin = None
661 self.xmin = None
677 self.xmax = None
662 self.xmax = None
678
663
679 self.figfile = None
664 self.figfile = None
680
665
681 def getSubplots(self):
666 def getSubplots(self):
682
667
683 ncol = 1
668 ncol = 1
684 nrow = self.nplots
669 nrow = self.nplots
685
670
686 return nrow, ncol
671 return nrow, ncol
687
672
688 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
673 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
689
674
690 self.__showprofile = showprofile
675 self.__showprofile = showprofile
691 self.nplots = nplots
676 self.nplots = nplots
692
677
693 ncolspan = 1
678 ncolspan = 1
694 colspan = 1
679 colspan = 1
695 if showprofile:
680 if showprofile:
696 ncolspan = 7
681 ncolspan = 7
697 colspan = 6
682 colspan = 6
698 self.__nsubplots = 2
683 self.__nsubplots = 2
699
684
700 self.createFigure(id = id,
685 self.createFigure(id = id,
701 wintitle = wintitle,
686 wintitle = wintitle,
702 widthplot = self.WIDTH + self.WIDTHPROF,
687 widthplot = self.WIDTH + self.WIDTHPROF,
703 heightplot = self.HEIGHT + self.HEIGHTPROF,
688 heightplot = self.HEIGHT + self.HEIGHTPROF,
704 show=show)
689 show=show)
705
690
706 nrow, ncol = self.getSubplots()
691 nrow, ncol = self.getSubplots()
707
692
708 counter = 0
693 counter = 0
709 for y in range(nrow):
694 for y in range(nrow):
710 for x in range(ncol):
695 for x in range(ncol):
711
696
712 if counter >= self.nplots:
697 if counter >= self.nplots:
713 break
698 break
714
699
715 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
700 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
716
701
717 if showprofile:
702 if showprofile:
718 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
703 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
719
704
720 counter += 1
705 counter += 1
721
706
722 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
707 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
723 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
708 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
724 timerange=None, colormap='jet',
709 timerange=None, colormap='jet',
725 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
710 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
726 server=None, folder=None, username=None, password=None,
711 server=None, folder=None, username=None, password=None,
727 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
712 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
728
713
729 """
714 """
730
715
731 Input:
716 Input:
732 dataOut :
717 dataOut :
733 id :
718 id :
734 wintitle :
719 wintitle :
735 channelList :
720 channelList :
736 showProfile :
721 showProfile :
737 xmin : None,
722 xmin : None,
738 xmax : None,
723 xmax : None,
739 ymin : None,
724 ymin : None,
740 ymax : None,
725 ymax : None,
741 zmin : None,
726 zmin : None,
742 zmax : None
727 zmax : None
743 """
728 """
744
729
745 #colormap = kwargs.get('colormap', 'jet')
730 #colormap = kwargs.get('colormap', 'jet')
746 if HEIGHT is not None:
731 if HEIGHT is not None:
747 self.HEIGHT = HEIGHT
732 self.HEIGHT = HEIGHT
748
733
749 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
734 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
750 return
735 return
751
736
752 if channelList == None:
737 if channelList == None:
753 channelIndexList = dataOut.channelIndexList
738 channelIndexList = dataOut.channelIndexList
754 else:
739 else:
755 channelIndexList = []
740 channelIndexList = []
756 for channel in channelList:
741 for channel in channelList:
757 if channel not in dataOut.channelList:
742 if channel not in dataOut.channelList:
758 raise ValueError, "Channel %d is not in dataOut.channelList"
743 raise ValueError, "Channel %d is not in dataOut.channelList"
759 channelIndexList.append(dataOut.channelList.index(channel))
744 channelIndexList.append(dataOut.channelList.index(channel))
760
745
761 if normFactor is None:
746 if normFactor is None:
762 factor = dataOut.normFactor
747 factor = dataOut.normFactor
763 else:
748 else:
764 factor = normFactor
749 factor = normFactor
765
750
766 # factor = dataOut.normFactor
751 # factor = dataOut.normFactor
767 x = dataOut.getTimeRange()
752 x = dataOut.getTimeRange()
768 y = dataOut.getHeiRange()
753 y = dataOut.getHeiRange()
769
754
770 z = dataOut.data_spc/factor
755 z = dataOut.data_spc/factor
771 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
756 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
772 avg = numpy.average(z, axis=1)
757 avg = numpy.average(z, axis=1)
773 avgdB = 10.*numpy.log10(avg)
758 avgdB = 10.*numpy.log10(avg)
774 # avgdB = dataOut.getPower()
759 # avgdB = dataOut.getPower()
775
760
776
761
777 thisDatetime = dataOut.datatime
762 thisDatetime = dataOut.datatime
778 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
763 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
779 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
764 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
780 xlabel = ""
765 xlabel = ""
781 ylabel = "Range (Km)"
766 ylabel = "Range (Km)"
782
767
783 update_figfile = False
768 update_figfile = False
784
769
785 if dataOut.ltctime >= self.xmax:
770 if dataOut.ltctime >= self.xmax:
786 self.counter_imagwr = wr_period
771 self.counter_imagwr = wr_period
787 self.isConfig = False
772 self.isConfig = False
788 update_figfile = True
773 update_figfile = True
789
774
790 if not self.isConfig:
775 if not self.isConfig:
791
776
792 nplots = len(channelIndexList)
777 nplots = len(channelIndexList)
793
778
794 self.setup(id=id,
779 self.setup(id=id,
795 nplots=nplots,
780 nplots=nplots,
796 wintitle=wintitle,
781 wintitle=wintitle,
797 showprofile=showprofile,
782 showprofile=showprofile,
798 show=show)
783 show=show)
799
784
800 if timerange != None:
785 if timerange != None:
801 self.timerange = timerange
786 self.timerange = timerange
802
787
803 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
788 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
804
789
805 noise = dataOut.noise/factor
790 noise = dataOut.noise/factor
806 noisedB = 10*numpy.log10(noise)
791 noisedB = 10*numpy.log10(noise)
807
792
808 if ymin == None: ymin = numpy.nanmin(y)
793 if ymin == None: ymin = numpy.nanmin(y)
809 if ymax == None: ymax = numpy.nanmax(y)
794 if ymax == None: ymax = numpy.nanmax(y)
810 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
795 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
811 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
796 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
812
797
813 self.FTP_WEI = ftp_wei
798 self.FTP_WEI = ftp_wei
814 self.EXP_CODE = exp_code
799 self.EXP_CODE = exp_code
815 self.SUB_EXP_CODE = sub_exp_code
800 self.SUB_EXP_CODE = sub_exp_code
816 self.PLOT_POS = plot_pos
801 self.PLOT_POS = plot_pos
817
802
818 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
803 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
819 self.isConfig = True
804 self.isConfig = True
820 self.figfile = figfile
805 self.figfile = figfile
821 update_figfile = True
806 update_figfile = True
822
807
823 self.setWinTitle(title)
808 self.setWinTitle(title)
824
809
825 for i in range(self.nplots):
810 for i in range(self.nplots):
826 index = channelIndexList[i]
811 index = channelIndexList[i]
827 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
812 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
828 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
813 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
829 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
814 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
830 axes = self.axesList[i*self.__nsubplots]
815 axes = self.axesList[i*self.__nsubplots]
831 zdB = avgdB[index].reshape((1,-1))
816 zdB = avgdB[index].reshape((1,-1))
832 axes.pcolorbuffer(x, y, zdB,
817 axes.pcolorbuffer(x, y, zdB,
833 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
818 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
834 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
819 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
835 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
820 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
836
821
837 if self.__showprofile:
822 if self.__showprofile:
838 axes = self.axesList[i*self.__nsubplots +1]
823 axes = self.axesList[i*self.__nsubplots +1]
839 axes.pline(avgdB[index], y,
824 axes.pline(avgdB[index], y,
840 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
825 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
841 xlabel='dB', ylabel='', title='',
826 xlabel='dB', ylabel='', title='',
842 ytick_visible=False,
827 ytick_visible=False,
843 grid='x')
828 grid='x')
844
829
845 self.draw()
830 self.draw()
846
831
847 self.save(figpath=figpath,
832 self.save(figpath=figpath,
848 figfile=figfile,
833 figfile=figfile,
849 save=save,
834 save=save,
850 ftp=ftp,
835 ftp=ftp,
851 wr_period=wr_period,
836 wr_period=wr_period,
852 thisDatetime=thisDatetime,
837 thisDatetime=thisDatetime,
853 update_figfile=update_figfile)
838 update_figfile=update_figfile)
854
839
855 class CoherenceMap(Figure):
840 class CoherenceMap(Figure):
856 isConfig = None
841 isConfig = None
857 __nsubplots = None
842 __nsubplots = None
858
843
859 WIDTHPROF = None
844 WIDTHPROF = None
860 HEIGHTPROF = None
845 HEIGHTPROF = None
861 PREFIX = 'cmap'
846 PREFIX = 'cmap'
862
847
863 def __init__(self, **kwargs):
848 def __init__(self, **kwargs):
864 Figure.__init__(self, **kwargs)
849 Figure.__init__(self, **kwargs)
865 self.timerange = 2*60*60
850 self.timerange = 2*60*60
866 self.isConfig = False
851 self.isConfig = False
867 self.__nsubplots = 1
852 self.__nsubplots = 1
868
853
869 self.WIDTH = 800
854 self.WIDTH = 800
870 self.HEIGHT = 180
855 self.HEIGHT = 180
871 self.WIDTHPROF = 120
856 self.WIDTHPROF = 120
872 self.HEIGHTPROF = 0
857 self.HEIGHTPROF = 0
873 self.counter_imagwr = 0
858 self.counter_imagwr = 0
874
859
875 self.PLOT_CODE = COH_CODE
860 self.PLOT_CODE = COH_CODE
876
861
877 self.FTP_WEI = None
862 self.FTP_WEI = None
878 self.EXP_CODE = None
863 self.EXP_CODE = None
879 self.SUB_EXP_CODE = None
864 self.SUB_EXP_CODE = None
880 self.PLOT_POS = None
865 self.PLOT_POS = None
881 self.counter_imagwr = 0
866 self.counter_imagwr = 0
882
867
883 self.xmin = None
868 self.xmin = None
884 self.xmax = None
869 self.xmax = None
885
870
886 def getSubplots(self):
871 def getSubplots(self):
887 ncol = 1
872 ncol = 1
888 nrow = self.nplots*2
873 nrow = self.nplots*2
889
874
890 return nrow, ncol
875 return nrow, ncol
891
876
892 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
877 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
893 self.__showprofile = showprofile
878 self.__showprofile = showprofile
894 self.nplots = nplots
879 self.nplots = nplots
895
880
896 ncolspan = 1
881 ncolspan = 1
897 colspan = 1
882 colspan = 1
898 if showprofile:
883 if showprofile:
899 ncolspan = 7
884 ncolspan = 7
900 colspan = 6
885 colspan = 6
901 self.__nsubplots = 2
886 self.__nsubplots = 2
902
887
903 self.createFigure(id = id,
888 self.createFigure(id = id,
904 wintitle = wintitle,
889 wintitle = wintitle,
905 widthplot = self.WIDTH + self.WIDTHPROF,
890 widthplot = self.WIDTH + self.WIDTHPROF,
906 heightplot = self.HEIGHT + self.HEIGHTPROF,
891 heightplot = self.HEIGHT + self.HEIGHTPROF,
907 show=True)
892 show=True)
908
893
909 nrow, ncol = self.getSubplots()
894 nrow, ncol = self.getSubplots()
910
895
911 for y in range(nrow):
896 for y in range(nrow):
912 for x in range(ncol):
897 for x in range(ncol):
913
898
914 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
899 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
915
900
916 if showprofile:
901 if showprofile:
917 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
918
903
919 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
904 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
920 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
905 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
921 timerange=None, phase_min=None, phase_max=None,
906 timerange=None, phase_min=None, phase_max=None,
922 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
907 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
923 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
908 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
924 server=None, folder=None, username=None, password=None,
909 server=None, folder=None, username=None, password=None,
925 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
910 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
926
911
927 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
912 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
928 return
913 return
929
914
930 if pairsList == None:
915 if pairsList == None:
931 pairsIndexList = dataOut.pairsIndexList
916 pairsIndexList = dataOut.pairsIndexList
932 else:
917 else:
933 pairsIndexList = []
918 pairsIndexList = []
934 for pair in pairsList:
919 for pair in pairsList:
935 if pair not in dataOut.pairsList:
920 if pair not in dataOut.pairsList:
936 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
921 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
937 pairsIndexList.append(dataOut.pairsList.index(pair))
922 pairsIndexList.append(dataOut.pairsList.index(pair))
938
923
939 if pairsIndexList == []:
924 if pairsIndexList == []:
940 return
925 return
941
926
942 if len(pairsIndexList) > 4:
927 if len(pairsIndexList) > 4:
943 pairsIndexList = pairsIndexList[0:4]
928 pairsIndexList = pairsIndexList[0:4]
944
929
945 if phase_min == None:
930 if phase_min == None:
946 phase_min = -180
931 phase_min = -180
947 if phase_max == None:
932 if phase_max == None:
948 phase_max = 180
933 phase_max = 180
949
934
950 x = dataOut.getTimeRange()
935 x = dataOut.getTimeRange()
951 y = dataOut.getHeiRange()
936 y = dataOut.getHeiRange()
952
937
953 thisDatetime = dataOut.datatime
938 thisDatetime = dataOut.datatime
954
939
955 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
940 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
956 xlabel = ""
941 xlabel = ""
957 ylabel = "Range (Km)"
942 ylabel = "Range (Km)"
958 update_figfile = False
943 update_figfile = False
959
944
960 if not self.isConfig:
945 if not self.isConfig:
961 nplots = len(pairsIndexList)
946 nplots = len(pairsIndexList)
962 self.setup(id=id,
947 self.setup(id=id,
963 nplots=nplots,
948 nplots=nplots,
964 wintitle=wintitle,
949 wintitle=wintitle,
965 showprofile=showprofile,
950 showprofile=showprofile,
966 show=show)
951 show=show)
967
952
968 if timerange != None:
953 if timerange != None:
969 self.timerange = timerange
954 self.timerange = timerange
970
955
971 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
956 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
972
957
973 if ymin == None: ymin = numpy.nanmin(y)
958 if ymin == None: ymin = numpy.nanmin(y)
974 if ymax == None: ymax = numpy.nanmax(y)
959 if ymax == None: ymax = numpy.nanmax(y)
975 if zmin == None: zmin = 0.
960 if zmin == None: zmin = 0.
976 if zmax == None: zmax = 1.
961 if zmax == None: zmax = 1.
977
962
978 self.FTP_WEI = ftp_wei
963 self.FTP_WEI = ftp_wei
979 self.EXP_CODE = exp_code
964 self.EXP_CODE = exp_code
980 self.SUB_EXP_CODE = sub_exp_code
965 self.SUB_EXP_CODE = sub_exp_code
981 self.PLOT_POS = plot_pos
966 self.PLOT_POS = plot_pos
982
967
983 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
968 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
984
969
985 self.isConfig = True
970 self.isConfig = True
986 update_figfile = True
971 update_figfile = True
987
972
988 self.setWinTitle(title)
973 self.setWinTitle(title)
989
974
990 for i in range(self.nplots):
975 for i in range(self.nplots):
991
976
992 pair = dataOut.pairsList[pairsIndexList[i]]
977 pair = dataOut.pairsList[pairsIndexList[i]]
993
978
994 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
979 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
995 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
980 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
996 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
981 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
997
982
998
983
999 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
984 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1000 coherence = numpy.abs(avgcoherenceComplex)
985 coherence = numpy.abs(avgcoherenceComplex)
1001
986
1002 z = coherence.reshape((1,-1))
987 z = coherence.reshape((1,-1))
1003
988
1004 counter = 0
989 counter = 0
1005
990
1006 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
991 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1007 axes = self.axesList[i*self.__nsubplots*2]
992 axes = self.axesList[i*self.__nsubplots*2]
1008 axes.pcolorbuffer(x, y, z,
993 axes.pcolorbuffer(x, y, z,
1009 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
994 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1010 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
995 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1011 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
996 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
1012
997
1013 if self.__showprofile:
998 if self.__showprofile:
1014 counter += 1
999 counter += 1
1015 axes = self.axesList[i*self.__nsubplots*2 + counter]
1000 axes = self.axesList[i*self.__nsubplots*2 + counter]
1016 axes.pline(coherence, y,
1001 axes.pline(coherence, y,
1017 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
1002 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
1018 xlabel='', ylabel='', title='', ticksize=7,
1003 xlabel='', ylabel='', title='', ticksize=7,
1019 ytick_visible=False, nxticks=5,
1004 ytick_visible=False, nxticks=5,
1020 grid='x')
1005 grid='x')
1021
1006
1022 counter += 1
1007 counter += 1
1023
1008
1024 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1009 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1025
1010
1026 z = phase.reshape((1,-1))
1011 z = phase.reshape((1,-1))
1027
1012
1028 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1013 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1029 axes = self.axesList[i*self.__nsubplots*2 + counter]
1014 axes = self.axesList[i*self.__nsubplots*2 + counter]
1030 axes.pcolorbuffer(x, y, z,
1015 axes.pcolorbuffer(x, y, z,
1031 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
1016 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
1032 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1017 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1033 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
1018 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
1034
1019
1035 if self.__showprofile:
1020 if self.__showprofile:
1036 counter += 1
1021 counter += 1
1037 axes = self.axesList[i*self.__nsubplots*2 + counter]
1022 axes = self.axesList[i*self.__nsubplots*2 + counter]
1038 axes.pline(phase, y,
1023 axes.pline(phase, y,
1039 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
1024 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
1040 xlabel='', ylabel='', title='', ticksize=7,
1025 xlabel='', ylabel='', title='', ticksize=7,
1041 ytick_visible=False, nxticks=4,
1026 ytick_visible=False, nxticks=4,
1042 grid='x')
1027 grid='x')
1043
1028
1044 self.draw()
1029 self.draw()
1045
1030
1046 if dataOut.ltctime >= self.xmax:
1031 if dataOut.ltctime >= self.xmax:
1047 self.counter_imagwr = wr_period
1032 self.counter_imagwr = wr_period
1048 self.isConfig = False
1033 self.isConfig = False
1049 update_figfile = True
1034 update_figfile = True
1050
1035
1051 self.save(figpath=figpath,
1036 self.save(figpath=figpath,
1052 figfile=figfile,
1037 figfile=figfile,
1053 save=save,
1038 save=save,
1054 ftp=ftp,
1039 ftp=ftp,
1055 wr_period=wr_period,
1040 wr_period=wr_period,
1056 thisDatetime=thisDatetime,
1041 thisDatetime=thisDatetime,
1057 update_figfile=update_figfile)
1042 update_figfile=update_figfile)
1058
1043
1059 class PowerProfilePlot(Figure):
1044 class PowerProfilePlot(Figure):
1060
1045
1061 isConfig = None
1046 isConfig = None
1062 __nsubplots = None
1047 __nsubplots = None
1063
1048
1064 WIDTHPROF = None
1049 WIDTHPROF = None
1065 HEIGHTPROF = None
1050 HEIGHTPROF = None
1066 PREFIX = 'spcprofile'
1051 PREFIX = 'spcprofile'
1067
1052
1068 def __init__(self, **kwargs):
1053 def __init__(self, **kwargs):
1069 Figure.__init__(self, **kwargs)
1054 Figure.__init__(self, **kwargs)
1070 self.isConfig = False
1055 self.isConfig = False
1071 self.__nsubplots = 1
1056 self.__nsubplots = 1
1072
1057
1073 self.PLOT_CODE = POWER_CODE
1058 self.PLOT_CODE = POWER_CODE
1074
1059
1075 self.WIDTH = 300
1060 self.WIDTH = 300
1076 self.HEIGHT = 500
1061 self.HEIGHT = 500
1077 self.counter_imagwr = 0
1062 self.counter_imagwr = 0
1078
1063
1079 def getSubplots(self):
1064 def getSubplots(self):
1080 ncol = 1
1065 ncol = 1
1081 nrow = 1
1066 nrow = 1
1082
1067
1083 return nrow, ncol
1068 return nrow, ncol
1084
1069
1085 def setup(self, id, nplots, wintitle, show):
1070 def setup(self, id, nplots, wintitle, show):
1086
1071
1087 self.nplots = nplots
1072 self.nplots = nplots
1088
1073
1089 ncolspan = 1
1074 ncolspan = 1
1090 colspan = 1
1075 colspan = 1
1091
1076
1092 self.createFigure(id = id,
1077 self.createFigure(id = id,
1093 wintitle = wintitle,
1078 wintitle = wintitle,
1094 widthplot = self.WIDTH,
1079 widthplot = self.WIDTH,
1095 heightplot = self.HEIGHT,
1080 heightplot = self.HEIGHT,
1096 show=show)
1081 show=show)
1097
1082
1098 nrow, ncol = self.getSubplots()
1083 nrow, ncol = self.getSubplots()
1099
1084
1100 counter = 0
1085 counter = 0
1101 for y in range(nrow):
1086 for y in range(nrow):
1102 for x in range(ncol):
1087 for x in range(ncol):
1103 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1088 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1104
1089
1105 def run(self, dataOut, id, wintitle="", channelList=None,
1090 def run(self, dataOut, id, wintitle="", channelList=None,
1106 xmin=None, xmax=None, ymin=None, ymax=None,
1091 xmin=None, xmax=None, ymin=None, ymax=None,
1107 save=False, figpath='./', figfile=None, show=True,
1092 save=False, figpath='./', figfile=None, show=True,
1108 ftp=False, wr_period=1, server=None,
1093 ftp=False, wr_period=1, server=None,
1109 folder=None, username=None, password=None):
1094 folder=None, username=None, password=None):
1110
1095
1111
1096
1112 if channelList == None:
1097 if channelList == None:
1113 channelIndexList = dataOut.channelIndexList
1098 channelIndexList = dataOut.channelIndexList
1114 channelList = dataOut.channelList
1099 channelList = dataOut.channelList
1115 else:
1100 else:
1116 channelIndexList = []
1101 channelIndexList = []
1117 for channel in channelList:
1102 for channel in channelList:
1118 if channel not in dataOut.channelList:
1103 if channel not in dataOut.channelList:
1119 raise ValueError, "Channel %d is not in dataOut.channelList"
1104 raise ValueError, "Channel %d is not in dataOut.channelList"
1120 channelIndexList.append(dataOut.channelList.index(channel))
1105 channelIndexList.append(dataOut.channelList.index(channel))
1121
1106
1122 factor = dataOut.normFactor
1107 factor = dataOut.normFactor
1123
1108
1124 y = dataOut.getHeiRange()
1109 y = dataOut.getHeiRange()
1125
1110
1126 #for voltage
1111 #for voltage
1127 if dataOut.type == 'Voltage':
1112 if dataOut.type == 'Voltage':
1128 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1113 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1129 x = x.real
1114 x = x.real
1130 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1115 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1131
1116
1132 #for spectra
1117 #for spectra
1133 if dataOut.type == 'Spectra':
1118 if dataOut.type == 'Spectra':
1134 x = dataOut.data_spc[channelIndexList,:,:]/factor
1119 x = dataOut.data_spc[channelIndexList,:,:]/factor
1135 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1120 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1136 x = numpy.average(x, axis=1)
1121 x = numpy.average(x, axis=1)
1137
1122
1138
1123
1139 xdB = 10*numpy.log10(x)
1124 xdB = 10*numpy.log10(x)
1140
1125
1141 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1126 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1142 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1127 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1143 xlabel = "dB"
1128 xlabel = "dB"
1144 ylabel = "Range (Km)"
1129 ylabel = "Range (Km)"
1145
1130
1146 if not self.isConfig:
1131 if not self.isConfig:
1147
1132
1148 nplots = 1
1133 nplots = 1
1149
1134
1150 self.setup(id=id,
1135 self.setup(id=id,
1151 nplots=nplots,
1136 nplots=nplots,
1152 wintitle=wintitle,
1137 wintitle=wintitle,
1153 show=show)
1138 show=show)
1154
1139
1155 if ymin == None: ymin = numpy.nanmin(y)
1140 if ymin == None: ymin = numpy.nanmin(y)
1156 if ymax == None: ymax = numpy.nanmax(y)
1141 if ymax == None: ymax = numpy.nanmax(y)
1157 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1142 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1158 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1143 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1159
1144
1160 self.isConfig = True
1145 self.isConfig = True
1161
1146
1162 self.setWinTitle(title)
1147 self.setWinTitle(title)
1163
1148
1164 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1149 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1165 axes = self.axesList[0]
1150 axes = self.axesList[0]
1166
1151
1167 legendlabels = ["channel %d"%x for x in channelList]
1152 legendlabels = ["channel %d"%x for x in channelList]
1168 axes.pmultiline(xdB, y,
1153 axes.pmultiline(xdB, y,
1169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1170 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1155 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1171 ytick_visible=True, nxticks=5,
1156 ytick_visible=True, nxticks=5,
1172 grid='x')
1157 grid='x')
1173
1158
1174 self.draw()
1159 self.draw()
1175
1160
1176 self.save(figpath=figpath,
1161 self.save(figpath=figpath,
1177 figfile=figfile,
1162 figfile=figfile,
1178 save=save,
1163 save=save,
1179 ftp=ftp,
1164 ftp=ftp,
1180 wr_period=wr_period,
1165 wr_period=wr_period,
1181 thisDatetime=thisDatetime)
1166 thisDatetime=thisDatetime)
1182
1167
1183 class SpectraCutPlot(Figure):
1168 class SpectraCutPlot(Figure):
1184
1169
1185 isConfig = None
1170 isConfig = None
1186 __nsubplots = None
1171 __nsubplots = None
1187
1172
1188 WIDTHPROF = None
1173 WIDTHPROF = None
1189 HEIGHTPROF = None
1174 HEIGHTPROF = None
1190 PREFIX = 'spc_cut'
1175 PREFIX = 'spc_cut'
1191
1176
1192 def __init__(self, **kwargs):
1177 def __init__(self, **kwargs):
1193 Figure.__init__(self, **kwargs)
1178 Figure.__init__(self, **kwargs)
1194 self.isConfig = False
1179 self.isConfig = False
1195 self.__nsubplots = 1
1180 self.__nsubplots = 1
1196
1181
1197 self.PLOT_CODE = POWER_CODE
1182 self.PLOT_CODE = POWER_CODE
1198
1183
1199 self.WIDTH = 700
1184 self.WIDTH = 700
1200 self.HEIGHT = 500
1185 self.HEIGHT = 500
1201 self.counter_imagwr = 0
1186 self.counter_imagwr = 0
1202
1187
1203 def getSubplots(self):
1188 def getSubplots(self):
1204 ncol = 1
1189 ncol = 1
1205 nrow = 1
1190 nrow = 1
1206
1191
1207 return nrow, ncol
1192 return nrow, ncol
1208
1193
1209 def setup(self, id, nplots, wintitle, show):
1194 def setup(self, id, nplots, wintitle, show):
1210
1195
1211 self.nplots = nplots
1196 self.nplots = nplots
1212
1197
1213 ncolspan = 1
1198 ncolspan = 1
1214 colspan = 1
1199 colspan = 1
1215
1200
1216 self.createFigure(id = id,
1201 self.createFigure(id = id,
1217 wintitle = wintitle,
1202 wintitle = wintitle,
1218 widthplot = self.WIDTH,
1203 widthplot = self.WIDTH,
1219 heightplot = self.HEIGHT,
1204 heightplot = self.HEIGHT,
1220 show=show)
1205 show=show)
1221
1206
1222 nrow, ncol = self.getSubplots()
1207 nrow, ncol = self.getSubplots()
1223
1208
1224 counter = 0
1209 counter = 0
1225 for y in range(nrow):
1210 for y in range(nrow):
1226 for x in range(ncol):
1211 for x in range(ncol):
1227 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1212 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1228
1213
1229 def run(self, dataOut, id, wintitle="", channelList=None,
1214 def run(self, dataOut, id, wintitle="", channelList=None,
1230 xmin=None, xmax=None, ymin=None, ymax=None,
1215 xmin=None, xmax=None, ymin=None, ymax=None,
1231 save=False, figpath='./', figfile=None, show=True,
1216 save=False, figpath='./', figfile=None, show=True,
1232 ftp=False, wr_period=1, server=None,
1217 ftp=False, wr_period=1, server=None,
1233 folder=None, username=None, password=None,
1218 folder=None, username=None, password=None,
1234 xaxis="frequency"):
1219 xaxis="frequency"):
1235
1220
1236
1221
1237 if channelList == None:
1222 if channelList == None:
1238 channelIndexList = dataOut.channelIndexList
1223 channelIndexList = dataOut.channelIndexList
1239 channelList = dataOut.channelList
1224 channelList = dataOut.channelList
1240 else:
1225 else:
1241 channelIndexList = []
1226 channelIndexList = []
1242 for channel in channelList:
1227 for channel in channelList:
1243 if channel not in dataOut.channelList:
1228 if channel not in dataOut.channelList:
1244 raise ValueError, "Channel %d is not in dataOut.channelList"
1229 raise ValueError, "Channel %d is not in dataOut.channelList"
1245 channelIndexList.append(dataOut.channelList.index(channel))
1230 channelIndexList.append(dataOut.channelList.index(channel))
1246
1231
1247 factor = dataOut.normFactor
1232 factor = dataOut.normFactor
1248
1233
1249 y = dataOut.getHeiRange()
1234 y = dataOut.getHeiRange()
1250
1235
1251 z = dataOut.data_spc/factor
1236 z = dataOut.data_spc/factor
1252 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1237 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1253
1238
1254 hei_index = numpy.arange(25)*3 + 20
1239 hei_index = numpy.arange(25)*3 + 20
1255
1240
1256 if xaxis == "frequency":
1241 if xaxis == "frequency":
1257 x = dataOut.getFreqRange()/1000.
1242 x = dataOut.getFreqRange()/1000.
1258 zdB = 10*numpy.log10(z[0,:,hei_index])
1243 zdB = 10*numpy.log10(z[0,:,hei_index])
1259 xlabel = "Frequency (kHz)"
1244 xlabel = "Frequency (kHz)"
1260 ylabel = "Power (dB)"
1245 ylabel = "Power (dB)"
1261
1246
1262 elif xaxis == "time":
1247 elif xaxis == "time":
1263 x = dataOut.getAcfRange()
1248 x = dataOut.getAcfRange()
1264 zdB = z[0,:,hei_index]
1249 zdB = z[0,:,hei_index]
1265 xlabel = "Time (ms)"
1250 xlabel = "Time (ms)"
1266 ylabel = "ACF"
1251 ylabel = "ACF"
1267
1252
1268 else:
1253 else:
1269 x = dataOut.getVelRange()
1254 x = dataOut.getVelRange()
1270 zdB = 10*numpy.log10(z[0,:,hei_index])
1255 zdB = 10*numpy.log10(z[0,:,hei_index])
1271 xlabel = "Velocity (m/s)"
1256 xlabel = "Velocity (m/s)"
1272 ylabel = "Power (dB)"
1257 ylabel = "Power (dB)"
1273
1258
1274 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1259 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1275 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1260 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1276
1261
1277 if not self.isConfig:
1262 if not self.isConfig:
1278
1263
1279 nplots = 1
1264 nplots = 1
1280
1265
1281 self.setup(id=id,
1266 self.setup(id=id,
1282 nplots=nplots,
1267 nplots=nplots,
1283 wintitle=wintitle,
1268 wintitle=wintitle,
1284 show=show)
1269 show=show)
1285
1270
1286 if xmin == None: xmin = numpy.nanmin(x)*0.9
1271 if xmin == None: xmin = numpy.nanmin(x)*0.9
1287 if xmax == None: xmax = numpy.nanmax(x)*1.1
1272 if xmax == None: xmax = numpy.nanmax(x)*1.1
1288 if ymin == None: ymin = numpy.nanmin(zdB)
1273 if ymin == None: ymin = numpy.nanmin(zdB)
1289 if ymax == None: ymax = numpy.nanmax(zdB)
1274 if ymax == None: ymax = numpy.nanmax(zdB)
1290
1275
1291 self.isConfig = True
1276 self.isConfig = True
1292
1277
1293 self.setWinTitle(title)
1278 self.setWinTitle(title)
1294
1279
1295 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1280 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1296 axes = self.axesList[0]
1281 axes = self.axesList[0]
1297
1282
1298 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1283 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1299
1284
1300 axes.pmultilineyaxis( x, zdB,
1285 axes.pmultilineyaxis( x, zdB,
1301 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1286 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1302 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1287 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1303 ytick_visible=True, nxticks=5,
1288 ytick_visible=True, nxticks=5,
1304 grid='x')
1289 grid='x')
1305
1290
1306 self.draw()
1291 self.draw()
1307
1292
1308 self.save(figpath=figpath,
1293 self.save(figpath=figpath,
1309 figfile=figfile,
1294 figfile=figfile,
1310 save=save,
1295 save=save,
1311 ftp=ftp,
1296 ftp=ftp,
1312 wr_period=wr_period,
1297 wr_period=wr_period,
1313 thisDatetime=thisDatetime)
1298 thisDatetime=thisDatetime)
1314
1299
1315 class Noise(Figure):
1300 class Noise(Figure):
1316
1301
1317 isConfig = None
1302 isConfig = None
1318 __nsubplots = None
1303 __nsubplots = None
1319
1304
1320 PREFIX = 'noise'
1305 PREFIX = 'noise'
1321
1306
1322
1307
1323 def __init__(self, **kwargs):
1308 def __init__(self, **kwargs):
1324 Figure.__init__(self, **kwargs)
1309 Figure.__init__(self, **kwargs)
1325 self.timerange = 24*60*60
1310 self.timerange = 24*60*60
1326 self.isConfig = False
1311 self.isConfig = False
1327 self.__nsubplots = 1
1312 self.__nsubplots = 1
1328 self.counter_imagwr = 0
1313 self.counter_imagwr = 0
1329 self.WIDTH = 800
1314 self.WIDTH = 800
1330 self.HEIGHT = 400
1315 self.HEIGHT = 400
1331 self.WIDTHPROF = 120
1316 self.WIDTHPROF = 120
1332 self.HEIGHTPROF = 0
1317 self.HEIGHTPROF = 0
1333 self.xdata = None
1318 self.xdata = None
1334 self.ydata = None
1319 self.ydata = None
1335
1320
1336 self.PLOT_CODE = NOISE_CODE
1321 self.PLOT_CODE = NOISE_CODE
1337
1322
1338 self.FTP_WEI = None
1323 self.FTP_WEI = None
1339 self.EXP_CODE = None
1324 self.EXP_CODE = None
1340 self.SUB_EXP_CODE = None
1325 self.SUB_EXP_CODE = None
1341 self.PLOT_POS = None
1326 self.PLOT_POS = None
1342 self.figfile = None
1327 self.figfile = None
1343
1328
1344 self.xmin = None
1329 self.xmin = None
1345 self.xmax = None
1330 self.xmax = None
1346
1331
1347 def getSubplots(self):
1332 def getSubplots(self):
1348
1333
1349 ncol = 1
1334 ncol = 1
1350 nrow = 1
1335 nrow = 1
1351
1336
1352 return nrow, ncol
1337 return nrow, ncol
1353
1338
1354 def openfile(self, filename):
1339 def openfile(self, filename):
1355 dirname = os.path.dirname(filename)
1340 dirname = os.path.dirname(filename)
1356
1341
1357 if not os.path.exists(dirname):
1342 if not os.path.exists(dirname):
1358 os.mkdir(dirname)
1343 os.mkdir(dirname)
1359
1344
1360 f = open(filename,'w+')
1345 f = open(filename,'w+')
1361 f.write('\n\n')
1346 f.write('\n\n')
1362 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1347 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1363 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1348 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1364 f.close()
1349 f.close()
1365
1350
1366 def save_data(self, filename_phase, data, data_datetime):
1351 def save_data(self, filename_phase, data, data_datetime):
1367
1352
1368 f=open(filename_phase,'a')
1353 f=open(filename_phase,'a')
1369
1354
1370 timetuple_data = data_datetime.timetuple()
1355 timetuple_data = data_datetime.timetuple()
1371 day = str(timetuple_data.tm_mday)
1356 day = str(timetuple_data.tm_mday)
1372 month = str(timetuple_data.tm_mon)
1357 month = str(timetuple_data.tm_mon)
1373 year = str(timetuple_data.tm_year)
1358 year = str(timetuple_data.tm_year)
1374 hour = str(timetuple_data.tm_hour)
1359 hour = str(timetuple_data.tm_hour)
1375 minute = str(timetuple_data.tm_min)
1360 minute = str(timetuple_data.tm_min)
1376 second = str(timetuple_data.tm_sec)
1361 second = str(timetuple_data.tm_sec)
1377
1362
1378 data_msg = ''
1363 data_msg = ''
1379 for i in range(len(data)):
1364 for i in range(len(data)):
1380 data_msg += str(data[i]) + ' '
1365 data_msg += str(data[i]) + ' '
1381
1366
1382 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1367 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1383 f.close()
1368 f.close()
1384
1369
1385
1370
1386 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1371 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1387
1372
1388 self.__showprofile = showprofile
1373 self.__showprofile = showprofile
1389 self.nplots = nplots
1374 self.nplots = nplots
1390
1375
1391 ncolspan = 7
1376 ncolspan = 7
1392 colspan = 6
1377 colspan = 6
1393 self.__nsubplots = 2
1378 self.__nsubplots = 2
1394
1379
1395 self.createFigure(id = id,
1380 self.createFigure(id = id,
1396 wintitle = wintitle,
1381 wintitle = wintitle,
1397 widthplot = self.WIDTH+self.WIDTHPROF,
1382 widthplot = self.WIDTH+self.WIDTHPROF,
1398 heightplot = self.HEIGHT+self.HEIGHTPROF,
1383 heightplot = self.HEIGHT+self.HEIGHTPROF,
1399 show=show)
1384 show=show)
1400
1385
1401 nrow, ncol = self.getSubplots()
1386 nrow, ncol = self.getSubplots()
1402
1387
1403 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1388 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1404
1389
1405
1390
1406 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1391 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1407 xmin=None, xmax=None, ymin=None, ymax=None,
1392 xmin=None, xmax=None, ymin=None, ymax=None,
1408 timerange=None,
1393 timerange=None,
1409 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1394 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1410 server=None, folder=None, username=None, password=None,
1395 server=None, folder=None, username=None, password=None,
1411 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1396 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1412
1397
1413 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1398 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1414 return
1399 return
1415
1400
1416 if channelList == None:
1401 if channelList == None:
1417 channelIndexList = dataOut.channelIndexList
1402 channelIndexList = dataOut.channelIndexList
1418 channelList = dataOut.channelList
1403 channelList = dataOut.channelList
1419 else:
1404 else:
1420 channelIndexList = []
1405 channelIndexList = []
1421 for channel in channelList:
1406 for channel in channelList:
1422 if channel not in dataOut.channelList:
1407 if channel not in dataOut.channelList:
1423 raise ValueError, "Channel %d is not in dataOut.channelList"
1408 raise ValueError, "Channel %d is not in dataOut.channelList"
1424 channelIndexList.append(dataOut.channelList.index(channel))
1409 channelIndexList.append(dataOut.channelList.index(channel))
1425
1410
1426 x = dataOut.getTimeRange()
1411 x = dataOut.getTimeRange()
1427 #y = dataOut.getHeiRange()
1412 #y = dataOut.getHeiRange()
1428 factor = dataOut.normFactor
1413 factor = dataOut.normFactor
1429 noise = dataOut.noise[channelIndexList]/factor
1414 noise = dataOut.noise[channelIndexList]/factor
1430 noisedB = 10*numpy.log10(noise)
1415 noisedB = 10*numpy.log10(noise)
1431
1416
1432 thisDatetime = dataOut.datatime
1417 thisDatetime = dataOut.datatime
1433
1418
1434 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1419 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1435 xlabel = ""
1420 xlabel = ""
1436 ylabel = "Intensity (dB)"
1421 ylabel = "Intensity (dB)"
1437 update_figfile = False
1422 update_figfile = False
1438
1423
1439 if not self.isConfig:
1424 if not self.isConfig:
1440
1425
1441 nplots = 1
1426 nplots = 1
1442
1427
1443 self.setup(id=id,
1428 self.setup(id=id,
1444 nplots=nplots,
1429 nplots=nplots,
1445 wintitle=wintitle,
1430 wintitle=wintitle,
1446 showprofile=showprofile,
1431 showprofile=showprofile,
1447 show=show)
1432 show=show)
1448
1433
1449 if timerange != None:
1434 if timerange != None:
1450 self.timerange = timerange
1435 self.timerange = timerange
1451
1436
1452 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1437 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1453
1438
1454 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1439 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1455 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1440 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1456
1441
1457 self.FTP_WEI = ftp_wei
1442 self.FTP_WEI = ftp_wei
1458 self.EXP_CODE = exp_code
1443 self.EXP_CODE = exp_code
1459 self.SUB_EXP_CODE = sub_exp_code
1444 self.SUB_EXP_CODE = sub_exp_code
1460 self.PLOT_POS = plot_pos
1445 self.PLOT_POS = plot_pos
1461
1446
1462
1447
1463 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1448 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1464 self.isConfig = True
1449 self.isConfig = True
1465 self.figfile = figfile
1450 self.figfile = figfile
1466 self.xdata = numpy.array([])
1451 self.xdata = numpy.array([])
1467 self.ydata = numpy.array([])
1452 self.ydata = numpy.array([])
1468
1453
1469 update_figfile = True
1454 update_figfile = True
1470
1455
1471 #open file beacon phase
1456 #open file beacon phase
1472 path = '%s%03d' %(self.PREFIX, self.id)
1457 path = '%s%03d' %(self.PREFIX, self.id)
1473 noise_file = os.path.join(path,'%s.txt'%self.name)
1458 noise_file = os.path.join(path,'%s.txt'%self.name)
1474 self.filename_noise = os.path.join(figpath,noise_file)
1459 self.filename_noise = os.path.join(figpath,noise_file)
1475
1460
1476 self.setWinTitle(title)
1461 self.setWinTitle(title)
1477
1462
1478 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1463 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1479
1464
1480 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1465 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1481 axes = self.axesList[0]
1466 axes = self.axesList[0]
1482
1467
1483 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1468 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1484
1469
1485 if len(self.ydata)==0:
1470 if len(self.ydata)==0:
1486 self.ydata = noisedB.reshape(-1,1)
1471 self.ydata = noisedB.reshape(-1,1)
1487 else:
1472 else:
1488 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1473 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1489
1474
1490
1475
1491 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1476 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1492 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1477 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1493 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1478 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1494 XAxisAsTime=True, grid='both'
1479 XAxisAsTime=True, grid='both'
1495 )
1480 )
1496
1481
1497 self.draw()
1482 self.draw()
1498
1483
1499 if dataOut.ltctime >= self.xmax:
1484 if dataOut.ltctime >= self.xmax:
1500 self.counter_imagwr = wr_period
1485 self.counter_imagwr = wr_period
1501 self.isConfig = False
1486 self.isConfig = False
1502 update_figfile = True
1487 update_figfile = True
1503
1488
1504 self.save(figpath=figpath,
1489 self.save(figpath=figpath,
1505 figfile=figfile,
1490 figfile=figfile,
1506 save=save,
1491 save=save,
1507 ftp=ftp,
1492 ftp=ftp,
1508 wr_period=wr_period,
1493 wr_period=wr_period,
1509 thisDatetime=thisDatetime,
1494 thisDatetime=thisDatetime,
1510 update_figfile=update_figfile)
1495 update_figfile=update_figfile)
1511
1496
1512 #store data beacon phase
1497 #store data beacon phase
1513 if save:
1498 if save:
1514 self.save_data(self.filename_noise, noisedB, thisDatetime)
1499 self.save_data(self.filename_noise, noisedB, thisDatetime)
1515
1500
1516 class BeaconPhase(Figure):
1501 class BeaconPhase(Figure):
1517
1502
1518 __isConfig = None
1503 __isConfig = None
1519 __nsubplots = None
1504 __nsubplots = None
1520
1505
1521 PREFIX = 'beacon_phase'
1506 PREFIX = 'beacon_phase'
1522
1507
1523 def __init__(self, **kwargs):
1508 def __init__(self, **kwargs):
1524 Figure.__init__(self, **kwargs)
1509 Figure.__init__(self, **kwargs)
1525 self.timerange = 24*60*60
1510 self.timerange = 24*60*60
1526 self.isConfig = False
1511 self.isConfig = False
1527 self.__nsubplots = 1
1512 self.__nsubplots = 1
1528 self.counter_imagwr = 0
1513 self.counter_imagwr = 0
1529 self.WIDTH = 800
1514 self.WIDTH = 800
1530 self.HEIGHT = 400
1515 self.HEIGHT = 400
1531 self.WIDTHPROF = 120
1516 self.WIDTHPROF = 120
1532 self.HEIGHTPROF = 0
1517 self.HEIGHTPROF = 0
1533 self.xdata = None
1518 self.xdata = None
1534 self.ydata = None
1519 self.ydata = None
1535
1520
1536 self.PLOT_CODE = BEACON_CODE
1521 self.PLOT_CODE = BEACON_CODE
1537
1522
1538 self.FTP_WEI = None
1523 self.FTP_WEI = None
1539 self.EXP_CODE = None
1524 self.EXP_CODE = None
1540 self.SUB_EXP_CODE = None
1525 self.SUB_EXP_CODE = None
1541 self.PLOT_POS = None
1526 self.PLOT_POS = None
1542
1527
1543 self.filename_phase = None
1528 self.filename_phase = None
1544
1529
1545 self.figfile = None
1530 self.figfile = None
1546
1531
1547 self.xmin = None
1532 self.xmin = None
1548 self.xmax = None
1533 self.xmax = None
1549
1534
1550 def getSubplots(self):
1535 def getSubplots(self):
1551
1536
1552 ncol = 1
1537 ncol = 1
1553 nrow = 1
1538 nrow = 1
1554
1539
1555 return nrow, ncol
1540 return nrow, ncol
1556
1541
1557 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1542 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1558
1543
1559 self.__showprofile = showprofile
1544 self.__showprofile = showprofile
1560 self.nplots = nplots
1545 self.nplots = nplots
1561
1546
1562 ncolspan = 7
1547 ncolspan = 7
1563 colspan = 6
1548 colspan = 6
1564 self.__nsubplots = 2
1549 self.__nsubplots = 2
1565
1550
1566 self.createFigure(id = id,
1551 self.createFigure(id = id,
1567 wintitle = wintitle,
1552 wintitle = wintitle,
1568 widthplot = self.WIDTH+self.WIDTHPROF,
1553 widthplot = self.WIDTH+self.WIDTHPROF,
1569 heightplot = self.HEIGHT+self.HEIGHTPROF,
1554 heightplot = self.HEIGHT+self.HEIGHTPROF,
1570 show=show)
1555 show=show)
1571
1556
1572 nrow, ncol = self.getSubplots()
1557 nrow, ncol = self.getSubplots()
1573
1558
1574 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1559 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1575
1560
1576 def save_phase(self, filename_phase):
1561 def save_phase(self, filename_phase):
1577 f = open(filename_phase,'w+')
1562 f = open(filename_phase,'w+')
1578 f.write('\n\n')
1563 f.write('\n\n')
1579 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1564 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1580 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1565 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1581 f.close()
1566 f.close()
1582
1567
1583 def save_data(self, filename_phase, data, data_datetime):
1568 def save_data(self, filename_phase, data, data_datetime):
1584 f=open(filename_phase,'a')
1569 f=open(filename_phase,'a')
1585 timetuple_data = data_datetime.timetuple()
1570 timetuple_data = data_datetime.timetuple()
1586 day = str(timetuple_data.tm_mday)
1571 day = str(timetuple_data.tm_mday)
1587 month = str(timetuple_data.tm_mon)
1572 month = str(timetuple_data.tm_mon)
1588 year = str(timetuple_data.tm_year)
1573 year = str(timetuple_data.tm_year)
1589 hour = str(timetuple_data.tm_hour)
1574 hour = str(timetuple_data.tm_hour)
1590 minute = str(timetuple_data.tm_min)
1575 minute = str(timetuple_data.tm_min)
1591 second = str(timetuple_data.tm_sec)
1576 second = str(timetuple_data.tm_sec)
1592 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1577 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1593 f.close()
1578 f.close()
1594
1579
1595
1580
1596 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1581 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1597 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1582 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1598 timerange=None,
1583 timerange=None,
1599 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1584 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1600 server=None, folder=None, username=None, password=None,
1585 server=None, folder=None, username=None, password=None,
1601 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1586 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1602
1587
1603 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1588 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1604 return
1589 return
1605
1590
1606 if pairsList == None:
1591 if pairsList == None:
1607 pairsIndexList = dataOut.pairsIndexList[:10]
1592 pairsIndexList = dataOut.pairsIndexList[:10]
1608 else:
1593 else:
1609 pairsIndexList = []
1594 pairsIndexList = []
1610 for pair in pairsList:
1595 for pair in pairsList:
1611 if pair not in dataOut.pairsList:
1596 if pair not in dataOut.pairsList:
1612 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1597 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1613 pairsIndexList.append(dataOut.pairsList.index(pair))
1598 pairsIndexList.append(dataOut.pairsList.index(pair))
1614
1599
1615 if pairsIndexList == []:
1600 if pairsIndexList == []:
1616 return
1601 return
1617
1602
1618 # if len(pairsIndexList) > 4:
1603 # if len(pairsIndexList) > 4:
1619 # pairsIndexList = pairsIndexList[0:4]
1604 # pairsIndexList = pairsIndexList[0:4]
1620
1605
1621 hmin_index = None
1606 hmin_index = None
1622 hmax_index = None
1607 hmax_index = None
1623
1608
1624 if hmin != None and hmax != None:
1609 if hmin != None and hmax != None:
1625 indexes = numpy.arange(dataOut.nHeights)
1610 indexes = numpy.arange(dataOut.nHeights)
1626 hmin_list = indexes[dataOut.heightList >= hmin]
1611 hmin_list = indexes[dataOut.heightList >= hmin]
1627 hmax_list = indexes[dataOut.heightList <= hmax]
1612 hmax_list = indexes[dataOut.heightList <= hmax]
1628
1613
1629 if hmin_list.any():
1614 if hmin_list.any():
1630 hmin_index = hmin_list[0]
1615 hmin_index = hmin_list[0]
1631
1616
1632 if hmax_list.any():
1617 if hmax_list.any():
1633 hmax_index = hmax_list[-1]+1
1618 hmax_index = hmax_list[-1]+1
1634
1619
1635 x = dataOut.getTimeRange()
1620 x = dataOut.getTimeRange()
1636 #y = dataOut.getHeiRange()
1621 #y = dataOut.getHeiRange()
1637
1622
1638
1623
1639 thisDatetime = dataOut.datatime
1624 thisDatetime = dataOut.datatime
1640
1625
1641 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1626 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1642 xlabel = "Local Time"
1627 xlabel = "Local Time"
1643 ylabel = "Phase (degrees)"
1628 ylabel = "Phase (degrees)"
1644
1629
1645 update_figfile = False
1630 update_figfile = False
1646
1631
1647 nplots = len(pairsIndexList)
1632 nplots = len(pairsIndexList)
1648 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1633 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1649 phase_beacon = numpy.zeros(len(pairsIndexList))
1634 phase_beacon = numpy.zeros(len(pairsIndexList))
1650 for i in range(nplots):
1635 for i in range(nplots):
1651 pair = dataOut.pairsList[pairsIndexList[i]]
1636 pair = dataOut.pairsList[pairsIndexList[i]]
1652 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1637 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1653 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1638 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1654 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1639 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1655 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1640 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1656 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1641 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1657
1642
1658 #print "Phase %d%d" %(pair[0], pair[1])
1643 #print "Phase %d%d" %(pair[0], pair[1])
1659 #print phase[dataOut.beacon_heiIndexList]
1644 #print phase[dataOut.beacon_heiIndexList]
1660
1645
1661 if dataOut.beacon_heiIndexList:
1646 if dataOut.beacon_heiIndexList:
1662 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1647 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1663 else:
1648 else:
1664 phase_beacon[i] = numpy.average(phase)
1649 phase_beacon[i] = numpy.average(phase)
1665
1650
1666 if not self.isConfig:
1651 if not self.isConfig:
1667
1652
1668 nplots = len(pairsIndexList)
1653 nplots = len(pairsIndexList)
1669
1654
1670 self.setup(id=id,
1655 self.setup(id=id,
1671 nplots=nplots,
1656 nplots=nplots,
1672 wintitle=wintitle,
1657 wintitle=wintitle,
1673 showprofile=showprofile,
1658 showprofile=showprofile,
1674 show=show)
1659 show=show)
1675
1660
1676 if timerange != None:
1661 if timerange != None:
1677 self.timerange = timerange
1662 self.timerange = timerange
1678
1663
1679 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1664 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1680
1665
1681 if ymin == None: ymin = 0
1666 if ymin == None: ymin = 0
1682 if ymax == None: ymax = 360
1667 if ymax == None: ymax = 360
1683
1668
1684 self.FTP_WEI = ftp_wei
1669 self.FTP_WEI = ftp_wei
1685 self.EXP_CODE = exp_code
1670 self.EXP_CODE = exp_code
1686 self.SUB_EXP_CODE = sub_exp_code
1671 self.SUB_EXP_CODE = sub_exp_code
1687 self.PLOT_POS = plot_pos
1672 self.PLOT_POS = plot_pos
1688
1673
1689 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1674 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1690 self.isConfig = True
1675 self.isConfig = True
1691 self.figfile = figfile
1676 self.figfile = figfile
1692 self.xdata = numpy.array([])
1677 self.xdata = numpy.array([])
1693 self.ydata = numpy.array([])
1678 self.ydata = numpy.array([])
1694
1679
1695 update_figfile = True
1680 update_figfile = True
1696
1681
1697 #open file beacon phase
1682 #open file beacon phase
1698 path = '%s%03d' %(self.PREFIX, self.id)
1683 path = '%s%03d' %(self.PREFIX, self.id)
1699 beacon_file = os.path.join(path,'%s.txt'%self.name)
1684 beacon_file = os.path.join(path,'%s.txt'%self.name)
1700 self.filename_phase = os.path.join(figpath,beacon_file)
1685 self.filename_phase = os.path.join(figpath,beacon_file)
1701 #self.save_phase(self.filename_phase)
1686 #self.save_phase(self.filename_phase)
1702
1687
1703
1688
1704 #store data beacon phase
1689 #store data beacon phase
1705 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1690 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1706
1691
1707 self.setWinTitle(title)
1692 self.setWinTitle(title)
1708
1693
1709
1694
1710 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1695 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1711
1696
1712 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1697 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1713
1698
1714 axes = self.axesList[0]
1699 axes = self.axesList[0]
1715
1700
1716 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1701 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1717
1702
1718 if len(self.ydata)==0:
1703 if len(self.ydata)==0:
1719 self.ydata = phase_beacon.reshape(-1,1)
1704 self.ydata = phase_beacon.reshape(-1,1)
1720 else:
1705 else:
1721 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1706 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1722
1707
1723
1708
1724 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1709 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1725 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1710 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1726 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1711 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1727 XAxisAsTime=True, grid='both'
1712 XAxisAsTime=True, grid='both'
1728 )
1713 )
1729
1714
1730 self.draw()
1715 self.draw()
1731
1716
1732 if dataOut.ltctime >= self.xmax:
1717 if dataOut.ltctime >= self.xmax:
1733 self.counter_imagwr = wr_period
1718 self.counter_imagwr = wr_period
1734 self.isConfig = False
1719 self.isConfig = False
1735 update_figfile = True
1720 update_figfile = True
1736
1721
1737 self.save(figpath=figpath,
1722 self.save(figpath=figpath,
1738 figfile=figfile,
1723 figfile=figfile,
1739 save=save,
1724 save=save,
1740 ftp=ftp,
1725 ftp=ftp,
1741 wr_period=wr_period,
1726 wr_period=wr_period,
1742 thisDatetime=thisDatetime,
1727 thisDatetime=thisDatetime,
1743 update_figfile=update_figfile)
1728 update_figfile=update_figfile)
@@ -1,951 +1,948
1 import itertools
1 import itertools
2
2
3 import numpy
3 import numpy
4
4
5 from jroproc_base import ProcessingUnit, Operation
5 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jrodata import Spectra
6 from schainpy.model.data.jrodata import Spectra
7 from schainpy.model.data.jrodata import hildebrand_sekhon
7 from schainpy.model.data.jrodata import hildebrand_sekhon
8
8
9
9
10 class SpectraProc(ProcessingUnit):
10 class SpectraProc(ProcessingUnit):
11
11
12 def __init__(self, **kwargs):
12 def __init__(self, **kwargs):
13
13
14 ProcessingUnit.__init__(self, **kwargs)
14 ProcessingUnit.__init__(self, **kwargs)
15
15
16 self.buffer = None
16 self.buffer = None
17 self.firstdatatime = None
17 self.firstdatatime = None
18 self.profIndex = 0
18 self.profIndex = 0
19 self.dataOut = Spectra()
19 self.dataOut = Spectra()
20 self.id_min = None
20 self.id_min = None
21 self.id_max = None
21 self.id_max = None
22
22
23 def __updateSpecFromVoltage(self):
23 def __updateSpecFromVoltage(self):
24
24
25 self.dataOut.timeZone = self.dataIn.timeZone
25 self.dataOut.timeZone = self.dataIn.timeZone
26 self.dataOut.dstFlag = self.dataIn.dstFlag
26 self.dataOut.dstFlag = self.dataIn.dstFlag
27 self.dataOut.errorCount = self.dataIn.errorCount
27 self.dataOut.errorCount = self.dataIn.errorCount
28 self.dataOut.useLocalTime = self.dataIn.useLocalTime
28 self.dataOut.useLocalTime= self.dataIn.useLocalTime
29 try:
29 try:
30 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
30 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
31 except:
31 except:
32 pass
32 pass
33 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
33 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
34 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
34 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
35 self.dataOut.channelList = self.dataIn.channelList
35 self.dataOut.channelList = self.dataIn.channelList
36 self.dataOut.heightList = self.dataIn.heightList
36 self.dataOut.heightList = self.dataIn.heightList
37 #print self.dataOut.heightList.shape,"spec4"
37 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
38 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
39
38
40 self.dataOut.nBaud = self.dataIn.nBaud
39 self.dataOut.nBaud = self.dataIn.nBaud
41 self.dataOut.nCode = self.dataIn.nCode
40 self.dataOut.nCode = self.dataIn.nCode
42 self.dataOut.code = self.dataIn.code
41 self.dataOut.code = self.dataIn.code
43 self.dataOut.nProfiles = self.dataOut.nFFTPoints
42 self.dataOut.nProfiles = self.dataOut.nFFTPoints
44
43
45 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
44 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
46 self.dataOut.utctime = self.firstdatatime
45 self.dataOut.utctime = self.firstdatatime
47 # asumo q la data esta decodificada
46 # asumo q la data esta decodificada
48 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
47 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
49 # asumo q la data esta sin flip
48 # asumo q la data esta sin flip
50 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
49 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
51 self.dataOut.flagShiftFFT = False
50 self.dataOut.flagShiftFFT = False
52
51
53 self.dataOut.nCohInt = self.dataIn.nCohInt
52 self.dataOut.nCohInt = self.dataIn.nCohInt
54 self.dataOut.nIncohInt = 1
53 self.dataOut.nIncohInt = 1
55
54
56 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
55 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
57
56
58 self.dataOut.frequency = self.dataIn.frequency
57 self.dataOut.frequency = self.dataIn.frequency
59 self.dataOut.realtime = self.dataIn.realtime
58 self.dataOut.realtime = self.dataIn.realtime
60
59
61 self.dataOut.azimuth = self.dataIn.azimuth
60 self.dataOut.azimuth = self.dataIn.azimuth
62 self.dataOut.zenith = self.dataIn.zenith
61 self.dataOut.zenith = self.dataIn.zenith
63
62
64 self.dataOut.beam.codeList = self.dataIn.beam.codeList
63 self.dataOut.beam.codeList = self.dataIn.beam.codeList
65 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
64 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
66 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
65 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
67
66
68 self.dataOut.step = self.dataIn.step #
69
70 def __getFft(self):
67 def __getFft(self):
71 """
68 """
72 Convierte valores de Voltaje a Spectra
69 Convierte valores de Voltaje a Spectra
73
70
74 Affected:
71 Affected:
75 self.dataOut.data_spc
72 self.dataOut.data_spc
76 self.dataOut.data_cspc
73 self.dataOut.data_cspc
77 self.dataOut.data_dc
74 self.dataOut.data_dc
78 self.dataOut.heightList
75 self.dataOut.heightList
79 self.profIndex
76 self.profIndex
80 self.buffer
77 self.buffer
81 self.dataOut.flagNoData
78 self.dataOut.flagNoData
82 """
79 """
83 fft_volt = numpy.fft.fft(
80 fft_volt = numpy.fft.fft(
84 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
81 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
85 fft_volt = fft_volt.astype(numpy.dtype('complex'))
82 fft_volt = fft_volt.astype(numpy.dtype('complex'))
86 dc = fft_volt[:, 0, :]
83 dc = fft_volt[:, 0, :]
87
84
88 # calculo de self-spectra
85 # calculo de self-spectra
89 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
86 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
90 spc = fft_volt * numpy.conjugate(fft_volt)
87 spc = fft_volt * numpy.conjugate(fft_volt)
91 spc = spc.real
88 spc = spc.real
92
89
93 blocksize = 0
90 blocksize = 0
94 blocksize += dc.size
91 blocksize += dc.size
95 blocksize += spc.size
92 blocksize += spc.size
96
93
97 cspc = None
94 cspc = None
98 pairIndex = 0
95 pairIndex = 0
99 if self.dataOut.pairsList != None:
96 if self.dataOut.pairsList != None:
100 # calculo de cross-spectra
97 # calculo de cross-spectra
101 cspc = numpy.zeros(
98 cspc = numpy.zeros(
102 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
99 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
103 for pair in self.dataOut.pairsList:
100 for pair in self.dataOut.pairsList:
104 if pair[0] not in self.dataOut.channelList:
101 if pair[0] not in self.dataOut.channelList:
105 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
102 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
106 str(pair), str(self.dataOut.channelList))
103 str(pair), str(self.dataOut.channelList))
107 if pair[1] not in self.dataOut.channelList:
104 if pair[1] not in self.dataOut.channelList:
108 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
105 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
109 str(pair), str(self.dataOut.channelList))
106 str(pair), str(self.dataOut.channelList))
110
107
111 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
108 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
112 numpy.conjugate(fft_volt[pair[1], :, :])
109 numpy.conjugate(fft_volt[pair[1], :, :])
113 pairIndex += 1
110 pairIndex += 1
114 blocksize += cspc.size
111 blocksize += cspc.size
115
112
116 self.dataOut.data_spc = spc
113 self.dataOut.data_spc = spc
117 self.dataOut.data_cspc = cspc
114 self.dataOut.data_cspc = cspc
118 self.dataOut.data_dc = dc
115 self.dataOut.data_dc = dc
119 self.dataOut.blockSize = blocksize
116 self.dataOut.blockSize = blocksize
120 self.dataOut.flagShiftFFT = True
117 self.dataOut.flagShiftFFT = True
121
118
122 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False):
119 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None, shift_fft=False):
123
120
124 self.dataOut.flagNoData = True
121 self.dataOut.flagNoData = True
125
122
126 if self.dataIn.type == "Spectra":
123 if self.dataIn.type == "Spectra":
127 self.dataOut.copy(self.dataIn)
124 self.dataOut.copy(self.dataIn)
128 print "hi",self.dataOut.ippSeconds
125
129 if shift_fft:
126 if shift_fft:
130 #desplaza a la derecha en el eje 2 determinadas posiciones
127 #desplaza a la derecha en el eje 2 determinadas posiciones
131 shift = int(self.dataOut.nFFTPoints/2)
128 shift = int(self.dataOut.nFFTPoints/2)
132 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
129 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
133
130
134 if self.dataOut.data_cspc is not None:
131 if self.dataOut.data_cspc is not None:
135 #desplaza a la derecha en el eje 2 determinadas posiciones
132 #desplaza a la derecha en el eje 2 determinadas posiciones
136 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
133 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
137
134
138 return True
135 return True
139
136
140 if self.dataIn.type == "Voltage":
137 if self.dataIn.type == "Voltage":
141
138
142 if nFFTPoints == None:
139 if nFFTPoints == None:
143 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
140 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
144
141
145 if nProfiles == None:
142 if nProfiles == None:
146 nProfiles = nFFTPoints
143 nProfiles = nFFTPoints
147
144
148 if ippFactor == None:
145 if ippFactor == None:
149 ippFactor = 1
146 ippFactor = 1
150
147
151 self.dataOut.ippFactor = ippFactor
148 self.dataOut.ippFactor = ippFactor
152
149
153 self.dataOut.nFFTPoints = nFFTPoints
150 self.dataOut.nFFTPoints = nFFTPoints
154 self.dataOut.pairsList = pairsList
151 self.dataOut.pairsList = pairsList
155
152
156 if self.buffer is None:
153 if self.buffer is None:
157 self.buffer = numpy.zeros((self.dataIn.nChannels,
154 self.buffer = numpy.zeros((self.dataIn.nChannels,
158 nProfiles,
155 nProfiles,
159 self.dataIn.heightList.shape[0]),
156 self.dataIn.heightList.shape[0]),#update heightlist
160 dtype='complex')
157 dtype='complex')
161
158
162
159
163
160
164 if self.dataIn.flagDataAsBlock:
161 if self.dataIn.flagDataAsBlock:
165 nVoltProfiles = self.dataIn.data.shape[1]
162 nVoltProfiles = self.dataIn.data.shape[1]
166
163
167 if nVoltProfiles == nProfiles:
164 if nVoltProfiles == nProfiles:
168 self.buffer = self.dataIn.data.copy()
165 self.buffer = self.dataIn.data.copy()
169 self.profIndex = nVoltProfiles
166 self.profIndex = nVoltProfiles
170
167
171 elif nVoltProfiles < nProfiles:
168 elif nVoltProfiles < nProfiles:
172
169
173 if self.profIndex == 0:
170 if self.profIndex == 0:
174 self.id_min = 0
171 self.id_min = 0
175 self.id_max = nVoltProfiles
172 self.id_max = nVoltProfiles
176
173
177 self.buffer[:, self.id_min:self.id_max,:] = self.dataIn.data
174 self.buffer[:, self.id_min:self.id_max,:] = self.dataIn.data
178 self.profIndex += nVoltProfiles
175 self.profIndex += nVoltProfiles
179 self.id_min += nVoltProfiles
176 self.id_min += nVoltProfiles
180 self.id_max += nVoltProfiles
177 self.id_max += nVoltProfiles
181 else:
178 else:
182 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles" % (
179 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles" % (
183 self.dataIn.type, self.dataIn.data.shape[1], nProfiles)
180 self.dataIn.type, self.dataIn.data.shape[1], nProfiles)
184 self.dataOut.flagNoData = True
181 self.dataOut.flagNoData = True
185 return 0
182 return 0
186 else:
183 else:
187 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
184 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
188 self.profIndex += 1
185 self.profIndex += 1
189
186
190 if self.firstdatatime == None:
187 if self.firstdatatime == None:
191 self.firstdatatime = self.dataIn.utctime
188 self.firstdatatime = self.dataIn.utctime
192
189
193 if self.profIndex == nProfiles:
190 if self.profIndex == nProfiles:
194 self.__updateSpecFromVoltage()
191 self.__updateSpecFromVoltage()
195 self.__getFft()
192 self.__getFft()
196
193
197 self.dataOut.flagNoData = False
194 self.dataOut.flagNoData = False
198 self.firstdatatime = None
195 self.firstdatatime = None
199 self.profIndex = 0
196 self.profIndex = 0
200
197
201 return True
198 return True
202
199
203 raise ValueError, "The type of input object '%s' is not valid" % (
200 raise ValueError, "The type of input object '%s' is not valid" % (
204 self.dataIn.type)
201 self.dataIn.type)
205
202
206 def __selectPairs(self, pairsList):
203 def __selectPairs(self, pairsList):
207
204
208 if not pairsList:
205 if not pairsList:
209 return
206 return
210
207
211 pairs = []
208 pairs = []
212 pairsIndex = []
209 pairsIndex = []
213
210
214 for pair in pairsList:
211 for pair in pairsList:
215 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
212 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
216 continue
213 continue
217 pairs.append(pair)
214 pairs.append(pair)
218 pairsIndex.append(pairs.index(pair))
215 pairsIndex.append(pairs.index(pair))
219
216
220 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
217 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
221 self.dataOut.pairsList = pairs
218 self.dataOut.pairsList = pairs
222
219
223 return
220 return
224
221
225 def __selectPairsByChannel(self, channelList=None):
222 def __selectPairsByChannel(self, channelList=None):
226
223
227 if channelList == None:
224 if channelList == None:
228 return
225 return
229
226
230 pairsIndexListSelected = []
227 pairsIndexListSelected = []
231 for pairIndex in self.dataOut.pairsIndexList:
228 for pairIndex in self.dataOut.pairsIndexList:
232 # First pair
229 # First pair
233 if self.dataOut.pairsList[pairIndex][0] not in channelList:
230 if self.dataOut.pairsList[pairIndex][0] not in channelList:
234 continue
231 continue
235 # Second pair
232 # Second pair
236 if self.dataOut.pairsList[pairIndex][1] not in channelList:
233 if self.dataOut.pairsList[pairIndex][1] not in channelList:
237 continue
234 continue
238
235
239 pairsIndexListSelected.append(pairIndex)
236 pairsIndexListSelected.append(pairIndex)
240
237
241 if not pairsIndexListSelected:
238 if not pairsIndexListSelected:
242 self.dataOut.data_cspc = None
239 self.dataOut.data_cspc = None
243 self.dataOut.pairsList = []
240 self.dataOut.pairsList = []
244 return
241 return
245
242
246 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
243 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
247 self.dataOut.pairsList = [self.dataOut.pairsList[i]
244 self.dataOut.pairsList = [self.dataOut.pairsList[i]
248 for i in pairsIndexListSelected]
245 for i in pairsIndexListSelected]
249
246
250 return
247 return
251
248
252 def selectChannels(self, channelList):
249 def selectChannels(self, channelList):
253
250
254 channelIndexList = []
251 channelIndexList = []
255
252
256 for channel in channelList:
253 for channel in channelList:
257 if channel not in self.dataOut.channelList:
254 if channel not in self.dataOut.channelList:
258 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % (
255 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" % (
259 channel, str(self.dataOut.channelList))
256 channel, str(self.dataOut.channelList))
260
257
261 index = self.dataOut.channelList.index(channel)
258 index = self.dataOut.channelList.index(channel)
262 channelIndexList.append(index)
259 channelIndexList.append(index)
263
260
264 self.selectChannelsByIndex(channelIndexList)
261 self.selectChannelsByIndex(channelIndexList)
265
262
266 def selectChannelsByIndex(self, channelIndexList):
263 def selectChannelsByIndex(self, channelIndexList):
267 """
264 """
268 Selecciona un bloque de datos en base a canales segun el channelIndexList
265 Selecciona un bloque de datos en base a canales segun el channelIndexList
269
266
270 Input:
267 Input:
271 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
268 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
272
269
273 Affected:
270 Affected:
274 self.dataOut.data_spc
271 self.dataOut.data_spc
275 self.dataOut.channelIndexList
272 self.dataOut.channelIndexList
276 self.dataOut.nChannels
273 self.dataOut.nChannels
277
274
278 Return:
275 Return:
279 None
276 None
280 """
277 """
281
278
282 for channelIndex in channelIndexList:
279 for channelIndex in channelIndexList:
283 if channelIndex not in self.dataOut.channelIndexList:
280 if channelIndex not in self.dataOut.channelIndexList:
284 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % (
281 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " % (
285 channelIndex, self.dataOut.channelIndexList)
282 channelIndex, self.dataOut.channelIndexList)
286
283
287 # nChannels = len(channelIndexList)
284 # nChannels = len(channelIndexList)
288
285
289 data_spc = self.dataOut.data_spc[channelIndexList, :]
286 data_spc = self.dataOut.data_spc[channelIndexList, :]
290 data_dc = self.dataOut.data_dc[channelIndexList, :]
287 data_dc = self.dataOut.data_dc[channelIndexList, :]
291
288
292 self.dataOut.data_spc = data_spc
289 self.dataOut.data_spc = data_spc
293 self.dataOut.data_dc = data_dc
290 self.dataOut.data_dc = data_dc
294
291
295 self.dataOut.channelList = [
292 self.dataOut.channelList = [
296 self.dataOut.channelList[i] for i in channelIndexList]
293 self.dataOut.channelList[i] for i in channelIndexList]
297 # self.dataOut.nChannels = nChannels
294 # self.dataOut.nChannels = nChannels
298
295
299 self.__selectPairsByChannel(self.dataOut.channelList)
296 self.__selectPairsByChannel(self.dataOut.channelList)
300
297
301 return 1
298 return 1
302
299
303 def selectHeights(self, minHei, maxHei):
300 def selectHeights(self, minHei, maxHei):
304 """
301 """
305 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
302 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
306 minHei <= height <= maxHei
303 minHei <= height <= maxHei
307
304
308 Input:
305 Input:
309 minHei : valor minimo de altura a considerar
306 minHei : valor minimo de altura a considerar
310 maxHei : valor maximo de altura a considerar
307 maxHei : valor maximo de altura a considerar
311
308
312 Affected:
309 Affected:
313 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
310 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
314
311
315 Return:
312 Return:
316 1 si el metodo se ejecuto con exito caso contrario devuelve 0
313 1 si el metodo se ejecuto con exito caso contrario devuelve 0
317 """
314 """
318
315
319 if (minHei > maxHei):
316 if (minHei > maxHei):
320 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (
317 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (
321 minHei, maxHei)
318 minHei, maxHei)
322
319
323 if (minHei < self.dataOut.heightList[0]):
320 if (minHei < self.dataOut.heightList[0]):
324 minHei = self.dataOut.heightList[0]
321 minHei = self.dataOut.heightList[0]
325
322
326 if (maxHei > self.dataOut.heightList[-1]):
323 if (maxHei > self.dataOut.heightList[-1]):
327 maxHei = self.dataOut.heightList[-1]
324 maxHei = self.dataOut.heightList[-1]
328
325
329 minIndex = 0
326 minIndex = 0
330 maxIndex = 0
327 maxIndex = 0
331 heights = self.dataOut.heightList
328 heights = self.dataOut.heightList
332
329
333 inda = numpy.where(heights >= minHei)
330 inda = numpy.where(heights >= minHei)
334 indb = numpy.where(heights <= maxHei)
331 indb = numpy.where(heights <= maxHei)
335
332
336 try:
333 try:
337 minIndex = inda[0][0]
334 minIndex = inda[0][0]
338 except:
335 except:
339 minIndex = 0
336 minIndex = 0
340
337
341 try:
338 try:
342 maxIndex = indb[0][-1]
339 maxIndex = indb[0][-1]
343 except:
340 except:
344 maxIndex = len(heights)
341 maxIndex = len(heights)
345
342
346 self.selectHeightsByIndex(minIndex, maxIndex)
343 self.selectHeightsByIndex(minIndex, maxIndex)
347
344
348 return 1
345 return 1
349
346
350 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
347 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
351 newheis = numpy.where(
348 newheis = numpy.where(
352 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
349 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
353
350
354 if hei_ref != None:
351 if hei_ref != None:
355 newheis = numpy.where(self.dataOut.heightList > hei_ref)
352 newheis = numpy.where(self.dataOut.heightList > hei_ref)
356
353
357 minIndex = min(newheis[0])
354 minIndex = min(newheis[0])
358 maxIndex = max(newheis[0])
355 maxIndex = max(newheis[0])
359 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
356 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
360 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
357 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
361
358
362 # determina indices
359 # determina indices
363 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
360 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
364 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
361 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
365 avg_dB = 10 * \
362 avg_dB = 10 * \
366 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
363 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
367 beacon_dB = numpy.sort(avg_dB)[-nheis:]
364 beacon_dB = numpy.sort(avg_dB)[-nheis:]
368 beacon_heiIndexList = []
365 beacon_heiIndexList = []
369 for val in avg_dB.tolist():
366 for val in avg_dB.tolist():
370 if val >= beacon_dB[0]:
367 if val >= beacon_dB[0]:
371 beacon_heiIndexList.append(avg_dB.tolist().index(val))
368 beacon_heiIndexList.append(avg_dB.tolist().index(val))
372
369
373 #data_spc = data_spc[:,:,beacon_heiIndexList]
370 #data_spc = data_spc[:,:,beacon_heiIndexList]
374 data_cspc = None
371 data_cspc = None
375 if self.dataOut.data_cspc is not None:
372 if self.dataOut.data_cspc is not None:
376 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
373 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
377 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
374 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
378
375
379 data_dc = None
376 data_dc = None
380 if self.dataOut.data_dc is not None:
377 if self.dataOut.data_dc is not None:
381 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
378 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
382 #data_dc = data_dc[:,beacon_heiIndexList]
379 #data_dc = data_dc[:,beacon_heiIndexList]
383
380
384 self.dataOut.data_spc = data_spc
381 self.dataOut.data_spc = data_spc
385 self.dataOut.data_cspc = data_cspc
382 self.dataOut.data_cspc = data_cspc
386 self.dataOut.data_dc = data_dc
383 self.dataOut.data_dc = data_dc
387 self.dataOut.heightList = heightList
384 self.dataOut.heightList = heightList
388 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
385 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
389
386
390 return 1
387 return 1
391
388
392 def selectHeightsByIndex(self, minIndex, maxIndex):
389 def selectHeightsByIndex(self, minIndex, maxIndex):
393 """
390 """
394 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
391 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
395 minIndex <= index <= maxIndex
392 minIndex <= index <= maxIndex
396
393
397 Input:
394 Input:
398 minIndex : valor de indice minimo de altura a considerar
395 minIndex : valor de indice minimo de altura a considerar
399 maxIndex : valor de indice maximo de altura a considerar
396 maxIndex : valor de indice maximo de altura a considerar
400
397
401 Affected:
398 Affected:
402 self.dataOut.data_spc
399 self.dataOut.data_spc
403 self.dataOut.data_cspc
400 self.dataOut.data_cspc
404 self.dataOut.data_dc
401 self.dataOut.data_dc
405 self.dataOut.heightList
402 self.dataOut.heightList
406
403
407 Return:
404 Return:
408 1 si el metodo se ejecuto con exito caso contrario devuelve 0
405 1 si el metodo se ejecuto con exito caso contrario devuelve 0
409 """
406 """
410
407
411 if (minIndex < 0) or (minIndex > maxIndex):
408 if (minIndex < 0) or (minIndex > maxIndex):
412 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (
409 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (
413 minIndex, maxIndex)
410 minIndex, maxIndex)
414
411
415 if (maxIndex >= self.dataOut.nHeights):
412 if (maxIndex >= self.dataOut.nHeights):
416 maxIndex = self.dataOut.nHeights - 1
413 maxIndex = self.dataOut.nHeights - 1
417
414
418 # Spectra
415 # Spectra
419 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
416 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
420
417
421 data_cspc = None
418 data_cspc = None
422 if self.dataOut.data_cspc is not None:
419 if self.dataOut.data_cspc is not None:
423 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
420 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
424
421
425 data_dc = None
422 data_dc = None
426 if self.dataOut.data_dc is not None:
423 if self.dataOut.data_dc is not None:
427 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
424 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
428
425
429 self.dataOut.data_spc = data_spc
426 self.dataOut.data_spc = data_spc
430 self.dataOut.data_cspc = data_cspc
427 self.dataOut.data_cspc = data_cspc
431 self.dataOut.data_dc = data_dc
428 self.dataOut.data_dc = data_dc
432
429
433 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
430 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
434
431
435 return 1
432 return 1
436
433
437 def removeDC(self, mode=2):
434 def removeDC(self, mode=2):
438 jspectra = self.dataOut.data_spc
435 jspectra = self.dataOut.data_spc
439 jcspectra = self.dataOut.data_cspc
436 jcspectra = self.dataOut.data_cspc
440
437
441 num_chan = jspectra.shape[0]
438 num_chan = jspectra.shape[0]
442 num_hei = jspectra.shape[2]
439 num_hei = jspectra.shape[2]
443
440
444 if jcspectra is not None:
441 if jcspectra is not None:
445 jcspectraExist = True
442 jcspectraExist = True
446 num_pairs = jcspectra.shape[0]
443 num_pairs = jcspectra.shape[0]
447 else:
444 else:
448 jcspectraExist = False
445 jcspectraExist = False
449
446
450 freq_dc = jspectra.shape[1] / 2
447 freq_dc = jspectra.shape[1] / 2
451 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
448 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
452
449
453 if ind_vel[0] < 0:
450 if ind_vel[0] < 0:
454 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
451 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
455
452
456 if mode == 1:
453 if mode == 1:
457 jspectra[:, freq_dc, :] = (
454 jspectra[:, freq_dc, :] = (
458 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
455 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
459
456
460 if jcspectraExist:
457 if jcspectraExist:
461 jcspectra[:, freq_dc, :] = (
458 jcspectra[:, freq_dc, :] = (
462 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
459 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
463
460
464 if mode == 2:
461 if mode == 2:
465
462
466 vel = numpy.array([-2, -1, 1, 2])
463 vel = numpy.array([-2, -1, 1, 2])
467 xx = numpy.zeros([4, 4])
464 xx = numpy.zeros([4, 4])
468
465
469 for fil in range(4):
466 for fil in range(4):
470 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
467 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
471
468
472 xx_inv = numpy.linalg.inv(xx)
469 xx_inv = numpy.linalg.inv(xx)
473 xx_aux = xx_inv[0, :]
470 xx_aux = xx_inv[0, :]
474
471
475 for ich in range(num_chan):
472 for ich in range(num_chan):
476 yy = jspectra[ich, ind_vel, :]
473 yy = jspectra[ich, ind_vel, :]
477 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
474 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
478
475
479 junkid = jspectra[ich, freq_dc, :] <= 0
476 junkid = jspectra[ich, freq_dc, :] <= 0
480 cjunkid = sum(junkid)
477 cjunkid = sum(junkid)
481
478
482 if cjunkid.any():
479 if cjunkid.any():
483 jspectra[ich, freq_dc, junkid.nonzero()] = (
480 jspectra[ich, freq_dc, junkid.nonzero()] = (
484 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
481 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
485
482
486 if jcspectraExist:
483 if jcspectraExist:
487 for ip in range(num_pairs):
484 for ip in range(num_pairs):
488 yy = jcspectra[ip, ind_vel, :]
485 yy = jcspectra[ip, ind_vel, :]
489 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
486 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
490
487
491 self.dataOut.data_spc = jspectra
488 self.dataOut.data_spc = jspectra
492 self.dataOut.data_cspc = jcspectra
489 self.dataOut.data_cspc = jcspectra
493
490
494 return 1
491 return 1
495
492
496 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
493 def removeInterference(self, interf=2, hei_interf=None, nhei_interf=None, offhei_interf=None):
497
494
498 jspectra = self.dataOut.data_spc
495 jspectra = self.dataOut.data_spc
499 jcspectra = self.dataOut.data_cspc
496 jcspectra = self.dataOut.data_cspc
500 jnoise = self.dataOut.getNoise()
497 jnoise = self.dataOut.getNoise()
501 num_incoh = self.dataOut.nIncohInt
498 num_incoh = self.dataOut.nIncohInt
502
499
503 num_channel = jspectra.shape[0]
500 num_channel = jspectra.shape[0]
504 num_prof = jspectra.shape[1]
501 num_prof = jspectra.shape[1]
505 num_hei = jspectra.shape[2]
502 num_hei = jspectra.shape[2]
506
503
507 # hei_interf
504 # hei_interf
508 if hei_interf is None:
505 if hei_interf is None:
509 count_hei = num_hei / 2 # Como es entero no importa
506 count_hei = num_hei / 2 # Como es entero no importa
510 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
507 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
511 hei_interf = numpy.asarray(hei_interf)[0]
508 hei_interf = numpy.asarray(hei_interf)[0]
512 # nhei_interf
509 # nhei_interf
513 if (nhei_interf == None):
510 if (nhei_interf == None):
514 nhei_interf = 5
511 nhei_interf = 5
515 if (nhei_interf < 1):
512 if (nhei_interf < 1):
516 nhei_interf = 1
513 nhei_interf = 1
517 if (nhei_interf > count_hei):
514 if (nhei_interf > count_hei):
518 nhei_interf = count_hei
515 nhei_interf = count_hei
519 if (offhei_interf == None):
516 if (offhei_interf == None):
520 offhei_interf = 0
517 offhei_interf = 0
521
518
522 ind_hei = range(num_hei)
519 ind_hei = range(num_hei)
523 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
520 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
524 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
521 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
525 mask_prof = numpy.asarray(range(num_prof))
522 mask_prof = numpy.asarray(range(num_prof))
526 num_mask_prof = mask_prof.size
523 num_mask_prof = mask_prof.size
527 comp_mask_prof = [0, num_prof / 2]
524 comp_mask_prof = [0, num_prof / 2]
528
525
529 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
526 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
530 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
527 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
531 jnoise = numpy.nan
528 jnoise = numpy.nan
532 noise_exist = jnoise[0] < numpy.Inf
529 noise_exist = jnoise[0] < numpy.Inf
533
530
534 # Subrutina de Remocion de la Interferencia
531 # Subrutina de Remocion de la Interferencia
535 for ich in range(num_channel):
532 for ich in range(num_channel):
536 # Se ordena los espectros segun su potencia (menor a mayor)
533 # Se ordena los espectros segun su potencia (menor a mayor)
537 power = jspectra[ich, mask_prof, :]
534 power = jspectra[ich, mask_prof, :]
538 power = power[:, hei_interf]
535 power = power[:, hei_interf]
539 power = power.sum(axis=0)
536 power = power.sum(axis=0)
540 psort = power.ravel().argsort()
537 psort = power.ravel().argsort()
541
538
542 # Se estima la interferencia promedio en los Espectros de Potencia empleando
539 # Se estima la interferencia promedio en los Espectros de Potencia empleando
543 junkspc_interf = jspectra[ich, :, hei_interf[psort[range(
540 junkspc_interf = jspectra[ich, :, hei_interf[psort[range(
544 offhei_interf, nhei_interf + offhei_interf)]]]
541 offhei_interf, nhei_interf + offhei_interf)]]]
545
542
546 if noise_exist:
543 if noise_exist:
547 # tmp_noise = jnoise[ich] / num_prof
544 # tmp_noise = jnoise[ich] / num_prof
548 tmp_noise = jnoise[ich]
545 tmp_noise = jnoise[ich]
549 junkspc_interf = junkspc_interf - tmp_noise
546 junkspc_interf = junkspc_interf - tmp_noise
550 #junkspc_interf[:,comp_mask_prof] = 0
547 #junkspc_interf[:,comp_mask_prof] = 0
551
548
552 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
549 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
553 jspc_interf = jspc_interf.transpose()
550 jspc_interf = jspc_interf.transpose()
554 # Calculando el espectro de interferencia promedio
551 # Calculando el espectro de interferencia promedio
555 noiseid = numpy.where(
552 noiseid = numpy.where(
556 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
553 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
557 noiseid = noiseid[0]
554 noiseid = noiseid[0]
558 cnoiseid = noiseid.size
555 cnoiseid = noiseid.size
559 interfid = numpy.where(
556 interfid = numpy.where(
560 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
557 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
561 interfid = interfid[0]
558 interfid = interfid[0]
562 cinterfid = interfid.size
559 cinterfid = interfid.size
563
560
564 if (cnoiseid > 0):
561 if (cnoiseid > 0):
565 jspc_interf[noiseid] = 0
562 jspc_interf[noiseid] = 0
566
563
567 # Expandiendo los perfiles a limpiar
564 # Expandiendo los perfiles a limpiar
568 if (cinterfid > 0):
565 if (cinterfid > 0):
569 new_interfid = (
566 new_interfid = (
570 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
567 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
571 new_interfid = numpy.asarray(new_interfid)
568 new_interfid = numpy.asarray(new_interfid)
572 new_interfid = {x for x in new_interfid}
569 new_interfid = {x for x in new_interfid}
573 new_interfid = numpy.array(list(new_interfid))
570 new_interfid = numpy.array(list(new_interfid))
574 new_cinterfid = new_interfid.size
571 new_cinterfid = new_interfid.size
575 else:
572 else:
576 new_cinterfid = 0
573 new_cinterfid = 0
577
574
578 for ip in range(new_cinterfid):
575 for ip in range(new_cinterfid):
579 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
576 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
580 jspc_interf[new_interfid[ip]
577 jspc_interf[new_interfid[ip]
581 ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]]
578 ] = junkspc_interf[ind[nhei_interf / 2], new_interfid[ip]]
582
579
583 jspectra[ich, :, ind_hei] = jspectra[ich, :,
580 jspectra[ich, :, ind_hei] = jspectra[ich, :,
584 ind_hei] - jspc_interf # Corregir indices
581 ind_hei] - jspc_interf # Corregir indices
585
582
586 # Removiendo la interferencia del punto de mayor interferencia
583 # Removiendo la interferencia del punto de mayor interferencia
587 ListAux = jspc_interf[mask_prof].tolist()
584 ListAux = jspc_interf[mask_prof].tolist()
588 maxid = ListAux.index(max(ListAux))
585 maxid = ListAux.index(max(ListAux))
589
586
590 if cinterfid > 0:
587 if cinterfid > 0:
591 for ip in range(cinterfid * (interf == 2) - 1):
588 for ip in range(cinterfid * (interf == 2) - 1):
592 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
589 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
593 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
590 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
594 cind = len(ind)
591 cind = len(ind)
595
592
596 if (cind > 0):
593 if (cind > 0):
597 jspectra[ich, interfid[ip], ind] = tmp_noise * \
594 jspectra[ich, interfid[ip], ind] = tmp_noise * \
598 (1 + (numpy.random.uniform(cind) - 0.5) /
595 (1 + (numpy.random.uniform(cind) - 0.5) /
599 numpy.sqrt(num_incoh))
596 numpy.sqrt(num_incoh))
600
597
601 ind = numpy.array([-2, -1, 1, 2])
598 ind = numpy.array([-2, -1, 1, 2])
602 xx = numpy.zeros([4, 4])
599 xx = numpy.zeros([4, 4])
603
600
604 for id1 in range(4):
601 for id1 in range(4):
605 xx[:, id1] = ind[id1]**numpy.asarray(range(4))
602 xx[:, id1] = ind[id1]**numpy.asarray(range(4))
606
603
607 xx_inv = numpy.linalg.inv(xx)
604 xx_inv = numpy.linalg.inv(xx)
608 xx = xx_inv[:, 0]
605 xx = xx_inv[:, 0]
609 ind = (ind + maxid + num_mask_prof) % num_mask_prof
606 ind = (ind + maxid + num_mask_prof) % num_mask_prof
610 yy = jspectra[ich, mask_prof[ind], :]
607 yy = jspectra[ich, mask_prof[ind], :]
611 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
608 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
612 yy.transpose(), xx)
609 yy.transpose(), xx)
613
610
614 indAux = (jspectra[ich, :, :] < tmp_noise *
611 indAux = (jspectra[ich, :, :] < tmp_noise *
615 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
612 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
616 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
613 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
617 (1 - 1 / numpy.sqrt(num_incoh))
614 (1 - 1 / numpy.sqrt(num_incoh))
618
615
619 # Remocion de Interferencia en el Cross Spectra
616 # Remocion de Interferencia en el Cross Spectra
620 if jcspectra is None:
617 if jcspectra is None:
621 return jspectra, jcspectra
618 return jspectra, jcspectra
622 num_pairs = jcspectra.size / (num_prof * num_hei)
619 num_pairs = jcspectra.size / (num_prof * num_hei)
623 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
620 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
624
621
625 for ip in range(num_pairs):
622 for ip in range(num_pairs):
626
623
627 #-------------------------------------------
624 #-------------------------------------------
628
625
629 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
626 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
630 cspower = cspower[:, hei_interf]
627 cspower = cspower[:, hei_interf]
631 cspower = cspower.sum(axis=0)
628 cspower = cspower.sum(axis=0)
632
629
633 cspsort = cspower.ravel().argsort()
630 cspsort = cspower.ravel().argsort()
634 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range(
631 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[range(
635 offhei_interf, nhei_interf + offhei_interf)]]]
632 offhei_interf, nhei_interf + offhei_interf)]]]
636 junkcspc_interf = junkcspc_interf.transpose()
633 junkcspc_interf = junkcspc_interf.transpose()
637 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
634 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
638
635
639 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
636 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
640
637
641 median_real = numpy.median(numpy.real(
638 median_real = numpy.median(numpy.real(
642 junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :]))
639 junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :]))
643 median_imag = numpy.median(numpy.imag(
640 median_imag = numpy.median(numpy.imag(
644 junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :]))
641 junkcspc_interf[mask_prof[ind[range(3 * num_prof / 4)]], :]))
645 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
642 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
646 median_real, median_imag)
643 median_real, median_imag)
647
644
648 for iprof in range(num_prof):
645 for iprof in range(num_prof):
649 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
646 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
650 jcspc_interf[iprof] = junkcspc_interf[iprof,
647 jcspc_interf[iprof] = junkcspc_interf[iprof,
651 ind[nhei_interf / 2]]
648 ind[nhei_interf / 2]]
652
649
653 # Removiendo la Interferencia
650 # Removiendo la Interferencia
654 jcspectra[ip, :, ind_hei] = jcspectra[ip,
651 jcspectra[ip, :, ind_hei] = jcspectra[ip,
655 :, ind_hei] - jcspc_interf
652 :, ind_hei] - jcspc_interf
656
653
657 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
654 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
658 maxid = ListAux.index(max(ListAux))
655 maxid = ListAux.index(max(ListAux))
659
656
660 ind = numpy.array([-2, -1, 1, 2])
657 ind = numpy.array([-2, -1, 1, 2])
661 xx = numpy.zeros([4, 4])
658 xx = numpy.zeros([4, 4])
662
659
663 for id1 in range(4):
660 for id1 in range(4):
664 xx[:, id1] = ind[id1]**numpy.asarray(range(4))
661 xx[:, id1] = ind[id1]**numpy.asarray(range(4))
665
662
666 xx_inv = numpy.linalg.inv(xx)
663 xx_inv = numpy.linalg.inv(xx)
667 xx = xx_inv[:, 0]
664 xx = xx_inv[:, 0]
668
665
669 ind = (ind + maxid + num_mask_prof) % num_mask_prof
666 ind = (ind + maxid + num_mask_prof) % num_mask_prof
670 yy = jcspectra[ip, mask_prof[ind], :]
667 yy = jcspectra[ip, mask_prof[ind], :]
671 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
668 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
672
669
673 # Guardar Resultados
670 # Guardar Resultados
674 self.dataOut.data_spc = jspectra
671 self.dataOut.data_spc = jspectra
675 self.dataOut.data_cspc = jcspectra
672 self.dataOut.data_cspc = jcspectra
676
673
677 return 1
674 return 1
678
675
679 def setRadarFrequency(self, frequency=None):
676 def setRadarFrequency(self, frequency=None):
680
677
681 if frequency != None:
678 if frequency != None:
682 self.dataOut.frequency = frequency
679 self.dataOut.frequency = frequency
683
680
684 return 1
681 return 1
685
682
686 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
683 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
687 # validacion de rango
684 # validacion de rango
688 if minHei == None:
685 if minHei == None:
689 minHei = self.dataOut.heightList[0]
686 minHei = self.dataOut.heightList[0]
690
687
691 if maxHei == None:
688 if maxHei == None:
692 maxHei = self.dataOut.heightList[-1]
689 maxHei = self.dataOut.heightList[-1]
693
690
694 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
691 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
695 print 'minHei: %.2f is out of the heights range' % (minHei)
692 print 'minHei: %.2f is out of the heights range' % (minHei)
696 print 'minHei is setting to %.2f' % (self.dataOut.heightList[0])
693 print 'minHei is setting to %.2f' % (self.dataOut.heightList[0])
697 minHei = self.dataOut.heightList[0]
694 minHei = self.dataOut.heightList[0]
698
695
699 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
696 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
700 print 'maxHei: %.2f is out of the heights range' % (maxHei)
697 print 'maxHei: %.2f is out of the heights range' % (maxHei)
701 print 'maxHei is setting to %.2f' % (self.dataOut.heightList[-1])
698 print 'maxHei is setting to %.2f' % (self.dataOut.heightList[-1])
702 maxHei = self.dataOut.heightList[-1]
699 maxHei = self.dataOut.heightList[-1]
703
700
704 # validacion de velocidades
701 # validacion de velocidades
705 velrange = self.dataOut.getVelRange(1)
702 velrange = self.dataOut.getVelRange(1)
706
703
707 if minVel == None:
704 if minVel == None:
708 minVel = velrange[0]
705 minVel = velrange[0]
709
706
710 if maxVel == None:
707 if maxVel == None:
711 maxVel = velrange[-1]
708 maxVel = velrange[-1]
712
709
713 if (minVel < velrange[0]) or (minVel > maxVel):
710 if (minVel < velrange[0]) or (minVel > maxVel):
714 print 'minVel: %.2f is out of the velocity range' % (minVel)
711 print 'minVel: %.2f is out of the velocity range' % (minVel)
715 print 'minVel is setting to %.2f' % (velrange[0])
712 print 'minVel is setting to %.2f' % (velrange[0])
716 minVel = velrange[0]
713 minVel = velrange[0]
717
714
718 if (maxVel > velrange[-1]) or (maxVel < minVel):
715 if (maxVel > velrange[-1]) or (maxVel < minVel):
719 print 'maxVel: %.2f is out of the velocity range' % (maxVel)
716 print 'maxVel: %.2f is out of the velocity range' % (maxVel)
720 print 'maxVel is setting to %.2f' % (velrange[-1])
717 print 'maxVel is setting to %.2f' % (velrange[-1])
721 maxVel = velrange[-1]
718 maxVel = velrange[-1]
722
719
723 # seleccion de indices para rango
720 # seleccion de indices para rango
724 minIndex = 0
721 minIndex = 0
725 maxIndex = 0
722 maxIndex = 0
726 heights = self.dataOut.heightList
723 heights = self.dataOut.heightList
727
724
728 inda = numpy.where(heights >= minHei)
725 inda = numpy.where(heights >= minHei)
729 indb = numpy.where(heights <= maxHei)
726 indb = numpy.where(heights <= maxHei)
730
727
731 try:
728 try:
732 minIndex = inda[0][0]
729 minIndex = inda[0][0]
733 except:
730 except:
734 minIndex = 0
731 minIndex = 0
735
732
736 try:
733 try:
737 maxIndex = indb[0][-1]
734 maxIndex = indb[0][-1]
738 except:
735 except:
739 maxIndex = len(heights)
736 maxIndex = len(heights)
740
737
741 if (minIndex < 0) or (minIndex > maxIndex):
738 if (minIndex < 0) or (minIndex > maxIndex):
742 raise ValueError, "some value in (%d,%d) is not valid" % (
739 raise ValueError, "some value in (%d,%d) is not valid" % (
743 minIndex, maxIndex)
740 minIndex, maxIndex)
744
741
745 if (maxIndex >= self.dataOut.nHeights):
742 if (maxIndex >= self.dataOut.nHeights):
746 maxIndex = self.dataOut.nHeights - 1
743 maxIndex = self.dataOut.nHeights - 1
747
744
748 # seleccion de indices para velocidades
745 # seleccion de indices para velocidades
749 indminvel = numpy.where(velrange >= minVel)
746 indminvel = numpy.where(velrange >= minVel)
750 indmaxvel = numpy.where(velrange <= maxVel)
747 indmaxvel = numpy.where(velrange <= maxVel)
751 try:
748 try:
752 minIndexVel = indminvel[0][0]
749 minIndexVel = indminvel[0][0]
753 except:
750 except:
754 minIndexVel = 0
751 minIndexVel = 0
755
752
756 try:
753 try:
757 maxIndexVel = indmaxvel[0][-1]
754 maxIndexVel = indmaxvel[0][-1]
758 except:
755 except:
759 maxIndexVel = len(velrange)
756 maxIndexVel = len(velrange)
760
757
761 # seleccion del espectro
758 # seleccion del espectro
762 data_spc = self.dataOut.data_spc[:,
759 data_spc = self.dataOut.data_spc[:,
763 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
760 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
764 # estimacion de ruido
761 # estimacion de ruido
765 noise = numpy.zeros(self.dataOut.nChannels)
762 noise = numpy.zeros(self.dataOut.nChannels)
766
763
767 for channel in range(self.dataOut.nChannels):
764 for channel in range(self.dataOut.nChannels):
768 daux = data_spc[channel, :, :]
765 daux = data_spc[channel, :, :]
769 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
766 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
770
767
771 self.dataOut.noise_estimation = noise.copy()
768 self.dataOut.noise_estimation = noise.copy()
772
769
773 return 1
770 return 1
774
771
775
772
776 class IncohInt(Operation):
773 class IncohInt(Operation):
777
774
778 __profIndex = 0
775 __profIndex = 0
779 __withOverapping = False
776 __withOverapping = False
780
777
781 __byTime = False
778 __byTime = False
782 __initime = None
779 __initime = None
783 __lastdatatime = None
780 __lastdatatime = None
784 __integrationtime = None
781 __integrationtime = None
785
782
786 __buffer_spc = None
783 __buffer_spc = None
787 __buffer_cspc = None
784 __buffer_cspc = None
788 __buffer_dc = None
785 __buffer_dc = None
789
786
790 __dataReady = False
787 __dataReady = False
791
788
792 __timeInterval = None
789 __timeInterval = None
793
790
794 n = None
791 n = None
795
792
796 def __init__(self, **kwargs):
793 def __init__(self, **kwargs):
797
794
798 Operation.__init__(self, **kwargs)
795 Operation.__init__(self, **kwargs)
799 # self.isConfig = False
796 # self.isConfig = False
800
797
801 def setup(self, n=None, timeInterval=None, overlapping=False):
798 def setup(self, n=None, timeInterval=None, overlapping=False):
802 """
799 """
803 Set the parameters of the integration class.
800 Set the parameters of the integration class.
804
801
805 Inputs:
802 Inputs:
806
803
807 n : Number of coherent integrations
804 n : Number of coherent integrations
808 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
805 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
809 overlapping :
806 overlapping :
810
807
811 """
808 """
812
809
813 self.__initime = None
810 self.__initime = None
814 self.__lastdatatime = 0
811 self.__lastdatatime = 0
815
812
816 self.__buffer_spc = 0
813 self.__buffer_spc = 0
817 self.__buffer_cspc = 0
814 self.__buffer_cspc = 0
818 self.__buffer_dc = 0
815 self.__buffer_dc = 0
819
816
820 self.__profIndex = 0
817 self.__profIndex = 0
821 self.__dataReady = False
818 self.__dataReady = False
822 self.__byTime = False
819 self.__byTime = False
823
820
824 if n is None and timeInterval is None:
821 if n is None and timeInterval is None:
825 raise ValueError, "n or timeInterval should be specified ..."
822 raise ValueError, "n or timeInterval should be specified ..."
826
823
827 if n is not None:
824 if n is not None:
828 self.n = int(n)
825 self.n = int(n)
829 else:
826 else:
830 # if (type(timeInterval)!=integer) -> change this line
827 # if (type(timeInterval)!=integer) -> change this line
831 self.__integrationtime = int(timeInterval)
828 self.__integrationtime = int(timeInterval)
832 self.n = None
829 self.n = None
833 self.__byTime = True
830 self.__byTime = True
834
831
835 def putData(self, data_spc, data_cspc, data_dc):
832 def putData(self, data_spc, data_cspc, data_dc):
836 """
833 """
837 Add a profile to the __buffer_spc and increase in one the __profileIndex
834 Add a profile to the __buffer_spc and increase in one the __profileIndex
838
835
839 """
836 """
840
837
841 self.__buffer_spc += data_spc
838 self.__buffer_spc += data_spc
842
839
843 if data_cspc is None:
840 if data_cspc is None:
844 self.__buffer_cspc = None
841 self.__buffer_cspc = None
845 else:
842 else:
846 self.__buffer_cspc += data_cspc
843 self.__buffer_cspc += data_cspc
847
844
848 if data_dc is None:
845 if data_dc is None:
849 self.__buffer_dc = None
846 self.__buffer_dc = None
850 else:
847 else:
851 self.__buffer_dc += data_dc
848 self.__buffer_dc += data_dc
852
849
853 self.__profIndex += 1
850 self.__profIndex += 1
854
851
855 return
852 return
856
853
857 def pushData(self):
854 def pushData(self):
858 """
855 """
859 Return the sum of the last profiles and the profiles used in the sum.
856 Return the sum of the last profiles and the profiles used in the sum.
860
857
861 Affected:
858 Affected:
862
859
863 self.__profileIndex
860 self.__profileIndex
864
861
865 """
862 """
866
863
867 data_spc = self.__buffer_spc
864 data_spc = self.__buffer_spc
868 data_cspc = self.__buffer_cspc
865 data_cspc = self.__buffer_cspc
869 data_dc = self.__buffer_dc
866 data_dc = self.__buffer_dc
870 n = self.__profIndex
867 n = self.__profIndex
871
868
872 self.__buffer_spc = 0
869 self.__buffer_spc = 0
873 self.__buffer_cspc = 0
870 self.__buffer_cspc = 0
874 self.__buffer_dc = 0
871 self.__buffer_dc = 0
875 self.__profIndex = 0
872 self.__profIndex = 0
876
873
877 return data_spc, data_cspc, data_dc, n
874 return data_spc, data_cspc, data_dc, n
878
875
879 def byProfiles(self, *args):
876 def byProfiles(self, *args):
880
877
881 self.__dataReady = False
878 self.__dataReady = False
882 avgdata_spc = None
879 avgdata_spc = None
883 avgdata_cspc = None
880 avgdata_cspc = None
884 avgdata_dc = None
881 avgdata_dc = None
885
882
886 self.putData(*args)
883 self.putData(*args)
887
884
888 if self.__profIndex == self.n:
885 if self.__profIndex == self.n:
889
886
890 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
887 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
891 self.n = n
888 self.n = n
892 self.__dataReady = True
889 self.__dataReady = True
893
890
894 return avgdata_spc, avgdata_cspc, avgdata_dc
891 return avgdata_spc, avgdata_cspc, avgdata_dc
895
892
896 def byTime(self, datatime, *args):
893 def byTime(self, datatime, *args):
897
894
898 self.__dataReady = False
895 self.__dataReady = False
899 avgdata_spc = None
896 avgdata_spc = None
900 avgdata_cspc = None
897 avgdata_cspc = None
901 avgdata_dc = None
898 avgdata_dc = None
902
899
903 self.putData(*args)
900 self.putData(*args)
904
901
905 if (datatime - self.__initime) >= self.__integrationtime:
902 if (datatime - self.__initime) >= self.__integrationtime:
906 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
903 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
907 self.n = n
904 self.n = n
908 self.__dataReady = True
905 self.__dataReady = True
909
906
910 return avgdata_spc, avgdata_cspc, avgdata_dc
907 return avgdata_spc, avgdata_cspc, avgdata_dc
911
908
912 def integrate(self, datatime, *args):
909 def integrate(self, datatime, *args):
913
910
914 if self.__profIndex == 0:
911 if self.__profIndex == 0:
915 self.__initime = datatime
912 self.__initime = datatime
916
913
917 if self.__byTime:
914 if self.__byTime:
918 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
915 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
919 datatime, *args)
916 datatime, *args)
920 else:
917 else:
921 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
918 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
922
919
923 if not self.__dataReady:
920 if not self.__dataReady:
924 return None, None, None, None
921 return None, None, None, None
925
922
926 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
923 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
927
924
928 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
925 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
929 if n == 1:
926 if n == 1:
930 return
927 return
931
928
932 dataOut.flagNoData = True
929 dataOut.flagNoData = True
933
930
934 if not self.isConfig:
931 if not self.isConfig:
935 self.setup(n, timeInterval, overlapping)
932 self.setup(n, timeInterval, overlapping)
936 self.isConfig = True
933 self.isConfig = True
937
934
938 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
935 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
939 dataOut.data_spc,
936 dataOut.data_spc,
940 dataOut.data_cspc,
937 dataOut.data_cspc,
941 dataOut.data_dc)
938 dataOut.data_dc)
942
939
943 if self.__dataReady:
940 if self.__dataReady:
944
941
945 dataOut.data_spc = avgdata_spc
942 dataOut.data_spc = avgdata_spc
946 dataOut.data_cspc = avgdata_cspc
943 dataOut.data_cspc = avgdata_cspc
947 dataOut.data_dc = avgdata_dc
944 dataOut.data_dc = avgdata_dc
948
945
949 dataOut.nIncohInt *= self.n
946 dataOut.nIncohInt *= self.n
950 dataOut.utctime = avgdatatime
947 dataOut.utctime = avgdatatime
951 dataOut.flagNoData = False
948 dataOut.flagNoData = False
@@ -1,761 +1,754
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import Spectra
4 from schainpy.model.data.jrodata import Spectra
5 from schainpy.model.data.jrodata import hildebrand_sekhon
5 from schainpy.model.data.jrodata import hildebrand_sekhon
6
6
7 class SpectraAFCProc(ProcessingUnit):
7 class SpectraAFCProc(ProcessingUnit):
8
8
9 def __init__(self, **kwargs):
9 def __init__(self, **kwargs):
10
10
11 ProcessingUnit.__init__(self, **kwargs)
11 ProcessingUnit.__init__(self, **kwargs)
12
12
13 self.buffer = None
13 self.buffer = None
14 self.firstdatatime = None
14 self.firstdatatime = None
15 self.profIndex = 0
15 self.profIndex = 0
16 self.dataOut = Spectra()
16 self.dataOut = Spectra()
17 self.id_min = None
17 self.id_min = None
18 self.id_max = None
18 self.id_max = None
19
19
20 def __updateSpecFromVoltage(self):
20 def __updateSpecFromVoltage(self):
21
21
22 self.dataOut.plotting = "spectra_acf"
22 self.dataOut.plotting = "spectra_acf"
23
23
24 self.dataOut.timeZone = self.dataIn.timeZone
24 self.dataOut.timeZone = self.dataIn.timeZone
25 self.dataOut.dstFlag = self.dataIn.dstFlag
25 self.dataOut.dstFlag = self.dataIn.dstFlag
26 self.dataOut.errorCount = self.dataIn.errorCount
26 self.dataOut.errorCount = self.dataIn.errorCount
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
28
28
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
31 self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15
31 self.dataOut.ippSeconds = self.dataIn.getDeltaH()*(10**-6)/0.15
32
32
33 self.dataOut.channelList = self.dataIn.channelList
33 self.dataOut.channelList = self.dataIn.channelList
34 self.dataOut.heightList = self.dataIn.heightList
34 self.dataOut.heightList = self.dataIn.heightList
35 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
35 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
36
36
37 self.dataOut.nBaud = self.dataIn.nBaud
37 self.dataOut.nBaud = self.dataIn.nBaud
38 self.dataOut.nCode = self.dataIn.nCode
38 self.dataOut.nCode = self.dataIn.nCode
39 self.dataOut.code = self.dataIn.code
39 self.dataOut.code = self.dataIn.code
40 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
40 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
41
41
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
42 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
43 self.dataOut.utctime = self.firstdatatime
43 self.dataOut.utctime = self.firstdatatime
44 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
44 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
45 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
45 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
46 self.dataOut.flagShiftFFT = False
46 self.dataOut.flagShiftFFT = False
47
47
48 self.dataOut.nCohInt = self.dataIn.nCohInt
48 self.dataOut.nCohInt = self.dataIn.nCohInt
49 self.dataOut.nIncohInt = 1
49 self.dataOut.nIncohInt = 1
50
50
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
51 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
52
52
53 self.dataOut.frequency = self.dataIn.frequency
53 self.dataOut.frequency = self.dataIn.frequency
54 self.dataOut.realtime = self.dataIn.realtime
54 self.dataOut.realtime = self.dataIn.realtime
55
55
56 self.dataOut.azimuth = self.dataIn.azimuth
56 self.dataOut.azimuth = self.dataIn.azimuth
57 self.dataOut.zenith = self.dataIn.zenith
57 self.dataOut.zenith = self.dataIn.zenith
58
58
59 self.dataOut.beam.codeList = self.dataIn.beam.codeList
59 self.dataOut.beam.codeList = self.dataIn.beam.codeList
60 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
60 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
61 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
61 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
62
62
63 def __decodeData(self, nProfiles, code):
63 def __decodeData(self, nProfiles, code):
64
64
65 if code is None:
65 if code is None:
66 return
66 return
67
67
68 for i in range(nProfiles):
68 for i in range(nProfiles):
69 self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i]
69 self.buffer[:,i,:] = self.buffer[:,i,:]*code[0][i]
70
70
71 def __getFft(self):
71 def __getFft(self):
72 """
72 """
73 Convierte valores de Voltaje a Spectra
73 Convierte valores de Voltaje a Spectra
74
74
75 Affected:
75 Affected:
76 self.dataOut.data_spc
76 self.dataOut.data_spc
77 self.dataOut.data_cspc
77 self.dataOut.data_cspc
78 self.dataOut.data_dc
78 self.dataOut.data_dc
79 self.dataOut.heightList
79 self.dataOut.heightList
80 self.profIndex
80 self.profIndex
81 self.buffer
81 self.buffer
82 self.dataOut.flagNoData
82 self.dataOut.flagNoData
83 """
83 """
84 nsegments = self.dataOut.nHeights
84 nsegments = self.dataOut.nHeights
85
85
86 _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex')
86 _fft_buffer = numpy.zeros((self.dataOut.nChannels, self.dataOut.nProfiles, nsegments), dtype='complex')
87
87
88 for i in range(nsegments):
88 for i in range(nsegments):
89 try:
89 try:
90 _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles]
90 _fft_buffer[:,:,i] = self.buffer[:,i:i+self.dataOut.nProfiles]
91
91
92 if self.code is not None:
92 if self.code is not None:
93 _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0]
93 _fft_buffer[:,:,i] = _fft_buffer[:,:,i]*self.code[0]
94 except:
94 except:
95 pass
95 pass
96
96
97 fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1)
97 fft_volt = numpy.fft.fft(_fft_buffer, n=self.dataOut.nFFTPoints, axis=1)
98 fft_volt = fft_volt.astype(numpy.dtype('complex'))
98 fft_volt = fft_volt.astype(numpy.dtype('complex'))
99 dc = fft_volt[:,0,:]
99 dc = fft_volt[:,0,:]
100
100
101 #calculo de self-spectra
101 #calculo de self-spectra
102 spc = fft_volt * numpy.conjugate(fft_volt)
102 spc = fft_volt * numpy.conjugate(fft_volt)
103 data = numpy.fft.ifft(spc, axis=1)
103 data = numpy.fft.ifft(spc, axis=1)
104 data = numpy.fft.fftshift(data, axes=(1,))
104 data = numpy.fft.fftshift(data, axes=(1,))
105
105
106 spc = data
106 spc = data
107
107
108 blocksize = 0
108 blocksize = 0
109 blocksize += dc.size
109 blocksize += dc.size
110 blocksize += spc.size
110 blocksize += spc.size
111
111
112 cspc = None
112 cspc = None
113 pairIndex = 0
113 pairIndex = 0
114
114
115 if self.dataOut.pairsList != None:
115 if self.dataOut.pairsList != None:
116 #calculo de cross-spectra
116 #calculo de cross-spectra
117 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
117 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
118 for pair in self.dataOut.pairsList:
118 for pair in self.dataOut.pairsList:
119 if pair[0] not in self.dataOut.channelList:
119 if pair[0] not in self.dataOut.channelList:
120 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
120 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
121 if pair[1] not in self.dataOut.channelList:
121 if pair[1] not in self.dataOut.channelList:
122 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
122 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
123
123
124 chan_index0 = self.dataOut.channelList.index(pair[0])
124 chan_index0 = self.dataOut.channelList.index(pair[0])
125 chan_index1 = self.dataOut.channelList.index(pair[1])
125 chan_index1 = self.dataOut.channelList.index(pair[1])
126
126
127 cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:])
127 cspc[pairIndex,:,:] = fft_volt[chan_index0,:,:] * numpy.conjugate(fft_volt[chan_index1,:,:])
128 pairIndex += 1
128 pairIndex += 1
129 blocksize += cspc.size
129 blocksize += cspc.size
130
130
131 self.dataOut.data_spc = spc
131 self.dataOut.data_spc = spc
132 self.dataOut.data_cspc = cspc
132 self.dataOut.data_cspc = cspc
133 self.dataOut.data_dc = dc
133 self.dataOut.data_dc = dc
134 self.dataOut.blockSize = blocksize
134 self.dataOut.blockSize = blocksize
135 self.dataOut.flagShiftFFT = True
135 self.dataOut.flagShiftFFT = True
136
136
137 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1):
137 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], code=None, nCode=1, nBaud=1,real= None, imag=None):
138
138
139 self.dataOut.flagNoData = True
139 self.dataOut.flagNoData = True
140
140
141 if self.dataIn.type == "Spectra":
141 if self.dataIn.type == "Spectra":
142 self.dataOut.copy(self.dataIn)
142 self.dataOut.copy(self.dataIn)
143 #print "hi",self.dataOut.ippSeconds
143 spc = self.dataOut.data_spc
144
144 data = numpy.fft.ifft(spc, axis=1)
145 spc = self.dataOut.data_spc
145 data = numpy.fft.fftshift(data, axes=(1,))
146 data = numpy.fft.ifft(spc, axis=1)
146 acf = numpy.abs(data) # Autocorrelacion LLAMAR A ESTE VALOR ACF
147 data = numpy.fft.fftshift(data, axes=(1,))
147 if real:
148 acf = numpy.abs(data) # Autocorrelacion LLAMAR A ESTE VALOR ACF
148 acf = data.real
149 #acf = data.imag
149 if imag:
150 shape = acf.shape #nchannels, nprofiles, nsamples
150 acf = data.imag
151
151 shape = acf.shape # nchannels, nprofiles, nsamples
152 #import matplotlib.pyplot as plt
153 #plt.plot(acf[0,:,0] / numpy.max(numpy.abs(acf[0,:,0])))
154 #plt.show()
155
152
156 # Normalizando
153 # Normalizando
157 for i in range(shape[0]):
154 for i in range(shape[0]):
158 for j in range(shape[2]):
155 for j in range(shape[2]):
159 acf[i,:,j]= acf[i,:,j] / numpy.max(numpy.abs(acf[i,:,j]))
156 acf[i,:,j]= acf[i,:,j] / numpy.max(numpy.abs(acf[i,:,j]))
160
157
161 #import matplotlib.pyplot as plt
162 #plt.plot(acf[0,:,0])
163 #plt.show()
164
165 self.dataOut.data_acf = acf
158 self.dataOut.data_acf = acf
166 return True
159 return True
167
160
168 if code is not None:
161 if code is not None:
169 self.code = numpy.array(code).reshape(nCode,nBaud)
162 self.code = numpy.array(code).reshape(nCode,nBaud)
170 else:
163 else:
171 self.code = None
164 self.code = None
172
165
173 if self.dataIn.type == "Voltage":
166 if self.dataIn.type == "Voltage":
174
167
175 if nFFTPoints == None:
168 if nFFTPoints == None:
176 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
169 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
177
170
178 if nProfiles == None:
171 if nProfiles == None:
179 nProfiles = nFFTPoints
172 nProfiles = nFFTPoints
180
173
181 self.dataOut.ippFactor = 1
174 self.dataOut.ippFactor = 1
182
175
183 self.dataOut.nFFTPoints = nFFTPoints
176 self.dataOut.nFFTPoints = nFFTPoints
184 self.dataOut.nProfiles = nProfiles
177 self.dataOut.nProfiles = nProfiles
185 self.dataOut.pairsList = pairsList
178 self.dataOut.pairsList = pairsList
186
179
187 # if self.buffer is None:
180 # if self.buffer is None:
188 # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights),
181 # self.buffer = numpy.zeros( (self.dataIn.nChannels, nProfiles, self.dataIn.nHeights),
189 # dtype='complex')
182 # dtype='complex')
190
183
191 if not self.dataIn.flagDataAsBlock:
184 if not self.dataIn.flagDataAsBlock:
192 self.buffer = self.dataIn.data.copy()
185 self.buffer = self.dataIn.data.copy()
193
186
194 # for i in range(self.dataIn.nHeights):
187 # for i in range(self.dataIn.nHeights):
195 # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex]
188 # self.buffer[:, self.profIndex, self.profIndex:] = voltage_data[:,:self.dataIn.nHeights - self.profIndex]
196 #
189 #
197 # self.profIndex += 1
190 # self.profIndex += 1
198
191
199 else:
192 else:
200 raise ValueError, ""
193 raise ValueError, ""
201
194
202 self.firstdatatime = self.dataIn.utctime
195 self.firstdatatime = self.dataIn.utctime
203
196
204 self.profIndex == nProfiles
197 self.profIndex == nProfiles
205
198
206 self.__updateSpecFromVoltage()
199 self.__updateSpecFromVoltage()
207
200
208 self.__getFft()
201 self.__getFft()
209
202
210 self.dataOut.flagNoData = False
203 self.dataOut.flagNoData = False
211
204
212 return True
205 return True
213
206
214 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
207 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
215
208
216 def __selectPairs(self, pairsList):
209 def __selectPairs(self, pairsList):
217
210
218 if channelList == None:
211 if channelList == None:
219 return
212 return
220
213
221 pairsIndexListSelected = []
214 pairsIndexListSelected = []
222
215
223 for thisPair in pairsList:
216 for thisPair in pairsList:
224
217
225 if thisPair not in self.dataOut.pairsList:
218 if thisPair not in self.dataOut.pairsList:
226 continue
219 continue
227
220
228 pairIndex = self.dataOut.pairsList.index(thisPair)
221 pairIndex = self.dataOut.pairsList.index(thisPair)
229
222
230 pairsIndexListSelected.append(pairIndex)
223 pairsIndexListSelected.append(pairIndex)
231
224
232 if not pairsIndexListSelected:
225 if not pairsIndexListSelected:
233 self.dataOut.data_cspc = None
226 self.dataOut.data_cspc = None
234 self.dataOut.pairsList = []
227 self.dataOut.pairsList = []
235 return
228 return
236
229
237 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
230 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
238 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
231 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
239
232
240 return
233 return
241
234
242 def __selectPairsByChannel(self, channelList=None):
235 def __selectPairsByChannel(self, channelList=None):
243
236
244 if channelList == None:
237 if channelList == None:
245 return
238 return
246
239
247 pairsIndexListSelected = []
240 pairsIndexListSelected = []
248 for pairIndex in self.dataOut.pairsIndexList:
241 for pairIndex in self.dataOut.pairsIndexList:
249 #First pair
242 #First pair
250 if self.dataOut.pairsList[pairIndex][0] not in channelList:
243 if self.dataOut.pairsList[pairIndex][0] not in channelList:
251 continue
244 continue
252 #Second pair
245 #Second pair
253 if self.dataOut.pairsList[pairIndex][1] not in channelList:
246 if self.dataOut.pairsList[pairIndex][1] not in channelList:
254 continue
247 continue
255
248
256 pairsIndexListSelected.append(pairIndex)
249 pairsIndexListSelected.append(pairIndex)
257
250
258 if not pairsIndexListSelected:
251 if not pairsIndexListSelected:
259 self.dataOut.data_cspc = None
252 self.dataOut.data_cspc = None
260 self.dataOut.pairsList = []
253 self.dataOut.pairsList = []
261 return
254 return
262
255
263 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
256 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
264 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
257 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
265
258
266 return
259 return
267
260
268 def selectChannels(self, channelList):
261 def selectChannels(self, channelList):
269
262
270 channelIndexList = []
263 channelIndexList = []
271
264
272 for channel in channelList:
265 for channel in channelList:
273 if channel not in self.dataOut.channelList:
266 if channel not in self.dataOut.channelList:
274 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
267 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
275
268
276 index = self.dataOut.channelList.index(channel)
269 index = self.dataOut.channelList.index(channel)
277 channelIndexList.append(index)
270 channelIndexList.append(index)
278
271
279 self.selectChannelsByIndex(channelIndexList)
272 self.selectChannelsByIndex(channelIndexList)
280
273
281 def selectChannelsByIndex(self, channelIndexList):
274 def selectChannelsByIndex(self, channelIndexList):
282 """
275 """
283 Selecciona un bloque de datos en base a canales segun el channelIndexList
276 Selecciona un bloque de datos en base a canales segun el channelIndexList
284
277
285 Input:
278 Input:
286 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
279 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
287
280
288 Affected:
281 Affected:
289 self.dataOut.data_spc
282 self.dataOut.data_spc
290 self.dataOut.channelIndexList
283 self.dataOut.channelIndexList
291 self.dataOut.nChannels
284 self.dataOut.nChannels
292
285
293 Return:
286 Return:
294 None
287 None
295 """
288 """
296
289
297 for channelIndex in channelIndexList:
290 for channelIndex in channelIndexList:
298 if channelIndex not in self.dataOut.channelIndexList:
291 if channelIndex not in self.dataOut.channelIndexList:
299 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
292 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
300
293
301 # nChannels = len(channelIndexList)
294 # nChannels = len(channelIndexList)
302
295
303 data_spc = self.dataOut.data_spc[channelIndexList,:]
296 data_spc = self.dataOut.data_spc[channelIndexList,:]
304 data_dc = self.dataOut.data_dc[channelIndexList,:]
297 data_dc = self.dataOut.data_dc[channelIndexList,:]
305
298
306 self.dataOut.data_spc = data_spc
299 self.dataOut.data_spc = data_spc
307 self.dataOut.data_dc = data_dc
300 self.dataOut.data_dc = data_dc
308
301
309 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
302 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
310 # self.dataOut.nChannels = nChannels
303 # self.dataOut.nChannels = nChannels
311
304
312 self.__selectPairsByChannel(self.dataOut.channelList)
305 self.__selectPairsByChannel(self.dataOut.channelList)
313
306
314 return 1
307 return 1
315
308
316 def selectHeights(self, minHei, maxHei):
309 def selectHeights(self, minHei, maxHei):
317 """
310 """
318 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
311 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
319 minHei <= height <= maxHei
312 minHei <= height <= maxHei
320
313
321 Input:
314 Input:
322 minHei : valor minimo de altura a considerar
315 minHei : valor minimo de altura a considerar
323 maxHei : valor maximo de altura a considerar
316 maxHei : valor maximo de altura a considerar
324
317
325 Affected:
318 Affected:
326 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
319 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
327
320
328 Return:
321 Return:
329 1 si el metodo se ejecuto con exito caso contrario devuelve 0
322 1 si el metodo se ejecuto con exito caso contrario devuelve 0
330 """
323 """
331
324
332 if (minHei > maxHei):
325 if (minHei > maxHei):
333 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
326 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
334
327
335 if (minHei < self.dataOut.heightList[0]):
328 if (minHei < self.dataOut.heightList[0]):
336 minHei = self.dataOut.heightList[0]
329 minHei = self.dataOut.heightList[0]
337
330
338 if (maxHei > self.dataOut.heightList[-1]):
331 if (maxHei > self.dataOut.heightList[-1]):
339 maxHei = self.dataOut.heightList[-1]
332 maxHei = self.dataOut.heightList[-1]
340
333
341 minIndex = 0
334 minIndex = 0
342 maxIndex = 0
335 maxIndex = 0
343 heights = self.dataOut.heightList
336 heights = self.dataOut.heightList
344
337
345 inda = numpy.where(heights >= minHei)
338 inda = numpy.where(heights >= minHei)
346 indb = numpy.where(heights <= maxHei)
339 indb = numpy.where(heights <= maxHei)
347
340
348 try:
341 try:
349 minIndex = inda[0][0]
342 minIndex = inda[0][0]
350 except:
343 except:
351 minIndex = 0
344 minIndex = 0
352
345
353 try:
346 try:
354 maxIndex = indb[0][-1]
347 maxIndex = indb[0][-1]
355 except:
348 except:
356 maxIndex = len(heights)
349 maxIndex = len(heights)
357
350
358 self.selectHeightsByIndex(minIndex, maxIndex)
351 self.selectHeightsByIndex(minIndex, maxIndex)
359
352
360 return 1
353 return 1
361
354
362 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
355 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
363 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
356 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
364
357
365 if hei_ref != None:
358 if hei_ref != None:
366 newheis = numpy.where(self.dataOut.heightList>hei_ref)
359 newheis = numpy.where(self.dataOut.heightList>hei_ref)
367
360
368 minIndex = min(newheis[0])
361 minIndex = min(newheis[0])
369 maxIndex = max(newheis[0])
362 maxIndex = max(newheis[0])
370 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
363 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
371 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
364 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
372
365
373 # determina indices
366 # determina indices
374 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
367 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
375 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
368 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
376 beacon_dB = numpy.sort(avg_dB)[-nheis:]
369 beacon_dB = numpy.sort(avg_dB)[-nheis:]
377 beacon_heiIndexList = []
370 beacon_heiIndexList = []
378 for val in avg_dB.tolist():
371 for val in avg_dB.tolist():
379 if val >= beacon_dB[0]:
372 if val >= beacon_dB[0]:
380 beacon_heiIndexList.append(avg_dB.tolist().index(val))
373 beacon_heiIndexList.append(avg_dB.tolist().index(val))
381
374
382 #data_spc = data_spc[:,:,beacon_heiIndexList]
375 #data_spc = data_spc[:,:,beacon_heiIndexList]
383 data_cspc = None
376 data_cspc = None
384 if self.dataOut.data_cspc is not None:
377 if self.dataOut.data_cspc is not None:
385 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
378 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
386 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
379 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
387
380
388 data_dc = None
381 data_dc = None
389 if self.dataOut.data_dc is not None:
382 if self.dataOut.data_dc is not None:
390 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
383 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
391 #data_dc = data_dc[:,beacon_heiIndexList]
384 #data_dc = data_dc[:,beacon_heiIndexList]
392
385
393 self.dataOut.data_spc = data_spc
386 self.dataOut.data_spc = data_spc
394 self.dataOut.data_cspc = data_cspc
387 self.dataOut.data_cspc = data_cspc
395 self.dataOut.data_dc = data_dc
388 self.dataOut.data_dc = data_dc
396 self.dataOut.heightList = heightList
389 self.dataOut.heightList = heightList
397 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
390 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
398
391
399 return 1
392 return 1
400
393
401
394
402 def selectHeightsByIndex(self, minIndex, maxIndex):
395 def selectHeightsByIndex(self, minIndex, maxIndex):
403 """
396 """
404 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
397 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
405 minIndex <= index <= maxIndex
398 minIndex <= index <= maxIndex
406
399
407 Input:
400 Input:
408 minIndex : valor de indice minimo de altura a considerar
401 minIndex : valor de indice minimo de altura a considerar
409 maxIndex : valor de indice maximo de altura a considerar
402 maxIndex : valor de indice maximo de altura a considerar
410
403
411 Affected:
404 Affected:
412 self.dataOut.data_spc
405 self.dataOut.data_spc
413 self.dataOut.data_cspc
406 self.dataOut.data_cspc
414 self.dataOut.data_dc
407 self.dataOut.data_dc
415 self.dataOut.heightList
408 self.dataOut.heightList
416
409
417 Return:
410 Return:
418 1 si el metodo se ejecuto con exito caso contrario devuelve 0
411 1 si el metodo se ejecuto con exito caso contrario devuelve 0
419 """
412 """
420
413
421 if (minIndex < 0) or (minIndex > maxIndex):
414 if (minIndex < 0) or (minIndex > maxIndex):
422 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
415 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
423
416
424 if (maxIndex >= self.dataOut.nHeights):
417 if (maxIndex >= self.dataOut.nHeights):
425 maxIndex = self.dataOut.nHeights-1
418 maxIndex = self.dataOut.nHeights-1
426
419
427 #Spectra
420 #Spectra
428 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
421 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
429
422
430 data_cspc = None
423 data_cspc = None
431 if self.dataOut.data_cspc is not None:
424 if self.dataOut.data_cspc is not None:
432 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
425 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
433
426
434 data_dc = None
427 data_dc = None
435 if self.dataOut.data_dc is not None:
428 if self.dataOut.data_dc is not None:
436 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
429 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
437
430
438 self.dataOut.data_spc = data_spc
431 self.dataOut.data_spc = data_spc
439 self.dataOut.data_cspc = data_cspc
432 self.dataOut.data_cspc = data_cspc
440 self.dataOut.data_dc = data_dc
433 self.dataOut.data_dc = data_dc
441
434
442 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
435 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
443
436
444 return 1
437 return 1
445
438
446 def removeDC(self, mode = 2):
439 def removeDC(self, mode = 2):
447 jspectra = self.dataOut.data_spc
440 jspectra = self.dataOut.data_spc
448 jcspectra = self.dataOut.data_cspc
441 jcspectra = self.dataOut.data_cspc
449
442
450
443
451 num_chan = jspectra.shape[0]
444 num_chan = jspectra.shape[0]
452 num_hei = jspectra.shape[2]
445 num_hei = jspectra.shape[2]
453
446
454 if jcspectra is not None:
447 if jcspectra is not None:
455 jcspectraExist = True
448 jcspectraExist = True
456 num_pairs = jcspectra.shape[0]
449 num_pairs = jcspectra.shape[0]
457 else: jcspectraExist = False
450 else: jcspectraExist = False
458
451
459 freq_dc = jspectra.shape[1]/2
452 freq_dc = jspectra.shape[1]/2
460 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
453 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
461
454
462 if ind_vel[0]<0:
455 if ind_vel[0]<0:
463 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
456 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
464
457
465 if mode == 1:
458 if mode == 1:
466 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
459 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
467
460
468 if jcspectraExist:
461 if jcspectraExist:
469 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
462 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
470
463
471 if mode == 2:
464 if mode == 2:
472
465
473 vel = numpy.array([-2,-1,1,2])
466 vel = numpy.array([-2,-1,1,2])
474 xx = numpy.zeros([4,4])
467 xx = numpy.zeros([4,4])
475
468
476 for fil in range(4):
469 for fil in range(4):
477 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
470 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
478
471
479 xx_inv = numpy.linalg.inv(xx)
472 xx_inv = numpy.linalg.inv(xx)
480 xx_aux = xx_inv[0,:]
473 xx_aux = xx_inv[0,:]
481
474
482 for ich in range(num_chan):
475 for ich in range(num_chan):
483 yy = jspectra[ich,ind_vel,:]
476 yy = jspectra[ich,ind_vel,:]
484 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
477 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
485
478
486 junkid = jspectra[ich,freq_dc,:]<=0
479 junkid = jspectra[ich,freq_dc,:]<=0
487 cjunkid = sum(junkid)
480 cjunkid = sum(junkid)
488
481
489 if cjunkid.any():
482 if cjunkid.any():
490 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
483 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
491
484
492 if jcspectraExist:
485 if jcspectraExist:
493 for ip in range(num_pairs):
486 for ip in range(num_pairs):
494 yy = jcspectra[ip,ind_vel,:]
487 yy = jcspectra[ip,ind_vel,:]
495 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
488 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
496
489
497
490
498 self.dataOut.data_spc = jspectra
491 self.dataOut.data_spc = jspectra
499 self.dataOut.data_cspc = jcspectra
492 self.dataOut.data_cspc = jcspectra
500
493
501 return 1
494 return 1
502
495
503 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
496 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
504
497
505 jspectra = self.dataOut.data_spc
498 jspectra = self.dataOut.data_spc
506 jcspectra = self.dataOut.data_cspc
499 jcspectra = self.dataOut.data_cspc
507 jnoise = self.dataOut.getNoise()
500 jnoise = self.dataOut.getNoise()
508 num_incoh = self.dataOut.nIncohInt
501 num_incoh = self.dataOut.nIncohInt
509
502
510 num_channel = jspectra.shape[0]
503 num_channel = jspectra.shape[0]
511 num_prof = jspectra.shape[1]
504 num_prof = jspectra.shape[1]
512 num_hei = jspectra.shape[2]
505 num_hei = jspectra.shape[2]
513
506
514 #hei_interf
507 #hei_interf
515 if hei_interf is None:
508 if hei_interf is None:
516 count_hei = num_hei/2 #Como es entero no importa
509 count_hei = num_hei/2 #Como es entero no importa
517 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
510 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
518 hei_interf = numpy.asarray(hei_interf)[0]
511 hei_interf = numpy.asarray(hei_interf)[0]
519 #nhei_interf
512 #nhei_interf
520 if (nhei_interf == None):
513 if (nhei_interf == None):
521 nhei_interf = 5
514 nhei_interf = 5
522 if (nhei_interf < 1):
515 if (nhei_interf < 1):
523 nhei_interf = 1
516 nhei_interf = 1
524 if (nhei_interf > count_hei):
517 if (nhei_interf > count_hei):
525 nhei_interf = count_hei
518 nhei_interf = count_hei
526 if (offhei_interf == None):
519 if (offhei_interf == None):
527 offhei_interf = 0
520 offhei_interf = 0
528
521
529 ind_hei = range(num_hei)
522 ind_hei = range(num_hei)
530 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
523 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
531 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
524 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
532 mask_prof = numpy.asarray(range(num_prof))
525 mask_prof = numpy.asarray(range(num_prof))
533 num_mask_prof = mask_prof.size
526 num_mask_prof = mask_prof.size
534 comp_mask_prof = [0, num_prof/2]
527 comp_mask_prof = [0, num_prof/2]
535
528
536
529
537 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
530 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
538 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
531 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
539 jnoise = numpy.nan
532 jnoise = numpy.nan
540 noise_exist = jnoise[0] < numpy.Inf
533 noise_exist = jnoise[0] < numpy.Inf
541
534
542 #Subrutina de Remocion de la Interferencia
535 #Subrutina de Remocion de la Interferencia
543 for ich in range(num_channel):
536 for ich in range(num_channel):
544 #Se ordena los espectros segun su potencia (menor a mayor)
537 #Se ordena los espectros segun su potencia (menor a mayor)
545 power = jspectra[ich,mask_prof,:]
538 power = jspectra[ich,mask_prof,:]
546 power = power[:,hei_interf]
539 power = power[:,hei_interf]
547 power = power.sum(axis = 0)
540 power = power.sum(axis = 0)
548 psort = power.ravel().argsort()
541 psort = power.ravel().argsort()
549
542
550 #Se estima la interferencia promedio en los Espectros de Potencia empleando
543 #Se estima la interferencia promedio en los Espectros de Potencia empleando
551 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
544 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
552
545
553 if noise_exist:
546 if noise_exist:
554 # tmp_noise = jnoise[ich] / num_prof
547 # tmp_noise = jnoise[ich] / num_prof
555 tmp_noise = jnoise[ich]
548 tmp_noise = jnoise[ich]
556 junkspc_interf = junkspc_interf - tmp_noise
549 junkspc_interf = junkspc_interf - tmp_noise
557 #junkspc_interf[:,comp_mask_prof] = 0
550 #junkspc_interf[:,comp_mask_prof] = 0
558
551
559 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
552 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
560 jspc_interf = jspc_interf.transpose()
553 jspc_interf = jspc_interf.transpose()
561 #Calculando el espectro de interferencia promedio
554 #Calculando el espectro de interferencia promedio
562 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
555 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
563 noiseid = noiseid[0]
556 noiseid = noiseid[0]
564 cnoiseid = noiseid.size
557 cnoiseid = noiseid.size
565 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
558 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
566 interfid = interfid[0]
559 interfid = interfid[0]
567 cinterfid = interfid.size
560 cinterfid = interfid.size
568
561
569 if (cnoiseid > 0): jspc_interf[noiseid] = 0
562 if (cnoiseid > 0): jspc_interf[noiseid] = 0
570
563
571 #Expandiendo los perfiles a limpiar
564 #Expandiendo los perfiles a limpiar
572 if (cinterfid > 0):
565 if (cinterfid > 0):
573 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
566 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
574 new_interfid = numpy.asarray(new_interfid)
567 new_interfid = numpy.asarray(new_interfid)
575 new_interfid = {x for x in new_interfid}
568 new_interfid = {x for x in new_interfid}
576 new_interfid = numpy.array(list(new_interfid))
569 new_interfid = numpy.array(list(new_interfid))
577 new_cinterfid = new_interfid.size
570 new_cinterfid = new_interfid.size
578 else: new_cinterfid = 0
571 else: new_cinterfid = 0
579
572
580 for ip in range(new_cinterfid):
573 for ip in range(new_cinterfid):
581 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
574 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
582 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
575 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
583
576
584
577
585 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
578 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
586
579
587 #Removiendo la interferencia del punto de mayor interferencia
580 #Removiendo la interferencia del punto de mayor interferencia
588 ListAux = jspc_interf[mask_prof].tolist()
581 ListAux = jspc_interf[mask_prof].tolist()
589 maxid = ListAux.index(max(ListAux))
582 maxid = ListAux.index(max(ListAux))
590
583
591
584
592 if cinterfid > 0:
585 if cinterfid > 0:
593 for ip in range(cinterfid*(interf == 2) - 1):
586 for ip in range(cinterfid*(interf == 2) - 1):
594 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
587 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
595 cind = len(ind)
588 cind = len(ind)
596
589
597 if (cind > 0):
590 if (cind > 0):
598 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
591 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
599
592
600 ind = numpy.array([-2,-1,1,2])
593 ind = numpy.array([-2,-1,1,2])
601 xx = numpy.zeros([4,4])
594 xx = numpy.zeros([4,4])
602
595
603 for id1 in range(4):
596 for id1 in range(4):
604 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
597 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
605
598
606 xx_inv = numpy.linalg.inv(xx)
599 xx_inv = numpy.linalg.inv(xx)
607 xx = xx_inv[:,0]
600 xx = xx_inv[:,0]
608 ind = (ind + maxid + num_mask_prof)%num_mask_prof
601 ind = (ind + maxid + num_mask_prof)%num_mask_prof
609 yy = jspectra[ich,mask_prof[ind],:]
602 yy = jspectra[ich,mask_prof[ind],:]
610 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
603 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
611
604
612
605
613 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
606 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
614 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
607 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
615
608
616 #Remocion de Interferencia en el Cross Spectra
609 #Remocion de Interferencia en el Cross Spectra
617 if jcspectra is None: return jspectra, jcspectra
610 if jcspectra is None: return jspectra, jcspectra
618 num_pairs = jcspectra.size/(num_prof*num_hei)
611 num_pairs = jcspectra.size/(num_prof*num_hei)
619 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
612 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
620
613
621 for ip in range(num_pairs):
614 for ip in range(num_pairs):
622
615
623 #-------------------------------------------
616 #-------------------------------------------
624
617
625 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
618 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
626 cspower = cspower[:,hei_interf]
619 cspower = cspower[:,hei_interf]
627 cspower = cspower.sum(axis = 0)
620 cspower = cspower.sum(axis = 0)
628
621
629 cspsort = cspower.ravel().argsort()
622 cspsort = cspower.ravel().argsort()
630 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
623 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
631 junkcspc_interf = junkcspc_interf.transpose()
624 junkcspc_interf = junkcspc_interf.transpose()
632 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
625 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
633
626
634 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
627 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
635
628
636 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
629 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
637 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
630 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
638 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
631 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
639
632
640 for iprof in range(num_prof):
633 for iprof in range(num_prof):
641 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
634 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
642 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
635 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
643
636
644 #Removiendo la Interferencia
637 #Removiendo la Interferencia
645 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
638 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
646
639
647 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
640 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
648 maxid = ListAux.index(max(ListAux))
641 maxid = ListAux.index(max(ListAux))
649
642
650 ind = numpy.array([-2,-1,1,2])
643 ind = numpy.array([-2,-1,1,2])
651 xx = numpy.zeros([4,4])
644 xx = numpy.zeros([4,4])
652
645
653 for id1 in range(4):
646 for id1 in range(4):
654 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
647 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
655
648
656 xx_inv = numpy.linalg.inv(xx)
649 xx_inv = numpy.linalg.inv(xx)
657 xx = xx_inv[:,0]
650 xx = xx_inv[:,0]
658
651
659 ind = (ind + maxid + num_mask_prof)%num_mask_prof
652 ind = (ind + maxid + num_mask_prof)%num_mask_prof
660 yy = jcspectra[ip,mask_prof[ind],:]
653 yy = jcspectra[ip,mask_prof[ind],:]
661 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
654 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
662
655
663 #Guardar Resultados
656 #Guardar Resultados
664 self.dataOut.data_spc = jspectra
657 self.dataOut.data_spc = jspectra
665 self.dataOut.data_cspc = jcspectra
658 self.dataOut.data_cspc = jcspectra
666
659
667 return 1
660 return 1
668
661
669 def setRadarFrequency(self, frequency=None):
662 def setRadarFrequency(self, frequency=None):
670
663
671 if frequency != None:
664 if frequency != None:
672 self.dataOut.frequency = frequency
665 self.dataOut.frequency = frequency
673
666
674 return 1
667 return 1
675
668
676 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
669 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
677 #validacion de rango
670 #validacion de rango
678 if minHei == None:
671 if minHei == None:
679 minHei = self.dataOut.heightList[0]
672 minHei = self.dataOut.heightList[0]
680
673
681 if maxHei == None:
674 if maxHei == None:
682 maxHei = self.dataOut.heightList[-1]
675 maxHei = self.dataOut.heightList[-1]
683
676
684 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
677 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
685 print 'minHei: %.2f is out of the heights range'%(minHei)
678 print 'minHei: %.2f is out of the heights range'%(minHei)
686 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
679 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
687 minHei = self.dataOut.heightList[0]
680 minHei = self.dataOut.heightList[0]
688
681
689 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
682 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
690 print 'maxHei: %.2f is out of the heights range'%(maxHei)
683 print 'maxHei: %.2f is out of the heights range'%(maxHei)
691 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
684 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
692 maxHei = self.dataOut.heightList[-1]
685 maxHei = self.dataOut.heightList[-1]
693
686
694 # validacion de velocidades
687 # validacion de velocidades
695 velrange = self.dataOut.getVelRange(1)
688 velrange = self.dataOut.getVelRange(1)
696
689
697 if minVel == None:
690 if minVel == None:
698 minVel = velrange[0]
691 minVel = velrange[0]
699
692
700 if maxVel == None:
693 if maxVel == None:
701 maxVel = velrange[-1]
694 maxVel = velrange[-1]
702
695
703 if (minVel < velrange[0]) or (minVel > maxVel):
696 if (minVel < velrange[0]) or (minVel > maxVel):
704 print 'minVel: %.2f is out of the velocity range'%(minVel)
697 print 'minVel: %.2f is out of the velocity range'%(minVel)
705 print 'minVel is setting to %.2f'%(velrange[0])
698 print 'minVel is setting to %.2f'%(velrange[0])
706 minVel = velrange[0]
699 minVel = velrange[0]
707
700
708 if (maxVel > velrange[-1]) or (maxVel < minVel):
701 if (maxVel > velrange[-1]) or (maxVel < minVel):
709 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
702 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
710 print 'maxVel is setting to %.2f'%(velrange[-1])
703 print 'maxVel is setting to %.2f'%(velrange[-1])
711 maxVel = velrange[-1]
704 maxVel = velrange[-1]
712
705
713 # seleccion de indices para rango
706 # seleccion de indices para rango
714 minIndex = 0
707 minIndex = 0
715 maxIndex = 0
708 maxIndex = 0
716 heights = self.dataOut.heightList
709 heights = self.dataOut.heightList
717
710
718 inda = numpy.where(heights >= minHei)
711 inda = numpy.where(heights >= minHei)
719 indb = numpy.where(heights <= maxHei)
712 indb = numpy.where(heights <= maxHei)
720
713
721 try:
714 try:
722 minIndex = inda[0][0]
715 minIndex = inda[0][0]
723 except:
716 except:
724 minIndex = 0
717 minIndex = 0
725
718
726 try:
719 try:
727 maxIndex = indb[0][-1]
720 maxIndex = indb[0][-1]
728 except:
721 except:
729 maxIndex = len(heights)
722 maxIndex = len(heights)
730
723
731 if (minIndex < 0) or (minIndex > maxIndex):
724 if (minIndex < 0) or (minIndex > maxIndex):
732 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
725 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
733
726
734 if (maxIndex >= self.dataOut.nHeights):
727 if (maxIndex >= self.dataOut.nHeights):
735 maxIndex = self.dataOut.nHeights-1
728 maxIndex = self.dataOut.nHeights-1
736
729
737 # seleccion de indices para velocidades
730 # seleccion de indices para velocidades
738 indminvel = numpy.where(velrange >= minVel)
731 indminvel = numpy.where(velrange >= minVel)
739 indmaxvel = numpy.where(velrange <= maxVel)
732 indmaxvel = numpy.where(velrange <= maxVel)
740 try:
733 try:
741 minIndexVel = indminvel[0][0]
734 minIndexVel = indminvel[0][0]
742 except:
735 except:
743 minIndexVel = 0
736 minIndexVel = 0
744
737
745 try:
738 try:
746 maxIndexVel = indmaxvel[0][-1]
739 maxIndexVel = indmaxvel[0][-1]
747 except:
740 except:
748 maxIndexVel = len(velrange)
741 maxIndexVel = len(velrange)
749
742
750 #seleccion del espectro
743 #seleccion del espectro
751 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
744 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
752 #estimacion de ruido
745 #estimacion de ruido
753 noise = numpy.zeros(self.dataOut.nChannels)
746 noise = numpy.zeros(self.dataOut.nChannels)
754
747
755 for channel in range(self.dataOut.nChannels):
748 for channel in range(self.dataOut.nChannels):
756 daux = data_spc[channel,:,:]
749 daux = data_spc[channel,:,:]
757 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
750 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
758
751
759 self.dataOut.noise_estimation = noise.copy()
752 self.dataOut.noise_estimation = noise.copy()
760
753
761 return 1
754 return 1
@@ -1,1398 +1,1395
1 import sys
1 import sys
2 import numpy
2 import numpy
3 from scipy import interpolate
3 from scipy import interpolate
4 from schainpy import cSchain
4 from schainpy import cSchain
5 from jroproc_base import ProcessingUnit, Operation
5 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jrodata import Voltage
6 from schainpy.model.data.jrodata import Voltage
7 from time import time
7 from time import time
8
8
9 class VoltageProc(ProcessingUnit):
9 class VoltageProc(ProcessingUnit):
10
10
11
11
12 def __init__(self, **kwargs):
12 def __init__(self, **kwargs):
13
13
14 ProcessingUnit.__init__(self, **kwargs)
14 ProcessingUnit.__init__(self, **kwargs)
15
15
16 # self.objectDict = {}
16 # self.objectDict = {}
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19
19
20 def run(self):
20 def run(self):
21 if self.dataIn.type == 'AMISR':
21 if self.dataIn.type == 'AMISR':
22 self.__updateObjFromAmisrInput()
22 self.__updateObjFromAmisrInput()
23
23
24 if self.dataIn.type == 'Voltage':
24 if self.dataIn.type == 'Voltage':
25 self.dataOut.copy(self.dataIn)
25 self.dataOut.copy(self.dataIn)
26
26
27 # self.dataOut.copy(self.dataIn)
27 # self.dataOut.copy(self.dataIn)
28
28
29 def __updateObjFromAmisrInput(self):
29 def __updateObjFromAmisrInput(self):
30
30
31 self.dataOut.timeZone = self.dataIn.timeZone
31 self.dataOut.timeZone = self.dataIn.timeZone
32 self.dataOut.dstFlag = self.dataIn.dstFlag
32 self.dataOut.dstFlag = self.dataIn.dstFlag
33 self.dataOut.errorCount = self.dataIn.errorCount
33 self.dataOut.errorCount = self.dataIn.errorCount
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
34 self.dataOut.useLocalTime = self.dataIn.useLocalTime
35
35
36 self.dataOut.flagNoData = self.dataIn.flagNoData
36 self.dataOut.flagNoData = self.dataIn.flagNoData
37 self.dataOut.data = self.dataIn.data
37 self.dataOut.data = self.dataIn.data
38 self.dataOut.utctime = self.dataIn.utctime
38 self.dataOut.utctime = self.dataIn.utctime
39 self.dataOut.channelList = self.dataIn.channelList
39 self.dataOut.channelList = self.dataIn.channelList
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
40 # self.dataOut.timeInterval = self.dataIn.timeInterval
41 self.dataOut.heightList = self.dataIn.heightList
41 self.dataOut.heightList = self.dataIn.heightList
42 self.dataOut.nProfiles = self.dataIn.nProfiles
42 self.dataOut.nProfiles = self.dataIn.nProfiles
43
43
44 self.dataOut.nCohInt = self.dataIn.nCohInt
44 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
45 self.dataOut.ippSeconds = self.dataIn.ippSeconds
46 self.dataOut.frequency = self.dataIn.frequency
46 self.dataOut.frequency = self.dataIn.frequency
47
47
48 self.dataOut.azimuth = self.dataIn.azimuth
48 self.dataOut.azimuth = self.dataIn.azimuth
49 self.dataOut.zenith = self.dataIn.zenith
49 self.dataOut.zenith = self.dataIn.zenith
50
50
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
51 self.dataOut.beam.codeList = self.dataIn.beam.codeList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54 #
54 #
55 # pass#
55 # pass#
56 #
56 #
57 # def init(self):
57 # def init(self):
58 #
58 #
59 #
59 #
60 # if self.dataIn.type == 'AMISR':
60 # if self.dataIn.type == 'AMISR':
61 # self.__updateObjFromAmisrInput()
61 # self.__updateObjFromAmisrInput()
62 #
62 #
63 # if self.dataIn.type == 'Voltage':
63 # if self.dataIn.type == 'Voltage':
64 # self.dataOut.copy(self.dataIn)
64 # self.dataOut.copy(self.dataIn)
65 # # No necesita copiar en cada init() los atributos de dataIn
65 # # No necesita copiar en cada init() los atributos de dataIn
66 # # la copia deberia hacerse por cada nuevo bloque de datos
66 # # la copia deberia hacerse por cada nuevo bloque de datos
67
67
68 def selectChannels(self, channelList):
68 def selectChannels(self, channelList):
69
69
70 channelIndexList = []
70 channelIndexList = []
71
71
72 for channel in channelList:
72 for channel in channelList:
73 if channel not in self.dataOut.channelList:
73 if channel not in self.dataOut.channelList:
74 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
74 raise ValueError, "Channel %d is not in %s" %(channel, str(self.dataOut.channelList))
75
75
76 index = self.dataOut.channelList.index(channel)
76 index = self.dataOut.channelList.index(channel)
77 channelIndexList.append(index)
77 channelIndexList.append(index)
78
78
79 self.selectChannelsByIndex(channelIndexList)
79 self.selectChannelsByIndex(channelIndexList)
80
80
81 def selectChannelsByIndex(self, channelIndexList):
81 def selectChannelsByIndex(self, channelIndexList):
82 """
82 """
83 Selecciona un bloque de datos en base a canales segun el channelIndexList
83 Selecciona un bloque de datos en base a canales segun el channelIndexList
84
84
85 Input:
85 Input:
86 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
86 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
87
87
88 Affected:
88 Affected:
89 self.dataOut.data
89 self.dataOut.data
90 self.dataOut.channelIndexList
90 self.dataOut.channelIndexList
91 self.dataOut.nChannels
91 self.dataOut.nChannels
92 self.dataOut.m_ProcessingHeader.totalSpectra
92 self.dataOut.m_ProcessingHeader.totalSpectra
93 self.dataOut.systemHeaderObj.numChannels
93 self.dataOut.systemHeaderObj.numChannels
94 self.dataOut.m_ProcessingHeader.blockSize
94 self.dataOut.m_ProcessingHeader.blockSize
95
95
96 Return:
96 Return:
97 None
97 None
98 """
98 """
99
99
100 for channelIndex in channelIndexList:
100 for channelIndex in channelIndexList:
101 if channelIndex not in self.dataOut.channelIndexList:
101 if channelIndex not in self.dataOut.channelIndexList:
102 print channelIndexList
102 print channelIndexList
103 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
103 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
104
104
105 if self.dataOut.flagDataAsBlock:
105 if self.dataOut.flagDataAsBlock:
106 """
106 """
107 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
107 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
108 """
108 """
109 data = self.dataOut.data[channelIndexList,:,:]
109 data = self.dataOut.data[channelIndexList,:,:]
110 else:
110 else:
111 data = self.dataOut.data[channelIndexList,:]
111 data = self.dataOut.data[channelIndexList,:]
112
112
113 self.dataOut.data = data
113 self.dataOut.data = data
114 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
114 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
115 # self.dataOut.nChannels = nChannels
115 # self.dataOut.nChannels = nChannels
116
116
117 return 1
117 return 1
118
118
119 def selectHeights(self, minHei=None, maxHei=None):
119 def selectHeights(self, minHei=None, maxHei=None):
120 """
120 """
121 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
121 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
122 minHei <= height <= maxHei
122 minHei <= height <= maxHei
123
123
124 Input:
124 Input:
125 minHei : valor minimo de altura a considerar
125 minHei : valor minimo de altura a considerar
126 maxHei : valor maximo de altura a considerar
126 maxHei : valor maximo de altura a considerar
127
127
128 Affected:
128 Affected:
129 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
129 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
130
130
131 Return:
131 Return:
132 1 si el metodo se ejecuto con exito caso contrario devuelve 0
132 1 si el metodo se ejecuto con exito caso contrario devuelve 0
133 """
133 """
134
134
135 if minHei == None:
135 if minHei == None:
136 minHei = self.dataOut.heightList[0]
136 minHei = self.dataOut.heightList[0]
137
137
138 if maxHei == None:
138 if maxHei == None:
139 maxHei = self.dataOut.heightList[-1]
139 maxHei = self.dataOut.heightList[-1]
140
140
141 if (minHei < self.dataOut.heightList[0]):
141 if (minHei < self.dataOut.heightList[0]):
142 minHei = self.dataOut.heightList[0]
142 minHei = self.dataOut.heightList[0]
143
143
144 if (maxHei > self.dataOut.heightList[-1]):
144 if (maxHei > self.dataOut.heightList[-1]):
145 maxHei = self.dataOut.heightList[-1]
145 maxHei = self.dataOut.heightList[-1]
146
146
147 minIndex = 0
147 minIndex = 0
148 maxIndex = 0
148 maxIndex = 0
149 heights = self.dataOut.heightList
149 heights = self.dataOut.heightList
150
150
151 inda = numpy.where(heights >= minHei)
151 inda = numpy.where(heights >= minHei)
152 indb = numpy.where(heights <= maxHei)
152 indb = numpy.where(heights <= maxHei)
153
153
154 try:
154 try:
155 minIndex = inda[0][0]
155 minIndex = inda[0][0]
156 except:
156 except:
157 minIndex = 0
157 minIndex = 0
158
158
159 try:
159 try:
160 maxIndex = indb[0][-1]
160 maxIndex = indb[0][-1]
161 except:
161 except:
162 maxIndex = len(heights)
162 maxIndex = len(heights)
163
163
164 self.selectHeightsByIndex(minIndex, maxIndex)
164 self.selectHeightsByIndex(minIndex, maxIndex)
165
165
166 return 1
166 return 1
167
167
168
168
169 def selectHeightsByIndex(self, minIndex, maxIndex):
169 def selectHeightsByIndex(self, minIndex, maxIndex):
170 """
170 """
171 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
171 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
172 minIndex <= index <= maxIndex
172 minIndex <= index <= maxIndex
173
173
174 Input:
174 Input:
175 minIndex : valor de indice minimo de altura a considerar
175 minIndex : valor de indice minimo de altura a considerar
176 maxIndex : valor de indice maximo de altura a considerar
176 maxIndex : valor de indice maximo de altura a considerar
177
177
178 Affected:
178 Affected:
179 self.dataOut.data
179 self.dataOut.data
180 self.dataOut.heightList
180 self.dataOut.heightList
181
181
182 Return:
182 Return:
183 1 si el metodo se ejecuto con exito caso contrario devuelve 0
183 1 si el metodo se ejecuto con exito caso contrario devuelve 0
184 """
184 """
185
185
186 if (minIndex < 0) or (minIndex > maxIndex):
186 if (minIndex < 0) or (minIndex > maxIndex):
187 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
187 raise ValueError, "Height index range (%d,%d) is not valid" % (minIndex, maxIndex)
188
188
189 if (maxIndex >= self.dataOut.nHeights):
189 if (maxIndex >= self.dataOut.nHeights):
190 maxIndex = self.dataOut.nHeights
190 maxIndex = self.dataOut.nHeights
191
191
192 #voltage
192 #voltage
193 if self.dataOut.flagDataAsBlock:
193 if self.dataOut.flagDataAsBlock:
194 """
194 """
195 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
195 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
196 """
196 """
197 data = self.dataOut.data[:,:, minIndex:maxIndex]
197 data = self.dataOut.data[:,:, minIndex:maxIndex]
198 else:
198 else:
199 data = self.dataOut.data[:, minIndex:maxIndex]
199 data = self.dataOut.data[:, minIndex:maxIndex]
200
200
201 # firstHeight = self.dataOut.heightList[minIndex]
201 # firstHeight = self.dataOut.heightList[minIndex]
202
202
203 self.dataOut.data = data
203 self.dataOut.data = data
204 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
204 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
205
205
206 if self.dataOut.nHeights <= 1:
206 if self.dataOut.nHeights <= 1:
207 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
207 raise ValueError, "selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights)
208
208
209 return 1
209 return 1
210
210
211
211
212 def filterByHeights(self, window):
212 def filterByHeights(self, window):
213
213
214 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
214 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
215
215
216 if window == None:
216 if window == None:
217 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
217 window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
218
218
219 newdelta = deltaHeight * window
219 newdelta = deltaHeight * window
220 r = self.dataOut.nHeights % window
220 r = self.dataOut.nHeights % window
221 newheights = (self.dataOut.nHeights-r)/window
221 newheights = (self.dataOut.nHeights-r)/window
222
222
223 if newheights <= 1:
223 if newheights <= 1:
224 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
224 raise ValueError, "filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(self.dataOut.nHeights, window)
225
225
226 if self.dataOut.flagDataAsBlock:
226 if self.dataOut.flagDataAsBlock:
227 """
227 """
228 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
228 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
229 """
229 """
230 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
230 buffer = self.dataOut.data[:, :, 0:self.dataOut.nHeights-r]
231 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
231 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nProfiles,self.dataOut.nHeights/window,window)
232 buffer = numpy.sum(buffer,3)
232 buffer = numpy.sum(buffer,3)
233
233
234 else:
234 else:
235 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
235 buffer = self.dataOut.data[:,0:self.dataOut.nHeights-r]
236 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
236 buffer = buffer.reshape(self.dataOut.nChannels,self.dataOut.nHeights/window,window)
237 buffer = numpy.sum(buffer,2)
237 buffer = numpy.sum(buffer,2)
238
238
239 self.dataOut.data = buffer
239 self.dataOut.data = buffer
240 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
240 self.dataOut.heightList = self.dataOut.heightList[0] + numpy.arange( newheights )*newdelta
241 self.dataOut.windowOfFilter = window
241 self.dataOut.windowOfFilter = window
242
242
243 def setH0(self, h0, deltaHeight = None):
243 def setH0(self, h0, deltaHeight = None):
244
244
245 if not deltaHeight:
245 if not deltaHeight:
246 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
246 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
247
247
248 nHeights = self.dataOut.nHeights
248 nHeights = self.dataOut.nHeights
249
249
250 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
250 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
251
251
252 self.dataOut.heightList = newHeiRange
252 self.dataOut.heightList = newHeiRange
253
253
254 def deFlip(self, channelList = []):
254 def deFlip(self, channelList = []):
255
255
256 data = self.dataOut.data.copy()
256 data = self.dataOut.data.copy()
257
257
258 if self.dataOut.flagDataAsBlock:
258 if self.dataOut.flagDataAsBlock:
259 flip = self.flip
259 flip = self.flip
260 profileList = range(self.dataOut.nProfiles)
260 profileList = range(self.dataOut.nProfiles)
261
261
262 if not channelList:
262 if not channelList:
263 for thisProfile in profileList:
263 for thisProfile in profileList:
264 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
264 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
265 flip *= -1.0
265 flip *= -1.0
266 else:
266 else:
267 for thisChannel in channelList:
267 for thisChannel in channelList:
268 if thisChannel not in self.dataOut.channelList:
268 if thisChannel not in self.dataOut.channelList:
269 continue
269 continue
270
270
271 for thisProfile in profileList:
271 for thisProfile in profileList:
272 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
272 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
273 flip *= -1.0
273 flip *= -1.0
274
274
275 self.flip = flip
275 self.flip = flip
276
276
277 else:
277 else:
278 if not channelList:
278 if not channelList:
279 data[:,:] = data[:,:]*self.flip
279 data[:,:] = data[:,:]*self.flip
280 else:
280 else:
281 for thisChannel in channelList:
281 for thisChannel in channelList:
282 if thisChannel not in self.dataOut.channelList:
282 if thisChannel not in self.dataOut.channelList:
283 continue
283 continue
284
284
285 data[thisChannel,:] = data[thisChannel,:]*self.flip
285 data[thisChannel,:] = data[thisChannel,:]*self.flip
286
286
287 self.flip *= -1.
287 self.flip *= -1.
288
288
289 self.dataOut.data = data
289 self.dataOut.data = data
290
290
291 def setRadarFrequency(self, frequency=None):
291 def setRadarFrequency(self, frequency=None):
292
292
293 if frequency != None:
293 if frequency != None:
294 self.dataOut.frequency = frequency
294 self.dataOut.frequency = frequency
295
295
296 return 1
296 return 1
297
297
298 def interpolateHeights(self, topLim, botLim):
298 def interpolateHeights(self, topLim, botLim):
299 #69 al 72 para julia
299 #69 al 72 para julia
300 #82-84 para meteoros
300 #82-84 para meteoros
301 if len(numpy.shape(self.dataOut.data))==2:
301 if len(numpy.shape(self.dataOut.data))==2:
302 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
302 sampInterp = (self.dataOut.data[:,botLim-1] + self.dataOut.data[:,topLim+1])/2
303 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
303 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
304 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
304 #self.dataOut.data[:,botLim:limSup+1] = sampInterp
305 self.dataOut.data[:,botLim:topLim+1] = sampInterp
305 self.dataOut.data[:,botLim:topLim+1] = sampInterp
306 else:
306 else:
307 nHeights = self.dataOut.data.shape[2]
307 nHeights = self.dataOut.data.shape[2]
308 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
308 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
309 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
309 y = self.dataOut.data[:,:,range(botLim)+range(topLim+1,nHeights)]
310 f = interpolate.interp1d(x, y, axis = 2)
310 f = interpolate.interp1d(x, y, axis = 2)
311 xnew = numpy.arange(botLim,topLim+1)
311 xnew = numpy.arange(botLim,topLim+1)
312 ynew = f(xnew)
312 ynew = f(xnew)
313
313
314 self.dataOut.data[:,:,botLim:topLim+1] = ynew
314 self.dataOut.data[:,:,botLim:topLim+1] = ynew
315
315
316 # import collections
316 # import collections
317
317
318 class CohInt(Operation):
318 class CohInt(Operation):
319
319
320 isConfig = False
320 isConfig = False
321 __profIndex = 0
321 __profIndex = 0
322 __byTime = False
322 __byTime = False
323 __initime = None
323 __initime = None
324 __lastdatatime = None
324 __lastdatatime = None
325 __integrationtime = None
325 __integrationtime = None
326 __buffer = None
326 __buffer = None
327 __bufferStride = []
327 __bufferStride = []
328 __dataReady = False
328 __dataReady = False
329 __profIndexStride = 0
329 __profIndexStride = 0
330 __dataToPutStride = False
330 __dataToPutStride = False
331 n = None
331 n = None
332
332
333 def __init__(self, **kwargs):
333 def __init__(self, **kwargs):
334
334
335 Operation.__init__(self, **kwargs)
335 Operation.__init__(self, **kwargs)
336
336
337 # self.isConfig = False
337 # self.isConfig = False
338
338
339 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
339 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
340 """
340 """
341 Set the parameters of the integration class.
341 Set the parameters of the integration class.
342
342
343 Inputs:
343 Inputs:
344
344
345 n : Number of coherent integrations
345 n : Number of coherent integrations
346 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
346 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
347 overlapping :
347 overlapping :
348 """
348 """
349
349
350 self.__initime = None
350 self.__initime = None
351 self.__lastdatatime = 0
351 self.__lastdatatime = 0
352 self.__buffer = None
352 self.__buffer = None
353 self.__dataReady = False
353 self.__dataReady = False
354 self.byblock = byblock
354 self.byblock = byblock
355 self.stride = stride
355 self.stride = stride
356
356
357 if n == None and timeInterval == None:
357 if n == None and timeInterval == None:
358 raise ValueError, "n or timeInterval should be specified ..."
358 raise ValueError, "n or timeInterval should be specified ..."
359
359
360 if n != None:
360 if n != None:
361 self.n = n
361 self.n = n
362 self.__byTime = False
362 self.__byTime = False
363 else:
363 else:
364 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
364 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
365 self.n = 9999
365 self.n = 9999
366 self.__byTime = True
366 self.__byTime = True
367
367
368 if overlapping:
368 if overlapping:
369 self.__withOverlapping = True
369 self.__withOverlapping = True
370 self.__buffer = None
370 self.__buffer = None
371 else:
371 else:
372 self.__withOverlapping = False
372 self.__withOverlapping = False
373 self.__buffer = 0
373 self.__buffer = 0
374
374
375 self.__profIndex = 0
375 self.__profIndex = 0
376
376
377 def putData(self, data):
377 def putData(self, data):
378
378
379 """
379 """
380 Add a profile to the __buffer and increase in one the __profileIndex
380 Add a profile to the __buffer and increase in one the __profileIndex
381
381
382 """
382 """
383
383
384 if not self.__withOverlapping:
384 if not self.__withOverlapping:
385 self.__buffer += data.copy()
385 self.__buffer += data.copy()
386 self.__profIndex += 1
386 self.__profIndex += 1
387 return
387 return
388
388
389 #Overlapping data
389 #Overlapping data
390 nChannels, nHeis = data.shape
390 nChannels, nHeis = data.shape
391 data = numpy.reshape(data, (1, nChannels, nHeis))
391 data = numpy.reshape(data, (1, nChannels, nHeis))
392
392
393 #If the buffer is empty then it takes the data value
393 #If the buffer is empty then it takes the data value
394 if self.__buffer is None:
394 if self.__buffer is None:
395 self.__buffer = data
395 self.__buffer = data
396 self.__profIndex += 1
396 self.__profIndex += 1
397 return
397 return
398
398
399 #If the buffer length is lower than n then stakcing the data value
399 #If the buffer length is lower than n then stakcing the data value
400 if self.__profIndex < self.n:
400 if self.__profIndex < self.n:
401 self.__buffer = numpy.vstack((self.__buffer, data))
401 self.__buffer = numpy.vstack((self.__buffer, data))
402 self.__profIndex += 1
402 self.__profIndex += 1
403 return
403 return
404
404
405 #If the buffer length is equal to n then replacing the last buffer value with the data value
405 #If the buffer length is equal to n then replacing the last buffer value with the data value
406 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
406 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
407 self.__buffer[self.n-1] = data
407 self.__buffer[self.n-1] = data
408 self.__profIndex = self.n
408 self.__profIndex = self.n
409 return
409 return
410
410
411
411
412 def pushData(self):
412 def pushData(self):
413 """
413 """
414 Return the sum of the last profiles and the profiles used in the sum.
414 Return the sum of the last profiles and the profiles used in the sum.
415
415
416 Affected:
416 Affected:
417
417
418 self.__profileIndex
418 self.__profileIndex
419
419
420 """
420 """
421
421
422 if not self.__withOverlapping:
422 if not self.__withOverlapping:
423 data = self.__buffer
423 data = self.__buffer
424 n = self.__profIndex
424 n = self.__profIndex
425
425
426 self.__buffer = 0
426 self.__buffer = 0
427 self.__profIndex = 0
427 self.__profIndex = 0
428
428
429 return data, n
429 return data, n
430
430
431 #Integration with Overlapping
431 #Integration with Overlapping
432 data = numpy.sum(self.__buffer, axis=0)
432 data = numpy.sum(self.__buffer, axis=0)
433 # print data
433 # print data
434 # raise
434 # raise
435 n = self.__profIndex
435 n = self.__profIndex
436
436
437 return data, n
437 return data, n
438
438
439 def byProfiles(self, data):
439 def byProfiles(self, data):
440
440
441 self.__dataReady = False
441 self.__dataReady = False
442 avgdata = None
442 avgdata = None
443 # n = None
443 # n = None
444 # print data
444 # print data
445 # raise
445 # raise
446 self.putData(data)
446 self.putData(data)
447
447
448 if self.__profIndex == self.n:
448 if self.__profIndex == self.n:
449 avgdata, n = self.pushData()
449 avgdata, n = self.pushData()
450 self.__dataReady = True
450 self.__dataReady = True
451
451
452 return avgdata
452 return avgdata
453
453
454 def byTime(self, data, datatime):
454 def byTime(self, data, datatime):
455
455
456 self.__dataReady = False
456 self.__dataReady = False
457 avgdata = None
457 avgdata = None
458 n = None
458 n = None
459
459
460 self.putData(data)
460 self.putData(data)
461
461
462 if (datatime - self.__initime) >= self.__integrationtime:
462 if (datatime - self.__initime) >= self.__integrationtime:
463 avgdata, n = self.pushData()
463 avgdata, n = self.pushData()
464 self.n = n
464 self.n = n
465 self.__dataReady = True
465 self.__dataReady = True
466
466
467 return avgdata
467 return avgdata
468
468
469 def integrateByStride(self, data, datatime):
469 def integrateByStride(self, data, datatime):
470 # print data
470 # print data
471 if self.__profIndex == 0:
471 if self.__profIndex == 0:
472 self.__buffer = [[data.copy(), datatime]]
472 self.__buffer = [[data.copy(), datatime]]
473 else:
473 else:
474 self.__buffer.append([data.copy(),datatime])
474 self.__buffer.append([data.copy(),datatime])
475 self.__profIndex += 1
475 self.__profIndex += 1
476 self.__dataReady = False
476 self.__dataReady = False
477
477
478 if self.__profIndex == self.n * self.stride :
478 if self.__profIndex == self.n * self.stride :
479 self.__dataToPutStride = True
479 self.__dataToPutStride = True
480 self.__profIndexStride = 0
480 self.__profIndexStride = 0
481 self.__profIndex = 0
481 self.__profIndex = 0
482 self.__bufferStride = []
482 self.__bufferStride = []
483 for i in range(self.stride):
483 for i in range(self.stride):
484 current = self.__buffer[i::self.stride]
484 current = self.__buffer[i::self.stride]
485 data = numpy.sum([t[0] for t in current], axis=0)
485 data = numpy.sum([t[0] for t in current], axis=0)
486 avgdatatime = numpy.average([t[1] for t in current])
486 avgdatatime = numpy.average([t[1] for t in current])
487 # print data
487 # print data
488 self.__bufferStride.append((data, avgdatatime))
488 self.__bufferStride.append((data, avgdatatime))
489
489
490 if self.__dataToPutStride:
490 if self.__dataToPutStride:
491 self.__dataReady = True
491 self.__dataReady = True
492 self.__profIndexStride += 1
492 self.__profIndexStride += 1
493 if self.__profIndexStride == self.stride:
493 if self.__profIndexStride == self.stride:
494 self.__dataToPutStride = False
494 self.__dataToPutStride = False
495 # print self.__bufferStride[self.__profIndexStride - 1]
495 # print self.__bufferStride[self.__profIndexStride - 1]
496 # raise
496 # raise
497 return self.__bufferStride[self.__profIndexStride - 1]
497 return self.__bufferStride[self.__profIndexStride - 1]
498
498
499
499
500 return None, None
500 return None, None
501
501
502 def integrate(self, data, datatime=None):
502 def integrate(self, data, datatime=None):
503
503
504 if self.__initime == None:
504 if self.__initime == None:
505 self.__initime = datatime
505 self.__initime = datatime
506
506
507 if self.__byTime:
507 if self.__byTime:
508 avgdata = self.byTime(data, datatime)
508 avgdata = self.byTime(data, datatime)
509 else:
509 else:
510 avgdata = self.byProfiles(data)
510 avgdata = self.byProfiles(data)
511
511
512
512
513 self.__lastdatatime = datatime
513 self.__lastdatatime = datatime
514
514
515 if avgdata is None:
515 if avgdata is None:
516 return None, None
516 return None, None
517
517
518 avgdatatime = self.__initime
518 avgdatatime = self.__initime
519
519
520 deltatime = datatime - self.__lastdatatime
520 deltatime = datatime - self.__lastdatatime
521
521
522 if not self.__withOverlapping:
522 if not self.__withOverlapping:
523 self.__initime = datatime
523 self.__initime = datatime
524 else:
524 else:
525 self.__initime += deltatime
525 self.__initime += deltatime
526
526
527 return avgdata, avgdatatime
527 return avgdata, avgdatatime
528
528
529 def integrateByBlock(self, dataOut):
529 def integrateByBlock(self, dataOut):
530
530
531 times = int(dataOut.data.shape[1]/self.n)
531 times = int(dataOut.data.shape[1]/self.n)
532 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
532 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
533
533
534 id_min = 0
534 id_min = 0
535 id_max = self.n
535 id_max = self.n
536
536
537 for i in range(times):
537 for i in range(times):
538 junk = dataOut.data[:,id_min:id_max,:]
538 junk = dataOut.data[:,id_min:id_max,:]
539 avgdata[:,i,:] = junk.sum(axis=1)
539 avgdata[:,i,:] = junk.sum(axis=1)
540 id_min += self.n
540 id_min += self.n
541 id_max += self.n
541 id_max += self.n
542
542
543 timeInterval = dataOut.ippSeconds*self.n
543 timeInterval = dataOut.ippSeconds*self.n
544 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
544 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
545 self.__dataReady = True
545 self.__dataReady = True
546 return avgdata, avgdatatime
546 return avgdata, avgdatatime
547
547
548 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
548 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
549 if not self.isConfig:
549 if not self.isConfig:
550 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
550 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
551 self.isConfig = True
551 self.isConfig = True
552
552
553 if dataOut.flagDataAsBlock:
553 if dataOut.flagDataAsBlock:
554 """
554 """
555 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
555 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
556 """
556 """
557 avgdata, avgdatatime = self.integrateByBlock(dataOut)
557 avgdata, avgdatatime = self.integrateByBlock(dataOut)
558 dataOut.nProfiles /= self.n
558 dataOut.nProfiles /= self.n
559 else:
559 else:
560 if stride is None:
560 if stride is None:
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562 else:
562 else:
563 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
563 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
564
564
565
565
566 # dataOut.timeInterval *= n
566 # dataOut.timeInterval *= n
567 dataOut.flagNoData = True
567 dataOut.flagNoData = True
568
568
569 if self.__dataReady:
569 if self.__dataReady:
570 dataOut.data = avgdata
570 dataOut.data = avgdata
571 dataOut.nCohInt *= self.n
571 dataOut.nCohInt *= self.n
572 dataOut.utctime = avgdatatime
572 dataOut.utctime = avgdatatime
573 # print avgdata, avgdatatime
573 # print avgdata, avgdatatime
574 # raise
574 # raise
575 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
575 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
576 dataOut.flagNoData = False
576 dataOut.flagNoData = False
577
577
578 class Decoder(Operation):
578 class Decoder(Operation):
579
579
580 isConfig = False
580 isConfig = False
581 __profIndex = 0
581 __profIndex = 0
582
582
583 code = None
583 code = None
584
584
585 nCode = None
585 nCode = None
586 nBaud = None
586 nBaud = None
587
587
588 def __init__(self, **kwargs):
588 def __init__(self, **kwargs):
589
589
590 Operation.__init__(self, **kwargs)
590 Operation.__init__(self, **kwargs)
591
591
592 self.times = None
592 self.times = None
593 self.osamp = None
593 self.osamp = None
594 # self.__setValues = False
594 # self.__setValues = False
595 self.isConfig = False
595 self.isConfig = False
596
596
597 def setup(self, code, osamp, dataOut):
597 def setup(self, code, osamp, dataOut):
598
598
599 self.__profIndex = 0
599 self.__profIndex = 0
600
600
601 self.code = code
601 self.code = code
602
602
603 self.nCode = len(code)
603 self.nCode = len(code)
604 self.nBaud = len(code[0])
604 self.nBaud = len(code[0])
605
605
606 if (osamp != None) and (osamp >1):
606 if (osamp != None) and (osamp >1):
607 self.osamp = osamp
607 self.osamp = osamp
608 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
608 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
609 self.nBaud = self.nBaud*self.osamp
609 self.nBaud = self.nBaud*self.osamp
610
610
611 self.__nChannels = dataOut.nChannels
611 self.__nChannels = dataOut.nChannels
612 self.__nProfiles = dataOut.nProfiles
612 self.__nProfiles = dataOut.nProfiles
613 self.__nHeis = dataOut.nHeights
613 self.__nHeis = dataOut.nHeights
614
614
615 if self.__nHeis < self.nBaud:
615 if self.__nHeis < self.nBaud:
616 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
616 raise ValueError, 'Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud)
617
617
618 #Frequency
618 #Frequency
619 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
619 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
620
620
621 __codeBuffer[:,0:self.nBaud] = self.code
621 __codeBuffer[:,0:self.nBaud] = self.code
622
622
623 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
623 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
624
624
625 if dataOut.flagDataAsBlock:
625 if dataOut.flagDataAsBlock:
626
626
627 self.ndatadec = self.__nHeis #- self.nBaud + 1
627 self.ndatadec = self.__nHeis #- self.nBaud + 1
628
628
629 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
629 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
630
630
631 else:
631 else:
632
632
633 #Time
633 #Time
634 self.ndatadec = self.__nHeis #- self.nBaud + 1
634 self.ndatadec = self.__nHeis #- self.nBaud + 1
635
635
636 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
636 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
637
637
638 def __convolutionInFreq(self, data):
638 def __convolutionInFreq(self, data):
639
639
640 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
640 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
641
641
642 fft_data = numpy.fft.fft(data, axis=1)
642 fft_data = numpy.fft.fft(data, axis=1)
643
643
644 conv = fft_data*fft_code
644 conv = fft_data*fft_code
645
645
646 data = numpy.fft.ifft(conv,axis=1)
646 data = numpy.fft.ifft(conv,axis=1)
647
647
648 return data
648 return data
649
649
650 def __convolutionInFreqOpt(self, data):
650 def __convolutionInFreqOpt(self, data):
651
651
652 raise NotImplementedError
652 raise NotImplementedError
653
653
654 def __convolutionInTime(self, data):
654 def __convolutionInTime(self, data):
655
655
656 code = self.code[self.__profIndex]
656 code = self.code[self.__profIndex]
657 for i in range(self.__nChannels):
657 for i in range(self.__nChannels):
658 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
658 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
659
659
660 return self.datadecTime
660 return self.datadecTime
661
661
662 def __convolutionByBlockInTime(self, data):
662 def __convolutionByBlockInTime(self, data):
663
663
664 repetitions = self.__nProfiles / self.nCode
664 repetitions = self.__nProfiles / self.nCode
665
665
666 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
666 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
667 junk = junk.flatten()
667 junk = junk.flatten()
668 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
668 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
669 profilesList = xrange(self.__nProfiles)
669 profilesList = xrange(self.__nProfiles)
670
670
671 for i in range(self.__nChannels):
671 for i in range(self.__nChannels):
672 for j in profilesList:
672 for j in profilesList:
673 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
673 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
674 return self.datadecTime
674 return self.datadecTime
675
675
676 def __convolutionByBlockInFreq(self, data):
676 def __convolutionByBlockInFreq(self, data):
677
677
678 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
678 raise NotImplementedError, "Decoder by frequency fro Blocks not implemented"
679
679
680
680
681 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
681 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
682
682
683 fft_data = numpy.fft.fft(data, axis=2)
683 fft_data = numpy.fft.fft(data, axis=2)
684
684
685 conv = fft_data*fft_code
685 conv = fft_data*fft_code
686
686
687 data = numpy.fft.ifft(conv,axis=2)
687 data = numpy.fft.ifft(conv,axis=2)
688
688
689 return data
689 return data
690
690
691
691
692 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
692 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
693
693
694 if dataOut.flagDecodeData:
694 if dataOut.flagDecodeData:
695 print "This data is already decoded, recoding again ..."
695 print "This data is already decoded, recoding again ..."
696
696
697 if not self.isConfig:
697 if not self.isConfig:
698
698
699 if code is None:
699 if code is None:
700 if dataOut.code is None:
700 if dataOut.code is None:
701 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
701 raise ValueError, "Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type
702
702
703 code = dataOut.code
703 code = dataOut.code
704 else:
704 else:
705 code = numpy.array(code).reshape(nCode,nBaud)
705 code = numpy.array(code).reshape(nCode,nBaud)
706 self.setup(code, osamp, dataOut)
706 self.setup(code, osamp, dataOut)
707
707
708 self.isConfig = True
708 self.isConfig = True
709
709
710 if mode == 3:
710 if mode == 3:
711 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
711 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
712
712
713 if times != None:
713 if times != None:
714 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
714 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
715
715
716 if self.code is None:
716 if self.code is None:
717 print "Fail decoding: Code is not defined."
717 print "Fail decoding: Code is not defined."
718 return
718 return
719
719
720 self.__nProfiles = dataOut.nProfiles
720 self.__nProfiles = dataOut.nProfiles
721 datadec = None
721 datadec = None
722
722
723 if mode == 3:
723 if mode == 3:
724 mode = 0
724 mode = 0
725
725
726 if dataOut.flagDataAsBlock:
726 if dataOut.flagDataAsBlock:
727 """
727 """
728 Decoding when data have been read as block,
728 Decoding when data have been read as block,
729 """
729 """
730
730
731 if mode == 0:
731 if mode == 0:
732 datadec = self.__convolutionByBlockInTime(dataOut.data)
732 datadec = self.__convolutionByBlockInTime(dataOut.data)
733 if mode == 1:
733 if mode == 1:
734 datadec = self.__convolutionByBlockInFreq(dataOut.data)
734 datadec = self.__convolutionByBlockInFreq(dataOut.data)
735 else:
735 else:
736 """
736 """
737 Decoding when data have been read profile by profile
737 Decoding when data have been read profile by profile
738 """
738 """
739 if mode == 0:
739 if mode == 0:
740 datadec = self.__convolutionInTime(dataOut.data)
740 datadec = self.__convolutionInTime(dataOut.data)
741
741
742 if mode == 1:
742 if mode == 1:
743 datadec = self.__convolutionInFreq(dataOut.data)
743 datadec = self.__convolutionInFreq(dataOut.data)
744
744
745 if mode == 2:
745 if mode == 2:
746 datadec = self.__convolutionInFreqOpt(dataOut.data)
746 datadec = self.__convolutionInFreqOpt(dataOut.data)
747
747
748 if datadec is None:
748 if datadec is None:
749 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
749 raise ValueError, "Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode
750
750
751 dataOut.code = self.code
751 dataOut.code = self.code
752 dataOut.nCode = self.nCode
752 dataOut.nCode = self.nCode
753 dataOut.nBaud = self.nBaud
753 dataOut.nBaud = self.nBaud
754
754
755 dataOut.data = datadec
755 dataOut.data = datadec
756
756
757 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
757 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
758
758
759 dataOut.flagDecodeData = True #asumo q la data esta decodificada
759 dataOut.flagDecodeData = True #asumo q la data esta decodificada
760
760
761 if self.__profIndex == self.nCode-1:
761 if self.__profIndex == self.nCode-1:
762 self.__profIndex = 0
762 self.__profIndex = 0
763 return 1
763 return 1
764
764
765 self.__profIndex += 1
765 self.__profIndex += 1
766
766
767 return 1
767 return 1
768 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
768 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
769
769
770
770
771 class ProfileConcat(Operation):
771 class ProfileConcat(Operation):
772
772
773 isConfig = False
773 isConfig = False
774 buffer = None
774 buffer = None
775
775
776 def __init__(self, **kwargs):
776 def __init__(self, **kwargs):
777
777
778 Operation.__init__(self, **kwargs)
778 Operation.__init__(self, **kwargs)
779 self.profileIndex = 0
779 self.profileIndex = 0
780
780
781 def reset(self):
781 def reset(self):
782 self.buffer = numpy.zeros_like(self.buffer)
782 self.buffer = numpy.zeros_like(self.buffer)
783 self.start_index = 0
783 self.start_index = 0
784 self.times = 1
784 self.times = 1
785
785
786 def setup(self, data, m, n=1):
786 def setup(self, data, m, n=1):
787 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
787 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
788 self.nHeights = data.shape[1]#.nHeights
788 self.nHeights = data.shape[1]#.nHeights
789 self.start_index = 0
789 self.start_index = 0
790 self.times = 1
790 self.times = 1
791
791
792 def concat(self, data):
792 def concat(self, data):
793
793
794 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
794 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
795 self.start_index = self.start_index + self.nHeights
795 self.start_index = self.start_index + self.nHeights
796
796
797 def run(self, dataOut, m):
797 def run(self, dataOut, m):
798
798
799 dataOut.flagNoData = True
799 dataOut.flagNoData = True
800
800
801 if not self.isConfig:
801 if not self.isConfig:
802 self.setup(dataOut.data, m, 1)
802 self.setup(dataOut.data, m, 1)
803 self.isConfig = True
803 self.isConfig = True
804
804
805 if dataOut.flagDataAsBlock:
805 if dataOut.flagDataAsBlock:
806 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
806 raise ValueError, "ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False"
807
807
808 else:
808 else:
809 self.concat(dataOut.data)
809 self.concat(dataOut.data)
810 self.times += 1
810 self.times += 1
811 if self.times > m:
811 if self.times > m:
812 dataOut.data = self.buffer
812 dataOut.data = self.buffer
813 self.reset()
813 self.reset()
814 dataOut.flagNoData = False
814 dataOut.flagNoData = False
815 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
815 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
816 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
816 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
817 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
817 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
818 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
818 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
819 dataOut.ippSeconds *= m
819 dataOut.ippSeconds *= m
820
820
821 class ProfileSelector(Operation):
821 class ProfileSelector(Operation):
822
822
823 profileIndex = None
823 profileIndex = None
824 # Tamanho total de los perfiles
824 # Tamanho total de los perfiles
825 nProfiles = None
825 nProfiles = None
826
826
827 def __init__(self, **kwargs):
827 def __init__(self, **kwargs):
828
828
829 Operation.__init__(self, **kwargs)
829 Operation.__init__(self, **kwargs)
830 self.profileIndex = 0
830 self.profileIndex = 0
831
831
832 def incProfileIndex(self):
832 def incProfileIndex(self):
833
833
834 self.profileIndex += 1
834 self.profileIndex += 1
835
835
836 if self.profileIndex >= self.nProfiles:
836 if self.profileIndex >= self.nProfiles:
837 self.profileIndex = 0
837 self.profileIndex = 0
838
838
839 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
839 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
840
840
841 if profileIndex < minIndex:
841 if profileIndex < minIndex:
842 return False
842 return False
843
843
844 if profileIndex > maxIndex:
844 if profileIndex > maxIndex:
845 return False
845 return False
846
846
847 return True
847 return True
848
848
849 def isThisProfileInList(self, profileIndex, profileList):
849 def isThisProfileInList(self, profileIndex, profileList):
850
850
851 if profileIndex not in profileList:
851 if profileIndex not in profileList:
852 return False
852 return False
853
853
854 return True
854 return True
855
855
856 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
856 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
857
857
858 """
858 """
859 ProfileSelector:
859 ProfileSelector:
860
860
861 Inputs:
861 Inputs:
862 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
862 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
863
863
864 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
864 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
865
865
866 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
866 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
867
867
868 """
868 """
869
869
870 if rangeList is not None:
870 if rangeList is not None:
871 if type(rangeList[0]) not in (tuple, list):
871 if type(rangeList[0]) not in (tuple, list):
872 rangeList = [rangeList]
872 rangeList = [rangeList]
873
873
874 dataOut.flagNoData = True
874 dataOut.flagNoData = True
875
875
876 if dataOut.flagDataAsBlock:
876 if dataOut.flagDataAsBlock:
877 """
877 """
878 data dimension = [nChannels, nProfiles, nHeis]
878 data dimension = [nChannels, nProfiles, nHeis]
879 """
879 """
880 if profileList != None:
880 if profileList != None:
881 dataOut.data = dataOut.data[:,profileList,:]
881 dataOut.data = dataOut.data[:,profileList,:]
882
882
883 if profileRangeList != None:
883 if profileRangeList != None:
884 minIndex = profileRangeList[0]
884 minIndex = profileRangeList[0]
885 maxIndex = profileRangeList[1]
885 maxIndex = profileRangeList[1]
886 profileList = range(minIndex, maxIndex+1)
886 profileList = range(minIndex, maxIndex+1)
887
887
888 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
888 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
889
889
890 if rangeList != None:
890 if rangeList != None:
891
891
892 profileList = []
892 profileList = []
893
893
894 for thisRange in rangeList:
894 for thisRange in rangeList:
895 minIndex = thisRange[0]
895 minIndex = thisRange[0]
896 maxIndex = thisRange[1]
896 maxIndex = thisRange[1]
897
897
898 profileList.extend(range(minIndex, maxIndex+1))
898 profileList.extend(range(minIndex, maxIndex+1))
899
899
900 dataOut.data = dataOut.data[:,profileList,:]
900 dataOut.data = dataOut.data[:,profileList,:]
901
901
902 dataOut.nProfiles = len(profileList)
902 dataOut.nProfiles = len(profileList)
903 dataOut.profileIndex = dataOut.nProfiles - 1
903 dataOut.profileIndex = dataOut.nProfiles - 1
904 dataOut.flagNoData = False
904 dataOut.flagNoData = False
905
905
906 return True
906 return True
907
907
908 """
908 """
909 data dimension = [nChannels, nHeis]
909 data dimension = [nChannels, nHeis]
910 """
910 """
911
911
912 if profileList != None:
912 if profileList != None:
913
913
914 if self.isThisProfileInList(dataOut.profileIndex, profileList):
914 if self.isThisProfileInList(dataOut.profileIndex, profileList):
915
915
916 self.nProfiles = len(profileList)
916 self.nProfiles = len(profileList)
917 dataOut.nProfiles = self.nProfiles
917 dataOut.nProfiles = self.nProfiles
918 dataOut.profileIndex = self.profileIndex
918 dataOut.profileIndex = self.profileIndex
919 dataOut.flagNoData = False
919 dataOut.flagNoData = False
920
920
921 self.incProfileIndex()
921 self.incProfileIndex()
922 return True
922 return True
923
923
924 if profileRangeList != None:
924 if profileRangeList != None:
925
925
926 minIndex = profileRangeList[0]
926 minIndex = profileRangeList[0]
927 maxIndex = profileRangeList[1]
927 maxIndex = profileRangeList[1]
928
928
929 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
929 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
930
930
931 self.nProfiles = maxIndex - minIndex + 1
931 self.nProfiles = maxIndex - minIndex + 1
932 dataOut.nProfiles = self.nProfiles
932 dataOut.nProfiles = self.nProfiles
933 dataOut.profileIndex = self.profileIndex
933 dataOut.profileIndex = self.profileIndex
934 dataOut.flagNoData = False
934 dataOut.flagNoData = False
935
935
936 self.incProfileIndex()
936 self.incProfileIndex()
937 return True
937 return True
938
938
939 if rangeList != None:
939 if rangeList != None:
940
940
941 nProfiles = 0
941 nProfiles = 0
942
942
943 for thisRange in rangeList:
943 for thisRange in rangeList:
944 minIndex = thisRange[0]
944 minIndex = thisRange[0]
945 maxIndex = thisRange[1]
945 maxIndex = thisRange[1]
946
946
947 nProfiles += maxIndex - minIndex + 1
947 nProfiles += maxIndex - minIndex + 1
948
948
949 for thisRange in rangeList:
949 for thisRange in rangeList:
950
950
951 minIndex = thisRange[0]
951 minIndex = thisRange[0]
952 maxIndex = thisRange[1]
952 maxIndex = thisRange[1]
953
953
954 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
954 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
955
955
956 self.nProfiles = nProfiles
956 self.nProfiles = nProfiles
957 dataOut.nProfiles = self.nProfiles
957 dataOut.nProfiles = self.nProfiles
958 dataOut.profileIndex = self.profileIndex
958 dataOut.profileIndex = self.profileIndex
959 dataOut.flagNoData = False
959 dataOut.flagNoData = False
960
960
961 self.incProfileIndex()
961 self.incProfileIndex()
962
962
963 break
963 break
964
964
965 return True
965 return True
966
966
967
967
968 if beam != None: #beam is only for AMISR data
968 if beam != None: #beam is only for AMISR data
969 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
969 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
970 dataOut.flagNoData = False
970 dataOut.flagNoData = False
971 dataOut.profileIndex = self.profileIndex
971 dataOut.profileIndex = self.profileIndex
972
972
973 self.incProfileIndex()
973 self.incProfileIndex()
974
974
975 return True
975 return True
976
976
977 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
977 raise ValueError, "ProfileSelector needs profileList, profileRangeList or rangeList parameter"
978
978
979 return False
979 return False
980
980
981 class Reshaper(Operation):
981 class Reshaper(Operation):
982
982
983 def __init__(self, **kwargs):
983 def __init__(self, **kwargs):
984
984
985 Operation.__init__(self, **kwargs)
985 Operation.__init__(self, **kwargs)
986
986
987 self.__buffer = None
987 self.__buffer = None
988 self.__nitems = 0
988 self.__nitems = 0
989
989
990 def __appendProfile(self, dataOut, nTxs):
990 def __appendProfile(self, dataOut, nTxs):
991
991
992 if self.__buffer is None:
992 if self.__buffer is None:
993 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
993 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
994 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
994 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
995
995
996 ini = dataOut.nHeights * self.__nitems
996 ini = dataOut.nHeights * self.__nitems
997 end = ini + dataOut.nHeights
997 end = ini + dataOut.nHeights
998
998
999 self.__buffer[:, ini:end] = dataOut.data
999 self.__buffer[:, ini:end] = dataOut.data
1000
1000
1001 self.__nitems += 1
1001 self.__nitems += 1
1002
1002
1003 return int(self.__nitems*nTxs)
1003 return int(self.__nitems*nTxs)
1004
1004
1005 def __getBuffer(self):
1005 def __getBuffer(self):
1006
1006
1007 if self.__nitems == int(1./self.__nTxs):
1007 if self.__nitems == int(1./self.__nTxs):
1008
1008
1009 self.__nitems = 0
1009 self.__nitems = 0
1010
1010
1011 return self.__buffer.copy()
1011 return self.__buffer.copy()
1012
1012
1013 return None
1013 return None
1014
1014
1015 def __checkInputs(self, dataOut, shape, nTxs):
1015 def __checkInputs(self, dataOut, shape, nTxs):
1016
1016
1017 if shape is None and nTxs is None:
1017 if shape is None and nTxs is None:
1018 raise ValueError, "Reshaper: shape of factor should be defined"
1018 raise ValueError, "Reshaper: shape of factor should be defined"
1019
1019
1020 if nTxs:
1020 if nTxs:
1021 if nTxs < 0:
1021 if nTxs < 0:
1022 raise ValueError, "nTxs should be greater than 0"
1022 raise ValueError, "nTxs should be greater than 0"
1023
1023
1024 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1024 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
1025 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1025 raise ValueError, "nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs))
1026
1026
1027 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1027 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
1028
1028
1029 return shape, nTxs
1029 return shape, nTxs
1030
1030
1031 if len(shape) != 2 and len(shape) != 3:
1031 if len(shape) != 2 and len(shape) != 3:
1032 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1032 raise ValueError, "shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights)
1033
1033
1034 if len(shape) == 2:
1034 if len(shape) == 2:
1035 shape_tuple = [dataOut.nChannels]
1035 shape_tuple = [dataOut.nChannels]
1036 shape_tuple.extend(shape)
1036 shape_tuple.extend(shape)
1037 else:
1037 else:
1038 shape_tuple = list(shape)
1038 shape_tuple = list(shape)
1039
1039
1040 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1040 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
1041
1041
1042 return shape_tuple, nTxs
1042 return shape_tuple, nTxs
1043
1043
1044 def run(self, dataOut, shape=None, nTxs=None):
1044 def run(self, dataOut, shape=None, nTxs=None):
1045
1045
1046 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1046 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
1047
1047
1048 dataOut.flagNoData = True
1048 dataOut.flagNoData = True
1049 profileIndex = None
1049 profileIndex = None
1050
1050
1051 if dataOut.flagDataAsBlock:
1051 if dataOut.flagDataAsBlock:
1052
1052
1053 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1053 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
1054 dataOut.flagNoData = False
1054 dataOut.flagNoData = False
1055
1055
1056 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1056 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
1057
1057
1058 else:
1058 else:
1059
1059
1060 if self.__nTxs < 1:
1060 if self.__nTxs < 1:
1061
1061
1062 self.__appendProfile(dataOut, self.__nTxs)
1062 self.__appendProfile(dataOut, self.__nTxs)
1063 new_data = self.__getBuffer()
1063 new_data = self.__getBuffer()
1064
1064
1065 if new_data is not None:
1065 if new_data is not None:
1066 dataOut.data = new_data
1066 dataOut.data = new_data
1067 dataOut.flagNoData = False
1067 dataOut.flagNoData = False
1068
1068
1069 profileIndex = dataOut.profileIndex*nTxs
1069 profileIndex = dataOut.profileIndex*nTxs
1070
1070
1071 else:
1071 else:
1072 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1072 raise ValueError, "nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)"
1073
1073
1074 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1074 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1075
1075
1076 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1076 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
1077
1077
1078 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1078 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
1079
1079
1080 dataOut.profileIndex = profileIndex
1080 dataOut.profileIndex = profileIndex
1081
1081
1082 dataOut.ippSeconds /= self.__nTxs
1082 dataOut.ippSeconds /= self.__nTxs
1083
1083
1084 class SplitProfiles(Operation):
1084 class SplitProfiles(Operation):
1085
1085
1086 def __init__(self, **kwargs):
1086 def __init__(self, **kwargs):
1087
1087
1088 Operation.__init__(self, **kwargs)
1088 Operation.__init__(self, **kwargs)
1089
1089
1090 def run(self, dataOut, n):
1090 def run(self, dataOut, n):
1091
1091
1092 dataOut.flagNoData = True
1092 dataOut.flagNoData = True
1093 profileIndex = None
1093 profileIndex = None
1094
1094
1095 if dataOut.flagDataAsBlock:
1095 if dataOut.flagDataAsBlock:
1096
1096
1097 #nchannels, nprofiles, nsamples
1097 #nchannels, nprofiles, nsamples
1098 shape = dataOut.data.shape
1098 shape = dataOut.data.shape
1099
1099
1100 if shape[2] % n != 0:
1100 if shape[2] % n != 0:
1101 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1101 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[2])
1102
1102
1103 new_shape = shape[0], shape[1]*n, shape[2]/n
1103 new_shape = shape[0], shape[1]*n, shape[2]/n
1104
1104
1105 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1105 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1106 dataOut.flagNoData = False
1106 dataOut.flagNoData = False
1107
1107
1108 profileIndex = int(dataOut.nProfiles/n) - 1
1108 profileIndex = int(dataOut.nProfiles/n) - 1
1109
1109
1110 else:
1110 else:
1111
1111
1112 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1112 raise ValueError, "Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)"
1113
1113
1114 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1114 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1115
1115
1116 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1116 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
1117
1117
1118 dataOut.nProfiles = int(dataOut.nProfiles*n)
1118 dataOut.nProfiles = int(dataOut.nProfiles*n)
1119
1119
1120 dataOut.profileIndex = profileIndex
1120 dataOut.profileIndex = profileIndex
1121
1121
1122 dataOut.ippSeconds /= n
1122 dataOut.ippSeconds /= n
1123
1123
1124 class CombineProfiles(Operation):
1124 class CombineProfiles(Operation):
1125
1125
1126 def __init__(self, **kwargs):
1126 def __init__(self, **kwargs):
1127
1127
1128 Operation.__init__(self, **kwargs)
1128 Operation.__init__(self, **kwargs)
1129
1129
1130 self.__remData = None
1130 self.__remData = None
1131 self.__profileIndex = 0
1131 self.__profileIndex = 0
1132
1132
1133 def run(self, dataOut, n):
1133 def run(self, dataOut, n):
1134
1134
1135 dataOut.flagNoData = True
1135 dataOut.flagNoData = True
1136 profileIndex = None
1136 profileIndex = None
1137
1137
1138 if dataOut.flagDataAsBlock:
1138 if dataOut.flagDataAsBlock:
1139
1139
1140 #nchannels, nprofiles, nsamples
1140 #nchannels, nprofiles, nsamples
1141 shape = dataOut.data.shape
1141 shape = dataOut.data.shape
1142 new_shape = shape[0], shape[1]/n, shape[2]*n
1142 new_shape = shape[0], shape[1]/n, shape[2]*n
1143
1143
1144 if shape[1] % n != 0:
1144 if shape[1] % n != 0:
1145 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1145 raise ValueError, "Could not split the data, n=%d has to be multiple of %d" %(n, shape[1])
1146
1146
1147 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1147 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1148 dataOut.flagNoData = False
1148 dataOut.flagNoData = False
1149
1149
1150 profileIndex = int(dataOut.nProfiles*n) - 1
1150 profileIndex = int(dataOut.nProfiles*n) - 1
1151
1151
1152 else:
1152 else:
1153
1153
1154 #nchannels, nsamples
1154 #nchannels, nsamples
1155 if self.__remData is None:
1155 if self.__remData is None:
1156 newData = dataOut.data
1156 newData = dataOut.data
1157 else:
1157 else:
1158 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1158 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1159
1159
1160 self.__profileIndex += 1
1160 self.__profileIndex += 1
1161
1161
1162 if self.__profileIndex < n:
1162 if self.__profileIndex < n:
1163 self.__remData = newData
1163 self.__remData = newData
1164 #continue
1164 #continue
1165 return
1165 return
1166
1166
1167 self.__profileIndex = 0
1167 self.__profileIndex = 0
1168 self.__remData = None
1168 self.__remData = None
1169
1169
1170 dataOut.data = newData
1170 dataOut.data = newData
1171 dataOut.flagNoData = False
1171 dataOut.flagNoData = False
1172
1172
1173 profileIndex = dataOut.profileIndex/n
1173 profileIndex = dataOut.profileIndex/n
1174
1174
1175
1175
1176 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1176 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1177
1177
1178 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1178 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
1179
1179
1180 dataOut.nProfiles = int(dataOut.nProfiles/n)
1180 dataOut.nProfiles = int(dataOut.nProfiles/n)
1181
1181
1182 dataOut.profileIndex = profileIndex
1182 dataOut.profileIndex = profileIndex
1183
1183
1184 dataOut.ippSeconds *= n
1184 dataOut.ippSeconds *= n
1185
1185
1186
1186
1187 class SSheightProfiles(Operation):
1187 class SSheightProfiles(Operation):
1188
1188
1189 step = None
1189 step = None
1190 nsamples = None
1190 nsamples = None
1191 bufferShape = None
1191 bufferShape = None
1192 profileShape= None
1192 profileShape = None
1193 sshProfiles = None
1193 sshProfiles = None
1194 profileIndex= None
1194 profileIndex = None
1195
1195
1196 def __init__(self, **kwargs):
1196 def __init__(self, **kwargs):
1197
1197
1198 Operation.__init__(self, **kwargs)
1198 Operation.__init__(self, **kwargs)
1199 self.isConfig = False
1199 self.isConfig = False
1200
1200
1201 def setup(self,dataOut ,step = None , nsamples = None):
1201 def setup(self,dataOut ,step = None , nsamples = None):
1202
1202
1203 if step == None and nsamples == None:
1203 if step == None and nsamples == None:
1204 raise ValueError, "step or nheights should be specified ..."
1204 raise ValueError, "step or nheights should be specified ..."
1205
1205
1206 self.step = step
1206 self.step = step
1207 self.nsamples = nsamples
1207 self.nsamples = nsamples
1208 self.__nChannels = dataOut.nChannels
1208 self.__nChannels = dataOut.nChannels
1209 self.__nProfiles = dataOut.nProfiles
1209 self.__nProfiles = dataOut.nProfiles
1210 self.__nHeis = dataOut.nHeights
1210 self.__nHeis = dataOut.nHeights
1211 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1211 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
1212 #print "shape",shape
1212
1213 #last test
1213
1214 residue = (shape[1] - self.nsamples) % self.step
1214 residue = (shape[1] - self.nsamples) % self.step
1215 if residue != 0:
1215 if residue != 0:
1216 print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)
1216 print "The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue)
1217
1217
1218 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1218 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1219 numberProfile = self.nsamples
1219 numberProfile = self.nsamples
1220 numberSamples = (shape[1] - self.nsamples)/self.step
1220 numberSamples = (shape[1] - self.nsamples)/self.step
1221
1221
1222 print "New number of profile: %d, number of height: %d, Resolution %d Km"%(numberProfile,numberSamples,deltaHeight*self.step)
1222 print "New number of profile: %d, number of height: %d, Resolution %d Km"%(numberProfile,numberSamples,deltaHeight*self.step)
1223
1223
1224 self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles
1224 self.bufferShape = shape[0], numberSamples, numberProfile # nchannels, nsamples , nprofiles
1225 self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples
1225 self.profileShape = shape[0], numberProfile, numberSamples # nchannels, nprofiles, nsamples
1226
1226
1227 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
1227 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
1228 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
1228 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
1229
1229
1230 def run(self, dataOut, step, nsamples):
1230 def run(self, dataOut, step, nsamples):
1231
1231
1232 dataOut.flagNoData = True
1232 dataOut.flagNoData = True
1233 dataOut.flagDataAsBlock =False
1233 dataOut.flagDataAsBlock = False
1234 profileIndex = None
1234 profileIndex = None
1235
1235
1236 if not self.isConfig:
1236 if not self.isConfig:
1237 self.setup(dataOut, step=step , nsamples=nsamples)
1237 self.setup(dataOut, step=step , nsamples=nsamples)
1238 self.isConfig = True
1238 self.isConfig = True
1239
1239
1240 for i in range(self.buffer.shape[1]):
1240 for i in range(self.buffer.shape[1]):
1241 self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
1241 self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
1242 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
1242 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
1243
1243
1244 for j in range(self.buffer.shape[0]):
1244 for j in range(self.buffer.shape[0]):
1245 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
1245 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
1246
1246
1247 profileIndex = self.nsamples
1247 profileIndex = self.nsamples
1248 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1248 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1249 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
1249 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
1250
1250
1251 #print "hi",dataOut.ippSeconds
1252 #print ippSeconds
1253 dataOut.data = self.sshProfiles
1251 dataOut.data = self.sshProfiles
1254 dataOut.flagNoData = False
1252 dataOut.flagNoData = False
1255 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
1253 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
1256 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
1254 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
1257 dataOut.profileIndex = profileIndex
1255 dataOut.profileIndex = profileIndex
1258 dataOut.flagDataAsBlock = True
1256 dataOut.flagDataAsBlock = True
1259 dataOut.ippSeconds = ippSeconds
1257 dataOut.ippSeconds = ippSeconds
1260 dataOut.step = self.step
1258 dataOut.step = self.step
1261 #print dataOut.ippSeconds
1262
1259
1263
1260
1264 # import collections
1261 # import collections
1265 # from scipy.stats import mode
1262 # from scipy.stats import mode
1266 #
1263 #
1267 # class Synchronize(Operation):
1264 # class Synchronize(Operation):
1268 #
1265 #
1269 # isConfig = False
1266 # isConfig = False
1270 # __profIndex = 0
1267 # __profIndex = 0
1271 #
1268 #
1272 # def __init__(self, **kwargs):
1269 # def __init__(self, **kwargs):
1273 #
1270 #
1274 # Operation.__init__(self, **kwargs)
1271 # Operation.__init__(self, **kwargs)
1275 # # self.isConfig = False
1272 # # self.isConfig = False
1276 # self.__powBuffer = None
1273 # self.__powBuffer = None
1277 # self.__startIndex = 0
1274 # self.__startIndex = 0
1278 # self.__pulseFound = False
1275 # self.__pulseFound = False
1279 #
1276 #
1280 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1277 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
1281 #
1278 #
1282 # #Read data
1279 # #Read data
1283 #
1280 #
1284 # powerdB = dataOut.getPower(channel = channel)
1281 # powerdB = dataOut.getPower(channel = channel)
1285 # noisedB = dataOut.getNoise(channel = channel)[0]
1282 # noisedB = dataOut.getNoise(channel = channel)[0]
1286 #
1283 #
1287 # self.__powBuffer.extend(powerdB.flatten())
1284 # self.__powBuffer.extend(powerdB.flatten())
1288 #
1285 #
1289 # dataArray = numpy.array(self.__powBuffer)
1286 # dataArray = numpy.array(self.__powBuffer)
1290 #
1287 #
1291 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1288 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
1292 #
1289 #
1293 # maxValue = numpy.nanmax(filteredPower)
1290 # maxValue = numpy.nanmax(filteredPower)
1294 #
1291 #
1295 # if maxValue < noisedB + 10:
1292 # if maxValue < noisedB + 10:
1296 # #No se encuentra ningun pulso de transmision
1293 # #No se encuentra ningun pulso de transmision
1297 # return None
1294 # return None
1298 #
1295 #
1299 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1296 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
1300 #
1297 #
1301 # if len(maxValuesIndex) < 2:
1298 # if len(maxValuesIndex) < 2:
1302 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1299 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
1303 # return None
1300 # return None
1304 #
1301 #
1305 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1302 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
1306 #
1303 #
1307 # #Seleccionar solo valores con un espaciamiento de nSamples
1304 # #Seleccionar solo valores con un espaciamiento de nSamples
1308 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1305 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
1309 #
1306 #
1310 # if len(pulseIndex) < 2:
1307 # if len(pulseIndex) < 2:
1311 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1308 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1312 # return None
1309 # return None
1313 #
1310 #
1314 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1311 # spacing = pulseIndex[1:] - pulseIndex[:-1]
1315 #
1312 #
1316 # #remover senales que se distancien menos de 10 unidades o muestras
1313 # #remover senales que se distancien menos de 10 unidades o muestras
1317 # #(No deberian existir IPP menor a 10 unidades)
1314 # #(No deberian existir IPP menor a 10 unidades)
1318 #
1315 #
1319 # realIndex = numpy.where(spacing > 10 )[0]
1316 # realIndex = numpy.where(spacing > 10 )[0]
1320 #
1317 #
1321 # if len(realIndex) < 2:
1318 # if len(realIndex) < 2:
1322 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1319 # #Solo se encontro un pulso de transmision con ancho mayor a 1
1323 # return None
1320 # return None
1324 #
1321 #
1325 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1322 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
1326 # realPulseIndex = pulseIndex[realIndex]
1323 # realPulseIndex = pulseIndex[realIndex]
1327 #
1324 #
1328 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1325 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
1329 #
1326 #
1330 # print "IPP = %d samples" %period
1327 # print "IPP = %d samples" %period
1331 #
1328 #
1332 # self.__newNSamples = dataOut.nHeights #int(period)
1329 # self.__newNSamples = dataOut.nHeights #int(period)
1333 # self.__startIndex = int(realPulseIndex[0])
1330 # self.__startIndex = int(realPulseIndex[0])
1334 #
1331 #
1335 # return 1
1332 # return 1
1336 #
1333 #
1337 #
1334 #
1338 # def setup(self, nSamples, nChannels, buffer_size = 4):
1335 # def setup(self, nSamples, nChannels, buffer_size = 4):
1339 #
1336 #
1340 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1337 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
1341 # maxlen = buffer_size*nSamples)
1338 # maxlen = buffer_size*nSamples)
1342 #
1339 #
1343 # bufferList = []
1340 # bufferList = []
1344 #
1341 #
1345 # for i in range(nChannels):
1342 # for i in range(nChannels):
1346 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1343 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
1347 # maxlen = buffer_size*nSamples)
1344 # maxlen = buffer_size*nSamples)
1348 #
1345 #
1349 # bufferList.append(bufferByChannel)
1346 # bufferList.append(bufferByChannel)
1350 #
1347 #
1351 # self.__nSamples = nSamples
1348 # self.__nSamples = nSamples
1352 # self.__nChannels = nChannels
1349 # self.__nChannels = nChannels
1353 # self.__bufferList = bufferList
1350 # self.__bufferList = bufferList
1354 #
1351 #
1355 # def run(self, dataOut, channel = 0):
1352 # def run(self, dataOut, channel = 0):
1356 #
1353 #
1357 # if not self.isConfig:
1354 # if not self.isConfig:
1358 # nSamples = dataOut.nHeights
1355 # nSamples = dataOut.nHeights
1359 # nChannels = dataOut.nChannels
1356 # nChannels = dataOut.nChannels
1360 # self.setup(nSamples, nChannels)
1357 # self.setup(nSamples, nChannels)
1361 # self.isConfig = True
1358 # self.isConfig = True
1362 #
1359 #
1363 # #Append new data to internal buffer
1360 # #Append new data to internal buffer
1364 # for thisChannel in range(self.__nChannels):
1361 # for thisChannel in range(self.__nChannels):
1365 # bufferByChannel = self.__bufferList[thisChannel]
1362 # bufferByChannel = self.__bufferList[thisChannel]
1366 # bufferByChannel.extend(dataOut.data[thisChannel])
1363 # bufferByChannel.extend(dataOut.data[thisChannel])
1367 #
1364 #
1368 # if self.__pulseFound:
1365 # if self.__pulseFound:
1369 # self.__startIndex -= self.__nSamples
1366 # self.__startIndex -= self.__nSamples
1370 #
1367 #
1371 # #Finding Tx Pulse
1368 # #Finding Tx Pulse
1372 # if not self.__pulseFound:
1369 # if not self.__pulseFound:
1373 # indexFound = self.__findTxPulse(dataOut, channel)
1370 # indexFound = self.__findTxPulse(dataOut, channel)
1374 #
1371 #
1375 # if indexFound == None:
1372 # if indexFound == None:
1376 # dataOut.flagNoData = True
1373 # dataOut.flagNoData = True
1377 # return
1374 # return
1378 #
1375 #
1379 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1376 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
1380 # self.__pulseFound = True
1377 # self.__pulseFound = True
1381 # self.__startIndex = indexFound
1378 # self.__startIndex = indexFound
1382 #
1379 #
1383 # #If pulse was found ...
1380 # #If pulse was found ...
1384 # for thisChannel in range(self.__nChannels):
1381 # for thisChannel in range(self.__nChannels):
1385 # bufferByChannel = self.__bufferList[thisChannel]
1382 # bufferByChannel = self.__bufferList[thisChannel]
1386 # #print self.__startIndex
1383 # #print self.__startIndex
1387 # x = numpy.array(bufferByChannel)
1384 # x = numpy.array(bufferByChannel)
1388 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1385 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
1389 #
1386 #
1390 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1387 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1391 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1388 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
1392 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1389 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
1393 #
1390 #
1394 # dataOut.data = self.__arrayBuffer
1391 # dataOut.data = self.__arrayBuffer
1395 #
1392 #
1396 # self.__startIndex += self.__newNSamples
1393 # self.__startIndex += self.__newNSamples
1397 #
1394 #
1398 # return
1395 # return
General Comments 0
You need to be logged in to leave comments. Login now