##// END OF EJS Templates
Fix SpectralMoments Plot
Juan C. Espinoza -
r1207:15feaa6e0b57
parent child
Show More
@@ -1,1353 +1,1358
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 import json
10 import json
11
11
12 from schainpy.utils import log
12 from schainpy.utils import log
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
13 from .jroheaderIO import SystemHeader, RadarControllerHeader
14
14
15
15
16 def getNumpyDtype(dataTypeCode):
16 def getNumpyDtype(dataTypeCode):
17
17
18 if dataTypeCode == 0:
18 if dataTypeCode == 0:
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
20 elif dataTypeCode == 1:
20 elif dataTypeCode == 1:
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
22 elif dataTypeCode == 2:
22 elif dataTypeCode == 2:
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
24 elif dataTypeCode == 3:
24 elif dataTypeCode == 3:
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
26 elif dataTypeCode == 4:
26 elif dataTypeCode == 4:
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
28 elif dataTypeCode == 5:
28 elif dataTypeCode == 5:
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
30 else:
30 else:
31 raise ValueError('dataTypeCode was not defined')
31 raise ValueError('dataTypeCode was not defined')
32
32
33 return numpyDtype
33 return numpyDtype
34
34
35
35
36 def getDataTypeCode(numpyDtype):
36 def getDataTypeCode(numpyDtype):
37
37
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
38 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
39 datatype = 0
39 datatype = 0
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
40 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
41 datatype = 1
41 datatype = 1
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
42 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
43 datatype = 2
43 datatype = 2
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
44 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
45 datatype = 3
45 datatype = 3
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
46 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
47 datatype = 4
47 datatype = 4
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
48 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
49 datatype = 5
49 datatype = 5
50 else:
50 else:
51 datatype = None
51 datatype = None
52
52
53 return datatype
53 return datatype
54
54
55
55
56 def hildebrand_sekhon(data, navg):
56 def hildebrand_sekhon(data, navg):
57 """
57 """
58 This method is for the objective determination of the noise level in Doppler spectra. This
58 This method is for the objective determination of the noise level in Doppler spectra. This
59 implementation technique is based on the fact that the standard deviation of the spectral
59 implementation technique is based on the fact that the standard deviation of the spectral
60 densities is equal to the mean spectral density for white Gaussian noise
60 densities is equal to the mean spectral density for white Gaussian noise
61
61
62 Inputs:
62 Inputs:
63 Data : heights
63 Data : heights
64 navg : numbers of averages
64 navg : numbers of averages
65
65
66 Return:
66 Return:
67 mean : noise's level
67 mean : noise's level
68 """
68 """
69
69
70 sortdata = numpy.sort(data, axis=None)
70 sortdata = numpy.sort(data, axis=None)
71 lenOfData = len(sortdata)
71 lenOfData = len(sortdata)
72 nums_min = lenOfData*0.2
72 nums_min = lenOfData*0.2
73
73
74 if nums_min <= 5:
74 if nums_min <= 5:
75
75
76 nums_min = 5
76 nums_min = 5
77
77
78 sump = 0.
78 sump = 0.
79 sumq = 0.
79 sumq = 0.
80
80
81 j = 0
81 j = 0
82 cont = 1
82 cont = 1
83
83
84 while((cont == 1)and(j < lenOfData)):
84 while((cont == 1)and(j < lenOfData)):
85
85
86 sump += sortdata[j]
86 sump += sortdata[j]
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
103
104 class Beam:
104 class Beam:
105
105
106 def __init__(self):
106 def __init__(self):
107 self.codeList = []
107 self.codeList = []
108 self.azimuthList = []
108 self.azimuthList = []
109 self.zenithList = []
109 self.zenithList = []
110
110
111
111
112 class GenericData(object):
112 class GenericData(object):
113
113
114 flagNoData = True
114 flagNoData = True
115
115
116 def copy(self, inputObj=None):
116 def copy(self, inputObj=None):
117
117
118 if inputObj == None:
118 if inputObj == None:
119 return copy.deepcopy(self)
119 return copy.deepcopy(self)
120
120
121 for key in list(inputObj.__dict__.keys()):
121 for key in list(inputObj.__dict__.keys()):
122
122
123 attribute = inputObj.__dict__[key]
123 attribute = inputObj.__dict__[key]
124
124
125 # If this attribute is a tuple or list
125 # If this attribute is a tuple or list
126 if type(inputObj.__dict__[key]) in (tuple, list):
126 if type(inputObj.__dict__[key]) in (tuple, list):
127 self.__dict__[key] = attribute[:]
127 self.__dict__[key] = attribute[:]
128 continue
128 continue
129
129
130 # If this attribute is another object or instance
130 # If this attribute is another object or instance
131 if hasattr(attribute, '__dict__'):
131 if hasattr(attribute, '__dict__'):
132 self.__dict__[key] = attribute.copy()
132 self.__dict__[key] = attribute.copy()
133 continue
133 continue
134
134
135 self.__dict__[key] = inputObj.__dict__[key]
135 self.__dict__[key] = inputObj.__dict__[key]
136
136
137 def deepcopy(self):
137 def deepcopy(self):
138
138
139 return copy.deepcopy(self)
139 return copy.deepcopy(self)
140
140
141 def isEmpty(self):
141 def isEmpty(self):
142
142
143 return self.flagNoData
143 return self.flagNoData
144
144
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 radarControllerHeaderObj = RadarControllerHeader()
152 radarControllerHeaderObj = RadarControllerHeader()
153 # data = None
153 # data = None
154 type = None
154 type = None
155 datatype = None # dtype but in string
155 datatype = None # dtype but in string
156 # dtype = None
156 # dtype = None
157 # nChannels = None
157 # nChannels = None
158 # nHeights = None
158 # nHeights = None
159 nProfiles = None
159 nProfiles = None
160 heightList = None
160 heightList = None
161 channelList = None
161 channelList = None
162 flagDiscontinuousBlock = False
162 flagDiscontinuousBlock = False
163 useLocalTime = False
163 useLocalTime = False
164 utctime = None
164 utctime = None
165 timeZone = None
165 timeZone = None
166 dstFlag = None
166 dstFlag = None
167 errorCount = None
167 errorCount = None
168 blocksize = None
168 blocksize = None
169 # nCode = None
169 # nCode = None
170 # nBaud = None
170 # nBaud = None
171 # code = None
171 # code = None
172 flagDecodeData = False # asumo q la data no esta decodificada
172 flagDecodeData = False # asumo q la data no esta decodificada
173 flagDeflipData = False # asumo q la data no esta sin flip
173 flagDeflipData = False # asumo q la data no esta sin flip
174 flagShiftFFT = False
174 flagShiftFFT = False
175 # ippSeconds = None
175 # ippSeconds = None
176 # timeInterval = None
176 # timeInterval = None
177 nCohInt = None
177 nCohInt = None
178 # noise = None
178 # noise = None
179 windowOfFilter = 1
179 windowOfFilter = 1
180 # Speed of ligth
180 # Speed of ligth
181 C = 3e8
181 C = 3e8
182 frequency = 49.92e6
182 frequency = 49.92e6
183 realtime = False
183 realtime = False
184 beacon_heiIndexList = None
184 beacon_heiIndexList = None
185 last_block = None
185 last_block = None
186 blocknow = None
186 blocknow = None
187 azimuth = None
187 azimuth = None
188 zenith = None
188 zenith = None
189 beam = Beam()
189 beam = Beam()
190 profileIndex = None
190 profileIndex = None
191 error = None
191 error = None
192 data = None
192 data = None
193 nmodes = None
193 nmodes = None
194
194
195 def __str__(self):
195 def __str__(self):
196
196
197 return '{} - {}'.format(self.type, self.getDatatime())
197 return '{} - {}'.format(self.type, self.getDatatime())
198
198
199 def getNoise(self):
199 def getNoise(self):
200
200
201 raise NotImplementedError
201 raise NotImplementedError
202
202
203 def getNChannels(self):
203 def getNChannels(self):
204
204
205 return len(self.channelList)
205 return len(self.channelList)
206
206
207 def getChannelIndexList(self):
207 def getChannelIndexList(self):
208
208
209 return list(range(self.nChannels))
209 return list(range(self.nChannels))
210
210
211 def getNHeights(self):
211 def getNHeights(self):
212
212
213 return len(self.heightList)
213 return len(self.heightList)
214
214
215 def getHeiRange(self, extrapoints=0):
215 def getHeiRange(self, extrapoints=0):
216
216
217 heis = self.heightList
217 heis = self.heightList
218 # deltah = self.heightList[1] - self.heightList[0]
218 # deltah = self.heightList[1] - self.heightList[0]
219 #
219 #
220 # heis.append(self.heightList[-1])
220 # heis.append(self.heightList[-1])
221
221
222 return heis
222 return heis
223
223
224 def getDeltaH(self):
224 def getDeltaH(self):
225
225
226 delta = self.heightList[1] - self.heightList[0]
226 delta = self.heightList[1] - self.heightList[0]
227
227
228 return delta
228 return delta
229
229
230 def getltctime(self):
230 def getltctime(self):
231
231
232 if self.useLocalTime:
232 if self.useLocalTime:
233 return self.utctime - self.timeZone * 60
233 return self.utctime - self.timeZone * 60
234
234
235 return self.utctime
235 return self.utctime
236
236
237 def getDatatime(self):
237 def getDatatime(self):
238
238
239 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
239 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
240 return datatimeValue
240 return datatimeValue
241
241
242 def getTimeRange(self):
242 def getTimeRange(self):
243
243
244 datatime = []
244 datatime = []
245
245
246 datatime.append(self.ltctime)
246 datatime.append(self.ltctime)
247 datatime.append(self.ltctime + self.timeInterval + 1)
247 datatime.append(self.ltctime + self.timeInterval + 1)
248
248
249 datatime = numpy.array(datatime)
249 datatime = numpy.array(datatime)
250
250
251 return datatime
251 return datatime
252
252
253 def getFmaxTimeResponse(self):
253 def getFmaxTimeResponse(self):
254
254
255 period = (10**-6) * self.getDeltaH() / (0.15)
255 period = (10**-6) * self.getDeltaH() / (0.15)
256
256
257 PRF = 1. / (period * self.nCohInt)
257 PRF = 1. / (period * self.nCohInt)
258
258
259 fmax = PRF
259 fmax = PRF
260
260
261 return fmax
261 return fmax
262
262
263 def getFmax(self):
263 def getFmax(self):
264 PRF = 1. / (self.ippSeconds * self.nCohInt)
264 PRF = 1. / (self.ippSeconds * self.nCohInt)
265
265
266 fmax = PRF
266 fmax = PRF
267 return fmax
267 return fmax
268
268
269 def getVmax(self):
269 def getVmax(self):
270
270
271 _lambda = self.C / self.frequency
271 _lambda = self.C / self.frequency
272
272
273 vmax = self.getFmax() * _lambda / 2
273 vmax = self.getFmax() * _lambda / 2
274
274
275 return vmax
275 return vmax
276
276
277 def get_ippSeconds(self):
277 def get_ippSeconds(self):
278 '''
278 '''
279 '''
279 '''
280 return self.radarControllerHeaderObj.ippSeconds
280 return self.radarControllerHeaderObj.ippSeconds
281
281
282 def set_ippSeconds(self, ippSeconds):
282 def set_ippSeconds(self, ippSeconds):
283 '''
283 '''
284 '''
284 '''
285
285
286 self.radarControllerHeaderObj.ippSeconds = ippSeconds
286 self.radarControllerHeaderObj.ippSeconds = ippSeconds
287
287
288 return
288 return
289
289
290 def get_dtype(self):
290 def get_dtype(self):
291 '''
291 '''
292 '''
292 '''
293 return getNumpyDtype(self.datatype)
293 return getNumpyDtype(self.datatype)
294
294
295 def set_dtype(self, numpyDtype):
295 def set_dtype(self, numpyDtype):
296 '''
296 '''
297 '''
297 '''
298
298
299 self.datatype = getDataTypeCode(numpyDtype)
299 self.datatype = getDataTypeCode(numpyDtype)
300
300
301 def get_code(self):
301 def get_code(self):
302 '''
302 '''
303 '''
303 '''
304 return self.radarControllerHeaderObj.code
304 return self.radarControllerHeaderObj.code
305
305
306 def set_code(self, code):
306 def set_code(self, code):
307 '''
307 '''
308 '''
308 '''
309 self.radarControllerHeaderObj.code = code
309 self.radarControllerHeaderObj.code = code
310
310
311 return
311 return
312
312
313 def get_ncode(self):
313 def get_ncode(self):
314 '''
314 '''
315 '''
315 '''
316 return self.radarControllerHeaderObj.nCode
316 return self.radarControllerHeaderObj.nCode
317
317
318 def set_ncode(self, nCode):
318 def set_ncode(self, nCode):
319 '''
319 '''
320 '''
320 '''
321 self.radarControllerHeaderObj.nCode = nCode
321 self.radarControllerHeaderObj.nCode = nCode
322
322
323 return
323 return
324
324
325 def get_nbaud(self):
325 def get_nbaud(self):
326 '''
326 '''
327 '''
327 '''
328 return self.radarControllerHeaderObj.nBaud
328 return self.radarControllerHeaderObj.nBaud
329
329
330 def set_nbaud(self, nBaud):
330 def set_nbaud(self, nBaud):
331 '''
331 '''
332 '''
332 '''
333 self.radarControllerHeaderObj.nBaud = nBaud
333 self.radarControllerHeaderObj.nBaud = nBaud
334
334
335 return
335 return
336
336
337 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
337 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
338 channelIndexList = property(
338 channelIndexList = property(
339 getChannelIndexList, "I'm the 'channelIndexList' property.")
339 getChannelIndexList, "I'm the 'channelIndexList' property.")
340 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
340 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
341 #noise = property(getNoise, "I'm the 'nHeights' property.")
341 #noise = property(getNoise, "I'm the 'nHeights' property.")
342 datatime = property(getDatatime, "I'm the 'datatime' property")
342 datatime = property(getDatatime, "I'm the 'datatime' property")
343 ltctime = property(getltctime, "I'm the 'ltctime' property")
343 ltctime = property(getltctime, "I'm the 'ltctime' property")
344 ippSeconds = property(get_ippSeconds, set_ippSeconds)
344 ippSeconds = property(get_ippSeconds, set_ippSeconds)
345 dtype = property(get_dtype, set_dtype)
345 dtype = property(get_dtype, set_dtype)
346 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
346 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
347 code = property(get_code, set_code)
347 code = property(get_code, set_code)
348 nCode = property(get_ncode, set_ncode)
348 nCode = property(get_ncode, set_ncode)
349 nBaud = property(get_nbaud, set_nbaud)
349 nBaud = property(get_nbaud, set_nbaud)
350
350
351
351
352 class Voltage(JROData):
352 class Voltage(JROData):
353
353
354 # data es un numpy array de 2 dmensiones (canales, alturas)
354 # data es un numpy array de 2 dmensiones (canales, alturas)
355 data = None
355 data = None
356
356
357 def __init__(self):
357 def __init__(self):
358 '''
358 '''
359 Constructor
359 Constructor
360 '''
360 '''
361
361
362 self.useLocalTime = True
362 self.useLocalTime = True
363 self.radarControllerHeaderObj = RadarControllerHeader()
363 self.radarControllerHeaderObj = RadarControllerHeader()
364 self.systemHeaderObj = SystemHeader()
364 self.systemHeaderObj = SystemHeader()
365 self.type = "Voltage"
365 self.type = "Voltage"
366 self.data = None
366 self.data = None
367 # self.dtype = None
367 # self.dtype = None
368 # self.nChannels = 0
368 # self.nChannels = 0
369 # self.nHeights = 0
369 # self.nHeights = 0
370 self.nProfiles = None
370 self.nProfiles = None
371 self.heightList = None
371 self.heightList = None
372 self.channelList = None
372 self.channelList = None
373 # self.channelIndexList = None
373 # self.channelIndexList = None
374 self.flagNoData = True
374 self.flagNoData = True
375 self.flagDiscontinuousBlock = False
375 self.flagDiscontinuousBlock = False
376 self.utctime = None
376 self.utctime = None
377 self.timeZone = None
377 self.timeZone = None
378 self.dstFlag = None
378 self.dstFlag = None
379 self.errorCount = None
379 self.errorCount = None
380 self.nCohInt = None
380 self.nCohInt = None
381 self.blocksize = None
381 self.blocksize = None
382 self.flagDecodeData = False # asumo q la data no esta decodificada
382 self.flagDecodeData = False # asumo q la data no esta decodificada
383 self.flagDeflipData = False # asumo q la data no esta sin flip
383 self.flagDeflipData = False # asumo q la data no esta sin flip
384 self.flagShiftFFT = False
384 self.flagShiftFFT = False
385 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
385 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
386 self.profileIndex = 0
386 self.profileIndex = 0
387
387
388 def getNoisebyHildebrand(self, channel=None):
388 def getNoisebyHildebrand(self, channel=None):
389 """
389 """
390 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
390 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
391
391
392 Return:
392 Return:
393 noiselevel
393 noiselevel
394 """
394 """
395
395
396 if channel != None:
396 if channel != None:
397 data = self.data[channel]
397 data = self.data[channel]
398 nChannels = 1
398 nChannels = 1
399 else:
399 else:
400 data = self.data
400 data = self.data
401 nChannels = self.nChannels
401 nChannels = self.nChannels
402
402
403 noise = numpy.zeros(nChannels)
403 noise = numpy.zeros(nChannels)
404 power = data * numpy.conjugate(data)
404 power = data * numpy.conjugate(data)
405
405
406 for thisChannel in range(nChannels):
406 for thisChannel in range(nChannels):
407 if nChannels == 1:
407 if nChannels == 1:
408 daux = power[:].real
408 daux = power[:].real
409 else:
409 else:
410 daux = power[thisChannel, :].real
410 daux = power[thisChannel, :].real
411 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
411 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
412
412
413 return noise
413 return noise
414
414
415 def getNoise(self, type=1, channel=None):
415 def getNoise(self, type=1, channel=None):
416
416
417 if type == 1:
417 if type == 1:
418 noise = self.getNoisebyHildebrand(channel)
418 noise = self.getNoisebyHildebrand(channel)
419
419
420 return noise
420 return noise
421
421
422 def getPower(self, channel=None):
422 def getPower(self, channel=None):
423
423
424 if channel != None:
424 if channel != None:
425 data = self.data[channel]
425 data = self.data[channel]
426 else:
426 else:
427 data = self.data
427 data = self.data
428
428
429 power = data * numpy.conjugate(data)
429 power = data * numpy.conjugate(data)
430 powerdB = 10 * numpy.log10(power.real)
430 powerdB = 10 * numpy.log10(power.real)
431 powerdB = numpy.squeeze(powerdB)
431 powerdB = numpy.squeeze(powerdB)
432
432
433 return powerdB
433 return powerdB
434
434
435 def getTimeInterval(self):
435 def getTimeInterval(self):
436
436
437 timeInterval = self.ippSeconds * self.nCohInt
437 timeInterval = self.ippSeconds * self.nCohInt
438
438
439 return timeInterval
439 return timeInterval
440
440
441 noise = property(getNoise, "I'm the 'nHeights' property.")
441 noise = property(getNoise, "I'm the 'nHeights' property.")
442 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
442 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
443
443
444
444
445 class Spectra(JROData):
445 class Spectra(JROData):
446
446
447 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
447 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
448 data_spc = None
448 data_spc = None
449 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
449 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
450 data_cspc = None
450 data_cspc = None
451 # data dc es un numpy array de 2 dmensiones (canales, alturas)
451 # data dc es un numpy array de 2 dmensiones (canales, alturas)
452 data_dc = None
452 data_dc = None
453 # data power
453 # data power
454 data_pwr = None
454 data_pwr = None
455 nFFTPoints = None
455 nFFTPoints = None
456 # nPairs = None
456 # nPairs = None
457 pairsList = None
457 pairsList = None
458 nIncohInt = None
458 nIncohInt = None
459 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
459 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
460 nCohInt = None # se requiere para determinar el valor de timeInterval
460 nCohInt = None # se requiere para determinar el valor de timeInterval
461 ippFactor = None
461 ippFactor = None
462 profileIndex = 0
462 profileIndex = 0
463 plotting = "spectra"
463 plotting = "spectra"
464
464
465 def __init__(self):
465 def __init__(self):
466 '''
466 '''
467 Constructor
467 Constructor
468 '''
468 '''
469
469
470 self.useLocalTime = True
470 self.useLocalTime = True
471 self.radarControllerHeaderObj = RadarControllerHeader()
471 self.radarControllerHeaderObj = RadarControllerHeader()
472 self.systemHeaderObj = SystemHeader()
472 self.systemHeaderObj = SystemHeader()
473 self.type = "Spectra"
473 self.type = "Spectra"
474 # self.data = None
474 # self.data = None
475 # self.dtype = None
475 # self.dtype = None
476 # self.nChannels = 0
476 # self.nChannels = 0
477 # self.nHeights = 0
477 # self.nHeights = 0
478 self.nProfiles = None
478 self.nProfiles = None
479 self.heightList = None
479 self.heightList = None
480 self.channelList = None
480 self.channelList = None
481 # self.channelIndexList = None
481 # self.channelIndexList = None
482 self.pairsList = None
482 self.pairsList = None
483 self.flagNoData = True
483 self.flagNoData = True
484 self.flagDiscontinuousBlock = False
484 self.flagDiscontinuousBlock = False
485 self.utctime = None
485 self.utctime = None
486 self.nCohInt = None
486 self.nCohInt = None
487 self.nIncohInt = None
487 self.nIncohInt = None
488 self.blocksize = None
488 self.blocksize = None
489 self.nFFTPoints = None
489 self.nFFTPoints = None
490 self.wavelength = None
490 self.wavelength = None
491 self.flagDecodeData = False # asumo q la data no esta decodificada
491 self.flagDecodeData = False # asumo q la data no esta decodificada
492 self.flagDeflipData = False # asumo q la data no esta sin flip
492 self.flagDeflipData = False # asumo q la data no esta sin flip
493 self.flagShiftFFT = False
493 self.flagShiftFFT = False
494 self.ippFactor = 1
494 self.ippFactor = 1
495 #self.noise = None
495 #self.noise = None
496 self.beacon_heiIndexList = []
496 self.beacon_heiIndexList = []
497 self.noise_estimation = None
497 self.noise_estimation = None
498
498
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
499 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
500 """
500 """
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
501 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
502
502
503 Return:
503 Return:
504 noiselevel
504 noiselevel
505 """
505 """
506
506
507 noise = numpy.zeros(self.nChannels)
507 noise = numpy.zeros(self.nChannels)
508
508
509 for channel in range(self.nChannels):
509 for channel in range(self.nChannels):
510 daux = self.data_spc[channel,
510 daux = self.data_spc[channel,
511 xmin_index:xmax_index, ymin_index:ymax_index]
511 xmin_index:xmax_index, ymin_index:ymax_index]
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
512 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
513
513
514 return noise
514 return noise
515
515
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
516 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
517
517
518 if self.noise_estimation is not None:
518 if self.noise_estimation is not None:
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
519 # this was estimated by getNoise Operation defined in jroproc_spectra.py
520 return self.noise_estimation
520 return self.noise_estimation
521 else:
521 else:
522 noise = self.getNoisebyHildebrand(
522 noise = self.getNoisebyHildebrand(
523 xmin_index, xmax_index, ymin_index, ymax_index)
523 xmin_index, xmax_index, ymin_index, ymax_index)
524 return noise
524 return noise
525
525
526 def getFreqRangeTimeResponse(self, extrapoints=0):
526 def getFreqRangeTimeResponse(self, extrapoints=0):
527
527
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
528 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
529 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
529 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
530
530
531 return freqrange
531 return freqrange
532
532
533 def getAcfRange(self, extrapoints=0):
533 def getAcfRange(self, extrapoints=0):
534
534
535 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
535 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
536 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
536 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
537
537
538 return freqrange
538 return freqrange
539
539
540 def getFreqRange(self, extrapoints=0):
540 def getFreqRange(self, extrapoints=0):
541
541
542 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
542 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
543 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
543 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
544
544
545 return freqrange
545 return freqrange
546
546
547 def getVelRange(self, extrapoints=0):
547 def getVelRange(self, extrapoints=0):
548
548
549 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
549 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
550 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
550 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
551
551
552 if self.nmodes:
552 if self.nmodes:
553 return velrange/self.nmodes
553 return velrange/self.nmodes
554 else:
554 else:
555 return velrange
555 return velrange
556
556
557 def getNPairs(self):
557 def getNPairs(self):
558
558
559 return len(self.pairsList)
559 return len(self.pairsList)
560
560
561 def getPairsIndexList(self):
561 def getPairsIndexList(self):
562
562
563 return list(range(self.nPairs))
563 return list(range(self.nPairs))
564
564
565 def getNormFactor(self):
565 def getNormFactor(self):
566
566
567 pwcode = 1
567 pwcode = 1
568
568
569 if self.flagDecodeData:
569 if self.flagDecodeData:
570 pwcode = numpy.sum(self.code[0]**2)
570 pwcode = numpy.sum(self.code[0]**2)
571 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
571 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
572 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
572 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
573
573
574 return normFactor
574 return normFactor
575
575
576 def getFlagCspc(self):
576 def getFlagCspc(self):
577
577
578 if self.data_cspc is None:
578 if self.data_cspc is None:
579 return True
579 return True
580
580
581 return False
581 return False
582
582
583 def getFlagDc(self):
583 def getFlagDc(self):
584
584
585 if self.data_dc is None:
585 if self.data_dc is None:
586 return True
586 return True
587
587
588 return False
588 return False
589
589
590 def getTimeInterval(self):
590 def getTimeInterval(self):
591
591
592 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
592 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
593
593
594 return timeInterval
594 return timeInterval
595
595
596 def getPower(self):
596 def getPower(self):
597
597
598 factor = self.normFactor
598 factor = self.normFactor
599 z = self.data_spc / factor
599 z = self.data_spc / factor
600 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
600 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
601 avg = numpy.average(z, axis=1)
601 avg = numpy.average(z, axis=1)
602
602
603 return 10 * numpy.log10(avg)
603 return 10 * numpy.log10(avg)
604
604
605 def getCoherence(self, pairsList=None, phase=False):
605 def getCoherence(self, pairsList=None, phase=False):
606
606
607 z = []
607 z = []
608 if pairsList is None:
608 if pairsList is None:
609 pairsIndexList = self.pairsIndexList
609 pairsIndexList = self.pairsIndexList
610 else:
610 else:
611 pairsIndexList = []
611 pairsIndexList = []
612 for pair in pairsList:
612 for pair in pairsList:
613 if pair not in self.pairsList:
613 if pair not in self.pairsList:
614 raise ValueError("Pair %s is not in dataOut.pairsList" % (
614 raise ValueError("Pair %s is not in dataOut.pairsList" % (
615 pair))
615 pair))
616 pairsIndexList.append(self.pairsList.index(pair))
616 pairsIndexList.append(self.pairsList.index(pair))
617 for i in range(len(pairsIndexList)):
617 for i in range(len(pairsIndexList)):
618 pair = self.pairsList[pairsIndexList[i]]
618 pair = self.pairsList[pairsIndexList[i]]
619 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
619 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
620 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
620 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
621 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
621 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
622 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
622 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
623 if phase:
623 if phase:
624 data = numpy.arctan2(avgcoherenceComplex.imag,
624 data = numpy.arctan2(avgcoherenceComplex.imag,
625 avgcoherenceComplex.real) * 180 / numpy.pi
625 avgcoherenceComplex.real) * 180 / numpy.pi
626 else:
626 else:
627 data = numpy.abs(avgcoherenceComplex)
627 data = numpy.abs(avgcoherenceComplex)
628
628
629 z.append(data)
629 z.append(data)
630
630
631 return numpy.array(z)
631 return numpy.array(z)
632
632
633 def setValue(self, value):
633 def setValue(self, value):
634
634
635 print("This property should not be initialized")
635 print("This property should not be initialized")
636
636
637 return
637 return
638
638
639 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
639 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
640 pairsIndexList = property(
640 pairsIndexList = property(
641 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
641 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
642 normFactor = property(getNormFactor, setValue,
642 normFactor = property(getNormFactor, setValue,
643 "I'm the 'getNormFactor' property.")
643 "I'm the 'getNormFactor' property.")
644 flag_cspc = property(getFlagCspc, setValue)
644 flag_cspc = property(getFlagCspc, setValue)
645 flag_dc = property(getFlagDc, setValue)
645 flag_dc = property(getFlagDc, setValue)
646 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
646 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
647 timeInterval = property(getTimeInterval, setValue,
647 timeInterval = property(getTimeInterval, setValue,
648 "I'm the 'timeInterval' property")
648 "I'm the 'timeInterval' property")
649
649
650
650
651 class SpectraHeis(Spectra):
651 class SpectraHeis(Spectra):
652
652
653 data_spc = None
653 data_spc = None
654 data_cspc = None
654 data_cspc = None
655 data_dc = None
655 data_dc = None
656 nFFTPoints = None
656 nFFTPoints = None
657 # nPairs = None
657 # nPairs = None
658 pairsList = None
658 pairsList = None
659 nCohInt = None
659 nCohInt = None
660 nIncohInt = None
660 nIncohInt = None
661
661
662 def __init__(self):
662 def __init__(self):
663
663
664 self.radarControllerHeaderObj = RadarControllerHeader()
664 self.radarControllerHeaderObj = RadarControllerHeader()
665
665
666 self.systemHeaderObj = SystemHeader()
666 self.systemHeaderObj = SystemHeader()
667
667
668 self.type = "SpectraHeis"
668 self.type = "SpectraHeis"
669
669
670 # self.dtype = None
670 # self.dtype = None
671
671
672 # self.nChannels = 0
672 # self.nChannels = 0
673
673
674 # self.nHeights = 0
674 # self.nHeights = 0
675
675
676 self.nProfiles = None
676 self.nProfiles = None
677
677
678 self.heightList = None
678 self.heightList = None
679
679
680 self.channelList = None
680 self.channelList = None
681
681
682 # self.channelIndexList = None
682 # self.channelIndexList = None
683
683
684 self.flagNoData = True
684 self.flagNoData = True
685
685
686 self.flagDiscontinuousBlock = False
686 self.flagDiscontinuousBlock = False
687
687
688 # self.nPairs = 0
688 # self.nPairs = 0
689
689
690 self.utctime = None
690 self.utctime = None
691
691
692 self.blocksize = None
692 self.blocksize = None
693
693
694 self.profileIndex = 0
694 self.profileIndex = 0
695
695
696 self.nCohInt = 1
696 self.nCohInt = 1
697
697
698 self.nIncohInt = 1
698 self.nIncohInt = 1
699
699
700 def getNormFactor(self):
700 def getNormFactor(self):
701 pwcode = 1
701 pwcode = 1
702 if self.flagDecodeData:
702 if self.flagDecodeData:
703 pwcode = numpy.sum(self.code[0]**2)
703 pwcode = numpy.sum(self.code[0]**2)
704
704
705 normFactor = self.nIncohInt * self.nCohInt * pwcode
705 normFactor = self.nIncohInt * self.nCohInt * pwcode
706
706
707 return normFactor
707 return normFactor
708
708
709 def getTimeInterval(self):
709 def getTimeInterval(self):
710
710
711 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
711 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
712
712
713 return timeInterval
713 return timeInterval
714
714
715 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
715 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
716 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
716 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
717
717
718
718
719 class Fits(JROData):
719 class Fits(JROData):
720
720
721 heightList = None
721 heightList = None
722 channelList = None
722 channelList = None
723 flagNoData = True
723 flagNoData = True
724 flagDiscontinuousBlock = False
724 flagDiscontinuousBlock = False
725 useLocalTime = False
725 useLocalTime = False
726 utctime = None
726 utctime = None
727 timeZone = None
727 timeZone = None
728 # ippSeconds = None
728 # ippSeconds = None
729 # timeInterval = None
729 # timeInterval = None
730 nCohInt = None
730 nCohInt = None
731 nIncohInt = None
731 nIncohInt = None
732 noise = None
732 noise = None
733 windowOfFilter = 1
733 windowOfFilter = 1
734 # Speed of ligth
734 # Speed of ligth
735 C = 3e8
735 C = 3e8
736 frequency = 49.92e6
736 frequency = 49.92e6
737 realtime = False
737 realtime = False
738
738
739 def __init__(self):
739 def __init__(self):
740
740
741 self.type = "Fits"
741 self.type = "Fits"
742
742
743 self.nProfiles = None
743 self.nProfiles = None
744
744
745 self.heightList = None
745 self.heightList = None
746
746
747 self.channelList = None
747 self.channelList = None
748
748
749 # self.channelIndexList = None
749 # self.channelIndexList = None
750
750
751 self.flagNoData = True
751 self.flagNoData = True
752
752
753 self.utctime = None
753 self.utctime = None
754
754
755 self.nCohInt = 1
755 self.nCohInt = 1
756
756
757 self.nIncohInt = 1
757 self.nIncohInt = 1
758
758
759 self.useLocalTime = True
759 self.useLocalTime = True
760
760
761 self.profileIndex = 0
761 self.profileIndex = 0
762
762
763 # self.utctime = None
763 # self.utctime = None
764 # self.timeZone = None
764 # self.timeZone = None
765 # self.ltctime = None
765 # self.ltctime = None
766 # self.timeInterval = None
766 # self.timeInterval = None
767 # self.header = None
767 # self.header = None
768 # self.data_header = None
768 # self.data_header = None
769 # self.data = None
769 # self.data = None
770 # self.datatime = None
770 # self.datatime = None
771 # self.flagNoData = False
771 # self.flagNoData = False
772 # self.expName = ''
772 # self.expName = ''
773 # self.nChannels = None
773 # self.nChannels = None
774 # self.nSamples = None
774 # self.nSamples = None
775 # self.dataBlocksPerFile = None
775 # self.dataBlocksPerFile = None
776 # self.comments = ''
776 # self.comments = ''
777 #
777 #
778
778
779 def getltctime(self):
779 def getltctime(self):
780
780
781 if self.useLocalTime:
781 if self.useLocalTime:
782 return self.utctime - self.timeZone * 60
782 return self.utctime - self.timeZone * 60
783
783
784 return self.utctime
784 return self.utctime
785
785
786 def getDatatime(self):
786 def getDatatime(self):
787
787
788 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
788 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
789 return datatime
789 return datatime
790
790
791 def getTimeRange(self):
791 def getTimeRange(self):
792
792
793 datatime = []
793 datatime = []
794
794
795 datatime.append(self.ltctime)
795 datatime.append(self.ltctime)
796 datatime.append(self.ltctime + self.timeInterval)
796 datatime.append(self.ltctime + self.timeInterval)
797
797
798 datatime = numpy.array(datatime)
798 datatime = numpy.array(datatime)
799
799
800 return datatime
800 return datatime
801
801
802 def getHeiRange(self):
802 def getHeiRange(self):
803
803
804 heis = self.heightList
804 heis = self.heightList
805
805
806 return heis
806 return heis
807
807
808 def getNHeights(self):
808 def getNHeights(self):
809
809
810 return len(self.heightList)
810 return len(self.heightList)
811
811
812 def getNChannels(self):
812 def getNChannels(self):
813
813
814 return len(self.channelList)
814 return len(self.channelList)
815
815
816 def getChannelIndexList(self):
816 def getChannelIndexList(self):
817
817
818 return list(range(self.nChannels))
818 return list(range(self.nChannels))
819
819
820 def getNoise(self, type=1):
820 def getNoise(self, type=1):
821
821
822 #noise = numpy.zeros(self.nChannels)
822 #noise = numpy.zeros(self.nChannels)
823
823
824 if type == 1:
824 if type == 1:
825 noise = self.getNoisebyHildebrand()
825 noise = self.getNoisebyHildebrand()
826
826
827 if type == 2:
827 if type == 2:
828 noise = self.getNoisebySort()
828 noise = self.getNoisebySort()
829
829
830 if type == 3:
830 if type == 3:
831 noise = self.getNoisebyWindow()
831 noise = self.getNoisebyWindow()
832
832
833 return noise
833 return noise
834
834
835 def getTimeInterval(self):
835 def getTimeInterval(self):
836
836
837 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
837 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
838
838
839 return timeInterval
839 return timeInterval
840
840
841 def get_ippSeconds(self):
841 def get_ippSeconds(self):
842 '''
842 '''
843 '''
843 '''
844 return self.ipp_sec
844 return self.ipp_sec
845
845
846
846
847 datatime = property(getDatatime, "I'm the 'datatime' property")
847 datatime = property(getDatatime, "I'm the 'datatime' property")
848 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
848 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
849 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
849 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
850 channelIndexList = property(
850 channelIndexList = property(
851 getChannelIndexList, "I'm the 'channelIndexList' property.")
851 getChannelIndexList, "I'm the 'channelIndexList' property.")
852 noise = property(getNoise, "I'm the 'nHeights' property.")
852 noise = property(getNoise, "I'm the 'nHeights' property.")
853
853
854 ltctime = property(getltctime, "I'm the 'ltctime' property")
854 ltctime = property(getltctime, "I'm the 'ltctime' property")
855 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
855 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
856 ippSeconds = property(get_ippSeconds, '')
856 ippSeconds = property(get_ippSeconds, '')
857
857
858 class Correlation(JROData):
858 class Correlation(JROData):
859
859
860 noise = None
860 noise = None
861 SNR = None
861 SNR = None
862 #--------------------------------------------------
862 #--------------------------------------------------
863 mode = None
863 mode = None
864 split = False
864 split = False
865 data_cf = None
865 data_cf = None
866 lags = None
866 lags = None
867 lagRange = None
867 lagRange = None
868 pairsList = None
868 pairsList = None
869 normFactor = None
869 normFactor = None
870 #--------------------------------------------------
870 #--------------------------------------------------
871 # calculateVelocity = None
871 # calculateVelocity = None
872 nLags = None
872 nLags = None
873 nPairs = None
873 nPairs = None
874 nAvg = None
874 nAvg = None
875
875
876 def __init__(self):
876 def __init__(self):
877 '''
877 '''
878 Constructor
878 Constructor
879 '''
879 '''
880 self.radarControllerHeaderObj = RadarControllerHeader()
880 self.radarControllerHeaderObj = RadarControllerHeader()
881
881
882 self.systemHeaderObj = SystemHeader()
882 self.systemHeaderObj = SystemHeader()
883
883
884 self.type = "Correlation"
884 self.type = "Correlation"
885
885
886 self.data = None
886 self.data = None
887
887
888 self.dtype = None
888 self.dtype = None
889
889
890 self.nProfiles = None
890 self.nProfiles = None
891
891
892 self.heightList = None
892 self.heightList = None
893
893
894 self.channelList = None
894 self.channelList = None
895
895
896 self.flagNoData = True
896 self.flagNoData = True
897
897
898 self.flagDiscontinuousBlock = False
898 self.flagDiscontinuousBlock = False
899
899
900 self.utctime = None
900 self.utctime = None
901
901
902 self.timeZone = None
902 self.timeZone = None
903
903
904 self.dstFlag = None
904 self.dstFlag = None
905
905
906 self.errorCount = None
906 self.errorCount = None
907
907
908 self.blocksize = None
908 self.blocksize = None
909
909
910 self.flagDecodeData = False # asumo q la data no esta decodificada
910 self.flagDecodeData = False # asumo q la data no esta decodificada
911
911
912 self.flagDeflipData = False # asumo q la data no esta sin flip
912 self.flagDeflipData = False # asumo q la data no esta sin flip
913
913
914 self.pairsList = None
914 self.pairsList = None
915
915
916 self.nPoints = None
916 self.nPoints = None
917
917
918 def getPairsList(self):
918 def getPairsList(self):
919
919
920 return self.pairsList
920 return self.pairsList
921
921
922 def getNoise(self, mode=2):
922 def getNoise(self, mode=2):
923
923
924 indR = numpy.where(self.lagR == 0)[0][0]
924 indR = numpy.where(self.lagR == 0)[0][0]
925 indT = numpy.where(self.lagT == 0)[0][0]
925 indT = numpy.where(self.lagT == 0)[0][0]
926
926
927 jspectra0 = self.data_corr[:, :, indR, :]
927 jspectra0 = self.data_corr[:, :, indR, :]
928 jspectra = copy.copy(jspectra0)
928 jspectra = copy.copy(jspectra0)
929
929
930 num_chan = jspectra.shape[0]
930 num_chan = jspectra.shape[0]
931 num_hei = jspectra.shape[2]
931 num_hei = jspectra.shape[2]
932
932
933 freq_dc = jspectra.shape[1] / 2
933 freq_dc = jspectra.shape[1] / 2
934 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
934 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
935
935
936 if ind_vel[0] < 0:
936 if ind_vel[0] < 0:
937 ind_vel[list(range(0, 1))] = ind_vel[list(
937 ind_vel[list(range(0, 1))] = ind_vel[list(
938 range(0, 1))] + self.num_prof
938 range(0, 1))] + self.num_prof
939
939
940 if mode == 1:
940 if mode == 1:
941 jspectra[:, freq_dc, :] = (
941 jspectra[:, freq_dc, :] = (
942 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
942 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
943
943
944 if mode == 2:
944 if mode == 2:
945
945
946 vel = numpy.array([-2, -1, 1, 2])
946 vel = numpy.array([-2, -1, 1, 2])
947 xx = numpy.zeros([4, 4])
947 xx = numpy.zeros([4, 4])
948
948
949 for fil in range(4):
949 for fil in range(4):
950 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
950 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
951
951
952 xx_inv = numpy.linalg.inv(xx)
952 xx_inv = numpy.linalg.inv(xx)
953 xx_aux = xx_inv[0, :]
953 xx_aux = xx_inv[0, :]
954
954
955 for ich in range(num_chan):
955 for ich in range(num_chan):
956 yy = jspectra[ich, ind_vel, :]
956 yy = jspectra[ich, ind_vel, :]
957 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
957 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
958
958
959 junkid = jspectra[ich, freq_dc, :] <= 0
959 junkid = jspectra[ich, freq_dc, :] <= 0
960 cjunkid = sum(junkid)
960 cjunkid = sum(junkid)
961
961
962 if cjunkid.any():
962 if cjunkid.any():
963 jspectra[ich, freq_dc, junkid.nonzero()] = (
963 jspectra[ich, freq_dc, junkid.nonzero()] = (
964 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
964 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
965
965
966 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
966 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
967
967
968 return noise
968 return noise
969
969
970 def getTimeInterval(self):
970 def getTimeInterval(self):
971
971
972 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
972 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
973
973
974 return timeInterval
974 return timeInterval
975
975
976 def splitFunctions(self):
976 def splitFunctions(self):
977
977
978 pairsList = self.pairsList
978 pairsList = self.pairsList
979 ccf_pairs = []
979 ccf_pairs = []
980 acf_pairs = []
980 acf_pairs = []
981 ccf_ind = []
981 ccf_ind = []
982 acf_ind = []
982 acf_ind = []
983 for l in range(len(pairsList)):
983 for l in range(len(pairsList)):
984 chan0 = pairsList[l][0]
984 chan0 = pairsList[l][0]
985 chan1 = pairsList[l][1]
985 chan1 = pairsList[l][1]
986
986
987 # Obteniendo pares de Autocorrelacion
987 # Obteniendo pares de Autocorrelacion
988 if chan0 == chan1:
988 if chan0 == chan1:
989 acf_pairs.append(chan0)
989 acf_pairs.append(chan0)
990 acf_ind.append(l)
990 acf_ind.append(l)
991 else:
991 else:
992 ccf_pairs.append(pairsList[l])
992 ccf_pairs.append(pairsList[l])
993 ccf_ind.append(l)
993 ccf_ind.append(l)
994
994
995 data_acf = self.data_cf[acf_ind]
995 data_acf = self.data_cf[acf_ind]
996 data_ccf = self.data_cf[ccf_ind]
996 data_ccf = self.data_cf[ccf_ind]
997
997
998 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
998 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
999
999
1000 def getNormFactor(self):
1000 def getNormFactor(self):
1001 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1001 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1002 acf_pairs = numpy.array(acf_pairs)
1002 acf_pairs = numpy.array(acf_pairs)
1003 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1003 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1004
1004
1005 for p in range(self.nPairs):
1005 for p in range(self.nPairs):
1006 pair = self.pairsList[p]
1006 pair = self.pairsList[p]
1007
1007
1008 ch0 = pair[0]
1008 ch0 = pair[0]
1009 ch1 = pair[1]
1009 ch1 = pair[1]
1010
1010
1011 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1011 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1012 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1012 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1013 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1013 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1014
1014
1015 return normFactor
1015 return normFactor
1016
1016
1017 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1017 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1018 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1018 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1019
1019
1020
1020
1021 class Parameters(Spectra):
1021 class Parameters(Spectra):
1022
1022
1023 experimentInfo = None # Information about the experiment
1023 experimentInfo = None # Information about the experiment
1024 # Information from previous data
1024 # Information from previous data
1025 inputUnit = None # Type of data to be processed
1025 inputUnit = None # Type of data to be processed
1026 operation = None # Type of operation to parametrize
1026 operation = None # Type of operation to parametrize
1027 # normFactor = None #Normalization Factor
1027 # normFactor = None #Normalization Factor
1028 groupList = None # List of Pairs, Groups, etc
1028 groupList = None # List of Pairs, Groups, etc
1029 # Parameters
1029 # Parameters
1030 data_param = None # Parameters obtained
1030 data_param = None # Parameters obtained
1031 data_pre = None # Data Pre Parametrization
1031 data_pre = None # Data Pre Parametrization
1032 data_SNR = None # Signal to Noise Ratio
1032 data_SNR = None # Signal to Noise Ratio
1033 # heightRange = None #Heights
1033 # heightRange = None #Heights
1034 abscissaList = None # Abscissa, can be velocities, lags or time
1034 abscissaList = None # Abscissa, can be velocities, lags or time
1035 # noise = None #Noise Potency
1035 # noise = None #Noise Potency
1036 utctimeInit = None # Initial UTC time
1036 utctimeInit = None # Initial UTC time
1037 paramInterval = None # Time interval to calculate Parameters in seconds
1037 paramInterval = None # Time interval to calculate Parameters in seconds
1038 useLocalTime = True
1038 useLocalTime = True
1039 # Fitting
1039 # Fitting
1040 data_error = None # Error of the estimation
1040 data_error = None # Error of the estimation
1041 constants = None
1041 constants = None
1042 library = None
1042 library = None
1043 # Output signal
1043 # Output signal
1044 outputInterval = None # Time interval to calculate output signal in seconds
1044 outputInterval = None # Time interval to calculate output signal in seconds
1045 data_output = None # Out signal
1045 data_output = None # Out signal
1046 nAvg = None
1046 nAvg = None
1047 noise_estimation = None
1047 noise_estimation = None
1048 GauSPC = None # Fit gaussian SPC
1048 GauSPC = None # Fit gaussian SPC
1049
1049
1050 def __init__(self):
1050 def __init__(self):
1051 '''
1051 '''
1052 Constructor
1052 Constructor
1053 '''
1053 '''
1054 self.radarControllerHeaderObj = RadarControllerHeader()
1054 self.radarControllerHeaderObj = RadarControllerHeader()
1055
1055
1056 self.systemHeaderObj = SystemHeader()
1056 self.systemHeaderObj = SystemHeader()
1057
1057
1058 self.type = "Parameters"
1058 self.type = "Parameters"
1059
1059
1060 def getTimeRange1(self, interval):
1060 def getTimeRange1(self, interval):
1061
1061
1062 datatime = []
1062 datatime = []
1063
1063
1064 if self.useLocalTime:
1064 if self.useLocalTime:
1065 time1 = self.utctimeInit - self.timeZone * 60
1065 time1 = self.utctimeInit - self.timeZone * 60
1066 else:
1066 else:
1067 time1 = self.utctimeInit
1067 time1 = self.utctimeInit
1068
1068
1069 datatime.append(time1)
1069 datatime.append(time1)
1070 datatime.append(time1 + interval)
1070 datatime.append(time1 + interval)
1071 datatime = numpy.array(datatime)
1071 datatime = numpy.array(datatime)
1072
1072
1073 return datatime
1073 return datatime
1074
1074
1075 def getTimeInterval(self):
1075 def getTimeInterval(self):
1076
1076
1077 if hasattr(self, 'timeInterval1'):
1077 if hasattr(self, 'timeInterval1'):
1078 return self.timeInterval1
1078 return self.timeInterval1
1079 else:
1079 else:
1080 return self.paramInterval
1080 return self.paramInterval
1081
1081
1082 def setValue(self, value):
1082 def setValue(self, value):
1083
1083
1084 print("This property should not be initialized")
1084 print("This property should not be initialized")
1085
1085
1086 return
1086 return
1087
1087
1088 def getNoise(self):
1088 def getNoise(self):
1089
1089
1090 return self.spc_noise
1090 return self.spc_noise
1091
1091
1092 timeInterval = property(getTimeInterval)
1092 timeInterval = property(getTimeInterval)
1093 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1093 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1094
1094
1095
1095
1096 class PlotterData(object):
1096 class PlotterData(object):
1097 '''
1097 '''
1098 Object to hold data to be plotted
1098 Object to hold data to be plotted
1099 '''
1099 '''
1100
1100
1101 MAXNUMX = 100
1101 MAXNUMX = 100
1102 MAXNUMY = 100
1102 MAXNUMY = 100
1103
1103
1104 def __init__(self, code, throttle_value, exp_code, buffering=True):
1104 def __init__(self, code, throttle_value, exp_code, buffering=True):
1105
1105
1106 self.throttle = throttle_value
1106 self.throttle = throttle_value
1107 self.exp_code = exp_code
1107 self.exp_code = exp_code
1108 self.buffering = buffering
1108 self.buffering = buffering
1109 self.ready = False
1109 self.ready = False
1110 self.localtime = False
1110 self.localtime = False
1111 self.data = {}
1111 self.data = {}
1112 self.meta = {}
1112 self.meta = {}
1113 self.__times = []
1113 self.__times = []
1114 self.__heights = []
1114 self.__heights = []
1115
1115
1116 if 'snr' in code:
1116 if 'snr' in code:
1117 self.plottypes = ['snr']
1117 self.plottypes = ['snr']
1118 elif code == 'spc':
1118 elif code == 'spc':
1119 self.plottypes = ['spc', 'noise', 'rti']
1119 self.plottypes = ['spc', 'noise', 'rti']
1120 elif code == 'rti':
1120 elif code == 'rti':
1121 self.plottypes = ['noise', 'rti']
1121 self.plottypes = ['noise', 'rti']
1122 else:
1122 else:
1123 self.plottypes = [code]
1123 self.plottypes = [code]
1124
1124
1125 for plot in self.plottypes:
1125 for plot in self.plottypes:
1126 self.data[plot] = {}
1126 self.data[plot] = {}
1127
1127
1128 def __str__(self):
1128 def __str__(self):
1129 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1129 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1130 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1130 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1131
1131
1132 def __len__(self):
1132 def __len__(self):
1133 return len(self.__times)
1133 return len(self.__times)
1134
1134
1135 def __getitem__(self, key):
1135 def __getitem__(self, key):
1136
1136
1137 if key not in self.data:
1137 if key not in self.data:
1138 raise KeyError(log.error('Missing key: {}'.format(key)))
1138 raise KeyError(log.error('Missing key: {}'.format(key)))
1139 if 'spc' in key or not self.buffering:
1139 if 'spc' in key or not self.buffering:
1140 ret = self.data[key]
1140 ret = self.data[key]
1141 elif 'scope' in key:
1141 elif 'scope' in key:
1142 ret = numpy.array(self.data[key][float(self.tm)])
1142 ret = numpy.array(self.data[key][float(self.tm)])
1143 else:
1143 else:
1144 ret = numpy.array([self.data[key][x] for x in self.times])
1144 ret = numpy.array([self.data[key][x] for x in self.times])
1145 if ret.ndim > 1:
1145 if ret.ndim > 1:
1146 ret = numpy.swapaxes(ret, 0, 1)
1146 ret = numpy.swapaxes(ret, 0, 1)
1147 return ret
1147 return ret
1148
1148
1149 def __contains__(self, key):
1149 def __contains__(self, key):
1150 return key in self.data
1150 return key in self.data
1151
1151
1152 def setup(self):
1152 def setup(self):
1153 '''
1153 '''
1154 Configure object
1154 Configure object
1155 '''
1155 '''
1156
1156
1157 self.type = ''
1157 self.type = ''
1158 self.ready = False
1158 self.ready = False
1159 self.data = {}
1159 self.data = {}
1160 self.__times = []
1160 self.__times = []
1161 self.__heights = []
1161 self.__heights = []
1162 self.__all_heights = set()
1162 self.__all_heights = set()
1163 for plot in self.plottypes:
1163 for plot in self.plottypes:
1164 if 'snr' in plot:
1164 if 'snr' in plot:
1165 plot = 'snr'
1165 plot = 'snr'
1166 elif 'spc_moments' == plot:
1167 plot = 'moments'
1166 self.data[plot] = {}
1168 self.data[plot] = {}
1167
1169
1168 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data:
1170 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data:
1169 self.data['noise'] = {}
1171 self.data['noise'] = {}
1170 if 'noise' not in self.plottypes:
1172 if 'noise' not in self.plottypes:
1171 self.plottypes.append('noise')
1173 self.plottypes.append('noise')
1172
1174
1173 def shape(self, key):
1175 def shape(self, key):
1174 '''
1176 '''
1175 Get the shape of the one-element data for the given key
1177 Get the shape of the one-element data for the given key
1176 '''
1178 '''
1177
1179
1178 if len(self.data[key]):
1180 if len(self.data[key]):
1179 if 'spc' in key or not self.buffering:
1181 if 'spc' in key or not self.buffering:
1180 return self.data[key].shape
1182 return self.data[key].shape
1181 return self.data[key][self.__times[0]].shape
1183 return self.data[key][self.__times[0]].shape
1182 return (0,)
1184 return (0,)
1183
1185
1184 def update(self, dataOut, tm):
1186 def update(self, dataOut, tm):
1185 '''
1187 '''
1186 Update data object with new dataOut
1188 Update data object with new dataOut
1187 '''
1189 '''
1188
1190
1189 if tm in self.__times:
1191 if tm in self.__times:
1190 return
1192 return
1191 self.profileIndex = dataOut.profileIndex
1193 self.profileIndex = dataOut.profileIndex
1192 self.tm = tm
1194 self.tm = tm
1193 self.type = dataOut.type
1195 self.type = dataOut.type
1194 self.parameters = getattr(dataOut, 'parameters', [])
1196 self.parameters = getattr(dataOut, 'parameters', [])
1195 if hasattr(dataOut, 'pairsList'):
1197 if hasattr(dataOut, 'pairsList'):
1196 self.pairs = dataOut.pairsList
1198 self.pairs = dataOut.pairsList
1197 if hasattr(dataOut, 'meta'):
1199 if hasattr(dataOut, 'meta'):
1198 self.meta = dataOut.meta
1200 self.meta = dataOut.meta
1199 self.channels = dataOut.channelList
1201 self.channels = dataOut.channelList
1200 self.interval = dataOut.getTimeInterval()
1202 self.interval = dataOut.getTimeInterval()
1201 self.localtime = dataOut.useLocalTime
1203 self.localtime = dataOut.useLocalTime
1202 if 'spc' in self.plottypes or 'cspc' in self.plottypes:
1204 if 'spc' in self.plottypes or 'cspc' in self.plottypes or 'spc_moments' in self.plottypes:
1203 self.xrange = (dataOut.getFreqRange(1)/1000.,
1205 self.xrange = (dataOut.getFreqRange(1)/1000.,
1204 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1206 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1205 self.factor = dataOut.normFactor
1207 self.factor = dataOut.normFactor
1206 self.__heights.append(dataOut.heightList)
1208 self.__heights.append(dataOut.heightList)
1207 self.__all_heights.update(dataOut.heightList)
1209 self.__all_heights.update(dataOut.heightList)
1208 self.__times.append(tm)
1210 self.__times.append(tm)
1209
1211
1210 for plot in self.plottypes:
1212 for plot in self.plottypes:
1211 if plot == 'spc':
1213 if plot in ('spc', 'spc_moments'):
1212 z = dataOut.data_spc/dataOut.normFactor
1214 z = dataOut.data_spc/dataOut.normFactor
1213 buffer = 10*numpy.log10(z)
1215 buffer = 10*numpy.log10(z)
1214 if plot == 'cspc':
1216 if plot == 'cspc':
1215 z = dataOut.data_spc/dataOut.normFactor
1217 z = dataOut.data_spc/dataOut.normFactor
1216 buffer = (dataOut.data_spc, dataOut.data_cspc)
1218 buffer = (dataOut.data_spc, dataOut.data_cspc)
1217 if plot == 'noise':
1219 if plot == 'noise':
1218 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1220 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1219 if plot == 'rti':
1221 if plot == 'rti':
1220 buffer = dataOut.getPower()
1222 buffer = dataOut.getPower()
1221 if plot == 'snr_db':
1223 if plot == 'snr_db':
1222 buffer = dataOut.data_SNR
1224 buffer = dataOut.data_SNR
1223 if plot == 'snr':
1225 if plot == 'snr':
1224 buffer = 10*numpy.log10(dataOut.data_SNR)
1226 buffer = 10*numpy.log10(dataOut.data_SNR)
1225 if plot == 'dop':
1227 if plot == 'dop':
1226 buffer = 10*numpy.log10(dataOut.data_DOP)
1228 buffer = 10*numpy.log10(dataOut.data_DOP)
1227 if plot == 'mean':
1229 if plot == 'mean':
1228 buffer = dataOut.data_MEAN
1230 buffer = dataOut.data_MEAN
1229 if plot == 'std':
1231 if plot == 'std':
1230 buffer = dataOut.data_STD
1232 buffer = dataOut.data_STD
1231 if plot == 'coh':
1233 if plot == 'coh':
1232 buffer = dataOut.getCoherence()
1234 buffer = dataOut.getCoherence()
1233 if plot == 'phase':
1235 if plot == 'phase':
1234 buffer = dataOut.getCoherence(phase=True)
1236 buffer = dataOut.getCoherence(phase=True)
1235 if plot == 'output':
1237 if plot == 'output':
1236 buffer = dataOut.data_output
1238 buffer = dataOut.data_output
1237 if plot == 'param':
1239 if plot == 'param':
1238 buffer = dataOut.data_param
1240 buffer = dataOut.data_param
1239 if plot == 'scope':
1241 if plot == 'scope':
1240 buffer = dataOut.data
1242 buffer = dataOut.data
1241 self.flagDataAsBlock = dataOut.flagDataAsBlock
1243 self.flagDataAsBlock = dataOut.flagDataAsBlock
1242 self.nProfiles = dataOut.nProfiles
1244 self.nProfiles = dataOut.nProfiles
1243
1245
1244 if plot == 'spc':
1246 if plot == 'spc':
1245 self.data[plot] = buffer
1247 self.data[plot] = buffer
1246 elif plot == 'cspc':
1248 elif plot == 'cspc':
1247 self.data['spc'] = buffer[0]
1249 self.data['spc'] = buffer[0]
1248 self.data['cspc'] = buffer[1]
1250 self.data['cspc'] = buffer[1]
1251 elif plot == 'spc_moments':
1252 self.data['spc'] = buffer
1253 self.data['moments'][tm] = dataOut.moments
1249 else:
1254 else:
1250 if self.buffering:
1255 if self.buffering:
1251 self.data[plot][tm] = buffer
1256 self.data[plot][tm] = buffer
1252 else:
1257 else:
1253 self.data[plot] = buffer
1258 self.data[plot] = buffer
1254
1259
1255 def normalize_heights(self):
1260 def normalize_heights(self):
1256 '''
1261 '''
1257 Ensure same-dimension of the data for different heighList
1262 Ensure same-dimension of the data for different heighList
1258 '''
1263 '''
1259
1264
1260 H = numpy.array(list(self.__all_heights))
1265 H = numpy.array(list(self.__all_heights))
1261 H.sort()
1266 H.sort()
1262 for key in self.data:
1267 for key in self.data:
1263 shape = self.shape(key)[:-1] + H.shape
1268 shape = self.shape(key)[:-1] + H.shape
1264 for tm, obj in list(self.data[key].items()):
1269 for tm, obj in list(self.data[key].items()):
1265 h = self.__heights[self.__times.index(tm)]
1270 h = self.__heights[self.__times.index(tm)]
1266 if H.size == h.size:
1271 if H.size == h.size:
1267 continue
1272 continue
1268 index = numpy.where(numpy.in1d(H, h))[0]
1273 index = numpy.where(numpy.in1d(H, h))[0]
1269 dummy = numpy.zeros(shape) + numpy.nan
1274 dummy = numpy.zeros(shape) + numpy.nan
1270 if len(shape) == 2:
1275 if len(shape) == 2:
1271 dummy[:, index] = obj
1276 dummy[:, index] = obj
1272 else:
1277 else:
1273 dummy[index] = obj
1278 dummy[index] = obj
1274 self.data[key][tm] = dummy
1279 self.data[key][tm] = dummy
1275
1280
1276 self.__heights = [H for tm in self.__times]
1281 self.__heights = [H for tm in self.__times]
1277
1282
1278 def jsonify(self, decimate=False):
1283 def jsonify(self, decimate=False):
1279 '''
1284 '''
1280 Convert data to json
1285 Convert data to json
1281 '''
1286 '''
1282
1287
1283 data = {}
1288 data = {}
1284 tm = self.times[-1]
1289 tm = self.times[-1]
1285 dy = int(self.heights.size/self.MAXNUMY) + 1
1290 dy = int(self.heights.size/self.MAXNUMY) + 1
1286 for key in self.data:
1291 for key in self.data:
1287 if key in ('spc', 'cspc') or not self.buffering:
1292 if key in ('spc', 'cspc') or not self.buffering:
1288 dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1
1293 dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1
1289 data[key] = self.roundFloats(
1294 data[key] = self.roundFloats(
1290 self.data[key][::, ::dx, ::dy].tolist())
1295 self.data[key][::, ::dx, ::dy].tolist())
1291 else:
1296 else:
1292 data[key] = self.roundFloats(self.data[key][tm].tolist())
1297 data[key] = self.roundFloats(self.data[key][tm].tolist())
1293
1298
1294 ret = {'data': data}
1299 ret = {'data': data}
1295 ret['exp_code'] = self.exp_code
1300 ret['exp_code'] = self.exp_code
1296 ret['time'] = float(tm)
1301 ret['time'] = float(tm)
1297 ret['interval'] = float(self.interval)
1302 ret['interval'] = float(self.interval)
1298 ret['localtime'] = self.localtime
1303 ret['localtime'] = self.localtime
1299 ret['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1304 ret['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1300 if 'spc' in self.data or 'cspc' in self.data:
1305 if 'spc' in self.data or 'cspc' in self.data:
1301 ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1306 ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1302 else:
1307 else:
1303 ret['xrange'] = []
1308 ret['xrange'] = []
1304 if hasattr(self, 'pairs'):
1309 if hasattr(self, 'pairs'):
1305 ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs]
1310 ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs]
1306 else:
1311 else:
1307 ret['pairs'] = []
1312 ret['pairs'] = []
1308
1313
1309 for key, value in list(self.meta.items()):
1314 for key, value in list(self.meta.items()):
1310 ret[key] = value
1315 ret[key] = value
1311
1316
1312 return json.dumps(ret)
1317 return json.dumps(ret)
1313
1318
1314 @property
1319 @property
1315 def times(self):
1320 def times(self):
1316 '''
1321 '''
1317 Return the list of times of the current data
1322 Return the list of times of the current data
1318 '''
1323 '''
1319
1324
1320 ret = numpy.array(self.__times)
1325 ret = numpy.array(self.__times)
1321 ret.sort()
1326 ret.sort()
1322 return ret
1327 return ret
1323
1328
1324 @property
1329 @property
1325 def min_time(self):
1330 def min_time(self):
1326 '''
1331 '''
1327 Return the minimun time value
1332 Return the minimun time value
1328 '''
1333 '''
1329
1334
1330 return self.times[0]
1335 return self.times[0]
1331
1336
1332 @property
1337 @property
1333 def max_time(self):
1338 def max_time(self):
1334 '''
1339 '''
1335 Return the maximun time value
1340 Return the maximun time value
1336 '''
1341 '''
1337
1342
1338 return self.times[-1]
1343 return self.times[-1]
1339
1344
1340 @property
1345 @property
1341 def heights(self):
1346 def heights(self):
1342 '''
1347 '''
1343 Return the list of heights of the current data
1348 Return the list of heights of the current data
1344 '''
1349 '''
1345
1350
1346 return numpy.array(self.__heights[-1])
1351 return numpy.array(self.__heights[-1])
1347
1352
1348 @staticmethod
1353 @staticmethod
1349 def roundFloats(obj):
1354 def roundFloats(obj):
1350 if isinstance(obj, list):
1355 if isinstance(obj, list):
1351 return list(map(PlotterData.roundFloats, obj))
1356 return list(map(PlotterData.roundFloats, obj))
1352 elif isinstance(obj, float):
1357 elif isinstance(obj, float):
1353 return round(obj, 2)
1358 return round(obj, 2)
@@ -1,748 +1,747
1 '''
1 '''
2 New Plots Operations
2 New Plots Operations
3
3
4 @author: juan.espinoza@jro.igp.gob.pe
4 @author: juan.espinoza@jro.igp.gob.pe
5 '''
5 '''
6
6
7
7
8 import time
8 import time
9 import datetime
9 import datetime
10 import numpy
10 import numpy
11
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt
12 from schainpy.model.graphics.jroplot_base import Plot, plt
13 from schainpy.utils import log
13 from schainpy.utils import log
14
14
15 EARTH_RADIUS = 6.3710e3
15 EARTH_RADIUS = 6.3710e3
16
16
17
17
18 def ll2xy(lat1, lon1, lat2, lon2):
18 def ll2xy(lat1, lon1, lat2, lon2):
19
19
20 p = 0.017453292519943295
20 p = 0.017453292519943295
21 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
21 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
22 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
22 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
23 r = 12742 * numpy.arcsin(numpy.sqrt(a))
23 r = 12742 * numpy.arcsin(numpy.sqrt(a))
24 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
24 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
25 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
25 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
26 theta = -theta + numpy.pi/2
26 theta = -theta + numpy.pi/2
27 return r*numpy.cos(theta), r*numpy.sin(theta)
27 return r*numpy.cos(theta), r*numpy.sin(theta)
28
28
29
29
30 def km2deg(km):
30 def km2deg(km):
31 '''
31 '''
32 Convert distance in km to degrees
32 Convert distance in km to degrees
33 '''
33 '''
34
34
35 return numpy.rad2deg(km/EARTH_RADIUS)
35 return numpy.rad2deg(km/EARTH_RADIUS)
36
36
37
37
38 class SpectraPlot(Plot):
38 class SpectraPlot(Plot):
39 '''
39 '''
40 Plot for Spectra data
40 Plot for Spectra data
41 '''
41 '''
42
42
43 CODE = 'spc'
43 CODE = 'spc'
44 colormap = 'jro'
44 colormap = 'jro'
45
45
46 def setup(self):
46 def setup(self):
47 self.nplots = len(self.data.channels)
47 self.nplots = len(self.data.channels)
48 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
48 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
49 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
49 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
50 self.width = 3.4 * self.ncols
50 self.width = 3.4 * self.ncols
51 self.height = 3 * self.nrows
51 self.height = 3 * self.nrows
52 self.cb_label = 'dB'
52 self.cb_label = 'dB'
53 if self.showprofile:
53 if self.showprofile:
54 self.width += 0.8 * self.ncols
54 self.width += 0.8 * self.ncols
55
55
56 self.ylabel = 'Range [km]'
56 self.ylabel = 'Range [km]'
57
57
58 def plot(self):
58 def plot(self):
59 if self.xaxis == "frequency":
59 if self.xaxis == "frequency":
60 x = self.data.xrange[0]
60 x = self.data.xrange[0]
61 self.xlabel = "Frequency (kHz)"
61 self.xlabel = "Frequency (kHz)"
62 elif self.xaxis == "time":
62 elif self.xaxis == "time":
63 x = self.data.xrange[1]
63 x = self.data.xrange[1]
64 self.xlabel = "Time (ms)"
64 self.xlabel = "Time (ms)"
65 else:
65 else:
66 x = self.data.xrange[2]
66 x = self.data.xrange[2]
67 self.xlabel = "Velocity (m/s)"
67 self.xlabel = "Velocity (m/s)"
68
68
69 if self.CODE == 'spc_mean':
69 if self.CODE == 'spc_moments':
70 x = self.data.xrange[2]
70 x = self.data.xrange[2]
71 self.xlabel = "Velocity (m/s)"
71 self.xlabel = "Velocity (m/s)"
72
72
73 self.titles = []
73 self.titles = []
74
74
75 y = self.data.heights
75 y = self.data.heights
76 self.y = y
76 self.y = y
77 z = self.data['spc']
77 z = self.data['spc']
78
78
79 for n, ax in enumerate(self.axes):
79 for n, ax in enumerate(self.axes):
80 noise = self.data['noise'][n][-1]
80 noise = self.data['noise'][n][-1]
81 if self.CODE == 'spc_mean':
81 if self.CODE == 'spc_moments':
82 mean = self.data['mean'][n][-1]
82 mean = self.data['moments'][n, :, 1, :][-1]
83 if ax.firsttime:
83 if ax.firsttime:
84 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
84 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
85 self.xmin = self.xmin if self.xmin else -self.xmax
85 self.xmin = self.xmin if self.xmin else -self.xmax
86 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
86 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
87 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
87 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
88 ax.plt = ax.pcolormesh(x, y, z[n].T,
88 ax.plt = ax.pcolormesh(x, y, z[n].T,
89 vmin=self.zmin,
89 vmin=self.zmin,
90 vmax=self.zmax,
90 vmax=self.zmax,
91 cmap=plt.get_cmap(self.colormap)
91 cmap=plt.get_cmap(self.colormap)
92 )
92 )
93
93
94 if self.showprofile:
94 if self.showprofile:
95 ax.plt_profile = self.pf_axes[n].plot(
95 ax.plt_profile = self.pf_axes[n].plot(
96 self.data['rti'][n][-1], y)[0]
96 self.data['rti'][n][-1], y)[0]
97 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
97 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
98 color="k", linestyle="dashed", lw=1)[0]
98 color="k", linestyle="dashed", lw=1)[0]
99 if self.CODE == 'spc_mean':
99 if self.CODE == 'spc_moments':
100 ax.plt_mean = ax.plot(mean, y, color='k')[0]
100 ax.plt_mean = ax.plot(mean, y, color='k')[0]
101 else:
101 else:
102 ax.plt.set_array(z[n].T.ravel())
102 ax.plt.set_array(z[n].T.ravel())
103 if self.showprofile:
103 if self.showprofile:
104 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
104 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
105 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
105 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
106 if self.CODE == 'spc_mean':
106 if self.CODE == 'spc_moments':
107 ax.plt_mean.set_data(mean, y)
107 ax.plt_mean.set_data(mean, y)
108
109 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
108 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
110
109
111
110
112 class CrossSpectraPlot(Plot):
111 class CrossSpectraPlot(Plot):
113
112
114 CODE = 'cspc'
113 CODE = 'cspc'
115 colormap = 'jet'
114 colormap = 'jet'
116 zmin_coh = None
115 zmin_coh = None
117 zmax_coh = None
116 zmax_coh = None
118 zmin_phase = None
117 zmin_phase = None
119 zmax_phase = None
118 zmax_phase = None
120
119
121 def setup(self):
120 def setup(self):
122
121
123 self.ncols = 4
122 self.ncols = 4
124 self.nrows = len(self.data.pairs)
123 self.nrows = len(self.data.pairs)
125 self.nplots = self.nrows * 4
124 self.nplots = self.nrows * 4
126 self.width = 3.4 * self.ncols
125 self.width = 3.4 * self.ncols
127 self.height = 3 * self.nrows
126 self.height = 3 * self.nrows
128 self.ylabel = 'Range [km]'
127 self.ylabel = 'Range [km]'
129 self.showprofile = False
128 self.showprofile = False
130
129
131 def plot(self):
130 def plot(self):
132
131
133 if self.xaxis == "frequency":
132 if self.xaxis == "frequency":
134 x = self.data.xrange[0]
133 x = self.data.xrange[0]
135 self.xlabel = "Frequency (kHz)"
134 self.xlabel = "Frequency (kHz)"
136 elif self.xaxis == "time":
135 elif self.xaxis == "time":
137 x = self.data.xrange[1]
136 x = self.data.xrange[1]
138 self.xlabel = "Time (ms)"
137 self.xlabel = "Time (ms)"
139 else:
138 else:
140 x = self.data.xrange[2]
139 x = self.data.xrange[2]
141 self.xlabel = "Velocity (m/s)"
140 self.xlabel = "Velocity (m/s)"
142
141
143 self.titles = []
142 self.titles = []
144
143
145 y = self.data.heights
144 y = self.data.heights
146 self.y = y
145 self.y = y
147 spc = self.data['spc']
146 spc = self.data['spc']
148 cspc = self.data['cspc']
147 cspc = self.data['cspc']
149
148
150 for n in range(self.nrows):
149 for n in range(self.nrows):
151 noise = self.data['noise'][n][-1]
150 noise = self.data['noise'][n][-1]
152 pair = self.data.pairs[n]
151 pair = self.data.pairs[n]
153 ax = self.axes[4 * n]
152 ax = self.axes[4 * n]
154 spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor)
153 spc0 = 10.*numpy.log10(spc[pair[0]]/self.data.factor)
155 if ax.firsttime:
154 if ax.firsttime:
156 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
155 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
157 self.xmin = self.xmin if self.xmin else -self.xmax
156 self.xmin = self.xmin if self.xmin else -self.xmax
158 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
157 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
159 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
158 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
160 ax.plt = ax.pcolormesh(x , y , spc0.T,
159 ax.plt = ax.pcolormesh(x , y , spc0.T,
161 vmin=self.zmin,
160 vmin=self.zmin,
162 vmax=self.zmax,
161 vmax=self.zmax,
163 cmap=plt.get_cmap(self.colormap)
162 cmap=plt.get_cmap(self.colormap)
164 )
163 )
165 else:
164 else:
166 ax.plt.set_array(spc0.T.ravel())
165 ax.plt.set_array(spc0.T.ravel())
167 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise))
166 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise))
168
167
169 ax = self.axes[4 * n + 1]
168 ax = self.axes[4 * n + 1]
170 spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor)
169 spc1 = 10.*numpy.log10(spc[pair[1]]/self.data.factor)
171 if ax.firsttime:
170 if ax.firsttime:
172 ax.plt = ax.pcolormesh(x , y, spc1.T,
171 ax.plt = ax.pcolormesh(x , y, spc1.T,
173 vmin=self.zmin,
172 vmin=self.zmin,
174 vmax=self.zmax,
173 vmax=self.zmax,
175 cmap=plt.get_cmap(self.colormap)
174 cmap=plt.get_cmap(self.colormap)
176 )
175 )
177 else:
176 else:
178 ax.plt.set_array(spc1.T.ravel())
177 ax.plt.set_array(spc1.T.ravel())
179 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise))
178 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise))
180
179
181 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
180 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
182 coh = numpy.abs(out)
181 coh = numpy.abs(out)
183 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
182 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
184
183
185 ax = self.axes[4 * n + 2]
184 ax = self.axes[4 * n + 2]
186 if ax.firsttime:
185 if ax.firsttime:
187 ax.plt = ax.pcolormesh(x, y, coh.T,
186 ax.plt = ax.pcolormesh(x, y, coh.T,
188 vmin=0,
187 vmin=0,
189 vmax=1,
188 vmax=1,
190 cmap=plt.get_cmap(self.colormap_coh)
189 cmap=plt.get_cmap(self.colormap_coh)
191 )
190 )
192 else:
191 else:
193 ax.plt.set_array(coh.T.ravel())
192 ax.plt.set_array(coh.T.ravel())
194 self.titles.append(
193 self.titles.append(
195 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
194 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
196
195
197 ax = self.axes[4 * n + 3]
196 ax = self.axes[4 * n + 3]
198 if ax.firsttime:
197 if ax.firsttime:
199 ax.plt = ax.pcolormesh(x, y, phase.T,
198 ax.plt = ax.pcolormesh(x, y, phase.T,
200 vmin=-180,
199 vmin=-180,
201 vmax=180,
200 vmax=180,
202 cmap=plt.get_cmap(self.colormap_phase)
201 cmap=plt.get_cmap(self.colormap_phase)
203 )
202 )
204 else:
203 else:
205 ax.plt.set_array(phase.T.ravel())
204 ax.plt.set_array(phase.T.ravel())
206 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
205 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
207
206
208
207
209 class SpectraMeanPlot(SpectraPlot):
208 class SpectralMomentsPlot(SpectraPlot):
210 '''
209 '''
211 Plot for Spectra and Mean
210 Plot for Spectral Moments
212 '''
211 '''
213 CODE = 'spc_mean'
212 CODE = 'spc_moments'
214 colormap = 'jro'
213 colormap = 'jro'
215
214
216
215
217 class RTIPlot(Plot):
216 class RTIPlot(Plot):
218 '''
217 '''
219 Plot for RTI data
218 Plot for RTI data
220 '''
219 '''
221
220
222 CODE = 'rti'
221 CODE = 'rti'
223 colormap = 'jro'
222 colormap = 'jro'
224
223
225 def setup(self):
224 def setup(self):
226 self.xaxis = 'time'
225 self.xaxis = 'time'
227 self.ncols = 1
226 self.ncols = 1
228 self.nrows = len(self.data.channels)
227 self.nrows = len(self.data.channels)
229 self.nplots = len(self.data.channels)
228 self.nplots = len(self.data.channels)
230 self.ylabel = 'Range [km]'
229 self.ylabel = 'Range [km]'
231 self.cb_label = 'dB'
230 self.cb_label = 'dB'
232 self.titles = ['{} Channel {}'.format(
231 self.titles = ['{} Channel {}'.format(
233 self.CODE.upper(), x) for x in range(self.nrows)]
232 self.CODE.upper(), x) for x in range(self.nrows)]
234
233
235 def plot(self):
234 def plot(self):
236 self.x = self.data.times
235 self.x = self.data.times
237 self.y = self.data.heights
236 self.y = self.data.heights
238 self.z = self.data[self.CODE]
237 self.z = self.data[self.CODE]
239 self.z = numpy.ma.masked_invalid(self.z)
238 self.z = numpy.ma.masked_invalid(self.z)
240
239
241 if self.decimation is None:
240 if self.decimation is None:
242 x, y, z = self.fill_gaps(self.x, self.y, self.z)
241 x, y, z = self.fill_gaps(self.x, self.y, self.z)
243 else:
242 else:
244 x, y, z = self.fill_gaps(*self.decimate())
243 x, y, z = self.fill_gaps(*self.decimate())
245
244
246 for n, ax in enumerate(self.axes):
245 for n, ax in enumerate(self.axes):
247 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
246 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
248 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
247 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
249 if ax.firsttime:
248 if ax.firsttime:
250 ax.plt = ax.pcolormesh(x, y, z[n].T,
249 ax.plt = ax.pcolormesh(x, y, z[n].T,
251 vmin=self.zmin,
250 vmin=self.zmin,
252 vmax=self.zmax,
251 vmax=self.zmax,
253 cmap=plt.get_cmap(self.colormap)
252 cmap=plt.get_cmap(self.colormap)
254 )
253 )
255 if self.showprofile:
254 if self.showprofile:
256 ax.plot_profile = self.pf_axes[n].plot(
255 ax.plot_profile = self.pf_axes[n].plot(
257 self.data['rti'][n][-1], self.y)[0]
256 self.data['rti'][n][-1], self.y)[0]
258 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
257 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
259 color="k", linestyle="dashed", lw=1)[0]
258 color="k", linestyle="dashed", lw=1)[0]
260 else:
259 else:
261 ax.collections.remove(ax.collections[0])
260 ax.collections.remove(ax.collections[0])
262 ax.plt = ax.pcolormesh(x, y, z[n].T,
261 ax.plt = ax.pcolormesh(x, y, z[n].T,
263 vmin=self.zmin,
262 vmin=self.zmin,
264 vmax=self.zmax,
263 vmax=self.zmax,
265 cmap=plt.get_cmap(self.colormap)
264 cmap=plt.get_cmap(self.colormap)
266 )
265 )
267 if self.showprofile:
266 if self.showprofile:
268 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
267 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
269 ax.plot_noise.set_data(numpy.repeat(
268 ax.plot_noise.set_data(numpy.repeat(
270 self.data['noise'][n][-1], len(self.y)), self.y)
269 self.data['noise'][n][-1], len(self.y)), self.y)
271
270
272
271
273 class CoherencePlot(RTIPlot):
272 class CoherencePlot(RTIPlot):
274 '''
273 '''
275 Plot for Coherence data
274 Plot for Coherence data
276 '''
275 '''
277
276
278 CODE = 'coh'
277 CODE = 'coh'
279
278
280 def setup(self):
279 def setup(self):
281 self.xaxis = 'time'
280 self.xaxis = 'time'
282 self.ncols = 1
281 self.ncols = 1
283 self.nrows = len(self.data.pairs)
282 self.nrows = len(self.data.pairs)
284 self.nplots = len(self.data.pairs)
283 self.nplots = len(self.data.pairs)
285 self.ylabel = 'Range [km]'
284 self.ylabel = 'Range [km]'
286 if self.CODE == 'coh':
285 if self.CODE == 'coh':
287 self.cb_label = ''
286 self.cb_label = ''
288 self.titles = [
287 self.titles = [
289 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
288 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
290 else:
289 else:
291 self.cb_label = 'Degrees'
290 self.cb_label = 'Degrees'
292 self.titles = [
291 self.titles = [
293 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
292 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
294
293
295
294
296 class PhasePlot(CoherencePlot):
295 class PhasePlot(CoherencePlot):
297 '''
296 '''
298 Plot for Phase map data
297 Plot for Phase map data
299 '''
298 '''
300
299
301 CODE = 'phase'
300 CODE = 'phase'
302 colormap = 'seismic'
301 colormap = 'seismic'
303
302
304
303
305 class NoisePlot(Plot):
304 class NoisePlot(Plot):
306 '''
305 '''
307 Plot for noise
306 Plot for noise
308 '''
307 '''
309
308
310 CODE = 'noise'
309 CODE = 'noise'
311
310
312 def setup(self):
311 def setup(self):
313 self.xaxis = 'time'
312 self.xaxis = 'time'
314 self.ncols = 1
313 self.ncols = 1
315 self.nrows = 1
314 self.nrows = 1
316 self.nplots = 1
315 self.nplots = 1
317 self.ylabel = 'Intensity [dB]'
316 self.ylabel = 'Intensity [dB]'
318 self.titles = ['Noise']
317 self.titles = ['Noise']
319 self.colorbar = False
318 self.colorbar = False
320
319
321 def plot(self):
320 def plot(self):
322
321
323 x = self.data.times
322 x = self.data.times
324 xmin = self.data.min_time
323 xmin = self.data.min_time
325 xmax = xmin + self.xrange * 60 * 60
324 xmax = xmin + self.xrange * 60 * 60
326 Y = self.data[self.CODE]
325 Y = self.data[self.CODE]
327
326
328 if self.axes[0].firsttime:
327 if self.axes[0].firsttime:
329 for ch in self.data.channels:
328 for ch in self.data.channels:
330 y = Y[ch]
329 y = Y[ch]
331 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
330 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
332 plt.legend()
331 plt.legend()
333 else:
332 else:
334 for ch in self.data.channels:
333 for ch in self.data.channels:
335 y = Y[ch]
334 y = Y[ch]
336 self.axes[0].lines[ch].set_data(x, y)
335 self.axes[0].lines[ch].set_data(x, y)
337
336
338 self.ymin = numpy.nanmin(Y) - 5
337 self.ymin = numpy.nanmin(Y) - 5
339 self.ymax = numpy.nanmax(Y) + 5
338 self.ymax = numpy.nanmax(Y) + 5
340
339
341
340
342 class SnrPlot(RTIPlot):
341 class SnrPlot(RTIPlot):
343 '''
342 '''
344 Plot for SNR Data
343 Plot for SNR Data
345 '''
344 '''
346
345
347 CODE = 'snr'
346 CODE = 'snr'
348 colormap = 'jet'
347 colormap = 'jet'
349
348
350
349
351 class DopplerPlot(RTIPlot):
350 class DopplerPlot(RTIPlot):
352 '''
351 '''
353 Plot for DOPPLER Data
352 Plot for DOPPLER Data
354 '''
353 '''
355
354
356 CODE = 'dop'
355 CODE = 'dop'
357 colormap = 'jet'
356 colormap = 'jet'
358
357
359
358
360 class SkyMapPlot(Plot):
359 class SkyMapPlot(Plot):
361 '''
360 '''
362 Plot for meteors detection data
361 Plot for meteors detection data
363 '''
362 '''
364
363
365 CODE = 'param'
364 CODE = 'param'
366
365
367 def setup(self):
366 def setup(self):
368
367
369 self.ncols = 1
368 self.ncols = 1
370 self.nrows = 1
369 self.nrows = 1
371 self.width = 7.2
370 self.width = 7.2
372 self.height = 7.2
371 self.height = 7.2
373 self.nplots = 1
372 self.nplots = 1
374 self.xlabel = 'Zonal Zenith Angle (deg)'
373 self.xlabel = 'Zonal Zenith Angle (deg)'
375 self.ylabel = 'Meridional Zenith Angle (deg)'
374 self.ylabel = 'Meridional Zenith Angle (deg)'
376 self.polar = True
375 self.polar = True
377 self.ymin = -180
376 self.ymin = -180
378 self.ymax = 180
377 self.ymax = 180
379 self.colorbar = False
378 self.colorbar = False
380
379
381 def plot(self):
380 def plot(self):
382
381
383 arrayParameters = numpy.concatenate(self.data['param'])
382 arrayParameters = numpy.concatenate(self.data['param'])
384 error = arrayParameters[:, -1]
383 error = arrayParameters[:, -1]
385 indValid = numpy.where(error == 0)[0]
384 indValid = numpy.where(error == 0)[0]
386 finalMeteor = arrayParameters[indValid, :]
385 finalMeteor = arrayParameters[indValid, :]
387 finalAzimuth = finalMeteor[:, 3]
386 finalAzimuth = finalMeteor[:, 3]
388 finalZenith = finalMeteor[:, 4]
387 finalZenith = finalMeteor[:, 4]
389
388
390 x = finalAzimuth * numpy.pi / 180
389 x = finalAzimuth * numpy.pi / 180
391 y = finalZenith
390 y = finalZenith
392
391
393 ax = self.axes[0]
392 ax = self.axes[0]
394
393
395 if ax.firsttime:
394 if ax.firsttime:
396 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
395 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
397 else:
396 else:
398 ax.plot.set_data(x, y)
397 ax.plot.set_data(x, y)
399
398
400 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
399 dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S')
401 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
400 dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S')
402 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
401 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
403 dt2,
402 dt2,
404 len(x))
403 len(x))
405 self.titles[0] = title
404 self.titles[0] = title
406
405
407
406
408 class ParametersPlot(RTIPlot):
407 class ParametersPlot(RTIPlot):
409 '''
408 '''
410 Plot for data_param object
409 Plot for data_param object
411 '''
410 '''
412
411
413 CODE = 'param'
412 CODE = 'param'
414 colormap = 'seismic'
413 colormap = 'seismic'
415
414
416 def setup(self):
415 def setup(self):
417 self.xaxis = 'time'
416 self.xaxis = 'time'
418 self.ncols = 1
417 self.ncols = 1
419 self.nrows = self.data.shape(self.CODE)[0]
418 self.nrows = self.data.shape(self.CODE)[0]
420 self.nplots = self.nrows
419 self.nplots = self.nrows
421 if self.showSNR:
420 if self.showSNR:
422 self.nrows += 1
421 self.nrows += 1
423 self.nplots += 1
422 self.nplots += 1
424
423
425 self.ylabel = 'Height [km]'
424 self.ylabel = 'Height [km]'
426 if not self.titles:
425 if not self.titles:
427 self.titles = self.data.parameters \
426 self.titles = self.data.parameters \
428 if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)]
427 if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)]
429 if self.showSNR:
428 if self.showSNR:
430 self.titles.append('SNR')
429 self.titles.append('SNR')
431
430
432 def plot(self):
431 def plot(self):
433 self.data.normalize_heights()
432 self.data.normalize_heights()
434 self.x = self.data.times
433 self.x = self.data.times
435 self.y = self.data.heights
434 self.y = self.data.heights
436 if self.showSNR:
435 if self.showSNR:
437 self.z = numpy.concatenate(
436 self.z = numpy.concatenate(
438 (self.data[self.CODE], self.data['snr'])
437 (self.data[self.CODE], self.data['snr'])
439 )
438 )
440 else:
439 else:
441 self.z = self.data[self.CODE]
440 self.z = self.data[self.CODE]
442
441
443 self.z = numpy.ma.masked_invalid(self.z)
442 self.z = numpy.ma.masked_invalid(self.z)
444
443
445 if self.decimation is None:
444 if self.decimation is None:
446 x, y, z = self.fill_gaps(self.x, self.y, self.z)
445 x, y, z = self.fill_gaps(self.x, self.y, self.z)
447 else:
446 else:
448 x, y, z = self.fill_gaps(*self.decimate())
447 x, y, z = self.fill_gaps(*self.decimate())
449
448
450 for n, ax in enumerate(self.axes):
449 for n, ax in enumerate(self.axes):
451
450
452 self.zmax = self.zmax if self.zmax is not None else numpy.max(
451 self.zmax = self.zmax if self.zmax is not None else numpy.max(
453 self.z[n])
452 self.z[n])
454 self.zmin = self.zmin if self.zmin is not None else numpy.min(
453 self.zmin = self.zmin if self.zmin is not None else numpy.min(
455 self.z[n])
454 self.z[n])
456
455
457 if ax.firsttime:
456 if ax.firsttime:
458 if self.zlimits is not None:
457 if self.zlimits is not None:
459 self.zmin, self.zmax = self.zlimits[n]
458 self.zmin, self.zmax = self.zlimits[n]
460
459
461 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
460 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
462 vmin=self.zmin,
461 vmin=self.zmin,
463 vmax=self.zmax,
462 vmax=self.zmax,
464 cmap=self.cmaps[n]
463 cmap=self.cmaps[n]
465 )
464 )
466 else:
465 else:
467 if self.zlimits is not None:
466 if self.zlimits is not None:
468 self.zmin, self.zmax = self.zlimits[n]
467 self.zmin, self.zmax = self.zlimits[n]
469 ax.collections.remove(ax.collections[0])
468 ax.collections.remove(ax.collections[0])
470 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
469 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
471 vmin=self.zmin,
470 vmin=self.zmin,
472 vmax=self.zmax,
471 vmax=self.zmax,
473 cmap=self.cmaps[n]
472 cmap=self.cmaps[n]
474 )
473 )
475
474
476
475
477 class OutputPlot(ParametersPlot):
476 class OutputPlot(ParametersPlot):
478 '''
477 '''
479 Plot data_output object
478 Plot data_output object
480 '''
479 '''
481
480
482 CODE = 'output'
481 CODE = 'output'
483 colormap = 'seismic'
482 colormap = 'seismic'
484
483
485
484
486 class PolarMapPlot(Plot):
485 class PolarMapPlot(Plot):
487 '''
486 '''
488 Plot for weather radar
487 Plot for weather radar
489 '''
488 '''
490
489
491 CODE = 'param'
490 CODE = 'param'
492 colormap = 'seismic'
491 colormap = 'seismic'
493
492
494 def setup(self):
493 def setup(self):
495 self.ncols = 1
494 self.ncols = 1
496 self.nrows = 1
495 self.nrows = 1
497 self.width = 9
496 self.width = 9
498 self.height = 8
497 self.height = 8
499 self.mode = self.data.meta['mode']
498 self.mode = self.data.meta['mode']
500 if self.channels is not None:
499 if self.channels is not None:
501 self.nplots = len(self.channels)
500 self.nplots = len(self.channels)
502 self.nrows = len(self.channels)
501 self.nrows = len(self.channels)
503 else:
502 else:
504 self.nplots = self.data.shape(self.CODE)[0]
503 self.nplots = self.data.shape(self.CODE)[0]
505 self.nrows = self.nplots
504 self.nrows = self.nplots
506 self.channels = list(range(self.nplots))
505 self.channels = list(range(self.nplots))
507 if self.mode == 'E':
506 if self.mode == 'E':
508 self.xlabel = 'Longitude'
507 self.xlabel = 'Longitude'
509 self.ylabel = 'Latitude'
508 self.ylabel = 'Latitude'
510 else:
509 else:
511 self.xlabel = 'Range (km)'
510 self.xlabel = 'Range (km)'
512 self.ylabel = 'Height (km)'
511 self.ylabel = 'Height (km)'
513 self.bgcolor = 'white'
512 self.bgcolor = 'white'
514 self.cb_labels = self.data.meta['units']
513 self.cb_labels = self.data.meta['units']
515 self.lat = self.data.meta['latitude']
514 self.lat = self.data.meta['latitude']
516 self.lon = self.data.meta['longitude']
515 self.lon = self.data.meta['longitude']
517 self.xmin, self.xmax = float(
516 self.xmin, self.xmax = float(
518 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
517 km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon)
519 self.ymin, self.ymax = float(
518 self.ymin, self.ymax = float(
520 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
519 km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat)
521 # self.polar = True
520 # self.polar = True
522
521
523 def plot(self):
522 def plot(self):
524
523
525 for n, ax in enumerate(self.axes):
524 for n, ax in enumerate(self.axes):
526 data = self.data['param'][self.channels[n]]
525 data = self.data['param'][self.channels[n]]
527
526
528 zeniths = numpy.linspace(
527 zeniths = numpy.linspace(
529 0, self.data.meta['max_range'], data.shape[1])
528 0, self.data.meta['max_range'], data.shape[1])
530 if self.mode == 'E':
529 if self.mode == 'E':
531 azimuths = -numpy.radians(self.data.heights)+numpy.pi/2
530 azimuths = -numpy.radians(self.data.heights)+numpy.pi/2
532 r, theta = numpy.meshgrid(zeniths, azimuths)
531 r, theta = numpy.meshgrid(zeniths, azimuths)
533 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
532 x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(
534 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
533 theta)*numpy.cos(numpy.radians(self.data.meta['elevation']))
535 x = km2deg(x) + self.lon
534 x = km2deg(x) + self.lon
536 y = km2deg(y) + self.lat
535 y = km2deg(y) + self.lat
537 else:
536 else:
538 azimuths = numpy.radians(self.data.heights)
537 azimuths = numpy.radians(self.data.heights)
539 r, theta = numpy.meshgrid(zeniths, azimuths)
538 r, theta = numpy.meshgrid(zeniths, azimuths)
540 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
539 x, y = r*numpy.cos(theta), r*numpy.sin(theta)
541 self.y = zeniths
540 self.y = zeniths
542
541
543 if ax.firsttime:
542 if ax.firsttime:
544 if self.zlimits is not None:
543 if self.zlimits is not None:
545 self.zmin, self.zmax = self.zlimits[n]
544 self.zmin, self.zmax = self.zlimits[n]
546 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
545 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
547 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
546 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
548 vmin=self.zmin,
547 vmin=self.zmin,
549 vmax=self.zmax,
548 vmax=self.zmax,
550 cmap=self.cmaps[n])
549 cmap=self.cmaps[n])
551 else:
550 else:
552 if self.zlimits is not None:
551 if self.zlimits is not None:
553 self.zmin, self.zmax = self.zlimits[n]
552 self.zmin, self.zmax = self.zlimits[n]
554 ax.collections.remove(ax.collections[0])
553 ax.collections.remove(ax.collections[0])
555 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
554 ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)),
556 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
555 x, y, numpy.ma.array(data, mask=numpy.isnan(data)),
557 vmin=self.zmin,
556 vmin=self.zmin,
558 vmax=self.zmax,
557 vmax=self.zmax,
559 cmap=self.cmaps[n])
558 cmap=self.cmaps[n])
560
559
561 if self.mode == 'A':
560 if self.mode == 'A':
562 continue
561 continue
563
562
564 # plot district names
563 # plot district names
565 f = open('/data/workspace/schain_scripts/distrito.csv')
564 f = open('/data/workspace/schain_scripts/distrito.csv')
566 for line in f:
565 for line in f:
567 label, lon, lat = [s.strip() for s in line.split(',') if s]
566 label, lon, lat = [s.strip() for s in line.split(',') if s]
568 lat = float(lat)
567 lat = float(lat)
569 lon = float(lon)
568 lon = float(lon)
570 # ax.plot(lon, lat, '.b', ms=2)
569 # ax.plot(lon, lat, '.b', ms=2)
571 ax.text(lon, lat, label.decode('utf8'), ha='center',
570 ax.text(lon, lat, label.decode('utf8'), ha='center',
572 va='bottom', size='8', color='black')
571 va='bottom', size='8', color='black')
573
572
574 # plot limites
573 # plot limites
575 limites = []
574 limites = []
576 tmp = []
575 tmp = []
577 for line in open('/data/workspace/schain_scripts/lima.csv'):
576 for line in open('/data/workspace/schain_scripts/lima.csv'):
578 if '#' in line:
577 if '#' in line:
579 if tmp:
578 if tmp:
580 limites.append(tmp)
579 limites.append(tmp)
581 tmp = []
580 tmp = []
582 continue
581 continue
583 values = line.strip().split(',')
582 values = line.strip().split(',')
584 tmp.append((float(values[0]), float(values[1])))
583 tmp.append((float(values[0]), float(values[1])))
585 for points in limites:
584 for points in limites:
586 ax.add_patch(
585 ax.add_patch(
587 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
586 Polygon(points, ec='k', fc='none', ls='--', lw=0.5))
588
587
589 # plot Cuencas
588 # plot Cuencas
590 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
589 for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'):
591 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
590 f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca))
592 values = [line.strip().split(',') for line in f]
591 values = [line.strip().split(',') for line in f]
593 points = [(float(s[0]), float(s[1])) for s in values]
592 points = [(float(s[0]), float(s[1])) for s in values]
594 ax.add_patch(Polygon(points, ec='b', fc='none'))
593 ax.add_patch(Polygon(points, ec='b', fc='none'))
595
594
596 # plot grid
595 # plot grid
597 for r in (15, 30, 45, 60):
596 for r in (15, 30, 45, 60):
598 ax.add_artist(plt.Circle((self.lon, self.lat),
597 ax.add_artist(plt.Circle((self.lon, self.lat),
599 km2deg(r), color='0.6', fill=False, lw=0.2))
598 km2deg(r), color='0.6', fill=False, lw=0.2))
600 ax.text(
599 ax.text(
601 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
600 self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180),
602 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
601 self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180),
603 '{}km'.format(r),
602 '{}km'.format(r),
604 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
603 ha='center', va='bottom', size='8', color='0.6', weight='heavy')
605
604
606 if self.mode == 'E':
605 if self.mode == 'E':
607 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
606 title = 'El={}$^\circ$'.format(self.data.meta['elevation'])
608 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
607 label = 'E{:02d}'.format(int(self.data.meta['elevation']))
609 else:
608 else:
610 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
609 title = 'Az={}$^\circ$'.format(self.data.meta['azimuth'])
611 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
610 label = 'A{:02d}'.format(int(self.data.meta['azimuth']))
612
611
613 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
612 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
614 self.titles = ['{} {}'.format(
613 self.titles = ['{} {}'.format(
615 self.data.parameters[x], title) for x in self.channels]
614 self.data.parameters[x], title) for x in self.channels]
616
615
617 class ScopePlot(Plot):
616 class ScopePlot(Plot):
618
617
619 '''
618 '''
620 Plot for Scope
619 Plot for Scope
621 '''
620 '''
622
621
623 CODE = 'scope'
622 CODE = 'scope'
624
623
625 def setup(self):
624 def setup(self):
626
625
627 self.xaxis = 'Range (Km)'
626 self.xaxis = 'Range (Km)'
628 self.ncols = 1
627 self.ncols = 1
629 self.nrows = 1
628 self.nrows = 1
630 self.nplots = 1
629 self.nplots = 1
631 self.ylabel = 'Intensity [dB]'
630 self.ylabel = 'Intensity [dB]'
632 self.titles = ['Scope']
631 self.titles = ['Scope']
633 self.colorbar = False
632 self.colorbar = False
634 colspan = 3
633 colspan = 3
635 rowspan = 1
634 rowspan = 1
636
635
637 def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle):
636 def plot_iq(self, x, y, channelIndexList, thisDatetime, wintitle):
638
637
639 yreal = y[channelIndexList,:].real
638 yreal = y[channelIndexList,:].real
640 yimag = y[channelIndexList,:].imag
639 yimag = y[channelIndexList,:].imag
641 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
640 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
642 self.xlabel = "Range (Km)"
641 self.xlabel = "Range (Km)"
643 self.ylabel = "Intensity - IQ"
642 self.ylabel = "Intensity - IQ"
644
643
645 self.y = yreal
644 self.y = yreal
646 self.x = x
645 self.x = x
647 self.xmin = min(x)
646 self.xmin = min(x)
648 self.xmax = max(x)
647 self.xmax = max(x)
649
648
650
649
651 self.titles[0] = title
650 self.titles[0] = title
652
651
653 for i,ax in enumerate(self.axes):
652 for i,ax in enumerate(self.axes):
654 title = "Channel %d" %(i)
653 title = "Channel %d" %(i)
655 if ax.firsttime:
654 if ax.firsttime:
656 ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0]
655 ax.plt_r = ax.plot(x, yreal[i,:], color='b')[0]
657 ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0]
656 ax.plt_i = ax.plot(x, yimag[i,:], color='r')[0]
658 else:
657 else:
659 #pass
658 #pass
660 ax.plt_r.set_data(x, yreal[i,:])
659 ax.plt_r.set_data(x, yreal[i,:])
661 ax.plt_i.set_data(x, yimag[i,:])
660 ax.plt_i.set_data(x, yimag[i,:])
662
661
663 def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle):
662 def plot_power(self, x, y, channelIndexList, thisDatetime, wintitle):
664 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
663 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
665 yreal = y.real
664 yreal = y.real
666 self.y = yreal
665 self.y = yreal
667 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
666 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y"))
668 self.xlabel = "Range (Km)"
667 self.xlabel = "Range (Km)"
669 self.ylabel = "Intensity"
668 self.ylabel = "Intensity"
670 self.xmin = min(x)
669 self.xmin = min(x)
671 self.xmax = max(x)
670 self.xmax = max(x)
672
671
673
672
674 self.titles[0] = title
673 self.titles[0] = title
675
674
676 for i,ax in enumerate(self.axes):
675 for i,ax in enumerate(self.axes):
677 title = "Channel %d" %(i)
676 title = "Channel %d" %(i)
678
677
679 ychannel = yreal[i,:]
678 ychannel = yreal[i,:]
680
679
681 if ax.firsttime:
680 if ax.firsttime:
682 ax.plt_r = ax.plot(x, ychannel)[0]
681 ax.plt_r = ax.plot(x, ychannel)[0]
683 else:
682 else:
684 #pass
683 #pass
685 ax.plt_r.set_data(x, ychannel)
684 ax.plt_r.set_data(x, ychannel)
686
685
687
686
688 def plot(self):
687 def plot(self):
689
688
690 if self.channels:
689 if self.channels:
691 channels = self.channels
690 channels = self.channels
692 else:
691 else:
693 channels = self.data.channels
692 channels = self.data.channels
694
693
695
694
696
695
697 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1])
696 thisDatetime = datetime.datetime.utcfromtimestamp(self.data.times[-1])
698
697
699 scope = self.data['scope']
698 scope = self.data['scope']
700
699
701
700
702 if self.data.flagDataAsBlock:
701 if self.data.flagDataAsBlock:
703
702
704 for i in range(self.data.nProfiles):
703 for i in range(self.data.nProfiles):
705
704
706 wintitle1 = " [Profile = %d] " %i
705 wintitle1 = " [Profile = %d] " %i
707
706
708 if self.type == "power":
707 if self.type == "power":
709 self.plot_power(self.data.heights,
708 self.plot_power(self.data.heights,
710 scope[:,i,:],
709 scope[:,i,:],
711 channels,
710 channels,
712 thisDatetime,
711 thisDatetime,
713 wintitle1
712 wintitle1
714 )
713 )
715
714
716 if self.type == "iq":
715 if self.type == "iq":
717 self.plot_iq(self.data.heights,
716 self.plot_iq(self.data.heights,
718 scope[:,i,:],
717 scope[:,i,:],
719 channels,
718 channels,
720 thisDatetime,
719 thisDatetime,
721 wintitle1
720 wintitle1
722 )
721 )
723
722
724
723
725
724
726
725
727
726
728 else:
727 else:
729 wintitle = " [Profile = %d] " %self.data.profileIndex
728 wintitle = " [Profile = %d] " %self.data.profileIndex
730
729
731 if self.type == "power":
730 if self.type == "power":
732 self.plot_power(self.data.heights,
731 self.plot_power(self.data.heights,
733 scope,
732 scope,
734 channels,
733 channels,
735 thisDatetime,
734 thisDatetime,
736 wintitle
735 wintitle
737 )
736 )
738
737
739 if self.type == "iq":
738 if self.type == "iq":
740 self.plot_iq(self.data.heights,
739 self.plot_iq(self.data.heights,
741 scope,
740 scope,
742 channels,
741 channels,
743 thisDatetime,
742 thisDatetime,
744 wintitle
743 wintitle
745 )
744 )
746
745
747
746
748 No newline at end of file
747
@@ -1,2394 +1,2394
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 from schainpy.model.proc.jroproc_base import MPDecorator
7 from schainpy.model.proc.jroproc_base import MPDecorator
8 from schainpy.utils import log
8 from schainpy.utils import log
9
9
10 class ParamLine_(Figure):
10 class ParamLine_(Figure):
11
11
12 isConfig = None
12 isConfig = None
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 self.isConfig = False
16 self.isConfig = False
17 self.WIDTH = 300
17 self.WIDTH = 300
18 self.HEIGHT = 200
18 self.HEIGHT = 200
19 self.counter_imagwr = 0
19 self.counter_imagwr = 0
20
20
21 def getSubplots(self):
21 def getSubplots(self):
22
22
23 nrow = self.nplots
23 nrow = self.nplots
24 ncol = 3
24 ncol = 3
25 return nrow, ncol
25 return nrow, ncol
26
26
27 def setup(self, id, nplots, wintitle, show):
27 def setup(self, id, nplots, wintitle, show):
28
28
29 self.nplots = nplots
29 self.nplots = nplots
30
30
31 self.createFigure(id=id,
31 self.createFigure(id=id,
32 wintitle=wintitle,
32 wintitle=wintitle,
33 show=show)
33 show=show)
34
34
35 nrow,ncol = self.getSubplots()
35 nrow,ncol = self.getSubplots()
36 colspan = 3
36 colspan = 3
37 rowspan = 1
37 rowspan = 1
38
38
39 for i in range(nplots):
39 for i in range(nplots):
40 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
40 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
41
41
42 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
42 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
43 yreal = y[channelIndexList,:].real
43 yreal = y[channelIndexList,:].real
44 yimag = y[channelIndexList,:].imag
44 yimag = y[channelIndexList,:].imag
45
45
46 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
46 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
47 xlabel = "Range (Km)"
47 xlabel = "Range (Km)"
48 ylabel = "Intensity - IQ"
48 ylabel = "Intensity - IQ"
49
49
50 if not self.isConfig:
50 if not self.isConfig:
51 nplots = len(channelIndexList)
51 nplots = len(channelIndexList)
52
52
53 self.setup(id=id,
53 self.setup(id=id,
54 nplots=nplots,
54 nplots=nplots,
55 wintitle='',
55 wintitle='',
56 show=show)
56 show=show)
57
57
58 if xmin == None: xmin = numpy.nanmin(x)
58 if xmin == None: xmin = numpy.nanmin(x)
59 if xmax == None: xmax = numpy.nanmax(x)
59 if xmax == None: xmax = numpy.nanmax(x)
60 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
60 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
61 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
61 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
62
62
63 self.isConfig = True
63 self.isConfig = True
64
64
65 self.setWinTitle(title)
65 self.setWinTitle(title)
66
66
67 for i in range(len(self.axesList)):
67 for i in range(len(self.axesList)):
68 title = "Channel %d" %(i)
68 title = "Channel %d" %(i)
69 axes = self.axesList[i]
69 axes = self.axesList[i]
70
70
71 axes.pline(x, yreal[i,:],
71 axes.pline(x, yreal[i,:],
72 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
72 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
73 xlabel=xlabel, ylabel=ylabel, title=title)
73 xlabel=xlabel, ylabel=ylabel, title=title)
74
74
75 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
75 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
76
76
77 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
77 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
78 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
78 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
79 yreal = y.real
79 yreal = y.real
80
80
81 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
81 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
82 xlabel = "Range (Km)"
82 xlabel = "Range (Km)"
83 ylabel = "Intensity"
83 ylabel = "Intensity"
84
84
85 if not self.isConfig:
85 if not self.isConfig:
86 nplots = len(channelIndexList)
86 nplots = len(channelIndexList)
87
87
88 self.setup(id=id,
88 self.setup(id=id,
89 nplots=nplots,
89 nplots=nplots,
90 wintitle='',
90 wintitle='',
91 show=show)
91 show=show)
92
92
93 if xmin == None: xmin = numpy.nanmin(x)
93 if xmin == None: xmin = numpy.nanmin(x)
94 if xmax == None: xmax = numpy.nanmax(x)
94 if xmax == None: xmax = numpy.nanmax(x)
95 if ymin == None: ymin = numpy.nanmin(yreal)
95 if ymin == None: ymin = numpy.nanmin(yreal)
96 if ymax == None: ymax = numpy.nanmax(yreal)
96 if ymax == None: ymax = numpy.nanmax(yreal)
97
97
98 self.isConfig = True
98 self.isConfig = True
99
99
100 self.setWinTitle(title)
100 self.setWinTitle(title)
101
101
102 for i in range(len(self.axesList)):
102 for i in range(len(self.axesList)):
103 title = "Channel %d" %(i)
103 title = "Channel %d" %(i)
104 axes = self.axesList[i]
104 axes = self.axesList[i]
105 ychannel = yreal[i,:]
105 ychannel = yreal[i,:]
106 axes.pline(x, ychannel,
106 axes.pline(x, ychannel,
107 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
107 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
108 xlabel=xlabel, ylabel=ylabel, title=title)
108 xlabel=xlabel, ylabel=ylabel, title=title)
109
109
110
110
111 def run(self, dataOut, id, wintitle="", channelList=None,
111 def run(self, dataOut, id, wintitle="", channelList=None,
112 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
112 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
113 figpath='./', figfile=None, show=True, wr_period=1,
113 figpath='./', figfile=None, show=True, wr_period=1,
114 ftp=False, server=None, folder=None, username=None, password=None):
114 ftp=False, server=None, folder=None, username=None, password=None):
115
115
116 """
116 """
117
117
118 Input:
118 Input:
119 dataOut :
119 dataOut :
120 id :
120 id :
121 wintitle :
121 wintitle :
122 channelList :
122 channelList :
123 xmin : None,
123 xmin : None,
124 xmax : None,
124 xmax : None,
125 ymin : None,
125 ymin : None,
126 ymax : None,
126 ymax : None,
127 """
127 """
128
128
129 if channelList == None:
129 if channelList == None:
130 channelIndexList = dataOut.channelIndexList
130 channelIndexList = dataOut.channelIndexList
131 else:
131 else:
132 channelIndexList = []
132 channelIndexList = []
133 for channel in channelList:
133 for channel in channelList:
134 if channel not in dataOut.channelList:
134 if channel not in dataOut.channelList:
135 raise ValueError("Channel %d is not in dataOut.channelList" % channel)
135 raise ValueError("Channel %d is not in dataOut.channelList" % channel)
136 channelIndexList.append(dataOut.channelList.index(channel))
136 channelIndexList.append(dataOut.channelList.index(channel))
137
137
138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
139
139
140 y = dataOut.RR
140 y = dataOut.RR
141
141
142 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
142 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
143 xlabel = "Range (Km)"
143 xlabel = "Range (Km)"
144 ylabel = "Intensity"
144 ylabel = "Intensity"
145
145
146 if not self.isConfig:
146 if not self.isConfig:
147 nplots = len(channelIndexList)
147 nplots = len(channelIndexList)
148
148
149 self.setup(id=id,
149 self.setup(id=id,
150 nplots=nplots,
150 nplots=nplots,
151 wintitle='',
151 wintitle='',
152 show=show)
152 show=show)
153
153
154 if xmin == None: xmin = numpy.nanmin(x)
154 if xmin == None: xmin = numpy.nanmin(x)
155 if xmax == None: xmax = numpy.nanmax(x)
155 if xmax == None: xmax = numpy.nanmax(x)
156 if ymin == None: ymin = numpy.nanmin(y)
156 if ymin == None: ymin = numpy.nanmin(y)
157 if ymax == None: ymax = numpy.nanmax(y)
157 if ymax == None: ymax = numpy.nanmax(y)
158
158
159 self.isConfig = True
159 self.isConfig = True
160
160
161 self.setWinTitle(title)
161 self.setWinTitle(title)
162
162
163 for i in range(len(self.axesList)):
163 for i in range(len(self.axesList)):
164 title = "Channel %d" %(i)
164 title = "Channel %d" %(i)
165 axes = self.axesList[i]
165 axes = self.axesList[i]
166 ychannel = y[i,:]
166 ychannel = y[i,:]
167 axes.pline(x, ychannel,
167 axes.pline(x, ychannel,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
168 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
169 xlabel=xlabel, ylabel=ylabel, title=title)
169 xlabel=xlabel, ylabel=ylabel, title=title)
170
170
171
171
172 self.draw()
172 self.draw()
173
173
174 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
174 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
175 figfile = self.getFilename(name = str_datetime)
175 figfile = self.getFilename(name = str_datetime)
176
176
177 self.save(figpath=figpath,
177 self.save(figpath=figpath,
178 figfile=figfile,
178 figfile=figfile,
179 save=save,
179 save=save,
180 ftp=ftp,
180 ftp=ftp,
181 wr_period=wr_period,
181 wr_period=wr_period,
182 thisDatetime=thisDatetime)
182 thisDatetime=thisDatetime)
183
183
184
184
185
185
186 class SpcParamPlot_(Figure):
186 class SpcParamPlot_(Figure):
187
187
188 isConfig = None
188 isConfig = None
189 __nsubplots = None
189 __nsubplots = None
190
190
191 WIDTHPROF = None
191 WIDTHPROF = None
192 HEIGHTPROF = None
192 HEIGHTPROF = None
193 PREFIX = 'SpcParam'
193 PREFIX = 'SpcParam'
194
194
195 def __init__(self, **kwargs):
195 def __init__(self, **kwargs):
196 Figure.__init__(self, **kwargs)
196 Figure.__init__(self, **kwargs)
197 self.isConfig = False
197 self.isConfig = False
198 self.__nsubplots = 1
198 self.__nsubplots = 1
199
199
200 self.WIDTH = 250
200 self.WIDTH = 250
201 self.HEIGHT = 250
201 self.HEIGHT = 250
202 self.WIDTHPROF = 120
202 self.WIDTHPROF = 120
203 self.HEIGHTPROF = 0
203 self.HEIGHTPROF = 0
204 self.counter_imagwr = 0
204 self.counter_imagwr = 0
205
205
206 self.PLOT_CODE = SPEC_CODE
206 self.PLOT_CODE = SPEC_CODE
207
207
208 self.FTP_WEI = None
208 self.FTP_WEI = None
209 self.EXP_CODE = None
209 self.EXP_CODE = None
210 self.SUB_EXP_CODE = None
210 self.SUB_EXP_CODE = None
211 self.PLOT_POS = None
211 self.PLOT_POS = None
212
212
213 self.__xfilter_ena = False
213 self.__xfilter_ena = False
214 self.__yfilter_ena = False
214 self.__yfilter_ena = False
215
215
216 def getSubplots(self):
216 def getSubplots(self):
217
217
218 ncol = int(numpy.sqrt(self.nplots)+0.9)
218 ncol = int(numpy.sqrt(self.nplots)+0.9)
219 nrow = int(self.nplots*1./ncol + 0.9)
219 nrow = int(self.nplots*1./ncol + 0.9)
220
220
221 return nrow, ncol
221 return nrow, ncol
222
222
223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
224
224
225 self.__showprofile = showprofile
225 self.__showprofile = showprofile
226 self.nplots = nplots
226 self.nplots = nplots
227
227
228 ncolspan = 1
228 ncolspan = 1
229 colspan = 1
229 colspan = 1
230 if showprofile:
230 if showprofile:
231 ncolspan = 3
231 ncolspan = 3
232 colspan = 2
232 colspan = 2
233 self.__nsubplots = 2
233 self.__nsubplots = 2
234
234
235 self.createFigure(id = id,
235 self.createFigure(id = id,
236 wintitle = wintitle,
236 wintitle = wintitle,
237 widthplot = self.WIDTH + self.WIDTHPROF,
237 widthplot = self.WIDTH + self.WIDTHPROF,
238 heightplot = self.HEIGHT + self.HEIGHTPROF,
238 heightplot = self.HEIGHT + self.HEIGHTPROF,
239 show=show)
239 show=show)
240
240
241 nrow, ncol = self.getSubplots()
241 nrow, ncol = self.getSubplots()
242
242
243 counter = 0
243 counter = 0
244 for y in range(nrow):
244 for y in range(nrow):
245 for x in range(ncol):
245 for x in range(ncol):
246
246
247 if counter >= self.nplots:
247 if counter >= self.nplots:
248 break
248 break
249
249
250 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
250 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
251
251
252 if showprofile:
252 if showprofile:
253 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
253 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
254
254
255 counter += 1
255 counter += 1
256
256
257 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
257 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
258 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
258 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
259 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
259 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
260 server=None, folder=None, username=None, password=None,
260 server=None, folder=None, username=None, password=None,
261 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
261 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
262 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
262 xaxis="frequency", colormap='jet', normFactor=None , Selector = 0):
263
263
264 """
264 """
265
265
266 Input:
266 Input:
267 dataOut :
267 dataOut :
268 id :
268 id :
269 wintitle :
269 wintitle :
270 channelList :
270 channelList :
271 showProfile :
271 showProfile :
272 xmin : None,
272 xmin : None,
273 xmax : None,
273 xmax : None,
274 ymin : None,
274 ymin : None,
275 ymax : None,
275 ymax : None,
276 zmin : None,
276 zmin : None,
277 zmax : None
277 zmax : None
278 """
278 """
279 if realtime:
279 if realtime:
280 if not(isRealtime(utcdatatime = dataOut.utctime)):
280 if not(isRealtime(utcdatatime = dataOut.utctime)):
281 print('Skipping this plot function')
281 print('Skipping this plot function')
282 return
282 return
283
283
284 if channelList == None:
284 if channelList == None:
285 channelIndexList = dataOut.channelIndexList
285 channelIndexList = dataOut.channelIndexList
286 else:
286 else:
287 channelIndexList = []
287 channelIndexList = []
288 for channel in channelList:
288 for channel in channelList:
289 if channel not in dataOut.channelList:
289 if channel not in dataOut.channelList:
290 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
290 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
291 channelIndexList.append(dataOut.channelList.index(channel))
291 channelIndexList.append(dataOut.channelList.index(channel))
292
292
293 # if normFactor is None:
293 # if normFactor is None:
294 # factor = dataOut.normFactor
294 # factor = dataOut.normFactor
295 # else:
295 # else:
296 # factor = normFactor
296 # factor = normFactor
297 if xaxis == "frequency":
297 if xaxis == "frequency":
298 x = dataOut.spcparam_range[0]
298 x = dataOut.spcparam_range[0]
299 xlabel = "Frequency (kHz)"
299 xlabel = "Frequency (kHz)"
300
300
301 elif xaxis == "time":
301 elif xaxis == "time":
302 x = dataOut.spcparam_range[1]
302 x = dataOut.spcparam_range[1]
303 xlabel = "Time (ms)"
303 xlabel = "Time (ms)"
304
304
305 else:
305 else:
306 x = dataOut.spcparam_range[2]
306 x = dataOut.spcparam_range[2]
307 xlabel = "Velocity (m/s)"
307 xlabel = "Velocity (m/s)"
308
308
309 ylabel = "Range (km)"
309 ylabel = "Range (km)"
310
310
311 y = dataOut.getHeiRange()
311 y = dataOut.getHeiRange()
312
312
313 z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor
313 z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor
314 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
314 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
315 zdB = 10*numpy.log10(z)
315 zdB = 10*numpy.log10(z)
316
316
317 avg = numpy.average(z, axis=1)
317 avg = numpy.average(z, axis=1)
318 avgdB = 10*numpy.log10(avg)
318 avgdB = 10*numpy.log10(avg)
319
319
320 noise = dataOut.spc_noise
320 noise = dataOut.spc_noise
321 noisedB = 10*numpy.log10(noise)
321 noisedB = 10*numpy.log10(noise)
322
322
323 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
323 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
324 title = wintitle + " Spectra"
324 title = wintitle + " Spectra"
325 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
325 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
326 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
326 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
327
327
328 if not self.isConfig:
328 if not self.isConfig:
329
329
330 nplots = len(channelIndexList)
330 nplots = len(channelIndexList)
331
331
332 self.setup(id=id,
332 self.setup(id=id,
333 nplots=nplots,
333 nplots=nplots,
334 wintitle=wintitle,
334 wintitle=wintitle,
335 showprofile=showprofile,
335 showprofile=showprofile,
336 show=show)
336 show=show)
337
337
338 if xmin == None: xmin = numpy.nanmin(x)
338 if xmin == None: xmin = numpy.nanmin(x)
339 if xmax == None: xmax = numpy.nanmax(x)
339 if xmax == None: xmax = numpy.nanmax(x)
340 if ymin == None: ymin = numpy.nanmin(y)
340 if ymin == None: ymin = numpy.nanmin(y)
341 if ymax == None: ymax = numpy.nanmax(y)
341 if ymax == None: ymax = numpy.nanmax(y)
342 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
342 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
343 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
343 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
344
344
345 self.FTP_WEI = ftp_wei
345 self.FTP_WEI = ftp_wei
346 self.EXP_CODE = exp_code
346 self.EXP_CODE = exp_code
347 self.SUB_EXP_CODE = sub_exp_code
347 self.SUB_EXP_CODE = sub_exp_code
348 self.PLOT_POS = plot_pos
348 self.PLOT_POS = plot_pos
349
349
350 self.isConfig = True
350 self.isConfig = True
351
351
352 self.setWinTitle(title)
352 self.setWinTitle(title)
353
353
354 for i in range(self.nplots):
354 for i in range(self.nplots):
355 index = channelIndexList[i]
355 index = channelIndexList[i]
356 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
356 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
357 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
357 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
358 if len(dataOut.beam.codeList) != 0:
358 if len(dataOut.beam.codeList) != 0:
359 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)
359 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)
360
360
361 axes = self.axesList[i*self.__nsubplots]
361 axes = self.axesList[i*self.__nsubplots]
362 axes.pcolor(x, y, zdB[index,:,:],
362 axes.pcolor(x, y, zdB[index,:,:],
363 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
363 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
364 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
364 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
365 ticksize=9, cblabel='')
365 ticksize=9, cblabel='')
366
366
367 if self.__showprofile:
367 if self.__showprofile:
368 axes = self.axesList[i*self.__nsubplots +1]
368 axes = self.axesList[i*self.__nsubplots +1]
369 axes.pline(avgdB[index,:], y,
369 axes.pline(avgdB[index,:], y,
370 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
370 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
371 xlabel='dB', ylabel='', title='',
371 xlabel='dB', ylabel='', title='',
372 ytick_visible=False,
372 ytick_visible=False,
373 grid='x')
373 grid='x')
374
374
375 noiseline = numpy.repeat(noisedB[index], len(y))
375 noiseline = numpy.repeat(noisedB[index], len(y))
376 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
376 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
377
377
378 self.draw()
378 self.draw()
379
379
380 if figfile == None:
380 if figfile == None:
381 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
381 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
382 name = str_datetime
382 name = str_datetime
383 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
383 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
384 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
384 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
385 figfile = self.getFilename(name)
385 figfile = self.getFilename(name)
386
386
387 self.save(figpath=figpath,
387 self.save(figpath=figpath,
388 figfile=figfile,
388 figfile=figfile,
389 save=save,
389 save=save,
390 ftp=ftp,
390 ftp=ftp,
391 wr_period=wr_period,
391 wr_period=wr_period,
392 thisDatetime=thisDatetime)
392 thisDatetime=thisDatetime)
393
393
394
394
395
395
396 class MomentsPlot_(Figure):
396 class MomentsPlot_(Figure):
397
397
398 isConfig = None
398 isConfig = None
399 __nsubplots = None
399 __nsubplots = None
400
400
401 WIDTHPROF = None
401 WIDTHPROF = None
402 HEIGHTPROF = None
402 HEIGHTPROF = None
403 PREFIX = 'prm'
403 PREFIX = 'prm'
404 def __init__(self):
404 def __init__(self):
405 Figure.__init__(self)
405 Figure.__init__(self)
406 self.isConfig = False
406 self.isConfig = False
407 self.__nsubplots = 1
407 self.__nsubplots = 1
408
408
409 self.WIDTH = 280
409 self.WIDTH = 280
410 self.HEIGHT = 250
410 self.HEIGHT = 250
411 self.WIDTHPROF = 120
411 self.WIDTHPROF = 120
412 self.HEIGHTPROF = 0
412 self.HEIGHTPROF = 0
413 self.counter_imagwr = 0
413 self.counter_imagwr = 0
414
414
415 self.PLOT_CODE = MOMENTS_CODE
415 self.PLOT_CODE = MOMENTS_CODE
416
416
417 self.FTP_WEI = None
417 self.FTP_WEI = None
418 self.EXP_CODE = None
418 self.EXP_CODE = None
419 self.SUB_EXP_CODE = None
419 self.SUB_EXP_CODE = None
420 self.PLOT_POS = None
420 self.PLOT_POS = None
421
421
422 def getSubplots(self):
422 def getSubplots(self):
423
423
424 ncol = int(numpy.sqrt(self.nplots)+0.9)
424 ncol = int(numpy.sqrt(self.nplots)+0.9)
425 nrow = int(self.nplots*1./ncol + 0.9)
425 nrow = int(self.nplots*1./ncol + 0.9)
426
426
427 return nrow, ncol
427 return nrow, ncol
428
428
429 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
429 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
430
430
431 self.__showprofile = showprofile
431 self.__showprofile = showprofile
432 self.nplots = nplots
432 self.nplots = nplots
433
433
434 ncolspan = 1
434 ncolspan = 1
435 colspan = 1
435 colspan = 1
436 if showprofile:
436 if showprofile:
437 ncolspan = 3
437 ncolspan = 3
438 colspan = 2
438 colspan = 2
439 self.__nsubplots = 2
439 self.__nsubplots = 2
440
440
441 self.createFigure(id = id,
441 self.createFigure(id = id,
442 wintitle = wintitle,
442 wintitle = wintitle,
443 widthplot = self.WIDTH + self.WIDTHPROF,
443 widthplot = self.WIDTH + self.WIDTHPROF,
444 heightplot = self.HEIGHT + self.HEIGHTPROF,
444 heightplot = self.HEIGHT + self.HEIGHTPROF,
445 show=show)
445 show=show)
446
446
447 nrow, ncol = self.getSubplots()
447 nrow, ncol = self.getSubplots()
448
448
449 counter = 0
449 counter = 0
450 for y in range(nrow):
450 for y in range(nrow):
451 for x in range(ncol):
451 for x in range(ncol):
452
452
453 if counter >= self.nplots:
453 if counter >= self.nplots:
454 break
454 break
455
455
456 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
456 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
457
457
458 if showprofile:
458 if showprofile:
459 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
459 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
460
460
461 counter += 1
461 counter += 1
462
462
463 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
463 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
464 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
464 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
465 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
465 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
466 server=None, folder=None, username=None, password=None,
466 server=None, folder=None, username=None, password=None,
467 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
467 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
468
468
469 """
469 """
470
470
471 Input:
471 Input:
472 dataOut :
472 dataOut :
473 id :
473 id :
474 wintitle :
474 wintitle :
475 channelList :
475 channelList :
476 showProfile :
476 showProfile :
477 xmin : None,
477 xmin : None,
478 xmax : None,
478 xmax : None,
479 ymin : None,
479 ymin : None,
480 ymax : None,
480 ymax : None,
481 zmin : None,
481 zmin : None,
482 zmax : None
482 zmax : None
483 """
483 """
484
484
485 if dataOut.flagNoData:
485 if dataOut.flagNoData:
486 return None
486 return None
487
487
488 if realtime:
488 if realtime:
489 if not(isRealtime(utcdatatime = dataOut.utctime)):
489 if not(isRealtime(utcdatatime = dataOut.utctime)):
490 print('Skipping this plot function')
490 print('Skipping this plot function')
491 return
491 return
492
492
493 if channelList == None:
493 if channelList == None:
494 channelIndexList = dataOut.channelIndexList
494 channelIndexList = dataOut.channelIndexList
495 else:
495 else:
496 channelIndexList = []
496 channelIndexList = []
497 for channel in channelList:
497 for channel in channelList:
498 if channel not in dataOut.channelList:
498 if channel not in dataOut.channelList:
499 raise ValueError("Channel %d is not in dataOut.channelList")
499 raise ValueError("Channel %d is not in dataOut.channelList")
500 channelIndexList.append(dataOut.channelList.index(channel))
500 channelIndexList.append(dataOut.channelList.index(channel))
501
501
502 factor = dataOut.normFactor
502 factor = dataOut.normFactor
503 x = dataOut.abscissaList
503 x = dataOut.abscissaList
504 y = dataOut.heightList
504 y = dataOut.heightList
505
505
506 z = dataOut.data_pre[channelIndexList,:,:]/factor
506 z = dataOut.data_pre[channelIndexList,:,:]/factor
507 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
507 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
508 avg = numpy.average(z, axis=1)
508 avg = numpy.average(z, axis=1)
509 noise = dataOut.noise/factor
509 noise = dataOut.noise/factor
510
510
511 zdB = 10*numpy.log10(z)
511 zdB = 10*numpy.log10(z)
512 avgdB = 10*numpy.log10(avg)
512 avgdB = 10*numpy.log10(avg)
513 noisedB = 10*numpy.log10(noise)
513 noisedB = 10*numpy.log10(noise)
514
514
515 #thisDatetime = dataOut.datatime
515 #thisDatetime = dataOut.datatime
516 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
516 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
517 title = wintitle + " Parameters"
517 title = wintitle + " Parameters"
518 xlabel = "Velocity (m/s)"
518 xlabel = "Velocity (m/s)"
519 ylabel = "Range (Km)"
519 ylabel = "Range (Km)"
520
520
521 update_figfile = False
521 update_figfile = False
522
522
523 if not self.isConfig:
523 if not self.isConfig:
524
524
525 nplots = len(channelIndexList)
525 nplots = len(channelIndexList)
526
526
527 self.setup(id=id,
527 self.setup(id=id,
528 nplots=nplots,
528 nplots=nplots,
529 wintitle=wintitle,
529 wintitle=wintitle,
530 showprofile=showprofile,
530 showprofile=showprofile,
531 show=show)
531 show=show)
532
532
533 if xmin == None: xmin = numpy.nanmin(x)
533 if xmin == None: xmin = numpy.nanmin(x)
534 if xmax == None: xmax = numpy.nanmax(x)
534 if xmax == None: xmax = numpy.nanmax(x)
535 if ymin == None: ymin = numpy.nanmin(y)
535 if ymin == None: ymin = numpy.nanmin(y)
536 if ymax == None: ymax = numpy.nanmax(y)
536 if ymax == None: ymax = numpy.nanmax(y)
537 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
537 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
538 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
538 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
539
539
540 self.FTP_WEI = ftp_wei
540 self.FTP_WEI = ftp_wei
541 self.EXP_CODE = exp_code
541 self.EXP_CODE = exp_code
542 self.SUB_EXP_CODE = sub_exp_code
542 self.SUB_EXP_CODE = sub_exp_code
543 self.PLOT_POS = plot_pos
543 self.PLOT_POS = plot_pos
544
544
545 self.isConfig = True
545 self.isConfig = True
546 update_figfile = True
546 update_figfile = True
547
547
548 self.setWinTitle(title)
548 self.setWinTitle(title)
549
549
550 for i in range(self.nplots):
550 for i in range(self.nplots):
551 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
551 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
552 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
552 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
553 axes = self.axesList[i*self.__nsubplots]
553 axes = self.axesList[i*self.__nsubplots]
554 axes.pcolor(x, y, zdB[i,:,:],
554 axes.pcolor(x, y, zdB[i,:,:],
555 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
555 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
556 xlabel=xlabel, ylabel=ylabel, title=title,
556 xlabel=xlabel, ylabel=ylabel, title=title,
557 ticksize=9, cblabel='')
557 ticksize=9, cblabel='')
558 #Mean Line
558 #Mean Line
559 mean = dataOut.data_param[i, 1, :]
559 mean = dataOut.data_param[i, 1, :]
560 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
560 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
561
561
562 if self.__showprofile:
562 if self.__showprofile:
563 axes = self.axesList[i*self.__nsubplots +1]
563 axes = self.axesList[i*self.__nsubplots +1]
564 axes.pline(avgdB[i], y,
564 axes.pline(avgdB[i], y,
565 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
565 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
566 xlabel='dB', ylabel='', title='',
566 xlabel='dB', ylabel='', title='',
567 ytick_visible=False,
567 ytick_visible=False,
568 grid='x')
568 grid='x')
569
569
570 noiseline = numpy.repeat(noisedB[i], len(y))
570 noiseline = numpy.repeat(noisedB[i], len(y))
571 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
571 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
572
572
573 self.draw()
573 self.draw()
574
574
575 self.save(figpath=figpath,
575 self.save(figpath=figpath,
576 figfile=figfile,
576 figfile=figfile,
577 save=save,
577 save=save,
578 ftp=ftp,
578 ftp=ftp,
579 wr_period=wr_period,
579 wr_period=wr_period,
580 thisDatetime=thisDatetime)
580 thisDatetime=thisDatetime)
581
581
582
582
583 class SkyMapPlot_(Figure):
583 class SkyMapPlot_(Figure):
584
584
585 __isConfig = None
585 __isConfig = None
586 __nsubplots = None
586 __nsubplots = None
587
587
588 WIDTHPROF = None
588 WIDTHPROF = None
589 HEIGHTPROF = None
589 HEIGHTPROF = None
590 PREFIX = 'mmap'
590 PREFIX = 'mmap'
591
591
592 def __init__(self, **kwargs):
592 def __init__(self, **kwargs):
593 Figure.__init__(self, **kwargs)
593 Figure.__init__(self, **kwargs)
594 self.isConfig = False
594 self.isConfig = False
595 self.__nsubplots = 1
595 self.__nsubplots = 1
596
596
597 # self.WIDTH = 280
597 # self.WIDTH = 280
598 # self.HEIGHT = 250
598 # self.HEIGHT = 250
599 self.WIDTH = 600
599 self.WIDTH = 600
600 self.HEIGHT = 600
600 self.HEIGHT = 600
601 self.WIDTHPROF = 120
601 self.WIDTHPROF = 120
602 self.HEIGHTPROF = 0
602 self.HEIGHTPROF = 0
603 self.counter_imagwr = 0
603 self.counter_imagwr = 0
604
604
605 self.PLOT_CODE = MSKYMAP_CODE
605 self.PLOT_CODE = MSKYMAP_CODE
606
606
607 self.FTP_WEI = None
607 self.FTP_WEI = None
608 self.EXP_CODE = None
608 self.EXP_CODE = None
609 self.SUB_EXP_CODE = None
609 self.SUB_EXP_CODE = None
610 self.PLOT_POS = None
610 self.PLOT_POS = None
611
611
612 def getSubplots(self):
612 def getSubplots(self):
613
613
614 ncol = int(numpy.sqrt(self.nplots)+0.9)
614 ncol = int(numpy.sqrt(self.nplots)+0.9)
615 nrow = int(self.nplots*1./ncol + 0.9)
615 nrow = int(self.nplots*1./ncol + 0.9)
616
616
617 return nrow, ncol
617 return nrow, ncol
618
618
619 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
619 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
620
620
621 self.__showprofile = showprofile
621 self.__showprofile = showprofile
622 self.nplots = nplots
622 self.nplots = nplots
623
623
624 ncolspan = 1
624 ncolspan = 1
625 colspan = 1
625 colspan = 1
626
626
627 self.createFigure(id = id,
627 self.createFigure(id = id,
628 wintitle = wintitle,
628 wintitle = wintitle,
629 widthplot = self.WIDTH, #+ self.WIDTHPROF,
629 widthplot = self.WIDTH, #+ self.WIDTHPROF,
630 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
630 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
631 show=show)
631 show=show)
632
632
633 nrow, ncol = 1,1
633 nrow, ncol = 1,1
634 counter = 0
634 counter = 0
635 x = 0
635 x = 0
636 y = 0
636 y = 0
637 self.addAxes(1, 1, 0, 0, 1, 1, True)
637 self.addAxes(1, 1, 0, 0, 1, 1, True)
638
638
639 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
639 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
640 tmin=0, tmax=24, timerange=None,
640 tmin=0, tmax=24, timerange=None,
641 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
641 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
642 server=None, folder=None, username=None, password=None,
642 server=None, folder=None, username=None, password=None,
643 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
643 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
644
644
645 """
645 """
646
646
647 Input:
647 Input:
648 dataOut :
648 dataOut :
649 id :
649 id :
650 wintitle :
650 wintitle :
651 channelList :
651 channelList :
652 showProfile :
652 showProfile :
653 xmin : None,
653 xmin : None,
654 xmax : None,
654 xmax : None,
655 ymin : None,
655 ymin : None,
656 ymax : None,
656 ymax : None,
657 zmin : None,
657 zmin : None,
658 zmax : None
658 zmax : None
659 """
659 """
660
660
661 arrayParameters = dataOut.data_param
661 arrayParameters = dataOut.data_param
662 error = arrayParameters[:,-1]
662 error = arrayParameters[:,-1]
663 indValid = numpy.where(error == 0)[0]
663 indValid = numpy.where(error == 0)[0]
664 finalMeteor = arrayParameters[indValid,:]
664 finalMeteor = arrayParameters[indValid,:]
665 finalAzimuth = finalMeteor[:,3]
665 finalAzimuth = finalMeteor[:,3]
666 finalZenith = finalMeteor[:,4]
666 finalZenith = finalMeteor[:,4]
667
667
668 x = finalAzimuth*numpy.pi/180
668 x = finalAzimuth*numpy.pi/180
669 y = finalZenith
669 y = finalZenith
670 x1 = [dataOut.ltctime, dataOut.ltctime]
670 x1 = [dataOut.ltctime, dataOut.ltctime]
671
671
672 #thisDatetime = dataOut.datatime
672 #thisDatetime = dataOut.datatime
673 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
673 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
674 title = wintitle + " Parameters"
674 title = wintitle + " Parameters"
675 xlabel = "Zonal Zenith Angle (deg) "
675 xlabel = "Zonal Zenith Angle (deg) "
676 ylabel = "Meridional Zenith Angle (deg)"
676 ylabel = "Meridional Zenith Angle (deg)"
677 update_figfile = False
677 update_figfile = False
678
678
679 if not self.isConfig:
679 if not self.isConfig:
680
680
681 nplots = 1
681 nplots = 1
682
682
683 self.setup(id=id,
683 self.setup(id=id,
684 nplots=nplots,
684 nplots=nplots,
685 wintitle=wintitle,
685 wintitle=wintitle,
686 showprofile=showprofile,
686 showprofile=showprofile,
687 show=show)
687 show=show)
688
688
689 if self.xmin is None and self.xmax is None:
689 if self.xmin is None and self.xmax is None:
690 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
690 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
691
691
692 if timerange != None:
692 if timerange != None:
693 self.timerange = timerange
693 self.timerange = timerange
694 else:
694 else:
695 self.timerange = self.xmax - self.xmin
695 self.timerange = self.xmax - self.xmin
696
696
697 self.FTP_WEI = ftp_wei
697 self.FTP_WEI = ftp_wei
698 self.EXP_CODE = exp_code
698 self.EXP_CODE = exp_code
699 self.SUB_EXP_CODE = sub_exp_code
699 self.SUB_EXP_CODE = sub_exp_code
700 self.PLOT_POS = plot_pos
700 self.PLOT_POS = plot_pos
701 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
701 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
702 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
702 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
703 self.isConfig = True
703 self.isConfig = True
704 update_figfile = True
704 update_figfile = True
705
705
706 self.setWinTitle(title)
706 self.setWinTitle(title)
707
707
708 i = 0
708 i = 0
709 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
709 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
710
710
711 axes = self.axesList[i*self.__nsubplots]
711 axes = self.axesList[i*self.__nsubplots]
712 nevents = axes.x_buffer.shape[0] + x.shape[0]
712 nevents = axes.x_buffer.shape[0] + x.shape[0]
713 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
713 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
714 axes.polar(x, y,
714 axes.polar(x, y,
715 title=title, xlabel=xlabel, ylabel=ylabel,
715 title=title, xlabel=xlabel, ylabel=ylabel,
716 ticksize=9, cblabel='')
716 ticksize=9, cblabel='')
717
717
718 self.draw()
718 self.draw()
719
719
720 self.save(figpath=figpath,
720 self.save(figpath=figpath,
721 figfile=figfile,
721 figfile=figfile,
722 save=save,
722 save=save,
723 ftp=ftp,
723 ftp=ftp,
724 wr_period=wr_period,
724 wr_period=wr_period,
725 thisDatetime=thisDatetime,
725 thisDatetime=thisDatetime,
726 update_figfile=update_figfile)
726 update_figfile=update_figfile)
727
727
728 if dataOut.ltctime >= self.xmax:
728 if dataOut.ltctime >= self.xmax:
729 self.isConfigmagwr = wr_period
729 self.isConfigmagwr = wr_period
730 self.isConfig = False
730 self.isConfig = False
731 update_figfile = True
731 update_figfile = True
732 axes.__firsttime = True
732 axes.__firsttime = True
733 self.xmin += self.timerange
733 self.xmin += self.timerange
734 self.xmax += self.timerange
734 self.xmax += self.timerange
735
735
736
736
737
737
738 @MPDecorator
738 @MPDecorator
739 class WindProfilerPlot_(Figure):
739 class WindProfilerPlot_(Figure):
740
740
741 __isConfig = None
741 __isConfig = None
742 __nsubplots = None
742 __nsubplots = None
743
743
744 WIDTHPROF = None
744 WIDTHPROF = None
745 HEIGHTPROF = None
745 HEIGHTPROF = None
746 PREFIX = 'wind'
746 PREFIX = 'wind'
747
747
748 def __init__(self):
748 def __init__(self):
749 Figure.__init__(self)
749 Figure.__init__(self)
750 self.timerange = None
750 self.timerange = None
751 self.isConfig = False
751 self.isConfig = False
752 self.__nsubplots = 1
752 self.__nsubplots = 1
753
753
754 self.WIDTH = 800
754 self.WIDTH = 800
755 self.HEIGHT = 300
755 self.HEIGHT = 300
756 self.WIDTHPROF = 120
756 self.WIDTHPROF = 120
757 self.HEIGHTPROF = 0
757 self.HEIGHTPROF = 0
758 self.counter_imagwr = 0
758 self.counter_imagwr = 0
759
759
760 self.PLOT_CODE = WIND_CODE
760 self.PLOT_CODE = WIND_CODE
761
761
762 self.FTP_WEI = None
762 self.FTP_WEI = None
763 self.EXP_CODE = None
763 self.EXP_CODE = None
764 self.SUB_EXP_CODE = None
764 self.SUB_EXP_CODE = None
765 self.PLOT_POS = None
765 self.PLOT_POS = None
766 self.tmin = None
766 self.tmin = None
767 self.tmax = None
767 self.tmax = None
768
768
769 self.xmin = None
769 self.xmin = None
770 self.xmax = None
770 self.xmax = None
771
771
772 self.figfile = None
772 self.figfile = None
773
773
774 def getSubplots(self):
774 def getSubplots(self):
775
775
776 ncol = 1
776 ncol = 1
777 nrow = self.nplots
777 nrow = self.nplots
778
778
779 return nrow, ncol
779 return nrow, ncol
780
780
781 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
781 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
782
782
783 self.__showprofile = showprofile
783 self.__showprofile = showprofile
784 self.nplots = nplots
784 self.nplots = nplots
785
785
786 ncolspan = 1
786 ncolspan = 1
787 colspan = 1
787 colspan = 1
788
788
789 self.createFigure(id = id,
789 self.createFigure(id = id,
790 wintitle = wintitle,
790 wintitle = wintitle,
791 widthplot = self.WIDTH + self.WIDTHPROF,
791 widthplot = self.WIDTH + self.WIDTHPROF,
792 heightplot = self.HEIGHT + self.HEIGHTPROF,
792 heightplot = self.HEIGHT + self.HEIGHTPROF,
793 show=show)
793 show=show)
794
794
795 nrow, ncol = self.getSubplots()
795 nrow, ncol = self.getSubplots()
796
796
797 counter = 0
797 counter = 0
798 for y in range(nrow):
798 for y in range(nrow):
799 if counter >= self.nplots:
799 if counter >= self.nplots:
800 break
800 break
801
801
802 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
802 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
803 counter += 1
803 counter += 1
804
804
805 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
805 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
806 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
806 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
807 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
807 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
808 timerange=None, SNRthresh = None,
808 timerange=None, SNRthresh = None,
809 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
809 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
810 server=None, folder=None, username=None, password=None,
810 server=None, folder=None, username=None, password=None,
811 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
811 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
812 """
812 """
813
813
814 Input:
814 Input:
815 dataOut :
815 dataOut :
816 id :
816 id :
817 wintitle :
817 wintitle :
818 channelList :
818 channelList :
819 showProfile :
819 showProfile :
820 xmin : None,
820 xmin : None,
821 xmax : None,
821 xmax : None,
822 ymin : None,
822 ymin : None,
823 ymax : None,
823 ymax : None,
824 zmin : None,
824 zmin : None,
825 zmax : None
825 zmax : None
826 """
826 """
827
827
828 if dataOut.flagNoData:
828 if dataOut.flagNoData:
829 return dataOut
829 return dataOut
830
830
831 # if timerange is not None:
831 # if timerange is not None:
832 # self.timerange = timerange
832 # self.timerange = timerange
833 #
833 #
834 # tmin = None
834 # tmin = None
835 # tmax = None
835 # tmax = None
836
836
837 x = dataOut.getTimeRange1(dataOut.paramInterval)
837 x = dataOut.getTimeRange1(dataOut.paramInterval)
838 y = dataOut.heightList
838 y = dataOut.heightList
839 z = dataOut.data_output.copy()
839 z = dataOut.data_output.copy()
840 nplots = z.shape[0] #Number of wind dimensions estimated
840 nplots = z.shape[0] #Number of wind dimensions estimated
841 nplotsw = nplots
841 nplotsw = nplots
842
842
843
843
844 #If there is a SNR function defined
844 #If there is a SNR function defined
845 if dataOut.data_SNR is not None:
845 if dataOut.data_SNR is not None:
846 nplots += 1
846 nplots += 1
847 SNR = dataOut.data_SNR[0]
847 SNR = dataOut.data_SNR[0]
848 SNRavg = SNR#numpy.average(SNR, axis=0)
848 SNRavg = SNR#numpy.average(SNR, axis=0)
849
849
850 SNRdB = 10*numpy.log10(SNR)
850 SNRdB = 10*numpy.log10(SNR)
851 SNRavgdB = 10*numpy.log10(SNRavg)
851 SNRavgdB = 10*numpy.log10(SNRavg)
852
852
853 if SNRthresh == None:
853 if SNRthresh == None:
854 SNRthresh = -5.0
854 SNRthresh = -5.0
855 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
855 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
856
856
857 for i in range(nplotsw):
857 for i in range(nplotsw):
858 z[i,ind] = numpy.nan
858 z[i,ind] = numpy.nan
859
859
860 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
860 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
861 #thisDatetime = datetime.datetime.now()
861 #thisDatetime = datetime.datetime.now()
862 title = wintitle + "Wind"
862 title = wintitle + "Wind"
863 xlabel = ""
863 xlabel = ""
864 ylabel = "Height (km)"
864 ylabel = "Height (km)"
865 update_figfile = False
865 update_figfile = False
866
866
867 if not self.isConfig:
867 if not self.isConfig:
868
868
869 self.setup(id=id,
869 self.setup(id=id,
870 nplots=nplots,
870 nplots=nplots,
871 wintitle=wintitle,
871 wintitle=wintitle,
872 showprofile=showprofile,
872 showprofile=showprofile,
873 show=show)
873 show=show)
874
874
875 if timerange is not None:
875 if timerange is not None:
876 self.timerange = timerange
876 self.timerange = timerange
877
877
878 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
878 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
879
879
880 if ymin == None: ymin = numpy.nanmin(y)
880 if ymin == None: ymin = numpy.nanmin(y)
881 if ymax == None: ymax = numpy.nanmax(y)
881 if ymax == None: ymax = numpy.nanmax(y)
882
882
883 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
883 if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:]))
884 #if numpy.isnan(zmax): zmax = 50
884 #if numpy.isnan(zmax): zmax = 50
885 if zmin == None: zmin = -zmax
885 if zmin == None: zmin = -zmax
886
886
887 if nplotsw == 3:
887 if nplotsw == 3:
888 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
888 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
889 if zmin_ver == None: zmin_ver = -zmax_ver
889 if zmin_ver == None: zmin_ver = -zmax_ver
890
890
891 if dataOut.data_SNR is not None:
891 if dataOut.data_SNR is not None:
892 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
892 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
893 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
893 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
894
894
895
895
896 self.FTP_WEI = ftp_wei
896 self.FTP_WEI = ftp_wei
897 self.EXP_CODE = exp_code
897 self.EXP_CODE = exp_code
898 self.SUB_EXP_CODE = sub_exp_code
898 self.SUB_EXP_CODE = sub_exp_code
899 self.PLOT_POS = plot_pos
899 self.PLOT_POS = plot_pos
900
900
901 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
901 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
902 self.isConfig = True
902 self.isConfig = True
903 self.figfile = figfile
903 self.figfile = figfile
904 update_figfile = True
904 update_figfile = True
905
905
906 self.setWinTitle(title)
906 self.setWinTitle(title)
907
907
908 if ((self.xmax - x[1]) < (x[1]-x[0])):
908 if ((self.xmax - x[1]) < (x[1]-x[0])):
909 x[1] = self.xmax
909 x[1] = self.xmax
910
910
911 strWind = ['Zonal', 'Meridional', 'Vertical']
911 strWind = ['Zonal', 'Meridional', 'Vertical']
912 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
912 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
913 zmaxVector = [zmax, zmax, zmax_ver]
913 zmaxVector = [zmax, zmax, zmax_ver]
914 zminVector = [zmin, zmin, zmin_ver]
914 zminVector = [zmin, zmin, zmin_ver]
915 windFactor = [1,1,100]
915 windFactor = [1,1,100]
916
916
917 for i in range(nplotsw):
917 for i in range(nplotsw):
918
918
919 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
919 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
920 axes = self.axesList[i*self.__nsubplots]
920 axes = self.axesList[i*self.__nsubplots]
921
921
922 z1 = z[i,:].reshape((1,-1))*windFactor[i]
922 z1 = z[i,:].reshape((1,-1))*windFactor[i]
923
923
924 axes.pcolorbuffer(x, y, z1,
924 axes.pcolorbuffer(x, y, z1,
925 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
925 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
926 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
926 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
927 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
927 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
928
928
929 if dataOut.data_SNR is not None:
929 if dataOut.data_SNR is not None:
930 i += 1
930 i += 1
931 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
931 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
932 axes = self.axesList[i*self.__nsubplots]
932 axes = self.axesList[i*self.__nsubplots]
933 SNRavgdB = SNRavgdB.reshape((1,-1))
933 SNRavgdB = SNRavgdB.reshape((1,-1))
934 axes.pcolorbuffer(x, y, SNRavgdB,
934 axes.pcolorbuffer(x, y, SNRavgdB,
935 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
935 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
936 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
936 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
937 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
937 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
938
938
939 self.draw()
939 self.draw()
940
940
941 self.save(figpath=figpath,
941 self.save(figpath=figpath,
942 figfile=figfile,
942 figfile=figfile,
943 save=save,
943 save=save,
944 ftp=ftp,
944 ftp=ftp,
945 wr_period=wr_period,
945 wr_period=wr_period,
946 thisDatetime=thisDatetime,
946 thisDatetime=thisDatetime,
947 update_figfile=update_figfile)
947 update_figfile=update_figfile)
948
948
949 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
949 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
950 self.counter_imagwr = wr_period
950 self.counter_imagwr = wr_period
951 self.isConfig = False
951 self.isConfig = False
952 update_figfile = True
952 update_figfile = True
953
953
954 return dataOut
954 return dataOut
955
955
956 @MPDecorator
956 @MPDecorator
957 class ParametersPlot_(Figure):
957 class ParametersPlot_(Figure):
958
958
959 __isConfig = None
959 __isConfig = None
960 __nsubplots = None
960 __nsubplots = None
961
961
962 WIDTHPROF = None
962 WIDTHPROF = None
963 HEIGHTPROF = None
963 HEIGHTPROF = None
964 PREFIX = 'param'
964 PREFIX = 'param'
965
965
966 nplots = None
966 nplots = None
967 nchan = None
967 nchan = None
968
968
969 def __init__(self):#, **kwargs):
969 def __init__(self):#, **kwargs):
970 Figure.__init__(self)#, **kwargs)
970 Figure.__init__(self)#, **kwargs)
971 self.timerange = None
971 self.timerange = None
972 self.isConfig = False
972 self.isConfig = False
973 self.__nsubplots = 1
973 self.__nsubplots = 1
974
974
975 self.WIDTH = 300
975 self.WIDTH = 300
976 self.HEIGHT = 550
976 self.HEIGHT = 550
977 self.WIDTHPROF = 120
977 self.WIDTHPROF = 120
978 self.HEIGHTPROF = 0
978 self.HEIGHTPROF = 0
979 self.counter_imagwr = 0
979 self.counter_imagwr = 0
980
980
981 self.PLOT_CODE = RTI_CODE
981 self.PLOT_CODE = RTI_CODE
982
982
983 self.FTP_WEI = None
983 self.FTP_WEI = None
984 self.EXP_CODE = None
984 self.EXP_CODE = None
985 self.SUB_EXP_CODE = None
985 self.SUB_EXP_CODE = None
986 self.PLOT_POS = None
986 self.PLOT_POS = None
987 self.tmin = None
987 self.tmin = None
988 self.tmax = None
988 self.tmax = None
989
989
990 self.xmin = None
990 self.xmin = None
991 self.xmax = None
991 self.xmax = None
992
992
993 self.figfile = None
993 self.figfile = None
994
994
995 def getSubplots(self):
995 def getSubplots(self):
996
996
997 ncol = 1
997 ncol = 1
998 nrow = self.nplots
998 nrow = self.nplots
999
999
1000 return nrow, ncol
1000 return nrow, ncol
1001
1001
1002 def setup(self, id, nplots, wintitle, show=True):
1002 def setup(self, id, nplots, wintitle, show=True):
1003
1003
1004 self.nplots = nplots
1004 self.nplots = nplots
1005
1005
1006 ncolspan = 1
1006 ncolspan = 1
1007 colspan = 1
1007 colspan = 1
1008
1008
1009 self.createFigure(id = id,
1009 self.createFigure(id = id,
1010 wintitle = wintitle,
1010 wintitle = wintitle,
1011 widthplot = self.WIDTH + self.WIDTHPROF,
1011 widthplot = self.WIDTH + self.WIDTHPROF,
1012 heightplot = self.HEIGHT + self.HEIGHTPROF,
1012 heightplot = self.HEIGHT + self.HEIGHTPROF,
1013 show=show)
1013 show=show)
1014
1014
1015 nrow, ncol = self.getSubplots()
1015 nrow, ncol = self.getSubplots()
1016
1016
1017 counter = 0
1017 counter = 0
1018 for y in range(nrow):
1018 for y in range(nrow):
1019 for x in range(ncol):
1019 for x in range(ncol):
1020
1020
1021 if counter >= self.nplots:
1021 if counter >= self.nplots:
1022 break
1022 break
1023
1023
1024 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1024 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1025
1025
1026 counter += 1
1026 counter += 1
1027
1027
1028 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
1028 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
1029 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
1029 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
1030 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
1030 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
1031 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1031 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1032 server=None, folder=None, username=None, password=None,
1032 server=None, folder=None, username=None, password=None,
1033 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
1033 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
1034 """
1034 """
1035
1035
1036 Input:
1036 Input:
1037 dataOut :
1037 dataOut :
1038 id :
1038 id :
1039 wintitle :
1039 wintitle :
1040 channelList :
1040 channelList :
1041 showProfile :
1041 showProfile :
1042 xmin : None,
1042 xmin : None,
1043 xmax : None,
1043 xmax : None,
1044 ymin : None,
1044 ymin : None,
1045 ymax : None,
1045 ymax : None,
1046 zmin : None,
1046 zmin : None,
1047 zmax : None
1047 zmax : None
1048 """
1048 """
1049 if dataOut.flagNoData:
1049 if dataOut.flagNoData:
1050 return dataOut
1050 return dataOut
1051
1051
1052
1052
1053 if HEIGHT is not None:
1053 if HEIGHT is not None:
1054 self.HEIGHT = HEIGHT
1054 self.HEIGHT = HEIGHT
1055
1055
1056
1056
1057 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1057 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1058 return
1058 return
1059
1059
1060 if channelList == None:
1060 if channelList == None:
1061 channelIndexList = list(range(dataOut.data_param.shape[0]))
1061 channelIndexList = list(range(dataOut.data_param.shape[0]))
1062 else:
1062 else:
1063 channelIndexList = []
1063 channelIndexList = []
1064 for channel in channelList:
1064 for channel in channelList:
1065 if channel not in dataOut.channelList:
1065 if channel not in dataOut.channelList:
1066 raise ValueError("Channel %d is not in dataOut.channelList")
1066 raise ValueError("Channel %d is not in dataOut.channelList")
1067 channelIndexList.append(dataOut.channelList.index(channel))
1067 channelIndexList.append(dataOut.channelList.index(channel))
1068
1068
1069 x = dataOut.getTimeRange1(dataOut.paramInterval)
1069 x = dataOut.getTimeRange1(dataOut.paramInterval)
1070 y = dataOut.getHeiRange()
1070 y = dataOut.getHeiRange()
1071
1071
1072 if dataOut.data_param.ndim == 3:
1072 if dataOut.data_param.ndim == 3:
1073 z = dataOut.data_param[channelIndexList,paramIndex,:]
1073 z = dataOut.data_param[channelIndexList,paramIndex,:]
1074 else:
1074 else:
1075 z = dataOut.data_param[channelIndexList,:]
1075 z = dataOut.data_param[channelIndexList,:]
1076
1076
1077 if showSNR:
1077 if showSNR:
1078 #SNR data
1078 #SNR data
1079 SNRarray = dataOut.data_SNR[channelIndexList,:]
1079 SNRarray = dataOut.data_SNR[channelIndexList,:]
1080 SNRdB = 10*numpy.log10(SNRarray)
1080 SNRdB = 10*numpy.log10(SNRarray)
1081 ind = numpy.where(SNRdB < SNRthresh)
1081 ind = numpy.where(SNRdB < SNRthresh)
1082 z[ind] = numpy.nan
1082 z[ind] = numpy.nan
1083
1083
1084 thisDatetime = dataOut.datatime
1084 thisDatetime = dataOut.datatime
1085 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1085 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1086 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1086 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1087 xlabel = ""
1087 xlabel = ""
1088 ylabel = "Range (km)"
1088 ylabel = "Range (km)"
1089
1089
1090 update_figfile = False
1090 update_figfile = False
1091
1091
1092 if not self.isConfig:
1092 if not self.isConfig:
1093
1093
1094 nchan = len(channelIndexList)
1094 nchan = len(channelIndexList)
1095 self.nchan = nchan
1095 self.nchan = nchan
1096 self.plotFact = 1
1096 self.plotFact = 1
1097 nplots = nchan
1097 nplots = nchan
1098
1098
1099 if showSNR:
1099 if showSNR:
1100 nplots = nchan*2
1100 nplots = nchan*2
1101 self.plotFact = 2
1101 self.plotFact = 2
1102 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1102 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1103 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1103 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1104
1104
1105 self.setup(id=id,
1105 self.setup(id=id,
1106 nplots=nplots,
1106 nplots=nplots,
1107 wintitle=wintitle,
1107 wintitle=wintitle,
1108 show=show)
1108 show=show)
1109
1109
1110 if timerange != None:
1110 if timerange != None:
1111 self.timerange = timerange
1111 self.timerange = timerange
1112
1112
1113 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1113 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1114
1114
1115 if ymin == None: ymin = numpy.nanmin(y)
1115 if ymin == None: ymin = numpy.nanmin(y)
1116 if ymax == None: ymax = numpy.nanmax(y)
1116 if ymax == None: ymax = numpy.nanmax(y)
1117 if zmin == None: zmin = numpy.nanmin(z)
1117 if zmin == None: zmin = numpy.nanmin(z)
1118 if zmax == None: zmax = numpy.nanmax(z)
1118 if zmax == None: zmax = numpy.nanmax(z)
1119
1119
1120 self.FTP_WEI = ftp_wei
1120 self.FTP_WEI = ftp_wei
1121 self.EXP_CODE = exp_code
1121 self.EXP_CODE = exp_code
1122 self.SUB_EXP_CODE = sub_exp_code
1122 self.SUB_EXP_CODE = sub_exp_code
1123 self.PLOT_POS = plot_pos
1123 self.PLOT_POS = plot_pos
1124
1124
1125 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1125 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1126 self.isConfig = True
1126 self.isConfig = True
1127 self.figfile = figfile
1127 self.figfile = figfile
1128 update_figfile = True
1128 update_figfile = True
1129
1129
1130 self.setWinTitle(title)
1130 self.setWinTitle(title)
1131
1131
1132 # for i in range(self.nchan):
1132 # for i in range(self.nchan):
1133 # index = channelIndexList[i]
1133 # index = channelIndexList[i]
1134 # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1134 # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1135 # axes = self.axesList[i*self.plotFact]
1135 # axes = self.axesList[i*self.plotFact]
1136 # z1 = z[i,:].reshape((1,-1))
1136 # z1 = z[i,:].reshape((1,-1))
1137 # axes.pcolorbuffer(x, y, z1,
1137 # axes.pcolorbuffer(x, y, z1,
1138 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1138 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1139 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1139 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1140 # ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1140 # ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1141 #
1141 #
1142 # if showSNR:
1142 # if showSNR:
1143 # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1143 # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1144 # axes = self.axesList[i*self.plotFact + 1]
1144 # axes = self.axesList[i*self.plotFact + 1]
1145 # SNRdB1 = SNRdB[i,:].reshape((1,-1))
1145 # SNRdB1 = SNRdB[i,:].reshape((1,-1))
1146 # axes.pcolorbuffer(x, y, SNRdB1,
1146 # axes.pcolorbuffer(x, y, SNRdB1,
1147 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1147 # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1148 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1148 # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1149 # ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1149 # ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1150
1150
1151 i=0
1151 i=0
1152 index = channelIndexList[i]
1152 index = channelIndexList[i]
1153 title = "Factor de reflectividad Z [dBZ]"
1153 title = "Factor de reflectividad Z [dBZ]"
1154 axes = self.axesList[i*self.plotFact]
1154 axes = self.axesList[i*self.plotFact]
1155 z1 = z[i,:].reshape((1,-1))
1155 z1 = z[i,:].reshape((1,-1))
1156 axes.pcolorbuffer(x, y, z1,
1156 axes.pcolorbuffer(x, y, z1,
1157 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1157 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1158 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1158 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1159 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1159 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
1160
1160
1161 if showSNR:
1161 if showSNR:
1162 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1162 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1163 axes = self.axesList[i*self.plotFact + 1]
1163 axes = self.axesList[i*self.plotFact + 1]
1164 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1164 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1165 axes.pcolorbuffer(x, y, SNRdB1,
1165 axes.pcolorbuffer(x, y, SNRdB1,
1166 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1166 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1167 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1167 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1168 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1168 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1169
1169
1170 i=1
1170 i=1
1171 index = channelIndexList[i]
1171 index = channelIndexList[i]
1172 title = "Velocidad vertical Doppler [m/s]"
1172 title = "Velocidad vertical Doppler [m/s]"
1173 axes = self.axesList[i*self.plotFact]
1173 axes = self.axesList[i*self.plotFact]
1174 z1 = z[i,:].reshape((1,-1))
1174 z1 = z[i,:].reshape((1,-1))
1175 axes.pcolorbuffer(x, y, z1,
1175 axes.pcolorbuffer(x, y, z1,
1176 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10,
1176 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10,
1177 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1177 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1178 ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r')
1178 ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r')
1179
1179
1180 if showSNR:
1180 if showSNR:
1181 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1181 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1182 axes = self.axesList[i*self.plotFact + 1]
1182 axes = self.axesList[i*self.plotFact + 1]
1183 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1183 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1184 axes.pcolorbuffer(x, y, SNRdB1,
1184 axes.pcolorbuffer(x, y, SNRdB1,
1185 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1185 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1186 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1186 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1187 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1187 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1188
1188
1189 i=2
1189 i=2
1190 index = channelIndexList[i]
1190 index = channelIndexList[i]
1191 title = "Intensidad de lluvia [mm/h]"
1191 title = "Intensidad de lluvia [mm/h]"
1192 axes = self.axesList[i*self.plotFact]
1192 axes = self.axesList[i*self.plotFact]
1193 z1 = z[i,:].reshape((1,-1))
1193 z1 = z[i,:].reshape((1,-1))
1194 axes.pcolorbuffer(x, y, z1,
1194 axes.pcolorbuffer(x, y, z1,
1195 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40,
1195 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40,
1196 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1196 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1197 ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r')
1197 ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r')
1198
1198
1199 if showSNR:
1199 if showSNR:
1200 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1200 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1201 axes = self.axesList[i*self.plotFact + 1]
1201 axes = self.axesList[i*self.plotFact + 1]
1202 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1202 SNRdB1 = SNRdB[i,:].reshape((1,-1))
1203 axes.pcolorbuffer(x, y, SNRdB1,
1203 axes.pcolorbuffer(x, y, SNRdB1,
1204 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1204 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1205 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1205 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1206 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1206 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
1207
1207
1208
1208
1209 self.draw()
1209 self.draw()
1210
1210
1211 if dataOut.ltctime >= self.xmax:
1211 if dataOut.ltctime >= self.xmax:
1212 self.counter_imagwr = wr_period
1212 self.counter_imagwr = wr_period
1213 self.isConfig = False
1213 self.isConfig = False
1214 update_figfile = True
1214 update_figfile = True
1215
1215
1216 self.save(figpath=figpath,
1216 self.save(figpath=figpath,
1217 figfile=figfile,
1217 figfile=figfile,
1218 save=save,
1218 save=save,
1219 ftp=ftp,
1219 ftp=ftp,
1220 wr_period=wr_period,
1220 wr_period=wr_period,
1221 thisDatetime=thisDatetime,
1221 thisDatetime=thisDatetime,
1222 update_figfile=update_figfile)
1222 update_figfile=update_figfile)
1223
1223
1224 return dataOut
1224 return dataOut
1225 @MPDecorator
1225 @MPDecorator
1226 class Parameters1Plot_(Figure):
1226 class Parameters1Plot_(Figure):
1227
1227
1228 __isConfig = None
1228 __isConfig = None
1229 __nsubplots = None
1229 __nsubplots = None
1230
1230
1231 WIDTHPROF = None
1231 WIDTHPROF = None
1232 HEIGHTPROF = None
1232 HEIGHTPROF = None
1233 PREFIX = 'prm'
1233 PREFIX = 'prm'
1234
1234
1235 def __init__(self):
1235 def __init__(self):
1236 Figure.__init__(self)
1236 Figure.__init__(self)
1237 self.timerange = 2*60*60
1237 self.timerange = 2*60*60
1238 self.isConfig = False
1238 self.isConfig = False
1239 self.__nsubplots = 1
1239 self.__nsubplots = 1
1240
1240
1241 self.WIDTH = 800
1241 self.WIDTH = 800
1242 self.HEIGHT = 180
1242 self.HEIGHT = 180
1243 self.WIDTHPROF = 120
1243 self.WIDTHPROF = 120
1244 self.HEIGHTPROF = 0
1244 self.HEIGHTPROF = 0
1245 self.counter_imagwr = 0
1245 self.counter_imagwr = 0
1246
1246
1247 self.PLOT_CODE = PARMS_CODE
1247 self.PLOT_CODE = PARMS_CODE
1248
1248
1249 self.FTP_WEI = None
1249 self.FTP_WEI = None
1250 self.EXP_CODE = None
1250 self.EXP_CODE = None
1251 self.SUB_EXP_CODE = None
1251 self.SUB_EXP_CODE = None
1252 self.PLOT_POS = None
1252 self.PLOT_POS = None
1253 self.tmin = None
1253 self.tmin = None
1254 self.tmax = None
1254 self.tmax = None
1255
1255
1256 self.xmin = None
1256 self.xmin = None
1257 self.xmax = None
1257 self.xmax = None
1258
1258
1259 self.figfile = None
1259 self.figfile = None
1260
1260
1261 def getSubplots(self):
1261 def getSubplots(self):
1262
1262
1263 ncol = 1
1263 ncol = 1
1264 nrow = self.nplots
1264 nrow = self.nplots
1265
1265
1266 return nrow, ncol
1266 return nrow, ncol
1267
1267
1268 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1268 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1269
1269
1270 self.__showprofile = showprofile
1270 self.__showprofile = showprofile
1271 self.nplots = nplots
1271 self.nplots = nplots
1272
1272
1273 ncolspan = 1
1273 ncolspan = 1
1274 colspan = 1
1274 colspan = 1
1275
1275
1276 self.createFigure(id = id,
1276 self.createFigure(id = id,
1277 wintitle = wintitle,
1277 wintitle = wintitle,
1278 widthplot = self.WIDTH + self.WIDTHPROF,
1278 widthplot = self.WIDTH + self.WIDTHPROF,
1279 heightplot = self.HEIGHT + self.HEIGHTPROF,
1279 heightplot = self.HEIGHT + self.HEIGHTPROF,
1280 show=show)
1280 show=show)
1281
1281
1282 nrow, ncol = self.getSubplots()
1282 nrow, ncol = self.getSubplots()
1283
1283
1284 counter = 0
1284 counter = 0
1285 for y in range(nrow):
1285 for y in range(nrow):
1286 for x in range(ncol):
1286 for x in range(ncol):
1287
1287
1288 if counter >= self.nplots:
1288 if counter >= self.nplots:
1289 break
1289 break
1290
1290
1291 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1291 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1292
1292
1293 if showprofile:
1293 if showprofile:
1294 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1294 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1295
1295
1296 counter += 1
1296 counter += 1
1297
1297
1298 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1298 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1299 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1299 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1300 parameterIndex = None, onlyPositive = False,
1300 parameterIndex = None, onlyPositive = False,
1301 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1301 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1302 DOP = True,
1302 DOP = True,
1303 zlabel = "", parameterName = "", parameterObject = "data_param",
1303 zlabel = "", parameterName = "", parameterObject = "data_param",
1304 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1304 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1305 server=None, folder=None, username=None, password=None,
1305 server=None, folder=None, username=None, password=None,
1306 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1306 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1307
1307
1308 """
1308 """
1309 Input:
1309 Input:
1310 dataOut :
1310 dataOut :
1311 id :
1311 id :
1312 wintitle :
1312 wintitle :
1313 channelList :
1313 channelList :
1314 showProfile :
1314 showProfile :
1315 xmin : None,
1315 xmin : None,
1316 xmax : None,
1316 xmax : None,
1317 ymin : None,
1317 ymin : None,
1318 ymax : None,
1318 ymax : None,
1319 zmin : None,
1319 zmin : None,
1320 zmax : None
1320 zmax : None
1321 """
1321 """
1322 if dataOut.flagNoData:
1322 if dataOut.flagNoData:
1323 return dataOut
1323 return dataOut
1324
1324
1325 data_param = getattr(dataOut, parameterObject)
1325 data_param = getattr(dataOut, parameterObject)
1326
1326
1327 if channelList == None:
1327 if channelList == None:
1328 channelIndexList = numpy.arange(data_param.shape[0])
1328 channelIndexList = numpy.arange(data_param.shape[0])
1329 else:
1329 else:
1330 channelIndexList = numpy.array(channelList)
1330 channelIndexList = numpy.array(channelList)
1331
1331
1332 nchan = len(channelIndexList) #Number of channels being plotted
1332 nchan = len(channelIndexList) #Number of channels being plotted
1333
1333
1334 if nchan < 1:
1334 if nchan < 1:
1335 return
1335 return
1336
1336
1337 nGraphsByChannel = 0
1337 nGraphsByChannel = 0
1338
1338
1339 if SNR:
1339 if SNR:
1340 nGraphsByChannel += 1
1340 nGraphsByChannel += 1
1341 if DOP:
1341 if DOP:
1342 nGraphsByChannel += 1
1342 nGraphsByChannel += 1
1343
1343
1344 if nGraphsByChannel < 1:
1344 if nGraphsByChannel < 1:
1345 return
1345 return
1346
1346
1347 nplots = nGraphsByChannel*nchan
1347 nplots = nGraphsByChannel*nchan
1348
1348
1349 if timerange is not None:
1349 if timerange is not None:
1350 self.timerange = timerange
1350 self.timerange = timerange
1351
1351
1352 #tmin = None
1352 #tmin = None
1353 #tmax = None
1353 #tmax = None
1354 if parameterIndex == None:
1354 if parameterIndex == None:
1355 parameterIndex = 1
1355 parameterIndex = 1
1356
1356
1357 x = dataOut.getTimeRange1(dataOut.paramInterval)
1357 x = dataOut.getTimeRange1(dataOut.paramInterval)
1358 y = dataOut.heightList
1358 y = dataOut.heightList
1359
1359
1360 if dataOut.data_param.ndim == 3:
1360 if dataOut.data_param.ndim == 3:
1361 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1361 z = dataOut.data_param[channelIndexList,parameterIndex,:]
1362 else:
1362 else:
1363 z = dataOut.data_param[channelIndexList,:]
1363 z = dataOut.data_param[channelIndexList,:]
1364
1364
1365 if dataOut.data_SNR is not None:
1365 if dataOut.data_SNR is not None:
1366 if dataOut.data_SNR.ndim == 2:
1366 if dataOut.data_SNR.ndim == 2:
1367 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1367 SNRavg = numpy.average(dataOut.data_SNR, axis=0)
1368 else:
1368 else:
1369 SNRavg = dataOut.data_SNR
1369 SNRavg = dataOut.data_SNR
1370 SNRdB = 10*numpy.log10(SNRavg)
1370 SNRdB = 10*numpy.log10(SNRavg)
1371
1371
1372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1372 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1373 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1373 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1374 xlabel = ""
1374 xlabel = ""
1375 ylabel = "Range (Km)"
1375 ylabel = "Range (Km)"
1376
1376
1377 if onlyPositive:
1377 if onlyPositive:
1378 colormap = "jet"
1378 colormap = "jet"
1379 zmin = 0
1379 zmin = 0
1380 else: colormap = "RdBu_r"
1380 else: colormap = "RdBu_r"
1381
1381
1382 if not self.isConfig:
1382 if not self.isConfig:
1383
1383
1384 self.setup(id=id,
1384 self.setup(id=id,
1385 nplots=nplots,
1385 nplots=nplots,
1386 wintitle=wintitle,
1386 wintitle=wintitle,
1387 showprofile=showprofile,
1387 showprofile=showprofile,
1388 show=show)
1388 show=show)
1389
1389
1390 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1390 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1391
1391
1392 if ymin == None: ymin = numpy.nanmin(y)
1392 if ymin == None: ymin = numpy.nanmin(y)
1393 if ymax == None: ymax = numpy.nanmax(y)
1393 if ymax == None: ymax = numpy.nanmax(y)
1394 if zmin == None: zmin = numpy.nanmin(z)
1394 if zmin == None: zmin = numpy.nanmin(z)
1395 if zmax == None: zmax = numpy.nanmax(z)
1395 if zmax == None: zmax = numpy.nanmax(z)
1396
1396
1397 if SNR:
1397 if SNR:
1398 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1398 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1399 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1399 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1400
1400
1401 self.FTP_WEI = ftp_wei
1401 self.FTP_WEI = ftp_wei
1402 self.EXP_CODE = exp_code
1402 self.EXP_CODE = exp_code
1403 self.SUB_EXP_CODE = sub_exp_code
1403 self.SUB_EXP_CODE = sub_exp_code
1404 self.PLOT_POS = plot_pos
1404 self.PLOT_POS = plot_pos
1405
1405
1406 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1406 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1407 self.isConfig = True
1407 self.isConfig = True
1408 self.figfile = figfile
1408 self.figfile = figfile
1409
1409
1410 self.setWinTitle(title)
1410 self.setWinTitle(title)
1411
1411
1412 if ((self.xmax - x[1]) < (x[1]-x[0])):
1412 if ((self.xmax - x[1]) < (x[1]-x[0])):
1413 x[1] = self.xmax
1413 x[1] = self.xmax
1414
1414
1415 for i in range(nchan):
1415 for i in range(nchan):
1416
1416
1417 if (SNR and not onlySNR): j = 2*i
1417 if (SNR and not onlySNR): j = 2*i
1418 else: j = i
1418 else: j = i
1419
1419
1420 j = nGraphsByChannel*i
1420 j = nGraphsByChannel*i
1421
1421
1422 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1422 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1423 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1423 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1424
1424
1425 if not onlySNR:
1425 if not onlySNR:
1426 axes = self.axesList[j*self.__nsubplots]
1426 axes = self.axesList[j*self.__nsubplots]
1427 z1 = z[i,:].reshape((1,-1))
1427 z1 = z[i,:].reshape((1,-1))
1428 axes.pcolorbuffer(x, y, z1,
1428 axes.pcolorbuffer(x, y, z1,
1429 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1429 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1430 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1430 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1431 ticksize=9, cblabel=zlabel, cbsize="1%")
1431 ticksize=9, cblabel=zlabel, cbsize="1%")
1432
1432
1433 if DOP:
1433 if DOP:
1434 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1434 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1435
1435
1436 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1436 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1437 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1437 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1438 axes = self.axesList[j]
1438 axes = self.axesList[j]
1439 z1 = z[i,:].reshape((1,-1))
1439 z1 = z[i,:].reshape((1,-1))
1440 axes.pcolorbuffer(x, y, z1,
1440 axes.pcolorbuffer(x, y, z1,
1441 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1441 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1442 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1442 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1443 ticksize=9, cblabel=zlabel, cbsize="1%")
1443 ticksize=9, cblabel=zlabel, cbsize="1%")
1444
1444
1445 if SNR:
1445 if SNR:
1446 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1446 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1447 axes = self.axesList[(j)*self.__nsubplots]
1447 axes = self.axesList[(j)*self.__nsubplots]
1448 if not onlySNR:
1448 if not onlySNR:
1449 axes = self.axesList[(j + 1)*self.__nsubplots]
1449 axes = self.axesList[(j + 1)*self.__nsubplots]
1450
1450
1451 axes = self.axesList[(j + nGraphsByChannel-1)]
1451 axes = self.axesList[(j + nGraphsByChannel-1)]
1452 z1 = SNRdB.reshape((1,-1))
1452 z1 = SNRdB.reshape((1,-1))
1453 axes.pcolorbuffer(x, y, z1,
1453 axes.pcolorbuffer(x, y, z1,
1454 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1454 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1455 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1455 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1456 ticksize=9, cblabel=zlabel, cbsize="1%")
1456 ticksize=9, cblabel=zlabel, cbsize="1%")
1457
1457
1458
1458
1459
1459
1460 self.draw()
1460 self.draw()
1461
1461
1462 if x[1] >= self.axesList[0].xmax:
1462 if x[1] >= self.axesList[0].xmax:
1463 self.counter_imagwr = wr_period
1463 self.counter_imagwr = wr_period
1464 self.isConfig = False
1464 self.isConfig = False
1465 self.figfile = None
1465 self.figfile = None
1466
1466
1467 self.save(figpath=figpath,
1467 self.save(figpath=figpath,
1468 figfile=figfile,
1468 figfile=figfile,
1469 save=save,
1469 save=save,
1470 ftp=ftp,
1470 ftp=ftp,
1471 wr_period=wr_period,
1471 wr_period=wr_period,
1472 thisDatetime=thisDatetime,
1472 thisDatetime=thisDatetime,
1473 update_figfile=False)
1473 update_figfile=False)
1474 return dataOut
1474 return dataOut
1475
1475
1476 class SpectralFittingPlot_(Figure):
1476 class SpectralFittingPlot_(Figure):
1477
1477
1478 __isConfig = None
1478 __isConfig = None
1479 __nsubplots = None
1479 __nsubplots = None
1480
1480
1481 WIDTHPROF = None
1481 WIDTHPROF = None
1482 HEIGHTPROF = None
1482 HEIGHTPROF = None
1483 PREFIX = 'prm'
1483 PREFIX = 'prm'
1484
1484
1485
1485
1486 N = None
1486 N = None
1487 ippSeconds = None
1487 ippSeconds = None
1488
1488
1489 def __init__(self, **kwargs):
1489 def __init__(self, **kwargs):
1490 Figure.__init__(self, **kwargs)
1490 Figure.__init__(self, **kwargs)
1491 self.isConfig = False
1491 self.isConfig = False
1492 self.__nsubplots = 1
1492 self.__nsubplots = 1
1493
1493
1494 self.PLOT_CODE = SPECFIT_CODE
1494 self.PLOT_CODE = SPECFIT_CODE
1495
1495
1496 self.WIDTH = 450
1496 self.WIDTH = 450
1497 self.HEIGHT = 250
1497 self.HEIGHT = 250
1498 self.WIDTHPROF = 0
1498 self.WIDTHPROF = 0
1499 self.HEIGHTPROF = 0
1499 self.HEIGHTPROF = 0
1500
1500
1501 def getSubplots(self):
1501 def getSubplots(self):
1502
1502
1503 ncol = int(numpy.sqrt(self.nplots)+0.9)
1503 ncol = int(numpy.sqrt(self.nplots)+0.9)
1504 nrow = int(self.nplots*1./ncol + 0.9)
1504 nrow = int(self.nplots*1./ncol + 0.9)
1505
1505
1506 return nrow, ncol
1506 return nrow, ncol
1507
1507
1508 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1508 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1509
1509
1510 showprofile = False
1510 showprofile = False
1511 self.__showprofile = showprofile
1511 self.__showprofile = showprofile
1512 self.nplots = nplots
1512 self.nplots = nplots
1513
1513
1514 ncolspan = 5
1514 ncolspan = 5
1515 colspan = 4
1515 colspan = 4
1516 if showprofile:
1516 if showprofile:
1517 ncolspan = 5
1517 ncolspan = 5
1518 colspan = 4
1518 colspan = 4
1519 self.__nsubplots = 2
1519 self.__nsubplots = 2
1520
1520
1521 self.createFigure(id = id,
1521 self.createFigure(id = id,
1522 wintitle = wintitle,
1522 wintitle = wintitle,
1523 widthplot = self.WIDTH + self.WIDTHPROF,
1523 widthplot = self.WIDTH + self.WIDTHPROF,
1524 heightplot = self.HEIGHT + self.HEIGHTPROF,
1524 heightplot = self.HEIGHT + self.HEIGHTPROF,
1525 show=show)
1525 show=show)
1526
1526
1527 nrow, ncol = self.getSubplots()
1527 nrow, ncol = self.getSubplots()
1528
1528
1529 counter = 0
1529 counter = 0
1530 for y in range(nrow):
1530 for y in range(nrow):
1531 for x in range(ncol):
1531 for x in range(ncol):
1532
1532
1533 if counter >= self.nplots:
1533 if counter >= self.nplots:
1534 break
1534 break
1535
1535
1536 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1536 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1537
1537
1538 if showprofile:
1538 if showprofile:
1539 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1539 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1540
1540
1541 counter += 1
1541 counter += 1
1542
1542
1543 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1543 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1544 xmin=None, xmax=None, ymin=None, ymax=None,
1544 xmin=None, xmax=None, ymin=None, ymax=None,
1545 save=False, figpath='./', figfile=None, show=True):
1545 save=False, figpath='./', figfile=None, show=True):
1546
1546
1547 """
1547 """
1548
1548
1549 Input:
1549 Input:
1550 dataOut :
1550 dataOut :
1551 id :
1551 id :
1552 wintitle :
1552 wintitle :
1553 channelList :
1553 channelList :
1554 showProfile :
1554 showProfile :
1555 xmin : None,
1555 xmin : None,
1556 xmax : None,
1556 xmax : None,
1557 zmin : None,
1557 zmin : None,
1558 zmax : None
1558 zmax : None
1559 """
1559 """
1560
1560
1561 if cutHeight==None:
1561 if cutHeight==None:
1562 h=270
1562 h=270
1563 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1563 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1564 cutHeight = dataOut.heightList[heightindex]
1564 cutHeight = dataOut.heightList[heightindex]
1565
1565
1566 factor = dataOut.normFactor
1566 factor = dataOut.normFactor
1567 x = dataOut.abscissaList[:-1]
1567 x = dataOut.abscissaList[:-1]
1568 #y = dataOut.getHeiRange()
1568 #y = dataOut.getHeiRange()
1569
1569
1570 z = dataOut.data_pre[:,:,heightindex]/factor
1570 z = dataOut.data_pre[:,:,heightindex]/factor
1571 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1571 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1572 avg = numpy.average(z, axis=1)
1572 avg = numpy.average(z, axis=1)
1573 listChannels = z.shape[0]
1573 listChannels = z.shape[0]
1574
1574
1575 #Reconstruct Function
1575 #Reconstruct Function
1576 if fit==True:
1576 if fit==True:
1577 groupArray = dataOut.groupList
1577 groupArray = dataOut.groupList
1578 listChannels = groupArray.reshape((groupArray.size))
1578 listChannels = groupArray.reshape((groupArray.size))
1579 listChannels.sort()
1579 listChannels.sort()
1580 spcFitLine = numpy.zeros(z.shape)
1580 spcFitLine = numpy.zeros(z.shape)
1581 constants = dataOut.constants
1581 constants = dataOut.constants
1582
1582
1583 nGroups = groupArray.shape[0]
1583 nGroups = groupArray.shape[0]
1584 nChannels = groupArray.shape[1]
1584 nChannels = groupArray.shape[1]
1585 nProfiles = z.shape[1]
1585 nProfiles = z.shape[1]
1586
1586
1587 for f in range(nGroups):
1587 for f in range(nGroups):
1588 groupChann = groupArray[f,:]
1588 groupChann = groupArray[f,:]
1589 p = dataOut.data_param[f,:,heightindex]
1589 p = dataOut.data_param[f,:,heightindex]
1590 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1590 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1591 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1591 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1592 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1592 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1593 spcFitLine[groupChann,:] = fitLineAux
1593 spcFitLine[groupChann,:] = fitLineAux
1594 # spcFitLine = spcFitLine/factor
1594 # spcFitLine = spcFitLine/factor
1595
1595
1596 z = z[listChannels,:]
1596 z = z[listChannels,:]
1597 spcFitLine = spcFitLine[listChannels,:]
1597 spcFitLine = spcFitLine[listChannels,:]
1598 spcFitLinedB = 10*numpy.log10(spcFitLine)
1598 spcFitLinedB = 10*numpy.log10(spcFitLine)
1599
1599
1600 zdB = 10*numpy.log10(z)
1600 zdB = 10*numpy.log10(z)
1601 #thisDatetime = dataOut.datatime
1601 #thisDatetime = dataOut.datatime
1602 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1602 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1603 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1603 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1604 xlabel = "Velocity (m/s)"
1604 xlabel = "Velocity (m/s)"
1605 ylabel = "Spectrum"
1605 ylabel = "Spectrum"
1606
1606
1607 if not self.isConfig:
1607 if not self.isConfig:
1608
1608
1609 nplots = listChannels.size
1609 nplots = listChannels.size
1610
1610
1611 self.setup(id=id,
1611 self.setup(id=id,
1612 nplots=nplots,
1612 nplots=nplots,
1613 wintitle=wintitle,
1613 wintitle=wintitle,
1614 showprofile=showprofile,
1614 showprofile=showprofile,
1615 show=show)
1615 show=show)
1616
1616
1617 if xmin == None: xmin = numpy.nanmin(x)
1617 if xmin == None: xmin = numpy.nanmin(x)
1618 if xmax == None: xmax = numpy.nanmax(x)
1618 if xmax == None: xmax = numpy.nanmax(x)
1619 if ymin == None: ymin = numpy.nanmin(zdB)
1619 if ymin == None: ymin = numpy.nanmin(zdB)
1620 if ymax == None: ymax = numpy.nanmax(zdB)+2
1620 if ymax == None: ymax = numpy.nanmax(zdB)+2
1621
1621
1622 self.isConfig = True
1622 self.isConfig = True
1623
1623
1624 self.setWinTitle(title)
1624 self.setWinTitle(title)
1625 for i in range(self.nplots):
1625 for i in range(self.nplots):
1626 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1626 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1627 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1627 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1628 axes = self.axesList[i*self.__nsubplots]
1628 axes = self.axesList[i*self.__nsubplots]
1629 if fit == False:
1629 if fit == False:
1630 axes.pline(x, zdB[i,:],
1630 axes.pline(x, zdB[i,:],
1631 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1631 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1632 xlabel=xlabel, ylabel=ylabel, title=title
1632 xlabel=xlabel, ylabel=ylabel, title=title
1633 )
1633 )
1634 if fit == True:
1634 if fit == True:
1635 fitline=spcFitLinedB[i,:]
1635 fitline=spcFitLinedB[i,:]
1636 y=numpy.vstack([zdB[i,:],fitline] )
1636 y=numpy.vstack([zdB[i,:],fitline] )
1637 legendlabels=['Data','Fitting']
1637 legendlabels=['Data','Fitting']
1638 axes.pmultilineyaxis(x, y,
1638 axes.pmultilineyaxis(x, y,
1639 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1639 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1640 xlabel=xlabel, ylabel=ylabel, title=title,
1640 xlabel=xlabel, ylabel=ylabel, title=title,
1641 legendlabels=legendlabels, marker=None,
1641 legendlabels=legendlabels, marker=None,
1642 linestyle='solid', grid='both')
1642 linestyle='solid', grid='both')
1643
1643
1644 self.draw()
1644 self.draw()
1645
1645
1646 self.save(figpath=figpath,
1646 self.save(figpath=figpath,
1647 figfile=figfile,
1647 figfile=figfile,
1648 save=save,
1648 save=save,
1649 ftp=ftp,
1649 ftp=ftp,
1650 wr_period=wr_period,
1650 wr_period=wr_period,
1651 thisDatetime=thisDatetime)
1651 thisDatetime=thisDatetime)
1652
1652
1653
1653
1654 class EWDriftsPlot_(Figure):
1654 class EWDriftsPlot_(Figure):
1655
1655
1656 __isConfig = None
1656 __isConfig = None
1657 __nsubplots = None
1657 __nsubplots = None
1658
1658
1659 WIDTHPROF = None
1659 WIDTHPROF = None
1660 HEIGHTPROF = None
1660 HEIGHTPROF = None
1661 PREFIX = 'drift'
1661 PREFIX = 'drift'
1662
1662
1663 def __init__(self, **kwargs):
1663 def __init__(self, **kwargs):
1664 Figure.__init__(self, **kwargs)
1664 Figure.__init__(self, **kwargs)
1665 self.timerange = 2*60*60
1665 self.timerange = 2*60*60
1666 self.isConfig = False
1666 self.isConfig = False
1667 self.__nsubplots = 1
1667 self.__nsubplots = 1
1668
1668
1669 self.WIDTH = 800
1669 self.WIDTH = 800
1670 self.HEIGHT = 150
1670 self.HEIGHT = 150
1671 self.WIDTHPROF = 120
1671 self.WIDTHPROF = 120
1672 self.HEIGHTPROF = 0
1672 self.HEIGHTPROF = 0
1673 self.counter_imagwr = 0
1673 self.counter_imagwr = 0
1674
1674
1675 self.PLOT_CODE = EWDRIFT_CODE
1675 self.PLOT_CODE = EWDRIFT_CODE
1676
1676
1677 self.FTP_WEI = None
1677 self.FTP_WEI = None
1678 self.EXP_CODE = None
1678 self.EXP_CODE = None
1679 self.SUB_EXP_CODE = None
1679 self.SUB_EXP_CODE = None
1680 self.PLOT_POS = None
1680 self.PLOT_POS = None
1681 self.tmin = None
1681 self.tmin = None
1682 self.tmax = None
1682 self.tmax = None
1683
1683
1684 self.xmin = None
1684 self.xmin = None
1685 self.xmax = None
1685 self.xmax = None
1686
1686
1687 self.figfile = None
1687 self.figfile = None
1688
1688
1689 def getSubplots(self):
1689 def getSubplots(self):
1690
1690
1691 ncol = 1
1691 ncol = 1
1692 nrow = self.nplots
1692 nrow = self.nplots
1693
1693
1694 return nrow, ncol
1694 return nrow, ncol
1695
1695
1696 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1696 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1697
1697
1698 self.__showprofile = showprofile
1698 self.__showprofile = showprofile
1699 self.nplots = nplots
1699 self.nplots = nplots
1700
1700
1701 ncolspan = 1
1701 ncolspan = 1
1702 colspan = 1
1702 colspan = 1
1703
1703
1704 self.createFigure(id = id,
1704 self.createFigure(id = id,
1705 wintitle = wintitle,
1705 wintitle = wintitle,
1706 widthplot = self.WIDTH + self.WIDTHPROF,
1706 widthplot = self.WIDTH + self.WIDTHPROF,
1707 heightplot = self.HEIGHT + self.HEIGHTPROF,
1707 heightplot = self.HEIGHT + self.HEIGHTPROF,
1708 show=show)
1708 show=show)
1709
1709
1710 nrow, ncol = self.getSubplots()
1710 nrow, ncol = self.getSubplots()
1711
1711
1712 counter = 0
1712 counter = 0
1713 for y in range(nrow):
1713 for y in range(nrow):
1714 if counter >= self.nplots:
1714 if counter >= self.nplots:
1715 break
1715 break
1716
1716
1717 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1717 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1718 counter += 1
1718 counter += 1
1719
1719
1720 def run(self, dataOut, id, wintitle="", channelList=None,
1720 def run(self, dataOut, id, wintitle="", channelList=None,
1721 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1721 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1722 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1722 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1723 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1723 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1724 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1724 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1725 server=None, folder=None, username=None, password=None,
1725 server=None, folder=None, username=None, password=None,
1726 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1726 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1727 """
1727 """
1728
1728
1729 Input:
1729 Input:
1730 dataOut :
1730 dataOut :
1731 id :
1731 id :
1732 wintitle :
1732 wintitle :
1733 channelList :
1733 channelList :
1734 showProfile :
1734 showProfile :
1735 xmin : None,
1735 xmin : None,
1736 xmax : None,
1736 xmax : None,
1737 ymin : None,
1737 ymin : None,
1738 ymax : None,
1738 ymax : None,
1739 zmin : None,
1739 zmin : None,
1740 zmax : None
1740 zmax : None
1741 """
1741 """
1742
1742
1743 if timerange is not None:
1743 if timerange is not None:
1744 self.timerange = timerange
1744 self.timerange = timerange
1745
1745
1746 tmin = None
1746 tmin = None
1747 tmax = None
1747 tmax = None
1748
1748
1749 x = dataOut.getTimeRange1(dataOut.outputInterval)
1749 x = dataOut.getTimeRange1(dataOut.outputInterval)
1750 # y = dataOut.heightList
1750 # y = dataOut.heightList
1751 y = dataOut.heightList
1751 y = dataOut.heightList
1752
1752
1753 z = dataOut.data_output
1753 z = dataOut.data_output
1754 nplots = z.shape[0] #Number of wind dimensions estimated
1754 nplots = z.shape[0] #Number of wind dimensions estimated
1755 nplotsw = nplots
1755 nplotsw = nplots
1756
1756
1757 #If there is a SNR function defined
1757 #If there is a SNR function defined
1758 if dataOut.data_SNR is not None:
1758 if dataOut.data_SNR is not None:
1759 nplots += 1
1759 nplots += 1
1760 SNR = dataOut.data_SNR
1760 SNR = dataOut.data_SNR
1761
1761
1762 if SNR_1:
1762 if SNR_1:
1763 SNR += 1
1763 SNR += 1
1764
1764
1765 SNRavg = numpy.average(SNR, axis=0)
1765 SNRavg = numpy.average(SNR, axis=0)
1766
1766
1767 SNRdB = 10*numpy.log10(SNR)
1767 SNRdB = 10*numpy.log10(SNR)
1768 SNRavgdB = 10*numpy.log10(SNRavg)
1768 SNRavgdB = 10*numpy.log10(SNRavg)
1769
1769
1770 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1770 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1771
1771
1772 for i in range(nplotsw):
1772 for i in range(nplotsw):
1773 z[i,ind] = numpy.nan
1773 z[i,ind] = numpy.nan
1774
1774
1775
1775
1776 showprofile = False
1776 showprofile = False
1777 # thisDatetime = dataOut.datatime
1777 # thisDatetime = dataOut.datatime
1778 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1778 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1779 title = wintitle + " EW Drifts"
1779 title = wintitle + " EW Drifts"
1780 xlabel = ""
1780 xlabel = ""
1781 ylabel = "Height (Km)"
1781 ylabel = "Height (Km)"
1782
1782
1783 if not self.isConfig:
1783 if not self.isConfig:
1784
1784
1785 self.setup(id=id,
1785 self.setup(id=id,
1786 nplots=nplots,
1786 nplots=nplots,
1787 wintitle=wintitle,
1787 wintitle=wintitle,
1788 showprofile=showprofile,
1788 showprofile=showprofile,
1789 show=show)
1789 show=show)
1790
1790
1791 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1791 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1792
1792
1793 if ymin == None: ymin = numpy.nanmin(y)
1793 if ymin == None: ymin = numpy.nanmin(y)
1794 if ymax == None: ymax = numpy.nanmax(y)
1794 if ymax == None: ymax = numpy.nanmax(y)
1795
1795
1796 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1796 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1797 if zminZonal == None: zminZonal = -zmaxZonal
1797 if zminZonal == None: zminZonal = -zmaxZonal
1798 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1798 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1799 if zminVertical == None: zminVertical = -zmaxVertical
1799 if zminVertical == None: zminVertical = -zmaxVertical
1800
1800
1801 if dataOut.data_SNR is not None:
1801 if dataOut.data_SNR is not None:
1802 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1802 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1803 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1803 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1804
1804
1805 self.FTP_WEI = ftp_wei
1805 self.FTP_WEI = ftp_wei
1806 self.EXP_CODE = exp_code
1806 self.EXP_CODE = exp_code
1807 self.SUB_EXP_CODE = sub_exp_code
1807 self.SUB_EXP_CODE = sub_exp_code
1808 self.PLOT_POS = plot_pos
1808 self.PLOT_POS = plot_pos
1809
1809
1810 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1810 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1811 self.isConfig = True
1811 self.isConfig = True
1812
1812
1813
1813
1814 self.setWinTitle(title)
1814 self.setWinTitle(title)
1815
1815
1816 if ((self.xmax - x[1]) < (x[1]-x[0])):
1816 if ((self.xmax - x[1]) < (x[1]-x[0])):
1817 x[1] = self.xmax
1817 x[1] = self.xmax
1818
1818
1819 strWind = ['Zonal','Vertical']
1819 strWind = ['Zonal','Vertical']
1820 strCb = 'Velocity (m/s)'
1820 strCb = 'Velocity (m/s)'
1821 zmaxVector = [zmaxZonal, zmaxVertical]
1821 zmaxVector = [zmaxZonal, zmaxVertical]
1822 zminVector = [zminZonal, zminVertical]
1822 zminVector = [zminZonal, zminVertical]
1823
1823
1824 for i in range(nplotsw):
1824 for i in range(nplotsw):
1825
1825
1826 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1826 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1827 axes = self.axesList[i*self.__nsubplots]
1827 axes = self.axesList[i*self.__nsubplots]
1828
1828
1829 z1 = z[i,:].reshape((1,-1))
1829 z1 = z[i,:].reshape((1,-1))
1830
1830
1831 axes.pcolorbuffer(x, y, z1,
1831 axes.pcolorbuffer(x, y, z1,
1832 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1832 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1833 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1833 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1834 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1834 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1835
1835
1836 if dataOut.data_SNR is not None:
1836 if dataOut.data_SNR is not None:
1837 i += 1
1837 i += 1
1838 if SNR_1:
1838 if SNR_1:
1839 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1839 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1840 else:
1840 else:
1841 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1841 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1842 axes = self.axesList[i*self.__nsubplots]
1842 axes = self.axesList[i*self.__nsubplots]
1843 SNRavgdB = SNRavgdB.reshape((1,-1))
1843 SNRavgdB = SNRavgdB.reshape((1,-1))
1844
1844
1845 axes.pcolorbuffer(x, y, SNRavgdB,
1845 axes.pcolorbuffer(x, y, SNRavgdB,
1846 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1846 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1847 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1847 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1848 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1848 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1849
1849
1850 self.draw()
1850 self.draw()
1851
1851
1852 if x[1] >= self.axesList[0].xmax:
1852 if x[1] >= self.axesList[0].xmax:
1853 self.counter_imagwr = wr_period
1853 self.counter_imagwr = wr_period
1854 self.isConfig = False
1854 self.isConfig = False
1855 self.figfile = None
1855 self.figfile = None
1856
1856
1857
1857
1858
1858
1859
1859
1860 class PhasePlot_(Figure):
1860 class PhasePlot_(Figure):
1861
1861
1862 __isConfig = None
1862 __isConfig = None
1863 __nsubplots = None
1863 __nsubplots = None
1864
1864
1865 PREFIX = 'mphase'
1865 PREFIX = 'mphase'
1866
1866
1867
1867
1868 def __init__(self, **kwargs):
1868 def __init__(self, **kwargs):
1869 Figure.__init__(self, **kwargs)
1869 Figure.__init__(self, **kwargs)
1870 self.timerange = 24*60*60
1870 self.timerange = 24*60*60
1871 self.isConfig = False
1871 self.isConfig = False
1872 self.__nsubplots = 1
1872 self.__nsubplots = 1
1873 self.counter_imagwr = 0
1873 self.counter_imagwr = 0
1874 self.WIDTH = 600
1874 self.WIDTH = 600
1875 self.HEIGHT = 300
1875 self.HEIGHT = 300
1876 self.WIDTHPROF = 120
1876 self.WIDTHPROF = 120
1877 self.HEIGHTPROF = 0
1877 self.HEIGHTPROF = 0
1878 self.xdata = None
1878 self.xdata = None
1879 self.ydata = None
1879 self.ydata = None
1880
1880
1881 self.PLOT_CODE = MPHASE_CODE
1881 self.PLOT_CODE = MPHASE_CODE
1882
1882
1883 self.FTP_WEI = None
1883 self.FTP_WEI = None
1884 self.EXP_CODE = None
1884 self.EXP_CODE = None
1885 self.SUB_EXP_CODE = None
1885 self.SUB_EXP_CODE = None
1886 self.PLOT_POS = None
1886 self.PLOT_POS = None
1887
1887
1888
1888
1889 self.filename_phase = None
1889 self.filename_phase = None
1890
1890
1891 self.figfile = None
1891 self.figfile = None
1892
1892
1893 def getSubplots(self):
1893 def getSubplots(self):
1894
1894
1895 ncol = 1
1895 ncol = 1
1896 nrow = 1
1896 nrow = 1
1897
1897
1898 return nrow, ncol
1898 return nrow, ncol
1899
1899
1900 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1900 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1901
1901
1902 self.__showprofile = showprofile
1902 self.__showprofile = showprofile
1903 self.nplots = nplots
1903 self.nplots = nplots
1904
1904
1905 ncolspan = 7
1905 ncolspan = 7
1906 colspan = 6
1906 colspan = 6
1907 self.__nsubplots = 2
1907 self.__nsubplots = 2
1908
1908
1909 self.createFigure(id = id,
1909 self.createFigure(id = id,
1910 wintitle = wintitle,
1910 wintitle = wintitle,
1911 widthplot = self.WIDTH+self.WIDTHPROF,
1911 widthplot = self.WIDTH+self.WIDTHPROF,
1912 heightplot = self.HEIGHT+self.HEIGHTPROF,
1912 heightplot = self.HEIGHT+self.HEIGHTPROF,
1913 show=show)
1913 show=show)
1914
1914
1915 nrow, ncol = self.getSubplots()
1915 nrow, ncol = self.getSubplots()
1916
1916
1917 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1917 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1918
1918
1919
1919
1920 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1920 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1921 xmin=None, xmax=None, ymin=None, ymax=None,
1921 xmin=None, xmax=None, ymin=None, ymax=None,
1922 timerange=None,
1922 timerange=None,
1923 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1923 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1924 server=None, folder=None, username=None, password=None,
1924 server=None, folder=None, username=None, password=None,
1925 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1925 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1926
1926
1927
1927
1928 tmin = None
1928 tmin = None
1929 tmax = None
1929 tmax = None
1930 x = dataOut.getTimeRange1(dataOut.outputInterval)
1930 x = dataOut.getTimeRange1(dataOut.outputInterval)
1931 y = dataOut.getHeiRange()
1931 y = dataOut.getHeiRange()
1932
1932
1933
1933
1934 #thisDatetime = dataOut.datatime
1934 #thisDatetime = dataOut.datatime
1935 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1935 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1936 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1936 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1937 xlabel = "Local Time"
1937 xlabel = "Local Time"
1938 ylabel = "Phase"
1938 ylabel = "Phase"
1939
1939
1940
1940
1941 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1941 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1942 phase_beacon = dataOut.data_output
1942 phase_beacon = dataOut.data_output
1943 update_figfile = False
1943 update_figfile = False
1944
1944
1945 if not self.isConfig:
1945 if not self.isConfig:
1946
1946
1947 self.nplots = phase_beacon.size
1947 self.nplots = phase_beacon.size
1948
1948
1949 self.setup(id=id,
1949 self.setup(id=id,
1950 nplots=self.nplots,
1950 nplots=self.nplots,
1951 wintitle=wintitle,
1951 wintitle=wintitle,
1952 showprofile=showprofile,
1952 showprofile=showprofile,
1953 show=show)
1953 show=show)
1954
1954
1955 if timerange is not None:
1955 if timerange is not None:
1956 self.timerange = timerange
1956 self.timerange = timerange
1957
1957
1958 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1958 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1959
1959
1960 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1960 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1961 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1961 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1962
1962
1963 self.FTP_WEI = ftp_wei
1963 self.FTP_WEI = ftp_wei
1964 self.EXP_CODE = exp_code
1964 self.EXP_CODE = exp_code
1965 self.SUB_EXP_CODE = sub_exp_code
1965 self.SUB_EXP_CODE = sub_exp_code
1966 self.PLOT_POS = plot_pos
1966 self.PLOT_POS = plot_pos
1967
1967
1968 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1968 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1969 self.isConfig = True
1969 self.isConfig = True
1970 self.figfile = figfile
1970 self.figfile = figfile
1971 self.xdata = numpy.array([])
1971 self.xdata = numpy.array([])
1972 self.ydata = numpy.array([])
1972 self.ydata = numpy.array([])
1973
1973
1974 #open file beacon phase
1974 #open file beacon phase
1975 path = '%s%03d' %(self.PREFIX, self.id)
1975 path = '%s%03d' %(self.PREFIX, self.id)
1976 beacon_file = os.path.join(path,'%s.txt'%self.name)
1976 beacon_file = os.path.join(path,'%s.txt'%self.name)
1977 self.filename_phase = os.path.join(figpath,beacon_file)
1977 self.filename_phase = os.path.join(figpath,beacon_file)
1978 update_figfile = True
1978 update_figfile = True
1979
1979
1980
1980
1981 #store data beacon phase
1981 #store data beacon phase
1982 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1982 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1983
1983
1984 self.setWinTitle(title)
1984 self.setWinTitle(title)
1985
1985
1986
1986
1987 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1987 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1988
1988
1989 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1989 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1990
1990
1991 axes = self.axesList[0]
1991 axes = self.axesList[0]
1992
1992
1993 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1993 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1994
1994
1995 if len(self.ydata)==0:
1995 if len(self.ydata)==0:
1996 self.ydata = phase_beacon.reshape(-1,1)
1996 self.ydata = phase_beacon.reshape(-1,1)
1997 else:
1997 else:
1998 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1998 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1999
1999
2000
2000
2001 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
2001 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
2002 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
2002 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
2003 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
2003 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
2004 XAxisAsTime=True, grid='both'
2004 XAxisAsTime=True, grid='both'
2005 )
2005 )
2006
2006
2007 self.draw()
2007 self.draw()
2008
2008
2009 self.save(figpath=figpath,
2009 self.save(figpath=figpath,
2010 figfile=figfile,
2010 figfile=figfile,
2011 save=save,
2011 save=save,
2012 ftp=ftp,
2012 ftp=ftp,
2013 wr_period=wr_period,
2013 wr_period=wr_period,
2014 thisDatetime=thisDatetime,
2014 thisDatetime=thisDatetime,
2015 update_figfile=update_figfile)
2015 update_figfile=update_figfile)
2016
2016
2017 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
2017 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
2018 self.counter_imagwr = wr_period
2018 self.counter_imagwr = wr_period
2019 self.isConfig = False
2019 self.isConfig = False
2020 update_figfile = True
2020 update_figfile = True
2021
2021
2022
2022
2023
2023
2024 class NSMeteorDetection1Plot_(Figure):
2024 class NSMeteorDetection1Plot_(Figure):
2025
2025
2026 isConfig = None
2026 isConfig = None
2027 __nsubplots = None
2027 __nsubplots = None
2028
2028
2029 WIDTHPROF = None
2029 WIDTHPROF = None
2030 HEIGHTPROF = None
2030 HEIGHTPROF = None
2031 PREFIX = 'nsm'
2031 PREFIX = 'nsm'
2032
2032
2033 zminList = None
2033 zminList = None
2034 zmaxList = None
2034 zmaxList = None
2035 cmapList = None
2035 cmapList = None
2036 titleList = None
2036 titleList = None
2037 nPairs = None
2037 nPairs = None
2038 nChannels = None
2038 nChannels = None
2039 nParam = None
2039 nParam = None
2040
2040
2041 def __init__(self, **kwargs):
2041 def __init__(self, **kwargs):
2042 Figure.__init__(self, **kwargs)
2042 Figure.__init__(self, **kwargs)
2043 self.isConfig = False
2043 self.isConfig = False
2044 self.__nsubplots = 1
2044 self.__nsubplots = 1
2045
2045
2046 self.WIDTH = 750
2046 self.WIDTH = 750
2047 self.HEIGHT = 250
2047 self.HEIGHT = 250
2048 self.WIDTHPROF = 120
2048 self.WIDTHPROF = 120
2049 self.HEIGHTPROF = 0
2049 self.HEIGHTPROF = 0
2050 self.counter_imagwr = 0
2050 self.counter_imagwr = 0
2051
2051
2052 self.PLOT_CODE = SPEC_CODE
2052 self.PLOT_CODE = SPEC_CODE
2053
2053
2054 self.FTP_WEI = None
2054 self.FTP_WEI = None
2055 self.EXP_CODE = None
2055 self.EXP_CODE = None
2056 self.SUB_EXP_CODE = None
2056 self.SUB_EXP_CODE = None
2057 self.PLOT_POS = None
2057 self.PLOT_POS = None
2058
2058
2059 self.__xfilter_ena = False
2059 self.__xfilter_ena = False
2060 self.__yfilter_ena = False
2060 self.__yfilter_ena = False
2061
2061
2062 def getSubplots(self):
2062 def getSubplots(self):
2063
2063
2064 ncol = 3
2064 ncol = 3
2065 nrow = int(numpy.ceil(self.nplots/3.0))
2065 nrow = int(numpy.ceil(self.nplots/3.0))
2066
2066
2067 return nrow, ncol
2067 return nrow, ncol
2068
2068
2069 def setup(self, id, nplots, wintitle, show=True):
2069 def setup(self, id, nplots, wintitle, show=True):
2070
2070
2071 self.nplots = nplots
2071 self.nplots = nplots
2072
2072
2073 ncolspan = 1
2073 ncolspan = 1
2074 colspan = 1
2074 colspan = 1
2075
2075
2076 self.createFigure(id = id,
2076 self.createFigure(id = id,
2077 wintitle = wintitle,
2077 wintitle = wintitle,
2078 widthplot = self.WIDTH + self.WIDTHPROF,
2078 widthplot = self.WIDTH + self.WIDTHPROF,
2079 heightplot = self.HEIGHT + self.HEIGHTPROF,
2079 heightplot = self.HEIGHT + self.HEIGHTPROF,
2080 show=show)
2080 show=show)
2081
2081
2082 nrow, ncol = self.getSubplots()
2082 nrow, ncol = self.getSubplots()
2083
2083
2084 counter = 0
2084 counter = 0
2085 for y in range(nrow):
2085 for y in range(nrow):
2086 for x in range(ncol):
2086 for x in range(ncol):
2087
2087
2088 if counter >= self.nplots:
2088 if counter >= self.nplots:
2089 break
2089 break
2090
2090
2091 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2091 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2092
2092
2093 counter += 1
2093 counter += 1
2094
2094
2095 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2095 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2096 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2096 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2097 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2097 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2098 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2098 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2099 server=None, folder=None, username=None, password=None,
2099 server=None, folder=None, username=None, password=None,
2100 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2100 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2101 xaxis="frequency"):
2101 xaxis="frequency"):
2102
2102
2103 """
2103 """
2104
2104
2105 Input:
2105 Input:
2106 dataOut :
2106 dataOut :
2107 id :
2107 id :
2108 wintitle :
2108 wintitle :
2109 channelList :
2109 channelList :
2110 showProfile :
2110 showProfile :
2111 xmin : None,
2111 xmin : None,
2112 xmax : None,
2112 xmax : None,
2113 ymin : None,
2113 ymin : None,
2114 ymax : None,
2114 ymax : None,
2115 zmin : None,
2115 zmin : None,
2116 zmax : None
2116 zmax : None
2117 """
2117 """
2118 #SEPARAR EN DOS PLOTS
2118 #SEPARAR EN DOS PLOTS
2119 nParam = dataOut.data_param.shape[1] - 3
2119 nParam = dataOut.data_param.shape[1] - 3
2120
2120
2121 utctime = dataOut.data_param[0,0]
2121 utctime = dataOut.data_param[0,0]
2122 tmet = dataOut.data_param[:,1].astype(int)
2122 tmet = dataOut.data_param[:,1].astype(int)
2123 hmet = dataOut.data_param[:,2].astype(int)
2123 hmet = dataOut.data_param[:,2].astype(int)
2124
2124
2125 x = dataOut.abscissaList
2125 x = dataOut.abscissaList
2126 y = dataOut.heightList
2126 y = dataOut.heightList
2127
2127
2128 z = numpy.zeros((nParam, y.size, x.size - 1))
2128 z = numpy.zeros((nParam, y.size, x.size - 1))
2129 z[:,:] = numpy.nan
2129 z[:,:] = numpy.nan
2130 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
2130 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
2131 z[0,:,:] = 10*numpy.log10(z[0,:,:])
2131 z[0,:,:] = 10*numpy.log10(z[0,:,:])
2132
2132
2133 xlabel = "Time (s)"
2133 xlabel = "Time (s)"
2134 ylabel = "Range (km)"
2134 ylabel = "Range (km)"
2135
2135
2136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2136 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2137
2137
2138 if not self.isConfig:
2138 if not self.isConfig:
2139
2139
2140 nplots = nParam
2140 nplots = nParam
2141
2141
2142 self.setup(id=id,
2142 self.setup(id=id,
2143 nplots=nplots,
2143 nplots=nplots,
2144 wintitle=wintitle,
2144 wintitle=wintitle,
2145 show=show)
2145 show=show)
2146
2146
2147 if xmin is None: xmin = numpy.nanmin(x)
2147 if xmin is None: xmin = numpy.nanmin(x)
2148 if xmax is None: xmax = numpy.nanmax(x)
2148 if xmax is None: xmax = numpy.nanmax(x)
2149 if ymin is None: ymin = numpy.nanmin(y)
2149 if ymin is None: ymin = numpy.nanmin(y)
2150 if ymax is None: ymax = numpy.nanmax(y)
2150 if ymax is None: ymax = numpy.nanmax(y)
2151 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2151 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2152 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2152 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2153 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2153 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2154 if vmin is None: vmin = -vmax
2154 if vmin is None: vmin = -vmax
2155 if wmin is None: wmin = 0
2155 if wmin is None: wmin = 0
2156 if wmax is None: wmax = 50
2156 if wmax is None: wmax = 50
2157
2157
2158 pairsList = dataOut.groupList
2158 pairsList = dataOut.groupList
2159 self.nPairs = len(dataOut.groupList)
2159 self.nPairs = len(dataOut.groupList)
2160
2160
2161 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
2161 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
2162 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
2162 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
2163 titleList = ["SNR","Radial Velocity","Coherence"]
2163 titleList = ["SNR","Radial Velocity","Coherence"]
2164 cmapList = ["jet","RdBu_r","jet"]
2164 cmapList = ["jet","RdBu_r","jet"]
2165
2165
2166 for i in range(self.nPairs):
2166 for i in range(self.nPairs):
2167 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
2167 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
2168 titleList = titleList + [strAux1]
2168 titleList = titleList + [strAux1]
2169 cmapList = cmapList + ["RdBu_r"]
2169 cmapList = cmapList + ["RdBu_r"]
2170
2170
2171 self.zminList = zminList
2171 self.zminList = zminList
2172 self.zmaxList = zmaxList
2172 self.zmaxList = zmaxList
2173 self.cmapList = cmapList
2173 self.cmapList = cmapList
2174 self.titleList = titleList
2174 self.titleList = titleList
2175
2175
2176 self.FTP_WEI = ftp_wei
2176 self.FTP_WEI = ftp_wei
2177 self.EXP_CODE = exp_code
2177 self.EXP_CODE = exp_code
2178 self.SUB_EXP_CODE = sub_exp_code
2178 self.SUB_EXP_CODE = sub_exp_code
2179 self.PLOT_POS = plot_pos
2179 self.PLOT_POS = plot_pos
2180
2180
2181 self.isConfig = True
2181 self.isConfig = True
2182
2182
2183 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2183 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2184
2184
2185 for i in range(nParam):
2185 for i in range(nParam):
2186 title = self.titleList[i] + ": " +str_datetime
2186 title = self.titleList[i] + ": " +str_datetime
2187 axes = self.axesList[i]
2187 axes = self.axesList[i]
2188 axes.pcolor(x, y, z[i,:].T,
2188 axes.pcolor(x, y, z[i,:].T,
2189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2189 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2190 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2190 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2191 self.draw()
2191 self.draw()
2192
2192
2193 if figfile == None:
2193 if figfile == None:
2194 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2194 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2195 name = str_datetime
2195 name = str_datetime
2196 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2196 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2197 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2197 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2198 figfile = self.getFilename(name)
2198 figfile = self.getFilename(name)
2199
2199
2200 self.save(figpath=figpath,
2200 self.save(figpath=figpath,
2201 figfile=figfile,
2201 figfile=figfile,
2202 save=save,
2202 save=save,
2203 ftp=ftp,
2203 ftp=ftp,
2204 wr_period=wr_period,
2204 wr_period=wr_period,
2205 thisDatetime=thisDatetime)
2205 thisDatetime=thisDatetime)
2206
2206
2207
2207
2208 class NSMeteorDetection2Plot_(Figure):
2208 class NSMeteorDetection2Plot_(Figure):
2209
2209
2210 isConfig = None
2210 isConfig = None
2211 __nsubplots = None
2211 __nsubplots = None
2212
2212
2213 WIDTHPROF = None
2213 WIDTHPROF = None
2214 HEIGHTPROF = None
2214 HEIGHTPROF = None
2215 PREFIX = 'nsm'
2215 PREFIX = 'nsm'
2216
2216
2217 zminList = None
2217 zminList = None
2218 zmaxList = None
2218 zmaxList = None
2219 cmapList = None
2219 cmapList = None
2220 titleList = None
2220 titleList = None
2221 nPairs = None
2221 nPairs = None
2222 nChannels = None
2222 nChannels = None
2223 nParam = None
2223 nParam = None
2224
2224
2225 def __init__(self, **kwargs):
2225 def __init__(self, **kwargs):
2226 Figure.__init__(self, **kwargs)
2226 Figure.__init__(self, **kwargs)
2227 self.isConfig = False
2227 self.isConfig = False
2228 self.__nsubplots = 1
2228 self.__nsubplots = 1
2229
2229
2230 self.WIDTH = 750
2230 self.WIDTH = 750
2231 self.HEIGHT = 250
2231 self.HEIGHT = 250
2232 self.WIDTHPROF = 120
2232 self.WIDTHPROF = 120
2233 self.HEIGHTPROF = 0
2233 self.HEIGHTPROF = 0
2234 self.counter_imagwr = 0
2234 self.counter_imagwr = 0
2235
2235
2236 self.PLOT_CODE = SPEC_CODE
2236 self.PLOT_CODE = SPEC_CODE
2237
2237
2238 self.FTP_WEI = None
2238 self.FTP_WEI = None
2239 self.EXP_CODE = None
2239 self.EXP_CODE = None
2240 self.SUB_EXP_CODE = None
2240 self.SUB_EXP_CODE = None
2241 self.PLOT_POS = None
2241 self.PLOT_POS = None
2242
2242
2243 self.__xfilter_ena = False
2243 self.__xfilter_ena = False
2244 self.__yfilter_ena = False
2244 self.__yfilter_ena = False
2245
2245
2246 def getSubplots(self):
2246 def getSubplots(self):
2247
2247
2248 ncol = 3
2248 ncol = 3
2249 nrow = int(numpy.ceil(self.nplots/3.0))
2249 nrow = int(numpy.ceil(self.nplots/3.0))
2250
2250
2251 return nrow, ncol
2251 return nrow, ncol
2252
2252
2253 def setup(self, id, nplots, wintitle, show=True):
2253 def setup(self, id, nplots, wintitle, show=True):
2254
2254
2255 self.nplots = nplots
2255 self.nplots = nplots
2256
2256
2257 ncolspan = 1
2257 ncolspan = 1
2258 colspan = 1
2258 colspan = 1
2259
2259
2260 self.createFigure(id = id,
2260 self.createFigure(id = id,
2261 wintitle = wintitle,
2261 wintitle = wintitle,
2262 widthplot = self.WIDTH + self.WIDTHPROF,
2262 widthplot = self.WIDTH + self.WIDTHPROF,
2263 heightplot = self.HEIGHT + self.HEIGHTPROF,
2263 heightplot = self.HEIGHT + self.HEIGHTPROF,
2264 show=show)
2264 show=show)
2265
2265
2266 nrow, ncol = self.getSubplots()
2266 nrow, ncol = self.getSubplots()
2267
2267
2268 counter = 0
2268 counter = 0
2269 for y in range(nrow):
2269 for y in range(nrow):
2270 for x in range(ncol):
2270 for x in range(ncol):
2271
2271
2272 if counter >= self.nplots:
2272 if counter >= self.nplots:
2273 break
2273 break
2274
2274
2275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2276
2276
2277 counter += 1
2277 counter += 1
2278
2278
2279 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2279 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2280 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2280 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2281 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2281 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2282 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2282 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2283 server=None, folder=None, username=None, password=None,
2283 server=None, folder=None, username=None, password=None,
2284 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2284 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2285 xaxis="frequency"):
2285 xaxis="frequency"):
2286
2286
2287 """
2287 """
2288
2288
2289 Input:
2289 Input:
2290 dataOut :
2290 dataOut :
2291 id :
2291 id :
2292 wintitle :
2292 wintitle :
2293 channelList :
2293 channelList :
2294 showProfile :
2294 showProfile :
2295 xmin : None,
2295 xmin : None,
2296 xmax : None,
2296 xmax : None,
2297 ymin : None,
2297 ymin : None,
2298 ymax : None,
2298 ymax : None,
2299 zmin : None,
2299 zmin : None,
2300 zmax : None
2300 zmax : None
2301 """
2301 """
2302 #Rebuild matrix
2302 #Rebuild matrix
2303 utctime = dataOut.data_param[0,0]
2303 utctime = dataOut.data_param[0,0]
2304 cmet = dataOut.data_param[:,1].astype(int)
2304 cmet = dataOut.data_param[:,1].astype(int)
2305 tmet = dataOut.data_param[:,2].astype(int)
2305 tmet = dataOut.data_param[:,2].astype(int)
2306 hmet = dataOut.data_param[:,3].astype(int)
2306 hmet = dataOut.data_param[:,3].astype(int)
2307
2307
2308 nParam = 3
2308 nParam = 3
2309 nChan = len(dataOut.groupList)
2309 nChan = len(dataOut.groupList)
2310 x = dataOut.abscissaList
2310 x = dataOut.abscissaList
2311 y = dataOut.heightList
2311 y = dataOut.heightList
2312
2312
2313 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2313 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2314 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2314 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2315 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2315 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2316 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2316 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2317
2317
2318 xlabel = "Time (s)"
2318 xlabel = "Time (s)"
2319 ylabel = "Range (km)"
2319 ylabel = "Range (km)"
2320
2320
2321 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2321 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2322
2322
2323 if not self.isConfig:
2323 if not self.isConfig:
2324
2324
2325 nplots = nParam*nChan
2325 nplots = nParam*nChan
2326
2326
2327 self.setup(id=id,
2327 self.setup(id=id,
2328 nplots=nplots,
2328 nplots=nplots,
2329 wintitle=wintitle,
2329 wintitle=wintitle,
2330 show=show)
2330 show=show)
2331
2331
2332 if xmin is None: xmin = numpy.nanmin(x)
2332 if xmin is None: xmin = numpy.nanmin(x)
2333 if xmax is None: xmax = numpy.nanmax(x)
2333 if xmax is None: xmax = numpy.nanmax(x)
2334 if ymin is None: ymin = numpy.nanmin(y)
2334 if ymin is None: ymin = numpy.nanmin(y)
2335 if ymax is None: ymax = numpy.nanmax(y)
2335 if ymax is None: ymax = numpy.nanmax(y)
2336 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2336 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2337 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2337 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2338 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2338 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2339 if vmin is None: vmin = -vmax
2339 if vmin is None: vmin = -vmax
2340 if wmin is None: wmin = 0
2340 if wmin is None: wmin = 0
2341 if wmax is None: wmax = 50
2341 if wmax is None: wmax = 50
2342
2342
2343 self.nChannels = nChan
2343 self.nChannels = nChan
2344
2344
2345 zminList = []
2345 zminList = []
2346 zmaxList = []
2346 zmaxList = []
2347 titleList = []
2347 titleList = []
2348 cmapList = []
2348 cmapList = []
2349 for i in range(self.nChannels):
2349 for i in range(self.nChannels):
2350 strAux1 = "SNR Channel "+ str(i)
2350 strAux1 = "SNR Channel "+ str(i)
2351 strAux2 = "Radial Velocity Channel "+ str(i)
2351 strAux2 = "Radial Velocity Channel "+ str(i)
2352 strAux3 = "Spectral Width Channel "+ str(i)
2352 strAux3 = "Spectral Width Channel "+ str(i)
2353
2353
2354 titleList = titleList + [strAux1,strAux2,strAux3]
2354 titleList = titleList + [strAux1,strAux2,strAux3]
2355 cmapList = cmapList + ["jet","RdBu_r","jet"]
2355 cmapList = cmapList + ["jet","RdBu_r","jet"]
2356 zminList = zminList + [SNRmin,vmin,wmin]
2356 zminList = zminList + [SNRmin,vmin,wmin]
2357 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2357 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2358
2358
2359 self.zminList = zminList
2359 self.zminList = zminList
2360 self.zmaxList = zmaxList
2360 self.zmaxList = zmaxList
2361 self.cmapList = cmapList
2361 self.cmapList = cmapList
2362 self.titleList = titleList
2362 self.titleList = titleList
2363
2363
2364 self.FTP_WEI = ftp_wei
2364 self.FTP_WEI = ftp_wei
2365 self.EXP_CODE = exp_code
2365 self.EXP_CODE = exp_code
2366 self.SUB_EXP_CODE = sub_exp_code
2366 self.SUB_EXP_CODE = sub_exp_code
2367 self.PLOT_POS = plot_pos
2367 self.PLOT_POS = plot_pos
2368
2368
2369 self.isConfig = True
2369 self.isConfig = True
2370
2370
2371 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2371 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2372
2372
2373 for i in range(self.nplots):
2373 for i in range(self.nplots):
2374 title = self.titleList[i] + ": " +str_datetime
2374 title = self.titleList[i] + ": " +str_datetime
2375 axes = self.axesList[i]
2375 axes = self.axesList[i]
2376 axes.pcolor(x, y, z[i,:].T,
2376 axes.pcolor(x, y, z[i,:].T,
2377 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2377 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2378 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2378 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2379 self.draw()
2379 self.draw()
2380
2380
2381 if figfile == None:
2381 if figfile == None:
2382 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2382 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2383 name = str_datetime
2383 name = str_datetime
2384 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2384 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2385 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2385 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2386 figfile = self.getFilename(name)
2386 figfile = self.getFilename(name)
2387
2387
2388 self.save(figpath=figpath,
2388 self.save(figpath=figpath,
2389 figfile=figfile,
2389 figfile=figfile,
2390 save=save,
2390 save=save,
2391 ftp=ftp,
2391 ftp=ftp,
2392 wr_period=wr_period,
2392 wr_period=wr_period,
2393 thisDatetime=thisDatetime)
2393 thisDatetime=thisDatetime)
2394 No newline at end of file
2394
@@ -1,1588 +1,1589
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from .figure import Figure, isRealtime, isTimeInHourRange
10 from .figure import Figure, isRealtime, isTimeInHourRange
11 from .plotting_codes import *
11 from .plotting_codes import *
12 from schainpy.model.proc.jroproc_base import MPDecorator
12 from schainpy.model.proc.jroproc_base import MPDecorator
13
13
14 from schainpy.utils import log
14 from schainpy.utils import log
15
15
16 @MPDecorator
16 @MPDecorator
17 class SpectraPlot_(Figure):
17 class SpectraPlot_(Figure):
18
18
19 isConfig = None
19 isConfig = None
20 __nsubplots = None
20 __nsubplots = None
21
21
22 WIDTHPROF = None
22 WIDTHPROF = None
23 HEIGHTPROF = None
23 HEIGHTPROF = None
24 PREFIX = 'spc'
24 PREFIX = 'spc'
25
25
26 def __init__(self):
26 def __init__(self):
27 Figure.__init__(self)
27 Figure.__init__(self)
28 self.isConfig = False
28 self.isConfig = False
29 self.__nsubplots = 1
29 self.__nsubplots = 1
30 self.WIDTH = 250
30 self.WIDTH = 250
31 self.HEIGHT = 250
31 self.HEIGHT = 250
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 dataOut.flagNoData:
111 if dataOut.flagNoData:
112 return dataOut
112 return dataOut
113
113
114 if realtime:
114 if realtime:
115 if not(isRealtime(utcdatatime = dataOut.utctime)):
115 if not(isRealtime(utcdatatime = dataOut.utctime)):
116 print('Skipping this plot function')
116 print('Skipping this plot function')
117 return
117 return
118
118
119 if channelList == None:
119 if channelList == None:
120 channelIndexList = dataOut.channelIndexList
120 channelIndexList = dataOut.channelIndexList
121 else:
121 else:
122 channelIndexList = []
122 channelIndexList = []
123 for channel in channelList:
123 for channel in channelList:
124 if channel not in dataOut.channelList:
124 if channel not in dataOut.channelList:
125 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
125 raise ValueError("Channel %d is not in dataOut.channelList" %channel)
126 channelIndexList.append(dataOut.channelList.index(channel))
126 channelIndexList.append(dataOut.channelList.index(channel))
127
127
128 if normFactor is None:
128 if normFactor is None:
129 factor = dataOut.normFactor
129 factor = dataOut.normFactor
130 else:
130 else:
131 factor = normFactor
131 factor = normFactor
132 if xaxis == "frequency":
132 if xaxis == "frequency":
133 x = dataOut.getFreqRange(1)/1000.
133 x = dataOut.getFreqRange(1)/1000.
134 xlabel = "Frequency (kHz)"
134 xlabel = "Frequency (kHz)"
135
135
136 elif xaxis == "time":
136 elif xaxis == "time":
137 x = dataOut.getAcfRange(1)
137 x = dataOut.getAcfRange(1)
138 xlabel = "Time (ms)"
138 xlabel = "Time (ms)"
139
139
140 else:
140 else:
141 x = dataOut.getVelRange(1)
141 x = dataOut.getVelRange(1)
142 xlabel = "Velocity (m/s)"
142 xlabel = "Velocity (m/s)"
143
143
144 ylabel = "Range (km)"
144 ylabel = "Range (km)"
145
145
146 y = dataOut.getHeiRange()
146 y = dataOut.getHeiRange()
147 z = dataOut.data_spc/factor
147 z = dataOut.data_spc/factor
148 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
148 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
149 zdB = 10*numpy.log10(z)
149 zdB = 10*numpy.log10(z)
150
150
151 avg = numpy.average(z, axis=1)
151 avg = numpy.average(z, axis=1)
152 avgdB = 10*numpy.log10(avg)
152 avgdB = 10*numpy.log10(avg)
153
153
154 noise = dataOut.getNoise()/factor
154 noise = dataOut.getNoise()/factor
155 noisedB = 10*numpy.log10(noise)
155 noisedB = 10*numpy.log10(noise)
156
156
157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
157 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
158 title = wintitle + " Spectra"
158 title = wintitle + " Spectra"
159
159
160 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
160 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
161 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
161 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
162
162
163 if not self.isConfig:
163 if not self.isConfig:
164
164
165 nplots = len(channelIndexList)
165 nplots = len(channelIndexList)
166
166
167 self.setup(id=id,
167 self.setup(id=id,
168 nplots=nplots,
168 nplots=nplots,
169 wintitle=wintitle,
169 wintitle=wintitle,
170 showprofile=showprofile,
170 showprofile=showprofile,
171 show=show)
171 show=show)
172
172
173 if xmin == None: xmin = numpy.nanmin(x)
173 if xmin == None: xmin = numpy.nanmin(x)
174 if xmax == None: xmax = numpy.nanmax(x)
174 if xmax == None: xmax = numpy.nanmax(x)
175 if ymin == None: ymin = numpy.nanmin(y)
175 if ymin == None: ymin = numpy.nanmin(y)
176 if ymax == None: ymax = numpy.nanmax(y)
176 if ymax == None: ymax = numpy.nanmax(y)
177 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
177 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
178 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
178 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
179
179
180 self.FTP_WEI = ftp_wei
180 self.FTP_WEI = ftp_wei
181 self.EXP_CODE = exp_code
181 self.EXP_CODE = exp_code
182 self.SUB_EXP_CODE = sub_exp_code
182 self.SUB_EXP_CODE = sub_exp_code
183 self.PLOT_POS = plot_pos
183 self.PLOT_POS = plot_pos
184
184
185 self.isConfig = True
185 self.isConfig = True
186
186
187 self.setWinTitle(title)
187 self.setWinTitle(title)
188
188
189 for i in range(self.nplots):
189 for i in range(self.nplots):
190 index = channelIndexList[i]
190 index = channelIndexList[i]
191 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
191 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
192 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
192 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
193 if len(dataOut.beam.codeList) != 0:
193 if len(dataOut.beam.codeList) != 0:
194 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)
194 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)
195
195
196 axes = self.axesList[i*self.__nsubplots]
196 axes = self.axesList[i*self.__nsubplots]
197 axes.pcolor(x, y, zdB[index,:,:],
197 axes.pcolor(x, y, zdB[index,:,:],
198 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
198 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
199 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
199 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
200 ticksize=9, cblabel='')
200 ticksize=9, cblabel='')
201
201
202 if self.__showprofile:
202 if self.__showprofile:
203 axes = self.axesList[i*self.__nsubplots +1]
203 axes = self.axesList[i*self.__nsubplots +1]
204 axes.pline(avgdB[index,:], y,
204 axes.pline(avgdB[index,:], y,
205 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
205 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
206 xlabel='dB', ylabel='', title='',
206 xlabel='dB', ylabel='', title='',
207 ytick_visible=False,
207 ytick_visible=False,
208 grid='x')
208 grid='x')
209
209
210 noiseline = numpy.repeat(noisedB[index], len(y))
210 noiseline = numpy.repeat(noisedB[index], len(y))
211 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
211 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
212
212
213 self.draw()
213 self.draw()
214
214
215 if figfile == None:
215 if figfile == None:
216 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
216 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
217 name = str_datetime
217 name = str_datetime
218 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
218 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
219 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
219 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
220 figfile = self.getFilename(name)
220 figfile = self.getFilename(name)
221
221
222 self.save(figpath=figpath,
222 self.save(figpath=figpath,
223 figfile=figfile,
223 figfile=figfile,
224 save=save,
224 save=save,
225 ftp=ftp,
225 ftp=ftp,
226 wr_period=wr_period,
226 wr_period=wr_period,
227 thisDatetime=thisDatetime)
227 thisDatetime=thisDatetime)
228
228
229
229
230 return dataOut
230 return dataOut
231
231 @MPDecorator
232 @MPDecorator
232 class CrossSpectraPlot_(Figure):
233 class CrossSpectraPlot_(Figure):
233
234
234 isConfig = None
235 isConfig = None
235 __nsubplots = None
236 __nsubplots = None
236
237
237 WIDTH = None
238 WIDTH = None
238 HEIGHT = None
239 HEIGHT = None
239 WIDTHPROF = None
240 WIDTHPROF = None
240 HEIGHTPROF = None
241 HEIGHTPROF = None
241 PREFIX = 'cspc'
242 PREFIX = 'cspc'
242
243
243 def __init__(self):
244 def __init__(self):
244 Figure.__init__(self)
245 Figure.__init__(self)
245 self.isConfig = False
246 self.isConfig = False
246 self.__nsubplots = 4
247 self.__nsubplots = 4
247 self.counter_imagwr = 0
248 self.counter_imagwr = 0
248 self.WIDTH = 250
249 self.WIDTH = 250
249 self.HEIGHT = 250
250 self.HEIGHT = 250
250 self.WIDTHPROF = 0
251 self.WIDTHPROF = 0
251 self.HEIGHTPROF = 0
252 self.HEIGHTPROF = 0
252
253
253 self.PLOT_CODE = CROSS_CODE
254 self.PLOT_CODE = CROSS_CODE
254 self.FTP_WEI = None
255 self.FTP_WEI = None
255 self.EXP_CODE = None
256 self.EXP_CODE = None
256 self.SUB_EXP_CODE = None
257 self.SUB_EXP_CODE = None
257 self.PLOT_POS = None
258 self.PLOT_POS = None
258
259
259 self.indice=0
260 self.indice=0
260
261
261 def getSubplots(self):
262 def getSubplots(self):
262
263
263 ncol = 4
264 ncol = 4
264 nrow = self.nplots
265 nrow = self.nplots
265
266
266 return nrow, ncol
267 return nrow, ncol
267
268
268 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
269 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
269
270
270 self.__showprofile = showprofile
271 self.__showprofile = showprofile
271 self.nplots = nplots
272 self.nplots = nplots
272
273
273 ncolspan = 1
274 ncolspan = 1
274 colspan = 1
275 colspan = 1
275
276
276 self.createFigure(id = id,
277 self.createFigure(id = id,
277 wintitle = wintitle,
278 wintitle = wintitle,
278 widthplot = self.WIDTH + self.WIDTHPROF,
279 widthplot = self.WIDTH + self.WIDTHPROF,
279 heightplot = self.HEIGHT + self.HEIGHTPROF,
280 heightplot = self.HEIGHT + self.HEIGHTPROF,
280 show=True)
281 show=True)
281
282
282 nrow, ncol = self.getSubplots()
283 nrow, ncol = self.getSubplots()
283
284
284 counter = 0
285 counter = 0
285 for y in range(nrow):
286 for y in range(nrow):
286 for x in range(ncol):
287 for x in range(ncol):
287 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
288 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
288
289
289 counter += 1
290 counter += 1
290
291
291 def run(self, dataOut, id, wintitle="", pairsList=None,
292 def run(self, dataOut, id, wintitle="", pairsList=None,
292 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
293 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
293 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
294 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
294 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
295 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
295 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
296 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
296 server=None, folder=None, username=None, password=None,
297 server=None, folder=None, username=None, password=None,
297 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
298 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
298 xaxis='frequency'):
299 xaxis='frequency'):
299
300
300 """
301 """
301
302
302 Input:
303 Input:
303 dataOut :
304 dataOut :
304 id :
305 id :
305 wintitle :
306 wintitle :
306 channelList :
307 channelList :
307 showProfile :
308 showProfile :
308 xmin : None,
309 xmin : None,
309 xmax : None,
310 xmax : None,
310 ymin : None,
311 ymin : None,
311 ymax : None,
312 ymax : None,
312 zmin : None,
313 zmin : None,
313 zmax : None
314 zmax : None
314 """
315 """
315
316
316 if dataOut.flagNoData:
317 if dataOut.flagNoData:
317 return dataOut
318 return dataOut
318
319
319 if pairsList == None:
320 if pairsList == None:
320 pairsIndexList = dataOut.pairsIndexList
321 pairsIndexList = dataOut.pairsIndexList
321 else:
322 else:
322 pairsIndexList = []
323 pairsIndexList = []
323 for pair in pairsList:
324 for pair in pairsList:
324 if pair not in dataOut.pairsList:
325 if pair not in dataOut.pairsList:
325 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
326 raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair))
326 pairsIndexList.append(dataOut.pairsList.index(pair))
327 pairsIndexList.append(dataOut.pairsList.index(pair))
327
328
328 if not pairsIndexList:
329 if not pairsIndexList:
329 return
330 return
330
331
331 if len(pairsIndexList) > 4:
332 if len(pairsIndexList) > 4:
332 pairsIndexList = pairsIndexList[0:4]
333 pairsIndexList = pairsIndexList[0:4]
333
334
334 if normFactor is None:
335 if normFactor is None:
335 factor = dataOut.normFactor
336 factor = dataOut.normFactor
336 else:
337 else:
337 factor = normFactor
338 factor = normFactor
338 x = dataOut.getVelRange(1)
339 x = dataOut.getVelRange(1)
339 y = dataOut.getHeiRange()
340 y = dataOut.getHeiRange()
340 z = dataOut.data_spc[:,:,:]/factor
341 z = dataOut.data_spc[:,:,:]/factor
341 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
342 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
342
343
343 noise = dataOut.noise/factor
344 noise = dataOut.noise/factor
344
345
345 zdB = 10*numpy.log10(z)
346 zdB = 10*numpy.log10(z)
346 noisedB = 10*numpy.log10(noise)
347 noisedB = 10*numpy.log10(noise)
347
348
348 if coh_min == None:
349 if coh_min == None:
349 coh_min = 0.0
350 coh_min = 0.0
350 if coh_max == None:
351 if coh_max == None:
351 coh_max = 1.0
352 coh_max = 1.0
352
353
353 if phase_min == None:
354 if phase_min == None:
354 phase_min = -180
355 phase_min = -180
355 if phase_max == None:
356 if phase_max == None:
356 phase_max = 180
357 phase_max = 180
357
358
358 #thisDatetime = dataOut.datatime
359 #thisDatetime = dataOut.datatime
359 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
360 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
360 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
361 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
361 # xlabel = "Velocity (m/s)"
362 # xlabel = "Velocity (m/s)"
362 ylabel = "Range (Km)"
363 ylabel = "Range (Km)"
363
364
364 if xaxis == "frequency":
365 if xaxis == "frequency":
365 x = dataOut.getFreqRange(1)/1000.
366 x = dataOut.getFreqRange(1)/1000.
366 xlabel = "Frequency (kHz)"
367 xlabel = "Frequency (kHz)"
367
368
368 elif xaxis == "time":
369 elif xaxis == "time":
369 x = dataOut.getAcfRange(1)
370 x = dataOut.getAcfRange(1)
370 xlabel = "Time (ms)"
371 xlabel = "Time (ms)"
371
372
372 else:
373 else:
373 x = dataOut.getVelRange(1)
374 x = dataOut.getVelRange(1)
374 xlabel = "Velocity (m/s)"
375 xlabel = "Velocity (m/s)"
375
376
376 if not self.isConfig:
377 if not self.isConfig:
377
378
378 nplots = len(pairsIndexList)
379 nplots = len(pairsIndexList)
379
380
380 self.setup(id=id,
381 self.setup(id=id,
381 nplots=nplots,
382 nplots=nplots,
382 wintitle=wintitle,
383 wintitle=wintitle,
383 showprofile=False,
384 showprofile=False,
384 show=show)
385 show=show)
385
386
386 avg = numpy.abs(numpy.average(z, axis=1))
387 avg = numpy.abs(numpy.average(z, axis=1))
387 avgdB = 10*numpy.log10(avg)
388 avgdB = 10*numpy.log10(avg)
388
389
389 if xmin == None: xmin = numpy.nanmin(x)
390 if xmin == None: xmin = numpy.nanmin(x)
390 if xmax == None: xmax = numpy.nanmax(x)
391 if xmax == None: xmax = numpy.nanmax(x)
391 if ymin == None: ymin = numpy.nanmin(y)
392 if ymin == None: ymin = numpy.nanmin(y)
392 if ymax == None: ymax = numpy.nanmax(y)
393 if ymax == None: ymax = numpy.nanmax(y)
393 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
394 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
394 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
395 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
395
396
396 self.FTP_WEI = ftp_wei
397 self.FTP_WEI = ftp_wei
397 self.EXP_CODE = exp_code
398 self.EXP_CODE = exp_code
398 self.SUB_EXP_CODE = sub_exp_code
399 self.SUB_EXP_CODE = sub_exp_code
399 self.PLOT_POS = plot_pos
400 self.PLOT_POS = plot_pos
400
401
401 self.isConfig = True
402 self.isConfig = True
402
403
403 self.setWinTitle(title)
404 self.setWinTitle(title)
404
405
405
406
406 for i in range(self.nplots):
407 for i in range(self.nplots):
407 pair = dataOut.pairsList[pairsIndexList[i]]
408 pair = dataOut.pairsList[pairsIndexList[i]]
408
409
409 chan_index0 = dataOut.channelList.index(pair[0])
410 chan_index0 = dataOut.channelList.index(pair[0])
410 chan_index1 = dataOut.channelList.index(pair[1])
411 chan_index1 = dataOut.channelList.index(pair[1])
411
412
412 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
413 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
413 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
414 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
414 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
415 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
415 axes0 = self.axesList[i*self.__nsubplots]
416 axes0 = self.axesList[i*self.__nsubplots]
416 axes0.pcolor(x, y, zdB,
417 axes0.pcolor(x, y, zdB,
417 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
418 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
418 xlabel=xlabel, ylabel=ylabel, title=title,
419 xlabel=xlabel, ylabel=ylabel, title=title,
419 ticksize=9, colormap=power_cmap, cblabel='')
420 ticksize=9, colormap=power_cmap, cblabel='')
420
421
421 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
422 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
422 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
423 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
423 axes0 = self.axesList[i*self.__nsubplots+1]
424 axes0 = self.axesList[i*self.__nsubplots+1]
424 axes0.pcolor(x, y, zdB,
425 axes0.pcolor(x, y, zdB,
425 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
426 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
426 xlabel=xlabel, ylabel=ylabel, title=title,
427 xlabel=xlabel, ylabel=ylabel, title=title,
427 ticksize=9, colormap=power_cmap, cblabel='')
428 ticksize=9, colormap=power_cmap, cblabel='')
428
429
429 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
430 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
430 coherence = numpy.abs(coherenceComplex)
431 coherence = numpy.abs(coherenceComplex)
431 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
432 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
432 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
433 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
433
434
434 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
435 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
435 axes0 = self.axesList[i*self.__nsubplots+2]
436 axes0 = self.axesList[i*self.__nsubplots+2]
436 axes0.pcolor(x, y, coherence,
437 axes0.pcolor(x, y, coherence,
437 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
438 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
438 xlabel=xlabel, ylabel=ylabel, title=title,
439 xlabel=xlabel, ylabel=ylabel, title=title,
439 ticksize=9, colormap=coherence_cmap, cblabel='')
440 ticksize=9, colormap=coherence_cmap, cblabel='')
440
441
441 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
442 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
442 axes0 = self.axesList[i*self.__nsubplots+3]
443 axes0 = self.axesList[i*self.__nsubplots+3]
443 axes0.pcolor(x, y, phase,
444 axes0.pcolor(x, y, phase,
444 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
445 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
445 xlabel=xlabel, ylabel=ylabel, title=title,
446 xlabel=xlabel, ylabel=ylabel, title=title,
446 ticksize=9, colormap=phase_cmap, cblabel='')
447 ticksize=9, colormap=phase_cmap, cblabel='')
447
448
448 self.draw()
449 self.draw()
449
450
450 self.save(figpath=figpath,
451 self.save(figpath=figpath,
451 figfile=figfile,
452 figfile=figfile,
452 save=save,
453 save=save,
453 ftp=ftp,
454 ftp=ftp,
454 wr_period=wr_period,
455 wr_period=wr_period,
455 thisDatetime=thisDatetime)
456 thisDatetime=thisDatetime)
456
457
457 return dataOut
458 return dataOut
458
459
459 @MPDecorator
460 @MPDecorator
460 class RTIPlot_(Figure):
461 class RTIPlot_(Figure):
461
462
462 __isConfig = None
463 __isConfig = None
463 __nsubplots = None
464 __nsubplots = None
464
465
465 WIDTHPROF = None
466 WIDTHPROF = None
466 HEIGHTPROF = None
467 HEIGHTPROF = None
467 PREFIX = 'rti'
468 PREFIX = 'rti'
468
469
469 def __init__(self):
470 def __init__(self):
470
471
471 Figure.__init__(self)
472 Figure.__init__(self)
472 self.timerange = None
473 self.timerange = None
473 self.isConfig = False
474 self.isConfig = False
474 self.__nsubplots = 1
475 self.__nsubplots = 1
475
476
476 self.WIDTH = 800
477 self.WIDTH = 800
477 self.HEIGHT = 250
478 self.HEIGHT = 250
478 self.WIDTHPROF = 120
479 self.WIDTHPROF = 120
479 self.HEIGHTPROF = 0
480 self.HEIGHTPROF = 0
480 self.counter_imagwr = 0
481 self.counter_imagwr = 0
481
482
482 self.PLOT_CODE = RTI_CODE
483 self.PLOT_CODE = RTI_CODE
483
484
484 self.FTP_WEI = None
485 self.FTP_WEI = None
485 self.EXP_CODE = None
486 self.EXP_CODE = None
486 self.SUB_EXP_CODE = None
487 self.SUB_EXP_CODE = None
487 self.PLOT_POS = None
488 self.PLOT_POS = None
488 self.tmin = None
489 self.tmin = None
489 self.tmax = None
490 self.tmax = None
490
491
491 self.xmin = None
492 self.xmin = None
492 self.xmax = None
493 self.xmax = None
493
494
494 self.figfile = None
495 self.figfile = None
495
496
496 def getSubplots(self):
497 def getSubplots(self):
497
498
498 ncol = 1
499 ncol = 1
499 nrow = self.nplots
500 nrow = self.nplots
500
501
501 return nrow, ncol
502 return nrow, ncol
502
503
503 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
504 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
504
505
505 self.__showprofile = showprofile
506 self.__showprofile = showprofile
506 self.nplots = nplots
507 self.nplots = nplots
507
508
508 ncolspan = 1
509 ncolspan = 1
509 colspan = 1
510 colspan = 1
510 if showprofile:
511 if showprofile:
511 ncolspan = 7
512 ncolspan = 7
512 colspan = 6
513 colspan = 6
513 self.__nsubplots = 2
514 self.__nsubplots = 2
514
515
515 self.createFigure(id = id,
516 self.createFigure(id = id,
516 wintitle = wintitle,
517 wintitle = wintitle,
517 widthplot = self.WIDTH + self.WIDTHPROF,
518 widthplot = self.WIDTH + self.WIDTHPROF,
518 heightplot = self.HEIGHT + self.HEIGHTPROF,
519 heightplot = self.HEIGHT + self.HEIGHTPROF,
519 show=show)
520 show=show)
520
521
521 nrow, ncol = self.getSubplots()
522 nrow, ncol = self.getSubplots()
522
523
523 counter = 0
524 counter = 0
524 for y in range(nrow):
525 for y in range(nrow):
525 for x in range(ncol):
526 for x in range(ncol):
526
527
527 if counter >= self.nplots:
528 if counter >= self.nplots:
528 break
529 break
529
530
530 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
531 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
531
532
532 if showprofile:
533 if showprofile:
533 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
534 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
534
535
535 counter += 1
536 counter += 1
536
537
537 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
538 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
538 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
539 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
539 timerange=None, colormap='jet',
540 timerange=None, colormap='jet',
540 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
541 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
541 server=None, folder=None, username=None, password=None,
542 server=None, folder=None, username=None, password=None,
542 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
543 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
543
544
544 """
545 """
545
546
546 Input:
547 Input:
547 dataOut :
548 dataOut :
548 id :
549 id :
549 wintitle :
550 wintitle :
550 channelList :
551 channelList :
551 showProfile :
552 showProfile :
552 xmin : None,
553 xmin : None,
553 xmax : None,
554 xmax : None,
554 ymin : None,
555 ymin : None,
555 ymax : None,
556 ymax : None,
556 zmin : None,
557 zmin : None,
557 zmax : None
558 zmax : None
558 """
559 """
559 if dataOut.flagNoData:
560 if dataOut.flagNoData:
560 return dataOut
561 return dataOut
561
562
562 #colormap = kwargs.get('colormap', 'jet')
563 #colormap = kwargs.get('colormap', 'jet')
563 if HEIGHT is not None:
564 if HEIGHT is not None:
564 self.HEIGHT = HEIGHT
565 self.HEIGHT = HEIGHT
565
566
566 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
567 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
567 return
568 return
568
569
569 if channelList == None:
570 if channelList == None:
570 channelIndexList = dataOut.channelIndexList
571 channelIndexList = dataOut.channelIndexList
571 else:
572 else:
572 channelIndexList = []
573 channelIndexList = []
573 for channel in channelList:
574 for channel in channelList:
574 if channel not in dataOut.channelList:
575 if channel not in dataOut.channelList:
575 raise ValueError("Channel %d is not in dataOut.channelList")
576 raise ValueError("Channel %d is not in dataOut.channelList")
576 channelIndexList.append(dataOut.channelList.index(channel))
577 channelIndexList.append(dataOut.channelList.index(channel))
577
578
578 if normFactor is None:
579 if normFactor is None:
579 factor = dataOut.normFactor
580 factor = dataOut.normFactor
580 else:
581 else:
581 factor = normFactor
582 factor = normFactor
582
583
583 #factor = dataOut.normFactor
584 #factor = dataOut.normFactor
584 x = dataOut.getTimeRange()
585 x = dataOut.getTimeRange()
585 y = dataOut.getHeiRange()
586 y = dataOut.getHeiRange()
586
587
587 z = dataOut.data_spc/factor
588 z = dataOut.data_spc/factor
588 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
589 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
589 avg = numpy.average(z, axis=1)
590 avg = numpy.average(z, axis=1)
590 avgdB = 10.*numpy.log10(avg)
591 avgdB = 10.*numpy.log10(avg)
591 # avgdB = dataOut.getPower()
592 # avgdB = dataOut.getPower()
592
593
593
594
594 thisDatetime = dataOut.datatime
595 thisDatetime = dataOut.datatime
595 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
596 #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
596 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
597 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
597 xlabel = ""
598 xlabel = ""
598 ylabel = "Range (Km)"
599 ylabel = "Range (Km)"
599
600
600 update_figfile = False
601 update_figfile = False
601
602
602 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
603 if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong
603 self.counter_imagwr = wr_period
604 self.counter_imagwr = wr_period
604 self.isConfig = False
605 self.isConfig = False
605 update_figfile = True
606 update_figfile = True
606
607
607 if not self.isConfig:
608 if not self.isConfig:
608
609
609 nplots = len(channelIndexList)
610 nplots = len(channelIndexList)
610
611
611 self.setup(id=id,
612 self.setup(id=id,
612 nplots=nplots,
613 nplots=nplots,
613 wintitle=wintitle,
614 wintitle=wintitle,
614 showprofile=showprofile,
615 showprofile=showprofile,
615 show=show)
616 show=show)
616
617
617 if timerange != None:
618 if timerange != None:
618 self.timerange = timerange
619 self.timerange = timerange
619
620
620 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
621 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
621
622
622 noise = dataOut.noise/factor
623 noise = dataOut.noise/factor
623 noisedB = 10*numpy.log10(noise)
624 noisedB = 10*numpy.log10(noise)
624
625
625 if ymin == None: ymin = numpy.nanmin(y)
626 if ymin == None: ymin = numpy.nanmin(y)
626 if ymax == None: ymax = numpy.nanmax(y)
627 if ymax == None: ymax = numpy.nanmax(y)
627 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
628 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
628 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
629 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
629
630
630 self.FTP_WEI = ftp_wei
631 self.FTP_WEI = ftp_wei
631 self.EXP_CODE = exp_code
632 self.EXP_CODE = exp_code
632 self.SUB_EXP_CODE = sub_exp_code
633 self.SUB_EXP_CODE = sub_exp_code
633 self.PLOT_POS = plot_pos
634 self.PLOT_POS = plot_pos
634
635
635 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
636 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
636 self.isConfig = True
637 self.isConfig = True
637 self.figfile = figfile
638 self.figfile = figfile
638 update_figfile = True
639 update_figfile = True
639
640
640 self.setWinTitle(title)
641 self.setWinTitle(title)
641
642
642 for i in range(self.nplots):
643 for i in range(self.nplots):
643 index = channelIndexList[i]
644 index = channelIndexList[i]
644 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
645 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
645 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
646 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
646 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
647 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
647 axes = self.axesList[i*self.__nsubplots]
648 axes = self.axesList[i*self.__nsubplots]
648 zdB = avgdB[index].reshape((1,-1))
649 zdB = avgdB[index].reshape((1,-1))
649 axes.pcolorbuffer(x, y, zdB,
650 axes.pcolorbuffer(x, y, zdB,
650 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
651 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
651 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
652 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
652 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
653 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
653
654
654 if self.__showprofile:
655 if self.__showprofile:
655 axes = self.axesList[i*self.__nsubplots +1]
656 axes = self.axesList[i*self.__nsubplots +1]
656 axes.pline(avgdB[index], y,
657 axes.pline(avgdB[index], y,
657 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
658 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
658 xlabel='dB', ylabel='', title='',
659 xlabel='dB', ylabel='', title='',
659 ytick_visible=False,
660 ytick_visible=False,
660 grid='x')
661 grid='x')
661
662
662 self.draw()
663 self.draw()
663
664
664 self.save(figpath=figpath,
665 self.save(figpath=figpath,
665 figfile=figfile,
666 figfile=figfile,
666 save=save,
667 save=save,
667 ftp=ftp,
668 ftp=ftp,
668 wr_period=wr_period,
669 wr_period=wr_period,
669 thisDatetime=thisDatetime,
670 thisDatetime=thisDatetime,
670 update_figfile=update_figfile)
671 update_figfile=update_figfile)
671 return dataOut
672 return dataOut
672
673
673 @MPDecorator
674 @MPDecorator
674 class CoherenceMap_(Figure):
675 class CoherenceMap_(Figure):
675 isConfig = None
676 isConfig = None
676 __nsubplots = None
677 __nsubplots = None
677
678
678 WIDTHPROF = None
679 WIDTHPROF = None
679 HEIGHTPROF = None
680 HEIGHTPROF = None
680 PREFIX = 'cmap'
681 PREFIX = 'cmap'
681
682
682 def __init__(self):
683 def __init__(self):
683 Figure.__init__(self)
684 Figure.__init__(self)
684 self.timerange = 2*60*60
685 self.timerange = 2*60*60
685 self.isConfig = False
686 self.isConfig = False
686 self.__nsubplots = 1
687 self.__nsubplots = 1
687
688
688 self.WIDTH = 800
689 self.WIDTH = 800
689 self.HEIGHT = 180
690 self.HEIGHT = 180
690 self.WIDTHPROF = 120
691 self.WIDTHPROF = 120
691 self.HEIGHTPROF = 0
692 self.HEIGHTPROF = 0
692 self.counter_imagwr = 0
693 self.counter_imagwr = 0
693
694
694 self.PLOT_CODE = COH_CODE
695 self.PLOT_CODE = COH_CODE
695
696
696 self.FTP_WEI = None
697 self.FTP_WEI = None
697 self.EXP_CODE = None
698 self.EXP_CODE = None
698 self.SUB_EXP_CODE = None
699 self.SUB_EXP_CODE = None
699 self.PLOT_POS = None
700 self.PLOT_POS = None
700 self.counter_imagwr = 0
701 self.counter_imagwr = 0
701
702
702 self.xmin = None
703 self.xmin = None
703 self.xmax = None
704 self.xmax = None
704
705
705 def getSubplots(self):
706 def getSubplots(self):
706 ncol = 1
707 ncol = 1
707 nrow = self.nplots*2
708 nrow = self.nplots*2
708
709
709 return nrow, ncol
710 return nrow, ncol
710
711
711 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
712 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
712 self.__showprofile = showprofile
713 self.__showprofile = showprofile
713 self.nplots = nplots
714 self.nplots = nplots
714
715
715 ncolspan = 1
716 ncolspan = 1
716 colspan = 1
717 colspan = 1
717 if showprofile:
718 if showprofile:
718 ncolspan = 7
719 ncolspan = 7
719 colspan = 6
720 colspan = 6
720 self.__nsubplots = 2
721 self.__nsubplots = 2
721
722
722 self.createFigure(id = id,
723 self.createFigure(id = id,
723 wintitle = wintitle,
724 wintitle = wintitle,
724 widthplot = self.WIDTH + self.WIDTHPROF,
725 widthplot = self.WIDTH + self.WIDTHPROF,
725 heightplot = self.HEIGHT + self.HEIGHTPROF,
726 heightplot = self.HEIGHT + self.HEIGHTPROF,
726 show=True)
727 show=True)
727
728
728 nrow, ncol = self.getSubplots()
729 nrow, ncol = self.getSubplots()
729
730
730 for y in range(nrow):
731 for y in range(nrow):
731 for x in range(ncol):
732 for x in range(ncol):
732
733
733 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
734 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
734
735
735 if showprofile:
736 if showprofile:
736 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
737 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
737
738
738 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
739 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
739 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
740 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
740 timerange=None, phase_min=None, phase_max=None,
741 timerange=None, phase_min=None, phase_max=None,
741 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
742 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
742 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
743 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
743 server=None, folder=None, username=None, password=None,
744 server=None, folder=None, username=None, password=None,
744 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
745 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
745
746
746
747
747 if dataOut.flagNoData:
748 if dataOut.flagNoData:
748 return dataOut
749 return dataOut
749
750
750 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
751 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
751 return
752 return
752
753
753 if pairsList == None:
754 if pairsList == None:
754 pairsIndexList = dataOut.pairsIndexList
755 pairsIndexList = dataOut.pairsIndexList
755 else:
756 else:
756 pairsIndexList = []
757 pairsIndexList = []
757 for pair in pairsList:
758 for pair in pairsList:
758 if pair not in dataOut.pairsList:
759 if pair not in dataOut.pairsList:
759 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
760 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
760 pairsIndexList.append(dataOut.pairsList.index(pair))
761 pairsIndexList.append(dataOut.pairsList.index(pair))
761
762
762 if pairsIndexList == []:
763 if pairsIndexList == []:
763 return
764 return
764
765
765 if len(pairsIndexList) > 4:
766 if len(pairsIndexList) > 4:
766 pairsIndexList = pairsIndexList[0:4]
767 pairsIndexList = pairsIndexList[0:4]
767
768
768 if phase_min == None:
769 if phase_min == None:
769 phase_min = -180
770 phase_min = -180
770 if phase_max == None:
771 if phase_max == None:
771 phase_max = 180
772 phase_max = 180
772
773
773 x = dataOut.getTimeRange()
774 x = dataOut.getTimeRange()
774 y = dataOut.getHeiRange()
775 y = dataOut.getHeiRange()
775
776
776 thisDatetime = dataOut.datatime
777 thisDatetime = dataOut.datatime
777
778
778 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
779 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
779 xlabel = ""
780 xlabel = ""
780 ylabel = "Range (Km)"
781 ylabel = "Range (Km)"
781 update_figfile = False
782 update_figfile = False
782
783
783 if not self.isConfig:
784 if not self.isConfig:
784 nplots = len(pairsIndexList)
785 nplots = len(pairsIndexList)
785 self.setup(id=id,
786 self.setup(id=id,
786 nplots=nplots,
787 nplots=nplots,
787 wintitle=wintitle,
788 wintitle=wintitle,
788 showprofile=showprofile,
789 showprofile=showprofile,
789 show=show)
790 show=show)
790
791
791 if timerange != None:
792 if timerange != None:
792 self.timerange = timerange
793 self.timerange = timerange
793
794
794 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
795 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
795
796
796 if ymin == None: ymin = numpy.nanmin(y)
797 if ymin == None: ymin = numpy.nanmin(y)
797 if ymax == None: ymax = numpy.nanmax(y)
798 if ymax == None: ymax = numpy.nanmax(y)
798 if zmin == None: zmin = 0.
799 if zmin == None: zmin = 0.
799 if zmax == None: zmax = 1.
800 if zmax == None: zmax = 1.
800
801
801 self.FTP_WEI = ftp_wei
802 self.FTP_WEI = ftp_wei
802 self.EXP_CODE = exp_code
803 self.EXP_CODE = exp_code
803 self.SUB_EXP_CODE = sub_exp_code
804 self.SUB_EXP_CODE = sub_exp_code
804 self.PLOT_POS = plot_pos
805 self.PLOT_POS = plot_pos
805
806
806 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
807 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
807
808
808 self.isConfig = True
809 self.isConfig = True
809 update_figfile = True
810 update_figfile = True
810
811
811 self.setWinTitle(title)
812 self.setWinTitle(title)
812
813
813 for i in range(self.nplots):
814 for i in range(self.nplots):
814
815
815 pair = dataOut.pairsList[pairsIndexList[i]]
816 pair = dataOut.pairsList[pairsIndexList[i]]
816
817
817 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
818 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
818 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
819 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
819 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
820 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
820
821
821
822
822 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
823 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
823 coherence = numpy.abs(avgcoherenceComplex)
824 coherence = numpy.abs(avgcoherenceComplex)
824
825
825 z = coherence.reshape((1,-1))
826 z = coherence.reshape((1,-1))
826
827
827 counter = 0
828 counter = 0
828
829
829 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
830 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
830 axes = self.axesList[i*self.__nsubplots*2]
831 axes = self.axesList[i*self.__nsubplots*2]
831 axes.pcolorbuffer(x, y, z,
832 axes.pcolorbuffer(x, y, z,
832 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
833 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
833 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
834 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
834 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
835 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
835
836
836 if self.__showprofile:
837 if self.__showprofile:
837 counter += 1
838 counter += 1
838 axes = self.axesList[i*self.__nsubplots*2 + counter]
839 axes = self.axesList[i*self.__nsubplots*2 + counter]
839 axes.pline(coherence, y,
840 axes.pline(coherence, y,
840 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
841 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
841 xlabel='', ylabel='', title='', ticksize=7,
842 xlabel='', ylabel='', title='', ticksize=7,
842 ytick_visible=False, nxticks=5,
843 ytick_visible=False, nxticks=5,
843 grid='x')
844 grid='x')
844
845
845 counter += 1
846 counter += 1
846
847
847 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
848 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
848
849
849 z = phase.reshape((1,-1))
850 z = phase.reshape((1,-1))
850
851
851 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
852 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
852 axes = self.axesList[i*self.__nsubplots*2 + counter]
853 axes = self.axesList[i*self.__nsubplots*2 + counter]
853 axes.pcolorbuffer(x, y, z,
854 axes.pcolorbuffer(x, y, z,
854 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
855 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
855 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
856 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
856 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
857 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
857
858
858 if self.__showprofile:
859 if self.__showprofile:
859 counter += 1
860 counter += 1
860 axes = self.axesList[i*self.__nsubplots*2 + counter]
861 axes = self.axesList[i*self.__nsubplots*2 + counter]
861 axes.pline(phase, y,
862 axes.pline(phase, y,
862 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
863 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
863 xlabel='', ylabel='', title='', ticksize=7,
864 xlabel='', ylabel='', title='', ticksize=7,
864 ytick_visible=False, nxticks=4,
865 ytick_visible=False, nxticks=4,
865 grid='x')
866 grid='x')
866
867
867 self.draw()
868 self.draw()
868
869
869 if dataOut.ltctime >= self.xmax:
870 if dataOut.ltctime >= self.xmax:
870 self.counter_imagwr = wr_period
871 self.counter_imagwr = wr_period
871 self.isConfig = False
872 self.isConfig = False
872 update_figfile = True
873 update_figfile = True
873
874
874 self.save(figpath=figpath,
875 self.save(figpath=figpath,
875 figfile=figfile,
876 figfile=figfile,
876 save=save,
877 save=save,
877 ftp=ftp,
878 ftp=ftp,
878 wr_period=wr_period,
879 wr_period=wr_period,
879 thisDatetime=thisDatetime,
880 thisDatetime=thisDatetime,
880 update_figfile=update_figfile)
881 update_figfile=update_figfile)
881
882
882 return dataOut
883 return dataOut
883
884
884 @MPDecorator
885 @MPDecorator
885 class PowerProfilePlot_(Figure):
886 class PowerProfilePlot_(Figure):
886
887
887 isConfig = None
888 isConfig = None
888 __nsubplots = None
889 __nsubplots = None
889
890
890 WIDTHPROF = None
891 WIDTHPROF = None
891 HEIGHTPROF = None
892 HEIGHTPROF = None
892 PREFIX = 'spcprofile'
893 PREFIX = 'spcprofile'
893
894
894 def __init__(self):
895 def __init__(self):
895 Figure.__init__(self)
896 Figure.__init__(self)
896 self.isConfig = False
897 self.isConfig = False
897 self.__nsubplots = 1
898 self.__nsubplots = 1
898
899
899 self.PLOT_CODE = POWER_CODE
900 self.PLOT_CODE = POWER_CODE
900
901
901 self.WIDTH = 300
902 self.WIDTH = 300
902 self.HEIGHT = 500
903 self.HEIGHT = 500
903 self.counter_imagwr = 0
904 self.counter_imagwr = 0
904
905
905 def getSubplots(self):
906 def getSubplots(self):
906 ncol = 1
907 ncol = 1
907 nrow = 1
908 nrow = 1
908
909
909 return nrow, ncol
910 return nrow, ncol
910
911
911 def setup(self, id, nplots, wintitle, show):
912 def setup(self, id, nplots, wintitle, show):
912
913
913 self.nplots = nplots
914 self.nplots = nplots
914
915
915 ncolspan = 1
916 ncolspan = 1
916 colspan = 1
917 colspan = 1
917
918
918 self.createFigure(id = id,
919 self.createFigure(id = id,
919 wintitle = wintitle,
920 wintitle = wintitle,
920 widthplot = self.WIDTH,
921 widthplot = self.WIDTH,
921 heightplot = self.HEIGHT,
922 heightplot = self.HEIGHT,
922 show=show)
923 show=show)
923
924
924 nrow, ncol = self.getSubplots()
925 nrow, ncol = self.getSubplots()
925
926
926 counter = 0
927 counter = 0
927 for y in range(nrow):
928 for y in range(nrow):
928 for x in range(ncol):
929 for x in range(ncol):
929 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
930 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
930
931
931 def run(self, dataOut, id, wintitle="", channelList=None,
932 def run(self, dataOut, id, wintitle="", channelList=None,
932 xmin=None, xmax=None, ymin=None, ymax=None,
933 xmin=None, xmax=None, ymin=None, ymax=None,
933 save=False, figpath='./', figfile=None, show=True,
934 save=False, figpath='./', figfile=None, show=True,
934 ftp=False, wr_period=1, server=None,
935 ftp=False, wr_period=1, server=None,
935 folder=None, username=None, password=None):
936 folder=None, username=None, password=None):
936
937
937 if dataOut.flagNoData:
938 if dataOut.flagNoData:
938 return dataOut
939 return dataOut
939
940
940
941
941 if channelList == None:
942 if channelList == None:
942 channelIndexList = dataOut.channelIndexList
943 channelIndexList = dataOut.channelIndexList
943 channelList = dataOut.channelList
944 channelList = dataOut.channelList
944 else:
945 else:
945 channelIndexList = []
946 channelIndexList = []
946 for channel in channelList:
947 for channel in channelList:
947 if channel not in dataOut.channelList:
948 if channel not in dataOut.channelList:
948 raise ValueError("Channel %d is not in dataOut.channelList")
949 raise ValueError("Channel %d is not in dataOut.channelList")
949 channelIndexList.append(dataOut.channelList.index(channel))
950 channelIndexList.append(dataOut.channelList.index(channel))
950
951
951 factor = dataOut.normFactor
952 factor = dataOut.normFactor
952
953
953 y = dataOut.getHeiRange()
954 y = dataOut.getHeiRange()
954
955
955 #for voltage
956 #for voltage
956 if dataOut.type == 'Voltage':
957 if dataOut.type == 'Voltage':
957 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
958 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
958 x = x.real
959 x = x.real
959 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
960 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
960
961
961 #for spectra
962 #for spectra
962 if dataOut.type == 'Spectra':
963 if dataOut.type == 'Spectra':
963 x = dataOut.data_spc[channelIndexList,:,:]/factor
964 x = dataOut.data_spc[channelIndexList,:,:]/factor
964 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
965 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
965 x = numpy.average(x, axis=1)
966 x = numpy.average(x, axis=1)
966
967
967
968
968 xdB = 10*numpy.log10(x)
969 xdB = 10*numpy.log10(x)
969
970
970 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
971 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
971 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
972 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
972 xlabel = "dB"
973 xlabel = "dB"
973 ylabel = "Range (Km)"
974 ylabel = "Range (Km)"
974
975
975 if not self.isConfig:
976 if not self.isConfig:
976
977
977 nplots = 1
978 nplots = 1
978
979
979 self.setup(id=id,
980 self.setup(id=id,
980 nplots=nplots,
981 nplots=nplots,
981 wintitle=wintitle,
982 wintitle=wintitle,
982 show=show)
983 show=show)
983
984
984 if ymin == None: ymin = numpy.nanmin(y)
985 if ymin == None: ymin = numpy.nanmin(y)
985 if ymax == None: ymax = numpy.nanmax(y)
986 if ymax == None: ymax = numpy.nanmax(y)
986 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
987 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
987 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
988 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
988
989
989 self.isConfig = True
990 self.isConfig = True
990
991
991 self.setWinTitle(title)
992 self.setWinTitle(title)
992
993
993 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
994 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
994 axes = self.axesList[0]
995 axes = self.axesList[0]
995
996
996 legendlabels = ["channel %d"%x for x in channelList]
997 legendlabels = ["channel %d"%x for x in channelList]
997 axes.pmultiline(xdB, y,
998 axes.pmultiline(xdB, y,
998 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
999 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
999 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1000 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1000 ytick_visible=True, nxticks=5,
1001 ytick_visible=True, nxticks=5,
1001 grid='x')
1002 grid='x')
1002
1003
1003 self.draw()
1004 self.draw()
1004
1005
1005 self.save(figpath=figpath,
1006 self.save(figpath=figpath,
1006 figfile=figfile,
1007 figfile=figfile,
1007 save=save,
1008 save=save,
1008 ftp=ftp,
1009 ftp=ftp,
1009 wr_period=wr_period,
1010 wr_period=wr_period,
1010 thisDatetime=thisDatetime)
1011 thisDatetime=thisDatetime)
1011
1012
1012 return dataOut
1013 return dataOut
1013
1014
1014 @MPDecorator
1015 @MPDecorator
1015 class SpectraCutPlot_(Figure):
1016 class SpectraCutPlot_(Figure):
1016
1017
1017 isConfig = None
1018 isConfig = None
1018 __nsubplots = None
1019 __nsubplots = None
1019
1020
1020 WIDTHPROF = None
1021 WIDTHPROF = None
1021 HEIGHTPROF = None
1022 HEIGHTPROF = None
1022 PREFIX = 'spc_cut'
1023 PREFIX = 'spc_cut'
1023
1024
1024 def __init__(self):
1025 def __init__(self):
1025 Figure.__init__(self)
1026 Figure.__init__(self)
1026 self.isConfig = False
1027 self.isConfig = False
1027 self.__nsubplots = 1
1028 self.__nsubplots = 1
1028
1029
1029 self.PLOT_CODE = POWER_CODE
1030 self.PLOT_CODE = POWER_CODE
1030
1031
1031 self.WIDTH = 700
1032 self.WIDTH = 700
1032 self.HEIGHT = 500
1033 self.HEIGHT = 500
1033 self.counter_imagwr = 0
1034 self.counter_imagwr = 0
1034
1035
1035 def getSubplots(self):
1036 def getSubplots(self):
1036 ncol = 1
1037 ncol = 1
1037 nrow = 1
1038 nrow = 1
1038
1039
1039 return nrow, ncol
1040 return nrow, ncol
1040
1041
1041 def setup(self, id, nplots, wintitle, show):
1042 def setup(self, id, nplots, wintitle, show):
1042
1043
1043 self.nplots = nplots
1044 self.nplots = nplots
1044
1045
1045 ncolspan = 1
1046 ncolspan = 1
1046 colspan = 1
1047 colspan = 1
1047
1048
1048 self.createFigure(id = id,
1049 self.createFigure(id = id,
1049 wintitle = wintitle,
1050 wintitle = wintitle,
1050 widthplot = self.WIDTH,
1051 widthplot = self.WIDTH,
1051 heightplot = self.HEIGHT,
1052 heightplot = self.HEIGHT,
1052 show=show)
1053 show=show)
1053
1054
1054 nrow, ncol = self.getSubplots()
1055 nrow, ncol = self.getSubplots()
1055
1056
1056 counter = 0
1057 counter = 0
1057 for y in range(nrow):
1058 for y in range(nrow):
1058 for x in range(ncol):
1059 for x in range(ncol):
1059 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1060 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1060
1061
1061 def run(self, dataOut, id, wintitle="", channelList=None,
1062 def run(self, dataOut, id, wintitle="", channelList=None,
1062 xmin=None, xmax=None, ymin=None, ymax=None,
1063 xmin=None, xmax=None, ymin=None, ymax=None,
1063 save=False, figpath='./', figfile=None, show=True,
1064 save=False, figpath='./', figfile=None, show=True,
1064 ftp=False, wr_period=1, server=None,
1065 ftp=False, wr_period=1, server=None,
1065 folder=None, username=None, password=None,
1066 folder=None, username=None, password=None,
1066 xaxis="frequency"):
1067 xaxis="frequency"):
1067
1068
1068 if dataOut.flagNoData:
1069 if dataOut.flagNoData:
1069 return dataOut
1070 return dataOut
1070
1071
1071 if channelList == None:
1072 if channelList == None:
1072 channelIndexList = dataOut.channelIndexList
1073 channelIndexList = dataOut.channelIndexList
1073 channelList = dataOut.channelList
1074 channelList = dataOut.channelList
1074 else:
1075 else:
1075 channelIndexList = []
1076 channelIndexList = []
1076 for channel in channelList:
1077 for channel in channelList:
1077 if channel not in dataOut.channelList:
1078 if channel not in dataOut.channelList:
1078 raise ValueError("Channel %d is not in dataOut.channelList")
1079 raise ValueError("Channel %d is not in dataOut.channelList")
1079 channelIndexList.append(dataOut.channelList.index(channel))
1080 channelIndexList.append(dataOut.channelList.index(channel))
1080
1081
1081 factor = dataOut.normFactor
1082 factor = dataOut.normFactor
1082
1083
1083 y = dataOut.getHeiRange()
1084 y = dataOut.getHeiRange()
1084
1085
1085 z = dataOut.data_spc/factor
1086 z = dataOut.data_spc/factor
1086 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1087 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1087
1088
1088 hei_index = numpy.arange(25)*3 + 20
1089 hei_index = numpy.arange(25)*3 + 20
1089
1090
1090 if xaxis == "frequency":
1091 if xaxis == "frequency":
1091 x = dataOut.getFreqRange()/1000.
1092 x = dataOut.getFreqRange()/1000.
1092 zdB = 10*numpy.log10(z[0,:,hei_index])
1093 zdB = 10*numpy.log10(z[0,:,hei_index])
1093 xlabel = "Frequency (kHz)"
1094 xlabel = "Frequency (kHz)"
1094 ylabel = "Power (dB)"
1095 ylabel = "Power (dB)"
1095
1096
1096 elif xaxis == "time":
1097 elif xaxis == "time":
1097 x = dataOut.getAcfRange()
1098 x = dataOut.getAcfRange()
1098 zdB = z[0,:,hei_index]
1099 zdB = z[0,:,hei_index]
1099 xlabel = "Time (ms)"
1100 xlabel = "Time (ms)"
1100 ylabel = "ACF"
1101 ylabel = "ACF"
1101
1102
1102 else:
1103 else:
1103 x = dataOut.getVelRange()
1104 x = dataOut.getVelRange()
1104 zdB = 10*numpy.log10(z[0,:,hei_index])
1105 zdB = 10*numpy.log10(z[0,:,hei_index])
1105 xlabel = "Velocity (m/s)"
1106 xlabel = "Velocity (m/s)"
1106 ylabel = "Power (dB)"
1107 ylabel = "Power (dB)"
1107
1108
1108 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1109 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1109 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1110 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1110
1111
1111 if not self.isConfig:
1112 if not self.isConfig:
1112
1113
1113 nplots = 1
1114 nplots = 1
1114
1115
1115 self.setup(id=id,
1116 self.setup(id=id,
1116 nplots=nplots,
1117 nplots=nplots,
1117 wintitle=wintitle,
1118 wintitle=wintitle,
1118 show=show)
1119 show=show)
1119
1120
1120 if xmin == None: xmin = numpy.nanmin(x)*0.9
1121 if xmin == None: xmin = numpy.nanmin(x)*0.9
1121 if xmax == None: xmax = numpy.nanmax(x)*1.1
1122 if xmax == None: xmax = numpy.nanmax(x)*1.1
1122 if ymin == None: ymin = numpy.nanmin(zdB)
1123 if ymin == None: ymin = numpy.nanmin(zdB)
1123 if ymax == None: ymax = numpy.nanmax(zdB)
1124 if ymax == None: ymax = numpy.nanmax(zdB)
1124
1125
1125 self.isConfig = True
1126 self.isConfig = True
1126
1127
1127 self.setWinTitle(title)
1128 self.setWinTitle(title)
1128
1129
1129 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1130 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1130 axes = self.axesList[0]
1131 axes = self.axesList[0]
1131
1132
1132 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1133 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1133
1134
1134 axes.pmultilineyaxis( x, zdB,
1135 axes.pmultilineyaxis( x, zdB,
1135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1136 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1137 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1137 ytick_visible=True, nxticks=5,
1138 ytick_visible=True, nxticks=5,
1138 grid='x')
1139 grid='x')
1139
1140
1140 self.draw()
1141 self.draw()
1141
1142
1142 self.save(figpath=figpath,
1143 self.save(figpath=figpath,
1143 figfile=figfile,
1144 figfile=figfile,
1144 save=save,
1145 save=save,
1145 ftp=ftp,
1146 ftp=ftp,
1146 wr_period=wr_period,
1147 wr_period=wr_period,
1147 thisDatetime=thisDatetime)
1148 thisDatetime=thisDatetime)
1148
1149
1149 return dataOut
1150 return dataOut
1150
1151
1151 @MPDecorator
1152 @MPDecorator
1152 class Noise_(Figure):
1153 class Noise_(Figure):
1153
1154
1154 isConfig = None
1155 isConfig = None
1155 __nsubplots = None
1156 __nsubplots = None
1156
1157
1157 PREFIX = 'noise'
1158 PREFIX = 'noise'
1158
1159
1159
1160
1160 def __init__(self):
1161 def __init__(self):
1161 Figure.__init__(self)
1162 Figure.__init__(self)
1162 self.timerange = 24*60*60
1163 self.timerange = 24*60*60
1163 self.isConfig = False
1164 self.isConfig = False
1164 self.__nsubplots = 1
1165 self.__nsubplots = 1
1165 self.counter_imagwr = 0
1166 self.counter_imagwr = 0
1166 self.WIDTH = 800
1167 self.WIDTH = 800
1167 self.HEIGHT = 400
1168 self.HEIGHT = 400
1168 self.WIDTHPROF = 120
1169 self.WIDTHPROF = 120
1169 self.HEIGHTPROF = 0
1170 self.HEIGHTPROF = 0
1170 self.xdata = None
1171 self.xdata = None
1171 self.ydata = None
1172 self.ydata = None
1172
1173
1173 self.PLOT_CODE = NOISE_CODE
1174 self.PLOT_CODE = NOISE_CODE
1174
1175
1175 self.FTP_WEI = None
1176 self.FTP_WEI = None
1176 self.EXP_CODE = None
1177 self.EXP_CODE = None
1177 self.SUB_EXP_CODE = None
1178 self.SUB_EXP_CODE = None
1178 self.PLOT_POS = None
1179 self.PLOT_POS = None
1179 self.figfile = None
1180 self.figfile = None
1180
1181
1181 self.xmin = None
1182 self.xmin = None
1182 self.xmax = None
1183 self.xmax = None
1183
1184
1184 def getSubplots(self):
1185 def getSubplots(self):
1185
1186
1186 ncol = 1
1187 ncol = 1
1187 nrow = 1
1188 nrow = 1
1188
1189
1189 return nrow, ncol
1190 return nrow, ncol
1190
1191
1191 def openfile(self, filename):
1192 def openfile(self, filename):
1192 dirname = os.path.dirname(filename)
1193 dirname = os.path.dirname(filename)
1193
1194
1194 if not os.path.exists(dirname):
1195 if not os.path.exists(dirname):
1195 os.mkdir(dirname)
1196 os.mkdir(dirname)
1196
1197
1197 f = open(filename,'w+')
1198 f = open(filename,'w+')
1198 f.write('\n\n')
1199 f.write('\n\n')
1199 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1200 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1200 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1201 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1201 f.close()
1202 f.close()
1202
1203
1203 def save_data(self, filename_phase, data, data_datetime):
1204 def save_data(self, filename_phase, data, data_datetime):
1204
1205
1205 f=open(filename_phase,'a')
1206 f=open(filename_phase,'a')
1206
1207
1207 timetuple_data = data_datetime.timetuple()
1208 timetuple_data = data_datetime.timetuple()
1208 day = str(timetuple_data.tm_mday)
1209 day = str(timetuple_data.tm_mday)
1209 month = str(timetuple_data.tm_mon)
1210 month = str(timetuple_data.tm_mon)
1210 year = str(timetuple_data.tm_year)
1211 year = str(timetuple_data.tm_year)
1211 hour = str(timetuple_data.tm_hour)
1212 hour = str(timetuple_data.tm_hour)
1212 minute = str(timetuple_data.tm_min)
1213 minute = str(timetuple_data.tm_min)
1213 second = str(timetuple_data.tm_sec)
1214 second = str(timetuple_data.tm_sec)
1214
1215
1215 data_msg = ''
1216 data_msg = ''
1216 for i in range(len(data)):
1217 for i in range(len(data)):
1217 data_msg += str(data[i]) + ' '
1218 data_msg += str(data[i]) + ' '
1218
1219
1219 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1220 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1220 f.close()
1221 f.close()
1221
1222
1222
1223
1223 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1224 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1224
1225
1225 self.__showprofile = showprofile
1226 self.__showprofile = showprofile
1226 self.nplots = nplots
1227 self.nplots = nplots
1227
1228
1228 ncolspan = 7
1229 ncolspan = 7
1229 colspan = 6
1230 colspan = 6
1230 self.__nsubplots = 2
1231 self.__nsubplots = 2
1231
1232
1232 self.createFigure(id = id,
1233 self.createFigure(id = id,
1233 wintitle = wintitle,
1234 wintitle = wintitle,
1234 widthplot = self.WIDTH+self.WIDTHPROF,
1235 widthplot = self.WIDTH+self.WIDTHPROF,
1235 heightplot = self.HEIGHT+self.HEIGHTPROF,
1236 heightplot = self.HEIGHT+self.HEIGHTPROF,
1236 show=show)
1237 show=show)
1237
1238
1238 nrow, ncol = self.getSubplots()
1239 nrow, ncol = self.getSubplots()
1239
1240
1240 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1241 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1241
1242
1242
1243
1243 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1244 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1244 xmin=None, xmax=None, ymin=None, ymax=None,
1245 xmin=None, xmax=None, ymin=None, ymax=None,
1245 timerange=None,
1246 timerange=None,
1246 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1247 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1247 server=None, folder=None, username=None, password=None,
1248 server=None, folder=None, username=None, password=None,
1248 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1249 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1249
1250
1250 if dataOut.flagNoData:
1251 if dataOut.flagNoData:
1251 return dataOut
1252 return dataOut
1252
1253
1253 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1254 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1254 return
1255 return
1255
1256
1256 if channelList == None:
1257 if channelList == None:
1257 channelIndexList = dataOut.channelIndexList
1258 channelIndexList = dataOut.channelIndexList
1258 channelList = dataOut.channelList
1259 channelList = dataOut.channelList
1259 else:
1260 else:
1260 channelIndexList = []
1261 channelIndexList = []
1261 for channel in channelList:
1262 for channel in channelList:
1262 if channel not in dataOut.channelList:
1263 if channel not in dataOut.channelList:
1263 raise ValueError("Channel %d is not in dataOut.channelList")
1264 raise ValueError("Channel %d is not in dataOut.channelList")
1264 channelIndexList.append(dataOut.channelList.index(channel))
1265 channelIndexList.append(dataOut.channelList.index(channel))
1265
1266
1266 x = dataOut.getTimeRange()
1267 x = dataOut.getTimeRange()
1267 #y = dataOut.getHeiRange()
1268 #y = dataOut.getHeiRange()
1268 factor = dataOut.normFactor
1269 factor = dataOut.normFactor
1269 noise = dataOut.noise[channelIndexList]/factor
1270 noise = dataOut.noise[channelIndexList]/factor
1270 noisedB = 10*numpy.log10(noise)
1271 noisedB = 10*numpy.log10(noise)
1271
1272
1272 thisDatetime = dataOut.datatime
1273 thisDatetime = dataOut.datatime
1273
1274
1274 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1275 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1275 xlabel = ""
1276 xlabel = ""
1276 ylabel = "Intensity (dB)"
1277 ylabel = "Intensity (dB)"
1277 update_figfile = False
1278 update_figfile = False
1278
1279
1279 if not self.isConfig:
1280 if not self.isConfig:
1280
1281
1281 nplots = 1
1282 nplots = 1
1282
1283
1283 self.setup(id=id,
1284 self.setup(id=id,
1284 nplots=nplots,
1285 nplots=nplots,
1285 wintitle=wintitle,
1286 wintitle=wintitle,
1286 showprofile=showprofile,
1287 showprofile=showprofile,
1287 show=show)
1288 show=show)
1288
1289
1289 if timerange != None:
1290 if timerange != None:
1290 self.timerange = timerange
1291 self.timerange = timerange
1291
1292
1292 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1293 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1293
1294
1294 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1295 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1295 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1296 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1296
1297
1297 self.FTP_WEI = ftp_wei
1298 self.FTP_WEI = ftp_wei
1298 self.EXP_CODE = exp_code
1299 self.EXP_CODE = exp_code
1299 self.SUB_EXP_CODE = sub_exp_code
1300 self.SUB_EXP_CODE = sub_exp_code
1300 self.PLOT_POS = plot_pos
1301 self.PLOT_POS = plot_pos
1301
1302
1302
1303
1303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1304 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1304 self.isConfig = True
1305 self.isConfig = True
1305 self.figfile = figfile
1306 self.figfile = figfile
1306 self.xdata = numpy.array([])
1307 self.xdata = numpy.array([])
1307 self.ydata = numpy.array([])
1308 self.ydata = numpy.array([])
1308
1309
1309 update_figfile = True
1310 update_figfile = True
1310
1311
1311 #open file beacon phase
1312 #open file beacon phase
1312 path = '%s%03d' %(self.PREFIX, self.id)
1313 path = '%s%03d' %(self.PREFIX, self.id)
1313 noise_file = os.path.join(path,'%s.txt'%self.name)
1314 noise_file = os.path.join(path,'%s.txt'%self.name)
1314 self.filename_noise = os.path.join(figpath,noise_file)
1315 self.filename_noise = os.path.join(figpath,noise_file)
1315
1316
1316 self.setWinTitle(title)
1317 self.setWinTitle(title)
1317
1318
1318 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1319 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1319
1320
1320 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1321 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1321 axes = self.axesList[0]
1322 axes = self.axesList[0]
1322
1323
1323 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1324 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1324
1325
1325 if len(self.ydata)==0:
1326 if len(self.ydata)==0:
1326 self.ydata = noisedB.reshape(-1,1)
1327 self.ydata = noisedB.reshape(-1,1)
1327 else:
1328 else:
1328 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1329 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1329
1330
1330
1331
1331 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1332 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1332 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1333 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1333 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1334 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1334 XAxisAsTime=True, grid='both'
1335 XAxisAsTime=True, grid='both'
1335 )
1336 )
1336
1337
1337 self.draw()
1338 self.draw()
1338
1339
1339 if dataOut.ltctime >= self.xmax:
1340 if dataOut.ltctime >= self.xmax:
1340 self.counter_imagwr = wr_period
1341 self.counter_imagwr = wr_period
1341 self.isConfig = False
1342 self.isConfig = False
1342 update_figfile = True
1343 update_figfile = True
1343
1344
1344 self.save(figpath=figpath,
1345 self.save(figpath=figpath,
1345 figfile=figfile,
1346 figfile=figfile,
1346 save=save,
1347 save=save,
1347 ftp=ftp,
1348 ftp=ftp,
1348 wr_period=wr_period,
1349 wr_period=wr_period,
1349 thisDatetime=thisDatetime,
1350 thisDatetime=thisDatetime,
1350 update_figfile=update_figfile)
1351 update_figfile=update_figfile)
1351
1352
1352 #store data beacon phase
1353 #store data beacon phase
1353 if save:
1354 if save:
1354 self.save_data(self.filename_noise, noisedB, thisDatetime)
1355 self.save_data(self.filename_noise, noisedB, thisDatetime)
1355
1356
1356 return dataOut
1357 return dataOut
1357
1358
1358 @MPDecorator
1359 @MPDecorator
1359 class BeaconPhase_(Figure):
1360 class BeaconPhase_(Figure):
1360
1361
1361 __isConfig = None
1362 __isConfig = None
1362 __nsubplots = None
1363 __nsubplots = None
1363
1364
1364 PREFIX = 'beacon_phase'
1365 PREFIX = 'beacon_phase'
1365
1366
1366 def __init__(self):
1367 def __init__(self):
1367 Figure.__init__(self)
1368 Figure.__init__(self)
1368 self.timerange = 24*60*60
1369 self.timerange = 24*60*60
1369 self.isConfig = False
1370 self.isConfig = False
1370 self.__nsubplots = 1
1371 self.__nsubplots = 1
1371 self.counter_imagwr = 0
1372 self.counter_imagwr = 0
1372 self.WIDTH = 800
1373 self.WIDTH = 800
1373 self.HEIGHT = 400
1374 self.HEIGHT = 400
1374 self.WIDTHPROF = 120
1375 self.WIDTHPROF = 120
1375 self.HEIGHTPROF = 0
1376 self.HEIGHTPROF = 0
1376 self.xdata = None
1377 self.xdata = None
1377 self.ydata = None
1378 self.ydata = None
1378
1379
1379 self.PLOT_CODE = BEACON_CODE
1380 self.PLOT_CODE = BEACON_CODE
1380
1381
1381 self.FTP_WEI = None
1382 self.FTP_WEI = None
1382 self.EXP_CODE = None
1383 self.EXP_CODE = None
1383 self.SUB_EXP_CODE = None
1384 self.SUB_EXP_CODE = None
1384 self.PLOT_POS = None
1385 self.PLOT_POS = None
1385
1386
1386 self.filename_phase = None
1387 self.filename_phase = None
1387
1388
1388 self.figfile = None
1389 self.figfile = None
1389
1390
1390 self.xmin = None
1391 self.xmin = None
1391 self.xmax = None
1392 self.xmax = None
1392
1393
1393 def getSubplots(self):
1394 def getSubplots(self):
1394
1395
1395 ncol = 1
1396 ncol = 1
1396 nrow = 1
1397 nrow = 1
1397
1398
1398 return nrow, ncol
1399 return nrow, ncol
1399
1400
1400 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1401 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1401
1402
1402 self.__showprofile = showprofile
1403 self.__showprofile = showprofile
1403 self.nplots = nplots
1404 self.nplots = nplots
1404
1405
1405 ncolspan = 7
1406 ncolspan = 7
1406 colspan = 6
1407 colspan = 6
1407 self.__nsubplots = 2
1408 self.__nsubplots = 2
1408
1409
1409 self.createFigure(id = id,
1410 self.createFigure(id = id,
1410 wintitle = wintitle,
1411 wintitle = wintitle,
1411 widthplot = self.WIDTH+self.WIDTHPROF,
1412 widthplot = self.WIDTH+self.WIDTHPROF,
1412 heightplot = self.HEIGHT+self.HEIGHTPROF,
1413 heightplot = self.HEIGHT+self.HEIGHTPROF,
1413 show=show)
1414 show=show)
1414
1415
1415 nrow, ncol = self.getSubplots()
1416 nrow, ncol = self.getSubplots()
1416
1417
1417 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1418 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1418
1419
1419 def save_phase(self, filename_phase):
1420 def save_phase(self, filename_phase):
1420 f = open(filename_phase,'w+')
1421 f = open(filename_phase,'w+')
1421 f.write('\n\n')
1422 f.write('\n\n')
1422 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1423 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1423 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1424 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1424 f.close()
1425 f.close()
1425
1426
1426 def save_data(self, filename_phase, data, data_datetime):
1427 def save_data(self, filename_phase, data, data_datetime):
1427 f=open(filename_phase,'a')
1428 f=open(filename_phase,'a')
1428 timetuple_data = data_datetime.timetuple()
1429 timetuple_data = data_datetime.timetuple()
1429 day = str(timetuple_data.tm_mday)
1430 day = str(timetuple_data.tm_mday)
1430 month = str(timetuple_data.tm_mon)
1431 month = str(timetuple_data.tm_mon)
1431 year = str(timetuple_data.tm_year)
1432 year = str(timetuple_data.tm_year)
1432 hour = str(timetuple_data.tm_hour)
1433 hour = str(timetuple_data.tm_hour)
1433 minute = str(timetuple_data.tm_min)
1434 minute = str(timetuple_data.tm_min)
1434 second = str(timetuple_data.tm_sec)
1435 second = str(timetuple_data.tm_sec)
1435 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1436 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1436 f.close()
1437 f.close()
1437
1438
1438
1439
1439 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1440 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1440 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1441 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1441 timerange=None,
1442 timerange=None,
1442 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1443 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1443 server=None, folder=None, username=None, password=None,
1444 server=None, folder=None, username=None, password=None,
1444 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1445 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1445
1446
1446 if dataOut.flagNoData:
1447 if dataOut.flagNoData:
1447 return dataOut
1448 return dataOut
1448
1449
1449 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1450 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1450 return
1451 return
1451
1452
1452 if pairsList == None:
1453 if pairsList == None:
1453 pairsIndexList = dataOut.pairsIndexList[:10]
1454 pairsIndexList = dataOut.pairsIndexList[:10]
1454 else:
1455 else:
1455 pairsIndexList = []
1456 pairsIndexList = []
1456 for pair in pairsList:
1457 for pair in pairsList:
1457 if pair not in dataOut.pairsList:
1458 if pair not in dataOut.pairsList:
1458 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1459 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1459 pairsIndexList.append(dataOut.pairsList.index(pair))
1460 pairsIndexList.append(dataOut.pairsList.index(pair))
1460
1461
1461 if pairsIndexList == []:
1462 if pairsIndexList == []:
1462 return
1463 return
1463
1464
1464 # if len(pairsIndexList) > 4:
1465 # if len(pairsIndexList) > 4:
1465 # pairsIndexList = pairsIndexList[0:4]
1466 # pairsIndexList = pairsIndexList[0:4]
1466
1467
1467 hmin_index = None
1468 hmin_index = None
1468 hmax_index = None
1469 hmax_index = None
1469
1470
1470 if hmin != None and hmax != None:
1471 if hmin != None and hmax != None:
1471 indexes = numpy.arange(dataOut.nHeights)
1472 indexes = numpy.arange(dataOut.nHeights)
1472 hmin_list = indexes[dataOut.heightList >= hmin]
1473 hmin_list = indexes[dataOut.heightList >= hmin]
1473 hmax_list = indexes[dataOut.heightList <= hmax]
1474 hmax_list = indexes[dataOut.heightList <= hmax]
1474
1475
1475 if hmin_list.any():
1476 if hmin_list.any():
1476 hmin_index = hmin_list[0]
1477 hmin_index = hmin_list[0]
1477
1478
1478 if hmax_list.any():
1479 if hmax_list.any():
1479 hmax_index = hmax_list[-1]+1
1480 hmax_index = hmax_list[-1]+1
1480
1481
1481 x = dataOut.getTimeRange()
1482 x = dataOut.getTimeRange()
1482 #y = dataOut.getHeiRange()
1483 #y = dataOut.getHeiRange()
1483
1484
1484
1485
1485 thisDatetime = dataOut.datatime
1486 thisDatetime = dataOut.datatime
1486
1487
1487 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1488 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1488 xlabel = "Local Time"
1489 xlabel = "Local Time"
1489 ylabel = "Phase (degrees)"
1490 ylabel = "Phase (degrees)"
1490
1491
1491 update_figfile = False
1492 update_figfile = False
1492
1493
1493 nplots = len(pairsIndexList)
1494 nplots = len(pairsIndexList)
1494 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1495 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1495 phase_beacon = numpy.zeros(len(pairsIndexList))
1496 phase_beacon = numpy.zeros(len(pairsIndexList))
1496 for i in range(nplots):
1497 for i in range(nplots):
1497 pair = dataOut.pairsList[pairsIndexList[i]]
1498 pair = dataOut.pairsList[pairsIndexList[i]]
1498 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1499 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1499 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1500 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1500 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1501 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1501 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1502 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1502 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1503 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1503
1504
1504 if dataOut.beacon_heiIndexList:
1505 if dataOut.beacon_heiIndexList:
1505 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1506 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1506 else:
1507 else:
1507 phase_beacon[i] = numpy.average(phase)
1508 phase_beacon[i] = numpy.average(phase)
1508
1509
1509 if not self.isConfig:
1510 if not self.isConfig:
1510
1511
1511 nplots = len(pairsIndexList)
1512 nplots = len(pairsIndexList)
1512
1513
1513 self.setup(id=id,
1514 self.setup(id=id,
1514 nplots=nplots,
1515 nplots=nplots,
1515 wintitle=wintitle,
1516 wintitle=wintitle,
1516 showprofile=showprofile,
1517 showprofile=showprofile,
1517 show=show)
1518 show=show)
1518
1519
1519 if timerange != None:
1520 if timerange != None:
1520 self.timerange = timerange
1521 self.timerange = timerange
1521
1522
1522 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1523 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1523
1524
1524 if ymin == None: ymin = 0
1525 if ymin == None: ymin = 0
1525 if ymax == None: ymax = 360
1526 if ymax == None: ymax = 360
1526
1527
1527 self.FTP_WEI = ftp_wei
1528 self.FTP_WEI = ftp_wei
1528 self.EXP_CODE = exp_code
1529 self.EXP_CODE = exp_code
1529 self.SUB_EXP_CODE = sub_exp_code
1530 self.SUB_EXP_CODE = sub_exp_code
1530 self.PLOT_POS = plot_pos
1531 self.PLOT_POS = plot_pos
1531
1532
1532 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1533 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1533 self.isConfig = True
1534 self.isConfig = True
1534 self.figfile = figfile
1535 self.figfile = figfile
1535 self.xdata = numpy.array([])
1536 self.xdata = numpy.array([])
1536 self.ydata = numpy.array([])
1537 self.ydata = numpy.array([])
1537
1538
1538 update_figfile = True
1539 update_figfile = True
1539
1540
1540 #open file beacon phase
1541 #open file beacon phase
1541 path = '%s%03d' %(self.PREFIX, self.id)
1542 path = '%s%03d' %(self.PREFIX, self.id)
1542 beacon_file = os.path.join(path,'%s.txt'%self.name)
1543 beacon_file = os.path.join(path,'%s.txt'%self.name)
1543 self.filename_phase = os.path.join(figpath,beacon_file)
1544 self.filename_phase = os.path.join(figpath,beacon_file)
1544 #self.save_phase(self.filename_phase)
1545 #self.save_phase(self.filename_phase)
1545
1546
1546
1547
1547 #store data beacon phase
1548 #store data beacon phase
1548 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1549 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1549
1550
1550 self.setWinTitle(title)
1551 self.setWinTitle(title)
1551
1552
1552
1553
1553 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1554 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1554
1555
1555 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1556 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1556
1557
1557 axes = self.axesList[0]
1558 axes = self.axesList[0]
1558
1559
1559 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1560 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1560
1561
1561 if len(self.ydata)==0:
1562 if len(self.ydata)==0:
1562 self.ydata = phase_beacon.reshape(-1,1)
1563 self.ydata = phase_beacon.reshape(-1,1)
1563 else:
1564 else:
1564 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1565 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1565
1566
1566
1567
1567 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1568 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1568 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1569 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1569 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1570 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1570 XAxisAsTime=True, grid='both'
1571 XAxisAsTime=True, grid='both'
1571 )
1572 )
1572
1573
1573 self.draw()
1574 self.draw()
1574
1575
1575 if dataOut.ltctime >= self.xmax:
1576 if dataOut.ltctime >= self.xmax:
1576 self.counter_imagwr = wr_period
1577 self.counter_imagwr = wr_period
1577 self.isConfig = False
1578 self.isConfig = False
1578 update_figfile = True
1579 update_figfile = True
1579
1580
1580 self.save(figpath=figpath,
1581 self.save(figpath=figpath,
1581 figfile=figfile,
1582 figfile=figfile,
1582 save=save,
1583 save=save,
1583 ftp=ftp,
1584 ftp=ftp,
1584 wr_period=wr_period,
1585 wr_period=wr_period,
1585 thisDatetime=thisDatetime,
1586 thisDatetime=thisDatetime,
1586 update_figfile=update_figfile)
1587 update_figfile=update_figfile)
1587
1588
1588 return dataOut No newline at end of file
1589 return dataOut
@@ -1,500 +1,470
1 import os
1 import os
2 import sys
2 import sys
3 import datetime
3 import datetime
4 import numpy
4 import numpy
5 import matplotlib
5 from .jroplot_base import matplotlib, make_axes_locatable, FuncFormatter, LinearLocator
6
7 if 'BACKEND' in os.environ:
8 matplotlib.use(os.environ['BACKEND'])
9 elif 'linux' in sys.platform:
10 matplotlib.use("TkAgg")
11 elif 'darwin' in sys.platform:
12 matplotlib.use('TkAgg')
13 else:
14 from schainpy.utils import log
15 log.warning('Using default Backend="Agg"', 'INFO')
16 matplotlib.use('Agg')
17 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
18 import matplotlib.pyplot
19
20 from mpl_toolkits.axes_grid1 import make_axes_locatable
21 from matplotlib.ticker import FuncFormatter, LinearLocator
22
23 ###########################################
24 # Actualizacion de las funciones del driver
25 ###########################################
26
27 # create jro colormap
28
29 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
30 blu_values = matplotlib.pyplot.get_cmap(
31 "seismic_r", 20)(numpy.arange(20))[10:15]
32 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
33 "jro", numpy.vstack((blu_values, jet_values)))
34 matplotlib.pyplot.register_cmap(cmap=ncmap)
35
36
6
37 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
7 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
38
8
39 matplotlib.pyplot.ioff()
9 matplotlib.pyplot.ioff()
40
10
41 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
11 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
42 1.0 * width / dpi, 1.0 * height / dpi))
12 1.0 * width / dpi, 1.0 * height / dpi))
43 fig.canvas.manager.set_window_title(wintitle)
13 fig.canvas.manager.set_window_title(wintitle)
44 # fig.canvas.manager.resize(width, height)
14 # fig.canvas.manager.resize(width, height)
45 matplotlib.pyplot.ion()
15 matplotlib.pyplot.ion()
46
16
47 if show:
17 if show:
48 matplotlib.pyplot.show()
18 matplotlib.pyplot.show()
49
19
50 return fig
20 return fig
51
21
52
22
53 def closeFigure(show=False, fig=None):
23 def closeFigure(show=False, fig=None):
54
24
55 # matplotlib.pyplot.ioff()
25 # matplotlib.pyplot.ioff()
56 # matplotlib.pyplot.pause(0)
26 # matplotlib.pyplot.pause(0)
57
27
58 if show:
28 if show:
59 matplotlib.pyplot.show()
29 matplotlib.pyplot.show()
60
30
61 if fig != None:
31 if fig != None:
62 matplotlib.pyplot.close(fig)
32 matplotlib.pyplot.close(fig)
63 # matplotlib.pyplot.pause(0)
33 # matplotlib.pyplot.pause(0)
64 # matplotlib.pyplot.ion()
34 # matplotlib.pyplot.ion()
65
35
66 return
36 return
67
37
68 matplotlib.pyplot.close("all")
38 matplotlib.pyplot.close("all")
69 # matplotlib.pyplot.pause(0)
39 # matplotlib.pyplot.pause(0)
70 # matplotlib.pyplot.ion()
40 # matplotlib.pyplot.ion()
71
41
72 return
42 return
73
43
74
44
75 def saveFigure(fig, filename):
45 def saveFigure(fig, filename):
76
46
77 # matplotlib.pyplot.ioff()
47 # matplotlib.pyplot.ioff()
78 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
48 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
79 # matplotlib.pyplot.ion()
49 # matplotlib.pyplot.ion()
80
50
81
51
82 def clearFigure(fig):
52 def clearFigure(fig):
83
53
84 fig.clf()
54 fig.clf()
85
55
86
56
87 def setWinTitle(fig, title):
57 def setWinTitle(fig, title):
88
58
89 fig.canvas.manager.set_window_title(title)
59 fig.canvas.manager.set_window_title(title)
90
60
91
61
92 def setTitle(fig, title):
62 def setTitle(fig, title):
93
63
94 fig.suptitle(title)
64 fig.suptitle(title)
95
65
96
66
97 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
67 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
98
68
99 matplotlib.pyplot.ioff()
69 matplotlib.pyplot.ioff()
100 matplotlib.pyplot.figure(fig.number)
70 matplotlib.pyplot.figure(fig.number)
101 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
71 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
102 (xpos, ypos),
72 (xpos, ypos),
103 colspan=colspan,
73 colspan=colspan,
104 rowspan=rowspan,
74 rowspan=rowspan,
105 polar=polar)
75 polar=polar)
106
76
107 matplotlib.pyplot.ion()
77 matplotlib.pyplot.ion()
108 return axes
78 return axes
109
79
110
80
111 def setAxesText(ax, text):
81 def setAxesText(ax, text):
112
82
113 ax.annotate(text,
83 ax.annotate(text,
114 xy=(.1, .99),
84 xy=(.1, .99),
115 xycoords='figure fraction',
85 xycoords='figure fraction',
116 horizontalalignment='left',
86 horizontalalignment='left',
117 verticalalignment='top',
87 verticalalignment='top',
118 fontsize=10)
88 fontsize=10)
119
89
120
90
121 def printLabels(ax, xlabel, ylabel, title):
91 def printLabels(ax, xlabel, ylabel, title):
122
92
123 ax.set_xlabel(xlabel, size=11)
93 ax.set_xlabel(xlabel, size=11)
124 ax.set_ylabel(ylabel, size=11)
94 ax.set_ylabel(ylabel, size=11)
125 ax.set_title(title, size=8)
95 ax.set_title(title, size=8)
126
96
127
97
128 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
98 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
129 ticksize=9, xtick_visible=True, ytick_visible=True,
99 ticksize=9, xtick_visible=True, ytick_visible=True,
130 nxticks=4, nyticks=10,
100 nxticks=4, nyticks=10,
131 grid=None, color='blue'):
101 grid=None, color='blue'):
132 """
102 """
133
103
134 Input:
104 Input:
135 grid : None, 'both', 'x', 'y'
105 grid : None, 'both', 'x', 'y'
136 """
106 """
137
107
138 matplotlib.pyplot.ioff()
108 matplotlib.pyplot.ioff()
139
109
140 ax.set_xlim([xmin, xmax])
110 ax.set_xlim([xmin, xmax])
141 ax.set_ylim([ymin, ymax])
111 ax.set_ylim([ymin, ymax])
142
112
143 printLabels(ax, xlabel, ylabel, title)
113 printLabels(ax, xlabel, ylabel, title)
144
114
145 ######################################################
115 ######################################################
146 if (xmax - xmin) <= 1:
116 if (xmax - xmin) <= 1:
147 xtickspos = numpy.linspace(xmin, xmax, nxticks)
117 xtickspos = numpy.linspace(xmin, xmax, nxticks)
148 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
118 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
149 ax.set_xticks(xtickspos)
119 ax.set_xticks(xtickspos)
150 else:
120 else:
151 xtickspos = numpy.arange(nxticks) * \
121 xtickspos = numpy.arange(nxticks) * \
152 int((xmax - xmin) / (nxticks)) + int(xmin)
122 int((xmax - xmin) / (nxticks)) + int(xmin)
153 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
123 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
154 ax.set_xticks(xtickspos)
124 ax.set_xticks(xtickspos)
155
125
156 for tick in ax.get_xticklabels():
126 for tick in ax.get_xticklabels():
157 tick.set_visible(xtick_visible)
127 tick.set_visible(xtick_visible)
158
128
159 for tick in ax.xaxis.get_major_ticks():
129 for tick in ax.xaxis.get_major_ticks():
160 tick.label.set_fontsize(ticksize)
130 tick.label.set_fontsize(ticksize)
161
131
162 ######################################################
132 ######################################################
163 for tick in ax.get_yticklabels():
133 for tick in ax.get_yticklabels():
164 tick.set_visible(ytick_visible)
134 tick.set_visible(ytick_visible)
165
135
166 for tick in ax.yaxis.get_major_ticks():
136 for tick in ax.yaxis.get_major_ticks():
167 tick.label.set_fontsize(ticksize)
137 tick.label.set_fontsize(ticksize)
168
138
169 ax.plot(x, y, color=color)
139 ax.plot(x, y, color=color)
170 iplot = ax.lines[-1]
140 iplot = ax.lines[-1]
171
141
172 ######################################################
142 ######################################################
173 if '0.' in matplotlib.__version__[0:2]:
143 if '0.' in matplotlib.__version__[0:2]:
174 print("The matplotlib version has to be updated to 1.1 or newer")
144 print("The matplotlib version has to be updated to 1.1 or newer")
175 return iplot
145 return iplot
176
146
177 if '1.0.' in matplotlib.__version__[0:4]:
147 if '1.0.' in matplotlib.__version__[0:4]:
178 print("The matplotlib version has to be updated to 1.1 or newer")
148 print("The matplotlib version has to be updated to 1.1 or newer")
179 return iplot
149 return iplot
180
150
181 if grid != None:
151 if grid != None:
182 ax.grid(b=True, which='major', axis=grid)
152 ax.grid(b=True, which='major', axis=grid)
183
153
184 matplotlib.pyplot.tight_layout()
154 matplotlib.pyplot.tight_layout()
185
155
186 matplotlib.pyplot.ion()
156 matplotlib.pyplot.ion()
187
157
188 return iplot
158 return iplot
189
159
190
160
191 def set_linedata(ax, x, y, idline):
161 def set_linedata(ax, x, y, idline):
192
162
193 ax.lines[idline].set_data(x, y)
163 ax.lines[idline].set_data(x, y)
194
164
195
165
196 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
166 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
197
167
198 ax = iplot.axes
168 ax = iplot.axes
199
169
200 printLabels(ax, xlabel, ylabel, title)
170 printLabels(ax, xlabel, ylabel, title)
201
171
202 set_linedata(ax, x, y, idline=0)
172 set_linedata(ax, x, y, idline=0)
203
173
204
174
205 def addpline(ax, x, y, color, linestyle, lw):
175 def addpline(ax, x, y, color, linestyle, lw):
206
176
207 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
177 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
208
178
209
179
210 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
180 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
211 xlabel='', ylabel='', title='', ticksize=9,
181 xlabel='', ylabel='', title='', ticksize=9,
212 colormap='jet', cblabel='', cbsize="5%",
182 colormap='jet', cblabel='', cbsize="5%",
213 XAxisAsTime=False):
183 XAxisAsTime=False):
214
184
215 matplotlib.pyplot.ioff()
185 matplotlib.pyplot.ioff()
216
186
217 divider = make_axes_locatable(ax)
187 divider = make_axes_locatable(ax)
218 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
188 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
219 fig = ax.get_figure()
189 fig = ax.get_figure()
220 fig.add_axes(ax_cb)
190 fig.add_axes(ax_cb)
221
191
222 ax.set_xlim([xmin, xmax])
192 ax.set_xlim([xmin, xmax])
223 ax.set_ylim([ymin, ymax])
193 ax.set_ylim([ymin, ymax])
224
194
225 printLabels(ax, xlabel, ylabel, title)
195 printLabels(ax, xlabel, ylabel, title)
226
196
227 z = numpy.ma.masked_invalid(z)
197 z = numpy.ma.masked_invalid(z)
228 cmap = matplotlib.pyplot.get_cmap(colormap)
198 cmap = matplotlib.pyplot.get_cmap(colormap)
229 cmap.set_bad('white', 1.)
199 cmap.set_bad('white', 1.)
230 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
200 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
231 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
201 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
232 cb.set_label(cblabel)
202 cb.set_label(cblabel)
233
203
234 # for tl in ax_cb.get_yticklabels():
204 # for tl in ax_cb.get_yticklabels():
235 # tl.set_visible(True)
205 # tl.set_visible(True)
236
206
237 for tick in ax.yaxis.get_major_ticks():
207 for tick in ax.yaxis.get_major_ticks():
238 tick.label.set_fontsize(ticksize)
208 tick.label.set_fontsize(ticksize)
239
209
240 for tick in ax.xaxis.get_major_ticks():
210 for tick in ax.xaxis.get_major_ticks():
241 tick.label.set_fontsize(ticksize)
211 tick.label.set_fontsize(ticksize)
242
212
243 for tick in cb.ax.get_yticklabels():
213 for tick in cb.ax.get_yticklabels():
244 tick.set_fontsize(ticksize)
214 tick.set_fontsize(ticksize)
245
215
246 ax_cb.yaxis.tick_right()
216 ax_cb.yaxis.tick_right()
247
217
248 if '0.' in matplotlib.__version__[0:2]:
218 if '0.' in matplotlib.__version__[0:2]:
249 print("The matplotlib version has to be updated to 1.1 or newer")
219 print("The matplotlib version has to be updated to 1.1 or newer")
250 return imesh
220 return imesh
251
221
252 if '1.0.' in matplotlib.__version__[0:4]:
222 if '1.0.' in matplotlib.__version__[0:4]:
253 print("The matplotlib version has to be updated to 1.1 or newer")
223 print("The matplotlib version has to be updated to 1.1 or newer")
254 return imesh
224 return imesh
255
225
256 matplotlib.pyplot.tight_layout()
226 matplotlib.pyplot.tight_layout()
257
227
258 if XAxisAsTime:
228 if XAxisAsTime:
259
229
260 def func(x, pos): return ('%s') % (
230 def func(x, pos): return ('%s') % (
261 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
231 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
262 ax.xaxis.set_major_formatter(FuncFormatter(func))
232 ax.xaxis.set_major_formatter(FuncFormatter(func))
263 ax.xaxis.set_major_locator(LinearLocator(7))
233 ax.xaxis.set_major_locator(LinearLocator(7))
264
234
265 matplotlib.pyplot.ion()
235 matplotlib.pyplot.ion()
266 return imesh
236 return imesh
267
237
268
238
269 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
239 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
270
240
271 z = z.T
241 z = z.T
272 ax = imesh.axes
242 ax = imesh.axes
273 printLabels(ax, xlabel, ylabel, title)
243 printLabels(ax, xlabel, ylabel, title)
274 imesh.set_array(z.ravel())
244 imesh.set_array(z.ravel())
275
245
276
246
277 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
247 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
278
248
279 printLabels(ax, xlabel, ylabel, title)
249 printLabels(ax, xlabel, ylabel, title)
280
250
281 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
251 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
282 cmap=matplotlib.pyplot.get_cmap(colormap))
252 cmap=matplotlib.pyplot.get_cmap(colormap))
283
253
284
254
285 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
255 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
286
256
287 printLabels(ax, xlabel, ylabel, title)
257 printLabels(ax, xlabel, ylabel, title)
288
258
289 ax.collections.remove(ax.collections[0])
259 ax.collections.remove(ax.collections[0])
290
260
291 z = numpy.ma.masked_invalid(z)
261 z = numpy.ma.masked_invalid(z)
292
262
293 cmap = matplotlib.pyplot.get_cmap(colormap)
263 cmap = matplotlib.pyplot.get_cmap(colormap)
294 cmap.set_bad('white', 1.)
264 cmap.set_bad('white', 1.)
295
265
296 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
266 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
297
267
298
268
299 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
269 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
300 ticksize=9, xtick_visible=True, ytick_visible=True,
270 ticksize=9, xtick_visible=True, ytick_visible=True,
301 nxticks=4, nyticks=10,
271 nxticks=4, nyticks=10,
302 grid=None):
272 grid=None):
303 """
273 """
304
274
305 Input:
275 Input:
306 grid : None, 'both', 'x', 'y'
276 grid : None, 'both', 'x', 'y'
307 """
277 """
308
278
309 matplotlib.pyplot.ioff()
279 matplotlib.pyplot.ioff()
310
280
311 lines = ax.plot(x.T, y)
281 lines = ax.plot(x.T, y)
312 leg = ax.legend(lines, legendlabels, loc='upper right')
282 leg = ax.legend(lines, legendlabels, loc='upper right')
313 leg.get_frame().set_alpha(0.5)
283 leg.get_frame().set_alpha(0.5)
314 ax.set_xlim([xmin, xmax])
284 ax.set_xlim([xmin, xmax])
315 ax.set_ylim([ymin, ymax])
285 ax.set_ylim([ymin, ymax])
316 printLabels(ax, xlabel, ylabel, title)
286 printLabels(ax, xlabel, ylabel, title)
317
287
318 xtickspos = numpy.arange(nxticks) * \
288 xtickspos = numpy.arange(nxticks) * \
319 int((xmax - xmin) / (nxticks)) + int(xmin)
289 int((xmax - xmin) / (nxticks)) + int(xmin)
320 ax.set_xticks(xtickspos)
290 ax.set_xticks(xtickspos)
321
291
322 for tick in ax.get_xticklabels():
292 for tick in ax.get_xticklabels():
323 tick.set_visible(xtick_visible)
293 tick.set_visible(xtick_visible)
324
294
325 for tick in ax.xaxis.get_major_ticks():
295 for tick in ax.xaxis.get_major_ticks():
326 tick.label.set_fontsize(ticksize)
296 tick.label.set_fontsize(ticksize)
327
297
328 for tick in ax.get_yticklabels():
298 for tick in ax.get_yticklabels():
329 tick.set_visible(ytick_visible)
299 tick.set_visible(ytick_visible)
330
300
331 for tick in ax.yaxis.get_major_ticks():
301 for tick in ax.yaxis.get_major_ticks():
332 tick.label.set_fontsize(ticksize)
302 tick.label.set_fontsize(ticksize)
333
303
334 iplot = ax.lines[-1]
304 iplot = ax.lines[-1]
335
305
336 if '0.' in matplotlib.__version__[0:2]:
306 if '0.' in matplotlib.__version__[0:2]:
337 print("The matplotlib version has to be updated to 1.1 or newer")
307 print("The matplotlib version has to be updated to 1.1 or newer")
338 return iplot
308 return iplot
339
309
340 if '1.0.' in matplotlib.__version__[0:4]:
310 if '1.0.' in matplotlib.__version__[0:4]:
341 print("The matplotlib version has to be updated to 1.1 or newer")
311 print("The matplotlib version has to be updated to 1.1 or newer")
342 return iplot
312 return iplot
343
313
344 if grid != None:
314 if grid != None:
345 ax.grid(b=True, which='major', axis=grid)
315 ax.grid(b=True, which='major', axis=grid)
346
316
347 matplotlib.pyplot.tight_layout()
317 matplotlib.pyplot.tight_layout()
348
318
349 matplotlib.pyplot.ion()
319 matplotlib.pyplot.ion()
350
320
351 return iplot
321 return iplot
352
322
353
323
354 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
324 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
355
325
356 ax = iplot.axes
326 ax = iplot.axes
357
327
358 printLabels(ax, xlabel, ylabel, title)
328 printLabels(ax, xlabel, ylabel, title)
359
329
360 for i in range(len(ax.lines)):
330 for i in range(len(ax.lines)):
361 line = ax.lines[i]
331 line = ax.lines[i]
362 line.set_data(x[i, :], y)
332 line.set_data(x[i, :], y)
363
333
364
334
365 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
335 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
366 ticksize=9, xtick_visible=True, ytick_visible=True,
336 ticksize=9, xtick_visible=True, ytick_visible=True,
367 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
337 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
368 grid=None, XAxisAsTime=False):
338 grid=None, XAxisAsTime=False):
369 """
339 """
370
340
371 Input:
341 Input:
372 grid : None, 'both', 'x', 'y'
342 grid : None, 'both', 'x', 'y'
373 """
343 """
374
344
375 matplotlib.pyplot.ioff()
345 matplotlib.pyplot.ioff()
376
346
377 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
347 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
378 lines = ax.plot(x, y.T)
348 lines = ax.plot(x, y.T)
379 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
349 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
380 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
350 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
381
351
382 leg = ax.legend(lines, legendlabels,
352 leg = ax.legend(lines, legendlabels,
383 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
353 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
384
354
385 for label in leg.get_texts():
355 for label in leg.get_texts():
386 label.set_fontsize(9)
356 label.set_fontsize(9)
387
357
388 ax.set_xlim([xmin, xmax])
358 ax.set_xlim([xmin, xmax])
389 ax.set_ylim([ymin, ymax])
359 ax.set_ylim([ymin, ymax])
390 printLabels(ax, xlabel, ylabel, title)
360 printLabels(ax, xlabel, ylabel, title)
391
361
392 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
362 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
393 # ax.set_xticks(xtickspos)
363 # ax.set_xticks(xtickspos)
394
364
395 for tick in ax.get_xticklabels():
365 for tick in ax.get_xticklabels():
396 tick.set_visible(xtick_visible)
366 tick.set_visible(xtick_visible)
397
367
398 for tick in ax.xaxis.get_major_ticks():
368 for tick in ax.xaxis.get_major_ticks():
399 tick.label.set_fontsize(ticksize)
369 tick.label.set_fontsize(ticksize)
400
370
401 for tick in ax.get_yticklabels():
371 for tick in ax.get_yticklabels():
402 tick.set_visible(ytick_visible)
372 tick.set_visible(ytick_visible)
403
373
404 for tick in ax.yaxis.get_major_ticks():
374 for tick in ax.yaxis.get_major_ticks():
405 tick.label.set_fontsize(ticksize)
375 tick.label.set_fontsize(ticksize)
406
376
407 iplot = ax.lines[-1]
377 iplot = ax.lines[-1]
408
378
409 if '0.' in matplotlib.__version__[0:2]:
379 if '0.' in matplotlib.__version__[0:2]:
410 print("The matplotlib version has to be updated to 1.1 or newer")
380 print("The matplotlib version has to be updated to 1.1 or newer")
411 return iplot
381 return iplot
412
382
413 if '1.0.' in matplotlib.__version__[0:4]:
383 if '1.0.' in matplotlib.__version__[0:4]:
414 print("The matplotlib version has to be updated to 1.1 or newer")
384 print("The matplotlib version has to be updated to 1.1 or newer")
415 return iplot
385 return iplot
416
386
417 if grid != None:
387 if grid != None:
418 ax.grid(b=True, which='major', axis=grid)
388 ax.grid(b=True, which='major', axis=grid)
419
389
420 matplotlib.pyplot.tight_layout()
390 matplotlib.pyplot.tight_layout()
421
391
422 if XAxisAsTime:
392 if XAxisAsTime:
423
393
424 def func(x, pos): return ('%s') % (
394 def func(x, pos): return ('%s') % (
425 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
395 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
426 ax.xaxis.set_major_formatter(FuncFormatter(func))
396 ax.xaxis.set_major_formatter(FuncFormatter(func))
427 ax.xaxis.set_major_locator(LinearLocator(7))
397 ax.xaxis.set_major_locator(LinearLocator(7))
428
398
429 matplotlib.pyplot.ion()
399 matplotlib.pyplot.ion()
430
400
431 return iplot
401 return iplot
432
402
433
403
434 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
404 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
435
405
436 ax = iplot.axes
406 ax = iplot.axes
437 printLabels(ax, xlabel, ylabel, title)
407 printLabels(ax, xlabel, ylabel, title)
438
408
439 for i in range(len(ax.lines)):
409 for i in range(len(ax.lines)):
440 line = ax.lines[i]
410 line = ax.lines[i]
441 line.set_data(x, y[i, :])
411 line.set_data(x, y[i, :])
442
412
443
413
444 def createPolar(ax, x, y,
414 def createPolar(ax, x, y,
445 xlabel='', ylabel='', title='', ticksize=9,
415 xlabel='', ylabel='', title='', ticksize=9,
446 colormap='jet', cblabel='', cbsize="5%",
416 colormap='jet', cblabel='', cbsize="5%",
447 XAxisAsTime=False):
417 XAxisAsTime=False):
448
418
449 matplotlib.pyplot.ioff()
419 matplotlib.pyplot.ioff()
450
420
451 ax.plot(x, y, 'bo', markersize=5)
421 ax.plot(x, y, 'bo', markersize=5)
452 # ax.set_rmax(90)
422 # ax.set_rmax(90)
453 ax.set_ylim(0, 90)
423 ax.set_ylim(0, 90)
454 ax.set_yticks(numpy.arange(0, 90, 20))
424 ax.set_yticks(numpy.arange(0, 90, 20))
455 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
425 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
456 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
426 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
457 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
427 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
458 ax.yaxis.labelpad = 40
428 ax.yaxis.labelpad = 40
459 printLabels(ax, xlabel, ylabel, title)
429 printLabels(ax, xlabel, ylabel, title)
460 iplot = ax.lines[-1]
430 iplot = ax.lines[-1]
461
431
462 if '0.' in matplotlib.__version__[0:2]:
432 if '0.' in matplotlib.__version__[0:2]:
463 print("The matplotlib version has to be updated to 1.1 or newer")
433 print("The matplotlib version has to be updated to 1.1 or newer")
464 return iplot
434 return iplot
465
435
466 if '1.0.' in matplotlib.__version__[0:4]:
436 if '1.0.' in matplotlib.__version__[0:4]:
467 print("The matplotlib version has to be updated to 1.1 or newer")
437 print("The matplotlib version has to be updated to 1.1 or newer")
468 return iplot
438 return iplot
469
439
470 # if grid != None:
440 # if grid != None:
471 # ax.grid(b=True, which='major', axis=grid)
441 # ax.grid(b=True, which='major', axis=grid)
472
442
473 matplotlib.pyplot.tight_layout()
443 matplotlib.pyplot.tight_layout()
474
444
475 matplotlib.pyplot.ion()
445 matplotlib.pyplot.ion()
476
446
477 return iplot
447 return iplot
478
448
479
449
480 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
450 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
481
451
482 ax = iplot.axes
452 ax = iplot.axes
483
453
484 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
454 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
485 printLabels(ax, xlabel, ylabel, title)
455 printLabels(ax, xlabel, ylabel, title)
486
456
487 set_linedata(ax, x, y, idline=0)
457 set_linedata(ax, x, y, idline=0)
488
458
489
459
490 def draw(fig):
460 def draw(fig):
491
461
492 if type(fig) == 'int':
462 if type(fig) == 'int':
493 raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure")
463 raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure")
494
464
495 fig.canvas.draw()
465 fig.canvas.draw()
496
466
497
467
498 def pause(interval=0.000001):
468 def pause(interval=0.000001):
499
469
500 matplotlib.pyplot.pause(interval) No newline at end of file
470 matplotlib.pyplot.pause(interval)
@@ -1,3858 +1,3858
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 time
13 import time
14
14
15 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
15 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
16 from .jroproc_base import ProcessingUnit, Operation, MPDecorator
16 from .jroproc_base import ProcessingUnit, Operation, MPDecorator
17 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
17 from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon
18 from scipy import asarray as ar,exp
18 from scipy import asarray as ar,exp
19 from scipy.optimize import curve_fit
19 from scipy.optimize import curve_fit
20 from schainpy.utils import log
20 from schainpy.utils import log
21 import warnings
21 import warnings
22 from numpy import NaN
22 from numpy import NaN
23 from scipy.optimize.optimize import OptimizeWarning
23 from scipy.optimize.optimize import OptimizeWarning
24 warnings.filterwarnings('ignore')
24 warnings.filterwarnings('ignore')
25
25
26
26
27 SPEED_OF_LIGHT = 299792458
27 SPEED_OF_LIGHT = 299792458
28
28
29
29
30 '''solving pickling issue'''
30 '''solving pickling issue'''
31
31
32 def _pickle_method(method):
32 def _pickle_method(method):
33 func_name = method.__func__.__name__
33 func_name = method.__func__.__name__
34 obj = method.__self__
34 obj = method.__self__
35 cls = method.__self__.__class__
35 cls = method.__self__.__class__
36 return _unpickle_method, (func_name, obj, cls)
36 return _unpickle_method, (func_name, obj, cls)
37
37
38 def _unpickle_method(func_name, obj, cls):
38 def _unpickle_method(func_name, obj, cls):
39 for cls in cls.mro():
39 for cls in cls.mro():
40 try:
40 try:
41 func = cls.__dict__[func_name]
41 func = cls.__dict__[func_name]
42 except KeyError:
42 except KeyError:
43 pass
43 pass
44 else:
44 else:
45 break
45 break
46 return func.__get__(obj, cls)
46 return func.__get__(obj, cls)
47
47
48 @MPDecorator
48 @MPDecorator
49 class ParametersProc(ProcessingUnit):
49 class ParametersProc(ProcessingUnit):
50
50
51 METHODS = {}
51 METHODS = {}
52 nSeconds = None
52 nSeconds = None
53
53
54 def __init__(self):
54 def __init__(self):
55 ProcessingUnit.__init__(self)
55 ProcessingUnit.__init__(self)
56
56
57 # self.objectDict = {}
57 # self.objectDict = {}
58 self.buffer = None
58 self.buffer = None
59 self.firstdatatime = None
59 self.firstdatatime = None
60 self.profIndex = 0
60 self.profIndex = 0
61 self.dataOut = Parameters()
61 self.dataOut = Parameters()
62 self.setupReq = False #Agregar a todas las unidades de proc
62 self.setupReq = False #Agregar a todas las unidades de proc
63
63
64 def __updateObjFromInput(self):
64 def __updateObjFromInput(self):
65
65
66 self.dataOut.inputUnit = self.dataIn.type
66 self.dataOut.inputUnit = self.dataIn.type
67
67
68 self.dataOut.timeZone = self.dataIn.timeZone
68 self.dataOut.timeZone = self.dataIn.timeZone
69 self.dataOut.dstFlag = self.dataIn.dstFlag
69 self.dataOut.dstFlag = self.dataIn.dstFlag
70 self.dataOut.errorCount = self.dataIn.errorCount
70 self.dataOut.errorCount = self.dataIn.errorCount
71 self.dataOut.useLocalTime = self.dataIn.useLocalTime
71 self.dataOut.useLocalTime = self.dataIn.useLocalTime
72
72
73 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
73 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
74 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
74 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
75 self.dataOut.channelList = self.dataIn.channelList
75 self.dataOut.channelList = self.dataIn.channelList
76 self.dataOut.heightList = self.dataIn.heightList
76 self.dataOut.heightList = self.dataIn.heightList
77 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
77 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
78 # self.dataOut.nHeights = self.dataIn.nHeights
78 # self.dataOut.nHeights = self.dataIn.nHeights
79 # self.dataOut.nChannels = self.dataIn.nChannels
79 # self.dataOut.nChannels = self.dataIn.nChannels
80 self.dataOut.nBaud = self.dataIn.nBaud
80 self.dataOut.nBaud = self.dataIn.nBaud
81 self.dataOut.nCode = self.dataIn.nCode
81 self.dataOut.nCode = self.dataIn.nCode
82 self.dataOut.code = self.dataIn.code
82 self.dataOut.code = self.dataIn.code
83 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
83 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
84 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
84 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
85 # self.dataOut.utctime = self.firstdatatime
85 # self.dataOut.utctime = self.firstdatatime
86 self.dataOut.utctime = self.dataIn.utctime
86 self.dataOut.utctime = self.dataIn.utctime
87 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
87 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
88 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
88 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
89 self.dataOut.nCohInt = self.dataIn.nCohInt
89 self.dataOut.nCohInt = self.dataIn.nCohInt
90 # self.dataOut.nIncohInt = 1
90 # self.dataOut.nIncohInt = 1
91 self.dataOut.ippSeconds = self.dataIn.ippSeconds
91 self.dataOut.ippSeconds = self.dataIn.ippSeconds
92 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
92 # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
93 self.dataOut.timeInterval1 = self.dataIn.timeInterval
93 self.dataOut.timeInterval1 = self.dataIn.timeInterval
94 self.dataOut.heightList = self.dataIn.getHeiRange()
94 self.dataOut.heightList = self.dataIn.getHeiRange()
95 self.dataOut.frequency = self.dataIn.frequency
95 self.dataOut.frequency = self.dataIn.frequency
96 # self.dataOut.noise = self.dataIn.noise
96 # self.dataOut.noise = self.dataIn.noise
97 self.dataOut.error = self.dataIn.error
97 self.dataOut.error = self.dataIn.error
98
98
99 def run(self):
99 def run(self):
100
100
101
101
102
102
103 #---------------------- Voltage Data ---------------------------
103 #---------------------- Voltage Data ---------------------------
104
104
105 if self.dataIn.type == "Voltage":
105 if self.dataIn.type == "Voltage":
106
106
107 self.__updateObjFromInput()
107 self.__updateObjFromInput()
108 self.dataOut.data_pre = self.dataIn.data.copy()
108 self.dataOut.data_pre = self.dataIn.data.copy()
109 self.dataOut.flagNoData = False
109 self.dataOut.flagNoData = False
110 self.dataOut.utctimeInit = self.dataIn.utctime
110 self.dataOut.utctimeInit = self.dataIn.utctime
111 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
111 self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds
112 return
112 return
113
113
114 #---------------------- Spectra Data ---------------------------
114 #---------------------- Spectra Data ---------------------------
115
115
116 if self.dataIn.type == "Spectra":
116 if self.dataIn.type == "Spectra":
117
117
118 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
118 self.dataOut.data_pre = (self.dataIn.data_spc, self.dataIn.data_cspc)
119 self.dataOut.data_spc = self.dataIn.data_spc
119 self.dataOut.data_spc = self.dataIn.data_spc
120 self.dataOut.data_cspc = self.dataIn.data_cspc
120 self.dataOut.data_cspc = self.dataIn.data_cspc
121 self.dataOut.nProfiles = self.dataIn.nProfiles
121 self.dataOut.nProfiles = self.dataIn.nProfiles
122 self.dataOut.nIncohInt = self.dataIn.nIncohInt
122 self.dataOut.nIncohInt = self.dataIn.nIncohInt
123 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
123 self.dataOut.nFFTPoints = self.dataIn.nFFTPoints
124 self.dataOut.ippFactor = self.dataIn.ippFactor
124 self.dataOut.ippFactor = self.dataIn.ippFactor
125 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
125 self.dataOut.abscissaList = self.dataIn.getVelRange(1)
126 self.dataOut.spc_noise = self.dataIn.getNoise()
126 self.dataOut.spc_noise = self.dataIn.getNoise()
127 self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1))
127 self.dataOut.spc_range = (self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1))
128 # self.dataOut.normFactor = self.dataIn.normFactor
128 # self.dataOut.normFactor = self.dataIn.normFactor
129 self.dataOut.pairsList = self.dataIn.pairsList
129 self.dataOut.pairsList = self.dataIn.pairsList
130 self.dataOut.groupList = self.dataIn.pairsList
130 self.dataOut.groupList = self.dataIn.pairsList
131 self.dataOut.flagNoData = False
131 self.dataOut.flagNoData = False
132
132
133 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
133 if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels
134 self.dataOut.ChanDist = self.dataIn.ChanDist
134 self.dataOut.ChanDist = self.dataIn.ChanDist
135 else: self.dataOut.ChanDist = None
135 else: self.dataOut.ChanDist = None
136
136
137 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
137 #if hasattr(self.dataIn, 'VelRange'): #Velocities range
138 # self.dataOut.VelRange = self.dataIn.VelRange
138 # self.dataOut.VelRange = self.dataIn.VelRange
139 #else: self.dataOut.VelRange = None
139 #else: self.dataOut.VelRange = None
140
140
141 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
141 if hasattr(self.dataIn, 'RadarConst'): #Radar Constant
142 self.dataOut.RadarConst = self.dataIn.RadarConst
142 self.dataOut.RadarConst = self.dataIn.RadarConst
143
143
144 if hasattr(self.dataIn, 'NPW'): #NPW
144 if hasattr(self.dataIn, 'NPW'): #NPW
145 self.dataOut.NPW = self.dataIn.NPW
145 self.dataOut.NPW = self.dataIn.NPW
146
146
147 if hasattr(self.dataIn, 'COFA'): #COFA
147 if hasattr(self.dataIn, 'COFA'): #COFA
148 self.dataOut.COFA = self.dataIn.COFA
148 self.dataOut.COFA = self.dataIn.COFA
149
149
150
150
151
151
152 #---------------------- Correlation Data ---------------------------
152 #---------------------- Correlation Data ---------------------------
153
153
154 if self.dataIn.type == "Correlation":
154 if self.dataIn.type == "Correlation":
155 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
155 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions()
156
156
157 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
157 self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:])
158 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
158 self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:])
159 self.dataOut.groupList = (acf_pairs, ccf_pairs)
159 self.dataOut.groupList = (acf_pairs, ccf_pairs)
160
160
161 self.dataOut.abscissaList = self.dataIn.lagRange
161 self.dataOut.abscissaList = self.dataIn.lagRange
162 self.dataOut.noise = self.dataIn.noise
162 self.dataOut.noise = self.dataIn.noise
163 self.dataOut.data_SNR = self.dataIn.SNR
163 self.dataOut.data_SNR = self.dataIn.SNR
164 self.dataOut.flagNoData = False
164 self.dataOut.flagNoData = False
165 self.dataOut.nAvg = self.dataIn.nAvg
165 self.dataOut.nAvg = self.dataIn.nAvg
166
166
167 #---------------------- Parameters Data ---------------------------
167 #---------------------- Parameters Data ---------------------------
168
168
169 if self.dataIn.type == "Parameters":
169 if self.dataIn.type == "Parameters":
170 self.dataOut.copy(self.dataIn)
170 self.dataOut.copy(self.dataIn)
171 self.dataOut.flagNoData = False
171 self.dataOut.flagNoData = False
172
172
173 return True
173 return True
174
174
175 self.__updateObjFromInput()
175 self.__updateObjFromInput()
176 self.dataOut.utctimeInit = self.dataIn.utctime
176 self.dataOut.utctimeInit = self.dataIn.utctime
177 self.dataOut.paramInterval = self.dataIn.timeInterval
177 self.dataOut.paramInterval = self.dataIn.timeInterval
178
178
179 return
179 return
180
180
181
181
182 def target(tups):
182 def target(tups):
183
183
184 obj, args = tups
184 obj, args = tups
185
185
186 return obj.FitGau(args)
186 return obj.FitGau(args)
187
187
188
188
189 class SpectralFilters(Operation):
189 class SpectralFilters(Operation):
190
190
191 '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR
191 '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR
192
192
193 LimitR : It is the limit in m/s of Rainfall
193 LimitR : It is the limit in m/s of Rainfall
194 LimitW : It is the limit in m/s for Winds
194 LimitW : It is the limit in m/s for Winds
195
195
196 Input:
196 Input:
197
197
198 self.dataOut.data_pre : SPC and CSPC
198 self.dataOut.data_pre : SPC and CSPC
199 self.dataOut.spc_range : To select wind and rainfall velocities
199 self.dataOut.spc_range : To select wind and rainfall velocities
200
200
201 Affected:
201 Affected:
202
202
203 self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind
203 self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind
204 self.dataOut.spcparam_range : Used in SpcParamPlot
204 self.dataOut.spcparam_range : Used in SpcParamPlot
205 self.dataOut.SPCparam : Used in PrecipitationProc
205 self.dataOut.SPCparam : Used in PrecipitationProc
206
206
207
207
208 '''
208 '''
209
209
210 def __init__(self):
210 def __init__(self):
211 Operation.__init__(self)
211 Operation.__init__(self)
212 self.i=0
212 self.i=0
213
213
214 def run(self, dataOut, PositiveLimit=1.5, NegativeLimit=2.5):
214 def run(self, dataOut, PositiveLimit=1.5, NegativeLimit=2.5):
215
215
216
216
217 #Limite de vientos
217 #Limite de vientos
218 LimitR = PositiveLimit
218 LimitR = PositiveLimit
219 LimitN = NegativeLimit
219 LimitN = NegativeLimit
220
220
221 self.spc = dataOut.data_pre[0].copy()
221 self.spc = dataOut.data_pre[0].copy()
222 self.cspc = dataOut.data_pre[1].copy()
222 self.cspc = dataOut.data_pre[1].copy()
223
223
224 self.Num_Hei = self.spc.shape[2]
224 self.Num_Hei = self.spc.shape[2]
225 self.Num_Bin = self.spc.shape[1]
225 self.Num_Bin = self.spc.shape[1]
226 self.Num_Chn = self.spc.shape[0]
226 self.Num_Chn = self.spc.shape[0]
227
227
228 VelRange = dataOut.spc_range[2]
228 VelRange = dataOut.spc_range[2]
229 TimeRange = dataOut.spc_range[1]
229 TimeRange = dataOut.spc_range[1]
230 FrecRange = dataOut.spc_range[0]
230 FrecRange = dataOut.spc_range[0]
231
231
232 Vmax= 2*numpy.max(dataOut.spc_range[2])
232 Vmax= 2*numpy.max(dataOut.spc_range[2])
233 Tmax= 2*numpy.max(dataOut.spc_range[1])
233 Tmax= 2*numpy.max(dataOut.spc_range[1])
234 Fmax= 2*numpy.max(dataOut.spc_range[0])
234 Fmax= 2*numpy.max(dataOut.spc_range[0])
235
235
236 Breaker1R=VelRange[numpy.abs(VelRange-(-LimitN)).argmin()]
236 Breaker1R=VelRange[numpy.abs(VelRange-(-LimitN)).argmin()]
237 Breaker1R=numpy.where(VelRange == Breaker1R)
237 Breaker1R=numpy.where(VelRange == Breaker1R)
238
238
239 Delta = self.Num_Bin/2 - Breaker1R[0]
239 Delta = self.Num_Bin/2 - Breaker1R[0]
240
240
241
241
242 '''Reacomodando SPCrange'''
242 '''Reacomodando SPCrange'''
243
243
244 VelRange=numpy.roll(VelRange,-(int(self.Num_Bin/2)) ,axis=0)
244 VelRange=numpy.roll(VelRange,-(int(self.Num_Bin/2)) ,axis=0)
245
245
246 VelRange[-(int(self.Num_Bin/2)):]+= Vmax
246 VelRange[-(int(self.Num_Bin/2)):]+= Vmax
247
247
248 FrecRange=numpy.roll(FrecRange,-(int(self.Num_Bin/2)),axis=0)
248 FrecRange=numpy.roll(FrecRange,-(int(self.Num_Bin/2)),axis=0)
249
249
250 FrecRange[-(int(self.Num_Bin/2)):]+= Fmax
250 FrecRange[-(int(self.Num_Bin/2)):]+= Fmax
251
251
252 TimeRange=numpy.roll(TimeRange,-(int(self.Num_Bin/2)),axis=0)
252 TimeRange=numpy.roll(TimeRange,-(int(self.Num_Bin/2)),axis=0)
253
253
254 TimeRange[-(int(self.Num_Bin/2)):]+= Tmax
254 TimeRange[-(int(self.Num_Bin/2)):]+= Tmax
255
255
256 ''' ------------------ '''
256 ''' ------------------ '''
257
257
258 Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()]
258 Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()]
259 Breaker2R=numpy.where(VelRange == Breaker2R)
259 Breaker2R=numpy.where(VelRange == Breaker2R)
260
260
261
261
262 SPCroll = numpy.roll(self.spc,-(int(self.Num_Bin/2)) ,axis=1)
262 SPCroll = numpy.roll(self.spc,-(int(self.Num_Bin/2)) ,axis=1)
263
263
264 SPCcut = SPCroll.copy()
264 SPCcut = SPCroll.copy()
265 for i in range(self.Num_Chn):
265 for i in range(self.Num_Chn):
266
266
267 SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i]
267 SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i]
268 SPCcut[i,-int(Delta):,:] = dataOut.noise[i]
268 SPCcut[i,-int(Delta):,:] = dataOut.noise[i]
269
269
270 SPCcut[i]=SPCcut[i]- dataOut.noise[i]
270 SPCcut[i]=SPCcut[i]- dataOut.noise[i]
271 SPCcut[ numpy.where( SPCcut<0 ) ] = 1e-20
271 SPCcut[ numpy.where( SPCcut<0 ) ] = 1e-20
272
272
273 SPCroll[i]=SPCroll[i]-dataOut.noise[i]
273 SPCroll[i]=SPCroll[i]-dataOut.noise[i]
274 SPCroll[ numpy.where( SPCroll<0 ) ] = 1e-20
274 SPCroll[ numpy.where( SPCroll<0 ) ] = 1e-20
275
275
276 SPC_ch1 = SPCroll
276 SPC_ch1 = SPCroll
277
277
278 SPC_ch2 = SPCcut
278 SPC_ch2 = SPCcut
279
279
280 SPCparam = (SPC_ch1, SPC_ch2, self.spc)
280 SPCparam = (SPC_ch1, SPC_ch2, self.spc)
281 dataOut.SPCparam = numpy.asarray(SPCparam)
281 dataOut.SPCparam = numpy.asarray(SPCparam)
282
282
283
283
284 dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1])
284 dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1])
285
285
286 dataOut.spcparam_range[2]=VelRange
286 dataOut.spcparam_range[2]=VelRange
287 dataOut.spcparam_range[1]=TimeRange
287 dataOut.spcparam_range[1]=TimeRange
288 dataOut.spcparam_range[0]=FrecRange
288 dataOut.spcparam_range[0]=FrecRange
289 return dataOut
289 return dataOut
290
290
291 class GaussianFit(Operation):
291 class GaussianFit(Operation):
292
292
293 '''
293 '''
294 Function that fit of one and two generalized gaussians (gg) based
294 Function that fit of one and two generalized gaussians (gg) based
295 on the PSD shape across an "power band" identified from a cumsum of
295 on the PSD shape across an "power band" identified from a cumsum of
296 the measured spectrum - noise.
296 the measured spectrum - noise.
297
297
298 Input:
298 Input:
299 self.dataOut.data_pre : SelfSpectra
299 self.dataOut.data_pre : SelfSpectra
300
300
301 Output:
301 Output:
302 self.dataOut.SPCparam : SPC_ch1, SPC_ch2
302 self.dataOut.SPCparam : SPC_ch1, SPC_ch2
303
303
304 '''
304 '''
305 def __init__(self):
305 def __init__(self):
306 Operation.__init__(self)
306 Operation.__init__(self)
307 self.i=0
307 self.i=0
308
308
309
309
310 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
310 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
311 """This routine will find a couple of generalized Gaussians to a power spectrum
311 """This routine will find a couple of generalized Gaussians to a power spectrum
312 input: spc
312 input: spc
313 output:
313 output:
314 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
314 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
315 """
315 """
316
316
317 self.spc = dataOut.data_pre[0].copy()
317 self.spc = dataOut.data_pre[0].copy()
318 self.Num_Hei = self.spc.shape[2]
318 self.Num_Hei = self.spc.shape[2]
319 self.Num_Bin = self.spc.shape[1]
319 self.Num_Bin = self.spc.shape[1]
320 self.Num_Chn = self.spc.shape[0]
320 self.Num_Chn = self.spc.shape[0]
321 Vrange = dataOut.abscissaList
321 Vrange = dataOut.abscissaList
322
322
323 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
323 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
324 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
324 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
325 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
325 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
326 SPC_ch1[:] = numpy.NaN
326 SPC_ch1[:] = numpy.NaN
327 SPC_ch2[:] = numpy.NaN
327 SPC_ch2[:] = numpy.NaN
328
328
329
329
330 start_time = time.time()
330 start_time = time.time()
331
331
332 noise_ = dataOut.spc_noise[0].copy()
332 noise_ = dataOut.spc_noise[0].copy()
333
333
334
334
335 pool = Pool(processes=self.Num_Chn)
335 pool = Pool(processes=self.Num_Chn)
336 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
336 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
337 objs = [self for __ in range(self.Num_Chn)]
337 objs = [self for __ in range(self.Num_Chn)]
338 attrs = list(zip(objs, args))
338 attrs = list(zip(objs, args))
339 gauSPC = pool.map(target, attrs)
339 gauSPC = pool.map(target, attrs)
340 dataOut.SPCparam = numpy.asarray(SPCparam)
340 dataOut.SPCparam = numpy.asarray(SPCparam)
341
341
342 ''' Parameters:
342 ''' Parameters:
343 1. Amplitude
343 1. Amplitude
344 2. Shift
344 2. Shift
345 3. Width
345 3. Width
346 4. Power
346 4. Power
347 '''
347 '''
348
348
349 def FitGau(self, X):
349 def FitGau(self, X):
350
350
351 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
351 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
352
352
353 SPCparam = []
353 SPCparam = []
354 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
354 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
355 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
355 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
356 SPC_ch1[:] = 0#numpy.NaN
356 SPC_ch1[:] = 0#numpy.NaN
357 SPC_ch2[:] = 0#numpy.NaN
357 SPC_ch2[:] = 0#numpy.NaN
358
358
359
359
360
360
361 for ht in range(self.Num_Hei):
361 for ht in range(self.Num_Hei):
362
362
363
363
364 spc = numpy.asarray(self.spc)[ch,:,ht]
364 spc = numpy.asarray(self.spc)[ch,:,ht]
365
365
366 #############################################
366 #############################################
367 # normalizing spc and noise
367 # normalizing spc and noise
368 # This part differs from gg1
368 # This part differs from gg1
369 spc_norm_max = max(spc)
369 spc_norm_max = max(spc)
370 #spc = spc / spc_norm_max
370 #spc = spc / spc_norm_max
371 pnoise = pnoise #/ spc_norm_max
371 pnoise = pnoise #/ spc_norm_max
372 #############################################
372 #############################################
373
373
374 fatspectra=1.0
374 fatspectra=1.0
375
375
376 wnoise = noise_ #/ spc_norm_max
376 wnoise = noise_ #/ spc_norm_max
377 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
377 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
378 #if wnoise>1.1*pnoise: # to be tested later
378 #if wnoise>1.1*pnoise: # to be tested later
379 # wnoise=pnoise
379 # wnoise=pnoise
380 noisebl=wnoise*0.9;
380 noisebl=wnoise*0.9;
381 noisebh=wnoise*1.1
381 noisebh=wnoise*1.1
382 spc=spc-wnoise
382 spc=spc-wnoise
383
383
384 minx=numpy.argmin(spc)
384 minx=numpy.argmin(spc)
385 #spcs=spc.copy()
385 #spcs=spc.copy()
386 spcs=numpy.roll(spc,-minx)
386 spcs=numpy.roll(spc,-minx)
387 cum=numpy.cumsum(spcs)
387 cum=numpy.cumsum(spcs)
388 tot_noise=wnoise * self.Num_Bin #64;
388 tot_noise=wnoise * self.Num_Bin #64;
389
389
390 snr = sum(spcs)/tot_noise
390 snr = sum(spcs)/tot_noise
391 snrdB=10.*numpy.log10(snr)
391 snrdB=10.*numpy.log10(snr)
392
392
393 if snrdB < SNRlimit :
393 if snrdB < SNRlimit :
394 snr = numpy.NaN
394 snr = numpy.NaN
395 SPC_ch1[:,ht] = 0#numpy.NaN
395 SPC_ch1[:,ht] = 0#numpy.NaN
396 SPC_ch1[:,ht] = 0#numpy.NaN
396 SPC_ch1[:,ht] = 0#numpy.NaN
397 SPCparam = (SPC_ch1,SPC_ch2)
397 SPCparam = (SPC_ch1,SPC_ch2)
398 continue
398 continue
399
399
400
400
401 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
401 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
402 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
402 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
403
403
404 cummax=max(cum);
404 cummax=max(cum);
405 epsi=0.08*fatspectra # cumsum to narrow down the energy region
405 epsi=0.08*fatspectra # cumsum to narrow down the energy region
406 cumlo=cummax*epsi;
406 cumlo=cummax*epsi;
407 cumhi=cummax*(1-epsi)
407 cumhi=cummax*(1-epsi)
408 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
408 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
409
409
410
410
411 if len(powerindex) < 1:# case for powerindex 0
411 if len(powerindex) < 1:# case for powerindex 0
412 continue
412 continue
413 powerlo=powerindex[0]
413 powerlo=powerindex[0]
414 powerhi=powerindex[-1]
414 powerhi=powerindex[-1]
415 powerwidth=powerhi-powerlo
415 powerwidth=powerhi-powerlo
416
416
417 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
417 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
418 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
418 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
419 midpeak=(firstpeak+secondpeak)/2.
419 midpeak=(firstpeak+secondpeak)/2.
420 firstamp=spcs[int(firstpeak)]
420 firstamp=spcs[int(firstpeak)]
421 secondamp=spcs[int(secondpeak)]
421 secondamp=spcs[int(secondpeak)]
422 midamp=spcs[int(midpeak)]
422 midamp=spcs[int(midpeak)]
423
423
424 x=numpy.arange( self.Num_Bin )
424 x=numpy.arange( self.Num_Bin )
425 y_data=spc+wnoise
425 y_data=spc+wnoise
426
426
427 ''' single Gaussian '''
427 ''' single Gaussian '''
428 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
428 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
429 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
429 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
430 power0=2.
430 power0=2.
431 amplitude0=midamp
431 amplitude0=midamp
432 state0=[shift0,width0,amplitude0,power0,wnoise]
432 state0=[shift0,width0,amplitude0,power0,wnoise]
433 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
433 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
434 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
434 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
435
435
436 chiSq1=lsq1[1];
436 chiSq1=lsq1[1];
437
437
438
438
439 if fatspectra<1.0 and powerwidth<4:
439 if fatspectra<1.0 and powerwidth<4:
440 choice=0
440 choice=0
441 Amplitude0=lsq1[0][2]
441 Amplitude0=lsq1[0][2]
442 shift0=lsq1[0][0]
442 shift0=lsq1[0][0]
443 width0=lsq1[0][1]
443 width0=lsq1[0][1]
444 p0=lsq1[0][3]
444 p0=lsq1[0][3]
445 Amplitude1=0.
445 Amplitude1=0.
446 shift1=0.
446 shift1=0.
447 width1=0.
447 width1=0.
448 p1=0.
448 p1=0.
449 noise=lsq1[0][4]
449 noise=lsq1[0][4]
450 #return (numpy.array([shift0,width0,Amplitude0,p0]),
450 #return (numpy.array([shift0,width0,Amplitude0,p0]),
451 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
451 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
452
452
453 ''' two gaussians '''
453 ''' two gaussians '''
454 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
454 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
455 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
455 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
456 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
456 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
457 width0=powerwidth/6.;
457 width0=powerwidth/6.;
458 width1=width0
458 width1=width0
459 power0=2.;
459 power0=2.;
460 power1=power0
460 power1=power0
461 amplitude0=firstamp;
461 amplitude0=firstamp;
462 amplitude1=secondamp
462 amplitude1=secondamp
463 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
463 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
464 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
464 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
465 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))
465 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))
466 #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))
466 #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))
467
467
468 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
468 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
469
469
470
470
471 chiSq2=lsq2[1];
471 chiSq2=lsq2[1];
472
472
473
473
474
474
475 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)
475 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)
476
476
477 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
477 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
478 if oneG:
478 if oneG:
479 choice=0
479 choice=0
480 else:
480 else:
481 w1=lsq2[0][1]; w2=lsq2[0][5]
481 w1=lsq2[0][1]; w2=lsq2[0][5]
482 a1=lsq2[0][2]; a2=lsq2[0][6]
482 a1=lsq2[0][2]; a2=lsq2[0][6]
483 p1=lsq2[0][3]; p2=lsq2[0][7]
483 p1=lsq2[0][3]; p2=lsq2[0][7]
484 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
484 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
485 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
485 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
486 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
486 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
487
487
488 if gp1>gp2:
488 if gp1>gp2:
489 if a1>0.7*a2:
489 if a1>0.7*a2:
490 choice=1
490 choice=1
491 else:
491 else:
492 choice=2
492 choice=2
493 elif gp2>gp1:
493 elif gp2>gp1:
494 if a2>0.7*a1:
494 if a2>0.7*a1:
495 choice=2
495 choice=2
496 else:
496 else:
497 choice=1
497 choice=1
498 else:
498 else:
499 choice=numpy.argmax([a1,a2])+1
499 choice=numpy.argmax([a1,a2])+1
500 #else:
500 #else:
501 #choice=argmin([std2a,std2b])+1
501 #choice=argmin([std2a,std2b])+1
502
502
503 else: # with low SNR go to the most energetic peak
503 else: # with low SNR go to the most energetic peak
504 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
504 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
505
505
506
506
507 shift0=lsq2[0][0];
507 shift0=lsq2[0][0];
508 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
508 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
509 shift1=lsq2[0][4];
509 shift1=lsq2[0][4];
510 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
510 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
511
511
512 max_vel = 1.0
512 max_vel = 1.0
513
513
514 #first peak will be 0, second peak will be 1
514 #first peak will be 0, second peak will be 1
515 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
515 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
516 shift0=lsq2[0][0]
516 shift0=lsq2[0][0]
517 width0=lsq2[0][1]
517 width0=lsq2[0][1]
518 Amplitude0=lsq2[0][2]
518 Amplitude0=lsq2[0][2]
519 p0=lsq2[0][3]
519 p0=lsq2[0][3]
520
520
521 shift1=lsq2[0][4]
521 shift1=lsq2[0][4]
522 width1=lsq2[0][5]
522 width1=lsq2[0][5]
523 Amplitude1=lsq2[0][6]
523 Amplitude1=lsq2[0][6]
524 p1=lsq2[0][7]
524 p1=lsq2[0][7]
525 noise=lsq2[0][8]
525 noise=lsq2[0][8]
526 else:
526 else:
527 shift1=lsq2[0][0]
527 shift1=lsq2[0][0]
528 width1=lsq2[0][1]
528 width1=lsq2[0][1]
529 Amplitude1=lsq2[0][2]
529 Amplitude1=lsq2[0][2]
530 p1=lsq2[0][3]
530 p1=lsq2[0][3]
531
531
532 shift0=lsq2[0][4]
532 shift0=lsq2[0][4]
533 width0=lsq2[0][5]
533 width0=lsq2[0][5]
534 Amplitude0=lsq2[0][6]
534 Amplitude0=lsq2[0][6]
535 p0=lsq2[0][7]
535 p0=lsq2[0][7]
536 noise=lsq2[0][8]
536 noise=lsq2[0][8]
537
537
538 if Amplitude0<0.05: # in case the peak is noise
538 if Amplitude0<0.05: # in case the peak is noise
539 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
539 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
540 if Amplitude1<0.05:
540 if Amplitude1<0.05:
541 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
541 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
542
542
543
543
544 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
544 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
545 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
545 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
546 SPCparam = (SPC_ch1,SPC_ch2)
546 SPCparam = (SPC_ch1,SPC_ch2)
547
547
548
548
549 return GauSPC
549 return GauSPC
550
550
551 def y_model1(self,x,state):
551 def y_model1(self,x,state):
552 shift0,width0,amplitude0,power0,noise=state
552 shift0,width0,amplitude0,power0,noise=state
553 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
553 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
554
554
555 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
555 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
556
556
557 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
557 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
558 return model0+model0u+model0d+noise
558 return model0+model0u+model0d+noise
559
559
560 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
560 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
561 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
561 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
562 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
562 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
563
563
564 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
564 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
565
565
566 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
566 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
567 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
567 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
568
568
569 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
569 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
570
570
571 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
571 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
572 return model0+model0u+model0d+model1+model1u+model1d+noise
572 return model0+model0u+model0d+model1+model1u+model1d+noise
573
573
574 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.
574 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.
575
575
576 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
576 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
577
577
578 def misfit2(self,state,y_data,x,num_intg):
578 def misfit2(self,state,y_data,x,num_intg):
579 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
579 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
580
580
581
581
582
582
583 class PrecipitationProc(Operation):
583 class PrecipitationProc(Operation):
584
584
585 '''
585 '''
586 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
586 Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R)
587
587
588 Input:
588 Input:
589 self.dataOut.data_pre : SelfSpectra
589 self.dataOut.data_pre : SelfSpectra
590
590
591 Output:
591 Output:
592
592
593 self.dataOut.data_output : Reflectivity factor, rainfall Rate
593 self.dataOut.data_output : Reflectivity factor, rainfall Rate
594
594
595
595
596 Parameters affected:
596 Parameters affected:
597 '''
597 '''
598
598
599 def __init__(self):
599 def __init__(self):
600 Operation.__init__(self)
600 Operation.__init__(self)
601 self.i=0
601 self.i=0
602
602
603
603
604 def gaus(self,xSamples,Amp,Mu,Sigma):
604 def gaus(self,xSamples,Amp,Mu,Sigma):
605 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
605 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
606
606
607
607
608
608
609 def Moments(self, ySamples, xSamples):
609 def Moments(self, ySamples, xSamples):
610 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
610 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
611 yNorm = ySamples / Pot
611 yNorm = ySamples / Pot
612
612
613 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
613 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
614 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
614 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
615 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
615 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
616
616
617 return numpy.array([Pot, Vr, Desv])
617 return numpy.array([Pot, Vr, Desv])
618
618
619 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
619 def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118,
620 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
620 tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350):
621
621
622
622
623 Velrange = dataOut.spcparam_range[2]
623 Velrange = dataOut.spcparam_range[2]
624 FrecRange = dataOut.spcparam_range[0]
624 FrecRange = dataOut.spcparam_range[0]
625
625
626 dV= Velrange[1]-Velrange[0]
626 dV= Velrange[1]-Velrange[0]
627 dF= FrecRange[1]-FrecRange[0]
627 dF= FrecRange[1]-FrecRange[0]
628
628
629 if radar == "MIRA35C" :
629 if radar == "MIRA35C" :
630
630
631 self.spc = dataOut.data_pre[0].copy()
631 self.spc = dataOut.data_pre[0].copy()
632 self.Num_Hei = self.spc.shape[2]
632 self.Num_Hei = self.spc.shape[2]
633 self.Num_Bin = self.spc.shape[1]
633 self.Num_Bin = self.spc.shape[1]
634 self.Num_Chn = self.spc.shape[0]
634 self.Num_Chn = self.spc.shape[0]
635 Ze = self.dBZeMODE2(dataOut)
635 Ze = self.dBZeMODE2(dataOut)
636
636
637 else:
637 else:
638
638
639 self.spc = dataOut.SPCparam[1].copy() #dataOut.data_pre[0].copy() #
639 self.spc = dataOut.SPCparam[1].copy() #dataOut.data_pre[0].copy() #
640
640
641 """NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX"""
641 """NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX"""
642
642
643 self.spc[:,:,0:7]= numpy.NaN
643 self.spc[:,:,0:7]= numpy.NaN
644
644
645 """##########################################"""
645 """##########################################"""
646
646
647 self.Num_Hei = self.spc.shape[2]
647 self.Num_Hei = self.spc.shape[2]
648 self.Num_Bin = self.spc.shape[1]
648 self.Num_Bin = self.spc.shape[1]
649 self.Num_Chn = self.spc.shape[0]
649 self.Num_Chn = self.spc.shape[0]
650
650
651 ''' Se obtiene la constante del RADAR '''
651 ''' Se obtiene la constante del RADAR '''
652
652
653 self.Pt = Pt
653 self.Pt = Pt
654 self.Gt = Gt
654 self.Gt = Gt
655 self.Gr = Gr
655 self.Gr = Gr
656 self.Lambda = Lambda
656 self.Lambda = Lambda
657 self.aL = aL
657 self.aL = aL
658 self.tauW = tauW
658 self.tauW = tauW
659 self.ThetaT = ThetaT
659 self.ThetaT = ThetaT
660 self.ThetaR = ThetaR
660 self.ThetaR = ThetaR
661
661
662 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
662 Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
663 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
663 Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR)
664 RadarConstant = 10e-26 * Numerator / Denominator #
664 RadarConstant = 10e-26 * Numerator / Denominator #
665
665
666 ''' ============================= '''
666 ''' ============================= '''
667
667
668 self.spc[0] = (self.spc[0]-dataOut.noise[0])
668 self.spc[0] = (self.spc[0]-dataOut.noise[0])
669 self.spc[1] = (self.spc[1]-dataOut.noise[1])
669 self.spc[1] = (self.spc[1]-dataOut.noise[1])
670 self.spc[2] = (self.spc[2]-dataOut.noise[2])
670 self.spc[2] = (self.spc[2]-dataOut.noise[2])
671
671
672 self.spc[ numpy.where(self.spc < 0)] = 0
672 self.spc[ numpy.where(self.spc < 0)] = 0
673
673
674 SPCmean = (numpy.mean(self.spc,0) - numpy.mean(dataOut.noise))
674 SPCmean = (numpy.mean(self.spc,0) - numpy.mean(dataOut.noise))
675 SPCmean[ numpy.where(SPCmean < 0)] = 0
675 SPCmean[ numpy.where(SPCmean < 0)] = 0
676
676
677 ETAn = numpy.zeros([self.Num_Bin,self.Num_Hei])
677 ETAn = numpy.zeros([self.Num_Bin,self.Num_Hei])
678 ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei])
678 ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei])
679 ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei])
679 ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei])
680
680
681 Pr = SPCmean[:,:]
681 Pr = SPCmean[:,:]
682
682
683 VelMeteoro = numpy.mean(SPCmean,axis=0)
683 VelMeteoro = numpy.mean(SPCmean,axis=0)
684
684
685 D_range = numpy.zeros([self.Num_Bin,self.Num_Hei])
685 D_range = numpy.zeros([self.Num_Bin,self.Num_Hei])
686 SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei])
686 SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei])
687 N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei])
687 N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei])
688 V_mean = numpy.zeros(self.Num_Hei)
688 V_mean = numpy.zeros(self.Num_Hei)
689 del_V = numpy.zeros(self.Num_Hei)
689 del_V = numpy.zeros(self.Num_Hei)
690 Z = numpy.zeros(self.Num_Hei)
690 Z = numpy.zeros(self.Num_Hei)
691 Ze = numpy.zeros(self.Num_Hei)
691 Ze = numpy.zeros(self.Num_Hei)
692 RR = numpy.zeros(self.Num_Hei)
692 RR = numpy.zeros(self.Num_Hei)
693
693
694 Range = dataOut.heightList*1000.
694 Range = dataOut.heightList*1000.
695
695
696 for R in range(self.Num_Hei):
696 for R in range(self.Num_Hei):
697
697
698 h = Range[R] + Altitude #Range from ground to radar pulse altitude
698 h = Range[R] + Altitude #Range from ground to radar pulse altitude
699 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
699 del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity
700
700
701 D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Diameter range [m]x10**-3
701 D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Diameter range [m]x10**-3
702
702
703 '''NOTA: ETA(n) dn = ETA(f) df
703 '''NOTA: ETA(n) dn = ETA(f) df
704
704
705 dn = 1 Diferencial de muestreo
705 dn = 1 Diferencial de muestreo
706 df = ETA(n) / ETA(f)
706 df = ETA(n) / ETA(f)
707
707
708 '''
708 '''
709
709
710 ETAn[:,R] = RadarConstant * Pr[:,R] * (Range[R] )**2 #Reflectivity (ETA)
710 ETAn[:,R] = RadarConstant * Pr[:,R] * (Range[R] )**2 #Reflectivity (ETA)
711
711
712 ETAv[:,R]=ETAn[:,R]/dV
712 ETAv[:,R]=ETAn[:,R]/dV
713
713
714 ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R])
714 ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R])
715
715
716 SIGMA[:,R] = Km * (D_range[:,R] * 1e-3 )**6 * numpy.pi**5 / Lambda**4 #Equivalent Section of drops (sigma)
716 SIGMA[:,R] = Km * (D_range[:,R] * 1e-3 )**6 * numpy.pi**5 / Lambda**4 #Equivalent Section of drops (sigma)
717
717
718 N_dist[:,R] = ETAn[:,R] / SIGMA[:,R]
718 N_dist[:,R] = ETAn[:,R] / SIGMA[:,R]
719
719
720 DMoments = self.Moments(Pr[:,R], Velrange[0:self.Num_Bin])
720 DMoments = self.Moments(Pr[:,R], Velrange[0:self.Num_Bin])
721
721
722 try:
722 try:
723 popt01,pcov = curve_fit(self.gaus, Velrange[0:self.Num_Bin] , Pr[:,R] , p0=DMoments)
723 popt01,pcov = curve_fit(self.gaus, Velrange[0:self.Num_Bin] , Pr[:,R] , p0=DMoments)
724 except:
724 except:
725 popt01=numpy.zeros(3)
725 popt01=numpy.zeros(3)
726 popt01[1]= DMoments[1]
726 popt01[1]= DMoments[1]
727
727
728 if popt01[1]<0 or popt01[1]>20:
728 if popt01[1]<0 or popt01[1]>20:
729 popt01[1]=numpy.NaN
729 popt01[1]=numpy.NaN
730
730
731
731
732 V_mean[R]=popt01[1]
732 V_mean[R]=popt01[1]
733
733
734 Z[R] = numpy.nansum( N_dist[:,R] * (D_range[:,R])**6 )#*10**-18
734 Z[R] = numpy.nansum( N_dist[:,R] * (D_range[:,R])**6 )#*10**-18
735
735
736 RR[R] = 0.0006*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate
736 RR[R] = 0.0006*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate
737
737
738 Ze[R] = (numpy.nansum( ETAn[:,R]) * Lambda**4) / ( 10**-18*numpy.pi**5 * Km)
738 Ze[R] = (numpy.nansum( ETAn[:,R]) * Lambda**4) / ( 10**-18*numpy.pi**5 * Km)
739
739
740
740
741
741
742 RR2 = (Z/200)**(1/1.6)
742 RR2 = (Z/200)**(1/1.6)
743 dBRR = 10*numpy.log10(RR)
743 dBRR = 10*numpy.log10(RR)
744 dBRR2 = 10*numpy.log10(RR2)
744 dBRR2 = 10*numpy.log10(RR2)
745
745
746 dBZe = 10*numpy.log10(Ze)
746 dBZe = 10*numpy.log10(Ze)
747 dBZ = 10*numpy.log10(Z)
747 dBZ = 10*numpy.log10(Z)
748
748
749 dataOut.data_output = RR[8]
749 dataOut.data_output = RR[8]
750 dataOut.data_param = numpy.ones([3,self.Num_Hei])
750 dataOut.data_param = numpy.ones([3,self.Num_Hei])
751 dataOut.channelList = [0,1,2]
751 dataOut.channelList = [0,1,2]
752
752
753 dataOut.data_param[0]=dBZ
753 dataOut.data_param[0]=dBZ
754 dataOut.data_param[1]=V_mean
754 dataOut.data_param[1]=V_mean
755 dataOut.data_param[2]=RR
755 dataOut.data_param[2]=RR
756
756
757 return dataOut
757 return dataOut
758
758
759 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
759 def dBZeMODE2(self, dataOut): # Processing for MIRA35C
760
760
761 NPW = dataOut.NPW
761 NPW = dataOut.NPW
762 COFA = dataOut.COFA
762 COFA = dataOut.COFA
763
763
764 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
764 SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]])
765 RadarConst = dataOut.RadarConst
765 RadarConst = dataOut.RadarConst
766 #frequency = 34.85*10**9
766 #frequency = 34.85*10**9
767
767
768 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
768 ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei]))
769 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
769 data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN
770
770
771 ETA = numpy.sum(SNR,1)
771 ETA = numpy.sum(SNR,1)
772
772
773 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
773 ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN)
774
774
775 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
775 Ze = numpy.ones([self.Num_Chn, self.Num_Hei] )
776
776
777 for r in range(self.Num_Hei):
777 for r in range(self.Num_Hei):
778
778
779 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
779 Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2)
780 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
780 #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2)
781
781
782 return Ze
782 return Ze
783
783
784 # def GetRadarConstant(self):
784 # def GetRadarConstant(self):
785 #
785 #
786 # """
786 # """
787 # Constants:
787 # Constants:
788 #
788 #
789 # Pt: Transmission Power dB 5kW 5000
789 # Pt: Transmission Power dB 5kW 5000
790 # Gt: Transmission Gain dB 24.7 dB 295.1209
790 # Gt: Transmission Gain dB 24.7 dB 295.1209
791 # Gr: Reception Gain dB 18.5 dB 70.7945
791 # Gr: Reception Gain dB 18.5 dB 70.7945
792 # Lambda: Wavelenght m 0.6741 m 0.6741
792 # Lambda: Wavelenght m 0.6741 m 0.6741
793 # aL: Attenuation loses dB 4dB 2.5118
793 # aL: Attenuation loses dB 4dB 2.5118
794 # tauW: Width of transmission pulse s 4us 4e-6
794 # tauW: Width of transmission pulse s 4us 4e-6
795 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
795 # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317
796 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
796 # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087
797 #
797 #
798 # """
798 # """
799 #
799 #
800 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
800 # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) )
801 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
801 # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR)
802 # RadarConstant = Numerator / Denominator
802 # RadarConstant = Numerator / Denominator
803 #
803 #
804 # return RadarConstant
804 # return RadarConstant
805
805
806
806
807
807
808 class FullSpectralAnalysis(Operation):
808 class FullSpectralAnalysis(Operation):
809
809
810 """
810 """
811 Function that implements Full Spectral Analisys technique.
811 Function that implements Full Spectral Analisys technique.
812
812
813 Input:
813 Input:
814 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
814 self.dataOut.data_pre : SelfSpectra and CrossSPectra data
815 self.dataOut.groupList : Pairlist of channels
815 self.dataOut.groupList : Pairlist of channels
816 self.dataOut.ChanDist : Physical distance between receivers
816 self.dataOut.ChanDist : Physical distance between receivers
817
817
818
818
819 Output:
819 Output:
820
820
821 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
821 self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind
822
822
823
823
824 Parameters affected: Winds, height range, SNR
824 Parameters affected: Winds, height range, SNR
825
825
826 """
826 """
827 def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRlimit=7):
827 def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRlimit=7):
828
828
829 self.indice=int(numpy.random.rand()*1000)
829 self.indice=int(numpy.random.rand()*1000)
830
830
831 spc = dataOut.data_pre[0].copy()
831 spc = dataOut.data_pre[0].copy()
832 cspc = dataOut.data_pre[1]
832 cspc = dataOut.data_pre[1]
833
833
834 """NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX"""
834 """NOTA SE DEBE REMOVER EL RANGO DEL PULSO TX"""
835
835
836 SNRspc = spc.copy()
836 SNRspc = spc.copy()
837 SNRspc[:,:,0:7]= numpy.NaN
837 SNRspc[:,:,0:7]= numpy.NaN
838
838
839 """##########################################"""
839 """##########################################"""
840
840
841
841
842 nChannel = spc.shape[0]
842 nChannel = spc.shape[0]
843 nProfiles = spc.shape[1]
843 nProfiles = spc.shape[1]
844 nHeights = spc.shape[2]
844 nHeights = spc.shape[2]
845
845
846 pairsList = dataOut.groupList
846 pairsList = dataOut.groupList
847 if dataOut.ChanDist is not None :
847 if dataOut.ChanDist is not None :
848 ChanDist = dataOut.ChanDist
848 ChanDist = dataOut.ChanDist
849 else:
849 else:
850 ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]])
850 ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]])
851
851
852 FrecRange = dataOut.spc_range[0]
852 FrecRange = dataOut.spc_range[0]
853
853
854 ySamples=numpy.ones([nChannel,nProfiles])
854 ySamples=numpy.ones([nChannel,nProfiles])
855 phase=numpy.ones([nChannel,nProfiles])
855 phase=numpy.ones([nChannel,nProfiles])
856 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
856 CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_)
857 coherence=numpy.ones([nChannel,nProfiles])
857 coherence=numpy.ones([nChannel,nProfiles])
858 PhaseSlope=numpy.ones(nChannel)
858 PhaseSlope=numpy.ones(nChannel)
859 PhaseInter=numpy.ones(nChannel)
859 PhaseInter=numpy.ones(nChannel)
860 data_SNR=numpy.zeros([nProfiles])
860 data_SNR=numpy.zeros([nProfiles])
861
861
862 data = dataOut.data_pre
862 data = dataOut.data_pre
863 noise = dataOut.noise
863 noise = dataOut.noise
864
864
865 dataOut.data_SNR = (numpy.mean(SNRspc,axis=1)- noise[0]) / noise[0]
865 dataOut.data_SNR = (numpy.mean(SNRspc,axis=1)- noise[0]) / noise[0]
866
866
867 dataOut.data_SNR[numpy.where( dataOut.data_SNR <0 )] = 1e-20
867 dataOut.data_SNR[numpy.where( dataOut.data_SNR <0 )] = 1e-20
868
868
869
869
870 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN
870 data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN
871
871
872 velocityX=[]
872 velocityX=[]
873 velocityY=[]
873 velocityY=[]
874 velocityV=[]
874 velocityV=[]
875 PhaseLine=[]
875 PhaseLine=[]
876
876
877 dbSNR = 10*numpy.log10(dataOut.data_SNR)
877 dbSNR = 10*numpy.log10(dataOut.data_SNR)
878 dbSNR = numpy.average(dbSNR,0)
878 dbSNR = numpy.average(dbSNR,0)
879
879
880 for Height in range(nHeights):
880 for Height in range(nHeights):
881
881
882 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range, dbSNR[Height], SNRlimit)
882 [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range, dbSNR[Height], SNRlimit)
883 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
883 PhaseLine = numpy.append(PhaseLine, PhaseSlope)
884
884
885 if abs(Vzon)<100. and abs(Vzon)> 0.:
885 if abs(Vzon)<100. and abs(Vzon)> 0.:
886 velocityX=numpy.append(velocityX, Vzon)#Vmag
886 velocityX=numpy.append(velocityX, Vzon)#Vmag
887
887
888 else:
888 else:
889 velocityX=numpy.append(velocityX, numpy.NaN)
889 velocityX=numpy.append(velocityX, numpy.NaN)
890
890
891 if abs(Vmer)<100. and abs(Vmer) > 0.:
891 if abs(Vmer)<100. and abs(Vmer) > 0.:
892 velocityY=numpy.append(velocityY, -Vmer)#Vang
892 velocityY=numpy.append(velocityY, -Vmer)#Vang
893
893
894 else:
894 else:
895 velocityY=numpy.append(velocityY, numpy.NaN)
895 velocityY=numpy.append(velocityY, numpy.NaN)
896
896
897 if dbSNR[Height] > SNRlimit:
897 if dbSNR[Height] > SNRlimit:
898 velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height])
898 velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height])
899 else:
899 else:
900 velocityV=numpy.append(velocityV, numpy.NaN)
900 velocityV=numpy.append(velocityV, numpy.NaN)
901
901
902
902
903
903
904 '''Nota: Cambiar el signo de numpy.array(velocityX) cuando se intente procesar datos de BLTR'''
904 '''Nota: Cambiar el signo de numpy.array(velocityX) cuando se intente procesar datos de BLTR'''
905 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
905 data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1)
906 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
906 data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1)
907 data_output[2] = velocityV#FirstMoment
907 data_output[2] = velocityV#FirstMoment
908
908
909 xFrec=FrecRange[0:spc.shape[1]]
909 xFrec=FrecRange[0:spc.shape[1]]
910
910
911 dataOut.data_output=data_output
911 dataOut.data_output=data_output
912
912
913 return dataOut
913 return dataOut
914
914
915
915
916 def moving_average(self,x, N=2):
916 def moving_average(self,x, N=2):
917 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
917 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
918
918
919 def gaus(self,xSamples,Amp,Mu,Sigma):
919 def gaus(self,xSamples,Amp,Mu,Sigma):
920 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
920 return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) ))
921
921
922
922
923
923
924 def Moments(self, ySamples, xSamples):
924 def Moments(self, ySamples, xSamples):
925 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
925 Pot = numpy.nansum( ySamples ) # Potencia, momento 0
926 yNorm = ySamples / Pot
926 yNorm = ySamples / Pot
927 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
927 Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento
928 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
928 Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento
929 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
929 Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral
930
930
931 return numpy.array([Pot, Vr, Desv])
931 return numpy.array([Pot, Vr, Desv])
932
932
933 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
933 def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit):
934
934
935
935
936
936
937 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
937 ySamples=numpy.ones([spc.shape[0],spc.shape[1]])
938 phase=numpy.ones([spc.shape[0],spc.shape[1]])
938 phase=numpy.ones([spc.shape[0],spc.shape[1]])
939 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
939 CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_)
940 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
940 coherence=numpy.ones([spc.shape[0],spc.shape[1]])
941 PhaseSlope=numpy.zeros(spc.shape[0])
941 PhaseSlope=numpy.zeros(spc.shape[0])
942 PhaseInter=numpy.ones(spc.shape[0])
942 PhaseInter=numpy.ones(spc.shape[0])
943 xFrec=AbbsisaRange[0][0:spc.shape[1]]
943 xFrec=AbbsisaRange[0][0:spc.shape[1]]
944 xVel =AbbsisaRange[2][0:spc.shape[1]]
944 xVel =AbbsisaRange[2][0:spc.shape[1]]
945 Vv=numpy.empty(spc.shape[2])*0
945 Vv=numpy.empty(spc.shape[2])*0
946 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
946 SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]#
947
947
948 SPCmoments = self.Moments(SPCav[:,Height], xVel )
948 SPCmoments = self.Moments(SPCav[:,Height], xVel )
949 CSPCmoments = []
949 CSPCmoments = []
950 cspcNoise = numpy.empty(3)
950 cspcNoise = numpy.empty(3)
951
951
952 '''Getting Eij and Nij'''
952 '''Getting Eij and Nij'''
953
953
954 Xi01=ChanDist[0][0]
954 Xi01=ChanDist[0][0]
955 Eta01=ChanDist[0][1]
955 Eta01=ChanDist[0][1]
956
956
957 Xi02=ChanDist[1][0]
957 Xi02=ChanDist[1][0]
958 Eta02=ChanDist[1][1]
958 Eta02=ChanDist[1][1]
959
959
960 Xi12=ChanDist[2][0]
960 Xi12=ChanDist[2][0]
961 Eta12=ChanDist[2][1]
961 Eta12=ChanDist[2][1]
962
962
963 z = spc.copy()
963 z = spc.copy()
964 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
964 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
965
965
966 for i in range(spc.shape[0]):
966 for i in range(spc.shape[0]):
967
967
968 '''****** Line of Data SPC ******'''
968 '''****** Line of Data SPC ******'''
969 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
969 zline=z[i,:,Height].copy() - noise[i] # Se resta ruido
970
970
971 '''****** SPC is normalized ******'''
971 '''****** SPC is normalized ******'''
972 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
972 SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido
973 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
973 FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado
974
974
975 xSamples = xFrec # Se toma el rango de frecuncias
975 xSamples = xFrec # Se toma el rango de frecuncias
976 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
976 ySamples[i] = FactNorm # Se toman los valores de SPC normalizado
977
977
978 for i in range(spc.shape[0]):
978 for i in range(spc.shape[0]):
979
979
980 '''****** Line of Data CSPC ******'''
980 '''****** Line of Data CSPC ******'''
981 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
981 cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido
982 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
982 SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido
983 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
983 cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado
984
984
985 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
985 '''****** CSPC is normalized with respect to Briggs and Vincent ******'''
986 chan_index0 = pairsList[i][0]
986 chan_index0 = pairsList[i][0]
987 chan_index1 = pairsList[i][1]
987 chan_index1 = pairsList[i][1]
988
988
989 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
989 CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2
990 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
990 CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor)
991
991
992 CSPCSamples[i] = CSPCNorm
992 CSPCSamples[i] = CSPCNorm
993
993
994 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
994 coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
995
995
996 #coherence[i]= self.moving_average(coherence[i],N=1)
996 #coherence[i]= self.moving_average(coherence[i],N=1)
997
997
998 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
998 phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
999
999
1000 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
1000 CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples),
1001 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
1001 self.Moments(numpy.abs(CSPCSamples[1]), xSamples),
1002 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
1002 self.Moments(numpy.abs(CSPCSamples[2]), xSamples)])
1003
1003
1004
1004
1005 popt=[1e-10,0,1e-10]
1005 popt=[1e-10,0,1e-10]
1006 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
1006 popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10]
1007 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
1007 FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0
1008
1008
1009 CSPCMask01 = numpy.abs(CSPCSamples[0])
1009 CSPCMask01 = numpy.abs(CSPCSamples[0])
1010 CSPCMask02 = numpy.abs(CSPCSamples[1])
1010 CSPCMask02 = numpy.abs(CSPCSamples[1])
1011 CSPCMask12 = numpy.abs(CSPCSamples[2])
1011 CSPCMask12 = numpy.abs(CSPCSamples[2])
1012
1012
1013 mask01 = ~numpy.isnan(CSPCMask01)
1013 mask01 = ~numpy.isnan(CSPCMask01)
1014 mask02 = ~numpy.isnan(CSPCMask02)
1014 mask02 = ~numpy.isnan(CSPCMask02)
1015 mask12 = ~numpy.isnan(CSPCMask12)
1015 mask12 = ~numpy.isnan(CSPCMask12)
1016
1016
1017 #mask = ~numpy.isnan(CSPCMask01)
1017 #mask = ~numpy.isnan(CSPCMask01)
1018 CSPCMask01 = CSPCMask01[mask01]
1018 CSPCMask01 = CSPCMask01[mask01]
1019 CSPCMask02 = CSPCMask02[mask02]
1019 CSPCMask02 = CSPCMask02[mask02]
1020 CSPCMask12 = CSPCMask12[mask12]
1020 CSPCMask12 = CSPCMask12[mask12]
1021 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
1021 #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01)
1022
1022
1023
1023
1024
1024
1025 '''***Fit Gauss CSPC01***'''
1025 '''***Fit Gauss CSPC01***'''
1026 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3 :
1026 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3 :
1027 try:
1027 try:
1028 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
1028 popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0])
1029 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
1029 popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1])
1030 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
1030 popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2])
1031 FitGauss01 = self.gaus(xSamples,*popt01)
1031 FitGauss01 = self.gaus(xSamples,*popt01)
1032 FitGauss02 = self.gaus(xSamples,*popt02)
1032 FitGauss02 = self.gaus(xSamples,*popt02)
1033 FitGauss12 = self.gaus(xSamples,*popt12)
1033 FitGauss12 = self.gaus(xSamples,*popt12)
1034 except:
1034 except:
1035 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
1035 FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0]))
1036 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
1036 FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1]))
1037 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
1037 FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2]))
1038
1038
1039
1039
1040 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1040 CSPCopt = numpy.vstack([popt01,popt02,popt12])
1041
1041
1042 '''****** Getting fij width ******'''
1042 '''****** Getting fij width ******'''
1043
1043
1044 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1044 yMean = numpy.average(ySamples, axis=0) # ySamples[0]
1045
1045
1046 '''******* Getting fitting Gaussian *******'''
1046 '''******* Getting fitting Gaussian *******'''
1047 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1047 meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia)
1048 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1048 sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia)
1049
1049
1050 yMoments = self.Moments(yMean, xSamples)
1050 yMoments = self.Moments(yMean, xSamples)
1051
1051
1052 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3: # and abs(meanGauss/sigma2) > 0.00001:
1052 if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3: # and abs(meanGauss/sigma2) > 0.00001:
1053 try:
1053 try:
1054 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1054 popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments)
1055 FitGauss=self.gaus(xSamples,*popt)
1055 FitGauss=self.gaus(xSamples,*popt)
1056
1056
1057 except :#RuntimeError:
1057 except :#RuntimeError:
1058 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1058 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1059
1059
1060
1060
1061 else:
1061 else:
1062 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1062 FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
1063
1063
1064
1064
1065
1065
1066 '''****** Getting Fij ******'''
1066 '''****** Getting Fij ******'''
1067 Fijcspc = CSPCopt[:,2]/2*3
1067 Fijcspc = CSPCopt[:,2]/2*3
1068
1068
1069
1069
1070 GaussCenter = popt[1] #xFrec[GCpos]
1070 GaussCenter = popt[1] #xFrec[GCpos]
1071 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1071 #Punto en Eje X de la Gaussiana donde se encuentra el centro
1072 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1072 ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()]
1073 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1073 PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0]
1074
1074
1075 #Punto e^-1 hubicado en la Gaussiana
1075 #Punto e^-1 hubicado en la Gaussiana
1076 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1076 PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1)
1077 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1077 FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss"
1078 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1078 PointFij = numpy.where(FitGauss==FijClosest)[0][0]
1079
1079
1080 if xSamples[PointFij] > xSamples[PointGauCenter]:
1080 if xSamples[PointFij] > xSamples[PointGauCenter]:
1081 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1081 Fij = xSamples[PointFij] - xSamples[PointGauCenter]
1082
1082
1083 else:
1083 else:
1084 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1084 Fij = xSamples[PointGauCenter] - xSamples[PointFij]
1085
1085
1086
1086
1087 '''****** Taking frequency ranges from SPCs ******'''
1087 '''****** Taking frequency ranges from SPCs ******'''
1088
1088
1089
1089
1090 #GaussCenter = popt[1] #Primer momento 01
1090 #GaussCenter = popt[1] #Primer momento 01
1091 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1091 GauWidth = popt[2] *3/2 #Ancho de banda de Gau01
1092 Range = numpy.empty(2)
1092 Range = numpy.empty(2)
1093 Range[0] = GaussCenter - GauWidth
1093 Range[0] = GaussCenter - GauWidth
1094 Range[1] = GaussCenter + GauWidth
1094 Range[1] = GaussCenter + GauWidth
1095 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1095 #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max)
1096 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1096 ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()]
1097 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1097 ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()]
1098
1098
1099 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1099 PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0]
1100 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1100 PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0]
1101
1101
1102 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1102 Range=numpy.array([ PointRangeMin, PointRangeMax ])
1103
1103
1104 FrecRange = xFrec[ Range[0] : Range[1] ]
1104 FrecRange = xFrec[ Range[0] : Range[1] ]
1105 VelRange = xVel[ Range[0] : Range[1] ]
1105 VelRange = xVel[ Range[0] : Range[1] ]
1106
1106
1107
1107
1108 '''****** Getting SCPC Slope ******'''
1108 '''****** Getting SCPC Slope ******'''
1109
1109
1110 for i in range(spc.shape[0]):
1110 for i in range(spc.shape[0]):
1111
1111
1112 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.3:
1112 if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.3:
1113 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1113 PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3)
1114
1114
1115 '''***********************VelRange******************'''
1115 '''***********************VelRange******************'''
1116
1116
1117 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1117 mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange)
1118
1118
1119 if len(FrecRange) == len(PhaseRange):
1119 if len(FrecRange) == len(PhaseRange):
1120 try:
1120 try:
1121 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1121 slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask])
1122 PhaseSlope[i]=slope
1122 PhaseSlope[i]=slope
1123 PhaseInter[i]=intercept
1123 PhaseInter[i]=intercept
1124 except:
1124 except:
1125 PhaseSlope[i]=0
1125 PhaseSlope[i]=0
1126 PhaseInter[i]=0
1126 PhaseInter[i]=0
1127 else:
1127 else:
1128 PhaseSlope[i]=0
1128 PhaseSlope[i]=0
1129 PhaseInter[i]=0
1129 PhaseInter[i]=0
1130 else:
1130 else:
1131 PhaseSlope[i]=0
1131 PhaseSlope[i]=0
1132 PhaseInter[i]=0
1132 PhaseInter[i]=0
1133
1133
1134
1134
1135 '''Getting constant C'''
1135 '''Getting constant C'''
1136 cC=(Fij*numpy.pi)**2
1136 cC=(Fij*numpy.pi)**2
1137
1137
1138 '''****** Getting constants F and G ******'''
1138 '''****** Getting constants F and G ******'''
1139 MijEijNij=numpy.array([[Xi02,Eta02], [Xi12,Eta12]])
1139 MijEijNij=numpy.array([[Xi02,Eta02], [Xi12,Eta12]])
1140 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1140 MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
1141 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1141 MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
1142 MijResults=numpy.array([MijResult0,MijResult1])
1142 MijResults=numpy.array([MijResult0,MijResult1])
1143 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1143 (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
1144
1144
1145 '''****** Getting constants A, B and H ******'''
1145 '''****** Getting constants A, B and H ******'''
1146 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1146 W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0]))
1147 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1147 W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1]))
1148 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1148 W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2]))
1149
1149
1150 WijResult0=((cF*Xi01+cG*Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1150 WijResult0=((cF*Xi01+cG*Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1151 WijResult1=((cF*Xi02+cG*Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1151 WijResult1=((cF*Xi02+cG*Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1152 WijResult2=((cF*Xi12+cG*Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1152 WijResult2=((cF*Xi12+cG*Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1153
1153
1154 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1154 WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1155
1155
1156 WijEijNij=numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ])
1156 WijEijNij=numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ])
1157 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1157 (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1158
1158
1159 VxVy=numpy.array([[cA,cH],[cH,cB]])
1159 VxVy=numpy.array([[cA,cH],[cH,cB]])
1160 VxVyResults=numpy.array([-cF,-cG])
1160 VxVyResults=numpy.array([-cF,-cG])
1161 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1161 (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1162
1162
1163 Vzon = Vy
1163 Vzon = Vy
1164 Vmer = Vx
1164 Vmer = Vx
1165 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1165 Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1166 Vang=numpy.arctan2(Vmer,Vzon)
1166 Vang=numpy.arctan2(Vmer,Vzon)
1167 if numpy.abs( popt[1] ) < 3.5 and len(FrecRange)>4:
1167 if numpy.abs( popt[1] ) < 3.5 and len(FrecRange)>4:
1168 Vver=popt[1]
1168 Vver=popt[1]
1169 else:
1169 else:
1170 Vver=numpy.NaN
1170 Vver=numpy.NaN
1171 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1171 FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12])
1172
1172
1173
1173
1174 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1174 return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC
1175
1175
1176 class SpectralMoments(Operation):
1176 class SpectralMoments(Operation):
1177
1177
1178 '''
1178 '''
1179 Function SpectralMoments()
1179 Function SpectralMoments()
1180
1180
1181 Calculates moments (power, mean, standard deviation) and SNR of the signal
1181 Calculates moments (power, mean, standard deviation) and SNR of the signal
1182
1182
1183 Type of dataIn: Spectra
1183 Type of dataIn: Spectra
1184
1184
1185 Configuration Parameters:
1185 Configuration Parameters:
1186
1186
1187 dirCosx : Cosine director in X axis
1187 dirCosx : Cosine director in X axis
1188 dirCosy : Cosine director in Y axis
1188 dirCosy : Cosine director in Y axis
1189
1189
1190 elevation :
1190 elevation :
1191 azimuth :
1191 azimuth :
1192
1192
1193 Input:
1193 Input:
1194 channelList : simple channel list to select e.g. [2,3,7]
1194 channelList : simple channel list to select e.g. [2,3,7]
1195 self.dataOut.data_pre : Spectral data
1195 self.dataOut.data_pre : Spectral data
1196 self.dataOut.abscissaList : List of frequencies
1196 self.dataOut.abscissaList : List of frequencies
1197 self.dataOut.noise : Noise level per channel
1197 self.dataOut.noise : Noise level per channel
1198
1198
1199 Affected:
1199 Affected:
1200 self.dataOut.moments : Parameters per channel
1200 self.dataOut.moments : Parameters per channel
1201 self.dataOut.data_SNR : SNR per channel
1201 self.dataOut.data_SNR : SNR per channel
1202
1202
1203 '''
1203 '''
1204
1204
1205 def run(self, dataOut):
1205 def run(self, dataOut):
1206
1206
1207 #dataOut.data_pre = dataOut.data_pre[0]
1207 #dataOut.data_pre = dataOut.data_pre[0]
1208 data = dataOut.data_pre[0]
1208 data = dataOut.data_pre[0]
1209 absc = dataOut.abscissaList[:-1]
1209 absc = dataOut.abscissaList[:-1]
1210 noise = dataOut.noise
1210 noise = dataOut.noise
1211 nChannel = data.shape[0]
1211 nChannel = data.shape[0]
1212 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1212 data_param = numpy.zeros((nChannel, 4, data.shape[2]))
1213
1213
1214 for ind in range(nChannel):
1214 for ind in range(nChannel):
1215 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1215 data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] )
1216
1216
1217 dataOut.moments = data_param[:,1:,:]
1217 dataOut.moments = data_param[:,1:,:]
1218 dataOut.data_SNR = data_param[:,0]
1218 dataOut.data_SNR = data_param[:,0]
1219 dataOut.data_DOP = data_param[:,1]
1219 dataOut.data_DOP = data_param[:,1]
1220 dataOut.data_MEAN = data_param[:,2]
1220 dataOut.data_MEAN = data_param[:,2]
1221 dataOut.data_STD = data_param[:,3]
1221 dataOut.data_STD = data_param[:,3]
1222 return dataOut
1222 return dataOut
1223
1223
1224 def __calculateMoments(self, oldspec, oldfreq, n0,
1224 def __calculateMoments(self, oldspec, oldfreq, n0,
1225 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1225 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1226
1226
1227 if (nicoh is None): nicoh = 1
1227 if (nicoh is None): nicoh = 1
1228 if (graph is None): graph = 0
1228 if (graph is None): graph = 0
1229 if (smooth is None): smooth = 0
1229 if (smooth is None): smooth = 0
1230 elif (self.smooth < 3): smooth = 0
1230 elif (self.smooth < 3): smooth = 0
1231
1231
1232 if (type1 is None): type1 = 0
1232 if (type1 is None): type1 = 0
1233 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
1233 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
1234 if (snrth is None): snrth = -3
1234 if (snrth is None): snrth = -3
1235 if (dc is None): dc = 0
1235 if (dc is None): dc = 0
1236 if (aliasing is None): aliasing = 0
1236 if (aliasing is None): aliasing = 0
1237 if (oldfd is None): oldfd = 0
1237 if (oldfd is None): oldfd = 0
1238 if (wwauto is None): wwauto = 0
1238 if (wwauto is None): wwauto = 0
1239
1239
1240 if (n0 < 1.e-20): n0 = 1.e-20
1240 if (n0 < 1.e-20): n0 = 1.e-20
1241
1241
1242 freq = oldfreq
1242 freq = oldfreq
1243 vec_power = numpy.zeros(oldspec.shape[1])
1243 vec_power = numpy.zeros(oldspec.shape[1])
1244 vec_fd = numpy.zeros(oldspec.shape[1])
1244 vec_fd = numpy.zeros(oldspec.shape[1])
1245 vec_w = numpy.zeros(oldspec.shape[1])
1245 vec_w = numpy.zeros(oldspec.shape[1])
1246 vec_snr = numpy.zeros(oldspec.shape[1])
1246 vec_snr = numpy.zeros(oldspec.shape[1])
1247
1247
1248 oldspec = numpy.ma.masked_invalid(oldspec)
1248 oldspec = numpy.ma.masked_invalid(oldspec)
1249
1249
1250 for ind in range(oldspec.shape[1]):
1250 for ind in range(oldspec.shape[1]):
1251
1251
1252 spec = oldspec[:,ind]
1252 spec = oldspec[:,ind]
1253 aux = spec*fwindow
1253 aux = spec*fwindow
1254 max_spec = aux.max()
1254 max_spec = aux.max()
1255 m = list(aux).index(max_spec)
1255 m = list(aux).index(max_spec)
1256
1256
1257 #Smooth
1257 #Smooth
1258 if (smooth == 0): spec2 = spec
1258 if (smooth == 0): spec2 = spec
1259 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1259 else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth)
1260
1260
1261 # Calculo de Momentos
1261 # Calculo de Momentos
1262 bb = spec2[list(range(m,spec2.size))]
1262 bb = spec2[list(range(m,spec2.size))]
1263 bb = (bb<n0).nonzero()
1263 bb = (bb<n0).nonzero()
1264 bb = bb[0]
1264 bb = bb[0]
1265
1265
1266 ss = spec2[list(range(0,m + 1))]
1266 ss = spec2[list(range(0,m + 1))]
1267 ss = (ss<n0).nonzero()
1267 ss = (ss<n0).nonzero()
1268 ss = ss[0]
1268 ss = ss[0]
1269
1269
1270 if (bb.size == 0):
1270 if (bb.size == 0):
1271 bb0 = spec.size - 1 - m
1271 bb0 = spec.size - 1 - m
1272 else:
1272 else:
1273 bb0 = bb[0] - 1
1273 bb0 = bb[0] - 1
1274 if (bb0 < 0):
1274 if (bb0 < 0):
1275 bb0 = 0
1275 bb0 = 0
1276
1276
1277 if (ss.size == 0): ss1 = 1
1277 if (ss.size == 0): ss1 = 1
1278 else: ss1 = max(ss) + 1
1278 else: ss1 = max(ss) + 1
1279
1279
1280 if (ss1 > m): ss1 = m
1280 if (ss1 > m): ss1 = m
1281
1281
1282 valid = numpy.asarray(list(range(int(m + bb0 - ss1 + 1)))) + ss1
1282 valid = numpy.asarray(list(range(int(m + bb0 - ss1 + 1)))) + ss1
1283 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1283 power = ((spec2[valid] - n0)*fwindow[valid]).sum()
1284 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1284 fd = ((spec2[valid]- n0)*freq[valid]*fwindow[valid]).sum()/power
1285 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1285 w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power)
1286 snr = (spec2.mean()-n0)/n0
1286 snr = (spec2.mean()-n0)/n0
1287
1287
1288 if (snr < 1.e-20) :
1288 if (snr < 1.e-20) :
1289 snr = 1.e-20
1289 snr = 1.e-20
1290
1290
1291 vec_power[ind] = power
1291 vec_power[ind] = power
1292 vec_fd[ind] = fd
1292 vec_fd[ind] = fd
1293 vec_w[ind] = w
1293 vec_w[ind] = w
1294 vec_snr[ind] = snr
1294 vec_snr[ind] = snr
1295
1295
1296 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1296 moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w))
1297 return moments
1297 return moments
1298
1298
1299 #------------------ Get SA Parameters --------------------------
1299 #------------------ Get SA Parameters --------------------------
1300
1300
1301 def GetSAParameters(self):
1301 def GetSAParameters(self):
1302 #SA en frecuencia
1302 #SA en frecuencia
1303 pairslist = self.dataOut.groupList
1303 pairslist = self.dataOut.groupList
1304 num_pairs = len(pairslist)
1304 num_pairs = len(pairslist)
1305
1305
1306 vel = self.dataOut.abscissaList
1306 vel = self.dataOut.abscissaList
1307 spectra = self.dataOut.data_pre
1307 spectra = self.dataOut.data_pre
1308 cspectra = self.dataIn.data_cspc
1308 cspectra = self.dataIn.data_cspc
1309 delta_v = vel[1] - vel[0]
1309 delta_v = vel[1] - vel[0]
1310
1310
1311 #Calculating the power spectrum
1311 #Calculating the power spectrum
1312 spc_pow = numpy.sum(spectra, 3)*delta_v
1312 spc_pow = numpy.sum(spectra, 3)*delta_v
1313 #Normalizing Spectra
1313 #Normalizing Spectra
1314 norm_spectra = spectra/spc_pow
1314 norm_spectra = spectra/spc_pow
1315 #Calculating the norm_spectra at peak
1315 #Calculating the norm_spectra at peak
1316 max_spectra = numpy.max(norm_spectra, 3)
1316 max_spectra = numpy.max(norm_spectra, 3)
1317
1317
1318 #Normalizing Cross Spectra
1318 #Normalizing Cross Spectra
1319 norm_cspectra = numpy.zeros(cspectra.shape)
1319 norm_cspectra = numpy.zeros(cspectra.shape)
1320
1320
1321 for i in range(num_chan):
1321 for i in range(num_chan):
1322 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1322 norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:])
1323
1323
1324 max_cspectra = numpy.max(norm_cspectra,2)
1324 max_cspectra = numpy.max(norm_cspectra,2)
1325 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1325 max_cspectra_index = numpy.argmax(norm_cspectra, 2)
1326
1326
1327 for i in range(num_pairs):
1327 for i in range(num_pairs):
1328 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1328 cspc_par[i,:,:] = __calculateMoments(norm_cspectra)
1329 #------------------- Get Lags ----------------------------------
1329 #------------------- Get Lags ----------------------------------
1330
1330
1331 class SALags(Operation):
1331 class SALags(Operation):
1332 '''
1332 '''
1333 Function GetMoments()
1333 Function GetMoments()
1334
1334
1335 Input:
1335 Input:
1336 self.dataOut.data_pre
1336 self.dataOut.data_pre
1337 self.dataOut.abscissaList
1337 self.dataOut.abscissaList
1338 self.dataOut.noise
1338 self.dataOut.noise
1339 self.dataOut.normFactor
1339 self.dataOut.normFactor
1340 self.dataOut.data_SNR
1340 self.dataOut.data_SNR
1341 self.dataOut.groupList
1341 self.dataOut.groupList
1342 self.dataOut.nChannels
1342 self.dataOut.nChannels
1343
1343
1344 Affected:
1344 Affected:
1345 self.dataOut.data_param
1345 self.dataOut.data_param
1346
1346
1347 '''
1347 '''
1348 def run(self, dataOut):
1348 def run(self, dataOut):
1349 data_acf = dataOut.data_pre[0]
1349 data_acf = dataOut.data_pre[0]
1350 data_ccf = dataOut.data_pre[1]
1350 data_ccf = dataOut.data_pre[1]
1351 normFactor_acf = dataOut.normFactor[0]
1351 normFactor_acf = dataOut.normFactor[0]
1352 normFactor_ccf = dataOut.normFactor[1]
1352 normFactor_ccf = dataOut.normFactor[1]
1353 pairs_acf = dataOut.groupList[0]
1353 pairs_acf = dataOut.groupList[0]
1354 pairs_ccf = dataOut.groupList[1]
1354 pairs_ccf = dataOut.groupList[1]
1355
1355
1356 nHeights = dataOut.nHeights
1356 nHeights = dataOut.nHeights
1357 absc = dataOut.abscissaList
1357 absc = dataOut.abscissaList
1358 noise = dataOut.noise
1358 noise = dataOut.noise
1359 SNR = dataOut.data_SNR
1359 SNR = dataOut.data_SNR
1360 nChannels = dataOut.nChannels
1360 nChannels = dataOut.nChannels
1361 # pairsList = dataOut.groupList
1361 # pairsList = dataOut.groupList
1362 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1362 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels)
1363
1363
1364 for l in range(len(pairs_acf)):
1364 for l in range(len(pairs_acf)):
1365 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1365 data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:]
1366
1366
1367 for l in range(len(pairs_ccf)):
1367 for l in range(len(pairs_ccf)):
1368 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1368 data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:]
1369
1369
1370 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1370 dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights))
1371 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1371 dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc)
1372 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1372 dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc)
1373 return
1373 return
1374
1374
1375 # def __getPairsAutoCorr(self, pairsList, nChannels):
1375 # def __getPairsAutoCorr(self, pairsList, nChannels):
1376 #
1376 #
1377 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1377 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1378 #
1378 #
1379 # for l in range(len(pairsList)):
1379 # for l in range(len(pairsList)):
1380 # firstChannel = pairsList[l][0]
1380 # firstChannel = pairsList[l][0]
1381 # secondChannel = pairsList[l][1]
1381 # secondChannel = pairsList[l][1]
1382 #
1382 #
1383 # #Obteniendo pares de Autocorrelacion
1383 # #Obteniendo pares de Autocorrelacion
1384 # if firstChannel == secondChannel:
1384 # if firstChannel == secondChannel:
1385 # pairsAutoCorr[firstChannel] = int(l)
1385 # pairsAutoCorr[firstChannel] = int(l)
1386 #
1386 #
1387 # pairsAutoCorr = pairsAutoCorr.astype(int)
1387 # pairsAutoCorr = pairsAutoCorr.astype(int)
1388 #
1388 #
1389 # pairsCrossCorr = range(len(pairsList))
1389 # pairsCrossCorr = range(len(pairsList))
1390 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1390 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1391 #
1391 #
1392 # return pairsAutoCorr, pairsCrossCorr
1392 # return pairsAutoCorr, pairsCrossCorr
1393
1393
1394 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1394 def __calculateTaus(self, data_acf, data_ccf, lagRange):
1395
1395
1396 lag0 = data_acf.shape[1]/2
1396 lag0 = data_acf.shape[1]/2
1397 #Funcion de Autocorrelacion
1397 #Funcion de Autocorrelacion
1398 mean_acf = stats.nanmean(data_acf, axis = 0)
1398 mean_acf = stats.nanmean(data_acf, axis = 0)
1399
1399
1400 #Obtencion Indice de TauCross
1400 #Obtencion Indice de TauCross
1401 ind_ccf = data_ccf.argmax(axis = 1)
1401 ind_ccf = data_ccf.argmax(axis = 1)
1402 #Obtencion Indice de TauAuto
1402 #Obtencion Indice de TauAuto
1403 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1403 ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int')
1404 ccf_lag0 = data_ccf[:,lag0,:]
1404 ccf_lag0 = data_ccf[:,lag0,:]
1405
1405
1406 for i in range(ccf_lag0.shape[0]):
1406 for i in range(ccf_lag0.shape[0]):
1407 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1407 ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0)
1408
1408
1409 #Obtencion de TauCross y TauAuto
1409 #Obtencion de TauCross y TauAuto
1410 tau_ccf = lagRange[ind_ccf]
1410 tau_ccf = lagRange[ind_ccf]
1411 tau_acf = lagRange[ind_acf]
1411 tau_acf = lagRange[ind_acf]
1412
1412
1413 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1413 Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0])
1414
1414
1415 tau_ccf[Nan1,Nan2] = numpy.nan
1415 tau_ccf[Nan1,Nan2] = numpy.nan
1416 tau_acf[Nan1,Nan2] = numpy.nan
1416 tau_acf[Nan1,Nan2] = numpy.nan
1417 tau = numpy.vstack((tau_ccf,tau_acf))
1417 tau = numpy.vstack((tau_ccf,tau_acf))
1418
1418
1419 return tau
1419 return tau
1420
1420
1421 def __calculateLag1Phase(self, data, lagTRange):
1421 def __calculateLag1Phase(self, data, lagTRange):
1422 data1 = stats.nanmean(data, axis = 0)
1422 data1 = stats.nanmean(data, axis = 0)
1423 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1423 lag1 = numpy.where(lagTRange == 0)[0][0] + 1
1424
1424
1425 phase = numpy.angle(data1[lag1,:])
1425 phase = numpy.angle(data1[lag1,:])
1426
1426
1427 return phase
1427 return phase
1428
1428
1429 class SpectralFitting(Operation):
1429 class SpectralFitting(Operation):
1430 '''
1430 '''
1431 Function GetMoments()
1431 Function GetMoments()
1432
1432
1433 Input:
1433 Input:
1434 Output:
1434 Output:
1435 Variables modified:
1435 Variables modified:
1436 '''
1436 '''
1437
1437
1438 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1438 def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None):
1439
1439
1440
1440
1441 if path != None:
1441 if path != None:
1442 sys.path.append(path)
1442 sys.path.append(path)
1443 self.dataOut.library = importlib.import_module(file)
1443 self.dataOut.library = importlib.import_module(file)
1444
1444
1445 #To be inserted as a parameter
1445 #To be inserted as a parameter
1446 groupArray = numpy.array(groupList)
1446 groupArray = numpy.array(groupList)
1447 # groupArray = numpy.array([[0,1],[2,3]])
1447 # groupArray = numpy.array([[0,1],[2,3]])
1448 self.dataOut.groupList = groupArray
1448 self.dataOut.groupList = groupArray
1449
1449
1450 nGroups = groupArray.shape[0]
1450 nGroups = groupArray.shape[0]
1451 nChannels = self.dataIn.nChannels
1451 nChannels = self.dataIn.nChannels
1452 nHeights=self.dataIn.heightList.size
1452 nHeights=self.dataIn.heightList.size
1453
1453
1454 #Parameters Array
1454 #Parameters Array
1455 self.dataOut.data_param = None
1455 self.dataOut.data_param = None
1456
1456
1457 #Set constants
1457 #Set constants
1458 constants = self.dataOut.library.setConstants(self.dataIn)
1458 constants = self.dataOut.library.setConstants(self.dataIn)
1459 self.dataOut.constants = constants
1459 self.dataOut.constants = constants
1460 M = self.dataIn.normFactor
1460 M = self.dataIn.normFactor
1461 N = self.dataIn.nFFTPoints
1461 N = self.dataIn.nFFTPoints
1462 ippSeconds = self.dataIn.ippSeconds
1462 ippSeconds = self.dataIn.ippSeconds
1463 K = self.dataIn.nIncohInt
1463 K = self.dataIn.nIncohInt
1464 pairsArray = numpy.array(self.dataIn.pairsList)
1464 pairsArray = numpy.array(self.dataIn.pairsList)
1465
1465
1466 #List of possible combinations
1466 #List of possible combinations
1467 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1467 listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2)
1468 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1468 indCross = numpy.zeros(len(list(listComb)), dtype = 'int')
1469
1469
1470 if getSNR:
1470 if getSNR:
1471 listChannels = groupArray.reshape((groupArray.size))
1471 listChannels = groupArray.reshape((groupArray.size))
1472 listChannels.sort()
1472 listChannels.sort()
1473 noise = self.dataIn.getNoise()
1473 noise = self.dataIn.getNoise()
1474 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1474 self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels])
1475
1475
1476 for i in range(nGroups):
1476 for i in range(nGroups):
1477 coord = groupArray[i,:]
1477 coord = groupArray[i,:]
1478
1478
1479 #Input data array
1479 #Input data array
1480 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1480 data = self.dataIn.data_spc[coord,:,:]/(M*N)
1481 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1481 data = data.reshape((data.shape[0]*data.shape[1],data.shape[2]))
1482
1482
1483 #Cross Spectra data array for Covariance Matrixes
1483 #Cross Spectra data array for Covariance Matrixes
1484 ind = 0
1484 ind = 0
1485 for pairs in listComb:
1485 for pairs in listComb:
1486 pairsSel = numpy.array([coord[x],coord[y]])
1486 pairsSel = numpy.array([coord[x],coord[y]])
1487 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1487 indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0])
1488 ind += 1
1488 ind += 1
1489 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1489 dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N)
1490 dataCross = dataCross**2/K
1490 dataCross = dataCross**2/K
1491
1491
1492 for h in range(nHeights):
1492 for h in range(nHeights):
1493
1493
1494 #Input
1494 #Input
1495 d = data[:,h]
1495 d = data[:,h]
1496
1496
1497 #Covariance Matrix
1497 #Covariance Matrix
1498 D = numpy.diag(d**2/K)
1498 D = numpy.diag(d**2/K)
1499 ind = 0
1499 ind = 0
1500 for pairs in listComb:
1500 for pairs in listComb:
1501 #Coordinates in Covariance Matrix
1501 #Coordinates in Covariance Matrix
1502 x = pairs[0]
1502 x = pairs[0]
1503 y = pairs[1]
1503 y = pairs[1]
1504 #Channel Index
1504 #Channel Index
1505 S12 = dataCross[ind,:,h]
1505 S12 = dataCross[ind,:,h]
1506 D12 = numpy.diag(S12)
1506 D12 = numpy.diag(S12)
1507 #Completing Covariance Matrix with Cross Spectras
1507 #Completing Covariance Matrix with Cross Spectras
1508 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1508 D[x*N:(x+1)*N,y*N:(y+1)*N] = D12
1509 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1509 D[y*N:(y+1)*N,x*N:(x+1)*N] = D12
1510 ind += 1
1510 ind += 1
1511 Dinv=numpy.linalg.inv(D)
1511 Dinv=numpy.linalg.inv(D)
1512 L=numpy.linalg.cholesky(Dinv)
1512 L=numpy.linalg.cholesky(Dinv)
1513 LT=L.T
1513 LT=L.T
1514
1514
1515 dp = numpy.dot(LT,d)
1515 dp = numpy.dot(LT,d)
1516
1516
1517 #Initial values
1517 #Initial values
1518 data_spc = self.dataIn.data_spc[coord,:,h]
1518 data_spc = self.dataIn.data_spc[coord,:,h]
1519
1519
1520 if (h>0)and(error1[3]<5):
1520 if (h>0)and(error1[3]<5):
1521 p0 = self.dataOut.data_param[i,:,h-1]
1521 p0 = self.dataOut.data_param[i,:,h-1]
1522 else:
1522 else:
1523 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1523 p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i))
1524
1524
1525 try:
1525 try:
1526 #Least Squares
1526 #Least Squares
1527 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1527 minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True)
1528 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1528 # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants))
1529 #Chi square error
1529 #Chi square error
1530 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1530 error0 = numpy.sum(infodict['fvec']**2)/(2*N)
1531 #Error with Jacobian
1531 #Error with Jacobian
1532 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1532 error1 = self.dataOut.library.errorFunction(minp,constants,LT)
1533 except:
1533 except:
1534 minp = p0*numpy.nan
1534 minp = p0*numpy.nan
1535 error0 = numpy.nan
1535 error0 = numpy.nan
1536 error1 = p0*numpy.nan
1536 error1 = p0*numpy.nan
1537
1537
1538 #Save
1538 #Save
1539 if self.dataOut.data_param is None:
1539 if self.dataOut.data_param is None:
1540 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1540 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1541 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1541 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1542
1542
1543 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1543 self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1))
1544 self.dataOut.data_param[i,:,h] = minp
1544 self.dataOut.data_param[i,:,h] = minp
1545 return
1545 return
1546
1546
1547 def __residFunction(self, p, dp, LT, constants):
1547 def __residFunction(self, p, dp, LT, constants):
1548
1548
1549 fm = self.dataOut.library.modelFunction(p, constants)
1549 fm = self.dataOut.library.modelFunction(p, constants)
1550 fmp=numpy.dot(LT,fm)
1550 fmp=numpy.dot(LT,fm)
1551
1551
1552 return dp-fmp
1552 return dp-fmp
1553
1553
1554 def __getSNR(self, z, noise):
1554 def __getSNR(self, z, noise):
1555
1555
1556 avg = numpy.average(z, axis=1)
1556 avg = numpy.average(z, axis=1)
1557 SNR = (avg.T-noise)/noise
1557 SNR = (avg.T-noise)/noise
1558 SNR = SNR.T
1558 SNR = SNR.T
1559 return SNR
1559 return SNR
1560
1560
1561 def __chisq(p,chindex,hindex):
1561 def __chisq(p,chindex,hindex):
1562 #similar to Resid but calculates CHI**2
1562 #similar to Resid but calculates CHI**2
1563 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1563 [LT,d,fm]=setupLTdfm(p,chindex,hindex)
1564 dp=numpy.dot(LT,d)
1564 dp=numpy.dot(LT,d)
1565 fmp=numpy.dot(LT,fm)
1565 fmp=numpy.dot(LT,fm)
1566 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1566 chisq=numpy.dot((dp-fmp).T,(dp-fmp))
1567 return chisq
1567 return chisq
1568
1568
1569 class WindProfiler(Operation):
1569 class WindProfiler(Operation):
1570
1570
1571 __isConfig = False
1571 __isConfig = False
1572
1572
1573 __initime = None
1573 __initime = None
1574 __lastdatatime = None
1574 __lastdatatime = None
1575 __integrationtime = None
1575 __integrationtime = None
1576
1576
1577 __buffer = None
1577 __buffer = None
1578
1578
1579 __dataReady = False
1579 __dataReady = False
1580
1580
1581 __firstdata = None
1581 __firstdata = None
1582
1582
1583 n = None
1583 n = None
1584
1584
1585 def __init__(self):
1585 def __init__(self):
1586 Operation.__init__(self)
1586 Operation.__init__(self)
1587
1587
1588 def __calculateCosDir(self, elev, azim):
1588 def __calculateCosDir(self, elev, azim):
1589 zen = (90 - elev)*numpy.pi/180
1589 zen = (90 - elev)*numpy.pi/180
1590 azim = azim*numpy.pi/180
1590 azim = azim*numpy.pi/180
1591 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1591 cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2)))
1592 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1592 cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2)
1593
1593
1594 signX = numpy.sign(numpy.cos(azim))
1594 signX = numpy.sign(numpy.cos(azim))
1595 signY = numpy.sign(numpy.sin(azim))
1595 signY = numpy.sign(numpy.sin(azim))
1596
1596
1597 cosDirX = numpy.copysign(cosDirX, signX)
1597 cosDirX = numpy.copysign(cosDirX, signX)
1598 cosDirY = numpy.copysign(cosDirY, signY)
1598 cosDirY = numpy.copysign(cosDirY, signY)
1599 return cosDirX, cosDirY
1599 return cosDirX, cosDirY
1600
1600
1601 def __calculateAngles(self, theta_x, theta_y, azimuth):
1601 def __calculateAngles(self, theta_x, theta_y, azimuth):
1602
1602
1603 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1603 dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2)
1604 zenith_arr = numpy.arccos(dir_cosw)
1604 zenith_arr = numpy.arccos(dir_cosw)
1605 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1605 azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180
1606
1606
1607 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1607 dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr)
1608 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1608 dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr)
1609
1609
1610 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1610 return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw
1611
1611
1612 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1612 def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly):
1613
1613
1614 #
1614 #
1615 if horOnly:
1615 if horOnly:
1616 A = numpy.c_[dir_cosu,dir_cosv]
1616 A = numpy.c_[dir_cosu,dir_cosv]
1617 else:
1617 else:
1618 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1618 A = numpy.c_[dir_cosu,dir_cosv,dir_cosw]
1619 A = numpy.asmatrix(A)
1619 A = numpy.asmatrix(A)
1620 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1620 A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose()
1621
1621
1622 return A1
1622 return A1
1623
1623
1624 def __correctValues(self, heiRang, phi, velRadial, SNR):
1624 def __correctValues(self, heiRang, phi, velRadial, SNR):
1625 listPhi = phi.tolist()
1625 listPhi = phi.tolist()
1626 maxid = listPhi.index(max(listPhi))
1626 maxid = listPhi.index(max(listPhi))
1627 minid = listPhi.index(min(listPhi))
1627 minid = listPhi.index(min(listPhi))
1628
1628
1629 rango = list(range(len(phi)))
1629 rango = list(range(len(phi)))
1630 # rango = numpy.delete(rango,maxid)
1630 # rango = numpy.delete(rango,maxid)
1631
1631
1632 heiRang1 = heiRang*math.cos(phi[maxid])
1632 heiRang1 = heiRang*math.cos(phi[maxid])
1633 heiRangAux = heiRang*math.cos(phi[minid])
1633 heiRangAux = heiRang*math.cos(phi[minid])
1634 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1634 indOut = (heiRang1 < heiRangAux[0]).nonzero()
1635 heiRang1 = numpy.delete(heiRang1,indOut)
1635 heiRang1 = numpy.delete(heiRang1,indOut)
1636
1636
1637 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1637 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
1638 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1638 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
1639
1639
1640 for i in rango:
1640 for i in rango:
1641 x = heiRang*math.cos(phi[i])
1641 x = heiRang*math.cos(phi[i])
1642 y1 = velRadial[i,:]
1642 y1 = velRadial[i,:]
1643 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1643 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
1644
1644
1645 x1 = heiRang1
1645 x1 = heiRang1
1646 y11 = f1(x1)
1646 y11 = f1(x1)
1647
1647
1648 y2 = SNR[i,:]
1648 y2 = SNR[i,:]
1649 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1649 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
1650 y21 = f2(x1)
1650 y21 = f2(x1)
1651
1651
1652 velRadial1[i,:] = y11
1652 velRadial1[i,:] = y11
1653 SNR1[i,:] = y21
1653 SNR1[i,:] = y21
1654
1654
1655 return heiRang1, velRadial1, SNR1
1655 return heiRang1, velRadial1, SNR1
1656
1656
1657 def __calculateVelUVW(self, A, velRadial):
1657 def __calculateVelUVW(self, A, velRadial):
1658
1658
1659 #Operacion Matricial
1659 #Operacion Matricial
1660 # velUVW = numpy.zeros((velRadial.shape[1],3))
1660 # velUVW = numpy.zeros((velRadial.shape[1],3))
1661 # for ind in range(velRadial.shape[1]):
1661 # for ind in range(velRadial.shape[1]):
1662 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1662 # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind])
1663 # velUVW = velUVW.transpose()
1663 # velUVW = velUVW.transpose()
1664 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1664 velUVW = numpy.zeros((A.shape[0],velRadial.shape[1]))
1665 velUVW[:,:] = numpy.dot(A,velRadial)
1665 velUVW[:,:] = numpy.dot(A,velRadial)
1666
1666
1667
1667
1668 return velUVW
1668 return velUVW
1669
1669
1670 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1670 # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0):
1671
1671
1672 def techniqueDBS(self, kwargs):
1672 def techniqueDBS(self, kwargs):
1673 """
1673 """
1674 Function that implements Doppler Beam Swinging (DBS) technique.
1674 Function that implements Doppler Beam Swinging (DBS) technique.
1675
1675
1676 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1676 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1677 Direction correction (if necessary), Ranges and SNR
1677 Direction correction (if necessary), Ranges and SNR
1678
1678
1679 Output: Winds estimation (Zonal, Meridional and Vertical)
1679 Output: Winds estimation (Zonal, Meridional and Vertical)
1680
1680
1681 Parameters affected: Winds, height range, SNR
1681 Parameters affected: Winds, height range, SNR
1682 """
1682 """
1683 velRadial0 = kwargs['velRadial']
1683 velRadial0 = kwargs['velRadial']
1684 heiRang = kwargs['heightList']
1684 heiRang = kwargs['heightList']
1685 SNR0 = kwargs['SNR']
1685 SNR0 = kwargs['SNR']
1686
1686
1687 if 'dirCosx' in kwargs and 'dirCosy' in kwargs:
1687 if 'dirCosx' in kwargs and 'dirCosy' in kwargs:
1688 theta_x = numpy.array(kwargs['dirCosx'])
1688 theta_x = numpy.array(kwargs['dirCosx'])
1689 theta_y = numpy.array(kwargs['dirCosy'])
1689 theta_y = numpy.array(kwargs['dirCosy'])
1690 else:
1690 else:
1691 elev = numpy.array(kwargs['elevation'])
1691 elev = numpy.array(kwargs['elevation'])
1692 azim = numpy.array(kwargs['azimuth'])
1692 azim = numpy.array(kwargs['azimuth'])
1693 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1693 theta_x, theta_y = self.__calculateCosDir(elev, azim)
1694 azimuth = kwargs['correctAzimuth']
1694 azimuth = kwargs['correctAzimuth']
1695 if 'horizontalOnly' in kwargs:
1695 if 'horizontalOnly' in kwargs:
1696 horizontalOnly = kwargs['horizontalOnly']
1696 horizontalOnly = kwargs['horizontalOnly']
1697 else: horizontalOnly = False
1697 else: horizontalOnly = False
1698 if 'correctFactor' in kwargs:
1698 if 'correctFactor' in kwargs:
1699 correctFactor = kwargs['correctFactor']
1699 correctFactor = kwargs['correctFactor']
1700 else: correctFactor = 1
1700 else: correctFactor = 1
1701 if 'channelList' in kwargs:
1701 if 'channelList' in kwargs:
1702 channelList = kwargs['channelList']
1702 channelList = kwargs['channelList']
1703 if len(channelList) == 2:
1703 if len(channelList) == 2:
1704 horizontalOnly = True
1704 horizontalOnly = True
1705 arrayChannel = numpy.array(channelList)
1705 arrayChannel = numpy.array(channelList)
1706 param = param[arrayChannel,:,:]
1706 param = param[arrayChannel,:,:]
1707 theta_x = theta_x[arrayChannel]
1707 theta_x = theta_x[arrayChannel]
1708 theta_y = theta_y[arrayChannel]
1708 theta_y = theta_y[arrayChannel]
1709
1709
1710 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1710 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
1711 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1711 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0)
1712 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1712 A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly)
1713
1713
1714 #Calculo de Componentes de la velocidad con DBS
1714 #Calculo de Componentes de la velocidad con DBS
1715 winds = self.__calculateVelUVW(A,velRadial1)
1715 winds = self.__calculateVelUVW(A,velRadial1)
1716
1716
1717 return winds, heiRang1, SNR1
1717 return winds, heiRang1, SNR1
1718
1718
1719 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1719 def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None):
1720
1720
1721 nPairs = len(pairs_ccf)
1721 nPairs = len(pairs_ccf)
1722 posx = numpy.asarray(posx)
1722 posx = numpy.asarray(posx)
1723 posy = numpy.asarray(posy)
1723 posy = numpy.asarray(posy)
1724
1724
1725 #Rotacion Inversa para alinear con el azimuth
1725 #Rotacion Inversa para alinear con el azimuth
1726 if azimuth!= None:
1726 if azimuth!= None:
1727 azimuth = azimuth*math.pi/180
1727 azimuth = azimuth*math.pi/180
1728 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1728 posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth)
1729 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1729 posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth)
1730 else:
1730 else:
1731 posx1 = posx
1731 posx1 = posx
1732 posy1 = posy
1732 posy1 = posy
1733
1733
1734 #Calculo de Distancias
1734 #Calculo de Distancias
1735 distx = numpy.zeros(nPairs)
1735 distx = numpy.zeros(nPairs)
1736 disty = numpy.zeros(nPairs)
1736 disty = numpy.zeros(nPairs)
1737 dist = numpy.zeros(nPairs)
1737 dist = numpy.zeros(nPairs)
1738 ang = numpy.zeros(nPairs)
1738 ang = numpy.zeros(nPairs)
1739
1739
1740 for i in range(nPairs):
1740 for i in range(nPairs):
1741 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1741 distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]]
1742 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1742 disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]]
1743 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1743 dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2)
1744 ang[i] = numpy.arctan2(disty[i],distx[i])
1744 ang[i] = numpy.arctan2(disty[i],distx[i])
1745
1745
1746 return distx, disty, dist, ang
1746 return distx, disty, dist, ang
1747 #Calculo de Matrices
1747 #Calculo de Matrices
1748 # nPairs = len(pairs)
1748 # nPairs = len(pairs)
1749 # ang1 = numpy.zeros((nPairs, 2, 1))
1749 # ang1 = numpy.zeros((nPairs, 2, 1))
1750 # dist1 = numpy.zeros((nPairs, 2, 1))
1750 # dist1 = numpy.zeros((nPairs, 2, 1))
1751 #
1751 #
1752 # for j in range(nPairs):
1752 # for j in range(nPairs):
1753 # dist1[j,0,0] = dist[pairs[j][0]]
1753 # dist1[j,0,0] = dist[pairs[j][0]]
1754 # dist1[j,1,0] = dist[pairs[j][1]]
1754 # dist1[j,1,0] = dist[pairs[j][1]]
1755 # ang1[j,0,0] = ang[pairs[j][0]]
1755 # ang1[j,0,0] = ang[pairs[j][0]]
1756 # ang1[j,1,0] = ang[pairs[j][1]]
1756 # ang1[j,1,0] = ang[pairs[j][1]]
1757 #
1757 #
1758 # return distx,disty, dist1,ang1
1758 # return distx,disty, dist1,ang1
1759
1759
1760
1760
1761 def __calculateVelVer(self, phase, lagTRange, _lambda):
1761 def __calculateVelVer(self, phase, lagTRange, _lambda):
1762
1762
1763 Ts = lagTRange[1] - lagTRange[0]
1763 Ts = lagTRange[1] - lagTRange[0]
1764 velW = -_lambda*phase/(4*math.pi*Ts)
1764 velW = -_lambda*phase/(4*math.pi*Ts)
1765
1765
1766 return velW
1766 return velW
1767
1767
1768 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1768 def __calculateVelHorDir(self, dist, tau1, tau2, ang):
1769 nPairs = tau1.shape[0]
1769 nPairs = tau1.shape[0]
1770 nHeights = tau1.shape[1]
1770 nHeights = tau1.shape[1]
1771 vel = numpy.zeros((nPairs,3,nHeights))
1771 vel = numpy.zeros((nPairs,3,nHeights))
1772 dist1 = numpy.reshape(dist, (dist.size,1))
1772 dist1 = numpy.reshape(dist, (dist.size,1))
1773
1773
1774 angCos = numpy.cos(ang)
1774 angCos = numpy.cos(ang)
1775 angSin = numpy.sin(ang)
1775 angSin = numpy.sin(ang)
1776
1776
1777 vel0 = dist1*tau1/(2*tau2**2)
1777 vel0 = dist1*tau1/(2*tau2**2)
1778 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1778 vel[:,0,:] = (vel0*angCos).sum(axis = 1)
1779 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1779 vel[:,1,:] = (vel0*angSin).sum(axis = 1)
1780
1780
1781 ind = numpy.where(numpy.isinf(vel))
1781 ind = numpy.where(numpy.isinf(vel))
1782 vel[ind] = numpy.nan
1782 vel[ind] = numpy.nan
1783
1783
1784 return vel
1784 return vel
1785
1785
1786 # def __getPairsAutoCorr(self, pairsList, nChannels):
1786 # def __getPairsAutoCorr(self, pairsList, nChannels):
1787 #
1787 #
1788 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1788 # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan
1789 #
1789 #
1790 # for l in range(len(pairsList)):
1790 # for l in range(len(pairsList)):
1791 # firstChannel = pairsList[l][0]
1791 # firstChannel = pairsList[l][0]
1792 # secondChannel = pairsList[l][1]
1792 # secondChannel = pairsList[l][1]
1793 #
1793 #
1794 # #Obteniendo pares de Autocorrelacion
1794 # #Obteniendo pares de Autocorrelacion
1795 # if firstChannel == secondChannel:
1795 # if firstChannel == secondChannel:
1796 # pairsAutoCorr[firstChannel] = int(l)
1796 # pairsAutoCorr[firstChannel] = int(l)
1797 #
1797 #
1798 # pairsAutoCorr = pairsAutoCorr.astype(int)
1798 # pairsAutoCorr = pairsAutoCorr.astype(int)
1799 #
1799 #
1800 # pairsCrossCorr = range(len(pairsList))
1800 # pairsCrossCorr = range(len(pairsList))
1801 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1801 # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr)
1802 #
1802 #
1803 # return pairsAutoCorr, pairsCrossCorr
1803 # return pairsAutoCorr, pairsCrossCorr
1804
1804
1805 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1805 # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor):
1806 def techniqueSA(self, kwargs):
1806 def techniqueSA(self, kwargs):
1807
1807
1808 """
1808 """
1809 Function that implements Spaced Antenna (SA) technique.
1809 Function that implements Spaced Antenna (SA) technique.
1810
1810
1811 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1811 Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth,
1812 Direction correction (if necessary), Ranges and SNR
1812 Direction correction (if necessary), Ranges and SNR
1813
1813
1814 Output: Winds estimation (Zonal, Meridional and Vertical)
1814 Output: Winds estimation (Zonal, Meridional and Vertical)
1815
1815
1816 Parameters affected: Winds
1816 Parameters affected: Winds
1817 """
1817 """
1818 position_x = kwargs['positionX']
1818 position_x = kwargs['positionX']
1819 position_y = kwargs['positionY']
1819 position_y = kwargs['positionY']
1820 azimuth = kwargs['azimuth']
1820 azimuth = kwargs['azimuth']
1821
1821
1822 if 'correctFactor' in kwargs:
1822 if 'correctFactor' in kwargs:
1823 correctFactor = kwargs['correctFactor']
1823 correctFactor = kwargs['correctFactor']
1824 else:
1824 else:
1825 correctFactor = 1
1825 correctFactor = 1
1826
1826
1827 groupList = kwargs['groupList']
1827 groupList = kwargs['groupList']
1828 pairs_ccf = groupList[1]
1828 pairs_ccf = groupList[1]
1829 tau = kwargs['tau']
1829 tau = kwargs['tau']
1830 _lambda = kwargs['_lambda']
1830 _lambda = kwargs['_lambda']
1831
1831
1832 #Cross Correlation pairs obtained
1832 #Cross Correlation pairs obtained
1833 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
1833 # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels)
1834 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1834 # pairsArray = numpy.array(pairsList)[pairsCrossCorr]
1835 # pairsSelArray = numpy.array(pairsSelected)
1835 # pairsSelArray = numpy.array(pairsSelected)
1836 # pairs = []
1836 # pairs = []
1837 #
1837 #
1838 # #Wind estimation pairs obtained
1838 # #Wind estimation pairs obtained
1839 # for i in range(pairsSelArray.shape[0]/2):
1839 # for i in range(pairsSelArray.shape[0]/2):
1840 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1840 # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0]
1841 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1841 # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0]
1842 # pairs.append((ind1,ind2))
1842 # pairs.append((ind1,ind2))
1843
1843
1844 indtau = tau.shape[0]/2
1844 indtau = tau.shape[0]/2
1845 tau1 = tau[:indtau,:]
1845 tau1 = tau[:indtau,:]
1846 tau2 = tau[indtau:-1,:]
1846 tau2 = tau[indtau:-1,:]
1847 # tau1 = tau1[pairs,:]
1847 # tau1 = tau1[pairs,:]
1848 # tau2 = tau2[pairs,:]
1848 # tau2 = tau2[pairs,:]
1849 phase1 = tau[-1,:]
1849 phase1 = tau[-1,:]
1850
1850
1851 #---------------------------------------------------------------------
1851 #---------------------------------------------------------------------
1852 #Metodo Directo
1852 #Metodo Directo
1853 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
1853 distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth)
1854 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1854 winds = self.__calculateVelHorDir(dist, tau1, tau2, ang)
1855 winds = stats.nanmean(winds, axis=0)
1855 winds = stats.nanmean(winds, axis=0)
1856 #---------------------------------------------------------------------
1856 #---------------------------------------------------------------------
1857 #Metodo General
1857 #Metodo General
1858 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1858 # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth)
1859 # #Calculo Coeficientes de Funcion de Correlacion
1859 # #Calculo Coeficientes de Funcion de Correlacion
1860 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1860 # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n)
1861 # #Calculo de Velocidades
1861 # #Calculo de Velocidades
1862 # winds = self.calculateVelUV(F,G,A,B,H)
1862 # winds = self.calculateVelUV(F,G,A,B,H)
1863
1863
1864 #---------------------------------------------------------------------
1864 #---------------------------------------------------------------------
1865 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1865 winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda)
1866 winds = correctFactor*winds
1866 winds = correctFactor*winds
1867 return winds
1867 return winds
1868
1868
1869 def __checkTime(self, currentTime, paramInterval, outputInterval):
1869 def __checkTime(self, currentTime, paramInterval, outputInterval):
1870
1870
1871 dataTime = currentTime + paramInterval
1871 dataTime = currentTime + paramInterval
1872 deltaTime = dataTime - self.__initime
1872 deltaTime = dataTime - self.__initime
1873
1873
1874 if deltaTime >= outputInterval or deltaTime < 0:
1874 if deltaTime >= outputInterval or deltaTime < 0:
1875 self.__dataReady = True
1875 self.__dataReady = True
1876 return
1876 return
1877
1877
1878 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1878 def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax):
1879 '''
1879 '''
1880 Function that implements winds estimation technique with detected meteors.
1880 Function that implements winds estimation technique with detected meteors.
1881
1881
1882 Input: Detected meteors, Minimum meteor quantity to wind estimation
1882 Input: Detected meteors, Minimum meteor quantity to wind estimation
1883
1883
1884 Output: Winds estimation (Zonal and Meridional)
1884 Output: Winds estimation (Zonal and Meridional)
1885
1885
1886 Parameters affected: Winds
1886 Parameters affected: Winds
1887 '''
1887 '''
1888 #Settings
1888 #Settings
1889 nInt = (heightMax - heightMin)/2
1889 nInt = (heightMax - heightMin)/2
1890 nInt = int(nInt)
1890 nInt = int(nInt)
1891 winds = numpy.zeros((2,nInt))*numpy.nan
1891 winds = numpy.zeros((2,nInt))*numpy.nan
1892
1892
1893 #Filter errors
1893 #Filter errors
1894 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1894 error = numpy.where(arrayMeteor[:,-1] == 0)[0]
1895 finalMeteor = arrayMeteor[error,:]
1895 finalMeteor = arrayMeteor[error,:]
1896
1896
1897 #Meteor Histogram
1897 #Meteor Histogram
1898 finalHeights = finalMeteor[:,2]
1898 finalHeights = finalMeteor[:,2]
1899 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1899 hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax))
1900 nMeteorsPerI = hist[0]
1900 nMeteorsPerI = hist[0]
1901 heightPerI = hist[1]
1901 heightPerI = hist[1]
1902
1902
1903 #Sort of meteors
1903 #Sort of meteors
1904 indSort = finalHeights.argsort()
1904 indSort = finalHeights.argsort()
1905 finalMeteor2 = finalMeteor[indSort,:]
1905 finalMeteor2 = finalMeteor[indSort,:]
1906
1906
1907 # Calculating winds
1907 # Calculating winds
1908 ind1 = 0
1908 ind1 = 0
1909 ind2 = 0
1909 ind2 = 0
1910
1910
1911 for i in range(nInt):
1911 for i in range(nInt):
1912 nMet = nMeteorsPerI[i]
1912 nMet = nMeteorsPerI[i]
1913 ind1 = ind2
1913 ind1 = ind2
1914 ind2 = ind1 + nMet
1914 ind2 = ind1 + nMet
1915
1915
1916 meteorAux = finalMeteor2[ind1:ind2,:]
1916 meteorAux = finalMeteor2[ind1:ind2,:]
1917
1917
1918 if meteorAux.shape[0] >= meteorThresh:
1918 if meteorAux.shape[0] >= meteorThresh:
1919 vel = meteorAux[:, 6]
1919 vel = meteorAux[:, 6]
1920 zen = meteorAux[:, 4]*numpy.pi/180
1920 zen = meteorAux[:, 4]*numpy.pi/180
1921 azim = meteorAux[:, 3]*numpy.pi/180
1921 azim = meteorAux[:, 3]*numpy.pi/180
1922
1922
1923 n = numpy.cos(zen)
1923 n = numpy.cos(zen)
1924 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1924 # m = (1 - n**2)/(1 - numpy.tan(azim)**2)
1925 # l = m*numpy.tan(azim)
1925 # l = m*numpy.tan(azim)
1926 l = numpy.sin(zen)*numpy.sin(azim)
1926 l = numpy.sin(zen)*numpy.sin(azim)
1927 m = numpy.sin(zen)*numpy.cos(azim)
1927 m = numpy.sin(zen)*numpy.cos(azim)
1928
1928
1929 A = numpy.vstack((l, m)).transpose()
1929 A = numpy.vstack((l, m)).transpose()
1930 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1930 A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose())
1931 windsAux = numpy.dot(A1, vel)
1931 windsAux = numpy.dot(A1, vel)
1932
1932
1933 winds[0,i] = windsAux[0]
1933 winds[0,i] = windsAux[0]
1934 winds[1,i] = windsAux[1]
1934 winds[1,i] = windsAux[1]
1935
1935
1936 return winds, heightPerI[:-1]
1936 return winds, heightPerI[:-1]
1937
1937
1938 def techniqueNSM_SA(self, **kwargs):
1938 def techniqueNSM_SA(self, **kwargs):
1939 metArray = kwargs['metArray']
1939 metArray = kwargs['metArray']
1940 heightList = kwargs['heightList']
1940 heightList = kwargs['heightList']
1941 timeList = kwargs['timeList']
1941 timeList = kwargs['timeList']
1942
1942
1943 rx_location = kwargs['rx_location']
1943 rx_location = kwargs['rx_location']
1944 groupList = kwargs['groupList']
1944 groupList = kwargs['groupList']
1945 azimuth = kwargs['azimuth']
1945 azimuth = kwargs['azimuth']
1946 dfactor = kwargs['dfactor']
1946 dfactor = kwargs['dfactor']
1947 k = kwargs['k']
1947 k = kwargs['k']
1948
1948
1949 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
1949 azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth)
1950 d = dist*dfactor
1950 d = dist*dfactor
1951 #Phase calculation
1951 #Phase calculation
1952 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
1952 metArray1 = self.__getPhaseSlope(metArray, heightList, timeList)
1953
1953
1954 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
1954 metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities
1955
1955
1956 velEst = numpy.zeros((heightList.size,2))*numpy.nan
1956 velEst = numpy.zeros((heightList.size,2))*numpy.nan
1957 azimuth1 = azimuth1*numpy.pi/180
1957 azimuth1 = azimuth1*numpy.pi/180
1958
1958
1959 for i in range(heightList.size):
1959 for i in range(heightList.size):
1960 h = heightList[i]
1960 h = heightList[i]
1961 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
1961 indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0]
1962 metHeight = metArray1[indH,:]
1962 metHeight = metArray1[indH,:]
1963 if metHeight.shape[0] >= 2:
1963 if metHeight.shape[0] >= 2:
1964 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
1964 velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities
1965 iazim = metHeight[:,1].astype(int)
1965 iazim = metHeight[:,1].astype(int)
1966 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
1966 azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths
1967 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
1967 A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux)))
1968 A = numpy.asmatrix(A)
1968 A = numpy.asmatrix(A)
1969 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
1969 A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose()
1970 velHor = numpy.dot(A1,velAux)
1970 velHor = numpy.dot(A1,velAux)
1971
1971
1972 velEst[i,:] = numpy.squeeze(velHor)
1972 velEst[i,:] = numpy.squeeze(velHor)
1973 return velEst
1973 return velEst
1974
1974
1975 def __getPhaseSlope(self, metArray, heightList, timeList):
1975 def __getPhaseSlope(self, metArray, heightList, timeList):
1976 meteorList = []
1976 meteorList = []
1977 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
1977 #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2
1978 #Putting back together the meteor matrix
1978 #Putting back together the meteor matrix
1979 utctime = metArray[:,0]
1979 utctime = metArray[:,0]
1980 uniqueTime = numpy.unique(utctime)
1980 uniqueTime = numpy.unique(utctime)
1981
1981
1982 phaseDerThresh = 0.5
1982 phaseDerThresh = 0.5
1983 ippSeconds = timeList[1] - timeList[0]
1983 ippSeconds = timeList[1] - timeList[0]
1984 sec = numpy.where(timeList>1)[0][0]
1984 sec = numpy.where(timeList>1)[0][0]
1985 nPairs = metArray.shape[1] - 6
1985 nPairs = metArray.shape[1] - 6
1986 nHeights = len(heightList)
1986 nHeights = len(heightList)
1987
1987
1988 for t in uniqueTime:
1988 for t in uniqueTime:
1989 metArray1 = metArray[utctime==t,:]
1989 metArray1 = metArray[utctime==t,:]
1990 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
1990 # phaseDerThresh = numpy.pi/4 #reducir Phase thresh
1991 tmet = metArray1[:,1].astype(int)
1991 tmet = metArray1[:,1].astype(int)
1992 hmet = metArray1[:,2].astype(int)
1992 hmet = metArray1[:,2].astype(int)
1993
1993
1994 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
1994 metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1))
1995 metPhase[:,:] = numpy.nan
1995 metPhase[:,:] = numpy.nan
1996 metPhase[:,hmet,tmet] = metArray1[:,6:].T
1996 metPhase[:,hmet,tmet] = metArray1[:,6:].T
1997
1997
1998 #Delete short trails
1998 #Delete short trails
1999 metBool = ~numpy.isnan(metPhase[0,:,:])
1999 metBool = ~numpy.isnan(metPhase[0,:,:])
2000 heightVect = numpy.sum(metBool, axis = 1)
2000 heightVect = numpy.sum(metBool, axis = 1)
2001 metBool[heightVect<sec,:] = False
2001 metBool[heightVect<sec,:] = False
2002 metPhase[:,heightVect<sec,:] = numpy.nan
2002 metPhase[:,heightVect<sec,:] = numpy.nan
2003
2003
2004 #Derivative
2004 #Derivative
2005 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2005 metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1])
2006 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2006 phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh))
2007 metPhase[phDerAux] = numpy.nan
2007 metPhase[phDerAux] = numpy.nan
2008
2008
2009 #--------------------------METEOR DETECTION -----------------------------------------
2009 #--------------------------METEOR DETECTION -----------------------------------------
2010 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2010 indMet = numpy.where(numpy.any(metBool,axis=1))[0]
2011
2011
2012 for p in numpy.arange(nPairs):
2012 for p in numpy.arange(nPairs):
2013 phase = metPhase[p,:,:]
2013 phase = metPhase[p,:,:]
2014 phDer = metDer[p,:,:]
2014 phDer = metDer[p,:,:]
2015
2015
2016 for h in indMet:
2016 for h in indMet:
2017 height = heightList[h]
2017 height = heightList[h]
2018 phase1 = phase[h,:] #82
2018 phase1 = phase[h,:] #82
2019 phDer1 = phDer[h,:]
2019 phDer1 = phDer[h,:]
2020
2020
2021 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2021 phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap
2022
2022
2023 indValid = numpy.where(~numpy.isnan(phase1))[0]
2023 indValid = numpy.where(~numpy.isnan(phase1))[0]
2024 initMet = indValid[0]
2024 initMet = indValid[0]
2025 endMet = 0
2025 endMet = 0
2026
2026
2027 for i in range(len(indValid)-1):
2027 for i in range(len(indValid)-1):
2028
2028
2029 #Time difference
2029 #Time difference
2030 inow = indValid[i]
2030 inow = indValid[i]
2031 inext = indValid[i+1]
2031 inext = indValid[i+1]
2032 idiff = inext - inow
2032 idiff = inext - inow
2033 #Phase difference
2033 #Phase difference
2034 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2034 phDiff = numpy.abs(phase1[inext] - phase1[inow])
2035
2035
2036 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2036 if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor
2037 sizeTrail = inow - initMet + 1
2037 sizeTrail = inow - initMet + 1
2038 if sizeTrail>3*sec: #Too short meteors
2038 if sizeTrail>3*sec: #Too short meteors
2039 x = numpy.arange(initMet,inow+1)*ippSeconds
2039 x = numpy.arange(initMet,inow+1)*ippSeconds
2040 y = phase1[initMet:inow+1]
2040 y = phase1[initMet:inow+1]
2041 ynnan = ~numpy.isnan(y)
2041 ynnan = ~numpy.isnan(y)
2042 x = x[ynnan]
2042 x = x[ynnan]
2043 y = y[ynnan]
2043 y = y[ynnan]
2044 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2044 slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
2045 ylin = x*slope + intercept
2045 ylin = x*slope + intercept
2046 rsq = r_value**2
2046 rsq = r_value**2
2047 if rsq > 0.5:
2047 if rsq > 0.5:
2048 vel = slope#*height*1000/(k*d)
2048 vel = slope#*height*1000/(k*d)
2049 estAux = numpy.array([utctime,p,height, vel, rsq])
2049 estAux = numpy.array([utctime,p,height, vel, rsq])
2050 meteorList.append(estAux)
2050 meteorList.append(estAux)
2051 initMet = inext
2051 initMet = inext
2052 metArray2 = numpy.array(meteorList)
2052 metArray2 = numpy.array(meteorList)
2053
2053
2054 return metArray2
2054 return metArray2
2055
2055
2056 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2056 def __calculateAzimuth1(self, rx_location, pairslist, azimuth0):
2057
2057
2058 azimuth1 = numpy.zeros(len(pairslist))
2058 azimuth1 = numpy.zeros(len(pairslist))
2059 dist = numpy.zeros(len(pairslist))
2059 dist = numpy.zeros(len(pairslist))
2060
2060
2061 for i in range(len(rx_location)):
2061 for i in range(len(rx_location)):
2062 ch0 = pairslist[i][0]
2062 ch0 = pairslist[i][0]
2063 ch1 = pairslist[i][1]
2063 ch1 = pairslist[i][1]
2064
2064
2065 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2065 diffX = rx_location[ch0][0] - rx_location[ch1][0]
2066 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2066 diffY = rx_location[ch0][1] - rx_location[ch1][1]
2067 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2067 azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi
2068 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2068 dist[i] = numpy.sqrt(diffX**2 + diffY**2)
2069
2069
2070 azimuth1 -= azimuth0
2070 azimuth1 -= azimuth0
2071 return azimuth1, dist
2071 return azimuth1, dist
2072
2072
2073 def techniqueNSM_DBS(self, **kwargs):
2073 def techniqueNSM_DBS(self, **kwargs):
2074 metArray = kwargs['metArray']
2074 metArray = kwargs['metArray']
2075 heightList = kwargs['heightList']
2075 heightList = kwargs['heightList']
2076 timeList = kwargs['timeList']
2076 timeList = kwargs['timeList']
2077 azimuth = kwargs['azimuth']
2077 azimuth = kwargs['azimuth']
2078 theta_x = numpy.array(kwargs['theta_x'])
2078 theta_x = numpy.array(kwargs['theta_x'])
2079 theta_y = numpy.array(kwargs['theta_y'])
2079 theta_y = numpy.array(kwargs['theta_y'])
2080
2080
2081 utctime = metArray[:,0]
2081 utctime = metArray[:,0]
2082 cmet = metArray[:,1].astype(int)
2082 cmet = metArray[:,1].astype(int)
2083 hmet = metArray[:,3].astype(int)
2083 hmet = metArray[:,3].astype(int)
2084 SNRmet = metArray[:,4]
2084 SNRmet = metArray[:,4]
2085 vmet = metArray[:,5]
2085 vmet = metArray[:,5]
2086 spcmet = metArray[:,6]
2086 spcmet = metArray[:,6]
2087
2087
2088 nChan = numpy.max(cmet) + 1
2088 nChan = numpy.max(cmet) + 1
2089 nHeights = len(heightList)
2089 nHeights = len(heightList)
2090
2090
2091 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
2091 azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth)
2092 hmet = heightList[hmet]
2092 hmet = heightList[hmet]
2093 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
2093 h1met = hmet*numpy.cos(zenith_arr[cmet]) #Corrected heights
2094
2094
2095 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2095 velEst = numpy.zeros((heightList.size,2))*numpy.nan
2096
2096
2097 for i in range(nHeights - 1):
2097 for i in range(nHeights - 1):
2098 hmin = heightList[i]
2098 hmin = heightList[i]
2099 hmax = heightList[i + 1]
2099 hmax = heightList[i + 1]
2100
2100
2101 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
2101 thisH = (h1met>=hmin) & (h1met<hmax) & (cmet!=2) & (SNRmet>8) & (vmet<50) & (spcmet<10)
2102 indthisH = numpy.where(thisH)
2102 indthisH = numpy.where(thisH)
2103
2103
2104 if numpy.size(indthisH) > 3:
2104 if numpy.size(indthisH) > 3:
2105
2105
2106 vel_aux = vmet[thisH]
2106 vel_aux = vmet[thisH]
2107 chan_aux = cmet[thisH]
2107 chan_aux = cmet[thisH]
2108 cosu_aux = dir_cosu[chan_aux]
2108 cosu_aux = dir_cosu[chan_aux]
2109 cosv_aux = dir_cosv[chan_aux]
2109 cosv_aux = dir_cosv[chan_aux]
2110 cosw_aux = dir_cosw[chan_aux]
2110 cosw_aux = dir_cosw[chan_aux]
2111
2111
2112 nch = numpy.size(numpy.unique(chan_aux))
2112 nch = numpy.size(numpy.unique(chan_aux))
2113 if nch > 1:
2113 if nch > 1:
2114 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
2114 A = self.__calculateMatA(cosu_aux, cosv_aux, cosw_aux, True)
2115 velEst[i,:] = numpy.dot(A,vel_aux)
2115 velEst[i,:] = numpy.dot(A,vel_aux)
2116
2116
2117 return velEst
2117 return velEst
2118
2118
2119 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
2119 def run(self, dataOut, technique, nHours=1, hmin=70, hmax=110, **kwargs):
2120
2120
2121 param = dataOut.data_param
2121 param = dataOut.data_param
2122 if dataOut.abscissaList != None:
2122 if dataOut.abscissaList != None:
2123 absc = dataOut.abscissaList[:-1]
2123 absc = dataOut.abscissaList[:-1]
2124 # noise = dataOut.noise
2124 # noise = dataOut.noise
2125 heightList = dataOut.heightList
2125 heightList = dataOut.heightList
2126 SNR = dataOut.data_SNR
2126 SNR = dataOut.data_SNR
2127
2127
2128 if technique == 'DBS':
2128 if technique == 'DBS':
2129
2129
2130 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2130 kwargs['velRadial'] = param[:,1,:] #Radial velocity
2131 kwargs['heightList'] = heightList
2131 kwargs['heightList'] = heightList
2132 kwargs['SNR'] = SNR
2132 kwargs['SNR'] = SNR
2133
2133
2134 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2134 dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function
2135 dataOut.utctimeInit = dataOut.utctime
2135 dataOut.utctimeInit = dataOut.utctime
2136 dataOut.outputInterval = dataOut.paramInterval
2136 dataOut.outputInterval = dataOut.paramInterval
2137
2137
2138 elif technique == 'SA':
2138 elif technique == 'SA':
2139
2139
2140 #Parameters
2140 #Parameters
2141 # position_x = kwargs['positionX']
2141 # position_x = kwargs['positionX']
2142 # position_y = kwargs['positionY']
2142 # position_y = kwargs['positionY']
2143 # azimuth = kwargs['azimuth']
2143 # azimuth = kwargs['azimuth']
2144 #
2144 #
2145 # if kwargs.has_key('crosspairsList'):
2145 # if kwargs.has_key('crosspairsList'):
2146 # pairs = kwargs['crosspairsList']
2146 # pairs = kwargs['crosspairsList']
2147 # else:
2147 # else:
2148 # pairs = None
2148 # pairs = None
2149 #
2149 #
2150 # if kwargs.has_key('correctFactor'):
2150 # if kwargs.has_key('correctFactor'):
2151 # correctFactor = kwargs['correctFactor']
2151 # correctFactor = kwargs['correctFactor']
2152 # else:
2152 # else:
2153 # correctFactor = 1
2153 # correctFactor = 1
2154
2154
2155 # tau = dataOut.data_param
2155 # tau = dataOut.data_param
2156 # _lambda = dataOut.C/dataOut.frequency
2156 # _lambda = dataOut.C/dataOut.frequency
2157 # pairsList = dataOut.groupList
2157 # pairsList = dataOut.groupList
2158 # nChannels = dataOut.nChannels
2158 # nChannels = dataOut.nChannels
2159
2159
2160 kwargs['groupList'] = dataOut.groupList
2160 kwargs['groupList'] = dataOut.groupList
2161 kwargs['tau'] = dataOut.data_param
2161 kwargs['tau'] = dataOut.data_param
2162 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2162 kwargs['_lambda'] = dataOut.C/dataOut.frequency
2163 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2163 # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor)
2164 dataOut.data_output = self.techniqueSA(kwargs)
2164 dataOut.data_output = self.techniqueSA(kwargs)
2165 dataOut.utctimeInit = dataOut.utctime
2165 dataOut.utctimeInit = dataOut.utctime
2166 dataOut.outputInterval = dataOut.timeInterval
2166 dataOut.outputInterval = dataOut.timeInterval
2167
2167
2168 elif technique == 'Meteors':
2168 elif technique == 'Meteors':
2169 dataOut.flagNoData = True
2169 dataOut.flagNoData = True
2170 self.__dataReady = False
2170 self.__dataReady = False
2171
2171
2172 if 'nHours' in kwargs:
2172 if 'nHours' in kwargs:
2173 nHours = kwargs['nHours']
2173 nHours = kwargs['nHours']
2174 else:
2174 else:
2175 nHours = 1
2175 nHours = 1
2176
2176
2177 if 'meteorsPerBin' in kwargs:
2177 if 'meteorsPerBin' in kwargs:
2178 meteorThresh = kwargs['meteorsPerBin']
2178 meteorThresh = kwargs['meteorsPerBin']
2179 else:
2179 else:
2180 meteorThresh = 6
2180 meteorThresh = 6
2181
2181
2182 if 'hmin' in kwargs:
2182 if 'hmin' in kwargs:
2183 hmin = kwargs['hmin']
2183 hmin = kwargs['hmin']
2184 else: hmin = 70
2184 else: hmin = 70
2185 if 'hmax' in kwargs:
2185 if 'hmax' in kwargs:
2186 hmax = kwargs['hmax']
2186 hmax = kwargs['hmax']
2187 else: hmax = 110
2187 else: hmax = 110
2188
2188
2189 dataOut.outputInterval = nHours*3600
2189 dataOut.outputInterval = nHours*3600
2190
2190
2191 if self.__isConfig == False:
2191 if self.__isConfig == False:
2192 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2192 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2193 #Get Initial LTC time
2193 #Get Initial LTC time
2194 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2194 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2195 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2195 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2196
2196
2197 self.__isConfig = True
2197 self.__isConfig = True
2198
2198
2199 if self.__buffer is None:
2199 if self.__buffer is None:
2200 self.__buffer = dataOut.data_param
2200 self.__buffer = dataOut.data_param
2201 self.__firstdata = copy.copy(dataOut)
2201 self.__firstdata = copy.copy(dataOut)
2202
2202
2203 else:
2203 else:
2204 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2204 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2205
2205
2206 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2206 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2207
2207
2208 if self.__dataReady:
2208 if self.__dataReady:
2209 dataOut.utctimeInit = self.__initime
2209 dataOut.utctimeInit = self.__initime
2210
2210
2211 self.__initime += dataOut.outputInterval #to erase time offset
2211 self.__initime += dataOut.outputInterval #to erase time offset
2212
2212
2213 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2213 dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax)
2214 dataOut.flagNoData = False
2214 dataOut.flagNoData = False
2215 self.__buffer = None
2215 self.__buffer = None
2216
2216
2217 elif technique == 'Meteors1':
2217 elif technique == 'Meteors1':
2218 dataOut.flagNoData = True
2218 dataOut.flagNoData = True
2219 self.__dataReady = False
2219 self.__dataReady = False
2220
2220
2221 if 'nMins' in kwargs:
2221 if 'nMins' in kwargs:
2222 nMins = kwargs['nMins']
2222 nMins = kwargs['nMins']
2223 else: nMins = 20
2223 else: nMins = 20
2224 if 'rx_location' in kwargs:
2224 if 'rx_location' in kwargs:
2225 rx_location = kwargs['rx_location']
2225 rx_location = kwargs['rx_location']
2226 else: rx_location = [(0,1),(1,1),(1,0)]
2226 else: rx_location = [(0,1),(1,1),(1,0)]
2227 if 'azimuth' in kwargs:
2227 if 'azimuth' in kwargs:
2228 azimuth = kwargs['azimuth']
2228 azimuth = kwargs['azimuth']
2229 else: azimuth = 51.06
2229 else: azimuth = 51.06
2230 if 'dfactor' in kwargs:
2230 if 'dfactor' in kwargs:
2231 dfactor = kwargs['dfactor']
2231 dfactor = kwargs['dfactor']
2232 if 'mode' in kwargs:
2232 if 'mode' in kwargs:
2233 mode = kwargs['mode']
2233 mode = kwargs['mode']
2234 if 'theta_x' in kwargs:
2234 if 'theta_x' in kwargs:
2235 theta_x = kwargs['theta_x']
2235 theta_x = kwargs['theta_x']
2236 if 'theta_y' in kwargs:
2236 if 'theta_y' in kwargs:
2237 theta_y = kwargs['theta_y']
2237 theta_y = kwargs['theta_y']
2238 else: mode = 'SA'
2238 else: mode = 'SA'
2239
2239
2240 #Borrar luego esto
2240 #Borrar luego esto
2241 if dataOut.groupList is None:
2241 if dataOut.groupList is None:
2242 dataOut.groupList = [(0,1),(0,2),(1,2)]
2242 dataOut.groupList = [(0,1),(0,2),(1,2)]
2243 groupList = dataOut.groupList
2243 groupList = dataOut.groupList
2244 C = 3e8
2244 C = 3e8
2245 freq = 50e6
2245 freq = 50e6
2246 lamb = C/freq
2246 lamb = C/freq
2247 k = 2*numpy.pi/lamb
2247 k = 2*numpy.pi/lamb
2248
2248
2249 timeList = dataOut.abscissaList
2249 timeList = dataOut.abscissaList
2250 heightList = dataOut.heightList
2250 heightList = dataOut.heightList
2251
2251
2252 if self.__isConfig == False:
2252 if self.__isConfig == False:
2253 dataOut.outputInterval = nMins*60
2253 dataOut.outputInterval = nMins*60
2254 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2254 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
2255 #Get Initial LTC time
2255 #Get Initial LTC time
2256 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2256 initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
2257 minuteAux = initime.minute
2257 minuteAux = initime.minute
2258 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2258 minuteNew = int(numpy.floor(minuteAux/nMins)*nMins)
2259 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2259 self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
2260
2260
2261 self.__isConfig = True
2261 self.__isConfig = True
2262
2262
2263 if self.__buffer is None:
2263 if self.__buffer is None:
2264 self.__buffer = dataOut.data_param
2264 self.__buffer = dataOut.data_param
2265 self.__firstdata = copy.copy(dataOut)
2265 self.__firstdata = copy.copy(dataOut)
2266
2266
2267 else:
2267 else:
2268 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2268 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
2269
2269
2270 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2270 self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
2271
2271
2272 if self.__dataReady:
2272 if self.__dataReady:
2273 dataOut.utctimeInit = self.__initime
2273 dataOut.utctimeInit = self.__initime
2274 self.__initime += dataOut.outputInterval #to erase time offset
2274 self.__initime += dataOut.outputInterval #to erase time offset
2275
2275
2276 metArray = self.__buffer
2276 metArray = self.__buffer
2277 if mode == 'SA':
2277 if mode == 'SA':
2278 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2278 dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList)
2279 elif mode == 'DBS':
2279 elif mode == 'DBS':
2280 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
2280 dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList, azimuth=azimuth, theta_x=theta_x, theta_y=theta_y)
2281 dataOut.data_output = dataOut.data_output.T
2281 dataOut.data_output = dataOut.data_output.T
2282 dataOut.flagNoData = False
2282 dataOut.flagNoData = False
2283 self.__buffer = None
2283 self.__buffer = None
2284
2284
2285 return
2285 return
2286
2286
2287 class EWDriftsEstimation(Operation):
2287 class EWDriftsEstimation(Operation):
2288
2288
2289 def __init__(self):
2289 def __init__(self):
2290 Operation.__init__(self)
2290 Operation.__init__(self)
2291
2291
2292 def __correctValues(self, heiRang, phi, velRadial, SNR):
2292 def __correctValues(self, heiRang, phi, velRadial, SNR):
2293 listPhi = phi.tolist()
2293 listPhi = phi.tolist()
2294 maxid = listPhi.index(max(listPhi))
2294 maxid = listPhi.index(max(listPhi))
2295 minid = listPhi.index(min(listPhi))
2295 minid = listPhi.index(min(listPhi))
2296
2296
2297 rango = list(range(len(phi)))
2297 rango = list(range(len(phi)))
2298 # rango = numpy.delete(rango,maxid)
2298 # rango = numpy.delete(rango,maxid)
2299
2299
2300 heiRang1 = heiRang*math.cos(phi[maxid])
2300 heiRang1 = heiRang*math.cos(phi[maxid])
2301 heiRangAux = heiRang*math.cos(phi[minid])
2301 heiRangAux = heiRang*math.cos(phi[minid])
2302 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2302 indOut = (heiRang1 < heiRangAux[0]).nonzero()
2303 heiRang1 = numpy.delete(heiRang1,indOut)
2303 heiRang1 = numpy.delete(heiRang1,indOut)
2304
2304
2305 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2305 velRadial1 = numpy.zeros([len(phi),len(heiRang1)])
2306 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2306 SNR1 = numpy.zeros([len(phi),len(heiRang1)])
2307
2307
2308 for i in rango:
2308 for i in rango:
2309 x = heiRang*math.cos(phi[i])
2309 x = heiRang*math.cos(phi[i])
2310 y1 = velRadial[i,:]
2310 y1 = velRadial[i,:]
2311 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2311 f1 = interpolate.interp1d(x,y1,kind = 'cubic')
2312
2312
2313 x1 = heiRang1
2313 x1 = heiRang1
2314 y11 = f1(x1)
2314 y11 = f1(x1)
2315
2315
2316 y2 = SNR[i,:]
2316 y2 = SNR[i,:]
2317 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2317 f2 = interpolate.interp1d(x,y2,kind = 'cubic')
2318 y21 = f2(x1)
2318 y21 = f2(x1)
2319
2319
2320 velRadial1[i,:] = y11
2320 velRadial1[i,:] = y11
2321 SNR1[i,:] = y21
2321 SNR1[i,:] = y21
2322
2322
2323 return heiRang1, velRadial1, SNR1
2323 return heiRang1, velRadial1, SNR1
2324
2324
2325 def run(self, dataOut, zenith, zenithCorrection):
2325 def run(self, dataOut, zenith, zenithCorrection):
2326 heiRang = dataOut.heightList
2326 heiRang = dataOut.heightList
2327 velRadial = dataOut.data_param[:,3,:]
2327 velRadial = dataOut.data_param[:,3,:]
2328 SNR = dataOut.data_SNR
2328 SNR = dataOut.data_SNR
2329
2329
2330 zenith = numpy.array(zenith)
2330 zenith = numpy.array(zenith)
2331 zenith -= zenithCorrection
2331 zenith -= zenithCorrection
2332 zenith *= numpy.pi/180
2332 zenith *= numpy.pi/180
2333
2333
2334 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2334 heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR)
2335
2335
2336 alp = zenith[0]
2336 alp = zenith[0]
2337 bet = zenith[1]
2337 bet = zenith[1]
2338
2338
2339 w_w = velRadial1[0,:]
2339 w_w = velRadial1[0,:]
2340 w_e = velRadial1[1,:]
2340 w_e = velRadial1[1,:]
2341
2341
2342 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2342 w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp))
2343 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2343 u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp))
2344
2344
2345 winds = numpy.vstack((u,w))
2345 winds = numpy.vstack((u,w))
2346
2346
2347 dataOut.heightList = heiRang1
2347 dataOut.heightList = heiRang1
2348 dataOut.data_output = winds
2348 dataOut.data_output = winds
2349 dataOut.data_SNR = SNR1
2349 dataOut.data_SNR = SNR1
2350
2350
2351 dataOut.utctimeInit = dataOut.utctime
2351 dataOut.utctimeInit = dataOut.utctime
2352 dataOut.outputInterval = dataOut.timeInterval
2352 dataOut.outputInterval = dataOut.timeInterval
2353 return
2353 return
2354
2354
2355 #--------------- Non Specular Meteor ----------------
2355 #--------------- Non Specular Meteor ----------------
2356
2356
2357 class NonSpecularMeteorDetection(Operation):
2357 class NonSpecularMeteorDetection(Operation):
2358
2358
2359 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2359 def run(self, dataOut, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False):
2360 data_acf = dataOut.data_pre[0]
2360 data_acf = dataOut.data_pre[0]
2361 data_ccf = dataOut.data_pre[1]
2361 data_ccf = dataOut.data_pre[1]
2362 pairsList = dataOut.groupList[1]
2362 pairsList = dataOut.groupList[1]
2363
2363
2364 lamb = dataOut.C/dataOut.frequency
2364 lamb = dataOut.C/dataOut.frequency
2365 tSamp = dataOut.ippSeconds*dataOut.nCohInt
2365 tSamp = dataOut.ippSeconds*dataOut.nCohInt
2366 paramInterval = dataOut.paramInterval
2366 paramInterval = dataOut.paramInterval
2367
2367
2368 nChannels = data_acf.shape[0]
2368 nChannels = data_acf.shape[0]
2369 nLags = data_acf.shape[1]
2369 nLags = data_acf.shape[1]
2370 nProfiles = data_acf.shape[2]
2370 nProfiles = data_acf.shape[2]
2371 nHeights = dataOut.nHeights
2371 nHeights = dataOut.nHeights
2372 nCohInt = dataOut.nCohInt
2372 nCohInt = dataOut.nCohInt
2373 sec = numpy.round(nProfiles/dataOut.paramInterval)
2373 sec = numpy.round(nProfiles/dataOut.paramInterval)
2374 heightList = dataOut.heightList
2374 heightList = dataOut.heightList
2375 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
2375 ippSeconds = dataOut.ippSeconds*dataOut.nCohInt*dataOut.nAvg
2376 utctime = dataOut.utctime
2376 utctime = dataOut.utctime
2377
2377
2378 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2378 dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds)
2379
2379
2380 #------------------------ SNR --------------------------------------
2380 #------------------------ SNR --------------------------------------
2381 power = data_acf[:,0,:,:].real
2381 power = data_acf[:,0,:,:].real
2382 noise = numpy.zeros(nChannels)
2382 noise = numpy.zeros(nChannels)
2383 SNR = numpy.zeros(power.shape)
2383 SNR = numpy.zeros(power.shape)
2384 for i in range(nChannels):
2384 for i in range(nChannels):
2385 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2385 noise[i] = hildebrand_sekhon(power[i,:], nCohInt)
2386 SNR[i] = (power[i]-noise[i])/noise[i]
2386 SNR[i] = (power[i]-noise[i])/noise[i]
2387 SNRm = numpy.nanmean(SNR, axis = 0)
2387 SNRm = numpy.nanmean(SNR, axis = 0)
2388 SNRdB = 10*numpy.log10(SNR)
2388 SNRdB = 10*numpy.log10(SNR)
2389
2389
2390 if mode == 'SA':
2390 if mode == 'SA':
2391 dataOut.groupList = dataOut.groupList[1]
2391 dataOut.groupList = dataOut.groupList[1]
2392 nPairs = data_ccf.shape[0]
2392 nPairs = data_ccf.shape[0]
2393 #---------------------- Coherence and Phase --------------------------
2393 #---------------------- Coherence and Phase --------------------------
2394 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2394 phase = numpy.zeros(data_ccf[:,0,:,:].shape)
2395 # phase1 = numpy.copy(phase)
2395 # phase1 = numpy.copy(phase)
2396 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2396 coh1 = numpy.zeros(data_ccf[:,0,:,:].shape)
2397
2397
2398 for p in range(nPairs):
2398 for p in range(nPairs):
2399 ch0 = pairsList[p][0]
2399 ch0 = pairsList[p][0]
2400 ch1 = pairsList[p][1]
2400 ch1 = pairsList[p][1]
2401 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2401 ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:])
2402 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2402 phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter
2403 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2403 # phase1[p,:,:] = numpy.angle(ccf) #median filter
2404 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2404 coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter
2405 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2405 # coh1[p,:,:] = numpy.abs(ccf) #median filter
2406 coh = numpy.nanmax(coh1, axis = 0)
2406 coh = numpy.nanmax(coh1, axis = 0)
2407 # struc = numpy.ones((5,1))
2407 # struc = numpy.ones((5,1))
2408 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2408 # coh = ndimage.morphology.grey_dilation(coh, size=(10,1))
2409 #---------------------- Radial Velocity ----------------------------
2409 #---------------------- Radial Velocity ----------------------------
2410 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2410 phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0)
2411 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2411 velRad = phaseAux*lamb/(4*numpy.pi*tSamp)
2412
2412
2413 if allData:
2413 if allData:
2414 boolMetFin = ~numpy.isnan(SNRm)
2414 boolMetFin = ~numpy.isnan(SNRm)
2415 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2415 # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2416 else:
2416 else:
2417 #------------------------ Meteor mask ---------------------------------
2417 #------------------------ Meteor mask ---------------------------------
2418 # #SNR mask
2418 # #SNR mask
2419 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2419 # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB))
2420 #
2420 #
2421 # #Erase small objects
2421 # #Erase small objects
2422 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2422 # boolMet1 = self.__erase_small(boolMet, 2*sec, 5)
2423 #
2423 #
2424 # auxEEJ = numpy.sum(boolMet1,axis=0)
2424 # auxEEJ = numpy.sum(boolMet1,axis=0)
2425 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2425 # indOver = auxEEJ>nProfiles*0.8 #Use this later
2426 # indEEJ = numpy.where(indOver)[0]
2426 # indEEJ = numpy.where(indOver)[0]
2427 # indNEEJ = numpy.where(~indOver)[0]
2427 # indNEEJ = numpy.where(~indOver)[0]
2428 #
2428 #
2429 # boolMetFin = boolMet1
2429 # boolMetFin = boolMet1
2430 #
2430 #
2431 # if indEEJ.size > 0:
2431 # if indEEJ.size > 0:
2432 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2432 # boolMet1[:,indEEJ] = False #Erase heights with EEJ
2433 #
2433 #
2434 # boolMet2 = coh > cohThresh
2434 # boolMet2 = coh > cohThresh
2435 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2435 # boolMet2 = self.__erase_small(boolMet2, 2*sec,5)
2436 #
2436 #
2437 # #Final Meteor mask
2437 # #Final Meteor mask
2438 # boolMetFin = boolMet1|boolMet2
2438 # boolMetFin = boolMet1|boolMet2
2439
2439
2440 #Coherence mask
2440 #Coherence mask
2441 boolMet1 = coh > 0.75
2441 boolMet1 = coh > 0.75
2442 struc = numpy.ones((30,1))
2442 struc = numpy.ones((30,1))
2443 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2443 boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc)
2444
2444
2445 #Derivative mask
2445 #Derivative mask
2446 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2446 derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0)
2447 boolMet2 = derPhase < 0.2
2447 boolMet2 = derPhase < 0.2
2448 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2448 # boolMet2 = ndimage.morphology.binary_opening(boolMet2)
2449 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2449 # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1)))
2450 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2450 boolMet2 = ndimage.median_filter(boolMet2,size=5)
2451 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2451 boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool)))
2452 # #Final mask
2452 # #Final mask
2453 # boolMetFin = boolMet2
2453 # boolMetFin = boolMet2
2454 boolMetFin = boolMet1&boolMet2
2454 boolMetFin = boolMet1&boolMet2
2455 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2455 # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin)
2456 #Creating data_param
2456 #Creating data_param
2457 coordMet = numpy.where(boolMetFin)
2457 coordMet = numpy.where(boolMetFin)
2458
2458
2459 tmet = coordMet[0]
2459 tmet = coordMet[0]
2460 hmet = coordMet[1]
2460 hmet = coordMet[1]
2461
2461
2462 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2462 data_param = numpy.zeros((tmet.size, 6 + nPairs))
2463 data_param[:,0] = utctime
2463 data_param[:,0] = utctime
2464 data_param[:,1] = tmet
2464 data_param[:,1] = tmet
2465 data_param[:,2] = hmet
2465 data_param[:,2] = hmet
2466 data_param[:,3] = SNRm[tmet,hmet]
2466 data_param[:,3] = SNRm[tmet,hmet]
2467 data_param[:,4] = velRad[tmet,hmet]
2467 data_param[:,4] = velRad[tmet,hmet]
2468 data_param[:,5] = coh[tmet,hmet]
2468 data_param[:,5] = coh[tmet,hmet]
2469 data_param[:,6:] = phase[:,tmet,hmet].T
2469 data_param[:,6:] = phase[:,tmet,hmet].T
2470
2470
2471 elif mode == 'DBS':
2471 elif mode == 'DBS':
2472 dataOut.groupList = numpy.arange(nChannels)
2472 dataOut.groupList = numpy.arange(nChannels)
2473
2473
2474 #Radial Velocities
2474 #Radial Velocities
2475 phase = numpy.angle(data_acf[:,1,:,:])
2475 phase = numpy.angle(data_acf[:,1,:,:])
2476 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2476 # phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1))
2477 velRad = phase*lamb/(4*numpy.pi*tSamp)
2477 velRad = phase*lamb/(4*numpy.pi*tSamp)
2478
2478
2479 #Spectral width
2479 #Spectral width
2480 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2480 # acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1))
2481 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2481 # acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1))
2482 acf1 = data_acf[:,1,:,:]
2482 acf1 = data_acf[:,1,:,:]
2483 acf2 = data_acf[:,2,:,:]
2483 acf2 = data_acf[:,2,:,:]
2484
2484
2485 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2485 spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2))
2486 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2486 # velRad = ndimage.median_filter(velRad, size = (1,5,1))
2487 if allData:
2487 if allData:
2488 boolMetFin = ~numpy.isnan(SNRdB)
2488 boolMetFin = ~numpy.isnan(SNRdB)
2489 else:
2489 else:
2490 #SNR
2490 #SNR
2491 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2491 boolMet1 = (SNRdB>SNRthresh) #SNR mask
2492 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2492 boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5))
2493
2493
2494 #Radial velocity
2494 #Radial velocity
2495 boolMet2 = numpy.abs(velRad) < 20
2495 boolMet2 = numpy.abs(velRad) < 20
2496 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2496 boolMet2 = ndimage.median_filter(boolMet2, (1,5,5))
2497
2497
2498 #Spectral Width
2498 #Spectral Width
2499 boolMet3 = spcWidth < 30
2499 boolMet3 = spcWidth < 30
2500 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2500 boolMet3 = ndimage.median_filter(boolMet3, (1,5,5))
2501 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2501 # boolMetFin = self.__erase_small(boolMet1, 10,5)
2502 boolMetFin = boolMet1&boolMet2&boolMet3
2502 boolMetFin = boolMet1&boolMet2&boolMet3
2503
2503
2504 #Creating data_param
2504 #Creating data_param
2505 coordMet = numpy.where(boolMetFin)
2505 coordMet = numpy.where(boolMetFin)
2506
2506
2507 cmet = coordMet[0]
2507 cmet = coordMet[0]
2508 tmet = coordMet[1]
2508 tmet = coordMet[1]
2509 hmet = coordMet[2]
2509 hmet = coordMet[2]
2510
2510
2511 data_param = numpy.zeros((tmet.size, 7))
2511 data_param = numpy.zeros((tmet.size, 7))
2512 data_param[:,0] = utctime
2512 data_param[:,0] = utctime
2513 data_param[:,1] = cmet
2513 data_param[:,1] = cmet
2514 data_param[:,2] = tmet
2514 data_param[:,2] = tmet
2515 data_param[:,3] = hmet
2515 data_param[:,3] = hmet
2516 data_param[:,4] = SNR[cmet,tmet,hmet].T
2516 data_param[:,4] = SNR[cmet,tmet,hmet].T
2517 data_param[:,5] = velRad[cmet,tmet,hmet].T
2517 data_param[:,5] = velRad[cmet,tmet,hmet].T
2518 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2518 data_param[:,6] = spcWidth[cmet,tmet,hmet].T
2519
2519
2520 # self.dataOut.data_param = data_int
2520 # self.dataOut.data_param = data_int
2521 if len(data_param) == 0:
2521 if len(data_param) == 0:
2522 dataOut.flagNoData = True
2522 dataOut.flagNoData = True
2523 else:
2523 else:
2524 dataOut.data_param = data_param
2524 dataOut.data_param = data_param
2525
2525
2526 def __erase_small(self, binArray, threshX, threshY):
2526 def __erase_small(self, binArray, threshX, threshY):
2527 labarray, numfeat = ndimage.measurements.label(binArray)
2527 labarray, numfeat = ndimage.measurements.label(binArray)
2528 binArray1 = numpy.copy(binArray)
2528 binArray1 = numpy.copy(binArray)
2529
2529
2530 for i in range(1,numfeat + 1):
2530 for i in range(1,numfeat + 1):
2531 auxBin = (labarray==i)
2531 auxBin = (labarray==i)
2532 auxSize = auxBin.sum()
2532 auxSize = auxBin.sum()
2533
2533
2534 x,y = numpy.where(auxBin)
2534 x,y = numpy.where(auxBin)
2535 widthX = x.max() - x.min()
2535 widthX = x.max() - x.min()
2536 widthY = y.max() - y.min()
2536 widthY = y.max() - y.min()
2537
2537
2538 #width X: 3 seg -> 12.5*3
2538 #width X: 3 seg -> 12.5*3
2539 #width Y:
2539 #width Y:
2540
2540
2541 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2541 if (auxSize < 50) or (widthX < threshX) or (widthY < threshY):
2542 binArray1[auxBin] = False
2542 binArray1[auxBin] = False
2543
2543
2544 return binArray1
2544 return binArray1
2545
2545
2546 #--------------- Specular Meteor ----------------
2546 #--------------- Specular Meteor ----------------
2547
2547
2548 class SMDetection(Operation):
2548 class SMDetection(Operation):
2549 '''
2549 '''
2550 Function DetectMeteors()
2550 Function DetectMeteors()
2551 Project developed with paper:
2551 Project developed with paper:
2552 HOLDSWORTH ET AL. 2004
2552 HOLDSWORTH ET AL. 2004
2553
2553
2554 Input:
2554 Input:
2555 self.dataOut.data_pre
2555 self.dataOut.data_pre
2556
2556
2557 centerReceiverIndex: From the channels, which is the center receiver
2557 centerReceiverIndex: From the channels, which is the center receiver
2558
2558
2559 hei_ref: Height reference for the Beacon signal extraction
2559 hei_ref: Height reference for the Beacon signal extraction
2560 tauindex:
2560 tauindex:
2561 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2561 predefinedPhaseShifts: Predefined phase offset for the voltge signals
2562
2562
2563 cohDetection: Whether to user Coherent detection or not
2563 cohDetection: Whether to user Coherent detection or not
2564 cohDet_timeStep: Coherent Detection calculation time step
2564 cohDet_timeStep: Coherent Detection calculation time step
2565 cohDet_thresh: Coherent Detection phase threshold to correct phases
2565 cohDet_thresh: Coherent Detection phase threshold to correct phases
2566
2566
2567 noise_timeStep: Noise calculation time step
2567 noise_timeStep: Noise calculation time step
2568 noise_multiple: Noise multiple to define signal threshold
2568 noise_multiple: Noise multiple to define signal threshold
2569
2569
2570 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2570 multDet_timeLimit: Multiple Detection Removal time limit in seconds
2571 multDet_rangeLimit: Multiple Detection Removal range limit in km
2571 multDet_rangeLimit: Multiple Detection Removal range limit in km
2572
2572
2573 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2573 phaseThresh: Maximum phase difference between receiver to be consider a meteor
2574 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2574 SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor
2575
2575
2576 hmin: Minimum Height of the meteor to use it in the further wind estimations
2576 hmin: Minimum Height of the meteor to use it in the further wind estimations
2577 hmax: Maximum Height of the meteor to use it in the further wind estimations
2577 hmax: Maximum Height of the meteor to use it in the further wind estimations
2578 azimuth: Azimuth angle correction
2578 azimuth: Azimuth angle correction
2579
2579
2580 Affected:
2580 Affected:
2581 self.dataOut.data_param
2581 self.dataOut.data_param
2582
2582
2583 Rejection Criteria (Errors):
2583 Rejection Criteria (Errors):
2584 0: No error; analysis OK
2584 0: No error; analysis OK
2585 1: SNR < SNR threshold
2585 1: SNR < SNR threshold
2586 2: angle of arrival (AOA) ambiguously determined
2586 2: angle of arrival (AOA) ambiguously determined
2587 3: AOA estimate not feasible
2587 3: AOA estimate not feasible
2588 4: Large difference in AOAs obtained from different antenna baselines
2588 4: Large difference in AOAs obtained from different antenna baselines
2589 5: echo at start or end of time series
2589 5: echo at start or end of time series
2590 6: echo less than 5 examples long; too short for analysis
2590 6: echo less than 5 examples long; too short for analysis
2591 7: echo rise exceeds 0.3s
2591 7: echo rise exceeds 0.3s
2592 8: echo decay time less than twice rise time
2592 8: echo decay time less than twice rise time
2593 9: large power level before echo
2593 9: large power level before echo
2594 10: large power level after echo
2594 10: large power level after echo
2595 11: poor fit to amplitude for estimation of decay time
2595 11: poor fit to amplitude for estimation of decay time
2596 12: poor fit to CCF phase variation for estimation of radial drift velocity
2596 12: poor fit to CCF phase variation for estimation of radial drift velocity
2597 13: height unresolvable echo: not valid height within 70 to 110 km
2597 13: height unresolvable echo: not valid height within 70 to 110 km
2598 14: height ambiguous echo: more then one possible height within 70 to 110 km
2598 14: height ambiguous echo: more then one possible height within 70 to 110 km
2599 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2599 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s
2600 16: oscilatory echo, indicating event most likely not an underdense echo
2600 16: oscilatory echo, indicating event most likely not an underdense echo
2601
2601
2602 17: phase difference in meteor Reestimation
2602 17: phase difference in meteor Reestimation
2603
2603
2604 Data Storage:
2604 Data Storage:
2605 Meteors for Wind Estimation (8):
2605 Meteors for Wind Estimation (8):
2606 Utc Time | Range Height
2606 Utc Time | Range Height
2607 Azimuth Zenith errorCosDir
2607 Azimuth Zenith errorCosDir
2608 VelRad errorVelRad
2608 VelRad errorVelRad
2609 Phase0 Phase1 Phase2 Phase3
2609 Phase0 Phase1 Phase2 Phase3
2610 TypeError
2610 TypeError
2611
2611
2612 '''
2612 '''
2613
2613
2614 def run(self, dataOut, hei_ref = None, tauindex = 0,
2614 def run(self, dataOut, hei_ref = None, tauindex = 0,
2615 phaseOffsets = None,
2615 phaseOffsets = None,
2616 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2616 cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25,
2617 noise_timeStep = 4, noise_multiple = 4,
2617 noise_timeStep = 4, noise_multiple = 4,
2618 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2618 multDet_timeLimit = 1, multDet_rangeLimit = 3,
2619 phaseThresh = 20, SNRThresh = 5,
2619 phaseThresh = 20, SNRThresh = 5,
2620 hmin = 50, hmax=150, azimuth = 0,
2620 hmin = 50, hmax=150, azimuth = 0,
2621 channelPositions = None) :
2621 channelPositions = None) :
2622
2622
2623
2623
2624 #Getting Pairslist
2624 #Getting Pairslist
2625 if channelPositions is None:
2625 if channelPositions is None:
2626 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2626 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2627 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2627 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2628 meteorOps = SMOperations()
2628 meteorOps = SMOperations()
2629 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2629 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
2630 heiRang = dataOut.getHeiRange()
2630 heiRang = dataOut.getHeiRange()
2631 #Get Beacon signal - No Beacon signal anymore
2631 #Get Beacon signal - No Beacon signal anymore
2632 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2632 # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
2633 #
2633 #
2634 # if hei_ref != None:
2634 # if hei_ref != None:
2635 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2635 # newheis = numpy.where(self.dataOut.heightList>hei_ref)
2636 #
2636 #
2637
2637
2638
2638
2639 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2639 #****************REMOVING HARDWARE PHASE DIFFERENCES***************
2640 # see if the user put in pre defined phase shifts
2640 # see if the user put in pre defined phase shifts
2641 voltsPShift = dataOut.data_pre.copy()
2641 voltsPShift = dataOut.data_pre.copy()
2642
2642
2643 # if predefinedPhaseShifts != None:
2643 # if predefinedPhaseShifts != None:
2644 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2644 # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180
2645 #
2645 #
2646 # # elif beaconPhaseShifts:
2646 # # elif beaconPhaseShifts:
2647 # # #get hardware phase shifts using beacon signal
2647 # # #get hardware phase shifts using beacon signal
2648 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2648 # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10)
2649 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2649 # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0)
2650 #
2650 #
2651 # else:
2651 # else:
2652 # hardwarePhaseShifts = numpy.zeros(5)
2652 # hardwarePhaseShifts = numpy.zeros(5)
2653 #
2653 #
2654 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2654 # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex')
2655 # for i in range(self.dataOut.data_pre.shape[0]):
2655 # for i in range(self.dataOut.data_pre.shape[0]):
2656 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2656 # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i])
2657
2657
2658 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2658 #******************END OF REMOVING HARDWARE PHASE DIFFERENCES*********
2659
2659
2660 #Remove DC
2660 #Remove DC
2661 voltsDC = numpy.mean(voltsPShift,1)
2661 voltsDC = numpy.mean(voltsPShift,1)
2662 voltsDC = numpy.mean(voltsDC,1)
2662 voltsDC = numpy.mean(voltsDC,1)
2663 for i in range(voltsDC.shape[0]):
2663 for i in range(voltsDC.shape[0]):
2664 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2664 voltsPShift[i] = voltsPShift[i] - voltsDC[i]
2665
2665
2666 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2666 #Don't considerate last heights, theyre used to calculate Hardware Phase Shift
2667 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2667 # voltsPShift = voltsPShift[:,:,:newheis[0][0]]
2668
2668
2669 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2669 #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) **********
2670 #Coherent Detection
2670 #Coherent Detection
2671 if cohDetection:
2671 if cohDetection:
2672 #use coherent detection to get the net power
2672 #use coherent detection to get the net power
2673 cohDet_thresh = cohDet_thresh*numpy.pi/180
2673 cohDet_thresh = cohDet_thresh*numpy.pi/180
2674 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2674 voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh)
2675
2675
2676 #Non-coherent detection!
2676 #Non-coherent detection!
2677 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2677 powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0)
2678 #********** END OF COH/NON-COH POWER CALCULATION**********************
2678 #********** END OF COH/NON-COH POWER CALCULATION**********************
2679
2679
2680 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2680 #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS ****************
2681 #Get noise
2681 #Get noise
2682 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2682 noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval)
2683 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2683 # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval)
2684 #Get signal threshold
2684 #Get signal threshold
2685 signalThresh = noise_multiple*noise
2685 signalThresh = noise_multiple*noise
2686 #Meteor echoes detection
2686 #Meteor echoes detection
2687 listMeteors = self.__findMeteors(powerNet, signalThresh)
2687 listMeteors = self.__findMeteors(powerNet, signalThresh)
2688 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2688 #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION **********
2689
2689
2690 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2690 #************** REMOVE MULTIPLE DETECTIONS (3.5) ***************************
2691 #Parameters
2691 #Parameters
2692 heiRange = dataOut.getHeiRange()
2692 heiRange = dataOut.getHeiRange()
2693 rangeInterval = heiRange[1] - heiRange[0]
2693 rangeInterval = heiRange[1] - heiRange[0]
2694 rangeLimit = multDet_rangeLimit/rangeInterval
2694 rangeLimit = multDet_rangeLimit/rangeInterval
2695 timeLimit = multDet_timeLimit/dataOut.timeInterval
2695 timeLimit = multDet_timeLimit/dataOut.timeInterval
2696 #Multiple detection removals
2696 #Multiple detection removals
2697 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2697 listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit)
2698 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2698 #************ END OF REMOVE MULTIPLE DETECTIONS **********************
2699
2699
2700 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2700 #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ********************
2701 #Parameters
2701 #Parameters
2702 phaseThresh = phaseThresh*numpy.pi/180
2702 phaseThresh = phaseThresh*numpy.pi/180
2703 thresh = [phaseThresh, noise_multiple, SNRThresh]
2703 thresh = [phaseThresh, noise_multiple, SNRThresh]
2704 #Meteor reestimation (Errors N 1, 6, 12, 17)
2704 #Meteor reestimation (Errors N 1, 6, 12, 17)
2705 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2705 listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency)
2706 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2706 # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise)
2707 #Estimation of decay times (Errors N 7, 8, 11)
2707 #Estimation of decay times (Errors N 7, 8, 11)
2708 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2708 listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency)
2709 #******************* END OF METEOR REESTIMATION *******************
2709 #******************* END OF METEOR REESTIMATION *******************
2710
2710
2711 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2711 #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) **************************
2712 #Calculating Radial Velocity (Error N 15)
2712 #Calculating Radial Velocity (Error N 15)
2713 radialStdThresh = 10
2713 radialStdThresh = 10
2714 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2714 listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval)
2715
2715
2716 if len(listMeteors4) > 0:
2716 if len(listMeteors4) > 0:
2717 #Setting New Array
2717 #Setting New Array
2718 date = dataOut.utctime
2718 date = dataOut.utctime
2719 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2719 arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang)
2720
2720
2721 #Correcting phase offset
2721 #Correcting phase offset
2722 if phaseOffsets != None:
2722 if phaseOffsets != None:
2723 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2723 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
2724 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2724 arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
2725
2725
2726 #Second Pairslist
2726 #Second Pairslist
2727 pairsList = []
2727 pairsList = []
2728 pairx = (0,1)
2728 pairx = (0,1)
2729 pairy = (2,3)
2729 pairy = (2,3)
2730 pairsList.append(pairx)
2730 pairsList.append(pairx)
2731 pairsList.append(pairy)
2731 pairsList.append(pairy)
2732
2732
2733 jph = numpy.array([0,0,0,0])
2733 jph = numpy.array([0,0,0,0])
2734 h = (hmin,hmax)
2734 h = (hmin,hmax)
2735 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2735 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
2736
2736
2737 # #Calculate AOA (Error N 3, 4)
2737 # #Calculate AOA (Error N 3, 4)
2738 # #JONES ET AL. 1998
2738 # #JONES ET AL. 1998
2739 # error = arrayParameters[:,-1]
2739 # error = arrayParameters[:,-1]
2740 # AOAthresh = numpy.pi/8
2740 # AOAthresh = numpy.pi/8
2741 # phases = -arrayParameters[:,9:13]
2741 # phases = -arrayParameters[:,9:13]
2742 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2742 # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth)
2743 #
2743 #
2744 # #Calculate Heights (Error N 13 and 14)
2744 # #Calculate Heights (Error N 13 and 14)
2745 # error = arrayParameters[:,-1]
2745 # error = arrayParameters[:,-1]
2746 # Ranges = arrayParameters[:,2]
2746 # Ranges = arrayParameters[:,2]
2747 # zenith = arrayParameters[:,5]
2747 # zenith = arrayParameters[:,5]
2748 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2748 # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax)
2749 # error = arrayParameters[:,-1]
2749 # error = arrayParameters[:,-1]
2750 #********************* END OF PARAMETERS CALCULATION **************************
2750 #********************* END OF PARAMETERS CALCULATION **************************
2751
2751
2752 #***************************+ PASS DATA TO NEXT STEP **********************
2752 #***************************+ PASS DATA TO NEXT STEP **********************
2753 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2753 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2754 dataOut.data_param = arrayParameters
2754 dataOut.data_param = arrayParameters
2755
2755
2756 if arrayParameters is None:
2756 if arrayParameters is None:
2757 dataOut.flagNoData = True
2757 dataOut.flagNoData = True
2758 else:
2758 else:
2759 dataOut.flagNoData = True
2759 dataOut.flagNoData = True
2760
2760
2761 return
2761 return
2762
2762
2763 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2763 def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n):
2764
2764
2765 minIndex = min(newheis[0])
2765 minIndex = min(newheis[0])
2766 maxIndex = max(newheis[0])
2766 maxIndex = max(newheis[0])
2767
2767
2768 voltage = voltage0[:,:,minIndex:maxIndex+1]
2768 voltage = voltage0[:,:,minIndex:maxIndex+1]
2769 nLength = voltage.shape[1]/n
2769 nLength = voltage.shape[1]/n
2770 nMin = 0
2770 nMin = 0
2771 nMax = 0
2771 nMax = 0
2772 phaseOffset = numpy.zeros((len(pairslist),n))
2772 phaseOffset = numpy.zeros((len(pairslist),n))
2773
2773
2774 for i in range(n):
2774 for i in range(n):
2775 nMax += nLength
2775 nMax += nLength
2776 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2776 phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0]))
2777 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2777 phaseCCF = numpy.mean(phaseCCF, axis = 2)
2778 phaseOffset[:,i] = phaseCCF.transpose()
2778 phaseOffset[:,i] = phaseCCF.transpose()
2779 nMin = nMax
2779 nMin = nMax
2780 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2780 # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist)
2781
2781
2782 #Remove Outliers
2782 #Remove Outliers
2783 factor = 2
2783 factor = 2
2784 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2784 wt = phaseOffset - signal.medfilt(phaseOffset,(1,5))
2785 dw = numpy.std(wt,axis = 1)
2785 dw = numpy.std(wt,axis = 1)
2786 dw = dw.reshape((dw.size,1))
2786 dw = dw.reshape((dw.size,1))
2787 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2787 ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor))
2788 phaseOffset[ind] = numpy.nan
2788 phaseOffset[ind] = numpy.nan
2789 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2789 phaseOffset = stats.nanmean(phaseOffset, axis=1)
2790
2790
2791 return phaseOffset
2791 return phaseOffset
2792
2792
2793 def __shiftPhase(self, data, phaseShift):
2793 def __shiftPhase(self, data, phaseShift):
2794 #this will shift the phase of a complex number
2794 #this will shift the phase of a complex number
2795 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2795 dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j)
2796 return dataShifted
2796 return dataShifted
2797
2797
2798 def __estimatePhaseDifference(self, array, pairslist):
2798 def __estimatePhaseDifference(self, array, pairslist):
2799 nChannel = array.shape[0]
2799 nChannel = array.shape[0]
2800 nHeights = array.shape[2]
2800 nHeights = array.shape[2]
2801 numPairs = len(pairslist)
2801 numPairs = len(pairslist)
2802 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2802 # phaseCCF = numpy.zeros((nChannel, 5, nHeights))
2803 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2803 phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2]))
2804
2804
2805 #Correct phases
2805 #Correct phases
2806 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2806 derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:]
2807 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2807 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
2808
2808
2809 if indDer[0].shape[0] > 0:
2809 if indDer[0].shape[0] > 0:
2810 for i in range(indDer[0].shape[0]):
2810 for i in range(indDer[0].shape[0]):
2811 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2811 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]])
2812 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2812 phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi
2813
2813
2814 # for j in range(numSides):
2814 # for j in range(numSides):
2815 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2815 # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2])
2816 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2816 # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux)
2817 #
2817 #
2818 #Linear
2818 #Linear
2819 phaseInt = numpy.zeros((numPairs,1))
2819 phaseInt = numpy.zeros((numPairs,1))
2820 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2820 angAllCCF = phaseCCF[:,[0,1,3,4],0]
2821 for j in range(numPairs):
2821 for j in range(numPairs):
2822 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2822 fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:])
2823 phaseInt[j] = fit[1]
2823 phaseInt[j] = fit[1]
2824 #Phase Differences
2824 #Phase Differences
2825 phaseDiff = phaseInt - phaseCCF[:,2,:]
2825 phaseDiff = phaseInt - phaseCCF[:,2,:]
2826 phaseArrival = phaseInt.reshape(phaseInt.size)
2826 phaseArrival = phaseInt.reshape(phaseInt.size)
2827
2827
2828 #Dealias
2828 #Dealias
2829 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2829 phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival))
2830 # indAlias = numpy.where(phaseArrival > numpy.pi)
2830 # indAlias = numpy.where(phaseArrival > numpy.pi)
2831 # phaseArrival[indAlias] -= 2*numpy.pi
2831 # phaseArrival[indAlias] -= 2*numpy.pi
2832 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2832 # indAlias = numpy.where(phaseArrival < -numpy.pi)
2833 # phaseArrival[indAlias] += 2*numpy.pi
2833 # phaseArrival[indAlias] += 2*numpy.pi
2834
2834
2835 return phaseDiff, phaseArrival
2835 return phaseDiff, phaseArrival
2836
2836
2837 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
2837 def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh):
2838 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
2838 #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power
2839 #find the phase shifts of each channel over 1 second intervals
2839 #find the phase shifts of each channel over 1 second intervals
2840 #only look at ranges below the beacon signal
2840 #only look at ranges below the beacon signal
2841 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2841 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2842 numBlocks = int(volts.shape[1]/numProfPerBlock)
2842 numBlocks = int(volts.shape[1]/numProfPerBlock)
2843 numHeights = volts.shape[2]
2843 numHeights = volts.shape[2]
2844 nChannel = volts.shape[0]
2844 nChannel = volts.shape[0]
2845 voltsCohDet = volts.copy()
2845 voltsCohDet = volts.copy()
2846
2846
2847 pairsarray = numpy.array(pairslist)
2847 pairsarray = numpy.array(pairslist)
2848 indSides = pairsarray[:,1]
2848 indSides = pairsarray[:,1]
2849 # indSides = numpy.array(range(nChannel))
2849 # indSides = numpy.array(range(nChannel))
2850 # indSides = numpy.delete(indSides, indCenter)
2850 # indSides = numpy.delete(indSides, indCenter)
2851 #
2851 #
2852 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
2852 # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0)
2853 listBlocks = numpy.array_split(volts, numBlocks, 1)
2853 listBlocks = numpy.array_split(volts, numBlocks, 1)
2854
2854
2855 startInd = 0
2855 startInd = 0
2856 endInd = 0
2856 endInd = 0
2857
2857
2858 for i in range(numBlocks):
2858 for i in range(numBlocks):
2859 startInd = endInd
2859 startInd = endInd
2860 endInd = endInd + listBlocks[i].shape[1]
2860 endInd = endInd + listBlocks[i].shape[1]
2861
2861
2862 arrayBlock = listBlocks[i]
2862 arrayBlock = listBlocks[i]
2863 # arrayBlockCenter = listCenter[i]
2863 # arrayBlockCenter = listCenter[i]
2864
2864
2865 #Estimate the Phase Difference
2865 #Estimate the Phase Difference
2866 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
2866 phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist)
2867 #Phase Difference RMS
2867 #Phase Difference RMS
2868 arrayPhaseRMS = numpy.abs(phaseDiff)
2868 arrayPhaseRMS = numpy.abs(phaseDiff)
2869 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
2869 phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0)
2870 indPhase = numpy.where(phaseRMSaux==4)
2870 indPhase = numpy.where(phaseRMSaux==4)
2871 #Shifting
2871 #Shifting
2872 if indPhase[0].shape[0] > 0:
2872 if indPhase[0].shape[0] > 0:
2873 for j in range(indSides.size):
2873 for j in range(indSides.size):
2874 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
2874 arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose())
2875 voltsCohDet[:,startInd:endInd,:] = arrayBlock
2875 voltsCohDet[:,startInd:endInd,:] = arrayBlock
2876
2876
2877 return voltsCohDet
2877 return voltsCohDet
2878
2878
2879 def __calculateCCF(self, volts, pairslist ,laglist):
2879 def __calculateCCF(self, volts, pairslist ,laglist):
2880
2880
2881 nHeights = volts.shape[2]
2881 nHeights = volts.shape[2]
2882 nPoints = volts.shape[1]
2882 nPoints = volts.shape[1]
2883 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
2883 voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex')
2884
2884
2885 for i in range(len(pairslist)):
2885 for i in range(len(pairslist)):
2886 volts1 = volts[pairslist[i][0]]
2886 volts1 = volts[pairslist[i][0]]
2887 volts2 = volts[pairslist[i][1]]
2887 volts2 = volts[pairslist[i][1]]
2888
2888
2889 for t in range(len(laglist)):
2889 for t in range(len(laglist)):
2890 idxT = laglist[t]
2890 idxT = laglist[t]
2891 if idxT >= 0:
2891 if idxT >= 0:
2892 vStacked = numpy.vstack((volts2[idxT:,:],
2892 vStacked = numpy.vstack((volts2[idxT:,:],
2893 numpy.zeros((idxT, nHeights),dtype='complex')))
2893 numpy.zeros((idxT, nHeights),dtype='complex')))
2894 else:
2894 else:
2895 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
2895 vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'),
2896 volts2[:(nPoints + idxT),:]))
2896 volts2[:(nPoints + idxT),:]))
2897 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
2897 voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0)
2898
2898
2899 vStacked = None
2899 vStacked = None
2900 return voltsCCF
2900 return voltsCCF
2901
2901
2902 def __getNoise(self, power, timeSegment, timeInterval):
2902 def __getNoise(self, power, timeSegment, timeInterval):
2903 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2903 numProfPerBlock = numpy.ceil(timeSegment/timeInterval)
2904 numBlocks = int(power.shape[0]/numProfPerBlock)
2904 numBlocks = int(power.shape[0]/numProfPerBlock)
2905 numHeights = power.shape[1]
2905 numHeights = power.shape[1]
2906
2906
2907 listPower = numpy.array_split(power, numBlocks, 0)
2907 listPower = numpy.array_split(power, numBlocks, 0)
2908 noise = numpy.zeros((power.shape[0], power.shape[1]))
2908 noise = numpy.zeros((power.shape[0], power.shape[1]))
2909 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
2909 noise1 = numpy.zeros((power.shape[0], power.shape[1]))
2910
2910
2911 startInd = 0
2911 startInd = 0
2912 endInd = 0
2912 endInd = 0
2913
2913
2914 for i in range(numBlocks): #split por canal
2914 for i in range(numBlocks): #split por canal
2915 startInd = endInd
2915 startInd = endInd
2916 endInd = endInd + listPower[i].shape[0]
2916 endInd = endInd + listPower[i].shape[0]
2917
2917
2918 arrayBlock = listPower[i]
2918 arrayBlock = listPower[i]
2919 noiseAux = numpy.mean(arrayBlock, 0)
2919 noiseAux = numpy.mean(arrayBlock, 0)
2920 # noiseAux = numpy.median(noiseAux)
2920 # noiseAux = numpy.median(noiseAux)
2921 # noiseAux = numpy.mean(arrayBlock)
2921 # noiseAux = numpy.mean(arrayBlock)
2922 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
2922 noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux
2923
2923
2924 noiseAux1 = numpy.mean(arrayBlock)
2924 noiseAux1 = numpy.mean(arrayBlock)
2925 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
2925 noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1
2926
2926
2927 return noise, noise1
2927 return noise, noise1
2928
2928
2929 def __findMeteors(self, power, thresh):
2929 def __findMeteors(self, power, thresh):
2930 nProf = power.shape[0]
2930 nProf = power.shape[0]
2931 nHeights = power.shape[1]
2931 nHeights = power.shape[1]
2932 listMeteors = []
2932 listMeteors = []
2933
2933
2934 for i in range(nHeights):
2934 for i in range(nHeights):
2935 powerAux = power[:,i]
2935 powerAux = power[:,i]
2936 threshAux = thresh[:,i]
2936 threshAux = thresh[:,i]
2937
2937
2938 indUPthresh = numpy.where(powerAux > threshAux)[0]
2938 indUPthresh = numpy.where(powerAux > threshAux)[0]
2939 indDNthresh = numpy.where(powerAux <= threshAux)[0]
2939 indDNthresh = numpy.where(powerAux <= threshAux)[0]
2940
2940
2941 j = 0
2941 j = 0
2942
2942
2943 while (j < indUPthresh.size - 2):
2943 while (j < indUPthresh.size - 2):
2944 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
2944 if (indUPthresh[j + 2] == indUPthresh[j] + 2):
2945 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
2945 indDNAux = numpy.where(indDNthresh > indUPthresh[j])
2946 indDNthresh = indDNthresh[indDNAux]
2946 indDNthresh = indDNthresh[indDNAux]
2947
2947
2948 if (indDNthresh.size > 0):
2948 if (indDNthresh.size > 0):
2949 indEnd = indDNthresh[0] - 1
2949 indEnd = indDNthresh[0] - 1
2950 indInit = indUPthresh[j]
2950 indInit = indUPthresh[j]
2951
2951
2952 meteor = powerAux[indInit:indEnd + 1]
2952 meteor = powerAux[indInit:indEnd + 1]
2953 indPeak = meteor.argmax() + indInit
2953 indPeak = meteor.argmax() + indInit
2954 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
2954 FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0)))
2955
2955
2956 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
2956 listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!!
2957 j = numpy.where(indUPthresh == indEnd)[0] + 1
2957 j = numpy.where(indUPthresh == indEnd)[0] + 1
2958 else: j+=1
2958 else: j+=1
2959 else: j+=1
2959 else: j+=1
2960
2960
2961 return listMeteors
2961 return listMeteors
2962
2962
2963 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
2963 def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit):
2964
2964
2965 arrayMeteors = numpy.asarray(listMeteors)
2965 arrayMeteors = numpy.asarray(listMeteors)
2966 listMeteors1 = []
2966 listMeteors1 = []
2967
2967
2968 while arrayMeteors.shape[0] > 0:
2968 while arrayMeteors.shape[0] > 0:
2969 FLAs = arrayMeteors[:,4]
2969 FLAs = arrayMeteors[:,4]
2970 maxFLA = FLAs.argmax()
2970 maxFLA = FLAs.argmax()
2971 listMeteors1.append(arrayMeteors[maxFLA,:])
2971 listMeteors1.append(arrayMeteors[maxFLA,:])
2972
2972
2973 MeteorInitTime = arrayMeteors[maxFLA,1]
2973 MeteorInitTime = arrayMeteors[maxFLA,1]
2974 MeteorEndTime = arrayMeteors[maxFLA,3]
2974 MeteorEndTime = arrayMeteors[maxFLA,3]
2975 MeteorHeight = arrayMeteors[maxFLA,0]
2975 MeteorHeight = arrayMeteors[maxFLA,0]
2976
2976
2977 #Check neighborhood
2977 #Check neighborhood
2978 maxHeightIndex = MeteorHeight + rangeLimit
2978 maxHeightIndex = MeteorHeight + rangeLimit
2979 minHeightIndex = MeteorHeight - rangeLimit
2979 minHeightIndex = MeteorHeight - rangeLimit
2980 minTimeIndex = MeteorInitTime - timeLimit
2980 minTimeIndex = MeteorInitTime - timeLimit
2981 maxTimeIndex = MeteorEndTime + timeLimit
2981 maxTimeIndex = MeteorEndTime + timeLimit
2982
2982
2983 #Check Heights
2983 #Check Heights
2984 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
2984 indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex)
2985 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
2985 indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex)
2986 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
2986 indBoth = numpy.where(numpy.logical_and(indTime,indHeight))
2987
2987
2988 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
2988 arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0)
2989
2989
2990 return listMeteors1
2990 return listMeteors1
2991
2991
2992 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
2992 def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency):
2993 numHeights = volts.shape[2]
2993 numHeights = volts.shape[2]
2994 nChannel = volts.shape[0]
2994 nChannel = volts.shape[0]
2995
2995
2996 thresholdPhase = thresh[0]
2996 thresholdPhase = thresh[0]
2997 thresholdNoise = thresh[1]
2997 thresholdNoise = thresh[1]
2998 thresholdDB = float(thresh[2])
2998 thresholdDB = float(thresh[2])
2999
2999
3000 thresholdDB1 = 10**(thresholdDB/10)
3000 thresholdDB1 = 10**(thresholdDB/10)
3001 pairsarray = numpy.array(pairslist)
3001 pairsarray = numpy.array(pairslist)
3002 indSides = pairsarray[:,1]
3002 indSides = pairsarray[:,1]
3003
3003
3004 pairslist1 = list(pairslist)
3004 pairslist1 = list(pairslist)
3005 pairslist1.append((0,1))
3005 pairslist1.append((0,1))
3006 pairslist1.append((3,4))
3006 pairslist1.append((3,4))
3007
3007
3008 listMeteors1 = []
3008 listMeteors1 = []
3009 listPowerSeries = []
3009 listPowerSeries = []
3010 listVoltageSeries = []
3010 listVoltageSeries = []
3011 #volts has the war data
3011 #volts has the war data
3012
3012
3013 if frequency == 30e6:
3013 if frequency == 30e6:
3014 timeLag = 45*10**-3
3014 timeLag = 45*10**-3
3015 else:
3015 else:
3016 timeLag = 15*10**-3
3016 timeLag = 15*10**-3
3017 lag = numpy.ceil(timeLag/timeInterval)
3017 lag = numpy.ceil(timeLag/timeInterval)
3018
3018
3019 for i in range(len(listMeteors)):
3019 for i in range(len(listMeteors)):
3020
3020
3021 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3021 ###################### 3.6 - 3.7 PARAMETERS REESTIMATION #########################
3022 meteorAux = numpy.zeros(16)
3022 meteorAux = numpy.zeros(16)
3023
3023
3024 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3024 #Loading meteor Data (mHeight, mStart, mPeak, mEnd)
3025 mHeight = listMeteors[i][0]
3025 mHeight = listMeteors[i][0]
3026 mStart = listMeteors[i][1]
3026 mStart = listMeteors[i][1]
3027 mPeak = listMeteors[i][2]
3027 mPeak = listMeteors[i][2]
3028 mEnd = listMeteors[i][3]
3028 mEnd = listMeteors[i][3]
3029
3029
3030 #get the volt data between the start and end times of the meteor
3030 #get the volt data between the start and end times of the meteor
3031 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3031 meteorVolts = volts[:,mStart:mEnd+1,mHeight]
3032 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3032 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3033
3033
3034 #3.6. Phase Difference estimation
3034 #3.6. Phase Difference estimation
3035 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3035 phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist)
3036
3036
3037 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3037 #3.7. Phase difference removal & meteor start, peak and end times reestimated
3038 #meteorVolts0.- all Channels, all Profiles
3038 #meteorVolts0.- all Channels, all Profiles
3039 meteorVolts0 = volts[:,:,mHeight]
3039 meteorVolts0 = volts[:,:,mHeight]
3040 meteorThresh = noise[:,mHeight]*thresholdNoise
3040 meteorThresh = noise[:,mHeight]*thresholdNoise
3041 meteorNoise = noise[:,mHeight]
3041 meteorNoise = noise[:,mHeight]
3042 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3042 meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting
3043 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3043 powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power
3044
3044
3045 #Times reestimation
3045 #Times reestimation
3046 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3046 mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0]
3047 if mStart1.size > 0:
3047 if mStart1.size > 0:
3048 mStart1 = mStart1[-1] + 1
3048 mStart1 = mStart1[-1] + 1
3049
3049
3050 else:
3050 else:
3051 mStart1 = mPeak
3051 mStart1 = mPeak
3052
3052
3053 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3053 mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1
3054 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3054 mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0]
3055 if mEndDecayTime1.size == 0:
3055 if mEndDecayTime1.size == 0:
3056 mEndDecayTime1 = powerNet0.size
3056 mEndDecayTime1 = powerNet0.size
3057 else:
3057 else:
3058 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3058 mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1
3059 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3059 # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax()
3060
3060
3061 #meteorVolts1.- all Channels, from start to end
3061 #meteorVolts1.- all Channels, from start to end
3062 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3062 meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1]
3063 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3063 meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1]
3064 if meteorVolts2.shape[1] == 0:
3064 if meteorVolts2.shape[1] == 0:
3065 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3065 meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1]
3066 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3066 meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1)
3067 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3067 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1)
3068 ##################### END PARAMETERS REESTIMATION #########################
3068 ##################### END PARAMETERS REESTIMATION #########################
3069
3069
3070 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3070 ##################### 3.8 PHASE DIFFERENCE REESTIMATION ########################
3071 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3071 # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis
3072 if meteorVolts2.shape[1] > 0:
3072 if meteorVolts2.shape[1] > 0:
3073 #Phase Difference re-estimation
3073 #Phase Difference re-estimation
3074 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3074 phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation
3075 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3075 # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist)
3076 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3076 meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1])
3077 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3077 phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1))
3078 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3078 meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting
3079
3079
3080 #Phase Difference RMS
3080 #Phase Difference RMS
3081 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3081 phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1)))
3082 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3082 powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0)
3083 #Data from Meteor
3083 #Data from Meteor
3084 mPeak1 = powerNet1.argmax() + mStart1
3084 mPeak1 = powerNet1.argmax() + mStart1
3085 mPeakPower1 = powerNet1.max()
3085 mPeakPower1 = powerNet1.max()
3086 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3086 noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight])
3087 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3087 mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux
3088 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3088 Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1])
3089 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3089 Meteor1 = numpy.hstack((Meteor1,phaseDiffint))
3090 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3090 PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1]
3091 #Vectorize
3091 #Vectorize
3092 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3092 meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]
3093 meteorAux[7:11] = phaseDiffint[0:4]
3093 meteorAux[7:11] = phaseDiffint[0:4]
3094
3094
3095 #Rejection Criterions
3095 #Rejection Criterions
3096 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3096 if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation
3097 meteorAux[-1] = 17
3097 meteorAux[-1] = 17
3098 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3098 elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB
3099 meteorAux[-1] = 1
3099 meteorAux[-1] = 1
3100
3100
3101
3101
3102 else:
3102 else:
3103 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3103 meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd]
3104 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3104 meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis
3105 PowerSeries = 0
3105 PowerSeries = 0
3106
3106
3107 listMeteors1.append(meteorAux)
3107 listMeteors1.append(meteorAux)
3108 listPowerSeries.append(PowerSeries)
3108 listPowerSeries.append(PowerSeries)
3109 listVoltageSeries.append(meteorVolts1)
3109 listVoltageSeries.append(meteorVolts1)
3110
3110
3111 return listMeteors1, listPowerSeries, listVoltageSeries
3111 return listMeteors1, listPowerSeries, listVoltageSeries
3112
3112
3113 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3113 def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency):
3114
3114
3115 threshError = 10
3115 threshError = 10
3116 #Depending if it is 30 or 50 MHz
3116 #Depending if it is 30 or 50 MHz
3117 if frequency == 30e6:
3117 if frequency == 30e6:
3118 timeLag = 45*10**-3
3118 timeLag = 45*10**-3
3119 else:
3119 else:
3120 timeLag = 15*10**-3
3120 timeLag = 15*10**-3
3121 lag = numpy.ceil(timeLag/timeInterval)
3121 lag = numpy.ceil(timeLag/timeInterval)
3122
3122
3123 listMeteors1 = []
3123 listMeteors1 = []
3124
3124
3125 for i in range(len(listMeteors)):
3125 for i in range(len(listMeteors)):
3126 meteorPower = listPower[i]
3126 meteorPower = listPower[i]
3127 meteorAux = listMeteors[i]
3127 meteorAux = listMeteors[i]
3128
3128
3129 if meteorAux[-1] == 0:
3129 if meteorAux[-1] == 0:
3130
3130
3131 try:
3131 try:
3132 indmax = meteorPower.argmax()
3132 indmax = meteorPower.argmax()
3133 indlag = indmax + lag
3133 indlag = indmax + lag
3134
3134
3135 y = meteorPower[indlag:]
3135 y = meteorPower[indlag:]
3136 x = numpy.arange(0, y.size)*timeLag
3136 x = numpy.arange(0, y.size)*timeLag
3137
3137
3138 #first guess
3138 #first guess
3139 a = y[0]
3139 a = y[0]
3140 tau = timeLag
3140 tau = timeLag
3141 #exponential fit
3141 #exponential fit
3142 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3142 popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau])
3143 y1 = self.__exponential_function(x, *popt)
3143 y1 = self.__exponential_function(x, *popt)
3144 #error estimation
3144 #error estimation
3145 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3145 error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size))
3146
3146
3147 decayTime = popt[1]
3147 decayTime = popt[1]
3148 riseTime = indmax*timeInterval
3148 riseTime = indmax*timeInterval
3149 meteorAux[11:13] = [decayTime, error]
3149 meteorAux[11:13] = [decayTime, error]
3150
3150
3151 #Table items 7, 8 and 11
3151 #Table items 7, 8 and 11
3152 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3152 if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s
3153 meteorAux[-1] = 7
3153 meteorAux[-1] = 7
3154 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3154 elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time
3155 meteorAux[-1] = 8
3155 meteorAux[-1] = 8
3156 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3156 if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time
3157 meteorAux[-1] = 11
3157 meteorAux[-1] = 11
3158
3158
3159
3159
3160 except:
3160 except:
3161 meteorAux[-1] = 11
3161 meteorAux[-1] = 11
3162
3162
3163
3163
3164 listMeteors1.append(meteorAux)
3164 listMeteors1.append(meteorAux)
3165
3165
3166 return listMeteors1
3166 return listMeteors1
3167
3167
3168 #Exponential Function
3168 #Exponential Function
3169
3169
3170 def __exponential_function(self, x, a, tau):
3170 def __exponential_function(self, x, a, tau):
3171 y = a*numpy.exp(-x/tau)
3171 y = a*numpy.exp(-x/tau)
3172 return y
3172 return y
3173
3173
3174 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3174 def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval):
3175
3175
3176 pairslist1 = list(pairslist)
3176 pairslist1 = list(pairslist)
3177 pairslist1.append((0,1))
3177 pairslist1.append((0,1))
3178 pairslist1.append((3,4))
3178 pairslist1.append((3,4))
3179 numPairs = len(pairslist1)
3179 numPairs = len(pairslist1)
3180 #Time Lag
3180 #Time Lag
3181 timeLag = 45*10**-3
3181 timeLag = 45*10**-3
3182 c = 3e8
3182 c = 3e8
3183 lag = numpy.ceil(timeLag/timeInterval)
3183 lag = numpy.ceil(timeLag/timeInterval)
3184 freq = 30e6
3184 freq = 30e6
3185
3185
3186 listMeteors1 = []
3186 listMeteors1 = []
3187
3187
3188 for i in range(len(listMeteors)):
3188 for i in range(len(listMeteors)):
3189 meteorAux = listMeteors[i]
3189 meteorAux = listMeteors[i]
3190 if meteorAux[-1] == 0:
3190 if meteorAux[-1] == 0:
3191 mStart = listMeteors[i][1]
3191 mStart = listMeteors[i][1]
3192 mPeak = listMeteors[i][2]
3192 mPeak = listMeteors[i][2]
3193 mLag = mPeak - mStart + lag
3193 mLag = mPeak - mStart + lag
3194
3194
3195 #get the volt data between the start and end times of the meteor
3195 #get the volt data between the start and end times of the meteor
3196 meteorVolts = listVolts[i]
3196 meteorVolts = listVolts[i]
3197 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3197 meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1)
3198
3198
3199 #Get CCF
3199 #Get CCF
3200 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3200 allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2])
3201
3201
3202 #Method 2
3202 #Method 2
3203 slopes = numpy.zeros(numPairs)
3203 slopes = numpy.zeros(numPairs)
3204 time = numpy.array([-2,-1,1,2])*timeInterval
3204 time = numpy.array([-2,-1,1,2])*timeInterval
3205 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3205 angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0])
3206
3206
3207 #Correct phases
3207 #Correct phases
3208 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3208 derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1]
3209 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3209 indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi)
3210
3210
3211 if indDer[0].shape[0] > 0:
3211 if indDer[0].shape[0] > 0:
3212 for i in range(indDer[0].shape[0]):
3212 for i in range(indDer[0].shape[0]):
3213 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3213 signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]])
3214 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3214 angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi
3215
3215
3216 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3216 # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]]))
3217 for j in range(numPairs):
3217 for j in range(numPairs):
3218 fit = stats.linregress(time, angAllCCF[j,:])
3218 fit = stats.linregress(time, angAllCCF[j,:])
3219 slopes[j] = fit[0]
3219 slopes[j] = fit[0]
3220
3220
3221 #Remove Outlier
3221 #Remove Outlier
3222 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3222 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3223 # slopes = numpy.delete(slopes,indOut)
3223 # slopes = numpy.delete(slopes,indOut)
3224 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3224 # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes)))
3225 # slopes = numpy.delete(slopes,indOut)
3225 # slopes = numpy.delete(slopes,indOut)
3226
3226
3227 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3227 radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq)
3228 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3228 radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq)
3229 meteorAux[-2] = radialError
3229 meteorAux[-2] = radialError
3230 meteorAux[-3] = radialVelocity
3230 meteorAux[-3] = radialVelocity
3231
3231
3232 #Setting Error
3232 #Setting Error
3233 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3233 #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s
3234 if numpy.abs(radialVelocity) > 200:
3234 if numpy.abs(radialVelocity) > 200:
3235 meteorAux[-1] = 15
3235 meteorAux[-1] = 15
3236 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3236 #Number 12: Poor fit to CCF variation for estimation of radial drift velocity
3237 elif radialError > radialStdThresh:
3237 elif radialError > radialStdThresh:
3238 meteorAux[-1] = 12
3238 meteorAux[-1] = 12
3239
3239
3240 listMeteors1.append(meteorAux)
3240 listMeteors1.append(meteorAux)
3241 return listMeteors1
3241 return listMeteors1
3242
3242
3243 def __setNewArrays(self, listMeteors, date, heiRang):
3243 def __setNewArrays(self, listMeteors, date, heiRang):
3244
3244
3245 #New arrays
3245 #New arrays
3246 arrayMeteors = numpy.array(listMeteors)
3246 arrayMeteors = numpy.array(listMeteors)
3247 arrayParameters = numpy.zeros((len(listMeteors), 13))
3247 arrayParameters = numpy.zeros((len(listMeteors), 13))
3248
3248
3249 #Date inclusion
3249 #Date inclusion
3250 # date = re.findall(r'\((.*?)\)', date)
3250 # date = re.findall(r'\((.*?)\)', date)
3251 # date = date[0].split(',')
3251 # date = date[0].split(',')
3252 # date = map(int, date)
3252 # date = map(int, date)
3253 #
3253 #
3254 # if len(date)<6:
3254 # if len(date)<6:
3255 # date.append(0)
3255 # date.append(0)
3256 #
3256 #
3257 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3257 # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]]
3258 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3258 # arrayDate = numpy.tile(date, (len(listMeteors), 1))
3259 arrayDate = numpy.tile(date, (len(listMeteors)))
3259 arrayDate = numpy.tile(date, (len(listMeteors)))
3260
3260
3261 #Meteor array
3261 #Meteor array
3262 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3262 # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)]
3263 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3263 # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors))
3264
3264
3265 #Parameters Array
3265 #Parameters Array
3266 arrayParameters[:,0] = arrayDate #Date
3266 arrayParameters[:,0] = arrayDate #Date
3267 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3267 arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range
3268 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3268 arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error
3269 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3269 arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases
3270 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3270 arrayParameters[:,-1] = arrayMeteors[:,-1] #Error
3271
3271
3272
3272
3273 return arrayParameters
3273 return arrayParameters
3274
3274
3275 class CorrectSMPhases(Operation):
3275 class CorrectSMPhases(Operation):
3276
3276
3277 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3277 def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None):
3278
3278
3279 arrayParameters = dataOut.data_param
3279 arrayParameters = dataOut.data_param
3280 pairsList = []
3280 pairsList = []
3281 pairx = (0,1)
3281 pairx = (0,1)
3282 pairy = (2,3)
3282 pairy = (2,3)
3283 pairsList.append(pairx)
3283 pairsList.append(pairx)
3284 pairsList.append(pairy)
3284 pairsList.append(pairy)
3285 jph = numpy.zeros(4)
3285 jph = numpy.zeros(4)
3286
3286
3287 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3287 phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180
3288 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3288 # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets)
3289 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3289 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3290
3290
3291 meteorOps = SMOperations()
3291 meteorOps = SMOperations()
3292 if channelPositions is None:
3292 if channelPositions is None:
3293 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3293 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3294 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3294 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3295
3295
3296 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3296 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3297 h = (hmin,hmax)
3297 h = (hmin,hmax)
3298
3298
3299 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3299 arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph)
3300
3300
3301 dataOut.data_param = arrayParameters
3301 dataOut.data_param = arrayParameters
3302 return
3302 return
3303
3303
3304 class SMPhaseCalibration(Operation):
3304 class SMPhaseCalibration(Operation):
3305
3305
3306 __buffer = None
3306 __buffer = None
3307
3307
3308 __initime = None
3308 __initime = None
3309
3309
3310 __dataReady = False
3310 __dataReady = False
3311
3311
3312 __isConfig = False
3312 __isConfig = False
3313
3313
3314 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3314 def __checkTime(self, currentTime, initTime, paramInterval, outputInterval):
3315
3315
3316 dataTime = currentTime + paramInterval
3316 dataTime = currentTime + paramInterval
3317 deltaTime = dataTime - initTime
3317 deltaTime = dataTime - initTime
3318
3318
3319 if deltaTime >= outputInterval or deltaTime < 0:
3319 if deltaTime >= outputInterval or deltaTime < 0:
3320 return True
3320 return True
3321
3321
3322 return False
3322 return False
3323
3323
3324 def __getGammas(self, pairs, d, phases):
3324 def __getGammas(self, pairs, d, phases):
3325 gammas = numpy.zeros(2)
3325 gammas = numpy.zeros(2)
3326
3326
3327 for i in range(len(pairs)):
3327 for i in range(len(pairs)):
3328
3328
3329 pairi = pairs[i]
3329 pairi = pairs[i]
3330
3330
3331 phip3 = phases[:,pairi[0]]
3331 phip3 = phases[:,pairi[0]]
3332 d3 = d[pairi[0]]
3332 d3 = d[pairi[0]]
3333 phip2 = phases[:,pairi[1]]
3333 phip2 = phases[:,pairi[1]]
3334 d2 = d[pairi[1]]
3334 d2 = d[pairi[1]]
3335 #Calculating gamma
3335 #Calculating gamma
3336 # jdcos = alp1/(k*d1)
3336 # jdcos = alp1/(k*d1)
3337 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3337 # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0)))
3338 jgamma = -phip2*d3/d2 - phip3
3338 jgamma = -phip2*d3/d2 - phip3
3339 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3339 jgamma = numpy.angle(numpy.exp(1j*jgamma))
3340 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3340 # jgamma[jgamma>numpy.pi] -= 2*numpy.pi
3341 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3341 # jgamma[jgamma<-numpy.pi] += 2*numpy.pi
3342
3342
3343 #Revised distribution
3343 #Revised distribution
3344 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3344 jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi))
3345
3345
3346 #Histogram
3346 #Histogram
3347 nBins = 64
3347 nBins = 64
3348 rmin = -0.5*numpy.pi
3348 rmin = -0.5*numpy.pi
3349 rmax = 0.5*numpy.pi
3349 rmax = 0.5*numpy.pi
3350 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3350 phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax))
3351
3351
3352 meteorsY = phaseHisto[0]
3352 meteorsY = phaseHisto[0]
3353 phasesX = phaseHisto[1][:-1]
3353 phasesX = phaseHisto[1][:-1]
3354 width = phasesX[1] - phasesX[0]
3354 width = phasesX[1] - phasesX[0]
3355 phasesX += width/2
3355 phasesX += width/2
3356
3356
3357 #Gaussian aproximation
3357 #Gaussian aproximation
3358 bpeak = meteorsY.argmax()
3358 bpeak = meteorsY.argmax()
3359 peak = meteorsY.max()
3359 peak = meteorsY.max()
3360 jmin = bpeak - 5
3360 jmin = bpeak - 5
3361 jmax = bpeak + 5 + 1
3361 jmax = bpeak + 5 + 1
3362
3362
3363 if jmin<0:
3363 if jmin<0:
3364 jmin = 0
3364 jmin = 0
3365 jmax = 6
3365 jmax = 6
3366 elif jmax > meteorsY.size:
3366 elif jmax > meteorsY.size:
3367 jmin = meteorsY.size - 6
3367 jmin = meteorsY.size - 6
3368 jmax = meteorsY.size
3368 jmax = meteorsY.size
3369
3369
3370 x0 = numpy.array([peak,bpeak,50])
3370 x0 = numpy.array([peak,bpeak,50])
3371 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3371 coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax]))
3372
3372
3373 #Gammas
3373 #Gammas
3374 gammas[i] = coeff[0][1]
3374 gammas[i] = coeff[0][1]
3375
3375
3376 return gammas
3376 return gammas
3377
3377
3378 def __residualFunction(self, coeffs, y, t):
3378 def __residualFunction(self, coeffs, y, t):
3379
3379
3380 return y - self.__gauss_function(t, coeffs)
3380 return y - self.__gauss_function(t, coeffs)
3381
3381
3382 def __gauss_function(self, t, coeffs):
3382 def __gauss_function(self, t, coeffs):
3383
3383
3384 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3384 return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2)
3385
3385
3386 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3386 def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray):
3387 meteorOps = SMOperations()
3387 meteorOps = SMOperations()
3388 nchan = 4
3388 nchan = 4
3389 pairx = pairsList[0] #x es 0
3389 pairx = pairsList[0] #x es 0
3390 pairy = pairsList[1] #y es 1
3390 pairy = pairsList[1] #y es 1
3391 center_xangle = 0
3391 center_xangle = 0
3392 center_yangle = 0
3392 center_yangle = 0
3393 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3393 range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4])
3394 ntimes = len(range_angle)
3394 ntimes = len(range_angle)
3395
3395
3396 nstepsx = 20
3396 nstepsx = 20
3397 nstepsy = 20
3397 nstepsy = 20
3398
3398
3399 for iz in range(ntimes):
3399 for iz in range(ntimes):
3400 min_xangle = -range_angle[iz]/2 + center_xangle
3400 min_xangle = -range_angle[iz]/2 + center_xangle
3401 max_xangle = range_angle[iz]/2 + center_xangle
3401 max_xangle = range_angle[iz]/2 + center_xangle
3402 min_yangle = -range_angle[iz]/2 + center_yangle
3402 min_yangle = -range_angle[iz]/2 + center_yangle
3403 max_yangle = range_angle[iz]/2 + center_yangle
3403 max_yangle = range_angle[iz]/2 + center_yangle
3404
3404
3405 inc_x = (max_xangle-min_xangle)/nstepsx
3405 inc_x = (max_xangle-min_xangle)/nstepsx
3406 inc_y = (max_yangle-min_yangle)/nstepsy
3406 inc_y = (max_yangle-min_yangle)/nstepsy
3407
3407
3408 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3408 alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle
3409 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3409 alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle
3410 penalty = numpy.zeros((nstepsx,nstepsy))
3410 penalty = numpy.zeros((nstepsx,nstepsy))
3411 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3411 jph_array = numpy.zeros((nchan,nstepsx,nstepsy))
3412 jph = numpy.zeros(nchan)
3412 jph = numpy.zeros(nchan)
3413
3413
3414 # Iterations looking for the offset
3414 # Iterations looking for the offset
3415 for iy in range(int(nstepsy)):
3415 for iy in range(int(nstepsy)):
3416 for ix in range(int(nstepsx)):
3416 for ix in range(int(nstepsx)):
3417 d3 = d[pairsList[1][0]]
3417 d3 = d[pairsList[1][0]]
3418 d2 = d[pairsList[1][1]]
3418 d2 = d[pairsList[1][1]]
3419 d5 = d[pairsList[0][0]]
3419 d5 = d[pairsList[0][0]]
3420 d4 = d[pairsList[0][1]]
3420 d4 = d[pairsList[0][1]]
3421
3421
3422 alp2 = alpha_y[iy] #gamma 1
3422 alp2 = alpha_y[iy] #gamma 1
3423 alp4 = alpha_x[ix] #gamma 0
3423 alp4 = alpha_x[ix] #gamma 0
3424
3424
3425 alp3 = -alp2*d3/d2 - gammas[1]
3425 alp3 = -alp2*d3/d2 - gammas[1]
3426 alp5 = -alp4*d5/d4 - gammas[0]
3426 alp5 = -alp4*d5/d4 - gammas[0]
3427 # jph[pairy[1]] = alpha_y[iy]
3427 # jph[pairy[1]] = alpha_y[iy]
3428 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3428 # jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]]
3429
3429
3430 # jph[pairx[1]] = alpha_x[ix]
3430 # jph[pairx[1]] = alpha_x[ix]
3431 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3431 # jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]]
3432 jph[pairsList[0][1]] = alp4
3432 jph[pairsList[0][1]] = alp4
3433 jph[pairsList[0][0]] = alp5
3433 jph[pairsList[0][0]] = alp5
3434 jph[pairsList[1][0]] = alp3
3434 jph[pairsList[1][0]] = alp3
3435 jph[pairsList[1][1]] = alp2
3435 jph[pairsList[1][1]] = alp2
3436 jph_array[:,ix,iy] = jph
3436 jph_array[:,ix,iy] = jph
3437 # d = [2.0,2.5,2.5,2.0]
3437 # d = [2.0,2.5,2.5,2.0]
3438 #falta chequear si va a leer bien los meteoros
3438 #falta chequear si va a leer bien los meteoros
3439 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3439 meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph)
3440 error = meteorsArray1[:,-1]
3440 error = meteorsArray1[:,-1]
3441 ind1 = numpy.where(error==0)[0]
3441 ind1 = numpy.where(error==0)[0]
3442 penalty[ix,iy] = ind1.size
3442 penalty[ix,iy] = ind1.size
3443
3443
3444 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3444 i,j = numpy.unravel_index(penalty.argmax(), penalty.shape)
3445 phOffset = jph_array[:,i,j]
3445 phOffset = jph_array[:,i,j]
3446
3446
3447 center_xangle = phOffset[pairx[1]]
3447 center_xangle = phOffset[pairx[1]]
3448 center_yangle = phOffset[pairy[1]]
3448 center_yangle = phOffset[pairy[1]]
3449
3449
3450 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3450 phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j]))
3451 phOffset = phOffset*180/numpy.pi
3451 phOffset = phOffset*180/numpy.pi
3452 return phOffset
3452 return phOffset
3453
3453
3454
3454
3455 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3455 def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1):
3456
3456
3457 dataOut.flagNoData = True
3457 dataOut.flagNoData = True
3458 self.__dataReady = False
3458 self.__dataReady = False
3459 dataOut.outputInterval = nHours*3600
3459 dataOut.outputInterval = nHours*3600
3460
3460
3461 if self.__isConfig == False:
3461 if self.__isConfig == False:
3462 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3462 # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03)
3463 #Get Initial LTC time
3463 #Get Initial LTC time
3464 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3464 self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime)
3465 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3465 self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds()
3466
3466
3467 self.__isConfig = True
3467 self.__isConfig = True
3468
3468
3469 if self.__buffer is None:
3469 if self.__buffer is None:
3470 self.__buffer = dataOut.data_param.copy()
3470 self.__buffer = dataOut.data_param.copy()
3471
3471
3472 else:
3472 else:
3473 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3473 self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param))
3474
3474
3475 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3475 self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready
3476
3476
3477 if self.__dataReady:
3477 if self.__dataReady:
3478 dataOut.utctimeInit = self.__initime
3478 dataOut.utctimeInit = self.__initime
3479 self.__initime += dataOut.outputInterval #to erase time offset
3479 self.__initime += dataOut.outputInterval #to erase time offset
3480
3480
3481 freq = dataOut.frequency
3481 freq = dataOut.frequency
3482 c = dataOut.C #m/s
3482 c = dataOut.C #m/s
3483 lamb = c/freq
3483 lamb = c/freq
3484 k = 2*numpy.pi/lamb
3484 k = 2*numpy.pi/lamb
3485 azimuth = 0
3485 azimuth = 0
3486 h = (hmin, hmax)
3486 h = (hmin, hmax)
3487 # pairs = ((0,1),(2,3)) #Estrella
3487 # pairs = ((0,1),(2,3)) #Estrella
3488 # pairs = ((1,0),(2,3)) #T
3488 # pairs = ((1,0),(2,3)) #T
3489
3489
3490 if channelPositions is None:
3490 if channelPositions is None:
3491 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3491 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3492 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3492 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3493 meteorOps = SMOperations()
3493 meteorOps = SMOperations()
3494 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3494 pairslist0, distances = meteorOps.getPhasePairs(channelPositions)
3495
3495
3496 #Checking correct order of pairs
3496 #Checking correct order of pairs
3497 pairs = []
3497 pairs = []
3498 if distances[1] > distances[0]:
3498 if distances[1] > distances[0]:
3499 pairs.append((1,0))
3499 pairs.append((1,0))
3500 else:
3500 else:
3501 pairs.append((0,1))
3501 pairs.append((0,1))
3502
3502
3503 if distances[3] > distances[2]:
3503 if distances[3] > distances[2]:
3504 pairs.append((3,2))
3504 pairs.append((3,2))
3505 else:
3505 else:
3506 pairs.append((2,3))
3506 pairs.append((2,3))
3507 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3507 # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb]
3508
3508
3509 meteorsArray = self.__buffer
3509 meteorsArray = self.__buffer
3510 error = meteorsArray[:,-1]
3510 error = meteorsArray[:,-1]
3511 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3511 boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14)
3512 ind1 = numpy.where(boolError)[0]
3512 ind1 = numpy.where(boolError)[0]
3513 meteorsArray = meteorsArray[ind1,:]
3513 meteorsArray = meteorsArray[ind1,:]
3514 meteorsArray[:,-1] = 0
3514 meteorsArray[:,-1] = 0
3515 phases = meteorsArray[:,8:12]
3515 phases = meteorsArray[:,8:12]
3516
3516
3517 #Calculate Gammas
3517 #Calculate Gammas
3518 gammas = self.__getGammas(pairs, distances, phases)
3518 gammas = self.__getGammas(pairs, distances, phases)
3519 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3519 # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180
3520 #Calculate Phases
3520 #Calculate Phases
3521 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3521 phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray)
3522 phasesOff = phasesOff.reshape((1,phasesOff.size))
3522 phasesOff = phasesOff.reshape((1,phasesOff.size))
3523 dataOut.data_output = -phasesOff
3523 dataOut.data_output = -phasesOff
3524 dataOut.flagNoData = False
3524 dataOut.flagNoData = False
3525 self.__buffer = None
3525 self.__buffer = None
3526
3526
3527
3527
3528 return
3528 return
3529
3529
3530 class SMOperations():
3530 class SMOperations():
3531
3531
3532 def __init__(self):
3532 def __init__(self):
3533
3533
3534 return
3534 return
3535
3535
3536 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3536 def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph):
3537
3537
3538 arrayParameters = arrayParameters0.copy()
3538 arrayParameters = arrayParameters0.copy()
3539 hmin = h[0]
3539 hmin = h[0]
3540 hmax = h[1]
3540 hmax = h[1]
3541
3541
3542 #Calculate AOA (Error N 3, 4)
3542 #Calculate AOA (Error N 3, 4)
3543 #JONES ET AL. 1998
3543 #JONES ET AL. 1998
3544 AOAthresh = numpy.pi/8
3544 AOAthresh = numpy.pi/8
3545 error = arrayParameters[:,-1]
3545 error = arrayParameters[:,-1]
3546 phases = -arrayParameters[:,8:12] + jph
3546 phases = -arrayParameters[:,8:12] + jph
3547 # phases = numpy.unwrap(phases)
3547 # phases = numpy.unwrap(phases)
3548 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3548 arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth)
3549
3549
3550 #Calculate Heights (Error N 13 and 14)
3550 #Calculate Heights (Error N 13 and 14)
3551 error = arrayParameters[:,-1]
3551 error = arrayParameters[:,-1]
3552 Ranges = arrayParameters[:,1]
3552 Ranges = arrayParameters[:,1]
3553 zenith = arrayParameters[:,4]
3553 zenith = arrayParameters[:,4]
3554 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3554 arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax)
3555
3555
3556 #----------------------- Get Final data ------------------------------------
3556 #----------------------- Get Final data ------------------------------------
3557 # error = arrayParameters[:,-1]
3557 # error = arrayParameters[:,-1]
3558 # ind1 = numpy.where(error==0)[0]
3558 # ind1 = numpy.where(error==0)[0]
3559 # arrayParameters = arrayParameters[ind1,:]
3559 # arrayParameters = arrayParameters[ind1,:]
3560
3560
3561 return arrayParameters
3561 return arrayParameters
3562
3562
3563 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3563 def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth):
3564
3564
3565 arrayAOA = numpy.zeros((phases.shape[0],3))
3565 arrayAOA = numpy.zeros((phases.shape[0],3))
3566 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3566 cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions)
3567
3567
3568 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3568 arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3569 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3569 cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3570 arrayAOA[:,2] = cosDirError
3570 arrayAOA[:,2] = cosDirError
3571
3571
3572 azimuthAngle = arrayAOA[:,0]
3572 azimuthAngle = arrayAOA[:,0]
3573 zenithAngle = arrayAOA[:,1]
3573 zenithAngle = arrayAOA[:,1]
3574
3574
3575 #Setting Error
3575 #Setting Error
3576 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3576 indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0]
3577 error[indError] = 0
3577 error[indError] = 0
3578 #Number 3: AOA not fesible
3578 #Number 3: AOA not fesible
3579 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3579 indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3580 error[indInvalid] = 3
3580 error[indInvalid] = 3
3581 #Number 4: Large difference in AOAs obtained from different antenna baselines
3581 #Number 4: Large difference in AOAs obtained from different antenna baselines
3582 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3582 indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3583 error[indInvalid] = 4
3583 error[indInvalid] = 4
3584 return arrayAOA, error
3584 return arrayAOA, error
3585
3585
3586 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3586 def __getDirectionCosines(self, arrayPhase, pairsList, distances):
3587
3587
3588 #Initializing some variables
3588 #Initializing some variables
3589 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3589 ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3590 ang_aux = ang_aux.reshape(1,ang_aux.size)
3590 ang_aux = ang_aux.reshape(1,ang_aux.size)
3591
3591
3592 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3592 cosdir = numpy.zeros((arrayPhase.shape[0],2))
3593 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3593 cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3594
3594
3595
3595
3596 for i in range(2):
3596 for i in range(2):
3597 ph0 = arrayPhase[:,pairsList[i][0]]
3597 ph0 = arrayPhase[:,pairsList[i][0]]
3598 ph1 = arrayPhase[:,pairsList[i][1]]
3598 ph1 = arrayPhase[:,pairsList[i][1]]
3599 d0 = distances[pairsList[i][0]]
3599 d0 = distances[pairsList[i][0]]
3600 d1 = distances[pairsList[i][1]]
3600 d1 = distances[pairsList[i][1]]
3601
3601
3602 ph0_aux = ph0 + ph1
3602 ph0_aux = ph0 + ph1
3603 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3603 ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux))
3604 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3604 # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi
3605 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3605 # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi
3606 #First Estimation
3606 #First Estimation
3607 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3607 cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1))
3608
3608
3609 #Most-Accurate Second Estimation
3609 #Most-Accurate Second Estimation
3610 phi1_aux = ph0 - ph1
3610 phi1_aux = ph0 - ph1
3611 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3611 phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3612 #Direction Cosine 1
3612 #Direction Cosine 1
3613 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3613 cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1))
3614
3614
3615 #Searching the correct Direction Cosine
3615 #Searching the correct Direction Cosine
3616 cosdir0_aux = cosdir0[:,i]
3616 cosdir0_aux = cosdir0[:,i]
3617 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3617 cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3618 #Minimum Distance
3618 #Minimum Distance
3619 cosDiff = (cosdir1 - cosdir0_aux)**2
3619 cosDiff = (cosdir1 - cosdir0_aux)**2
3620 indcos = cosDiff.argmin(axis = 1)
3620 indcos = cosDiff.argmin(axis = 1)
3621 #Saving Value obtained
3621 #Saving Value obtained
3622 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3622 cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3623
3623
3624 return cosdir0, cosdir
3624 return cosdir0, cosdir
3625
3625
3626 def __calculateAOA(self, cosdir, azimuth):
3626 def __calculateAOA(self, cosdir, azimuth):
3627 cosdirX = cosdir[:,0]
3627 cosdirX = cosdir[:,0]
3628 cosdirY = cosdir[:,1]
3628 cosdirY = cosdir[:,1]
3629
3629
3630 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3630 zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3631 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3631 azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east
3632 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3632 angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3633
3633
3634 return angles
3634 return angles
3635
3635
3636 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3636 def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3637
3637
3638 Ramb = 375 #Ramb = c/(2*PRF)
3638 Ramb = 375 #Ramb = c/(2*PRF)
3639 Re = 6371 #Earth Radius
3639 Re = 6371 #Earth Radius
3640 heights = numpy.zeros(Ranges.shape)
3640 heights = numpy.zeros(Ranges.shape)
3641
3641
3642 R_aux = numpy.array([0,1,2])*Ramb
3642 R_aux = numpy.array([0,1,2])*Ramb
3643 R_aux = R_aux.reshape(1,R_aux.size)
3643 R_aux = R_aux.reshape(1,R_aux.size)
3644
3644
3645 Ranges = Ranges.reshape(Ranges.size,1)
3645 Ranges = Ranges.reshape(Ranges.size,1)
3646
3646
3647 Ri = Ranges + R_aux
3647 Ri = Ranges + R_aux
3648 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3648 hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3649
3649
3650 #Check if there is a height between 70 and 110 km
3650 #Check if there is a height between 70 and 110 km
3651 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3651 h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3652 ind_h = numpy.where(h_bool == 1)[0]
3652 ind_h = numpy.where(h_bool == 1)[0]
3653
3653
3654 hCorr = hi[ind_h, :]
3654 hCorr = hi[ind_h, :]
3655 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3655 ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3656
3656
3657 hCorr = hi[ind_hCorr][:len(ind_h)]
3657 hCorr = hi[ind_hCorr][:len(ind_h)]
3658 heights[ind_h] = hCorr
3658 heights[ind_h] = hCorr
3659
3659
3660 #Setting Error
3660 #Setting Error
3661 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3661 #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3662 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3662 #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3663 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3663 indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0]
3664 error[indError] = 0
3664 error[indError] = 0
3665 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3665 indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3666 error[indInvalid2] = 14
3666 error[indInvalid2] = 14
3667 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3667 indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3668 error[indInvalid1] = 13
3668 error[indInvalid1] = 13
3669
3669
3670 return heights, error
3670 return heights, error
3671
3671
3672 def getPhasePairs(self, channelPositions):
3672 def getPhasePairs(self, channelPositions):
3673 chanPos = numpy.array(channelPositions)
3673 chanPos = numpy.array(channelPositions)
3674 listOper = list(itertools.combinations(list(range(5)),2))
3674 listOper = list(itertools.combinations(list(range(5)),2))
3675
3675
3676 distances = numpy.zeros(4)
3676 distances = numpy.zeros(4)
3677 axisX = []
3677 axisX = []
3678 axisY = []
3678 axisY = []
3679 distX = numpy.zeros(3)
3679 distX = numpy.zeros(3)
3680 distY = numpy.zeros(3)
3680 distY = numpy.zeros(3)
3681 ix = 0
3681 ix = 0
3682 iy = 0
3682 iy = 0
3683
3683
3684 pairX = numpy.zeros((2,2))
3684 pairX = numpy.zeros((2,2))
3685 pairY = numpy.zeros((2,2))
3685 pairY = numpy.zeros((2,2))
3686
3686
3687 for i in range(len(listOper)):
3687 for i in range(len(listOper)):
3688 pairi = listOper[i]
3688 pairi = listOper[i]
3689
3689
3690 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3690 posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:])
3691
3691
3692 if posDif[0] == 0:
3692 if posDif[0] == 0:
3693 axisY.append(pairi)
3693 axisY.append(pairi)
3694 distY[iy] = posDif[1]
3694 distY[iy] = posDif[1]
3695 iy += 1
3695 iy += 1
3696 elif posDif[1] == 0:
3696 elif posDif[1] == 0:
3697 axisX.append(pairi)
3697 axisX.append(pairi)
3698 distX[ix] = posDif[0]
3698 distX[ix] = posDif[0]
3699 ix += 1
3699 ix += 1
3700
3700
3701 for i in range(2):
3701 for i in range(2):
3702 if i==0:
3702 if i==0:
3703 dist0 = distX
3703 dist0 = distX
3704 axis0 = axisX
3704 axis0 = axisX
3705 else:
3705 else:
3706 dist0 = distY
3706 dist0 = distY
3707 axis0 = axisY
3707 axis0 = axisY
3708
3708
3709 side = numpy.argsort(dist0)[:-1]
3709 side = numpy.argsort(dist0)[:-1]
3710 axis0 = numpy.array(axis0)[side,:]
3710 axis0 = numpy.array(axis0)[side,:]
3711 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3711 chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0])
3712 axis1 = numpy.unique(numpy.reshape(axis0,4))
3712 axis1 = numpy.unique(numpy.reshape(axis0,4))
3713 side = axis1[axis1 != chanC]
3713 side = axis1[axis1 != chanC]
3714 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3714 diff1 = chanPos[chanC,i] - chanPos[side[0],i]
3715 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3715 diff2 = chanPos[chanC,i] - chanPos[side[1],i]
3716 if diff1<0:
3716 if diff1<0:
3717 chan2 = side[0]
3717 chan2 = side[0]
3718 d2 = numpy.abs(diff1)
3718 d2 = numpy.abs(diff1)
3719 chan1 = side[1]
3719 chan1 = side[1]
3720 d1 = numpy.abs(diff2)
3720 d1 = numpy.abs(diff2)
3721 else:
3721 else:
3722 chan2 = side[1]
3722 chan2 = side[1]
3723 d2 = numpy.abs(diff2)
3723 d2 = numpy.abs(diff2)
3724 chan1 = side[0]
3724 chan1 = side[0]
3725 d1 = numpy.abs(diff1)
3725 d1 = numpy.abs(diff1)
3726
3726
3727 if i==0:
3727 if i==0:
3728 chanCX = chanC
3728 chanCX = chanC
3729 chan1X = chan1
3729 chan1X = chan1
3730 chan2X = chan2
3730 chan2X = chan2
3731 distances[0:2] = numpy.array([d1,d2])
3731 distances[0:2] = numpy.array([d1,d2])
3732 else:
3732 else:
3733 chanCY = chanC
3733 chanCY = chanC
3734 chan1Y = chan1
3734 chan1Y = chan1
3735 chan2Y = chan2
3735 chan2Y = chan2
3736 distances[2:4] = numpy.array([d1,d2])
3736 distances[2:4] = numpy.array([d1,d2])
3737 # axisXsides = numpy.reshape(axisX[ix,:],4)
3737 # axisXsides = numpy.reshape(axisX[ix,:],4)
3738 #
3738 #
3739 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3739 # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0])
3740 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3740 # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0])
3741 #
3741 #
3742 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3742 # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0]
3743 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3743 # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0]
3744 # channel25X = int(pairX[0,ind25X])
3744 # channel25X = int(pairX[0,ind25X])
3745 # channel20X = int(pairX[1,ind20X])
3745 # channel20X = int(pairX[1,ind20X])
3746 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3746 # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0]
3747 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3747 # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0]
3748 # channel25Y = int(pairY[0,ind25Y])
3748 # channel25Y = int(pairY[0,ind25Y])
3749 # channel20Y = int(pairY[1,ind20Y])
3749 # channel20Y = int(pairY[1,ind20Y])
3750
3750
3751 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3751 # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)]
3752 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3752 pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)]
3753
3753
3754 return pairslist, distances
3754 return pairslist, distances
3755 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3755 # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth):
3756 #
3756 #
3757 # arrayAOA = numpy.zeros((phases.shape[0],3))
3757 # arrayAOA = numpy.zeros((phases.shape[0],3))
3758 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3758 # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList)
3759 #
3759 #
3760 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3760 # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth)
3761 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3761 # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1)
3762 # arrayAOA[:,2] = cosDirError
3762 # arrayAOA[:,2] = cosDirError
3763 #
3763 #
3764 # azimuthAngle = arrayAOA[:,0]
3764 # azimuthAngle = arrayAOA[:,0]
3765 # zenithAngle = arrayAOA[:,1]
3765 # zenithAngle = arrayAOA[:,1]
3766 #
3766 #
3767 # #Setting Error
3767 # #Setting Error
3768 # #Number 3: AOA not fesible
3768 # #Number 3: AOA not fesible
3769 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3769 # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0]
3770 # error[indInvalid] = 3
3770 # error[indInvalid] = 3
3771 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3771 # #Number 4: Large difference in AOAs obtained from different antenna baselines
3772 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3772 # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0]
3773 # error[indInvalid] = 4
3773 # error[indInvalid] = 4
3774 # return arrayAOA, error
3774 # return arrayAOA, error
3775 #
3775 #
3776 # def __getDirectionCosines(self, arrayPhase, pairsList):
3776 # def __getDirectionCosines(self, arrayPhase, pairsList):
3777 #
3777 #
3778 # #Initializing some variables
3778 # #Initializing some variables
3779 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3779 # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi
3780 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3780 # ang_aux = ang_aux.reshape(1,ang_aux.size)
3781 #
3781 #
3782 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3782 # cosdir = numpy.zeros((arrayPhase.shape[0],2))
3783 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3783 # cosdir0 = numpy.zeros((arrayPhase.shape[0],2))
3784 #
3784 #
3785 #
3785 #
3786 # for i in range(2):
3786 # for i in range(2):
3787 # #First Estimation
3787 # #First Estimation
3788 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3788 # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]]
3789 # #Dealias
3789 # #Dealias
3790 # indcsi = numpy.where(phi0_aux > numpy.pi)
3790 # indcsi = numpy.where(phi0_aux > numpy.pi)
3791 # phi0_aux[indcsi] -= 2*numpy.pi
3791 # phi0_aux[indcsi] -= 2*numpy.pi
3792 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3792 # indcsi = numpy.where(phi0_aux < -numpy.pi)
3793 # phi0_aux[indcsi] += 2*numpy.pi
3793 # phi0_aux[indcsi] += 2*numpy.pi
3794 # #Direction Cosine 0
3794 # #Direction Cosine 0
3795 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3795 # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5)
3796 #
3796 #
3797 # #Most-Accurate Second Estimation
3797 # #Most-Accurate Second Estimation
3798 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3798 # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]]
3799 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3799 # phi1_aux = phi1_aux.reshape(phi1_aux.size,1)
3800 # #Direction Cosine 1
3800 # #Direction Cosine 1
3801 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3801 # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5)
3802 #
3802 #
3803 # #Searching the correct Direction Cosine
3803 # #Searching the correct Direction Cosine
3804 # cosdir0_aux = cosdir0[:,i]
3804 # cosdir0_aux = cosdir0[:,i]
3805 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3805 # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1)
3806 # #Minimum Distance
3806 # #Minimum Distance
3807 # cosDiff = (cosdir1 - cosdir0_aux)**2
3807 # cosDiff = (cosdir1 - cosdir0_aux)**2
3808 # indcos = cosDiff.argmin(axis = 1)
3808 # indcos = cosDiff.argmin(axis = 1)
3809 # #Saving Value obtained
3809 # #Saving Value obtained
3810 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3810 # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos]
3811 #
3811 #
3812 # return cosdir0, cosdir
3812 # return cosdir0, cosdir
3813 #
3813 #
3814 # def __calculateAOA(self, cosdir, azimuth):
3814 # def __calculateAOA(self, cosdir, azimuth):
3815 # cosdirX = cosdir[:,0]
3815 # cosdirX = cosdir[:,0]
3816 # cosdirY = cosdir[:,1]
3816 # cosdirY = cosdir[:,1]
3817 #
3817 #
3818 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3818 # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi
3819 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3819 # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east
3820 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3820 # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose()
3821 #
3821 #
3822 # return angles
3822 # return angles
3823 #
3823 #
3824 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3824 # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight):
3825 #
3825 #
3826 # Ramb = 375 #Ramb = c/(2*PRF)
3826 # Ramb = 375 #Ramb = c/(2*PRF)
3827 # Re = 6371 #Earth Radius
3827 # Re = 6371 #Earth Radius
3828 # heights = numpy.zeros(Ranges.shape)
3828 # heights = numpy.zeros(Ranges.shape)
3829 #
3829 #
3830 # R_aux = numpy.array([0,1,2])*Ramb
3830 # R_aux = numpy.array([0,1,2])*Ramb
3831 # R_aux = R_aux.reshape(1,R_aux.size)
3831 # R_aux = R_aux.reshape(1,R_aux.size)
3832 #
3832 #
3833 # Ranges = Ranges.reshape(Ranges.size,1)
3833 # Ranges = Ranges.reshape(Ranges.size,1)
3834 #
3834 #
3835 # Ri = Ranges + R_aux
3835 # Ri = Ranges + R_aux
3836 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3836 # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re
3837 #
3837 #
3838 # #Check if there is a height between 70 and 110 km
3838 # #Check if there is a height between 70 and 110 km
3839 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3839 # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1)
3840 # ind_h = numpy.where(h_bool == 1)[0]
3840 # ind_h = numpy.where(h_bool == 1)[0]
3841 #
3841 #
3842 # hCorr = hi[ind_h, :]
3842 # hCorr = hi[ind_h, :]
3843 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3843 # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight))
3844 #
3844 #
3845 # hCorr = hi[ind_hCorr]
3845 # hCorr = hi[ind_hCorr]
3846 # heights[ind_h] = hCorr
3846 # heights[ind_h] = hCorr
3847 #
3847 #
3848 # #Setting Error
3848 # #Setting Error
3849 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3849 # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km
3850 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3850 # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km
3851 #
3851 #
3852 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3852 # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0]
3853 # error[indInvalid2] = 14
3853 # error[indInvalid2] = 14
3854 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3854 # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0]
3855 # error[indInvalid1] = 13
3855 # error[indInvalid1] = 13
3856 #
3856 #
3857 # return heights, error
3857 # return heights, error
3858 No newline at end of file
3858
General Comments 0
You need to be logged in to leave comments. Login now