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