##// END OF EJS Templates
7 de marzo 2018
ebocanegra -
r1148:fee9f80824df
parent child
Show More
@@ -1,1231 +1,1229
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 def getDataTypeCode(numpyDtype):
34 def getDataTypeCode(numpyDtype):
35
35
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
37 datatype = 0
37 datatype = 0
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
39 datatype = 1
39 datatype = 1
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
41 datatype = 2
41 datatype = 2
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
43 datatype = 3
43 datatype = 3
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
45 datatype = 4
45 datatype = 4
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
47 datatype = 5
47 datatype = 5
48 else:
48 else:
49 datatype = None
49 datatype = None
50
50
51 return datatype
51 return datatype
52
52
53 def hildebrand_sekhon(data, navg):
53 def hildebrand_sekhon(data, navg):
54 """
54 """
55 This method is for the objective determination of the noise level in Doppler spectra. This
55 This method is for the objective determination of the noise level in Doppler spectra. This
56 implementation technique is based on the fact that the standard deviation of the spectral
56 implementation technique is based on the fact that the standard deviation of the spectral
57 densities is equal to the mean spectral density for white Gaussian noise
57 densities is equal to the mean spectral density for white Gaussian noise
58
58
59 Inputs:
59 Inputs:
60 Data : heights
60 Data : heights
61 navg : numbers of averages
61 navg : numbers of averages
62
62
63 Return:
63 Return:
64 -1 : any error
64 -1 : any error
65 anoise : noise's level
65 anoise : noise's level
66 """
66 """
67
67
68 sortdata = numpy.sort(data, axis=None)
68 sortdata = numpy.sort(data, axis=None)
69 # lenOfData = len(sortdata)
69 # lenOfData = len(sortdata)
70 # nums_min = lenOfData*0.2
70 # nums_min = lenOfData*0.2
71 #
71 #
72 # if nums_min <= 5:
72 # if nums_min <= 5:
73 # nums_min = 5
73 # nums_min = 5
74 #
74 #
75 # sump = 0.
75 # sump = 0.
76 #
76 #
77 # sumq = 0.
77 # sumq = 0.
78 #
78 #
79 # j = 0
79 # j = 0
80 #
80 #
81 # cont = 1
81 # cont = 1
82 #
82 #
83 # while((cont==1)and(j<lenOfData)):
83 # while((cont==1)and(j<lenOfData)):
84 #
84 #
85 # sump += sortdata[j]
85 # sump += sortdata[j]
86 #
86 #
87 # sumq += sortdata[j]**2
87 # sumq += sortdata[j]**2
88 #
88 #
89 # if j > nums_min:
89 # if j > nums_min:
90 # rtest = float(j)/(j-1) + 1.0/navg
90 # rtest = float(j)/(j-1) + 1.0/navg
91 # if ((sumq*j) > (rtest*sump**2)):
91 # if ((sumq*j) > (rtest*sump**2)):
92 # j = j - 1
92 # j = j - 1
93 # sump = sump - sortdata[j]
93 # sump = sump - sortdata[j]
94 # sumq = sumq - sortdata[j]**2
94 # sumq = sumq - sortdata[j]**2
95 # cont = 0
95 # cont = 0
96 #
96 #
97 # j += 1
97 # j += 1
98 #
98 #
99 # lnoise = sump /j
99 # lnoise = sump /j
100 #
100 #
101 # return lnoise
101 # return lnoise
102
102
103 return cSchain.hildebrand_sekhon(sortdata, navg)
103 return cSchain.hildebrand_sekhon(sortdata, navg)
104
104
105
105
106 class Beam:
106 class Beam:
107
107
108 def __init__(self):
108 def __init__(self):
109 self.codeList = []
109 self.codeList = []
110 self.azimuthList = []
110 self.azimuthList = []
111 self.zenithList = []
111 self.zenithList = []
112
112
113 class GenericData(object):
113 class GenericData(object):
114
114
115 flagNoData = True
115 flagNoData = True
116
116
117 def copy(self, inputObj=None):
117 def copy(self, inputObj=None):
118
118
119 if inputObj == None:
119 if inputObj == None:
120 return copy.deepcopy(self)
120 return copy.deepcopy(self)
121
121
122 for key in inputObj.__dict__.keys():
122 for key in inputObj.__dict__.keys():
123
123
124 attribute = inputObj.__dict__[key]
124 attribute = inputObj.__dict__[key]
125
125
126 #If this attribute is a tuple or list
126 #If this attribute is a tuple or list
127 if type(inputObj.__dict__[key]) in (tuple, list):
127 if type(inputObj.__dict__[key]) in (tuple, list):
128 self.__dict__[key] = attribute[:]
128 self.__dict__[key] = attribute[:]
129 continue
129 continue
130
130
131 #If this attribute is another object or instance
131 #If this attribute is another object or instance
132 if hasattr(attribute, '__dict__'):
132 if hasattr(attribute, '__dict__'):
133 self.__dict__[key] = attribute.copy()
133 self.__dict__[key] = attribute.copy()
134 continue
134 continue
135
135
136 self.__dict__[key] = inputObj.__dict__[key]
136 self.__dict__[key] = inputObj.__dict__[key]
137
137
138 def deepcopy(self):
138 def deepcopy(self):
139
139
140 return copy.deepcopy(self)
140 return copy.deepcopy(self)
141
141
142 def isEmpty(self):
142 def isEmpty(self):
143
143
144 return self.flagNoData
144 return self.flagNoData
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152
152
153 radarControllerHeaderObj = RadarControllerHeader()
153 radarControllerHeaderObj = RadarControllerHeader()
154
154
155 # data = None
155 # data = None
156
156
157 type = None
157 type = None
158
158
159 datatype = None #dtype but in string
159 datatype = None #dtype but in string
160
160
161 # dtype = None
161 # dtype = None
162
162
163 # nChannels = None
163 # nChannels = None
164
164
165 # nHeights = None
165 # nHeights = None
166
166
167 nProfiles = None
167 nProfiles = None
168
168
169 heightList = None
169 heightList = None
170
170
171 channelList = None
171 channelList = None
172
172
173 flagDiscontinuousBlock = False
173 flagDiscontinuousBlock = False
174
174
175 useLocalTime = False
175 useLocalTime = False
176
176
177 utctime = None
177 utctime = None
178
178
179 timeZone = None
179 timeZone = None
180
180
181 dstFlag = None
181 dstFlag = None
182
182
183 errorCount = None
183 errorCount = None
184
184
185 blocksize = None
185 blocksize = None
186
186
187 # nCode = None
187 # nCode = None
188 #
188 #
189 # nBaud = None
189 # nBaud = None
190 #
190 #
191 # code = None
191 # code = None
192
192
193 flagDecodeData = False #asumo q la data no esta decodificada
193 flagDecodeData = False #asumo q la data no esta decodificada
194
194
195 flagDeflipData = False #asumo q la data no esta sin flip
195 flagDeflipData = False #asumo q la data no esta sin flip
196
196
197 flagShiftFFT = False
197 flagShiftFFT = False
198
198
199 # ippSeconds = None
199 # ippSeconds = None
200
200
201 # timeInterval = None
201 # timeInterval = None
202
202
203 nCohInt = None
203 nCohInt = None
204
204
205 # noise = None
205 # noise = None
206
206
207 windowOfFilter = 1
207 windowOfFilter = 1
208
208
209 #Speed of ligth
209 #Speed of ligth
210 C = 3e8
210 C = 3e8
211
211
212 frequency = 49.92e6
212 frequency = 49.92e6
213
213
214 realtime = False
214 realtime = False
215
215
216 beacon_heiIndexList = None
216 beacon_heiIndexList = None
217
217
218 last_block = None
218 last_block = None
219
219
220 blocknow = None
220 blocknow = None
221
221
222 azimuth = None
222 azimuth = None
223
223
224 zenith = None
224 zenith = None
225
225
226 beam = Beam()
226 beam = Beam()
227
227
228 profileIndex = None
228 profileIndex = None
229
229
230 def getNoise(self):
230 def getNoise(self):
231
231
232 raise NotImplementedError
232 raise NotImplementedError
233
233
234 def getNChannels(self):
234 def getNChannels(self):
235
235
236 return len(self.channelList)
236 return len(self.channelList)
237
237
238 def getChannelIndexList(self):
238 def getChannelIndexList(self):
239
239
240 return range(self.nChannels)
240 return range(self.nChannels)
241
241
242 def getNHeights(self):
242 def getNHeights(self):
243
243
244 return len(self.heightList)
244 return len(self.heightList)
245
245
246 def getHeiRange(self, extrapoints=0):
246 def getHeiRange(self, extrapoints=0):
247
247
248 heis = self.heightList
248 heis = self.heightList
249 # deltah = self.heightList[1] - self.heightList[0]
249 # deltah = self.heightList[1] - self.heightList[0]
250 #
250 #
251 # heis.append(self.heightList[-1])
251 # heis.append(self.heightList[-1])
252
252
253 return heis
253 return heis
254
254
255 def getDeltaH(self):
255 def getDeltaH(self):
256
256
257 delta = self.heightList[1] - self.heightList[0]
257 delta = self.heightList[1] - self.heightList[0]
258
258
259 return delta
259 return delta
260
260
261 def getltctime(self):
261 def getltctime(self):
262
262
263 if self.useLocalTime:
263 if self.useLocalTime:
264 return self.utctime - self.timeZone*60
264 return self.utctime - self.timeZone*60
265
265
266 return self.utctime
266 return self.utctime
267
267
268 def getDatatime(self):
268 def getDatatime(self):
269
269
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
271 return datatimeValue
271 return datatimeValue
272
272
273 def getTimeRange(self):
273 def getTimeRange(self):
274
274
275 datatime = []
275 datatime = []
276
276
277 datatime.append(self.ltctime)
277 datatime.append(self.ltctime)
278 datatime.append(self.ltctime + self.timeInterval+1)
278 datatime.append(self.ltctime + self.timeInterval+1)
279
279
280 datatime = numpy.array(datatime)
280 datatime = numpy.array(datatime)
281
281
282 return datatime
282 return datatime
283
283
284 def getFmaxTimeResponse(self):
284 def getFmaxTimeResponse(self):
285
285
286 period = (10**-6)*self.getDeltaH()/(0.15)
286 period = (10**-6)*self.getDeltaH()/(0.15)
287
287
288 PRF = 1./(period * self.nCohInt)
288 PRF = 1./(period * self.nCohInt)
289
289
290 fmax = PRF
290 fmax = PRF
291
291
292 return fmax
292 return fmax
293
293
294 def getFmax(self):
294 def getFmax(self):
295
295
296 PRF = 1./(self.ippSeconds * self.nCohInt)
296 PRF = 1./(self.ippSeconds * self.nCohInt)
297
297
298 fmax = PRF
298 fmax = PRF
299
299
300 return fmax
300 return fmax
301
301
302 def getVmax(self):
302 def getVmax(self):
303
303
304 _lambda = self.C/self.frequency
304 _lambda = self.C/self.frequency
305
305
306 vmax = self.getFmax() * _lambda/2
306 vmax = self.getFmax() * _lambda/2
307
307
308 return vmax
308 return vmax
309
309
310 def get_ippSeconds(self):
310 def get_ippSeconds(self):
311 '''
311 '''
312 '''
312 '''
313 return self.radarControllerHeaderObj.ippSeconds
313 return self.radarControllerHeaderObj.ippSeconds
314
314
315 def set_ippSeconds(self, ippSeconds):
315 def set_ippSeconds(self, ippSeconds):
316 '''
316 '''
317 '''
317 '''
318
318
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
320
320
321 return
321 return
322
322
323 def get_dtype(self):
323 def get_dtype(self):
324 '''
324 '''
325 '''
325 '''
326 return getNumpyDtype(self.datatype)
326 return getNumpyDtype(self.datatype)
327
327
328 def set_dtype(self, numpyDtype):
328 def set_dtype(self, numpyDtype):
329 '''
329 '''
330 '''
330 '''
331
331
332 self.datatype = getDataTypeCode(numpyDtype)
332 self.datatype = getDataTypeCode(numpyDtype)
333
333
334 def get_code(self):
334 def get_code(self):
335 '''
335 '''
336 '''
336 '''
337 return self.radarControllerHeaderObj.code
337 return self.radarControllerHeaderObj.code
338
338
339 def set_code(self, code):
339 def set_code(self, code):
340 '''
340 '''
341 '''
341 '''
342 self.radarControllerHeaderObj.code = code
342 self.radarControllerHeaderObj.code = code
343
343
344 return
344 return
345
345
346 def get_ncode(self):
346 def get_ncode(self):
347 '''
347 '''
348 '''
348 '''
349 return self.radarControllerHeaderObj.nCode
349 return self.radarControllerHeaderObj.nCode
350
350
351 def set_ncode(self, nCode):
351 def set_ncode(self, nCode):
352 '''
352 '''
353 '''
353 '''
354 self.radarControllerHeaderObj.nCode = nCode
354 self.radarControllerHeaderObj.nCode = nCode
355
355
356 return
356 return
357
357
358 def get_nbaud(self):
358 def get_nbaud(self):
359 '''
359 '''
360 '''
360 '''
361 return self.radarControllerHeaderObj.nBaud
361 return self.radarControllerHeaderObj.nBaud
362
362
363 def set_nbaud(self, nBaud):
363 def set_nbaud(self, nBaud):
364 '''
364 '''
365 '''
365 '''
366 self.radarControllerHeaderObj.nBaud = nBaud
366 self.radarControllerHeaderObj.nBaud = nBaud
367
367
368 return
368 return
369
369
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
377 dtype = property(get_dtype, set_dtype)
377 dtype = property(get_dtype, set_dtype)
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
379 code = property(get_code, set_code)
379 code = property(get_code, set_code)
380 nCode = property(get_ncode, set_ncode)
380 nCode = property(get_ncode, set_ncode)
381 nBaud = property(get_nbaud, set_nbaud)
381 nBaud = property(get_nbaud, set_nbaud)
382
382
383 class Voltage(JROData):
383 class Voltage(JROData):
384
384
385 #data es un numpy array de 2 dmensiones (canales, alturas)
385 #data es un numpy array de 2 dmensiones (canales, alturas)
386 data = None
386 data = None
387
387
388 def __init__(self):
388 def __init__(self):
389 '''
389 '''
390 Constructor
390 Constructor
391 '''
391 '''
392
392
393 self.useLocalTime = True
393 self.useLocalTime = True
394
394
395 self.radarControllerHeaderObj = RadarControllerHeader()
395 self.radarControllerHeaderObj = RadarControllerHeader()
396
396
397 self.systemHeaderObj = SystemHeader()
397 self.systemHeaderObj = SystemHeader()
398
398
399 self.type = "Voltage"
399 self.type = "Voltage"
400
400
401 self.data = None
401 self.data = None
402
402
403 # self.dtype = None
403 # self.dtype = None
404
404
405 # self.nChannels = 0
405 # self.nChannels = 0
406
406
407 # self.nHeights = 0
407 # self.nHeights = 0
408
408
409 self.nProfiles = None
409 self.nProfiles = None
410
410
411 self.heightList = None
411 self.heightList = None
412
412
413 self.channelList = None
413 self.channelList = None
414
414
415 # self.channelIndexList = None
415 # self.channelIndexList = None
416
416
417 self.flagNoData = True
417 self.flagNoData = True
418
418
419 self.flagDiscontinuousBlock = False
419 self.flagDiscontinuousBlock = False
420
420
421 self.utctime = None
421 self.utctime = None
422
422
423 self.timeZone = None
423 self.timeZone = None
424
424
425 self.dstFlag = None
425 self.dstFlag = None
426
426
427 self.errorCount = None
427 self.errorCount = None
428
428
429 self.nCohInt = None
429 self.nCohInt = None
430
430
431 self.blocksize = None
431 self.blocksize = None
432
432
433 self.flagDecodeData = False #asumo q la data no esta decodificada
433 self.flagDecodeData = False #asumo q la data no esta decodificada
434
434
435 self.flagDeflipData = False #asumo q la data no esta sin flip
435 self.flagDeflipData = False #asumo q la data no esta sin flip
436
436
437 self.flagShiftFFT = False
437 self.flagShiftFFT = False
438
438
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
440
440
441 self.profileIndex = 0
441 self.profileIndex = 0
442
442
443 def getNoisebyHildebrand(self, channel = None):
443 def getNoisebyHildebrand(self, channel = None):
444 """
444 """
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
446
446
447 Return:
447 Return:
448 noiselevel
448 noiselevel
449 """
449 """
450
450
451 if channel != None:
451 if channel != None:
452 data = self.data[channel]
452 data = self.data[channel]
453 nChannels = 1
453 nChannels = 1
454 else:
454 else:
455 data = self.data
455 data = self.data
456 nChannels = self.nChannels
456 nChannels = self.nChannels
457
457
458 noise = numpy.zeros(nChannels)
458 noise = numpy.zeros(nChannels)
459 power = data * numpy.conjugate(data)
459 power = data * numpy.conjugate(data)
460
460
461 for thisChannel in range(nChannels):
461 for thisChannel in range(nChannels):
462 if nChannels == 1:
462 if nChannels == 1:
463 daux = power[:].real
463 daux = power[:].real
464 else:
464 else:
465 daux = power[thisChannel,:].real
465 daux = power[thisChannel,:].real
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
467
467
468 return noise
468 return noise
469
469
470 def getNoise(self, type = 1, channel = None):
470 def getNoise(self, type = 1, channel = None):
471
471
472 if type == 1:
472 if type == 1:
473 noise = self.getNoisebyHildebrand(channel)
473 noise = self.getNoisebyHildebrand(channel)
474
474
475 return noise
475 return noise
476
476
477 def getPower(self, channel = None):
477 def getPower(self, channel = None):
478
478
479 if channel != None:
479 if channel != None:
480 data = self.data[channel]
480 data = self.data[channel]
481 else:
481 else:
482 data = self.data
482 data = self.data
483
483
484 power = data * numpy.conjugate(data)
484 power = data * numpy.conjugate(data)
485 powerdB = 10*numpy.log10(power.real)
485 powerdB = 10*numpy.log10(power.real)
486 powerdB = numpy.squeeze(powerdB)
486 powerdB = numpy.squeeze(powerdB)
487
487
488 return powerdB
488 return powerdB
489
489
490 def getTimeInterval(self):
490 def getTimeInterval(self):
491
491
492 timeInterval = self.ippSeconds * self.nCohInt
492 timeInterval = self.ippSeconds * self.nCohInt
493
493
494 return timeInterval
494 return timeInterval
495
495
496 noise = property(getNoise, "I'm the 'nHeights' property.")
496 noise = property(getNoise, "I'm the 'nHeights' property.")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
498
498
499 class Spectra(JROData):
499 class Spectra(JROData):
500
500
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
502 data_spc = None
502 data_spc = None
503
503
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
505 data_cspc = None
505 data_cspc = None
506
506
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
508 data_dc = None
508 data_dc = None
509
509
510 #data power
510 #data power
511 data_pwr = None
511 data_pwr = None
512
512
513 nFFTPoints = None
513 nFFTPoints = None
514
514
515 # nPairs = None
515 # nPairs = None
516
516
517 pairsList = None
517 pairsList = None
518
518
519 nIncohInt = None
519 nIncohInt = None
520
520
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
522
522
523 nCohInt = None #se requiere para determinar el valor de timeInterval
523 nCohInt = None #se requiere para determinar el valor de timeInterval
524
524
525 ippFactor = None
525 ippFactor = None
526
526
527 profileIndex = 0
527 profileIndex = 0
528
528
529 plotting = "spectra"
529 plotting = "spectra"
530
530
531 def __init__(self):
531 def __init__(self):
532 '''
532 '''
533 Constructor
533 Constructor
534 '''
534 '''
535
535
536 self.useLocalTime = True
536 self.useLocalTime = True
537
537
538 self.radarControllerHeaderObj = RadarControllerHeader()
538 self.radarControllerHeaderObj = RadarControllerHeader()
539
539
540 self.systemHeaderObj = SystemHeader()
540 self.systemHeaderObj = SystemHeader()
541
541
542 self.type = "Spectra"
542 self.type = "Spectra"
543
543
544 # self.data = None
544 # self.data = None
545
545
546 # self.dtype = None
546 # self.dtype = None
547
547
548 # self.nChannels = 0
548 # self.nChannels = 0
549
549
550 # self.nHeights = 0
550 # self.nHeights = 0
551
551
552 self.nProfiles = None
552 self.nProfiles = None
553
553
554 self.heightList = None
554 self.heightList = None
555
555
556 self.channelList = None
556 self.channelList = None
557
557
558 # self.channelIndexList = None
558 # self.channelIndexList = None
559
559
560 self.pairsList = None
560 self.pairsList = None
561
561
562 self.flagNoData = True
562 self.flagNoData = True
563
563
564 self.flagDiscontinuousBlock = False
564 self.flagDiscontinuousBlock = False
565
565
566 self.utctime = None
566 self.utctime = None
567
567
568 self.nCohInt = None
568 self.nCohInt = None
569
569
570 self.nIncohInt = None
570 self.nIncohInt = None
571
571
572 self.blocksize = None
572 self.blocksize = None
573
573
574 self.nFFTPoints = None
574 self.nFFTPoints = None
575
575
576 self.wavelength = None
576 self.wavelength = None
577
577
578 self.flagDecodeData = False #asumo q la data no esta decodificada
578 self.flagDecodeData = False #asumo q la data no esta decodificada
579
579
580 self.flagDeflipData = False #asumo q la data no esta sin flip
580 self.flagDeflipData = False #asumo q la data no esta sin flip
581
581
582 self.flagShiftFFT = False
582 self.flagShiftFFT = False
583
583
584 self.ippFactor = 1
584 self.ippFactor = 1
585
585
586 #self.noise = None
586 #self.noise = None
587
587
588 self.beacon_heiIndexList = []
588 self.beacon_heiIndexList = []
589
589
590 self.noise_estimation = None
590 self.noise_estimation = None
591
591
592
592
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
594 """
594 """
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
596
596
597 Return:
597 Return:
598 noiselevel
598 noiselevel
599 """
599 """
600
600
601 noise = numpy.zeros(self.nChannels)
601 noise = numpy.zeros(self.nChannels)
602
602
603 for channel in range(self.nChannels):
603 for channel in range(self.nChannels):
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
606
606
607 return noise
607 return noise
608
608
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
610
610
611 if self.noise_estimation is not None:
611 if self.noise_estimation is not None:
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
613 else:
613 else:
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
615 return noise
615 return noise
616
616
617 def getFreqRangeTimeResponse(self, extrapoints=0):
617 def getFreqRangeTimeResponse(self, extrapoints=0):
618
618
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
621
621
622 return freqrange
622 return freqrange
623
623
624 def getAcfRange(self, extrapoints=0):
624 def getAcfRange(self, extrapoints=0):
625
625
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
628
628
629 return freqrange
629 return freqrange
630
630
631 def getFreqRange(self, extrapoints=0):
631 def getFreqRange(self, extrapoints=0):
632
632
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
635
635
636 return freqrange
636 return freqrange
637
637
638 def getVelRange(self, extrapoints=0):
638 def getVelRange(self, extrapoints=0):
639
639
640 print 'VELMAX', self.getVmax()
641 asdasdasd
642 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
640 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
643 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
641 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
644
642
645 return velrange
643 return velrange
646
644
647 def getNPairs(self):
645 def getNPairs(self):
648
646
649 return len(self.pairsList)
647 return len(self.pairsList)
650
648
651 def getPairsIndexList(self):
649 def getPairsIndexList(self):
652
650
653 return range(self.nPairs)
651 return range(self.nPairs)
654
652
655 def getNormFactor(self):
653 def getNormFactor(self):
656
654
657 pwcode = 1
655 pwcode = 1
658
656
659 if self.flagDecodeData:
657 if self.flagDecodeData:
660 pwcode = numpy.sum(self.code[0]**2)
658 pwcode = numpy.sum(self.code[0]**2)
661 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
659 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
662 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
660 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
663
661
664 return normFactor
662 return normFactor
665
663
666 def getFlagCspc(self):
664 def getFlagCspc(self):
667
665
668 if self.data_cspc is None:
666 if self.data_cspc is None:
669 return True
667 return True
670
668
671 return False
669 return False
672
670
673 def getFlagDc(self):
671 def getFlagDc(self):
674
672
675 if self.data_dc is None:
673 if self.data_dc is None:
676 return True
674 return True
677
675
678 return False
676 return False
679
677
680 def getTimeInterval(self):
678 def getTimeInterval(self):
681
679
682 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
680 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
683
681
684 return timeInterval
682 return timeInterval
685
683
686 def getPower(self):
684 def getPower(self):
687
685
688 factor = self.normFactor
686 factor = self.normFactor
689 z = self.data_spc/factor
687 z = self.data_spc/factor
690 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
688 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
691 avg = numpy.average(z, axis=1)
689 avg = numpy.average(z, axis=1)
692
690
693 return 10*numpy.log10(avg)
691 return 10*numpy.log10(avg)
694
692
695 def getCoherence(self, pairsList=None, phase=False):
693 def getCoherence(self, pairsList=None, phase=False):
696
694
697 z = []
695 z = []
698 if pairsList is None:
696 if pairsList is None:
699 pairsIndexList = self.pairsIndexList
697 pairsIndexList = self.pairsIndexList
700 else:
698 else:
701 pairsIndexList = []
699 pairsIndexList = []
702 for pair in pairsList:
700 for pair in pairsList:
703 if pair not in self.pairsList:
701 if pair not in self.pairsList:
704 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
702 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
705 pairsIndexList.append(self.pairsList.index(pair))
703 pairsIndexList.append(self.pairsList.index(pair))
706 for i in range(len(pairsIndexList)):
704 for i in range(len(pairsIndexList)):
707 pair = self.pairsList[pairsIndexList[i]]
705 pair = self.pairsList[pairsIndexList[i]]
708 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
706 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
709 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
707 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
710 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
708 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
711 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
709 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
712 if phase:
710 if phase:
713 data = numpy.arctan2(avgcoherenceComplex.imag,
711 data = numpy.arctan2(avgcoherenceComplex.imag,
714 avgcoherenceComplex.real)*180/numpy.pi
712 avgcoherenceComplex.real)*180/numpy.pi
715 else:
713 else:
716 data = numpy.abs(avgcoherenceComplex)
714 data = numpy.abs(avgcoherenceComplex)
717
715
718 z.append(data)
716 z.append(data)
719
717
720 return numpy.array(z)
718 return numpy.array(z)
721
719
722 def setValue(self, value):
720 def setValue(self, value):
723
721
724 print "This property should not be initialized"
722 print "This property should not be initialized"
725
723
726 return
724 return
727
725
728 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
726 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
729 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
727 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
730 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
728 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
731 flag_cspc = property(getFlagCspc, setValue)
729 flag_cspc = property(getFlagCspc, setValue)
732 flag_dc = property(getFlagDc, setValue)
730 flag_dc = property(getFlagDc, setValue)
733 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
731 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
734 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
732 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
735
733
736 class SpectraHeis(Spectra):
734 class SpectraHeis(Spectra):
737
735
738 data_spc = None
736 data_spc = None
739
737
740 data_cspc = None
738 data_cspc = None
741
739
742 data_dc = None
740 data_dc = None
743
741
744 nFFTPoints = None
742 nFFTPoints = None
745
743
746 # nPairs = None
744 # nPairs = None
747
745
748 pairsList = None
746 pairsList = None
749
747
750 nCohInt = None
748 nCohInt = None
751
749
752 nIncohInt = None
750 nIncohInt = None
753
751
754 def __init__(self):
752 def __init__(self):
755
753
756 self.radarControllerHeaderObj = RadarControllerHeader()
754 self.radarControllerHeaderObj = RadarControllerHeader()
757
755
758 self.systemHeaderObj = SystemHeader()
756 self.systemHeaderObj = SystemHeader()
759
757
760 self.type = "SpectraHeis"
758 self.type = "SpectraHeis"
761
759
762 # self.dtype = None
760 # self.dtype = None
763
761
764 # self.nChannels = 0
762 # self.nChannels = 0
765
763
766 # self.nHeights = 0
764 # self.nHeights = 0
767
765
768 self.nProfiles = None
766 self.nProfiles = None
769
767
770 self.heightList = None
768 self.heightList = None
771
769
772 self.channelList = None
770 self.channelList = None
773
771
774 # self.channelIndexList = None
772 # self.channelIndexList = None
775
773
776 self.flagNoData = True
774 self.flagNoData = True
777
775
778 self.flagDiscontinuousBlock = False
776 self.flagDiscontinuousBlock = False
779
777
780 # self.nPairs = 0
778 # self.nPairs = 0
781
779
782 self.utctime = None
780 self.utctime = None
783
781
784 self.blocksize = None
782 self.blocksize = None
785
783
786 self.profileIndex = 0
784 self.profileIndex = 0
787
785
788 self.nCohInt = 1
786 self.nCohInt = 1
789
787
790 self.nIncohInt = 1
788 self.nIncohInt = 1
791
789
792 def getNormFactor(self):
790 def getNormFactor(self):
793 pwcode = 1
791 pwcode = 1
794 if self.flagDecodeData:
792 if self.flagDecodeData:
795 pwcode = numpy.sum(self.code[0]**2)
793 pwcode = numpy.sum(self.code[0]**2)
796
794
797 normFactor = self.nIncohInt*self.nCohInt*pwcode
795 normFactor = self.nIncohInt*self.nCohInt*pwcode
798
796
799 return normFactor
797 return normFactor
800
798
801 def getTimeInterval(self):
799 def getTimeInterval(self):
802
800
803 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
801 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
804
802
805 return timeInterval
803 return timeInterval
806
804
807 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
805 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
808 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
806 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
809
807
810 class Fits(JROData):
808 class Fits(JROData):
811
809
812 heightList = None
810 heightList = None
813
811
814 channelList = None
812 channelList = None
815
813
816 flagNoData = True
814 flagNoData = True
817
815
818 flagDiscontinuousBlock = False
816 flagDiscontinuousBlock = False
819
817
820 useLocalTime = False
818 useLocalTime = False
821
819
822 utctime = None
820 utctime = None
823
821
824 timeZone = None
822 timeZone = None
825
823
826 # ippSeconds = None
824 # ippSeconds = None
827
825
828 # timeInterval = None
826 # timeInterval = None
829
827
830 nCohInt = None
828 nCohInt = None
831
829
832 nIncohInt = None
830 nIncohInt = None
833
831
834 noise = None
832 noise = None
835
833
836 windowOfFilter = 1
834 windowOfFilter = 1
837
835
838 #Speed of ligth
836 #Speed of ligth
839 C = 3e8
837 C = 3e8
840
838
841 frequency = 49.92e6
839 frequency = 49.92e6
842
840
843 realtime = False
841 realtime = False
844
842
845
843
846 def __init__(self):
844 def __init__(self):
847
845
848 self.type = "Fits"
846 self.type = "Fits"
849
847
850 self.nProfiles = None
848 self.nProfiles = None
851
849
852 self.heightList = None
850 self.heightList = None
853
851
854 self.channelList = None
852 self.channelList = None
855
853
856 # self.channelIndexList = None
854 # self.channelIndexList = None
857
855
858 self.flagNoData = True
856 self.flagNoData = True
859
857
860 self.utctime = None
858 self.utctime = None
861
859
862 self.nCohInt = 1
860 self.nCohInt = 1
863
861
864 self.nIncohInt = 1
862 self.nIncohInt = 1
865
863
866 self.useLocalTime = True
864 self.useLocalTime = True
867
865
868 self.profileIndex = 0
866 self.profileIndex = 0
869
867
870 # self.utctime = None
868 # self.utctime = None
871 # self.timeZone = None
869 # self.timeZone = None
872 # self.ltctime = None
870 # self.ltctime = None
873 # self.timeInterval = None
871 # self.timeInterval = None
874 # self.header = None
872 # self.header = None
875 # self.data_header = None
873 # self.data_header = None
876 # self.data = None
874 # self.data = None
877 # self.datatime = None
875 # self.datatime = None
878 # self.flagNoData = False
876 # self.flagNoData = False
879 # self.expName = ''
877 # self.expName = ''
880 # self.nChannels = None
878 # self.nChannels = None
881 # self.nSamples = None
879 # self.nSamples = None
882 # self.dataBlocksPerFile = None
880 # self.dataBlocksPerFile = None
883 # self.comments = ''
881 # self.comments = ''
884 #
882 #
885
883
886
884
887 def getltctime(self):
885 def getltctime(self):
888
886
889 if self.useLocalTime:
887 if self.useLocalTime:
890 return self.utctime - self.timeZone*60
888 return self.utctime - self.timeZone*60
891
889
892 return self.utctime
890 return self.utctime
893
891
894 def getDatatime(self):
892 def getDatatime(self):
895
893
896 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
894 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
897 return datatime
895 return datatime
898
896
899 def getTimeRange(self):
897 def getTimeRange(self):
900
898
901 datatime = []
899 datatime = []
902
900
903 datatime.append(self.ltctime)
901 datatime.append(self.ltctime)
904 datatime.append(self.ltctime + self.timeInterval)
902 datatime.append(self.ltctime + self.timeInterval)
905
903
906 datatime = numpy.array(datatime)
904 datatime = numpy.array(datatime)
907
905
908 return datatime
906 return datatime
909
907
910 def getHeiRange(self):
908 def getHeiRange(self):
911
909
912 heis = self.heightList
910 heis = self.heightList
913
911
914 return heis
912 return heis
915
913
916 def getNHeights(self):
914 def getNHeights(self):
917
915
918 return len(self.heightList)
916 return len(self.heightList)
919
917
920 def getNChannels(self):
918 def getNChannels(self):
921
919
922 return len(self.channelList)
920 return len(self.channelList)
923
921
924 def getChannelIndexList(self):
922 def getChannelIndexList(self):
925
923
926 return range(self.nChannels)
924 return range(self.nChannels)
927
925
928 def getNoise(self, type = 1):
926 def getNoise(self, type = 1):
929
927
930 #noise = numpy.zeros(self.nChannels)
928 #noise = numpy.zeros(self.nChannels)
931
929
932 if type == 1:
930 if type == 1:
933 noise = self.getNoisebyHildebrand()
931 noise = self.getNoisebyHildebrand()
934
932
935 if type == 2:
933 if type == 2:
936 noise = self.getNoisebySort()
934 noise = self.getNoisebySort()
937
935
938 if type == 3:
936 if type == 3:
939 noise = self.getNoisebyWindow()
937 noise = self.getNoisebyWindow()
940
938
941 return noise
939 return noise
942
940
943 def getTimeInterval(self):
941 def getTimeInterval(self):
944
942
945 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
943 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
946
944
947 return timeInterval
945 return timeInterval
948
946
949 datatime = property(getDatatime, "I'm the 'datatime' property")
947 datatime = property(getDatatime, "I'm the 'datatime' property")
950 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
948 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
951 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
949 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
952 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
950 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
953 noise = property(getNoise, "I'm the 'nHeights' property.")
951 noise = property(getNoise, "I'm the 'nHeights' property.")
954
952
955 ltctime = property(getltctime, "I'm the 'ltctime' property")
953 ltctime = property(getltctime, "I'm the 'ltctime' property")
956 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
954 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
957
955
958
956
959 class Correlation(JROData):
957 class Correlation(JROData):
960
958
961 noise = None
959 noise = None
962
960
963 SNR = None
961 SNR = None
964
962
965 #--------------------------------------------------
963 #--------------------------------------------------
966
964
967 mode = None
965 mode = None
968
966
969 split = False
967 split = False
970
968
971 data_cf = None
969 data_cf = None
972
970
973 lags = None
971 lags = None
974
972
975 lagRange = None
973 lagRange = None
976
974
977 pairsList = None
975 pairsList = None
978
976
979 normFactor = None
977 normFactor = None
980
978
981 #--------------------------------------------------
979 #--------------------------------------------------
982
980
983 # calculateVelocity = None
981 # calculateVelocity = None
984
982
985 nLags = None
983 nLags = None
986
984
987 nPairs = None
985 nPairs = None
988
986
989 nAvg = None
987 nAvg = None
990
988
991
989
992 def __init__(self):
990 def __init__(self):
993 '''
991 '''
994 Constructor
992 Constructor
995 '''
993 '''
996 self.radarControllerHeaderObj = RadarControllerHeader()
994 self.radarControllerHeaderObj = RadarControllerHeader()
997
995
998 self.systemHeaderObj = SystemHeader()
996 self.systemHeaderObj = SystemHeader()
999
997
1000 self.type = "Correlation"
998 self.type = "Correlation"
1001
999
1002 self.data = None
1000 self.data = None
1003
1001
1004 self.dtype = None
1002 self.dtype = None
1005
1003
1006 self.nProfiles = None
1004 self.nProfiles = None
1007
1005
1008 self.heightList = None
1006 self.heightList = None
1009
1007
1010 self.channelList = None
1008 self.channelList = None
1011
1009
1012 self.flagNoData = True
1010 self.flagNoData = True
1013
1011
1014 self.flagDiscontinuousBlock = False
1012 self.flagDiscontinuousBlock = False
1015
1013
1016 self.utctime = None
1014 self.utctime = None
1017
1015
1018 self.timeZone = None
1016 self.timeZone = None
1019
1017
1020 self.dstFlag = None
1018 self.dstFlag = None
1021
1019
1022 self.errorCount = None
1020 self.errorCount = None
1023
1021
1024 self.blocksize = None
1022 self.blocksize = None
1025
1023
1026 self.flagDecodeData = False #asumo q la data no esta decodificada
1024 self.flagDecodeData = False #asumo q la data no esta decodificada
1027
1025
1028 self.flagDeflipData = False #asumo q la data no esta sin flip
1026 self.flagDeflipData = False #asumo q la data no esta sin flip
1029
1027
1030 self.pairsList = None
1028 self.pairsList = None
1031
1029
1032 self.nPoints = None
1030 self.nPoints = None
1033
1031
1034 def getPairsList(self):
1032 def getPairsList(self):
1035
1033
1036 return self.pairsList
1034 return self.pairsList
1037
1035
1038 def getNoise(self, mode = 2):
1036 def getNoise(self, mode = 2):
1039
1037
1040 indR = numpy.where(self.lagR == 0)[0][0]
1038 indR = numpy.where(self.lagR == 0)[0][0]
1041 indT = numpy.where(self.lagT == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1042
1040
1043 jspectra0 = self.data_corr[:,:,indR,:]
1041 jspectra0 = self.data_corr[:,:,indR,:]
1044 jspectra = copy.copy(jspectra0)
1042 jspectra = copy.copy(jspectra0)
1045
1043
1046 num_chan = jspectra.shape[0]
1044 num_chan = jspectra.shape[0]
1047 num_hei = jspectra.shape[2]
1045 num_hei = jspectra.shape[2]
1048
1046
1049 freq_dc = jspectra.shape[1]/2
1047 freq_dc = jspectra.shape[1]/2
1050 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1051
1049
1052 if ind_vel[0]<0:
1050 if ind_vel[0]<0:
1053 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1054
1052
1055 if mode == 1:
1053 if mode == 1:
1056 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1057
1055
1058 if mode == 2:
1056 if mode == 2:
1059
1057
1060 vel = numpy.array([-2,-1,1,2])
1058 vel = numpy.array([-2,-1,1,2])
1061 xx = numpy.zeros([4,4])
1059 xx = numpy.zeros([4,4])
1062
1060
1063 for fil in range(4):
1061 for fil in range(4):
1064 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1065
1063
1066 xx_inv = numpy.linalg.inv(xx)
1064 xx_inv = numpy.linalg.inv(xx)
1067 xx_aux = xx_inv[0,:]
1065 xx_aux = xx_inv[0,:]
1068
1066
1069 for ich in range(num_chan):
1067 for ich in range(num_chan):
1070 yy = jspectra[ich,ind_vel,:]
1068 yy = jspectra[ich,ind_vel,:]
1071 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1072
1070
1073 junkid = jspectra[ich,freq_dc,:]<=0
1071 junkid = jspectra[ich,freq_dc,:]<=0
1074 cjunkid = sum(junkid)
1072 cjunkid = sum(junkid)
1075
1073
1076 if cjunkid.any():
1074 if cjunkid.any():
1077 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1078
1076
1079 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1080
1078
1081 return noise
1079 return noise
1082
1080
1083 def getTimeInterval(self):
1081 def getTimeInterval(self):
1084
1082
1085 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1086
1084
1087 return timeInterval
1085 return timeInterval
1088
1086
1089 def splitFunctions(self):
1087 def splitFunctions(self):
1090
1088
1091 pairsList = self.pairsList
1089 pairsList = self.pairsList
1092 ccf_pairs = []
1090 ccf_pairs = []
1093 acf_pairs = []
1091 acf_pairs = []
1094 ccf_ind = []
1092 ccf_ind = []
1095 acf_ind = []
1093 acf_ind = []
1096 for l in range(len(pairsList)):
1094 for l in range(len(pairsList)):
1097 chan0 = pairsList[l][0]
1095 chan0 = pairsList[l][0]
1098 chan1 = pairsList[l][1]
1096 chan1 = pairsList[l][1]
1099
1097
1100 #Obteniendo pares de Autocorrelacion
1098 #Obteniendo pares de Autocorrelacion
1101 if chan0 == chan1:
1099 if chan0 == chan1:
1102 acf_pairs.append(chan0)
1100 acf_pairs.append(chan0)
1103 acf_ind.append(l)
1101 acf_ind.append(l)
1104 else:
1102 else:
1105 ccf_pairs.append(pairsList[l])
1103 ccf_pairs.append(pairsList[l])
1106 ccf_ind.append(l)
1104 ccf_ind.append(l)
1107
1105
1108 data_acf = self.data_cf[acf_ind]
1106 data_acf = self.data_cf[acf_ind]
1109 data_ccf = self.data_cf[ccf_ind]
1107 data_ccf = self.data_cf[ccf_ind]
1110
1108
1111 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1109 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1112
1110
1113 def getNormFactor(self):
1111 def getNormFactor(self):
1114 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1112 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1115 acf_pairs = numpy.array(acf_pairs)
1113 acf_pairs = numpy.array(acf_pairs)
1116 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1114 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1117
1115
1118 for p in range(self.nPairs):
1116 for p in range(self.nPairs):
1119 pair = self.pairsList[p]
1117 pair = self.pairsList[p]
1120
1118
1121 ch0 = pair[0]
1119 ch0 = pair[0]
1122 ch1 = pair[1]
1120 ch1 = pair[1]
1123
1121
1124 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1122 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1125 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1123 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1126 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1124 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1127
1125
1128 return normFactor
1126 return normFactor
1129
1127
1130 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1128 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1131 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1129 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1132
1130
1133 class Parameters(Spectra):
1131 class Parameters(Spectra):
1134
1132
1135 experimentInfo = None #Information about the experiment
1133 experimentInfo = None #Information about the experiment
1136
1134
1137 #Information from previous data
1135 #Information from previous data
1138
1136
1139 inputUnit = None #Type of data to be processed
1137 inputUnit = None #Type of data to be processed
1140
1138
1141 operation = None #Type of operation to parametrize
1139 operation = None #Type of operation to parametrize
1142
1140
1143 #normFactor = None #Normalization Factor
1141 #normFactor = None #Normalization Factor
1144
1142
1145 groupList = None #List of Pairs, Groups, etc
1143 groupList = None #List of Pairs, Groups, etc
1146
1144
1147 #Parameters
1145 #Parameters
1148
1146
1149 data_param = None #Parameters obtained
1147 data_param = None #Parameters obtained
1150
1148
1151 data_pre = None #Data Pre Parametrization
1149 data_pre = None #Data Pre Parametrization
1152
1150
1153 data_SNR = None #Signal to Noise Ratio
1151 data_SNR = None #Signal to Noise Ratio
1154
1152
1155 # heightRange = None #Heights
1153 # heightRange = None #Heights
1156
1154
1157 abscissaList = None #Abscissa, can be velocities, lags or time
1155 abscissaList = None #Abscissa, can be velocities, lags or time
1158
1156
1159 # noise = None #Noise Potency
1157 # noise = None #Noise Potency
1160
1158
1161 utctimeInit = None #Initial UTC time
1159 utctimeInit = None #Initial UTC time
1162
1160
1163 paramInterval = None #Time interval to calculate Parameters in seconds
1161 paramInterval = None #Time interval to calculate Parameters in seconds
1164
1162
1165 useLocalTime = True
1163 useLocalTime = True
1166
1164
1167 #Fitting
1165 #Fitting
1168
1166
1169 data_error = None #Error of the estimation
1167 data_error = None #Error of the estimation
1170
1168
1171 constants = None
1169 constants = None
1172
1170
1173 library = None
1171 library = None
1174
1172
1175 #Output signal
1173 #Output signal
1176
1174
1177 outputInterval = None #Time interval to calculate output signal in seconds
1175 outputInterval = None #Time interval to calculate output signal in seconds
1178
1176
1179 data_output = None #Out signal
1177 data_output = None #Out signal
1180
1178
1181 nAvg = None
1179 nAvg = None
1182
1180
1183 noise_estimation = None
1181 noise_estimation = None
1184
1182
1185 GauSPC = None #Fit gaussian SPC
1183 GauSPC = None #Fit gaussian SPC
1186
1184
1187
1185
1188 def __init__(self):
1186 def __init__(self):
1189 '''
1187 '''
1190 Constructor
1188 Constructor
1191 '''
1189 '''
1192 self.radarControllerHeaderObj = RadarControllerHeader()
1190 self.radarControllerHeaderObj = RadarControllerHeader()
1193
1191
1194 self.systemHeaderObj = SystemHeader()
1192 self.systemHeaderObj = SystemHeader()
1195
1193
1196 self.type = "Parameters"
1194 self.type = "Parameters"
1197
1195
1198 def getTimeRange1(self, interval):
1196 def getTimeRange1(self, interval):
1199
1197
1200 datatime = []
1198 datatime = []
1201
1199
1202 if self.useLocalTime:
1200 if self.useLocalTime:
1203 time1 = self.utctimeInit - self.timeZone*60
1201 time1 = self.utctimeInit - self.timeZone*60
1204 else:
1202 else:
1205 time1 = self.utctimeInit
1203 time1 = self.utctimeInit
1206
1204
1207 datatime.append(time1)
1205 datatime.append(time1)
1208 datatime.append(time1 + interval)
1206 datatime.append(time1 + interval)
1209 datatime = numpy.array(datatime)
1207 datatime = numpy.array(datatime)
1210
1208
1211 return datatime
1209 return datatime
1212
1210
1213 def getTimeInterval(self):
1211 def getTimeInterval(self):
1214
1212
1215 if hasattr(self, 'timeInterval1'):
1213 if hasattr(self, 'timeInterval1'):
1216 return self.timeInterval1
1214 return self.timeInterval1
1217 else:
1215 else:
1218 return self.paramInterval
1216 return self.paramInterval
1219
1217
1220 def setValue(self, value):
1218 def setValue(self, value):
1221
1219
1222 print "This property should not be initialized"
1220 print "This property should not be initialized"
1223
1221
1224 return
1222 return
1225
1223
1226 def getNoise(self):
1224 def getNoise(self):
1227
1225
1228 return self.spc_noise
1226 return self.spc_noise
1229
1227
1230 timeInterval = property(getTimeInterval)
1228 timeInterval = property(getTimeInterval)
1231 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -1,2160 +1,2160
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class FitGauPlot(Figure):
9 class SpcParamPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'fitgau'
16 PREFIX = 'SpcParam'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 250
23 self.WIDTH = 250
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = SPEC_CODE
29 self.PLOT_CODE = SPEC_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 self.__xfilter_ena = False
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
37 self.__yfilter_ena = False
38
38
39 def getSubplots(self):
39 def getSubplots(self):
40
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
43
44 return nrow, ncol
44 return nrow, ncol
45
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
47
48 self.__showprofile = showprofile
48 self.__showprofile = showprofile
49 self.nplots = nplots
49 self.nplots = nplots
50
50
51 ncolspan = 1
51 ncolspan = 1
52 colspan = 1
52 colspan = 1
53 if showprofile:
53 if showprofile:
54 ncolspan = 3
54 ncolspan = 3
55 colspan = 2
55 colspan = 2
56 self.__nsubplots = 2
56 self.__nsubplots = 2
57
57
58 self.createFigure(id = id,
58 self.createFigure(id = id,
59 wintitle = wintitle,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
62 show=show)
63
63
64 nrow, ncol = self.getSubplots()
64 nrow, ncol = self.getSubplots()
65
65
66 counter = 0
66 counter = 0
67 for y in range(nrow):
67 for y in range(nrow):
68 for x in range(ncol):
68 for x in range(ncol):
69
69
70 if counter >= self.nplots:
70 if counter >= self.nplots:
71 break
71 break
72
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
74
75 if showprofile:
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
77
78 counter += 1
78 counter += 1
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 0):
85 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
86
86
87 """
87 """
88
88
89 Input:
89 Input:
90 dataOut :
90 dataOut :
91 id :
91 id :
92 wintitle :
92 wintitle :
93 channelList :
93 channelList :
94 showProfile :
94 showProfile :
95 xmin : None,
95 xmin : None,
96 xmax : None,
96 xmax : None,
97 ymin : None,
97 ymin : None,
98 ymax : None,
98 ymax : None,
99 zmin : None,
99 zmin : None,
100 zmax : None
100 zmax : None
101 """
101 """
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # if normFactor is None:
116 # if normFactor is None:
117 # factor = dataOut.normFactor
117 # factor = dataOut.normFactor
118 # else:
118 # else:
119 # factor = normFactor
119 # factor = normFactor
120 if xaxis == "frequency":
120 if xaxis == "frequency":
121 x = dataOut.spc_range[0]
121 x = dataOut.spcparam_range[0]
122 xlabel = "Frequency (kHz)"
122 xlabel = "Frequency (kHz)"
123
123
124 elif xaxis == "time":
124 elif xaxis == "time":
125 x = dataOut.spc_range[1]
125 x = dataOut.spcparam_range[1]
126 xlabel = "Time (ms)"
126 xlabel = "Time (ms)"
127
127
128 else:
128 else:
129 x = dataOut.spc_range[2]
129 x = dataOut.spcparam_range[2]
130 xlabel = "Velocity (m/s)"
130 xlabel = "Velocity (m/s)"
131
131
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 y = dataOut.getHeiRange()
134 y = dataOut.getHeiRange()
135
135
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
136 z = dataOut.SPCparam[Selector] #GauSelector] #dataOut.data_spc/factor
137 print 'GausSPC', z[0,32,10:40]
137 #print 'GausSPC', z[0,32,10:40]
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
139 zdB = 10*numpy.log10(z)
140
140
141 avg = numpy.average(z, axis=1)
141 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
142 avgdB = 10*numpy.log10(avg)
143
143
144 noise = dataOut.spc_noise
144 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
145 noisedB = 10*numpy.log10(noise)
146
146
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
148 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
151
152 if not self.isConfig:
152 if not self.isConfig:
153
153
154 nplots = len(channelIndexList)
154 nplots = len(channelIndexList)
155
155
156 self.setup(id=id,
156 self.setup(id=id,
157 nplots=nplots,
157 nplots=nplots,
158 wintitle=wintitle,
158 wintitle=wintitle,
159 showprofile=showprofile,
159 showprofile=showprofile,
160 show=show)
160 show=show)
161
161
162 if xmin == None: xmin = numpy.nanmin(x)
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
168
169 self.FTP_WEI = ftp_wei
169 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
170 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
172 self.PLOT_POS = plot_pos
173
173
174 self.isConfig = True
174 self.isConfig = True
175
175
176 self.setWinTitle(title)
176 self.setWinTitle(title)
177
177
178 for i in range(self.nplots):
178 for i in range(self.nplots):
179 index = channelIndexList[i]
179 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
182 if len(dataOut.beam.codeList) != 0:
183 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)
183 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)
184
184
185 axes = self.axesList[i*self.__nsubplots]
185 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
186 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
189 ticksize=9, cblabel='')
190
190
191 if self.__showprofile:
191 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
193 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
195 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
196 ytick_visible=False,
197 grid='x')
197 grid='x')
198
198
199 noiseline = numpy.repeat(noisedB[index], len(y))
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
201
202 self.draw()
202 self.draw()
203
203
204 if figfile == None:
204 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
206 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
209 figfile = self.getFilename(name)
210
210
211 self.save(figpath=figpath,
211 self.save(figpath=figpath,
212 figfile=figfile,
212 figfile=figfile,
213 save=save,
213 save=save,
214 ftp=ftp,
214 ftp=ftp,
215 wr_period=wr_period,
215 wr_period=wr_period,
216 thisDatetime=thisDatetime)
216 thisDatetime=thisDatetime)
217
217
218
218
219
219
220 class MomentsPlot(Figure):
220 class MomentsPlot(Figure):
221
221
222 isConfig = None
222 isConfig = None
223 __nsubplots = None
223 __nsubplots = None
224
224
225 WIDTHPROF = None
225 WIDTHPROF = None
226 HEIGHTPROF = None
226 HEIGHTPROF = None
227 PREFIX = 'prm'
227 PREFIX = 'prm'
228
228
229 def __init__(self, **kwargs):
229 def __init__(self, **kwargs):
230 Figure.__init__(self, **kwargs)
230 Figure.__init__(self, **kwargs)
231 self.isConfig = False
231 self.isConfig = False
232 self.__nsubplots = 1
232 self.__nsubplots = 1
233
233
234 self.WIDTH = 280
234 self.WIDTH = 280
235 self.HEIGHT = 250
235 self.HEIGHT = 250
236 self.WIDTHPROF = 120
236 self.WIDTHPROF = 120
237 self.HEIGHTPROF = 0
237 self.HEIGHTPROF = 0
238 self.counter_imagwr = 0
238 self.counter_imagwr = 0
239
239
240 self.PLOT_CODE = MOMENTS_CODE
240 self.PLOT_CODE = MOMENTS_CODE
241
241
242 self.FTP_WEI = None
242 self.FTP_WEI = None
243 self.EXP_CODE = None
243 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
244 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
245 self.PLOT_POS = None
246
246
247 def getSubplots(self):
247 def getSubplots(self):
248
248
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
251
251
252 return nrow, ncol
252 return nrow, ncol
253
253
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
255
256 self.__showprofile = showprofile
256 self.__showprofile = showprofile
257 self.nplots = nplots
257 self.nplots = nplots
258
258
259 ncolspan = 1
259 ncolspan = 1
260 colspan = 1
260 colspan = 1
261 if showprofile:
261 if showprofile:
262 ncolspan = 3
262 ncolspan = 3
263 colspan = 2
263 colspan = 2
264 self.__nsubplots = 2
264 self.__nsubplots = 2
265
265
266 self.createFigure(id = id,
266 self.createFigure(id = id,
267 wintitle = wintitle,
267 wintitle = wintitle,
268 widthplot = self.WIDTH + self.WIDTHPROF,
268 widthplot = self.WIDTH + self.WIDTHPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 show=show)
270 show=show)
271
271
272 nrow, ncol = self.getSubplots()
272 nrow, ncol = self.getSubplots()
273
273
274 counter = 0
274 counter = 0
275 for y in range(nrow):
275 for y in range(nrow):
276 for x in range(ncol):
276 for x in range(ncol):
277
277
278 if counter >= self.nplots:
278 if counter >= self.nplots:
279 break
279 break
280
280
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282
282
283 if showprofile:
283 if showprofile:
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285
285
286 counter += 1
286 counter += 1
287
287
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 server=None, folder=None, username=None, password=None,
291 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293
293
294 """
294 """
295
295
296 Input:
296 Input:
297 dataOut :
297 dataOut :
298 id :
298 id :
299 wintitle :
299 wintitle :
300 channelList :
300 channelList :
301 showProfile :
301 showProfile :
302 xmin : None,
302 xmin : None,
303 xmax : None,
303 xmax : None,
304 ymin : None,
304 ymin : None,
305 ymax : None,
305 ymax : None,
306 zmin : None,
306 zmin : None,
307 zmax : None
307 zmax : None
308 """
308 """
309
309
310 if dataOut.flagNoData:
310 if dataOut.flagNoData:
311 return None
311 return None
312
312
313 if realtime:
313 if realtime:
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 print 'Skipping this plot function'
315 print 'Skipping this plot function'
316 return
316 return
317
317
318 if channelList == None:
318 if channelList == None:
319 channelIndexList = dataOut.channelIndexList
319 channelIndexList = dataOut.channelIndexList
320 else:
320 else:
321 channelIndexList = []
321 channelIndexList = []
322 for channel in channelList:
322 for channel in channelList:
323 if channel not in dataOut.channelList:
323 if channel not in dataOut.channelList:
324 raise ValueError, "Channel %d is not in dataOut.channelList"
324 raise ValueError, "Channel %d is not in dataOut.channelList"
325 channelIndexList.append(dataOut.channelList.index(channel))
325 channelIndexList.append(dataOut.channelList.index(channel))
326
326
327 factor = dataOut.normFactor
327 factor = dataOut.normFactor
328 x = dataOut.abscissaList
328 x = dataOut.abscissaList
329 y = dataOut.heightList
329 y = dataOut.heightList
330
330
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 avg = numpy.average(z, axis=1)
333 avg = numpy.average(z, axis=1)
334 noise = dataOut.noise/factor
334 noise = dataOut.noise/factor
335
335
336 zdB = 10*numpy.log10(z)
336 zdB = 10*numpy.log10(z)
337 avgdB = 10*numpy.log10(avg)
337 avgdB = 10*numpy.log10(avg)
338 noisedB = 10*numpy.log10(noise)
338 noisedB = 10*numpy.log10(noise)
339
339
340 #thisDatetime = dataOut.datatime
340 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Parameters"
342 title = wintitle + " Parameters"
343 xlabel = "Velocity (m/s)"
343 xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
344 ylabel = "Range (Km)"
345
345
346 update_figfile = False
346 update_figfile = False
347
347
348 if not self.isConfig:
348 if not self.isConfig:
349
349
350 nplots = len(channelIndexList)
350 nplots = len(channelIndexList)
351
351
352 self.setup(id=id,
352 self.setup(id=id,
353 nplots=nplots,
353 nplots=nplots,
354 wintitle=wintitle,
354 wintitle=wintitle,
355 showprofile=showprofile,
355 showprofile=showprofile,
356 show=show)
356 show=show)
357
357
358 if xmin == None: xmin = numpy.nanmin(x)
358 if xmin == None: xmin = numpy.nanmin(x)
359 if xmax == None: xmax = numpy.nanmax(x)
359 if xmax == None: xmax = numpy.nanmax(x)
360 if ymin == None: ymin = numpy.nanmin(y)
360 if ymin == None: ymin = numpy.nanmin(y)
361 if ymax == None: ymax = numpy.nanmax(y)
361 if ymax == None: ymax = numpy.nanmax(y)
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364
364
365 self.FTP_WEI = ftp_wei
365 self.FTP_WEI = ftp_wei
366 self.EXP_CODE = exp_code
366 self.EXP_CODE = exp_code
367 self.SUB_EXP_CODE = sub_exp_code
367 self.SUB_EXP_CODE = sub_exp_code
368 self.PLOT_POS = plot_pos
368 self.PLOT_POS = plot_pos
369
369
370 self.isConfig = True
370 self.isConfig = True
371 update_figfile = True
371 update_figfile = True
372
372
373 self.setWinTitle(title)
373 self.setWinTitle(title)
374
374
375 for i in range(self.nplots):
375 for i in range(self.nplots):
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 axes = self.axesList[i*self.__nsubplots]
378 axes = self.axesList[i*self.__nsubplots]
379 axes.pcolor(x, y, zdB[i,:,:],
379 axes.pcolor(x, y, zdB[i,:,:],
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xlabel=xlabel, ylabel=ylabel, title=title,
381 xlabel=xlabel, ylabel=ylabel, title=title,
382 ticksize=9, cblabel='')
382 ticksize=9, cblabel='')
383 #Mean Line
383 #Mean Line
384 mean = dataOut.data_param[i, 1, :]
384 mean = dataOut.data_param[i, 1, :]
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386
386
387 if self.__showprofile:
387 if self.__showprofile:
388 axes = self.axesList[i*self.__nsubplots +1]
388 axes = self.axesList[i*self.__nsubplots +1]
389 axes.pline(avgdB[i], y,
389 axes.pline(avgdB[i], y,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xlabel='dB', ylabel='', title='',
391 xlabel='dB', ylabel='', title='',
392 ytick_visible=False,
392 ytick_visible=False,
393 grid='x')
393 grid='x')
394
394
395 noiseline = numpy.repeat(noisedB[i], len(y))
395 noiseline = numpy.repeat(noisedB[i], len(y))
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397
397
398 self.draw()
398 self.draw()
399
399
400 self.save(figpath=figpath,
400 self.save(figpath=figpath,
401 figfile=figfile,
401 figfile=figfile,
402 save=save,
402 save=save,
403 ftp=ftp,
403 ftp=ftp,
404 wr_period=wr_period,
404 wr_period=wr_period,
405 thisDatetime=thisDatetime)
405 thisDatetime=thisDatetime)
406
406
407
407
408
408
409 class SkyMapPlot(Figure):
409 class SkyMapPlot(Figure):
410
410
411 __isConfig = None
411 __isConfig = None
412 __nsubplots = None
412 __nsubplots = None
413
413
414 WIDTHPROF = None
414 WIDTHPROF = None
415 HEIGHTPROF = None
415 HEIGHTPROF = None
416 PREFIX = 'mmap'
416 PREFIX = 'mmap'
417
417
418 def __init__(self, **kwargs):
418 def __init__(self, **kwargs):
419 Figure.__init__(self, **kwargs)
419 Figure.__init__(self, **kwargs)
420 self.isConfig = False
420 self.isConfig = False
421 self.__nsubplots = 1
421 self.__nsubplots = 1
422
422
423 # self.WIDTH = 280
423 # self.WIDTH = 280
424 # self.HEIGHT = 250
424 # self.HEIGHT = 250
425 self.WIDTH = 600
425 self.WIDTH = 600
426 self.HEIGHT = 600
426 self.HEIGHT = 600
427 self.WIDTHPROF = 120
427 self.WIDTHPROF = 120
428 self.HEIGHTPROF = 0
428 self.HEIGHTPROF = 0
429 self.counter_imagwr = 0
429 self.counter_imagwr = 0
430
430
431 self.PLOT_CODE = MSKYMAP_CODE
431 self.PLOT_CODE = MSKYMAP_CODE
432
432
433 self.FTP_WEI = None
433 self.FTP_WEI = None
434 self.EXP_CODE = None
434 self.EXP_CODE = None
435 self.SUB_EXP_CODE = None
435 self.SUB_EXP_CODE = None
436 self.PLOT_POS = None
436 self.PLOT_POS = None
437
437
438 def getSubplots(self):
438 def getSubplots(self):
439
439
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
442
442
443 return nrow, ncol
443 return nrow, ncol
444
444
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
446
446
447 self.__showprofile = showprofile
447 self.__showprofile = showprofile
448 self.nplots = nplots
448 self.nplots = nplots
449
449
450 ncolspan = 1
450 ncolspan = 1
451 colspan = 1
451 colspan = 1
452
452
453 self.createFigure(id = id,
453 self.createFigure(id = id,
454 wintitle = wintitle,
454 wintitle = wintitle,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
457 show=show)
457 show=show)
458
458
459 nrow, ncol = 1,1
459 nrow, ncol = 1,1
460 counter = 0
460 counter = 0
461 x = 0
461 x = 0
462 y = 0
462 y = 0
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
464
464
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
466 tmin=0, tmax=24, timerange=None,
466 tmin=0, tmax=24, timerange=None,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
468 server=None, folder=None, username=None, password=None,
468 server=None, folder=None, username=None, password=None,
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
470
470
471 """
471 """
472
472
473 Input:
473 Input:
474 dataOut :
474 dataOut :
475 id :
475 id :
476 wintitle :
476 wintitle :
477 channelList :
477 channelList :
478 showProfile :
478 showProfile :
479 xmin : None,
479 xmin : None,
480 xmax : None,
480 xmax : None,
481 ymin : None,
481 ymin : None,
482 ymax : None,
482 ymax : None,
483 zmin : None,
483 zmin : None,
484 zmax : None
484 zmax : None
485 """
485 """
486
486
487 arrayParameters = dataOut.data_param
487 arrayParameters = dataOut.data_param
488 error = arrayParameters[:,-1]
488 error = arrayParameters[:,-1]
489 indValid = numpy.where(error == 0)[0]
489 indValid = numpy.where(error == 0)[0]
490 finalMeteor = arrayParameters[indValid,:]
490 finalMeteor = arrayParameters[indValid,:]
491 finalAzimuth = finalMeteor[:,3]
491 finalAzimuth = finalMeteor[:,3]
492 finalZenith = finalMeteor[:,4]
492 finalZenith = finalMeteor[:,4]
493
493
494 x = finalAzimuth*numpy.pi/180
494 x = finalAzimuth*numpy.pi/180
495 y = finalZenith
495 y = finalZenith
496 x1 = [dataOut.ltctime, dataOut.ltctime]
496 x1 = [dataOut.ltctime, dataOut.ltctime]
497
497
498 #thisDatetime = dataOut.datatime
498 #thisDatetime = dataOut.datatime
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 title = wintitle + " Parameters"
500 title = wintitle + " Parameters"
501 xlabel = "Zonal Zenith Angle (deg) "
501 xlabel = "Zonal Zenith Angle (deg) "
502 ylabel = "Meridional Zenith Angle (deg)"
502 ylabel = "Meridional Zenith Angle (deg)"
503 update_figfile = False
503 update_figfile = False
504
504
505 if not self.isConfig:
505 if not self.isConfig:
506
506
507 nplots = 1
507 nplots = 1
508
508
509 self.setup(id=id,
509 self.setup(id=id,
510 nplots=nplots,
510 nplots=nplots,
511 wintitle=wintitle,
511 wintitle=wintitle,
512 showprofile=showprofile,
512 showprofile=showprofile,
513 show=show)
513 show=show)
514
514
515 if self.xmin is None and self.xmax is None:
515 if self.xmin is None and self.xmax is None:
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
517
517
518 if timerange != None:
518 if timerange != None:
519 self.timerange = timerange
519 self.timerange = timerange
520 else:
520 else:
521 self.timerange = self.xmax - self.xmin
521 self.timerange = self.xmax - self.xmin
522
522
523 self.FTP_WEI = ftp_wei
523 self.FTP_WEI = ftp_wei
524 self.EXP_CODE = exp_code
524 self.EXP_CODE = exp_code
525 self.SUB_EXP_CODE = sub_exp_code
525 self.SUB_EXP_CODE = sub_exp_code
526 self.PLOT_POS = plot_pos
526 self.PLOT_POS = plot_pos
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
529 self.isConfig = True
529 self.isConfig = True
530 update_figfile = True
530 update_figfile = True
531
531
532 self.setWinTitle(title)
532 self.setWinTitle(title)
533
533
534 i = 0
534 i = 0
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
536
536
537 axes = self.axesList[i*self.__nsubplots]
537 axes = self.axesList[i*self.__nsubplots]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
540 axes.polar(x, y,
540 axes.polar(x, y,
541 title=title, xlabel=xlabel, ylabel=ylabel,
541 title=title, xlabel=xlabel, ylabel=ylabel,
542 ticksize=9, cblabel='')
542 ticksize=9, cblabel='')
543
543
544 self.draw()
544 self.draw()
545
545
546 self.save(figpath=figpath,
546 self.save(figpath=figpath,
547 figfile=figfile,
547 figfile=figfile,
548 save=save,
548 save=save,
549 ftp=ftp,
549 ftp=ftp,
550 wr_period=wr_period,
550 wr_period=wr_period,
551 thisDatetime=thisDatetime,
551 thisDatetime=thisDatetime,
552 update_figfile=update_figfile)
552 update_figfile=update_figfile)
553
553
554 if dataOut.ltctime >= self.xmax:
554 if dataOut.ltctime >= self.xmax:
555 self.isConfigmagwr = wr_period
555 self.isConfigmagwr = wr_period
556 self.isConfig = False
556 self.isConfig = False
557 update_figfile = True
557 update_figfile = True
558 axes.__firsttime = True
558 axes.__firsttime = True
559 self.xmin += self.timerange
559 self.xmin += self.timerange
560 self.xmax += self.timerange
560 self.xmax += self.timerange
561
561
562
562
563
563
564
564
565 class WindProfilerPlot(Figure):
565 class WindProfilerPlot(Figure):
566
566
567 __isConfig = None
567 __isConfig = None
568 __nsubplots = None
568 __nsubplots = None
569
569
570 WIDTHPROF = None
570 WIDTHPROF = None
571 HEIGHTPROF = None
571 HEIGHTPROF = None
572 PREFIX = 'wind'
572 PREFIX = 'wind'
573
573
574 def __init__(self, **kwargs):
574 def __init__(self, **kwargs):
575 Figure.__init__(self, **kwargs)
575 Figure.__init__(self, **kwargs)
576 self.timerange = None
576 self.timerange = None
577 self.isConfig = False
577 self.isConfig = False
578 self.__nsubplots = 1
578 self.__nsubplots = 1
579
579
580 self.WIDTH = 800
580 self.WIDTH = 800
581 self.HEIGHT = 300
581 self.HEIGHT = 300
582 self.WIDTHPROF = 120
582 self.WIDTHPROF = 120
583 self.HEIGHTPROF = 0
583 self.HEIGHTPROF = 0
584 self.counter_imagwr = 0
584 self.counter_imagwr = 0
585
585
586 self.PLOT_CODE = WIND_CODE
586 self.PLOT_CODE = WIND_CODE
587
587
588 self.FTP_WEI = None
588 self.FTP_WEI = None
589 self.EXP_CODE = None
589 self.EXP_CODE = None
590 self.SUB_EXP_CODE = None
590 self.SUB_EXP_CODE = None
591 self.PLOT_POS = None
591 self.PLOT_POS = None
592 self.tmin = None
592 self.tmin = None
593 self.tmax = None
593 self.tmax = None
594
594
595 self.xmin = None
595 self.xmin = None
596 self.xmax = None
596 self.xmax = None
597
597
598 self.figfile = None
598 self.figfile = None
599
599
600 def getSubplots(self):
600 def getSubplots(self):
601
601
602 ncol = 1
602 ncol = 1
603 nrow = self.nplots
603 nrow = self.nplots
604
604
605 return nrow, ncol
605 return nrow, ncol
606
606
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
608
608
609 self.__showprofile = showprofile
609 self.__showprofile = showprofile
610 self.nplots = nplots
610 self.nplots = nplots
611
611
612 ncolspan = 1
612 ncolspan = 1
613 colspan = 1
613 colspan = 1
614
614
615 self.createFigure(id = id,
615 self.createFigure(id = id,
616 wintitle = wintitle,
616 wintitle = wintitle,
617 widthplot = self.WIDTH + self.WIDTHPROF,
617 widthplot = self.WIDTH + self.WIDTHPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
619 show=show)
619 show=show)
620
620
621 nrow, ncol = self.getSubplots()
621 nrow, ncol = self.getSubplots()
622
622
623 counter = 0
623 counter = 0
624 for y in range(nrow):
624 for y in range(nrow):
625 if counter >= self.nplots:
625 if counter >= self.nplots:
626 break
626 break
627
627
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
629 counter += 1
629 counter += 1
630
630
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
634 timerange=None, SNRthresh = None,
634 timerange=None, SNRthresh = None,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
636 server=None, folder=None, username=None, password=None,
636 server=None, folder=None, username=None, password=None,
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
638 """
638 """
639
639
640 Input:
640 Input:
641 dataOut :
641 dataOut :
642 id :
642 id :
643 wintitle :
643 wintitle :
644 channelList :
644 channelList :
645 showProfile :
645 showProfile :
646 xmin : None,
646 xmin : None,
647 xmax : None,
647 xmax : None,
648 ymin : None,
648 ymin : None,
649 ymax : None,
649 ymax : None,
650 zmin : None,
650 zmin : None,
651 zmax : None
651 zmax : None
652 """
652 """
653
653
654 # if timerange is not None:
654 # if timerange is not None:
655 # self.timerange = timerange
655 # self.timerange = timerange
656 #
656 #
657 # tmin = None
657 # tmin = None
658 # tmax = None
658 # tmax = None
659
659
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
661 y = dataOut.heightList
661 y = dataOut.heightList
662 z = dataOut.data_output.copy()
662 z = dataOut.data_output.copy()
663 nplots = z.shape[0] #Number of wind dimensions estimated
663 nplots = z.shape[0] #Number of wind dimensions estimated
664 nplotsw = nplots
664 nplotsw = nplots
665
665
666
666
667 #If there is a SNR function defined
667 #If there is a SNR function defined
668 if dataOut.data_SNR is not None:
668 if dataOut.data_SNR is not None:
669 nplots += 1
669 nplots += 1
670 SNR = dataOut.data_SNR[0]
670 SNR = dataOut.data_SNR[0]
671 SNRavg = SNR#numpy.average(SNR, axis=0)
671 SNRavg = SNR#numpy.average(SNR, axis=0)
672
672
673 SNRdB = 10*numpy.log10(SNR)
673 SNRdB = 10*numpy.log10(SNR)
674 SNRavgdB = 10*numpy.log10(SNRavg)
674 SNRavgdB = 10*numpy.log10(SNRavg)
675
675
676 if SNRthresh == None:
676 if SNRthresh == None:
677 SNRthresh = -5.0
677 SNRthresh = -5.0
678 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
678 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
679
679
680 for i in range(nplotsw):
680 for i in range(nplotsw):
681 z[i,ind] = numpy.nan
681 z[i,ind] = numpy.nan
682
682
683 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
683 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
684 #thisDatetime = datetime.datetime.now()
684 #thisDatetime = datetime.datetime.now()
685 title = wintitle + "Wind"
685 title = wintitle + "Wind"
686 xlabel = ""
686 xlabel = ""
687 ylabel = "Height (km)"
687 ylabel = "Height (km)"
688 update_figfile = False
688 update_figfile = False
689
689
690 if not self.isConfig:
690 if not self.isConfig:
691
691
692 self.setup(id=id,
692 self.setup(id=id,
693 nplots=nplots,
693 nplots=nplots,
694 wintitle=wintitle,
694 wintitle=wintitle,
695 showprofile=showprofile,
695 showprofile=showprofile,
696 show=show)
696 show=show)
697
697
698 if timerange is not None:
698 if timerange is not None:
699 self.timerange = timerange
699 self.timerange = timerange
700
700
701 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
701 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
702
702
703 if ymin == None: ymin = numpy.nanmin(y)
703 if ymin == None: ymin = numpy.nanmin(y)
704 if ymax == None: ymax = numpy.nanmax(y)
704 if ymax == None: ymax = numpy.nanmax(y)
705
705
706 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
706 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
707 #if numpy.isnan(zmax): zmax = 50
707 #if numpy.isnan(zmax): zmax = 50
708 if zmin == None: zmin = -zmax
708 if zmin == None: zmin = -zmax
709
709
710 if nplotsw == 3:
710 if nplotsw == 3:
711 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
711 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
712 if zmin_ver == None: zmin_ver = -zmax_ver
712 if zmin_ver == None: zmin_ver = -zmax_ver
713
713
714 if dataOut.data_SNR is not None:
714 if dataOut.data_SNR is not None:
715 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
715 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
716 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
716 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
717
717
718
718
719 self.FTP_WEI = ftp_wei
719 self.FTP_WEI = ftp_wei
720 self.EXP_CODE = exp_code
720 self.EXP_CODE = exp_code
721 self.SUB_EXP_CODE = sub_exp_code
721 self.SUB_EXP_CODE = sub_exp_code
722 self.PLOT_POS = plot_pos
722 self.PLOT_POS = plot_pos
723
723
724 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
724 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
725 self.isConfig = True
725 self.isConfig = True
726 self.figfile = figfile
726 self.figfile = figfile
727 update_figfile = True
727 update_figfile = True
728
728
729 self.setWinTitle(title)
729 self.setWinTitle(title)
730
730
731 if ((self.xmax - x[1]) < (x[1]-x[0])):
731 if ((self.xmax - x[1]) < (x[1]-x[0])):
732 x[1] = self.xmax
732 x[1] = self.xmax
733
733
734 strWind = ['Zonal', 'Meridional', 'Vertical']
734 strWind = ['Zonal', 'Meridional', 'Vertical']
735 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
735 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
736 zmaxVector = [zmax, zmax, zmax_ver]
736 zmaxVector = [zmax, zmax, zmax_ver]
737 zminVector = [zmin, zmin, zmin_ver]
737 zminVector = [zmin, zmin, zmin_ver]
738 windFactor = [1,1,100]
738 windFactor = [1,1,100]
739
739
740 for i in range(nplotsw):
740 for i in range(nplotsw):
741
741
742 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
743 axes = self.axesList[i*self.__nsubplots]
743 axes = self.axesList[i*self.__nsubplots]
744
744
745 z1 = z[i,:].reshape((1,-1))*windFactor[i]
745 z1 = z[i,:].reshape((1,-1))*windFactor[i]
746
746
747 print 'x', x
747 print 'x', x
748 print datetime.datetime.utcfromtimestamp(x[0])
748 print datetime.datetime.utcfromtimestamp(x[0])
749 print datetime.datetime.utcfromtimestamp(x[1])
749 print datetime.datetime.utcfromtimestamp(x[1])
750
750
751 #z1=numpy.ma.masked_where(z1==0.,z1)
751 #z1=numpy.ma.masked_where(z1==0.,z1)
752
752
753 axes.pcolorbuffer(x, y, z1,
753 axes.pcolorbuffer(x, y, z1,
754 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
754 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
755 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
755 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
756 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
756 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
757
757
758 if dataOut.data_SNR is not None:
758 if dataOut.data_SNR is not None:
759 i += 1
759 i += 1
760 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
760 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
761 axes = self.axesList[i*self.__nsubplots]
761 axes = self.axesList[i*self.__nsubplots]
762 SNRavgdB = SNRavgdB.reshape((1,-1))
762 SNRavgdB = SNRavgdB.reshape((1,-1))
763 axes.pcolorbuffer(x, y, SNRavgdB,
763 axes.pcolorbuffer(x, y, SNRavgdB,
764 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
764 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
765 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
765 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
766 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
766 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
767
767
768 self.draw()
768 self.draw()
769
769
770 self.save(figpath=figpath,
770 self.save(figpath=figpath,
771 figfile=figfile,
771 figfile=figfile,
772 save=save,
772 save=save,
773 ftp=ftp,
773 ftp=ftp,
774 wr_period=wr_period,
774 wr_period=wr_period,
775 thisDatetime=thisDatetime,
775 thisDatetime=thisDatetime,
776 update_figfile=update_figfile)
776 update_figfile=update_figfile)
777
777
778 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
778 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
779 self.counter_imagwr = wr_period
779 self.counter_imagwr = wr_period
780 self.isConfig = False
780 self.isConfig = False
781 update_figfile = True
781 update_figfile = True
782
782
783
783
784 class ParametersPlot(Figure):
784 class ParametersPlot(Figure):
785
785
786 __isConfig = None
786 __isConfig = None
787 __nsubplots = None
787 __nsubplots = None
788
788
789 WIDTHPROF = None
789 WIDTHPROF = None
790 HEIGHTPROF = None
790 HEIGHTPROF = None
791 PREFIX = 'param'
791 PREFIX = 'param'
792
792
793 nplots = None
793 nplots = None
794 nchan = None
794 nchan = None
795
795
796 def __init__(self, **kwargs):
796 def __init__(self, **kwargs):
797 Figure.__init__(self, **kwargs)
797 Figure.__init__(self, **kwargs)
798 self.timerange = None
798 self.timerange = None
799 self.isConfig = False
799 self.isConfig = False
800 self.__nsubplots = 1
800 self.__nsubplots = 1
801
801
802 self.WIDTH = 800
802 self.WIDTH = 800
803 self.HEIGHT = 180
803 self.HEIGHT = 180
804 self.WIDTHPROF = 120
804 self.WIDTHPROF = 120
805 self.HEIGHTPROF = 0
805 self.HEIGHTPROF = 0
806 self.counter_imagwr = 0
806 self.counter_imagwr = 0
807
807
808 self.PLOT_CODE = RTI_CODE
808 self.PLOT_CODE = RTI_CODE
809
809
810 self.FTP_WEI = None
810 self.FTP_WEI = None
811 self.EXP_CODE = None
811 self.EXP_CODE = None
812 self.SUB_EXP_CODE = None
812 self.SUB_EXP_CODE = None
813 self.PLOT_POS = None
813 self.PLOT_POS = None
814 self.tmin = None
814 self.tmin = None
815 self.tmax = None
815 self.tmax = None
816
816
817 self.xmin = None
817 self.xmin = None
818 self.xmax = None
818 self.xmax = None
819
819
820 self.figfile = None
820 self.figfile = None
821
821
822 def getSubplots(self):
822 def getSubplots(self):
823
823
824 ncol = 1
824 ncol = 1
825 nrow = self.nplots
825 nrow = self.nplots
826
826
827 return nrow, ncol
827 return nrow, ncol
828
828
829 def setup(self, id, nplots, wintitle, show=True):
829 def setup(self, id, nplots, wintitle, show=True):
830
830
831 self.nplots = nplots
831 self.nplots = nplots
832
832
833 ncolspan = 1
833 ncolspan = 1
834 colspan = 1
834 colspan = 1
835
835
836 self.createFigure(id = id,
836 self.createFigure(id = id,
837 wintitle = wintitle,
837 wintitle = wintitle,
838 widthplot = self.WIDTH + self.WIDTHPROF,
838 widthplot = self.WIDTH + self.WIDTHPROF,
839 heightplot = self.HEIGHT + self.HEIGHTPROF,
839 heightplot = self.HEIGHT + self.HEIGHTPROF,
840 show=show)
840 show=show)
841
841
842 nrow, ncol = self.getSubplots()
842 nrow, ncol = self.getSubplots()
843
843
844 counter = 0
844 counter = 0
845 for y in range(nrow):
845 for y in range(nrow):
846 for x in range(ncol):
846 for x in range(ncol):
847
847
848 if counter >= self.nplots:
848 if counter >= self.nplots:
849 break
849 break
850
850
851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
852
852
853 counter += 1
853 counter += 1
854
854
855 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
855 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
857 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
857 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
858 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
858 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
859 server=None, folder=None, username=None, password=None,
859 server=None, folder=None, username=None, password=None,
860 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
860 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
861 """
861 """
862
862
863 Input:
863 Input:
864 dataOut :
864 dataOut :
865 id :
865 id :
866 wintitle :
866 wintitle :
867 channelList :
867 channelList :
868 showProfile :
868 showProfile :
869 xmin : None,
869 xmin : None,
870 xmax : None,
870 xmax : None,
871 ymin : None,
871 ymin : None,
872 ymax : None,
872 ymax : None,
873 zmin : None,
873 zmin : None,
874 zmax : None
874 zmax : None
875 """
875 """
876
876
877 if HEIGHT is not None:
877 if HEIGHT is not None:
878 self.HEIGHT = HEIGHT
878 self.HEIGHT = HEIGHT
879
879
880
880
881 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
881 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
882 return
882 return
883
883
884 if channelList == None:
884 if channelList == None:
885 channelIndexList = range(dataOut.data_param.shape[0])
885 channelIndexList = range(dataOut.data_param.shape[0])
886 else:
886 else:
887 channelIndexList = []
887 channelIndexList = []
888 for channel in channelList:
888 for channel in channelList:
889 if channel not in dataOut.channelList:
889 if channel not in dataOut.channelList:
890 raise ValueError, "Channel %d is not in dataOut.channelList"
890 raise ValueError, "Channel %d is not in dataOut.channelList"
891 channelIndexList.append(dataOut.channelList.index(channel))
891 channelIndexList.append(dataOut.channelList.index(channel))
892
892
893 x = dataOut.getTimeRange1(dataOut.paramInterval)
893 x = dataOut.getTimeRange1(dataOut.paramInterval)
894 y = dataOut.getHeiRange()
894 y = dataOut.getHeiRange()
895
895
896 if dataOut.data_param.ndim == 3:
896 if dataOut.data_param.ndim == 3:
897 z = dataOut.data_param[channelIndexList,paramIndex,:]
897 z = dataOut.data_param[channelIndexList,paramIndex,:]
898 else:
898 else:
899 z = dataOut.data_param[channelIndexList,:]
899 z = dataOut.data_param[channelIndexList,:]
900
900
901 if showSNR:
901 if showSNR:
902 #SNR data
902 #SNR data
903 SNRarray = dataOut.data_SNR[channelIndexList,:]
903 SNRarray = dataOut.data_SNR[channelIndexList,:]
904 SNRdB = 10*numpy.log10(SNRarray)
904 SNRdB = 10*numpy.log10(SNRarray)
905 ind = numpy.where(SNRdB < SNRthresh)
905 ind = numpy.where(SNRdB < SNRthresh)
906 z[ind] = numpy.nan
906 z[ind] = numpy.nan
907
907
908 thisDatetime = dataOut.datatime
908 thisDatetime = dataOut.datatime
909 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
909 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
910 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
910 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
911 xlabel = ""
911 xlabel = ""
912 ylabel = "Range (Km)"
912 ylabel = "Range (Km)"
913
913
914 update_figfile = False
914 update_figfile = False
915
915
916 if not self.isConfig:
916 if not self.isConfig:
917
917
918 nchan = len(channelIndexList)
918 nchan = len(channelIndexList)
919 self.nchan = nchan
919 self.nchan = nchan
920 self.plotFact = 1
920 self.plotFact = 1
921 nplots = nchan
921 nplots = nchan
922
922
923 if showSNR:
923 if showSNR:
924 nplots = nchan*2
924 nplots = nchan*2
925 self.plotFact = 2
925 self.plotFact = 2
926 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
926 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
927 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
927 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
928
928
929 self.setup(id=id,
929 self.setup(id=id,
930 nplots=nplots,
930 nplots=nplots,
931 wintitle=wintitle,
931 wintitle=wintitle,
932 show=show)
932 show=show)
933
933
934 if timerange != None:
934 if timerange != None:
935 self.timerange = timerange
935 self.timerange = timerange
936
936
937 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
937 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
938
938
939 if ymin == None: ymin = numpy.nanmin(y)
939 if ymin == None: ymin = numpy.nanmin(y)
940 if ymax == None: ymax = numpy.nanmax(y)
940 if ymax == None: ymax = numpy.nanmax(y)
941 if zmin == None: zmin = numpy.nanmin(z)
941 if zmin == None: zmin = numpy.nanmin(z)
942 if zmax == None: zmax = numpy.nanmax(z)
942 if zmax == None: zmax = numpy.nanmax(z)
943
943
944 self.FTP_WEI = ftp_wei
944 self.FTP_WEI = ftp_wei
945 self.EXP_CODE = exp_code
945 self.EXP_CODE = exp_code
946 self.SUB_EXP_CODE = sub_exp_code
946 self.SUB_EXP_CODE = sub_exp_code
947 self.PLOT_POS = plot_pos
947 self.PLOT_POS = plot_pos
948
948
949 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
949 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
950 self.isConfig = True
950 self.isConfig = True
951 self.figfile = figfile
951 self.figfile = figfile
952 update_figfile = True
952 update_figfile = True
953
953
954 self.setWinTitle(title)
954 self.setWinTitle(title)
955
955
956 for i in range(self.nchan):
956 for i in range(self.nchan):
957 index = channelIndexList[i]
957 index = channelIndexList[i]
958 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
958 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
959 axes = self.axesList[i*self.plotFact]
959 axes = self.axesList[i*self.plotFact]
960 z1 = z[i,:].reshape((1,-1))
960 z1 = z[i,:].reshape((1,-1))
961 axes.pcolorbuffer(x, y, z1,
961 axes.pcolorbuffer(x, y, z1,
962 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
962 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
963 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
963 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
964 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
964 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
965
965
966 if showSNR:
966 if showSNR:
967 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
967 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
968 axes = self.axesList[i*self.plotFact + 1]
968 axes = self.axesList[i*self.plotFact + 1]
969 SNRdB1 = SNRdB[i,:].reshape((1,-1))
969 SNRdB1 = SNRdB[i,:].reshape((1,-1))
970 axes.pcolorbuffer(x, y, SNRdB1,
970 axes.pcolorbuffer(x, y, SNRdB1,
971 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
971 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
972 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
972 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
973 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
973 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
974
974
975
975
976 self.draw()
976 self.draw()
977
977
978 if dataOut.ltctime >= self.xmax:
978 if dataOut.ltctime >= self.xmax:
979 self.counter_imagwr = wr_period
979 self.counter_imagwr = wr_period
980 self.isConfig = False
980 self.isConfig = False
981 update_figfile = True
981 update_figfile = True
982
982
983 self.save(figpath=figpath,
983 self.save(figpath=figpath,
984 figfile=figfile,
984 figfile=figfile,
985 save=save,
985 save=save,
986 ftp=ftp,
986 ftp=ftp,
987 wr_period=wr_period,
987 wr_period=wr_period,
988 thisDatetime=thisDatetime,
988 thisDatetime=thisDatetime,
989 update_figfile=update_figfile)
989 update_figfile=update_figfile)
990
990
991
991
992
992
993 class Parameters1Plot(Figure):
993 class Parameters1Plot(Figure):
994
994
995 __isConfig = None
995 __isConfig = None
996 __nsubplots = None
996 __nsubplots = None
997
997
998 WIDTHPROF = None
998 WIDTHPROF = None
999 HEIGHTPROF = None
999 HEIGHTPROF = None
1000 PREFIX = 'prm'
1000 PREFIX = 'prm'
1001
1001
1002 def __init__(self, **kwargs):
1002 def __init__(self, **kwargs):
1003 Figure.__init__(self, **kwargs)
1003 Figure.__init__(self, **kwargs)
1004 self.timerange = 2*60*60
1004 self.timerange = 2*60*60
1005 self.isConfig = False
1005 self.isConfig = False
1006 self.__nsubplots = 1
1006 self.__nsubplots = 1
1007
1007
1008 self.WIDTH = 800
1008 self.WIDTH = 800
1009 self.HEIGHT = 180
1009 self.HEIGHT = 180
1010 self.WIDTHPROF = 120
1010 self.WIDTHPROF = 120
1011 self.HEIGHTPROF = 0
1011 self.HEIGHTPROF = 0
1012 self.counter_imagwr = 0
1012 self.counter_imagwr = 0
1013
1013
1014 self.PLOT_CODE = PARMS_CODE
1014 self.PLOT_CODE = PARMS_CODE
1015
1015
1016 self.FTP_WEI = None
1016 self.FTP_WEI = None
1017 self.EXP_CODE = None
1017 self.EXP_CODE = None
1018 self.SUB_EXP_CODE = None
1018 self.SUB_EXP_CODE = None
1019 self.PLOT_POS = None
1019 self.PLOT_POS = None
1020 self.tmin = None
1020 self.tmin = None
1021 self.tmax = None
1021 self.tmax = None
1022
1022
1023 self.xmin = None
1023 self.xmin = None
1024 self.xmax = None
1024 self.xmax = None
1025
1025
1026 self.figfile = None
1026 self.figfile = None
1027
1027
1028 def getSubplots(self):
1028 def getSubplots(self):
1029
1029
1030 ncol = 1
1030 ncol = 1
1031 nrow = self.nplots
1031 nrow = self.nplots
1032
1032
1033 return nrow, ncol
1033 return nrow, ncol
1034
1034
1035 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1035 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1036
1036
1037 self.__showprofile = showprofile
1037 self.__showprofile = showprofile
1038 self.nplots = nplots
1038 self.nplots = nplots
1039
1039
1040 ncolspan = 1
1040 ncolspan = 1
1041 colspan = 1
1041 colspan = 1
1042
1042
1043 self.createFigure(id = id,
1043 self.createFigure(id = id,
1044 wintitle = wintitle,
1044 wintitle = wintitle,
1045 widthplot = self.WIDTH + self.WIDTHPROF,
1045 widthplot = self.WIDTH + self.WIDTHPROF,
1046 heightplot = self.HEIGHT + self.HEIGHTPROF,
1046 heightplot = self.HEIGHT + self.HEIGHTPROF,
1047 show=show)
1047 show=show)
1048
1048
1049 nrow, ncol = self.getSubplots()
1049 nrow, ncol = self.getSubplots()
1050
1050
1051 counter = 0
1051 counter = 0
1052 for y in range(nrow):
1052 for y in range(nrow):
1053 for x in range(ncol):
1053 for x in range(ncol):
1054
1054
1055 if counter >= self.nplots:
1055 if counter >= self.nplots:
1056 break
1056 break
1057
1057
1058 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1058 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1059
1059
1060 if showprofile:
1060 if showprofile:
1061 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1061 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1062
1062
1063 counter += 1
1063 counter += 1
1064
1064
1065 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1065 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1066 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1066 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1067 parameterIndex = None, onlyPositive = False,
1067 parameterIndex = None, onlyPositive = False,
1068 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1068 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1069 DOP = True,
1069 DOP = True,
1070 zlabel = "", parameterName = "", parameterObject = "data_param",
1070 zlabel = "", parameterName = "", parameterObject = "data_param",
1071 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1071 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1072 server=None, folder=None, username=None, password=None,
1072 server=None, folder=None, username=None, password=None,
1073 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1073 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1074 #print inspect.getargspec(self.run).args
1074 #print inspect.getargspec(self.run).args
1075 """
1075 """
1076
1076
1077 Input:
1077 Input:
1078 dataOut :
1078 dataOut :
1079 id :
1079 id :
1080 wintitle :
1080 wintitle :
1081 channelList :
1081 channelList :
1082 showProfile :
1082 showProfile :
1083 xmin : None,
1083 xmin : None,
1084 xmax : None,
1084 xmax : None,
1085 ymin : None,
1085 ymin : None,
1086 ymax : None,
1086 ymax : None,
1087 zmin : None,
1087 zmin : None,
1088 zmax : None
1088 zmax : None
1089 """
1089 """
1090
1090
1091 data_param = getattr(dataOut, parameterObject)
1091 data_param = getattr(dataOut, parameterObject)
1092
1092
1093 if channelList == None:
1093 if channelList == None:
1094 channelIndexList = numpy.arange(data_param.shape[0])
1094 channelIndexList = numpy.arange(data_param.shape[0])
1095 else:
1095 else:
1096 channelIndexList = numpy.array(channelList)
1096 channelIndexList = numpy.array(channelList)
1097
1097
1098 nchan = len(channelIndexList) #Number of channels being plotted
1098 nchan = len(channelIndexList) #Number of channels being plotted
1099
1099
1100 if nchan < 1:
1100 if nchan < 1:
1101 return
1101 return
1102
1102
1103 nGraphsByChannel = 0
1103 nGraphsByChannel = 0
1104
1104
1105 if SNR:
1105 if SNR:
1106 nGraphsByChannel += 1
1106 nGraphsByChannel += 1
1107 if DOP:
1107 if DOP:
1108 nGraphsByChannel += 1
1108 nGraphsByChannel += 1
1109
1109
1110 if nGraphsByChannel < 1:
1110 if nGraphsByChannel < 1:
1111 return
1111 return
1112
1112
1113 nplots = nGraphsByChannel*nchan
1113 nplots = nGraphsByChannel*nchan
1114
1114
1115 if timerange is not None:
1115 if timerange is not None:
1116 self.timerange = timerange
1116 self.timerange = timerange
1117
1117
1118 #tmin = None
1118 #tmin = None
1119 #tmax = None
1119 #tmax = None
1120 if parameterIndex == None:
1120 if parameterIndex == None:
1121 parameterIndex = 1
1121 parameterIndex = 1
1122
1122
1123 x = dataOut.getTimeRange1(dataOut.paramInterval)
1123 x = dataOut.getTimeRange1(dataOut.paramInterval)
1124 y = dataOut.heightList
1124 y = dataOut.heightList
1125 z = data_param[channelIndexList,parameterIndex,:].copy()
1125 z = data_param[channelIndexList,parameterIndex,:].copy()
1126
1126
1127 zRange = dataOut.abscissaList
1127 zRange = dataOut.abscissaList
1128 # nChannels = z.shape[0] #Number of wind dimensions estimated
1128 # nChannels = z.shape[0] #Number of wind dimensions estimated
1129 # thisDatetime = dataOut.datatime
1129 # thisDatetime = dataOut.datatime
1130
1130
1131 if dataOut.data_SNR is not None:
1131 if dataOut.data_SNR is not None:
1132 SNRarray = dataOut.data_SNR[channelIndexList,:]
1132 SNRarray = dataOut.data_SNR[channelIndexList,:]
1133 SNRdB = 10*numpy.log10(SNRarray)
1133 SNRdB = 10*numpy.log10(SNRarray)
1134 # SNRavgdB = 10*numpy.log10(SNRavg)
1134 # SNRavgdB = 10*numpy.log10(SNRavg)
1135 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1135 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1136 z[ind] = numpy.nan
1136 z[ind] = numpy.nan
1137
1137
1138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1139 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1139 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1140 xlabel = ""
1140 xlabel = ""
1141 ylabel = "Range (Km)"
1141 ylabel = "Range (Km)"
1142
1142
1143 if (SNR and not onlySNR): nplots = 2*nplots
1143 if (SNR and not onlySNR): nplots = 2*nplots
1144
1144
1145 if onlyPositive:
1145 if onlyPositive:
1146 colormap = "jet"
1146 colormap = "jet"
1147 zmin = 0
1147 zmin = 0
1148 else: colormap = "RdBu_r"
1148 else: colormap = "RdBu_r"
1149
1149
1150 if not self.isConfig:
1150 if not self.isConfig:
1151
1151
1152 self.setup(id=id,
1152 self.setup(id=id,
1153 nplots=nplots,
1153 nplots=nplots,
1154 wintitle=wintitle,
1154 wintitle=wintitle,
1155 showprofile=showprofile,
1155 showprofile=showprofile,
1156 show=show)
1156 show=show)
1157
1157
1158 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1158 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1159
1159
1160 if ymin == None: ymin = numpy.nanmin(y)
1160 if ymin == None: ymin = numpy.nanmin(y)
1161 if ymax == None: ymax = numpy.nanmax(y)
1161 if ymax == None: ymax = numpy.nanmax(y)
1162 if zmin == None: zmin = numpy.nanmin(zRange)
1162 if zmin == None: zmin = numpy.nanmin(zRange)
1163 if zmax == None: zmax = numpy.nanmax(zRange)
1163 if zmax == None: zmax = numpy.nanmax(zRange)
1164
1164
1165 if SNR:
1165 if SNR:
1166 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1166 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1167 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1167 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1168
1168
1169 self.FTP_WEI = ftp_wei
1169 self.FTP_WEI = ftp_wei
1170 self.EXP_CODE = exp_code
1170 self.EXP_CODE = exp_code
1171 self.SUB_EXP_CODE = sub_exp_code
1171 self.SUB_EXP_CODE = sub_exp_code
1172 self.PLOT_POS = plot_pos
1172 self.PLOT_POS = plot_pos
1173
1173
1174 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1174 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1175 self.isConfig = True
1175 self.isConfig = True
1176 self.figfile = figfile
1176 self.figfile = figfile
1177
1177
1178 self.setWinTitle(title)
1178 self.setWinTitle(title)
1179
1179
1180 if ((self.xmax - x[1]) < (x[1]-x[0])):
1180 if ((self.xmax - x[1]) < (x[1]-x[0])):
1181 x[1] = self.xmax
1181 x[1] = self.xmax
1182
1182
1183 for i in range(nchan):
1183 for i in range(nchan):
1184
1184
1185 if (SNR and not onlySNR): j = 2*i
1185 if (SNR and not onlySNR): j = 2*i
1186 else: j = i
1186 else: j = i
1187
1187
1188 j = nGraphsByChannel*i
1188 j = nGraphsByChannel*i
1189
1189
1190 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1190 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1191 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1191 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1192
1192
1193 if not onlySNR:
1193 if not onlySNR:
1194 axes = self.axesList[j*self.__nsubplots]
1194 axes = self.axesList[j*self.__nsubplots]
1195 z1 = z[i,:].reshape((1,-1))
1195 z1 = z[i,:].reshape((1,-1))
1196 axes.pcolorbuffer(x, y, z1,
1196 axes.pcolorbuffer(x, y, z1,
1197 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1197 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1198 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1198 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1199 ticksize=9, cblabel=zlabel, cbsize="1%")
1199 ticksize=9, cblabel=zlabel, cbsize="1%")
1200
1200
1201 if DOP:
1201 if DOP:
1202 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1202 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1203
1203
1204 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1204 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1205 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1205 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1206 axes = self.axesList[j]
1206 axes = self.axesList[j]
1207 z1 = z[i,:].reshape((1,-1))
1207 z1 = z[i,:].reshape((1,-1))
1208 axes.pcolorbuffer(x, y, z1,
1208 axes.pcolorbuffer(x, y, z1,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1210 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1210 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1211 ticksize=9, cblabel=zlabel, cbsize="1%")
1211 ticksize=9, cblabel=zlabel, cbsize="1%")
1212
1212
1213 if SNR:
1213 if SNR:
1214 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1214 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1215 axes = self.axesList[(j)*self.__nsubplots]
1215 axes = self.axesList[(j)*self.__nsubplots]
1216 if not onlySNR:
1216 if not onlySNR:
1217 axes = self.axesList[(j + 1)*self.__nsubplots]
1217 axes = self.axesList[(j + 1)*self.__nsubplots]
1218
1218
1219 axes = self.axesList[(j + nGraphsByChannel-1)]
1219 axes = self.axesList[(j + nGraphsByChannel-1)]
1220
1220
1221 z1 = SNRdB[i,:].reshape((1,-1))
1221 z1 = SNRdB[i,:].reshape((1,-1))
1222 axes.pcolorbuffer(x, y, z1,
1222 axes.pcolorbuffer(x, y, z1,
1223 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1223 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1224 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1224 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1225 ticksize=9, cblabel=zlabel, cbsize="1%")
1225 ticksize=9, cblabel=zlabel, cbsize="1%")
1226
1226
1227
1227
1228
1228
1229 self.draw()
1229 self.draw()
1230
1230
1231 if x[1] >= self.axesList[0].xmax:
1231 if x[1] >= self.axesList[0].xmax:
1232 self.counter_imagwr = wr_period
1232 self.counter_imagwr = wr_period
1233 self.isConfig = False
1233 self.isConfig = False
1234 self.figfile = None
1234 self.figfile = None
1235
1235
1236 self.save(figpath=figpath,
1236 self.save(figpath=figpath,
1237 figfile=figfile,
1237 figfile=figfile,
1238 save=save,
1238 save=save,
1239 ftp=ftp,
1239 ftp=ftp,
1240 wr_period=wr_period,
1240 wr_period=wr_period,
1241 thisDatetime=thisDatetime,
1241 thisDatetime=thisDatetime,
1242 update_figfile=False)
1242 update_figfile=False)
1243
1243
1244 class SpectralFittingPlot(Figure):
1244 class SpectralFittingPlot(Figure):
1245
1245
1246 __isConfig = None
1246 __isConfig = None
1247 __nsubplots = None
1247 __nsubplots = None
1248
1248
1249 WIDTHPROF = None
1249 WIDTHPROF = None
1250 HEIGHTPROF = None
1250 HEIGHTPROF = None
1251 PREFIX = 'prm'
1251 PREFIX = 'prm'
1252
1252
1253
1253
1254 N = None
1254 N = None
1255 ippSeconds = None
1255 ippSeconds = None
1256
1256
1257 def __init__(self, **kwargs):
1257 def __init__(self, **kwargs):
1258 Figure.__init__(self, **kwargs)
1258 Figure.__init__(self, **kwargs)
1259 self.isConfig = False
1259 self.isConfig = False
1260 self.__nsubplots = 1
1260 self.__nsubplots = 1
1261
1261
1262 self.PLOT_CODE = SPECFIT_CODE
1262 self.PLOT_CODE = SPECFIT_CODE
1263
1263
1264 self.WIDTH = 450
1264 self.WIDTH = 450
1265 self.HEIGHT = 250
1265 self.HEIGHT = 250
1266 self.WIDTHPROF = 0
1266 self.WIDTHPROF = 0
1267 self.HEIGHTPROF = 0
1267 self.HEIGHTPROF = 0
1268
1268
1269 def getSubplots(self):
1269 def getSubplots(self):
1270
1270
1271 ncol = int(numpy.sqrt(self.nplots)+0.9)
1271 ncol = int(numpy.sqrt(self.nplots)+0.9)
1272 nrow = int(self.nplots*1./ncol + 0.9)
1272 nrow = int(self.nplots*1./ncol + 0.9)
1273
1273
1274 return nrow, ncol
1274 return nrow, ncol
1275
1275
1276 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1276 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1277
1277
1278 showprofile = False
1278 showprofile = False
1279 self.__showprofile = showprofile
1279 self.__showprofile = showprofile
1280 self.nplots = nplots
1280 self.nplots = nplots
1281
1281
1282 ncolspan = 5
1282 ncolspan = 5
1283 colspan = 4
1283 colspan = 4
1284 if showprofile:
1284 if showprofile:
1285 ncolspan = 5
1285 ncolspan = 5
1286 colspan = 4
1286 colspan = 4
1287 self.__nsubplots = 2
1287 self.__nsubplots = 2
1288
1288
1289 self.createFigure(id = id,
1289 self.createFigure(id = id,
1290 wintitle = wintitle,
1290 wintitle = wintitle,
1291 widthplot = self.WIDTH + self.WIDTHPROF,
1291 widthplot = self.WIDTH + self.WIDTHPROF,
1292 heightplot = self.HEIGHT + self.HEIGHTPROF,
1292 heightplot = self.HEIGHT + self.HEIGHTPROF,
1293 show=show)
1293 show=show)
1294
1294
1295 nrow, ncol = self.getSubplots()
1295 nrow, ncol = self.getSubplots()
1296
1296
1297 counter = 0
1297 counter = 0
1298 for y in range(nrow):
1298 for y in range(nrow):
1299 for x in range(ncol):
1299 for x in range(ncol):
1300
1300
1301 if counter >= self.nplots:
1301 if counter >= self.nplots:
1302 break
1302 break
1303
1303
1304 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1304 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1305
1305
1306 if showprofile:
1306 if showprofile:
1307 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1307 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1308
1308
1309 counter += 1
1309 counter += 1
1310
1310
1311 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1311 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1312 xmin=None, xmax=None, ymin=None, ymax=None,
1312 xmin=None, xmax=None, ymin=None, ymax=None,
1313 save=False, figpath='./', figfile=None, show=True):
1313 save=False, figpath='./', figfile=None, show=True):
1314
1314
1315 """
1315 """
1316
1316
1317 Input:
1317 Input:
1318 dataOut :
1318 dataOut :
1319 id :
1319 id :
1320 wintitle :
1320 wintitle :
1321 channelList :
1321 channelList :
1322 showProfile :
1322 showProfile :
1323 xmin : None,
1323 xmin : None,
1324 xmax : None,
1324 xmax : None,
1325 zmin : None,
1325 zmin : None,
1326 zmax : None
1326 zmax : None
1327 """
1327 """
1328
1328
1329 if cutHeight==None:
1329 if cutHeight==None:
1330 h=270
1330 h=270
1331 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1331 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1332 cutHeight = dataOut.heightList[heightindex]
1332 cutHeight = dataOut.heightList[heightindex]
1333
1333
1334 factor = dataOut.normFactor
1334 factor = dataOut.normFactor
1335 x = dataOut.abscissaList[:-1]
1335 x = dataOut.abscissaList[:-1]
1336 #y = dataOut.getHeiRange()
1336 #y = dataOut.getHeiRange()
1337
1337
1338 z = dataOut.data_pre[:,:,heightindex]/factor
1338 z = dataOut.data_pre[:,:,heightindex]/factor
1339 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1339 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1340 avg = numpy.average(z, axis=1)
1340 avg = numpy.average(z, axis=1)
1341 listChannels = z.shape[0]
1341 listChannels = z.shape[0]
1342
1342
1343 #Reconstruct Function
1343 #Reconstruct Function
1344 if fit==True:
1344 if fit==True:
1345 groupArray = dataOut.groupList
1345 groupArray = dataOut.groupList
1346 listChannels = groupArray.reshape((groupArray.size))
1346 listChannels = groupArray.reshape((groupArray.size))
1347 listChannels.sort()
1347 listChannels.sort()
1348 spcFitLine = numpy.zeros(z.shape)
1348 spcFitLine = numpy.zeros(z.shape)
1349 constants = dataOut.constants
1349 constants = dataOut.constants
1350
1350
1351 nGroups = groupArray.shape[0]
1351 nGroups = groupArray.shape[0]
1352 nChannels = groupArray.shape[1]
1352 nChannels = groupArray.shape[1]
1353 nProfiles = z.shape[1]
1353 nProfiles = z.shape[1]
1354
1354
1355 for f in range(nGroups):
1355 for f in range(nGroups):
1356 groupChann = groupArray[f,:]
1356 groupChann = groupArray[f,:]
1357 p = dataOut.data_param[f,:,heightindex]
1357 p = dataOut.data_param[f,:,heightindex]
1358 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1358 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1359 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1359 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1360 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1360 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1361 spcFitLine[groupChann,:] = fitLineAux
1361 spcFitLine[groupChann,:] = fitLineAux
1362 # spcFitLine = spcFitLine/factor
1362 # spcFitLine = spcFitLine/factor
1363
1363
1364 z = z[listChannels,:]
1364 z = z[listChannels,:]
1365 spcFitLine = spcFitLine[listChannels,:]
1365 spcFitLine = spcFitLine[listChannels,:]
1366 spcFitLinedB = 10*numpy.log10(spcFitLine)
1366 spcFitLinedB = 10*numpy.log10(spcFitLine)
1367
1367
1368 zdB = 10*numpy.log10(z)
1368 zdB = 10*numpy.log10(z)
1369 #thisDatetime = dataOut.datatime
1369 #thisDatetime = dataOut.datatime
1370 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1370 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1371 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1371 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1372 xlabel = "Velocity (m/s)"
1372 xlabel = "Velocity (m/s)"
1373 ylabel = "Spectrum"
1373 ylabel = "Spectrum"
1374
1374
1375 if not self.isConfig:
1375 if not self.isConfig:
1376
1376
1377 nplots = listChannels.size
1377 nplots = listChannels.size
1378
1378
1379 self.setup(id=id,
1379 self.setup(id=id,
1380 nplots=nplots,
1380 nplots=nplots,
1381 wintitle=wintitle,
1381 wintitle=wintitle,
1382 showprofile=showprofile,
1382 showprofile=showprofile,
1383 show=show)
1383 show=show)
1384
1384
1385 if xmin == None: xmin = numpy.nanmin(x)
1385 if xmin == None: xmin = numpy.nanmin(x)
1386 if xmax == None: xmax = numpy.nanmax(x)
1386 if xmax == None: xmax = numpy.nanmax(x)
1387 if ymin == None: ymin = numpy.nanmin(zdB)
1387 if ymin == None: ymin = numpy.nanmin(zdB)
1388 if ymax == None: ymax = numpy.nanmax(zdB)+2
1388 if ymax == None: ymax = numpy.nanmax(zdB)+2
1389
1389
1390 self.isConfig = True
1390 self.isConfig = True
1391
1391
1392 self.setWinTitle(title)
1392 self.setWinTitle(title)
1393 for i in range(self.nplots):
1393 for i in range(self.nplots):
1394 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1394 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1395 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1395 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1396 axes = self.axesList[i*self.__nsubplots]
1396 axes = self.axesList[i*self.__nsubplots]
1397 if fit == False:
1397 if fit == False:
1398 axes.pline(x, zdB[i,:],
1398 axes.pline(x, zdB[i,:],
1399 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1399 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1400 xlabel=xlabel, ylabel=ylabel, title=title
1400 xlabel=xlabel, ylabel=ylabel, title=title
1401 )
1401 )
1402 if fit == True:
1402 if fit == True:
1403 fitline=spcFitLinedB[i,:]
1403 fitline=spcFitLinedB[i,:]
1404 y=numpy.vstack([zdB[i,:],fitline] )
1404 y=numpy.vstack([zdB[i,:],fitline] )
1405 legendlabels=['Data','Fitting']
1405 legendlabels=['Data','Fitting']
1406 axes.pmultilineyaxis(x, y,
1406 axes.pmultilineyaxis(x, y,
1407 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1407 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1408 xlabel=xlabel, ylabel=ylabel, title=title,
1408 xlabel=xlabel, ylabel=ylabel, title=title,
1409 legendlabels=legendlabels, marker=None,
1409 legendlabels=legendlabels, marker=None,
1410 linestyle='solid', grid='both')
1410 linestyle='solid', grid='both')
1411
1411
1412 self.draw()
1412 self.draw()
1413
1413
1414 self.save(figpath=figpath,
1414 self.save(figpath=figpath,
1415 figfile=figfile,
1415 figfile=figfile,
1416 save=save,
1416 save=save,
1417 ftp=ftp,
1417 ftp=ftp,
1418 wr_period=wr_period,
1418 wr_period=wr_period,
1419 thisDatetime=thisDatetime)
1419 thisDatetime=thisDatetime)
1420
1420
1421
1421
1422 class EWDriftsPlot(Figure):
1422 class EWDriftsPlot(Figure):
1423
1423
1424 __isConfig = None
1424 __isConfig = None
1425 __nsubplots = None
1425 __nsubplots = None
1426
1426
1427 WIDTHPROF = None
1427 WIDTHPROF = None
1428 HEIGHTPROF = None
1428 HEIGHTPROF = None
1429 PREFIX = 'drift'
1429 PREFIX = 'drift'
1430
1430
1431 def __init__(self, **kwargs):
1431 def __init__(self, **kwargs):
1432 Figure.__init__(self, **kwargs)
1432 Figure.__init__(self, **kwargs)
1433 self.timerange = 2*60*60
1433 self.timerange = 2*60*60
1434 self.isConfig = False
1434 self.isConfig = False
1435 self.__nsubplots = 1
1435 self.__nsubplots = 1
1436
1436
1437 self.WIDTH = 800
1437 self.WIDTH = 800
1438 self.HEIGHT = 150
1438 self.HEIGHT = 150
1439 self.WIDTHPROF = 120
1439 self.WIDTHPROF = 120
1440 self.HEIGHTPROF = 0
1440 self.HEIGHTPROF = 0
1441 self.counter_imagwr = 0
1441 self.counter_imagwr = 0
1442
1442
1443 self.PLOT_CODE = EWDRIFT_CODE
1443 self.PLOT_CODE = EWDRIFT_CODE
1444
1444
1445 self.FTP_WEI = None
1445 self.FTP_WEI = None
1446 self.EXP_CODE = None
1446 self.EXP_CODE = None
1447 self.SUB_EXP_CODE = None
1447 self.SUB_EXP_CODE = None
1448 self.PLOT_POS = None
1448 self.PLOT_POS = None
1449 self.tmin = None
1449 self.tmin = None
1450 self.tmax = None
1450 self.tmax = None
1451
1451
1452 self.xmin = None
1452 self.xmin = None
1453 self.xmax = None
1453 self.xmax = None
1454
1454
1455 self.figfile = None
1455 self.figfile = None
1456
1456
1457 def getSubplots(self):
1457 def getSubplots(self):
1458
1458
1459 ncol = 1
1459 ncol = 1
1460 nrow = self.nplots
1460 nrow = self.nplots
1461
1461
1462 return nrow, ncol
1462 return nrow, ncol
1463
1463
1464 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1464 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1465
1465
1466 self.__showprofile = showprofile
1466 self.__showprofile = showprofile
1467 self.nplots = nplots
1467 self.nplots = nplots
1468
1468
1469 ncolspan = 1
1469 ncolspan = 1
1470 colspan = 1
1470 colspan = 1
1471
1471
1472 self.createFigure(id = id,
1472 self.createFigure(id = id,
1473 wintitle = wintitle,
1473 wintitle = wintitle,
1474 widthplot = self.WIDTH + self.WIDTHPROF,
1474 widthplot = self.WIDTH + self.WIDTHPROF,
1475 heightplot = self.HEIGHT + self.HEIGHTPROF,
1475 heightplot = self.HEIGHT + self.HEIGHTPROF,
1476 show=show)
1476 show=show)
1477
1477
1478 nrow, ncol = self.getSubplots()
1478 nrow, ncol = self.getSubplots()
1479
1479
1480 counter = 0
1480 counter = 0
1481 for y in range(nrow):
1481 for y in range(nrow):
1482 if counter >= self.nplots:
1482 if counter >= self.nplots:
1483 break
1483 break
1484
1484
1485 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1485 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1486 counter += 1
1486 counter += 1
1487
1487
1488 def run(self, dataOut, id, wintitle="", channelList=None,
1488 def run(self, dataOut, id, wintitle="", channelList=None,
1489 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1489 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1490 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1490 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1491 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1491 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1492 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1492 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1493 server=None, folder=None, username=None, password=None,
1493 server=None, folder=None, username=None, password=None,
1494 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1494 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1495 """
1495 """
1496
1496
1497 Input:
1497 Input:
1498 dataOut :
1498 dataOut :
1499 id :
1499 id :
1500 wintitle :
1500 wintitle :
1501 channelList :
1501 channelList :
1502 showProfile :
1502 showProfile :
1503 xmin : None,
1503 xmin : None,
1504 xmax : None,
1504 xmax : None,
1505 ymin : None,
1505 ymin : None,
1506 ymax : None,
1506 ymax : None,
1507 zmin : None,
1507 zmin : None,
1508 zmax : None
1508 zmax : None
1509 """
1509 """
1510
1510
1511 if timerange is not None:
1511 if timerange is not None:
1512 self.timerange = timerange
1512 self.timerange = timerange
1513
1513
1514 tmin = None
1514 tmin = None
1515 tmax = None
1515 tmax = None
1516
1516
1517 x = dataOut.getTimeRange1(dataOut.outputInterval)
1517 x = dataOut.getTimeRange1(dataOut.outputInterval)
1518 # y = dataOut.heightList
1518 # y = dataOut.heightList
1519 y = dataOut.heightList
1519 y = dataOut.heightList
1520
1520
1521 z = dataOut.data_output
1521 z = dataOut.data_output
1522 nplots = z.shape[0] #Number of wind dimensions estimated
1522 nplots = z.shape[0] #Number of wind dimensions estimated
1523 nplotsw = nplots
1523 nplotsw = nplots
1524
1524
1525 #If there is a SNR function defined
1525 #If there is a SNR function defined
1526 if dataOut.data_SNR is not None:
1526 if dataOut.data_SNR is not None:
1527 nplots += 1
1527 nplots += 1
1528 SNR = dataOut.data_SNR
1528 SNR = dataOut.data_SNR
1529
1529
1530 if SNR_1:
1530 if SNR_1:
1531 SNR += 1
1531 SNR += 1
1532
1532
1533 SNRavg = numpy.average(SNR, axis=0)
1533 SNRavg = numpy.average(SNR, axis=0)
1534
1534
1535 SNRdB = 10*numpy.log10(SNR)
1535 SNRdB = 10*numpy.log10(SNR)
1536 SNRavgdB = 10*numpy.log10(SNRavg)
1536 SNRavgdB = 10*numpy.log10(SNRavg)
1537
1537
1538 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1538 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1539
1539
1540 for i in range(nplotsw):
1540 for i in range(nplotsw):
1541 z[i,ind] = numpy.nan
1541 z[i,ind] = numpy.nan
1542
1542
1543
1543
1544 showprofile = False
1544 showprofile = False
1545 # thisDatetime = dataOut.datatime
1545 # thisDatetime = dataOut.datatime
1546 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1546 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1547 title = wintitle + " EW Drifts"
1547 title = wintitle + " EW Drifts"
1548 xlabel = ""
1548 xlabel = ""
1549 ylabel = "Height (Km)"
1549 ylabel = "Height (Km)"
1550
1550
1551 if not self.isConfig:
1551 if not self.isConfig:
1552
1552
1553 self.setup(id=id,
1553 self.setup(id=id,
1554 nplots=nplots,
1554 nplots=nplots,
1555 wintitle=wintitle,
1555 wintitle=wintitle,
1556 showprofile=showprofile,
1556 showprofile=showprofile,
1557 show=show)
1557 show=show)
1558
1558
1559 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1559 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1560
1560
1561 if ymin == None: ymin = numpy.nanmin(y)
1561 if ymin == None: ymin = numpy.nanmin(y)
1562 if ymax == None: ymax = numpy.nanmax(y)
1562 if ymax == None: ymax = numpy.nanmax(y)
1563
1563
1564 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1564 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1565 if zminZonal == None: zminZonal = -zmaxZonal
1565 if zminZonal == None: zminZonal = -zmaxZonal
1566 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1566 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1567 if zminVertical == None: zminVertical = -zmaxVertical
1567 if zminVertical == None: zminVertical = -zmaxVertical
1568
1568
1569 if dataOut.data_SNR is not None:
1569 if dataOut.data_SNR is not None:
1570 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1570 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1571 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1571 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1572
1572
1573 self.FTP_WEI = ftp_wei
1573 self.FTP_WEI = ftp_wei
1574 self.EXP_CODE = exp_code
1574 self.EXP_CODE = exp_code
1575 self.SUB_EXP_CODE = sub_exp_code
1575 self.SUB_EXP_CODE = sub_exp_code
1576 self.PLOT_POS = plot_pos
1576 self.PLOT_POS = plot_pos
1577
1577
1578 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1578 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1579 self.isConfig = True
1579 self.isConfig = True
1580
1580
1581
1581
1582 self.setWinTitle(title)
1582 self.setWinTitle(title)
1583
1583
1584 if ((self.xmax - x[1]) < (x[1]-x[0])):
1584 if ((self.xmax - x[1]) < (x[1]-x[0])):
1585 x[1] = self.xmax
1585 x[1] = self.xmax
1586
1586
1587 strWind = ['Zonal','Vertical']
1587 strWind = ['Zonal','Vertical']
1588 strCb = 'Velocity (m/s)'
1588 strCb = 'Velocity (m/s)'
1589 zmaxVector = [zmaxZonal, zmaxVertical]
1589 zmaxVector = [zmaxZonal, zmaxVertical]
1590 zminVector = [zminZonal, zminVertical]
1590 zminVector = [zminZonal, zminVertical]
1591
1591
1592 for i in range(nplotsw):
1592 for i in range(nplotsw):
1593
1593
1594 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1594 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1595 axes = self.axesList[i*self.__nsubplots]
1595 axes = self.axesList[i*self.__nsubplots]
1596
1596
1597 z1 = z[i,:].reshape((1,-1))
1597 z1 = z[i,:].reshape((1,-1))
1598
1598
1599 axes.pcolorbuffer(x, y, z1,
1599 axes.pcolorbuffer(x, y, z1,
1600 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1600 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1601 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1601 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1602 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1602 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1603
1603
1604 if dataOut.data_SNR is not None:
1604 if dataOut.data_SNR is not None:
1605 i += 1
1605 i += 1
1606 if SNR_1:
1606 if SNR_1:
1607 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1607 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1608 else:
1608 else:
1609 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1609 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1610 axes = self.axesList[i*self.__nsubplots]
1610 axes = self.axesList[i*self.__nsubplots]
1611 SNRavgdB = SNRavgdB.reshape((1,-1))
1611 SNRavgdB = SNRavgdB.reshape((1,-1))
1612
1612
1613 axes.pcolorbuffer(x, y, SNRavgdB,
1613 axes.pcolorbuffer(x, y, SNRavgdB,
1614 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1614 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1615 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1615 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1616 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1616 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1617
1617
1618 self.draw()
1618 self.draw()
1619
1619
1620 if x[1] >= self.axesList[0].xmax:
1620 if x[1] >= self.axesList[0].xmax:
1621 self.counter_imagwr = wr_period
1621 self.counter_imagwr = wr_period
1622 self.isConfig = False
1622 self.isConfig = False
1623 self.figfile = None
1623 self.figfile = None
1624
1624
1625
1625
1626
1626
1627
1627
1628 class PhasePlot(Figure):
1628 class PhasePlot(Figure):
1629
1629
1630 __isConfig = None
1630 __isConfig = None
1631 __nsubplots = None
1631 __nsubplots = None
1632
1632
1633 PREFIX = 'mphase'
1633 PREFIX = 'mphase'
1634
1634
1635 def __init__(self, **kwargs):
1635 def __init__(self, **kwargs):
1636 Figure.__init__(self, **kwargs)
1636 Figure.__init__(self, **kwargs)
1637 self.timerange = 24*60*60
1637 self.timerange = 24*60*60
1638 self.isConfig = False
1638 self.isConfig = False
1639 self.__nsubplots = 1
1639 self.__nsubplots = 1
1640 self.counter_imagwr = 0
1640 self.counter_imagwr = 0
1641 self.WIDTH = 600
1641 self.WIDTH = 600
1642 self.HEIGHT = 300
1642 self.HEIGHT = 300
1643 self.WIDTHPROF = 120
1643 self.WIDTHPROF = 120
1644 self.HEIGHTPROF = 0
1644 self.HEIGHTPROF = 0
1645 self.xdata = None
1645 self.xdata = None
1646 self.ydata = None
1646 self.ydata = None
1647
1647
1648 self.PLOT_CODE = MPHASE_CODE
1648 self.PLOT_CODE = MPHASE_CODE
1649
1649
1650 self.FTP_WEI = None
1650 self.FTP_WEI = None
1651 self.EXP_CODE = None
1651 self.EXP_CODE = None
1652 self.SUB_EXP_CODE = None
1652 self.SUB_EXP_CODE = None
1653 self.PLOT_POS = None
1653 self.PLOT_POS = None
1654
1654
1655
1655
1656 self.filename_phase = None
1656 self.filename_phase = None
1657
1657
1658 self.figfile = None
1658 self.figfile = None
1659
1659
1660 def getSubplots(self):
1660 def getSubplots(self):
1661
1661
1662 ncol = 1
1662 ncol = 1
1663 nrow = 1
1663 nrow = 1
1664
1664
1665 return nrow, ncol
1665 return nrow, ncol
1666
1666
1667 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1667 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1668
1668
1669 self.__showprofile = showprofile
1669 self.__showprofile = showprofile
1670 self.nplots = nplots
1670 self.nplots = nplots
1671
1671
1672 ncolspan = 7
1672 ncolspan = 7
1673 colspan = 6
1673 colspan = 6
1674 self.__nsubplots = 2
1674 self.__nsubplots = 2
1675
1675
1676 self.createFigure(id = id,
1676 self.createFigure(id = id,
1677 wintitle = wintitle,
1677 wintitle = wintitle,
1678 widthplot = self.WIDTH+self.WIDTHPROF,
1678 widthplot = self.WIDTH+self.WIDTHPROF,
1679 heightplot = self.HEIGHT+self.HEIGHTPROF,
1679 heightplot = self.HEIGHT+self.HEIGHTPROF,
1680 show=show)
1680 show=show)
1681
1681
1682 nrow, ncol = self.getSubplots()
1682 nrow, ncol = self.getSubplots()
1683
1683
1684 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1684 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1685
1685
1686
1686
1687 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1687 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1688 xmin=None, xmax=None, ymin=None, ymax=None,
1688 xmin=None, xmax=None, ymin=None, ymax=None,
1689 timerange=None,
1689 timerange=None,
1690 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1690 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1691 server=None, folder=None, username=None, password=None,
1691 server=None, folder=None, username=None, password=None,
1692 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1692 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1693
1693
1694
1694
1695 tmin = None
1695 tmin = None
1696 tmax = None
1696 tmax = None
1697 x = dataOut.getTimeRange1(dataOut.outputInterval)
1697 x = dataOut.getTimeRange1(dataOut.outputInterval)
1698 y = dataOut.getHeiRange()
1698 y = dataOut.getHeiRange()
1699
1699
1700
1700
1701 #thisDatetime = dataOut.datatime
1701 #thisDatetime = dataOut.datatime
1702 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1702 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1703 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1703 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1704 xlabel = "Local Time"
1704 xlabel = "Local Time"
1705 ylabel = "Phase"
1705 ylabel = "Phase"
1706
1706
1707
1707
1708 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1708 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1709 phase_beacon = dataOut.data_output
1709 phase_beacon = dataOut.data_output
1710 update_figfile = False
1710 update_figfile = False
1711
1711
1712 if not self.isConfig:
1712 if not self.isConfig:
1713
1713
1714 self.nplots = phase_beacon.size
1714 self.nplots = phase_beacon.size
1715
1715
1716 self.setup(id=id,
1716 self.setup(id=id,
1717 nplots=self.nplots,
1717 nplots=self.nplots,
1718 wintitle=wintitle,
1718 wintitle=wintitle,
1719 showprofile=showprofile,
1719 showprofile=showprofile,
1720 show=show)
1720 show=show)
1721
1721
1722 if timerange is not None:
1722 if timerange is not None:
1723 self.timerange = timerange
1723 self.timerange = timerange
1724
1724
1725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1726
1726
1727 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1727 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1728 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1728 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1729
1729
1730 self.FTP_WEI = ftp_wei
1730 self.FTP_WEI = ftp_wei
1731 self.EXP_CODE = exp_code
1731 self.EXP_CODE = exp_code
1732 self.SUB_EXP_CODE = sub_exp_code
1732 self.SUB_EXP_CODE = sub_exp_code
1733 self.PLOT_POS = plot_pos
1733 self.PLOT_POS = plot_pos
1734
1734
1735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1736 self.isConfig = True
1736 self.isConfig = True
1737 self.figfile = figfile
1737 self.figfile = figfile
1738 self.xdata = numpy.array([])
1738 self.xdata = numpy.array([])
1739 self.ydata = numpy.array([])
1739 self.ydata = numpy.array([])
1740
1740
1741 #open file beacon phase
1741 #open file beacon phase
1742 path = '%s%03d' %(self.PREFIX, self.id)
1742 path = '%s%03d' %(self.PREFIX, self.id)
1743 beacon_file = os.path.join(path,'%s.txt'%self.name)
1743 beacon_file = os.path.join(path,'%s.txt'%self.name)
1744 self.filename_phase = os.path.join(figpath,beacon_file)
1744 self.filename_phase = os.path.join(figpath,beacon_file)
1745 update_figfile = True
1745 update_figfile = True
1746
1746
1747
1747
1748 #store data beacon phase
1748 #store data beacon phase
1749 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1749 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1750
1750
1751 self.setWinTitle(title)
1751 self.setWinTitle(title)
1752
1752
1753
1753
1754 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1754 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1755
1755
1756 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1756 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1757
1757
1758 axes = self.axesList[0]
1758 axes = self.axesList[0]
1759
1759
1760 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1760 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1761
1761
1762 if len(self.ydata)==0:
1762 if len(self.ydata)==0:
1763 self.ydata = phase_beacon.reshape(-1,1)
1763 self.ydata = phase_beacon.reshape(-1,1)
1764 else:
1764 else:
1765 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1765 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1766
1766
1767
1767
1768 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1768 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1770 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1770 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1771 XAxisAsTime=True, grid='both'
1771 XAxisAsTime=True, grid='both'
1772 )
1772 )
1773
1773
1774 self.draw()
1774 self.draw()
1775
1775
1776 self.save(figpath=figpath,
1776 self.save(figpath=figpath,
1777 figfile=figfile,
1777 figfile=figfile,
1778 save=save,
1778 save=save,
1779 ftp=ftp,
1779 ftp=ftp,
1780 wr_period=wr_period,
1780 wr_period=wr_period,
1781 thisDatetime=thisDatetime,
1781 thisDatetime=thisDatetime,
1782 update_figfile=update_figfile)
1782 update_figfile=update_figfile)
1783
1783
1784 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1784 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1785 self.counter_imagwr = wr_period
1785 self.counter_imagwr = wr_period
1786 self.isConfig = False
1786 self.isConfig = False
1787 update_figfile = True
1787 update_figfile = True
1788
1788
1789
1789
1790
1790
1791 class NSMeteorDetection1Plot(Figure):
1791 class NSMeteorDetection1Plot(Figure):
1792
1792
1793 isConfig = None
1793 isConfig = None
1794 __nsubplots = None
1794 __nsubplots = None
1795
1795
1796 WIDTHPROF = None
1796 WIDTHPROF = None
1797 HEIGHTPROF = None
1797 HEIGHTPROF = None
1798 PREFIX = 'nsm'
1798 PREFIX = 'nsm'
1799
1799
1800 zminList = None
1800 zminList = None
1801 zmaxList = None
1801 zmaxList = None
1802 cmapList = None
1802 cmapList = None
1803 titleList = None
1803 titleList = None
1804 nPairs = None
1804 nPairs = None
1805 nChannels = None
1805 nChannels = None
1806 nParam = None
1806 nParam = None
1807
1807
1808 def __init__(self, **kwargs):
1808 def __init__(self, **kwargs):
1809 Figure.__init__(self, **kwargs)
1809 Figure.__init__(self, **kwargs)
1810 self.isConfig = False
1810 self.isConfig = False
1811 self.__nsubplots = 1
1811 self.__nsubplots = 1
1812
1812
1813 self.WIDTH = 750
1813 self.WIDTH = 750
1814 self.HEIGHT = 250
1814 self.HEIGHT = 250
1815 self.WIDTHPROF = 120
1815 self.WIDTHPROF = 120
1816 self.HEIGHTPROF = 0
1816 self.HEIGHTPROF = 0
1817 self.counter_imagwr = 0
1817 self.counter_imagwr = 0
1818
1818
1819 self.PLOT_CODE = SPEC_CODE
1819 self.PLOT_CODE = SPEC_CODE
1820
1820
1821 self.FTP_WEI = None
1821 self.FTP_WEI = None
1822 self.EXP_CODE = None
1822 self.EXP_CODE = None
1823 self.SUB_EXP_CODE = None
1823 self.SUB_EXP_CODE = None
1824 self.PLOT_POS = None
1824 self.PLOT_POS = None
1825
1825
1826 self.__xfilter_ena = False
1826 self.__xfilter_ena = False
1827 self.__yfilter_ena = False
1827 self.__yfilter_ena = False
1828
1828
1829 def getSubplots(self):
1829 def getSubplots(self):
1830
1830
1831 ncol = 3
1831 ncol = 3
1832 nrow = int(numpy.ceil(self.nplots/3.0))
1832 nrow = int(numpy.ceil(self.nplots/3.0))
1833
1833
1834 return nrow, ncol
1834 return nrow, ncol
1835
1835
1836 def setup(self, id, nplots, wintitle, show=True):
1836 def setup(self, id, nplots, wintitle, show=True):
1837
1837
1838 self.nplots = nplots
1838 self.nplots = nplots
1839
1839
1840 ncolspan = 1
1840 ncolspan = 1
1841 colspan = 1
1841 colspan = 1
1842
1842
1843 self.createFigure(id = id,
1843 self.createFigure(id = id,
1844 wintitle = wintitle,
1844 wintitle = wintitle,
1845 widthplot = self.WIDTH + self.WIDTHPROF,
1845 widthplot = self.WIDTH + self.WIDTHPROF,
1846 heightplot = self.HEIGHT + self.HEIGHTPROF,
1846 heightplot = self.HEIGHT + self.HEIGHTPROF,
1847 show=show)
1847 show=show)
1848
1848
1849 nrow, ncol = self.getSubplots()
1849 nrow, ncol = self.getSubplots()
1850
1850
1851 counter = 0
1851 counter = 0
1852 for y in range(nrow):
1852 for y in range(nrow):
1853 for x in range(ncol):
1853 for x in range(ncol):
1854
1854
1855 if counter >= self.nplots:
1855 if counter >= self.nplots:
1856 break
1856 break
1857
1857
1858 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1858 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1859
1859
1860 counter += 1
1860 counter += 1
1861
1861
1862 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1862 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1863 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1863 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1864 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1864 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1865 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1865 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1866 server=None, folder=None, username=None, password=None,
1866 server=None, folder=None, username=None, password=None,
1867 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1867 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1868 xaxis="frequency"):
1868 xaxis="frequency"):
1869
1869
1870 """
1870 """
1871
1871
1872 Input:
1872 Input:
1873 dataOut :
1873 dataOut :
1874 id :
1874 id :
1875 wintitle :
1875 wintitle :
1876 channelList :
1876 channelList :
1877 showProfile :
1877 showProfile :
1878 xmin : None,
1878 xmin : None,
1879 xmax : None,
1879 xmax : None,
1880 ymin : None,
1880 ymin : None,
1881 ymax : None,
1881 ymax : None,
1882 zmin : None,
1882 zmin : None,
1883 zmax : None
1883 zmax : None
1884 """
1884 """
1885 #SEPARAR EN DOS PLOTS
1885 #SEPARAR EN DOS PLOTS
1886 nParam = dataOut.data_param.shape[1] - 3
1886 nParam = dataOut.data_param.shape[1] - 3
1887
1887
1888 utctime = dataOut.data_param[0,0]
1888 utctime = dataOut.data_param[0,0]
1889 tmet = dataOut.data_param[:,1].astype(int)
1889 tmet = dataOut.data_param[:,1].astype(int)
1890 hmet = dataOut.data_param[:,2].astype(int)
1890 hmet = dataOut.data_param[:,2].astype(int)
1891
1891
1892 x = dataOut.abscissaList
1892 x = dataOut.abscissaList
1893 y = dataOut.heightList
1893 y = dataOut.heightList
1894
1894
1895 z = numpy.zeros((nParam, y.size, x.size - 1))
1895 z = numpy.zeros((nParam, y.size, x.size - 1))
1896 z[:,:] = numpy.nan
1896 z[:,:] = numpy.nan
1897 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1897 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1898 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1898 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1899
1899
1900 xlabel = "Time (s)"
1900 xlabel = "Time (s)"
1901 ylabel = "Range (km)"
1901 ylabel = "Range (km)"
1902
1902
1903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1904
1904
1905 if not self.isConfig:
1905 if not self.isConfig:
1906
1906
1907 nplots = nParam
1907 nplots = nParam
1908
1908
1909 self.setup(id=id,
1909 self.setup(id=id,
1910 nplots=nplots,
1910 nplots=nplots,
1911 wintitle=wintitle,
1911 wintitle=wintitle,
1912 show=show)
1912 show=show)
1913
1913
1914 if xmin is None: xmin = numpy.nanmin(x)
1914 if xmin is None: xmin = numpy.nanmin(x)
1915 if xmax is None: xmax = numpy.nanmax(x)
1915 if xmax is None: xmax = numpy.nanmax(x)
1916 if ymin is None: ymin = numpy.nanmin(y)
1916 if ymin is None: ymin = numpy.nanmin(y)
1917 if ymax is None: ymax = numpy.nanmax(y)
1917 if ymax is None: ymax = numpy.nanmax(y)
1918 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1918 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1919 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1919 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1920 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1920 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1921 if vmin is None: vmin = -vmax
1921 if vmin is None: vmin = -vmax
1922 if wmin is None: wmin = 0
1922 if wmin is None: wmin = 0
1923 if wmax is None: wmax = 50
1923 if wmax is None: wmax = 50
1924
1924
1925 pairsList = dataOut.groupList
1925 pairsList = dataOut.groupList
1926 self.nPairs = len(dataOut.groupList)
1926 self.nPairs = len(dataOut.groupList)
1927
1927
1928 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1928 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1929 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1929 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1930 titleList = ["SNR","Radial Velocity","Coherence"]
1930 titleList = ["SNR","Radial Velocity","Coherence"]
1931 cmapList = ["jet","RdBu_r","jet"]
1931 cmapList = ["jet","RdBu_r","jet"]
1932
1932
1933 for i in range(self.nPairs):
1933 for i in range(self.nPairs):
1934 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1934 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1935 titleList = titleList + [strAux1]
1935 titleList = titleList + [strAux1]
1936 cmapList = cmapList + ["RdBu_r"]
1936 cmapList = cmapList + ["RdBu_r"]
1937
1937
1938 self.zminList = zminList
1938 self.zminList = zminList
1939 self.zmaxList = zmaxList
1939 self.zmaxList = zmaxList
1940 self.cmapList = cmapList
1940 self.cmapList = cmapList
1941 self.titleList = titleList
1941 self.titleList = titleList
1942
1942
1943 self.FTP_WEI = ftp_wei
1943 self.FTP_WEI = ftp_wei
1944 self.EXP_CODE = exp_code
1944 self.EXP_CODE = exp_code
1945 self.SUB_EXP_CODE = sub_exp_code
1945 self.SUB_EXP_CODE = sub_exp_code
1946 self.PLOT_POS = plot_pos
1946 self.PLOT_POS = plot_pos
1947
1947
1948 self.isConfig = True
1948 self.isConfig = True
1949
1949
1950 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1950 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1951
1951
1952 for i in range(nParam):
1952 for i in range(nParam):
1953 title = self.titleList[i] + ": " +str_datetime
1953 title = self.titleList[i] + ": " +str_datetime
1954 axes = self.axesList[i]
1954 axes = self.axesList[i]
1955 axes.pcolor(x, y, z[i,:].T,
1955 axes.pcolor(x, y, z[i,:].T,
1956 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1956 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1957 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1957 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1958 self.draw()
1958 self.draw()
1959
1959
1960 if figfile == None:
1960 if figfile == None:
1961 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1961 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1962 name = str_datetime
1962 name = str_datetime
1963 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1963 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1964 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1964 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1965 figfile = self.getFilename(name)
1965 figfile = self.getFilename(name)
1966
1966
1967 self.save(figpath=figpath,
1967 self.save(figpath=figpath,
1968 figfile=figfile,
1968 figfile=figfile,
1969 save=save,
1969 save=save,
1970 ftp=ftp,
1970 ftp=ftp,
1971 wr_period=wr_period,
1971 wr_period=wr_period,
1972 thisDatetime=thisDatetime)
1972 thisDatetime=thisDatetime)
1973
1973
1974
1974
1975 class NSMeteorDetection2Plot(Figure):
1975 class NSMeteorDetection2Plot(Figure):
1976
1976
1977 isConfig = None
1977 isConfig = None
1978 __nsubplots = None
1978 __nsubplots = None
1979
1979
1980 WIDTHPROF = None
1980 WIDTHPROF = None
1981 HEIGHTPROF = None
1981 HEIGHTPROF = None
1982 PREFIX = 'nsm'
1982 PREFIX = 'nsm'
1983
1983
1984 zminList = None
1984 zminList = None
1985 zmaxList = None
1985 zmaxList = None
1986 cmapList = None
1986 cmapList = None
1987 titleList = None
1987 titleList = None
1988 nPairs = None
1988 nPairs = None
1989 nChannels = None
1989 nChannels = None
1990 nParam = None
1990 nParam = None
1991
1991
1992 def __init__(self, **kwargs):
1992 def __init__(self, **kwargs):
1993 Figure.__init__(self, **kwargs)
1993 Figure.__init__(self, **kwargs)
1994 self.isConfig = False
1994 self.isConfig = False
1995 self.__nsubplots = 1
1995 self.__nsubplots = 1
1996
1996
1997 self.WIDTH = 750
1997 self.WIDTH = 750
1998 self.HEIGHT = 250
1998 self.HEIGHT = 250
1999 self.WIDTHPROF = 120
1999 self.WIDTHPROF = 120
2000 self.HEIGHTPROF = 0
2000 self.HEIGHTPROF = 0
2001 self.counter_imagwr = 0
2001 self.counter_imagwr = 0
2002
2002
2003 self.PLOT_CODE = SPEC_CODE
2003 self.PLOT_CODE = SPEC_CODE
2004
2004
2005 self.FTP_WEI = None
2005 self.FTP_WEI = None
2006 self.EXP_CODE = None
2006 self.EXP_CODE = None
2007 self.SUB_EXP_CODE = None
2007 self.SUB_EXP_CODE = None
2008 self.PLOT_POS = None
2008 self.PLOT_POS = None
2009
2009
2010 self.__xfilter_ena = False
2010 self.__xfilter_ena = False
2011 self.__yfilter_ena = False
2011 self.__yfilter_ena = False
2012
2012
2013 def getSubplots(self):
2013 def getSubplots(self):
2014
2014
2015 ncol = 3
2015 ncol = 3
2016 nrow = int(numpy.ceil(self.nplots/3.0))
2016 nrow = int(numpy.ceil(self.nplots/3.0))
2017
2017
2018 return nrow, ncol
2018 return nrow, ncol
2019
2019
2020 def setup(self, id, nplots, wintitle, show=True):
2020 def setup(self, id, nplots, wintitle, show=True):
2021
2021
2022 self.nplots = nplots
2022 self.nplots = nplots
2023
2023
2024 ncolspan = 1
2024 ncolspan = 1
2025 colspan = 1
2025 colspan = 1
2026
2026
2027 self.createFigure(id = id,
2027 self.createFigure(id = id,
2028 wintitle = wintitle,
2028 wintitle = wintitle,
2029 widthplot = self.WIDTH + self.WIDTHPROF,
2029 widthplot = self.WIDTH + self.WIDTHPROF,
2030 heightplot = self.HEIGHT + self.HEIGHTPROF,
2030 heightplot = self.HEIGHT + self.HEIGHTPROF,
2031 show=show)
2031 show=show)
2032
2032
2033 nrow, ncol = self.getSubplots()
2033 nrow, ncol = self.getSubplots()
2034
2034
2035 counter = 0
2035 counter = 0
2036 for y in range(nrow):
2036 for y in range(nrow):
2037 for x in range(ncol):
2037 for x in range(ncol):
2038
2038
2039 if counter >= self.nplots:
2039 if counter >= self.nplots:
2040 break
2040 break
2041
2041
2042 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2042 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2043
2043
2044 counter += 1
2044 counter += 1
2045
2045
2046 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2046 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2047 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2047 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2048 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2048 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2049 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2049 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2050 server=None, folder=None, username=None, password=None,
2050 server=None, folder=None, username=None, password=None,
2051 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2051 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2052 xaxis="frequency"):
2052 xaxis="frequency"):
2053
2053
2054 """
2054 """
2055
2055
2056 Input:
2056 Input:
2057 dataOut :
2057 dataOut :
2058 id :
2058 id :
2059 wintitle :
2059 wintitle :
2060 channelList :
2060 channelList :
2061 showProfile :
2061 showProfile :
2062 xmin : None,
2062 xmin : None,
2063 xmax : None,
2063 xmax : None,
2064 ymin : None,
2064 ymin : None,
2065 ymax : None,
2065 ymax : None,
2066 zmin : None,
2066 zmin : None,
2067 zmax : None
2067 zmax : None
2068 """
2068 """
2069 #Rebuild matrix
2069 #Rebuild matrix
2070 utctime = dataOut.data_param[0,0]
2070 utctime = dataOut.data_param[0,0]
2071 cmet = dataOut.data_param[:,1].astype(int)
2071 cmet = dataOut.data_param[:,1].astype(int)
2072 tmet = dataOut.data_param[:,2].astype(int)
2072 tmet = dataOut.data_param[:,2].astype(int)
2073 hmet = dataOut.data_param[:,3].astype(int)
2073 hmet = dataOut.data_param[:,3].astype(int)
2074
2074
2075 nParam = 3
2075 nParam = 3
2076 nChan = len(dataOut.groupList)
2076 nChan = len(dataOut.groupList)
2077 x = dataOut.abscissaList
2077 x = dataOut.abscissaList
2078 y = dataOut.heightList
2078 y = dataOut.heightList
2079
2079
2080 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2080 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2081 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2081 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2082 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2082 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2083 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2083 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2084
2084
2085 xlabel = "Time (s)"
2085 xlabel = "Time (s)"
2086 ylabel = "Range (km)"
2086 ylabel = "Range (km)"
2087
2087
2088 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2088 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2089
2089
2090 if not self.isConfig:
2090 if not self.isConfig:
2091
2091
2092 nplots = nParam*nChan
2092 nplots = nParam*nChan
2093
2093
2094 self.setup(id=id,
2094 self.setup(id=id,
2095 nplots=nplots,
2095 nplots=nplots,
2096 wintitle=wintitle,
2096 wintitle=wintitle,
2097 show=show)
2097 show=show)
2098
2098
2099 if xmin is None: xmin = numpy.nanmin(x)
2099 if xmin is None: xmin = numpy.nanmin(x)
2100 if xmax is None: xmax = numpy.nanmax(x)
2100 if xmax is None: xmax = numpy.nanmax(x)
2101 if ymin is None: ymin = numpy.nanmin(y)
2101 if ymin is None: ymin = numpy.nanmin(y)
2102 if ymax is None: ymax = numpy.nanmax(y)
2102 if ymax is None: ymax = numpy.nanmax(y)
2103 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2103 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2104 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2104 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2105 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2105 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2106 if vmin is None: vmin = -vmax
2106 if vmin is None: vmin = -vmax
2107 if wmin is None: wmin = 0
2107 if wmin is None: wmin = 0
2108 if wmax is None: wmax = 50
2108 if wmax is None: wmax = 50
2109
2109
2110 self.nChannels = nChan
2110 self.nChannels = nChan
2111
2111
2112 zminList = []
2112 zminList = []
2113 zmaxList = []
2113 zmaxList = []
2114 titleList = []
2114 titleList = []
2115 cmapList = []
2115 cmapList = []
2116 for i in range(self.nChannels):
2116 for i in range(self.nChannels):
2117 strAux1 = "SNR Channel "+ str(i)
2117 strAux1 = "SNR Channel "+ str(i)
2118 strAux2 = "Radial Velocity Channel "+ str(i)
2118 strAux2 = "Radial Velocity Channel "+ str(i)
2119 strAux3 = "Spectral Width Channel "+ str(i)
2119 strAux3 = "Spectral Width Channel "+ str(i)
2120
2120
2121 titleList = titleList + [strAux1,strAux2,strAux3]
2121 titleList = titleList + [strAux1,strAux2,strAux3]
2122 cmapList = cmapList + ["jet","RdBu_r","jet"]
2122 cmapList = cmapList + ["jet","RdBu_r","jet"]
2123 zminList = zminList + [SNRmin,vmin,wmin]
2123 zminList = zminList + [SNRmin,vmin,wmin]
2124 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2124 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2125
2125
2126 self.zminList = zminList
2126 self.zminList = zminList
2127 self.zmaxList = zmaxList
2127 self.zmaxList = zmaxList
2128 self.cmapList = cmapList
2128 self.cmapList = cmapList
2129 self.titleList = titleList
2129 self.titleList = titleList
2130
2130
2131 self.FTP_WEI = ftp_wei
2131 self.FTP_WEI = ftp_wei
2132 self.EXP_CODE = exp_code
2132 self.EXP_CODE = exp_code
2133 self.SUB_EXP_CODE = sub_exp_code
2133 self.SUB_EXP_CODE = sub_exp_code
2134 self.PLOT_POS = plot_pos
2134 self.PLOT_POS = plot_pos
2135
2135
2136 self.isConfig = True
2136 self.isConfig = True
2137
2137
2138 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2138 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2139
2139
2140 for i in range(self.nplots):
2140 for i in range(self.nplots):
2141 title = self.titleList[i] + ": " +str_datetime
2141 title = self.titleList[i] + ": " +str_datetime
2142 axes = self.axesList[i]
2142 axes = self.axesList[i]
2143 axes.pcolor(x, y, z[i,:].T,
2143 axes.pcolor(x, y, z[i,:].T,
2144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2145 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2145 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2146 self.draw()
2146 self.draw()
2147
2147
2148 if figfile == None:
2148 if figfile == None:
2149 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2149 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2150 name = str_datetime
2150 name = str_datetime
2151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2152 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2152 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2153 figfile = self.getFilename(name)
2153 figfile = self.getFilename(name)
2154
2154
2155 self.save(figpath=figpath,
2155 self.save(figpath=figpath,
2156 figfile=figfile,
2156 figfile=figfile,
2157 save=save,
2157 save=save,
2158 ftp=ftp,
2158 ftp=ftp,
2159 wr_period=wr_period,
2159 wr_period=wr_period,
2160 thisDatetime=thisDatetime)
2160 thisDatetime=thisDatetime)
@@ -1,1611 +1,1605
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 import matplotlib.pyplot as plt
10 import matplotlib.pyplot as plt
11
11
12 from figure import Figure, isRealtime, isTimeInHourRange
12 from figure import Figure, isRealtime, isTimeInHourRange
13 from plotting_codes import *
13 from plotting_codes import *
14 from matplotlib.pyplot import savefig
14 from matplotlib.pyplot import savefig
15
15
16 class SpectraPlot(Figure):
16 class SpectraPlot(Figure):
17
17
18 isConfig = None
18 isConfig = None
19 __nsubplots = None
19 __nsubplots = None
20
20
21 WIDTHPROF = None
21 WIDTHPROF = None
22 HEIGHTPROF = None
22 HEIGHTPROF = None
23 PREFIX = 'spc'
23 PREFIX = 'spc'
24
24
25 def __init__(self, **kwargs):
25 def __init__(self, **kwargs):
26 Figure.__init__(self, **kwargs)
26 Figure.__init__(self, **kwargs)
27 self.isConfig = False
27 self.isConfig = False
28 self.__nsubplots = 1
28 self.__nsubplots = 1
29
29
30 self.WIDTH = 300
30 self.WIDTH = 300
31 self.HEIGHT = 300
31 self.HEIGHT = 300
32 self.WIDTHPROF = 120
32 self.WIDTHPROF = 120
33 self.HEIGHTPROF = 0
33 self.HEIGHTPROF = 0
34 self.counter_imagwr = 0
34 self.counter_imagwr = 0
35
35
36 self.PLOT_CODE = SPEC_CODE
36 self.PLOT_CODE = SPEC_CODE
37
37
38 self.FTP_WEI = None
38 self.FTP_WEI = None
39 self.EXP_CODE = None
39 self.EXP_CODE = None
40 self.SUB_EXP_CODE = None
40 self.SUB_EXP_CODE = None
41 self.PLOT_POS = None
41 self.PLOT_POS = None
42
42
43 self.__xfilter_ena = False
43 self.__xfilter_ena = False
44 self.__yfilter_ena = False
44 self.__yfilter_ena = False
45
45
46 self.indice=1
46 self.indice=1
47
47
48 def getSubplots(self):
48 def getSubplots(self):
49
49
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
52
52
53 return nrow, ncol
53 return nrow, ncol
54
54
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
56
56
57 self.__showprofile = showprofile
57 self.__showprofile = showprofile
58 self.nplots = nplots
58 self.nplots = nplots
59
59
60 ncolspan = 1
60 ncolspan = 1
61 colspan = 1
61 colspan = 1
62 if showprofile:
62 if showprofile:
63 ncolspan = 3
63 ncolspan = 3
64 colspan = 2
64 colspan = 2
65 self.__nsubplots = 2
65 self.__nsubplots = 2
66
66
67 self.createFigure(id = id,
67 self.createFigure(id = id,
68 wintitle = wintitle,
68 wintitle = wintitle,
69 widthplot = self.WIDTH + self.WIDTHPROF,
69 widthplot = self.WIDTH + self.WIDTHPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
71 show=show)
71 show=show)
72
72
73 nrow, ncol = self.getSubplots()
73 nrow, ncol = self.getSubplots()
74
74
75 counter = 0
75 counter = 0
76 for y in range(nrow):
76 for y in range(nrow):
77 for x in range(ncol):
77 for x in range(ncol):
78
78
79 if counter >= self.nplots:
79 if counter >= self.nplots:
80 break
80 break
81
81
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
83
83
84 if showprofile:
84 if showprofile:
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
86
86
87 counter += 1
87 counter += 1
88
88
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
92 server=None, folder=None, username=None, password=None,
92 server=None, folder=None, username=None, password=None,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
94 xaxis="frequency", colormap='jet', normFactor=None):
94 xaxis="frequency", colormap='jet', normFactor=None):
95
95
96 """
96 """
97
97
98 Input:
98 Input:
99 dataOut :
99 dataOut :
100 id :
100 id :
101 wintitle :
101 wintitle :
102 channelList :
102 channelList :
103 showProfile :
103 showProfile :
104 xmin : None,
104 xmin : None,
105 xmax : None,
105 xmax : None,
106 ymin : None,
106 ymin : None,
107 ymax : None,
107 ymax : None,
108 zmin : None,
108 zmin : None,
109 zmax : None
109 zmax : None
110 """
110 """
111 if realtime:
111 if realtime:
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
113 print 'Skipping this plot function'
113 print 'Skipping this plot function'
114 return
114 return
115
115
116 if channelList == None:
116 if channelList == None:
117 channelIndexList = dataOut.channelIndexList
117 channelIndexList = dataOut.channelIndexList
118 else:
118 else:
119 channelIndexList = []
119 channelIndexList = []
120 for channel in channelList:
120 for channel in channelList:
121 if channel not in dataOut.channelList:
121 if channel not in dataOut.channelList:
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
123 channelIndexList.append(dataOut.channelList.index(channel))
123 channelIndexList.append(dataOut.channelList.index(channel))
124
124
125 if normFactor is None:
125 if normFactor is None:
126 factor = dataOut.normFactor
126 factor = dataOut.normFactor
127 else:
127 else:
128 factor = normFactor
128 factor = normFactor
129 if xaxis == "frequency":
129 if xaxis == "frequency":
130 x = dataOut.getFreqRange(1)/1000.
130 x = dataOut.getFreqRange(1)/1000.
131 print 'FRECUENCIA MAXIMA', numpy.amax(x)
132 asfasfasdfaf
133 print '#######################################################'
134 print 'xlen', len(x)
135 print x
136 print '#######################################################'
137 xlabel = "Frequency (kHz)"
131 xlabel = "Frequency (kHz)"
138
132
139 elif xaxis == "time":
133 elif xaxis == "time":
140 x = dataOut.getAcfRange(1)
134 x = dataOut.getAcfRange(1)
141 xlabel = "Time (ms)"
135 xlabel = "Time (ms)"
142
136
143 else:
137 else:
144 x = dataOut.getVelRange(1)
138 x = dataOut.getVelRange(1)
145 xlabel = "Velocity (m/s)"
139 xlabel = "Velocity (m/s)"
146
140
147 ylabel = "Range (Km)"
141 ylabel = "Range (Km)"
148
142
149 y = dataOut.getHeiRange()
143 y = dataOut.getHeiRange()
150
144
151 z = dataOut.data_spc/factor
145 z = dataOut.data_spc/factor
152 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
146 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
153 zdB = 10*numpy.log10(z)
147 zdB = 10*numpy.log10(z)
154
148
155 avg = numpy.average(z, axis=1)
149 avg = numpy.average(z, axis=1)
156 avgdB = 10*numpy.log10(avg)
150 avgdB = 10*numpy.log10(avg)
157
151
158 noise = dataOut.getNoise()/factor
152 noise = dataOut.getNoise()/factor
159 noisedB = 10*numpy.log10(noise)
153 noisedB = 10*numpy.log10(noise)
160
154
161 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
155 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
162 title = wintitle + " Spectra"
156 title = wintitle + " Spectra"
163
157
164
158
165
159
166 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
160 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
167 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
161 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
168 #a=z[1,:,15]
162 #a=z[1,:,15]
169
163
170 # fig = plt.figure(10+self.indice)
164 # fig = plt.figure(10+self.indice)
171 # plt.plot( x[0:128], zdB[0,:,10] )
165 # plt.plot( x[0:128], zdB[0,:,10] )
172 # plt.axis([-12, 12, 15, 50])
166 # plt.axis([-12, 12, 15, 50])
173 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
167 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
174 # plt.ylabel('Intensidad [dB]')
168 # plt.ylabel('Intensidad [dB]')
175 # plt.xlabel('Velocidad [m/s]')
169 # plt.xlabel('Velocidad [m/s]')
176 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
170 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
177 #
171 #
178 # plt.show()
172 # plt.show()
179 #
173 #
180 # self.indice=self.indice+1
174 # self.indice=self.indice+1
181
175
182
176
183
177
184 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
178 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
185 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
179 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
186
180
187 if not self.isConfig:
181 if not self.isConfig:
188
182
189 nplots = len(channelIndexList)
183 nplots = len(channelIndexList)
190
184
191 self.setup(id=id,
185 self.setup(id=id,
192 nplots=nplots,
186 nplots=nplots,
193 wintitle=wintitle,
187 wintitle=wintitle,
194 showprofile=showprofile,
188 showprofile=showprofile,
195 show=show)
189 show=show)
196
190
197 if xmin == None: xmin = numpy.nanmin(x)
191 if xmin == None: xmin = numpy.nanmin(x)
198 if xmax == None: xmax = numpy.nanmax(x)
192 if xmax == None: xmax = numpy.nanmax(x)
199 if ymin == None: ymin = numpy.nanmin(y)
193 if ymin == None: ymin = numpy.nanmin(y)
200 if ymax == None: ymax = numpy.nanmax(y)
194 if ymax == None: ymax = numpy.nanmax(y)
201 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
195 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
202 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
196 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
203
197
204 self.FTP_WEI = ftp_wei
198 self.FTP_WEI = ftp_wei
205 self.EXP_CODE = exp_code
199 self.EXP_CODE = exp_code
206 self.SUB_EXP_CODE = sub_exp_code
200 self.SUB_EXP_CODE = sub_exp_code
207 self.PLOT_POS = plot_pos
201 self.PLOT_POS = plot_pos
208
202
209 self.isConfig = True
203 self.isConfig = True
210
204
211 self.setWinTitle(title)
205 self.setWinTitle(title)
212
206
213 for i in range(self.nplots):
207 for i in range(self.nplots):
214 index = channelIndexList[i]
208 index = channelIndexList[i]
215 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
209 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
216 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
210 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
217 if len(dataOut.beam.codeList) != 0:
211 if len(dataOut.beam.codeList) != 0:
218 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)
212 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)
219
213
220 axes = self.axesList[i*self.__nsubplots]
214 axes = self.axesList[i*self.__nsubplots]
221 axes.pcolor(x, y, zdB[index,:,:],
215 axes.pcolor(x, y, zdB[index,:,:],
222 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
216 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
223 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
217 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
224 ticksize=9, cblabel='')
218 ticksize=9, cblabel='')
225
219
226 if self.__showprofile:
220 if self.__showprofile:
227 axes = self.axesList[i*self.__nsubplots +1]
221 axes = self.axesList[i*self.__nsubplots +1]
228 axes.pline(avgdB[index,:], y,
222 axes.pline(avgdB[index,:], y,
229 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
223 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
230 xlabel='dB', ylabel='', title='',
224 xlabel='dB', ylabel='', title='',
231 ytick_visible=False,
225 ytick_visible=False,
232 grid='x')
226 grid='x')
233
227
234 noiseline = numpy.repeat(noisedB[index], len(y))
228 noiseline = numpy.repeat(noisedB[index], len(y))
235 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
229 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
236
230
237 self.draw()
231 self.draw()
238
232
239 if figfile == None:
233 if figfile == None:
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
234 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
241 name = str_datetime
235 name = str_datetime
242 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
236 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
243 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
237 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
244 figfile = self.getFilename(name)
238 figfile = self.getFilename(name)
245
239
246 self.save(figpath=figpath,
240 self.save(figpath=figpath,
247 figfile=figfile,
241 figfile=figfile,
248 save=save,
242 save=save,
249 ftp=ftp,
243 ftp=ftp,
250 wr_period=wr_period,
244 wr_period=wr_period,
251 thisDatetime=thisDatetime)
245 thisDatetime=thisDatetime)
252
246
253
247
254 class CrossSpectraPlot(Figure):
248 class CrossSpectraPlot(Figure):
255
249
256 isConfig = None
250 isConfig = None
257 __nsubplots = None
251 __nsubplots = None
258
252
259 WIDTH = None
253 WIDTH = None
260 HEIGHT = None
254 HEIGHT = None
261 WIDTHPROF = None
255 WIDTHPROF = None
262 HEIGHTPROF = None
256 HEIGHTPROF = None
263 PREFIX = 'cspc'
257 PREFIX = 'cspc'
264
258
265 def __init__(self, **kwargs):
259 def __init__(self, **kwargs):
266 Figure.__init__(self, **kwargs)
260 Figure.__init__(self, **kwargs)
267 self.isConfig = False
261 self.isConfig = False
268 self.__nsubplots = 4
262 self.__nsubplots = 4
269 self.counter_imagwr = 0
263 self.counter_imagwr = 0
270 self.WIDTH = 250
264 self.WIDTH = 250
271 self.HEIGHT = 250
265 self.HEIGHT = 250
272 self.WIDTHPROF = 0
266 self.WIDTHPROF = 0
273 self.HEIGHTPROF = 0
267 self.HEIGHTPROF = 0
274
268
275 self.PLOT_CODE = CROSS_CODE
269 self.PLOT_CODE = CROSS_CODE
276 self.FTP_WEI = None
270 self.FTP_WEI = None
277 self.EXP_CODE = None
271 self.EXP_CODE = None
278 self.SUB_EXP_CODE = None
272 self.SUB_EXP_CODE = None
279 self.PLOT_POS = None
273 self.PLOT_POS = None
280
274
281 self.indice=0
275 self.indice=0
282
276
283 def getSubplots(self):
277 def getSubplots(self):
284
278
285 ncol = 4
279 ncol = 4
286 nrow = self.nplots
280 nrow = self.nplots
287
281
288 return nrow, ncol
282 return nrow, ncol
289
283
290 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
284 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
291
285
292 self.__showprofile = showprofile
286 self.__showprofile = showprofile
293 self.nplots = nplots
287 self.nplots = nplots
294
288
295 ncolspan = 1
289 ncolspan = 1
296 colspan = 1
290 colspan = 1
297
291
298 self.createFigure(id = id,
292 self.createFigure(id = id,
299 wintitle = wintitle,
293 wintitle = wintitle,
300 widthplot = self.WIDTH + self.WIDTHPROF,
294 widthplot = self.WIDTH + self.WIDTHPROF,
301 heightplot = self.HEIGHT + self.HEIGHTPROF,
295 heightplot = self.HEIGHT + self.HEIGHTPROF,
302 show=True)
296 show=True)
303
297
304 nrow, ncol = self.getSubplots()
298 nrow, ncol = self.getSubplots()
305
299
306 counter = 0
300 counter = 0
307 for y in range(nrow):
301 for y in range(nrow):
308 for x in range(ncol):
302 for x in range(ncol):
309 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
303 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
310
304
311 counter += 1
305 counter += 1
312
306
313 def run(self, dataOut, id, wintitle="", pairsList=None,
307 def run(self, dataOut, id, wintitle="", pairsList=None,
314 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
308 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
315 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
309 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
316 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
310 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
317 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
311 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
318 server=None, folder=None, username=None, password=None,
312 server=None, folder=None, username=None, password=None,
319 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
313 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
320 xaxis='frequency'):
314 xaxis='frequency'):
321
315
322 """
316 """
323
317
324 Input:
318 Input:
325 dataOut :
319 dataOut :
326 id :
320 id :
327 wintitle :
321 wintitle :
328 channelList :
322 channelList :
329 showProfile :
323 showProfile :
330 xmin : None,
324 xmin : None,
331 xmax : None,
325 xmax : None,
332 ymin : None,
326 ymin : None,
333 ymax : None,
327 ymax : None,
334 zmin : None,
328 zmin : None,
335 zmax : None
329 zmax : None
336 """
330 """
337
331
338 if pairsList == None:
332 if pairsList == None:
339 pairsIndexList = dataOut.pairsIndexList
333 pairsIndexList = dataOut.pairsIndexList
340 else:
334 else:
341 pairsIndexList = []
335 pairsIndexList = []
342 for pair in pairsList:
336 for pair in pairsList:
343 if pair not in dataOut.pairsList:
337 if pair not in dataOut.pairsList:
344 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
338 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
345 pairsIndexList.append(dataOut.pairsList.index(pair))
339 pairsIndexList.append(dataOut.pairsList.index(pair))
346
340
347 if not pairsIndexList:
341 if not pairsIndexList:
348 return
342 return
349
343
350 if len(pairsIndexList) > 4:
344 if len(pairsIndexList) > 4:
351 pairsIndexList = pairsIndexList[0:4]
345 pairsIndexList = pairsIndexList[0:4]
352
346
353 if normFactor is None:
347 if normFactor is None:
354 factor = dataOut.normFactor
348 factor = dataOut.normFactor
355 else:
349 else:
356 factor = normFactor
350 factor = normFactor
357 x = dataOut.getVelRange(1)
351 x = dataOut.getVelRange(1)
358 y = dataOut.getHeiRange()
352 y = dataOut.getHeiRange()
359 z = dataOut.data_spc[:,:,:]/factor
353 z = dataOut.data_spc[:,:,:]/factor
360 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
354 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
361
355
362 noise = dataOut.noise/factor
356 noise = dataOut.noise/factor
363
357
364 zdB = 10*numpy.log10(z)
358 zdB = 10*numpy.log10(z)
365 noisedB = 10*numpy.log10(noise)
359 noisedB = 10*numpy.log10(noise)
366
360
367 if coh_min == None:
361 if coh_min == None:
368 coh_min = 0.0
362 coh_min = 0.0
369 if coh_max == None:
363 if coh_max == None:
370 coh_max = 1.0
364 coh_max = 1.0
371
365
372 if phase_min == None:
366 if phase_min == None:
373 phase_min = -180
367 phase_min = -180
374 if phase_max == None:
368 if phase_max == None:
375 phase_max = 180
369 phase_max = 180
376
370
377 #thisDatetime = dataOut.datatime
371 #thisDatetime = dataOut.datatime
378 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
379 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
373 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
380 # xlabel = "Velocity (m/s)"
374 # xlabel = "Velocity (m/s)"
381 ylabel = "Range (Km)"
375 ylabel = "Range (Km)"
382
376
383 if xaxis == "frequency":
377 if xaxis == "frequency":
384 x = dataOut.getFreqRange(1)/1000.
378 x = dataOut.getFreqRange(1)/1000.
385 xlabel = "Frequency (kHz)"
379 xlabel = "Frequency (kHz)"
386
380
387 elif xaxis == "time":
381 elif xaxis == "time":
388 x = dataOut.getAcfRange(1)
382 x = dataOut.getAcfRange(1)
389 xlabel = "Time (ms)"
383 xlabel = "Time (ms)"
390
384
391 else:
385 else:
392 x = dataOut.getVelRange(1)
386 x = dataOut.getVelRange(1)
393 xlabel = "Velocity (m/s)"
387 xlabel = "Velocity (m/s)"
394
388
395 if not self.isConfig:
389 if not self.isConfig:
396
390
397 nplots = len(pairsIndexList)
391 nplots = len(pairsIndexList)
398
392
399 self.setup(id=id,
393 self.setup(id=id,
400 nplots=nplots,
394 nplots=nplots,
401 wintitle=wintitle,
395 wintitle=wintitle,
402 showprofile=False,
396 showprofile=False,
403 show=show)
397 show=show)
404
398
405 avg = numpy.abs(numpy.average(z, axis=1))
399 avg = numpy.abs(numpy.average(z, axis=1))
406 avgdB = 10*numpy.log10(avg)
400 avgdB = 10*numpy.log10(avg)
407
401
408 if xmin == None: xmin = numpy.nanmin(x)
402 if xmin == None: xmin = numpy.nanmin(x)
409 if xmax == None: xmax = numpy.nanmax(x)
403 if xmax == None: xmax = numpy.nanmax(x)
410 if ymin == None: ymin = numpy.nanmin(y)
404 if ymin == None: ymin = numpy.nanmin(y)
411 if ymax == None: ymax = numpy.nanmax(y)
405 if ymax == None: ymax = numpy.nanmax(y)
412 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
406 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
413 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
407 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
414
408
415 self.FTP_WEI = ftp_wei
409 self.FTP_WEI = ftp_wei
416 self.EXP_CODE = exp_code
410 self.EXP_CODE = exp_code
417 self.SUB_EXP_CODE = sub_exp_code
411 self.SUB_EXP_CODE = sub_exp_code
418 self.PLOT_POS = plot_pos
412 self.PLOT_POS = plot_pos
419
413
420 self.isConfig = True
414 self.isConfig = True
421
415
422 self.setWinTitle(title)
416 self.setWinTitle(title)
423
417
424
418
425 for i in range(self.nplots):
419 for i in range(self.nplots):
426 pair = dataOut.pairsList[pairsIndexList[i]]
420 pair = dataOut.pairsList[pairsIndexList[i]]
427
421
428 chan_index0 = dataOut.channelList.index(pair[0])
422 chan_index0 = dataOut.channelList.index(pair[0])
429 chan_index1 = dataOut.channelList.index(pair[1])
423 chan_index1 = dataOut.channelList.index(pair[1])
430
424
431 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
425 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
432 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
426 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
433 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
427 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
434 axes0 = self.axesList[i*self.__nsubplots]
428 axes0 = self.axesList[i*self.__nsubplots]
435 axes0.pcolor(x, y, zdB,
429 axes0.pcolor(x, y, zdB,
436 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
430 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
437 xlabel=xlabel, ylabel=ylabel, title=title,
431 xlabel=xlabel, ylabel=ylabel, title=title,
438 ticksize=9, colormap=power_cmap, cblabel='')
432 ticksize=9, colormap=power_cmap, cblabel='')
439
433
440 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
434 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
441 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
435 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
442 axes0 = self.axesList[i*self.__nsubplots+1]
436 axes0 = self.axesList[i*self.__nsubplots+1]
443 axes0.pcolor(x, y, zdB,
437 axes0.pcolor(x, y, zdB,
444 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
445 xlabel=xlabel, ylabel=ylabel, title=title,
439 xlabel=xlabel, ylabel=ylabel, title=title,
446 ticksize=9, colormap=power_cmap, cblabel='')
440 ticksize=9, colormap=power_cmap, cblabel='')
447
441
448 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
442 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
449 coherence = numpy.abs(coherenceComplex)
443 coherence = numpy.abs(coherenceComplex)
450 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
444 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
451 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
445 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
452
446
453
447
454
448
455
449
456 # #print 'FASE', numpy.shape(phase), y[25]
450 # #print 'FASE', numpy.shape(phase), y[25]
457 # fig = plt.figure(10+self.indice)
451 # fig = plt.figure(10+self.indice)
458 # #plt.plot( x[0:256],coherence[:,25] )
452 # #plt.plot( x[0:256],coherence[:,25] )
459 # cohAv = numpy.average(coherence,1)
453 # cohAv = numpy.average(coherence,1)
460 #
454 #
461 # plt.plot( x[0:256],cohAv )
455 # plt.plot( x[0:256],cohAv )
462 # #plt.axis([-12, 12, 15, 50])
456 # #plt.axis([-12, 12, 15, 50])
463 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
457 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
464 # plt.ylabel('Desfase [grados]')
458 # plt.ylabel('Desfase [grados]')
465 # plt.xlabel('Velocidad [m/s]')
459 # plt.xlabel('Velocidad [m/s]')
466 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
460 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
467 #
461 #
468 # plt.show()
462 # plt.show()
469 # self.indice=self.indice+1
463 # self.indice=self.indice+1
470
464
471
465
472 # print 'FASE', numpy.shape(phase), y[25]
466 # print 'FASE', numpy.shape(phase), y[25]
473 # fig = plt.figure(10+self.indice)
467 # fig = plt.figure(10+self.indice)
474 # plt.plot( x[0:256],phase[:,25] )
468 # plt.plot( x[0:256],phase[:,25] )
475 # #plt.axis([-12, 12, 15, 50])
469 # #plt.axis([-12, 12, 15, 50])
476 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
470 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
477 # plt.ylabel('Desfase [grados]')
471 # plt.ylabel('Desfase [grados]')
478 # plt.xlabel('Velocidad [m/s]')
472 # plt.xlabel('Velocidad [m/s]')
479 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
473 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
480 #
474 #
481 # plt.show()
475 # plt.show()
482 # self.indice=self.indice+1
476 # self.indice=self.indice+1
483
477
484
478
485
479
486
480
487 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
481 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
488 axes0 = self.axesList[i*self.__nsubplots+2]
482 axes0 = self.axesList[i*self.__nsubplots+2]
489 axes0.pcolor(x, y, coherence,
483 axes0.pcolor(x, y, coherence,
490 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
484 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
491 xlabel=xlabel, ylabel=ylabel, title=title,
485 xlabel=xlabel, ylabel=ylabel, title=title,
492 ticksize=9, colormap=coherence_cmap, cblabel='')
486 ticksize=9, colormap=coherence_cmap, cblabel='')
493
487
494 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
488 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
495 axes0 = self.axesList[i*self.__nsubplots+3]
489 axes0 = self.axesList[i*self.__nsubplots+3]
496 axes0.pcolor(x, y, phase,
490 axes0.pcolor(x, y, phase,
497 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
491 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
498 xlabel=xlabel, ylabel=ylabel, title=title,
492 xlabel=xlabel, ylabel=ylabel, title=title,
499 ticksize=9, colormap=phase_cmap, cblabel='')
493 ticksize=9, colormap=phase_cmap, cblabel='')
500
494
501
495
502
496
503 self.draw()
497 self.draw()
504
498
505 self.save(figpath=figpath,
499 self.save(figpath=figpath,
506 figfile=figfile,
500 figfile=figfile,
507 save=save,
501 save=save,
508 ftp=ftp,
502 ftp=ftp,
509 wr_period=wr_period,
503 wr_period=wr_period,
510 thisDatetime=thisDatetime)
504 thisDatetime=thisDatetime)
511
505
512
506
513 class RTIPlot(Figure):
507 class RTIPlot(Figure):
514
508
515 __isConfig = None
509 __isConfig = None
516 __nsubplots = None
510 __nsubplots = None
517
511
518 WIDTHPROF = None
512 WIDTHPROF = None
519 HEIGHTPROF = None
513 HEIGHTPROF = None
520 PREFIX = 'rti'
514 PREFIX = 'rti'
521
515
522 def __init__(self, **kwargs):
516 def __init__(self, **kwargs):
523
517
524 Figure.__init__(self, **kwargs)
518 Figure.__init__(self, **kwargs)
525 self.timerange = None
519 self.timerange = None
526 self.isConfig = False
520 self.isConfig = False
527 self.__nsubplots = 1
521 self.__nsubplots = 1
528
522
529 self.WIDTH = 800
523 self.WIDTH = 800
530 self.HEIGHT = 250
524 self.HEIGHT = 250
531 self.WIDTHPROF = 120
525 self.WIDTHPROF = 120
532 self.HEIGHTPROF = 0
526 self.HEIGHTPROF = 0
533 self.counter_imagwr = 0
527 self.counter_imagwr = 0
534
528
535 self.PLOT_CODE = RTI_CODE
529 self.PLOT_CODE = RTI_CODE
536
530
537 self.FTP_WEI = None
531 self.FTP_WEI = None
538 self.EXP_CODE = None
532 self.EXP_CODE = None
539 self.SUB_EXP_CODE = None
533 self.SUB_EXP_CODE = None
540 self.PLOT_POS = None
534 self.PLOT_POS = None
541 self.tmin = None
535 self.tmin = None
542 self.tmax = None
536 self.tmax = None
543
537
544 self.xmin = None
538 self.xmin = None
545 self.xmax = None
539 self.xmax = None
546
540
547 self.figfile = None
541 self.figfile = None
548
542
549 def getSubplots(self):
543 def getSubplots(self):
550
544
551 ncol = 1
545 ncol = 1
552 nrow = self.nplots
546 nrow = self.nplots
553
547
554 return nrow, ncol
548 return nrow, ncol
555
549
556 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
550 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
557
551
558 self.__showprofile = showprofile
552 self.__showprofile = showprofile
559 self.nplots = nplots
553 self.nplots = nplots
560
554
561 ncolspan = 1
555 ncolspan = 1
562 colspan = 1
556 colspan = 1
563 if showprofile:
557 if showprofile:
564 ncolspan = 7
558 ncolspan = 7
565 colspan = 6
559 colspan = 6
566 self.__nsubplots = 2
560 self.__nsubplots = 2
567
561
568 self.createFigure(id = id,
562 self.createFigure(id = id,
569 wintitle = wintitle,
563 wintitle = wintitle,
570 widthplot = self.WIDTH + self.WIDTHPROF,
564 widthplot = self.WIDTH + self.WIDTHPROF,
571 heightplot = self.HEIGHT + self.HEIGHTPROF,
565 heightplot = self.HEIGHT + self.HEIGHTPROF,
572 show=show)
566 show=show)
573
567
574 nrow, ncol = self.getSubplots()
568 nrow, ncol = self.getSubplots()
575
569
576 counter = 0
570 counter = 0
577 for y in range(nrow):
571 for y in range(nrow):
578 for x in range(ncol):
572 for x in range(ncol):
579
573
580 if counter >= self.nplots:
574 if counter >= self.nplots:
581 break
575 break
582
576
583 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
577 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
584
578
585 if showprofile:
579 if showprofile:
586 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
580 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
587
581
588 counter += 1
582 counter += 1
589
583
590 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
584 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
591 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
585 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
592 timerange=None, colormap='jet',
586 timerange=None, colormap='jet',
593 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
587 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
594 server=None, folder=None, username=None, password=None,
588 server=None, folder=None, username=None, password=None,
595 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
589 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
596
590
597 """
591 """
598
592
599 Input:
593 Input:
600 dataOut :
594 dataOut :
601 id :
595 id :
602 wintitle :
596 wintitle :
603 channelList :
597 channelList :
604 showProfile :
598 showProfile :
605 xmin : None,
599 xmin : None,
606 xmax : None,
600 xmax : None,
607 ymin : None,
601 ymin : None,
608 ymax : None,
602 ymax : None,
609 zmin : None,
603 zmin : None,
610 zmax : None
604 zmax : None
611 """
605 """
612
606
613 #colormap = kwargs.get('colormap', 'jet')
607 #colormap = kwargs.get('colormap', 'jet')
614 if HEIGHT is not None:
608 if HEIGHT is not None:
615 self.HEIGHT = HEIGHT
609 self.HEIGHT = HEIGHT
616
610
617 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
611 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
618 return
612 return
619
613
620 if channelList == None:
614 if channelList == None:
621 channelIndexList = dataOut.channelIndexList
615 channelIndexList = dataOut.channelIndexList
622 else:
616 else:
623 channelIndexList = []
617 channelIndexList = []
624 for channel in channelList:
618 for channel in channelList:
625 if channel not in dataOut.channelList:
619 if channel not in dataOut.channelList:
626 raise ValueError, "Channel %d is not in dataOut.channelList"
620 raise ValueError, "Channel %d is not in dataOut.channelList"
627 channelIndexList.append(dataOut.channelList.index(channel))
621 channelIndexList.append(dataOut.channelList.index(channel))
628
622
629 if normFactor is None:
623 if normFactor is None:
630 factor = dataOut.normFactor
624 factor = dataOut.normFactor
631 else:
625 else:
632 factor = normFactor
626 factor = normFactor
633
627
634 # factor = dataOut.normFactor
628 # factor = dataOut.normFactor
635 x = dataOut.getTimeRange()
629 x = dataOut.getTimeRange()
636 y = dataOut.getHeiRange()
630 y = dataOut.getHeiRange()
637
631
638 z = dataOut.data_spc/factor
632 z = dataOut.data_spc/factor
639 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
633 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
640 avg = numpy.average(z, axis=1)
634 avg = numpy.average(z, axis=1)
641 avgdB = 10.*numpy.log10(avg)
635 avgdB = 10.*numpy.log10(avg)
642 # avgdB = dataOut.getPower()
636 # avgdB = dataOut.getPower()
643
637
644
638
645 thisDatetime = dataOut.datatime
639 thisDatetime = dataOut.datatime
646 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
640 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
647 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
641 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
648 xlabel = ""
642 xlabel = ""
649 ylabel = "Range (Km)"
643 ylabel = "Range (Km)"
650
644
651 update_figfile = False
645 update_figfile = False
652
646
653 if dataOut.ltctime >= self.xmax:
647 if dataOut.ltctime >= self.xmax:
654 self.counter_imagwr = wr_period
648 self.counter_imagwr = wr_period
655 self.isConfig = False
649 self.isConfig = False
656 update_figfile = True
650 update_figfile = True
657
651
658 if not self.isConfig:
652 if not self.isConfig:
659
653
660 nplots = len(channelIndexList)
654 nplots = len(channelIndexList)
661
655
662 self.setup(id=id,
656 self.setup(id=id,
663 nplots=nplots,
657 nplots=nplots,
664 wintitle=wintitle,
658 wintitle=wintitle,
665 showprofile=showprofile,
659 showprofile=showprofile,
666 show=show)
660 show=show)
667
661
668 if timerange != None:
662 if timerange != None:
669 self.timerange = timerange
663 self.timerange = timerange
670
664
671 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
665 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
672
666
673 noise = dataOut.noise/factor
667 noise = dataOut.noise/factor
674 noisedB = 10*numpy.log10(noise)
668 noisedB = 10*numpy.log10(noise)
675
669
676 if ymin == None: ymin = numpy.nanmin(y)
670 if ymin == None: ymin = numpy.nanmin(y)
677 if ymax == None: ymax = numpy.nanmax(y)
671 if ymax == None: ymax = numpy.nanmax(y)
678 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
672 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
679 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
673 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
680
674
681 self.FTP_WEI = ftp_wei
675 self.FTP_WEI = ftp_wei
682 self.EXP_CODE = exp_code
676 self.EXP_CODE = exp_code
683 self.SUB_EXP_CODE = sub_exp_code
677 self.SUB_EXP_CODE = sub_exp_code
684 self.PLOT_POS = plot_pos
678 self.PLOT_POS = plot_pos
685
679
686 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
680 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
687 self.isConfig = True
681 self.isConfig = True
688 self.figfile = figfile
682 self.figfile = figfile
689 update_figfile = True
683 update_figfile = True
690
684
691 self.setWinTitle(title)
685 self.setWinTitle(title)
692
686
693 for i in range(self.nplots):
687 for i in range(self.nplots):
694 index = channelIndexList[i]
688 index = channelIndexList[i]
695 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
689 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
696 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
690 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
697 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
691 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
698 axes = self.axesList[i*self.__nsubplots]
692 axes = self.axesList[i*self.__nsubplots]
699 zdB = avgdB[index].reshape((1,-1))
693 zdB = avgdB[index].reshape((1,-1))
700 axes.pcolorbuffer(x, y, zdB,
694 axes.pcolorbuffer(x, y, zdB,
701 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
695 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
702 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
696 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
703 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
697 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
704
698
705 if self.__showprofile:
699 if self.__showprofile:
706 axes = self.axesList[i*self.__nsubplots +1]
700 axes = self.axesList[i*self.__nsubplots +1]
707 axes.pline(avgdB[index], y,
701 axes.pline(avgdB[index], y,
708 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
702 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
709 xlabel='dB', ylabel='', title='',
703 xlabel='dB', ylabel='', title='',
710 ytick_visible=False,
704 ytick_visible=False,
711 grid='x')
705 grid='x')
712
706
713 self.draw()
707 self.draw()
714
708
715 self.save(figpath=figpath,
709 self.save(figpath=figpath,
716 figfile=figfile,
710 figfile=figfile,
717 save=save,
711 save=save,
718 ftp=ftp,
712 ftp=ftp,
719 wr_period=wr_period,
713 wr_period=wr_period,
720 thisDatetime=thisDatetime,
714 thisDatetime=thisDatetime,
721 update_figfile=update_figfile)
715 update_figfile=update_figfile)
722
716
723 class CoherenceMap(Figure):
717 class CoherenceMap(Figure):
724 isConfig = None
718 isConfig = None
725 __nsubplots = None
719 __nsubplots = None
726
720
727 WIDTHPROF = None
721 WIDTHPROF = None
728 HEIGHTPROF = None
722 HEIGHTPROF = None
729 PREFIX = 'cmap'
723 PREFIX = 'cmap'
730
724
731 def __init__(self, **kwargs):
725 def __init__(self, **kwargs):
732 Figure.__init__(self, **kwargs)
726 Figure.__init__(self, **kwargs)
733 self.timerange = 2*60*60
727 self.timerange = 2*60*60
734 self.isConfig = False
728 self.isConfig = False
735 self.__nsubplots = 1
729 self.__nsubplots = 1
736
730
737 self.WIDTH = 800
731 self.WIDTH = 800
738 self.HEIGHT = 180
732 self.HEIGHT = 180
739 self.WIDTHPROF = 120
733 self.WIDTHPROF = 120
740 self.HEIGHTPROF = 0
734 self.HEIGHTPROF = 0
741 self.counter_imagwr = 0
735 self.counter_imagwr = 0
742
736
743 self.PLOT_CODE = COH_CODE
737 self.PLOT_CODE = COH_CODE
744
738
745 self.FTP_WEI = None
739 self.FTP_WEI = None
746 self.EXP_CODE = None
740 self.EXP_CODE = None
747 self.SUB_EXP_CODE = None
741 self.SUB_EXP_CODE = None
748 self.PLOT_POS = None
742 self.PLOT_POS = None
749 self.counter_imagwr = 0
743 self.counter_imagwr = 0
750
744
751 self.xmin = None
745 self.xmin = None
752 self.xmax = None
746 self.xmax = None
753
747
754 def getSubplots(self):
748 def getSubplots(self):
755 ncol = 1
749 ncol = 1
756 nrow = self.nplots*2
750 nrow = self.nplots*2
757
751
758 return nrow, ncol
752 return nrow, ncol
759
753
760 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
754 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
761 self.__showprofile = showprofile
755 self.__showprofile = showprofile
762 self.nplots = nplots
756 self.nplots = nplots
763
757
764 ncolspan = 1
758 ncolspan = 1
765 colspan = 1
759 colspan = 1
766 if showprofile:
760 if showprofile:
767 ncolspan = 7
761 ncolspan = 7
768 colspan = 6
762 colspan = 6
769 self.__nsubplots = 2
763 self.__nsubplots = 2
770
764
771 self.createFigure(id = id,
765 self.createFigure(id = id,
772 wintitle = wintitle,
766 wintitle = wintitle,
773 widthplot = self.WIDTH + self.WIDTHPROF,
767 widthplot = self.WIDTH + self.WIDTHPROF,
774 heightplot = self.HEIGHT + self.HEIGHTPROF,
768 heightplot = self.HEIGHT + self.HEIGHTPROF,
775 show=True)
769 show=True)
776
770
777 nrow, ncol = self.getSubplots()
771 nrow, ncol = self.getSubplots()
778
772
779 for y in range(nrow):
773 for y in range(nrow):
780 for x in range(ncol):
774 for x in range(ncol):
781
775
782 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
776 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
783
777
784 if showprofile:
778 if showprofile:
785 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
779 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
786
780
787 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
781 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
788 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
782 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
789 timerange=None, phase_min=None, phase_max=None,
783 timerange=None, phase_min=None, phase_max=None,
790 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
784 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
791 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
785 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
792 server=None, folder=None, username=None, password=None,
786 server=None, folder=None, username=None, password=None,
793 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
787 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
794
788
795 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
789 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
796 return
790 return
797
791
798 if pairsList == None:
792 if pairsList == None:
799 pairsIndexList = dataOut.pairsIndexList
793 pairsIndexList = dataOut.pairsIndexList
800 else:
794 else:
801 pairsIndexList = []
795 pairsIndexList = []
802 for pair in pairsList:
796 for pair in pairsList:
803 if pair not in dataOut.pairsList:
797 if pair not in dataOut.pairsList:
804 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
798 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
805 pairsIndexList.append(dataOut.pairsList.index(pair))
799 pairsIndexList.append(dataOut.pairsList.index(pair))
806
800
807 if pairsIndexList == []:
801 if pairsIndexList == []:
808 return
802 return
809
803
810 if len(pairsIndexList) > 4:
804 if len(pairsIndexList) > 4:
811 pairsIndexList = pairsIndexList[0:4]
805 pairsIndexList = pairsIndexList[0:4]
812
806
813 if phase_min == None:
807 if phase_min == None:
814 phase_min = -180
808 phase_min = -180
815 if phase_max == None:
809 if phase_max == None:
816 phase_max = 180
810 phase_max = 180
817
811
818 x = dataOut.getTimeRange()
812 x = dataOut.getTimeRange()
819 y = dataOut.getHeiRange()
813 y = dataOut.getHeiRange()
820
814
821 thisDatetime = dataOut.datatime
815 thisDatetime = dataOut.datatime
822
816
823 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
817 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
824 xlabel = ""
818 xlabel = ""
825 ylabel = "Range (Km)"
819 ylabel = "Range (Km)"
826 update_figfile = False
820 update_figfile = False
827
821
828 if not self.isConfig:
822 if not self.isConfig:
829 nplots = len(pairsIndexList)
823 nplots = len(pairsIndexList)
830 self.setup(id=id,
824 self.setup(id=id,
831 nplots=nplots,
825 nplots=nplots,
832 wintitle=wintitle,
826 wintitle=wintitle,
833 showprofile=showprofile,
827 showprofile=showprofile,
834 show=show)
828 show=show)
835
829
836 if timerange != None:
830 if timerange != None:
837 self.timerange = timerange
831 self.timerange = timerange
838
832
839 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
833 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
840
834
841 if ymin == None: ymin = numpy.nanmin(y)
835 if ymin == None: ymin = numpy.nanmin(y)
842 if ymax == None: ymax = numpy.nanmax(y)
836 if ymax == None: ymax = numpy.nanmax(y)
843 if zmin == None: zmin = 0.
837 if zmin == None: zmin = 0.
844 if zmax == None: zmax = 1.
838 if zmax == None: zmax = 1.
845
839
846 self.FTP_WEI = ftp_wei
840 self.FTP_WEI = ftp_wei
847 self.EXP_CODE = exp_code
841 self.EXP_CODE = exp_code
848 self.SUB_EXP_CODE = sub_exp_code
842 self.SUB_EXP_CODE = sub_exp_code
849 self.PLOT_POS = plot_pos
843 self.PLOT_POS = plot_pos
850
844
851 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
845 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
852
846
853 self.isConfig = True
847 self.isConfig = True
854 update_figfile = True
848 update_figfile = True
855
849
856 self.setWinTitle(title)
850 self.setWinTitle(title)
857
851
858 for i in range(self.nplots):
852 for i in range(self.nplots):
859
853
860 pair = dataOut.pairsList[pairsIndexList[i]]
854 pair = dataOut.pairsList[pairsIndexList[i]]
861
855
862 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
856 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
863 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
857 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
864 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
858 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
865
859
866
860
867 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
861 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
868 coherence = numpy.abs(avgcoherenceComplex)
862 coherence = numpy.abs(avgcoherenceComplex)
869
863
870 z = coherence.reshape((1,-1))
864 z = coherence.reshape((1,-1))
871
865
872 counter = 0
866 counter = 0
873
867
874 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
868 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
875 axes = self.axesList[i*self.__nsubplots*2]
869 axes = self.axesList[i*self.__nsubplots*2]
876 axes.pcolorbuffer(x, y, z,
870 axes.pcolorbuffer(x, y, z,
877 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
871 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
878 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
872 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
879 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
873 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
880
874
881 if self.__showprofile:
875 if self.__showprofile:
882 counter += 1
876 counter += 1
883 axes = self.axesList[i*self.__nsubplots*2 + counter]
877 axes = self.axesList[i*self.__nsubplots*2 + counter]
884 axes.pline(coherence, y,
878 axes.pline(coherence, y,
885 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
879 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
886 xlabel='', ylabel='', title='', ticksize=7,
880 xlabel='', ylabel='', title='', ticksize=7,
887 ytick_visible=False, nxticks=5,
881 ytick_visible=False, nxticks=5,
888 grid='x')
882 grid='x')
889
883
890 counter += 1
884 counter += 1
891
885
892 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
886 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
893
887
894 z = phase.reshape((1,-1))
888 z = phase.reshape((1,-1))
895
889
896 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
890 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
897 axes = self.axesList[i*self.__nsubplots*2 + counter]
891 axes = self.axesList[i*self.__nsubplots*2 + counter]
898 axes.pcolorbuffer(x, y, z,
892 axes.pcolorbuffer(x, y, z,
899 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
893 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
900 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
894 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
901 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
895 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
902
896
903 if self.__showprofile:
897 if self.__showprofile:
904 counter += 1
898 counter += 1
905 axes = self.axesList[i*self.__nsubplots*2 + counter]
899 axes = self.axesList[i*self.__nsubplots*2 + counter]
906 axes.pline(phase, y,
900 axes.pline(phase, y,
907 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
901 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
908 xlabel='', ylabel='', title='', ticksize=7,
902 xlabel='', ylabel='', title='', ticksize=7,
909 ytick_visible=False, nxticks=4,
903 ytick_visible=False, nxticks=4,
910 grid='x')
904 grid='x')
911
905
912 self.draw()
906 self.draw()
913
907
914 if dataOut.ltctime >= self.xmax:
908 if dataOut.ltctime >= self.xmax:
915 self.counter_imagwr = wr_period
909 self.counter_imagwr = wr_period
916 self.isConfig = False
910 self.isConfig = False
917 update_figfile = True
911 update_figfile = True
918
912
919 self.save(figpath=figpath,
913 self.save(figpath=figpath,
920 figfile=figfile,
914 figfile=figfile,
921 save=save,
915 save=save,
922 ftp=ftp,
916 ftp=ftp,
923 wr_period=wr_period,
917 wr_period=wr_period,
924 thisDatetime=thisDatetime,
918 thisDatetime=thisDatetime,
925 update_figfile=update_figfile)
919 update_figfile=update_figfile)
926
920
927 class PowerProfilePlot(Figure):
921 class PowerProfilePlot(Figure):
928
922
929 isConfig = None
923 isConfig = None
930 __nsubplots = None
924 __nsubplots = None
931
925
932 WIDTHPROF = None
926 WIDTHPROF = None
933 HEIGHTPROF = None
927 HEIGHTPROF = None
934 PREFIX = 'spcprofile'
928 PREFIX = 'spcprofile'
935
929
936 def __init__(self, **kwargs):
930 def __init__(self, **kwargs):
937 Figure.__init__(self, **kwargs)
931 Figure.__init__(self, **kwargs)
938 self.isConfig = False
932 self.isConfig = False
939 self.__nsubplots = 1
933 self.__nsubplots = 1
940
934
941 self.PLOT_CODE = POWER_CODE
935 self.PLOT_CODE = POWER_CODE
942
936
943 self.WIDTH = 300
937 self.WIDTH = 300
944 self.HEIGHT = 500
938 self.HEIGHT = 500
945 self.counter_imagwr = 0
939 self.counter_imagwr = 0
946
940
947 def getSubplots(self):
941 def getSubplots(self):
948 ncol = 1
942 ncol = 1
949 nrow = 1
943 nrow = 1
950
944
951 return nrow, ncol
945 return nrow, ncol
952
946
953 def setup(self, id, nplots, wintitle, show):
947 def setup(self, id, nplots, wintitle, show):
954
948
955 self.nplots = nplots
949 self.nplots = nplots
956
950
957 ncolspan = 1
951 ncolspan = 1
958 colspan = 1
952 colspan = 1
959
953
960 self.createFigure(id = id,
954 self.createFigure(id = id,
961 wintitle = wintitle,
955 wintitle = wintitle,
962 widthplot = self.WIDTH,
956 widthplot = self.WIDTH,
963 heightplot = self.HEIGHT,
957 heightplot = self.HEIGHT,
964 show=show)
958 show=show)
965
959
966 nrow, ncol = self.getSubplots()
960 nrow, ncol = self.getSubplots()
967
961
968 counter = 0
962 counter = 0
969 for y in range(nrow):
963 for y in range(nrow):
970 for x in range(ncol):
964 for x in range(ncol):
971 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
965 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
972
966
973 def run(self, dataOut, id, wintitle="", channelList=None,
967 def run(self, dataOut, id, wintitle="", channelList=None,
974 xmin=None, xmax=None, ymin=None, ymax=None,
968 xmin=None, xmax=None, ymin=None, ymax=None,
975 save=False, figpath='./', figfile=None, show=True,
969 save=False, figpath='./', figfile=None, show=True,
976 ftp=False, wr_period=1, server=None,
970 ftp=False, wr_period=1, server=None,
977 folder=None, username=None, password=None):
971 folder=None, username=None, password=None):
978
972
979
973
980 if channelList == None:
974 if channelList == None:
981 channelIndexList = dataOut.channelIndexList
975 channelIndexList = dataOut.channelIndexList
982 channelList = dataOut.channelList
976 channelList = dataOut.channelList
983 else:
977 else:
984 channelIndexList = []
978 channelIndexList = []
985 for channel in channelList:
979 for channel in channelList:
986 if channel not in dataOut.channelList:
980 if channel not in dataOut.channelList:
987 raise ValueError, "Channel %d is not in dataOut.channelList"
981 raise ValueError, "Channel %d is not in dataOut.channelList"
988 channelIndexList.append(dataOut.channelList.index(channel))
982 channelIndexList.append(dataOut.channelList.index(channel))
989
983
990 factor = dataOut.normFactor
984 factor = dataOut.normFactor
991
985
992 y = dataOut.getHeiRange()
986 y = dataOut.getHeiRange()
993
987
994 #for voltage
988 #for voltage
995 if dataOut.type == 'Voltage':
989 if dataOut.type == 'Voltage':
996 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
990 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
997 x = x.real
991 x = x.real
998 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
992 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
999
993
1000 #for spectra
994 #for spectra
1001 if dataOut.type == 'Spectra':
995 if dataOut.type == 'Spectra':
1002 x = dataOut.data_spc[channelIndexList,:,:]/factor
996 x = dataOut.data_spc[channelIndexList,:,:]/factor
1003 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
997 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1004 x = numpy.average(x, axis=1)
998 x = numpy.average(x, axis=1)
1005
999
1006
1000
1007 xdB = 10*numpy.log10(x)
1001 xdB = 10*numpy.log10(x)
1008
1002
1009 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1003 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1010 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1004 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1011 xlabel = "dB"
1005 xlabel = "dB"
1012 ylabel = "Range (Km)"
1006 ylabel = "Range (Km)"
1013
1007
1014 if not self.isConfig:
1008 if not self.isConfig:
1015
1009
1016 nplots = 1
1010 nplots = 1
1017
1011
1018 self.setup(id=id,
1012 self.setup(id=id,
1019 nplots=nplots,
1013 nplots=nplots,
1020 wintitle=wintitle,
1014 wintitle=wintitle,
1021 show=show)
1015 show=show)
1022
1016
1023 if ymin == None: ymin = numpy.nanmin(y)
1017 if ymin == None: ymin = numpy.nanmin(y)
1024 if ymax == None: ymax = numpy.nanmax(y)
1018 if ymax == None: ymax = numpy.nanmax(y)
1025 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1019 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1026 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1020 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1027
1021
1028 self.isConfig = True
1022 self.isConfig = True
1029
1023
1030 self.setWinTitle(title)
1024 self.setWinTitle(title)
1031
1025
1032 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1026 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1033 axes = self.axesList[0]
1027 axes = self.axesList[0]
1034
1028
1035 legendlabels = ["channel %d"%x for x in channelList]
1029 legendlabels = ["channel %d"%x for x in channelList]
1036 axes.pmultiline(xdB, y,
1030 axes.pmultiline(xdB, y,
1037 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1031 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1038 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1032 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1039 ytick_visible=True, nxticks=5,
1033 ytick_visible=True, nxticks=5,
1040 grid='x')
1034 grid='x')
1041
1035
1042 self.draw()
1036 self.draw()
1043
1037
1044 self.save(figpath=figpath,
1038 self.save(figpath=figpath,
1045 figfile=figfile,
1039 figfile=figfile,
1046 save=save,
1040 save=save,
1047 ftp=ftp,
1041 ftp=ftp,
1048 wr_period=wr_period,
1042 wr_period=wr_period,
1049 thisDatetime=thisDatetime)
1043 thisDatetime=thisDatetime)
1050
1044
1051 class SpectraCutPlot(Figure):
1045 class SpectraCutPlot(Figure):
1052
1046
1053 isConfig = None
1047 isConfig = None
1054 __nsubplots = None
1048 __nsubplots = None
1055
1049
1056 WIDTHPROF = None
1050 WIDTHPROF = None
1057 HEIGHTPROF = None
1051 HEIGHTPROF = None
1058 PREFIX = 'spc_cut'
1052 PREFIX = 'spc_cut'
1059
1053
1060 def __init__(self, **kwargs):
1054 def __init__(self, **kwargs):
1061 Figure.__init__(self, **kwargs)
1055 Figure.__init__(self, **kwargs)
1062 self.isConfig = False
1056 self.isConfig = False
1063 self.__nsubplots = 1
1057 self.__nsubplots = 1
1064
1058
1065 self.PLOT_CODE = POWER_CODE
1059 self.PLOT_CODE = POWER_CODE
1066
1060
1067 self.WIDTH = 700
1061 self.WIDTH = 700
1068 self.HEIGHT = 500
1062 self.HEIGHT = 500
1069 self.counter_imagwr = 0
1063 self.counter_imagwr = 0
1070
1064
1071 def getSubplots(self):
1065 def getSubplots(self):
1072 ncol = 1
1066 ncol = 1
1073 nrow = 1
1067 nrow = 1
1074
1068
1075 return nrow, ncol
1069 return nrow, ncol
1076
1070
1077 def setup(self, id, nplots, wintitle, show):
1071 def setup(self, id, nplots, wintitle, show):
1078
1072
1079 self.nplots = nplots
1073 self.nplots = nplots
1080
1074
1081 ncolspan = 1
1075 ncolspan = 1
1082 colspan = 1
1076 colspan = 1
1083
1077
1084 self.createFigure(id = id,
1078 self.createFigure(id = id,
1085 wintitle = wintitle,
1079 wintitle = wintitle,
1086 widthplot = self.WIDTH,
1080 widthplot = self.WIDTH,
1087 heightplot = self.HEIGHT,
1081 heightplot = self.HEIGHT,
1088 show=show)
1082 show=show)
1089
1083
1090 nrow, ncol = self.getSubplots()
1084 nrow, ncol = self.getSubplots()
1091
1085
1092 counter = 0
1086 counter = 0
1093 for y in range(nrow):
1087 for y in range(nrow):
1094 for x in range(ncol):
1088 for x in range(ncol):
1095 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1089 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1096
1090
1097 def run(self, dataOut, id, wintitle="", channelList=None,
1091 def run(self, dataOut, id, wintitle="", channelList=None,
1098 xmin=None, xmax=None, ymin=None, ymax=None,
1092 xmin=None, xmax=None, ymin=None, ymax=None,
1099 save=False, figpath='./', figfile=None, show=True,
1093 save=False, figpath='./', figfile=None, show=True,
1100 ftp=False, wr_period=1, server=None,
1094 ftp=False, wr_period=1, server=None,
1101 folder=None, username=None, password=None,
1095 folder=None, username=None, password=None,
1102 xaxis="frequency"):
1096 xaxis="frequency"):
1103
1097
1104
1098
1105 if channelList == None:
1099 if channelList == None:
1106 channelIndexList = dataOut.channelIndexList
1100 channelIndexList = dataOut.channelIndexList
1107 channelList = dataOut.channelList
1101 channelList = dataOut.channelList
1108 else:
1102 else:
1109 channelIndexList = []
1103 channelIndexList = []
1110 for channel in channelList:
1104 for channel in channelList:
1111 if channel not in dataOut.channelList:
1105 if channel not in dataOut.channelList:
1112 raise ValueError, "Channel %d is not in dataOut.channelList"
1106 raise ValueError, "Channel %d is not in dataOut.channelList"
1113 channelIndexList.append(dataOut.channelList.index(channel))
1107 channelIndexList.append(dataOut.channelList.index(channel))
1114
1108
1115 factor = dataOut.normFactor
1109 factor = dataOut.normFactor
1116
1110
1117 y = dataOut.getHeiRange()
1111 y = dataOut.getHeiRange()
1118
1112
1119 z = dataOut.data_spc/factor
1113 z = dataOut.data_spc/factor
1120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1114 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1121
1115
1122 hei_index = numpy.arange(25)*3 + 20
1116 hei_index = numpy.arange(25)*3 + 20
1123
1117
1124 if xaxis == "frequency":
1118 if xaxis == "frequency":
1125 x = dataOut.getFreqRange()/1000.
1119 x = dataOut.getFreqRange()/1000.
1126 zdB = 10*numpy.log10(z[0,:,hei_index])
1120 zdB = 10*numpy.log10(z[0,:,hei_index])
1127 xlabel = "Frequency (kHz)"
1121 xlabel = "Frequency (kHz)"
1128 ylabel = "Power (dB)"
1122 ylabel = "Power (dB)"
1129
1123
1130 elif xaxis == "time":
1124 elif xaxis == "time":
1131 x = dataOut.getAcfRange()
1125 x = dataOut.getAcfRange()
1132 zdB = z[0,:,hei_index]
1126 zdB = z[0,:,hei_index]
1133 xlabel = "Time (ms)"
1127 xlabel = "Time (ms)"
1134 ylabel = "ACF"
1128 ylabel = "ACF"
1135
1129
1136 else:
1130 else:
1137 x = dataOut.getVelRange()
1131 x = dataOut.getVelRange()
1138 zdB = 10*numpy.log10(z[0,:,hei_index])
1132 zdB = 10*numpy.log10(z[0,:,hei_index])
1139 xlabel = "Velocity (m/s)"
1133 xlabel = "Velocity (m/s)"
1140 ylabel = "Power (dB)"
1134 ylabel = "Power (dB)"
1141
1135
1142 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1143 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1137 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1144
1138
1145 if not self.isConfig:
1139 if not self.isConfig:
1146
1140
1147 nplots = 1
1141 nplots = 1
1148
1142
1149 self.setup(id=id,
1143 self.setup(id=id,
1150 nplots=nplots,
1144 nplots=nplots,
1151 wintitle=wintitle,
1145 wintitle=wintitle,
1152 show=show)
1146 show=show)
1153
1147
1154 if xmin == None: xmin = numpy.nanmin(x)*0.9
1148 if xmin == None: xmin = numpy.nanmin(x)*0.9
1155 if xmax == None: xmax = numpy.nanmax(x)*1.1
1149 if xmax == None: xmax = numpy.nanmax(x)*1.1
1156 if ymin == None: ymin = numpy.nanmin(zdB)
1150 if ymin == None: ymin = numpy.nanmin(zdB)
1157 if ymax == None: ymax = numpy.nanmax(zdB)
1151 if ymax == None: ymax = numpy.nanmax(zdB)
1158
1152
1159 self.isConfig = True
1153 self.isConfig = True
1160
1154
1161 self.setWinTitle(title)
1155 self.setWinTitle(title)
1162
1156
1163 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1157 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1164 axes = self.axesList[0]
1158 axes = self.axesList[0]
1165
1159
1166 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1160 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1167
1161
1168 axes.pmultilineyaxis( x, zdB,
1162 axes.pmultilineyaxis( x, zdB,
1169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1170 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1164 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1171 ytick_visible=True, nxticks=5,
1165 ytick_visible=True, nxticks=5,
1172 grid='x')
1166 grid='x')
1173
1167
1174 self.draw()
1168 self.draw()
1175
1169
1176 self.save(figpath=figpath,
1170 self.save(figpath=figpath,
1177 figfile=figfile,
1171 figfile=figfile,
1178 save=save,
1172 save=save,
1179 ftp=ftp,
1173 ftp=ftp,
1180 wr_period=wr_period,
1174 wr_period=wr_period,
1181 thisDatetime=thisDatetime)
1175 thisDatetime=thisDatetime)
1182
1176
1183 class Noise(Figure):
1177 class Noise(Figure):
1184
1178
1185 isConfig = None
1179 isConfig = None
1186 __nsubplots = None
1180 __nsubplots = None
1187
1181
1188 PREFIX = 'noise'
1182 PREFIX = 'noise'
1189
1183
1190
1184
1191 def __init__(self, **kwargs):
1185 def __init__(self, **kwargs):
1192 Figure.__init__(self, **kwargs)
1186 Figure.__init__(self, **kwargs)
1193 self.timerange = 24*60*60
1187 self.timerange = 24*60*60
1194 self.isConfig = False
1188 self.isConfig = False
1195 self.__nsubplots = 1
1189 self.__nsubplots = 1
1196 self.counter_imagwr = 0
1190 self.counter_imagwr = 0
1197 self.WIDTH = 800
1191 self.WIDTH = 800
1198 self.HEIGHT = 400
1192 self.HEIGHT = 400
1199 self.WIDTHPROF = 120
1193 self.WIDTHPROF = 120
1200 self.HEIGHTPROF = 0
1194 self.HEIGHTPROF = 0
1201 self.xdata = None
1195 self.xdata = None
1202 self.ydata = None
1196 self.ydata = None
1203
1197
1204 self.PLOT_CODE = NOISE_CODE
1198 self.PLOT_CODE = NOISE_CODE
1205
1199
1206 self.FTP_WEI = None
1200 self.FTP_WEI = None
1207 self.EXP_CODE = None
1201 self.EXP_CODE = None
1208 self.SUB_EXP_CODE = None
1202 self.SUB_EXP_CODE = None
1209 self.PLOT_POS = None
1203 self.PLOT_POS = None
1210 self.figfile = None
1204 self.figfile = None
1211
1205
1212 self.xmin = None
1206 self.xmin = None
1213 self.xmax = None
1207 self.xmax = None
1214
1208
1215 def getSubplots(self):
1209 def getSubplots(self):
1216
1210
1217 ncol = 1
1211 ncol = 1
1218 nrow = 1
1212 nrow = 1
1219
1213
1220 return nrow, ncol
1214 return nrow, ncol
1221
1215
1222 def openfile(self, filename):
1216 def openfile(self, filename):
1223 dirname = os.path.dirname(filename)
1217 dirname = os.path.dirname(filename)
1224
1218
1225 if not os.path.exists(dirname):
1219 if not os.path.exists(dirname):
1226 os.mkdir(dirname)
1220 os.mkdir(dirname)
1227
1221
1228 f = open(filename,'w+')
1222 f = open(filename,'w+')
1229 f.write('\n\n')
1223 f.write('\n\n')
1230 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1224 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1231 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1225 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1232 f.close()
1226 f.close()
1233
1227
1234 def save_data(self, filename_phase, data, data_datetime):
1228 def save_data(self, filename_phase, data, data_datetime):
1235
1229
1236 f=open(filename_phase,'a')
1230 f=open(filename_phase,'a')
1237
1231
1238 timetuple_data = data_datetime.timetuple()
1232 timetuple_data = data_datetime.timetuple()
1239 day = str(timetuple_data.tm_mday)
1233 day = str(timetuple_data.tm_mday)
1240 month = str(timetuple_data.tm_mon)
1234 month = str(timetuple_data.tm_mon)
1241 year = str(timetuple_data.tm_year)
1235 year = str(timetuple_data.tm_year)
1242 hour = str(timetuple_data.tm_hour)
1236 hour = str(timetuple_data.tm_hour)
1243 minute = str(timetuple_data.tm_min)
1237 minute = str(timetuple_data.tm_min)
1244 second = str(timetuple_data.tm_sec)
1238 second = str(timetuple_data.tm_sec)
1245
1239
1246 data_msg = ''
1240 data_msg = ''
1247 for i in range(len(data)):
1241 for i in range(len(data)):
1248 data_msg += str(data[i]) + ' '
1242 data_msg += str(data[i]) + ' '
1249
1243
1250 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1244 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1251 f.close()
1245 f.close()
1252
1246
1253
1247
1254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1248 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1255
1249
1256 self.__showprofile = showprofile
1250 self.__showprofile = showprofile
1257 self.nplots = nplots
1251 self.nplots = nplots
1258
1252
1259 ncolspan = 7
1253 ncolspan = 7
1260 colspan = 6
1254 colspan = 6
1261 self.__nsubplots = 2
1255 self.__nsubplots = 2
1262
1256
1263 self.createFigure(id = id,
1257 self.createFigure(id = id,
1264 wintitle = wintitle,
1258 wintitle = wintitle,
1265 widthplot = self.WIDTH+self.WIDTHPROF,
1259 widthplot = self.WIDTH+self.WIDTHPROF,
1266 heightplot = self.HEIGHT+self.HEIGHTPROF,
1260 heightplot = self.HEIGHT+self.HEIGHTPROF,
1267 show=show)
1261 show=show)
1268
1262
1269 nrow, ncol = self.getSubplots()
1263 nrow, ncol = self.getSubplots()
1270
1264
1271 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1265 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1272
1266
1273
1267
1274 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1268 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1275 xmin=None, xmax=None, ymin=None, ymax=None,
1269 xmin=None, xmax=None, ymin=None, ymax=None,
1276 timerange=None,
1270 timerange=None,
1277 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1271 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1278 server=None, folder=None, username=None, password=None,
1272 server=None, folder=None, username=None, password=None,
1279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1273 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1280
1274
1281 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1275 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1282 return
1276 return
1283
1277
1284 if channelList == None:
1278 if channelList == None:
1285 channelIndexList = dataOut.channelIndexList
1279 channelIndexList = dataOut.channelIndexList
1286 channelList = dataOut.channelList
1280 channelList = dataOut.channelList
1287 else:
1281 else:
1288 channelIndexList = []
1282 channelIndexList = []
1289 for channel in channelList:
1283 for channel in channelList:
1290 if channel not in dataOut.channelList:
1284 if channel not in dataOut.channelList:
1291 raise ValueError, "Channel %d is not in dataOut.channelList"
1285 raise ValueError, "Channel %d is not in dataOut.channelList"
1292 channelIndexList.append(dataOut.channelList.index(channel))
1286 channelIndexList.append(dataOut.channelList.index(channel))
1293
1287
1294 x = dataOut.getTimeRange()
1288 x = dataOut.getTimeRange()
1295 #y = dataOut.getHeiRange()
1289 #y = dataOut.getHeiRange()
1296 factor = dataOut.normFactor
1290 factor = dataOut.normFactor
1297 noise = dataOut.noise[channelIndexList]/factor
1291 noise = dataOut.noise[channelIndexList]/factor
1298 noisedB = 10*numpy.log10(noise)
1292 noisedB = 10*numpy.log10(noise)
1299
1293
1300 thisDatetime = dataOut.datatime
1294 thisDatetime = dataOut.datatime
1301
1295
1302 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1296 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1303 xlabel = ""
1297 xlabel = ""
1304 ylabel = "Intensity (dB)"
1298 ylabel = "Intensity (dB)"
1305 update_figfile = False
1299 update_figfile = False
1306
1300
1307 if not self.isConfig:
1301 if not self.isConfig:
1308
1302
1309 nplots = 1
1303 nplots = 1
1310
1304
1311 self.setup(id=id,
1305 self.setup(id=id,
1312 nplots=nplots,
1306 nplots=nplots,
1313 wintitle=wintitle,
1307 wintitle=wintitle,
1314 showprofile=showprofile,
1308 showprofile=showprofile,
1315 show=show)
1309 show=show)
1316
1310
1317 if timerange != None:
1311 if timerange != None:
1318 self.timerange = timerange
1312 self.timerange = timerange
1319
1313
1320 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1314 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1321
1315
1322 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1316 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1323 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1317 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1324
1318
1325 self.FTP_WEI = ftp_wei
1319 self.FTP_WEI = ftp_wei
1326 self.EXP_CODE = exp_code
1320 self.EXP_CODE = exp_code
1327 self.SUB_EXP_CODE = sub_exp_code
1321 self.SUB_EXP_CODE = sub_exp_code
1328 self.PLOT_POS = plot_pos
1322 self.PLOT_POS = plot_pos
1329
1323
1330
1324
1331 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1325 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1332 self.isConfig = True
1326 self.isConfig = True
1333 self.figfile = figfile
1327 self.figfile = figfile
1334 self.xdata = numpy.array([])
1328 self.xdata = numpy.array([])
1335 self.ydata = numpy.array([])
1329 self.ydata = numpy.array([])
1336
1330
1337 update_figfile = True
1331 update_figfile = True
1338
1332
1339 #open file beacon phase
1333 #open file beacon phase
1340 path = '%s%03d' %(self.PREFIX, self.id)
1334 path = '%s%03d' %(self.PREFIX, self.id)
1341 noise_file = os.path.join(path,'%s.txt'%self.name)
1335 noise_file = os.path.join(path,'%s.txt'%self.name)
1342 self.filename_noise = os.path.join(figpath,noise_file)
1336 self.filename_noise = os.path.join(figpath,noise_file)
1343
1337
1344 self.setWinTitle(title)
1338 self.setWinTitle(title)
1345
1339
1346 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1340 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1347
1341
1348 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1342 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1349 axes = self.axesList[0]
1343 axes = self.axesList[0]
1350
1344
1351 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1345 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1352
1346
1353 if len(self.ydata)==0:
1347 if len(self.ydata)==0:
1354 self.ydata = noisedB.reshape(-1,1)
1348 self.ydata = noisedB.reshape(-1,1)
1355 else:
1349 else:
1356 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1350 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1357
1351
1358
1352
1359 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1353 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1360 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1354 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1361 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1355 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1362 XAxisAsTime=True, grid='both'
1356 XAxisAsTime=True, grid='both'
1363 )
1357 )
1364
1358
1365 self.draw()
1359 self.draw()
1366
1360
1367 if dataOut.ltctime >= self.xmax:
1361 if dataOut.ltctime >= self.xmax:
1368 self.counter_imagwr = wr_period
1362 self.counter_imagwr = wr_period
1369 self.isConfig = False
1363 self.isConfig = False
1370 update_figfile = True
1364 update_figfile = True
1371
1365
1372 self.save(figpath=figpath,
1366 self.save(figpath=figpath,
1373 figfile=figfile,
1367 figfile=figfile,
1374 save=save,
1368 save=save,
1375 ftp=ftp,
1369 ftp=ftp,
1376 wr_period=wr_period,
1370 wr_period=wr_period,
1377 thisDatetime=thisDatetime,
1371 thisDatetime=thisDatetime,
1378 update_figfile=update_figfile)
1372 update_figfile=update_figfile)
1379
1373
1380 #store data beacon phase
1374 #store data beacon phase
1381 if save:
1375 if save:
1382 self.save_data(self.filename_noise, noisedB, thisDatetime)
1376 self.save_data(self.filename_noise, noisedB, thisDatetime)
1383
1377
1384 class BeaconPhase(Figure):
1378 class BeaconPhase(Figure):
1385
1379
1386 __isConfig = None
1380 __isConfig = None
1387 __nsubplots = None
1381 __nsubplots = None
1388
1382
1389 PREFIX = 'beacon_phase'
1383 PREFIX = 'beacon_phase'
1390
1384
1391 def __init__(self, **kwargs):
1385 def __init__(self, **kwargs):
1392 Figure.__init__(self, **kwargs)
1386 Figure.__init__(self, **kwargs)
1393 self.timerange = 24*60*60
1387 self.timerange = 24*60*60
1394 self.isConfig = False
1388 self.isConfig = False
1395 self.__nsubplots = 1
1389 self.__nsubplots = 1
1396 self.counter_imagwr = 0
1390 self.counter_imagwr = 0
1397 self.WIDTH = 800
1391 self.WIDTH = 800
1398 self.HEIGHT = 400
1392 self.HEIGHT = 400
1399 self.WIDTHPROF = 120
1393 self.WIDTHPROF = 120
1400 self.HEIGHTPROF = 0
1394 self.HEIGHTPROF = 0
1401 self.xdata = None
1395 self.xdata = None
1402 self.ydata = None
1396 self.ydata = None
1403
1397
1404 self.PLOT_CODE = BEACON_CODE
1398 self.PLOT_CODE = BEACON_CODE
1405
1399
1406 self.FTP_WEI = None
1400 self.FTP_WEI = None
1407 self.EXP_CODE = None
1401 self.EXP_CODE = None
1408 self.SUB_EXP_CODE = None
1402 self.SUB_EXP_CODE = None
1409 self.PLOT_POS = None
1403 self.PLOT_POS = None
1410
1404
1411 self.filename_phase = None
1405 self.filename_phase = None
1412
1406
1413 self.figfile = None
1407 self.figfile = None
1414
1408
1415 self.xmin = None
1409 self.xmin = None
1416 self.xmax = None
1410 self.xmax = None
1417
1411
1418 def getSubplots(self):
1412 def getSubplots(self):
1419
1413
1420 ncol = 1
1414 ncol = 1
1421 nrow = 1
1415 nrow = 1
1422
1416
1423 return nrow, ncol
1417 return nrow, ncol
1424
1418
1425 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1419 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1426
1420
1427 self.__showprofile = showprofile
1421 self.__showprofile = showprofile
1428 self.nplots = nplots
1422 self.nplots = nplots
1429
1423
1430 ncolspan = 7
1424 ncolspan = 7
1431 colspan = 6
1425 colspan = 6
1432 self.__nsubplots = 2
1426 self.__nsubplots = 2
1433
1427
1434 self.createFigure(id = id,
1428 self.createFigure(id = id,
1435 wintitle = wintitle,
1429 wintitle = wintitle,
1436 widthplot = self.WIDTH+self.WIDTHPROF,
1430 widthplot = self.WIDTH+self.WIDTHPROF,
1437 heightplot = self.HEIGHT+self.HEIGHTPROF,
1431 heightplot = self.HEIGHT+self.HEIGHTPROF,
1438 show=show)
1432 show=show)
1439
1433
1440 nrow, ncol = self.getSubplots()
1434 nrow, ncol = self.getSubplots()
1441
1435
1442 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1436 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1443
1437
1444 def save_phase(self, filename_phase):
1438 def save_phase(self, filename_phase):
1445 f = open(filename_phase,'w+')
1439 f = open(filename_phase,'w+')
1446 f.write('\n\n')
1440 f.write('\n\n')
1447 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1441 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1448 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1442 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1449 f.close()
1443 f.close()
1450
1444
1451 def save_data(self, filename_phase, data, data_datetime):
1445 def save_data(self, filename_phase, data, data_datetime):
1452 f=open(filename_phase,'a')
1446 f=open(filename_phase,'a')
1453 timetuple_data = data_datetime.timetuple()
1447 timetuple_data = data_datetime.timetuple()
1454 day = str(timetuple_data.tm_mday)
1448 day = str(timetuple_data.tm_mday)
1455 month = str(timetuple_data.tm_mon)
1449 month = str(timetuple_data.tm_mon)
1456 year = str(timetuple_data.tm_year)
1450 year = str(timetuple_data.tm_year)
1457 hour = str(timetuple_data.tm_hour)
1451 hour = str(timetuple_data.tm_hour)
1458 minute = str(timetuple_data.tm_min)
1452 minute = str(timetuple_data.tm_min)
1459 second = str(timetuple_data.tm_sec)
1453 second = str(timetuple_data.tm_sec)
1460 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1454 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1461 f.close()
1455 f.close()
1462
1456
1463
1457
1464 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1458 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1465 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1459 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1466 timerange=None,
1460 timerange=None,
1467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1461 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1468 server=None, folder=None, username=None, password=None,
1462 server=None, folder=None, username=None, password=None,
1469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1463 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1470
1464
1471 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1465 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1472 return
1466 return
1473
1467
1474 if pairsList == None:
1468 if pairsList == None:
1475 pairsIndexList = dataOut.pairsIndexList[:10]
1469 pairsIndexList = dataOut.pairsIndexList[:10]
1476 else:
1470 else:
1477 pairsIndexList = []
1471 pairsIndexList = []
1478 for pair in pairsList:
1472 for pair in pairsList:
1479 if pair not in dataOut.pairsList:
1473 if pair not in dataOut.pairsList:
1480 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1474 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1481 pairsIndexList.append(dataOut.pairsList.index(pair))
1475 pairsIndexList.append(dataOut.pairsList.index(pair))
1482
1476
1483 if pairsIndexList == []:
1477 if pairsIndexList == []:
1484 return
1478 return
1485
1479
1486 # if len(pairsIndexList) > 4:
1480 # if len(pairsIndexList) > 4:
1487 # pairsIndexList = pairsIndexList[0:4]
1481 # pairsIndexList = pairsIndexList[0:4]
1488
1482
1489 hmin_index = None
1483 hmin_index = None
1490 hmax_index = None
1484 hmax_index = None
1491
1485
1492 if hmin != None and hmax != None:
1486 if hmin != None and hmax != None:
1493 indexes = numpy.arange(dataOut.nHeights)
1487 indexes = numpy.arange(dataOut.nHeights)
1494 hmin_list = indexes[dataOut.heightList >= hmin]
1488 hmin_list = indexes[dataOut.heightList >= hmin]
1495 hmax_list = indexes[dataOut.heightList <= hmax]
1489 hmax_list = indexes[dataOut.heightList <= hmax]
1496
1490
1497 if hmin_list.any():
1491 if hmin_list.any():
1498 hmin_index = hmin_list[0]
1492 hmin_index = hmin_list[0]
1499
1493
1500 if hmax_list.any():
1494 if hmax_list.any():
1501 hmax_index = hmax_list[-1]+1
1495 hmax_index = hmax_list[-1]+1
1502
1496
1503 x = dataOut.getTimeRange()
1497 x = dataOut.getTimeRange()
1504 #y = dataOut.getHeiRange()
1498 #y = dataOut.getHeiRange()
1505
1499
1506
1500
1507 thisDatetime = dataOut.datatime
1501 thisDatetime = dataOut.datatime
1508
1502
1509 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1503 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1510 xlabel = "Local Time"
1504 xlabel = "Local Time"
1511 ylabel = "Phase (degrees)"
1505 ylabel = "Phase (degrees)"
1512
1506
1513 update_figfile = False
1507 update_figfile = False
1514
1508
1515 nplots = len(pairsIndexList)
1509 nplots = len(pairsIndexList)
1516 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1510 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1517 phase_beacon = numpy.zeros(len(pairsIndexList))
1511 phase_beacon = numpy.zeros(len(pairsIndexList))
1518 for i in range(nplots):
1512 for i in range(nplots):
1519 pair = dataOut.pairsList[pairsIndexList[i]]
1513 pair = dataOut.pairsList[pairsIndexList[i]]
1520 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1514 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1521 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1515 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1522 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1516 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1523 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1517 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1524 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1518 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1525
1519
1526 #print "Phase %d%d" %(pair[0], pair[1])
1520 #print "Phase %d%d" %(pair[0], pair[1])
1527 #print phase[dataOut.beacon_heiIndexList]
1521 #print phase[dataOut.beacon_heiIndexList]
1528
1522
1529 if dataOut.beacon_heiIndexList:
1523 if dataOut.beacon_heiIndexList:
1530 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1524 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1531 else:
1525 else:
1532 phase_beacon[i] = numpy.average(phase)
1526 phase_beacon[i] = numpy.average(phase)
1533
1527
1534 if not self.isConfig:
1528 if not self.isConfig:
1535
1529
1536 nplots = len(pairsIndexList)
1530 nplots = len(pairsIndexList)
1537
1531
1538 self.setup(id=id,
1532 self.setup(id=id,
1539 nplots=nplots,
1533 nplots=nplots,
1540 wintitle=wintitle,
1534 wintitle=wintitle,
1541 showprofile=showprofile,
1535 showprofile=showprofile,
1542 show=show)
1536 show=show)
1543
1537
1544 if timerange != None:
1538 if timerange != None:
1545 self.timerange = timerange
1539 self.timerange = timerange
1546
1540
1547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1541 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1548
1542
1549 if ymin == None: ymin = 0
1543 if ymin == None: ymin = 0
1550 if ymax == None: ymax = 360
1544 if ymax == None: ymax = 360
1551
1545
1552 self.FTP_WEI = ftp_wei
1546 self.FTP_WEI = ftp_wei
1553 self.EXP_CODE = exp_code
1547 self.EXP_CODE = exp_code
1554 self.SUB_EXP_CODE = sub_exp_code
1548 self.SUB_EXP_CODE = sub_exp_code
1555 self.PLOT_POS = plot_pos
1549 self.PLOT_POS = plot_pos
1556
1550
1557 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1551 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1558 self.isConfig = True
1552 self.isConfig = True
1559 self.figfile = figfile
1553 self.figfile = figfile
1560 self.xdata = numpy.array([])
1554 self.xdata = numpy.array([])
1561 self.ydata = numpy.array([])
1555 self.ydata = numpy.array([])
1562
1556
1563 update_figfile = True
1557 update_figfile = True
1564
1558
1565 #open file beacon phase
1559 #open file beacon phase
1566 path = '%s%03d' %(self.PREFIX, self.id)
1560 path = '%s%03d' %(self.PREFIX, self.id)
1567 beacon_file = os.path.join(path,'%s.txt'%self.name)
1561 beacon_file = os.path.join(path,'%s.txt'%self.name)
1568 self.filename_phase = os.path.join(figpath,beacon_file)
1562 self.filename_phase = os.path.join(figpath,beacon_file)
1569 #self.save_phase(self.filename_phase)
1563 #self.save_phase(self.filename_phase)
1570
1564
1571
1565
1572 #store data beacon phase
1566 #store data beacon phase
1573 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1567 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1574
1568
1575 self.setWinTitle(title)
1569 self.setWinTitle(title)
1576
1570
1577
1571
1578 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1572 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1579
1573
1580 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1574 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1581
1575
1582 axes = self.axesList[0]
1576 axes = self.axesList[0]
1583
1577
1584 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1578 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1585
1579
1586 if len(self.ydata)==0:
1580 if len(self.ydata)==0:
1587 self.ydata = phase_beacon.reshape(-1,1)
1581 self.ydata = phase_beacon.reshape(-1,1)
1588 else:
1582 else:
1589 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1583 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1590
1584
1591
1585
1592 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1586 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1593 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1587 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1594 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1588 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1595 XAxisAsTime=True, grid='both'
1589 XAxisAsTime=True, grid='both'
1596 )
1590 )
1597
1591
1598 self.draw()
1592 self.draw()
1599
1593
1600 if dataOut.ltctime >= self.xmax:
1594 if dataOut.ltctime >= self.xmax:
1601 self.counter_imagwr = wr_period
1595 self.counter_imagwr = wr_period
1602 self.isConfig = False
1596 self.isConfig = False
1603 update_figfile = True
1597 update_figfile = True
1604
1598
1605 self.save(figpath=figpath,
1599 self.save(figpath=figpath,
1606 figfile=figfile,
1600 figfile=figfile,
1607 save=save,
1601 save=save,
1608 ftp=ftp,
1602 ftp=ftp,
1609 wr_period=wr_period,
1603 wr_period=wr_period,
1610 thisDatetime=thisDatetime,
1604 thisDatetime=thisDatetime,
1611 update_figfile=update_figfile)
1605 update_figfile=update_figfile)
@@ -1,3863 +1,3982
1 import numpy
1 import numpy
2 import math
2 import math
3 from scipy import optimize, interpolate, signal, stats, ndimage
3 from scipy import optimize, interpolate, signal, stats, ndimage
4 import scipy
4 import scipy
5 import re
5 import re
6 import datetime
6 import datetime
7 import copy
7 import copy
8 import sys
8 import sys
9 import importlib
9 import importlib
10 import itertools
10 import itertools
11 from multiprocessing import Pool, TimeoutError
11 from multiprocessing import Pool, TimeoutError
12 from multiprocessing.pool import ThreadPool
12 from multiprocessing.pool import ThreadPool
13 import copy_reg
13 import copy_reg
14 import cPickle
14 import cPickle
15 import types
15 import types
16 from functools import partial
16 from functools import partial
17 import time
17 import time
18 #from sklearn.cluster import KMeans
18 #from sklearn.cluster import KMeans
19
19
20 import matplotlib.pyplot as plt
20 import matplotlib.pyplot as plt
21
21
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
23 from jroproc_base import ProcessingUnit, Operation
23 from jroproc_base import ProcessingUnit, Operation
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
24 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
25 from scipy import asarray as ar,exp
25 from scipy import asarray as ar,exp
26 from scipy.optimize import curve_fit
26 from scipy.optimize import curve_fit
27
27
28 import warnings
28 import warnings
29 from numpy import NaN
29 from numpy import NaN
30 from scipy.optimize.optimize import OptimizeWarning
30 from scipy.optimize.optimize import OptimizeWarning
31 from IPython.parallel.controller.scheduler import numpy
31 warnings.filterwarnings('ignore')
32 warnings.filterwarnings('ignore')
32
33
33
34
34 SPEED_OF_LIGHT = 299792458
35 SPEED_OF_LIGHT = 299792458
35
36
36
37
37 '''solving pickling issue'''
38 '''solving pickling issue'''
38
39
39 def _pickle_method(method):
40 def _pickle_method(method):
40 func_name = method.im_func.__name__
41 func_name = method.im_func.__name__
41 obj = method.im_self
42 obj = method.im_self
42 cls = method.im_class
43 cls = method.im_class
43 return _unpickle_method, (func_name, obj, cls)
44 return _unpickle_method, (func_name, obj, cls)
44
45
45 def _unpickle_method(func_name, obj, cls):
46 def _unpickle_method(func_name, obj, cls):
46 for cls in cls.mro():
47 for cls in cls.mro():
47 try:
48 try:
48 func = cls.__dict__[func_name]
49 func = cls.__dict__[func_name]
49 except KeyError:
50 except KeyError:
50 pass
51 pass
51 else:
52 else:
52 break
53 break
53 return func.__get__(obj, cls)
54 return func.__get__(obj, cls)
54
55
55 class ParametersProc(ProcessingUnit):
56 class ParametersProc(ProcessingUnit):
56
57
57 nSeconds = None
58 nSeconds = None
58
59
59 def __init__(self):
60 def __init__(self):
60 ProcessingUnit.__init__(self)
61 ProcessingUnit.__init__(self)
61
62
62 # self.objectDict = {}
63 # self.objectDict = {}
63 self.buffer = None
64 self.buffer = None
64 self.firstdatatime = None
65 self.firstdatatime = None
65 self.profIndex = 0
66 self.profIndex = 0
66 self.dataOut = Parameters()
67 self.dataOut = Parameters()
67
68
68 def __updateObjFromInput(self):
69 def __updateObjFromInput(self):
69
70
70 self.dataOut.inputUnit = self.dataIn.type
71 self.dataOut.inputUnit = self.dataIn.type
71
72
72 self.dataOut.timeZone = self.dataIn.timeZone
73 self.dataOut.timeZone = self.dataIn.timeZone
73 self.dataOut.dstFlag = self.dataIn.dstFlag
74 self.dataOut.dstFlag = self.dataIn.dstFlag
74 self.dataOut.errorCount = self.dataIn.errorCount
75 self.dataOut.errorCount = self.dataIn.errorCount
75 self.dataOut.useLocalTime = self.dataIn.useLocalTime
76 self.dataOut.useLocalTime = self.dataIn.useLocalTime
76
77
77 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
78 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
78 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
79 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
79 self.dataOut.channelList = self.dataIn.channelList
80 self.dataOut.channelList = self.dataIn.channelList
80 self.dataOut.heightList = self.dataIn.heightList
81 self.dataOut.heightList = self.dataIn.heightList
81 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
82 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
82 # self.dataOut.nHeights = self.dataIn.nHeights
83 # self.dataOut.nHeights = self.dataIn.nHeights
83 # self.dataOut.nChannels = self.dataIn.nChannels
84 # self.dataOut.nChannels = self.dataIn.nChannels
84 self.dataOut.nBaud = self.dataIn.nBaud
85 self.dataOut.nBaud = self.dataIn.nBaud
85 self.dataOut.nCode = self.dataIn.nCode
86 self.dataOut.nCode = self.dataIn.nCode
86 self.dataOut.code = self.dataIn.code
87 self.dataOut.code = self.dataIn.code
87 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
88 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
88 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
89 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
89 # self.dataOut.utctime = self.firstdatatime
90 # self.dataOut.utctime = self.firstdatatime
90 self.dataOut.utctime = self.dataIn.utctime
91 self.dataOut.utctime = self.dataIn.utctime
91 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
92 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
92 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
93 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
93 self.dataOut.nCohInt = self.dataIn.nCohInt
94 self.dataOut.nCohInt = self.dataIn.nCohInt
94 # self.dataOut.nIncohInt = 1
95 # self.dataOut.nIncohInt = 1
95 self.dataOut.ippSeconds = self.dataIn.ippSeconds
96 self.dataOut.ippSeconds = self.dataIn.ippSeconds
96 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
97 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
97 self.dataOut.timeInterval1 = self.dataIn.timeInterval
98 self.dataOut.timeInterval1 = self.dataIn.timeInterval
98 self.dataOut.heightList = self.dataIn.getHeiRange()
99 self.dataOut.heightList = self.dataIn.getHeiRange()
99 self.dataOut.frequency = self.dataIn.frequency
100 self.dataOut.frequency = self.dataIn.frequency
100 self.dataOut.noise = self.dataIn.noise
101 self.dataOut.noise = self.dataIn.noise
101
102
102
103
103
104
104 def run(self):
105 def run(self):
105
106
106 #---------------------- Voltage Data ---------------------------
107 #---------------------- Voltage Data ---------------------------
107
108
108 if self.dataIn.type == "Voltage":
109 if self.dataIn.type == "Voltage":
109
110
110 self.__updateObjFromInput()
111 self.__updateObjFromInput()
111 self.dataOut.data_pre = self.dataIn.data.copy()
112 self.dataOut.data_pre = self.dataIn.data.copy()
112 self.dataOut.flagNoData = False
113 self.dataOut.flagNoData = False
113 self.dataOut.utctimeInit = self.dataIn.utctime
114 self.dataOut.utctimeInit = self.dataIn.utctime
114 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
115 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
115 return
116 return
116
117
117 #---------------------- Spectra Data ---------------------------
118 #---------------------- Spectra Data ---------------------------
118
119
119 if self.dataIn.type == "Spectra":
120 if self.dataIn.type == "Spectra":
120
121
121 self.dataOut.data_pre = (self.dataIn.data_spc , self.dataIn.data_cspc)
122 self.dataOut.data_pre = (self.dataIn.data_spc , self.dataIn.data_cspc)
122 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
123 print 'self.dataIn.data_spc', self.dataIn.data_spc.shape
123 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
124 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
124 self.dataOut.spc_noise = self.dataIn.getNoise()
125 self.dataOut.spc_noise = self.dataIn.getNoise()
125 self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) )
126 self.dataOut.spc_range = numpy.asanyarray((self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) ))
126
127
127 self.dataOut.normFactor = self.dataIn.normFactor
128 self.dataOut.normFactor = self.dataIn.normFactor
128 #self.dataOut.outputInterval = self.dataIn.outputInterval
129 #self.dataOut.outputInterval = self.dataIn.outputInterval
129 self.dataOut.groupList = self.dataIn.pairsList
130 self.dataOut.groupList = self.dataIn.pairsList
130 self.dataOut.flagNoData = False
131 self.dataOut.flagNoData = False
131 #print 'datain chandist ',self.dataIn.ChanDist
132 #print 'datain chandist ',self.dataIn.ChanDist
132 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
133 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
133 self.dataOut.ChanDist = self.dataIn.ChanDist
134 self.dataOut.ChanDist = self.dataIn.ChanDist
134 else: self.dataOut.ChanDist = None
135 else: self.dataOut.ChanDist = None
135
136
136 print 'datain chandist ',self.dataOut.ChanDist
137 print 'datain chandist ',self.dataOut.ChanDist
137
138
138 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
139 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
139 # self.dataOut.VelRange = self.dataIn.VelRange
140 # self.dataOut.VelRange = self.dataIn.VelRange
140 #else: self.dataOut.VelRange = None
141 #else: self.dataOut.VelRange = None
141
142
142 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
143 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
143 self.dataOut.RadarConst = self.dataIn.RadarConst
144 self.dataOut.RadarConst = self.dataIn.RadarConst
144
145
145 if hasattr(self.dataIn, 'NPW'): #NPW
146 if hasattr(self.dataIn, 'NPW'): #NPW
146 self.dataOut.NPW = self.dataIn.NPW
147 self.dataOut.NPW = self.dataIn.NPW
147
148
148 if hasattr(self.dataIn, 'COFA'): #COFA
149 if hasattr(self.dataIn, 'COFA'): #COFA
149 self.dataOut.COFA = self.dataIn.COFA
150 self.dataOut.COFA = self.dataIn.COFA
150
151
151
152
152
153
153 #---------------------- Correlation Data ---------------------------
154 #---------------------- Correlation Data ---------------------------
154
155
155 if self.dataIn.type == "Correlation":
156 if self.dataIn.type == "Correlation":
156 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
157 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
157
158
158 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
159 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
159 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
160 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
160 self.dataOut.groupList = (acf_pairs, ccf_pairs)
161 self.dataOut.groupList = (acf_pairs, ccf_pairs)
161
162
162 self.dataOut.abscissaList = self.dataIn.lagRange
163 self.dataOut.abscissaList = self.dataIn.lagRange
163 self.dataOut.noise = self.dataIn.noise
164 self.dataOut.noise = self.dataIn.noise
164 self.dataOut.data_SNR = self.dataIn.SNR
165 self.dataOut.data_SNR = self.dataIn.SNR
165 self.dataOut.flagNoData = False
166 self.dataOut.flagNoData = False
166 self.dataOut.nAvg = self.dataIn.nAvg
167 self.dataOut.nAvg = self.dataIn.nAvg
167
168
168 #---------------------- Parameters Data ---------------------------
169 #---------------------- Parameters Data ---------------------------
169
170
170 if self.dataIn.type == "Parameters":
171 if self.dataIn.type == "Parameters":
171 self.dataOut.copy(self.dataIn)
172 self.dataOut.copy(self.dataIn)
172 self.dataOut.flagNoData = False
173 self.dataOut.flagNoData = False
173
174
174 return True
175 return True
175
176
176 self.__updateObjFromInput()
177 self.__updateObjFromInput()
177 self.dataOut.utctimeInit = self.dataIn.utctime
178 self.dataOut.utctimeInit = self.dataIn.utctime
178 self.dataOut.paramInterval = self.dataIn.timeInterval
179 self.dataOut.paramInterval = self.dataIn.timeInterval
179
180
180 return
181 return
181
182
182
183
183 def target(tups):
184 def target(tups):
184
185
185 obj, args = tups
186 obj, args = tups
186 #print 'TARGETTT', obj, args
187 #print 'TARGETTT', obj, args
187 return obj.FitGau(args)
188 return obj.FitGau(args)
188
189
189
190
191 class SpectralFilters(Operation):
192
193 '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR
194
195 LimitR : It is the limit in m/s of Rainfall
196 LimitW : It is the limit in m/s for Winds
197
198 Input:
199
200 self.dataOut.data_pre : SPC and CSPC
201 self.dataOut.spc_range : To select wind and rainfall velocities
202
203 Affected:
204
205 self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind
206 self.dataOut.spcparam_range : Used in SpcParamPlot
207 self.dataOut.SPCparam : Used in PrecipitationProc
208
209
210 '''
211
212 def __init__(self, **kwargs):
213 Operation.__init__(self, **kwargs)
214 self.i=0
215
216 def run(self, dataOut, Rain_Velocity_Limit=1.5, Wind_Velocity_Limit=2.5):
217
218 #Limite de vientos
219 LimitR = Rain_Velocity_Limit
220 LimitW = Wind_Velocity_Limit
221
222 self.spc = dataOut.data_pre[0].copy()
223 self.cspc = dataOut.data_pre[1].copy()
224
225 self.Num_Hei = self.spc.shape[2]
226 self.Num_Bin = self.spc.shape[1]
227 self.Num_Chn = self.spc.shape[0]
228
229 VelRange = dataOut.spc_range[2]
230 TimeRange = dataOut.spc_range[1]
231 FrecRange = dataOut.spc_range[0]
232
233 Vmax= 2*numpy.max(dataOut.spc_range[2])
234 Tmax= 2*numpy.max(dataOut.spc_range[1])
235 Fmax= 2*numpy.max(dataOut.spc_range[0])
236
237 Breaker1R=VelRange[numpy.abs(VelRange-(-LimitR)).argmin()]
238 Breaker1R=numpy.where(VelRange == Breaker1R)
239
240 Breaker1W=VelRange[numpy.abs(VelRange-(-LimitW)).argmin()]
241 Breaker1W=numpy.where(VelRange == Breaker1W)
242
243 Breaker2W=VelRange[numpy.abs(VelRange-(LimitW)).argmin()]
244 Breaker2W=numpy.where(VelRange == Breaker2W)
245
246
247 '''Reacomodando SPCrange'''
248
249 VelRange=numpy.roll(VelRange,-Breaker1R[0],axis=0)
250
251 VelRange[-int(Breaker1R[0]):]+= Vmax
252
253 FrecRange=numpy.roll(FrecRange,-Breaker1R[0],axis=0)
254
255 FrecRange[-int(Breaker1R[0]):]+= Fmax
256
257 TimeRange=numpy.roll(TimeRange,-Breaker1R[0],axis=0)
258
259 TimeRange[-int(Breaker1R[0]):]+= Tmax
260
261 ''' ------------------ '''
262
263 Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()]
264 Breaker2R=numpy.where(VelRange == Breaker2R)
265
266
267
268
269 SPCroll = numpy.roll(self.spc,-Breaker1R[0],axis=1)
270
271 SPCcut = SPCroll.copy()
272 for i in range(self.Num_Chn):
273 SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i]
274
275 self.spc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
276 self.spc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
277
278 self.cspc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i]
279 self.cspc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i]
280
281
282 SPC_ch1 = SPCroll
283
284 SPC_ch2 = SPCcut
285
286 SPCparam = (SPC_ch1, SPC_ch2, self.spc)
287 dataOut.SPCparam = numpy.asarray(SPCparam)
288
289 dataOut.data_pre= (self.spc , self.cspc)
290
291 #dataOut.data_preParam = (self.spc , self.cspc)
292
293 dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1])
294
295 dataOut.spcparam_range[2]=VelRange
296 dataOut.spcparam_range[1]=TimeRange
297 dataOut.spcparam_range[0]=FrecRange
298
299
300
301
190 class GaussianFit(Operation):
302 class GaussianFit(Operation):
191
303
192 '''
304 '''
193 Function that fit of one and two generalized gaussians (gg) based
305 Function that fit of one and two generalized gaussians (gg) based
194 on the PSD shape across an "power band" identified from a cumsum of
306 on the PSD shape across an "power band" identified from a cumsum of
195 the measured spectrum - noise.
307 the measured spectrum - noise.
196
308
197 Input:
309 Input:
198 self.dataOut.data_pre : SelfSpectra
310 self.dataOut.data_pre : SelfSpectra
199
311
200 Output:
312 Output:
201 self.dataOut.GauSPC : SPC_ch1, SPC_ch2
313 self.dataOut.SPCparam : SPC_ch1, SPC_ch2
202
314
203 '''
315 '''
204 def __init__(self, **kwargs):
316 def __init__(self, **kwargs):
205 Operation.__init__(self, **kwargs)
317 Operation.__init__(self, **kwargs)
206 self.i=0
318 self.i=0
207
319
208
320
209 def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
321 def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
210 """This routine will find a couple of generalized Gaussians to a power spectrum
322 """This routine will find a couple of generalized Gaussians to a power spectrum
211 input: spc
323 input: spc
212 output:
324 output:
213 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
325 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
214 """
326 """
215
327
216 self.spc = dataOut.data_pre[0].copy()
328 self.spc = dataOut.data_pre[0].copy()
217
329
218
330
219 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
331 print 'SelfSpectra Shape', numpy.asarray(self.spc).shape
220
332
221
333
222 #plt.figure(50)
334 #plt.figure(50)
223 #plt.subplot(121)
335 #plt.subplot(121)
224 #plt.plot(self.spc,'k',label='spc(66)')
336 #plt.plot(self.spc,'k',label='spc(66)')
225 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
337 #plt.plot(xFrec,ySamples[1],'g',label='Ch1')
226 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
338 #plt.plot(xFrec,ySamples[2],'r',label='Ch2')
227 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
339 #plt.plot(xFrec,FitGauss,'yo:',label='fit')
228 #plt.legend()
340 #plt.legend()
229 #plt.title('DATOS A ALTURA DE 7500 METROS')
341 #plt.title('DATOS A ALTURA DE 7500 METROS')
230 #plt.show()
342 #plt.show()
231
343
232 self.Num_Hei = self.spc.shape[2]
344 self.Num_Hei = self.spc.shape[2]
233 #self.Num_Bin = len(self.spc)
345 #self.Num_Bin = len(self.spc)
234 self.Num_Bin = self.spc.shape[1]
346 self.Num_Bin = self.spc.shape[1]
235 self.Num_Chn = self.spc.shape[0]
347 self.Num_Chn = self.spc.shape[0]
236 Vrange = dataOut.abscissaList
348 Vrange = dataOut.abscissaList
237
349
238 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
350 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
239 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
351 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
240 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
352 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
241 SPC_ch1[:] = numpy.NaN
353 SPC_ch1[:] = numpy.NaN
242 SPC_ch2[:] = numpy.NaN
354 SPC_ch2[:] = numpy.NaN
243
355
244
356
245 start_time = time.time()
357 start_time = time.time()
246
358
247 noise_ = dataOut.spc_noise[0].copy()
359 noise_ = dataOut.spc_noise[0].copy()
248
360
249
361
250 pool = Pool(processes=self.Num_Chn)
362 pool = Pool(processes=self.Num_Chn)
251 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
363 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
252 objs = [self for __ in range(self.Num_Chn)]
364 objs = [self for __ in range(self.Num_Chn)]
253 attrs = zip(objs, args)
365 attrs = zip(objs, args)
254 gauSPC = pool.map(target, attrs)
366 gauSPC = pool.map(target, attrs)
255 dataOut.GauSPC = numpy.asarray(gauSPC)
367 dataOut.SPCparam = numpy.asarray(SPCparam)
256
368
257
369
258
370
259 print '========================================================'
371 print '========================================================'
260 print 'total_time: ', time.time()-start_time
372 print 'total_time: ', time.time()-start_time
261
373
262 # re-normalizing spc and noise
374 # re-normalizing spc and noise
263 # This part differs from gg1
375 # This part differs from gg1
264
376
265
377
266
378
267 ''' Parameters:
379 ''' Parameters:
268 1. Amplitude
380 1. Amplitude
269 2. Shift
381 2. Shift
270 3. Width
382 3. Width
271 4. Power
383 4. Power
272 '''
384 '''
273
385
274
386
275 ###############################################################################
387 ###############################################################################
276 def FitGau(self, X):
388 def FitGau(self, X):
277
389
278 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
390 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
279 #print 'VARSSSS', ch, pnoise, noise, num_intg
391 #print 'VARSSSS', ch, pnoise, noise, num_intg
280
392
281 #print 'HEIGHTS', self.Num_Hei
393 #print 'HEIGHTS', self.Num_Hei
282
394
283 GauSPC = []
395 SPCparam = []
284 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
396 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
285 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
397 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
286 SPC_ch1[:] = 0#numpy.NaN
398 SPC_ch1[:] = 0#numpy.NaN
287 SPC_ch2[:] = 0#numpy.NaN
399 SPC_ch2[:] = 0#numpy.NaN
288
400
289
401
290
402
291 for ht in range(self.Num_Hei):
403 for ht in range(self.Num_Hei):
292 #print (numpy.asarray(self.spc).shape)
404 #print (numpy.asarray(self.spc).shape)
293
405
294 #print 'TTTTT', ch , ht
406 #print 'TTTTT', ch , ht
295 #print self.spc.shape
407 #print self.spc.shape
296
408
297
409
298 spc = numpy.asarray(self.spc)[ch,:,ht]
410 spc = numpy.asarray(self.spc)[ch,:,ht]
299
411
300 #############################################
412 #############################################
301 # normalizing spc and noise
413 # normalizing spc and noise
302 # This part differs from gg1
414 # This part differs from gg1
303 spc_norm_max = max(spc)
415 spc_norm_max = max(spc)
304 #spc = spc / spc_norm_max
416 #spc = spc / spc_norm_max
305 pnoise = pnoise #/ spc_norm_max
417 pnoise = pnoise #/ spc_norm_max
306 #############################################
418 #############################################
307
419
308 fatspectra=1.0
420 fatspectra=1.0
309
421
310 wnoise = noise_ #/ spc_norm_max
422 wnoise = noise_ #/ spc_norm_max
311 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
423 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
312 #if wnoise>1.1*pnoise: # to be tested later
424 #if wnoise>1.1*pnoise: # to be tested later
313 # wnoise=pnoise
425 # wnoise=pnoise
314 noisebl=wnoise*0.9;
426 noisebl=wnoise*0.9;
315 noisebh=wnoise*1.1
427 noisebh=wnoise*1.1
316 spc=spc-wnoise
428 spc=spc-wnoise
317 # print 'wnoise', noise_[0], spc_norm_max, wnoise
429 # print 'wnoise', noise_[0], spc_norm_max, wnoise
318 minx=numpy.argmin(spc)
430 minx=numpy.argmin(spc)
319 #spcs=spc.copy()
431 #spcs=spc.copy()
320 spcs=numpy.roll(spc,-minx)
432 spcs=numpy.roll(spc,-minx)
321 cum=numpy.cumsum(spcs)
433 cum=numpy.cumsum(spcs)
322 tot_noise=wnoise * self.Num_Bin #64;
434 tot_noise=wnoise * self.Num_Bin #64;
323 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
435 #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise
324 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
436 #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? '''
325 #snr=tot_signal/tot_noise
437 #snr=tot_signal/tot_noise
326 #snr=cum[-1]/tot_noise
438 #snr=cum[-1]/tot_noise
327 snr = sum(spcs)/tot_noise
439 snr = sum(spcs)/tot_noise
328 snrdB=10.*numpy.log10(snr)
440 snrdB=10.*numpy.log10(snr)
329
441
330 if snrdB < SNRlimit :
442 if snrdB < SNRlimit :
331 snr = numpy.NaN
443 snr = numpy.NaN
332 SPC_ch1[:,ht] = 0#numpy.NaN
444 SPC_ch1[:,ht] = 0#numpy.NaN
333 SPC_ch1[:,ht] = 0#numpy.NaN
445 SPC_ch1[:,ht] = 0#numpy.NaN
334 GauSPC = (SPC_ch1,SPC_ch2)
446 SPCparam = (SPC_ch1,SPC_ch2)
335 continue
447 continue
336 #print 'snr',snrdB #, sum(spcs) , tot_noise
448 #print 'snr',snrdB #, sum(spcs) , tot_noise
337
449
338
450
339
451
340 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
452 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
341 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
453 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
342
454
343 cummax=max(cum);
455 cummax=max(cum);
344 epsi=0.08*fatspectra # cumsum to narrow down the energy region
456 epsi=0.08*fatspectra # cumsum to narrow down the energy region
345 cumlo=cummax*epsi;
457 cumlo=cummax*epsi;
346 cumhi=cummax*(1-epsi)
458 cumhi=cummax*(1-epsi)
347 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
459 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
348
460
349
461
350 if len(powerindex) < 1:# case for powerindex 0
462 if len(powerindex) < 1:# case for powerindex 0
351 continue
463 continue
352 powerlo=powerindex[0]
464 powerlo=powerindex[0]
353 powerhi=powerindex[-1]
465 powerhi=powerindex[-1]
354 powerwidth=powerhi-powerlo
466 powerwidth=powerhi-powerlo
355
467
356 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
468 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
357 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
469 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
358 midpeak=(firstpeak+secondpeak)/2.
470 midpeak=(firstpeak+secondpeak)/2.
359 firstamp=spcs[int(firstpeak)]
471 firstamp=spcs[int(firstpeak)]
360 secondamp=spcs[int(secondpeak)]
472 secondamp=spcs[int(secondpeak)]
361 midamp=spcs[int(midpeak)]
473 midamp=spcs[int(midpeak)]
362
474
363 x=numpy.arange( self.Num_Bin )
475 x=numpy.arange( self.Num_Bin )
364 y_data=spc+wnoise
476 y_data=spc+wnoise
365
477
366 ''' single Gaussian '''
478 ''' single Gaussian '''
367 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
479 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
368 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
480 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
369 power0=2.
481 power0=2.
370 amplitude0=midamp
482 amplitude0=midamp
371 state0=[shift0,width0,amplitude0,power0,wnoise]
483 state0=[shift0,width0,amplitude0,power0,wnoise]
372 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
484 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
373 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
485 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
374
486
375 chiSq1=lsq1[1];
487 chiSq1=lsq1[1];
376
488
377
489
378 if fatspectra<1.0 and powerwidth<4:
490 if fatspectra<1.0 and powerwidth<4:
379 choice=0
491 choice=0
380 Amplitude0=lsq1[0][2]
492 Amplitude0=lsq1[0][2]
381 shift0=lsq1[0][0]
493 shift0=lsq1[0][0]
382 width0=lsq1[0][1]
494 width0=lsq1[0][1]
383 p0=lsq1[0][3]
495 p0=lsq1[0][3]
384 Amplitude1=0.
496 Amplitude1=0.
385 shift1=0.
497 shift1=0.
386 width1=0.
498 width1=0.
387 p1=0.
499 p1=0.
388 noise=lsq1[0][4]
500 noise=lsq1[0][4]
389 #return (numpy.array([shift0,width0,Amplitude0,p0]),
501 #return (numpy.array([shift0,width0,Amplitude0,p0]),
390 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
502 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
391
503
392 ''' two gaussians '''
504 ''' two gaussians '''
393 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
505 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
394 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
506 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
395 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
507 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
396 width0=powerwidth/6.;
508 width0=powerwidth/6.;
397 width1=width0
509 width1=width0
398 power0=2.;
510 power0=2.;
399 power1=power0
511 power1=power0
400 amplitude0=firstamp;
512 amplitude0=firstamp;
401 amplitude1=secondamp
513 amplitude1=secondamp
402 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
514 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
403 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
515 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
404 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
516 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
405 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
517 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
406
518
407 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
519 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
408
520
409
521
410 chiSq2=lsq2[1];
522 chiSq2=lsq2[1];
411
523
412
524
413
525
414 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
526 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
415
527
416 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
528 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
417 if oneG:
529 if oneG:
418 choice=0
530 choice=0
419 else:
531 else:
420 w1=lsq2[0][1]; w2=lsq2[0][5]
532 w1=lsq2[0][1]; w2=lsq2[0][5]
421 a1=lsq2[0][2]; a2=lsq2[0][6]
533 a1=lsq2[0][2]; a2=lsq2[0][6]
422 p1=lsq2[0][3]; p2=lsq2[0][7]
534 p1=lsq2[0][3]; p2=lsq2[0][7]
423 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
535 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
424 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
536 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
425 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
537 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
426
538
427 if gp1>gp2:
539 if gp1>gp2:
428 if a1>0.7*a2:
540 if a1>0.7*a2:
429 choice=1
541 choice=1
430 else:
542 else:
431 choice=2
543 choice=2
432 elif gp2>gp1:
544 elif gp2>gp1:
433 if a2>0.7*a1:
545 if a2>0.7*a1:
434 choice=2
546 choice=2
435 else:
547 else:
436 choice=1
548 choice=1
437 else:
549 else:
438 choice=numpy.argmax([a1,a2])+1
550 choice=numpy.argmax([a1,a2])+1
439 #else:
551 #else:
440 #choice=argmin([std2a,std2b])+1
552 #choice=argmin([std2a,std2b])+1
441
553
442 else: # with low SNR go to the most energetic peak
554 else: # with low SNR go to the most energetic peak
443 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
555 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
444
556
445
557
446 shift0=lsq2[0][0];
558 shift0=lsq2[0][0];
447 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
559 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
448 shift1=lsq2[0][4];
560 shift1=lsq2[0][4];
449 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
561 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
450
562
451 max_vel = 1.0
563 max_vel = 1.0
452
564
453 #first peak will be 0, second peak will be 1
565 #first peak will be 0, second peak will be 1
454 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
566 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
455 shift0=lsq2[0][0]
567 shift0=lsq2[0][0]
456 width0=lsq2[0][1]
568 width0=lsq2[0][1]
457 Amplitude0=lsq2[0][2]
569 Amplitude0=lsq2[0][2]
458 p0=lsq2[0][3]
570 p0=lsq2[0][3]
459
571
460 shift1=lsq2[0][4]
572 shift1=lsq2[0][4]
461 width1=lsq2[0][5]
573 width1=lsq2[0][5]
462 Amplitude1=lsq2[0][6]
574 Amplitude1=lsq2[0][6]
463 p1=lsq2[0][7]
575 p1=lsq2[0][7]
464 noise=lsq2[0][8]
576 noise=lsq2[0][8]
465 else:
577 else:
466 shift1=lsq2[0][0]
578 shift1=lsq2[0][0]
467 width1=lsq2[0][1]
579 width1=lsq2[0][1]
468 Amplitude1=lsq2[0][2]
580 Amplitude1=lsq2[0][2]
469 p1=lsq2[0][3]
581 p1=lsq2[0][3]
470
582
471 shift0=lsq2[0][4]
583 shift0=lsq2[0][4]
472 width0=lsq2[0][5]
584 width0=lsq2[0][5]
473 Amplitude0=lsq2[0][6]
585 Amplitude0=lsq2[0][6]
474 p0=lsq2[0][7]
586 p0=lsq2[0][7]
475 noise=lsq2[0][8]
587 noise=lsq2[0][8]
476
588
477 if Amplitude0<0.05: # in case the peak is noise
589 if Amplitude0<0.05: # in case the peak is noise
478 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
590 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
479 if Amplitude1<0.05:
591 if Amplitude1<0.05:
480 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
592 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
481
593
482
594
483 # if choice==0: # pick the single gaussian fit
595 # if choice==0: # pick the single gaussian fit
484 # Amplitude0=lsq1[0][2]
596 # Amplitude0=lsq1[0][2]
485 # shift0=lsq1[0][0]
597 # shift0=lsq1[0][0]
486 # width0=lsq1[0][1]
598 # width0=lsq1[0][1]
487 # p0=lsq1[0][3]
599 # p0=lsq1[0][3]
488 # Amplitude1=0.
600 # Amplitude1=0.
489 # shift1=0.
601 # shift1=0.
490 # width1=0.
602 # width1=0.
491 # p1=0.
603 # p1=0.
492 # noise=lsq1[0][4]
604 # noise=lsq1[0][4]
493 # elif choice==1: # take the first one of the 2 gaussians fitted
605 # elif choice==1: # take the first one of the 2 gaussians fitted
494 # Amplitude0 = lsq2[0][2]
606 # Amplitude0 = lsq2[0][2]
495 # shift0 = lsq2[0][0]
607 # shift0 = lsq2[0][0]
496 # width0 = lsq2[0][1]
608 # width0 = lsq2[0][1]
497 # p0 = lsq2[0][3]
609 # p0 = lsq2[0][3]
498 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
610 # Amplitude1 = lsq2[0][6] # This is 0 in gg1
499 # shift1 = lsq2[0][4] # This is 0 in gg1
611 # shift1 = lsq2[0][4] # This is 0 in gg1
500 # width1 = lsq2[0][5] # This is 0 in gg1
612 # width1 = lsq2[0][5] # This is 0 in gg1
501 # p1 = lsq2[0][7] # This is 0 in gg1
613 # p1 = lsq2[0][7] # This is 0 in gg1
502 # noise = lsq2[0][8]
614 # noise = lsq2[0][8]
503 # else: # the second one
615 # else: # the second one
504 # Amplitude0 = lsq2[0][6]
616 # Amplitude0 = lsq2[0][6]
505 # shift0 = lsq2[0][4]
617 # shift0 = lsq2[0][4]
506 # width0 = lsq2[0][5]
618 # width0 = lsq2[0][5]
507 # p0 = lsq2[0][7]
619 # p0 = lsq2[0][7]
508 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
620 # Amplitude1 = lsq2[0][2] # This is 0 in gg1
509 # shift1 = lsq2[0][0] # This is 0 in gg1
621 # shift1 = lsq2[0][0] # This is 0 in gg1
510 # width1 = lsq2[0][1] # This is 0 in gg1
622 # width1 = lsq2[0][1] # This is 0 in gg1
511 # p1 = lsq2[0][3] # This is 0 in gg1
623 # p1 = lsq2[0][3] # This is 0 in gg1
512 # noise = lsq2[0][8]
624 # noise = lsq2[0][8]
513
625
514 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
626 #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0)
515 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
627 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
516 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
628 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
517 #print 'SPC_ch1.shape',SPC_ch1.shape
629 #print 'SPC_ch1.shape',SPC_ch1.shape
518 #print 'SPC_ch2.shape',SPC_ch2.shape
630 #print 'SPC_ch2.shape',SPC_ch2.shape
519 #dataOut.data_param = SPC_ch1
631 #dataOut.data_param = SPC_ch1
520 GauSPC = (SPC_ch1,SPC_ch2)
632 SPCparam = (SPC_ch1,SPC_ch2)
521 #GauSPC[1] = SPC_ch2
633 #GauSPC[1] = SPC_ch2
522
634
523 # print 'shift0', shift0
635 # print 'shift0', shift0
524 # print 'Amplitude0', Amplitude0
636 # print 'Amplitude0', Amplitude0
525 # print 'width0', width0
637 # print 'width0', width0
526 # print 'p0', p0
638 # print 'p0', p0
527 # print '========================'
639 # print '========================'
528 # print 'shift1', shift1
640 # print 'shift1', shift1
529 # print 'Amplitude1', Amplitude1
641 # print 'Amplitude1', Amplitude1
530 # print 'width1', width1
642 # print 'width1', width1
531 # print 'p1', p1
643 # print 'p1', p1
532 # print 'noise', noise
644 # print 'noise', noise
533 # print 's_noise', wnoise
645 # print 's_noise', wnoise
534
646
535 return GauSPC
647 return GauSPC
536
648
537 def y_model1(self,x,state):
649 def y_model1(self,x,state):
538 shift0,width0,amplitude0,power0,noise=state
650 shift0,width0,amplitude0,power0,noise=state
539 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
651 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
540
652
541 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
653 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
542
654
543 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
655 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
544 return model0+model0u+model0d+noise
656 return model0+model0u+model0d+noise
545
657
546 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
658 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
547 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
659 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
548 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
660 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
549
661
550 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
662 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
551
663
552 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
664 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
553 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
665 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
554
666
555 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
667 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
556
668
557 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
669 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
558 return model0+model0u+model0d+model1+model1u+model1d+noise
670 return model0+model0u+model0d+model1+model1u+model1d+noise
559
671
560 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
672 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
561
673
562 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
674 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
563
675
564 def misfit2(self,state,y_data,x,num_intg):
676 def misfit2(self,state,y_data,x,num_intg):
565 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
677 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
566
678
567
679
568
680
569 class PrecipitationProc(Operation):
681 class PrecipitationProc(Operation):
570
682
571 '''
683 '''
572 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
684 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
573
685
574 Input:
686 Input:
575 self.dataOut.data_pre : SelfSpectra
687 self.dataOut.data_pre : SelfSpectra
576
688
577 Output:
689 Output:
578
690
579 self.dataOut.data_output : Reflectivity factor, rainfall Rate
691 self.dataOut.data_output : Reflectivity factor, rainfall Rate
580
692
581
693
582 Parameters affected:
694 Parameters affected:
583 '''
695 '''
584
696 def gaus(self,xSamples,Amp,Mu,Sigma):
697 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
698
699
700
701 def Moments(self, ySamples, xSamples):
702 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
703 yNorm = ySamples / Pot
704
705 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
706 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
707 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
708
709 return numpy.array([Pot, Vr, Desv])
585
710
586 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
711 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
587 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
712 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
588
713
589
714
590 Velrange = dataOut.abscissaList
715 Velrange = dataOut.spc_range[2]
716 FrecRange = dataOut.spc_range[0]
717
718 dV= Velrange[1]-Velrange[0]
719 dF= FrecRange[1]-FrecRange[0]
591
720
592 if radar == "MIRA35C" :
721 if radar == "MIRA35C" :
593
722
594 self.spc = dataOut.data_pre[0].copy()
723 self.spc = dataOut.data_pre[0].copy()
595 self.Num_Hei = self.spc.shape[2]
724 self.Num_Hei = self.spc.shape[2]
596 self.Num_Bin = self.spc.shape[1]
725 self.Num_Bin = self.spc.shape[1]
597 self.Num_Chn = self.spc.shape[0]
726 self.Num_Chn = self.spc.shape[0]
598 Ze = self.dBZeMODE2(dataOut)
727 Ze = self.dBZeMODE2(dataOut)
599
728
600 else:
729 else:
601
730
602 self.spc = dataOut.GauSPC[1] #dataOut.data_pre[0].copy()
731 self.spc = dataOut.SPCparam[1] #dataOut.data_pre[0].copy() #
603 self.Num_Hei = self.spc.shape[2]
732 self.Num_Hei = self.spc.shape[2]
604 self.Num_Bin = self.spc.shape[1]
733 self.Num_Bin = self.spc.shape[1]
605 self.Num_Chn = self.spc.shape[0]
734 self.Num_Chn = self.spc.shape[0]
606 print '==================== SPC SHAPE',numpy.shape(self.spc)
735 print '==================== SPC SHAPE',numpy.shape(self.spc)
607
736
608
737
609 ''' Se obtiene la constante del RADAR '''
738 ''' Se obtiene la constante del RADAR '''
610
739
611 self.Pt = Pt
740 self.Pt = Pt
612 self.Gt = Gt
741 self.Gt = Gt
613 self.Gr = Gr
742 self.Gr = Gr
614 self.Lambda = Lambda
743 self.Lambda = Lambda
615 self.aL = aL
744 self.aL = aL
616 self.tauW = tauW
745 self.tauW = tauW
617 self.ThetaT = ThetaT
746 self.ThetaT = ThetaT
618 self.ThetaR = ThetaR
747 self.ThetaR = ThetaR
619
748
620 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
749 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
621 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
750 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
622 RadarConstant = Numerator / Denominator
751 RadarConstant = 4.1396e+08# Numerator / Denominator
623 print '***'
752 print '***'
624 print '*** RadarConstant' , RadarConstant, '****'
753 print '*** RadarConstant' , RadarConstant, '****'
625 print '***'
754 print '***'
626 ''' ============================= '''
755 ''' ============================= '''
627
756
628 SPCmean = numpy.mean(self.spc,0)
757 SPCmean = numpy.mean(self.spc,0)
629 ETA = numpy.zeros(self.Num_Hei,self.Num_Bin)
758 ETAf = numpy.zeros([self.Num_Bin,self.Num_Hei])
759 ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei])
760 ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei])
761
630 Pr = self.spc[0,:,:]
762 Pr = self.spc[0,:,:]
631
763
632 VelMeteoro = numpy.mean(SPCmean,axis=0)
764 VelMeteoro = numpy.mean(SPCmean,axis=0)
633 print '==================== Vel SHAPE',VelMeteoro
634
765
635 D_range = numpy.zeros(self.Num_Hei)
766 #print '==================== Vel SHAPE',VelMeteoro
636 SIGMA = numpy.zeros(self.Num_Hei)
767
637 N_dist = numpy.zeros(self.Num_Hei)
768 D_range = numpy.zeros([self.Num_Bin,self.Num_Hei])
638 EqSec = numpy.zeros(self.Num_Hei)
769 SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei])
770 N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei])
771 D_mean = numpy.zeros(self.Num_Hei)
639 del_V = numpy.zeros(self.Num_Hei)
772 del_V = numpy.zeros(self.Num_Hei)
773 Z = numpy.zeros(self.Num_Hei)
774 Ze = numpy.zeros(self.Num_Hei)
775 RR = numpy.zeros(self.Num_Hei)
640
776
641
777
642 for R in range(self.Num_Hei):
778 for R in range(self.Num_Hei):
643 ETA[:,R] = RadarConstant * Pr[:,R] * R**2 #Reflectivity (ETA)
644
779
645 h = R + Altitude #Range from ground to radar pulse altitude
780 h = R*75 + Altitude #Range from ground to radar pulse altitude
646 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
781 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
647
782
648 D_range[R] = numpy.log( (9.65 - (VelMeteoro[R]/del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
783 D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Range of Diameter of drops related to velocity
649 SIGMA[R] = numpy.pi**5 / Lambda**4 * Km * D_range[R]**6 #Equivalent Section of drops (sigma)
784
650 #print '******* D_range ********', self.Num_Hei
785 ETAf[:,R] = 1/RadarConstant * Pr[:,R] * (R*0.075)**2 #Reflectivity (ETA)
651 #print D_range
786
652 N_dist[R] = ETA[R] / SIGMA[R]
787 ETAv[:,R]=ETAf[:,R]*dF/dV
788
789 ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R])
790
791 SIGMA[:,R] = numpy.pi**5 / Lambda**4 * Km * D_range[:,R]**6 #Equivalent Section of drops (sigma)
792
793 N_dist[:,R] = ETAd[:,R] / SIGMA[:,R]
794
795 DMoments = self.Moments(Pr[:,R], D_range[:,R])
653
796
797 try:
798 popt01,pcov = curve_fit(self.gaus, D_range[:,R] , Pr[:,R] , p0=DMoments)
799 except:
800 popt01=numpy.zeros(3)
801 popt01[1]= DMoments[1]
802 D_mean[R]=popt01[1]
803
804 Z[R] = numpy.nansum( N_dist[:,R] * D_range[:,R]**6 )
654
805
806 RR[R] = 6*10**-4.*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate
655
807
656 Ze = (ETA * Lambda**4) / (numpy.pi * Km)
808 Ze[R] = (numpy.nansum(ETAd[:,R]) * Lambda**4) / (numpy.pi * Km)
657 Z = numpy.sum( N_dist * D_range**6 )
658 #print 'Velrange',len(Velrange), 'D_range', len(D_range)
659 RR = 6*10**-4*numpy.pi * numpy.sum( D_range[R]**3 * N_dist[R] * VelMeteoro[R] ) #Rainfall rate
660
809
661
810
662
811
663 RR2 = (Ze/200)**(1/1.6)
812 RR2 = (Z/200)**(1/1.6)
664 dBRR = 10*numpy.log10(RR)
813 dBRR = 10*numpy.log10(RR)
814 dBRR2 = 10*numpy.log10(RR2)
665
815
666 dBZe = 10*numpy.log10(Ze)
816 dBZe = 10*numpy.log10(Ze)
667 dataOut.data_output = Ze
817 dBZ = 10*numpy.log10(Z)
818
819 dataOut.data_output = Z
668 dataOut.data_param = numpy.ones([3,self.Num_Hei])
820 dataOut.data_param = numpy.ones([3,self.Num_Hei])
669 dataOut.channelList = [0,1,2]
821 dataOut.channelList = [0,1,2]
670 print 'channelList', dataOut.channelList
822
671 dataOut.data_param[0]=dBZe
823 dataOut.data_param[0]=dBZ
672 dataOut.data_param[1]=dBRR
824 dataOut.data_param[1]=dBZe
825 dataOut.data_param[2]=dBRR2
826
673 print 'RR SHAPE', dBRR.shape
827 print 'RR SHAPE', dBRR.shape
674 print 'Ze SHAPE', dBZe.shape
828 #print 'Ze ', dBZe
675 print 'dataOut.data_param SHAPE', dataOut.data_param.shape
829 print 'Z ', dBZ
830 print 'RR ', dBRR
831 #print 'RR2 ', dBRR2
832 #print 'D_mean', D_mean
833 #print 'del_V', del_V
834 #print 'D_range',D_range.shape, D_range[:,30]
835 #print 'Velrange', Velrange
836 #print 'numpy.nansum( N_dist[:,R]', numpy.nansum( N_dist, axis=0)
837 #print 'dataOut.data_param SHAPE', dataOut.data_param.shape
676
838
677
839
678 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
840 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
679
841
680 NPW = dataOut.NPW
842 NPW = dataOut.NPW
681 COFA = dataOut.COFA
843 COFA = dataOut.COFA
682
844
683 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
845 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
684 RadarConst = dataOut.RadarConst
846 RadarConst = dataOut.RadarConst
685 #frequency = 34.85*10**9
847 #frequency = 34.85*10**9
686
848
687 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
849 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
688 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
850 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
689
851
690 ETA = numpy.sum(SNR,1)
852 ETA = numpy.sum(SNR,1)
691 print 'ETA' , ETA
853 print 'ETA' , ETA
692 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
854 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
693
855
694 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
856 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
695
857
696 for r in range(self.Num_Hei):
858 for r in range(self.Num_Hei):
697
859
698 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
860 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
699 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
861 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
700
862
701 return Ze
863 return Ze
702
864
703 # def GetRadarConstant(self):
865 # def GetRadarConstant(self):
704 #
866 #
705 # """
867 # """
706 # Constants:
868 # Constants:
707 #
869 #
708 # Pt: Transmission Power dB 5kW 5000
870 # Pt: Transmission Power dB 5kW 5000
709 # Gt: Transmission Gain dB 24.7 dB 295.1209
871 # Gt: Transmission Gain dB 24.7 dB 295.1209
710 # Gr: Reception Gain dB 18.5 dB 70.7945
872 # Gr: Reception Gain dB 18.5 dB 70.7945
711 # Lambda: Wavelenght m 0.6741 m 0.6741
873 # Lambda: Wavelenght m 0.6741 m 0.6741
712 # aL: Attenuation loses dB 4dB 2.5118
874 # aL: Attenuation loses dB 4dB 2.5118
713 # tauW: Width of transmission pulse s 4us 4e-6
875 # tauW: Width of transmission pulse s 4us 4e-6
714 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
876 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
715 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
877 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
716 #
878 #
717 # """
879 # """
718 #
880 #
719 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
881 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
720 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
882 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
721 # RadarConstant = Numerator / Denominator
883 # RadarConstant = Numerator / Denominator
722 #
884 #
723 # return RadarConstant
885 # return RadarConstant
724
886
725
887
726
888
727 class FullSpectralAnalysis(Operation):
889 class FullSpectralAnalysis(Operation):
728
890
729 """
891 """
730 Function that implements Full Spectral Analisys technique.
892 Function that implements Full Spectral Analisys technique.
731
893
732 Input:
894 Input:
733 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
895 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
734 self.dataOut.groupList : Pairlist of channels
896 self.dataOut.groupList : Pairlist of channels
735 self.dataOut.ChanDist : Physical distance between receivers
897 self.dataOut.ChanDist : Physical distance between receivers
736
898
737
899
738 Output:
900 Output:
739
901
740 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
902 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
741
903
742
904
743 Parameters affected: Winds, height range, SNR
905 Parameters affected: Winds, height range, SNR
744
906
745 """
907 """
746 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
908 def run(self, dataOut, E01=None, E02=None, E12=None, N01=None, N02=None, N12=None, SNRlimit=7):
747
909
748 self.indice=int(numpy.random.rand()*1000)
910 self.indice=int(numpy.random.rand()*1000)
749
911
750 spc = dataOut.data_pre[0]
912 spc = dataOut.data_pre[0].copy()
751 cspc = dataOut.data_pre[1]
913 cspc = dataOut.data_pre[1]
752
914
753 nChannel = spc.shape[0]
915 nChannel = spc.shape[0]
754 nProfiles = spc.shape[1]
916 nProfiles = spc.shape[1]
755 nHeights = spc.shape[2]
917 nHeights = spc.shape[2]
756
918
757 pairsList = dataOut.groupList
919 pairsList = dataOut.groupList
758 if dataOut.ChanDist is not None :
920 if dataOut.ChanDist is not None :
759 ChanDist = dataOut.ChanDist
921 ChanDist = dataOut.ChanDist
760 else:
922 else:
761 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
923 ChanDist = numpy.array([[E01, N01],[E02,N02],[E12,N12]])
762
924
763 #print 'ChanDist', ChanDist
925 FrecRange = dataOut.spc_range[0]
764
765 #if dataOut.VelRange is not None:
766 AbbsisaRange= dataOut.spc_range#dataOut.VelRange
767 #else:
768 # AbbsisaRange= dataOut.spc_range#dataOut.abscissaList
769
926
770 ySamples=numpy.ones([nChannel,nProfiles])
927 ySamples=numpy.ones([nChannel,nProfiles])
771 phase=numpy.ones([nChannel,nProfiles])
928 phase=numpy.ones([nChannel,nProfiles])
772 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
929 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
773 coherence=numpy.ones([nChannel,nProfiles])
930 coherence=numpy.ones([nChannel,nProfiles])
774 PhaseSlope=numpy.ones(nChannel)
931 PhaseSlope=numpy.ones(nChannel)
775 PhaseInter=numpy.ones(nChannel)
932 PhaseInter=numpy.ones(nChannel)
776 dataSNR = dataOut.data_SNR
933 data_SNR=numpy.zeros([nProfiles])
777
778
779
934
780 data = dataOut.data_pre
935 data = dataOut.data_pre
781 noise = dataOut.noise
936 noise = dataOut.noise
782 #print 'noise',noise
783 #SNRdB = 10*numpy.log10(dataOut.data_SNR)
784
937
785 FirstMoment = dataOut.data_param[0,1,:]#numpy.average(dataOut.data_param[:,1,:],0)
938 dataOut.data_SNR = (numpy.mean(spc,axis=1)- noise[0]) / noise[0]
786 SecondMoment = numpy.average(dataOut.data_param[:,2,:],0)
787
939
788 #SNRdBMean = []
789
790
940
791 #for j in range(nHeights):
792 # FirstMoment = numpy.append(FirstMoment,numpy.mean([dataOut.data_param[0,1,j],dataOut.data_param[1,1,j],dataOut.data_param[2,1,j]]))
793 # SNRdBMean = numpy.append(SNRdBMean,numpy.mean([SNRdB[0,j],SNRdB[1,j],SNRdB[2,j]]))
794
941
795 data_output=numpy.ones([3,spc.shape[2]])*numpy.NaN
942 print dataOut.data_SNR.shape
943 #FirstMoment = dataOut.moments[0,1,:]#numpy.average(dataOut.data_param[:,1,:],0)
944 #SecondMoment = numpy.average(dataOut.moments[:,2,:],0)
945
946 #SNRdBMean = []
947
948 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN
796
949
797 velocityX=[]
950 velocityX=[]
798 velocityY=[]
951 velocityY=[]
799 velocityV=[]
952 velocityV=[]
800 PhaseLine=[]
953 PhaseLine=[]
801
954
802 dbSNR = 10*numpy.log10(dataSNR)
955 dbSNR = 10*numpy.log10(dataOut.data_SNR)
803 dbSNR = numpy.average(dbSNR,0)
956 dbSNR = numpy.average(dbSNR,0)
804
957
805 for Height in range(nHeights):
958 for Height in range(nHeights):
806
959
807 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(dataOut.data_param, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR[Height], SNRlimit)
960 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range.copy(), dbSNR[Height], SNRlimit)
808 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
961 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
809
962
810 if abs(Vzon)<100. and abs(Vzon)> 0.:
963 if abs(Vzon)<100. and abs(Vzon)> 0.:
811 velocityX=numpy.append(velocityX, -Vzon)#Vmag
964 velocityX=numpy.append(velocityX, -Vzon)#Vmag
812
965
813 else:
966 else:
814 #print 'Vzon',Vzon
967 #print 'Vzon',Vzon
815 velocityX=numpy.append(velocityX, numpy.NaN)
968 velocityX=numpy.append(velocityX, numpy.NaN)
816
969
817 if abs(Vmer)<100. and abs(Vmer) > 0.:
970 if abs(Vmer)<100. and abs(Vmer) > 0.:
818 velocityY=numpy.append(velocityY, -Vmer)#Vang
971 velocityY=numpy.append(velocityY, -Vmer)#Vang
819
972
820 else:
973 else:
821 #print 'Vmer',Vmer
974 #print 'Vmer',Vmer
822 velocityY=numpy.append(velocityY, numpy.NaN)
975 velocityY=numpy.append(velocityY, numpy.NaN)
823
976
824 if dbSNR[Height] > SNRlimit:
977 if dbSNR[Height] > SNRlimit:
825 velocityV=numpy.append(velocityV, FirstMoment[Height])
978 velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height])
826 else:
979 else:
827 velocityV=numpy.append(velocityV, numpy.NaN)
980 velocityV=numpy.append(velocityV, numpy.NaN)
828 #FirstMoment[Height]= numpy.NaN
981 #FirstMoment[Height]= numpy.NaN
829 # if SNRdBMean[Height] <12:
982 # if SNRdBMean[Height] <12:
830 # FirstMoment[Height] = numpy.NaN
983 # FirstMoment[Height] = numpy.NaN
831 # velocityX[Height] = numpy.NaN
984 # velocityX[Height] = numpy.NaN
832 # velocityY[Height] = numpy.NaN
985 # velocityY[Height] = numpy.NaN
833
986
834
987
835
988
836 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
989 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
837 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
990 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
838 data_output[2] = -velocityV#FirstMoment
991 data_output[2] = -velocityV#FirstMoment
839
992
840 print ' '
993 print 'FirstMoment', data_output[2]
841 #print 'FirstMoment'
842 #print FirstMoment
994 #print FirstMoment
843 print 'velocityX',numpy.shape(data_output[0])
995 # print 'velocityX',numpy.shape(data_output[0])
844 print 'velocityX',data_output[0]
996 # print 'velocityX',data_output[0]
845 print ' '
997 # print ' '
846 print 'velocityY',numpy.shape(data_output[1])
998 # print 'velocityY',numpy.shape(data_output[1])
847 print 'velocityY',data_output[1]
999 # print 'velocityY',data_output[1]
848 print 'velocityV',data_output[2]
1000 # print 'velocityV',data_output[2]
849 print 'PhaseLine',PhaseLine
1001 # print 'PhaseLine',PhaseLine
850 #print numpy.array(velocityY)
1002 #print numpy.array(velocityY)
851 #print 'SNR'
1003 #print 'SNR'
852 #print 10*numpy.log10(dataOut.data_SNR)
1004 #print 10*numpy.log10(dataOut.data_SNR)
853 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
1005 #print numpy.shape(10*numpy.log10(dataOut.data_SNR))
854 print ' '
1006 print ' '
855
1007
856 xFrec=AbbsisaRange[0][0:spc.shape[1]]
1008 xFrec=FrecRange[0:spc.shape[1]]
857
1009
858 dataOut.data_output=data_output
1010 dataOut.data_output=data_output
859
1011
860 return
1012 return
861
1013
862
1014
863 def moving_average(self,x, N=2):
1015 def moving_average(self,x, N=2):
864 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
1016 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
865
1017
866 def gaus(self,xSamples,Amp,Mu,Sigma):
1018 def gaus(self,xSamples,Amp,Mu,Sigma):
867 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
1019 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
868
1020
869
1021
870
1022
871 def Moments(self, ySamples, xSamples):
1023 def Moments(self, ySamples, xSamples):
872 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
1024 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
873 yNorm = ySamples / Pot
1025 yNorm = ySamples / Pot
874
1026
875 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
1027 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
876 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
1028 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
877 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
1029 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
878
1030
879 return numpy.array([Pot, Vr, Desv])
1031 return numpy.array([Pot, Vr, Desv])
880
1032
881 def WindEstimation(self, data_param, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
1033 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
882
1034
883 print ' '
1035 # print ' '
884 print '######################## Height',Height, (1000 + 75*Height), '##############################'
1036 # print '######################## Height',Height, (1000 + 75*Height), '##############################'
885 print ' '
1037 # print ' '
886
1038
887 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
1039 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
888 phase=numpy.ones([spc.shape[0],spc.shape[1]])
1040 phase=numpy.ones([spc.shape[0],spc.shape[1]])
889 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
1041 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
890 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
1042 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
891 PhaseSlope=numpy.zeros(spc.shape[0])
1043 PhaseSlope=numpy.zeros(spc.shape[0])
892 PhaseInter=numpy.ones(spc.shape[0])
1044 PhaseInter=numpy.ones(spc.shape[0])
893 xFrec=AbbsisaRange[0][0:spc.shape[1]]
1045 xFrec=AbbsisaRange[0][0:spc.shape[1]]
894 xVel =AbbsisaRange[2][0:spc.shape[1]]
1046 xVel =AbbsisaRange[2][0:spc.shape[1]]
895 Vv=numpy.empty(spc.shape[2])*0
1047 Vv=numpy.empty(spc.shape[2])*0
896 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
1048 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
897
1049
898 SPCmoments = self.Moments(SPCav[:,Height], xVel )
1050 SPCmoments = self.Moments(SPCav[:,Height], xVel )
899 CSPCmoments = []
1051 CSPCmoments = []
900 cspcNoise = numpy.empty(3)
1052 cspcNoise = numpy.empty(3)
901
1053
902 '''Getting Eij and Nij'''
1054 '''Getting Eij and Nij'''
903
1055
904 E01=ChanDist[0][0]
1056 E01=ChanDist[0][0]
905 N01=ChanDist[0][1]
1057 N01=ChanDist[0][1]
906
1058
907 E02=ChanDist[1][0]
1059 E02=ChanDist[1][0]
908 N02=ChanDist[1][1]
1060 N02=ChanDist[1][1]
909
1061
910 E12=ChanDist[2][0]
1062 E12=ChanDist[2][0]
911 N12=ChanDist[2][1]
1063 N12=ChanDist[2][1]
912
1064
913 z = spc.copy()
1065 z = spc.copy()
914 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1066 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
915
1067
916 for i in range(spc.shape[0]):
1068 for i in range(spc.shape[0]):
917
1069
918 '''****** Line of Data SPC ******'''
1070 '''****** Line of Data SPC ******'''
919 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
1071 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
920
1072
921 '''****** SPC is normalized ******'''
1073 '''****** SPC is normalized ******'''
922 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
1074 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
923 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
1075 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
924
1076
925 xSamples = xFrec # Se toma el rango de frecuncias
1077 xSamples = xFrec # Se toma el rango de frecuncias
926 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
1078 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
927
1079
928 for i in range(spc.shape[0]):
1080 for i in range(spc.shape[0]):
929
1081
930 '''****** Line of Data CSPC ******'''
1082 '''****** Line of Data CSPC ******'''
931 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
1083 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
932 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
1084 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
933 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
1085 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
934
1086
935 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
1087 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
936 chan_index0 = pairsList[i][0]
1088 chan_index0 = pairsList[i][0]
937 chan_index1 = pairsList[i][1]
1089 chan_index1 = pairsList[i][1]
938
1090
939 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
1091 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
940 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
1092 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
941
1093
942 CSPCSamples[i] = CSPCNorm
1094 CSPCSamples[i] = CSPCNorm
943
1095
944 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
1096 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
945
1097
946 #coherence[i]= self.moving_average(coherence[i],N=1)
1098 #coherence[i]= self.moving_average(coherence[i],N=1)
947
1099
948 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
1100 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
949
1101
950 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
1102 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
951 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
1103 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
952 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
1104 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
953
1105
954 #print '##### SUMA de SPC #####', len(ySamples)
1106 #print '##### SUMA de SPC #####', len(ySamples)
955 #print numpy.sum(ySamples[0])
1107 #print numpy.sum(ySamples[0])
956 #print '##### SUMA de CSPC #####', len(coherence)
1108 #print '##### SUMA de CSPC #####', len(coherence)
957 #print numpy.sum(numpy.abs(CSPCNorm))
1109 #print numpy.sum(numpy.abs(CSPCNorm))
958 #print numpy.sum(coherence[0])
1110 #print numpy.sum(coherence[0])
959 print 'len',len(xSamples)
1111 # print 'len',len(xSamples)
960 print 'CSPCmoments', numpy.shape(CSPCmoments)
1112 # print 'CSPCmoments', numpy.shape(CSPCmoments)
961 print CSPCmoments
1113 # print CSPCmoments
962 print '#######################'
1114 # print '#######################'
963
1115
964 popt=[1e-10,1e-10,1e-10]
1116 popt=[1e-10,1e-10,1e-10]
965 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
1117 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
966 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
1118 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
967
1119
968 CSPCMask01 = numpy.abs(CSPCSamples[0])
1120 CSPCMask01 = numpy.abs(CSPCSamples[0])
969 CSPCMask02 = numpy.abs(CSPCSamples[1])
1121 CSPCMask02 = numpy.abs(CSPCSamples[1])
970 CSPCMask12 = numpy.abs(CSPCSamples[2])
1122 CSPCMask12 = numpy.abs(CSPCSamples[2])
971
1123
972 mask01 = ~numpy.isnan(CSPCMask01)
1124 mask01 = ~numpy.isnan(CSPCMask01)
973 mask02 = ~numpy.isnan(CSPCMask02)
1125 mask02 = ~numpy.isnan(CSPCMask02)
974 mask12 = ~numpy.isnan(CSPCMask12)
1126 mask12 = ~numpy.isnan(CSPCMask12)
975
1127
976 #mask = ~numpy.isnan(CSPCMask01)
1128 #mask = ~numpy.isnan(CSPCMask01)
977 CSPCMask01 = CSPCMask01[mask01]
1129 CSPCMask01 = CSPCMask01[mask01]
978 CSPCMask02 = CSPCMask02[mask02]
1130 CSPCMask02 = CSPCMask02[mask02]
979 CSPCMask12 = CSPCMask12[mask12]
1131 CSPCMask12 = CSPCMask12[mask12]
980 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
1132 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
981
1133
982
1134
983
1135
984
985
986 '''***Fit Gauss CSPC01***'''
1136 '''***Fit Gauss CSPC01***'''
987 if dbSNR > SNRlimit:
1137 if dbSNR > SNRlimit:
988 try:
1138 try:
989 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
1139 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
990 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
1140 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
991 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
1141 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
992 FitGauss01 = self.gaus(xSamples,*popt01)
1142 FitGauss01 = self.gaus(xSamples,*popt01)
993 FitGauss02 = self.gaus(xSamples,*popt02)
1143 FitGauss02 = self.gaus(xSamples,*popt02)
994 FitGauss12 = self.gaus(xSamples,*popt12)
1144 FitGauss12 = self.gaus(xSamples,*popt12)
995 except:
1145 except:
996 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
1146 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
997 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
1147 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
998 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
1148 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
999
1149
1000
1150
1001 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1151 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1002
1152
1003 '''****** Getting fij width ******'''
1153 '''****** Getting fij width ******'''
1004
1154
1005 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1155 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1006
1156
1007 '''******* Getting fitting Gaussian *******'''
1157 '''******* Getting fitting Gaussian *******'''
1008 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1158 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1009 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1159 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1010
1160
1011 yMoments = self.Moments(yMean, xSamples)
1161 yMoments = self.Moments(yMean, xSamples)
1012
1162
1013 if dbSNR > SNRlimit: # and abs(meanGauss/sigma2) > 0.00001:
1163 if dbSNR > SNRlimit: # and abs(meanGauss/sigma2) > 0.00001:
1014 try:
1164 try:
1015 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1165 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1016 FitGauss=self.gaus(xSamples,*popt)
1166 FitGauss=self.gaus(xSamples,*popt)
1017
1167
1018 except :#RuntimeError:
1168 except :#RuntimeError:
1019 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1169 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1020
1170
1021
1171
1022 else:
1172 else:
1023 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1173 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1024
1174
1025
1175
1026
1176
1027 '''****** Getting Fij ******'''
1177 '''****** Getting Fij ******'''
1028 Fijcspc = CSPCopt[:,2]/2*3
1178 Fijcspc = CSPCopt[:,2]/2*3
1029
1179
1030 #GauWidth = (popt[2]/2)*3
1180 #GauWidth = (popt[2]/2)*3
1031 GaussCenter = popt[1] #xFrec[GCpos]
1181 GaussCenter = popt[1] #xFrec[GCpos]
1032 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1182 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1033 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1183 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1034 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1184 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1035
1185
1036 #Punto e^-1 hubicado en la Gaussiana
1186 #Punto e^-1 hubicado en la Gaussiana
1037 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1187 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1038 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1188 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1039 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1189 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1040
1190
1041 if xSamples[PointFij] > xSamples[PointGauCenter]:
1191 if xSamples[PointFij] > xSamples[PointGauCenter]:
1042 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1192 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1043
1193
1044 else:
1194 else:
1045 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1195 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1046
1196
1047 print 'CSPCopt'
1197 # print 'CSPCopt'
1048 print CSPCopt
1198 # print CSPCopt
1049 print 'popt'
1199 # print 'popt'
1050 print popt
1200 # print popt
1051 print '#######################################'
1201 # print '#######################################'
1052 #print 'dataOut.data_param', numpy.shape(data_param)
1202 #print 'dataOut.data_param', numpy.shape(data_param)
1053 #print 'dataOut.data_param0', data_param[0,0,Height]
1203 #print 'dataOut.data_param0', data_param[0,0,Height]
1054 #print 'dataOut.data_param1', data_param[0,1,Height]
1204 #print 'dataOut.data_param1', data_param[0,1,Height]
1055 #print 'dataOut.data_param2', data_param[0,2,Height]
1205 #print 'dataOut.data_param2', data_param[0,2,Height]
1056
1206
1057
1207
1058 print 'yMoments', yMoments
1208 # print 'yMoments', yMoments
1059 print 'Moments', SPCmoments
1209 # print 'Moments', SPCmoments
1060 print 'Fij2 Moment', Fij
1210 # print 'Fij2 Moment', Fij
1061 #print 'Fij', Fij, 'popt[2]/2',popt[2]/2
1211 # #print 'Fij', Fij, 'popt[2]/2',popt[2]/2
1062 print 'Fijcspc',Fijcspc
1212 # print 'Fijcspc',Fijcspc
1063 print '#######################################'
1213 # print '#######################################'
1064
1065
1066 # Range = numpy.empty([3,2])
1067 # GaussCenter = numpy.empty(3)
1068 # FrecRange, VelRange = [[],[],[]],[[],[],[]]
1069 # FrecRange01, FrecRange02, FrecRange12 = numpy.empty(3), numpy.empty(3), numpy.empty(3)
1070 # VelRange01, VelRange02, VelRange12 = numpy.empty(3), numpy.empty(3), numpy.empty(3)
1071 #
1072 # GauWidth = numpy.empty(3)
1073 # ClosRangeMin, ClosRangeMax = numpy.empty(3), numpy.empty(3)
1074 # PointRangeMin, PointRangeMax = numpy.empty(3), numpy.empty(3)
1075 # '''****** Taking frequency ranges from CSPCs ******'''
1076 # for i in range(spc.shape[0]):
1077 #
1078 # GaussCenter[i] = CSPCopt[i][1] #Primer momento 01
1079 # GauWidth[i] = CSPCopt[i][2]*2/2 #Ancho de banda de Gau01
1080 #
1081 # Range[i][0] = GaussCenter[i] - GauWidth[i]
1082 # Range[i][1] = GaussCenter[i] + GauWidth[i]
1083 # #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1084 # ClosRangeMin[i] = xSamples[numpy.abs(xSamples-Range[i][0]).argmin()]
1085 # ClosRangeMax[i] = xSamples[numpy.abs(xSamples-Range[i][1]).argmin()]
1086 #
1087 # PointRangeMin[i] = numpy.where(xSamples==ClosRangeMin[i])[0][0]
1088 # PointRangeMax[i] = numpy.where(xSamples==ClosRangeMax[i])[0][0]
1089 #
1090 # Range[i]=numpy.array([ PointRangeMin[i], PointRangeMax[i] ])
1091 #
1092 # FrecRange[i] = xFrec[ Range[i][0] : Range[i][1] ]
1093 # VelRange[i] = xVel[ Range[i][0] : Range[i][1] ]
1094
1095
1096
1214
1215
1097 '''****** Taking frequency ranges from SPCs ******'''
1216 '''****** Taking frequency ranges from SPCs ******'''
1098
1217
1099
1218
1100 #GaussCenter = popt[1] #Primer momento 01
1219 #GaussCenter = popt[1] #Primer momento 01
1101 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1220 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1102 Range = numpy.empty(2)
1221 Range = numpy.empty(2)
1103 Range[0] = GaussCenter - GauWidth
1222 Range[0] = GaussCenter - GauWidth
1104 Range[1] = GaussCenter + GauWidth
1223 Range[1] = GaussCenter + GauWidth
1105 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1224 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1106 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1225 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1107 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1226 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1108
1227
1109 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1228 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1110 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1229 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1111
1230
1112 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1231 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1113
1232
1114 FrecRange = xFrec[ Range[0] : Range[1] ]
1233 FrecRange = xFrec[ Range[0] : Range[1] ]
1115 VelRange = xVel[ Range[0] : Range[1] ]
1234 VelRange = xVel[ Range[0] : Range[1] ]
1116
1235
1117
1236
1118 #print 'RANGE: ', Range
1237 #print 'RANGE: ', Range
1119 #print 'FrecRange', numpy.shape(FrecRange)#,FrecRange
1238 #print 'FrecRange', numpy.shape(FrecRange)#,FrecRange
1120 #print 'len: ', len(FrecRange)
1239 #print 'len: ', len(FrecRange)
1121
1240
1122 '''****** Getting SCPC Slope ******'''
1241 '''****** Getting SCPC Slope ******'''
1123
1242
1124 for i in range(spc.shape[0]):
1243 for i in range(spc.shape[0]):
1125
1244
1126 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.6:
1245 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.6:
1127 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1246 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1128
1247
1129 #print 'Ancho espectral Frecuencias', FrecRange[-1]-FrecRange[0], 'Hz'
1248 #print 'Ancho espectral Frecuencias', FrecRange[-1]-FrecRange[0], 'Hz'
1130 #print 'Ancho espectral Velocidades', VelRange[-1]-VelRange[0], 'm/s'
1249 #print 'Ancho espectral Velocidades', VelRange[-1]-VelRange[0], 'm/s'
1131 #print 'FrecRange', len(FrecRange) , FrecRange
1250 #print 'FrecRange', len(FrecRange) , FrecRange
1132 #print 'VelRange', len(VelRange) , VelRange
1251 #print 'VelRange', len(VelRange) , VelRange
1133 #print 'PhaseRange', numpy.shape(PhaseRange), PhaseRange
1252 #print 'PhaseRange', numpy.shape(PhaseRange), PhaseRange
1134 #print ' '
1253 #print ' '
1135
1254
1136 '''***********************VelRange******************'''
1255 '''***********************VelRange******************'''
1137
1256
1138 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1257 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1139
1258
1140 if len(FrecRange) == len(PhaseRange):
1259 if len(FrecRange) == len(PhaseRange):
1141 try:
1260 try:
1142 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1261 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1143 PhaseSlope[i]=slope
1262 PhaseSlope[i]=slope
1144 PhaseInter[i]=intercept
1263 PhaseInter[i]=intercept
1145 except:
1264 except:
1146 PhaseSlope[i]=0
1265 PhaseSlope[i]=0
1147 PhaseInter[i]=0
1266 PhaseInter[i]=0
1148 else:
1267 else:
1149 PhaseSlope[i]=0
1268 PhaseSlope[i]=0
1150 PhaseInter[i]=0
1269 PhaseInter[i]=0
1151 else:
1270 else:
1152 PhaseSlope[i]=0
1271 PhaseSlope[i]=0
1153 PhaseInter[i]=0
1272 PhaseInter[i]=0
1154
1273
1155
1274
1156 '''Getting constant C'''
1275 '''Getting constant C'''
1157 cC=(Fij*numpy.pi)**2
1276 cC=(Fij*numpy.pi)**2
1158
1277
1159 '''****** Getting constants F and G ******'''
1278 '''****** Getting constants F and G ******'''
1160 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1279 MijEijNij=numpy.array([[E02,N02], [E12,N12]])
1161 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1280 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1162 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1281 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1163 MijResults=numpy.array([MijResult0,MijResult1])
1282 MijResults=numpy.array([MijResult0,MijResult1])
1164 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1283 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1165
1284
1166 '''****** Getting constants A, B and H ******'''
1285 '''****** Getting constants A, B and H ******'''
1167 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1286 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1168 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1287 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1169 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1288 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1170
1289
1171 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1290 WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1172 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1291 WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1173 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1292 WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1174
1293
1175 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1294 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1176
1295
1177 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1296 WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1178 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1297 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1179
1298
1180 VxVy=numpy.array([[cA,cH],[cH,cB]])
1299 VxVy=numpy.array([[cA,cH],[cH,cB]])
1181
1182 VxVyResults=numpy.array([-cF,-cG])
1300 VxVyResults=numpy.array([-cF,-cG])
1183 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1301 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1302
1184 #print 'MijResults, cC, PhaseSlope', MijResults, cC, PhaseSlope
1303 #print 'MijResults, cC, PhaseSlope', MijResults, cC, PhaseSlope
1185 #print 'W01,02,12', W01, W02, W12
1304 #print 'W01,02,12', W01, W02, W12
1186 #print 'WijResult0,1,2',WijResult0, WijResult1, WijResult2, 'Results', WijResults
1305 #print 'WijResult0,1,2',WijResult0, WijResult1, WijResult2, 'Results', WijResults
1187 #print 'cA,cB,cH, cF, cG', cA, cB, cH, cF, cG
1306 #print 'cA,cB,cH, cF, cG', cA, cB, cH, cF, cG
1188 #print 'VxVy', VxVyResults
1307 #print 'VxVy', VxVyResults
1189 #print '###########################****************************************'
1308 #print '###########################****************************************'
1190 Vzon = Vy
1309 Vzon = Vy
1191 Vmer = Vx
1310 Vmer = Vx
1192 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1311 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1193 Vang=numpy.arctan2(Vmer,Vzon)
1312 Vang=numpy.arctan2(Vmer,Vzon)
1194 Vver=SPCmoments[1]
1313 Vver=SPCmoments[1]
1195 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1314 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1196
1315
1197
1316
1198 # ''' Ploteo por altura '''
1317 # ''' Ploteo por altura '''
1199 # if Height == 28:
1318 # if Height == 28:
1200 # for i in range(3):
1319 # for i in range(3):
1201 # #print 'FASE', numpy.shape(phase), y[25]
1320 # #print 'FASE', numpy.shape(phase), y[25]
1202 # #print numpy.shape(coherence)
1321 # #print numpy.shape(coherence)
1203 # fig = plt.figure(10+self.indice)
1322 # fig = plt.figure(10+self.indice)
1204 # #plt.plot( x[0:256],coherence[:,25] )
1323 # #plt.plot( x[0:256],coherence[:,25] )
1205 # #cohAv = numpy.average(coherence[i],1)
1324 # #cohAv = numpy.average(coherence[i],1)
1206 # Pendiente = FrecRange * PhaseSlope[i]
1325 # Pendiente = FrecRange * PhaseSlope[i]
1207 # plt.plot( FrecRange, Pendiente)
1326 # plt.plot( FrecRange, Pendiente)
1208 # plt.plot( xFrec,phase[i])
1327 # plt.plot( xFrec,phase[i])
1209 #
1328 #
1210 # CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
1329 # CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
1211 # #plt.plot(xFrec, FitGauss01)
1330 # #plt.plot(xFrec, FitGauss01)
1212 # #plt.plot(xFrec, CSPCmean)
1331 # #plt.plot(xFrec, CSPCmean)
1213 # #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
1332 # #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
1214 # #plt.plot(xFrec, FitGauss)
1333 # #plt.plot(xFrec, FitGauss)
1215 # #plt.plot(xFrec, yMean)
1334 # #plt.plot(xFrec, yMean)
1216 # #plt.plot(xFrec, numpy.abs(coherence[0]))
1335 # #plt.plot(xFrec, numpy.abs(coherence[0]))
1217 #
1336 #
1218 # #plt.axis([-12, 12, 15, 50])
1337 # #plt.axis([-12, 12, 15, 50])
1219 # #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
1338 # #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
1220 # plt.ylabel('Desfase [rad]')
1339 # plt.ylabel('Desfase [rad]')
1221 # #plt.ylabel('CSPC normalizado')
1340 # #plt.ylabel('CSPC normalizado')
1222 # plt.xlabel('Frec range [Hz]')
1341 # plt.xlabel('Frec range [Hz]')
1223
1342
1224 #fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
1343 #fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
1225
1344
1226 # plt.show()
1345 # plt.show()
1227 # self.indice=self.indice+1
1346 # self.indice=self.indice+1
1228
1347
1229
1348
1230
1349
1231
1350
1232
1351
1233 print 'vzon y vmer', Vzon, Vmer
1352 # print 'vzon y vmer', Vzon, Vmer
1234 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1353 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1235
1354
1236 class SpectralMoments(Operation):
1355 class SpectralMoments(Operation):
1237
1356
1238 '''
1357 '''
1239 Function SpectralMoments()
1358 Function SpectralMoments()
1240
1359
1241 Calculates moments (power, mean, standard deviation) and SNR of the signal
1360 Calculates moments (power, mean, standard deviation) and SNR of the signal
1242
1361
1243 Type of dataIn: Spectra
1362 Type of dataIn: Spectra
1244
1363
1245 Configuration Parameters:
1364 Configuration Parameters:
1246
1365
1247 dirCosx : Cosine director in X axis
1366 dirCosx : Cosine director in X axis
1248 dirCosy : Cosine director in Y axis
1367 dirCosy : Cosine director in Y axis
1249
1368
1250 elevation :
1369 elevation :
1251 azimuth :
1370 azimuth :
1252
1371
1253 Input:
1372 Input:
1254 channelList : simple channel list to select e.g. [2,3,7]
1373 channelList : simple channel list to select e.g. [2,3,7]
1255 self.dataOut.data_pre : Spectral data
1374 self.dataOut.data_pre : Spectral data
1256 self.dataOut.abscissaList : List of frequencies
1375 self.dataOut.abscissaList : List of frequencies
1257 self.dataOut.noise : Noise level per channel
1376 self.dataOut.noise : Noise level per channel
1258
1377
1259 Affected:
1378 Affected:
1260 self.dataOut.data_param : Parameters per channel
1379 self.dataOut.moments : Parameters per channel
1261 self.dataOut.data_SNR : SNR per channel
1380 self.dataOut.data_SNR : SNR per channel
1262
1381
1263 '''
1382 '''
1264
1383
1265 def run(self, dataOut):
1384 def run(self, dataOut):
1266
1385
1267 #dataOut.data_pre = dataOut.data_pre[0]
1386 #dataOut.data_pre = dataOut.data_pre[0]
1268 data = dataOut.data_pre[0]
1387 data = dataOut.data_pre[0]
1269 absc = dataOut.abscissaList[:-1]
1388 absc = dataOut.abscissaList[:-1]
1270 noise = dataOut.noise
1389 noise = dataOut.noise
1271 nChannel = data.shape[0]
1390 nChannel = data.shape[0]
1272 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1391 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1273
1392
1274 for ind in range(nChannel):
1393 for ind in range(nChannel):
1275 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1394 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1276
1395
1277 dataOut.data_param = data_param[:,1:,:]
1396 dataOut.moments = data_param[:,1:,:]
1278 dataOut.data_SNR = data_param[:,0]
1397 dataOut.data_SNR = data_param[:,0]
1279 return
1398 return
1280
1399
1281 def __calculateMoments(self, oldspec, oldfreq, n0,
1400 def __calculateMoments(self, oldspec, oldfreq, n0,
1282 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1401 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1283
1402
1284 if (nicoh == None): nicoh = 1
1403 if (nicoh == None): nicoh = 1
1285 if (graph == None): graph = 0
1404 if (graph == None): graph = 0
1286 if (smooth == None): smooth = 0
1405 if (smooth == None): smooth = 0
1287 elif (self.smooth < 3): smooth = 0
1406 elif (self.smooth < 3): smooth = 0
1288
1407
1289 if (type1 == None): type1 = 0
1408 if (type1 == None): type1 = 0
1290 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1409 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1291 if (snrth == None): snrth = -3
1410 if (snrth == None): snrth = -3
1292 if (dc == None): dc = 0
1411 if (dc == None): dc = 0
1293 if (aliasing == None): aliasing = 0
1412 if (aliasing == None): aliasing = 0
1294 if (oldfd == None): oldfd = 0
1413 if (oldfd == None): oldfd = 0
1295 if (wwauto == None): wwauto = 0
1414 if (wwauto == None): wwauto = 0
1296
1415
1297 if (n0 < 1.e-20): n0 = 1.e-20
1416 if (n0 < 1.e-20): n0 = 1.e-20
1298
1417
1299 freq = oldfreq
1418 freq = oldfreq
1300 vec_power = numpy.zeros(oldspec.shape[1])
1419 vec_power = numpy.zeros(oldspec.shape[1])
1301 vec_fd = numpy.zeros(oldspec.shape[1])
1420 vec_fd = numpy.zeros(oldspec.shape[1])
1302 vec_w = numpy.zeros(oldspec.shape[1])
1421 vec_w = numpy.zeros(oldspec.shape[1])
1303 vec_snr = numpy.zeros(oldspec.shape[1])
1422 vec_snr = numpy.zeros(oldspec.shape[1])
1304
1423
1305 oldspec = numpy.ma.masked_invalid(oldspec)
1424 oldspec = numpy.ma.masked_invalid(oldspec)
1306
1425
1307 for ind in range(oldspec.shape[1]):
1426 for ind in range(oldspec.shape[1]):
1308
1427
1309 spec = oldspec[:,ind]
1428 spec = oldspec[:,ind]
1310 aux = spec*fwindow
1429 aux = spec*fwindow
1311 max_spec = aux.max()
1430 max_spec = aux.max()
1312 m = list(aux).index(max_spec)
1431 m = list(aux).index(max_spec)
1313
1432
1314 #Smooth
1433 #Smooth
1315 if (smooth == 0): spec2 = spec
1434 if (smooth == 0): spec2 = spec
1316 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1435 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1317
1436
1318 # Calculo de Momentos
1437 # Calculo de Momentos
1319 bb = spec2[range(m,spec2.size)]
1438 bb = spec2[range(m,spec2.size)]
1320 bb = (bb<n0).nonzero()
1439 bb = (bb<n0).nonzero()
1321 bb = bb[0]
1440 bb = bb[0]
1322
1441
1323 ss = spec2[range(0,m + 1)]
1442 ss = spec2[range(0,m + 1)]
1324 ss = (ss<n0).nonzero()
1443 ss = (ss<n0).nonzero()
1325 ss = ss[0]
1444 ss = ss[0]
1326
1445
1327 if (bb.size == 0):
1446 if (bb.size == 0):
1328 bb0 = spec.size - 1 - m
1447 bb0 = spec.size - 1 - m
1329 else:
1448 else:
1330 bb0 = bb[0] - 1
1449 bb0 = bb[0] - 1
1331 if (bb0 < 0):
1450 if (bb0 < 0):
1332 bb0 = 0
1451 bb0 = 0
1333
1452
1334 if (ss.size == 0): ss1 = 1
1453 if (ss.size == 0): ss1 = 1
1335 else: ss1 = max(ss) + 1
1454 else: ss1 = max(ss) + 1
1336
1455
1337 if (ss1 > m): ss1 = m
1456 if (ss1 > m): ss1 = m
1338
1457
1339 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1458 valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1
1340 power = ( (spec2[valid] - n0) * fwindow[valid] ).sum()
1459 power = ( (spec2[valid] - n0) * fwindow[valid] ).sum()
1341 fd = ( (spec2[valid]- n0) * freq[valid] * fwindow[valid] ).sum() / power
1460 fd = ( (spec2[valid]- n0) * freq[valid] * fwindow[valid] ).sum() / power
1342 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1461 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1343 snr = (spec2.mean()-n0)/n0
1462 snr = (spec2.mean()-n0)/n0
1344
1463
1345 if (snr < 1.e-20) :
1464 if (snr < 1.e-20) :
1346 snr = 1.e-20
1465 snr = 1.e-20
1347
1466
1348 vec_power[ind] = power
1467 vec_power[ind] = power
1349 vec_fd[ind] = fd
1468 vec_fd[ind] = fd
1350 vec_w[ind] = w
1469 vec_w[ind] = w
1351 vec_snr[ind] = snr
1470 vec_snr[ind] = snr
1352
1471
1353 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1472 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1354 return moments
1473 return moments
1355
1474
1356 #------------------ Get SA Parameters --------------------------
1475 #------------------ Get SA Parameters --------------------------
1357
1476
1358 def GetSAParameters(self):
1477 def GetSAParameters(self):
1359 #SA en frecuencia
1478 #SA en frecuencia
1360 pairslist = self.dataOut.groupList
1479 pairslist = self.dataOut.groupList
1361 num_pairs = len(pairslist)
1480 num_pairs = len(pairslist)
1362
1481
1363 vel = self.dataOut.abscissaList
1482 vel = self.dataOut.abscissaList
1364 spectra = self.dataOut.data_pre
1483 spectra = self.dataOut.data_pre
1365 cspectra = self.dataIn.data_cspc
1484 cspectra = self.dataIn.data_cspc
1366 delta_v = vel[1] - vel[0]
1485 delta_v = vel[1] - vel[0]
1367
1486
1368 #Calculating the power spectrum
1487 #Calculating the power spectrum
1369 spc_pow = numpy.sum(spectra, 3)*delta_v
1488 spc_pow = numpy.sum(spectra, 3)*delta_v
1370 #Normalizing Spectra
1489 #Normalizing Spectra
1371 norm_spectra = spectra/spc_pow
1490 norm_spectra = spectra/spc_pow
1372 #Calculating the norm_spectra at peak
1491 #Calculating the norm_spectra at peak
1373 max_spectra = numpy.max(norm_spectra, 3)
1492 max_spectra = numpy.max(norm_spectra, 3)
1374
1493
1375 #Normalizing Cross Spectra
1494 #Normalizing Cross Spectra
1376 norm_cspectra = numpy.zeros(cspectra.shape)
1495 norm_cspectra = numpy.zeros(cspectra.shape)
1377
1496
1378 for i in range(num_chan):
1497 for i in range(num_chan):
1379 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1498 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1380
1499
1381 max_cspectra = numpy.max(norm_cspectra,2)
1500 max_cspectra = numpy.max(norm_cspectra,2)
1382 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1501 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1383
1502
1384 for i in range(num_pairs):
1503 for i in range(num_pairs):
1385 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1504 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1386 #------------------- Get Lags ----------------------------------
1505 #------------------- Get Lags ----------------------------------
1387
1506
1388 class SALags(Operation):
1507 class SALags(Operation):
1389 '''
1508 '''
1390 Function GetMoments()
1509 Function GetMoments()
1391
1510
1392 Input:
1511 Input:
1393 self.dataOut.data_pre
1512 self.dataOut.data_pre
1394 self.dataOut.abscissaList
1513 self.dataOut.abscissaList
1395 self.dataOut.noise
1514 self.dataOut.noise
1396 self.dataOut.normFactor
1515 self.dataOut.normFactor
1397 self.dataOut.data_SNR
1516 self.dataOut.data_SNR
1398 self.dataOut.groupList
1517 self.dataOut.groupList
1399 self.dataOut.nChannels
1518 self.dataOut.nChannels
1400
1519
1401 Affected:
1520 Affected:
1402 self.dataOut.data_param
1521 self.dataOut.data_param
1403
1522
1404 '''
1523 '''
1405 def run(self, dataOut):
1524 def run(self, dataOut):
1406 data_acf = dataOut.data_pre[0]
1525 data_acf = dataOut.data_pre[0]
1407 data_ccf = dataOut.data_pre[1]
1526 data_ccf = dataOut.data_pre[1]
1408 normFactor_acf = dataOut.normFactor[0]
1527 normFactor_acf = dataOut.normFactor[0]
1409 normFactor_ccf = dataOut.normFactor[1]
1528 normFactor_ccf = dataOut.normFactor[1]
1410 pairs_acf = dataOut.groupList[0]
1529 pairs_acf = dataOut.groupList[0]
1411 pairs_ccf = dataOut.groupList[1]
1530 pairs_ccf = dataOut.groupList[1]
1412
1531
1413 nHeights = dataOut.nHeights
1532 nHeights = dataOut.nHeights
1414 absc = dataOut.abscissaList
1533 absc = dataOut.abscissaList
1415 noise = dataOut.noise
1534 noise = dataOut.noise
1416 SNR = dataOut.data_SNR
1535 SNR = dataOut.data_SNR
1417 nChannels = dataOut.nChannels
1536 nChannels = dataOut.nChannels
1418 # pairsList = dataOut.groupList
1537 # pairsList = dataOut.groupList
1419 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1538 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1420
1539
1421 for l in range(len(pairs_acf)):
1540 for l in range(len(pairs_acf)):
1422 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1541 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1423
1542
1424 for l in range(len(pairs_ccf)):
1543 for l in range(len(pairs_ccf)):
1425 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1544 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1426
1545
1427 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1546 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1428 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1547 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1429 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1548 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1430 return
1549 return
1431
1550
1432 # def __getPairsAutoCorr(self, pairsList, nChannels):
1551 # def __getPairsAutoCorr(self, pairsList, nChannels):
1433 #
1552 #
1434 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1553 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1435 #
1554 #
1436 # for l in range(len(pairsList)):
1555 # for l in range(len(pairsList)):
1437 # firstChannel = pairsList[l][0]
1556 # firstChannel = pairsList[l][0]
1438 # secondChannel = pairsList[l][1]
1557 # secondChannel = pairsList[l][1]
1439 #
1558 #
1440 # #Obteniendo pares de Autocorrelacion
1559 # #Obteniendo pares de Autocorrelacion
1441 # if firstChannel == secondChannel:
1560 # if firstChannel == secondChannel:
1442 # pairsAutoCorr[firstChannel] = int(l)
1561 # pairsAutoCorr[firstChannel] = int(l)
1443 #
1562 #
1444 # pairsAutoCorr = pairsAutoCorr.astype(int)
1563 # pairsAutoCorr = pairsAutoCorr.astype(int)
1445 #
1564 #
1446 # pairsCrossCorr = range(len(pairsList))
1565 # pairsCrossCorr = range(len(pairsList))
1447 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1566 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1448 #
1567 #
1449 # return pairsAutoCorr, pairsCrossCorr
1568 # return pairsAutoCorr, pairsCrossCorr
1450
1569
1451 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1570 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1452
1571
1453 lag0 = data_acf.shape[1]/2
1572 lag0 = data_acf.shape[1]/2
1454 #Funcion de Autocorrelacion
1573 #Funcion de Autocorrelacion
1455 mean_acf = stats.nanmean(data_acf, axis = 0)
1574 mean_acf = stats.nanmean(data_acf, axis = 0)
1456
1575
1457 #Obtencion Indice de TauCross
1576 #Obtencion Indice de TauCross
1458 ind_ccf = data_ccf.argmax(axis = 1)
1577 ind_ccf = data_ccf.argmax(axis = 1)
1459 #Obtencion Indice de TauAuto
1578 #Obtencion Indice de TauAuto
1460 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1579 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1461 ccf_lag0 = data_ccf[:,lag0,:]
1580 ccf_lag0 = data_ccf[:,lag0,:]
1462
1581
1463 for i in range(ccf_lag0.shape[0]):
1582 for i in range(ccf_lag0.shape[0]):
1464 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1583 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1465
1584
1466 #Obtencion de TauCross y TauAuto
1585 #Obtencion de TauCross y TauAuto
1467 tau_ccf = lagRange[ind_ccf]
1586 tau_ccf = lagRange[ind_ccf]
1468 tau_acf = lagRange[ind_acf]
1587 tau_acf = lagRange[ind_acf]
1469
1588
1470 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1589 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1471
1590
1472 tau_ccf[Nan1,Nan2] = numpy.nan
1591 tau_ccf[Nan1,Nan2] = numpy.nan
1473 tau_acf[Nan1,Nan2] = numpy.nan
1592 tau_acf[Nan1,Nan2] = numpy.nan
1474 tau = numpy.vstack((tau_ccf,tau_acf))
1593 tau = numpy.vstack((tau_ccf,tau_acf))
1475
1594
1476 return tau
1595 return tau
1477
1596
1478 def __calculateLag1Phase(self, data, lagTRange):
1597 def __calculateLag1Phase(self, data, lagTRange):
1479 data1 = stats.nanmean(data, axis = 0)
1598 data1 = stats.nanmean(data, axis = 0)
1480 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1599 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1481
1600
1482 phase = numpy.angle(data1[lag1,:])
1601 phase = numpy.angle(data1[lag1,:])
1483
1602
1484 return phase
1603 return phase
1485
1604
1486 class SpectralFitting(Operation):
1605 class SpectralFitting(Operation):
1487 '''
1606 '''
1488 Function GetMoments()
1607 Function GetMoments()
1489
1608
1490 Input:
1609 Input:
1491 Output:
1610 Output:
1492 Variables modified:
1611 Variables modified:
1493 '''
1612 '''
1494
1613
1495 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1614 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1496
1615
1497
1616
1498 if path != None:
1617 if path != None:
1499 sys.path.append(path)
1618 sys.path.append(path)
1500 self.dataOut.library = importlib.import_module(file)
1619 self.dataOut.library = importlib.import_module(file)
1501
1620
1502 #To be inserted as a parameter
1621 #To be inserted as a parameter
1503 groupArray = numpy.array(groupList)
1622 groupArray = numpy.array(groupList)
1504 # groupArray = numpy.array([[0,1],[2,3]])
1623 # groupArray = numpy.array([[0,1],[2,3]])
1505 self.dataOut.groupList = groupArray
1624 self.dataOut.groupList = groupArray
1506
1625
1507 nGroups = groupArray.shape[0]
1626 nGroups = groupArray.shape[0]
1508 nChannels = self.dataIn.nChannels
1627 nChannels = self.dataIn.nChannels
1509 nHeights=self.dataIn.heightList.size
1628 nHeights=self.dataIn.heightList.size
1510
1629
1511 #Parameters Array
1630 #Parameters Array
1512 self.dataOut.data_param = None
1631 self.dataOut.data_param = None
1513
1632
1514 #Set constants
1633 #Set constants
1515 constants = self.dataOut.library.setConstants(self.dataIn)
1634 constants = self.dataOut.library.setConstants(self.dataIn)
1516 self.dataOut.constants = constants
1635 self.dataOut.constants = constants
1517 M = self.dataIn.normFactor
1636 M = self.dataIn.normFactor
1518 N = self.dataIn.nFFTPoints
1637 N = self.dataIn.nFFTPoints
1519 ippSeconds = self.dataIn.ippSeconds
1638 ippSeconds = self.dataIn.ippSeconds
1520 K = self.dataIn.nIncohInt
1639 K = self.dataIn.nIncohInt
1521 pairsArray = numpy.array(self.dataIn.pairsList)
1640 pairsArray = numpy.array(self.dataIn.pairsList)
1522
1641
1523 #List of possible combinations
1642 #List of possible combinations
1524 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1643 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1525 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1644 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1526
1645
1527 if getSNR:
1646 if getSNR:
1528 listChannels = groupArray.reshape((groupArray.size))
1647 listChannels = groupArray.reshape((groupArray.size))
1529 listChannels.sort()
1648 listChannels.sort()
1530 noise = self.dataIn.getNoise()
1649 noise = self.dataIn.getNoise()
1531 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1650 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1532
1651
1533 for i in range(nGroups):
1652 for i in range(nGroups):
1534 coord = groupArray[i,:]
1653 coord = groupArray[i,:]
1535
1654
1536 #Input data array
1655 #Input data array
1537 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1656 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1538 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1657 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1539
1658
1540 #Cross Spectra data array for Covariance Matrixes
1659 #Cross Spectra data array for Covariance Matrixes
1541 ind = 0
1660 ind = 0
1542 for pairs in listComb:
1661 for pairs in listComb:
1543 pairsSel = numpy.array([coord[x],coord[y]])
1662 pairsSel = numpy.array([coord[x],coord[y]])
1544 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1663 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1545 ind += 1
1664 ind += 1
1546 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1665 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1547 dataCross = dataCross**2/K
1666 dataCross = dataCross**2/K
1548
1667
1549 for h in range(nHeights):
1668 for h in range(nHeights):
1550 # print self.dataOut.heightList[h]
1669 # print self.dataOut.heightList[h]
1551
1670
1552 #Input
1671 #Input
1553 d = data[:,h]
1672 d = data[:,h]
1554
1673
1555 #Covariance Matrix
1674 #Covariance Matrix
1556 D = numpy.diag(d**2/K)
1675 D = numpy.diag(d**2/K)
1557 ind = 0
1676 ind = 0
1558 for pairs in listComb:
1677 for pairs in listComb:
1559 #Coordinates in Covariance Matrix
1678 #Coordinates in Covariance Matrix
1560 x = pairs[0]
1679 x = pairs[0]
1561 y = pairs[1]
1680 y = pairs[1]
1562 #Channel Index
1681 #Channel Index
1563 S12 = dataCross[ind,:,h]
1682 S12 = dataCross[ind,:,h]
1564 D12 = numpy.diag(S12)
1683 D12 = numpy.diag(S12)
1565 #Completing Covariance Matrix with Cross Spectras
1684 #Completing Covariance Matrix with Cross Spectras
1566 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1685 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1567 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1686 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1568 ind += 1
1687 ind += 1
1569 Dinv=numpy.linalg.inv(D)
1688 Dinv=numpy.linalg.inv(D)
1570 L=numpy.linalg.cholesky(Dinv)
1689 L=numpy.linalg.cholesky(Dinv)
1571 LT=L.T
1690 LT=L.T
1572
1691
1573 dp = numpy.dot(LT,d)
1692 dp = numpy.dot(LT,d)
1574
1693
1575 #Initial values
1694 #Initial values
1576 data_spc = self.dataIn.data_spc[coord,:,h]
1695 data_spc = self.dataIn.data_spc[coord,:,h]
1577
1696
1578 if (h>0)and(error1[3]<5):
1697 if (h>0)and(error1[3]<5):
1579 p0 = self.dataOut.data_param[i,:,h-1]
1698 p0 = self.dataOut.data_param[i,:,h-1]
1580 else:
1699 else:
1581 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1700 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1582
1701
1583 try:
1702 try:
1584 #Least Squares
1703 #Least Squares
1585 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1704 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1586 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1705 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1587 #Chi square error
1706 #Chi square error
1588 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1707 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1589 #Error with Jacobian
1708 #Error with Jacobian
1590 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1709 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1591 except:
1710 except:
1592 minp = p0*numpy.nan
1711 minp = p0*numpy.nan
1593 error0 = numpy.nan
1712 error0 = numpy.nan
1594 error1 = p0*numpy.nan
1713 error1 = p0*numpy.nan
1595
1714
1596 #Save
1715 #Save
1597 if self.dataOut.data_param == None:
1716 if self.dataOut.data_param == None:
1598 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1717 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1599 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1718 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1600
1719
1601 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1720 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1602 self.dataOut.data_param[i,:,h] = minp
1721 self.dataOut.data_param[i,:,h] = minp
1603 return
1722 return
1604
1723
1605 def __residFunction(self, p, dp, LT, constants):
1724 def __residFunction(self, p, dp, LT, constants):
1606
1725
1607 fm = self.dataOut.library.modelFunction(p, constants)
1726 fm = self.dataOut.library.modelFunction(p, constants)
1608 fmp=numpy.dot(LT,fm)
1727 fmp=numpy.dot(LT,fm)
1609
1728
1610 return dp-fmp
1729 return dp-fmp
1611
1730
1612 def __getSNR(self, z, noise):
1731 def __getSNR(self, z, noise):
1613
1732
1614 avg = numpy.average(z, axis=1)
1733 avg = numpy.average(z, axis=1)
1615 SNR = (avg.T-noise)/noise
1734 SNR = (avg.T-noise)/noise
1616 SNR = SNR.T
1735 SNR = SNR.T
1617 return SNR
1736 return SNR
1618
1737
1619 def __chisq(p,chindex,hindex):
1738 def __chisq(p,chindex,hindex):
1620 #similar to Resid but calculates CHI**2
1739 #similar to Resid but calculates CHI**2
1621 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1740 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1622 dp=numpy.dot(LT,d)
1741 dp=numpy.dot(LT,d)
1623 fmp=numpy.dot(LT,fm)
1742 fmp=numpy.dot(LT,fm)
1624 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1743 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1625 return chisq
1744 return chisq
1626
1745
1627 class WindProfiler(Operation):
1746 class WindProfiler(Operation):
1628
1747
1629 __isConfig = False
1748 __isConfig = False
1630
1749
1631 __initime = None
1750 __initime = None
1632 __lastdatatime = None
1751 __lastdatatime = None
1633 __integrationtime = None
1752 __integrationtime = None
1634
1753
1635 __buffer = None
1754 __buffer = None
1636
1755
1637 __dataReady = False
1756 __dataReady = False
1638
1757
1639 __firstdata = None
1758 __firstdata = None
1640
1759
1641 n = None
1760 n = None
1642
1761
1643 def __init__(self, **kwargs):
1762 def __init__(self, **kwargs):
1644 Operation.__init__(self, **kwargs)
1763 Operation.__init__(self, **kwargs)
1645
1764
1646 def __calculateCosDir(self, elev, azim):
1765 def __calculateCosDir(self, elev, azim):
1647 zen = (90 - elev)*numpy.pi/180
1766 zen = (90 - elev)*numpy.pi/180
1648 azim = azim*numpy.pi/180
1767 azim = azim*numpy.pi/180
1649 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1768 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1650 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1769 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1651
1770
1652 signX = numpy.sign(numpy.cos(azim))
1771 signX = numpy.sign(numpy.cos(azim))
1653 signY = numpy.sign(numpy.sin(azim))
1772 signY = numpy.sign(numpy.sin(azim))
1654
1773
1655 cosDirX = numpy.copysign(cosDirX, signX)
1774 cosDirX = numpy.copysign(cosDirX, signX)
1656 cosDirY = numpy.copysign(cosDirY, signY)
1775 cosDirY = numpy.copysign(cosDirY, signY)
1657 return cosDirX, cosDirY
1776 return cosDirX, cosDirY
1658
1777
1659 def __calculateAngles(self, theta_x, theta_y, azimuth):
1778 def __calculateAngles(self, theta_x, theta_y, azimuth):
1660
1779
1661 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1780 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1662 zenith_arr = numpy.arccos(dir_cosw)
1781 zenith_arr = numpy.arccos(dir_cosw)
1663 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1782 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1664
1783
1665 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1784 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1666 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1785 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1667
1786
1668 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1787 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1669
1788
1670 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1789 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1671
1790
1672 #
1791 #
1673 if horOnly:
1792 if horOnly:
1674 A = numpy.c_[dir_cosu,dir_cosv]
1793 A = numpy.c_[dir_cosu,dir_cosv]
1675 else:
1794 else:
1676 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1795 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1677 A = numpy.asmatrix(A)
1796 A = numpy.asmatrix(A)
1678 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1797 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1679
1798
1680 return A1
1799 return A1
1681
1800
1682 def __correctValues(self, heiRang, phi, velRadial, SNR):
1801 def __correctValues(self, heiRang, phi, velRadial, SNR):
1683 listPhi = phi.tolist()
1802 listPhi = phi.tolist()
1684 maxid = listPhi.index(max(listPhi))
1803 maxid = listPhi.index(max(listPhi))
1685 minid = listPhi.index(min(listPhi))
1804 minid = listPhi.index(min(listPhi))
1686
1805
1687 rango = range(len(phi))
1806 rango = range(len(phi))
1688 # rango = numpy.delete(rango,maxid)
1807 # rango = numpy.delete(rango,maxid)
1689
1808
1690 heiRang1 = heiRang*math.cos(phi[maxid])
1809 heiRang1 = heiRang*math.cos(phi[maxid])
1691 heiRangAux = heiRang*math.cos(phi[minid])
1810 heiRangAux = heiRang*math.cos(phi[minid])
1692 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1811 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1693 heiRang1 = numpy.delete(heiRang1,indOut)
1812 heiRang1 = numpy.delete(heiRang1,indOut)
1694
1813
1695 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1814 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1696 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1815 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1697
1816
1698 for i in rango:
1817 for i in rango:
1699 x = heiRang*math.cos(phi[i])
1818 x = heiRang*math.cos(phi[i])
1700 y1 = velRadial[i,:]
1819 y1 = velRadial[i,:]
1701 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1820 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1702
1821
1703 x1 = heiRang1
1822 x1 = heiRang1
1704 y11 = f1(x1)
1823 y11 = f1(x1)
1705
1824
1706 y2 = SNR[i,:]
1825 y2 = SNR[i,:]
1707 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1826 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1708 y21 = f2(x1)
1827 y21 = f2(x1)
1709
1828
1710 velRadial1[i,:] = y11
1829 velRadial1[i,:] = y11
1711 SNR1[i,:] = y21
1830 SNR1[i,:] = y21
1712
1831
1713 return heiRang1, velRadial1, SNR1
1832 return heiRang1, velRadial1, SNR1
1714
1833
1715 def __calculateVelUVW(self, A, velRadial):
1834 def __calculateVelUVW(self, A, velRadial):
1716
1835
1717 #Operacion Matricial
1836 #Operacion Matricial
1718 # velUVW = numpy.zeros((velRadial.shape[1],3))
1837 # velUVW = numpy.zeros((velRadial.shape[1],3))
1719 # for ind in range(velRadial.shape[1]):
1838 # for ind in range(velRadial.shape[1]):
1720 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1839 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1721 # velUVW = velUVW.transpose()
1840 # velUVW = velUVW.transpose()
1722 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1841 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1723 velUVW[:,:] = numpy.dot(A,velRadial)
1842 velUVW[:,:] = numpy.dot(A,velRadial)
1724
1843
1725
1844
1726 return velUVW
1845 return velUVW
1727
1846
1728 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1847 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1729
1848
1730 def techniqueDBS(self, kwargs):
1849 def techniqueDBS(self, kwargs):
1731 """
1850 """
1732 Function that implements Doppler Beam Swinging (DBS) technique.
1851 Function that implements Doppler Beam Swinging (DBS) technique.
1733
1852
1734 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1853 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1735 Direction correction (if necessary), Ranges and SNR
1854 Direction correction (if necessary), Ranges and SNR
1736
1855
1737 Output: Winds estimation (Zonal, Meridional and Vertical)
1856 Output: Winds estimation (Zonal, Meridional and Vertical)
1738
1857
1739 Parameters affected: Winds, height range, SNR
1858 Parameters affected: Winds, height range, SNR
1740 """
1859 """
1741 velRadial0 = kwargs['velRadial']
1860 velRadial0 = kwargs['velRadial']
1742 heiRang = kwargs['heightList']
1861 heiRang = kwargs['heightList']
1743 SNR0 = kwargs['SNR']
1862 SNR0 = kwargs['SNR']
1744
1863
1745 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1864 if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'):
1746 theta_x = numpy.array(kwargs['dirCosx'])
1865 theta_x = numpy.array(kwargs['dirCosx'])
1747 theta_y = numpy.array(kwargs['dirCosy'])
1866 theta_y = numpy.array(kwargs['dirCosy'])
1748 else:
1867 else:
1749 elev = numpy.array(kwargs['elevation'])
1868 elev = numpy.array(kwargs['elevation'])
1750 azim = numpy.array(kwargs['azimuth'])
1869 azim = numpy.array(kwargs['azimuth'])
1751 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1870 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1752 azimuth = kwargs['correctAzimuth']
1871 azimuth = kwargs['correctAzimuth']
1753 if kwargs.has_key('horizontalOnly'):
1872 if kwargs.has_key('horizontalOnly'):
1754 horizontalOnly = kwargs['horizontalOnly']
1873 horizontalOnly = kwargs['horizontalOnly']
1755 else: horizontalOnly = False
1874 else: horizontalOnly = False
1756 if kwargs.has_key('correctFactor'):
1875 if kwargs.has_key('correctFactor'):
1757 correctFactor = kwargs['correctFactor']
1876 correctFactor = kwargs['correctFactor']
1758 else: correctFactor = 1
1877 else: correctFactor = 1
1759 if kwargs.has_key('channelList'):
1878 if kwargs.has_key('channelList'):
1760 channelList = kwargs['channelList']
1879 channelList = kwargs['channelList']
1761 if len(channelList) == 2:
1880 if len(channelList) == 2:
1762 horizontalOnly = True
1881 horizontalOnly = True
1763 arrayChannel = numpy.array(channelList)
1882 arrayChannel = numpy.array(channelList)
1764 param = param[arrayChannel,:,:]
1883 param = param[arrayChannel,:,:]
1765 theta_x = theta_x[arrayChannel]
1884 theta_x = theta_x[arrayChannel]
1766 theta_y = theta_y[arrayChannel]
1885 theta_y = theta_y[arrayChannel]
1767
1886
1768 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1887 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1769 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1888 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1770 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1889 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1771
1890
1772 #Calculo de Componentes de la velocidad con DBS
1891 #Calculo de Componentes de la velocidad con DBS
1773 winds = self.__calculateVelUVW(A,velRadial1)
1892 winds = self.__calculateVelUVW(A,velRadial1)
1774
1893
1775 return winds, heiRang1, SNR1
1894 return winds, heiRang1, SNR1
1776
1895
1777 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1896 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1778
1897
1779 nPairs = len(pairs_ccf)
1898 nPairs = len(pairs_ccf)
1780 posx = numpy.asarray(posx)
1899 posx = numpy.asarray(posx)
1781 posy = numpy.asarray(posy)
1900 posy = numpy.asarray(posy)
1782
1901
1783 #Rotacion Inversa para alinear con el azimuth
1902 #Rotacion Inversa para alinear con el azimuth
1784 if azimuth!= None:
1903 if azimuth!= None:
1785 azimuth = azimuth*math.pi/180
1904 azimuth = azimuth*math.pi/180
1786 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1905 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1787 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1906 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1788 else:
1907 else:
1789 posx1 = posx
1908 posx1 = posx
1790 posy1 = posy
1909 posy1 = posy
1791
1910
1792 #Calculo de Distancias
1911 #Calculo de Distancias
1793 distx = numpy.zeros(nPairs)
1912 distx = numpy.zeros(nPairs)
1794 disty = numpy.zeros(nPairs)
1913 disty = numpy.zeros(nPairs)
1795 dist = numpy.zeros(nPairs)
1914 dist = numpy.zeros(nPairs)
1796 ang = numpy.zeros(nPairs)
1915 ang = numpy.zeros(nPairs)
1797
1916
1798 for i in range(nPairs):
1917 for i in range(nPairs):
1799 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1918 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1800 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1919 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1801 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1920 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1802 ang[i] = numpy.arctan2(disty[i],distx[i])
1921 ang[i] = numpy.arctan2(disty[i],distx[i])
1803
1922
1804 return distx, disty, dist, ang
1923 return distx, disty, dist, ang
1805 #Calculo de Matrices
1924 #Calculo de Matrices
1806 # nPairs = len(pairs)
1925 # nPairs = len(pairs)
1807 # ang1 = numpy.zeros((nPairs, 2, 1))
1926 # ang1 = numpy.zeros((nPairs, 2, 1))
1808 # dist1 = numpy.zeros((nPairs, 2, 1))
1927 # dist1 = numpy.zeros((nPairs, 2, 1))
1809 #
1928 #
1810 # for j in range(nPairs):
1929 # for j in range(nPairs):
1811 # dist1[j,0,0] = dist[pairs[j][0]]
1930 # dist1[j,0,0] = dist[pairs[j][0]]
1812 # dist1[j,1,0] = dist[pairs[j][1]]
1931 # dist1[j,1,0] = dist[pairs[j][1]]
1813 # ang1[j,0,0] = ang[pairs[j][0]]
1932 # ang1[j,0,0] = ang[pairs[j][0]]
1814 # ang1[j,1,0] = ang[pairs[j][1]]
1933 # ang1[j,1,0] = ang[pairs[j][1]]
1815 #
1934 #
1816 # return distx,disty, dist1,ang1
1935 # return distx,disty, dist1,ang1
1817
1936
1818
1937
1819 def __calculateVelVer(self, phase, lagTRange, _lambda):
1938 def __calculateVelVer(self, phase, lagTRange, _lambda):
1820
1939
1821 Ts = lagTRange[1] - lagTRange[0]
1940 Ts = lagTRange[1] - lagTRange[0]
1822 velW = -_lambda*phase/(4*math.pi*Ts)
1941 velW = -_lambda*phase/(4*math.pi*Ts)
1823
1942
1824 return velW
1943 return velW
1825
1944
1826 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1945 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1827 nPairs = tau1.shape[0]
1946 nPairs = tau1.shape[0]
1828 nHeights = tau1.shape[1]
1947 nHeights = tau1.shape[1]
1829 vel = numpy.zeros((nPairs,3,nHeights))
1948 vel = numpy.zeros((nPairs,3,nHeights))
1830 dist1 = numpy.reshape(dist, (dist.size,1))
1949 dist1 = numpy.reshape(dist, (dist.size,1))
1831
1950
1832 angCos = numpy.cos(ang)
1951 angCos = numpy.cos(ang)
1833 angSin = numpy.sin(ang)
1952 angSin = numpy.sin(ang)
1834
1953
1835 vel0 = dist1*tau1/(2*tau2**2)
1954 vel0 = dist1*tau1/(2*tau2**2)
1836 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1955 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1837 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1956 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1838
1957
1839 ind = numpy.where(numpy.isinf(vel))
1958 ind = numpy.where(numpy.isinf(vel))
1840 vel[ind] = numpy.nan
1959 vel[ind] = numpy.nan
1841
1960
1842 return vel
1961 return vel
1843
1962
1844 # def __getPairsAutoCorr(self, pairsList, nChannels):
1963 # def __getPairsAutoCorr(self, pairsList, nChannels):
1845 #
1964 #
1846 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1965 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1847 #
1966 #
1848 # for l in range(len(pairsList)):
1967 # for l in range(len(pairsList)):
1849 # firstChannel = pairsList[l][0]
1968 # firstChannel = pairsList[l][0]
1850 # secondChannel = pairsList[l][1]
1969 # secondChannel = pairsList[l][1]
1851 #
1970 #
1852 # #Obteniendo pares de Autocorrelacion
1971 # #Obteniendo pares de Autocorrelacion
1853 # if firstChannel == secondChannel:
1972 # if firstChannel == secondChannel:
1854 # pairsAutoCorr[firstChannel] = int(l)
1973 # pairsAutoCorr[firstChannel] = int(l)
1855 #
1974 #
1856 # pairsAutoCorr = pairsAutoCorr.astype(int)
1975 # pairsAutoCorr = pairsAutoCorr.astype(int)
1857 #
1976 #
1858 # pairsCrossCorr = range(len(pairsList))
1977 # pairsCrossCorr = range(len(pairsList))
1859 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1978 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1860 #
1979 #
1861 # return pairsAutoCorr, pairsCrossCorr
1980 # return pairsAutoCorr, pairsCrossCorr
1862
1981
1863 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1982 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1864 def techniqueSA(self, kwargs):
1983 def techniqueSA(self, kwargs):
1865
1984
1866 """
1985 """
1867 Function that implements Spaced Antenna (SA) technique.
1986 Function that implements Spaced Antenna (SA) technique.
1868
1987
1869 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1988 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1870 Direction correction (if necessary), Ranges and SNR
1989 Direction correction (if necessary), Ranges and SNR
1871
1990
1872 Output: Winds estimation (Zonal, Meridional and Vertical)
1991 Output: Winds estimation (Zonal, Meridional and Vertical)
1873
1992
1874 Parameters affected: Winds
1993 Parameters affected: Winds
1875 """
1994 """
1876 position_x = kwargs['positionX']
1995 position_x = kwargs['positionX']
1877 position_y = kwargs['positionY']
1996 position_y = kwargs['positionY']
1878 azimuth = kwargs['azimuth']
1997 azimuth = kwargs['azimuth']
1879
1998
1880 if kwargs.has_key('correctFactor'):
1999 if kwargs.has_key('correctFactor'):
1881 correctFactor = kwargs['correctFactor']
2000 correctFactor = kwargs['correctFactor']
1882 else:
2001 else:
1883 correctFactor = 1
2002 correctFactor = 1
1884
2003
1885 groupList = kwargs['groupList']
2004 groupList = kwargs['groupList']
1886 pairs_ccf = groupList[1]
2005 pairs_ccf = groupList[1]
1887 tau = kwargs['tau']
2006 tau = kwargs['tau']
1888 _lambda = kwargs['_lambda']
2007 _lambda = kwargs['_lambda']
1889
2008
1890 #Cross Correlation pairs obtained
2009 #Cross Correlation pairs obtained
1891 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
2010 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
1892 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
2011 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1893 # pairsSelArray = numpy.array(pairsSelected)
2012 # pairsSelArray = numpy.array(pairsSelected)
1894 # pairs = []
2013 # pairs = []
1895 #
2014 #
1896 # #Wind estimation pairs obtained
2015 # #Wind estimation pairs obtained
1897 # for i in range(pairsSelArray.shape[0]/2):
2016 # for i in range(pairsSelArray.shape[0]/2):
1898 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
2017 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1899 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
2018 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1900 # pairs.append((ind1,ind2))
2019 # pairs.append((ind1,ind2))
1901
2020
1902 indtau = tau.shape[0]/2
2021 indtau = tau.shape[0]/2
1903 tau1 = tau[:indtau,:]
2022 tau1 = tau[:indtau,:]
1904 tau2 = tau[indtau:-1,:]
2023 tau2 = tau[indtau:-1,:]
1905 # tau1 = tau1[pairs,:]
2024 # tau1 = tau1[pairs,:]
1906 # tau2 = tau2[pairs,:]
2025 # tau2 = tau2[pairs,:]
1907 phase1 = tau[-1,:]
2026 phase1 = tau[-1,:]
1908
2027
1909 #---------------------------------------------------------------------
2028 #---------------------------------------------------------------------
1910 #Metodo Directo
2029 #Metodo Directo
1911 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
2030 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
1912 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
2031 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1913 winds = stats.nanmean(winds, axis=0)
2032 winds = stats.nanmean(winds, axis=0)
1914 #---------------------------------------------------------------------
2033 #---------------------------------------------------------------------
1915 #Metodo General
2034 #Metodo General
1916 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
2035 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1917 # #Calculo Coeficientes de Funcion de Correlacion
2036 # #Calculo Coeficientes de Funcion de Correlacion
1918 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
2037 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1919 # #Calculo de Velocidades
2038 # #Calculo de Velocidades
1920 # winds = self.calculateVelUV(F,G,A,B,H)
2039 # winds = self.calculateVelUV(F,G,A,B,H)
1921
2040
1922 #---------------------------------------------------------------------
2041 #---------------------------------------------------------------------
1923 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
2042 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1924 winds = correctFactor*winds
2043 winds = correctFactor*winds
1925 return winds
2044 return winds
1926
2045
1927 def __checkTime(self, currentTime, paramInterval, outputInterval):
2046 def __checkTime(self, currentTime, paramInterval, outputInterval):
1928
2047
1929 dataTime = currentTime + paramInterval
2048 dataTime = currentTime + paramInterval
1930 deltaTime = dataTime - self.__initime
2049 deltaTime = dataTime - self.__initime
1931
2050
1932 if deltaTime >= outputInterval or deltaTime < 0:
2051 if deltaTime >= outputInterval or deltaTime < 0:
1933 self.__dataReady = True
2052 self.__dataReady = True
1934 return
2053 return
1935
2054
1936 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
2055 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1937 '''
2056 '''
1938 Function that implements winds estimation technique with detected meteors.
2057 Function that implements winds estimation technique with detected meteors.
1939
2058
1940 Input: Detected meteors, Minimum meteor quantity to wind estimation
2059 Input: Detected meteors, Minimum meteor quantity to wind estimation
1941
2060
1942 Output: Winds estimation (Zonal and Meridional)
2061 Output: Winds estimation (Zonal and Meridional)
1943
2062
1944 Parameters affected: Winds
2063 Parameters affected: Winds
1945 '''
2064 '''
1946 # print arrayMeteor.shape
2065 # print arrayMeteor.shape
1947 #Settings
2066 #Settings
1948 nInt = (heightMax - heightMin)/2
2067 nInt = (heightMax - heightMin)/2
1949 # print nInt
2068 # print nInt
1950 nInt = int(nInt)
2069 nInt = int(nInt)
1951 # print nInt
2070 # print nInt
1952 winds = numpy.zeros((2,nInt))*numpy.nan
2071 winds = numpy.zeros((2,nInt))*numpy.nan
1953
2072
1954 #Filter errors
2073 #Filter errors
1955 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
2074 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1956 finalMeteor = arrayMeteor[error,:]
2075 finalMeteor = arrayMeteor[error,:]
1957
2076
1958 #Meteor Histogram
2077 #Meteor Histogram
1959 finalHeights = finalMeteor[:,2]
2078 finalHeights = finalMeteor[:,2]
1960 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
2079 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1961 nMeteorsPerI = hist[0]
2080 nMeteorsPerI = hist[0]
1962 heightPerI = hist[1]
2081 heightPerI = hist[1]
1963
2082
1964 #Sort of meteors
2083 #Sort of meteors
1965 indSort = finalHeights.argsort()
2084 indSort = finalHeights.argsort()
1966 finalMeteor2 = finalMeteor[indSort,:]
2085 finalMeteor2 = finalMeteor[indSort,:]
1967
2086
1968 # Calculating winds
2087 # Calculating winds
1969 ind1 = 0
2088 ind1 = 0
1970 ind2 = 0
2089 ind2 = 0
1971
2090
1972 for i in range(nInt):
2091 for i in range(nInt):
1973 nMet = nMeteorsPerI[i]
2092 nMet = nMeteorsPerI[i]
1974 ind1 = ind2
2093 ind1 = ind2
1975 ind2 = ind1 + nMet
2094 ind2 = ind1 + nMet
1976
2095
1977 meteorAux = finalMeteor2[ind1:ind2,:]
2096 meteorAux = finalMeteor2[ind1:ind2,:]
1978
2097
1979 if meteorAux.shape[0] >= meteorThresh:
2098 if meteorAux.shape[0] >= meteorThresh:
1980 vel = meteorAux[:, 6]
2099 vel = meteorAux[:, 6]
1981 zen = meteorAux[:, 4]*numpy.pi/180
2100 zen = meteorAux[:, 4]*numpy.pi/180
1982 azim = meteorAux[:, 3]*numpy.pi/180
2101 azim = meteorAux[:, 3]*numpy.pi/180
1983
2102
1984 n = numpy.cos(zen)
2103 n = numpy.cos(zen)
1985 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
2104 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1986 # l = m*numpy.tan(azim)
2105 # l = m*numpy.tan(azim)
1987 l = numpy.sin(zen)*numpy.sin(azim)
2106 l = numpy.sin(zen)*numpy.sin(azim)
1988 m = numpy.sin(zen)*numpy.cos(azim)
2107 m = numpy.sin(zen)*numpy.cos(azim)
1989
2108
1990 A = numpy.vstack((l, m)).transpose()
2109 A = numpy.vstack((l, m)).transpose()
1991 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
2110 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1992 windsAux = numpy.dot(A1, vel)
2111 windsAux = numpy.dot(A1, vel)
1993
2112
1994 winds[0,i] = windsAux[0]
2113 winds[0,i] = windsAux[0]
1995 winds[1,i] = windsAux[1]
2114 winds[1,i] = windsAux[1]
1996
2115
1997 return winds, heightPerI[:-1]
2116 return winds, heightPerI[:-1]
1998
2117
1999 def techniqueNSM_SA(self, **kwargs):
2118 def techniqueNSM_SA(self, **kwargs):
2000 metArray = kwargs['metArray']
2119 metArray = kwargs['metArray']
2001 heightList = kwargs['heightList']
2120 heightList = kwargs['heightList']
2002 timeList = kwargs['timeList']
2121 timeList = kwargs['timeList']
2003
2122
2004 rx_location = kwargs['rx_location']
2123 rx_location = kwargs['rx_location']
2005 groupList = kwargs['groupList']
2124 groupList = kwargs['groupList']
2006 azimuth = kwargs['azimuth']
2125 azimuth = kwargs['azimuth']
2007 dfactor = kwargs['dfactor']
2126 dfactor = kwargs['dfactor']
2008 k = kwargs['k']
2127 k = kwargs['k']
2009
2128
2010 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2129 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
2011 d = dist*dfactor
2130 d = dist*dfactor
2012 #Phase calculation
2131 #Phase calculation
2013 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2132 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
2014
2133
2015 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2134 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
2016
2135
2017 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2136 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2018 azimuth1 = azimuth1*numpy.pi/180
2137 azimuth1 = azimuth1*numpy.pi/180
2019
2138
2020 for i in range(heightList.size):
2139 for i in range(heightList.size):
2021 h = heightList[i]
2140 h = heightList[i]
2022 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2141 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
2023 metHeight = metArray1[indH,:]
2142 metHeight = metArray1[indH,:]
2024 if metHeight.shape[0] >= 2:
2143 if metHeight.shape[0] >= 2:
2025 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2144 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
2026 iazim = metHeight[:,1].astype(int)
2145 iazim = metHeight[:,1].astype(int)
2027 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2146 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
2028 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2147 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
2029 A = numpy.asmatrix(A)
2148 A = numpy.asmatrix(A)
2030 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2149 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
2031 velHor = numpy.dot(A1,velAux)
2150 velHor = numpy.dot(A1,velAux)
2032
2151
2033 velEst[i,:] = numpy.squeeze(velHor)
2152 velEst[i,:] = numpy.squeeze(velHor)
2034 return velEst
2153 return velEst
2035
2154
2036 def __getPhaseSlope(self, metArray, heightList, timeList):
2155 def __getPhaseSlope(self, metArray, heightList, timeList):
2037 meteorList = []
2156 meteorList = []
2038 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2157 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
2039 #Putting back together the meteor matrix
2158 #Putting back together the meteor matrix
2040 utctime = metArray[:,0]
2159 utctime = metArray[:,0]
2041 uniqueTime = numpy.unique(utctime)
2160 uniqueTime = numpy.unique(utctime)
2042
2161
2043 phaseDerThresh = 0.5
2162 phaseDerThresh = 0.5
2044 ippSeconds = timeList[1] - timeList[0]
2163 ippSeconds = timeList[1] - timeList[0]
2045 sec = numpy.where(timeList>1)[0][0]
2164 sec = numpy.where(timeList>1)[0][0]
2046 nPairs = metArray.shape[1] - 6
2165 nPairs = metArray.shape[1] - 6
2047 nHeights = len(heightList)
2166 nHeights = len(heightList)
2048
2167
2049 for t in uniqueTime:
2168 for t in uniqueTime:
2050 metArray1 = metArray[utctime==t,:]
2169 metArray1 = metArray[utctime==t,:]
2051 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2170 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
2052 tmet = metArray1[:,1].astype(int)
2171 tmet = metArray1[:,1].astype(int)
2053 hmet = metArray1[:,2].astype(int)
2172 hmet = metArray1[:,2].astype(int)
2054
2173
2055 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2174 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
2056 metPhase[:,:] = numpy.nan
2175 metPhase[:,:] = numpy.nan
2057 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2176 metPhase[:,hmet,tmet] = metArray1[:,6:].T
2058
2177
2059 #Delete short trails
2178 #Delete short trails
2060 metBool = ~numpy.isnan(metPhase[0,:,:])
2179 metBool = ~numpy.isnan(metPhase[0,:,:])
2061 heightVect = numpy.sum(metBool, axis = 1)
2180 heightVect = numpy.sum(metBool, axis = 1)
2062 metBool[heightVect<sec,:] = False
2181 metBool[heightVect<sec,:] = False
2063 metPhase[:,heightVect<sec,:] = numpy.nan
2182 metPhase[:,heightVect<sec,:] = numpy.nan
2064
2183
2065 #Derivative
2184 #Derivative
2066 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2185 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2067 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2186 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2068 metPhase[phDerAux] = numpy.nan
2187 metPhase[phDerAux] = numpy.nan
2069
2188
2070 #--------------------------METEOR DETECTION -----------------------------------------
2189 #--------------------------METEOR DETECTION -----------------------------------------
2071 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2190 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2072
2191
2073 for p in numpy.arange(nPairs):
2192 for p in numpy.arange(nPairs):
2074 phase = metPhase[p,:,:]
2193 phase = metPhase[p,:,:]
2075 phDer = metDer[p,:,:]
2194 phDer = metDer[p,:,:]
2076
2195
2077 for h in indMet:
2196 for h in indMet:
2078 height = heightList[h]
2197 height = heightList[h]
2079 phase1 = phase[h,:] #82
2198 phase1 = phase[h,:] #82
2080 phDer1 = phDer[h,:]
2199 phDer1 = phDer[h,:]
2081
2200
2082 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2201 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2083
2202
2084 indValid = numpy.where(~numpy.isnan(phase1))[0]
2203 indValid = numpy.where(~numpy.isnan(phase1))[0]
2085 initMet = indValid[0]
2204 initMet = indValid[0]
2086 endMet = 0
2205 endMet = 0
2087
2206
2088 for i in range(len(indValid)-1):
2207 for i in range(len(indValid)-1):
2089
2208
2090 #Time difference
2209 #Time difference
2091 inow = indValid[i]
2210 inow = indValid[i]
2092 inext = indValid[i+1]
2211 inext = indValid[i+1]
2093 idiff = inext - inow
2212 idiff = inext - inow
2094 #Phase difference
2213 #Phase difference
2095 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2214 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2096
2215
2097 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2216 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2098 sizeTrail = inow - initMet + 1
2217 sizeTrail = inow - initMet + 1
2099 if sizeTrail>3*sec: #Too short meteors
2218 if sizeTrail>3*sec: #Too short meteors
2100 x = numpy.arange(initMet,inow+1)*ippSeconds
2219 x = numpy.arange(initMet,inow+1)*ippSeconds
2101 y = phase1[initMet:inow+1]
2220 y = phase1[initMet:inow+1]
2102 ynnan = ~numpy.isnan(y)
2221 ynnan = ~numpy.isnan(y)
2103 x = x[ynnan]
2222 x = x[ynnan]
2104 y = y[ynnan]
2223 y = y[ynnan]
2105 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2224 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2106 ylin = x*slope + intercept
2225 ylin = x*slope + intercept
2107 rsq = r_value**2
2226 rsq = r_value**2
2108 if rsq > 0.5:
2227 if rsq > 0.5:
2109 vel = slope#*height*1000/(k*d)
2228 vel = slope#*height*1000/(k*d)
2110 estAux = numpy.array([utctime,p,height, vel, rsq])
2229 estAux = numpy.array([utctime,p,height, vel, rsq])
2111 meteorList.append(estAux)
2230 meteorList.append(estAux)
2112 initMet = inext
2231 initMet = inext
2113 metArray2 = numpy.array(meteorList)
2232 metArray2 = numpy.array(meteorList)
2114
2233
2115 return metArray2
2234 return metArray2
2116
2235
2117 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2236 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2118
2237
2119 azimuth1 = numpy.zeros(len(pairslist))
2238 azimuth1 = numpy.zeros(len(pairslist))
2120 dist = numpy.zeros(len(pairslist))
2239 dist = numpy.zeros(len(pairslist))
2121
2240
2122 for i in range(len(rx_location)):
2241 for i in range(len(rx_location)):
2123 ch0 = pairslist[i][0]
2242 ch0 = pairslist[i][0]
2124 ch1 = pairslist[i][1]
2243 ch1 = pairslist[i][1]
2125
2244
2126 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2245 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2127 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2246 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2128 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2247 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2129 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2248 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2130
2249
2131 azimuth1 -= azimuth0
2250 azimuth1 -= azimuth0
2132 return azimuth1, dist
2251 return azimuth1, dist
2133
2252
2134 def techniqueNSM_DBS(self, **kwargs):
2253 def techniqueNSM_DBS(self, **kwargs):
2135 metArray = kwargs['metArray']
2254 metArray = kwargs['metArray']
2136 heightList = kwargs['heightList']
2255 heightList = kwargs['heightList']
2137 timeList = kwargs['timeList']
2256 timeList = kwargs['timeList']
2138 zenithList = kwargs['zenithList']
2257 zenithList = kwargs['zenithList']
2139 nChan = numpy.max(cmet) + 1
2258 nChan = numpy.max(cmet) + 1
2140 nHeights = len(heightList)
2259 nHeights = len(heightList)
2141
2260
2142 utctime = metArray[:,0]
2261 utctime = metArray[:,0]
2143 cmet = metArray[:,1]
2262 cmet = metArray[:,1]
2144 hmet = metArray1[:,3].astype(int)
2263 hmet = metArray1[:,3].astype(int)
2145 h1met = heightList[hmet]*zenithList[cmet]
2264 h1met = heightList[hmet]*zenithList[cmet]
2146 vmet = metArray1[:,5]
2265 vmet = metArray1[:,5]
2147
2266
2148 for i in range(nHeights - 1):
2267 for i in range(nHeights - 1):
2149 hmin = heightList[i]
2268 hmin = heightList[i]
2150 hmax = heightList[i + 1]
2269 hmax = heightList[i + 1]
2151
2270
2152 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2271 vthisH = vmet[(h1met>=hmin) & (h1met<hmax)]
2153
2272
2154
2273
2155
2274
2156 return data_output
2275 return data_output
2157
2276
2158 def run(self, dataOut, technique, positionY, positionX, azimuth, **kwargs):
2277 def run(self, dataOut, technique, positionY, positionX, azimuth, **kwargs):
2159
2278
2160 param = dataOut.data_param
2279 param = dataOut.data_param
2161 if dataOut.abscissaList != None:
2280 if dataOut.abscissaList != None:
2162 absc = dataOut.abscissaList[:-1]
2281 absc = dataOut.abscissaList[:-1]
2163 noise = dataOut.noise
2282 noise = dataOut.noise
2164 heightList = dataOut.heightList
2283 heightList = dataOut.heightList
2165 SNR = dataOut.data_SNR
2284 SNR = dataOut.data_SNR
2166
2285
2167 if technique == 'DBS':
2286 if technique == 'DBS':
2168
2287
2169 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2288 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2170 kwargs['heightList'] = heightList
2289 kwargs['heightList'] = heightList
2171 kwargs['SNR'] = SNR
2290 kwargs['SNR'] = SNR
2172
2291
2173 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2292 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2174 dataOut.utctimeInit = dataOut.utctime
2293 dataOut.utctimeInit = dataOut.utctime
2175 dataOut.outputInterval = dataOut.paramInterval
2294 dataOut.outputInterval = dataOut.paramInterval
2176
2295
2177 elif technique == 'SA':
2296 elif technique == 'SA':
2178
2297
2179 #Parameters
2298 #Parameters
2180 # position_x = kwargs['positionX']
2299 # position_x = kwargs['positionX']
2181 # position_y = kwargs['positionY']
2300 # position_y = kwargs['positionY']
2182 # azimuth = kwargs['azimuth']
2301 # azimuth = kwargs['azimuth']
2183 #
2302 #
2184 # if kwargs.has_key('crosspairsList'):
2303 # if kwargs.has_key('crosspairsList'):
2185 # pairs = kwargs['crosspairsList']
2304 # pairs = kwargs['crosspairsList']
2186 # else:
2305 # else:
2187 # pairs = None
2306 # pairs = None
2188 #
2307 #
2189 # if kwargs.has_key('correctFactor'):
2308 # if kwargs.has_key('correctFactor'):
2190 # correctFactor = kwargs['correctFactor']
2309 # correctFactor = kwargs['correctFactor']
2191 # else:
2310 # else:
2192 # correctFactor = 1
2311 # correctFactor = 1
2193
2312
2194 # tau = dataOut.data_param
2313 # tau = dataOut.data_param
2195 # _lambda = dataOut.C/dataOut.frequency
2314 # _lambda = dataOut.C/dataOut.frequency
2196 # pairsList = dataOut.groupList
2315 # pairsList = dataOut.groupList
2197 # nChannels = dataOut.nChannels
2316 # nChannels = dataOut.nChannels
2198
2317
2199 kwargs['groupList'] = dataOut.groupList
2318 kwargs['groupList'] = dataOut.groupList
2200 kwargs['tau'] = dataOut.data_param
2319 kwargs['tau'] = dataOut.data_param
2201 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2320 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2202 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2321 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2203 dataOut.data_output = self.techniqueSA(kwargs)
2322 dataOut.data_output = self.techniqueSA(kwargs)
2204 dataOut.utctimeInit = dataOut.utctime
2323 dataOut.utctimeInit = dataOut.utctime
2205 dataOut.outputInterval = dataOut.timeInterval
2324 dataOut.outputInterval = dataOut.timeInterval
2206
2325
2207 elif technique == 'Meteors':
2326 elif technique == 'Meteors':
2208 dataOut.flagNoData = True
2327 dataOut.flagNoData = True
2209 self.__dataReady = False
2328 self.__dataReady = False
2210
2329
2211 if kwargs.has_key('nHours'):
2330 if kwargs.has_key('nHours'):
2212 nHours = kwargs['nHours']
2331 nHours = kwargs['nHours']
2213 else:
2332 else:
2214 nHours = 1
2333 nHours = 1
2215
2334
2216 if kwargs.has_key('meteorsPerBin'):
2335 if kwargs.has_key('meteorsPerBin'):
2217 meteorThresh = kwargs['meteorsPerBin']
2336 meteorThresh = kwargs['meteorsPerBin']
2218 else:
2337 else:
2219 meteorThresh = 6
2338 meteorThresh = 6
2220
2339
2221 if kwargs.has_key('hmin'):
2340 if kwargs.has_key('hmin'):
2222 hmin = kwargs['hmin']
2341 hmin = kwargs['hmin']
2223 else: hmin = 70
2342 else: hmin = 70
2224 if kwargs.has_key('hmax'):
2343 if kwargs.has_key('hmax'):
2225 hmax = kwargs['hmax']
2344 hmax = kwargs['hmax']
2226 else: hmax = 110
2345 else: hmax = 110
2227
2346
2228 dataOut.outputInterval = nHours*3600
2347 dataOut.outputInterval = nHours*3600
2229
2348
2230 if self.__isConfig == False:
2349 if self.__isConfig == False:
2231 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2350 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2232 #Get Initial LTC time
2351 #Get Initial LTC time
2233 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2352 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2234 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2353 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2235
2354
2236 self.__isConfig = True
2355 self.__isConfig = True
2237
2356
2238 if self.__buffer == None:
2357 if self.__buffer == None:
2239 self.__buffer = dataOut.data_param
2358 self.__buffer = dataOut.data_param
2240 self.__firstdata = copy.copy(dataOut)
2359 self.__firstdata = copy.copy(dataOut)
2241
2360
2242 else:
2361 else:
2243 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2362 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2244
2363
2245 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2364 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2246
2365
2247 if self.__dataReady:
2366 if self.__dataReady:
2248 dataOut.utctimeInit = self.__initime
2367 dataOut.utctimeInit = self.__initime
2249
2368
2250 self.__initime += dataOut.outputInterval #to erase time offset
2369 self.__initime += dataOut.outputInterval #to erase time offset
2251
2370
2252 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2371 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2253 dataOut.flagNoData = False
2372 dataOut.flagNoData = False
2254 self.__buffer = None
2373 self.__buffer = None
2255
2374
2256 elif technique == 'Meteors1':
2375 elif technique == 'Meteors1':
2257 dataOut.flagNoData = True
2376 dataOut.flagNoData = True
2258 self.__dataReady = False
2377 self.__dataReady = False
2259
2378
2260 if kwargs.has_key('nMins'):
2379 if kwargs.has_key('nMins'):
2261 nMins = kwargs['nMins']
2380 nMins = kwargs['nMins']
2262 else: nMins = 20
2381 else: nMins = 20
2263 if kwargs.has_key('rx_location'):
2382 if kwargs.has_key('rx_location'):
2264 rx_location = kwargs['rx_location']
2383 rx_location = kwargs['rx_location']
2265 else: rx_location = [(0,1),(1,1),(1,0)]
2384 else: rx_location = [(0,1),(1,1),(1,0)]
2266 if kwargs.has_key('azimuth'):
2385 if kwargs.has_key('azimuth'):
2267 azimuth = kwargs['azimuth']
2386 azimuth = kwargs['azimuth']
2268 else: azimuth = 51
2387 else: azimuth = 51
2269 if kwargs.has_key('dfactor'):
2388 if kwargs.has_key('dfactor'):
2270 dfactor = kwargs['dfactor']
2389 dfactor = kwargs['dfactor']
2271 if kwargs.has_key('mode'):
2390 if kwargs.has_key('mode'):
2272 mode = kwargs['mode']
2391 mode = kwargs['mode']
2273 else: mode = 'SA'
2392 else: mode = 'SA'
2274
2393
2275 #Borrar luego esto
2394 #Borrar luego esto
2276 if dataOut.groupList == None:
2395 if dataOut.groupList == None:
2277 dataOut.groupList = [(0,1),(0,2),(1,2)]
2396 dataOut.groupList = [(0,1),(0,2),(1,2)]
2278 groupList = dataOut.groupList
2397 groupList = dataOut.groupList
2279 C = 3e8
2398 C = 3e8
2280 freq = 50e6
2399 freq = 50e6
2281 lamb = C/freq
2400 lamb = C/freq
2282 k = 2*numpy.pi/lamb
2401 k = 2*numpy.pi/lamb
2283
2402
2284 timeList = dataOut.abscissaList
2403 timeList = dataOut.abscissaList
2285 heightList = dataOut.heightList
2404 heightList = dataOut.heightList
2286
2405
2287 if self.__isConfig == False:
2406 if self.__isConfig == False:
2288 dataOut.outputInterval = nMins*60
2407 dataOut.outputInterval = nMins*60
2289 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2408 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2290 #Get Initial LTC time
2409 #Get Initial LTC time
2291 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2410 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2292 minuteAux = initime.minute
2411 minuteAux = initime.minute
2293 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2412 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2294 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2413 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2295
2414
2296 self.__isConfig = True
2415 self.__isConfig = True
2297
2416
2298 if self.__buffer == None:
2417 if self.__buffer == None:
2299 self.__buffer = dataOut.data_param
2418 self.__buffer = dataOut.data_param
2300 self.__firstdata = copy.copy(dataOut)
2419 self.__firstdata = copy.copy(dataOut)
2301
2420
2302 else:
2421 else:
2303 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2422 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2304
2423
2305 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2424 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2306
2425
2307 if self.__dataReady:
2426 if self.__dataReady:
2308 dataOut.utctimeInit = self.__initime
2427 dataOut.utctimeInit = self.__initime
2309 self.__initime += dataOut.outputInterval #to erase time offset
2428 self.__initime += dataOut.outputInterval #to erase time offset
2310
2429
2311 metArray = self.__buffer
2430 metArray = self.__buffer
2312 if mode == 'SA':
2431 if mode == 'SA':
2313 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2432 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2314 elif mode == 'DBS':
2433 elif mode == 'DBS':
2315 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2434 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList)
2316 dataOut.data_output = dataOut.data_output.T
2435 dataOut.data_output = dataOut.data_output.T
2317 dataOut.flagNoData = False
2436 dataOut.flagNoData = False
2318 self.__buffer = None
2437 self.__buffer = None
2319
2438
2320 return
2439 return
2321
2440
2322 class EWDriftsEstimation(Operation):
2441 class EWDriftsEstimation(Operation):
2323
2442
2324 def __init__(self):
2443 def __init__(self):
2325 Operation.__init__(self)
2444 Operation.__init__(self)
2326
2445
2327 def __correctValues(self, heiRang, phi, velRadial, SNR):
2446 def __correctValues(self, heiRang, phi, velRadial, SNR):
2328 listPhi = phi.tolist()
2447 listPhi = phi.tolist()
2329 maxid = listPhi.index(max(listPhi))
2448 maxid = listPhi.index(max(listPhi))
2330 minid = listPhi.index(min(listPhi))
2449 minid = listPhi.index(min(listPhi))
2331
2450
2332 rango = range(len(phi))
2451 rango = range(len(phi))
2333 # rango = numpy.delete(rango,maxid)
2452 # rango = numpy.delete(rango,maxid)
2334
2453
2335 heiRang1 = heiRang*math.cos(phi[maxid])
2454 heiRang1 = heiRang*math.cos(phi[maxid])
2336 heiRangAux = heiRang*math.cos(phi[minid])
2455 heiRangAux = heiRang*math.cos(phi[minid])
2337 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2456 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2338 heiRang1 = numpy.delete(heiRang1,indOut)
2457 heiRang1 = numpy.delete(heiRang1,indOut)
2339
2458
2340 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2459 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2341 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2460 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2342
2461
2343 for i in rango:
2462 for i in rango:
2344 x = heiRang*math.cos(phi[i])
2463 x = heiRang*math.cos(phi[i])
2345 y1 = velRadial[i,:]
2464 y1 = velRadial[i,:]
2346 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2465 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2347
2466
2348 x1 = heiRang1
2467 x1 = heiRang1
2349 y11 = f1(x1)
2468 y11 = f1(x1)
2350
2469
2351 y2 = SNR[i,:]
2470 y2 = SNR[i,:]
2352 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2471 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2353 y21 = f2(x1)
2472 y21 = f2(x1)
2354
2473
2355 velRadial1[i,:] = y11
2474 velRadial1[i,:] = y11
2356 SNR1[i,:] = y21
2475 SNR1[i,:] = y21
2357
2476
2358 return heiRang1, velRadial1, SNR1
2477 return heiRang1, velRadial1, SNR1
2359
2478
2360 def run(self, dataOut, zenith, zenithCorrection):
2479 def run(self, dataOut, zenith, zenithCorrection):
2361 heiRang = dataOut.heightList
2480 heiRang = dataOut.heightList
2362 velRadial = dataOut.data_param[:,3,:]
2481 velRadial = dataOut.data_param[:,3,:]
2363 SNR = dataOut.data_SNR
2482 SNR = dataOut.data_SNR
2364
2483
2365 zenith = numpy.array(zenith)
2484 zenith = numpy.array(zenith)
2366 zenith -= zenithCorrection
2485 zenith -= zenithCorrection
2367 zenith *= numpy.pi/180
2486 zenith *= numpy.pi/180
2368
2487
2369 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2488 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2370
2489
2371 alp = zenith[0]
2490 alp = zenith[0]
2372 bet = zenith[1]
2491 bet = zenith[1]
2373
2492
2374 w_w = velRadial1[0,:]
2493 w_w = velRadial1[0,:]
2375 w_e = velRadial1[1,:]
2494 w_e = velRadial1[1,:]
2376
2495
2377 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2496 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2378 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2497 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2379
2498
2380 winds = numpy.vstack((u,w))
2499 winds = numpy.vstack((u,w))
2381
2500
2382 dataOut.heightList = heiRang1
2501 dataOut.heightList = heiRang1
2383 dataOut.data_output = winds
2502 dataOut.data_output = winds
2384 dataOut.data_SNR = SNR1
2503 dataOut.data_SNR = SNR1
2385
2504
2386 dataOut.utctimeInit = dataOut.utctime
2505 dataOut.utctimeInit = dataOut.utctime
2387 dataOut.outputInterval = dataOut.timeInterval
2506 dataOut.outputInterval = dataOut.timeInterval
2388 return
2507 return
2389
2508
2390 #--------------- Non Specular Meteor ----------------
2509 #--------------- Non Specular Meteor ----------------
2391
2510
2392 class NonSpecularMeteorDetection(Operation):
2511 class NonSpecularMeteorDetection(Operation):
2393
2512
2394 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2513 def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2395 data_acf = self.dataOut.data_pre[0]
2514 data_acf = self.dataOut.data_pre[0]
2396 data_ccf = self.dataOut.data_pre[1]
2515 data_ccf = self.dataOut.data_pre[1]
2397
2516
2398 lamb = self.dataOut.C/self.dataOut.frequency
2517 lamb = self.dataOut.C/self.dataOut.frequency
2399 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2518 tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt
2400 paramInterval = self.dataOut.paramInterval
2519 paramInterval = self.dataOut.paramInterval
2401
2520
2402 nChannels = data_acf.shape[0]
2521 nChannels = data_acf.shape[0]
2403 nLags = data_acf.shape[1]
2522 nLags = data_acf.shape[1]
2404 nProfiles = data_acf.shape[2]
2523 nProfiles = data_acf.shape[2]
2405 nHeights = self.dataOut.nHeights
2524 nHeights = self.dataOut.nHeights
2406 nCohInt = self.dataOut.nCohInt
2525 nCohInt = self.dataOut.nCohInt
2407 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2526 sec = numpy.round(nProfiles/self.dataOut.paramInterval)
2408 heightList = self.dataOut.heightList
2527 heightList = self.dataOut.heightList
2409 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2528 ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg
2410 utctime = self.dataOut.utctime
2529 utctime = self.dataOut.utctime
2411
2530
2412 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2531 self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2413
2532
2414 #------------------------ SNR --------------------------------------
2533 #------------------------ SNR --------------------------------------
2415 power = data_acf[:,0,:,:].real
2534 power = data_acf[:,0,:,:].real
2416 noise = numpy.zeros(nChannels)
2535 noise = numpy.zeros(nChannels)
2417 SNR = numpy.zeros(power.shape)
2536 SNR = numpy.zeros(power.shape)
2418 for i in range(nChannels):
2537 for i in range(nChannels):
2419 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2538 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2420 SNR[i] = (power[i]-noise[i])/noise[i]
2539 SNR[i] = (power[i]-noise[i])/noise[i]
2421 SNRm = numpy.nanmean(SNR, axis = 0)
2540 SNRm = numpy.nanmean(SNR, axis = 0)
2422 SNRdB = 10*numpy.log10(SNR)
2541 SNRdB = 10*numpy.log10(SNR)
2423
2542
2424 if mode == 'SA':
2543 if mode == 'SA':
2425 nPairs = data_ccf.shape[0]
2544 nPairs = data_ccf.shape[0]
2426 #---------------------- Coherence and Phase --------------------------
2545 #---------------------- Coherence and Phase --------------------------
2427 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2546 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2428 # phase1 = numpy.copy(phase)
2547 # phase1 = numpy.copy(phase)
2429 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2548 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2430
2549
2431 for p in range(nPairs):
2550 for p in range(nPairs):
2432 ch0 = self.dataOut.groupList[p][0]
2551 ch0 = self.dataOut.groupList[p][0]
2433 ch1 = self.dataOut.groupList[p][1]
2552 ch1 = self.dataOut.groupList[p][1]
2434 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2553 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2435 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2554 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2436 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2555 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2437 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2556 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2438 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2557 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2439 coh = numpy.nanmax(coh1, axis = 0)
2558 coh = numpy.nanmax(coh1, axis = 0)
2440 # struc = numpy.ones((5,1))
2559 # struc = numpy.ones((5,1))
2441 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2560 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2442 #---------------------- Radial Velocity ----------------------------
2561 #---------------------- Radial Velocity ----------------------------
2443 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2562 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2444 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2563 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2445
2564
2446 if allData:
2565 if allData:
2447 boolMetFin = ~numpy.isnan(SNRm)
2566 boolMetFin = ~numpy.isnan(SNRm)
2448 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2567 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2449 else:
2568 else:
2450 #------------------------ Meteor mask ---------------------------------
2569 #------------------------ Meteor mask ---------------------------------
2451 # #SNR mask
2570 # #SNR mask
2452 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2571 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2453 #
2572 #
2454 # #Erase small objects
2573 # #Erase small objects
2455 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2574 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2456 #
2575 #
2457 # auxEEJ = numpy.sum(boolMet1,axis=0)
2576 # auxEEJ = numpy.sum(boolMet1,axis=0)
2458 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2577 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2459 # indEEJ = numpy.where(indOver)[0]
2578 # indEEJ = numpy.where(indOver)[0]
2460 # indNEEJ = numpy.where(~indOver)[0]
2579 # indNEEJ = numpy.where(~indOver)[0]
2461 #
2580 #
2462 # boolMetFin = boolMet1
2581 # boolMetFin = boolMet1
2463 #
2582 #
2464 # if indEEJ.size > 0:
2583 # if indEEJ.size > 0:
2465 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2584 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2466 #
2585 #
2467 # boolMet2 = coh > cohThresh
2586 # boolMet2 = coh > cohThresh
2468 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2587 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2469 #
2588 #
2470 # #Final Meteor mask
2589 # #Final Meteor mask
2471 # boolMetFin = boolMet1|boolMet2
2590 # boolMetFin = boolMet1|boolMet2
2472
2591
2473 #Coherence mask
2592 #Coherence mask
2474 boolMet1 = coh > 0.75
2593 boolMet1 = coh > 0.75
2475 struc = numpy.ones((30,1))
2594 struc = numpy.ones((30,1))
2476 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2595 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2477
2596
2478 #Derivative mask
2597 #Derivative mask
2479 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2598 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2480 boolMet2 = derPhase < 0.2
2599 boolMet2 = derPhase < 0.2
2481 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2600 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2482 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2601 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2483 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2602 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2484 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2603 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2485 # #Final mask
2604 # #Final mask
2486 # boolMetFin = boolMet2
2605 # boolMetFin = boolMet2
2487 boolMetFin = boolMet1&boolMet2
2606 boolMetFin = boolMet1&boolMet2
2488 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2607 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2489 #Creating data_param
2608 #Creating data_param
2490 coordMet = numpy.where(boolMetFin)
2609 coordMet = numpy.where(boolMetFin)
2491
2610
2492 tmet = coordMet[0]
2611 tmet = coordMet[0]
2493 hmet = coordMet[1]
2612 hmet = coordMet[1]
2494
2613
2495 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2614 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2496 data_param[:,0] = utctime
2615 data_param[:,0] = utctime
2497 data_param[:,1] = tmet
2616 data_param[:,1] = tmet
2498 data_param[:,2] = hmet
2617 data_param[:,2] = hmet
2499 data_param[:,3] = SNRm[tmet,hmet]
2618 data_param[:,3] = SNRm[tmet,hmet]
2500 data_param[:,4] = velRad[tmet,hmet]
2619 data_param[:,4] = velRad[tmet,hmet]
2501 data_param[:,5] = coh[tmet,hmet]
2620 data_param[:,5] = coh[tmet,hmet]
2502 data_param[:,6:] = phase[:,tmet,hmet].T
2621 data_param[:,6:] = phase[:,tmet,hmet].T
2503
2622
2504 elif mode == 'DBS':
2623 elif mode == 'DBS':
2505 self.dataOut.groupList = numpy.arange(nChannels)
2624 self.dataOut.groupList = numpy.arange(nChannels)
2506
2625
2507 #Radial Velocities
2626 #Radial Velocities
2508 # phase = numpy.angle(data_acf[:,1,:,:])
2627 # phase = numpy.angle(data_acf[:,1,:,:])
2509 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2628 phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2510 velRad = phase*lamb/(4*numpy.pi*tSamp)
2629 velRad = phase*lamb/(4*numpy.pi*tSamp)
2511
2630
2512 #Spectral width
2631 #Spectral width
2513 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2632 acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2514 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2633 acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2515
2634
2516 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2635 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2517 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2636 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2518 if allData:
2637 if allData:
2519 boolMetFin = ~numpy.isnan(SNRdB)
2638 boolMetFin = ~numpy.isnan(SNRdB)
2520 else:
2639 else:
2521 #SNR
2640 #SNR
2522 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2641 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2523 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2642 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2524
2643
2525 #Radial velocity
2644 #Radial velocity
2526 boolMet2 = numpy.abs(velRad) < 30
2645 boolMet2 = numpy.abs(velRad) < 30
2527 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2646 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2528
2647
2529 #Spectral Width
2648 #Spectral Width
2530 boolMet3 = spcWidth < 30
2649 boolMet3 = spcWidth < 30
2531 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2650 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2532 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2651 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2533 boolMetFin = boolMet1&boolMet2&boolMet3
2652 boolMetFin = boolMet1&boolMet2&boolMet3
2534
2653
2535 #Creating data_param
2654 #Creating data_param
2536 coordMet = numpy.where(boolMetFin)
2655 coordMet = numpy.where(boolMetFin)
2537
2656
2538 cmet = coordMet[0]
2657 cmet = coordMet[0]
2539 tmet = coordMet[1]
2658 tmet = coordMet[1]
2540 hmet = coordMet[2]
2659 hmet = coordMet[2]
2541
2660
2542 data_param = numpy.zeros((tmet.size, 7))
2661 data_param = numpy.zeros((tmet.size, 7))
2543 data_param[:,0] = utctime
2662 data_param[:,0] = utctime
2544 data_param[:,1] = cmet
2663 data_param[:,1] = cmet
2545 data_param[:,2] = tmet
2664 data_param[:,2] = tmet
2546 data_param[:,3] = hmet
2665 data_param[:,3] = hmet
2547 data_param[:,4] = SNR[cmet,tmet,hmet].T
2666 data_param[:,4] = SNR[cmet,tmet,hmet].T
2548 data_param[:,5] = velRad[cmet,tmet,hmet].T
2667 data_param[:,5] = velRad[cmet,tmet,hmet].T
2549 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2668 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2550
2669
2551 # self.dataOut.data_param = data_int
2670 # self.dataOut.data_param = data_int
2552 if len(data_param) == 0:
2671 if len(data_param) == 0:
2553 self.dataOut.flagNoData = True
2672 self.dataOut.flagNoData = True
2554 else:
2673 else:
2555 self.dataOut.data_param = data_param
2674 self.dataOut.data_param = data_param
2556
2675
2557 def __erase_small(self, binArray, threshX, threshY):
2676 def __erase_small(self, binArray, threshX, threshY):
2558 labarray, numfeat = ndimage.measurements.label(binArray)
2677 labarray, numfeat = ndimage.measurements.label(binArray)
2559 binArray1 = numpy.copy(binArray)
2678 binArray1 = numpy.copy(binArray)
2560
2679
2561 for i in range(1,numfeat + 1):
2680 for i in range(1,numfeat + 1):
2562 auxBin = (labarray==i)
2681 auxBin = (labarray==i)
2563 auxSize = auxBin.sum()
2682 auxSize = auxBin.sum()
2564
2683
2565 x,y = numpy.where(auxBin)
2684 x,y = numpy.where(auxBin)
2566 widthX = x.max() - x.min()
2685 widthX = x.max() - x.min()
2567 widthY = y.max() - y.min()
2686 widthY = y.max() - y.min()
2568
2687
2569 #width X: 3 seg -> 12.5*3
2688 #width X: 3 seg -> 12.5*3
2570 #width Y:
2689 #width Y:
2571
2690
2572 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2691 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2573 binArray1[auxBin] = False
2692 binArray1[auxBin] = False
2574
2693
2575 return binArray1
2694 return binArray1
2576
2695
2577 #--------------- Specular Meteor ----------------
2696 #--------------- Specular Meteor ----------------
2578
2697
2579 class SMDetection(Operation):
2698 class SMDetection(Operation):
2580 '''
2699 '''
2581 Function DetectMeteors()
2700 Function DetectMeteors()
2582 Project developed with paper:
2701 Project developed with paper:
2583 HOLDSWORTH ET AL. 2004
2702 HOLDSWORTH ET AL. 2004
2584
2703
2585 Input:
2704 Input:
2586 self.dataOut.data_pre
2705 self.dataOut.data_pre
2587
2706
2588 centerReceiverIndex: From the channels, which is the center receiver
2707 centerReceiverIndex: From the channels, which is the center receiver
2589
2708
2590 hei_ref: Height reference for the Beacon signal extraction
2709 hei_ref: Height reference for the Beacon signal extraction
2591 tauindex:
2710 tauindex:
2592 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2711 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2593
2712
2594 cohDetection: Whether to user Coherent detection or not
2713 cohDetection: Whether to user Coherent detection or not
2595 cohDet_timeStep: Coherent Detection calculation time step
2714 cohDet_timeStep: Coherent Detection calculation time step
2596 cohDet_thresh: Coherent Detection phase threshold to correct phases
2715 cohDet_thresh: Coherent Detection phase threshold to correct phases
2597
2716
2598 noise_timeStep: Noise calculation time step
2717 noise_timeStep: Noise calculation time step
2599 noise_multiple: Noise multiple to define signal threshold
2718 noise_multiple: Noise multiple to define signal threshold
2600
2719
2601 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2720 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2602 multDet_rangeLimit: Multiple Detection Removal range limit in km
2721 multDet_rangeLimit: Multiple Detection Removal range limit in km
2603
2722
2604 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2723 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2605 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2724 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2606
2725
2607 hmin: Minimum Height of the meteor to use it in the further wind estimations
2726 hmin: Minimum Height of the meteor to use it in the further wind estimations
2608 hmax: Maximum Height of the meteor to use it in the further wind estimations
2727 hmax: Maximum Height of the meteor to use it in the further wind estimations
2609 azimuth: Azimuth angle correction
2728 azimuth: Azimuth angle correction
2610
2729
2611 Affected:
2730 Affected:
2612 self.dataOut.data_param
2731 self.dataOut.data_param
2613
2732
2614 Rejection Criteria (Errors):
2733 Rejection Criteria (Errors):
2615 0: No error; analysis OK
2734 0: No error; analysis OK
2616 1: SNR < SNR threshold
2735 1: SNR < SNR threshold
2617 2: angle of arrival (AOA) ambiguously determined
2736 2: angle of arrival (AOA) ambiguously determined
2618 3: AOA estimate not feasible
2737 3: AOA estimate not feasible
2619 4: Large difference in AOAs obtained from different antenna baselines
2738 4: Large difference in AOAs obtained from different antenna baselines
2620 5: echo at start or end of time series
2739 5: echo at start or end of time series
2621 6: echo less than 5 examples long; too short for analysis
2740 6: echo less than 5 examples long; too short for analysis
2622 7: echo rise exceeds 0.3s
2741 7: echo rise exceeds 0.3s
2623 8: echo decay time less than twice rise time
2742 8: echo decay time less than twice rise time
2624 9: large power level before echo
2743 9: large power level before echo
2625 10: large power level after echo
2744 10: large power level after echo
2626 11: poor fit to amplitude for estimation of decay time
2745 11: poor fit to amplitude for estimation of decay time
2627 12: poor fit to CCF phase variation for estimation of radial drift velocity
2746 12: poor fit to CCF phase variation for estimation of radial drift velocity
2628 13: height unresolvable echo: not valid height within 70 to 110 km
2747 13: height unresolvable echo: not valid height within 70 to 110 km
2629 14: height ambiguous echo: more then one possible height within 70 to 110 km
2748 14: height ambiguous echo: more then one possible height within 70 to 110 km
2630 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2749 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2631 16: oscilatory echo, indicating event most likely not an underdense echo
2750 16: oscilatory echo, indicating event most likely not an underdense echo
2632
2751
2633 17: phase difference in meteor Reestimation
2752 17: phase difference in meteor Reestimation
2634
2753
2635 Data Storage:
2754 Data Storage:
2636 Meteors for Wind Estimation (8):
2755 Meteors for Wind Estimation (8):
2637 Utc Time | Range Height
2756 Utc Time | Range Height
2638 Azimuth Zenith errorCosDir
2757 Azimuth Zenith errorCosDir
2639 VelRad errorVelRad
2758 VelRad errorVelRad
2640 Phase0 Phase1 Phase2 Phase3
2759 Phase0 Phase1 Phase2 Phase3
2641 TypeError
2760 TypeError
2642
2761
2643 '''
2762 '''
2644
2763
2645 def run(self, dataOut, hei_ref = None, tauindex = 0,
2764 def run(self, dataOut, hei_ref = None, tauindex = 0,
2646 phaseOffsets = None,
2765 phaseOffsets = None,
2647 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2766 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2648 noise_timeStep = 4, noise_multiple = 4,
2767 noise_timeStep = 4, noise_multiple = 4,
2649 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2768 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2650 phaseThresh = 20, SNRThresh = 5,
2769 phaseThresh = 20, SNRThresh = 5,
2651 hmin = 50, hmax=150, azimuth = 0,
2770 hmin = 50, hmax=150, azimuth = 0,
2652 channelPositions = None) :
2771 channelPositions = None) :
2653
2772
2654
2773
2655 #Getting Pairslist
2774 #Getting Pairslist
2656 if channelPositions == None:
2775 if channelPositions == None:
2657 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2776 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2658 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2777 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2659 meteorOps = SMOperations()
2778 meteorOps = SMOperations()
2660 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2779 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2661 heiRang = dataOut.getHeiRange()
2780 heiRang = dataOut.getHeiRange()
2662 #Get Beacon signal - No Beacon signal anymore
2781 #Get Beacon signal - No Beacon signal anymore
2663 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2782 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2664 #
2783 #
2665 # if hei_ref != None:
2784 # if hei_ref != None:
2666 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2785 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2667 #
2786 #
2668
2787
2669
2788
2670 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2789 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2671 # see if the user put in pre defined phase shifts
2790 # see if the user put in pre defined phase shifts
2672 voltsPShift = dataOut.data_pre.copy()
2791 voltsPShift = dataOut.data_pre.copy()
2673
2792
2674 # if predefinedPhaseShifts != None:
2793 # if predefinedPhaseShifts != None:
2675 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2794 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2676 #
2795 #
2677 # # elif beaconPhaseShifts:
2796 # # elif beaconPhaseShifts:
2678 # # #get hardware phase shifts using beacon signal
2797 # # #get hardware phase shifts using beacon signal
2679 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2798 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2680 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2799 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2681 #
2800 #
2682 # else:
2801 # else:
2683 # hardwarePhaseShifts = numpy.zeros(5)
2802 # hardwarePhaseShifts = numpy.zeros(5)
2684 #
2803 #
2685 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2804 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2686 # for i in range(self.dataOut.data_pre.shape[0]):
2805 # for i in range(self.dataOut.data_pre.shape[0]):
2687 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2806 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2688
2807
2689 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2808 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2690
2809
2691 #Remove DC
2810 #Remove DC
2692 voltsDC = numpy.mean(voltsPShift,1)
2811 voltsDC = numpy.mean(voltsPShift,1)
2693 voltsDC = numpy.mean(voltsDC,1)
2812 voltsDC = numpy.mean(voltsDC,1)
2694 for i in range(voltsDC.shape[0]):
2813 for i in range(voltsDC.shape[0]):
2695 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2814 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2696
2815
2697 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2816 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2698 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2817 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2699
2818
2700 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2819 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2701 #Coherent Detection
2820 #Coherent Detection
2702 if cohDetection:
2821 if cohDetection:
2703 #use coherent detection to get the net power
2822 #use coherent detection to get the net power
2704 cohDet_thresh = cohDet_thresh*numpy.pi/180
2823 cohDet_thresh = cohDet_thresh*numpy.pi/180
2705 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2824 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2706
2825
2707 #Non-coherent detection!
2826 #Non-coherent detection!
2708 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2827 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2709 #********** END OF COH/NON-COH POWER CALCULATION**********************
2828 #********** END OF COH/NON-COH POWER CALCULATION**********************
2710
2829
2711 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2830 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2712 #Get noise
2831 #Get noise
2713 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2832 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2714 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2833 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2715 #Get signal threshold
2834 #Get signal threshold
2716 signalThresh = noise_multiple*noise
2835 signalThresh = noise_multiple*noise
2717 #Meteor echoes detection
2836 #Meteor echoes detection
2718 listMeteors = self.__findMeteors(powerNet, signalThresh)
2837 listMeteors = self.__findMeteors(powerNet, signalThresh)
2719 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2838 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2720
2839
2721 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2840 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2722 #Parameters
2841 #Parameters
2723 heiRange = dataOut.getHeiRange()
2842 heiRange = dataOut.getHeiRange()
2724 rangeInterval = heiRange[1] - heiRange[0]
2843 rangeInterval = heiRange[1] - heiRange[0]
2725 rangeLimit = multDet_rangeLimit/rangeInterval
2844 rangeLimit = multDet_rangeLimit/rangeInterval
2726 timeLimit = multDet_timeLimit/dataOut.timeInterval
2845 timeLimit = multDet_timeLimit/dataOut.timeInterval
2727 #Multiple detection removals
2846 #Multiple detection removals
2728 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2847 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2729 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2848 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2730
2849
2731 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2850 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2732 #Parameters
2851 #Parameters
2733 phaseThresh = phaseThresh*numpy.pi/180
2852 phaseThresh = phaseThresh*numpy.pi/180
2734 thresh = [phaseThresh, noise_multiple, SNRThresh]
2853 thresh = [phaseThresh, noise_multiple, SNRThresh]
2735 #Meteor reestimation (Errors N 1, 6, 12, 17)
2854 #Meteor reestimation (Errors N 1, 6, 12, 17)
2736 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2855 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2737 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2856 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2738 #Estimation of decay times (Errors N 7, 8, 11)
2857 #Estimation of decay times (Errors N 7, 8, 11)
2739 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2858 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2740 #******************* END OF METEOR REESTIMATION *******************
2859 #******************* END OF METEOR REESTIMATION *******************
2741
2860
2742 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2861 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2743 #Calculating Radial Velocity (Error N 15)
2862 #Calculating Radial Velocity (Error N 15)
2744 radialStdThresh = 10
2863 radialStdThresh = 10
2745 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2864 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2746
2865
2747 if len(listMeteors4) > 0:
2866 if len(listMeteors4) > 0:
2748 #Setting New Array
2867 #Setting New Array
2749 date = dataOut.utctime
2868 date = dataOut.utctime
2750 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2869 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2751
2870
2752 #Correcting phase offset
2871 #Correcting phase offset
2753 if phaseOffsets != None:
2872 if phaseOffsets != None:
2754 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2873 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2755 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2874 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2756
2875
2757 #Second Pairslist
2876 #Second Pairslist
2758 pairsList = []
2877 pairsList = []
2759 pairx = (0,1)
2878 pairx = (0,1)
2760 pairy = (2,3)
2879 pairy = (2,3)
2761 pairsList.append(pairx)
2880 pairsList.append(pairx)
2762 pairsList.append(pairy)
2881 pairsList.append(pairy)
2763
2882
2764 jph = numpy.array([0,0,0,0])
2883 jph = numpy.array([0,0,0,0])
2765 h = (hmin,hmax)
2884 h = (hmin,hmax)
2766 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2885 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2767
2886
2768 # #Calculate AOA (Error N 3, 4)
2887 # #Calculate AOA (Error N 3, 4)
2769 # #JONES ET AL. 1998
2888 # #JONES ET AL. 1998
2770 # error = arrayParameters[:,-1]
2889 # error = arrayParameters[:,-1]
2771 # AOAthresh = numpy.pi/8
2890 # AOAthresh = numpy.pi/8
2772 # phases = -arrayParameters[:,9:13]
2891 # phases = -arrayParameters[:,9:13]
2773 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2892 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2774 #
2893 #
2775 # #Calculate Heights (Error N 13 and 14)
2894 # #Calculate Heights (Error N 13 and 14)
2776 # error = arrayParameters[:,-1]
2895 # error = arrayParameters[:,-1]
2777 # Ranges = arrayParameters[:,2]
2896 # Ranges = arrayParameters[:,2]
2778 # zenith = arrayParameters[:,5]
2897 # zenith = arrayParameters[:,5]
2779 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2898 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2780 # error = arrayParameters[:,-1]
2899 # error = arrayParameters[:,-1]
2781 #********************* END OF PARAMETERS CALCULATION **************************
2900 #********************* END OF PARAMETERS CALCULATION **************************
2782
2901
2783 #***************************+ PASS DATA TO NEXT STEP **********************
2902 #***************************+ PASS DATA TO NEXT STEP **********************
2784 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2903 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2785 dataOut.data_param = arrayParameters
2904 dataOut.data_param = arrayParameters
2786
2905
2787 if arrayParameters == None:
2906 if arrayParameters == None:
2788 dataOut.flagNoData = True
2907 dataOut.flagNoData = True
2789 else:
2908 else:
2790 dataOut.flagNoData = True
2909 dataOut.flagNoData = True
2791
2910
2792 return
2911 return
2793
2912
2794 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2913 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2795
2914
2796 minIndex = min(newheis[0])
2915 minIndex = min(newheis[0])
2797 maxIndex = max(newheis[0])
2916 maxIndex = max(newheis[0])
2798
2917
2799 voltage = voltage0[:,:,minIndex:maxIndex+1]
2918 voltage = voltage0[:,:,minIndex:maxIndex+1]
2800 nLength = voltage.shape[1]/n
2919 nLength = voltage.shape[1]/n
2801 nMin = 0
2920 nMin = 0
2802 nMax = 0
2921 nMax = 0
2803 phaseOffset = numpy.zeros((len(pairslist),n))
2922 phaseOffset = numpy.zeros((len(pairslist),n))
2804
2923
2805 for i in range(n):
2924 for i in range(n):
2806 nMax += nLength
2925 nMax += nLength
2807 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2926 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2808 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2927 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2809 phaseOffset[:,i] = phaseCCF.transpose()
2928 phaseOffset[:,i] = phaseCCF.transpose()
2810 nMin = nMax
2929 nMin = nMax
2811 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2930 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2812
2931
2813 #Remove Outliers
2932 #Remove Outliers
2814 factor = 2
2933 factor = 2
2815 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2934 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2816 dw = numpy.std(wt,axis = 1)
2935 dw = numpy.std(wt,axis = 1)
2817 dw = dw.reshape((dw.size,1))
2936 dw = dw.reshape((dw.size,1))
2818 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2937 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2819 phaseOffset[ind] = numpy.nan
2938 phaseOffset[ind] = numpy.nan
2820 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2939 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2821
2940
2822 return phaseOffset
2941 return phaseOffset
2823
2942
2824 def __shiftPhase(self, data, phaseShift):
2943 def __shiftPhase(self, data, phaseShift):
2825 #this will shift the phase of a complex number
2944 #this will shift the phase of a complex number
2826 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2945 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2827 return dataShifted
2946 return dataShifted
2828
2947
2829 def __estimatePhaseDifference(self, array, pairslist):
2948 def __estimatePhaseDifference(self, array, pairslist):
2830 nChannel = array.shape[0]
2949 nChannel = array.shape[0]
2831 nHeights = array.shape[2]
2950 nHeights = array.shape[2]
2832 numPairs = len(pairslist)
2951 numPairs = len(pairslist)
2833 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2952 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2834 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2953 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2835
2954
2836 #Correct phases
2955 #Correct phases
2837 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2956 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2838 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2957 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2839
2958
2840 if indDer[0].shape[0] > 0:
2959 if indDer[0].shape[0] > 0:
2841 for i in range(indDer[0].shape[0]):
2960 for i in range(indDer[0].shape[0]):
2842 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2961 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2843 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2962 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2844
2963
2845 # for j in range(numSides):
2964 # for j in range(numSides):
2846 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2965 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2847 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2966 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2848 #
2967 #
2849 #Linear
2968 #Linear
2850 phaseInt = numpy.zeros((numPairs,1))
2969 phaseInt = numpy.zeros((numPairs,1))
2851 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2970 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2852 for j in range(numPairs):
2971 for j in range(numPairs):
2853 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2972 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2854 phaseInt[j] = fit[1]
2973 phaseInt[j] = fit[1]
2855 #Phase Differences
2974 #Phase Differences
2856 phaseDiff = phaseInt - phaseCCF[:,2,:]
2975 phaseDiff = phaseInt - phaseCCF[:,2,:]
2857 phaseArrival = phaseInt.reshape(phaseInt.size)
2976 phaseArrival = phaseInt.reshape(phaseInt.size)
2858
2977
2859 #Dealias
2978 #Dealias
2860 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2979 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2861 # indAlias = numpy.where(phaseArrival > numpy.pi)
2980 # indAlias = numpy.where(phaseArrival > numpy.pi)
2862 # phaseArrival[indAlias] -= 2*numpy.pi
2981 # phaseArrival[indAlias] -= 2*numpy.pi
2863 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2982 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2864 # phaseArrival[indAlias] += 2*numpy.pi
2983 # phaseArrival[indAlias] += 2*numpy.pi
2865
2984
2866 return phaseDiff, phaseArrival
2985 return phaseDiff, phaseArrival
2867
2986
2868 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
2987 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
2869 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
2988 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
2870 #find the phase shifts of each channel over 1 second intervals
2989 #find the phase shifts of each channel over 1 second intervals
2871 #only look at ranges below the beacon signal
2990 #only look at ranges below the beacon signal
2872 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2991 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2873 numBlocks = int(volts.shape[1]/numProfPerBlock)
2992 numBlocks = int(volts.shape[1]/numProfPerBlock)
2874 numHeights = volts.shape[2]
2993 numHeights = volts.shape[2]
2875 nChannel = volts.shape[0]
2994 nChannel = volts.shape[0]
2876 voltsCohDet = volts.copy()
2995 voltsCohDet = volts.copy()
2877
2996
2878 pairsarray = numpy.array(pairslist)
2997 pairsarray = numpy.array(pairslist)
2879 indSides = pairsarray[:,1]
2998 indSides = pairsarray[:,1]
2880 # indSides = numpy.array(range(nChannel))
2999 # indSides = numpy.array(range(nChannel))
2881 # indSides = numpy.delete(indSides, indCenter)
3000 # indSides = numpy.delete(indSides, indCenter)
2882 #
3001 #
2883 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
3002 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
2884 listBlocks = numpy.array_split(volts, numBlocks, 1)
3003 listBlocks = numpy.array_split(volts, numBlocks, 1)
2885
3004
2886 startInd = 0
3005 startInd = 0
2887 endInd = 0
3006 endInd = 0
2888
3007
2889 for i in range(numBlocks):
3008 for i in range(numBlocks):
2890 startInd = endInd
3009 startInd = endInd
2891 endInd = endInd + listBlocks[i].shape[1]
3010 endInd = endInd + listBlocks[i].shape[1]
2892
3011
2893 arrayBlock = listBlocks[i]
3012 arrayBlock = listBlocks[i]
2894 # arrayBlockCenter = listCenter[i]
3013 # arrayBlockCenter = listCenter[i]
2895
3014
2896 #Estimate the Phase Difference
3015 #Estimate the Phase Difference
2897 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
3016 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
2898 #Phase Difference RMS
3017 #Phase Difference RMS
2899 arrayPhaseRMS = numpy.abs(phaseDiff)
3018 arrayPhaseRMS = numpy.abs(phaseDiff)
2900 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
3019 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
2901 indPhase = numpy.where(phaseRMSaux==4)
3020 indPhase = numpy.where(phaseRMSaux==4)
2902 #Shifting
3021 #Shifting
2903 if indPhase[0].shape[0] > 0:
3022 if indPhase[0].shape[0] > 0:
2904 for j in range(indSides.size):
3023 for j in range(indSides.size):
2905 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
3024 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
2906 voltsCohDet[:,startInd:endInd,:] = arrayBlock
3025 voltsCohDet[:,startInd:endInd,:] = arrayBlock
2907
3026
2908 return voltsCohDet
3027 return voltsCohDet
2909
3028
2910 def __calculateCCF(self, volts, pairslist ,laglist):
3029 def __calculateCCF(self, volts, pairslist ,laglist):
2911
3030
2912 nHeights = volts.shape[2]
3031 nHeights = volts.shape[2]
2913 nPoints = volts.shape[1]
3032 nPoints = volts.shape[1]
2914 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
3033 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
2915
3034
2916 for i in range(len(pairslist)):
3035 for i in range(len(pairslist)):
2917 volts1 = volts[pairslist[i][0]]
3036 volts1 = volts[pairslist[i][0]]
2918 volts2 = volts[pairslist[i][1]]
3037 volts2 = volts[pairslist[i][1]]
2919
3038
2920 for t in range(len(laglist)):
3039 for t in range(len(laglist)):
2921 idxT = laglist[t]
3040 idxT = laglist[t]
2922 if idxT >= 0:
3041 if idxT >= 0:
2923 vStacked = numpy.vstack((volts2[idxT:,:],
3042 vStacked = numpy.vstack((volts2[idxT:,:],
2924 numpy.zeros((idxT, nHeights),dtype='complex')))
3043 numpy.zeros((idxT, nHeights),dtype='complex')))
2925 else:
3044 else:
2926 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
3045 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
2927 volts2[:(nPoints + idxT),:]))
3046 volts2[:(nPoints + idxT),:]))
2928 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
3047 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
2929
3048
2930 vStacked = None
3049 vStacked = None
2931 return voltsCCF
3050 return voltsCCF
2932
3051
2933 def __getNoise(self, power, timeSegment, timeInterval):
3052 def __getNoise(self, power, timeSegment, timeInterval):
2934 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
3053 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2935 numBlocks = int(power.shape[0]/numProfPerBlock)
3054 numBlocks = int(power.shape[0]/numProfPerBlock)
2936 numHeights = power.shape[1]
3055 numHeights = power.shape[1]
2937
3056
2938 listPower = numpy.array_split(power, numBlocks, 0)
3057 listPower = numpy.array_split(power, numBlocks, 0)
2939 noise = numpy.zeros((power.shape[0], power.shape[1]))
3058 noise = numpy.zeros((power.shape[0], power.shape[1]))
2940 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
3059 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
2941
3060
2942 startInd = 0
3061 startInd = 0
2943 endInd = 0
3062 endInd = 0
2944
3063
2945 for i in range(numBlocks): #split por canal
3064 for i in range(numBlocks): #split por canal
2946 startInd = endInd
3065 startInd = endInd
2947 endInd = endInd + listPower[i].shape[0]
3066 endInd = endInd + listPower[i].shape[0]
2948
3067
2949 arrayBlock = listPower[i]
3068 arrayBlock = listPower[i]
2950 noiseAux = numpy.mean(arrayBlock, 0)
3069 noiseAux = numpy.mean(arrayBlock, 0)
2951 # noiseAux = numpy.median(noiseAux)
3070 # noiseAux = numpy.median(noiseAux)
2952 # noiseAux = numpy.mean(arrayBlock)
3071 # noiseAux = numpy.mean(arrayBlock)
2953 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
3072 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
2954
3073
2955 noiseAux1 = numpy.mean(arrayBlock)
3074 noiseAux1 = numpy.mean(arrayBlock)
2956 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
3075 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
2957
3076
2958 return noise, noise1
3077 return noise, noise1
2959
3078
2960 def __findMeteors(self, power, thresh):
3079 def __findMeteors(self, power, thresh):
2961 nProf = power.shape[0]
3080 nProf = power.shape[0]
2962 nHeights = power.shape[1]
3081 nHeights = power.shape[1]
2963 listMeteors = []
3082 listMeteors = []
2964
3083
2965 for i in range(nHeights):
3084 for i in range(nHeights):
2966 powerAux = power[:,i]
3085 powerAux = power[:,i]
2967 threshAux = thresh[:,i]
3086 threshAux = thresh[:,i]
2968
3087
2969 indUPthresh = numpy.where(powerAux > threshAux)[0]
3088 indUPthresh = numpy.where(powerAux > threshAux)[0]
2970 indDNthresh = numpy.where(powerAux <= threshAux)[0]
3089 indDNthresh = numpy.where(powerAux <= threshAux)[0]
2971
3090
2972 j = 0
3091 j = 0
2973
3092
2974 while (j < indUPthresh.size - 2):
3093 while (j < indUPthresh.size - 2):
2975 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
3094 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
2976 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
3095 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
2977 indDNthresh = indDNthresh[indDNAux]
3096 indDNthresh = indDNthresh[indDNAux]
2978
3097
2979 if (indDNthresh.size > 0):
3098 if (indDNthresh.size > 0):
2980 indEnd = indDNthresh[0] - 1
3099 indEnd = indDNthresh[0] - 1
2981 indInit = indUPthresh[j]
3100 indInit = indUPthresh[j]
2982
3101
2983 meteor = powerAux[indInit:indEnd + 1]
3102 meteor = powerAux[indInit:indEnd + 1]
2984 indPeak = meteor.argmax() + indInit
3103 indPeak = meteor.argmax() + indInit
2985 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
3104 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
2986
3105
2987 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
3106 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
2988 j = numpy.where(indUPthresh == indEnd)[0] + 1
3107 j = numpy.where(indUPthresh == indEnd)[0] + 1
2989 else: j+=1
3108 else: j+=1
2990 else: j+=1
3109 else: j+=1
2991
3110
2992 return listMeteors
3111 return listMeteors
2993
3112
2994 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
3113 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
2995
3114
2996 arrayMeteors = numpy.asarray(listMeteors)
3115 arrayMeteors = numpy.asarray(listMeteors)
2997 listMeteors1 = []
3116 listMeteors1 = []
2998
3117
2999 while arrayMeteors.shape[0] > 0:
3118 while arrayMeteors.shape[0] > 0:
3000 FLAs = arrayMeteors[:,4]
3119 FLAs = arrayMeteors[:,4]
3001 maxFLA = FLAs.argmax()
3120 maxFLA = FLAs.argmax()
3002 listMeteors1.append(arrayMeteors[maxFLA,:])
3121 listMeteors1.append(arrayMeteors[maxFLA,:])
3003
3122
3004 MeteorInitTime = arrayMeteors[maxFLA,1]
3123 MeteorInitTime = arrayMeteors[maxFLA,1]
3005 MeteorEndTime = arrayMeteors[maxFLA,3]
3124 MeteorEndTime = arrayMeteors[maxFLA,3]
3006 MeteorHeight = arrayMeteors[maxFLA,0]
3125 MeteorHeight = arrayMeteors[maxFLA,0]
3007
3126
3008 #Check neighborhood
3127 #Check neighborhood
3009 maxHeightIndex = MeteorHeight + rangeLimit
3128 maxHeightIndex = MeteorHeight + rangeLimit
3010 minHeightIndex = MeteorHeight - rangeLimit
3129 minHeightIndex = MeteorHeight - rangeLimit
3011 minTimeIndex = MeteorInitTime - timeLimit
3130 minTimeIndex = MeteorInitTime - timeLimit
3012 maxTimeIndex = MeteorEndTime + timeLimit
3131 maxTimeIndex = MeteorEndTime + timeLimit
3013
3132
3014 #Check Heights
3133 #Check Heights
3015 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3134 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
3016 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3135 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
3017 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3136 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
3018
3137
3019 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3138 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
3020
3139
3021 return listMeteors1
3140 return listMeteors1
3022
3141
3023 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3142 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
3024 numHeights = volts.shape[2]
3143 numHeights = volts.shape[2]
3025 nChannel = volts.shape[0]
3144 nChannel = volts.shape[0]
3026
3145
3027 thresholdPhase = thresh[0]
3146 thresholdPhase = thresh[0]
3028 thresholdNoise = thresh[1]
3147 thresholdNoise = thresh[1]
3029 thresholdDB = float(thresh[2])
3148 thresholdDB = float(thresh[2])
3030
3149
3031 thresholdDB1 = 10**(thresholdDB/10)
3150 thresholdDB1 = 10**(thresholdDB/10)
3032 pairsarray = numpy.array(pairslist)
3151 pairsarray = numpy.array(pairslist)
3033 indSides = pairsarray[:,1]
3152 indSides = pairsarray[:,1]
3034
3153
3035 pairslist1 = list(pairslist)
3154 pairslist1 = list(pairslist)
3036 pairslist1.append((0,1))
3155 pairslist1.append((0,1))
3037 pairslist1.append((3,4))
3156 pairslist1.append((3,4))
3038
3157
3039 listMeteors1 = []
3158 listMeteors1 = []
3040 listPowerSeries = []
3159 listPowerSeries = []
3041 listVoltageSeries = []
3160 listVoltageSeries = []
3042 #volts has the war data
3161 #volts has the war data
3043
3162
3044 if frequency == 30e6:
3163 if frequency == 30e6:
3045 timeLag = 45*10**-3
3164 timeLag = 45*10**-3
3046 else:
3165 else:
3047 timeLag = 15*10**-3
3166 timeLag = 15*10**-3
3048 lag = numpy.ceil(timeLag/timeInterval)
3167 lag = numpy.ceil(timeLag/timeInterval)
3049
3168
3050 for i in range(len(listMeteors)):
3169 for i in range(len(listMeteors)):
3051
3170
3052 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3171 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3053 meteorAux = numpy.zeros(16)
3172 meteorAux = numpy.zeros(16)
3054
3173
3055 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3174 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3056 mHeight = listMeteors[i][0]
3175 mHeight = listMeteors[i][0]
3057 mStart = listMeteors[i][1]
3176 mStart = listMeteors[i][1]
3058 mPeak = listMeteors[i][2]
3177 mPeak = listMeteors[i][2]
3059 mEnd = listMeteors[i][3]
3178 mEnd = listMeteors[i][3]
3060
3179
3061 #get the volt data between the start and end times of the meteor
3180 #get the volt data between the start and end times of the meteor
3062 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3181 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3063 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3182 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3064
3183
3065 #3.6. Phase Difference estimation
3184 #3.6. Phase Difference estimation
3066 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3185 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3067
3186
3068 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3187 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3069 #meteorVolts0.- all Channels, all Profiles
3188 #meteorVolts0.- all Channels, all Profiles
3070 meteorVolts0 = volts[:,:,mHeight]
3189 meteorVolts0 = volts[:,:,mHeight]
3071 meteorThresh = noise[:,mHeight]*thresholdNoise
3190 meteorThresh = noise[:,mHeight]*thresholdNoise
3072 meteorNoise = noise[:,mHeight]
3191 meteorNoise = noise[:,mHeight]
3073 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3192 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3074 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3193 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3075
3194
3076 #Times reestimation
3195 #Times reestimation
3077 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3196 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3078 if mStart1.size > 0:
3197 if mStart1.size > 0:
3079 mStart1 = mStart1[-1] + 1
3198 mStart1 = mStart1[-1] + 1
3080
3199
3081 else:
3200 else:
3082 mStart1 = mPeak
3201 mStart1 = mPeak
3083
3202
3084 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3203 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3085 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3204 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3086 if mEndDecayTime1.size == 0:
3205 if mEndDecayTime1.size == 0:
3087 mEndDecayTime1 = powerNet0.size
3206 mEndDecayTime1 = powerNet0.size
3088 else:
3207 else:
3089 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3208 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3090 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3209 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3091
3210
3092 #meteorVolts1.- all Channels, from start to end
3211 #meteorVolts1.- all Channels, from start to end
3093 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3212 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3094 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3213 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3095 if meteorVolts2.shape[1] == 0:
3214 if meteorVolts2.shape[1] == 0:
3096 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3215 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3097 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3216 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3098 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3217 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3099 ##################### END PARAMETERS REESTIMATION #########################
3218 ##################### END PARAMETERS REESTIMATION #########################
3100
3219
3101 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3220 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3102 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3221 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3103 if meteorVolts2.shape[1] > 0:
3222 if meteorVolts2.shape[1] > 0:
3104 #Phase Difference re-estimation
3223 #Phase Difference re-estimation
3105 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3224 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3106 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3225 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3107 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3226 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3108 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3227 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3109 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3228 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3110
3229
3111 #Phase Difference RMS
3230 #Phase Difference RMS
3112 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3231 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3113 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3232 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3114 #Data from Meteor
3233 #Data from Meteor
3115 mPeak1 = powerNet1.argmax() + mStart1
3234 mPeak1 = powerNet1.argmax() + mStart1
3116 mPeakPower1 = powerNet1.max()
3235 mPeakPower1 = powerNet1.max()
3117 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3236 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3118 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3237 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3119 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3238 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3120 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3239 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3121 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3240 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3122 #Vectorize
3241 #Vectorize
3123 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3242 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3124 meteorAux[7:11] = phaseDiffint[0:4]
3243 meteorAux[7:11] = phaseDiffint[0:4]
3125
3244
3126 #Rejection Criterions
3245 #Rejection Criterions
3127 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3246 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3128 meteorAux[-1] = 17
3247 meteorAux[-1] = 17
3129 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3248 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3130 meteorAux[-1] = 1
3249 meteorAux[-1] = 1
3131
3250
3132
3251
3133 else:
3252 else:
3134 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3253 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3135 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3254 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3136 PowerSeries = 0
3255 PowerSeries = 0
3137
3256
3138 listMeteors1.append(meteorAux)
3257 listMeteors1.append(meteorAux)
3139 listPowerSeries.append(PowerSeries)
3258 listPowerSeries.append(PowerSeries)
3140 listVoltageSeries.append(meteorVolts1)
3259 listVoltageSeries.append(meteorVolts1)
3141
3260
3142 return listMeteors1, listPowerSeries, listVoltageSeries
3261 return listMeteors1, listPowerSeries, listVoltageSeries
3143
3262
3144 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3263 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3145
3264
3146 threshError = 10
3265 threshError = 10
3147 #Depending if it is 30 or 50 MHz
3266 #Depending if it is 30 or 50 MHz
3148 if frequency == 30e6:
3267 if frequency == 30e6:
3149 timeLag = 45*10**-3
3268 timeLag = 45*10**-3
3150 else:
3269 else:
3151 timeLag = 15*10**-3
3270 timeLag = 15*10**-3
3152 lag = numpy.ceil(timeLag/timeInterval)
3271 lag = numpy.ceil(timeLag/timeInterval)
3153
3272
3154 listMeteors1 = []
3273 listMeteors1 = []
3155
3274
3156 for i in range(len(listMeteors)):
3275 for i in range(len(listMeteors)):
3157 meteorPower = listPower[i]
3276 meteorPower = listPower[i]
3158 meteorAux = listMeteors[i]
3277 meteorAux = listMeteors[i]
3159
3278
3160 if meteorAux[-1] == 0:
3279 if meteorAux[-1] == 0:
3161
3280
3162 try:
3281 try:
3163 indmax = meteorPower.argmax()
3282 indmax = meteorPower.argmax()
3164 indlag = indmax + lag
3283 indlag = indmax + lag
3165
3284
3166 y = meteorPower[indlag:]
3285 y = meteorPower[indlag:]
3167 x = numpy.arange(0, y.size)*timeLag
3286 x = numpy.arange(0, y.size)*timeLag
3168
3287
3169 #first guess
3288 #first guess
3170 a = y[0]
3289 a = y[0]
3171 tau = timeLag
3290 tau = timeLag
3172 #exponential fit
3291 #exponential fit
3173 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3292 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3174 y1 = self.__exponential_function(x, *popt)
3293 y1 = self.__exponential_function(x, *popt)
3175 #error estimation
3294 #error estimation
3176 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3295 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3177
3296
3178 decayTime = popt[1]
3297 decayTime = popt[1]
3179 riseTime = indmax*timeInterval
3298 riseTime = indmax*timeInterval
3180 meteorAux[11:13] = [decayTime, error]
3299 meteorAux[11:13] = [decayTime, error]
3181
3300
3182 #Table items 7, 8 and 11
3301 #Table items 7, 8 and 11
3183 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3302 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3184 meteorAux[-1] = 7
3303 meteorAux[-1] = 7
3185 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3304 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3186 meteorAux[-1] = 8
3305 meteorAux[-1] = 8
3187 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3306 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3188 meteorAux[-1] = 11
3307 meteorAux[-1] = 11
3189
3308
3190
3309
3191 except:
3310 except:
3192 meteorAux[-1] = 11
3311 meteorAux[-1] = 11
3193
3312
3194
3313
3195 listMeteors1.append(meteorAux)
3314 listMeteors1.append(meteorAux)
3196
3315
3197 return listMeteors1
3316 return listMeteors1
3198
3317
3199 #Exponential Function
3318 #Exponential Function
3200
3319
3201 def __exponential_function(self, x, a, tau):
3320 def __exponential_function(self, x, a, tau):
3202 y = a*numpy.exp(-x/tau)
3321 y = a*numpy.exp(-x/tau)
3203 return y
3322 return y
3204
3323
3205 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3324 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3206
3325
3207 pairslist1 = list(pairslist)
3326 pairslist1 = list(pairslist)
3208 pairslist1.append((0,1))
3327 pairslist1.append((0,1))
3209 pairslist1.append((3,4))
3328 pairslist1.append((3,4))
3210 numPairs = len(pairslist1)
3329 numPairs = len(pairslist1)
3211 #Time Lag
3330 #Time Lag
3212 timeLag = 45*10**-3
3331 timeLag = 45*10**-3
3213 c = 3e8
3332 c = 3e8
3214 lag = numpy.ceil(timeLag/timeInterval)
3333 lag = numpy.ceil(timeLag/timeInterval)
3215 freq = 30e6
3334 freq = 30e6
3216
3335
3217 listMeteors1 = []
3336 listMeteors1 = []
3218
3337
3219 for i in range(len(listMeteors)):
3338 for i in range(len(listMeteors)):
3220 meteorAux = listMeteors[i]
3339 meteorAux = listMeteors[i]
3221 if meteorAux[-1] == 0:
3340 if meteorAux[-1] == 0:
3222 mStart = listMeteors[i][1]
3341 mStart = listMeteors[i][1]
3223 mPeak = listMeteors[i][2]
3342 mPeak = listMeteors[i][2]
3224 mLag = mPeak - mStart + lag
3343 mLag = mPeak - mStart + lag
3225
3344
3226 #get the volt data between the start and end times of the meteor
3345 #get the volt data between the start and end times of the meteor
3227 meteorVolts = listVolts[i]
3346 meteorVolts = listVolts[i]
3228 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3347 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3229
3348
3230 #Get CCF
3349 #Get CCF
3231 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3350 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3232
3351
3233 #Method 2
3352 #Method 2
3234 slopes = numpy.zeros(numPairs)
3353 slopes = numpy.zeros(numPairs)
3235 time = numpy.array([-2,-1,1,2])*timeInterval
3354 time = numpy.array([-2,-1,1,2])*timeInterval
3236 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3355 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3237
3356
3238 #Correct phases
3357 #Correct phases
3239 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3358 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3240 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3359 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3241
3360
3242 if indDer[0].shape[0] > 0:
3361 if indDer[0].shape[0] > 0:
3243 for i in range(indDer[0].shape[0]):
3362 for i in range(indDer[0].shape[0]):
3244 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3363 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3245 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3364 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3246
3365
3247 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3366 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3248 for j in range(numPairs):
3367 for j in range(numPairs):
3249 fit = stats.linregress(time, angAllCCF[j,:])
3368 fit = stats.linregress(time, angAllCCF[j,:])
3250 slopes[j] = fit[0]
3369 slopes[j] = fit[0]
3251
3370
3252 #Remove Outlier
3371 #Remove Outlier
3253 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3372 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3254 # slopes = numpy.delete(slopes,indOut)
3373 # slopes = numpy.delete(slopes,indOut)
3255 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3374 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3256 # slopes = numpy.delete(slopes,indOut)
3375 # slopes = numpy.delete(slopes,indOut)
3257
3376
3258 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3377 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3259 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3378 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3260 meteorAux[-2] = radialError
3379 meteorAux[-2] = radialError
3261 meteorAux[-3] = radialVelocity
3380 meteorAux[-3] = radialVelocity
3262
3381
3263 #Setting Error
3382 #Setting Error
3264 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3383 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3265 if numpy.abs(radialVelocity) > 200:
3384 if numpy.abs(radialVelocity) > 200:
3266 meteorAux[-1] = 15
3385 meteorAux[-1] = 15
3267 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3386 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3268 elif radialError > radialStdThresh:
3387 elif radialError > radialStdThresh:
3269 meteorAux[-1] = 12
3388 meteorAux[-1] = 12
3270
3389
3271 listMeteors1.append(meteorAux)
3390 listMeteors1.append(meteorAux)
3272 return listMeteors1
3391 return listMeteors1
3273
3392
3274 def __setNewArrays(self, listMeteors, date, heiRang):
3393 def __setNewArrays(self, listMeteors, date, heiRang):
3275
3394
3276 #New arrays
3395 #New arrays
3277 arrayMeteors = numpy.array(listMeteors)
3396 arrayMeteors = numpy.array(listMeteors)
3278 arrayParameters = numpy.zeros((len(listMeteors), 13))
3397 arrayParameters = numpy.zeros((len(listMeteors), 13))
3279
3398
3280 #Date inclusion
3399 #Date inclusion
3281 # date = re.findall(r'\((.*?)\)', date)
3400 # date = re.findall(r'\((.*?)\)', date)
3282 # date = date[0].split(',')
3401 # date = date[0].split(',')
3283 # date = map(int, date)
3402 # date = map(int, date)
3284 #
3403 #
3285 # if len(date)<6:
3404 # if len(date)<6:
3286 # date.append(0)
3405 # date.append(0)
3287 #
3406 #
3288 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3407 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3289 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3408 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3290 arrayDate = numpy.tile(date, (len(listMeteors)))
3409 arrayDate = numpy.tile(date, (len(listMeteors)))
3291
3410
3292 #Meteor array
3411 #Meteor array
3293 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3412 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3294 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3413 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3295
3414
3296 #Parameters Array
3415 #Parameters Array
3297 arrayParameters[:,0] = arrayDate #Date
3416 arrayParameters[:,0] = arrayDate #Date
3298 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3417 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3299 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3418 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3300 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3419 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3301 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3420 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3302
3421
3303
3422
3304 return arrayParameters
3423 return arrayParameters
3305
3424
3306 class CorrectSMPhases(Operation):
3425 class CorrectSMPhases(Operation):
3307
3426
3308 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3427 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3309
3428
3310 arrayParameters = dataOut.data_param
3429 arrayParameters = dataOut.data_param
3311 pairsList = []
3430 pairsList = []
3312 pairx = (0,1)
3431 pairx = (0,1)
3313 pairy = (2,3)
3432 pairy = (2,3)
3314 pairsList.append(pairx)
3433 pairsList.append(pairx)
3315 pairsList.append(pairy)
3434 pairsList.append(pairy)
3316 jph = numpy.zeros(4)
3435 jph = numpy.zeros(4)
3317
3436
3318 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3437 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3319 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3438 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3320 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3439 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3321
3440
3322 meteorOps = SMOperations()
3441 meteorOps = SMOperations()
3323 if channelPositions == None:
3442 if channelPositions == None:
3324 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3443 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3325 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3444 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3326
3445
3327 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3446 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3328 h = (hmin,hmax)
3447 h = (hmin,hmax)
3329
3448
3330 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3449 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3331
3450
3332 dataOut.data_param = arrayParameters
3451 dataOut.data_param = arrayParameters
3333 return
3452 return
3334
3453
3335 class SMPhaseCalibration(Operation):
3454 class SMPhaseCalibration(Operation):
3336
3455
3337 __buffer = None
3456 __buffer = None
3338
3457
3339 __initime = None
3458 __initime = None
3340
3459
3341 __dataReady = False
3460 __dataReady = False
3342
3461
3343 __isConfig = False
3462 __isConfig = False
3344
3463
3345 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3464 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3346
3465
3347 dataTime = currentTime + paramInterval
3466 dataTime = currentTime + paramInterval
3348 deltaTime = dataTime - initTime
3467 deltaTime = dataTime - initTime
3349
3468
3350 if deltaTime >= outputInterval or deltaTime < 0:
3469 if deltaTime >= outputInterval or deltaTime < 0:
3351 return True
3470 return True
3352
3471
3353 return False
3472 return False
3354
3473
3355 def __getGammas(self, pairs, d, phases):
3474 def __getGammas(self, pairs, d, phases):
3356 gammas = numpy.zeros(2)
3475 gammas = numpy.zeros(2)
3357
3476
3358 for i in range(len(pairs)):
3477 for i in range(len(pairs)):
3359
3478
3360 pairi = pairs[i]
3479 pairi = pairs[i]
3361
3480
3362 phip3 = phases[:,pairi[1]]
3481 phip3 = phases[:,pairi[1]]
3363 d3 = d[pairi[1]]
3482 d3 = d[pairi[1]]
3364 phip2 = phases[:,pairi[0]]
3483 phip2 = phases[:,pairi[0]]
3365 d2 = d[pairi[0]]
3484 d2 = d[pairi[0]]
3366 #Calculating gamma
3485 #Calculating gamma
3367 # jdcos = alp1/(k*d1)
3486 # jdcos = alp1/(k*d1)
3368 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3487 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3369 jgamma = -phip2*d3/d2 - phip3
3488 jgamma = -phip2*d3/d2 - phip3
3370 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3489 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3371 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3490 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3372 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3491 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3373
3492
3374 #Revised distribution
3493 #Revised distribution
3375 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3494 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3376
3495
3377 #Histogram
3496 #Histogram
3378 nBins = 64.0
3497 nBins = 64.0
3379 rmin = -0.5*numpy.pi
3498 rmin = -0.5*numpy.pi
3380 rmax = 0.5*numpy.pi
3499 rmax = 0.5*numpy.pi
3381 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3500 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3382
3501
3383 meteorsY = phaseHisto[0]
3502 meteorsY = phaseHisto[0]
3384 phasesX = phaseHisto[1][:-1]
3503 phasesX = phaseHisto[1][:-1]
3385 width = phasesX[1] - phasesX[0]
3504 width = phasesX[1] - phasesX[0]
3386 phasesX += width/2
3505 phasesX += width/2
3387
3506
3388 #Gaussian aproximation
3507 #Gaussian aproximation
3389 bpeak = meteorsY.argmax()
3508 bpeak = meteorsY.argmax()
3390 peak = meteorsY.max()
3509 peak = meteorsY.max()
3391 jmin = bpeak - 5
3510 jmin = bpeak - 5
3392 jmax = bpeak + 5 + 1
3511 jmax = bpeak + 5 + 1
3393
3512
3394 if jmin<0:
3513 if jmin<0:
3395 jmin = 0
3514 jmin = 0
3396 jmax = 6
3515 jmax = 6
3397 elif jmax > meteorsY.size:
3516 elif jmax > meteorsY.size:
3398 jmin = meteorsY.size - 6
3517 jmin = meteorsY.size - 6
3399 jmax = meteorsY.size
3518 jmax = meteorsY.size
3400
3519
3401 x0 = numpy.array([peak,bpeak,50])
3520 x0 = numpy.array([peak,bpeak,50])
3402 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3521 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3403
3522
3404 #Gammas
3523 #Gammas
3405 gammas[i] = coeff[0][1]
3524 gammas[i] = coeff[0][1]
3406
3525
3407 return gammas
3526 return gammas
3408
3527
3409 def __residualFunction(self, coeffs, y, t):
3528 def __residualFunction(self, coeffs, y, t):
3410
3529
3411 return y - self.__gauss_function(t, coeffs)
3530 return y - self.__gauss_function(t, coeffs)
3412
3531
3413 def __gauss_function(self, t, coeffs):
3532 def __gauss_function(self, t, coeffs):
3414
3533
3415 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3534 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3416
3535
3417 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3536 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3418 meteorOps = SMOperations()
3537 meteorOps = SMOperations()
3419 nchan = 4
3538 nchan = 4
3420 pairx = pairsList[0]
3539 pairx = pairsList[0]
3421 pairy = pairsList[1]
3540 pairy = pairsList[1]
3422 center_xangle = 0
3541 center_xangle = 0
3423 center_yangle = 0
3542 center_yangle = 0
3424 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3543 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3425 ntimes = len(range_angle)
3544 ntimes = len(range_angle)
3426
3545
3427 nstepsx = 20.0
3546 nstepsx = 20.0
3428 nstepsy = 20.0
3547 nstepsy = 20.0
3429
3548
3430 for iz in range(ntimes):
3549 for iz in range(ntimes):
3431 min_xangle = -range_angle[iz]/2 + center_xangle
3550 min_xangle = -range_angle[iz]/2 + center_xangle
3432 max_xangle = range_angle[iz]/2 + center_xangle
3551 max_xangle = range_angle[iz]/2 + center_xangle
3433 min_yangle = -range_angle[iz]/2 + center_yangle
3552 min_yangle = -range_angle[iz]/2 + center_yangle
3434 max_yangle = range_angle[iz]/2 + center_yangle
3553 max_yangle = range_angle[iz]/2 + center_yangle
3435
3554
3436 inc_x = (max_xangle-min_xangle)/nstepsx
3555 inc_x = (max_xangle-min_xangle)/nstepsx
3437 inc_y = (max_yangle-min_yangle)/nstepsy
3556 inc_y = (max_yangle-min_yangle)/nstepsy
3438
3557
3439 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3558 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3440 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3559 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3441 penalty = numpy.zeros((nstepsx,nstepsy))
3560 penalty = numpy.zeros((nstepsx,nstepsy))
3442 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3561 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3443 jph = numpy.zeros(nchan)
3562 jph = numpy.zeros(nchan)
3444
3563
3445 # Iterations looking for the offset
3564 # Iterations looking for the offset
3446 for iy in range(int(nstepsy)):
3565 for iy in range(int(nstepsy)):
3447 for ix in range(int(nstepsx)):
3566 for ix in range(int(nstepsx)):
3448 jph[pairy[1]] = alpha_y[iy]
3567 jph[pairy[1]] = alpha_y[iy]
3449 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3568 jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3450
3569
3451 jph[pairx[1]] = alpha_x[ix]
3570 jph[pairx[1]] = alpha_x[ix]
3452 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3571 jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3453
3572
3454 jph_array[:,ix,iy] = jph
3573 jph_array[:,ix,iy] = jph
3455
3574
3456 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3575 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3457 error = meteorsArray1[:,-1]
3576 error = meteorsArray1[:,-1]
3458 ind1 = numpy.where(error==0)[0]
3577 ind1 = numpy.where(error==0)[0]
3459 penalty[ix,iy] = ind1.size
3578 penalty[ix,iy] = ind1.size
3460
3579
3461 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3580 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3462 phOffset = jph_array[:,i,j]
3581 phOffset = jph_array[:,i,j]
3463
3582
3464 center_xangle = phOffset[pairx[1]]
3583 center_xangle = phOffset[pairx[1]]
3465 center_yangle = phOffset[pairy[1]]
3584 center_yangle = phOffset[pairy[1]]
3466
3585
3467 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3586 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3468 phOffset = phOffset*180/numpy.pi
3587 phOffset = phOffset*180/numpy.pi
3469 return phOffset
3588 return phOffset
3470
3589
3471
3590
3472 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3591 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3473
3592
3474 dataOut.flagNoData = True
3593 dataOut.flagNoData = True
3475 self.__dataReady = False
3594 self.__dataReady = False
3476 dataOut.outputInterval = nHours*3600
3595 dataOut.outputInterval = nHours*3600
3477
3596
3478 if self.__isConfig == False:
3597 if self.__isConfig == False:
3479 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3598 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3480 #Get Initial LTC time
3599 #Get Initial LTC time
3481 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3600 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3482 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3601 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3483
3602
3484 self.__isConfig = True
3603 self.__isConfig = True
3485
3604
3486 if self.__buffer == None:
3605 if self.__buffer == None:
3487 self.__buffer = dataOut.data_param.copy()
3606 self.__buffer = dataOut.data_param.copy()
3488
3607
3489 else:
3608 else:
3490 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3609 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3491
3610
3492 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3611 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3493
3612
3494 if self.__dataReady:
3613 if self.__dataReady:
3495 dataOut.utctimeInit = self.__initime
3614 dataOut.utctimeInit = self.__initime
3496 self.__initime += dataOut.outputInterval #to erase time offset
3615 self.__initime += dataOut.outputInterval #to erase time offset
3497
3616
3498 freq = dataOut.frequency
3617 freq = dataOut.frequency
3499 c = dataOut.C #m/s
3618 c = dataOut.C #m/s
3500 lamb = c/freq
3619 lamb = c/freq
3501 k = 2*numpy.pi/lamb
3620 k = 2*numpy.pi/lamb
3502 azimuth = 0
3621 azimuth = 0
3503 h = (hmin, hmax)
3622 h = (hmin, hmax)
3504 pairs = ((0,1),(2,3))
3623 pairs = ((0,1),(2,3))
3505
3624
3506 if channelPositions == None:
3625 if channelPositions == None:
3507 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3626 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3508 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3627 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3509 meteorOps = SMOperations()
3628 meteorOps = SMOperations()
3510 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3629 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3511
3630
3512 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3631 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3513
3632
3514 meteorsArray = self.__buffer
3633 meteorsArray = self.__buffer
3515 error = meteorsArray[:,-1]
3634 error = meteorsArray[:,-1]
3516 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3635 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3517 ind1 = numpy.where(boolError)[0]
3636 ind1 = numpy.where(boolError)[0]
3518 meteorsArray = meteorsArray[ind1,:]
3637 meteorsArray = meteorsArray[ind1,:]
3519 meteorsArray[:,-1] = 0
3638 meteorsArray[:,-1] = 0
3520 phases = meteorsArray[:,8:12]
3639 phases = meteorsArray[:,8:12]
3521
3640
3522 #Calculate Gammas
3641 #Calculate Gammas
3523 gammas = self.__getGammas(pairs, distances, phases)
3642 gammas = self.__getGammas(pairs, distances, phases)
3524 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3643 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3525 #Calculate Phases
3644 #Calculate Phases
3526 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3645 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3527 phasesOff = phasesOff.reshape((1,phasesOff.size))
3646 phasesOff = phasesOff.reshape((1,phasesOff.size))
3528 dataOut.data_output = -phasesOff
3647 dataOut.data_output = -phasesOff
3529 dataOut.flagNoData = False
3648 dataOut.flagNoData = False
3530 self.__buffer = None
3649 self.__buffer = None
3531
3650
3532
3651
3533 return
3652 return
3534
3653
3535 class SMOperations():
3654 class SMOperations():
3536
3655
3537 def __init__(self):
3656 def __init__(self):
3538
3657
3539 return
3658 return
3540
3659
3541 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3660 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3542
3661
3543 arrayParameters = arrayParameters0.copy()
3662 arrayParameters = arrayParameters0.copy()
3544 hmin = h[0]
3663 hmin = h[0]
3545 hmax = h[1]
3664 hmax = h[1]
3546
3665
3547 #Calculate AOA (Error N 3, 4)
3666 #Calculate AOA (Error N 3, 4)
3548 #JONES ET AL. 1998
3667 #JONES ET AL. 1998
3549 AOAthresh = numpy.pi/8
3668 AOAthresh = numpy.pi/8
3550 error = arrayParameters[:,-1]
3669 error = arrayParameters[:,-1]
3551 phases = -arrayParameters[:,8:12] + jph
3670 phases = -arrayParameters[:,8:12] + jph
3552 # phases = numpy.unwrap(phases)
3671 # phases = numpy.unwrap(phases)
3553 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3672 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3554
3673
3555 #Calculate Heights (Error N 13 and 14)
3674 #Calculate Heights (Error N 13 and 14)
3556 error = arrayParameters[:,-1]
3675 error = arrayParameters[:,-1]
3557 Ranges = arrayParameters[:,1]
3676 Ranges = arrayParameters[:,1]
3558 zenith = arrayParameters[:,4]
3677 zenith = arrayParameters[:,4]
3559 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3678 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3560
3679
3561 #----------------------- Get Final data ------------------------------------
3680 #----------------------- Get Final data ------------------------------------
3562 # error = arrayParameters[:,-1]
3681 # error = arrayParameters[:,-1]
3563 # ind1 = numpy.where(error==0)[0]
3682 # ind1 = numpy.where(error==0)[0]
3564 # arrayParameters = arrayParameters[ind1,:]
3683 # arrayParameters = arrayParameters[ind1,:]
3565
3684
3566 return arrayParameters
3685 return arrayParameters
3567
3686
3568 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3687 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3569
3688
3570 arrayAOA = numpy.zeros((phases.shape[0],3))
3689 arrayAOA = numpy.zeros((phases.shape[0],3))
3571 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3690 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3572
3691
3573 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3692 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3574 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3693 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3575 arrayAOA[:,2] = cosDirError
3694 arrayAOA[:,2] = cosDirError
3576
3695
3577 azimuthAngle = arrayAOA[:,0]
3696 azimuthAngle = arrayAOA[:,0]
3578 zenithAngle = arrayAOA[:,1]
3697 zenithAngle = arrayAOA[:,1]
3579
3698
3580 #Setting Error
3699 #Setting Error
3581 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3700 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3582 error[indError] = 0
3701 error[indError] = 0
3583 #Number 3: AOA not fesible
3702 #Number 3: AOA not fesible
3584 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3703 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3585 error[indInvalid] = 3
3704 error[indInvalid] = 3
3586 #Number 4: Large difference in AOAs obtained from different antenna baselines
3705 #Number 4: Large difference in AOAs obtained from different antenna baselines
3587 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3706 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3588 error[indInvalid] = 4
3707 error[indInvalid] = 4
3589 return arrayAOA, error
3708 return arrayAOA, error
3590
3709
3591 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3710 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3592
3711
3593 #Initializing some variables
3712 #Initializing some variables
3594 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3713 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3595 ang_aux = ang_aux.reshape(1,ang_aux.size)
3714 ang_aux = ang_aux.reshape(1,ang_aux.size)
3596
3715
3597 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3716 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3598 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3717 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3599
3718
3600
3719
3601 for i in range(2):
3720 for i in range(2):
3602 ph0 = arrayPhase[:,pairsList[i][0]]
3721 ph0 = arrayPhase[:,pairsList[i][0]]
3603 ph1 = arrayPhase[:,pairsList[i][1]]
3722 ph1 = arrayPhase[:,pairsList[i][1]]
3604 d0 = distances[pairsList[i][0]]
3723 d0 = distances[pairsList[i][0]]
3605 d1 = distances[pairsList[i][1]]
3724 d1 = distances[pairsList[i][1]]
3606
3725
3607 ph0_aux = ph0 + ph1
3726 ph0_aux = ph0 + ph1
3608 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3727 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3609 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3728 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3610 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3729 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3611 #First Estimation
3730 #First Estimation
3612 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3731 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3613
3732
3614 #Most-Accurate Second Estimation
3733 #Most-Accurate Second Estimation
3615 phi1_aux = ph0 - ph1
3734 phi1_aux = ph0 - ph1
3616 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3735 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3617 #Direction Cosine 1
3736 #Direction Cosine 1
3618 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3737 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3619
3738
3620 #Searching the correct Direction Cosine
3739 #Searching the correct Direction Cosine
3621 cosdir0_aux = cosdir0[:,i]
3740 cosdir0_aux = cosdir0[:,i]
3622 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3741 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3623 #Minimum Distance
3742 #Minimum Distance
3624 cosDiff = (cosdir1 - cosdir0_aux)**2
3743 cosDiff = (cosdir1 - cosdir0_aux)**2
3625 indcos = cosDiff.argmin(axis = 1)
3744 indcos = cosDiff.argmin(axis = 1)
3626 #Saving Value obtained
3745 #Saving Value obtained
3627 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3746 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3628
3747
3629 return cosdir0, cosdir
3748 return cosdir0, cosdir
3630
3749
3631 def __calculateAOA(self, cosdir, azimuth):
3750 def __calculateAOA(self, cosdir, azimuth):
3632 cosdirX = cosdir[:,0]
3751 cosdirX = cosdir[:,0]
3633 cosdirY = cosdir[:,1]
3752 cosdirY = cosdir[:,1]
3634
3753
3635 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3754 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3636 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3755 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3637 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3756 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3638
3757
3639 return angles
3758 return angles
3640
3759
3641 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3760 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3642
3761
3643 Ramb = 375 #Ramb = c/(2*PRF)
3762 Ramb = 375 #Ramb = c/(2*PRF)
3644 Re = 6371 #Earth Radius
3763 Re = 6371 #Earth Radius
3645 heights = numpy.zeros(Ranges.shape)
3764 heights = numpy.zeros(Ranges.shape)
3646
3765
3647 R_aux = numpy.array([0,1,2])*Ramb
3766 R_aux = numpy.array([0,1,2])*Ramb
3648 R_aux = R_aux.reshape(1,R_aux.size)
3767 R_aux = R_aux.reshape(1,R_aux.size)
3649
3768
3650 Ranges = Ranges.reshape(Ranges.size,1)
3769 Ranges = Ranges.reshape(Ranges.size,1)
3651
3770
3652 Ri = Ranges + R_aux
3771 Ri = Ranges + R_aux
3653 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3772 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3654
3773
3655 #Check if there is a height between 70 and 110 km
3774 #Check if there is a height between 70 and 110 km
3656 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3775 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3657 ind_h = numpy.where(h_bool == 1)[0]
3776 ind_h = numpy.where(h_bool == 1)[0]
3658
3777
3659 hCorr = hi[ind_h, :]
3778 hCorr = hi[ind_h, :]
3660 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3779 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3661
3780
3662 hCorr = hi[ind_hCorr]
3781 hCorr = hi[ind_hCorr]
3663 heights[ind_h] = hCorr
3782 heights[ind_h] = hCorr
3664
3783
3665 #Setting Error
3784 #Setting Error
3666 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3785 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3667 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3786 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3668 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3787 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3669 error[indError] = 0
3788 error[indError] = 0
3670 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3789 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3671 error[indInvalid2] = 14
3790 error[indInvalid2] = 14
3672 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3791 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3673 error[indInvalid1] = 13
3792 error[indInvalid1] = 13
3674
3793
3675 return heights, error
3794 return heights, error
3676
3795
3677 def getPhasePairs(self, channelPositions):
3796 def getPhasePairs(self, channelPositions):
3678 chanPos = numpy.array(channelPositions)
3797 chanPos = numpy.array(channelPositions)
3679 listOper = list(itertools.combinations(range(5),2))
3798 listOper = list(itertools.combinations(range(5),2))
3680
3799
3681 distances = numpy.zeros(4)
3800 distances = numpy.zeros(4)
3682 axisX = []
3801 axisX = []
3683 axisY = []
3802 axisY = []
3684 distX = numpy.zeros(3)
3803 distX = numpy.zeros(3)
3685 distY = numpy.zeros(3)
3804 distY = numpy.zeros(3)
3686 ix = 0
3805 ix = 0
3687 iy = 0
3806 iy = 0
3688
3807
3689 pairX = numpy.zeros((2,2))
3808 pairX = numpy.zeros((2,2))
3690 pairY = numpy.zeros((2,2))
3809 pairY = numpy.zeros((2,2))
3691
3810
3692 for i in range(len(listOper)):
3811 for i in range(len(listOper)):
3693 pairi = listOper[i]
3812 pairi = listOper[i]
3694
3813
3695 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3814 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3696
3815
3697 if posDif[0] == 0:
3816 if posDif[0] == 0:
3698 axisY.append(pairi)
3817 axisY.append(pairi)
3699 distY[iy] = posDif[1]
3818 distY[iy] = posDif[1]
3700 iy += 1
3819 iy += 1
3701 elif posDif[1] == 0:
3820 elif posDif[1] == 0:
3702 axisX.append(pairi)
3821 axisX.append(pairi)
3703 distX[ix] = posDif[0]
3822 distX[ix] = posDif[0]
3704 ix += 1
3823 ix += 1
3705
3824
3706 for i in range(2):
3825 for i in range(2):
3707 if i==0:
3826 if i==0:
3708 dist0 = distX
3827 dist0 = distX
3709 axis0 = axisX
3828 axis0 = axisX
3710 else:
3829 else:
3711 dist0 = distY
3830 dist0 = distY
3712 axis0 = axisY
3831 axis0 = axisY
3713
3832
3714 side = numpy.argsort(dist0)[:-1]
3833 side = numpy.argsort(dist0)[:-1]
3715 axis0 = numpy.array(axis0)[side,:]
3834 axis0 = numpy.array(axis0)[side,:]
3716 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3835 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3717 axis1 = numpy.unique(numpy.reshape(axis0,4))
3836 axis1 = numpy.unique(numpy.reshape(axis0,4))
3718 side = axis1[axis1 != chanC]
3837 side = axis1[axis1 != chanC]
3719 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3838 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3720 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3839 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3721 if diff1<0:
3840 if diff1<0:
3722 chan2 = side[0]
3841 chan2 = side[0]
3723 d2 = numpy.abs(diff1)
3842 d2 = numpy.abs(diff1)
3724 chan1 = side[1]
3843 chan1 = side[1]
3725 d1 = numpy.abs(diff2)
3844 d1 = numpy.abs(diff2)
3726 else:
3845 else:
3727 chan2 = side[1]
3846 chan2 = side[1]
3728 d2 = numpy.abs(diff2)
3847 d2 = numpy.abs(diff2)
3729 chan1 = side[0]
3848 chan1 = side[0]
3730 d1 = numpy.abs(diff1)
3849 d1 = numpy.abs(diff1)
3731
3850
3732 if i==0:
3851 if i==0:
3733 chanCX = chanC
3852 chanCX = chanC
3734 chan1X = chan1
3853 chan1X = chan1
3735 chan2X = chan2
3854 chan2X = chan2
3736 distances[0:2] = numpy.array([d1,d2])
3855 distances[0:2] = numpy.array([d1,d2])
3737 else:
3856 else:
3738 chanCY = chanC
3857 chanCY = chanC
3739 chan1Y = chan1
3858 chan1Y = chan1
3740 chan2Y = chan2
3859 chan2Y = chan2
3741 distances[2:4] = numpy.array([d1,d2])
3860 distances[2:4] = numpy.array([d1,d2])
3742 # axisXsides = numpy.reshape(axisX[ix,:],4)
3861 # axisXsides = numpy.reshape(axisX[ix,:],4)
3743 #
3862 #
3744 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3863 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3745 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3864 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3746 #
3865 #
3747 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3866 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3748 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3867 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3749 # channel25X = int(pairX[0,ind25X])
3868 # channel25X = int(pairX[0,ind25X])
3750 # channel20X = int(pairX[1,ind20X])
3869 # channel20X = int(pairX[1,ind20X])
3751 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3870 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3752 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3871 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3753 # channel25Y = int(pairY[0,ind25Y])
3872 # channel25Y = int(pairY[0,ind25Y])
3754 # channel20Y = int(pairY[1,ind20Y])
3873 # channel20Y = int(pairY[1,ind20Y])
3755
3874
3756 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3875 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3757 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3876 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3758
3877
3759 return pairslist, distances
3878 return pairslist, distances
3760 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3879 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3761 #
3880 #
3762 # arrayAOA = numpy.zeros((phases.shape[0],3))
3881 # arrayAOA = numpy.zeros((phases.shape[0],3))
3763 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3882 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3764 #
3883 #
3765 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3884 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3766 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3885 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3767 # arrayAOA[:,2] = cosDirError
3886 # arrayAOA[:,2] = cosDirError
3768 #
3887 #
3769 # azimuthAngle = arrayAOA[:,0]
3888 # azimuthAngle = arrayAOA[:,0]
3770 # zenithAngle = arrayAOA[:,1]
3889 # zenithAngle = arrayAOA[:,1]
3771 #
3890 #
3772 # #Setting Error
3891 # #Setting Error
3773 # #Number 3: AOA not fesible
3892 # #Number 3: AOA not fesible
3774 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3893 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3775 # error[indInvalid] = 3
3894 # error[indInvalid] = 3
3776 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3895 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3777 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3896 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3778 # error[indInvalid] = 4
3897 # error[indInvalid] = 4
3779 # return arrayAOA, error
3898 # return arrayAOA, error
3780 #
3899 #
3781 # def __getDirectionCosines(self, arrayPhase, pairsList):
3900 # def __getDirectionCosines(self, arrayPhase, pairsList):
3782 #
3901 #
3783 # #Initializing some variables
3902 # #Initializing some variables
3784 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3903 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3785 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3904 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3786 #
3905 #
3787 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3906 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3788 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3907 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3789 #
3908 #
3790 #
3909 #
3791 # for i in range(2):
3910 # for i in range(2):
3792 # #First Estimation
3911 # #First Estimation
3793 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3912 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3794 # #Dealias
3913 # #Dealias
3795 # indcsi = numpy.where(phi0_aux > numpy.pi)
3914 # indcsi = numpy.where(phi0_aux > numpy.pi)
3796 # phi0_aux[indcsi] -= 2*numpy.pi
3915 # phi0_aux[indcsi] -= 2*numpy.pi
3797 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3916 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3798 # phi0_aux[indcsi] += 2*numpy.pi
3917 # phi0_aux[indcsi] += 2*numpy.pi
3799 # #Direction Cosine 0
3918 # #Direction Cosine 0
3800 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3919 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3801 #
3920 #
3802 # #Most-Accurate Second Estimation
3921 # #Most-Accurate Second Estimation
3803 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3922 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3804 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3923 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3805 # #Direction Cosine 1
3924 # #Direction Cosine 1
3806 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3925 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3807 #
3926 #
3808 # #Searching the correct Direction Cosine
3927 # #Searching the correct Direction Cosine
3809 # cosdir0_aux = cosdir0[:,i]
3928 # cosdir0_aux = cosdir0[:,i]
3810 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3929 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3811 # #Minimum Distance
3930 # #Minimum Distance
3812 # cosDiff = (cosdir1 - cosdir0_aux)**2
3931 # cosDiff = (cosdir1 - cosdir0_aux)**2
3813 # indcos = cosDiff.argmin(axis = 1)
3932 # indcos = cosDiff.argmin(axis = 1)
3814 # #Saving Value obtained
3933 # #Saving Value obtained
3815 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3934 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3816 #
3935 #
3817 # return cosdir0, cosdir
3936 # return cosdir0, cosdir
3818 #
3937 #
3819 # def __calculateAOA(self, cosdir, azimuth):
3938 # def __calculateAOA(self, cosdir, azimuth):
3820 # cosdirX = cosdir[:,0]
3939 # cosdirX = cosdir[:,0]
3821 # cosdirY = cosdir[:,1]
3940 # cosdirY = cosdir[:,1]
3822 #
3941 #
3823 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3942 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3824 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3943 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3825 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3944 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3826 #
3945 #
3827 # return angles
3946 # return angles
3828 #
3947 #
3829 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3948 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3830 #
3949 #
3831 # Ramb = 375 #Ramb = c/(2*PRF)
3950 # Ramb = 375 #Ramb = c/(2*PRF)
3832 # Re = 6371 #Earth Radius
3951 # Re = 6371 #Earth Radius
3833 # heights = numpy.zeros(Ranges.shape)
3952 # heights = numpy.zeros(Ranges.shape)
3834 #
3953 #
3835 # R_aux = numpy.array([0,1,2])*Ramb
3954 # R_aux = numpy.array([0,1,2])*Ramb
3836 # R_aux = R_aux.reshape(1,R_aux.size)
3955 # R_aux = R_aux.reshape(1,R_aux.size)
3837 #
3956 #
3838 # Ranges = Ranges.reshape(Ranges.size,1)
3957 # Ranges = Ranges.reshape(Ranges.size,1)
3839 #
3958 #
3840 # Ri = Ranges + R_aux
3959 # Ri = Ranges + R_aux
3841 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3960 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3842 #
3961 #
3843 # #Check if there is a height between 70 and 110 km
3962 # #Check if there is a height between 70 and 110 km
3844 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3963 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3845 # ind_h = numpy.where(h_bool == 1)[0]
3964 # ind_h = numpy.where(h_bool == 1)[0]
3846 #
3965 #
3847 # hCorr = hi[ind_h, :]
3966 # hCorr = hi[ind_h, :]
3848 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3967 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3849 #
3968 #
3850 # hCorr = hi[ind_hCorr]
3969 # hCorr = hi[ind_hCorr]
3851 # heights[ind_h] = hCorr
3970 # heights[ind_h] = hCorr
3852 #
3971 #
3853 # #Setting Error
3972 # #Setting Error
3854 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3973 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3855 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3974 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3856 #
3975 #
3857 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3976 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3858 # error[indInvalid2] = 14
3977 # error[indInvalid2] = 14
3859 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3978 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3860 # error[indInvalid1] = 13
3979 # error[indInvalid1] = 13
3861 #
3980 #
3862 # return heights, error
3981 # return heights, error
3863 No newline at end of file
3982
@@ -1,1068 +1,1067
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 import matplotlib.pyplot as plt
7 import matplotlib.pyplot as plt
8
8
9 class SpectraProc(ProcessingUnit):
9 class SpectraProc(ProcessingUnit):
10
10
11 def __init__(self, **kwargs):
11 def __init__(self, **kwargs):
12
12
13 ProcessingUnit.__init__(self, **kwargs)
13 ProcessingUnit.__init__(self, **kwargs)
14
14
15 self.buffer = None
15 self.buffer = None
16 self.firstdatatime = None
16 self.firstdatatime = None
17 self.profIndex = 0
17 self.profIndex = 0
18 self.dataOut = Spectra()
18 self.dataOut = Spectra()
19 self.id_min = None
19 self.id_min = None
20 self.id_max = None
20 self.id_max = None
21
21
22 def __updateSpecFromVoltage(self):
22 def __updateSpecFromVoltage(self):
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.channelList = self.dataIn.channelList
31 self.dataOut.channelList = self.dataIn.channelList
32 self.dataOut.heightList = self.dataIn.heightList
32 self.dataOut.heightList = self.dataIn.heightList
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
34
34
35 self.dataOut.nBaud = self.dataIn.nBaud
35 self.dataOut.nBaud = self.dataIn.nBaud
36 self.dataOut.nCode = self.dataIn.nCode
36 self.dataOut.nCode = self.dataIn.nCode
37 self.dataOut.code = self.dataIn.code
37 self.dataOut.code = self.dataIn.code
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
39
39
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 self.dataOut.utctime = self.firstdatatime
41 self.dataOut.utctime = self.firstdatatime
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 self.dataOut.flagShiftFFT = False
44 self.dataOut.flagShiftFFT = False
45
45
46 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.nIncohInt = 1
47 self.dataOut.nIncohInt = 1
48
48
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50
50
51 self.dataOut.frequency = self.dataIn.frequency
51 self.dataOut.frequency = self.dataIn.frequency
52 self.dataOut.realtime = self.dataIn.realtime
52 self.dataOut.realtime = self.dataIn.realtime
53
53
54 self.dataOut.azimuth = self.dataIn.azimuth
54 self.dataOut.azimuth = self.dataIn.azimuth
55 self.dataOut.zenith = self.dataIn.zenith
55 self.dataOut.zenith = self.dataIn.zenith
56
56
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
60
60
61 def __getFft(self):
61 def __getFft(self):
62 """
62 """
63 Convierte valores de Voltaje a Spectra
63 Convierte valores de Voltaje a Spectra
64
64
65 Affected:
65 Affected:
66 self.dataOut.data_spc
66 self.dataOut.data_spc
67 self.dataOut.data_cspc
67 self.dataOut.data_cspc
68 self.dataOut.data_dc
68 self.dataOut.data_dc
69 self.dataOut.heightList
69 self.dataOut.heightList
70 self.profIndex
70 self.profIndex
71 self.buffer
71 self.buffer
72 self.dataOut.flagNoData
72 self.dataOut.flagNoData
73 """
73 """
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
75
75
76 fft_volt = fft_volt.astype(numpy.dtype('complex'))
76 fft_volt = fft_volt.astype(numpy.dtype('complex'))
77 dc = fft_volt[:,0,:]
77 dc = fft_volt[:,0,:]
78
78
79 #calculo de self-spectra
79 #calculo de self-spectra
80 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
80 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
81 spc = fft_volt * numpy.conjugate(fft_volt)
81 spc = fft_volt * numpy.conjugate(fft_volt)
82 spc = spc.real
82 spc = spc.real
83
83
84 blocksize = 0
84 blocksize = 0
85 blocksize += dc.size
85 blocksize += dc.size
86 blocksize += spc.size
86 blocksize += spc.size
87
87
88 cspc = None
88 cspc = None
89 pairIndex = 0
89 pairIndex = 0
90 if self.dataOut.pairsList != None:
90 if self.dataOut.pairsList != None:
91 #calculo de cross-spectra
91 #calculo de cross-spectra
92 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
92 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
93 for pair in self.dataOut.pairsList:
93 for pair in self.dataOut.pairsList:
94 if pair[0] not in self.dataOut.channelList:
94 if pair[0] not in self.dataOut.channelList:
95 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
95 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
96 if pair[1] not in self.dataOut.channelList:
96 if pair[1] not in self.dataOut.channelList:
97 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
97 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
98
98
99 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
99 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
100 pairIndex += 1
100 pairIndex += 1
101 blocksize += cspc.size
101 blocksize += cspc.size
102
102
103 self.dataOut.data_spc = spc
103 self.dataOut.data_spc = spc
104 self.dataOut.data_cspc = cspc
104 self.dataOut.data_cspc = cspc
105 self.dataOut.data_dc = dc
105 self.dataOut.data_dc = dc
106 self.dataOut.blockSize = blocksize
106 self.dataOut.blockSize = blocksize
107 self.dataOut.flagShiftFFT = True
107 self.dataOut.flagShiftFFT = True
108
108
109 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
109 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
110
110
111 self.dataOut.flagNoData = True
111 self.dataOut.flagNoData = True
112
112
113 if self.dataIn.type == "Spectra":
113 if self.dataIn.type == "Spectra":
114 self.dataOut.copy(self.dataIn)
114 self.dataOut.copy(self.dataIn)
115 # self.__selectPairs(pairsList)
115 # self.__selectPairs(pairsList)
116 return True
116 return True
117
117
118 if self.dataIn.type == "Voltage":
118 if self.dataIn.type == "Voltage":
119
119
120 if nFFTPoints == None:
120 if nFFTPoints == None:
121 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
121 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
122
122
123 if nProfiles == None:
123 if nProfiles == None:
124 nProfiles = nFFTPoints
124 nProfiles = nFFTPoints
125
125
126 if ippFactor == None:
126 if ippFactor == None:
127 ippFactor = 1
127 ippFactor = 1
128
128
129 self.dataOut.ippFactor = ippFactor
129 self.dataOut.ippFactor = ippFactor
130
130
131 self.dataOut.nFFTPoints = nFFTPoints
131 self.dataOut.nFFTPoints = nFFTPoints
132 self.dataOut.pairsList = pairsList
132 self.dataOut.pairsList = pairsList
133
133
134 if self.buffer is None:
134 if self.buffer is None:
135 self.buffer = numpy.zeros( (self.dataIn.nChannels,
135 self.buffer = numpy.zeros( (self.dataIn.nChannels,
136 nProfiles,
136 nProfiles,
137 self.dataIn.nHeights),
137 self.dataIn.nHeights),
138 dtype='complex')
138 dtype='complex')
139
139
140 if self.dataIn.flagDataAsBlock:
140 if self.dataIn.flagDataAsBlock:
141 #data dimension: [nChannels, nProfiles, nSamples]
141 #data dimension: [nChannels, nProfiles, nSamples]
142
142
143 nVoltProfiles = self.dataIn.data.shape[1]
143 nVoltProfiles = self.dataIn.data.shape[1]
144 # nVoltProfiles = self.dataIn.nProfiles
144 # nVoltProfiles = self.dataIn.nProfiles
145
145
146 if nVoltProfiles == nProfiles:
146 if nVoltProfiles == nProfiles:
147 self.buffer = self.dataIn.data.copy()
147 self.buffer = self.dataIn.data.copy()
148 self.profIndex = nVoltProfiles
148 self.profIndex = nVoltProfiles
149
149
150 elif nVoltProfiles < nProfiles:
150 elif nVoltProfiles < nProfiles:
151
151
152 if self.profIndex == 0:
152 if self.profIndex == 0:
153 self.id_min = 0
153 self.id_min = 0
154 self.id_max = nVoltProfiles
154 self.id_max = nVoltProfiles
155
155
156 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
156 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
157 self.profIndex += nVoltProfiles
157 self.profIndex += nVoltProfiles
158 self.id_min += nVoltProfiles
158 self.id_min += nVoltProfiles
159 self.id_max += nVoltProfiles
159 self.id_max += nVoltProfiles
160 else:
160 else:
161 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
161 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
162 self.dataOut.flagNoData = True
162 self.dataOut.flagNoData = True
163 return 0
163 return 0
164 else:
164 else:
165 print 'DATA shape', self.dataIn.data.shape
165
166 sadsdf
167 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
166 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
168 self.profIndex += 1
167 self.profIndex += 1
169
168
170 if self.firstdatatime == None:
169 if self.firstdatatime == None:
171 self.firstdatatime = self.dataIn.utctime
170 self.firstdatatime = self.dataIn.utctime
172
171
173 if self.profIndex == nProfiles:
172 if self.profIndex == nProfiles:
174 self.__updateSpecFromVoltage()
173 self.__updateSpecFromVoltage()
175 self.__getFft()
174 self.__getFft()
176
175
177 self.dataOut.flagNoData = False
176 self.dataOut.flagNoData = False
178 self.firstdatatime = None
177 self.firstdatatime = None
179 self.profIndex = 0
178 self.profIndex = 0
180
179
181 return True
180 return True
182
181
183 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
182 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
184
183
185 def __selectPairs(self, pairsList):
184 def __selectPairs(self, pairsList):
186
185
187 if channelList == None:
186 if channelList == None:
188 return
187 return
189
188
190 pairsIndexListSelected = []
189 pairsIndexListSelected = []
191
190
192 for thisPair in pairsList:
191 for thisPair in pairsList:
193
192
194 if thisPair not in self.dataOut.pairsList:
193 if thisPair not in self.dataOut.pairsList:
195 continue
194 continue
196
195
197 pairIndex = self.dataOut.pairsList.index(thisPair)
196 pairIndex = self.dataOut.pairsList.index(thisPair)
198
197
199 pairsIndexListSelected.append(pairIndex)
198 pairsIndexListSelected.append(pairIndex)
200
199
201 if not pairsIndexListSelected:
200 if not pairsIndexListSelected:
202 self.dataOut.data_cspc = None
201 self.dataOut.data_cspc = None
203 self.dataOut.pairsList = []
202 self.dataOut.pairsList = []
204 return
203 return
205
204
206 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
205 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
207 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
206 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
208
207
209 return
208 return
210
209
211 def __selectPairsByChannel(self, channelList=None):
210 def __selectPairsByChannel(self, channelList=None):
212
211
213 if channelList == None:
212 if channelList == None:
214 return
213 return
215
214
216 pairsIndexListSelected = []
215 pairsIndexListSelected = []
217 for pairIndex in self.dataOut.pairsIndexList:
216 for pairIndex in self.dataOut.pairsIndexList:
218 #First pair
217 #First pair
219 if self.dataOut.pairsList[pairIndex][0] not in channelList:
218 if self.dataOut.pairsList[pairIndex][0] not in channelList:
220 continue
219 continue
221 #Second pair
220 #Second pair
222 if self.dataOut.pairsList[pairIndex][1] not in channelList:
221 if self.dataOut.pairsList[pairIndex][1] not in channelList:
223 continue
222 continue
224
223
225 pairsIndexListSelected.append(pairIndex)
224 pairsIndexListSelected.append(pairIndex)
226
225
227 if not pairsIndexListSelected:
226 if not pairsIndexListSelected:
228 self.dataOut.data_cspc = None
227 self.dataOut.data_cspc = None
229 self.dataOut.pairsList = []
228 self.dataOut.pairsList = []
230 return
229 return
231
230
232 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
231 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
233 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
232 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
234
233
235 return
234 return
236
235
237 def selectChannels(self, channelList):
236 def selectChannels(self, channelList):
238
237
239 channelIndexList = []
238 channelIndexList = []
240
239
241 for channel in channelList:
240 for channel in channelList:
242 if channel not in self.dataOut.channelList:
241 if channel not in self.dataOut.channelList:
243 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
242 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
244
243
245 index = self.dataOut.channelList.index(channel)
244 index = self.dataOut.channelList.index(channel)
246 channelIndexList.append(index)
245 channelIndexList.append(index)
247
246
248 self.selectChannelsByIndex(channelIndexList)
247 self.selectChannelsByIndex(channelIndexList)
249
248
250 def selectChannelsByIndex(self, channelIndexList):
249 def selectChannelsByIndex(self, channelIndexList):
251 """
250 """
252 Selecciona un bloque de datos en base a canales segun el channelIndexList
251 Selecciona un bloque de datos en base a canales segun el channelIndexList
253
252
254 Input:
253 Input:
255 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
254 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
256
255
257 Affected:
256 Affected:
258 self.dataOut.data_spc
257 self.dataOut.data_spc
259 self.dataOut.channelIndexList
258 self.dataOut.channelIndexList
260 self.dataOut.nChannels
259 self.dataOut.nChannels
261
260
262 Return:
261 Return:
263 None
262 None
264 """
263 """
265
264
266 for channelIndex in channelIndexList:
265 for channelIndex in channelIndexList:
267 if channelIndex not in self.dataOut.channelIndexList:
266 if channelIndex not in self.dataOut.channelIndexList:
268 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
267 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
269
268
270 # nChannels = len(channelIndexList)
269 # nChannels = len(channelIndexList)
271
270
272 data_spc = self.dataOut.data_spc[channelIndexList,:]
271 data_spc = self.dataOut.data_spc[channelIndexList,:]
273 data_dc = self.dataOut.data_dc[channelIndexList,:]
272 data_dc = self.dataOut.data_dc[channelIndexList,:]
274
273
275 self.dataOut.data_spc = data_spc
274 self.dataOut.data_spc = data_spc
276 self.dataOut.data_dc = data_dc
275 self.dataOut.data_dc = data_dc
277
276
278 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
277 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
279 # self.dataOut.nChannels = nChannels
278 # self.dataOut.nChannels = nChannels
280
279
281 self.__selectPairsByChannel(self.dataOut.channelList)
280 self.__selectPairsByChannel(self.dataOut.channelList)
282
281
283 return 1
282 return 1
284
283
285
284
286 def selectFFTs(self, minFFT, maxFFT ):
285 def selectFFTs(self, minFFT, maxFFT ):
287 """
286 """
288 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
287 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
289 minFFT<= FFT <= maxFFT
288 minFFT<= FFT <= maxFFT
290 """
289 """
291
290
292 if (minFFT > maxFFT):
291 if (minFFT > maxFFT):
293 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)
292 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)
294
293
295 if (minFFT < self.dataOut.getFreqRange()[0]):
294 if (minFFT < self.dataOut.getFreqRange()[0]):
296 minFFT = self.dataOut.getFreqRange()[0]
295 minFFT = self.dataOut.getFreqRange()[0]
297
296
298 if (maxFFT > self.dataOut.getFreqRange()[-1]):
297 if (maxFFT > self.dataOut.getFreqRange()[-1]):
299 maxFFT = self.dataOut.getFreqRange()[-1]
298 maxFFT = self.dataOut.getFreqRange()[-1]
300
299
301 minIndex = 0
300 minIndex = 0
302 maxIndex = 0
301 maxIndex = 0
303 FFTs = self.dataOut.getFreqRange()
302 FFTs = self.dataOut.getFreqRange()
304
303
305 inda = numpy.where(FFTs >= minFFT)
304 inda = numpy.where(FFTs >= minFFT)
306 indb = numpy.where(FFTs <= maxFFT)
305 indb = numpy.where(FFTs <= maxFFT)
307
306
308 try:
307 try:
309 minIndex = inda[0][0]
308 minIndex = inda[0][0]
310 except:
309 except:
311 minIndex = 0
310 minIndex = 0
312
311
313 try:
312 try:
314 maxIndex = indb[0][-1]
313 maxIndex = indb[0][-1]
315 except:
314 except:
316 maxIndex = len(FFTs)
315 maxIndex = len(FFTs)
317
316
318 self.selectFFTsByIndex(minIndex, maxIndex)
317 self.selectFFTsByIndex(minIndex, maxIndex)
319
318
320 return 1
319 return 1
321
320
322
321
323
322
324 def selectHeights(self, minHei, maxHei):
323 def selectHeights(self, minHei, maxHei):
325 """
324 """
326 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
325 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
327 minHei <= height <= maxHei
326 minHei <= height <= maxHei
328
327
329 Input:
328 Input:
330 minHei : valor minimo de altura a considerar
329 minHei : valor minimo de altura a considerar
331 maxHei : valor maximo de altura a considerar
330 maxHei : valor maximo de altura a considerar
332
331
333 Affected:
332 Affected:
334 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
333 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
335
334
336 Return:
335 Return:
337 1 si el metodo se ejecuto con exito caso contrario devuelve 0
336 1 si el metodo se ejecuto con exito caso contrario devuelve 0
338 """
337 """
339
338
340
339
341 if (minHei > maxHei):
340 if (minHei > maxHei):
342 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
341 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
343
342
344 if (minHei < self.dataOut.heightList[0]):
343 if (minHei < self.dataOut.heightList[0]):
345 minHei = self.dataOut.heightList[0]
344 minHei = self.dataOut.heightList[0]
346
345
347 if (maxHei > self.dataOut.heightList[-1]):
346 if (maxHei > self.dataOut.heightList[-1]):
348 maxHei = self.dataOut.heightList[-1]
347 maxHei = self.dataOut.heightList[-1]
349
348
350 minIndex = 0
349 minIndex = 0
351 maxIndex = 0
350 maxIndex = 0
352 heights = self.dataOut.heightList
351 heights = self.dataOut.heightList
353
352
354 inda = numpy.where(heights >= minHei)
353 inda = numpy.where(heights >= minHei)
355 indb = numpy.where(heights <= maxHei)
354 indb = numpy.where(heights <= maxHei)
356
355
357 try:
356 try:
358 minIndex = inda[0][0]
357 minIndex = inda[0][0]
359 except:
358 except:
360 minIndex = 0
359 minIndex = 0
361
360
362 try:
361 try:
363 maxIndex = indb[0][-1]
362 maxIndex = indb[0][-1]
364 except:
363 except:
365 maxIndex = len(heights)
364 maxIndex = len(heights)
366
365
367 self.selectHeightsByIndex(minIndex, maxIndex)
366 self.selectHeightsByIndex(minIndex, maxIndex)
368
367
369
368
370 return 1
369 return 1
371
370
372 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
371 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
373 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
372 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
374
373
375 if hei_ref != None:
374 if hei_ref != None:
376 newheis = numpy.where(self.dataOut.heightList>hei_ref)
375 newheis = numpy.where(self.dataOut.heightList>hei_ref)
377
376
378 minIndex = min(newheis[0])
377 minIndex = min(newheis[0])
379 maxIndex = max(newheis[0])
378 maxIndex = max(newheis[0])
380 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
379 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
381 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
380 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
382
381
383 # determina indices
382 # determina indices
384 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
383 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
385 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
384 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
386 beacon_dB = numpy.sort(avg_dB)[-nheis:]
385 beacon_dB = numpy.sort(avg_dB)[-nheis:]
387 beacon_heiIndexList = []
386 beacon_heiIndexList = []
388 for val in avg_dB.tolist():
387 for val in avg_dB.tolist():
389 if val >= beacon_dB[0]:
388 if val >= beacon_dB[0]:
390 beacon_heiIndexList.append(avg_dB.tolist().index(val))
389 beacon_heiIndexList.append(avg_dB.tolist().index(val))
391
390
392 #data_spc = data_spc[:,:,beacon_heiIndexList]
391 #data_spc = data_spc[:,:,beacon_heiIndexList]
393 data_cspc = None
392 data_cspc = None
394 if self.dataOut.data_cspc is not None:
393 if self.dataOut.data_cspc is not None:
395 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
394 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
396 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
395 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
397
396
398 data_dc = None
397 data_dc = None
399 if self.dataOut.data_dc is not None:
398 if self.dataOut.data_dc is not None:
400 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
399 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
401 #data_dc = data_dc[:,beacon_heiIndexList]
400 #data_dc = data_dc[:,beacon_heiIndexList]
402
401
403 self.dataOut.data_spc = data_spc
402 self.dataOut.data_spc = data_spc
404 self.dataOut.data_cspc = data_cspc
403 self.dataOut.data_cspc = data_cspc
405 self.dataOut.data_dc = data_dc
404 self.dataOut.data_dc = data_dc
406 self.dataOut.heightList = heightList
405 self.dataOut.heightList = heightList
407 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
406 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
408
407
409 return 1
408 return 1
410
409
411 def selectFFTsByIndex(self, minIndex, maxIndex):
410 def selectFFTsByIndex(self, minIndex, maxIndex):
412 """
411 """
413
412
414 """
413 """
415
414
416 if (minIndex < 0) or (minIndex > maxIndex):
415 if (minIndex < 0) or (minIndex > maxIndex):
417 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
416 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
418
417
419 if (maxIndex >= self.dataOut.nProfiles):
418 if (maxIndex >= self.dataOut.nProfiles):
420 maxIndex = self.dataOut.nProfiles-1
419 maxIndex = self.dataOut.nProfiles-1
421
420
422 #Spectra
421 #Spectra
423 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
422 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
424
423
425 data_cspc = None
424 data_cspc = None
426 if self.dataOut.data_cspc is not None:
425 if self.dataOut.data_cspc is not None:
427 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
426 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
428
427
429 data_dc = None
428 data_dc = None
430 if self.dataOut.data_dc is not None:
429 if self.dataOut.data_dc is not None:
431 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
430 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
432
431
433 self.dataOut.data_spc = data_spc
432 self.dataOut.data_spc = data_spc
434 self.dataOut.data_cspc = data_cspc
433 self.dataOut.data_cspc = data_cspc
435 self.dataOut.data_dc = data_dc
434 self.dataOut.data_dc = data_dc
436
435
437 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
436 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
438 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
437 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
439 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
438 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
440
439
441 #self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
440 #self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
442
441
443 return 1
442 return 1
444
443
445
444
446
445
447 def selectHeightsByIndex(self, minIndex, maxIndex):
446 def selectHeightsByIndex(self, minIndex, maxIndex):
448 """
447 """
449 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
448 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
450 minIndex <= index <= maxIndex
449 minIndex <= index <= maxIndex
451
450
452 Input:
451 Input:
453 minIndex : valor de indice minimo de altura a considerar
452 minIndex : valor de indice minimo de altura a considerar
454 maxIndex : valor de indice maximo de altura a considerar
453 maxIndex : valor de indice maximo de altura a considerar
455
454
456 Affected:
455 Affected:
457 self.dataOut.data_spc
456 self.dataOut.data_spc
458 self.dataOut.data_cspc
457 self.dataOut.data_cspc
459 self.dataOut.data_dc
458 self.dataOut.data_dc
460 self.dataOut.heightList
459 self.dataOut.heightList
461
460
462 Return:
461 Return:
463 1 si el metodo se ejecuto con exito caso contrario devuelve 0
462 1 si el metodo se ejecuto con exito caso contrario devuelve 0
464 """
463 """
465
464
466 if (minIndex < 0) or (minIndex > maxIndex):
465 if (minIndex < 0) or (minIndex > maxIndex):
467 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
466 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
468
467
469 if (maxIndex >= self.dataOut.nHeights):
468 if (maxIndex >= self.dataOut.nHeights):
470 maxIndex = self.dataOut.nHeights-1
469 maxIndex = self.dataOut.nHeights-1
471
470
472 #Spectra
471 #Spectra
473 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
472 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
474
473
475 data_cspc = None
474 data_cspc = None
476 if self.dataOut.data_cspc is not None:
475 if self.dataOut.data_cspc is not None:
477 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
476 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
478
477
479 data_dc = None
478 data_dc = None
480 if self.dataOut.data_dc is not None:
479 if self.dataOut.data_dc is not None:
481 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
480 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
482
481
483 self.dataOut.data_spc = data_spc
482 self.dataOut.data_spc = data_spc
484 self.dataOut.data_cspc = data_cspc
483 self.dataOut.data_cspc = data_cspc
485 self.dataOut.data_dc = data_dc
484 self.dataOut.data_dc = data_dc
486
485
487 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
486 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
488
487
489 return 1
488 return 1
490
489
491
490
492 def removeDC(self, mode = 2):
491 def removeDC(self, mode = 2):
493 jspectra = self.dataOut.data_spc
492 jspectra = self.dataOut.data_spc
494 jcspectra = self.dataOut.data_cspc
493 jcspectra = self.dataOut.data_cspc
495
494
496
495
497 num_chan = jspectra.shape[0]
496 num_chan = jspectra.shape[0]
498 num_hei = jspectra.shape[2]
497 num_hei = jspectra.shape[2]
499
498
500 if jcspectra is not None:
499 if jcspectra is not None:
501 jcspectraExist = True
500 jcspectraExist = True
502 num_pairs = jcspectra.shape[0]
501 num_pairs = jcspectra.shape[0]
503 else: jcspectraExist = False
502 else: jcspectraExist = False
504
503
505 freq_dc = jspectra.shape[1]/2
504 freq_dc = jspectra.shape[1]/2
506 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
505 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
507
506
508 if ind_vel[0]<0:
507 if ind_vel[0]<0:
509 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
508 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
510
509
511 if mode == 1:
510 if mode == 1:
512 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
511 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
513
512
514 if jcspectraExist:
513 if jcspectraExist:
515 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
514 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
516
515
517 if mode == 2:
516 if mode == 2:
518
517
519 vel = numpy.array([-2,-1,1,2])
518 vel = numpy.array([-2,-1,1,2])
520 xx = numpy.zeros([4,4])
519 xx = numpy.zeros([4,4])
521
520
522 for fil in range(4):
521 for fil in range(4):
523 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
522 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
524
523
525 xx_inv = numpy.linalg.inv(xx)
524 xx_inv = numpy.linalg.inv(xx)
526 xx_aux = xx_inv[0,:]
525 xx_aux = xx_inv[0,:]
527
526
528 for ich in range(num_chan):
527 for ich in range(num_chan):
529 yy = jspectra[ich,ind_vel,:]
528 yy = jspectra[ich,ind_vel,:]
530 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
529 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
531
530
532 junkid = jspectra[ich,freq_dc,:]<=0
531 junkid = jspectra[ich,freq_dc,:]<=0
533 cjunkid = sum(junkid)
532 cjunkid = sum(junkid)
534
533
535 if cjunkid.any():
534 if cjunkid.any():
536 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
535 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
537
536
538 if jcspectraExist:
537 if jcspectraExist:
539 for ip in range(num_pairs):
538 for ip in range(num_pairs):
540 yy = jcspectra[ip,ind_vel,:]
539 yy = jcspectra[ip,ind_vel,:]
541 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
540 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
542
541
543
542
544 self.dataOut.data_spc = jspectra
543 self.dataOut.data_spc = jspectra
545 self.dataOut.data_cspc = jcspectra
544 self.dataOut.data_cspc = jcspectra
546
545
547 return 1
546 return 1
548
547
549 def removeInterference2(self):
548 def removeInterference2(self):
550
549
551 cspc = self.dataOut.data_cspc
550 cspc = self.dataOut.data_cspc
552 spc = self.dataOut.data_spc
551 spc = self.dataOut.data_spc
553 print numpy.shape(spc)
552 print numpy.shape(spc)
554 Heights = numpy.arange(cspc.shape[2])
553 Heights = numpy.arange(cspc.shape[2])
555 realCspc = numpy.abs(cspc)
554 realCspc = numpy.abs(cspc)
556
555
557 for i in range(cspc.shape[0]):
556 for i in range(cspc.shape[0]):
558 LinePower= numpy.sum(realCspc[i], axis=0)
557 LinePower= numpy.sum(realCspc[i], axis=0)
559 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
558 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
560 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
559 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
561 #print numpy.shape(realCspc)
560 #print numpy.shape(realCspc)
562 #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
561 #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
563 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
562 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
564 print SelectedHeights
563 print SelectedHeights
565 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
564 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
566 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
565 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
567
566
568
567
569 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
568 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
570 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
569 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
571 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
570 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
572 cspc[i,InterferenceRange,:] = numpy.NaN
571 cspc[i,InterferenceRange,:] = numpy.NaN
573
572
574 print '########################################################################################'
573 print '########################################################################################'
575 print 'Len interference sum',len(InterferenceSum)
574 print 'Len interference sum',len(InterferenceSum)
576 print 'InterferenceThresholdMin', InterferenceThresholdMin, 'InterferenceThresholdMax', InterferenceThresholdMax
575 print 'InterferenceThresholdMin', InterferenceThresholdMin, 'InterferenceThresholdMax', InterferenceThresholdMax
577 print 'InterferenceRange',InterferenceRange
576 print 'InterferenceRange',InterferenceRange
578 print '########################################################################################'
577 print '########################################################################################'
579
578
580 ''' Ploteo '''
579 ''' Ploteo '''
581
580
582 #for i in range(3):
581 #for i in range(3):
583 #print 'FASE', numpy.shape(phase), y[25]
582 #print 'FASE', numpy.shape(phase), y[25]
584 #print numpy.shape(coherence)
583 #print numpy.shape(coherence)
585 #fig = plt.figure(10+ int(numpy.random.rand()*100))
584 #fig = plt.figure(10+ int(numpy.random.rand()*100))
586 #plt.plot( x[0:256],coherence[:,25] )
585 #plt.plot( x[0:256],coherence[:,25] )
587 #cohAv = numpy.average(coherence[i],1)
586 #cohAv = numpy.average(coherence[i],1)
588 #Pendiente = FrecRange * PhaseSlope[i]
587 #Pendiente = FrecRange * PhaseSlope[i]
589 #plt.plot( InterferenceSum)
588 #plt.plot( InterferenceSum)
590 #plt.plot( numpy.sort(InterferenceSum))
589 #plt.plot( numpy.sort(InterferenceSum))
591 #plt.plot( LinePower )
590 #plt.plot( LinePower )
592 #plt.plot( xFrec,phase[i])
591 #plt.plot( xFrec,phase[i])
593
592
594 #CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
593 #CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
595 #plt.plot(xFrec, FitGauss01)
594 #plt.plot(xFrec, FitGauss01)
596 #plt.plot(xFrec, CSPCmean)
595 #plt.plot(xFrec, CSPCmean)
597 #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
596 #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
598 #plt.plot(xFrec, FitGauss)
597 #plt.plot(xFrec, FitGauss)
599 #plt.plot(xFrec, yMean)
598 #plt.plot(xFrec, yMean)
600 #plt.plot(xFrec, numpy.abs(coherence[0]))
599 #plt.plot(xFrec, numpy.abs(coherence[0]))
601
600
602 #plt.axis([-12, 12, 15, 50])
601 #plt.axis([-12, 12, 15, 50])
603 #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
602 #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
604
603
605
604
606 #fig.savefig('/home/erick/Documents/Pics/nom{}.png'.format(int(numpy.random.rand()*100)))
605 #fig.savefig('/home/erick/Documents/Pics/nom{}.png'.format(int(numpy.random.rand()*100)))
607
606
608 #plt.show()
607 #plt.show()
609 #self.indice=self.indice+1
608 #self.indice=self.indice+1
610 #raise
609 #raise
611
610
612
611
613 self.dataOut.data_cspc = cspc
612 self.dataOut.data_cspc = cspc
614
613
615 # for i in range(spc.shape[0]):
614 # for i in range(spc.shape[0]):
616 # LinePower= numpy.sum(spc[i], axis=0)
615 # LinePower= numpy.sum(spc[i], axis=0)
617 # Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
616 # Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
618 # SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
617 # SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
619 # #print numpy.shape(realCspc)
618 # #print numpy.shape(realCspc)
620 # #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
619 # #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
621 # InterferenceSum = numpy.sum( spc[i,:,SelectedHeights], axis=0 )
620 # InterferenceSum = numpy.sum( spc[i,:,SelectedHeights], axis=0 )
622 # InterferenceThreshold = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
621 # InterferenceThreshold = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
623 # InterferenceRange = numpy.where( InterferenceSum > InterferenceThreshold )
622 # InterferenceRange = numpy.where( InterferenceSum > InterferenceThreshold )
624 # if len(InterferenceRange)<int(spc.shape[1]*0.03):
623 # if len(InterferenceRange)<int(spc.shape[1]*0.03):
625 # spc[i,InterferenceRange,:] = numpy.NaN
624 # spc[i,InterferenceRange,:] = numpy.NaN
626
625
627 #self.dataOut.data_spc = spc
626 #self.dataOut.data_spc = spc
628
627
629 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
628 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
630
629
631 jspectra = self.dataOut.data_spc
630 jspectra = self.dataOut.data_spc
632 jcspectra = self.dataOut.data_cspc
631 jcspectra = self.dataOut.data_cspc
633 jnoise = self.dataOut.getNoise()
632 jnoise = self.dataOut.getNoise()
634 num_incoh = self.dataOut.nIncohInt
633 num_incoh = self.dataOut.nIncohInt
635
634
636 num_channel = jspectra.shape[0]
635 num_channel = jspectra.shape[0]
637 num_prof = jspectra.shape[1]
636 num_prof = jspectra.shape[1]
638 num_hei = jspectra.shape[2]
637 num_hei = jspectra.shape[2]
639
638
640 #hei_interf
639 #hei_interf
641 if hei_interf is None:
640 if hei_interf is None:
642 count_hei = num_hei/2 #Como es entero no importa
641 count_hei = num_hei/2 #Como es entero no importa
643 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
642 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
644 hei_interf = numpy.asarray(hei_interf)[0]
643 hei_interf = numpy.asarray(hei_interf)[0]
645 #nhei_interf
644 #nhei_interf
646 if (nhei_interf == None):
645 if (nhei_interf == None):
647 nhei_interf = 5
646 nhei_interf = 5
648 if (nhei_interf < 1):
647 if (nhei_interf < 1):
649 nhei_interf = 1
648 nhei_interf = 1
650 if (nhei_interf > count_hei):
649 if (nhei_interf > count_hei):
651 nhei_interf = count_hei
650 nhei_interf = count_hei
652 if (offhei_interf == None):
651 if (offhei_interf == None):
653 offhei_interf = 0
652 offhei_interf = 0
654
653
655 ind_hei = range(num_hei)
654 ind_hei = range(num_hei)
656 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
655 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
657 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
656 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
658 mask_prof = numpy.asarray(range(num_prof))
657 mask_prof = numpy.asarray(range(num_prof))
659 num_mask_prof = mask_prof.size
658 num_mask_prof = mask_prof.size
660 comp_mask_prof = [0, num_prof/2]
659 comp_mask_prof = [0, num_prof/2]
661
660
662
661
663 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
662 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
664 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
663 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
665 jnoise = numpy.nan
664 jnoise = numpy.nan
666 noise_exist = jnoise[0] < numpy.Inf
665 noise_exist = jnoise[0] < numpy.Inf
667
666
668 #Subrutina de Remocion de la Interferencia
667 #Subrutina de Remocion de la Interferencia
669 for ich in range(num_channel):
668 for ich in range(num_channel):
670 #Se ordena los espectros segun su potencia (menor a mayor)
669 #Se ordena los espectros segun su potencia (menor a mayor)
671 power = jspectra[ich,mask_prof,:]
670 power = jspectra[ich,mask_prof,:]
672 power = power[:,hei_interf]
671 power = power[:,hei_interf]
673 power = power.sum(axis = 0)
672 power = power.sum(axis = 0)
674 psort = power.ravel().argsort()
673 psort = power.ravel().argsort()
675
674
676 #Se estima la interferencia promedio en los Espectros de Potencia empleando
675 #Se estima la interferencia promedio en los Espectros de Potencia empleando
677 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
676 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
678
677
679 if noise_exist:
678 if noise_exist:
680 # tmp_noise = jnoise[ich] / num_prof
679 # tmp_noise = jnoise[ich] / num_prof
681 tmp_noise = jnoise[ich]
680 tmp_noise = jnoise[ich]
682 junkspc_interf = junkspc_interf - tmp_noise
681 junkspc_interf = junkspc_interf - tmp_noise
683 #junkspc_interf[:,comp_mask_prof] = 0
682 #junkspc_interf[:,comp_mask_prof] = 0
684
683
685 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
684 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
686 jspc_interf = jspc_interf.transpose()
685 jspc_interf = jspc_interf.transpose()
687 #Calculando el espectro de interferencia promedio
686 #Calculando el espectro de interferencia promedio
688 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
687 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
689 noiseid = noiseid[0]
688 noiseid = noiseid[0]
690 cnoiseid = noiseid.size
689 cnoiseid = noiseid.size
691 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
690 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
692 interfid = interfid[0]
691 interfid = interfid[0]
693 cinterfid = interfid.size
692 cinterfid = interfid.size
694
693
695 if (cnoiseid > 0): jspc_interf[noiseid] = 0
694 if (cnoiseid > 0): jspc_interf[noiseid] = 0
696
695
697 #Expandiendo los perfiles a limpiar
696 #Expandiendo los perfiles a limpiar
698 if (cinterfid > 0):
697 if (cinterfid > 0):
699 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
698 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
700 new_interfid = numpy.asarray(new_interfid)
699 new_interfid = numpy.asarray(new_interfid)
701 new_interfid = {x for x in new_interfid}
700 new_interfid = {x for x in new_interfid}
702 new_interfid = numpy.array(list(new_interfid))
701 new_interfid = numpy.array(list(new_interfid))
703 new_cinterfid = new_interfid.size
702 new_cinterfid = new_interfid.size
704 else: new_cinterfid = 0
703 else: new_cinterfid = 0
705
704
706 for ip in range(new_cinterfid):
705 for ip in range(new_cinterfid):
707 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
706 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
708 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
707 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
709
708
710
709
711 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
710 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
712
711
713 #Removiendo la interferencia del punto de mayor interferencia
712 #Removiendo la interferencia del punto de mayor interferencia
714 ListAux = jspc_interf[mask_prof].tolist()
713 ListAux = jspc_interf[mask_prof].tolist()
715 maxid = ListAux.index(max(ListAux))
714 maxid = ListAux.index(max(ListAux))
716
715
717
716
718 if cinterfid > 0:
717 if cinterfid > 0:
719 for ip in range(cinterfid*(interf == 2) - 1):
718 for ip in range(cinterfid*(interf == 2) - 1):
720 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
719 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
721 cind = len(ind)
720 cind = len(ind)
722
721
723 if (cind > 0):
722 if (cind > 0):
724 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
723 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
725
724
726 ind = numpy.array([-2,-1,1,2])
725 ind = numpy.array([-2,-1,1,2])
727 xx = numpy.zeros([4,4])
726 xx = numpy.zeros([4,4])
728
727
729 for id1 in range(4):
728 for id1 in range(4):
730 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
729 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
731
730
732 xx_inv = numpy.linalg.inv(xx)
731 xx_inv = numpy.linalg.inv(xx)
733 xx = xx_inv[:,0]
732 xx = xx_inv[:,0]
734 ind = (ind + maxid + num_mask_prof)%num_mask_prof
733 ind = (ind + maxid + num_mask_prof)%num_mask_prof
735 yy = jspectra[ich,mask_prof[ind],:]
734 yy = jspectra[ich,mask_prof[ind],:]
736 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
735 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
737
736
738
737
739 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
738 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
740 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
739 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
741
740
742 #Remocion de Interferencia en el Cross Spectra
741 #Remocion de Interferencia en el Cross Spectra
743 if jcspectra is None: return jspectra, jcspectra
742 if jcspectra is None: return jspectra, jcspectra
744 num_pairs = jcspectra.size/(num_prof*num_hei)
743 num_pairs = jcspectra.size/(num_prof*num_hei)
745 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
744 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
746
745
747 for ip in range(num_pairs):
746 for ip in range(num_pairs):
748
747
749 #-------------------------------------------
748 #-------------------------------------------
750
749
751 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
750 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
752 cspower = cspower[:,hei_interf]
751 cspower = cspower[:,hei_interf]
753 cspower = cspower.sum(axis = 0)
752 cspower = cspower.sum(axis = 0)
754
753
755 cspsort = cspower.ravel().argsort()
754 cspsort = cspower.ravel().argsort()
756 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
755 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
757 junkcspc_interf = junkcspc_interf.transpose()
756 junkcspc_interf = junkcspc_interf.transpose()
758 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
757 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
759
758
760 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
759 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
761
760
762 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
761 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
763 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
762 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
764 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
763 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
765
764
766 for iprof in range(num_prof):
765 for iprof in range(num_prof):
767 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
766 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
768 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
767 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
769
768
770 #Removiendo la Interferencia
769 #Removiendo la Interferencia
771 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
770 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
772
771
773 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
772 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
774 maxid = ListAux.index(max(ListAux))
773 maxid = ListAux.index(max(ListAux))
775
774
776 ind = numpy.array([-2,-1,1,2])
775 ind = numpy.array([-2,-1,1,2])
777 xx = numpy.zeros([4,4])
776 xx = numpy.zeros([4,4])
778
777
779 for id1 in range(4):
778 for id1 in range(4):
780 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
779 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
781
780
782 xx_inv = numpy.linalg.inv(xx)
781 xx_inv = numpy.linalg.inv(xx)
783 xx = xx_inv[:,0]
782 xx = xx_inv[:,0]
784
783
785 ind = (ind + maxid + num_mask_prof)%num_mask_prof
784 ind = (ind + maxid + num_mask_prof)%num_mask_prof
786 yy = jcspectra[ip,mask_prof[ind],:]
785 yy = jcspectra[ip,mask_prof[ind],:]
787 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
786 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
788
787
789 #Guardar Resultados
788 #Guardar Resultados
790 self.dataOut.data_spc = jspectra
789 self.dataOut.data_spc = jspectra
791 self.dataOut.data_cspc = jcspectra
790 self.dataOut.data_cspc = jcspectra
792
791
793 return 1
792 return 1
794
793
795 def setRadarFrequency(self, frequency=None):
794 def setRadarFrequency(self, frequency=None):
796
795
797 if frequency != None:
796 if frequency != None:
798 self.dataOut.frequency = frequency
797 self.dataOut.frequency = frequency
799
798
800 return 1
799 return 1
801
800
802 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
801 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
803 #validacion de rango
802 #validacion de rango
804 if minHei == None:
803 if minHei == None:
805 minHei = self.dataOut.heightList[0]
804 minHei = self.dataOut.heightList[0]
806
805
807 if maxHei == None:
806 if maxHei == None:
808 maxHei = self.dataOut.heightList[-1]
807 maxHei = self.dataOut.heightList[-1]
809
808
810 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
809 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
811 print 'minHei: %.2f is out of the heights range'%(minHei)
810 print 'minHei: %.2f is out of the heights range'%(minHei)
812 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
811 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
813 minHei = self.dataOut.heightList[0]
812 minHei = self.dataOut.heightList[0]
814
813
815 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
814 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
816 print 'maxHei: %.2f is out of the heights range'%(maxHei)
815 print 'maxHei: %.2f is out of the heights range'%(maxHei)
817 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
816 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
818 maxHei = self.dataOut.heightList[-1]
817 maxHei = self.dataOut.heightList[-1]
819
818
820 # validacion de velocidades
819 # validacion de velocidades
821 velrange = self.dataOut.getVelRange(1)
820 velrange = self.dataOut.getVelRange(1)
822
821
823 if minVel == None:
822 if minVel == None:
824 minVel = velrange[0]
823 minVel = velrange[0]
825
824
826 if maxVel == None:
825 if maxVel == None:
827 maxVel = velrange[-1]
826 maxVel = velrange[-1]
828
827
829 if (minVel < velrange[0]) or (minVel > maxVel):
828 if (minVel < velrange[0]) or (minVel > maxVel):
830 print 'minVel: %.2f is out of the velocity range'%(minVel)
829 print 'minVel: %.2f is out of the velocity range'%(minVel)
831 print 'minVel is setting to %.2f'%(velrange[0])
830 print 'minVel is setting to %.2f'%(velrange[0])
832 minVel = velrange[0]
831 minVel = velrange[0]
833
832
834 if (maxVel > velrange[-1]) or (maxVel < minVel):
833 if (maxVel > velrange[-1]) or (maxVel < minVel):
835 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
834 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
836 print 'maxVel is setting to %.2f'%(velrange[-1])
835 print 'maxVel is setting to %.2f'%(velrange[-1])
837 maxVel = velrange[-1]
836 maxVel = velrange[-1]
838
837
839 # seleccion de indices para rango
838 # seleccion de indices para rango
840 minIndex = 0
839 minIndex = 0
841 maxIndex = 0
840 maxIndex = 0
842 heights = self.dataOut.heightList
841 heights = self.dataOut.heightList
843
842
844 inda = numpy.where(heights >= minHei)
843 inda = numpy.where(heights >= minHei)
845 indb = numpy.where(heights <= maxHei)
844 indb = numpy.where(heights <= maxHei)
846
845
847 try:
846 try:
848 minIndex = inda[0][0]
847 minIndex = inda[0][0]
849 except:
848 except:
850 minIndex = 0
849 minIndex = 0
851
850
852 try:
851 try:
853 maxIndex = indb[0][-1]
852 maxIndex = indb[0][-1]
854 except:
853 except:
855 maxIndex = len(heights)
854 maxIndex = len(heights)
856
855
857 if (minIndex < 0) or (minIndex > maxIndex):
856 if (minIndex < 0) or (minIndex > maxIndex):
858 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
857 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
859
858
860 if (maxIndex >= self.dataOut.nHeights):
859 if (maxIndex >= self.dataOut.nHeights):
861 maxIndex = self.dataOut.nHeights-1
860 maxIndex = self.dataOut.nHeights-1
862
861
863 # seleccion de indices para velocidades
862 # seleccion de indices para velocidades
864 indminvel = numpy.where(velrange >= minVel)
863 indminvel = numpy.where(velrange >= minVel)
865 indmaxvel = numpy.where(velrange <= maxVel)
864 indmaxvel = numpy.where(velrange <= maxVel)
866 try:
865 try:
867 minIndexVel = indminvel[0][0]
866 minIndexVel = indminvel[0][0]
868 except:
867 except:
869 minIndexVel = 0
868 minIndexVel = 0
870
869
871 try:
870 try:
872 maxIndexVel = indmaxvel[0][-1]
871 maxIndexVel = indmaxvel[0][-1]
873 except:
872 except:
874 maxIndexVel = len(velrange)
873 maxIndexVel = len(velrange)
875
874
876 #seleccion del espectro
875 #seleccion del espectro
877 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
876 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
878 #estimacion de ruido
877 #estimacion de ruido
879 noise = numpy.zeros(self.dataOut.nChannels)
878 noise = numpy.zeros(self.dataOut.nChannels)
880
879
881 for channel in range(self.dataOut.nChannels):
880 for channel in range(self.dataOut.nChannels):
882 daux = data_spc[channel,:,:]
881 daux = data_spc[channel,:,:]
883 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
882 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
884
883
885 self.dataOut.noise_estimation = noise.copy()
884 self.dataOut.noise_estimation = noise.copy()
886
885
887 return 1
886 return 1
888
887
889 class IncohInt(Operation):
888 class IncohInt(Operation):
890
889
891
890
892 __profIndex = 0
891 __profIndex = 0
893 __withOverapping = False
892 __withOverapping = False
894
893
895 __byTime = False
894 __byTime = False
896 __initime = None
895 __initime = None
897 __lastdatatime = None
896 __lastdatatime = None
898 __integrationtime = None
897 __integrationtime = None
899
898
900 __buffer_spc = None
899 __buffer_spc = None
901 __buffer_cspc = None
900 __buffer_cspc = None
902 __buffer_dc = None
901 __buffer_dc = None
903
902
904 __dataReady = False
903 __dataReady = False
905
904
906 __timeInterval = None
905 __timeInterval = None
907
906
908 n = None
907 n = None
909
908
910
909
911
910
912 def __init__(self, **kwargs):
911 def __init__(self, **kwargs):
913
912
914 Operation.__init__(self, **kwargs)
913 Operation.__init__(self, **kwargs)
915 # self.isConfig = False
914 # self.isConfig = False
916
915
917 def setup(self, n=None, timeInterval=None, overlapping=False):
916 def setup(self, n=None, timeInterval=None, overlapping=False):
918 """
917 """
919 Set the parameters of the integration class.
918 Set the parameters of the integration class.
920
919
921 Inputs:
920 Inputs:
922
921
923 n : Number of coherent integrations
922 n : Number of coherent integrations
924 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
923 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
925 overlapping :
924 overlapping :
926
925
927 """
926 """
928
927
929 self.__initime = None
928 self.__initime = None
930 self.__lastdatatime = 0
929 self.__lastdatatime = 0
931
930
932 self.__buffer_spc = 0
931 self.__buffer_spc = 0
933 self.__buffer_cspc = 0
932 self.__buffer_cspc = 0
934 self.__buffer_dc = 0
933 self.__buffer_dc = 0
935
934
936 self.__profIndex = 0
935 self.__profIndex = 0
937 self.__dataReady = False
936 self.__dataReady = False
938 self.__byTime = False
937 self.__byTime = False
939
938
940 if n is None and timeInterval is None:
939 if n is None and timeInterval is None:
941 raise ValueError, "n or timeInterval should be specified ..."
940 raise ValueError, "n or timeInterval should be specified ..."
942
941
943 if n is not None:
942 if n is not None:
944 self.n = int(n)
943 self.n = int(n)
945 else:
944 else:
946 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
945 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
947 self.n = None
946 self.n = None
948 self.__byTime = True
947 self.__byTime = True
949
948
950 def putData(self, data_spc, data_cspc, data_dc):
949 def putData(self, data_spc, data_cspc, data_dc):
951
950
952 """
951 """
953 Add a profile to the __buffer_spc and increase in one the __profileIndex
952 Add a profile to the __buffer_spc and increase in one the __profileIndex
954
953
955 """
954 """
956
955
957 self.__buffer_spc += data_spc
956 self.__buffer_spc += data_spc
958
957
959 if data_cspc is None:
958 if data_cspc is None:
960 self.__buffer_cspc = None
959 self.__buffer_cspc = None
961 else:
960 else:
962 self.__buffer_cspc += data_cspc
961 self.__buffer_cspc += data_cspc
963
962
964 if data_dc is None:
963 if data_dc is None:
965 self.__buffer_dc = None
964 self.__buffer_dc = None
966 else:
965 else:
967 self.__buffer_dc += data_dc
966 self.__buffer_dc += data_dc
968
967
969 self.__profIndex += 1
968 self.__profIndex += 1
970
969
971 return
970 return
972
971
973 def pushData(self):
972 def pushData(self):
974 """
973 """
975 Return the sum of the last profiles and the profiles used in the sum.
974 Return the sum of the last profiles and the profiles used in the sum.
976
975
977 Affected:
976 Affected:
978
977
979 self.__profileIndex
978 self.__profileIndex
980
979
981 """
980 """
982
981
983 data_spc = self.__buffer_spc
982 data_spc = self.__buffer_spc
984 data_cspc = self.__buffer_cspc
983 data_cspc = self.__buffer_cspc
985 data_dc = self.__buffer_dc
984 data_dc = self.__buffer_dc
986 n = self.__profIndex
985 n = self.__profIndex
987
986
988 self.__buffer_spc = 0
987 self.__buffer_spc = 0
989 self.__buffer_cspc = 0
988 self.__buffer_cspc = 0
990 self.__buffer_dc = 0
989 self.__buffer_dc = 0
991 self.__profIndex = 0
990 self.__profIndex = 0
992
991
993 return data_spc, data_cspc, data_dc, n
992 return data_spc, data_cspc, data_dc, n
994
993
995 def byProfiles(self, *args):
994 def byProfiles(self, *args):
996
995
997 self.__dataReady = False
996 self.__dataReady = False
998 avgdata_spc = None
997 avgdata_spc = None
999 avgdata_cspc = None
998 avgdata_cspc = None
1000 avgdata_dc = None
999 avgdata_dc = None
1001
1000
1002 self.putData(*args)
1001 self.putData(*args)
1003
1002
1004 if self.__profIndex == self.n:
1003 if self.__profIndex == self.n:
1005
1004
1006 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1005 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1007 self.n = n
1006 self.n = n
1008 self.__dataReady = True
1007 self.__dataReady = True
1009
1008
1010 return avgdata_spc, avgdata_cspc, avgdata_dc
1009 return avgdata_spc, avgdata_cspc, avgdata_dc
1011
1010
1012 def byTime(self, datatime, *args):
1011 def byTime(self, datatime, *args):
1013
1012
1014 self.__dataReady = False
1013 self.__dataReady = False
1015 avgdata_spc = None
1014 avgdata_spc = None
1016 avgdata_cspc = None
1015 avgdata_cspc = None
1017 avgdata_dc = None
1016 avgdata_dc = None
1018
1017
1019 self.putData(*args)
1018 self.putData(*args)
1020
1019
1021 if (datatime - self.__initime) >= self.__integrationtime:
1020 if (datatime - self.__initime) >= self.__integrationtime:
1022 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1021 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1023 self.n = n
1022 self.n = n
1024 self.__dataReady = True
1023 self.__dataReady = True
1025
1024
1026 return avgdata_spc, avgdata_cspc, avgdata_dc
1025 return avgdata_spc, avgdata_cspc, avgdata_dc
1027
1026
1028 def integrate(self, datatime, *args):
1027 def integrate(self, datatime, *args):
1029
1028
1030 if self.__profIndex == 0:
1029 if self.__profIndex == 0:
1031 self.__initime = datatime
1030 self.__initime = datatime
1032
1031
1033 if self.__byTime:
1032 if self.__byTime:
1034 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1033 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1035 else:
1034 else:
1036 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1035 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1037
1036
1038 if not self.__dataReady:
1037 if not self.__dataReady:
1039 return None, None, None, None
1038 return None, None, None, None
1040
1039
1041 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1040 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1042
1041
1043 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1042 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1044
1043
1045 if n==1:
1044 if n==1:
1046 return
1045 return
1047
1046
1048 dataOut.flagNoData = True
1047 dataOut.flagNoData = True
1049
1048
1050 if not self.isConfig:
1049 if not self.isConfig:
1051 self.setup(n, timeInterval, overlapping)
1050 self.setup(n, timeInterval, overlapping)
1052 self.isConfig = True
1051 self.isConfig = True
1053
1052
1054 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1053 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1055 dataOut.data_spc,
1054 dataOut.data_spc,
1056 dataOut.data_cspc,
1055 dataOut.data_cspc,
1057 dataOut.data_dc)
1056 dataOut.data_dc)
1058
1057
1059 if self.__dataReady:
1058 if self.__dataReady:
1060
1059
1061 dataOut.data_spc = avgdata_spc
1060 dataOut.data_spc = avgdata_spc
1062 dataOut.data_cspc = avgdata_cspc
1061 dataOut.data_cspc = avgdata_cspc
1063 dataOut.data_dc = avgdata_dc
1062 dataOut.data_dc = avgdata_dc
1064
1063
1065 dataOut.nIncohInt *= self.n
1064 dataOut.nIncohInt *= self.n
1066 dataOut.utctime = avgdatatime
1065 dataOut.utctime = avgdatatime
1067 dataOut.flagNoData = False
1066 dataOut.flagNoData = False
1068
1067
@@ -1,1 +1,1
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024/d2017234" /><Parameter format="date" id="191113" name="startDate" value="2017/08/22" /><Parameter format="date" id="191114" name="endDate" value="2017/08/22" /><Parameter format="time" id="191115" name="startTime" value="02:00:00" /><Parameter format="time" id="191116" name="endTime" value="06:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="ParamWriter" priority="4" type="other"><Parameter format="str" id="191341" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191342" name="blocksPerFile" value="100" /><Parameter format="list" id="191343" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191344" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self"><Parameter format="pairslist" id="191211" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation><Operation id="19123" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191231" name="n" value="5" /></Operation><Operation id="19124" name="SpectraPlot" priority="4" type="external"><Parameter format="int" id="191241" name="id" value="11" /><Parameter format="str" id="191242" name="wintitle" value="SpectraPlot" /><Parameter format="str" id="191243" name="xaxis" value="frequency" /><Parameter format="float" id="191244" name="ymin" value="1" /><Parameter format="int" id="191245" name="ymax" value="5" /><Parameter format="int" id="191246" name="zmin" value="15" /><Parameter format="int" id="191247" name="zmax" value="50" /><Parameter format="int" id="191248" name="save" value="2" /><Parameter format="int" id="191249" name="save" value="5" /><Parameter format="str" id="191250" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/FirstResults1024" /></Operation><Operation id="19125" name="CrossSpectraPlot" priority="5" type="other"><Parameter format="int" id="191251" name="id" value="2005" /><Parameter format="str" id="191252" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191253" name="xaxis" value="Velocity" /><Parameter format="float" id="191254" name="xmin" value="-10" /><Parameter format="float" id="191255" name="xmax" value="10" /><Parameter format="int" id="191256" name="zmin" value="15" /><Parameter format="int" id="191257" name="zmax" value="50" /><Parameter format="str" id="191258" name="phase_cmap" value="bwr" /><Parameter format="float" id="191259" name="ymin" value="1" /><Parameter format="float" id="191260" name="ymax" value="5" /></Operation></ProcUnit></Project> No newline at end of file
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /><Parameter format="date" id="191113" name="startDate" value="2018/02/01" /><Parameter format="date" id="191114" name="endDate" value="2018/02/01" /><Parameter format="time" id="191115" name="startTime" value="17:00:00" /><Parameter format="time" id="191116" name="endTime" value="20:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralFilters" priority="2" type="other"><Parameter format="float" id="191321" name="Wind_Velocity_Limit" value="2.5" /><Parameter format="float" id="191322" name="Rain_Velocity_Limit" value="1.5" /></Operation><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="WindProfilerPlot" priority="4" type="other"><Parameter format="int" id="191341" name="id" value="4" /><Parameter format="str" id="191342" name="wintitle" value="Wind Profiler" /><Parameter format="float" id="191343" name="xmin" value="17" /><Parameter format="float" id="191344" name="xmax" value="20" /><Parameter format="float" id="191345" name="ymin" value="0" /><Parameter format="int" id="191346" name="ymax" value="8" /><Parameter format="float" id="191347" name="zmin" value="-20" /><Parameter format="float" id="191348" name="zmax" value="20" /><Parameter format="float" id="191349" name="SNRmin" value="-20" /><Parameter format="float" id="191350" name="SNRmax" value="20" /><Parameter format="float" id="191351" name="zmin_ver" value="-200" /><Parameter format="float" id="191352" name="zmax_ver" value="200" /><Parameter format="float" id="191353" name="SNRthresh" value="-20" /><Parameter format="int" id="191354" name="save" value="1" /><Parameter format="str" id="191355" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19135" name="PrecipitationProc" priority="5" type="other" /><Operation id="19136" name="ParametersPlot" priority="6" type="other"><Parameter format="int" id="191361" name="id" value="10" /><Parameter format="str" id="191362" name="wintitle" value="First_gg" /><Parameter format="int" id="191363" name="zmin" value="-20" /><Parameter format="int" id="191364" name="zmax" value="60" /><Parameter format="int" id="191365" name="ymin" value="0" /><Parameter format="int" id="191366" name="ymax" value="8" /><Parameter format="int" id="191367" name="xmin" value="17" /><Parameter format="int" id="191368" name="xmax" value="20" /><Parameter format="int" id="191369" name="save" value="1" /><Parameter format="str" id="191370" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra" /></Operation><Operation id="19137" name="ParamWriter" priority="7" type="other"><Parameter format="str" id="191371" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191372" name="blocksPerFile" value="100" /><Parameter format="list" id="191373" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191374" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation></ProcUnit></Project> No newline at end of file
@@ -1,238 +1,239
1 import os, sys
1 import os, sys
2
2
3 from schainpy.controller import Project
3 from schainpy.controller import Project
4
4
5 if __name__ == '__main__':
5 if __name__ == '__main__':
6
6
7 desc = "Segundo Test"
7 desc = "Segundo Test"
8 filename = "schain.xml"
8 filename = "schain.xml"
9
9
10 pathW='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024'
10 pathW='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra'
11 figpath = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/test1024'
11 figpath = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/Extra'
12
12
13 controllerObj = Project()
13 controllerObj = Project()
14
14
15 controllerObj.setup(id='191', name='test01', description=desc)
15 controllerObj.setup(id='191', name='test01', description=desc)
16
16
17 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
17 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
18 path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/',
18 path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/',
19 #path='/home/erick/Documents/Data/Claire_Data/raw',
19 #path='/home/erick/Documents/Data/Claire_Data/raw',
20 startDate='2017/08/22',
20 startDate='2018/02/01',
21 endDate='2017/08/22',
21 endDate='2018/02/01',
22 startTime='01:00:00',
22 startTime='12:00:00',
23 endTime='06:00:00',
23 endTime='20:00:00',
24 online=0,
24 online=0,
25 walk=1)
25 walk=1)
26
26
27 opObj00 = readUnitConfObj.addOperation(name='printInfo')
27 opObj00 = readUnitConfObj.addOperation(name='printInfo')
28 #
28 #
29 # procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
29 # procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
30 # inputId=readUnitConfObj.getId())
30 # inputId=readUnitConfObj.getId())
31 #
31 #
32 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
32 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
33 # opObj10.addParameter(name='minHei', value='0', format='float')
33 # opObj10.addParameter(name='minHei', value='0', format='float')
34 # opObj10.addParameter(name='maxHei', value='8', format='float')
34 # opObj10.addParameter(name='maxHei', value='8', format='float')
35 #
35 #
36 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
36 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
37 # opObj10.addParameter(name='window', value='2', format='float')
37 # opObj10.addParameter(name='window', value='2', format='float')
38 #
38 #
39 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
39 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
40 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
40 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
41 # opObj10.addParameter(name='nCode', value='2', format='float')
41 # opObj10.addParameter(name='nCode', value='2', format='float')
42 # opObj10.addParameter(name='nBaud', value='1', format='float')
42 # opObj10.addParameter(name='nBaud', value='1', format='float')
43 #
43 #
44 #
44 #
45 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
45 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
46 # opObj10.addParameter(name='n', value='1296', format='float')
46 # opObj10.addParameter(name='n', value='1296', format='float')
47
47
48 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
48 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
49
49
50 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
50 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
51 inputId=readUnitConfObj.getId())
51 inputId=readUnitConfObj.getId())
52
52
53
53
54 opObj10 = procUnitConfObj0.addOperation(name='setRadarFrequency')
54 opObj10 = procUnitConfObj0.addOperation(name='setRadarFrequency')
55 opObj10.addParameter(name='frequency', value='445.09e6', format='float')
55 opObj10.addParameter(name='frequency', value='445.09e6', format='float')
56
56
57 #opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
57 opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
58 #opObj10.addParameter(name='n', value='1', format='float')
58 opObj10.addParameter(name='n', value='2', format='float')
59
59
60 #opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
60 #opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
61 #opObj10.addParameter(name='minHei', value='1', format='float')
61 #opObj10.addParameter(name='minHei', value='1', format='float')
62 #opObj10.addParameter(name='maxHei', value='15', format='float')
62 #opObj10.addParameter(name='maxHei', value='15', format='float')
63
63
64 #opObj10 = procUnitConfObj0.addOperation(name='selectFFTs')
64 #opObj10 = procUnitConfObj0.addOperation(name='selectFFTs')
65 #opObj10.addParameter(name='minHei', value='', format='float')
65 #opObj10.addParameter(name='minHei', value='', format='float')
66 #opObj10.addParameter(name='maxHei', value='', format='float')
66 #opObj10.addParameter(name='maxHei', value='', format='float')
67
67
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
69 inputId=procUnitConfObj0.getId())
69 inputId=procUnitConfObj0.getId())
70
70
71 # Creating a processing object with its parameters
71 # Creating a processing object with its parameters
72 # schainpy.model.proc.jroproc_spectra.SpectraProc.run()
72 # schainpy.model.proc.jroproc_spectra.SpectraProc.run()
73 # If you need to add more parameters can use the "addParameter method"
73 # If you need to add more parameters can use the "addParameter method"
74 procUnitConfObj1.addParameter(name='nFFTPoints', value='1024', format='int')
74 procUnitConfObj1.addParameter(name='nFFTPoints', value='256', format='int')
75
75
76
76
77 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
77 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
78 #opObj10 = procUnitConfObj1.addOperation(name='removeInterference')
78 #opObj10 = procUnitConfObj1.addOperation(name='removeInterference')
79 #opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
79 opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
80 #opObj10.addParameter(name='n', value='30', format='float')
80 opObj10.addParameter(name='n', value='10', format='float')
81
81
82
82
83
83
84 #opObj10 = procUnitConfObj1.addOperation(name='selectFFTs')
84 #opObj10 = procUnitConfObj1.addOperation(name='selectFFTs')
85 #opObj10.addParameter(name='minFFT', value='-15', format='float')
85 #opObj10.addParameter(name='minFFT', value='-15', format='float')
86 #opObj10.addParameter(name='maxFFT', value='15', format='float')
86 #opObj10.addParameter(name='maxFFT', value='15', format='float')
87
87
88
88
89
89
90 opObj10 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other')
90 opObj10 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other')
91 opObj10.addParameter(name='blocksPerFile', value='64', format = 'int')
91 opObj10.addParameter(name='blocksPerFile', value='64', format = 'int')
92 opObj10.addParameter(name='path', value=pathW)
92 opObj10.addParameter(name='path', value=pathW)
93 # Using internal methods
93 # Using internal methods
94 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
94 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
95 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
95 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
96 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
96 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
97
97
98 # Using internal methods
98 # Using internal methods
99 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
99 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
100 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
100 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
101 # opObj10.addParameter(name='minHei', value='90', format='float')
101 # opObj10.addParameter(name='minHei', value='90', format='float')
102 # opObj10.addParameter(name='maxHei', value='180', format='float')
102 # opObj10.addParameter(name='maxHei', value='180', format='float')
103
103
104 # Using external methods (new modules)
104 # Using external methods (new modules)
105 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
105 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
106 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
106 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
107 # opObj12.addParameter(name='n', value='1', format='int')
107 # opObj12.addParameter(name='n', value='1', format='int')
108
108
109 # Using external methods (new modules)
109 # Using external methods (new modules)
110 # schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
110 # schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
111 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
111 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
112 opObj11.addParameter(name='id', value='11', format='int')
112 opObj11.addParameter(name='id', value='11', format='int')
113 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
113 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
114 opObj11.addParameter(name='xaxis', value='velocity', format='str')
114 opObj11.addParameter(name='xaxis', value='velocity', format='str')
115 # opObj11.addParameter(name='xmin', value='-10', format='int')
115 # opObj11.addParameter(name='xmin', value='-10', format='int')
116 # opObj11.addParameter(name='xmax', value='10', format='int')
116 # opObj11.addParameter(name='xmax', value='10', format='int')
117
117
118 # opObj11.addParameter(name='ymin', value='1', format='float')
118 # opObj11.addParameter(name='ymin', value='1', format='float')
119 # opObj11.addParameter(name='ymax', value='3', format='int')
119 # opObj11.addParameter(name='ymax', value='3', format='int')
120 #opObj11.addParameter(name='zmin', value='10', format='int')
120 #opObj11.addParameter(name='zmin', value='10', format='int')
121 #opObj11.addParameter(name='zmax', value='35', format='int')
121 #opObj11.addParameter(name='zmax', value='35', format='int')
122 # opObj11.addParameter(name='save', value='2', format='int')
122 # opObj11.addParameter(name='save', value='2', format='int')
123 # opObj11.addParameter(name='save', value='5', format='int')
123 # opObj11.addParameter(name='save', value='5', format='int')
124 # opObj11.addParameter(name='figpath', value=figpath, format='str')
124 # opObj11.addParameter(name='figpath', value=figpath, format='str')
125
125
126
126
127 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
127 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
128 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
128 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
129 opObj11.addParameter(name='id', value='2005', format='int')
129 opObj11.addParameter(name='id', value='2005', format='int')
130 #opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
130 #opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
131 #opObj11.addParameter(name='exp_code', value='13', format='int')
131 #opObj11.addParameter(name='exp_code', value='13', format='int')
132 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
132 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
133 #opObj11.addParameter(name='xmin', value='-6', format='float')
133 #opObj11.addParameter(name='xmin', value='-6', format='float')
134 #opObj11.addParameter(name='xmax', value='6', format='float')
134 #opObj11.addParameter(name='xmax', value='6', format='float')
135 opObj11.addParameter(name='zmin', value='15', format='float')
135 opObj11.addParameter(name='zmin', value='15', format='float')
136 opObj11.addParameter(name='zmax', value='50', format='float')
136 opObj11.addParameter(name='zmax', value='50', format='float')
137 opObj11.addParameter(name='ymin', value='0', format='float')
137 opObj11.addParameter(name='ymin', value='0', format='float')
138 opObj11.addParameter(name='ymax', value='7', format='float')
138 opObj11.addParameter(name='ymax', value='7', format='float')
139 #opObj11.addParameter(name='phase_min', value='-4', format='int')
139 #opObj11.addParameter(name='phase_min', value='-4', format='int')
140 #opObj11.addParameter(name='phase_max', value='4', format='int')
140 #opObj11.addParameter(name='phase_max', value='4', format='int')
141 #
141 #
142
142
143 # Using external methods (new modules)
143 # Using external methods (new modules)
144 # schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
144 # schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
145 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
145 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
146 opObj11.addParameter(name='id', value='30', format='int')
146 opObj11.addParameter(name='id', value='30', format='int')
147 opObj11.addParameter(name='wintitle', value='RTI', format='str')
147 opObj11.addParameter(name='wintitle', value='RTI', format='str')
148 opObj11.addParameter(name='zmin', value='15', format='int')
148 opObj11.addParameter(name='zmin', value='15', format='int')
149 opObj11.addParameter(name='zmax', value='40', format='int')
149 opObj11.addParameter(name='zmax', value='40', format='int')
150 opObj11.addParameter(name='ymin', value='1', format='int')
150 opObj11.addParameter(name='ymin', value='1', format='int')
151 opObj11.addParameter(name='ymax', value='7', format='int')
151 opObj11.addParameter(name='ymax', value='7', format='int')
152 opObj11.addParameter(name='showprofile', value='1', format='int')
152 opObj11.addParameter(name='showprofile', value='1', format='int')
153 # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int')
153 # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int')
154 opObj11.addParameter(name='xmin', value='1', format='float')
154 #opObj11.addParameter(name='xmin', value='1', format='float')
155 opObj11.addParameter(name='xmax', value='6', format='float')
155 #opObj11.addParameter(name='xmax', value='6', format='float')
156 opObj11.addParameter(name='save', value='1', format='int')
156 opObj11.addParameter(name='save', value='1', format='int')
157 opObj11.addParameter(name='figpath', value=figpath, format='str')
157
158
158
159
159 # '''#########################################################################################'''
160 # '''#########################################################################################'''
160 #
161 #
161 #
162 #
162 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
163 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
163 # opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
164 # opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
164 #
165 #
165 # '''
166 # '''
166 # # Discriminacion de ecos
167 # # Discriminacion de ecos
167 # opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other')
168 # opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other')
168 # opObj11.addParameter(name='SNRlimit', value='0', format='int')
169 # opObj11.addParameter(name='SNRlimit', value='0', format='int')
169 # '''
170 # '''
170 #
171 #
171 # '''
172 # '''
172 # # Estimacion de Precipitacion
173 # # Estimacion de Precipitacion
173 # opObj11 = procUnitConfObj2.addOperation(name='PrecipitationProc', optype='other')
174 # opObj11 = procUnitConfObj2.addOperation(name='PrecipitationProc', optype='other')
174 # '''
175 # '''
175 #
176 #
176 # opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
177 # opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
177 #
178 #
178 # opObj22.addParameter(name='SNRlimit', value='-10', format='float')
179 # opObj22.addParameter(name='SNRlimit', value='-10', format='float')
179 # opObj22.addParameter(name='E01', value='1.500', format='float')
180 # opObj22.addParameter(name='E01', value='1.500', format='float')
180 # opObj22.addParameter(name='E02', value='1.500', format='float')
181 # opObj22.addParameter(name='E02', value='1.500', format='float')
181 # opObj22.addParameter(name='E12', value='0', format='float')
182 # opObj22.addParameter(name='E12', value='0', format='float')
182 # opObj22.addParameter(name='N01', value='0.875', format='float')
183 # opObj22.addParameter(name='N01', value='0.875', format='float')
183 # opObj22.addParameter(name='N02', value='-0.875', format='float')
184 # opObj22.addParameter(name='N02', value='-0.875', format='float')
184 # opObj22.addParameter(name='N12', value='-1.750', format='float')
185 # opObj22.addParameter(name='N12', value='-1.750', format='float')
185 #
186 #
186 #
187 #
187 # opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
188 # opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
188 # opObj22.addParameter(name='id', value='4', format='int')
189 # opObj22.addParameter(name='id', value='4', format='int')
189 # opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
190 # opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
190 # opObj22.addParameter(name='save', value='1', format='bool')
191 # opObj22.addParameter(name='save', value='1', format='bool')
191 # opObj22.addParameter(name='xmin', value='0', format='float')
192 # opObj22.addParameter(name='xmin', value='0', format='float')
192 # opObj22.addParameter(name='xmax', value='6', format='float')
193 # opObj22.addParameter(name='xmax', value='6', format='float')
193 # opObj22.addParameter(name='ymin', value='1', format='float')
194 # opObj22.addParameter(name='ymin', value='1', format='float')
194 # opObj22.addParameter(name='ymax', value='3.5', format='float')
195 # opObj22.addParameter(name='ymax', value='3.5', format='float')
195 # opObj22.addParameter(name='zmin', value='-1', format='float')
196 # opObj22.addParameter(name='zmin', value='-1', format='float')
196 # opObj22.addParameter(name='zmax', value='1', format='float')
197 # opObj22.addParameter(name='zmax', value='1', format='float')
197 # opObj22.addParameter(name='SNRmin', value='-15', format='float')
198 # opObj22.addParameter(name='SNRmin', value='-15', format='float')
198 # opObj22.addParameter(name='SNRmax', value='20', format='float')
199 # opObj22.addParameter(name='SNRmax', value='20', format='float')
199 # opObj22.addParameter(name='zmin_ver', value='-200', format='float')
200 # opObj22.addParameter(name='zmin_ver', value='-200', format='float')
200 # opObj22.addParameter(name='zmax_ver', value='200', format='float')
201 # opObj22.addParameter(name='zmax_ver', value='200', format='float')
201 # opObj22.addParameter(name='save', value='1', format='int')
202 # opObj22.addParameter(name='save', value='1', format='int')
202 # opObj22.addParameter(name='figpath', value=figpath, format='str')
203 # opObj22.addParameter(name='figpath', value=figpath, format='str')
203 #
204 #
204 #
205 #
205 #
206 #
206 # #opObj11.addParameter(name='zmin', value='75', format='int')
207 # #opObj11.addParameter(name='zmin', value='75', format='int')
207 #
208 #
208 # #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other')
209 # #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other')
209 # #opObj12.addParameter(name='id',value='4',format='int')
210 # #opObj12.addParameter(name='id',value='4',format='int')
210 # #opObj12.addParameter(name='wintitle',value='First_gg',format='str')
211 # #opObj12.addParameter(name='wintitle',value='First_gg',format='str')
211 # '''
212 # '''
212 # #Ploteo de Discriminacion de Gaussianas
213 # #Ploteo de Discriminacion de Gaussianas
213 #
214 #
214 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
215 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
215 # opObj11.addParameter(name='id', value='21', format='int')
216 # opObj11.addParameter(name='id', value='21', format='int')
216 # opObj11.addParameter(name='wintitle', value='Rainfall Gaussian', format='str')
217 # opObj11.addParameter(name='wintitle', value='Rainfall Gaussian', format='str')
217 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
218 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
218 # opObj11.addParameter(name='showprofile', value='1', format='int')
219 # opObj11.addParameter(name='showprofile', value='1', format='int')
219 # opObj11.addParameter(name='zmin', value='75', format='int')
220 # opObj11.addParameter(name='zmin', value='75', format='int')
220 # opObj11.addParameter(name='zmax', value='100', format='int')
221 # opObj11.addParameter(name='zmax', value='100', format='int')
221 # opObj11.addParameter(name='GauSelector', value='1', format='int')
222 # opObj11.addParameter(name='GauSelector', value='1', format='int')
222 # #opObj11.addParameter(name='save', value='1', format='int')
223 # #opObj11.addParameter(name='save', value='1', format='int')
223 # #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
224 # #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
224 #
225 #
225 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
226 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
226 # opObj11.addParameter(name='id', value='22', format='int')
227 # opObj11.addParameter(name='id', value='22', format='int')
227 # opObj11.addParameter(name='wintitle', value='Wind Gaussian', format='str')
228 # opObj11.addParameter(name='wintitle', value='Wind Gaussian', format='str')
228 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
229 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
229 # opObj11.addParameter(name='showprofile', value='1', format='int')
230 # opObj11.addParameter(name='showprofile', value='1', format='int')
230 # opObj11.addParameter(name='zmin', value='75', format='int')
231 # opObj11.addParameter(name='zmin', value='75', format='int')
231 # opObj11.addParameter(name='zmax', value='100', format='int')
232 # opObj11.addParameter(name='zmax', value='100', format='int')
232 # opObj11.addParameter(name='GauSelector', value='0', format='int')
233 # opObj11.addParameter(name='GauSelector', value='0', format='int')
233 # '''
234 # '''
234 #
235 #
235 #
236 #
236
237
237
238
238 controllerObj.start()
239 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now