##// END OF EJS Templates
Claire, Erick Bocanegra 21-02-18
ebocanegra -
r1146:dc5534725adf
parent child
Show More

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

@@ -1,1229 +1,1231
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
12 from schainpy import cSchain
13
13
14
14
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError, 'dataTypeCode was not defined'
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34 def getDataTypeCode(numpyDtype):
34 def getDataTypeCode(numpyDtype):
35
35
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
37 datatype = 0
37 datatype = 0
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
39 datatype = 1
39 datatype = 1
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
41 datatype = 2
41 datatype = 2
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
43 datatype = 3
43 datatype = 3
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
45 datatype = 4
45 datatype = 4
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
47 datatype = 5
47 datatype = 5
48 else:
48 else:
49 datatype = None
49 datatype = None
50
50
51 return datatype
51 return datatype
52
52
53 def hildebrand_sekhon(data, navg):
53 def hildebrand_sekhon(data, navg):
54 """
54 """
55 This method is for the objective determination of the noise level in Doppler spectra. This
55 This method is for the objective determination of the noise level in Doppler spectra. This
56 implementation technique is based on the fact that the standard deviation of the spectral
56 implementation technique is based on the fact that the standard deviation of the spectral
57 densities is equal to the mean spectral density for white Gaussian noise
57 densities is equal to the mean spectral density for white Gaussian noise
58
58
59 Inputs:
59 Inputs:
60 Data : heights
60 Data : heights
61 navg : numbers of averages
61 navg : numbers of averages
62
62
63 Return:
63 Return:
64 -1 : any error
64 -1 : any error
65 anoise : noise's level
65 anoise : noise's level
66 """
66 """
67
67
68 sortdata = numpy.sort(data, axis=None)
68 sortdata = numpy.sort(data, axis=None)
69 # lenOfData = len(sortdata)
69 # lenOfData = len(sortdata)
70 # nums_min = lenOfData*0.2
70 # nums_min = lenOfData*0.2
71 #
71 #
72 # if nums_min <= 5:
72 # if nums_min <= 5:
73 # nums_min = 5
73 # nums_min = 5
74 #
74 #
75 # sump = 0.
75 # sump = 0.
76 #
76 #
77 # sumq = 0.
77 # sumq = 0.
78 #
78 #
79 # j = 0
79 # j = 0
80 #
80 #
81 # cont = 1
81 # cont = 1
82 #
82 #
83 # while((cont==1)and(j<lenOfData)):
83 # while((cont==1)and(j<lenOfData)):
84 #
84 #
85 # sump += sortdata[j]
85 # sump += sortdata[j]
86 #
86 #
87 # sumq += sortdata[j]**2
87 # sumq += sortdata[j]**2
88 #
88 #
89 # if j > nums_min:
89 # if j > nums_min:
90 # rtest = float(j)/(j-1) + 1.0/navg
90 # rtest = float(j)/(j-1) + 1.0/navg
91 # if ((sumq*j) > (rtest*sump**2)):
91 # if ((sumq*j) > (rtest*sump**2)):
92 # j = j - 1
92 # j = j - 1
93 # sump = sump - sortdata[j]
93 # sump = sump - sortdata[j]
94 # sumq = sumq - sortdata[j]**2
94 # sumq = sumq - sortdata[j]**2
95 # cont = 0
95 # cont = 0
96 #
96 #
97 # j += 1
97 # j += 1
98 #
98 #
99 # lnoise = sump /j
99 # lnoise = sump /j
100 #
100 #
101 # return lnoise
101 # return lnoise
102
102
103 return cSchain.hildebrand_sekhon(sortdata, navg)
103 return cSchain.hildebrand_sekhon(sortdata, navg)
104
104
105
105
106 class Beam:
106 class Beam:
107
107
108 def __init__(self):
108 def __init__(self):
109 self.codeList = []
109 self.codeList = []
110 self.azimuthList = []
110 self.azimuthList = []
111 self.zenithList = []
111 self.zenithList = []
112
112
113 class GenericData(object):
113 class GenericData(object):
114
114
115 flagNoData = True
115 flagNoData = True
116
116
117 def copy(self, inputObj=None):
117 def copy(self, inputObj=None):
118
118
119 if inputObj == None:
119 if inputObj == None:
120 return copy.deepcopy(self)
120 return copy.deepcopy(self)
121
121
122 for key in inputObj.__dict__.keys():
122 for key in inputObj.__dict__.keys():
123
123
124 attribute = inputObj.__dict__[key]
124 attribute = inputObj.__dict__[key]
125
125
126 #If this attribute is a tuple or list
126 #If this attribute is a tuple or list
127 if type(inputObj.__dict__[key]) in (tuple, list):
127 if type(inputObj.__dict__[key]) in (tuple, list):
128 self.__dict__[key] = attribute[:]
128 self.__dict__[key] = attribute[:]
129 continue
129 continue
130
130
131 #If this attribute is another object or instance
131 #If this attribute is another object or instance
132 if hasattr(attribute, '__dict__'):
132 if hasattr(attribute, '__dict__'):
133 self.__dict__[key] = attribute.copy()
133 self.__dict__[key] = attribute.copy()
134 continue
134 continue
135
135
136 self.__dict__[key] = inputObj.__dict__[key]
136 self.__dict__[key] = inputObj.__dict__[key]
137
137
138 def deepcopy(self):
138 def deepcopy(self):
139
139
140 return copy.deepcopy(self)
140 return copy.deepcopy(self)
141
141
142 def isEmpty(self):
142 def isEmpty(self):
143
143
144 return self.flagNoData
144 return self.flagNoData
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152
152
153 radarControllerHeaderObj = RadarControllerHeader()
153 radarControllerHeaderObj = RadarControllerHeader()
154
154
155 # data = None
155 # data = None
156
156
157 type = None
157 type = None
158
158
159 datatype = None #dtype but in string
159 datatype = None #dtype but in string
160
160
161 # dtype = None
161 # dtype = None
162
162
163 # nChannels = None
163 # nChannels = None
164
164
165 # nHeights = None
165 # nHeights = None
166
166
167 nProfiles = None
167 nProfiles = None
168
168
169 heightList = None
169 heightList = None
170
170
171 channelList = None
171 channelList = None
172
172
173 flagDiscontinuousBlock = False
173 flagDiscontinuousBlock = False
174
174
175 useLocalTime = False
175 useLocalTime = False
176
176
177 utctime = None
177 utctime = None
178
178
179 timeZone = None
179 timeZone = None
180
180
181 dstFlag = None
181 dstFlag = None
182
182
183 errorCount = None
183 errorCount = None
184
184
185 blocksize = None
185 blocksize = None
186
186
187 # nCode = None
187 # nCode = None
188 #
188 #
189 # nBaud = None
189 # nBaud = None
190 #
190 #
191 # code = None
191 # code = None
192
192
193 flagDecodeData = False #asumo q la data no esta decodificada
193 flagDecodeData = False #asumo q la data no esta decodificada
194
194
195 flagDeflipData = False #asumo q la data no esta sin flip
195 flagDeflipData = False #asumo q la data no esta sin flip
196
196
197 flagShiftFFT = False
197 flagShiftFFT = False
198
198
199 # ippSeconds = None
199 # ippSeconds = None
200
200
201 # timeInterval = None
201 # timeInterval = None
202
202
203 nCohInt = None
203 nCohInt = None
204
204
205 # noise = None
205 # noise = None
206
206
207 windowOfFilter = 1
207 windowOfFilter = 1
208
208
209 #Speed of ligth
209 #Speed of ligth
210 C = 3e8
210 C = 3e8
211
211
212 frequency = 49.92e6
212 frequency = 49.92e6
213
213
214 realtime = False
214 realtime = False
215
215
216 beacon_heiIndexList = None
216 beacon_heiIndexList = None
217
217
218 last_block = None
218 last_block = None
219
219
220 blocknow = None
220 blocknow = None
221
221
222 azimuth = None
222 azimuth = None
223
223
224 zenith = None
224 zenith = None
225
225
226 beam = Beam()
226 beam = Beam()
227
227
228 profileIndex = None
228 profileIndex = None
229
229
230 def getNoise(self):
230 def getNoise(self):
231
231
232 raise NotImplementedError
232 raise NotImplementedError
233
233
234 def getNChannels(self):
234 def getNChannels(self):
235
235
236 return len(self.channelList)
236 return len(self.channelList)
237
237
238 def getChannelIndexList(self):
238 def getChannelIndexList(self):
239
239
240 return range(self.nChannels)
240 return range(self.nChannels)
241
241
242 def getNHeights(self):
242 def getNHeights(self):
243
243
244 return len(self.heightList)
244 return len(self.heightList)
245
245
246 def getHeiRange(self, extrapoints=0):
246 def getHeiRange(self, extrapoints=0):
247
247
248 heis = self.heightList
248 heis = self.heightList
249 # deltah = self.heightList[1] - self.heightList[0]
249 # deltah = self.heightList[1] - self.heightList[0]
250 #
250 #
251 # heis.append(self.heightList[-1])
251 # heis.append(self.heightList[-1])
252
252
253 return heis
253 return heis
254
254
255 def getDeltaH(self):
255 def getDeltaH(self):
256
256
257 delta = self.heightList[1] - self.heightList[0]
257 delta = self.heightList[1] - self.heightList[0]
258
258
259 return delta
259 return delta
260
260
261 def getltctime(self):
261 def getltctime(self):
262
262
263 if self.useLocalTime:
263 if self.useLocalTime:
264 return self.utctime - self.timeZone*60
264 return self.utctime - self.timeZone*60
265
265
266 return self.utctime
266 return self.utctime
267
267
268 def getDatatime(self):
268 def getDatatime(self):
269
269
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
271 return datatimeValue
271 return datatimeValue
272
272
273 def getTimeRange(self):
273 def getTimeRange(self):
274
274
275 datatime = []
275 datatime = []
276
276
277 datatime.append(self.ltctime)
277 datatime.append(self.ltctime)
278 datatime.append(self.ltctime + self.timeInterval+1)
278 datatime.append(self.ltctime + self.timeInterval+1)
279
279
280 datatime = numpy.array(datatime)
280 datatime = numpy.array(datatime)
281
281
282 return datatime
282 return datatime
283
283
284 def getFmaxTimeResponse(self):
284 def getFmaxTimeResponse(self):
285
285
286 period = (10**-6)*self.getDeltaH()/(0.15)
286 period = (10**-6)*self.getDeltaH()/(0.15)
287
287
288 PRF = 1./(period * self.nCohInt)
288 PRF = 1./(period * self.nCohInt)
289
289
290 fmax = PRF
290 fmax = PRF
291
291
292 return fmax
292 return fmax
293
293
294 def getFmax(self):
294 def getFmax(self):
295
295
296 PRF = 1./(self.ippSeconds * self.nCohInt)
296 PRF = 1./(self.ippSeconds * self.nCohInt)
297
297
298 fmax = PRF
298 fmax = PRF
299
299
300 return fmax
300 return fmax
301
301
302 def getVmax(self):
302 def getVmax(self):
303
303
304 _lambda = self.C/self.frequency
304 _lambda = self.C/self.frequency
305
305
306 vmax = self.getFmax() * _lambda/2
306 vmax = self.getFmax() * _lambda/2
307
307
308 return vmax
308 return vmax
309
309
310 def get_ippSeconds(self):
310 def get_ippSeconds(self):
311 '''
311 '''
312 '''
312 '''
313 return self.radarControllerHeaderObj.ippSeconds
313 return self.radarControllerHeaderObj.ippSeconds
314
314
315 def set_ippSeconds(self, ippSeconds):
315 def set_ippSeconds(self, ippSeconds):
316 '''
316 '''
317 '''
317 '''
318
318
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
320
320
321 return
321 return
322
322
323 def get_dtype(self):
323 def get_dtype(self):
324 '''
324 '''
325 '''
325 '''
326 return getNumpyDtype(self.datatype)
326 return getNumpyDtype(self.datatype)
327
327
328 def set_dtype(self, numpyDtype):
328 def set_dtype(self, numpyDtype):
329 '''
329 '''
330 '''
330 '''
331
331
332 self.datatype = getDataTypeCode(numpyDtype)
332 self.datatype = getDataTypeCode(numpyDtype)
333
333
334 def get_code(self):
334 def get_code(self):
335 '''
335 '''
336 '''
336 '''
337 return self.radarControllerHeaderObj.code
337 return self.radarControllerHeaderObj.code
338
338
339 def set_code(self, code):
339 def set_code(self, code):
340 '''
340 '''
341 '''
341 '''
342 self.radarControllerHeaderObj.code = code
342 self.radarControllerHeaderObj.code = code
343
343
344 return
344 return
345
345
346 def get_ncode(self):
346 def get_ncode(self):
347 '''
347 '''
348 '''
348 '''
349 return self.radarControllerHeaderObj.nCode
349 return self.radarControllerHeaderObj.nCode
350
350
351 def set_ncode(self, nCode):
351 def set_ncode(self, nCode):
352 '''
352 '''
353 '''
353 '''
354 self.radarControllerHeaderObj.nCode = nCode
354 self.radarControllerHeaderObj.nCode = nCode
355
355
356 return
356 return
357
357
358 def get_nbaud(self):
358 def get_nbaud(self):
359 '''
359 '''
360 '''
360 '''
361 return self.radarControllerHeaderObj.nBaud
361 return self.radarControllerHeaderObj.nBaud
362
362
363 def set_nbaud(self, nBaud):
363 def set_nbaud(self, nBaud):
364 '''
364 '''
365 '''
365 '''
366 self.radarControllerHeaderObj.nBaud = nBaud
366 self.radarControllerHeaderObj.nBaud = nBaud
367
367
368 return
368 return
369
369
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
377 dtype = property(get_dtype, set_dtype)
377 dtype = property(get_dtype, set_dtype)
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
379 code = property(get_code, set_code)
379 code = property(get_code, set_code)
380 nCode = property(get_ncode, set_ncode)
380 nCode = property(get_ncode, set_ncode)
381 nBaud = property(get_nbaud, set_nbaud)
381 nBaud = property(get_nbaud, set_nbaud)
382
382
383 class Voltage(JROData):
383 class Voltage(JROData):
384
384
385 #data es un numpy array de 2 dmensiones (canales, alturas)
385 #data es un numpy array de 2 dmensiones (canales, alturas)
386 data = None
386 data = None
387
387
388 def __init__(self):
388 def __init__(self):
389 '''
389 '''
390 Constructor
390 Constructor
391 '''
391 '''
392
392
393 self.useLocalTime = True
393 self.useLocalTime = True
394
394
395 self.radarControllerHeaderObj = RadarControllerHeader()
395 self.radarControllerHeaderObj = RadarControllerHeader()
396
396
397 self.systemHeaderObj = SystemHeader()
397 self.systemHeaderObj = SystemHeader()
398
398
399 self.type = "Voltage"
399 self.type = "Voltage"
400
400
401 self.data = None
401 self.data = None
402
402
403 # self.dtype = None
403 # self.dtype = None
404
404
405 # self.nChannels = 0
405 # self.nChannels = 0
406
406
407 # self.nHeights = 0
407 # self.nHeights = 0
408
408
409 self.nProfiles = None
409 self.nProfiles = None
410
410
411 self.heightList = None
411 self.heightList = None
412
412
413 self.channelList = None
413 self.channelList = None
414
414
415 # self.channelIndexList = None
415 # self.channelIndexList = None
416
416
417 self.flagNoData = True
417 self.flagNoData = True
418
418
419 self.flagDiscontinuousBlock = False
419 self.flagDiscontinuousBlock = False
420
420
421 self.utctime = None
421 self.utctime = None
422
422
423 self.timeZone = None
423 self.timeZone = None
424
424
425 self.dstFlag = None
425 self.dstFlag = None
426
426
427 self.errorCount = None
427 self.errorCount = None
428
428
429 self.nCohInt = None
429 self.nCohInt = None
430
430
431 self.blocksize = None
431 self.blocksize = None
432
432
433 self.flagDecodeData = False #asumo q la data no esta decodificada
433 self.flagDecodeData = False #asumo q la data no esta decodificada
434
434
435 self.flagDeflipData = False #asumo q la data no esta sin flip
435 self.flagDeflipData = False #asumo q la data no esta sin flip
436
436
437 self.flagShiftFFT = False
437 self.flagShiftFFT = False
438
438
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
440
440
441 self.profileIndex = 0
441 self.profileIndex = 0
442
442
443 def getNoisebyHildebrand(self, channel = None):
443 def getNoisebyHildebrand(self, channel = None):
444 """
444 """
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
446
446
447 Return:
447 Return:
448 noiselevel
448 noiselevel
449 """
449 """
450
450
451 if channel != None:
451 if channel != None:
452 data = self.data[channel]
452 data = self.data[channel]
453 nChannels = 1
453 nChannels = 1
454 else:
454 else:
455 data = self.data
455 data = self.data
456 nChannels = self.nChannels
456 nChannels = self.nChannels
457
457
458 noise = numpy.zeros(nChannels)
458 noise = numpy.zeros(nChannels)
459 power = data * numpy.conjugate(data)
459 power = data * numpy.conjugate(data)
460
460
461 for thisChannel in range(nChannels):
461 for thisChannel in range(nChannels):
462 if nChannels == 1:
462 if nChannels == 1:
463 daux = power[:].real
463 daux = power[:].real
464 else:
464 else:
465 daux = power[thisChannel,:].real
465 daux = power[thisChannel,:].real
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
467
467
468 return noise
468 return noise
469
469
470 def getNoise(self, type = 1, channel = None):
470 def getNoise(self, type = 1, channel = None):
471
471
472 if type == 1:
472 if type == 1:
473 noise = self.getNoisebyHildebrand(channel)
473 noise = self.getNoisebyHildebrand(channel)
474
474
475 return noise
475 return noise
476
476
477 def getPower(self, channel = None):
477 def getPower(self, channel = None):
478
478
479 if channel != None:
479 if channel != None:
480 data = self.data[channel]
480 data = self.data[channel]
481 else:
481 else:
482 data = self.data
482 data = self.data
483
483
484 power = data * numpy.conjugate(data)
484 power = data * numpy.conjugate(data)
485 powerdB = 10*numpy.log10(power.real)
485 powerdB = 10*numpy.log10(power.real)
486 powerdB = numpy.squeeze(powerdB)
486 powerdB = numpy.squeeze(powerdB)
487
487
488 return powerdB
488 return powerdB
489
489
490 def getTimeInterval(self):
490 def getTimeInterval(self):
491
491
492 timeInterval = self.ippSeconds * self.nCohInt
492 timeInterval = self.ippSeconds * self.nCohInt
493
493
494 return timeInterval
494 return timeInterval
495
495
496 noise = property(getNoise, "I'm the 'nHeights' property.")
496 noise = property(getNoise, "I'm the 'nHeights' property.")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
498
498
499 class Spectra(JROData):
499 class Spectra(JROData):
500
500
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
502 data_spc = None
502 data_spc = None
503
503
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
505 data_cspc = None
505 data_cspc = None
506
506
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
508 data_dc = None
508 data_dc = None
509
509
510 #data power
510 #data power
511 data_pwr = None
511 data_pwr = None
512
512
513 nFFTPoints = None
513 nFFTPoints = None
514
514
515 # nPairs = None
515 # nPairs = None
516
516
517 pairsList = None
517 pairsList = None
518
518
519 nIncohInt = None
519 nIncohInt = None
520
520
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
522
522
523 nCohInt = None #se requiere para determinar el valor de timeInterval
523 nCohInt = None #se requiere para determinar el valor de timeInterval
524
524
525 ippFactor = None
525 ippFactor = None
526
526
527 profileIndex = 0
527 profileIndex = 0
528
528
529 plotting = "spectra"
529 plotting = "spectra"
530
530
531 def __init__(self):
531 def __init__(self):
532 '''
532 '''
533 Constructor
533 Constructor
534 '''
534 '''
535
535
536 self.useLocalTime = True
536 self.useLocalTime = True
537
537
538 self.radarControllerHeaderObj = RadarControllerHeader()
538 self.radarControllerHeaderObj = RadarControllerHeader()
539
539
540 self.systemHeaderObj = SystemHeader()
540 self.systemHeaderObj = SystemHeader()
541
541
542 self.type = "Spectra"
542 self.type = "Spectra"
543
543
544 # self.data = None
544 # self.data = None
545
545
546 # self.dtype = None
546 # self.dtype = None
547
547
548 # self.nChannels = 0
548 # self.nChannels = 0
549
549
550 # self.nHeights = 0
550 # self.nHeights = 0
551
551
552 self.nProfiles = None
552 self.nProfiles = None
553
553
554 self.heightList = None
554 self.heightList = None
555
555
556 self.channelList = None
556 self.channelList = None
557
557
558 # self.channelIndexList = None
558 # self.channelIndexList = None
559
559
560 self.pairsList = None
560 self.pairsList = None
561
561
562 self.flagNoData = True
562 self.flagNoData = True
563
563
564 self.flagDiscontinuousBlock = False
564 self.flagDiscontinuousBlock = False
565
565
566 self.utctime = None
566 self.utctime = None
567
567
568 self.nCohInt = None
568 self.nCohInt = None
569
569
570 self.nIncohInt = None
570 self.nIncohInt = None
571
571
572 self.blocksize = None
572 self.blocksize = None
573
573
574 self.nFFTPoints = None
574 self.nFFTPoints = None
575
575
576 self.wavelength = None
576 self.wavelength = None
577
577
578 self.flagDecodeData = False #asumo q la data no esta decodificada
578 self.flagDecodeData = False #asumo q la data no esta decodificada
579
579
580 self.flagDeflipData = False #asumo q la data no esta sin flip
580 self.flagDeflipData = False #asumo q la data no esta sin flip
581
581
582 self.flagShiftFFT = False
582 self.flagShiftFFT = False
583
583
584 self.ippFactor = 1
584 self.ippFactor = 1
585
585
586 #self.noise = None
586 #self.noise = None
587
587
588 self.beacon_heiIndexList = []
588 self.beacon_heiIndexList = []
589
589
590 self.noise_estimation = None
590 self.noise_estimation = None
591
591
592
592
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
594 """
594 """
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
596
596
597 Return:
597 Return:
598 noiselevel
598 noiselevel
599 """
599 """
600
600
601 noise = numpy.zeros(self.nChannels)
601 noise = numpy.zeros(self.nChannels)
602
602
603 for channel in range(self.nChannels):
603 for channel in range(self.nChannels):
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
606
606
607 return noise
607 return noise
608
608
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
610
610
611 if self.noise_estimation is not None:
611 if self.noise_estimation is not None:
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
613 else:
613 else:
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
615 return noise
615 return noise
616
616
617 def getFreqRangeTimeResponse(self, extrapoints=0):
617 def getFreqRangeTimeResponse(self, extrapoints=0):
618
618
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
621
621
622 return freqrange
622 return freqrange
623
623
624 def getAcfRange(self, extrapoints=0):
624 def getAcfRange(self, extrapoints=0):
625
625
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
628
628
629 return freqrange
629 return freqrange
630
630
631 def getFreqRange(self, extrapoints=0):
631 def getFreqRange(self, extrapoints=0):
632
632
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
635
635
636 return freqrange
636 return freqrange
637
637
638 def getVelRange(self, extrapoints=0):
638 def getVelRange(self, extrapoints=0):
639
639
640 print 'VELMAX', self.getVmax()
641 asdasdasd
640 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
642 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
641 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
643 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
642
644
643 return velrange
645 return velrange
644
646
645 def getNPairs(self):
647 def getNPairs(self):
646
648
647 return len(self.pairsList)
649 return len(self.pairsList)
648
650
649 def getPairsIndexList(self):
651 def getPairsIndexList(self):
650
652
651 return range(self.nPairs)
653 return range(self.nPairs)
652
654
653 def getNormFactor(self):
655 def getNormFactor(self):
654
656
655 pwcode = 1
657 pwcode = 1
656
658
657 if self.flagDecodeData:
659 if self.flagDecodeData:
658 pwcode = numpy.sum(self.code[0]**2)
660 pwcode = numpy.sum(self.code[0]**2)
659 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
661 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
660 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
662 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
661
663
662 return normFactor
664 return normFactor
663
665
664 def getFlagCspc(self):
666 def getFlagCspc(self):
665
667
666 if self.data_cspc is None:
668 if self.data_cspc is None:
667 return True
669 return True
668
670
669 return False
671 return False
670
672
671 def getFlagDc(self):
673 def getFlagDc(self):
672
674
673 if self.data_dc is None:
675 if self.data_dc is None:
674 return True
676 return True
675
677
676 return False
678 return False
677
679
678 def getTimeInterval(self):
680 def getTimeInterval(self):
679
681
680 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
682 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
681
683
682 return timeInterval
684 return timeInterval
683
685
684 def getPower(self):
686 def getPower(self):
685
687
686 factor = self.normFactor
688 factor = self.normFactor
687 z = self.data_spc/factor
689 z = self.data_spc/factor
688 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
690 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
689 avg = numpy.average(z, axis=1)
691 avg = numpy.average(z, axis=1)
690
692
691 return 10*numpy.log10(avg)
693 return 10*numpy.log10(avg)
692
694
693 def getCoherence(self, pairsList=None, phase=False):
695 def getCoherence(self, pairsList=None, phase=False):
694
696
695 z = []
697 z = []
696 if pairsList is None:
698 if pairsList is None:
697 pairsIndexList = self.pairsIndexList
699 pairsIndexList = self.pairsIndexList
698 else:
700 else:
699 pairsIndexList = []
701 pairsIndexList = []
700 for pair in pairsList:
702 for pair in pairsList:
701 if pair not in self.pairsList:
703 if pair not in self.pairsList:
702 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
704 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
703 pairsIndexList.append(self.pairsList.index(pair))
705 pairsIndexList.append(self.pairsList.index(pair))
704 for i in range(len(pairsIndexList)):
706 for i in range(len(pairsIndexList)):
705 pair = self.pairsList[pairsIndexList[i]]
707 pair = self.pairsList[pairsIndexList[i]]
706 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
708 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
707 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
709 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
708 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
710 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
709 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
711 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
710 if phase:
712 if phase:
711 data = numpy.arctan2(avgcoherenceComplex.imag,
713 data = numpy.arctan2(avgcoherenceComplex.imag,
712 avgcoherenceComplex.real)*180/numpy.pi
714 avgcoherenceComplex.real)*180/numpy.pi
713 else:
715 else:
714 data = numpy.abs(avgcoherenceComplex)
716 data = numpy.abs(avgcoherenceComplex)
715
717
716 z.append(data)
718 z.append(data)
717
719
718 return numpy.array(z)
720 return numpy.array(z)
719
721
720 def setValue(self, value):
722 def setValue(self, value):
721
723
722 print "This property should not be initialized"
724 print "This property should not be initialized"
723
725
724 return
726 return
725
727
726 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
728 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
727 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
729 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
728 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
730 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
729 flag_cspc = property(getFlagCspc, setValue)
731 flag_cspc = property(getFlagCspc, setValue)
730 flag_dc = property(getFlagDc, setValue)
732 flag_dc = property(getFlagDc, setValue)
731 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
733 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
732 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
734 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
733
735
734 class SpectraHeis(Spectra):
736 class SpectraHeis(Spectra):
735
737
736 data_spc = None
738 data_spc = None
737
739
738 data_cspc = None
740 data_cspc = None
739
741
740 data_dc = None
742 data_dc = None
741
743
742 nFFTPoints = None
744 nFFTPoints = None
743
745
744 # nPairs = None
746 # nPairs = None
745
747
746 pairsList = None
748 pairsList = None
747
749
748 nCohInt = None
750 nCohInt = None
749
751
750 nIncohInt = None
752 nIncohInt = None
751
753
752 def __init__(self):
754 def __init__(self):
753
755
754 self.radarControllerHeaderObj = RadarControllerHeader()
756 self.radarControllerHeaderObj = RadarControllerHeader()
755
757
756 self.systemHeaderObj = SystemHeader()
758 self.systemHeaderObj = SystemHeader()
757
759
758 self.type = "SpectraHeis"
760 self.type = "SpectraHeis"
759
761
760 # self.dtype = None
762 # self.dtype = None
761
763
762 # self.nChannels = 0
764 # self.nChannels = 0
763
765
764 # self.nHeights = 0
766 # self.nHeights = 0
765
767
766 self.nProfiles = None
768 self.nProfiles = None
767
769
768 self.heightList = None
770 self.heightList = None
769
771
770 self.channelList = None
772 self.channelList = None
771
773
772 # self.channelIndexList = None
774 # self.channelIndexList = None
773
775
774 self.flagNoData = True
776 self.flagNoData = True
775
777
776 self.flagDiscontinuousBlock = False
778 self.flagDiscontinuousBlock = False
777
779
778 # self.nPairs = 0
780 # self.nPairs = 0
779
781
780 self.utctime = None
782 self.utctime = None
781
783
782 self.blocksize = None
784 self.blocksize = None
783
785
784 self.profileIndex = 0
786 self.profileIndex = 0
785
787
786 self.nCohInt = 1
788 self.nCohInt = 1
787
789
788 self.nIncohInt = 1
790 self.nIncohInt = 1
789
791
790 def getNormFactor(self):
792 def getNormFactor(self):
791 pwcode = 1
793 pwcode = 1
792 if self.flagDecodeData:
794 if self.flagDecodeData:
793 pwcode = numpy.sum(self.code[0]**2)
795 pwcode = numpy.sum(self.code[0]**2)
794
796
795 normFactor = self.nIncohInt*self.nCohInt*pwcode
797 normFactor = self.nIncohInt*self.nCohInt*pwcode
796
798
797 return normFactor
799 return normFactor
798
800
799 def getTimeInterval(self):
801 def getTimeInterval(self):
800
802
801 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
803 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
802
804
803 return timeInterval
805 return timeInterval
804
806
805 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
807 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
806 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
808 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
807
809
808 class Fits(JROData):
810 class Fits(JROData):
809
811
810 heightList = None
812 heightList = None
811
813
812 channelList = None
814 channelList = None
813
815
814 flagNoData = True
816 flagNoData = True
815
817
816 flagDiscontinuousBlock = False
818 flagDiscontinuousBlock = False
817
819
818 useLocalTime = False
820 useLocalTime = False
819
821
820 utctime = None
822 utctime = None
821
823
822 timeZone = None
824 timeZone = None
823
825
824 # ippSeconds = None
826 # ippSeconds = None
825
827
826 # timeInterval = None
828 # timeInterval = None
827
829
828 nCohInt = None
830 nCohInt = None
829
831
830 nIncohInt = None
832 nIncohInt = None
831
833
832 noise = None
834 noise = None
833
835
834 windowOfFilter = 1
836 windowOfFilter = 1
835
837
836 #Speed of ligth
838 #Speed of ligth
837 C = 3e8
839 C = 3e8
838
840
839 frequency = 49.92e6
841 frequency = 49.92e6
840
842
841 realtime = False
843 realtime = False
842
844
843
845
844 def __init__(self):
846 def __init__(self):
845
847
846 self.type = "Fits"
848 self.type = "Fits"
847
849
848 self.nProfiles = None
850 self.nProfiles = None
849
851
850 self.heightList = None
852 self.heightList = None
851
853
852 self.channelList = None
854 self.channelList = None
853
855
854 # self.channelIndexList = None
856 # self.channelIndexList = None
855
857
856 self.flagNoData = True
858 self.flagNoData = True
857
859
858 self.utctime = None
860 self.utctime = None
859
861
860 self.nCohInt = 1
862 self.nCohInt = 1
861
863
862 self.nIncohInt = 1
864 self.nIncohInt = 1
863
865
864 self.useLocalTime = True
866 self.useLocalTime = True
865
867
866 self.profileIndex = 0
868 self.profileIndex = 0
867
869
868 # self.utctime = None
870 # self.utctime = None
869 # self.timeZone = None
871 # self.timeZone = None
870 # self.ltctime = None
872 # self.ltctime = None
871 # self.timeInterval = None
873 # self.timeInterval = None
872 # self.header = None
874 # self.header = None
873 # self.data_header = None
875 # self.data_header = None
874 # self.data = None
876 # self.data = None
875 # self.datatime = None
877 # self.datatime = None
876 # self.flagNoData = False
878 # self.flagNoData = False
877 # self.expName = ''
879 # self.expName = ''
878 # self.nChannels = None
880 # self.nChannels = None
879 # self.nSamples = None
881 # self.nSamples = None
880 # self.dataBlocksPerFile = None
882 # self.dataBlocksPerFile = None
881 # self.comments = ''
883 # self.comments = ''
882 #
884 #
883
885
884
886
885 def getltctime(self):
887 def getltctime(self):
886
888
887 if self.useLocalTime:
889 if self.useLocalTime:
888 return self.utctime - self.timeZone*60
890 return self.utctime - self.timeZone*60
889
891
890 return self.utctime
892 return self.utctime
891
893
892 def getDatatime(self):
894 def getDatatime(self):
893
895
894 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
896 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
895 return datatime
897 return datatime
896
898
897 def getTimeRange(self):
899 def getTimeRange(self):
898
900
899 datatime = []
901 datatime = []
900
902
901 datatime.append(self.ltctime)
903 datatime.append(self.ltctime)
902 datatime.append(self.ltctime + self.timeInterval)
904 datatime.append(self.ltctime + self.timeInterval)
903
905
904 datatime = numpy.array(datatime)
906 datatime = numpy.array(datatime)
905
907
906 return datatime
908 return datatime
907
909
908 def getHeiRange(self):
910 def getHeiRange(self):
909
911
910 heis = self.heightList
912 heis = self.heightList
911
913
912 return heis
914 return heis
913
915
914 def getNHeights(self):
916 def getNHeights(self):
915
917
916 return len(self.heightList)
918 return len(self.heightList)
917
919
918 def getNChannels(self):
920 def getNChannels(self):
919
921
920 return len(self.channelList)
922 return len(self.channelList)
921
923
922 def getChannelIndexList(self):
924 def getChannelIndexList(self):
923
925
924 return range(self.nChannels)
926 return range(self.nChannels)
925
927
926 def getNoise(self, type = 1):
928 def getNoise(self, type = 1):
927
929
928 #noise = numpy.zeros(self.nChannels)
930 #noise = numpy.zeros(self.nChannels)
929
931
930 if type == 1:
932 if type == 1:
931 noise = self.getNoisebyHildebrand()
933 noise = self.getNoisebyHildebrand()
932
934
933 if type == 2:
935 if type == 2:
934 noise = self.getNoisebySort()
936 noise = self.getNoisebySort()
935
937
936 if type == 3:
938 if type == 3:
937 noise = self.getNoisebyWindow()
939 noise = self.getNoisebyWindow()
938
940
939 return noise
941 return noise
940
942
941 def getTimeInterval(self):
943 def getTimeInterval(self):
942
944
943 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
945 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
944
946
945 return timeInterval
947 return timeInterval
946
948
947 datatime = property(getDatatime, "I'm the 'datatime' property")
949 datatime = property(getDatatime, "I'm the 'datatime' property")
948 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
950 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
949 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
951 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
950 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
952 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
951 noise = property(getNoise, "I'm the 'nHeights' property.")
953 noise = property(getNoise, "I'm the 'nHeights' property.")
952
954
953 ltctime = property(getltctime, "I'm the 'ltctime' property")
955 ltctime = property(getltctime, "I'm the 'ltctime' property")
954 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
956 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
955
957
956
958
957 class Correlation(JROData):
959 class Correlation(JROData):
958
960
959 noise = None
961 noise = None
960
962
961 SNR = None
963 SNR = None
962
964
963 #--------------------------------------------------
965 #--------------------------------------------------
964
966
965 mode = None
967 mode = None
966
968
967 split = False
969 split = False
968
970
969 data_cf = None
971 data_cf = None
970
972
971 lags = None
973 lags = None
972
974
973 lagRange = None
975 lagRange = None
974
976
975 pairsList = None
977 pairsList = None
976
978
977 normFactor = None
979 normFactor = None
978
980
979 #--------------------------------------------------
981 #--------------------------------------------------
980
982
981 # calculateVelocity = None
983 # calculateVelocity = None
982
984
983 nLags = None
985 nLags = None
984
986
985 nPairs = None
987 nPairs = None
986
988
987 nAvg = None
989 nAvg = None
988
990
989
991
990 def __init__(self):
992 def __init__(self):
991 '''
993 '''
992 Constructor
994 Constructor
993 '''
995 '''
994 self.radarControllerHeaderObj = RadarControllerHeader()
996 self.radarControllerHeaderObj = RadarControllerHeader()
995
997
996 self.systemHeaderObj = SystemHeader()
998 self.systemHeaderObj = SystemHeader()
997
999
998 self.type = "Correlation"
1000 self.type = "Correlation"
999
1001
1000 self.data = None
1002 self.data = None
1001
1003
1002 self.dtype = None
1004 self.dtype = None
1003
1005
1004 self.nProfiles = None
1006 self.nProfiles = None
1005
1007
1006 self.heightList = None
1008 self.heightList = None
1007
1009
1008 self.channelList = None
1010 self.channelList = None
1009
1011
1010 self.flagNoData = True
1012 self.flagNoData = True
1011
1013
1012 self.flagDiscontinuousBlock = False
1014 self.flagDiscontinuousBlock = False
1013
1015
1014 self.utctime = None
1016 self.utctime = None
1015
1017
1016 self.timeZone = None
1018 self.timeZone = None
1017
1019
1018 self.dstFlag = None
1020 self.dstFlag = None
1019
1021
1020 self.errorCount = None
1022 self.errorCount = None
1021
1023
1022 self.blocksize = None
1024 self.blocksize = None
1023
1025
1024 self.flagDecodeData = False #asumo q la data no esta decodificada
1026 self.flagDecodeData = False #asumo q la data no esta decodificada
1025
1027
1026 self.flagDeflipData = False #asumo q la data no esta sin flip
1028 self.flagDeflipData = False #asumo q la data no esta sin flip
1027
1029
1028 self.pairsList = None
1030 self.pairsList = None
1029
1031
1030 self.nPoints = None
1032 self.nPoints = None
1031
1033
1032 def getPairsList(self):
1034 def getPairsList(self):
1033
1035
1034 return self.pairsList
1036 return self.pairsList
1035
1037
1036 def getNoise(self, mode = 2):
1038 def getNoise(self, mode = 2):
1037
1039
1038 indR = numpy.where(self.lagR == 0)[0][0]
1040 indR = numpy.where(self.lagR == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1041 indT = numpy.where(self.lagT == 0)[0][0]
1040
1042
1041 jspectra0 = self.data_corr[:,:,indR,:]
1043 jspectra0 = self.data_corr[:,:,indR,:]
1042 jspectra = copy.copy(jspectra0)
1044 jspectra = copy.copy(jspectra0)
1043
1045
1044 num_chan = jspectra.shape[0]
1046 num_chan = jspectra.shape[0]
1045 num_hei = jspectra.shape[2]
1047 num_hei = jspectra.shape[2]
1046
1048
1047 freq_dc = jspectra.shape[1]/2
1049 freq_dc = jspectra.shape[1]/2
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1050 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1049
1051
1050 if ind_vel[0]<0:
1052 if ind_vel[0]<0:
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1053 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1052
1054
1053 if mode == 1:
1055 if mode == 1:
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1056 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1055
1057
1056 if mode == 2:
1058 if mode == 2:
1057
1059
1058 vel = numpy.array([-2,-1,1,2])
1060 vel = numpy.array([-2,-1,1,2])
1059 xx = numpy.zeros([4,4])
1061 xx = numpy.zeros([4,4])
1060
1062
1061 for fil in range(4):
1063 for fil in range(4):
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1064 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1063
1065
1064 xx_inv = numpy.linalg.inv(xx)
1066 xx_inv = numpy.linalg.inv(xx)
1065 xx_aux = xx_inv[0,:]
1067 xx_aux = xx_inv[0,:]
1066
1068
1067 for ich in range(num_chan):
1069 for ich in range(num_chan):
1068 yy = jspectra[ich,ind_vel,:]
1070 yy = jspectra[ich,ind_vel,:]
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1071 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1070
1072
1071 junkid = jspectra[ich,freq_dc,:]<=0
1073 junkid = jspectra[ich,freq_dc,:]<=0
1072 cjunkid = sum(junkid)
1074 cjunkid = sum(junkid)
1073
1075
1074 if cjunkid.any():
1076 if cjunkid.any():
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1077 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1076
1078
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1079 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1078
1080
1079 return noise
1081 return noise
1080
1082
1081 def getTimeInterval(self):
1083 def getTimeInterval(self):
1082
1084
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1085 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1084
1086
1085 return timeInterval
1087 return timeInterval
1086
1088
1087 def splitFunctions(self):
1089 def splitFunctions(self):
1088
1090
1089 pairsList = self.pairsList
1091 pairsList = self.pairsList
1090 ccf_pairs = []
1092 ccf_pairs = []
1091 acf_pairs = []
1093 acf_pairs = []
1092 ccf_ind = []
1094 ccf_ind = []
1093 acf_ind = []
1095 acf_ind = []
1094 for l in range(len(pairsList)):
1096 for l in range(len(pairsList)):
1095 chan0 = pairsList[l][0]
1097 chan0 = pairsList[l][0]
1096 chan1 = pairsList[l][1]
1098 chan1 = pairsList[l][1]
1097
1099
1098 #Obteniendo pares de Autocorrelacion
1100 #Obteniendo pares de Autocorrelacion
1099 if chan0 == chan1:
1101 if chan0 == chan1:
1100 acf_pairs.append(chan0)
1102 acf_pairs.append(chan0)
1101 acf_ind.append(l)
1103 acf_ind.append(l)
1102 else:
1104 else:
1103 ccf_pairs.append(pairsList[l])
1105 ccf_pairs.append(pairsList[l])
1104 ccf_ind.append(l)
1106 ccf_ind.append(l)
1105
1107
1106 data_acf = self.data_cf[acf_ind]
1108 data_acf = self.data_cf[acf_ind]
1107 data_ccf = self.data_cf[ccf_ind]
1109 data_ccf = self.data_cf[ccf_ind]
1108
1110
1109 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1111 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1110
1112
1111 def getNormFactor(self):
1113 def getNormFactor(self):
1112 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1114 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1113 acf_pairs = numpy.array(acf_pairs)
1115 acf_pairs = numpy.array(acf_pairs)
1114 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1116 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1115
1117
1116 for p in range(self.nPairs):
1118 for p in range(self.nPairs):
1117 pair = self.pairsList[p]
1119 pair = self.pairsList[p]
1118
1120
1119 ch0 = pair[0]
1121 ch0 = pair[0]
1120 ch1 = pair[1]
1122 ch1 = pair[1]
1121
1123
1122 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1124 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1123 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1125 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1124 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1126 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1125
1127
1126 return normFactor
1128 return normFactor
1127
1129
1128 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1130 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1129 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1131 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1130
1132
1131 class Parameters(Spectra):
1133 class Parameters(Spectra):
1132
1134
1133 experimentInfo = None #Information about the experiment
1135 experimentInfo = None #Information about the experiment
1134
1136
1135 #Information from previous data
1137 #Information from previous data
1136
1138
1137 inputUnit = None #Type of data to be processed
1139 inputUnit = None #Type of data to be processed
1138
1140
1139 operation = None #Type of operation to parametrize
1141 operation = None #Type of operation to parametrize
1140
1142
1141 #normFactor = None #Normalization Factor
1143 #normFactor = None #Normalization Factor
1142
1144
1143 groupList = None #List of Pairs, Groups, etc
1145 groupList = None #List of Pairs, Groups, etc
1144
1146
1145 #Parameters
1147 #Parameters
1146
1148
1147 data_param = None #Parameters obtained
1149 data_param = None #Parameters obtained
1148
1150
1149 data_pre = None #Data Pre Parametrization
1151 data_pre = None #Data Pre Parametrization
1150
1152
1151 data_SNR = None #Signal to Noise Ratio
1153 data_SNR = None #Signal to Noise Ratio
1152
1154
1153 # heightRange = None #Heights
1155 # heightRange = None #Heights
1154
1156
1155 abscissaList = None #Abscissa, can be velocities, lags or time
1157 abscissaList = None #Abscissa, can be velocities, lags or time
1156
1158
1157 # noise = None #Noise Potency
1159 # noise = None #Noise Potency
1158
1160
1159 utctimeInit = None #Initial UTC time
1161 utctimeInit = None #Initial UTC time
1160
1162
1161 paramInterval = None #Time interval to calculate Parameters in seconds
1163 paramInterval = None #Time interval to calculate Parameters in seconds
1162
1164
1163 useLocalTime = True
1165 useLocalTime = True
1164
1166
1165 #Fitting
1167 #Fitting
1166
1168
1167 data_error = None #Error of the estimation
1169 data_error = None #Error of the estimation
1168
1170
1169 constants = None
1171 constants = None
1170
1172
1171 library = None
1173 library = None
1172
1174
1173 #Output signal
1175 #Output signal
1174
1176
1175 outputInterval = None #Time interval to calculate output signal in seconds
1177 outputInterval = None #Time interval to calculate output signal in seconds
1176
1178
1177 data_output = None #Out signal
1179 data_output = None #Out signal
1178
1180
1179 nAvg = None
1181 nAvg = None
1180
1182
1181 noise_estimation = None
1183 noise_estimation = None
1182
1184
1183 GauSPC = None #Fit gaussian SPC
1185 GauSPC = None #Fit gaussian SPC
1184
1186
1185
1187
1186 def __init__(self):
1188 def __init__(self):
1187 '''
1189 '''
1188 Constructor
1190 Constructor
1189 '''
1191 '''
1190 self.radarControllerHeaderObj = RadarControllerHeader()
1192 self.radarControllerHeaderObj = RadarControllerHeader()
1191
1193
1192 self.systemHeaderObj = SystemHeader()
1194 self.systemHeaderObj = SystemHeader()
1193
1195
1194 self.type = "Parameters"
1196 self.type = "Parameters"
1195
1197
1196 def getTimeRange1(self, interval):
1198 def getTimeRange1(self, interval):
1197
1199
1198 datatime = []
1200 datatime = []
1199
1201
1200 if self.useLocalTime:
1202 if self.useLocalTime:
1201 time1 = self.utctimeInit - self.timeZone*60
1203 time1 = self.utctimeInit - self.timeZone*60
1202 else:
1204 else:
1203 time1 = self.utctimeInit
1205 time1 = self.utctimeInit
1204
1206
1205 datatime.append(time1)
1207 datatime.append(time1)
1206 datatime.append(time1 + interval)
1208 datatime.append(time1 + interval)
1207 datatime = numpy.array(datatime)
1209 datatime = numpy.array(datatime)
1208
1210
1209 return datatime
1211 return datatime
1210
1212
1211 def getTimeInterval(self):
1213 def getTimeInterval(self):
1212
1214
1213 if hasattr(self, 'timeInterval1'):
1215 if hasattr(self, 'timeInterval1'):
1214 return self.timeInterval1
1216 return self.timeInterval1
1215 else:
1217 else:
1216 return self.paramInterval
1218 return self.paramInterval
1217
1219
1218 def setValue(self, value):
1220 def setValue(self, value):
1219
1221
1220 print "This property should not be initialized"
1222 print "This property should not be initialized"
1221
1223
1222 return
1224 return
1223
1225
1224 def getNoise(self):
1226 def getNoise(self):
1225
1227
1226 return self.spc_noise
1228 return self.spc_noise
1227
1229
1228 timeInterval = property(getTimeInterval)
1230 timeInterval = property(getTimeInterval)
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1231 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -1,762 +1,762
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10
10
11 SPEED_OF_LIGHT = 299792458
11 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 3e8
12 SPEED_OF_LIGHT = 3e8
13
13
14 BASIC_STRUCTURE = numpy.dtype([
14 BASIC_STRUCTURE = numpy.dtype([
15 ('nSize','<u4'),
15 ('nSize','<u4'),
16 ('nVersion','<u2'),
16 ('nVersion','<u2'),
17 ('nDataBlockId','<u4'),
17 ('nDataBlockId','<u4'),
18 ('nUtime','<u4'),
18 ('nUtime','<u4'),
19 ('nMilsec','<u2'),
19 ('nMilsec','<u2'),
20 ('nTimezone','<i2'),
20 ('nTimezone','<i2'),
21 ('nDstflag','<i2'),
21 ('nDstflag','<i2'),
22 ('nErrorCount','<u4')
22 ('nErrorCount','<u4')
23 ])
23 ])
24
24
25 SYSTEM_STRUCTURE = numpy.dtype([
25 SYSTEM_STRUCTURE = numpy.dtype([
26 ('nSize','<u4'),
26 ('nSize','<u4'),
27 ('nNumSamples','<u4'),
27 ('nNumSamples','<u4'),
28 ('nNumProfiles','<u4'),
28 ('nNumProfiles','<u4'),
29 ('nNumChannels','<u4'),
29 ('nNumChannels','<u4'),
30 ('nADCResolution','<u4'),
30 ('nADCResolution','<u4'),
31 ('nPCDIOBusWidth','<u4'),
31 ('nPCDIOBusWidth','<u4'),
32 ])
32 ])
33
33
34 RADAR_STRUCTURE = numpy.dtype([
34 RADAR_STRUCTURE = numpy.dtype([
35 ('nSize','<u4'),
35 ('nSize','<u4'),
36 ('nExpType','<u4'),
36 ('nExpType','<u4'),
37 ('nNTx','<u4'),
37 ('nNTx','<u4'),
38 ('fIpp','<f4'),
38 ('fIpp','<f4'),
39 ('fTxA','<f4'),
39 ('fTxA','<f4'),
40 ('fTxB','<f4'),
40 ('fTxB','<f4'),
41 ('nNumWindows','<u4'),
41 ('nNumWindows','<u4'),
42 ('nNumTaus','<u4'),
42 ('nNumTaus','<u4'),
43 ('nCodeType','<u4'),
43 ('nCodeType','<u4'),
44 ('nLine6Function','<u4'),
44 ('nLine6Function','<u4'),
45 ('nLine5Function','<u4'),
45 ('nLine5Function','<u4'),
46 ('fClock','<f4'),
46 ('fClock','<f4'),
47 ('nPrePulseBefore','<u4'),
47 ('nPrePulseBefore','<u4'),
48 ('nPrePulseAfter','<u4'),
48 ('nPrePulseAfter','<u4'),
49 ('sRangeIPP','<a20'),
49 ('sRangeIPP','<a20'),
50 ('sRangeTxA','<a20'),
50 ('sRangeTxA','<a20'),
51 ('sRangeTxB','<a20'),
51 ('sRangeTxB','<a20'),
52 ])
52 ])
53
53
54 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
54 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55
55
56
56
57 PROCESSING_STRUCTURE = numpy.dtype([
57 PROCESSING_STRUCTURE = numpy.dtype([
58 ('nSize','<u4'),
58 ('nSize','<u4'),
59 ('nDataType','<u4'),
59 ('nDataType','<u4'),
60 ('nSizeOfDataBlock','<u4'),
60 ('nSizeOfDataBlock','<u4'),
61 ('nProfilesperBlock','<u4'),
61 ('nProfilesperBlock','<u4'),
62 ('nDataBlocksperFile','<u4'),
62 ('nDataBlocksperFile','<u4'),
63 ('nNumWindows','<u4'),
63 ('nNumWindows','<u4'),
64 ('nProcessFlags','<u4'),
64 ('nProcessFlags','<u4'),
65 ('nCoherentIntegrations','<u4'),
65 ('nCoherentIntegrations','<u4'),
66 ('nIncoherentIntegrations','<u4'),
66 ('nIncoherentIntegrations','<u4'),
67 ('nTotalSpectra','<u4')
67 ('nTotalSpectra','<u4')
68 ])
68 ])
69
69
70 class Header(object):
70 class Header(object):
71
71
72 def __init__(self):
72 def __init__(self):
73 raise NotImplementedError
73 raise NotImplementedError
74
74
75 def copy(self):
75 def copy(self):
76 return copy.deepcopy(self)
76 return copy.deepcopy(self)
77
77
78 def read(self):
78 def read(self):
79
79
80 raise NotImplementedError
80 raise NotImplementedError
81
81
82 def write(self):
82 def write(self):
83
83
84 raise NotImplementedError
84 raise NotImplementedError
85
85
86 def printInfo(self):
86 def printInfo(self):
87
87
88 message = "#"*50 + "\n"
88 message = "#"*50 + "\n"
89 message += self.__class__.__name__.upper() + "\n"
89 message += self.__class__.__name__.upper() + "\n"
90 message += "#"*50 + "\n"
90 message += "#"*50 + "\n"
91
91
92 keyList = self.__dict__.keys()
92 keyList = self.__dict__.keys()
93 keyList.sort()
93 keyList.sort()
94
94
95 for key in keyList:
95 for key in keyList:
96 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
96 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
97
97
98 if "size" not in keyList:
98 if "size" not in keyList:
99 attr = getattr(self, "size")
99 attr = getattr(self, "size")
100
100
101 if attr:
101 if attr:
102 message += "%s = %s" %("size", attr) + "\n"
102 message += "%s = %s" %("size", attr) + "\n"
103
103
104 print message
104 print message
105
105
106 class BasicHeader(Header):
106 class BasicHeader(Header):
107
107
108 size = None
108 size = None
109 version = None
109 version = None
110 dataBlock = None
110 dataBlock = None
111 utc = None
111 utc = None
112 ltc = None
112 ltc = None
113 miliSecond = None
113 miliSecond = None
114 timeZone = None
114 timeZone = None
115 dstFlag = None
115 dstFlag = None
116 errorCount = None
116 errorCount = None
117 datatime = None
117 datatime = None
118
118
119 __LOCALTIME = None
119 __LOCALTIME = None
120
120
121 def __init__(self, useLocalTime=True):
121 def __init__(self, useLocalTime=True):
122
122
123 self.size = 24
123 self.size = 24
124 self.version = 0
124 self.version = 0
125 self.dataBlock = 0
125 self.dataBlock = 0
126 self.utc = 0
126 self.utc = 0
127 self.miliSecond = 0
127 self.miliSecond = 0
128 self.timeZone = 0
128 self.timeZone = 0
129 self.dstFlag = 0
129 self.dstFlag = 0
130 self.errorCount = 0
130 self.errorCount = 0
131
131
132 self.useLocalTime = useLocalTime
132 self.useLocalTime = useLocalTime
133
133
134 def read(self, fp):
134 def read(self, fp):
135
135
136 try:
136 try:
137 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
137 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
138
138
139 except Exception, e:
139 except Exception, e:
140 print "BasicHeader: "
140 print "BasicHeader: "
141 print e
141 print e
142 return 0
142 return 0
143
143
144 self.size = int(header['nSize'][0])
144 self.size = int(header['nSize'][0])
145 self.version = int(header['nVersion'][0])
145 self.version = int(header['nVersion'][0])
146 self.dataBlock = int(header['nDataBlockId'][0])
146 self.dataBlock = int(header['nDataBlockId'][0])
147 self.utc = int(header['nUtime'][0])
147 self.utc = int(header['nUtime'][0])
148 self.miliSecond = int(header['nMilsec'][0])
148 self.miliSecond = int(header['nMilsec'][0])
149 self.timeZone = int(header['nTimezone'][0])
149 self.timeZone = int(header['nTimezone'][0])
150 self.dstFlag = int(header['nDstflag'][0])
150 self.dstFlag = int(header['nDstflag'][0])
151 self.errorCount = int(header['nErrorCount'][0])
151 self.errorCount = int(header['nErrorCount'][0])
152
152
153 if self.size < 24:
153 if self.size < 24:
154 return 0
154 return 0
155
155
156 return 1
156 return 1
157
157
158 def write(self, fp):
158 def write(self, fp):
159
159
160 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
160 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
161 header = numpy.array(headerTuple, BASIC_STRUCTURE)
161 header = numpy.array(headerTuple, BASIC_STRUCTURE)
162 header.tofile(fp)
162 header.tofile(fp)
163
163
164 return 1
164 return 1
165
165
166 def get_ltc(self):
166 def get_ltc(self):
167
167
168 return self.utc - self.timeZone*60
168 return self.utc - self.timeZone*60
169
169
170 def set_ltc(self, value):
170 def set_ltc(self, value):
171
171
172 self.utc = value + self.timeZone*60
172 self.utc = value + self.timeZone*60
173
173
174 def get_datatime(self):
174 def get_datatime(self):
175
175
176 return datetime.datetime.utcfromtimestamp(self.ltc)
176 return datetime.datetime.utcfromtimestamp(self.ltc)
177
177
178 ltc = property(get_ltc, set_ltc)
178 ltc = property(get_ltc, set_ltc)
179 datatime = property(get_datatime)
179 datatime = property(get_datatime)
180
180
181 class SystemHeader(Header):
181 class SystemHeader(Header):
182
182
183 size = None
183 size = None
184 nSamples = None
184 nSamples = None
185 nProfiles = None
185 nProfiles = None
186 nChannels = None
186 nChannels = None
187 adcResolution = None
187 adcResolution = None
188 pciDioBusWidth = None
188 pciDioBusWidth = None
189
189
190 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
190 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
191
191
192 self.size = 24
192 self.size = 24
193 self.nSamples = nSamples
193 self.nSamples = nSamples
194 self.nProfiles = nProfiles
194 self.nProfiles = nProfiles
195 self.nChannels = nChannels
195 self.nChannels = nChannels
196 self.adcResolution = adcResolution
196 self.adcResolution = adcResolution
197 self.pciDioBusWidth = pciDioBusWith
197 self.pciDioBusWidth = pciDioBusWith
198
198
199 def read(self, fp):
199 def read(self, fp):
200
200
201 startFp = fp.tell()
201 startFp = fp.tell()
202
202
203 try:
203 try:
204 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
204 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
205 except Exception, e:
205 except Exception, e:
206 print "System Header: " + e
206 print "System Header: " + e
207 return 0
207 return 0
208
208
209 self.size = header['nSize'][0]
209 self.size = header['nSize'][0]
210 self.nSamples = header['nNumSamples'][0]
210 self.nSamples = header['nNumSamples'][0]
211 self.nProfiles = header['nNumProfiles'][0]
211 self.nProfiles = header['nNumProfiles'][0]
212 self.nChannels = header['nNumChannels'][0]
212 self.nChannels = header['nNumChannels'][0]
213 self.adcResolution = header['nADCResolution'][0]
213 self.adcResolution = header['nADCResolution'][0]
214 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
214 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
215
215
216 endFp = self.size + startFp
216 endFp = self.size + startFp
217
217
218 if fp.tell() > endFp:
218 if fp.tell() > endFp:
219 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
219 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
220 return 0
220 return 0
221
221
222 if fp.tell() < endFp:
222 if fp.tell() < endFp:
223 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
223 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
224 return 0
224 return 0
225
225
226 return 1
226 return 1
227
227
228 def write(self, fp):
228 def write(self, fp):
229
229
230 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
230 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
231 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
231 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
232 header.tofile(fp)
232 header.tofile(fp)
233
233
234 return 1
234 return 1
235
235
236 class RadarControllerHeader(Header):
236 class RadarControllerHeader(Header):
237
237
238 expType = None
238 expType = None
239 nTx = None
239 nTx = None
240 ipp = None
240 ipp = None
241 txA = None
241 txA = None
242 txB = None
242 txB = None
243 nWindows = None
243 nWindows = None
244 numTaus = None
244 numTaus = None
245 codeType = None
245 codeType = None
246 line6Function = None
246 line6Function = None
247 line5Function = None
247 line5Function = None
248 fClock = None
248 fClock = None
249 prePulseBefore = None
249 prePulseBefore = None
250 prePulserAfter = None
250 prePulserAfter = None
251 rangeIpp = None
251 rangeIpp = None
252 rangeTxA = None
252 rangeTxA = None
253 rangeTxB = None
253 rangeTxB = None
254
254
255 __size = None
255 __size = None
256
256
257 def __init__(self, expType=2, nTx=1,
257 def __init__(self, expType=2, nTx=1,
258 ippKm=None, txA=0, txB=0,
258 ippKm=None, txA=0, txB=0,
259 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
259 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
260 numTaus=0, line6Function=0, line5Function=0, fClock=None,
260 numTaus=0, line6Function=0, line5Function=0, fClock=None,
261 prePulseBefore=0, prePulseAfter=0,
261 prePulseBefore=0, prePulseAfter=0,
262 codeType=0, nCode=0, nBaud=0, code=None,
262 codeType=0, nCode=0, nBaud=0, code=None,
263 flip1=0, flip2=0):
263 flip1=0, flip2=0):
264
264
265 # self.size = 116
265 # self.size = 116
266 self.expType = expType
266 self.expType = expType
267 self.nTx = nTx
267 self.nTx = nTx
268 self.ipp = ippKm
268 self.ipp = ippKm
269 self.txA = txA
269 self.txA = txA
270 self.txB = txB
270 self.txB = txB
271 self.rangeIpp = ippKm
271 self.rangeIpp = ippKm
272 self.rangeTxA = txA
272 self.rangeTxA = txA
273 self.rangeTxB = txB
273 self.rangeTxB = txB
274
274
275 self.nWindows = nWindows
275 self.nWindows = nWindows
276 self.numTaus = numTaus
276 self.numTaus = numTaus
277 self.codeType = codeType
277 self.codeType = codeType
278 self.line6Function = line6Function
278 self.line6Function = line6Function
279 self.line5Function = line5Function
279 self.line5Function = line5Function
280 self.fClock = fClock
280 self.fClock = fClock
281 self.prePulseBefore = prePulseBefore
281 self.prePulseBefore = prePulseBefore
282 self.prePulserAfter = prePulseAfter
282 self.prePulserAfter = prePulseAfter
283
283
284 self.nHeights = nHeights
284 self.nHeights = nHeights
285 self.firstHeight = firstHeight
285 self.firstHeight = firstHeight
286 self.deltaHeight = deltaHeight
286 self.deltaHeight = deltaHeight
287 self.samplesWin = nHeights
287 self.samplesWin = nHeights
288
288
289 self.nCode = nCode
289 self.nCode = nCode
290 self.nBaud = nBaud
290 self.nBaud = nBaud
291 self.code = code
291 self.code = code
292 self.flip1 = flip1
292 self.flip1 = flip1
293 self.flip2 = flip2
293 self.flip2 = flip2
294
294
295 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
295 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
296 # self.dynamic = numpy.array([],numpy.dtype('byte'))
296 # self.dynamic = numpy.array([],numpy.dtype('byte'))
297
297
298 if self.fClock is None and self.deltaHeight is not None:
298 if self.fClock is None and self.deltaHeight is not None:
299 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
299 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
300
300
301 def read(self, fp):
301 def read(self, fp):
302
302
303
303
304 startFp = fp.tell()
304 startFp = fp.tell()
305 try:
305 try:
306 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
306 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
307 except Exception, e:
307 except Exception, e:
308 print "RadarControllerHeader: " + e
308 print "RadarControllerHeader: " + e
309 return 0
309 return 0
310
310
311 size = int(header['nSize'][0])
311 size = int(header['nSize'][0])
312 self.expType = int(header['nExpType'][0])
312 self.expType = int(header['nExpType'][0])
313 self.nTx = int(header['nNTx'][0])
313 self.nTx = int(header['nNTx'][0])
314 self.ipp = float(header['fIpp'][0])
314 self.ipp = float(header['fIpp'][0])
315 self.txA = float(header['fTxA'][0])
315 self.txA = float(header['fTxA'][0])
316 self.txB = float(header['fTxB'][0])
316 self.txB = float(header['fTxB'][0])
317 self.nWindows = int(header['nNumWindows'][0])
317 self.nWindows = int(header['nNumWindows'][0])
318 self.numTaus = int(header['nNumTaus'][0])
318 self.numTaus = int(header['nNumTaus'][0])
319 self.codeType = int(header['nCodeType'][0])
319 self.codeType = int(header['nCodeType'][0])
320 self.line6Function = int(header['nLine6Function'][0])
320 self.line6Function = int(header['nLine6Function'][0])
321 self.line5Function = int(header['nLine5Function'][0])
321 self.line5Function = int(header['nLine5Function'][0])
322 self.fClock = float(header['fClock'][0])
322 self.fClock = float(header['fClock'][0])
323 self.prePulseBefore = int(header['nPrePulseBefore'][0])
323 self.prePulseBefore = int(header['nPrePulseBefore'][0])
324 self.prePulserAfter = int(header['nPrePulseAfter'][0])
324 self.prePulserAfter = int(header['nPrePulseAfter'][0])
325 self.rangeIpp = header['sRangeIPP'][0]
325 self.rangeIpp = header['sRangeIPP'][0]
326 self.rangeTxA = header['sRangeTxA'][0]
326 self.rangeTxA = header['sRangeTxA'][0]
327 self.rangeTxB = header['sRangeTxB'][0]
327 self.rangeTxB = header['sRangeTxB'][0]
328
328
329 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
329 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
330
330
331 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
331 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
332 self.firstHeight = samplingWindow['h0']
332 self.firstHeight = samplingWindow['h0']
333 self.deltaHeight = samplingWindow['dh']
333 self.deltaHeight = samplingWindow['dh']
334 self.samplesWin = samplingWindow['nsa']
334 self.samplesWin = samplingWindow['nsa']
335
335
336 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
336 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
337
337
338 self.code_size = 0
338 self.code_size = 0
339 if self.codeType != 0:
339 if self.codeType != 0:
340 self.nCode = int(numpy.fromfile(fp,'<u4',1))
340 self.nCode = int(numpy.fromfile(fp,'<u4',1))
341 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
341 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
342
342
343 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
343 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
344 for ic in range(self.nCode):
344 for ic in range(self.nCode):
345 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
345 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
346 for ib in range(self.nBaud-1,-1,-1):
346 for ib in range(self.nBaud-1,-1,-1):
347 code[ic,ib] = temp[ib/32]%2
347 code[ic,ib] = temp[ib/32]%2
348 temp[ib/32] = temp[ib/32]/2
348 temp[ib/32] = temp[ib/32]/2
349
349
350 self.code = 2.0*code - 1.0
350 self.code = 2.0*code - 1.0
351 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
351 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
352
352
353 # if self.line5Function == RCfunction.FLIP:
353 # if self.line5Function == RCfunction.FLIP:
354 # self.flip1 = numpy.fromfile(fp,'<u4',1)
354 # self.flip1 = numpy.fromfile(fp,'<u4',1)
355 #
355 #
356 # if self.line6Function == RCfunction.FLIP:
356 # if self.line6Function == RCfunction.FLIP:
357 # self.flip2 = numpy.fromfile(fp,'<u4',1)
357 # self.flip2 = numpy.fromfile(fp,'<u4',1)
358
358
359 endFp = size + startFp
359 endFp = size + startFp
360
360
361 if fp.tell() != endFp:
361 if fp.tell() != endFp:
362 # fp.seek(endFp)
362 # fp.seek(endFp)
363 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
363 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
364 # return 0
364 # return 0
365
365
366 if fp.tell() > endFp:
366 if fp.tell() > endFp:
367 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
367 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
368 # return 0
368 # return 0
369
369
370 if fp.tell() < endFp:
370 if fp.tell() < endFp:
371 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
371 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
372
372
373
373
374 return 1
374 return 1
375
375
376 def write(self, fp):
376 def write(self, fp):
377
377
378 headerTuple = (self.size,
378 headerTuple = (self.size,
379 self.expType,
379 self.expType,
380 self.nTx,
380 self.nTx,
381 self.ipp,
381 self.ipp,
382 self.txA,
382 self.txA,
383 self.txB,
383 self.txB,
384 self.nWindows,
384 self.nWindows,
385 self.numTaus,
385 self.numTaus,
386 self.codeType,
386 self.codeType,
387 self.line6Function,
387 self.line6Function,
388 self.line5Function,
388 self.line5Function,
389 self.fClock,
389 self.fClock,
390 self.prePulseBefore,
390 self.prePulseBefore,
391 self.prePulserAfter,
391 self.prePulserAfter,
392 self.rangeIpp,
392 self.rangeIpp,
393 self.rangeTxA,
393 self.rangeTxA,
394 self.rangeTxB)
394 self.rangeTxB)
395
395
396 header = numpy.array(headerTuple,RADAR_STRUCTURE)
396 header = numpy.array(headerTuple,RADAR_STRUCTURE)
397 header.tofile(fp)
397 header.tofile(fp)
398
398
399 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
399 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
400 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
400 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
401 samplingWindow.tofile(fp)
401 samplingWindow.tofile(fp)
402
402
403 if self.numTaus > 0:
403 if self.numTaus > 0:
404 self.Taus.tofile(fp)
404 self.Taus.tofile(fp)
405
405
406 if self.codeType !=0:
406 if self.codeType !=0:
407 nCode = numpy.array(self.nCode, '<u4')
407 nCode = numpy.array(self.nCode, '<u4')
408 nCode.tofile(fp)
408 nCode.tofile(fp)
409 nBaud = numpy.array(self.nBaud, '<u4')
409 nBaud = numpy.array(self.nBaud, '<u4')
410 nBaud.tofile(fp)
410 nBaud.tofile(fp)
411 code1 = (self.code + 1.0)/2.
411 code1 = (self.code + 1.0)/2.
412
412
413 for ic in range(self.nCode):
413 for ic in range(self.nCode):
414 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
414 tempx = numpy.zeros(int(numpy.ceil(self.nBaud/32.)))
415 start = 0
415 start = 0
416 end = 32
416 end = 32
417 for i in range(len(tempx)):
417 for i in range(len(tempx)):
418 code_selected = code1[ic,start:end]
418 code_selected = code1[ic,start:end]
419 for j in range(len(code_selected)-1,-1,-1):
419 for j in range(len(code_selected)-1,-1,-1):
420 if code_selected[j] == 1:
420 if code_selected[j] == 1:
421 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
421 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
422 start = start + 32
422 start = start + 32
423 end = end + 32
423 end = end + 32
424
424
425 tempx = tempx.astype('u4')
425 tempx = tempx.astype('u4')
426 tempx.tofile(fp)
426 tempx.tofile(fp)
427
427
428 # if self.line5Function == RCfunction.FLIP:
428 # if self.line5Function == RCfunction.FLIP:
429 # self.flip1.tofile(fp)
429 # self.flip1.tofile(fp)
430 #
430 #
431 # if self.line6Function == RCfunction.FLIP:
431 # if self.line6Function == RCfunction.FLIP:
432 # self.flip2.tofile(fp)
432 # self.flip2.tofile(fp)
433
433
434 return 1
434 return 1
435
435
436 def get_ippSeconds(self):
436 def get_ippSeconds(self):
437 '''
437 '''
438 '''
438 '''
439 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
439 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
440
440
441 return ippSeconds
441 return ippSeconds
442
442
443 def set_ippSeconds(self, ippSeconds):
443 def set_ippSeconds(self, ippSeconds):
444 '''
444 '''
445 '''
445 '''
446
446
447 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
447 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
448
448
449 return
449 return
450
450
451 def get_size(self):
451 def get_size(self):
452
452
453 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
453 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
454
454
455 if self.codeType != 0:
455 if self.codeType != 0:
456 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
456 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
457
457
458 return self.__size
458 return self.__size
459
459
460 def set_size(self, value):
460 def set_size(self, value):
461
461
462 raise IOError, "size is a property and it cannot be set, just read"
462 raise IOError, "size is a property and it cannot be set, just read"
463
463
464 return
464 return
465
465
466 ippSeconds = property(get_ippSeconds, set_ippSeconds)
466 ippSeconds = property(get_ippSeconds, set_ippSeconds)
467 size = property(get_size, set_size)
467 size = property(get_size, set_size)
468
468
469 class ProcessingHeader(Header):
469 class ProcessingHeader(Header):
470
470
471 # size = None
471 # size = None
472 dtype = None
472 dtype = None
473 blockSize = None
473 blockSize = None
474 profilesPerBlock = None
474 profilesPerBlock = None
475 dataBlocksPerFile = None
475 dataBlocksPerFile = None
476 nWindows = None
476 nWindows = None
477 processFlags = None
477 processFlags = None
478 nCohInt = None
478 nCohInt = None
479 nIncohInt = None
479 nIncohInt = None
480 totalSpectra = None
480 totalSpectra = None
481
481
482 flag_dc = None
482 flag_dc = None
483 flag_cspc = None
483 flag_cspc = None
484
484
485 def __init__(self):
485 def __init__(self):
486
486
487 # self.size = 0
487 # self.size = 0
488 self.dtype = 0
488 self.dtype = 0
489 self.blockSize = 0
489 self.blockSize = 0
490 self.profilesPerBlock = 0
490 self.profilesPerBlock = 0
491 self.dataBlocksPerFile = 0
491 self.dataBlocksPerFile = 0
492 self.nWindows = 0
492 self.nWindows = 0
493 self.processFlags = 0
493 self.processFlags = 0
494 self.nCohInt = 0
494 self.nCohInt = 0
495 self.nIncohInt = 0
495 self.nIncohInt = 0
496 self.totalSpectra = 0
496 self.totalSpectra = 0
497
497
498 self.nHeights = 0
498 self.nHeights = 0
499 self.firstHeight = 0
499 self.firstHeight = 0
500 self.deltaHeight = 0
500 self.deltaHeight = 0
501 self.samplesWin = 0
501 self.samplesWin = 0
502 self.spectraComb = 0
502 self.spectraComb = 0
503 self.nCode = None
503 self.nCode = None
504 self.code = None
504 self.code = None
505 self.nBaud = None
505 self.nBaud = None
506
506
507 self.shif_fft = False
507 self.shif_fft = False
508 self.flag_dc = False
508 self.flag_dc = False
509 self.flag_cspc = False
509 self.flag_cspc = False
510 self.flag_decode = False
510 self.flag_decode = False
511 self.flag_deflip = False
511 self.flag_deflip = False
512
512
513 def read(self, fp):
513 def read(self, fp):
514
514
515 startFp = fp.tell()
515 startFp = fp.tell()
516
516
517 try:
517 try:
518 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
518 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
519 except Exception, e:
519 except Exception, e:
520 print "ProcessingHeader: " + e
520 print "ProcessingHeader: " + e
521 return 0
521 return 0
522
522
523 size = int(header['nSize'][0])
523 size = int(header['nSize'][0])
524 self.dtype = int(header['nDataType'][0])
524 self.dtype = int(header['nDataType'][0])
525 self.blockSize = int(header['nSizeOfDataBlock'][0])
525 self.blockSize = int(header['nSizeOfDataBlock'][0])
526 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
526 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
527 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
527 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
528 self.nWindows = int(header['nNumWindows'][0])
528 self.nWindows = int(header['nNumWindows'][0])
529 self.processFlags = header['nProcessFlags']
529 self.processFlags = header['nProcessFlags']
530 self.nCohInt = int(header['nCoherentIntegrations'][0])
530 self.nCohInt = int(header['nCoherentIntegrations'][0])
531 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
531 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
532 self.totalSpectra = int(header['nTotalSpectra'][0])
532 self.totalSpectra = int(header['nTotalSpectra'][0])
533
533
534 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
534 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
535
535
536 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
536 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
537 self.firstHeight = float(samplingWindow['h0'][0])
537 self.firstHeight = float(samplingWindow['h0'][0])
538 self.deltaHeight = float(samplingWindow['dh'][0])
538 self.deltaHeight = float(samplingWindow['dh'][0])
539 self.samplesWin = samplingWindow['nsa'][0]
539 self.samplesWin = samplingWindow['nsa'][0]
540
540
541 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
541 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
542
542
543 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
543 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
544 self.nCode = int(numpy.fromfile(fp,'<u4',1))
544 self.nCode = int(numpy.fromfile(fp,'<u4',1))
545 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
545 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
546 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
546 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
547
547
548 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
548 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
549 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
549 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
550 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
550 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
551
551
552 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
552 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
553 self.shif_fft = True
553 self.shif_fft = True
554 else:
554 else:
555 self.shif_fft = False
555 self.shif_fft = False
556
556
557 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
557 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
558 self.flag_dc = True
558 self.flag_dc = True
559 else:
559 else:
560 self.flag_dc = False
560 self.flag_dc = False
561
561
562 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
562 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
563 self.flag_decode = True
563 self.flag_decode = True
564 else:
564 else:
565 self.flag_decode = False
565 self.flag_decode = False
566
566
567 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
567 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
568 self.flag_deflip = True
568 self.flag_deflip = True
569 else:
569 else:
570 self.flag_deflip = False
570 self.flag_deflip = False
571
571
572 nChannels = 0
572 nChannels = 0
573 nPairs = 0
573 nPairs = 0
574 pairList = []
574 pairList = []
575
575
576 for i in range( 0, self.totalSpectra*2, 2 ):
576 for i in range( 0, self.totalSpectra*2, 2 ):
577 if self.spectraComb[i] == self.spectraComb[i+1]:
577 if self.spectraComb[i] == self.spectraComb[i+1]:
578 nChannels = nChannels + 1 #par de canales iguales
578 nChannels = nChannels + 1 #par de canales iguales
579 else:
579 else:
580 nPairs = nPairs + 1 #par de canales diferentes
580 nPairs = nPairs + 1 #par de canales diferentes
581 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
581 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
582
582
583 self.flag_cspc = False
583 self.flag_cspc = False
584 if nPairs > 0:
584 if nPairs > 0:
585 self.flag_cspc = True
585 self.flag_cspc = True
586
586
587 endFp = size + startFp
587 endFp = size + startFp
588
588
589 if fp.tell() > endFp:
589 if fp.tell() > endFp:
590 sys.stderr.write("Warning: Processing header size is lower than it has to be")
590 sys.stderr.write("Warning: Processing header size is lower than it has to be")
591 return 0
591 return 0
592
592
593 if fp.tell() < endFp:
593 if fp.tell() < endFp:
594 sys.stderr.write("Warning: Processing header size is greater than it is considered")
594 sys.stderr.write("Warning: Processing header size is greater than it is considered")
595
595
596 return 1
596 return 1
597
597
598 def write(self, fp):
598 def write(self, fp):
599 #Clear DEFINE_PROCESS_CODE
599 #Clear DEFINE_PROCESS_CODE
600 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
600 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
601
601
602 headerTuple = (self.size,
602 headerTuple = (self.size,
603 self.dtype,
603 self.dtype,
604 self.blockSize,
604 self.blockSize,
605 self.profilesPerBlock,
605 self.profilesPerBlock,
606 self.dataBlocksPerFile,
606 self.dataBlocksPerFile,
607 self.nWindows,
607 self.nWindows,
608 self.processFlags,
608 self.processFlags,
609 self.nCohInt,
609 self.nCohInt,
610 self.nIncohInt,
610 self.nIncohInt,
611 self.totalSpectra)
611 self.totalSpectra)
612
612
613 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
613 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
614 header.tofile(fp)
614 header.tofile(fp)
615
615
616 if self.nWindows != 0:
616 if self.nWindows != 0:
617 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
617 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
618 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
618 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
619 samplingWindow.tofile(fp)
619 samplingWindow.tofile(fp)
620
620
621 if self.totalSpectra != 0:
621 if self.totalSpectra != 0:
622 # spectraComb = numpy.array([],numpy.dtype('u1'))
622 # spectraComb = numpy.array([],numpy.dtype('u1'))
623 spectraComb = self.spectraComb
623 spectraComb = self.spectraComb
624 spectraComb.tofile(fp)
624 spectraComb.tofile(fp)
625
625
626 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
626 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
627 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
627 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
628 # nCode.tofile(fp)
628 # nCode.tofile(fp)
629 #
629 #
630 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
630 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
631 # nBaud.tofile(fp)
631 # nBaud.tofile(fp)
632 #
632 #
633 # code = self.code.reshape(self.nCode*self.nBaud)
633 # code = self.code.reshape(self.nCode*self.nBaud)
634 # code = code.astype(numpy.dtype('<f4'))
634 # code = code.astype(numpy.dtype('<f4'))
635 # code.tofile(fp)
635 # code.tofile(fp)
636
636
637 return 1
637 return 1
638
638
639 def get_size(self):
639 def get_size(self):
640
640
641 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
641 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
642
642
643 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
643 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
644 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
644 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
645 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
645 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
646
646
647 return self.__size
647 return self.__size
648
648
649 def set_size(self, value):
649 def set_size(self, value):
650
650
651 raise IOError, "size is a property and it cannot be set, just read"
651 raise IOError, "size is a property and it cannot be set, just read"
652
652
653 return
653 return
654
654
655 size = property(get_size, set_size)
655 size = property(get_size, set_size)
656
656
657 class RCfunction:
657 class RCfunction:
658 NONE=0
658 NONE=0
659 FLIP=1
659 FLIP=1
660 CODE=2
660 CODE=2
661 SAMPLING=3
661 SAMPLING=3
662 LIN6DIV256=4
662 LIN6DIV256=4
663 SYNCHRO=5
663 SYNCHRO=5
664
664
665 class nCodeType:
665 class nCodeType:
666 NONE=0
666 NONE=0
667 USERDEFINE=1
667 USERDEFINE=1
668 BARKER2=2
668 BARKER2=2
669 BARKER3=3
669 BARKER3=3
670 BARKER4=4
670 BARKER4=4
671 BARKER5=5
671 BARKER5=5
672 BARKER7=6
672 BARKER7=6
673 BARKER11=7
673 BARKER11=7
674 BARKER13=8
674 BARKER13=8
675 AC128=9
675 AC128=9
676 COMPLEMENTARYCODE2=10
676 COMPLEMENTARYCODE2=10
677 COMPLEMENTARYCODE4=11
677 COMPLEMENTARYCODE4=11
678 COMPLEMENTARYCODE8=12
678 COMPLEMENTARYCODE8=12
679 COMPLEMENTARYCODE16=13
679 COMPLEMENTARYCODE16=13
680 COMPLEMENTARYCODE32=14
680 COMPLEMENTARYCODE32=14
681 COMPLEMENTARYCODE64=15
681 COMPLEMENTARYCODE64=15
682 COMPLEMENTARYCODE128=16
682 COMPLEMENTARYCODE128=16
683 CODE_BINARY28=17
683 CODE_BINARY28=17
684
684
685 class PROCFLAG:
685 class PROCFLAG:
686
686
687 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
687 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
688 DECODE_DATA = numpy.uint32(0x00000002)
688 DECODE_DATA = numpy.uint32(0x00000002)
689 SPECTRA_CALC = numpy.uint32(0x00000004)
689 SPECTRA_CALC = numpy.uint32(0x00000004)
690 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
690 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
691 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
691 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
692 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
692 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
693
693
694 DATATYPE_CHAR = numpy.uint32(0x00000040)
694 DATATYPE_CHAR = numpy.uint32(0x00000040)
695 DATATYPE_SHORT = numpy.uint32(0x00000080)
695 DATATYPE_SHORT = numpy.uint32(0x00000080)
696 DATATYPE_LONG = numpy.uint32(0x00000100)
696 DATATYPE_LONG = numpy.uint32(0x00000100)
697 DATATYPE_INT64 = numpy.uint32(0x00000200)
697 DATATYPE_INT64 = numpy.uint32(0x00000200)
698 DATATYPE_FLOAT = numpy.uint32(0x00000400)
698 DATATYPE_FLOAT = numpy.uint32(0x00000400)
699 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
699 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
700
700
701 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
701 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
702 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
702 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
703 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
703 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
704
704
705 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
705 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
706 DEFLIP_DATA = numpy.uint32(0x00010000)
706 DEFLIP_DATA = numpy.uint32(0x00010000)
707 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
707 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
708
708
709 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
709 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
710 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
710 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
711 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
711 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
712 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
712 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
713 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
713 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
714
714
715 EXP_NAME_ESP = numpy.uint32(0x00200000)
715 EXP_NAME_ESP = numpy.uint32(0x00200000)
716 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
716 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
717
717
718 OPERATION_MASK = numpy.uint32(0x0000003F)
718 OPERATION_MASK = numpy.uint32(0x0000003F)
719 DATATYPE_MASK = numpy.uint32(0x00000FC0)
719 DATATYPE_MASK = numpy.uint32(0x00000FC0)
720 DATAARRANGE_MASK = numpy.uint32(0x00007000)
720 DATAARRANGE_MASK = numpy.uint32(0x00007000)
721 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
721 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
722
722
723 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
723 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
724 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
724 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
725 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
725 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
726 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
726 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
727 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
727 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
728 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
728 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
729
729
730 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
730 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
731
731
732 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
732 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
733 PROCFLAG.DATATYPE_SHORT,
733 PROCFLAG.DATATYPE_SHORT,
734 PROCFLAG.DATATYPE_LONG,
734 PROCFLAG.DATATYPE_LONG,
735 PROCFLAG.DATATYPE_INT64,
735 PROCFLAG.DATATYPE_INT64,
736 PROCFLAG.DATATYPE_FLOAT,
736 PROCFLAG.DATATYPE_FLOAT,
737 PROCFLAG.DATATYPE_DOUBLE]
737 PROCFLAG.DATATYPE_DOUBLE]
738
738
739 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
739 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
740
740
741 def get_dtype_index(numpy_dtype):
741 def get_dtype_index(numpy_dtype):
742
742
743 index = None
743 index = None
744
744
745 for i in range(len(NUMPY_DTYPE_LIST)):
745 for i in range(len(NUMPY_DTYPE_LIST)):
746 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
746 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
747 index = i
747 index = i
748 break
748 break
749
749
750 return index
750 return index
751
751
752 def get_numpy_dtype(index):
752 def get_numpy_dtype(index):
753
753
754 return NUMPY_DTYPE_LIST[index]
754 return NUMPY_DTYPE_LIST[index]
755
755
756 def get_procflag_dtype(index):
756 def get_procflag_dtype(index):
757
757
758 return PROCFLAG_DTYPE_LIST[index]
758 return PROCFLAG_DTYPE_LIST[index]
759
759
760 def get_dtype_width(index):
760 def get_dtype_width(index):
761
761
762 return DTYPE_WIDTH[index] No newline at end of file
762 return DTYPE_WIDTH[index]
@@ -1,2155 +1,2160
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import inspect
4 import inspect
5 from figure import Figure, isRealtime, isTimeInHourRange
5 from figure import Figure, isRealtime, isTimeInHourRange
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8
8
9 class FitGauPlot(Figure):
9 class FitGauPlot(Figure):
10
10
11 isConfig = None
11 isConfig = None
12 __nsubplots = None
12 __nsubplots = None
13
13
14 WIDTHPROF = None
14 WIDTHPROF = None
15 HEIGHTPROF = None
15 HEIGHTPROF = None
16 PREFIX = 'fitgau'
16 PREFIX = 'fitgau'
17
17
18 def __init__(self, **kwargs):
18 def __init__(self, **kwargs):
19 Figure.__init__(self, **kwargs)
19 Figure.__init__(self, **kwargs)
20 self.isConfig = False
20 self.isConfig = False
21 self.__nsubplots = 1
21 self.__nsubplots = 1
22
22
23 self.WIDTH = 250
23 self.WIDTH = 250
24 self.HEIGHT = 250
24 self.HEIGHT = 250
25 self.WIDTHPROF = 120
25 self.WIDTHPROF = 120
26 self.HEIGHTPROF = 0
26 self.HEIGHTPROF = 0
27 self.counter_imagwr = 0
27 self.counter_imagwr = 0
28
28
29 self.PLOT_CODE = SPEC_CODE
29 self.PLOT_CODE = SPEC_CODE
30
30
31 self.FTP_WEI = None
31 self.FTP_WEI = None
32 self.EXP_CODE = None
32 self.EXP_CODE = None
33 self.SUB_EXP_CODE = None
33 self.SUB_EXP_CODE = None
34 self.PLOT_POS = None
34 self.PLOT_POS = None
35
35
36 self.__xfilter_ena = False
36 self.__xfilter_ena = False
37 self.__yfilter_ena = False
37 self.__yfilter_ena = False
38
38
39 def getSubplots(self):
39 def getSubplots(self):
40
40
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
41 ncol = int(numpy.sqrt(self.nplots)+0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
42 nrow = int(self.nplots*1./ncol + 0.9)
43
43
44 return nrow, ncol
44 return nrow, ncol
45
45
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
46 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
47
47
48 self.__showprofile = showprofile
48 self.__showprofile = showprofile
49 self.nplots = nplots
49 self.nplots = nplots
50
50
51 ncolspan = 1
51 ncolspan = 1
52 colspan = 1
52 colspan = 1
53 if showprofile:
53 if showprofile:
54 ncolspan = 3
54 ncolspan = 3
55 colspan = 2
55 colspan = 2
56 self.__nsubplots = 2
56 self.__nsubplots = 2
57
57
58 self.createFigure(id = id,
58 self.createFigure(id = id,
59 wintitle = wintitle,
59 wintitle = wintitle,
60 widthplot = self.WIDTH + self.WIDTHPROF,
60 widthplot = self.WIDTH + self.WIDTHPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 heightplot = self.HEIGHT + self.HEIGHTPROF,
62 show=show)
62 show=show)
63
63
64 nrow, ncol = self.getSubplots()
64 nrow, ncol = self.getSubplots()
65
65
66 counter = 0
66 counter = 0
67 for y in range(nrow):
67 for y in range(nrow):
68 for x in range(ncol):
68 for x in range(ncol):
69
69
70 if counter >= self.nplots:
70 if counter >= self.nplots:
71 break
71 break
72
72
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
74
74
75 if showprofile:
75 if showprofile:
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
77
77
78 counter += 1
78 counter += 1
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
80 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
82 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 0):
85 xaxis="frequency", colormap='jet', normFactor=None , GauSelector = 0):
86
86
87 """
87 """
88
88
89 Input:
89 Input:
90 dataOut :
90 dataOut :
91 id :
91 id :
92 wintitle :
92 wintitle :
93 channelList :
93 channelList :
94 showProfile :
94 showProfile :
95 xmin : None,
95 xmin : None,
96 xmax : None,
96 xmax : None,
97 ymin : None,
97 ymin : None,
98 ymax : None,
98 ymax : None,
99 zmin : None,
99 zmin : None,
100 zmax : None
100 zmax : None
101 """
101 """
102 if realtime:
102 if realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print 'Skipping this plot function'
104 print 'Skipping this plot function'
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
113 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # if normFactor is None:
116 # if normFactor is None:
117 # factor = dataOut.normFactor
117 # factor = dataOut.normFactor
118 # else:
118 # else:
119 # factor = normFactor
119 # factor = normFactor
120 if xaxis == "frequency":
120 if xaxis == "frequency":
121 x = dataOut.spc_range[0]
121 x = dataOut.spc_range[0]
122 xlabel = "Frequency (kHz)"
122 xlabel = "Frequency (kHz)"
123
123
124 elif xaxis == "time":
124 elif xaxis == "time":
125 x = dataOut.spc_range[1]
125 x = dataOut.spc_range[1]
126 xlabel = "Time (ms)"
126 xlabel = "Time (ms)"
127
127
128 else:
128 else:
129 x = dataOut.spc_range[2]
129 x = dataOut.spc_range[2]
130 xlabel = "Velocity (m/s)"
130 xlabel = "Velocity (m/s)"
131
131
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 y = dataOut.getHeiRange()
134 y = dataOut.getHeiRange()
135
135
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
136 z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor
137 print 'GausSPC', z[0,32,10:40]
137 print 'GausSPC', z[0,32,10:40]
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
138 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
139 zdB = 10*numpy.log10(z)
139 zdB = 10*numpy.log10(z)
140
140
141 avg = numpy.average(z, axis=1)
141 avg = numpy.average(z, axis=1)
142 avgdB = 10*numpy.log10(avg)
142 avgdB = 10*numpy.log10(avg)
143
143
144 noise = dataOut.spc_noise
144 noise = dataOut.spc_noise
145 noisedB = 10*numpy.log10(noise)
145 noisedB = 10*numpy.log10(noise)
146
146
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
147 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
148 title = wintitle + " Spectra"
148 title = wintitle + " Spectra"
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
149 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
150 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
151
151
152 if not self.isConfig:
152 if not self.isConfig:
153
153
154 nplots = len(channelIndexList)
154 nplots = len(channelIndexList)
155
155
156 self.setup(id=id,
156 self.setup(id=id,
157 nplots=nplots,
157 nplots=nplots,
158 wintitle=wintitle,
158 wintitle=wintitle,
159 showprofile=showprofile,
159 showprofile=showprofile,
160 show=show)
160 show=show)
161
161
162 if xmin == None: xmin = numpy.nanmin(x)
162 if xmin == None: xmin = numpy.nanmin(x)
163 if xmax == None: xmax = numpy.nanmax(x)
163 if xmax == None: xmax = numpy.nanmax(x)
164 if ymin == None: ymin = numpy.nanmin(y)
164 if ymin == None: ymin = numpy.nanmin(y)
165 if ymax == None: ymax = numpy.nanmax(y)
165 if ymax == None: ymax = numpy.nanmax(y)
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
166 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
167 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
168
168
169 self.FTP_WEI = ftp_wei
169 self.FTP_WEI = ftp_wei
170 self.EXP_CODE = exp_code
170 self.EXP_CODE = exp_code
171 self.SUB_EXP_CODE = sub_exp_code
171 self.SUB_EXP_CODE = sub_exp_code
172 self.PLOT_POS = plot_pos
172 self.PLOT_POS = plot_pos
173
173
174 self.isConfig = True
174 self.isConfig = True
175
175
176 self.setWinTitle(title)
176 self.setWinTitle(title)
177
177
178 for i in range(self.nplots):
178 for i in range(self.nplots):
179 index = channelIndexList[i]
179 index = channelIndexList[i]
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
180 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
181 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
182 if len(dataOut.beam.codeList) != 0:
182 if len(dataOut.beam.codeList) != 0:
183 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
183 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
184
184
185 axes = self.axesList[i*self.__nsubplots]
185 axes = self.axesList[i*self.__nsubplots]
186 axes.pcolor(x, y, zdB[index,:,:],
186 axes.pcolor(x, y, zdB[index,:,:],
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
187 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
188 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
189 ticksize=9, cblabel='')
189 ticksize=9, cblabel='')
190
190
191 if self.__showprofile:
191 if self.__showprofile:
192 axes = self.axesList[i*self.__nsubplots +1]
192 axes = self.axesList[i*self.__nsubplots +1]
193 axes.pline(avgdB[index,:], y,
193 axes.pline(avgdB[index,:], y,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
194 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
195 xlabel='dB', ylabel='', title='',
195 xlabel='dB', ylabel='', title='',
196 ytick_visible=False,
196 ytick_visible=False,
197 grid='x')
197 grid='x')
198
198
199 noiseline = numpy.repeat(noisedB[index], len(y))
199 noiseline = numpy.repeat(noisedB[index], len(y))
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
200 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
201
201
202 self.draw()
202 self.draw()
203
203
204 if figfile == None:
204 if figfile == None:
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
205 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
206 name = str_datetime
206 name = str_datetime
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
207 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
208 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
209 figfile = self.getFilename(name)
209 figfile = self.getFilename(name)
210
210
211 self.save(figpath=figpath,
211 self.save(figpath=figpath,
212 figfile=figfile,
212 figfile=figfile,
213 save=save,
213 save=save,
214 ftp=ftp,
214 ftp=ftp,
215 wr_period=wr_period,
215 wr_period=wr_period,
216 thisDatetime=thisDatetime)
216 thisDatetime=thisDatetime)
217
217
218
218
219
219
220 class MomentsPlot(Figure):
220 class MomentsPlot(Figure):
221
221
222 isConfig = None
222 isConfig = None
223 __nsubplots = None
223 __nsubplots = None
224
224
225 WIDTHPROF = None
225 WIDTHPROF = None
226 HEIGHTPROF = None
226 HEIGHTPROF = None
227 PREFIX = 'prm'
227 PREFIX = 'prm'
228
228
229 def __init__(self, **kwargs):
229 def __init__(self, **kwargs):
230 Figure.__init__(self, **kwargs)
230 Figure.__init__(self, **kwargs)
231 self.isConfig = False
231 self.isConfig = False
232 self.__nsubplots = 1
232 self.__nsubplots = 1
233
233
234 self.WIDTH = 280
234 self.WIDTH = 280
235 self.HEIGHT = 250
235 self.HEIGHT = 250
236 self.WIDTHPROF = 120
236 self.WIDTHPROF = 120
237 self.HEIGHTPROF = 0
237 self.HEIGHTPROF = 0
238 self.counter_imagwr = 0
238 self.counter_imagwr = 0
239
239
240 self.PLOT_CODE = MOMENTS_CODE
240 self.PLOT_CODE = MOMENTS_CODE
241
241
242 self.FTP_WEI = None
242 self.FTP_WEI = None
243 self.EXP_CODE = None
243 self.EXP_CODE = None
244 self.SUB_EXP_CODE = None
244 self.SUB_EXP_CODE = None
245 self.PLOT_POS = None
245 self.PLOT_POS = None
246
246
247 def getSubplots(self):
247 def getSubplots(self):
248
248
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
249 ncol = int(numpy.sqrt(self.nplots)+0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
250 nrow = int(self.nplots*1./ncol + 0.9)
251
251
252 return nrow, ncol
252 return nrow, ncol
253
253
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
255
255
256 self.__showprofile = showprofile
256 self.__showprofile = showprofile
257 self.nplots = nplots
257 self.nplots = nplots
258
258
259 ncolspan = 1
259 ncolspan = 1
260 colspan = 1
260 colspan = 1
261 if showprofile:
261 if showprofile:
262 ncolspan = 3
262 ncolspan = 3
263 colspan = 2
263 colspan = 2
264 self.__nsubplots = 2
264 self.__nsubplots = 2
265
265
266 self.createFigure(id = id,
266 self.createFigure(id = id,
267 wintitle = wintitle,
267 wintitle = wintitle,
268 widthplot = self.WIDTH + self.WIDTHPROF,
268 widthplot = self.WIDTH + self.WIDTHPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
269 heightplot = self.HEIGHT + self.HEIGHTPROF,
270 show=show)
270 show=show)
271
271
272 nrow, ncol = self.getSubplots()
272 nrow, ncol = self.getSubplots()
273
273
274 counter = 0
274 counter = 0
275 for y in range(nrow):
275 for y in range(nrow):
276 for x in range(ncol):
276 for x in range(ncol):
277
277
278 if counter >= self.nplots:
278 if counter >= self.nplots:
279 break
279 break
280
280
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
281 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
282
282
283 if showprofile:
283 if showprofile:
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
284 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
285
285
286 counter += 1
286 counter += 1
287
287
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
288 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
289 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
290 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
291 server=None, folder=None, username=None, password=None,
291 server=None, folder=None, username=None, password=None,
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
292 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
293
293
294 """
294 """
295
295
296 Input:
296 Input:
297 dataOut :
297 dataOut :
298 id :
298 id :
299 wintitle :
299 wintitle :
300 channelList :
300 channelList :
301 showProfile :
301 showProfile :
302 xmin : None,
302 xmin : None,
303 xmax : None,
303 xmax : None,
304 ymin : None,
304 ymin : None,
305 ymax : None,
305 ymax : None,
306 zmin : None,
306 zmin : None,
307 zmax : None
307 zmax : None
308 """
308 """
309
309
310 if dataOut.flagNoData:
310 if dataOut.flagNoData:
311 return None
311 return None
312
312
313 if realtime:
313 if realtime:
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
314 if not(isRealtime(utcdatatime = dataOut.utctime)):
315 print 'Skipping this plot function'
315 print 'Skipping this plot function'
316 return
316 return
317
317
318 if channelList == None:
318 if channelList == None:
319 channelIndexList = dataOut.channelIndexList
319 channelIndexList = dataOut.channelIndexList
320 else:
320 else:
321 channelIndexList = []
321 channelIndexList = []
322 for channel in channelList:
322 for channel in channelList:
323 if channel not in dataOut.channelList:
323 if channel not in dataOut.channelList:
324 raise ValueError, "Channel %d is not in dataOut.channelList"
324 raise ValueError, "Channel %d is not in dataOut.channelList"
325 channelIndexList.append(dataOut.channelList.index(channel))
325 channelIndexList.append(dataOut.channelList.index(channel))
326
326
327 factor = dataOut.normFactor
327 factor = dataOut.normFactor
328 x = dataOut.abscissaList
328 x = dataOut.abscissaList
329 y = dataOut.heightList
329 y = dataOut.heightList
330
330
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
331 z = dataOut.data_pre[channelIndexList,:,:]/factor
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
332 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
333 avg = numpy.average(z, axis=1)
333 avg = numpy.average(z, axis=1)
334 noise = dataOut.noise/factor
334 noise = dataOut.noise/factor
335
335
336 zdB = 10*numpy.log10(z)
336 zdB = 10*numpy.log10(z)
337 avgdB = 10*numpy.log10(avg)
337 avgdB = 10*numpy.log10(avg)
338 noisedB = 10*numpy.log10(noise)
338 noisedB = 10*numpy.log10(noise)
339
339
340 #thisDatetime = dataOut.datatime
340 #thisDatetime = dataOut.datatime
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
341 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
342 title = wintitle + " Parameters"
342 title = wintitle + " Parameters"
343 xlabel = "Velocity (m/s)"
343 xlabel = "Velocity (m/s)"
344 ylabel = "Range (Km)"
344 ylabel = "Range (Km)"
345
345
346 update_figfile = False
346 update_figfile = False
347
347
348 if not self.isConfig:
348 if not self.isConfig:
349
349
350 nplots = len(channelIndexList)
350 nplots = len(channelIndexList)
351
351
352 self.setup(id=id,
352 self.setup(id=id,
353 nplots=nplots,
353 nplots=nplots,
354 wintitle=wintitle,
354 wintitle=wintitle,
355 showprofile=showprofile,
355 showprofile=showprofile,
356 show=show)
356 show=show)
357
357
358 if xmin == None: xmin = numpy.nanmin(x)
358 if xmin == None: xmin = numpy.nanmin(x)
359 if xmax == None: xmax = numpy.nanmax(x)
359 if xmax == None: xmax = numpy.nanmax(x)
360 if ymin == None: ymin = numpy.nanmin(y)
360 if ymin == None: ymin = numpy.nanmin(y)
361 if ymax == None: ymax = numpy.nanmax(y)
361 if ymax == None: ymax = numpy.nanmax(y)
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
362 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
363 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
364
364
365 self.FTP_WEI = ftp_wei
365 self.FTP_WEI = ftp_wei
366 self.EXP_CODE = exp_code
366 self.EXP_CODE = exp_code
367 self.SUB_EXP_CODE = sub_exp_code
367 self.SUB_EXP_CODE = sub_exp_code
368 self.PLOT_POS = plot_pos
368 self.PLOT_POS = plot_pos
369
369
370 self.isConfig = True
370 self.isConfig = True
371 update_figfile = True
371 update_figfile = True
372
372
373 self.setWinTitle(title)
373 self.setWinTitle(title)
374
374
375 for i in range(self.nplots):
375 for i in range(self.nplots):
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
376 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
377 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime)
378 axes = self.axesList[i*self.__nsubplots]
378 axes = self.axesList[i*self.__nsubplots]
379 axes.pcolor(x, y, zdB[i,:,:],
379 axes.pcolor(x, y, zdB[i,:,:],
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
380 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
381 xlabel=xlabel, ylabel=ylabel, title=title,
381 xlabel=xlabel, ylabel=ylabel, title=title,
382 ticksize=9, cblabel='')
382 ticksize=9, cblabel='')
383 #Mean Line
383 #Mean Line
384 mean = dataOut.data_param[i, 1, :]
384 mean = dataOut.data_param[i, 1, :]
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
385 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
386
386
387 if self.__showprofile:
387 if self.__showprofile:
388 axes = self.axesList[i*self.__nsubplots +1]
388 axes = self.axesList[i*self.__nsubplots +1]
389 axes.pline(avgdB[i], y,
389 axes.pline(avgdB[i], y,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
390 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
391 xlabel='dB', ylabel='', title='',
391 xlabel='dB', ylabel='', title='',
392 ytick_visible=False,
392 ytick_visible=False,
393 grid='x')
393 grid='x')
394
394
395 noiseline = numpy.repeat(noisedB[i], len(y))
395 noiseline = numpy.repeat(noisedB[i], len(y))
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
396 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
397
397
398 self.draw()
398 self.draw()
399
399
400 self.save(figpath=figpath,
400 self.save(figpath=figpath,
401 figfile=figfile,
401 figfile=figfile,
402 save=save,
402 save=save,
403 ftp=ftp,
403 ftp=ftp,
404 wr_period=wr_period,
404 wr_period=wr_period,
405 thisDatetime=thisDatetime)
405 thisDatetime=thisDatetime)
406
406
407
407
408
408
409 class SkyMapPlot(Figure):
409 class SkyMapPlot(Figure):
410
410
411 __isConfig = None
411 __isConfig = None
412 __nsubplots = None
412 __nsubplots = None
413
413
414 WIDTHPROF = None
414 WIDTHPROF = None
415 HEIGHTPROF = None
415 HEIGHTPROF = None
416 PREFIX = 'mmap'
416 PREFIX = 'mmap'
417
417
418 def __init__(self, **kwargs):
418 def __init__(self, **kwargs):
419 Figure.__init__(self, **kwargs)
419 Figure.__init__(self, **kwargs)
420 self.isConfig = False
420 self.isConfig = False
421 self.__nsubplots = 1
421 self.__nsubplots = 1
422
422
423 # self.WIDTH = 280
423 # self.WIDTH = 280
424 # self.HEIGHT = 250
424 # self.HEIGHT = 250
425 self.WIDTH = 600
425 self.WIDTH = 600
426 self.HEIGHT = 600
426 self.HEIGHT = 600
427 self.WIDTHPROF = 120
427 self.WIDTHPROF = 120
428 self.HEIGHTPROF = 0
428 self.HEIGHTPROF = 0
429 self.counter_imagwr = 0
429 self.counter_imagwr = 0
430
430
431 self.PLOT_CODE = MSKYMAP_CODE
431 self.PLOT_CODE = MSKYMAP_CODE
432
432
433 self.FTP_WEI = None
433 self.FTP_WEI = None
434 self.EXP_CODE = None
434 self.EXP_CODE = None
435 self.SUB_EXP_CODE = None
435 self.SUB_EXP_CODE = None
436 self.PLOT_POS = None
436 self.PLOT_POS = None
437
437
438 def getSubplots(self):
438 def getSubplots(self):
439
439
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
440 ncol = int(numpy.sqrt(self.nplots)+0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
441 nrow = int(self.nplots*1./ncol + 0.9)
442
442
443 return nrow, ncol
443 return nrow, ncol
444
444
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
445 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
446
446
447 self.__showprofile = showprofile
447 self.__showprofile = showprofile
448 self.nplots = nplots
448 self.nplots = nplots
449
449
450 ncolspan = 1
450 ncolspan = 1
451 colspan = 1
451 colspan = 1
452
452
453 self.createFigure(id = id,
453 self.createFigure(id = id,
454 wintitle = wintitle,
454 wintitle = wintitle,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
455 widthplot = self.WIDTH, #+ self.WIDTHPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
456 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
457 show=show)
457 show=show)
458
458
459 nrow, ncol = 1,1
459 nrow, ncol = 1,1
460 counter = 0
460 counter = 0
461 x = 0
461 x = 0
462 y = 0
462 y = 0
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
463 self.addAxes(1, 1, 0, 0, 1, 1, True)
464
464
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
465 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
466 tmin=0, tmax=24, timerange=None,
466 tmin=0, tmax=24, timerange=None,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
468 server=None, folder=None, username=None, password=None,
468 server=None, folder=None, username=None, password=None,
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
470
470
471 """
471 """
472
472
473 Input:
473 Input:
474 dataOut :
474 dataOut :
475 id :
475 id :
476 wintitle :
476 wintitle :
477 channelList :
477 channelList :
478 showProfile :
478 showProfile :
479 xmin : None,
479 xmin : None,
480 xmax : None,
480 xmax : None,
481 ymin : None,
481 ymin : None,
482 ymax : None,
482 ymax : None,
483 zmin : None,
483 zmin : None,
484 zmax : None
484 zmax : None
485 """
485 """
486
486
487 arrayParameters = dataOut.data_param
487 arrayParameters = dataOut.data_param
488 error = arrayParameters[:,-1]
488 error = arrayParameters[:,-1]
489 indValid = numpy.where(error == 0)[0]
489 indValid = numpy.where(error == 0)[0]
490 finalMeteor = arrayParameters[indValid,:]
490 finalMeteor = arrayParameters[indValid,:]
491 finalAzimuth = finalMeteor[:,3]
491 finalAzimuth = finalMeteor[:,3]
492 finalZenith = finalMeteor[:,4]
492 finalZenith = finalMeteor[:,4]
493
493
494 x = finalAzimuth*numpy.pi/180
494 x = finalAzimuth*numpy.pi/180
495 y = finalZenith
495 y = finalZenith
496 x1 = [dataOut.ltctime, dataOut.ltctime]
496 x1 = [dataOut.ltctime, dataOut.ltctime]
497
497
498 #thisDatetime = dataOut.datatime
498 #thisDatetime = dataOut.datatime
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
499 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
500 title = wintitle + " Parameters"
500 title = wintitle + " Parameters"
501 xlabel = "Zonal Zenith Angle (deg) "
501 xlabel = "Zonal Zenith Angle (deg) "
502 ylabel = "Meridional Zenith Angle (deg)"
502 ylabel = "Meridional Zenith Angle (deg)"
503 update_figfile = False
503 update_figfile = False
504
504
505 if not self.isConfig:
505 if not self.isConfig:
506
506
507 nplots = 1
507 nplots = 1
508
508
509 self.setup(id=id,
509 self.setup(id=id,
510 nplots=nplots,
510 nplots=nplots,
511 wintitle=wintitle,
511 wintitle=wintitle,
512 showprofile=showprofile,
512 showprofile=showprofile,
513 show=show)
513 show=show)
514
514
515 if self.xmin is None and self.xmax is None:
515 if self.xmin is None and self.xmax is None:
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
516 self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange)
517
517
518 if timerange != None:
518 if timerange != None:
519 self.timerange = timerange
519 self.timerange = timerange
520 else:
520 else:
521 self.timerange = self.xmax - self.xmin
521 self.timerange = self.xmax - self.xmin
522
522
523 self.FTP_WEI = ftp_wei
523 self.FTP_WEI = ftp_wei
524 self.EXP_CODE = exp_code
524 self.EXP_CODE = exp_code
525 self.SUB_EXP_CODE = sub_exp_code
525 self.SUB_EXP_CODE = sub_exp_code
526 self.PLOT_POS = plot_pos
526 self.PLOT_POS = plot_pos
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
527 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
528 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
529 self.isConfig = True
529 self.isConfig = True
530 update_figfile = True
530 update_figfile = True
531
531
532 self.setWinTitle(title)
532 self.setWinTitle(title)
533
533
534 i = 0
534 i = 0
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
535 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
536
536
537 axes = self.axesList[i*self.__nsubplots]
537 axes = self.axesList[i*self.__nsubplots]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
538 nevents = axes.x_buffer.shape[0] + x.shape[0]
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
539 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
540 axes.polar(x, y,
540 axes.polar(x, y,
541 title=title, xlabel=xlabel, ylabel=ylabel,
541 title=title, xlabel=xlabel, ylabel=ylabel,
542 ticksize=9, cblabel='')
542 ticksize=9, cblabel='')
543
543
544 self.draw()
544 self.draw()
545
545
546 self.save(figpath=figpath,
546 self.save(figpath=figpath,
547 figfile=figfile,
547 figfile=figfile,
548 save=save,
548 save=save,
549 ftp=ftp,
549 ftp=ftp,
550 wr_period=wr_period,
550 wr_period=wr_period,
551 thisDatetime=thisDatetime,
551 thisDatetime=thisDatetime,
552 update_figfile=update_figfile)
552 update_figfile=update_figfile)
553
553
554 if dataOut.ltctime >= self.xmax:
554 if dataOut.ltctime >= self.xmax:
555 self.isConfigmagwr = wr_period
555 self.isConfigmagwr = wr_period
556 self.isConfig = False
556 self.isConfig = False
557 update_figfile = True
557 update_figfile = True
558 axes.__firsttime = True
558 axes.__firsttime = True
559 self.xmin += self.timerange
559 self.xmin += self.timerange
560 self.xmax += self.timerange
560 self.xmax += self.timerange
561
561
562
562
563
563
564
564
565 class WindProfilerPlot(Figure):
565 class WindProfilerPlot(Figure):
566
566
567 __isConfig = None
567 __isConfig = None
568 __nsubplots = None
568 __nsubplots = None
569
569
570 WIDTHPROF = None
570 WIDTHPROF = None
571 HEIGHTPROF = None
571 HEIGHTPROF = None
572 PREFIX = 'wind'
572 PREFIX = 'wind'
573
573
574 def __init__(self, **kwargs):
574 def __init__(self, **kwargs):
575 Figure.__init__(self, **kwargs)
575 Figure.__init__(self, **kwargs)
576 self.timerange = None
576 self.timerange = None
577 self.isConfig = False
577 self.isConfig = False
578 self.__nsubplots = 1
578 self.__nsubplots = 1
579
579
580 self.WIDTH = 800
580 self.WIDTH = 800
581 self.HEIGHT = 300
581 self.HEIGHT = 300
582 self.WIDTHPROF = 120
582 self.WIDTHPROF = 120
583 self.HEIGHTPROF = 0
583 self.HEIGHTPROF = 0
584 self.counter_imagwr = 0
584 self.counter_imagwr = 0
585
585
586 self.PLOT_CODE = WIND_CODE
586 self.PLOT_CODE = WIND_CODE
587
587
588 self.FTP_WEI = None
588 self.FTP_WEI = None
589 self.EXP_CODE = None
589 self.EXP_CODE = None
590 self.SUB_EXP_CODE = None
590 self.SUB_EXP_CODE = None
591 self.PLOT_POS = None
591 self.PLOT_POS = None
592 self.tmin = None
592 self.tmin = None
593 self.tmax = None
593 self.tmax = None
594
594
595 self.xmin = None
595 self.xmin = None
596 self.xmax = None
596 self.xmax = None
597
597
598 self.figfile = None
598 self.figfile = None
599
599
600 def getSubplots(self):
600 def getSubplots(self):
601
601
602 ncol = 1
602 ncol = 1
603 nrow = self.nplots
603 nrow = self.nplots
604
604
605 return nrow, ncol
605 return nrow, ncol
606
606
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
607 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
608
608
609 self.__showprofile = showprofile
609 self.__showprofile = showprofile
610 self.nplots = nplots
610 self.nplots = nplots
611
611
612 ncolspan = 1
612 ncolspan = 1
613 colspan = 1
613 colspan = 1
614
614
615 self.createFigure(id = id,
615 self.createFigure(id = id,
616 wintitle = wintitle,
616 wintitle = wintitle,
617 widthplot = self.WIDTH + self.WIDTHPROF,
617 widthplot = self.WIDTH + self.WIDTHPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
618 heightplot = self.HEIGHT + self.HEIGHTPROF,
619 show=show)
619 show=show)
620
620
621 nrow, ncol = self.getSubplots()
621 nrow, ncol = self.getSubplots()
622
622
623 counter = 0
623 counter = 0
624 for y in range(nrow):
624 for y in range(nrow):
625 if counter >= self.nplots:
625 if counter >= self.nplots:
626 break
626 break
627
627
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
628 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
629 counter += 1
629 counter += 1
630
630
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
631 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
632 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
633 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
634 timerange=None, SNRthresh = None,
634 timerange=None, SNRthresh = None,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
635 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
636 server=None, folder=None, username=None, password=None,
636 server=None, folder=None, username=None, password=None,
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
637 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
638 """
638 """
639
639
640 Input:
640 Input:
641 dataOut :
641 dataOut :
642 id :
642 id :
643 wintitle :
643 wintitle :
644 channelList :
644 channelList :
645 showProfile :
645 showProfile :
646 xmin : None,
646 xmin : None,
647 xmax : None,
647 xmax : None,
648 ymin : None,
648 ymin : None,
649 ymax : None,
649 ymax : None,
650 zmin : None,
650 zmin : None,
651 zmax : None
651 zmax : None
652 """
652 """
653
653
654 # if timerange is not None:
654 # if timerange is not None:
655 # self.timerange = timerange
655 # self.timerange = timerange
656 #
656 #
657 # tmin = None
657 # tmin = None
658 # tmax = None
658 # tmax = None
659
659
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
660 x = dataOut.getTimeRange1(dataOut.paramInterval)
661 y = dataOut.heightList
661 y = dataOut.heightList
662 z = dataOut.data_output.copy()
662 z = dataOut.data_output.copy()
663 nplots = z.shape[0] #Number of wind dimensions estimated
663 nplots = z.shape[0] #Number of wind dimensions estimated
664 nplotsw = nplots
664 nplotsw = nplots
665
665
666
666
667 #If there is a SNR function defined
667 #If there is a SNR function defined
668 if dataOut.data_SNR is not None:
668 if dataOut.data_SNR is not None:
669 nplots += 1
669 nplots += 1
670 SNR = dataOut.data_SNR[0]
670 SNR = dataOut.data_SNR[0]
671 SNRavg = SNR#numpy.average(SNR, axis=0)
671 SNRavg = SNR#numpy.average(SNR, axis=0)
672
672
673 SNRdB = 10*numpy.log10(SNR)
673 SNRdB = 10*numpy.log10(SNR)
674 SNRavgdB = 10*numpy.log10(SNRavg)
674 SNRavgdB = 10*numpy.log10(SNRavg)
675
675
676 if SNRthresh == None:
676 if SNRthresh == None:
677 SNRthresh = -5.0
677 SNRthresh = -5.0
678 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
678 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
679
679
680 for i in range(nplotsw):
680 for i in range(nplotsw):
681 z[i,ind] = numpy.nan
681 z[i,ind] = numpy.nan
682
682
683 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
683 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
684 #thisDatetime = datetime.datetime.now()
684 #thisDatetime = datetime.datetime.now()
685 title = wintitle + "Wind"
685 title = wintitle + "Wind"
686 xlabel = ""
686 xlabel = ""
687 ylabel = "Height (km)"
687 ylabel = "Height (km)"
688 update_figfile = False
688 update_figfile = False
689
689
690 if not self.isConfig:
690 if not self.isConfig:
691
691
692 self.setup(id=id,
692 self.setup(id=id,
693 nplots=nplots,
693 nplots=nplots,
694 wintitle=wintitle,
694 wintitle=wintitle,
695 showprofile=showprofile,
695 showprofile=showprofile,
696 show=show)
696 show=show)
697
697
698 if timerange is not None:
698 if timerange is not None:
699 self.timerange = timerange
699 self.timerange = timerange
700
700
701 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
701 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
702
702
703 if ymin == None: ymin = numpy.nanmin(y)
703 if ymin == None: ymin = numpy.nanmin(y)
704 if ymax == None: ymax = numpy.nanmax(y)
704 if ymax == None: ymax = numpy.nanmax(y)
705
705
706 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
706 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
707 #if numpy.isnan(zmax): zmax = 50
707 #if numpy.isnan(zmax): zmax = 50
708 if zmin == None: zmin = -zmax
708 if zmin == None: zmin = -zmax
709
709
710 if nplotsw == 3:
710 if nplotsw == 3:
711 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
711 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
712 if zmin_ver == None: zmin_ver = -zmax_ver
712 if zmin_ver == None: zmin_ver = -zmax_ver
713
713
714 if dataOut.data_SNR is not None:
714 if dataOut.data_SNR is not None:
715 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
715 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
716 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
716 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
717
717
718
718
719 self.FTP_WEI = ftp_wei
719 self.FTP_WEI = ftp_wei
720 self.EXP_CODE = exp_code
720 self.EXP_CODE = exp_code
721 self.SUB_EXP_CODE = sub_exp_code
721 self.SUB_EXP_CODE = sub_exp_code
722 self.PLOT_POS = plot_pos
722 self.PLOT_POS = plot_pos
723
723
724 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
724 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
725 self.isConfig = True
725 self.isConfig = True
726 self.figfile = figfile
726 self.figfile = figfile
727 update_figfile = True
727 update_figfile = True
728
728
729 self.setWinTitle(title)
729 self.setWinTitle(title)
730
730
731 if ((self.xmax - x[1]) < (x[1]-x[0])):
731 if ((self.xmax - x[1]) < (x[1]-x[0])):
732 x[1] = self.xmax
732 x[1] = self.xmax
733
733
734 strWind = ['Zonal', 'Meridional', 'Vertical']
734 strWind = ['Zonal', 'Meridional', 'Vertical']
735 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
735 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
736 zmaxVector = [zmax, zmax, zmax_ver]
736 zmaxVector = [zmax, zmax, zmax_ver]
737 zminVector = [zmin, zmin, zmin_ver]
737 zminVector = [zmin, zmin, zmin_ver]
738 windFactor = [1,1,100]
738 windFactor = [1,1,100]
739
739
740 for i in range(nplotsw):
740 for i in range(nplotsw):
741
741
742 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
742 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
743 axes = self.axesList[i*self.__nsubplots]
743 axes = self.axesList[i*self.__nsubplots]
744
744
745 z1 = z[i,:].reshape((1,-1))*windFactor[i]
745 z1 = z[i,:].reshape((1,-1))*windFactor[i]
746
747 print 'x', x
748 print datetime.datetime.utcfromtimestamp(x[0])
749 print datetime.datetime.utcfromtimestamp(x[1])
750
746 #z1=numpy.ma.masked_where(z1==0.,z1)
751 #z1=numpy.ma.masked_where(z1==0.,z1)
747
752
748 axes.pcolorbuffer(x, y, z1,
753 axes.pcolorbuffer(x, y, z1,
749 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
754 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
750 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
755 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
751 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
756 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" )
752
757
753 if dataOut.data_SNR is not None:
758 if dataOut.data_SNR is not None:
754 i += 1
759 i += 1
755 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
760 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
756 axes = self.axesList[i*self.__nsubplots]
761 axes = self.axesList[i*self.__nsubplots]
757 SNRavgdB = SNRavgdB.reshape((1,-1))
762 SNRavgdB = SNRavgdB.reshape((1,-1))
758 axes.pcolorbuffer(x, y, SNRavgdB,
763 axes.pcolorbuffer(x, y, SNRavgdB,
759 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
764 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
760 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
765 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
761 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
766 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
762
767
763 self.draw()
768 self.draw()
764
769
765 self.save(figpath=figpath,
770 self.save(figpath=figpath,
766 figfile=figfile,
771 figfile=figfile,
767 save=save,
772 save=save,
768 ftp=ftp,
773 ftp=ftp,
769 wr_period=wr_period,
774 wr_period=wr_period,
770 thisDatetime=thisDatetime,
775 thisDatetime=thisDatetime,
771 update_figfile=update_figfile)
776 update_figfile=update_figfile)
772
777
773 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
778 if dataOut.ltctime + dataOut.paramInterval >= self.xmax:
774 self.counter_imagwr = wr_period
779 self.counter_imagwr = wr_period
775 self.isConfig = False
780 self.isConfig = False
776 update_figfile = True
781 update_figfile = True
777
782
778
783
779 class ParametersPlot(Figure):
784 class ParametersPlot(Figure):
780
785
781 __isConfig = None
786 __isConfig = None
782 __nsubplots = None
787 __nsubplots = None
783
788
784 WIDTHPROF = None
789 WIDTHPROF = None
785 HEIGHTPROF = None
790 HEIGHTPROF = None
786 PREFIX = 'param'
791 PREFIX = 'param'
787
792
788 nplots = None
793 nplots = None
789 nchan = None
794 nchan = None
790
795
791 def __init__(self, **kwargs):
796 def __init__(self, **kwargs):
792 Figure.__init__(self, **kwargs)
797 Figure.__init__(self, **kwargs)
793 self.timerange = None
798 self.timerange = None
794 self.isConfig = False
799 self.isConfig = False
795 self.__nsubplots = 1
800 self.__nsubplots = 1
796
801
797 self.WIDTH = 800
802 self.WIDTH = 800
798 self.HEIGHT = 180
803 self.HEIGHT = 180
799 self.WIDTHPROF = 120
804 self.WIDTHPROF = 120
800 self.HEIGHTPROF = 0
805 self.HEIGHTPROF = 0
801 self.counter_imagwr = 0
806 self.counter_imagwr = 0
802
807
803 self.PLOT_CODE = RTI_CODE
808 self.PLOT_CODE = RTI_CODE
804
809
805 self.FTP_WEI = None
810 self.FTP_WEI = None
806 self.EXP_CODE = None
811 self.EXP_CODE = None
807 self.SUB_EXP_CODE = None
812 self.SUB_EXP_CODE = None
808 self.PLOT_POS = None
813 self.PLOT_POS = None
809 self.tmin = None
814 self.tmin = None
810 self.tmax = None
815 self.tmax = None
811
816
812 self.xmin = None
817 self.xmin = None
813 self.xmax = None
818 self.xmax = None
814
819
815 self.figfile = None
820 self.figfile = None
816
821
817 def getSubplots(self):
822 def getSubplots(self):
818
823
819 ncol = 1
824 ncol = 1
820 nrow = self.nplots
825 nrow = self.nplots
821
826
822 return nrow, ncol
827 return nrow, ncol
823
828
824 def setup(self, id, nplots, wintitle, show=True):
829 def setup(self, id, nplots, wintitle, show=True):
825
830
826 self.nplots = nplots
831 self.nplots = nplots
827
832
828 ncolspan = 1
833 ncolspan = 1
829 colspan = 1
834 colspan = 1
830
835
831 self.createFigure(id = id,
836 self.createFigure(id = id,
832 wintitle = wintitle,
837 wintitle = wintitle,
833 widthplot = self.WIDTH + self.WIDTHPROF,
838 widthplot = self.WIDTH + self.WIDTHPROF,
834 heightplot = self.HEIGHT + self.HEIGHTPROF,
839 heightplot = self.HEIGHT + self.HEIGHTPROF,
835 show=show)
840 show=show)
836
841
837 nrow, ncol = self.getSubplots()
842 nrow, ncol = self.getSubplots()
838
843
839 counter = 0
844 counter = 0
840 for y in range(nrow):
845 for y in range(nrow):
841 for x in range(ncol):
846 for x in range(ncol):
842
847
843 if counter >= self.nplots:
848 if counter >= self.nplots:
844 break
849 break
845
850
846 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
851 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
847
852
848 counter += 1
853 counter += 1
849
854
850 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
855 def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet",
851 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
856 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None,
852 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
857 showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None,
853 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
858 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
854 server=None, folder=None, username=None, password=None,
859 server=None, folder=None, username=None, password=None,
855 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
860 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None):
856 """
861 """
857
862
858 Input:
863 Input:
859 dataOut :
864 dataOut :
860 id :
865 id :
861 wintitle :
866 wintitle :
862 channelList :
867 channelList :
863 showProfile :
868 showProfile :
864 xmin : None,
869 xmin : None,
865 xmax : None,
870 xmax : None,
866 ymin : None,
871 ymin : None,
867 ymax : None,
872 ymax : None,
868 zmin : None,
873 zmin : None,
869 zmax : None
874 zmax : None
870 """
875 """
871
876
872 if HEIGHT is not None:
877 if HEIGHT is not None:
873 self.HEIGHT = HEIGHT
878 self.HEIGHT = HEIGHT
874
879
875
880
876 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
881 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
877 return
882 return
878
883
879 if channelList == None:
884 if channelList == None:
880 channelIndexList = range(dataOut.data_param.shape[0])
885 channelIndexList = range(dataOut.data_param.shape[0])
881 else:
886 else:
882 channelIndexList = []
887 channelIndexList = []
883 for channel in channelList:
888 for channel in channelList:
884 if channel not in dataOut.channelList:
889 if channel not in dataOut.channelList:
885 raise ValueError, "Channel %d is not in dataOut.channelList"
890 raise ValueError, "Channel %d is not in dataOut.channelList"
886 channelIndexList.append(dataOut.channelList.index(channel))
891 channelIndexList.append(dataOut.channelList.index(channel))
887
892
888 x = dataOut.getTimeRange1(dataOut.paramInterval)
893 x = dataOut.getTimeRange1(dataOut.paramInterval)
889 y = dataOut.getHeiRange()
894 y = dataOut.getHeiRange()
890
895
891 if dataOut.data_param.ndim == 3:
896 if dataOut.data_param.ndim == 3:
892 z = dataOut.data_param[channelIndexList,paramIndex,:]
897 z = dataOut.data_param[channelIndexList,paramIndex,:]
893 else:
898 else:
894 z = dataOut.data_param[channelIndexList,:]
899 z = dataOut.data_param[channelIndexList,:]
895
900
896 if showSNR:
901 if showSNR:
897 #SNR data
902 #SNR data
898 SNRarray = dataOut.data_SNR[channelIndexList,:]
903 SNRarray = dataOut.data_SNR[channelIndexList,:]
899 SNRdB = 10*numpy.log10(SNRarray)
904 SNRdB = 10*numpy.log10(SNRarray)
900 ind = numpy.where(SNRdB < SNRthresh)
905 ind = numpy.where(SNRdB < SNRthresh)
901 z[ind] = numpy.nan
906 z[ind] = numpy.nan
902
907
903 thisDatetime = dataOut.datatime
908 thisDatetime = dataOut.datatime
904 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
909 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
905 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
910 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
906 xlabel = ""
911 xlabel = ""
907 ylabel = "Range (Km)"
912 ylabel = "Range (Km)"
908
913
909 update_figfile = False
914 update_figfile = False
910
915
911 if not self.isConfig:
916 if not self.isConfig:
912
917
913 nchan = len(channelIndexList)
918 nchan = len(channelIndexList)
914 self.nchan = nchan
919 self.nchan = nchan
915 self.plotFact = 1
920 self.plotFact = 1
916 nplots = nchan
921 nplots = nchan
917
922
918 if showSNR:
923 if showSNR:
919 nplots = nchan*2
924 nplots = nchan*2
920 self.plotFact = 2
925 self.plotFact = 2
921 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
926 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
922 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
927 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
923
928
924 self.setup(id=id,
929 self.setup(id=id,
925 nplots=nplots,
930 nplots=nplots,
926 wintitle=wintitle,
931 wintitle=wintitle,
927 show=show)
932 show=show)
928
933
929 if timerange != None:
934 if timerange != None:
930 self.timerange = timerange
935 self.timerange = timerange
931
936
932 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
937 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
933
938
934 if ymin == None: ymin = numpy.nanmin(y)
939 if ymin == None: ymin = numpy.nanmin(y)
935 if ymax == None: ymax = numpy.nanmax(y)
940 if ymax == None: ymax = numpy.nanmax(y)
936 if zmin == None: zmin = numpy.nanmin(z)
941 if zmin == None: zmin = numpy.nanmin(z)
937 if zmax == None: zmax = numpy.nanmax(z)
942 if zmax == None: zmax = numpy.nanmax(z)
938
943
939 self.FTP_WEI = ftp_wei
944 self.FTP_WEI = ftp_wei
940 self.EXP_CODE = exp_code
945 self.EXP_CODE = exp_code
941 self.SUB_EXP_CODE = sub_exp_code
946 self.SUB_EXP_CODE = sub_exp_code
942 self.PLOT_POS = plot_pos
947 self.PLOT_POS = plot_pos
943
948
944 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
949 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
945 self.isConfig = True
950 self.isConfig = True
946 self.figfile = figfile
951 self.figfile = figfile
947 update_figfile = True
952 update_figfile = True
948
953
949 self.setWinTitle(title)
954 self.setWinTitle(title)
950
955
951 for i in range(self.nchan):
956 for i in range(self.nchan):
952 index = channelIndexList[i]
957 index = channelIndexList[i]
953 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
958 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
954 axes = self.axesList[i*self.plotFact]
959 axes = self.axesList[i*self.plotFact]
955 z1 = z[i,:].reshape((1,-1))
960 z1 = z[i,:].reshape((1,-1))
956 axes.pcolorbuffer(x, y, z1,
961 axes.pcolorbuffer(x, y, z1,
957 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
962 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
958 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
963 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
959 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
964 ticksize=9, cblabel='', cbsize="1%",colormap=colormap)
960
965
961 if showSNR:
966 if showSNR:
962 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
967 title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
963 axes = self.axesList[i*self.plotFact + 1]
968 axes = self.axesList[i*self.plotFact + 1]
964 SNRdB1 = SNRdB[i,:].reshape((1,-1))
969 SNRdB1 = SNRdB[i,:].reshape((1,-1))
965 axes.pcolorbuffer(x, y, SNRdB1,
970 axes.pcolorbuffer(x, y, SNRdB1,
966 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
971 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
967 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
972 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
968 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
973 ticksize=9, cblabel='', cbsize="1%",colormap='jet')
969
974
970
975
971 self.draw()
976 self.draw()
972
977
973 if dataOut.ltctime >= self.xmax:
978 if dataOut.ltctime >= self.xmax:
974 self.counter_imagwr = wr_period
979 self.counter_imagwr = wr_period
975 self.isConfig = False
980 self.isConfig = False
976 update_figfile = True
981 update_figfile = True
977
982
978 self.save(figpath=figpath,
983 self.save(figpath=figpath,
979 figfile=figfile,
984 figfile=figfile,
980 save=save,
985 save=save,
981 ftp=ftp,
986 ftp=ftp,
982 wr_period=wr_period,
987 wr_period=wr_period,
983 thisDatetime=thisDatetime,
988 thisDatetime=thisDatetime,
984 update_figfile=update_figfile)
989 update_figfile=update_figfile)
985
990
986
991
987
992
988 class Parameters1Plot(Figure):
993 class Parameters1Plot(Figure):
989
994
990 __isConfig = None
995 __isConfig = None
991 __nsubplots = None
996 __nsubplots = None
992
997
993 WIDTHPROF = None
998 WIDTHPROF = None
994 HEIGHTPROF = None
999 HEIGHTPROF = None
995 PREFIX = 'prm'
1000 PREFIX = 'prm'
996
1001
997 def __init__(self, **kwargs):
1002 def __init__(self, **kwargs):
998 Figure.__init__(self, **kwargs)
1003 Figure.__init__(self, **kwargs)
999 self.timerange = 2*60*60
1004 self.timerange = 2*60*60
1000 self.isConfig = False
1005 self.isConfig = False
1001 self.__nsubplots = 1
1006 self.__nsubplots = 1
1002
1007
1003 self.WIDTH = 800
1008 self.WIDTH = 800
1004 self.HEIGHT = 180
1009 self.HEIGHT = 180
1005 self.WIDTHPROF = 120
1010 self.WIDTHPROF = 120
1006 self.HEIGHTPROF = 0
1011 self.HEIGHTPROF = 0
1007 self.counter_imagwr = 0
1012 self.counter_imagwr = 0
1008
1013
1009 self.PLOT_CODE = PARMS_CODE
1014 self.PLOT_CODE = PARMS_CODE
1010
1015
1011 self.FTP_WEI = None
1016 self.FTP_WEI = None
1012 self.EXP_CODE = None
1017 self.EXP_CODE = None
1013 self.SUB_EXP_CODE = None
1018 self.SUB_EXP_CODE = None
1014 self.PLOT_POS = None
1019 self.PLOT_POS = None
1015 self.tmin = None
1020 self.tmin = None
1016 self.tmax = None
1021 self.tmax = None
1017
1022
1018 self.xmin = None
1023 self.xmin = None
1019 self.xmax = None
1024 self.xmax = None
1020
1025
1021 self.figfile = None
1026 self.figfile = None
1022
1027
1023 def getSubplots(self):
1028 def getSubplots(self):
1024
1029
1025 ncol = 1
1030 ncol = 1
1026 nrow = self.nplots
1031 nrow = self.nplots
1027
1032
1028 return nrow, ncol
1033 return nrow, ncol
1029
1034
1030 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1035 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1031
1036
1032 self.__showprofile = showprofile
1037 self.__showprofile = showprofile
1033 self.nplots = nplots
1038 self.nplots = nplots
1034
1039
1035 ncolspan = 1
1040 ncolspan = 1
1036 colspan = 1
1041 colspan = 1
1037
1042
1038 self.createFigure(id = id,
1043 self.createFigure(id = id,
1039 wintitle = wintitle,
1044 wintitle = wintitle,
1040 widthplot = self.WIDTH + self.WIDTHPROF,
1045 widthplot = self.WIDTH + self.WIDTHPROF,
1041 heightplot = self.HEIGHT + self.HEIGHTPROF,
1046 heightplot = self.HEIGHT + self.HEIGHTPROF,
1042 show=show)
1047 show=show)
1043
1048
1044 nrow, ncol = self.getSubplots()
1049 nrow, ncol = self.getSubplots()
1045
1050
1046 counter = 0
1051 counter = 0
1047 for y in range(nrow):
1052 for y in range(nrow):
1048 for x in range(ncol):
1053 for x in range(ncol):
1049
1054
1050 if counter >= self.nplots:
1055 if counter >= self.nplots:
1051 break
1056 break
1052
1057
1053 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1058 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1054
1059
1055 if showprofile:
1060 if showprofile:
1056 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1061 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1057
1062
1058 counter += 1
1063 counter += 1
1059
1064
1060 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1065 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
1061 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1066 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
1062 parameterIndex = None, onlyPositive = False,
1067 parameterIndex = None, onlyPositive = False,
1063 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1068 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
1064 DOP = True,
1069 DOP = True,
1065 zlabel = "", parameterName = "", parameterObject = "data_param",
1070 zlabel = "", parameterName = "", parameterObject = "data_param",
1066 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1071 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1067 server=None, folder=None, username=None, password=None,
1072 server=None, folder=None, username=None, password=None,
1068 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1073 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1069 #print inspect.getargspec(self.run).args
1074 #print inspect.getargspec(self.run).args
1070 """
1075 """
1071
1076
1072 Input:
1077 Input:
1073 dataOut :
1078 dataOut :
1074 id :
1079 id :
1075 wintitle :
1080 wintitle :
1076 channelList :
1081 channelList :
1077 showProfile :
1082 showProfile :
1078 xmin : None,
1083 xmin : None,
1079 xmax : None,
1084 xmax : None,
1080 ymin : None,
1085 ymin : None,
1081 ymax : None,
1086 ymax : None,
1082 zmin : None,
1087 zmin : None,
1083 zmax : None
1088 zmax : None
1084 """
1089 """
1085
1090
1086 data_param = getattr(dataOut, parameterObject)
1091 data_param = getattr(dataOut, parameterObject)
1087
1092
1088 if channelList == None:
1093 if channelList == None:
1089 channelIndexList = numpy.arange(data_param.shape[0])
1094 channelIndexList = numpy.arange(data_param.shape[0])
1090 else:
1095 else:
1091 channelIndexList = numpy.array(channelList)
1096 channelIndexList = numpy.array(channelList)
1092
1097
1093 nchan = len(channelIndexList) #Number of channels being plotted
1098 nchan = len(channelIndexList) #Number of channels being plotted
1094
1099
1095 if nchan < 1:
1100 if nchan < 1:
1096 return
1101 return
1097
1102
1098 nGraphsByChannel = 0
1103 nGraphsByChannel = 0
1099
1104
1100 if SNR:
1105 if SNR:
1101 nGraphsByChannel += 1
1106 nGraphsByChannel += 1
1102 if DOP:
1107 if DOP:
1103 nGraphsByChannel += 1
1108 nGraphsByChannel += 1
1104
1109
1105 if nGraphsByChannel < 1:
1110 if nGraphsByChannel < 1:
1106 return
1111 return
1107
1112
1108 nplots = nGraphsByChannel*nchan
1113 nplots = nGraphsByChannel*nchan
1109
1114
1110 if timerange is not None:
1115 if timerange is not None:
1111 self.timerange = timerange
1116 self.timerange = timerange
1112
1117
1113 #tmin = None
1118 #tmin = None
1114 #tmax = None
1119 #tmax = None
1115 if parameterIndex == None:
1120 if parameterIndex == None:
1116 parameterIndex = 1
1121 parameterIndex = 1
1117
1122
1118 x = dataOut.getTimeRange1(dataOut.paramInterval)
1123 x = dataOut.getTimeRange1(dataOut.paramInterval)
1119 y = dataOut.heightList
1124 y = dataOut.heightList
1120 z = data_param[channelIndexList,parameterIndex,:].copy()
1125 z = data_param[channelIndexList,parameterIndex,:].copy()
1121
1126
1122 zRange = dataOut.abscissaList
1127 zRange = dataOut.abscissaList
1123 # nChannels = z.shape[0] #Number of wind dimensions estimated
1128 # nChannels = z.shape[0] #Number of wind dimensions estimated
1124 # thisDatetime = dataOut.datatime
1129 # thisDatetime = dataOut.datatime
1125
1130
1126 if dataOut.data_SNR is not None:
1131 if dataOut.data_SNR is not None:
1127 SNRarray = dataOut.data_SNR[channelIndexList,:]
1132 SNRarray = dataOut.data_SNR[channelIndexList,:]
1128 SNRdB = 10*numpy.log10(SNRarray)
1133 SNRdB = 10*numpy.log10(SNRarray)
1129 # SNRavgdB = 10*numpy.log10(SNRavg)
1134 # SNRavgdB = 10*numpy.log10(SNRavg)
1130 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1135 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
1131 z[ind] = numpy.nan
1136 z[ind] = numpy.nan
1132
1137
1133 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1138 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1134 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1139 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1135 xlabel = ""
1140 xlabel = ""
1136 ylabel = "Range (Km)"
1141 ylabel = "Range (Km)"
1137
1142
1138 if (SNR and not onlySNR): nplots = 2*nplots
1143 if (SNR and not onlySNR): nplots = 2*nplots
1139
1144
1140 if onlyPositive:
1145 if onlyPositive:
1141 colormap = "jet"
1146 colormap = "jet"
1142 zmin = 0
1147 zmin = 0
1143 else: colormap = "RdBu_r"
1148 else: colormap = "RdBu_r"
1144
1149
1145 if not self.isConfig:
1150 if not self.isConfig:
1146
1151
1147 self.setup(id=id,
1152 self.setup(id=id,
1148 nplots=nplots,
1153 nplots=nplots,
1149 wintitle=wintitle,
1154 wintitle=wintitle,
1150 showprofile=showprofile,
1155 showprofile=showprofile,
1151 show=show)
1156 show=show)
1152
1157
1153 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1158 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1154
1159
1155 if ymin == None: ymin = numpy.nanmin(y)
1160 if ymin == None: ymin = numpy.nanmin(y)
1156 if ymax == None: ymax = numpy.nanmax(y)
1161 if ymax == None: ymax = numpy.nanmax(y)
1157 if zmin == None: zmin = numpy.nanmin(zRange)
1162 if zmin == None: zmin = numpy.nanmin(zRange)
1158 if zmax == None: zmax = numpy.nanmax(zRange)
1163 if zmax == None: zmax = numpy.nanmax(zRange)
1159
1164
1160 if SNR:
1165 if SNR:
1161 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1166 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
1162 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1167 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
1163
1168
1164 self.FTP_WEI = ftp_wei
1169 self.FTP_WEI = ftp_wei
1165 self.EXP_CODE = exp_code
1170 self.EXP_CODE = exp_code
1166 self.SUB_EXP_CODE = sub_exp_code
1171 self.SUB_EXP_CODE = sub_exp_code
1167 self.PLOT_POS = plot_pos
1172 self.PLOT_POS = plot_pos
1168
1173
1169 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1174 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1170 self.isConfig = True
1175 self.isConfig = True
1171 self.figfile = figfile
1176 self.figfile = figfile
1172
1177
1173 self.setWinTitle(title)
1178 self.setWinTitle(title)
1174
1179
1175 if ((self.xmax - x[1]) < (x[1]-x[0])):
1180 if ((self.xmax - x[1]) < (x[1]-x[0])):
1176 x[1] = self.xmax
1181 x[1] = self.xmax
1177
1182
1178 for i in range(nchan):
1183 for i in range(nchan):
1179
1184
1180 if (SNR and not onlySNR): j = 2*i
1185 if (SNR and not onlySNR): j = 2*i
1181 else: j = i
1186 else: j = i
1182
1187
1183 j = nGraphsByChannel*i
1188 j = nGraphsByChannel*i
1184
1189
1185 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1190 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1186 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1191 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1187
1192
1188 if not onlySNR:
1193 if not onlySNR:
1189 axes = self.axesList[j*self.__nsubplots]
1194 axes = self.axesList[j*self.__nsubplots]
1190 z1 = z[i,:].reshape((1,-1))
1195 z1 = z[i,:].reshape((1,-1))
1191 axes.pcolorbuffer(x, y, z1,
1196 axes.pcolorbuffer(x, y, z1,
1192 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1197 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1193 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1198 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1194 ticksize=9, cblabel=zlabel, cbsize="1%")
1199 ticksize=9, cblabel=zlabel, cbsize="1%")
1195
1200
1196 if DOP:
1201 if DOP:
1197 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1202 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1198
1203
1199 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1204 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1200 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1205 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
1201 axes = self.axesList[j]
1206 axes = self.axesList[j]
1202 z1 = z[i,:].reshape((1,-1))
1207 z1 = z[i,:].reshape((1,-1))
1203 axes.pcolorbuffer(x, y, z1,
1208 axes.pcolorbuffer(x, y, z1,
1204 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
1205 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1210 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
1206 ticksize=9, cblabel=zlabel, cbsize="1%")
1211 ticksize=9, cblabel=zlabel, cbsize="1%")
1207
1212
1208 if SNR:
1213 if SNR:
1209 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1214 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1210 axes = self.axesList[(j)*self.__nsubplots]
1215 axes = self.axesList[(j)*self.__nsubplots]
1211 if not onlySNR:
1216 if not onlySNR:
1212 axes = self.axesList[(j + 1)*self.__nsubplots]
1217 axes = self.axesList[(j + 1)*self.__nsubplots]
1213
1218
1214 axes = self.axesList[(j + nGraphsByChannel-1)]
1219 axes = self.axesList[(j + nGraphsByChannel-1)]
1215
1220
1216 z1 = SNRdB[i,:].reshape((1,-1))
1221 z1 = SNRdB[i,:].reshape((1,-1))
1217 axes.pcolorbuffer(x, y, z1,
1222 axes.pcolorbuffer(x, y, z1,
1218 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1223 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1219 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1224 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
1220 ticksize=9, cblabel=zlabel, cbsize="1%")
1225 ticksize=9, cblabel=zlabel, cbsize="1%")
1221
1226
1222
1227
1223
1228
1224 self.draw()
1229 self.draw()
1225
1230
1226 if x[1] >= self.axesList[0].xmax:
1231 if x[1] >= self.axesList[0].xmax:
1227 self.counter_imagwr = wr_period
1232 self.counter_imagwr = wr_period
1228 self.isConfig = False
1233 self.isConfig = False
1229 self.figfile = None
1234 self.figfile = None
1230
1235
1231 self.save(figpath=figpath,
1236 self.save(figpath=figpath,
1232 figfile=figfile,
1237 figfile=figfile,
1233 save=save,
1238 save=save,
1234 ftp=ftp,
1239 ftp=ftp,
1235 wr_period=wr_period,
1240 wr_period=wr_period,
1236 thisDatetime=thisDatetime,
1241 thisDatetime=thisDatetime,
1237 update_figfile=False)
1242 update_figfile=False)
1238
1243
1239 class SpectralFittingPlot(Figure):
1244 class SpectralFittingPlot(Figure):
1240
1245
1241 __isConfig = None
1246 __isConfig = None
1242 __nsubplots = None
1247 __nsubplots = None
1243
1248
1244 WIDTHPROF = None
1249 WIDTHPROF = None
1245 HEIGHTPROF = None
1250 HEIGHTPROF = None
1246 PREFIX = 'prm'
1251 PREFIX = 'prm'
1247
1252
1248
1253
1249 N = None
1254 N = None
1250 ippSeconds = None
1255 ippSeconds = None
1251
1256
1252 def __init__(self, **kwargs):
1257 def __init__(self, **kwargs):
1253 Figure.__init__(self, **kwargs)
1258 Figure.__init__(self, **kwargs)
1254 self.isConfig = False
1259 self.isConfig = False
1255 self.__nsubplots = 1
1260 self.__nsubplots = 1
1256
1261
1257 self.PLOT_CODE = SPECFIT_CODE
1262 self.PLOT_CODE = SPECFIT_CODE
1258
1263
1259 self.WIDTH = 450
1264 self.WIDTH = 450
1260 self.HEIGHT = 250
1265 self.HEIGHT = 250
1261 self.WIDTHPROF = 0
1266 self.WIDTHPROF = 0
1262 self.HEIGHTPROF = 0
1267 self.HEIGHTPROF = 0
1263
1268
1264 def getSubplots(self):
1269 def getSubplots(self):
1265
1270
1266 ncol = int(numpy.sqrt(self.nplots)+0.9)
1271 ncol = int(numpy.sqrt(self.nplots)+0.9)
1267 nrow = int(self.nplots*1./ncol + 0.9)
1272 nrow = int(self.nplots*1./ncol + 0.9)
1268
1273
1269 return nrow, ncol
1274 return nrow, ncol
1270
1275
1271 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1276 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
1272
1277
1273 showprofile = False
1278 showprofile = False
1274 self.__showprofile = showprofile
1279 self.__showprofile = showprofile
1275 self.nplots = nplots
1280 self.nplots = nplots
1276
1281
1277 ncolspan = 5
1282 ncolspan = 5
1278 colspan = 4
1283 colspan = 4
1279 if showprofile:
1284 if showprofile:
1280 ncolspan = 5
1285 ncolspan = 5
1281 colspan = 4
1286 colspan = 4
1282 self.__nsubplots = 2
1287 self.__nsubplots = 2
1283
1288
1284 self.createFigure(id = id,
1289 self.createFigure(id = id,
1285 wintitle = wintitle,
1290 wintitle = wintitle,
1286 widthplot = self.WIDTH + self.WIDTHPROF,
1291 widthplot = self.WIDTH + self.WIDTHPROF,
1287 heightplot = self.HEIGHT + self.HEIGHTPROF,
1292 heightplot = self.HEIGHT + self.HEIGHTPROF,
1288 show=show)
1293 show=show)
1289
1294
1290 nrow, ncol = self.getSubplots()
1295 nrow, ncol = self.getSubplots()
1291
1296
1292 counter = 0
1297 counter = 0
1293 for y in range(nrow):
1298 for y in range(nrow):
1294 for x in range(ncol):
1299 for x in range(ncol):
1295
1300
1296 if counter >= self.nplots:
1301 if counter >= self.nplots:
1297 break
1302 break
1298
1303
1299 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1304 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1300
1305
1301 if showprofile:
1306 if showprofile:
1302 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1307 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1303
1308
1304 counter += 1
1309 counter += 1
1305
1310
1306 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1311 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
1307 xmin=None, xmax=None, ymin=None, ymax=None,
1312 xmin=None, xmax=None, ymin=None, ymax=None,
1308 save=False, figpath='./', figfile=None, show=True):
1313 save=False, figpath='./', figfile=None, show=True):
1309
1314
1310 """
1315 """
1311
1316
1312 Input:
1317 Input:
1313 dataOut :
1318 dataOut :
1314 id :
1319 id :
1315 wintitle :
1320 wintitle :
1316 channelList :
1321 channelList :
1317 showProfile :
1322 showProfile :
1318 xmin : None,
1323 xmin : None,
1319 xmax : None,
1324 xmax : None,
1320 zmin : None,
1325 zmin : None,
1321 zmax : None
1326 zmax : None
1322 """
1327 """
1323
1328
1324 if cutHeight==None:
1329 if cutHeight==None:
1325 h=270
1330 h=270
1326 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1331 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
1327 cutHeight = dataOut.heightList[heightindex]
1332 cutHeight = dataOut.heightList[heightindex]
1328
1333
1329 factor = dataOut.normFactor
1334 factor = dataOut.normFactor
1330 x = dataOut.abscissaList[:-1]
1335 x = dataOut.abscissaList[:-1]
1331 #y = dataOut.getHeiRange()
1336 #y = dataOut.getHeiRange()
1332
1337
1333 z = dataOut.data_pre[:,:,heightindex]/factor
1338 z = dataOut.data_pre[:,:,heightindex]/factor
1334 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1339 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1335 avg = numpy.average(z, axis=1)
1340 avg = numpy.average(z, axis=1)
1336 listChannels = z.shape[0]
1341 listChannels = z.shape[0]
1337
1342
1338 #Reconstruct Function
1343 #Reconstruct Function
1339 if fit==True:
1344 if fit==True:
1340 groupArray = dataOut.groupList
1345 groupArray = dataOut.groupList
1341 listChannels = groupArray.reshape((groupArray.size))
1346 listChannels = groupArray.reshape((groupArray.size))
1342 listChannels.sort()
1347 listChannels.sort()
1343 spcFitLine = numpy.zeros(z.shape)
1348 spcFitLine = numpy.zeros(z.shape)
1344 constants = dataOut.constants
1349 constants = dataOut.constants
1345
1350
1346 nGroups = groupArray.shape[0]
1351 nGroups = groupArray.shape[0]
1347 nChannels = groupArray.shape[1]
1352 nChannels = groupArray.shape[1]
1348 nProfiles = z.shape[1]
1353 nProfiles = z.shape[1]
1349
1354
1350 for f in range(nGroups):
1355 for f in range(nGroups):
1351 groupChann = groupArray[f,:]
1356 groupChann = groupArray[f,:]
1352 p = dataOut.data_param[f,:,heightindex]
1357 p = dataOut.data_param[f,:,heightindex]
1353 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1358 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
1354 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1359 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
1355 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1360 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
1356 spcFitLine[groupChann,:] = fitLineAux
1361 spcFitLine[groupChann,:] = fitLineAux
1357 # spcFitLine = spcFitLine/factor
1362 # spcFitLine = spcFitLine/factor
1358
1363
1359 z = z[listChannels,:]
1364 z = z[listChannels,:]
1360 spcFitLine = spcFitLine[listChannels,:]
1365 spcFitLine = spcFitLine[listChannels,:]
1361 spcFitLinedB = 10*numpy.log10(spcFitLine)
1366 spcFitLinedB = 10*numpy.log10(spcFitLine)
1362
1367
1363 zdB = 10*numpy.log10(z)
1368 zdB = 10*numpy.log10(z)
1364 #thisDatetime = dataOut.datatime
1369 #thisDatetime = dataOut.datatime
1365 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1370 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1366 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1371 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1367 xlabel = "Velocity (m/s)"
1372 xlabel = "Velocity (m/s)"
1368 ylabel = "Spectrum"
1373 ylabel = "Spectrum"
1369
1374
1370 if not self.isConfig:
1375 if not self.isConfig:
1371
1376
1372 nplots = listChannels.size
1377 nplots = listChannels.size
1373
1378
1374 self.setup(id=id,
1379 self.setup(id=id,
1375 nplots=nplots,
1380 nplots=nplots,
1376 wintitle=wintitle,
1381 wintitle=wintitle,
1377 showprofile=showprofile,
1382 showprofile=showprofile,
1378 show=show)
1383 show=show)
1379
1384
1380 if xmin == None: xmin = numpy.nanmin(x)
1385 if xmin == None: xmin = numpy.nanmin(x)
1381 if xmax == None: xmax = numpy.nanmax(x)
1386 if xmax == None: xmax = numpy.nanmax(x)
1382 if ymin == None: ymin = numpy.nanmin(zdB)
1387 if ymin == None: ymin = numpy.nanmin(zdB)
1383 if ymax == None: ymax = numpy.nanmax(zdB)+2
1388 if ymax == None: ymax = numpy.nanmax(zdB)+2
1384
1389
1385 self.isConfig = True
1390 self.isConfig = True
1386
1391
1387 self.setWinTitle(title)
1392 self.setWinTitle(title)
1388 for i in range(self.nplots):
1393 for i in range(self.nplots):
1389 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1394 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
1390 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1395 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i])
1391 axes = self.axesList[i*self.__nsubplots]
1396 axes = self.axesList[i*self.__nsubplots]
1392 if fit == False:
1397 if fit == False:
1393 axes.pline(x, zdB[i,:],
1398 axes.pline(x, zdB[i,:],
1394 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1399 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1395 xlabel=xlabel, ylabel=ylabel, title=title
1400 xlabel=xlabel, ylabel=ylabel, title=title
1396 )
1401 )
1397 if fit == True:
1402 if fit == True:
1398 fitline=spcFitLinedB[i,:]
1403 fitline=spcFitLinedB[i,:]
1399 y=numpy.vstack([zdB[i,:],fitline] )
1404 y=numpy.vstack([zdB[i,:],fitline] )
1400 legendlabels=['Data','Fitting']
1405 legendlabels=['Data','Fitting']
1401 axes.pmultilineyaxis(x, y,
1406 axes.pmultilineyaxis(x, y,
1402 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1407 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1403 xlabel=xlabel, ylabel=ylabel, title=title,
1408 xlabel=xlabel, ylabel=ylabel, title=title,
1404 legendlabels=legendlabels, marker=None,
1409 legendlabels=legendlabels, marker=None,
1405 linestyle='solid', grid='both')
1410 linestyle='solid', grid='both')
1406
1411
1407 self.draw()
1412 self.draw()
1408
1413
1409 self.save(figpath=figpath,
1414 self.save(figpath=figpath,
1410 figfile=figfile,
1415 figfile=figfile,
1411 save=save,
1416 save=save,
1412 ftp=ftp,
1417 ftp=ftp,
1413 wr_period=wr_period,
1418 wr_period=wr_period,
1414 thisDatetime=thisDatetime)
1419 thisDatetime=thisDatetime)
1415
1420
1416
1421
1417 class EWDriftsPlot(Figure):
1422 class EWDriftsPlot(Figure):
1418
1423
1419 __isConfig = None
1424 __isConfig = None
1420 __nsubplots = None
1425 __nsubplots = None
1421
1426
1422 WIDTHPROF = None
1427 WIDTHPROF = None
1423 HEIGHTPROF = None
1428 HEIGHTPROF = None
1424 PREFIX = 'drift'
1429 PREFIX = 'drift'
1425
1430
1426 def __init__(self, **kwargs):
1431 def __init__(self, **kwargs):
1427 Figure.__init__(self, **kwargs)
1432 Figure.__init__(self, **kwargs)
1428 self.timerange = 2*60*60
1433 self.timerange = 2*60*60
1429 self.isConfig = False
1434 self.isConfig = False
1430 self.__nsubplots = 1
1435 self.__nsubplots = 1
1431
1436
1432 self.WIDTH = 800
1437 self.WIDTH = 800
1433 self.HEIGHT = 150
1438 self.HEIGHT = 150
1434 self.WIDTHPROF = 120
1439 self.WIDTHPROF = 120
1435 self.HEIGHTPROF = 0
1440 self.HEIGHTPROF = 0
1436 self.counter_imagwr = 0
1441 self.counter_imagwr = 0
1437
1442
1438 self.PLOT_CODE = EWDRIFT_CODE
1443 self.PLOT_CODE = EWDRIFT_CODE
1439
1444
1440 self.FTP_WEI = None
1445 self.FTP_WEI = None
1441 self.EXP_CODE = None
1446 self.EXP_CODE = None
1442 self.SUB_EXP_CODE = None
1447 self.SUB_EXP_CODE = None
1443 self.PLOT_POS = None
1448 self.PLOT_POS = None
1444 self.tmin = None
1449 self.tmin = None
1445 self.tmax = None
1450 self.tmax = None
1446
1451
1447 self.xmin = None
1452 self.xmin = None
1448 self.xmax = None
1453 self.xmax = None
1449
1454
1450 self.figfile = None
1455 self.figfile = None
1451
1456
1452 def getSubplots(self):
1457 def getSubplots(self):
1453
1458
1454 ncol = 1
1459 ncol = 1
1455 nrow = self.nplots
1460 nrow = self.nplots
1456
1461
1457 return nrow, ncol
1462 return nrow, ncol
1458
1463
1459 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1464 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1460
1465
1461 self.__showprofile = showprofile
1466 self.__showprofile = showprofile
1462 self.nplots = nplots
1467 self.nplots = nplots
1463
1468
1464 ncolspan = 1
1469 ncolspan = 1
1465 colspan = 1
1470 colspan = 1
1466
1471
1467 self.createFigure(id = id,
1472 self.createFigure(id = id,
1468 wintitle = wintitle,
1473 wintitle = wintitle,
1469 widthplot = self.WIDTH + self.WIDTHPROF,
1474 widthplot = self.WIDTH + self.WIDTHPROF,
1470 heightplot = self.HEIGHT + self.HEIGHTPROF,
1475 heightplot = self.HEIGHT + self.HEIGHTPROF,
1471 show=show)
1476 show=show)
1472
1477
1473 nrow, ncol = self.getSubplots()
1478 nrow, ncol = self.getSubplots()
1474
1479
1475 counter = 0
1480 counter = 0
1476 for y in range(nrow):
1481 for y in range(nrow):
1477 if counter >= self.nplots:
1482 if counter >= self.nplots:
1478 break
1483 break
1479
1484
1480 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1485 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1481 counter += 1
1486 counter += 1
1482
1487
1483 def run(self, dataOut, id, wintitle="", channelList=None,
1488 def run(self, dataOut, id, wintitle="", channelList=None,
1484 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1489 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1485 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1490 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1486 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1491 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1487 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1492 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1488 server=None, folder=None, username=None, password=None,
1493 server=None, folder=None, username=None, password=None,
1489 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1494 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1490 """
1495 """
1491
1496
1492 Input:
1497 Input:
1493 dataOut :
1498 dataOut :
1494 id :
1499 id :
1495 wintitle :
1500 wintitle :
1496 channelList :
1501 channelList :
1497 showProfile :
1502 showProfile :
1498 xmin : None,
1503 xmin : None,
1499 xmax : None,
1504 xmax : None,
1500 ymin : None,
1505 ymin : None,
1501 ymax : None,
1506 ymax : None,
1502 zmin : None,
1507 zmin : None,
1503 zmax : None
1508 zmax : None
1504 """
1509 """
1505
1510
1506 if timerange is not None:
1511 if timerange is not None:
1507 self.timerange = timerange
1512 self.timerange = timerange
1508
1513
1509 tmin = None
1514 tmin = None
1510 tmax = None
1515 tmax = None
1511
1516
1512 x = dataOut.getTimeRange1(dataOut.outputInterval)
1517 x = dataOut.getTimeRange1(dataOut.outputInterval)
1513 # y = dataOut.heightList
1518 # y = dataOut.heightList
1514 y = dataOut.heightList
1519 y = dataOut.heightList
1515
1520
1516 z = dataOut.data_output
1521 z = dataOut.data_output
1517 nplots = z.shape[0] #Number of wind dimensions estimated
1522 nplots = z.shape[0] #Number of wind dimensions estimated
1518 nplotsw = nplots
1523 nplotsw = nplots
1519
1524
1520 #If there is a SNR function defined
1525 #If there is a SNR function defined
1521 if dataOut.data_SNR is not None:
1526 if dataOut.data_SNR is not None:
1522 nplots += 1
1527 nplots += 1
1523 SNR = dataOut.data_SNR
1528 SNR = dataOut.data_SNR
1524
1529
1525 if SNR_1:
1530 if SNR_1:
1526 SNR += 1
1531 SNR += 1
1527
1532
1528 SNRavg = numpy.average(SNR, axis=0)
1533 SNRavg = numpy.average(SNR, axis=0)
1529
1534
1530 SNRdB = 10*numpy.log10(SNR)
1535 SNRdB = 10*numpy.log10(SNR)
1531 SNRavgdB = 10*numpy.log10(SNRavg)
1536 SNRavgdB = 10*numpy.log10(SNRavg)
1532
1537
1533 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1538 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1534
1539
1535 for i in range(nplotsw):
1540 for i in range(nplotsw):
1536 z[i,ind] = numpy.nan
1541 z[i,ind] = numpy.nan
1537
1542
1538
1543
1539 showprofile = False
1544 showprofile = False
1540 # thisDatetime = dataOut.datatime
1545 # thisDatetime = dataOut.datatime
1541 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1546 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1542 title = wintitle + " EW Drifts"
1547 title = wintitle + " EW Drifts"
1543 xlabel = ""
1548 xlabel = ""
1544 ylabel = "Height (Km)"
1549 ylabel = "Height (Km)"
1545
1550
1546 if not self.isConfig:
1551 if not self.isConfig:
1547
1552
1548 self.setup(id=id,
1553 self.setup(id=id,
1549 nplots=nplots,
1554 nplots=nplots,
1550 wintitle=wintitle,
1555 wintitle=wintitle,
1551 showprofile=showprofile,
1556 showprofile=showprofile,
1552 show=show)
1557 show=show)
1553
1558
1554 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1559 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1555
1560
1556 if ymin == None: ymin = numpy.nanmin(y)
1561 if ymin == None: ymin = numpy.nanmin(y)
1557 if ymax == None: ymax = numpy.nanmax(y)
1562 if ymax == None: ymax = numpy.nanmax(y)
1558
1563
1559 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1564 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1560 if zminZonal == None: zminZonal = -zmaxZonal
1565 if zminZonal == None: zminZonal = -zmaxZonal
1561 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1566 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1562 if zminVertical == None: zminVertical = -zmaxVertical
1567 if zminVertical == None: zminVertical = -zmaxVertical
1563
1568
1564 if dataOut.data_SNR is not None:
1569 if dataOut.data_SNR is not None:
1565 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1570 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1566 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1571 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1567
1572
1568 self.FTP_WEI = ftp_wei
1573 self.FTP_WEI = ftp_wei
1569 self.EXP_CODE = exp_code
1574 self.EXP_CODE = exp_code
1570 self.SUB_EXP_CODE = sub_exp_code
1575 self.SUB_EXP_CODE = sub_exp_code
1571 self.PLOT_POS = plot_pos
1576 self.PLOT_POS = plot_pos
1572
1577
1573 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1578 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1574 self.isConfig = True
1579 self.isConfig = True
1575
1580
1576
1581
1577 self.setWinTitle(title)
1582 self.setWinTitle(title)
1578
1583
1579 if ((self.xmax - x[1]) < (x[1]-x[0])):
1584 if ((self.xmax - x[1]) < (x[1]-x[0])):
1580 x[1] = self.xmax
1585 x[1] = self.xmax
1581
1586
1582 strWind = ['Zonal','Vertical']
1587 strWind = ['Zonal','Vertical']
1583 strCb = 'Velocity (m/s)'
1588 strCb = 'Velocity (m/s)'
1584 zmaxVector = [zmaxZonal, zmaxVertical]
1589 zmaxVector = [zmaxZonal, zmaxVertical]
1585 zminVector = [zminZonal, zminVertical]
1590 zminVector = [zminZonal, zminVertical]
1586
1591
1587 for i in range(nplotsw):
1592 for i in range(nplotsw):
1588
1593
1589 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1594 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1590 axes = self.axesList[i*self.__nsubplots]
1595 axes = self.axesList[i*self.__nsubplots]
1591
1596
1592 z1 = z[i,:].reshape((1,-1))
1597 z1 = z[i,:].reshape((1,-1))
1593
1598
1594 axes.pcolorbuffer(x, y, z1,
1599 axes.pcolorbuffer(x, y, z1,
1595 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1600 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1596 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1601 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1597 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1602 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1598
1603
1599 if dataOut.data_SNR is not None:
1604 if dataOut.data_SNR is not None:
1600 i += 1
1605 i += 1
1601 if SNR_1:
1606 if SNR_1:
1602 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1607 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1603 else:
1608 else:
1604 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1609 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1605 axes = self.axesList[i*self.__nsubplots]
1610 axes = self.axesList[i*self.__nsubplots]
1606 SNRavgdB = SNRavgdB.reshape((1,-1))
1611 SNRavgdB = SNRavgdB.reshape((1,-1))
1607
1612
1608 axes.pcolorbuffer(x, y, SNRavgdB,
1613 axes.pcolorbuffer(x, y, SNRavgdB,
1609 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1614 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1610 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1615 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1611 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1616 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1612
1617
1613 self.draw()
1618 self.draw()
1614
1619
1615 if x[1] >= self.axesList[0].xmax:
1620 if x[1] >= self.axesList[0].xmax:
1616 self.counter_imagwr = wr_period
1621 self.counter_imagwr = wr_period
1617 self.isConfig = False
1622 self.isConfig = False
1618 self.figfile = None
1623 self.figfile = None
1619
1624
1620
1625
1621
1626
1622
1627
1623 class PhasePlot(Figure):
1628 class PhasePlot(Figure):
1624
1629
1625 __isConfig = None
1630 __isConfig = None
1626 __nsubplots = None
1631 __nsubplots = None
1627
1632
1628 PREFIX = 'mphase'
1633 PREFIX = 'mphase'
1629
1634
1630 def __init__(self, **kwargs):
1635 def __init__(self, **kwargs):
1631 Figure.__init__(self, **kwargs)
1636 Figure.__init__(self, **kwargs)
1632 self.timerange = 24*60*60
1637 self.timerange = 24*60*60
1633 self.isConfig = False
1638 self.isConfig = False
1634 self.__nsubplots = 1
1639 self.__nsubplots = 1
1635 self.counter_imagwr = 0
1640 self.counter_imagwr = 0
1636 self.WIDTH = 600
1641 self.WIDTH = 600
1637 self.HEIGHT = 300
1642 self.HEIGHT = 300
1638 self.WIDTHPROF = 120
1643 self.WIDTHPROF = 120
1639 self.HEIGHTPROF = 0
1644 self.HEIGHTPROF = 0
1640 self.xdata = None
1645 self.xdata = None
1641 self.ydata = None
1646 self.ydata = None
1642
1647
1643 self.PLOT_CODE = MPHASE_CODE
1648 self.PLOT_CODE = MPHASE_CODE
1644
1649
1645 self.FTP_WEI = None
1650 self.FTP_WEI = None
1646 self.EXP_CODE = None
1651 self.EXP_CODE = None
1647 self.SUB_EXP_CODE = None
1652 self.SUB_EXP_CODE = None
1648 self.PLOT_POS = None
1653 self.PLOT_POS = None
1649
1654
1650
1655
1651 self.filename_phase = None
1656 self.filename_phase = None
1652
1657
1653 self.figfile = None
1658 self.figfile = None
1654
1659
1655 def getSubplots(self):
1660 def getSubplots(self):
1656
1661
1657 ncol = 1
1662 ncol = 1
1658 nrow = 1
1663 nrow = 1
1659
1664
1660 return nrow, ncol
1665 return nrow, ncol
1661
1666
1662 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1667 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1663
1668
1664 self.__showprofile = showprofile
1669 self.__showprofile = showprofile
1665 self.nplots = nplots
1670 self.nplots = nplots
1666
1671
1667 ncolspan = 7
1672 ncolspan = 7
1668 colspan = 6
1673 colspan = 6
1669 self.__nsubplots = 2
1674 self.__nsubplots = 2
1670
1675
1671 self.createFigure(id = id,
1676 self.createFigure(id = id,
1672 wintitle = wintitle,
1677 wintitle = wintitle,
1673 widthplot = self.WIDTH+self.WIDTHPROF,
1678 widthplot = self.WIDTH+self.WIDTHPROF,
1674 heightplot = self.HEIGHT+self.HEIGHTPROF,
1679 heightplot = self.HEIGHT+self.HEIGHTPROF,
1675 show=show)
1680 show=show)
1676
1681
1677 nrow, ncol = self.getSubplots()
1682 nrow, ncol = self.getSubplots()
1678
1683
1679 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1684 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1680
1685
1681
1686
1682 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1687 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1683 xmin=None, xmax=None, ymin=None, ymax=None,
1688 xmin=None, xmax=None, ymin=None, ymax=None,
1684 timerange=None,
1689 timerange=None,
1685 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1690 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1686 server=None, folder=None, username=None, password=None,
1691 server=None, folder=None, username=None, password=None,
1687 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1692 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1688
1693
1689
1694
1690 tmin = None
1695 tmin = None
1691 tmax = None
1696 tmax = None
1692 x = dataOut.getTimeRange1(dataOut.outputInterval)
1697 x = dataOut.getTimeRange1(dataOut.outputInterval)
1693 y = dataOut.getHeiRange()
1698 y = dataOut.getHeiRange()
1694
1699
1695
1700
1696 #thisDatetime = dataOut.datatime
1701 #thisDatetime = dataOut.datatime
1697 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1702 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1698 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1703 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1699 xlabel = "Local Time"
1704 xlabel = "Local Time"
1700 ylabel = "Phase"
1705 ylabel = "Phase"
1701
1706
1702
1707
1703 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1708 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1704 phase_beacon = dataOut.data_output
1709 phase_beacon = dataOut.data_output
1705 update_figfile = False
1710 update_figfile = False
1706
1711
1707 if not self.isConfig:
1712 if not self.isConfig:
1708
1713
1709 self.nplots = phase_beacon.size
1714 self.nplots = phase_beacon.size
1710
1715
1711 self.setup(id=id,
1716 self.setup(id=id,
1712 nplots=self.nplots,
1717 nplots=self.nplots,
1713 wintitle=wintitle,
1718 wintitle=wintitle,
1714 showprofile=showprofile,
1719 showprofile=showprofile,
1715 show=show)
1720 show=show)
1716
1721
1717 if timerange is not None:
1722 if timerange is not None:
1718 self.timerange = timerange
1723 self.timerange = timerange
1719
1724
1720 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1721
1726
1722 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1727 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1723 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1728 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1724
1729
1725 self.FTP_WEI = ftp_wei
1730 self.FTP_WEI = ftp_wei
1726 self.EXP_CODE = exp_code
1731 self.EXP_CODE = exp_code
1727 self.SUB_EXP_CODE = sub_exp_code
1732 self.SUB_EXP_CODE = sub_exp_code
1728 self.PLOT_POS = plot_pos
1733 self.PLOT_POS = plot_pos
1729
1734
1730 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1735 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1731 self.isConfig = True
1736 self.isConfig = True
1732 self.figfile = figfile
1737 self.figfile = figfile
1733 self.xdata = numpy.array([])
1738 self.xdata = numpy.array([])
1734 self.ydata = numpy.array([])
1739 self.ydata = numpy.array([])
1735
1740
1736 #open file beacon phase
1741 #open file beacon phase
1737 path = '%s%03d' %(self.PREFIX, self.id)
1742 path = '%s%03d' %(self.PREFIX, self.id)
1738 beacon_file = os.path.join(path,'%s.txt'%self.name)
1743 beacon_file = os.path.join(path,'%s.txt'%self.name)
1739 self.filename_phase = os.path.join(figpath,beacon_file)
1744 self.filename_phase = os.path.join(figpath,beacon_file)
1740 update_figfile = True
1745 update_figfile = True
1741
1746
1742
1747
1743 #store data beacon phase
1748 #store data beacon phase
1744 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1749 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1745
1750
1746 self.setWinTitle(title)
1751 self.setWinTitle(title)
1747
1752
1748
1753
1749 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1754 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1750
1755
1751 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1756 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1752
1757
1753 axes = self.axesList[0]
1758 axes = self.axesList[0]
1754
1759
1755 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1760 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1756
1761
1757 if len(self.ydata)==0:
1762 if len(self.ydata)==0:
1758 self.ydata = phase_beacon.reshape(-1,1)
1763 self.ydata = phase_beacon.reshape(-1,1)
1759 else:
1764 else:
1760 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1765 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1761
1766
1762
1767
1763 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1768 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1764 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1765 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1770 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1766 XAxisAsTime=True, grid='both'
1771 XAxisAsTime=True, grid='both'
1767 )
1772 )
1768
1773
1769 self.draw()
1774 self.draw()
1770
1775
1771 self.save(figpath=figpath,
1776 self.save(figpath=figpath,
1772 figfile=figfile,
1777 figfile=figfile,
1773 save=save,
1778 save=save,
1774 ftp=ftp,
1779 ftp=ftp,
1775 wr_period=wr_period,
1780 wr_period=wr_period,
1776 thisDatetime=thisDatetime,
1781 thisDatetime=thisDatetime,
1777 update_figfile=update_figfile)
1782 update_figfile=update_figfile)
1778
1783
1779 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1784 if dataOut.ltctime + dataOut.outputInterval >= self.xmax:
1780 self.counter_imagwr = wr_period
1785 self.counter_imagwr = wr_period
1781 self.isConfig = False
1786 self.isConfig = False
1782 update_figfile = True
1787 update_figfile = True
1783
1788
1784
1789
1785
1790
1786 class NSMeteorDetection1Plot(Figure):
1791 class NSMeteorDetection1Plot(Figure):
1787
1792
1788 isConfig = None
1793 isConfig = None
1789 __nsubplots = None
1794 __nsubplots = None
1790
1795
1791 WIDTHPROF = None
1796 WIDTHPROF = None
1792 HEIGHTPROF = None
1797 HEIGHTPROF = None
1793 PREFIX = 'nsm'
1798 PREFIX = 'nsm'
1794
1799
1795 zminList = None
1800 zminList = None
1796 zmaxList = None
1801 zmaxList = None
1797 cmapList = None
1802 cmapList = None
1798 titleList = None
1803 titleList = None
1799 nPairs = None
1804 nPairs = None
1800 nChannels = None
1805 nChannels = None
1801 nParam = None
1806 nParam = None
1802
1807
1803 def __init__(self, **kwargs):
1808 def __init__(self, **kwargs):
1804 Figure.__init__(self, **kwargs)
1809 Figure.__init__(self, **kwargs)
1805 self.isConfig = False
1810 self.isConfig = False
1806 self.__nsubplots = 1
1811 self.__nsubplots = 1
1807
1812
1808 self.WIDTH = 750
1813 self.WIDTH = 750
1809 self.HEIGHT = 250
1814 self.HEIGHT = 250
1810 self.WIDTHPROF = 120
1815 self.WIDTHPROF = 120
1811 self.HEIGHTPROF = 0
1816 self.HEIGHTPROF = 0
1812 self.counter_imagwr = 0
1817 self.counter_imagwr = 0
1813
1818
1814 self.PLOT_CODE = SPEC_CODE
1819 self.PLOT_CODE = SPEC_CODE
1815
1820
1816 self.FTP_WEI = None
1821 self.FTP_WEI = None
1817 self.EXP_CODE = None
1822 self.EXP_CODE = None
1818 self.SUB_EXP_CODE = None
1823 self.SUB_EXP_CODE = None
1819 self.PLOT_POS = None
1824 self.PLOT_POS = None
1820
1825
1821 self.__xfilter_ena = False
1826 self.__xfilter_ena = False
1822 self.__yfilter_ena = False
1827 self.__yfilter_ena = False
1823
1828
1824 def getSubplots(self):
1829 def getSubplots(self):
1825
1830
1826 ncol = 3
1831 ncol = 3
1827 nrow = int(numpy.ceil(self.nplots/3.0))
1832 nrow = int(numpy.ceil(self.nplots/3.0))
1828
1833
1829 return nrow, ncol
1834 return nrow, ncol
1830
1835
1831 def setup(self, id, nplots, wintitle, show=True):
1836 def setup(self, id, nplots, wintitle, show=True):
1832
1837
1833 self.nplots = nplots
1838 self.nplots = nplots
1834
1839
1835 ncolspan = 1
1840 ncolspan = 1
1836 colspan = 1
1841 colspan = 1
1837
1842
1838 self.createFigure(id = id,
1843 self.createFigure(id = id,
1839 wintitle = wintitle,
1844 wintitle = wintitle,
1840 widthplot = self.WIDTH + self.WIDTHPROF,
1845 widthplot = self.WIDTH + self.WIDTHPROF,
1841 heightplot = self.HEIGHT + self.HEIGHTPROF,
1846 heightplot = self.HEIGHT + self.HEIGHTPROF,
1842 show=show)
1847 show=show)
1843
1848
1844 nrow, ncol = self.getSubplots()
1849 nrow, ncol = self.getSubplots()
1845
1850
1846 counter = 0
1851 counter = 0
1847 for y in range(nrow):
1852 for y in range(nrow):
1848 for x in range(ncol):
1853 for x in range(ncol):
1849
1854
1850 if counter >= self.nplots:
1855 if counter >= self.nplots:
1851 break
1856 break
1852
1857
1853 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1858 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1854
1859
1855 counter += 1
1860 counter += 1
1856
1861
1857 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1862 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
1858 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1863 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
1859 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1864 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
1860 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1865 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1861 server=None, folder=None, username=None, password=None,
1866 server=None, folder=None, username=None, password=None,
1862 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1867 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
1863 xaxis="frequency"):
1868 xaxis="frequency"):
1864
1869
1865 """
1870 """
1866
1871
1867 Input:
1872 Input:
1868 dataOut :
1873 dataOut :
1869 id :
1874 id :
1870 wintitle :
1875 wintitle :
1871 channelList :
1876 channelList :
1872 showProfile :
1877 showProfile :
1873 xmin : None,
1878 xmin : None,
1874 xmax : None,
1879 xmax : None,
1875 ymin : None,
1880 ymin : None,
1876 ymax : None,
1881 ymax : None,
1877 zmin : None,
1882 zmin : None,
1878 zmax : None
1883 zmax : None
1879 """
1884 """
1880 #SEPARAR EN DOS PLOTS
1885 #SEPARAR EN DOS PLOTS
1881 nParam = dataOut.data_param.shape[1] - 3
1886 nParam = dataOut.data_param.shape[1] - 3
1882
1887
1883 utctime = dataOut.data_param[0,0]
1888 utctime = dataOut.data_param[0,0]
1884 tmet = dataOut.data_param[:,1].astype(int)
1889 tmet = dataOut.data_param[:,1].astype(int)
1885 hmet = dataOut.data_param[:,2].astype(int)
1890 hmet = dataOut.data_param[:,2].astype(int)
1886
1891
1887 x = dataOut.abscissaList
1892 x = dataOut.abscissaList
1888 y = dataOut.heightList
1893 y = dataOut.heightList
1889
1894
1890 z = numpy.zeros((nParam, y.size, x.size - 1))
1895 z = numpy.zeros((nParam, y.size, x.size - 1))
1891 z[:,:] = numpy.nan
1896 z[:,:] = numpy.nan
1892 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1897 z[:,hmet,tmet] = dataOut.data_param[:,3:].T
1893 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1898 z[0,:,:] = 10*numpy.log10(z[0,:,:])
1894
1899
1895 xlabel = "Time (s)"
1900 xlabel = "Time (s)"
1896 ylabel = "Range (km)"
1901 ylabel = "Range (km)"
1897
1902
1898 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1903 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
1899
1904
1900 if not self.isConfig:
1905 if not self.isConfig:
1901
1906
1902 nplots = nParam
1907 nplots = nParam
1903
1908
1904 self.setup(id=id,
1909 self.setup(id=id,
1905 nplots=nplots,
1910 nplots=nplots,
1906 wintitle=wintitle,
1911 wintitle=wintitle,
1907 show=show)
1912 show=show)
1908
1913
1909 if xmin is None: xmin = numpy.nanmin(x)
1914 if xmin is None: xmin = numpy.nanmin(x)
1910 if xmax is None: xmax = numpy.nanmax(x)
1915 if xmax is None: xmax = numpy.nanmax(x)
1911 if ymin is None: ymin = numpy.nanmin(y)
1916 if ymin is None: ymin = numpy.nanmin(y)
1912 if ymax is None: ymax = numpy.nanmax(y)
1917 if ymax is None: ymax = numpy.nanmax(y)
1913 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1918 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
1914 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1919 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
1915 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1920 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
1916 if vmin is None: vmin = -vmax
1921 if vmin is None: vmin = -vmax
1917 if wmin is None: wmin = 0
1922 if wmin is None: wmin = 0
1918 if wmax is None: wmax = 50
1923 if wmax is None: wmax = 50
1919
1924
1920 pairsList = dataOut.groupList
1925 pairsList = dataOut.groupList
1921 self.nPairs = len(dataOut.groupList)
1926 self.nPairs = len(dataOut.groupList)
1922
1927
1923 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1928 zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs
1924 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1929 zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs
1925 titleList = ["SNR","Radial Velocity","Coherence"]
1930 titleList = ["SNR","Radial Velocity","Coherence"]
1926 cmapList = ["jet","RdBu_r","jet"]
1931 cmapList = ["jet","RdBu_r","jet"]
1927
1932
1928 for i in range(self.nPairs):
1933 for i in range(self.nPairs):
1929 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1934 strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1])
1930 titleList = titleList + [strAux1]
1935 titleList = titleList + [strAux1]
1931 cmapList = cmapList + ["RdBu_r"]
1936 cmapList = cmapList + ["RdBu_r"]
1932
1937
1933 self.zminList = zminList
1938 self.zminList = zminList
1934 self.zmaxList = zmaxList
1939 self.zmaxList = zmaxList
1935 self.cmapList = cmapList
1940 self.cmapList = cmapList
1936 self.titleList = titleList
1941 self.titleList = titleList
1937
1942
1938 self.FTP_WEI = ftp_wei
1943 self.FTP_WEI = ftp_wei
1939 self.EXP_CODE = exp_code
1944 self.EXP_CODE = exp_code
1940 self.SUB_EXP_CODE = sub_exp_code
1945 self.SUB_EXP_CODE = sub_exp_code
1941 self.PLOT_POS = plot_pos
1946 self.PLOT_POS = plot_pos
1942
1947
1943 self.isConfig = True
1948 self.isConfig = True
1944
1949
1945 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1950 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
1946
1951
1947 for i in range(nParam):
1952 for i in range(nParam):
1948 title = self.titleList[i] + ": " +str_datetime
1953 title = self.titleList[i] + ": " +str_datetime
1949 axes = self.axesList[i]
1954 axes = self.axesList[i]
1950 axes.pcolor(x, y, z[i,:].T,
1955 axes.pcolor(x, y, z[i,:].T,
1951 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1956 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
1952 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1957 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
1953 self.draw()
1958 self.draw()
1954
1959
1955 if figfile == None:
1960 if figfile == None:
1956 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1961 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1957 name = str_datetime
1962 name = str_datetime
1958 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1963 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
1959 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1964 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
1960 figfile = self.getFilename(name)
1965 figfile = self.getFilename(name)
1961
1966
1962 self.save(figpath=figpath,
1967 self.save(figpath=figpath,
1963 figfile=figfile,
1968 figfile=figfile,
1964 save=save,
1969 save=save,
1965 ftp=ftp,
1970 ftp=ftp,
1966 wr_period=wr_period,
1971 wr_period=wr_period,
1967 thisDatetime=thisDatetime)
1972 thisDatetime=thisDatetime)
1968
1973
1969
1974
1970 class NSMeteorDetection2Plot(Figure):
1975 class NSMeteorDetection2Plot(Figure):
1971
1976
1972 isConfig = None
1977 isConfig = None
1973 __nsubplots = None
1978 __nsubplots = None
1974
1979
1975 WIDTHPROF = None
1980 WIDTHPROF = None
1976 HEIGHTPROF = None
1981 HEIGHTPROF = None
1977 PREFIX = 'nsm'
1982 PREFIX = 'nsm'
1978
1983
1979 zminList = None
1984 zminList = None
1980 zmaxList = None
1985 zmaxList = None
1981 cmapList = None
1986 cmapList = None
1982 titleList = None
1987 titleList = None
1983 nPairs = None
1988 nPairs = None
1984 nChannels = None
1989 nChannels = None
1985 nParam = None
1990 nParam = None
1986
1991
1987 def __init__(self, **kwargs):
1992 def __init__(self, **kwargs):
1988 Figure.__init__(self, **kwargs)
1993 Figure.__init__(self, **kwargs)
1989 self.isConfig = False
1994 self.isConfig = False
1990 self.__nsubplots = 1
1995 self.__nsubplots = 1
1991
1996
1992 self.WIDTH = 750
1997 self.WIDTH = 750
1993 self.HEIGHT = 250
1998 self.HEIGHT = 250
1994 self.WIDTHPROF = 120
1999 self.WIDTHPROF = 120
1995 self.HEIGHTPROF = 0
2000 self.HEIGHTPROF = 0
1996 self.counter_imagwr = 0
2001 self.counter_imagwr = 0
1997
2002
1998 self.PLOT_CODE = SPEC_CODE
2003 self.PLOT_CODE = SPEC_CODE
1999
2004
2000 self.FTP_WEI = None
2005 self.FTP_WEI = None
2001 self.EXP_CODE = None
2006 self.EXP_CODE = None
2002 self.SUB_EXP_CODE = None
2007 self.SUB_EXP_CODE = None
2003 self.PLOT_POS = None
2008 self.PLOT_POS = None
2004
2009
2005 self.__xfilter_ena = False
2010 self.__xfilter_ena = False
2006 self.__yfilter_ena = False
2011 self.__yfilter_ena = False
2007
2012
2008 def getSubplots(self):
2013 def getSubplots(self):
2009
2014
2010 ncol = 3
2015 ncol = 3
2011 nrow = int(numpy.ceil(self.nplots/3.0))
2016 nrow = int(numpy.ceil(self.nplots/3.0))
2012
2017
2013 return nrow, ncol
2018 return nrow, ncol
2014
2019
2015 def setup(self, id, nplots, wintitle, show=True):
2020 def setup(self, id, nplots, wintitle, show=True):
2016
2021
2017 self.nplots = nplots
2022 self.nplots = nplots
2018
2023
2019 ncolspan = 1
2024 ncolspan = 1
2020 colspan = 1
2025 colspan = 1
2021
2026
2022 self.createFigure(id = id,
2027 self.createFigure(id = id,
2023 wintitle = wintitle,
2028 wintitle = wintitle,
2024 widthplot = self.WIDTH + self.WIDTHPROF,
2029 widthplot = self.WIDTH + self.WIDTHPROF,
2025 heightplot = self.HEIGHT + self.HEIGHTPROF,
2030 heightplot = self.HEIGHT + self.HEIGHTPROF,
2026 show=show)
2031 show=show)
2027
2032
2028 nrow, ncol = self.getSubplots()
2033 nrow, ncol = self.getSubplots()
2029
2034
2030 counter = 0
2035 counter = 0
2031 for y in range(nrow):
2036 for y in range(nrow):
2032 for x in range(ncol):
2037 for x in range(ncol):
2033
2038
2034 if counter >= self.nplots:
2039 if counter >= self.nplots:
2035 break
2040 break
2036
2041
2037 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2042 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
2038
2043
2039 counter += 1
2044 counter += 1
2040
2045
2041 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2046 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
2042 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2047 xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None,
2043 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2048 vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA',
2044 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2049 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
2045 server=None, folder=None, username=None, password=None,
2050 server=None, folder=None, username=None, password=None,
2046 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2051 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
2047 xaxis="frequency"):
2052 xaxis="frequency"):
2048
2053
2049 """
2054 """
2050
2055
2051 Input:
2056 Input:
2052 dataOut :
2057 dataOut :
2053 id :
2058 id :
2054 wintitle :
2059 wintitle :
2055 channelList :
2060 channelList :
2056 showProfile :
2061 showProfile :
2057 xmin : None,
2062 xmin : None,
2058 xmax : None,
2063 xmax : None,
2059 ymin : None,
2064 ymin : None,
2060 ymax : None,
2065 ymax : None,
2061 zmin : None,
2066 zmin : None,
2062 zmax : None
2067 zmax : None
2063 """
2068 """
2064 #Rebuild matrix
2069 #Rebuild matrix
2065 utctime = dataOut.data_param[0,0]
2070 utctime = dataOut.data_param[0,0]
2066 cmet = dataOut.data_param[:,1].astype(int)
2071 cmet = dataOut.data_param[:,1].astype(int)
2067 tmet = dataOut.data_param[:,2].astype(int)
2072 tmet = dataOut.data_param[:,2].astype(int)
2068 hmet = dataOut.data_param[:,3].astype(int)
2073 hmet = dataOut.data_param[:,3].astype(int)
2069
2074
2070 nParam = 3
2075 nParam = 3
2071 nChan = len(dataOut.groupList)
2076 nChan = len(dataOut.groupList)
2072 x = dataOut.abscissaList
2077 x = dataOut.abscissaList
2073 y = dataOut.heightList
2078 y = dataOut.heightList
2074
2079
2075 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2080 z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan)
2076 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2081 z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:]
2077 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2082 z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale
2078 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2083 z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1))
2079
2084
2080 xlabel = "Time (s)"
2085 xlabel = "Time (s)"
2081 ylabel = "Range (km)"
2086 ylabel = "Range (km)"
2082
2087
2083 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2088 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime)
2084
2089
2085 if not self.isConfig:
2090 if not self.isConfig:
2086
2091
2087 nplots = nParam*nChan
2092 nplots = nParam*nChan
2088
2093
2089 self.setup(id=id,
2094 self.setup(id=id,
2090 nplots=nplots,
2095 nplots=nplots,
2091 wintitle=wintitle,
2096 wintitle=wintitle,
2092 show=show)
2097 show=show)
2093
2098
2094 if xmin is None: xmin = numpy.nanmin(x)
2099 if xmin is None: xmin = numpy.nanmin(x)
2095 if xmax is None: xmax = numpy.nanmax(x)
2100 if xmax is None: xmax = numpy.nanmax(x)
2096 if ymin is None: ymin = numpy.nanmin(y)
2101 if ymin is None: ymin = numpy.nanmin(y)
2097 if ymax is None: ymax = numpy.nanmax(y)
2102 if ymax is None: ymax = numpy.nanmax(y)
2098 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2103 if SNRmin is None: SNRmin = numpy.nanmin(z[0,:])
2099 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2104 if SNRmax is None: SNRmax = numpy.nanmax(z[0,:])
2100 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2105 if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:]))
2101 if vmin is None: vmin = -vmax
2106 if vmin is None: vmin = -vmax
2102 if wmin is None: wmin = 0
2107 if wmin is None: wmin = 0
2103 if wmax is None: wmax = 50
2108 if wmax is None: wmax = 50
2104
2109
2105 self.nChannels = nChan
2110 self.nChannels = nChan
2106
2111
2107 zminList = []
2112 zminList = []
2108 zmaxList = []
2113 zmaxList = []
2109 titleList = []
2114 titleList = []
2110 cmapList = []
2115 cmapList = []
2111 for i in range(self.nChannels):
2116 for i in range(self.nChannels):
2112 strAux1 = "SNR Channel "+ str(i)
2117 strAux1 = "SNR Channel "+ str(i)
2113 strAux2 = "Radial Velocity Channel "+ str(i)
2118 strAux2 = "Radial Velocity Channel "+ str(i)
2114 strAux3 = "Spectral Width Channel "+ str(i)
2119 strAux3 = "Spectral Width Channel "+ str(i)
2115
2120
2116 titleList = titleList + [strAux1,strAux2,strAux3]
2121 titleList = titleList + [strAux1,strAux2,strAux3]
2117 cmapList = cmapList + ["jet","RdBu_r","jet"]
2122 cmapList = cmapList + ["jet","RdBu_r","jet"]
2118 zminList = zminList + [SNRmin,vmin,wmin]
2123 zminList = zminList + [SNRmin,vmin,wmin]
2119 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2124 zmaxList = zmaxList + [SNRmax,vmax,wmax]
2120
2125
2121 self.zminList = zminList
2126 self.zminList = zminList
2122 self.zmaxList = zmaxList
2127 self.zmaxList = zmaxList
2123 self.cmapList = cmapList
2128 self.cmapList = cmapList
2124 self.titleList = titleList
2129 self.titleList = titleList
2125
2130
2126 self.FTP_WEI = ftp_wei
2131 self.FTP_WEI = ftp_wei
2127 self.EXP_CODE = exp_code
2132 self.EXP_CODE = exp_code
2128 self.SUB_EXP_CODE = sub_exp_code
2133 self.SUB_EXP_CODE = sub_exp_code
2129 self.PLOT_POS = plot_pos
2134 self.PLOT_POS = plot_pos
2130
2135
2131 self.isConfig = True
2136 self.isConfig = True
2132
2137
2133 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2138 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
2134
2139
2135 for i in range(self.nplots):
2140 for i in range(self.nplots):
2136 title = self.titleList[i] + ": " +str_datetime
2141 title = self.titleList[i] + ": " +str_datetime
2137 axes = self.axesList[i]
2142 axes = self.axesList[i]
2138 axes.pcolor(x, y, z[i,:].T,
2143 axes.pcolor(x, y, z[i,:].T,
2139 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2144 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i],
2140 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2145 xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='')
2141 self.draw()
2146 self.draw()
2142
2147
2143 if figfile == None:
2148 if figfile == None:
2144 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2149 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
2145 name = str_datetime
2150 name = str_datetime
2146 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2151 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
2147 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2152 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
2148 figfile = self.getFilename(name)
2153 figfile = self.getFilename(name)
2149
2154
2150 self.save(figpath=figpath,
2155 self.save(figpath=figpath,
2151 figfile=figfile,
2156 figfile=figfile,
2152 save=save,
2157 save=save,
2153 ftp=ftp,
2158 ftp=ftp,
2154 wr_period=wr_period,
2159 wr_period=wr_period,
2155 thisDatetime=thisDatetime)
2160 thisDatetime=thisDatetime)
@@ -1,1609 +1,1611
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 import matplotlib.pyplot as plt
10 import matplotlib.pyplot as plt
11
11
12 from figure import Figure, isRealtime, isTimeInHourRange
12 from figure import Figure, isRealtime, isTimeInHourRange
13 from plotting_codes import *
13 from plotting_codes import *
14 from matplotlib.pyplot import savefig
14 from matplotlib.pyplot import savefig
15
15
16 class SpectraPlot(Figure):
16 class SpectraPlot(Figure):
17
17
18 isConfig = None
18 isConfig = None
19 __nsubplots = None
19 __nsubplots = None
20
20
21 WIDTHPROF = None
21 WIDTHPROF = None
22 HEIGHTPROF = None
22 HEIGHTPROF = None
23 PREFIX = 'spc'
23 PREFIX = 'spc'
24
24
25 def __init__(self, **kwargs):
25 def __init__(self, **kwargs):
26 Figure.__init__(self, **kwargs)
26 Figure.__init__(self, **kwargs)
27 self.isConfig = False
27 self.isConfig = False
28 self.__nsubplots = 1
28 self.__nsubplots = 1
29
29
30 self.WIDTH = 300
30 self.WIDTH = 300
31 self.HEIGHT = 300
31 self.HEIGHT = 300
32 self.WIDTHPROF = 120
32 self.WIDTHPROF = 120
33 self.HEIGHTPROF = 0
33 self.HEIGHTPROF = 0
34 self.counter_imagwr = 0
34 self.counter_imagwr = 0
35
35
36 self.PLOT_CODE = SPEC_CODE
36 self.PLOT_CODE = SPEC_CODE
37
37
38 self.FTP_WEI = None
38 self.FTP_WEI = None
39 self.EXP_CODE = None
39 self.EXP_CODE = None
40 self.SUB_EXP_CODE = None
40 self.SUB_EXP_CODE = None
41 self.PLOT_POS = None
41 self.PLOT_POS = None
42
42
43 self.__xfilter_ena = False
43 self.__xfilter_ena = False
44 self.__yfilter_ena = False
44 self.__yfilter_ena = False
45
45
46 self.indice=1
46 self.indice=1
47
47
48 def getSubplots(self):
48 def getSubplots(self):
49
49
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
50 ncol = int(numpy.sqrt(self.nplots)+0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
51 nrow = int(self.nplots*1./ncol + 0.9)
52
52
53 return nrow, ncol
53 return nrow, ncol
54
54
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
55 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
56
56
57 self.__showprofile = showprofile
57 self.__showprofile = showprofile
58 self.nplots = nplots
58 self.nplots = nplots
59
59
60 ncolspan = 1
60 ncolspan = 1
61 colspan = 1
61 colspan = 1
62 if showprofile:
62 if showprofile:
63 ncolspan = 3
63 ncolspan = 3
64 colspan = 2
64 colspan = 2
65 self.__nsubplots = 2
65 self.__nsubplots = 2
66
66
67 self.createFigure(id = id,
67 self.createFigure(id = id,
68 wintitle = wintitle,
68 wintitle = wintitle,
69 widthplot = self.WIDTH + self.WIDTHPROF,
69 widthplot = self.WIDTH + self.WIDTHPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
70 heightplot = self.HEIGHT + self.HEIGHTPROF,
71 show=show)
71 show=show)
72
72
73 nrow, ncol = self.getSubplots()
73 nrow, ncol = self.getSubplots()
74
74
75 counter = 0
75 counter = 0
76 for y in range(nrow):
76 for y in range(nrow):
77 for x in range(ncol):
77 for x in range(ncol):
78
78
79 if counter >= self.nplots:
79 if counter >= self.nplots:
80 break
80 break
81
81
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
82 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
83
83
84 if showprofile:
84 if showprofile:
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
85 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
86
86
87 counter += 1
87 counter += 1
88
88
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
89 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
90 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
91 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
92 server=None, folder=None, username=None, password=None,
92 server=None, folder=None, username=None, password=None,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
93 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
94 xaxis="frequency", colormap='jet', normFactor=None):
94 xaxis="frequency", colormap='jet', normFactor=None):
95
95
96 """
96 """
97
97
98 Input:
98 Input:
99 dataOut :
99 dataOut :
100 id :
100 id :
101 wintitle :
101 wintitle :
102 channelList :
102 channelList :
103 showProfile :
103 showProfile :
104 xmin : None,
104 xmin : None,
105 xmax : None,
105 xmax : None,
106 ymin : None,
106 ymin : None,
107 ymax : None,
107 ymax : None,
108 zmin : None,
108 zmin : None,
109 zmax : None
109 zmax : None
110 """
110 """
111 if realtime:
111 if realtime:
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
112 if not(isRealtime(utcdatatime = dataOut.utctime)):
113 print 'Skipping this plot function'
113 print 'Skipping this plot function'
114 return
114 return
115
115
116 if channelList == None:
116 if channelList == None:
117 channelIndexList = dataOut.channelIndexList
117 channelIndexList = dataOut.channelIndexList
118 else:
118 else:
119 channelIndexList = []
119 channelIndexList = []
120 for channel in channelList:
120 for channel in channelList:
121 if channel not in dataOut.channelList:
121 if channel not in dataOut.channelList:
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
122 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
123 channelIndexList.append(dataOut.channelList.index(channel))
123 channelIndexList.append(dataOut.channelList.index(channel))
124
124
125 if normFactor is None:
125 if normFactor is None:
126 factor = dataOut.normFactor
126 factor = dataOut.normFactor
127 else:
127 else:
128 factor = normFactor
128 factor = normFactor
129 if xaxis == "frequency":
129 if xaxis == "frequency":
130 x = dataOut.getFreqRange(1)/1000.
130 x = dataOut.getFreqRange(1)/1000.
131 print 'FRECUENCIA MAXIMA', numpy.amax(x)
132 asfasfasdfaf
131 print '#######################################################'
133 print '#######################################################'
132 print 'xlen', len(x)
134 print 'xlen', len(x)
133 print x
135 print x
134 print '#######################################################'
136 print '#######################################################'
135 xlabel = "Frequency (kHz)"
137 xlabel = "Frequency (kHz)"
136
138
137 elif xaxis == "time":
139 elif xaxis == "time":
138 x = dataOut.getAcfRange(1)
140 x = dataOut.getAcfRange(1)
139 xlabel = "Time (ms)"
141 xlabel = "Time (ms)"
140
142
141 else:
143 else:
142 x = dataOut.getVelRange(1)
144 x = dataOut.getVelRange(1)
143 xlabel = "Velocity (m/s)"
145 xlabel = "Velocity (m/s)"
144
146
145 ylabel = "Range (Km)"
147 ylabel = "Range (Km)"
146
148
147 y = dataOut.getHeiRange()
149 y = dataOut.getHeiRange()
148
150
149 z = dataOut.data_spc/factor
151 z = dataOut.data_spc/factor
150 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
152 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
151 zdB = 10*numpy.log10(z)
153 zdB = 10*numpy.log10(z)
152
154
153 avg = numpy.average(z, axis=1)
155 avg = numpy.average(z, axis=1)
154 avgdB = 10*numpy.log10(avg)
156 avgdB = 10*numpy.log10(avg)
155
157
156 noise = dataOut.getNoise()/factor
158 noise = dataOut.getNoise()/factor
157 noisedB = 10*numpy.log10(noise)
159 noisedB = 10*numpy.log10(noise)
158
160
159 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
161 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
160 title = wintitle + " Spectra"
162 title = wintitle + " Spectra"
161
163
162
164
163
165
164 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
166 print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc)
165 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
167 print 'Altura:', y[0], y[1], y[13], y[14], y[10]
166 #a=z[1,:,15]
168 #a=z[1,:,15]
167
169
168 # fig = plt.figure(10+self.indice)
170 # fig = plt.figure(10+self.indice)
169 # plt.plot( x[0:128], zdB[0,:,10] )
171 # plt.plot( x[0:128], zdB[0,:,10] )
170 # plt.axis([-12, 12, 15, 50])
172 # plt.axis([-12, 12, 15, 50])
171 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
173 # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) )
172 # plt.ylabel('Intensidad [dB]')
174 # plt.ylabel('Intensidad [dB]')
173 # plt.xlabel('Velocidad [m/s]')
175 # plt.xlabel('Velocidad [m/s]')
174 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
176 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
175 #
177 #
176 # plt.show()
178 # plt.show()
177 #
179 #
178 # self.indice=self.indice+1
180 # self.indice=self.indice+1
179
181
180
182
181
183
182 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
184 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
183 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
185 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
184
186
185 if not self.isConfig:
187 if not self.isConfig:
186
188
187 nplots = len(channelIndexList)
189 nplots = len(channelIndexList)
188
190
189 self.setup(id=id,
191 self.setup(id=id,
190 nplots=nplots,
192 nplots=nplots,
191 wintitle=wintitle,
193 wintitle=wintitle,
192 showprofile=showprofile,
194 showprofile=showprofile,
193 show=show)
195 show=show)
194
196
195 if xmin == None: xmin = numpy.nanmin(x)
197 if xmin == None: xmin = numpy.nanmin(x)
196 if xmax == None: xmax = numpy.nanmax(x)
198 if xmax == None: xmax = numpy.nanmax(x)
197 if ymin == None: ymin = numpy.nanmin(y)
199 if ymin == None: ymin = numpy.nanmin(y)
198 if ymax == None: ymax = numpy.nanmax(y)
200 if ymax == None: ymax = numpy.nanmax(y)
199 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
201 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
200 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
202 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
201
203
202 self.FTP_WEI = ftp_wei
204 self.FTP_WEI = ftp_wei
203 self.EXP_CODE = exp_code
205 self.EXP_CODE = exp_code
204 self.SUB_EXP_CODE = sub_exp_code
206 self.SUB_EXP_CODE = sub_exp_code
205 self.PLOT_POS = plot_pos
207 self.PLOT_POS = plot_pos
206
208
207 self.isConfig = True
209 self.isConfig = True
208
210
209 self.setWinTitle(title)
211 self.setWinTitle(title)
210
212
211 for i in range(self.nplots):
213 for i in range(self.nplots):
212 index = channelIndexList[i]
214 index = channelIndexList[i]
213 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
215 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
214 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
216 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
215 if len(dataOut.beam.codeList) != 0:
217 if len(dataOut.beam.codeList) != 0:
216 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)
218 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
217
219
218 axes = self.axesList[i*self.__nsubplots]
220 axes = self.axesList[i*self.__nsubplots]
219 axes.pcolor(x, y, zdB[index,:,:],
221 axes.pcolor(x, y, zdB[index,:,:],
220 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
222 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
221 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
223 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
222 ticksize=9, cblabel='')
224 ticksize=9, cblabel='')
223
225
224 if self.__showprofile:
226 if self.__showprofile:
225 axes = self.axesList[i*self.__nsubplots +1]
227 axes = self.axesList[i*self.__nsubplots +1]
226 axes.pline(avgdB[index,:], y,
228 axes.pline(avgdB[index,:], y,
227 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
229 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
228 xlabel='dB', ylabel='', title='',
230 xlabel='dB', ylabel='', title='',
229 ytick_visible=False,
231 ytick_visible=False,
230 grid='x')
232 grid='x')
231
233
232 noiseline = numpy.repeat(noisedB[index], len(y))
234 noiseline = numpy.repeat(noisedB[index], len(y))
233 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
235 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
234
236
235 self.draw()
237 self.draw()
236
238
237 if figfile == None:
239 if figfile == None:
238 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
240 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
239 name = str_datetime
241 name = str_datetime
240 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
242 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
241 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
243 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
242 figfile = self.getFilename(name)
244 figfile = self.getFilename(name)
243
245
244 self.save(figpath=figpath,
246 self.save(figpath=figpath,
245 figfile=figfile,
247 figfile=figfile,
246 save=save,
248 save=save,
247 ftp=ftp,
249 ftp=ftp,
248 wr_period=wr_period,
250 wr_period=wr_period,
249 thisDatetime=thisDatetime)
251 thisDatetime=thisDatetime)
250
252
251
253
252 class CrossSpectraPlot(Figure):
254 class CrossSpectraPlot(Figure):
253
255
254 isConfig = None
256 isConfig = None
255 __nsubplots = None
257 __nsubplots = None
256
258
257 WIDTH = None
259 WIDTH = None
258 HEIGHT = None
260 HEIGHT = None
259 WIDTHPROF = None
261 WIDTHPROF = None
260 HEIGHTPROF = None
262 HEIGHTPROF = None
261 PREFIX = 'cspc'
263 PREFIX = 'cspc'
262
264
263 def __init__(self, **kwargs):
265 def __init__(self, **kwargs):
264 Figure.__init__(self, **kwargs)
266 Figure.__init__(self, **kwargs)
265 self.isConfig = False
267 self.isConfig = False
266 self.__nsubplots = 4
268 self.__nsubplots = 4
267 self.counter_imagwr = 0
269 self.counter_imagwr = 0
268 self.WIDTH = 250
270 self.WIDTH = 250
269 self.HEIGHT = 250
271 self.HEIGHT = 250
270 self.WIDTHPROF = 0
272 self.WIDTHPROF = 0
271 self.HEIGHTPROF = 0
273 self.HEIGHTPROF = 0
272
274
273 self.PLOT_CODE = CROSS_CODE
275 self.PLOT_CODE = CROSS_CODE
274 self.FTP_WEI = None
276 self.FTP_WEI = None
275 self.EXP_CODE = None
277 self.EXP_CODE = None
276 self.SUB_EXP_CODE = None
278 self.SUB_EXP_CODE = None
277 self.PLOT_POS = None
279 self.PLOT_POS = None
278
280
279 self.indice=0
281 self.indice=0
280
282
281 def getSubplots(self):
283 def getSubplots(self):
282
284
283 ncol = 4
285 ncol = 4
284 nrow = self.nplots
286 nrow = self.nplots
285
287
286 return nrow, ncol
288 return nrow, ncol
287
289
288 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
290 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
289
291
290 self.__showprofile = showprofile
292 self.__showprofile = showprofile
291 self.nplots = nplots
293 self.nplots = nplots
292
294
293 ncolspan = 1
295 ncolspan = 1
294 colspan = 1
296 colspan = 1
295
297
296 self.createFigure(id = id,
298 self.createFigure(id = id,
297 wintitle = wintitle,
299 wintitle = wintitle,
298 widthplot = self.WIDTH + self.WIDTHPROF,
300 widthplot = self.WIDTH + self.WIDTHPROF,
299 heightplot = self.HEIGHT + self.HEIGHTPROF,
301 heightplot = self.HEIGHT + self.HEIGHTPROF,
300 show=True)
302 show=True)
301
303
302 nrow, ncol = self.getSubplots()
304 nrow, ncol = self.getSubplots()
303
305
304 counter = 0
306 counter = 0
305 for y in range(nrow):
307 for y in range(nrow):
306 for x in range(ncol):
308 for x in range(ncol):
307 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
309 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
308
310
309 counter += 1
311 counter += 1
310
312
311 def run(self, dataOut, id, wintitle="", pairsList=None,
313 def run(self, dataOut, id, wintitle="", pairsList=None,
312 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
314 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
313 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
315 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
314 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
316 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
315 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
317 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
316 server=None, folder=None, username=None, password=None,
318 server=None, folder=None, username=None, password=None,
317 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
319 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
318 xaxis='frequency'):
320 xaxis='frequency'):
319
321
320 """
322 """
321
323
322 Input:
324 Input:
323 dataOut :
325 dataOut :
324 id :
326 id :
325 wintitle :
327 wintitle :
326 channelList :
328 channelList :
327 showProfile :
329 showProfile :
328 xmin : None,
330 xmin : None,
329 xmax : None,
331 xmax : None,
330 ymin : None,
332 ymin : None,
331 ymax : None,
333 ymax : None,
332 zmin : None,
334 zmin : None,
333 zmax : None
335 zmax : None
334 """
336 """
335
337
336 if pairsList == None:
338 if pairsList == None:
337 pairsIndexList = dataOut.pairsIndexList
339 pairsIndexList = dataOut.pairsIndexList
338 else:
340 else:
339 pairsIndexList = []
341 pairsIndexList = []
340 for pair in pairsList:
342 for pair in pairsList:
341 if pair not in dataOut.pairsList:
343 if pair not in dataOut.pairsList:
342 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
344 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
343 pairsIndexList.append(dataOut.pairsList.index(pair))
345 pairsIndexList.append(dataOut.pairsList.index(pair))
344
346
345 if not pairsIndexList:
347 if not pairsIndexList:
346 return
348 return
347
349
348 if len(pairsIndexList) > 4:
350 if len(pairsIndexList) > 4:
349 pairsIndexList = pairsIndexList[0:4]
351 pairsIndexList = pairsIndexList[0:4]
350
352
351 if normFactor is None:
353 if normFactor is None:
352 factor = dataOut.normFactor
354 factor = dataOut.normFactor
353 else:
355 else:
354 factor = normFactor
356 factor = normFactor
355 x = dataOut.getVelRange(1)
357 x = dataOut.getVelRange(1)
356 y = dataOut.getHeiRange()
358 y = dataOut.getHeiRange()
357 z = dataOut.data_spc[:,:,:]/factor
359 z = dataOut.data_spc[:,:,:]/factor
358 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
360 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
359
361
360 noise = dataOut.noise/factor
362 noise = dataOut.noise/factor
361
363
362 zdB = 10*numpy.log10(z)
364 zdB = 10*numpy.log10(z)
363 noisedB = 10*numpy.log10(noise)
365 noisedB = 10*numpy.log10(noise)
364
366
365 if coh_min == None:
367 if coh_min == None:
366 coh_min = 0.0
368 coh_min = 0.0
367 if coh_max == None:
369 if coh_max == None:
368 coh_max = 1.0
370 coh_max = 1.0
369
371
370 if phase_min == None:
372 if phase_min == None:
371 phase_min = -180
373 phase_min = -180
372 if phase_max == None:
374 if phase_max == None:
373 phase_max = 180
375 phase_max = 180
374
376
375 #thisDatetime = dataOut.datatime
377 #thisDatetime = dataOut.datatime
376 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
378 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
377 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
379 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
378 # xlabel = "Velocity (m/s)"
380 # xlabel = "Velocity (m/s)"
379 ylabel = "Range (Km)"
381 ylabel = "Range (Km)"
380
382
381 if xaxis == "frequency":
383 if xaxis == "frequency":
382 x = dataOut.getFreqRange(1)/1000.
384 x = dataOut.getFreqRange(1)/1000.
383 xlabel = "Frequency (kHz)"
385 xlabel = "Frequency (kHz)"
384
386
385 elif xaxis == "time":
387 elif xaxis == "time":
386 x = dataOut.getAcfRange(1)
388 x = dataOut.getAcfRange(1)
387 xlabel = "Time (ms)"
389 xlabel = "Time (ms)"
388
390
389 else:
391 else:
390 x = dataOut.getVelRange(1)
392 x = dataOut.getVelRange(1)
391 xlabel = "Velocity (m/s)"
393 xlabel = "Velocity (m/s)"
392
394
393 if not self.isConfig:
395 if not self.isConfig:
394
396
395 nplots = len(pairsIndexList)
397 nplots = len(pairsIndexList)
396
398
397 self.setup(id=id,
399 self.setup(id=id,
398 nplots=nplots,
400 nplots=nplots,
399 wintitle=wintitle,
401 wintitle=wintitle,
400 showprofile=False,
402 showprofile=False,
401 show=show)
403 show=show)
402
404
403 avg = numpy.abs(numpy.average(z, axis=1))
405 avg = numpy.abs(numpy.average(z, axis=1))
404 avgdB = 10*numpy.log10(avg)
406 avgdB = 10*numpy.log10(avg)
405
407
406 if xmin == None: xmin = numpy.nanmin(x)
408 if xmin == None: xmin = numpy.nanmin(x)
407 if xmax == None: xmax = numpy.nanmax(x)
409 if xmax == None: xmax = numpy.nanmax(x)
408 if ymin == None: ymin = numpy.nanmin(y)
410 if ymin == None: ymin = numpy.nanmin(y)
409 if ymax == None: ymax = numpy.nanmax(y)
411 if ymax == None: ymax = numpy.nanmax(y)
410 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
412 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
411 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
413 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
412
414
413 self.FTP_WEI = ftp_wei
415 self.FTP_WEI = ftp_wei
414 self.EXP_CODE = exp_code
416 self.EXP_CODE = exp_code
415 self.SUB_EXP_CODE = sub_exp_code
417 self.SUB_EXP_CODE = sub_exp_code
416 self.PLOT_POS = plot_pos
418 self.PLOT_POS = plot_pos
417
419
418 self.isConfig = True
420 self.isConfig = True
419
421
420 self.setWinTitle(title)
422 self.setWinTitle(title)
421
423
422
424
423 for i in range(self.nplots):
425 for i in range(self.nplots):
424 pair = dataOut.pairsList[pairsIndexList[i]]
426 pair = dataOut.pairsList[pairsIndexList[i]]
425
427
426 chan_index0 = dataOut.channelList.index(pair[0])
428 chan_index0 = dataOut.channelList.index(pair[0])
427 chan_index1 = dataOut.channelList.index(pair[1])
429 chan_index1 = dataOut.channelList.index(pair[1])
428
430
429 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
431 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
430 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
432 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
431 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
433 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
432 axes0 = self.axesList[i*self.__nsubplots]
434 axes0 = self.axesList[i*self.__nsubplots]
433 axes0.pcolor(x, y, zdB,
435 axes0.pcolor(x, y, zdB,
434 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
436 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
435 xlabel=xlabel, ylabel=ylabel, title=title,
437 xlabel=xlabel, ylabel=ylabel, title=title,
436 ticksize=9, colormap=power_cmap, cblabel='')
438 ticksize=9, colormap=power_cmap, cblabel='')
437
439
438 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
440 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
439 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
441 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
440 axes0 = self.axesList[i*self.__nsubplots+1]
442 axes0 = self.axesList[i*self.__nsubplots+1]
441 axes0.pcolor(x, y, zdB,
443 axes0.pcolor(x, y, zdB,
442 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
444 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
443 xlabel=xlabel, ylabel=ylabel, title=title,
445 xlabel=xlabel, ylabel=ylabel, title=title,
444 ticksize=9, colormap=power_cmap, cblabel='')
446 ticksize=9, colormap=power_cmap, cblabel='')
445
447
446 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
448 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] )
447 coherence = numpy.abs(coherenceComplex)
449 coherence = numpy.abs(coherenceComplex)
448 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
450 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
449 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
451 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
450
452
451
453
452
454
453
455
454 # #print 'FASE', numpy.shape(phase), y[25]
456 # #print 'FASE', numpy.shape(phase), y[25]
455 # fig = plt.figure(10+self.indice)
457 # fig = plt.figure(10+self.indice)
456 # #plt.plot( x[0:256],coherence[:,25] )
458 # #plt.plot( x[0:256],coherence[:,25] )
457 # cohAv = numpy.average(coherence,1)
459 # cohAv = numpy.average(coherence,1)
458 #
460 #
459 # plt.plot( x[0:256],cohAv )
461 # plt.plot( x[0:256],cohAv )
460 # #plt.axis([-12, 12, 15, 50])
462 # #plt.axis([-12, 12, 15, 50])
461 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
463 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
462 # plt.ylabel('Desfase [grados]')
464 # plt.ylabel('Desfase [grados]')
463 # plt.xlabel('Velocidad [m/s]')
465 # plt.xlabel('Velocidad [m/s]')
464 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
466 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
465 #
467 #
466 # plt.show()
468 # plt.show()
467 # self.indice=self.indice+1
469 # self.indice=self.indice+1
468
470
469
471
470 # print 'FASE', numpy.shape(phase), y[25]
472 # print 'FASE', numpy.shape(phase), y[25]
471 # fig = plt.figure(10+self.indice)
473 # fig = plt.figure(10+self.indice)
472 # plt.plot( x[0:256],phase[:,25] )
474 # plt.plot( x[0:256],phase[:,25] )
473 # #plt.axis([-12, 12, 15, 50])
475 # #plt.axis([-12, 12, 15, 50])
474 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
476 # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
475 # plt.ylabel('Desfase [grados]')
477 # plt.ylabel('Desfase [grados]')
476 # plt.xlabel('Velocidad [m/s]')
478 # plt.xlabel('Velocidad [m/s]')
477 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
479 # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice))
478 #
480 #
479 # plt.show()
481 # plt.show()
480 # self.indice=self.indice+1
482 # self.indice=self.indice+1
481
483
482
484
483
485
484
486
485 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
487 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
486 axes0 = self.axesList[i*self.__nsubplots+2]
488 axes0 = self.axesList[i*self.__nsubplots+2]
487 axes0.pcolor(x, y, coherence,
489 axes0.pcolor(x, y, coherence,
488 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
490 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
489 xlabel=xlabel, ylabel=ylabel, title=title,
491 xlabel=xlabel, ylabel=ylabel, title=title,
490 ticksize=9, colormap=coherence_cmap, cblabel='')
492 ticksize=9, colormap=coherence_cmap, cblabel='')
491
493
492 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
494 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
493 axes0 = self.axesList[i*self.__nsubplots+3]
495 axes0 = self.axesList[i*self.__nsubplots+3]
494 axes0.pcolor(x, y, phase,
496 axes0.pcolor(x, y, phase,
495 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
497 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
496 xlabel=xlabel, ylabel=ylabel, title=title,
498 xlabel=xlabel, ylabel=ylabel, title=title,
497 ticksize=9, colormap=phase_cmap, cblabel='')
499 ticksize=9, colormap=phase_cmap, cblabel='')
498
500
499
501
500
502
501 self.draw()
503 self.draw()
502
504
503 self.save(figpath=figpath,
505 self.save(figpath=figpath,
504 figfile=figfile,
506 figfile=figfile,
505 save=save,
507 save=save,
506 ftp=ftp,
508 ftp=ftp,
507 wr_period=wr_period,
509 wr_period=wr_period,
508 thisDatetime=thisDatetime)
510 thisDatetime=thisDatetime)
509
511
510
512
511 class RTIPlot(Figure):
513 class RTIPlot(Figure):
512
514
513 __isConfig = None
515 __isConfig = None
514 __nsubplots = None
516 __nsubplots = None
515
517
516 WIDTHPROF = None
518 WIDTHPROF = None
517 HEIGHTPROF = None
519 HEIGHTPROF = None
518 PREFIX = 'rti'
520 PREFIX = 'rti'
519
521
520 def __init__(self, **kwargs):
522 def __init__(self, **kwargs):
521
523
522 Figure.__init__(self, **kwargs)
524 Figure.__init__(self, **kwargs)
523 self.timerange = None
525 self.timerange = None
524 self.isConfig = False
526 self.isConfig = False
525 self.__nsubplots = 1
527 self.__nsubplots = 1
526
528
527 self.WIDTH = 800
529 self.WIDTH = 800
528 self.HEIGHT = 250
530 self.HEIGHT = 250
529 self.WIDTHPROF = 120
531 self.WIDTHPROF = 120
530 self.HEIGHTPROF = 0
532 self.HEIGHTPROF = 0
531 self.counter_imagwr = 0
533 self.counter_imagwr = 0
532
534
533 self.PLOT_CODE = RTI_CODE
535 self.PLOT_CODE = RTI_CODE
534
536
535 self.FTP_WEI = None
537 self.FTP_WEI = None
536 self.EXP_CODE = None
538 self.EXP_CODE = None
537 self.SUB_EXP_CODE = None
539 self.SUB_EXP_CODE = None
538 self.PLOT_POS = None
540 self.PLOT_POS = None
539 self.tmin = None
541 self.tmin = None
540 self.tmax = None
542 self.tmax = None
541
543
542 self.xmin = None
544 self.xmin = None
543 self.xmax = None
545 self.xmax = None
544
546
545 self.figfile = None
547 self.figfile = None
546
548
547 def getSubplots(self):
549 def getSubplots(self):
548
550
549 ncol = 1
551 ncol = 1
550 nrow = self.nplots
552 nrow = self.nplots
551
553
552 return nrow, ncol
554 return nrow, ncol
553
555
554 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
556 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
555
557
556 self.__showprofile = showprofile
558 self.__showprofile = showprofile
557 self.nplots = nplots
559 self.nplots = nplots
558
560
559 ncolspan = 1
561 ncolspan = 1
560 colspan = 1
562 colspan = 1
561 if showprofile:
563 if showprofile:
562 ncolspan = 7
564 ncolspan = 7
563 colspan = 6
565 colspan = 6
564 self.__nsubplots = 2
566 self.__nsubplots = 2
565
567
566 self.createFigure(id = id,
568 self.createFigure(id = id,
567 wintitle = wintitle,
569 wintitle = wintitle,
568 widthplot = self.WIDTH + self.WIDTHPROF,
570 widthplot = self.WIDTH + self.WIDTHPROF,
569 heightplot = self.HEIGHT + self.HEIGHTPROF,
571 heightplot = self.HEIGHT + self.HEIGHTPROF,
570 show=show)
572 show=show)
571
573
572 nrow, ncol = self.getSubplots()
574 nrow, ncol = self.getSubplots()
573
575
574 counter = 0
576 counter = 0
575 for y in range(nrow):
577 for y in range(nrow):
576 for x in range(ncol):
578 for x in range(ncol):
577
579
578 if counter >= self.nplots:
580 if counter >= self.nplots:
579 break
581 break
580
582
581 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
583 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
582
584
583 if showprofile:
585 if showprofile:
584 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
586 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
585
587
586 counter += 1
588 counter += 1
587
589
588 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
590 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
589 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
591 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
590 timerange=None, colormap='jet',
592 timerange=None, colormap='jet',
591 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
593 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
592 server=None, folder=None, username=None, password=None,
594 server=None, folder=None, username=None, password=None,
593 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
595 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
594
596
595 """
597 """
596
598
597 Input:
599 Input:
598 dataOut :
600 dataOut :
599 id :
601 id :
600 wintitle :
602 wintitle :
601 channelList :
603 channelList :
602 showProfile :
604 showProfile :
603 xmin : None,
605 xmin : None,
604 xmax : None,
606 xmax : None,
605 ymin : None,
607 ymin : None,
606 ymax : None,
608 ymax : None,
607 zmin : None,
609 zmin : None,
608 zmax : None
610 zmax : None
609 """
611 """
610
612
611 #colormap = kwargs.get('colormap', 'jet')
613 #colormap = kwargs.get('colormap', 'jet')
612 if HEIGHT is not None:
614 if HEIGHT is not None:
613 self.HEIGHT = HEIGHT
615 self.HEIGHT = HEIGHT
614
616
615 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
617 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
616 return
618 return
617
619
618 if channelList == None:
620 if channelList == None:
619 channelIndexList = dataOut.channelIndexList
621 channelIndexList = dataOut.channelIndexList
620 else:
622 else:
621 channelIndexList = []
623 channelIndexList = []
622 for channel in channelList:
624 for channel in channelList:
623 if channel not in dataOut.channelList:
625 if channel not in dataOut.channelList:
624 raise ValueError, "Channel %d is not in dataOut.channelList"
626 raise ValueError, "Channel %d is not in dataOut.channelList"
625 channelIndexList.append(dataOut.channelList.index(channel))
627 channelIndexList.append(dataOut.channelList.index(channel))
626
628
627 if normFactor is None:
629 if normFactor is None:
628 factor = dataOut.normFactor
630 factor = dataOut.normFactor
629 else:
631 else:
630 factor = normFactor
632 factor = normFactor
631
633
632 # factor = dataOut.normFactor
634 # factor = dataOut.normFactor
633 x = dataOut.getTimeRange()
635 x = dataOut.getTimeRange()
634 y = dataOut.getHeiRange()
636 y = dataOut.getHeiRange()
635
637
636 z = dataOut.data_spc/factor
638 z = dataOut.data_spc/factor
637 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
639 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
638 avg = numpy.average(z, axis=1)
640 avg = numpy.average(z, axis=1)
639 avgdB = 10.*numpy.log10(avg)
641 avgdB = 10.*numpy.log10(avg)
640 # avgdB = dataOut.getPower()
642 # avgdB = dataOut.getPower()
641
643
642
644
643 thisDatetime = dataOut.datatime
645 thisDatetime = dataOut.datatime
644 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
646 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
645 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
647 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
646 xlabel = ""
648 xlabel = ""
647 ylabel = "Range (Km)"
649 ylabel = "Range (Km)"
648
650
649 update_figfile = False
651 update_figfile = False
650
652
651 if dataOut.ltctime >= self.xmax:
653 if dataOut.ltctime >= self.xmax:
652 self.counter_imagwr = wr_period
654 self.counter_imagwr = wr_period
653 self.isConfig = False
655 self.isConfig = False
654 update_figfile = True
656 update_figfile = True
655
657
656 if not self.isConfig:
658 if not self.isConfig:
657
659
658 nplots = len(channelIndexList)
660 nplots = len(channelIndexList)
659
661
660 self.setup(id=id,
662 self.setup(id=id,
661 nplots=nplots,
663 nplots=nplots,
662 wintitle=wintitle,
664 wintitle=wintitle,
663 showprofile=showprofile,
665 showprofile=showprofile,
664 show=show)
666 show=show)
665
667
666 if timerange != None:
668 if timerange != None:
667 self.timerange = timerange
669 self.timerange = timerange
668
670
669 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
671 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
670
672
671 noise = dataOut.noise/factor
673 noise = dataOut.noise/factor
672 noisedB = 10*numpy.log10(noise)
674 noisedB = 10*numpy.log10(noise)
673
675
674 if ymin == None: ymin = numpy.nanmin(y)
676 if ymin == None: ymin = numpy.nanmin(y)
675 if ymax == None: ymax = numpy.nanmax(y)
677 if ymax == None: ymax = numpy.nanmax(y)
676 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
678 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
677 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
679 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
678
680
679 self.FTP_WEI = ftp_wei
681 self.FTP_WEI = ftp_wei
680 self.EXP_CODE = exp_code
682 self.EXP_CODE = exp_code
681 self.SUB_EXP_CODE = sub_exp_code
683 self.SUB_EXP_CODE = sub_exp_code
682 self.PLOT_POS = plot_pos
684 self.PLOT_POS = plot_pos
683
685
684 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
686 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
685 self.isConfig = True
687 self.isConfig = True
686 self.figfile = figfile
688 self.figfile = figfile
687 update_figfile = True
689 update_figfile = True
688
690
689 self.setWinTitle(title)
691 self.setWinTitle(title)
690
692
691 for i in range(self.nplots):
693 for i in range(self.nplots):
692 index = channelIndexList[i]
694 index = channelIndexList[i]
693 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
695 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
694 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
696 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
695 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
697 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
696 axes = self.axesList[i*self.__nsubplots]
698 axes = self.axesList[i*self.__nsubplots]
697 zdB = avgdB[index].reshape((1,-1))
699 zdB = avgdB[index].reshape((1,-1))
698 axes.pcolorbuffer(x, y, zdB,
700 axes.pcolorbuffer(x, y, zdB,
699 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
701 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
700 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
702 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
701 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
703 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
702
704
703 if self.__showprofile:
705 if self.__showprofile:
704 axes = self.axesList[i*self.__nsubplots +1]
706 axes = self.axesList[i*self.__nsubplots +1]
705 axes.pline(avgdB[index], y,
707 axes.pline(avgdB[index], y,
706 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
708 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
707 xlabel='dB', ylabel='', title='',
709 xlabel='dB', ylabel='', title='',
708 ytick_visible=False,
710 ytick_visible=False,
709 grid='x')
711 grid='x')
710
712
711 self.draw()
713 self.draw()
712
714
713 self.save(figpath=figpath,
715 self.save(figpath=figpath,
714 figfile=figfile,
716 figfile=figfile,
715 save=save,
717 save=save,
716 ftp=ftp,
718 ftp=ftp,
717 wr_period=wr_period,
719 wr_period=wr_period,
718 thisDatetime=thisDatetime,
720 thisDatetime=thisDatetime,
719 update_figfile=update_figfile)
721 update_figfile=update_figfile)
720
722
721 class CoherenceMap(Figure):
723 class CoherenceMap(Figure):
722 isConfig = None
724 isConfig = None
723 __nsubplots = None
725 __nsubplots = None
724
726
725 WIDTHPROF = None
727 WIDTHPROF = None
726 HEIGHTPROF = None
728 HEIGHTPROF = None
727 PREFIX = 'cmap'
729 PREFIX = 'cmap'
728
730
729 def __init__(self, **kwargs):
731 def __init__(self, **kwargs):
730 Figure.__init__(self, **kwargs)
732 Figure.__init__(self, **kwargs)
731 self.timerange = 2*60*60
733 self.timerange = 2*60*60
732 self.isConfig = False
734 self.isConfig = False
733 self.__nsubplots = 1
735 self.__nsubplots = 1
734
736
735 self.WIDTH = 800
737 self.WIDTH = 800
736 self.HEIGHT = 180
738 self.HEIGHT = 180
737 self.WIDTHPROF = 120
739 self.WIDTHPROF = 120
738 self.HEIGHTPROF = 0
740 self.HEIGHTPROF = 0
739 self.counter_imagwr = 0
741 self.counter_imagwr = 0
740
742
741 self.PLOT_CODE = COH_CODE
743 self.PLOT_CODE = COH_CODE
742
744
743 self.FTP_WEI = None
745 self.FTP_WEI = None
744 self.EXP_CODE = None
746 self.EXP_CODE = None
745 self.SUB_EXP_CODE = None
747 self.SUB_EXP_CODE = None
746 self.PLOT_POS = None
748 self.PLOT_POS = None
747 self.counter_imagwr = 0
749 self.counter_imagwr = 0
748
750
749 self.xmin = None
751 self.xmin = None
750 self.xmax = None
752 self.xmax = None
751
753
752 def getSubplots(self):
754 def getSubplots(self):
753 ncol = 1
755 ncol = 1
754 nrow = self.nplots*2
756 nrow = self.nplots*2
755
757
756 return nrow, ncol
758 return nrow, ncol
757
759
758 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
760 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
759 self.__showprofile = showprofile
761 self.__showprofile = showprofile
760 self.nplots = nplots
762 self.nplots = nplots
761
763
762 ncolspan = 1
764 ncolspan = 1
763 colspan = 1
765 colspan = 1
764 if showprofile:
766 if showprofile:
765 ncolspan = 7
767 ncolspan = 7
766 colspan = 6
768 colspan = 6
767 self.__nsubplots = 2
769 self.__nsubplots = 2
768
770
769 self.createFigure(id = id,
771 self.createFigure(id = id,
770 wintitle = wintitle,
772 wintitle = wintitle,
771 widthplot = self.WIDTH + self.WIDTHPROF,
773 widthplot = self.WIDTH + self.WIDTHPROF,
772 heightplot = self.HEIGHT + self.HEIGHTPROF,
774 heightplot = self.HEIGHT + self.HEIGHTPROF,
773 show=True)
775 show=True)
774
776
775 nrow, ncol = self.getSubplots()
777 nrow, ncol = self.getSubplots()
776
778
777 for y in range(nrow):
779 for y in range(nrow):
778 for x in range(ncol):
780 for x in range(ncol):
779
781
780 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
782 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
781
783
782 if showprofile:
784 if showprofile:
783 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
785 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
784
786
785 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
787 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
786 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
788 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
787 timerange=None, phase_min=None, phase_max=None,
789 timerange=None, phase_min=None, phase_max=None,
788 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
790 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
789 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
791 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
790 server=None, folder=None, username=None, password=None,
792 server=None, folder=None, username=None, password=None,
791 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
793 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
792
794
793 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
795 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
794 return
796 return
795
797
796 if pairsList == None:
798 if pairsList == None:
797 pairsIndexList = dataOut.pairsIndexList
799 pairsIndexList = dataOut.pairsIndexList
798 else:
800 else:
799 pairsIndexList = []
801 pairsIndexList = []
800 for pair in pairsList:
802 for pair in pairsList:
801 if pair not in dataOut.pairsList:
803 if pair not in dataOut.pairsList:
802 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
804 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
803 pairsIndexList.append(dataOut.pairsList.index(pair))
805 pairsIndexList.append(dataOut.pairsList.index(pair))
804
806
805 if pairsIndexList == []:
807 if pairsIndexList == []:
806 return
808 return
807
809
808 if len(pairsIndexList) > 4:
810 if len(pairsIndexList) > 4:
809 pairsIndexList = pairsIndexList[0:4]
811 pairsIndexList = pairsIndexList[0:4]
810
812
811 if phase_min == None:
813 if phase_min == None:
812 phase_min = -180
814 phase_min = -180
813 if phase_max == None:
815 if phase_max == None:
814 phase_max = 180
816 phase_max = 180
815
817
816 x = dataOut.getTimeRange()
818 x = dataOut.getTimeRange()
817 y = dataOut.getHeiRange()
819 y = dataOut.getHeiRange()
818
820
819 thisDatetime = dataOut.datatime
821 thisDatetime = dataOut.datatime
820
822
821 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
823 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
822 xlabel = ""
824 xlabel = ""
823 ylabel = "Range (Km)"
825 ylabel = "Range (Km)"
824 update_figfile = False
826 update_figfile = False
825
827
826 if not self.isConfig:
828 if not self.isConfig:
827 nplots = len(pairsIndexList)
829 nplots = len(pairsIndexList)
828 self.setup(id=id,
830 self.setup(id=id,
829 nplots=nplots,
831 nplots=nplots,
830 wintitle=wintitle,
832 wintitle=wintitle,
831 showprofile=showprofile,
833 showprofile=showprofile,
832 show=show)
834 show=show)
833
835
834 if timerange != None:
836 if timerange != None:
835 self.timerange = timerange
837 self.timerange = timerange
836
838
837 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
839 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
838
840
839 if ymin == None: ymin = numpy.nanmin(y)
841 if ymin == None: ymin = numpy.nanmin(y)
840 if ymax == None: ymax = numpy.nanmax(y)
842 if ymax == None: ymax = numpy.nanmax(y)
841 if zmin == None: zmin = 0.
843 if zmin == None: zmin = 0.
842 if zmax == None: zmax = 1.
844 if zmax == None: zmax = 1.
843
845
844 self.FTP_WEI = ftp_wei
846 self.FTP_WEI = ftp_wei
845 self.EXP_CODE = exp_code
847 self.EXP_CODE = exp_code
846 self.SUB_EXP_CODE = sub_exp_code
848 self.SUB_EXP_CODE = sub_exp_code
847 self.PLOT_POS = plot_pos
849 self.PLOT_POS = plot_pos
848
850
849 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
851 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
850
852
851 self.isConfig = True
853 self.isConfig = True
852 update_figfile = True
854 update_figfile = True
853
855
854 self.setWinTitle(title)
856 self.setWinTitle(title)
855
857
856 for i in range(self.nplots):
858 for i in range(self.nplots):
857
859
858 pair = dataOut.pairsList[pairsIndexList[i]]
860 pair = dataOut.pairsList[pairsIndexList[i]]
859
861
860 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
862 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
861 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
863 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
862 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
864 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
863
865
864
866
865 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
867 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
866 coherence = numpy.abs(avgcoherenceComplex)
868 coherence = numpy.abs(avgcoherenceComplex)
867
869
868 z = coherence.reshape((1,-1))
870 z = coherence.reshape((1,-1))
869
871
870 counter = 0
872 counter = 0
871
873
872 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
874 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
873 axes = self.axesList[i*self.__nsubplots*2]
875 axes = self.axesList[i*self.__nsubplots*2]
874 axes.pcolorbuffer(x, y, z,
876 axes.pcolorbuffer(x, y, z,
875 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
877 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
876 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
878 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
877 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
879 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
878
880
879 if self.__showprofile:
881 if self.__showprofile:
880 counter += 1
882 counter += 1
881 axes = self.axesList[i*self.__nsubplots*2 + counter]
883 axes = self.axesList[i*self.__nsubplots*2 + counter]
882 axes.pline(coherence, y,
884 axes.pline(coherence, y,
883 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
885 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
884 xlabel='', ylabel='', title='', ticksize=7,
886 xlabel='', ylabel='', title='', ticksize=7,
885 ytick_visible=False, nxticks=5,
887 ytick_visible=False, nxticks=5,
886 grid='x')
888 grid='x')
887
889
888 counter += 1
890 counter += 1
889
891
890 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
892 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
891
893
892 z = phase.reshape((1,-1))
894 z = phase.reshape((1,-1))
893
895
894 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
896 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
895 axes = self.axesList[i*self.__nsubplots*2 + counter]
897 axes = self.axesList[i*self.__nsubplots*2 + counter]
896 axes.pcolorbuffer(x, y, z,
898 axes.pcolorbuffer(x, y, z,
897 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
899 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
898 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
900 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
899 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
901 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
900
902
901 if self.__showprofile:
903 if self.__showprofile:
902 counter += 1
904 counter += 1
903 axes = self.axesList[i*self.__nsubplots*2 + counter]
905 axes = self.axesList[i*self.__nsubplots*2 + counter]
904 axes.pline(phase, y,
906 axes.pline(phase, y,
905 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
907 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
906 xlabel='', ylabel='', title='', ticksize=7,
908 xlabel='', ylabel='', title='', ticksize=7,
907 ytick_visible=False, nxticks=4,
909 ytick_visible=False, nxticks=4,
908 grid='x')
910 grid='x')
909
911
910 self.draw()
912 self.draw()
911
913
912 if dataOut.ltctime >= self.xmax:
914 if dataOut.ltctime >= self.xmax:
913 self.counter_imagwr = wr_period
915 self.counter_imagwr = wr_period
914 self.isConfig = False
916 self.isConfig = False
915 update_figfile = True
917 update_figfile = True
916
918
917 self.save(figpath=figpath,
919 self.save(figpath=figpath,
918 figfile=figfile,
920 figfile=figfile,
919 save=save,
921 save=save,
920 ftp=ftp,
922 ftp=ftp,
921 wr_period=wr_period,
923 wr_period=wr_period,
922 thisDatetime=thisDatetime,
924 thisDatetime=thisDatetime,
923 update_figfile=update_figfile)
925 update_figfile=update_figfile)
924
926
925 class PowerProfilePlot(Figure):
927 class PowerProfilePlot(Figure):
926
928
927 isConfig = None
929 isConfig = None
928 __nsubplots = None
930 __nsubplots = None
929
931
930 WIDTHPROF = None
932 WIDTHPROF = None
931 HEIGHTPROF = None
933 HEIGHTPROF = None
932 PREFIX = 'spcprofile'
934 PREFIX = 'spcprofile'
933
935
934 def __init__(self, **kwargs):
936 def __init__(self, **kwargs):
935 Figure.__init__(self, **kwargs)
937 Figure.__init__(self, **kwargs)
936 self.isConfig = False
938 self.isConfig = False
937 self.__nsubplots = 1
939 self.__nsubplots = 1
938
940
939 self.PLOT_CODE = POWER_CODE
941 self.PLOT_CODE = POWER_CODE
940
942
941 self.WIDTH = 300
943 self.WIDTH = 300
942 self.HEIGHT = 500
944 self.HEIGHT = 500
943 self.counter_imagwr = 0
945 self.counter_imagwr = 0
944
946
945 def getSubplots(self):
947 def getSubplots(self):
946 ncol = 1
948 ncol = 1
947 nrow = 1
949 nrow = 1
948
950
949 return nrow, ncol
951 return nrow, ncol
950
952
951 def setup(self, id, nplots, wintitle, show):
953 def setup(self, id, nplots, wintitle, show):
952
954
953 self.nplots = nplots
955 self.nplots = nplots
954
956
955 ncolspan = 1
957 ncolspan = 1
956 colspan = 1
958 colspan = 1
957
959
958 self.createFigure(id = id,
960 self.createFigure(id = id,
959 wintitle = wintitle,
961 wintitle = wintitle,
960 widthplot = self.WIDTH,
962 widthplot = self.WIDTH,
961 heightplot = self.HEIGHT,
963 heightplot = self.HEIGHT,
962 show=show)
964 show=show)
963
965
964 nrow, ncol = self.getSubplots()
966 nrow, ncol = self.getSubplots()
965
967
966 counter = 0
968 counter = 0
967 for y in range(nrow):
969 for y in range(nrow):
968 for x in range(ncol):
970 for x in range(ncol):
969 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
971 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
970
972
971 def run(self, dataOut, id, wintitle="", channelList=None,
973 def run(self, dataOut, id, wintitle="", channelList=None,
972 xmin=None, xmax=None, ymin=None, ymax=None,
974 xmin=None, xmax=None, ymin=None, ymax=None,
973 save=False, figpath='./', figfile=None, show=True,
975 save=False, figpath='./', figfile=None, show=True,
974 ftp=False, wr_period=1, server=None,
976 ftp=False, wr_period=1, server=None,
975 folder=None, username=None, password=None):
977 folder=None, username=None, password=None):
976
978
977
979
978 if channelList == None:
980 if channelList == None:
979 channelIndexList = dataOut.channelIndexList
981 channelIndexList = dataOut.channelIndexList
980 channelList = dataOut.channelList
982 channelList = dataOut.channelList
981 else:
983 else:
982 channelIndexList = []
984 channelIndexList = []
983 for channel in channelList:
985 for channel in channelList:
984 if channel not in dataOut.channelList:
986 if channel not in dataOut.channelList:
985 raise ValueError, "Channel %d is not in dataOut.channelList"
987 raise ValueError, "Channel %d is not in dataOut.channelList"
986 channelIndexList.append(dataOut.channelList.index(channel))
988 channelIndexList.append(dataOut.channelList.index(channel))
987
989
988 factor = dataOut.normFactor
990 factor = dataOut.normFactor
989
991
990 y = dataOut.getHeiRange()
992 y = dataOut.getHeiRange()
991
993
992 #for voltage
994 #for voltage
993 if dataOut.type == 'Voltage':
995 if dataOut.type == 'Voltage':
994 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
996 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
995 x = x.real
997 x = x.real
996 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
998 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
997
999
998 #for spectra
1000 #for spectra
999 if dataOut.type == 'Spectra':
1001 if dataOut.type == 'Spectra':
1000 x = dataOut.data_spc[channelIndexList,:,:]/factor
1002 x = dataOut.data_spc[channelIndexList,:,:]/factor
1001 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1003 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
1002 x = numpy.average(x, axis=1)
1004 x = numpy.average(x, axis=1)
1003
1005
1004
1006
1005 xdB = 10*numpy.log10(x)
1007 xdB = 10*numpy.log10(x)
1006
1008
1007 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1009 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1008 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1010 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
1009 xlabel = "dB"
1011 xlabel = "dB"
1010 ylabel = "Range (Km)"
1012 ylabel = "Range (Km)"
1011
1013
1012 if not self.isConfig:
1014 if not self.isConfig:
1013
1015
1014 nplots = 1
1016 nplots = 1
1015
1017
1016 self.setup(id=id,
1018 self.setup(id=id,
1017 nplots=nplots,
1019 nplots=nplots,
1018 wintitle=wintitle,
1020 wintitle=wintitle,
1019 show=show)
1021 show=show)
1020
1022
1021 if ymin == None: ymin = numpy.nanmin(y)
1023 if ymin == None: ymin = numpy.nanmin(y)
1022 if ymax == None: ymax = numpy.nanmax(y)
1024 if ymax == None: ymax = numpy.nanmax(y)
1023 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1025 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
1024 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1026 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
1025
1027
1026 self.isConfig = True
1028 self.isConfig = True
1027
1029
1028 self.setWinTitle(title)
1030 self.setWinTitle(title)
1029
1031
1030 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1032 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1031 axes = self.axesList[0]
1033 axes = self.axesList[0]
1032
1034
1033 legendlabels = ["channel %d"%x for x in channelList]
1035 legendlabels = ["channel %d"%x for x in channelList]
1034 axes.pmultiline(xdB, y,
1036 axes.pmultiline(xdB, y,
1035 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1037 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1036 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1038 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1037 ytick_visible=True, nxticks=5,
1039 ytick_visible=True, nxticks=5,
1038 grid='x')
1040 grid='x')
1039
1041
1040 self.draw()
1042 self.draw()
1041
1043
1042 self.save(figpath=figpath,
1044 self.save(figpath=figpath,
1043 figfile=figfile,
1045 figfile=figfile,
1044 save=save,
1046 save=save,
1045 ftp=ftp,
1047 ftp=ftp,
1046 wr_period=wr_period,
1048 wr_period=wr_period,
1047 thisDatetime=thisDatetime)
1049 thisDatetime=thisDatetime)
1048
1050
1049 class SpectraCutPlot(Figure):
1051 class SpectraCutPlot(Figure):
1050
1052
1051 isConfig = None
1053 isConfig = None
1052 __nsubplots = None
1054 __nsubplots = None
1053
1055
1054 WIDTHPROF = None
1056 WIDTHPROF = None
1055 HEIGHTPROF = None
1057 HEIGHTPROF = None
1056 PREFIX = 'spc_cut'
1058 PREFIX = 'spc_cut'
1057
1059
1058 def __init__(self, **kwargs):
1060 def __init__(self, **kwargs):
1059 Figure.__init__(self, **kwargs)
1061 Figure.__init__(self, **kwargs)
1060 self.isConfig = False
1062 self.isConfig = False
1061 self.__nsubplots = 1
1063 self.__nsubplots = 1
1062
1064
1063 self.PLOT_CODE = POWER_CODE
1065 self.PLOT_CODE = POWER_CODE
1064
1066
1065 self.WIDTH = 700
1067 self.WIDTH = 700
1066 self.HEIGHT = 500
1068 self.HEIGHT = 500
1067 self.counter_imagwr = 0
1069 self.counter_imagwr = 0
1068
1070
1069 def getSubplots(self):
1071 def getSubplots(self):
1070 ncol = 1
1072 ncol = 1
1071 nrow = 1
1073 nrow = 1
1072
1074
1073 return nrow, ncol
1075 return nrow, ncol
1074
1076
1075 def setup(self, id, nplots, wintitle, show):
1077 def setup(self, id, nplots, wintitle, show):
1076
1078
1077 self.nplots = nplots
1079 self.nplots = nplots
1078
1080
1079 ncolspan = 1
1081 ncolspan = 1
1080 colspan = 1
1082 colspan = 1
1081
1083
1082 self.createFigure(id = id,
1084 self.createFigure(id = id,
1083 wintitle = wintitle,
1085 wintitle = wintitle,
1084 widthplot = self.WIDTH,
1086 widthplot = self.WIDTH,
1085 heightplot = self.HEIGHT,
1087 heightplot = self.HEIGHT,
1086 show=show)
1088 show=show)
1087
1089
1088 nrow, ncol = self.getSubplots()
1090 nrow, ncol = self.getSubplots()
1089
1091
1090 counter = 0
1092 counter = 0
1091 for y in range(nrow):
1093 for y in range(nrow):
1092 for x in range(ncol):
1094 for x in range(ncol):
1093 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1095 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1094
1096
1095 def run(self, dataOut, id, wintitle="", channelList=None,
1097 def run(self, dataOut, id, wintitle="", channelList=None,
1096 xmin=None, xmax=None, ymin=None, ymax=None,
1098 xmin=None, xmax=None, ymin=None, ymax=None,
1097 save=False, figpath='./', figfile=None, show=True,
1099 save=False, figpath='./', figfile=None, show=True,
1098 ftp=False, wr_period=1, server=None,
1100 ftp=False, wr_period=1, server=None,
1099 folder=None, username=None, password=None,
1101 folder=None, username=None, password=None,
1100 xaxis="frequency"):
1102 xaxis="frequency"):
1101
1103
1102
1104
1103 if channelList == None:
1105 if channelList == None:
1104 channelIndexList = dataOut.channelIndexList
1106 channelIndexList = dataOut.channelIndexList
1105 channelList = dataOut.channelList
1107 channelList = dataOut.channelList
1106 else:
1108 else:
1107 channelIndexList = []
1109 channelIndexList = []
1108 for channel in channelList:
1110 for channel in channelList:
1109 if channel not in dataOut.channelList:
1111 if channel not in dataOut.channelList:
1110 raise ValueError, "Channel %d is not in dataOut.channelList"
1112 raise ValueError, "Channel %d is not in dataOut.channelList"
1111 channelIndexList.append(dataOut.channelList.index(channel))
1113 channelIndexList.append(dataOut.channelList.index(channel))
1112
1114
1113 factor = dataOut.normFactor
1115 factor = dataOut.normFactor
1114
1116
1115 y = dataOut.getHeiRange()
1117 y = dataOut.getHeiRange()
1116
1118
1117 z = dataOut.data_spc/factor
1119 z = dataOut.data_spc/factor
1118 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1119
1121
1120 hei_index = numpy.arange(25)*3 + 20
1122 hei_index = numpy.arange(25)*3 + 20
1121
1123
1122 if xaxis == "frequency":
1124 if xaxis == "frequency":
1123 x = dataOut.getFreqRange()/1000.
1125 x = dataOut.getFreqRange()/1000.
1124 zdB = 10*numpy.log10(z[0,:,hei_index])
1126 zdB = 10*numpy.log10(z[0,:,hei_index])
1125 xlabel = "Frequency (kHz)"
1127 xlabel = "Frequency (kHz)"
1126 ylabel = "Power (dB)"
1128 ylabel = "Power (dB)"
1127
1129
1128 elif xaxis == "time":
1130 elif xaxis == "time":
1129 x = dataOut.getAcfRange()
1131 x = dataOut.getAcfRange()
1130 zdB = z[0,:,hei_index]
1132 zdB = z[0,:,hei_index]
1131 xlabel = "Time (ms)"
1133 xlabel = "Time (ms)"
1132 ylabel = "ACF"
1134 ylabel = "ACF"
1133
1135
1134 else:
1136 else:
1135 x = dataOut.getVelRange()
1137 x = dataOut.getVelRange()
1136 zdB = 10*numpy.log10(z[0,:,hei_index])
1138 zdB = 10*numpy.log10(z[0,:,hei_index])
1137 xlabel = "Velocity (m/s)"
1139 xlabel = "Velocity (m/s)"
1138 ylabel = "Power (dB)"
1140 ylabel = "Power (dB)"
1139
1141
1140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1142 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1141 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1143 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1142
1144
1143 if not self.isConfig:
1145 if not self.isConfig:
1144
1146
1145 nplots = 1
1147 nplots = 1
1146
1148
1147 self.setup(id=id,
1149 self.setup(id=id,
1148 nplots=nplots,
1150 nplots=nplots,
1149 wintitle=wintitle,
1151 wintitle=wintitle,
1150 show=show)
1152 show=show)
1151
1153
1152 if xmin == None: xmin = numpy.nanmin(x)*0.9
1154 if xmin == None: xmin = numpy.nanmin(x)*0.9
1153 if xmax == None: xmax = numpy.nanmax(x)*1.1
1155 if xmax == None: xmax = numpy.nanmax(x)*1.1
1154 if ymin == None: ymin = numpy.nanmin(zdB)
1156 if ymin == None: ymin = numpy.nanmin(zdB)
1155 if ymax == None: ymax = numpy.nanmax(zdB)
1157 if ymax == None: ymax = numpy.nanmax(zdB)
1156
1158
1157 self.isConfig = True
1159 self.isConfig = True
1158
1160
1159 self.setWinTitle(title)
1161 self.setWinTitle(title)
1160
1162
1161 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1163 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1162 axes = self.axesList[0]
1164 axes = self.axesList[0]
1163
1165
1164 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1166 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1165
1167
1166 axes.pmultilineyaxis( x, zdB,
1168 axes.pmultilineyaxis( x, zdB,
1167 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1169 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1168 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1170 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1169 ytick_visible=True, nxticks=5,
1171 ytick_visible=True, nxticks=5,
1170 grid='x')
1172 grid='x')
1171
1173
1172 self.draw()
1174 self.draw()
1173
1175
1174 self.save(figpath=figpath,
1176 self.save(figpath=figpath,
1175 figfile=figfile,
1177 figfile=figfile,
1176 save=save,
1178 save=save,
1177 ftp=ftp,
1179 ftp=ftp,
1178 wr_period=wr_period,
1180 wr_period=wr_period,
1179 thisDatetime=thisDatetime)
1181 thisDatetime=thisDatetime)
1180
1182
1181 class Noise(Figure):
1183 class Noise(Figure):
1182
1184
1183 isConfig = None
1185 isConfig = None
1184 __nsubplots = None
1186 __nsubplots = None
1185
1187
1186 PREFIX = 'noise'
1188 PREFIX = 'noise'
1187
1189
1188
1190
1189 def __init__(self, **kwargs):
1191 def __init__(self, **kwargs):
1190 Figure.__init__(self, **kwargs)
1192 Figure.__init__(self, **kwargs)
1191 self.timerange = 24*60*60
1193 self.timerange = 24*60*60
1192 self.isConfig = False
1194 self.isConfig = False
1193 self.__nsubplots = 1
1195 self.__nsubplots = 1
1194 self.counter_imagwr = 0
1196 self.counter_imagwr = 0
1195 self.WIDTH = 800
1197 self.WIDTH = 800
1196 self.HEIGHT = 400
1198 self.HEIGHT = 400
1197 self.WIDTHPROF = 120
1199 self.WIDTHPROF = 120
1198 self.HEIGHTPROF = 0
1200 self.HEIGHTPROF = 0
1199 self.xdata = None
1201 self.xdata = None
1200 self.ydata = None
1202 self.ydata = None
1201
1203
1202 self.PLOT_CODE = NOISE_CODE
1204 self.PLOT_CODE = NOISE_CODE
1203
1205
1204 self.FTP_WEI = None
1206 self.FTP_WEI = None
1205 self.EXP_CODE = None
1207 self.EXP_CODE = None
1206 self.SUB_EXP_CODE = None
1208 self.SUB_EXP_CODE = None
1207 self.PLOT_POS = None
1209 self.PLOT_POS = None
1208 self.figfile = None
1210 self.figfile = None
1209
1211
1210 self.xmin = None
1212 self.xmin = None
1211 self.xmax = None
1213 self.xmax = None
1212
1214
1213 def getSubplots(self):
1215 def getSubplots(self):
1214
1216
1215 ncol = 1
1217 ncol = 1
1216 nrow = 1
1218 nrow = 1
1217
1219
1218 return nrow, ncol
1220 return nrow, ncol
1219
1221
1220 def openfile(self, filename):
1222 def openfile(self, filename):
1221 dirname = os.path.dirname(filename)
1223 dirname = os.path.dirname(filename)
1222
1224
1223 if not os.path.exists(dirname):
1225 if not os.path.exists(dirname):
1224 os.mkdir(dirname)
1226 os.mkdir(dirname)
1225
1227
1226 f = open(filename,'w+')
1228 f = open(filename,'w+')
1227 f.write('\n\n')
1229 f.write('\n\n')
1228 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1230 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1229 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1231 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1230 f.close()
1232 f.close()
1231
1233
1232 def save_data(self, filename_phase, data, data_datetime):
1234 def save_data(self, filename_phase, data, data_datetime):
1233
1235
1234 f=open(filename_phase,'a')
1236 f=open(filename_phase,'a')
1235
1237
1236 timetuple_data = data_datetime.timetuple()
1238 timetuple_data = data_datetime.timetuple()
1237 day = str(timetuple_data.tm_mday)
1239 day = str(timetuple_data.tm_mday)
1238 month = str(timetuple_data.tm_mon)
1240 month = str(timetuple_data.tm_mon)
1239 year = str(timetuple_data.tm_year)
1241 year = str(timetuple_data.tm_year)
1240 hour = str(timetuple_data.tm_hour)
1242 hour = str(timetuple_data.tm_hour)
1241 minute = str(timetuple_data.tm_min)
1243 minute = str(timetuple_data.tm_min)
1242 second = str(timetuple_data.tm_sec)
1244 second = str(timetuple_data.tm_sec)
1243
1245
1244 data_msg = ''
1246 data_msg = ''
1245 for i in range(len(data)):
1247 for i in range(len(data)):
1246 data_msg += str(data[i]) + ' '
1248 data_msg += str(data[i]) + ' '
1247
1249
1248 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1250 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1249 f.close()
1251 f.close()
1250
1252
1251
1253
1252 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1254 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1253
1255
1254 self.__showprofile = showprofile
1256 self.__showprofile = showprofile
1255 self.nplots = nplots
1257 self.nplots = nplots
1256
1258
1257 ncolspan = 7
1259 ncolspan = 7
1258 colspan = 6
1260 colspan = 6
1259 self.__nsubplots = 2
1261 self.__nsubplots = 2
1260
1262
1261 self.createFigure(id = id,
1263 self.createFigure(id = id,
1262 wintitle = wintitle,
1264 wintitle = wintitle,
1263 widthplot = self.WIDTH+self.WIDTHPROF,
1265 widthplot = self.WIDTH+self.WIDTHPROF,
1264 heightplot = self.HEIGHT+self.HEIGHTPROF,
1266 heightplot = self.HEIGHT+self.HEIGHTPROF,
1265 show=show)
1267 show=show)
1266
1268
1267 nrow, ncol = self.getSubplots()
1269 nrow, ncol = self.getSubplots()
1268
1270
1269 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1271 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1270
1272
1271
1273
1272 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1274 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1273 xmin=None, xmax=None, ymin=None, ymax=None,
1275 xmin=None, xmax=None, ymin=None, ymax=None,
1274 timerange=None,
1276 timerange=None,
1275 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1277 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1276 server=None, folder=None, username=None, password=None,
1278 server=None, folder=None, username=None, password=None,
1277 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1279 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1278
1280
1279 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1281 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1280 return
1282 return
1281
1283
1282 if channelList == None:
1284 if channelList == None:
1283 channelIndexList = dataOut.channelIndexList
1285 channelIndexList = dataOut.channelIndexList
1284 channelList = dataOut.channelList
1286 channelList = dataOut.channelList
1285 else:
1287 else:
1286 channelIndexList = []
1288 channelIndexList = []
1287 for channel in channelList:
1289 for channel in channelList:
1288 if channel not in dataOut.channelList:
1290 if channel not in dataOut.channelList:
1289 raise ValueError, "Channel %d is not in dataOut.channelList"
1291 raise ValueError, "Channel %d is not in dataOut.channelList"
1290 channelIndexList.append(dataOut.channelList.index(channel))
1292 channelIndexList.append(dataOut.channelList.index(channel))
1291
1293
1292 x = dataOut.getTimeRange()
1294 x = dataOut.getTimeRange()
1293 #y = dataOut.getHeiRange()
1295 #y = dataOut.getHeiRange()
1294 factor = dataOut.normFactor
1296 factor = dataOut.normFactor
1295 noise = dataOut.noise[channelIndexList]/factor
1297 noise = dataOut.noise[channelIndexList]/factor
1296 noisedB = 10*numpy.log10(noise)
1298 noisedB = 10*numpy.log10(noise)
1297
1299
1298 thisDatetime = dataOut.datatime
1300 thisDatetime = dataOut.datatime
1299
1301
1300 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1302 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1301 xlabel = ""
1303 xlabel = ""
1302 ylabel = "Intensity (dB)"
1304 ylabel = "Intensity (dB)"
1303 update_figfile = False
1305 update_figfile = False
1304
1306
1305 if not self.isConfig:
1307 if not self.isConfig:
1306
1308
1307 nplots = 1
1309 nplots = 1
1308
1310
1309 self.setup(id=id,
1311 self.setup(id=id,
1310 nplots=nplots,
1312 nplots=nplots,
1311 wintitle=wintitle,
1313 wintitle=wintitle,
1312 showprofile=showprofile,
1314 showprofile=showprofile,
1313 show=show)
1315 show=show)
1314
1316
1315 if timerange != None:
1317 if timerange != None:
1316 self.timerange = timerange
1318 self.timerange = timerange
1317
1319
1318 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1320 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1319
1321
1320 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1322 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1321 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1323 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1322
1324
1323 self.FTP_WEI = ftp_wei
1325 self.FTP_WEI = ftp_wei
1324 self.EXP_CODE = exp_code
1326 self.EXP_CODE = exp_code
1325 self.SUB_EXP_CODE = sub_exp_code
1327 self.SUB_EXP_CODE = sub_exp_code
1326 self.PLOT_POS = plot_pos
1328 self.PLOT_POS = plot_pos
1327
1329
1328
1330
1329 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1331 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1330 self.isConfig = True
1332 self.isConfig = True
1331 self.figfile = figfile
1333 self.figfile = figfile
1332 self.xdata = numpy.array([])
1334 self.xdata = numpy.array([])
1333 self.ydata = numpy.array([])
1335 self.ydata = numpy.array([])
1334
1336
1335 update_figfile = True
1337 update_figfile = True
1336
1338
1337 #open file beacon phase
1339 #open file beacon phase
1338 path = '%s%03d' %(self.PREFIX, self.id)
1340 path = '%s%03d' %(self.PREFIX, self.id)
1339 noise_file = os.path.join(path,'%s.txt'%self.name)
1341 noise_file = os.path.join(path,'%s.txt'%self.name)
1340 self.filename_noise = os.path.join(figpath,noise_file)
1342 self.filename_noise = os.path.join(figpath,noise_file)
1341
1343
1342 self.setWinTitle(title)
1344 self.setWinTitle(title)
1343
1345
1344 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1346 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1345
1347
1346 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1348 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1347 axes = self.axesList[0]
1349 axes = self.axesList[0]
1348
1350
1349 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1351 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1350
1352
1351 if len(self.ydata)==0:
1353 if len(self.ydata)==0:
1352 self.ydata = noisedB.reshape(-1,1)
1354 self.ydata = noisedB.reshape(-1,1)
1353 else:
1355 else:
1354 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1356 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1355
1357
1356
1358
1357 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1359 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1358 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1360 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1359 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1361 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1360 XAxisAsTime=True, grid='both'
1362 XAxisAsTime=True, grid='both'
1361 )
1363 )
1362
1364
1363 self.draw()
1365 self.draw()
1364
1366
1365 if dataOut.ltctime >= self.xmax:
1367 if dataOut.ltctime >= self.xmax:
1366 self.counter_imagwr = wr_period
1368 self.counter_imagwr = wr_period
1367 self.isConfig = False
1369 self.isConfig = False
1368 update_figfile = True
1370 update_figfile = True
1369
1371
1370 self.save(figpath=figpath,
1372 self.save(figpath=figpath,
1371 figfile=figfile,
1373 figfile=figfile,
1372 save=save,
1374 save=save,
1373 ftp=ftp,
1375 ftp=ftp,
1374 wr_period=wr_period,
1376 wr_period=wr_period,
1375 thisDatetime=thisDatetime,
1377 thisDatetime=thisDatetime,
1376 update_figfile=update_figfile)
1378 update_figfile=update_figfile)
1377
1379
1378 #store data beacon phase
1380 #store data beacon phase
1379 if save:
1381 if save:
1380 self.save_data(self.filename_noise, noisedB, thisDatetime)
1382 self.save_data(self.filename_noise, noisedB, thisDatetime)
1381
1383
1382 class BeaconPhase(Figure):
1384 class BeaconPhase(Figure):
1383
1385
1384 __isConfig = None
1386 __isConfig = None
1385 __nsubplots = None
1387 __nsubplots = None
1386
1388
1387 PREFIX = 'beacon_phase'
1389 PREFIX = 'beacon_phase'
1388
1390
1389 def __init__(self, **kwargs):
1391 def __init__(self, **kwargs):
1390 Figure.__init__(self, **kwargs)
1392 Figure.__init__(self, **kwargs)
1391 self.timerange = 24*60*60
1393 self.timerange = 24*60*60
1392 self.isConfig = False
1394 self.isConfig = False
1393 self.__nsubplots = 1
1395 self.__nsubplots = 1
1394 self.counter_imagwr = 0
1396 self.counter_imagwr = 0
1395 self.WIDTH = 800
1397 self.WIDTH = 800
1396 self.HEIGHT = 400
1398 self.HEIGHT = 400
1397 self.WIDTHPROF = 120
1399 self.WIDTHPROF = 120
1398 self.HEIGHTPROF = 0
1400 self.HEIGHTPROF = 0
1399 self.xdata = None
1401 self.xdata = None
1400 self.ydata = None
1402 self.ydata = None
1401
1403
1402 self.PLOT_CODE = BEACON_CODE
1404 self.PLOT_CODE = BEACON_CODE
1403
1405
1404 self.FTP_WEI = None
1406 self.FTP_WEI = None
1405 self.EXP_CODE = None
1407 self.EXP_CODE = None
1406 self.SUB_EXP_CODE = None
1408 self.SUB_EXP_CODE = None
1407 self.PLOT_POS = None
1409 self.PLOT_POS = None
1408
1410
1409 self.filename_phase = None
1411 self.filename_phase = None
1410
1412
1411 self.figfile = None
1413 self.figfile = None
1412
1414
1413 self.xmin = None
1415 self.xmin = None
1414 self.xmax = None
1416 self.xmax = None
1415
1417
1416 def getSubplots(self):
1418 def getSubplots(self):
1417
1419
1418 ncol = 1
1420 ncol = 1
1419 nrow = 1
1421 nrow = 1
1420
1422
1421 return nrow, ncol
1423 return nrow, ncol
1422
1424
1423 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1425 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1424
1426
1425 self.__showprofile = showprofile
1427 self.__showprofile = showprofile
1426 self.nplots = nplots
1428 self.nplots = nplots
1427
1429
1428 ncolspan = 7
1430 ncolspan = 7
1429 colspan = 6
1431 colspan = 6
1430 self.__nsubplots = 2
1432 self.__nsubplots = 2
1431
1433
1432 self.createFigure(id = id,
1434 self.createFigure(id = id,
1433 wintitle = wintitle,
1435 wintitle = wintitle,
1434 widthplot = self.WIDTH+self.WIDTHPROF,
1436 widthplot = self.WIDTH+self.WIDTHPROF,
1435 heightplot = self.HEIGHT+self.HEIGHTPROF,
1437 heightplot = self.HEIGHT+self.HEIGHTPROF,
1436 show=show)
1438 show=show)
1437
1439
1438 nrow, ncol = self.getSubplots()
1440 nrow, ncol = self.getSubplots()
1439
1441
1440 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1442 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1441
1443
1442 def save_phase(self, filename_phase):
1444 def save_phase(self, filename_phase):
1443 f = open(filename_phase,'w+')
1445 f = open(filename_phase,'w+')
1444 f.write('\n\n')
1446 f.write('\n\n')
1445 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1447 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1446 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1448 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1447 f.close()
1449 f.close()
1448
1450
1449 def save_data(self, filename_phase, data, data_datetime):
1451 def save_data(self, filename_phase, data, data_datetime):
1450 f=open(filename_phase,'a')
1452 f=open(filename_phase,'a')
1451 timetuple_data = data_datetime.timetuple()
1453 timetuple_data = data_datetime.timetuple()
1452 day = str(timetuple_data.tm_mday)
1454 day = str(timetuple_data.tm_mday)
1453 month = str(timetuple_data.tm_mon)
1455 month = str(timetuple_data.tm_mon)
1454 year = str(timetuple_data.tm_year)
1456 year = str(timetuple_data.tm_year)
1455 hour = str(timetuple_data.tm_hour)
1457 hour = str(timetuple_data.tm_hour)
1456 minute = str(timetuple_data.tm_min)
1458 minute = str(timetuple_data.tm_min)
1457 second = str(timetuple_data.tm_sec)
1459 second = str(timetuple_data.tm_sec)
1458 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1460 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1459 f.close()
1461 f.close()
1460
1462
1461
1463
1462 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1464 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1463 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1465 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1464 timerange=None,
1466 timerange=None,
1465 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1467 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1466 server=None, folder=None, username=None, password=None,
1468 server=None, folder=None, username=None, password=None,
1467 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1469 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1468
1470
1469 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1471 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1470 return
1472 return
1471
1473
1472 if pairsList == None:
1474 if pairsList == None:
1473 pairsIndexList = dataOut.pairsIndexList[:10]
1475 pairsIndexList = dataOut.pairsIndexList[:10]
1474 else:
1476 else:
1475 pairsIndexList = []
1477 pairsIndexList = []
1476 for pair in pairsList:
1478 for pair in pairsList:
1477 if pair not in dataOut.pairsList:
1479 if pair not in dataOut.pairsList:
1478 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1480 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1479 pairsIndexList.append(dataOut.pairsList.index(pair))
1481 pairsIndexList.append(dataOut.pairsList.index(pair))
1480
1482
1481 if pairsIndexList == []:
1483 if pairsIndexList == []:
1482 return
1484 return
1483
1485
1484 # if len(pairsIndexList) > 4:
1486 # if len(pairsIndexList) > 4:
1485 # pairsIndexList = pairsIndexList[0:4]
1487 # pairsIndexList = pairsIndexList[0:4]
1486
1488
1487 hmin_index = None
1489 hmin_index = None
1488 hmax_index = None
1490 hmax_index = None
1489
1491
1490 if hmin != None and hmax != None:
1492 if hmin != None and hmax != None:
1491 indexes = numpy.arange(dataOut.nHeights)
1493 indexes = numpy.arange(dataOut.nHeights)
1492 hmin_list = indexes[dataOut.heightList >= hmin]
1494 hmin_list = indexes[dataOut.heightList >= hmin]
1493 hmax_list = indexes[dataOut.heightList <= hmax]
1495 hmax_list = indexes[dataOut.heightList <= hmax]
1494
1496
1495 if hmin_list.any():
1497 if hmin_list.any():
1496 hmin_index = hmin_list[0]
1498 hmin_index = hmin_list[0]
1497
1499
1498 if hmax_list.any():
1500 if hmax_list.any():
1499 hmax_index = hmax_list[-1]+1
1501 hmax_index = hmax_list[-1]+1
1500
1502
1501 x = dataOut.getTimeRange()
1503 x = dataOut.getTimeRange()
1502 #y = dataOut.getHeiRange()
1504 #y = dataOut.getHeiRange()
1503
1505
1504
1506
1505 thisDatetime = dataOut.datatime
1507 thisDatetime = dataOut.datatime
1506
1508
1507 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1509 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1508 xlabel = "Local Time"
1510 xlabel = "Local Time"
1509 ylabel = "Phase (degrees)"
1511 ylabel = "Phase (degrees)"
1510
1512
1511 update_figfile = False
1513 update_figfile = False
1512
1514
1513 nplots = len(pairsIndexList)
1515 nplots = len(pairsIndexList)
1514 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1516 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1515 phase_beacon = numpy.zeros(len(pairsIndexList))
1517 phase_beacon = numpy.zeros(len(pairsIndexList))
1516 for i in range(nplots):
1518 for i in range(nplots):
1517 pair = dataOut.pairsList[pairsIndexList[i]]
1519 pair = dataOut.pairsList[pairsIndexList[i]]
1518 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1520 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1519 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1521 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1520 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1522 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1521 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1523 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1522 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1524 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1523
1525
1524 #print "Phase %d%d" %(pair[0], pair[1])
1526 #print "Phase %d%d" %(pair[0], pair[1])
1525 #print phase[dataOut.beacon_heiIndexList]
1527 #print phase[dataOut.beacon_heiIndexList]
1526
1528
1527 if dataOut.beacon_heiIndexList:
1529 if dataOut.beacon_heiIndexList:
1528 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1530 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1529 else:
1531 else:
1530 phase_beacon[i] = numpy.average(phase)
1532 phase_beacon[i] = numpy.average(phase)
1531
1533
1532 if not self.isConfig:
1534 if not self.isConfig:
1533
1535
1534 nplots = len(pairsIndexList)
1536 nplots = len(pairsIndexList)
1535
1537
1536 self.setup(id=id,
1538 self.setup(id=id,
1537 nplots=nplots,
1539 nplots=nplots,
1538 wintitle=wintitle,
1540 wintitle=wintitle,
1539 showprofile=showprofile,
1541 showprofile=showprofile,
1540 show=show)
1542 show=show)
1541
1543
1542 if timerange != None:
1544 if timerange != None:
1543 self.timerange = timerange
1545 self.timerange = timerange
1544
1546
1545 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1547 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1546
1548
1547 if ymin == None: ymin = 0
1549 if ymin == None: ymin = 0
1548 if ymax == None: ymax = 360
1550 if ymax == None: ymax = 360
1549
1551
1550 self.FTP_WEI = ftp_wei
1552 self.FTP_WEI = ftp_wei
1551 self.EXP_CODE = exp_code
1553 self.EXP_CODE = exp_code
1552 self.SUB_EXP_CODE = sub_exp_code
1554 self.SUB_EXP_CODE = sub_exp_code
1553 self.PLOT_POS = plot_pos
1555 self.PLOT_POS = plot_pos
1554
1556
1555 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1557 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1556 self.isConfig = True
1558 self.isConfig = True
1557 self.figfile = figfile
1559 self.figfile = figfile
1558 self.xdata = numpy.array([])
1560 self.xdata = numpy.array([])
1559 self.ydata = numpy.array([])
1561 self.ydata = numpy.array([])
1560
1562
1561 update_figfile = True
1563 update_figfile = True
1562
1564
1563 #open file beacon phase
1565 #open file beacon phase
1564 path = '%s%03d' %(self.PREFIX, self.id)
1566 path = '%s%03d' %(self.PREFIX, self.id)
1565 beacon_file = os.path.join(path,'%s.txt'%self.name)
1567 beacon_file = os.path.join(path,'%s.txt'%self.name)
1566 self.filename_phase = os.path.join(figpath,beacon_file)
1568 self.filename_phase = os.path.join(figpath,beacon_file)
1567 #self.save_phase(self.filename_phase)
1569 #self.save_phase(self.filename_phase)
1568
1570
1569
1571
1570 #store data beacon phase
1572 #store data beacon phase
1571 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1573 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1572
1574
1573 self.setWinTitle(title)
1575 self.setWinTitle(title)
1574
1576
1575
1577
1576 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1578 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1577
1579
1578 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1580 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1579
1581
1580 axes = self.axesList[0]
1582 axes = self.axesList[0]
1581
1583
1582 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1584 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1583
1585
1584 if len(self.ydata)==0:
1586 if len(self.ydata)==0:
1585 self.ydata = phase_beacon.reshape(-1,1)
1587 self.ydata = phase_beacon.reshape(-1,1)
1586 else:
1588 else:
1587 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1589 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1588
1590
1589
1591
1590 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1592 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1591 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1593 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1592 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1594 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1593 XAxisAsTime=True, grid='both'
1595 XAxisAsTime=True, grid='both'
1594 )
1596 )
1595
1597
1596 self.draw()
1598 self.draw()
1597
1599
1598 if dataOut.ltctime >= self.xmax:
1600 if dataOut.ltctime >= self.xmax:
1599 self.counter_imagwr = wr_period
1601 self.counter_imagwr = wr_period
1600 self.isConfig = False
1602 self.isConfig = False
1601 update_figfile = True
1603 update_figfile = True
1602
1604
1603 self.save(figpath=figpath,
1605 self.save(figpath=figpath,
1604 figfile=figfile,
1606 figfile=figfile,
1605 save=save,
1607 save=save,
1606 ftp=ftp,
1608 ftp=ftp,
1607 wr_period=wr_period,
1609 wr_period=wr_period,
1608 thisDatetime=thisDatetime,
1610 thisDatetime=thisDatetime,
1609 update_figfile=update_figfile)
1611 update_figfile=update_figfile)
@@ -1,481 +1,481
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import sys
4 import matplotlib
4 import matplotlib
5
5
6 if 'linux' in sys.platform:
6 if 'linux' in sys.platform:
7 matplotlib.use("TKAgg")
7 matplotlib.use("TKAgg")
8
8
9 if 'darwin' in sys.platform:
9 if 'darwin' in sys.platform:
10 matplotlib.use('TKAgg')
10 matplotlib.use('TKAgg')
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
12 import matplotlib.pyplot
13
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import FuncFormatter, LinearLocator
15 from matplotlib.ticker import FuncFormatter, LinearLocator
16
16
17 ###########################################
17 ###########################################
18 #Actualizacion de las funciones del driver
18 #Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 # create jro colormap
21 # create jro colormap
22
22
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
27
27
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
29
29
30 matplotlib.pyplot.ioff()
30 matplotlib.pyplot.ioff()
31
31
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
33 fig.canvas.manager.set_window_title(wintitle)
33 fig.canvas.manager.set_window_title(wintitle)
34 # fig.canvas.manager.resize(width, height)
34 # fig.canvas.manager.resize(width, height)
35 matplotlib.pyplot.ion()
35 matplotlib.pyplot.ion()
36
36
37 if show:
37 if show:
38 matplotlib.pyplot.show()
38 matplotlib.pyplot.show()
39
39
40 return fig
40 return fig
41
41
42 def closeFigure(show=False, fig=None):
42 def closeFigure(show=False, fig=None):
43
43
44 # matplotlib.pyplot.ioff()
44 # matplotlib.pyplot.ioff()
45 # matplotlib.pyplot.pause(0)
45 # matplotlib.pyplot.pause(0)
46
46
47 if show:
47 if show:
48 matplotlib.pyplot.show()
48 matplotlib.pyplot.show()
49
49
50 if fig != None:
50 if fig != None:
51 matplotlib.pyplot.close(fig)
51 matplotlib.pyplot.close(fig)
52 # matplotlib.pyplot.pause(0)
52 # matplotlib.pyplot.pause(0)
53 # matplotlib.pyplot.ion()
53 # matplotlib.pyplot.ion()
54
54
55 return
55 return
56
56
57 matplotlib.pyplot.close("all")
57 matplotlib.pyplot.close("all")
58 # matplotlib.pyplot.pause(0)
58 # matplotlib.pyplot.pause(0)
59 # matplotlib.pyplot.ion()
59 # matplotlib.pyplot.ion()
60
60
61 return
61 return
62
62
63 def saveFigure(fig, filename):
63 def saveFigure(fig, filename):
64
64
65 # matplotlib.pyplot.ioff()
65 # matplotlib.pyplot.ioff()
66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
67 # matplotlib.pyplot.ion()
67 # matplotlib.pyplot.ion()
68
68
69 def clearFigure(fig):
69 def clearFigure(fig):
70
70
71 fig.clf()
71 fig.clf()
72
72
73 def setWinTitle(fig, title):
73 def setWinTitle(fig, title):
74
74
75 fig.canvas.manager.set_window_title(title)
75 fig.canvas.manager.set_window_title(title)
76
76
77 def setTitle(fig, title):
77 def setTitle(fig, title):
78
78
79 fig.suptitle(title)
79 fig.suptitle(title)
80
80
81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
82
82
83 matplotlib.pyplot.ioff()
83 matplotlib.pyplot.ioff()
84 matplotlib.pyplot.figure(fig.number)
84 matplotlib.pyplot.figure(fig.number)
85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
86 (xpos, ypos),
86 (xpos, ypos),
87 colspan=colspan,
87 colspan=colspan,
88 rowspan=rowspan,
88 rowspan=rowspan,
89 polar=polar)
89 polar=polar)
90
90
91 axes.grid(True)
91 axes.grid(True)
92
92
93 matplotlib.pyplot.ion()
93 matplotlib.pyplot.ion()
94 return axes
94 return axes
95
95
96 def setAxesText(ax, text):
96 def setAxesText(ax, text):
97
97
98 ax.annotate(text,
98 ax.annotate(text,
99 xy = (.1, .99),
99 xy = (.1, .99),
100 xycoords = 'figure fraction',
100 xycoords = 'figure fraction',
101 horizontalalignment = 'left',
101 horizontalalignment = 'left',
102 verticalalignment = 'top',
102 verticalalignment = 'top',
103 fontsize = 10)
103 fontsize = 10)
104
104
105 def printLabels(ax, xlabel, ylabel, title):
105 def printLabels(ax, xlabel, ylabel, title):
106
106
107 ax.set_xlabel(xlabel, size=11)
107 ax.set_xlabel(xlabel, size=11)
108 ax.set_ylabel(ylabel, size=11)
108 ax.set_ylabel(ylabel, size=11)
109 ax.set_title(title, size=8)
109 ax.set_title(title, size=8)
110
110
111 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
111 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
112 ticksize=9, xtick_visible=True, ytick_visible=True,
112 ticksize=9, xtick_visible=True, ytick_visible=True,
113 nxticks=4, nyticks=10,
113 nxticks=4, nyticks=10,
114 grid=None,color='blue'):
114 grid=None,color='blue'):
115
115
116 """
116 """
117
117
118 Input:
118 Input:
119 grid : None, 'both', 'x', 'y'
119 grid : None, 'both', 'x', 'y'
120 """
120 """
121
121
122 matplotlib.pyplot.ioff()
122 matplotlib.pyplot.ioff()
123
123
124 ax.set_xlim([xmin,xmax])
124 ax.set_xlim([xmin,xmax])
125 ax.set_ylim([ymin,ymax])
125 ax.set_ylim([ymin,ymax])
126
126
127 printLabels(ax, xlabel, ylabel, title)
127 printLabels(ax, xlabel, ylabel, title)
128
128
129 ######################################################
129 ######################################################
130 if (xmax-xmin)<=1:
130 if (xmax-xmin)<=1:
131 xtickspos = numpy.linspace(xmin,xmax,nxticks)
131 xtickspos = numpy.linspace(xmin,xmax,nxticks)
132 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
132 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
133 ax.set_xticks(xtickspos)
133 ax.set_xticks(xtickspos)
134 else:
134 else:
135 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
135 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
136 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
136 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
137 ax.set_xticks(xtickspos)
137 ax.set_xticks(xtickspos)
138
138
139 for tick in ax.get_xticklabels():
139 for tick in ax.get_xticklabels():
140 tick.set_visible(xtick_visible)
140 tick.set_visible(xtick_visible)
141
141
142 for tick in ax.xaxis.get_major_ticks():
142 for tick in ax.xaxis.get_major_ticks():
143 tick.label.set_fontsize(ticksize)
143 tick.label.set_fontsize(ticksize)
144
144
145 ######################################################
145 ######################################################
146 for tick in ax.get_yticklabels():
146 for tick in ax.get_yticklabels():
147 tick.set_visible(ytick_visible)
147 tick.set_visible(ytick_visible)
148
148
149 for tick in ax.yaxis.get_major_ticks():
149 for tick in ax.yaxis.get_major_ticks():
150 tick.label.set_fontsize(ticksize)
150 tick.label.set_fontsize(ticksize)
151
151
152 ax.plot(x, y, color=color)
152 ax.plot(x, y, color=color)
153 iplot = ax.lines[-1]
153 iplot = ax.lines[-1]
154
154
155 ######################################################
155 ######################################################
156 if '0.' in matplotlib.__version__[0:2]:
156 if '0.' in matplotlib.__version__[0:2]:
157 print "The matplotlib version has to be updated to 1.1 or newer"
157 print "The matplotlib version has to be updated to 1.1 or newer"
158 return iplot
158 return iplot
159
159
160 if '1.0.' in matplotlib.__version__[0:4]:
160 if '1.0.' in matplotlib.__version__[0:4]:
161 print "The matplotlib version has to be updated to 1.1 or newer"
161 print "The matplotlib version has to be updated to 1.1 or newer"
162 return iplot
162 return iplot
163
163
164 if grid != None:
164 if grid != None:
165 ax.grid(b=True, which='major', axis=grid)
165 ax.grid(b=True, which='major', axis=grid)
166
166
167 matplotlib.pyplot.tight_layout()
167 matplotlib.pyplot.tight_layout()
168
168
169 matplotlib.pyplot.ion()
169 matplotlib.pyplot.ion()
170
170
171 return iplot
171 return iplot
172
172
173 def set_linedata(ax, x, y, idline):
173 def set_linedata(ax, x, y, idline):
174
174
175 ax.lines[idline].set_data(x,y)
175 ax.lines[idline].set_data(x,y)
176
176
177 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
177 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
178
178
179 ax = iplot.get_axes()
179 ax = iplot.axes
180
180
181 printLabels(ax, xlabel, ylabel, title)
181 printLabels(ax, xlabel, ylabel, title)
182
182
183 set_linedata(ax, x, y, idline=0)
183 set_linedata(ax, x, y, idline=0)
184
184
185 def addpline(ax, x, y, color, linestyle, lw):
185 def addpline(ax, x, y, color, linestyle, lw):
186
186
187 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
187 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
188
188
189
189
190 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
190 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
191 xlabel='', ylabel='', title='', ticksize = 9,
191 xlabel='', ylabel='', title='', ticksize = 9,
192 colormap='jet',cblabel='', cbsize="5%",
192 colormap='jet',cblabel='', cbsize="5%",
193 XAxisAsTime=False):
193 XAxisAsTime=False):
194
194
195 matplotlib.pyplot.ioff()
195 matplotlib.pyplot.ioff()
196
196
197 divider = make_axes_locatable(ax)
197 divider = make_axes_locatable(ax)
198 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
198 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
199 fig = ax.get_figure()
199 fig = ax.get_figure()
200 fig.add_axes(ax_cb)
200 fig.add_axes(ax_cb)
201
201
202 ax.set_xlim([xmin,xmax])
202 ax.set_xlim([xmin,xmax])
203 ax.set_ylim([ymin,ymax])
203 ax.set_ylim([ymin,ymax])
204
204
205 printLabels(ax, xlabel, ylabel, title)
205 printLabels(ax, xlabel, ylabel, title)
206
206
207 z = numpy.ma.masked_invalid(z)
207 z = numpy.ma.masked_invalid(z)
208 cmap=matplotlib.pyplot.get_cmap(colormap)
208 cmap=matplotlib.pyplot.get_cmap(colormap)
209 cmap.set_bad('white',1.)
209 cmap.set_bad('white',1.)
210 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
210 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
211 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
211 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
212 cb.set_label(cblabel)
212 cb.set_label(cblabel)
213
213
214 # for tl in ax_cb.get_yticklabels():
214 # for tl in ax_cb.get_yticklabels():
215 # tl.set_visible(True)
215 # tl.set_visible(True)
216
216
217 for tick in ax.yaxis.get_major_ticks():
217 for tick in ax.yaxis.get_major_ticks():
218 tick.label.set_fontsize(ticksize)
218 tick.label.set_fontsize(ticksize)
219
219
220 for tick in ax.xaxis.get_major_ticks():
220 for tick in ax.xaxis.get_major_ticks():
221 tick.label.set_fontsize(ticksize)
221 tick.label.set_fontsize(ticksize)
222
222
223 for tick in cb.ax.get_yticklabels():
223 for tick in cb.ax.get_yticklabels():
224 tick.set_fontsize(ticksize)
224 tick.set_fontsize(ticksize)
225
225
226 ax_cb.yaxis.tick_right()
226 ax_cb.yaxis.tick_right()
227
227
228 if '0.' in matplotlib.__version__[0:2]:
228 if '0.' in matplotlib.__version__[0:2]:
229 print "The matplotlib version has to be updated to 1.1 or newer"
229 print "The matplotlib version has to be updated to 1.1 or newer"
230 return imesh
230 return imesh
231
231
232 if '1.0.' in matplotlib.__version__[0:4]:
232 if '1.0.' in matplotlib.__version__[0:4]:
233 print "The matplotlib version has to be updated to 1.1 or newer"
233 print "The matplotlib version has to be updated to 1.1 or newer"
234 return imesh
234 return imesh
235
235
236 matplotlib.pyplot.tight_layout()
236 matplotlib.pyplot.tight_layout()
237
237
238 if XAxisAsTime:
238 if XAxisAsTime:
239
239
240 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
240 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
241 ax.xaxis.set_major_formatter(FuncFormatter(func))
241 ax.xaxis.set_major_formatter(FuncFormatter(func))
242 ax.xaxis.set_major_locator(LinearLocator(7))
242 ax.xaxis.set_major_locator(LinearLocator(7))
243
243
244 ax.grid(True)
244 ax.grid(True)
245 matplotlib.pyplot.ion()
245 matplotlib.pyplot.ion()
246 return imesh
246 return imesh
247
247
248 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
248 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
249
249
250 z = numpy.ma.masked_invalid(z)
250 z = numpy.ma.masked_invalid(z)
251
251
252 cmap=matplotlib.pyplot.get_cmap('jet')
252 cmap=matplotlib.pyplot.get_cmap('jet')
253 cmap.set_bad('white',1.)
253 cmap.set_bad('white',1.)
254
254
255 z = z.T
255 z = z.T
256 ax = imesh.get_axes()
256 ax = imesh.axes
257 printLabels(ax, xlabel, ylabel, title)
257 printLabels(ax, xlabel, ylabel, title)
258 imesh.set_array(z.ravel())
258 imesh.set_array(z.ravel())
259 ax.grid(True)
259 ax.grid(True)
260
260
261
261
262 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
262 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
263
263
264 printLabels(ax, xlabel, ylabel, title)
264 printLabels(ax, xlabel, ylabel, title)
265 z = numpy.ma.masked_invalid(z)
265 z = numpy.ma.masked_invalid(z)
266 cmap=matplotlib.pyplot.get_cmap(colormap)
266 cmap=matplotlib.pyplot.get_cmap(colormap)
267 cmap.set_bad('white',1.)
267 cmap.set_bad('white',1.)
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
269 ax.grid(True)
269 ax.grid(True)
270
270
271 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
271 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
272
272
273 printLabels(ax, xlabel, ylabel, title)
273 printLabels(ax, xlabel, ylabel, title)
274
274
275 ax.collections.remove(ax.collections[0])
275 ax.collections.remove(ax.collections[0])
276
276
277 z = numpy.ma.masked_invalid(z)
277 z = numpy.ma.masked_invalid(z)
278
278
279 cmap=matplotlib.pyplot.get_cmap(colormap)
279 cmap=matplotlib.pyplot.get_cmap(colormap)
280 cmap.set_bad('white',1.)
280 cmap.set_bad('white',1.)
281
281
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
283 ax.grid(True)
283 ax.grid(True)
284
284
285
285
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
288 nxticks=4, nyticks=10,
288 nxticks=4, nyticks=10,
289 grid=None):
289 grid=None):
290
290
291 """
291 """
292
292
293 Input:
293 Input:
294 grid : None, 'both', 'x', 'y'
294 grid : None, 'both', 'x', 'y'
295 """
295 """
296
296
297 matplotlib.pyplot.ioff()
297 matplotlib.pyplot.ioff()
298
298
299 lines = ax.plot(x.T, y)
299 lines = ax.plot(x.T, y)
300 leg = ax.legend(lines, legendlabels, loc='upper right')
300 leg = ax.legend(lines, legendlabels, loc='upper right')
301 leg.get_frame().set_alpha(0.5)
301 leg.get_frame().set_alpha(0.5)
302 ax.set_xlim([xmin,xmax])
302 ax.set_xlim([xmin,xmax])
303 ax.set_ylim([ymin,ymax])
303 ax.set_ylim([ymin,ymax])
304 printLabels(ax, xlabel, ylabel, title)
304 printLabels(ax, xlabel, ylabel, title)
305
305
306 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
306 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
307 ax.set_xticks(xtickspos)
307 ax.set_xticks(xtickspos)
308
308
309 for tick in ax.get_xticklabels():
309 for tick in ax.get_xticklabels():
310 tick.set_visible(xtick_visible)
310 tick.set_visible(xtick_visible)
311
311
312 for tick in ax.xaxis.get_major_ticks():
312 for tick in ax.xaxis.get_major_ticks():
313 tick.label.set_fontsize(ticksize)
313 tick.label.set_fontsize(ticksize)
314
314
315 for tick in ax.get_yticklabels():
315 for tick in ax.get_yticklabels():
316 tick.set_visible(ytick_visible)
316 tick.set_visible(ytick_visible)
317
317
318 for tick in ax.yaxis.get_major_ticks():
318 for tick in ax.yaxis.get_major_ticks():
319 tick.label.set_fontsize(ticksize)
319 tick.label.set_fontsize(ticksize)
320
320
321 iplot = ax.lines[-1]
321 iplot = ax.lines[-1]
322
322
323 if '0.' in matplotlib.__version__[0:2]:
323 if '0.' in matplotlib.__version__[0:2]:
324 print "The matplotlib version has to be updated to 1.1 or newer"
324 print "The matplotlib version has to be updated to 1.1 or newer"
325 return iplot
325 return iplot
326
326
327 if '1.0.' in matplotlib.__version__[0:4]:
327 if '1.0.' in matplotlib.__version__[0:4]:
328 print "The matplotlib version has to be updated to 1.1 or newer"
328 print "The matplotlib version has to be updated to 1.1 or newer"
329 return iplot
329 return iplot
330
330
331 if grid != None:
331 if grid != None:
332 ax.grid(b=True, which='major', axis=grid)
332 ax.grid(b=True, which='major', axis=grid)
333
333
334 matplotlib.pyplot.tight_layout()
334 matplotlib.pyplot.tight_layout()
335
335
336 matplotlib.pyplot.ion()
336 matplotlib.pyplot.ion()
337
337
338 return iplot
338 return iplot
339
339
340
340
341 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
341 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
342
342
343 ax = iplot.get_axes()
343 ax = iplot.axes
344
344
345 printLabels(ax, xlabel, ylabel, title)
345 printLabels(ax, xlabel, ylabel, title)
346
346
347 for i in range(len(ax.lines)):
347 for i in range(len(ax.lines)):
348 line = ax.lines[i]
348 line = ax.lines[i]
349 line.set_data(x[i,:],y)
349 line.set_data(x[i,:],y)
350
350
351 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
351 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
352 ticksize=9, xtick_visible=True, ytick_visible=True,
352 ticksize=9, xtick_visible=True, ytick_visible=True,
353 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
353 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
354 grid=None, XAxisAsTime=False):
354 grid=None, XAxisAsTime=False):
355
355
356 """
356 """
357
357
358 Input:
358 Input:
359 grid : None, 'both', 'x', 'y'
359 grid : None, 'both', 'x', 'y'
360 """
360 """
361
361
362 matplotlib.pyplot.ioff()
362 matplotlib.pyplot.ioff()
363
363
364 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
364 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
365 lines = ax.plot(x, y.T)
365 lines = ax.plot(x, y.T)
366 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
366 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
367 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
367 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
368
368
369 leg = ax.legend(lines, legendlabels,
369 leg = ax.legend(lines, legendlabels,
370 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
370 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
371
371
372 for label in leg.get_texts(): label.set_fontsize(9)
372 for label in leg.get_texts(): label.set_fontsize(9)
373
373
374 ax.set_xlim([xmin,xmax])
374 ax.set_xlim([xmin,xmax])
375 ax.set_ylim([ymin,ymax])
375 ax.set_ylim([ymin,ymax])
376 printLabels(ax, xlabel, ylabel, title)
376 printLabels(ax, xlabel, ylabel, title)
377
377
378 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
378 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
379 # ax.set_xticks(xtickspos)
379 # ax.set_xticks(xtickspos)
380
380
381 for tick in ax.get_xticklabels():
381 for tick in ax.get_xticklabels():
382 tick.set_visible(xtick_visible)
382 tick.set_visible(xtick_visible)
383
383
384 for tick in ax.xaxis.get_major_ticks():
384 for tick in ax.xaxis.get_major_ticks():
385 tick.label.set_fontsize(ticksize)
385 tick.label.set_fontsize(ticksize)
386
386
387 for tick in ax.get_yticklabels():
387 for tick in ax.get_yticklabels():
388 tick.set_visible(ytick_visible)
388 tick.set_visible(ytick_visible)
389
389
390 for tick in ax.yaxis.get_major_ticks():
390 for tick in ax.yaxis.get_major_ticks():
391 tick.label.set_fontsize(ticksize)
391 tick.label.set_fontsize(ticksize)
392
392
393 iplot = ax.lines[-1]
393 iplot = ax.lines[-1]
394
394
395 if '0.' in matplotlib.__version__[0:2]:
395 if '0.' in matplotlib.__version__[0:2]:
396 print "The matplotlib version has to be updated to 1.1 or newer"
396 print "The matplotlib version has to be updated to 1.1 or newer"
397 return iplot
397 return iplot
398
398
399 if '1.0.' in matplotlib.__version__[0:4]:
399 if '1.0.' in matplotlib.__version__[0:4]:
400 print "The matplotlib version has to be updated to 1.1 or newer"
400 print "The matplotlib version has to be updated to 1.1 or newer"
401 return iplot
401 return iplot
402
402
403 if grid != None:
403 if grid != None:
404 ax.grid(b=True, which='major', axis=grid)
404 ax.grid(b=True, which='major', axis=grid)
405
405
406 matplotlib.pyplot.tight_layout()
406 matplotlib.pyplot.tight_layout()
407
407
408 if XAxisAsTime:
408 if XAxisAsTime:
409
409
410 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
410 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
411 ax.xaxis.set_major_formatter(FuncFormatter(func))
411 ax.xaxis.set_major_formatter(FuncFormatter(func))
412 ax.xaxis.set_major_locator(LinearLocator(7))
412 ax.xaxis.set_major_locator(LinearLocator(7))
413
413
414 matplotlib.pyplot.ion()
414 matplotlib.pyplot.ion()
415
415
416 return iplot
416 return iplot
417
417
418 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
418 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
419
419
420 ax = iplot.get_axes()
420 ax = iplot.axes
421 printLabels(ax, xlabel, ylabel, title)
421 printLabels(ax, xlabel, ylabel, title)
422
422
423 for i in range(len(ax.lines)):
423 for i in range(len(ax.lines)):
424 line = ax.lines[i]
424 line = ax.lines[i]
425 line.set_data(x,y[i,:])
425 line.set_data(x,y[i,:])
426
426
427 def createPolar(ax, x, y,
427 def createPolar(ax, x, y,
428 xlabel='', ylabel='', title='', ticksize = 9,
428 xlabel='', ylabel='', title='', ticksize = 9,
429 colormap='jet',cblabel='', cbsize="5%",
429 colormap='jet',cblabel='', cbsize="5%",
430 XAxisAsTime=False):
430 XAxisAsTime=False):
431
431
432 matplotlib.pyplot.ioff()
432 matplotlib.pyplot.ioff()
433
433
434 ax.plot(x,y,'bo', markersize=5)
434 ax.plot(x,y,'bo', markersize=5)
435 # ax.set_rmax(90)
435 # ax.set_rmax(90)
436 ax.set_ylim(0,90)
436 ax.set_ylim(0,90)
437 ax.set_yticks(numpy.arange(0,90,20))
437 ax.set_yticks(numpy.arange(0,90,20))
438 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
438 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
439 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
439 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
440 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
440 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
441 ax.yaxis.labelpad = 230
441 ax.yaxis.labelpad = 230
442 printLabels(ax, xlabel, ylabel, title)
442 printLabels(ax, xlabel, ylabel, title)
443 iplot = ax.lines[-1]
443 iplot = ax.lines[-1]
444
444
445 if '0.' in matplotlib.__version__[0:2]:
445 if '0.' in matplotlib.__version__[0:2]:
446 print "The matplotlib version has to be updated to 1.1 or newer"
446 print "The matplotlib version has to be updated to 1.1 or newer"
447 return iplot
447 return iplot
448
448
449 if '1.0.' in matplotlib.__version__[0:4]:
449 if '1.0.' in matplotlib.__version__[0:4]:
450 print "The matplotlib version has to be updated to 1.1 or newer"
450 print "The matplotlib version has to be updated to 1.1 or newer"
451 return iplot
451 return iplot
452
452
453 # if grid != None:
453 # if grid != None:
454 # ax.grid(b=True, which='major', axis=grid)
454 # ax.grid(b=True, which='major', axis=grid)
455
455
456 matplotlib.pyplot.tight_layout()
456 matplotlib.pyplot.tight_layout()
457
457
458 matplotlib.pyplot.ion()
458 matplotlib.pyplot.ion()
459
459
460
460
461 return iplot
461 return iplot
462
462
463 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
463 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
464
464
465 ax = iplot.get_axes()
465 ax = iplot.axes
466
466
467 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
467 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
468 printLabels(ax, xlabel, ylabel, title)
468 printLabels(ax, xlabel, ylabel, title)
469
469
470 set_linedata(ax, x, y, idline=0)
470 set_linedata(ax, x, y, idline=0)
471
471
472 def draw(fig):
472 def draw(fig):
473
473
474 if type(fig) == 'int':
474 if type(fig) == 'int':
475 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
475 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
476
476
477 fig.canvas.draw()
477 fig.canvas.draw()
478
478
479 def pause(interval=0.000001):
479 def pause(interval=0.000001):
480
480
481 matplotlib.pyplot.pause(interval)
481 matplotlib.pyplot.pause(interval)
@@ -1,1090 +1,1091
1 import numpy
1 import numpy
2 import time
2 import time
3 import os
3 import os
4 import h5py
4 import h5py
5 import re
5 import re
6 import datetime
6 import datetime
7
7
8 from schainpy.model.data.jrodata import *
8 from schainpy.model.data.jrodata import *
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 # from jroIO_base import *
10 # from jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
11 from schainpy.model.io.jroIO_base import *
12 import schainpy
12 import schainpy
13
13
14
14
15 class ParamReader(ProcessingUnit):
15 class ParamReader(ProcessingUnit):
16 '''
16 '''
17 Reads HDF5 format files
17 Reads HDF5 format files
18
18
19 path
19 path
20
20
21 startDate
21 startDate
22
22
23 endDate
23 endDate
24
24
25 startTime
25 startTime
26
26
27 endTime
27 endTime
28 '''
28 '''
29
29
30 ext = ".hdf5"
30 ext = ".hdf5"
31
31
32 optchar = "D"
32 optchar = "D"
33
33
34 timezone = None
34 timezone = None
35
35
36 startTime = None
36 startTime = None
37
37
38 endTime = None
38 endTime = None
39
39
40 fileIndex = None
40 fileIndex = None
41
41
42 utcList = None #To select data in the utctime list
42 utcList = None #To select data in the utctime list
43
43
44 blockList = None #List to blocks to be read from the file
44 blockList = None #List to blocks to be read from the file
45
45
46 blocksPerFile = None #Number of blocks to be read
46 blocksPerFile = None #Number of blocks to be read
47
47
48 blockIndex = None
48 blockIndex = None
49
49
50 path = None
50 path = None
51
51
52 #List of Files
52 #List of Files
53
53
54 filenameList = None
54 filenameList = None
55
55
56 datetimeList = None
56 datetimeList = None
57
57
58 #Hdf5 File
58 #Hdf5 File
59
59
60 listMetaname = None
60 listMetaname = None
61
61
62 listMeta = None
62 listMeta = None
63
63
64 listDataname = None
64 listDataname = None
65
65
66 listData = None
66 listData = None
67
67
68 listShapes = None
68 listShapes = None
69
69
70 fp = None
70 fp = None
71
71
72 #dataOut reconstruction
72 #dataOut reconstruction
73
73
74 dataOut = None
74 dataOut = None
75
75
76
76
77 def __init__(self, **kwargs):
77 def __init__(self, **kwargs):
78 ProcessingUnit.__init__(self, **kwargs)
78 ProcessingUnit.__init__(self, **kwargs)
79 self.dataOut = Parameters()
79 self.dataOut = Parameters()
80 return
80 return
81
81
82 def setup(self, **kwargs):
82 def setup(self, **kwargs):
83
83
84 path = kwargs['path']
84 path = kwargs['path']
85 startDate = kwargs['startDate']
85 startDate = kwargs['startDate']
86 endDate = kwargs['endDate']
86 endDate = kwargs['endDate']
87 startTime = kwargs['startTime']
87 startTime = kwargs['startTime']
88 endTime = kwargs['endTime']
88 endTime = kwargs['endTime']
89 walk = kwargs['walk']
89 walk = kwargs['walk']
90 if kwargs.has_key('ext'):
90 if kwargs.has_key('ext'):
91 ext = kwargs['ext']
91 ext = kwargs['ext']
92 else:
92 else:
93 ext = '.hdf5'
93 ext = '.hdf5'
94 if kwargs.has_key('timezone'):
94 if kwargs.has_key('timezone'):
95 self.timezone = kwargs['timezone']
95 self.timezone = kwargs['timezone']
96 else:
96 else:
97 self.timezone = 'lt'
97 self.timezone = 'lt'
98
98
99 print "[Reading] Searching files in offline mode ..."
99 print "[Reading] Searching files in offline mode ..."
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
100 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
101 startTime=startTime, endTime=endTime,
101 startTime=startTime, endTime=endTime,
102 ext=ext, walk=walk)
102 ext=ext, walk=walk)
103
103
104 if not(filenameList):
104 if not(filenameList):
105 print "There is no files into the folder: %s"%(path)
105 print "There is no files into the folder: %s"%(path)
106 sys.exit(-1)
106 sys.exit(-1)
107
107
108 self.fileIndex = -1
108 self.fileIndex = -1
109 self.startTime = startTime
109 self.startTime = startTime
110 self.endTime = endTime
110 self.endTime = endTime
111
111
112 self.__readMetadata()
112 self.__readMetadata()
113
113
114 self.__setNextFileOffline()
114 self.__setNextFileOffline()
115
115
116 return
116 return
117
117
118 def __searchFilesOffLine(self,
118 def __searchFilesOffLine(self,
119 path,
119 path,
120 startDate=None,
120 startDate=None,
121 endDate=None,
121 endDate=None,
122 startTime=datetime.time(0,0,0),
122 startTime=datetime.time(0,0,0),
123 endTime=datetime.time(23,59,59),
123 endTime=datetime.time(23,59,59),
124 ext='.hdf5',
124 ext='.hdf5',
125 walk=True):
125 walk=True):
126
126
127 expLabel = ''
127 expLabel = ''
128 self.filenameList = []
128 self.filenameList = []
129 self.datetimeList = []
129 self.datetimeList = []
130
130
131 pathList = []
131 pathList = []
132
132
133 JRODataObj = JRODataReader()
133 JRODataObj = JRODataReader()
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
134 dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
135
135
136 if dateList == []:
136 if dateList == []:
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
137 print "[Reading] No *%s files in %s from %s to %s)"%(ext, path,
138 datetime.datetime.combine(startDate,startTime).ctime(),
138 datetime.datetime.combine(startDate,startTime).ctime(),
139 datetime.datetime.combine(endDate,endTime).ctime())
139 datetime.datetime.combine(endDate,endTime).ctime())
140
140
141 return None, None
141 return None, None
142
142
143 if len(dateList) > 1:
143 if len(dateList) > 1:
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
144 print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate)
145 else:
145 else:
146 print "[Reading] data was found for the date %s" %(dateList[0])
146 print "[Reading] data was found for the date %s" %(dateList[0])
147
147
148 filenameList = []
148 filenameList = []
149 datetimeList = []
149 datetimeList = []
150
150
151 #----------------------------------------------------------------------------------
151 #----------------------------------------------------------------------------------
152
152
153 for thisPath in pathList:
153 for thisPath in pathList:
154 # thisPath = pathList[pathDict[file]]
154 # thisPath = pathList[pathDict[file]]
155
155
156 fileList = glob.glob1(thisPath, "*%s" %ext)
156 fileList = glob.glob1(thisPath, "*%s" %ext)
157 fileList.sort()
157 fileList.sort()
158
158
159 for file in fileList:
159 for file in fileList:
160
160
161 filename = os.path.join(thisPath,file)
161 filename = os.path.join(thisPath,file)
162
162
163 if not isFileInDateRange(filename, startDate, endDate):
163 if not isFileInDateRange(filename, startDate, endDate):
164 continue
164 continue
165
165
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
166 thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
167
167
168 if not(thisDatetime):
168 if not(thisDatetime):
169 continue
169 continue
170
170
171 filenameList.append(filename)
171 filenameList.append(filename)
172 datetimeList.append(thisDatetime)
172 datetimeList.append(thisDatetime)
173
173
174 if not(filenameList):
174 if not(filenameList):
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
175 print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
176 return None, None
176 return None, None
177
177
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
178 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
179 print
179 print
180
180
181 # for i in range(len(filenameList)):
181 # for i in range(len(filenameList)):
182 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
182 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
183
183
184 self.filenameList = filenameList
184 self.filenameList = filenameList
185 self.datetimeList = datetimeList
185 self.datetimeList = datetimeList
186
186
187 return pathList, filenameList
187 return pathList, filenameList
188
188
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
189 def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime):
190
190
191 """
191 """
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
192 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
193
193
194 Inputs:
194 Inputs:
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
195 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
196
196
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
197 startDate : fecha inicial del rango seleccionado en formato datetime.date
198
198
199 endDate : fecha final del rango seleccionado en formato datetime.date
199 endDate : fecha final del rango seleccionado en formato datetime.date
200
200
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
201 startTime : tiempo inicial del rango seleccionado en formato datetime.time
202
202
203 endTime : tiempo final del rango seleccionado en formato datetime.time
203 endTime : tiempo final del rango seleccionado en formato datetime.time
204
204
205 Return:
205 Return:
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
206 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
207 fecha especificado, de lo contrario retorna False.
207 fecha especificado, de lo contrario retorna False.
208
208
209 Excepciones:
209 Excepciones:
210 Si el archivo no existe o no puede ser abierto
210 Si el archivo no existe o no puede ser abierto
211 Si la cabecera no puede ser leida.
211 Si la cabecera no puede ser leida.
212
212
213 """
213 """
214
214
215 try:
215 try:
216 fp = h5py.File(filename,'r')
216 fp = h5py.File(filename,'r')
217 grp1 = fp['Data']
217 grp1 = fp['Data']
218
218
219 except IOError:
219 except IOError:
220 traceback.print_exc()
220 traceback.print_exc()
221 raise IOError, "The file %s can't be opened" %(filename)
221 raise IOError, "The file %s can't be opened" %(filename)
222 #chino rata
222 #chino rata
223 #In case has utctime attribute
223 #In case has utctime attribute
224 grp2 = grp1['utctime']
224 grp2 = grp1['utctime']
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
225 # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time
226 thisUtcTime = grp2.value[0]
226 thisUtcTime = grp2.value[0]
227
227
228 fp.close()
228 fp.close()
229
229
230 if self.timezone == 'lt':
230 if self.timezone == 'lt':
231 thisUtcTime -= 5*3600
231 thisUtcTime -= 5*3600
232
232
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
233 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
234 # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0])
235 thisDate = thisDatetime.date()
235 thisDate = thisDatetime.date()
236 thisTime = thisDatetime.time()
236 thisTime = thisDatetime.time()
237
237
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
238 startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
239 endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds()
240
240
241 #General case
241 #General case
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
242 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
243 #-----------o----------------------------o-----------
243 #-----------o----------------------------o-----------
244 # startTime endTime
244 # startTime endTime
245
245
246 if endTime >= startTime:
246 if endTime >= startTime:
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
247 thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime)
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
248 if numpy.any(thisUtcLog): #If there is one block between the hours mentioned
249 return thisDatetime
249 return thisDatetime
250 return None
250 return None
251
251
252 #If endTime < startTime then endTime belongs to the next day
252 #If endTime < startTime then endTime belongs to the next day
253 #<<<<<<<<<<<o o>>>>>>>>>>>
253 #<<<<<<<<<<<o o>>>>>>>>>>>
254 #-----------o----------------------------o-----------
254 #-----------o----------------------------o-----------
255 # endTime startTime
255 # endTime startTime
256
256
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
257 if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime):
258 return None
258 return None
259
259
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
260 if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime):
261 return None
261 return None
262
262
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
263 if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime):
264 return None
264 return None
265
265
266 return thisDatetime
266 return thisDatetime
267
267
268 def __setNextFileOffline(self):
268 def __setNextFileOffline(self):
269
269
270 self.fileIndex += 1
270 self.fileIndex += 1
271 idFile = self.fileIndex
271 idFile = self.fileIndex
272
272
273 if not(idFile < len(self.filenameList)):
273 if not(idFile < len(self.filenameList)):
274 print "No more Files"
274 print "No more Files"
275 return 0
275 return 0
276
276
277 filename = self.filenameList[idFile]
277 filename = self.filenameList[idFile]
278
278
279 filePointer = h5py.File(filename,'r')
279 filePointer = h5py.File(filename,'r')
280
280
281 self.filename = filename
281 self.filename = filename
282
282
283 self.fp = filePointer
283 self.fp = filePointer
284
284
285 print "Setting the file: %s"%self.filename
285 print "Setting the file: %s"%self.filename
286
286
287 # self.__readMetadata()
287 # self.__readMetadata()
288 self.__setBlockList()
288 self.__setBlockList()
289 self.__readData()
289 self.__readData()
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
290 # self.nRecords = self.fp['Data'].attrs['blocksPerFile']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
291 # self.nRecords = self.fp['Data'].attrs['nRecords']
292 self.blockIndex = 0
292 self.blockIndex = 0
293 return 1
293 return 1
294
294
295 def __setBlockList(self):
295 def __setBlockList(self):
296 '''
296 '''
297 Selects the data within the times defined
297 Selects the data within the times defined
298
298
299 self.fp
299 self.fp
300 self.startTime
300 self.startTime
301 self.endTime
301 self.endTime
302
302
303 self.blockList
303 self.blockList
304 self.blocksPerFile
304 self.blocksPerFile
305
305
306 '''
306 '''
307 fp = self.fp
307 fp = self.fp
308 startTime = self.startTime
308 startTime = self.startTime
309 endTime = self.endTime
309 endTime = self.endTime
310
310
311 grp = fp['Data']
311 grp = fp['Data']
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
312 thisUtcTime = grp['utctime'].value.astype(numpy.float)[0]
313
313
314 #ERROOOOR
314 #ERROOOOR
315 if self.timezone == 'lt':
315 if self.timezone == 'lt':
316 thisUtcTime -= 5*3600
316 thisUtcTime -= 5*3600
317
317
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
318 thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600)
319
319
320 thisDate = thisDatetime.date()
320 thisDate = thisDatetime.date()
321 thisTime = thisDatetime.time()
321 thisTime = thisDatetime.time()
322
322
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
323 startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
324 endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds()
325
325
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
326 ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0]
327
327
328 self.blockList = ind
328 self.blockList = ind
329 self.blocksPerFile = len(ind)
329 self.blocksPerFile = len(ind)
330
330
331 return
331 return
332
332
333 def __readMetadata(self):
333 def __readMetadata(self):
334 '''
334 '''
335 Reads Metadata
335 Reads Metadata
336
336
337 self.pathMeta
337 self.pathMeta
338
338
339 self.listShapes
339 self.listShapes
340 self.listMetaname
340 self.listMetaname
341 self.listMeta
341 self.listMeta
342
342
343 '''
343 '''
344
344
345 # grp = self.fp['Data']
345 # grp = self.fp['Data']
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
346 # pathMeta = os.path.join(self.path, grp.attrs['metadata'])
347 #
347 #
348 # if pathMeta == self.pathMeta:
348 # if pathMeta == self.pathMeta:
349 # return
349 # return
350 # else:
350 # else:
351 # self.pathMeta = pathMeta
351 # self.pathMeta = pathMeta
352 #
352 #
353 # filePointer = h5py.File(self.pathMeta,'r')
353 # filePointer = h5py.File(self.pathMeta,'r')
354 # groupPointer = filePointer['Metadata']
354 # groupPointer = filePointer['Metadata']
355
355
356 filename = self.filenameList[0]
356 filename = self.filenameList[0]
357
357
358 fp = h5py.File(filename,'r')
358 fp = h5py.File(filename,'r')
359
359
360 gp = fp['Metadata']
360 gp = fp['Metadata']
361
361
362 listMetaname = []
362 listMetaname = []
363 listMetadata = []
363 listMetadata = []
364 for item in gp.items():
364 for item in gp.items():
365 name = item[0]
365 name = item[0]
366
366
367 if name=='array dimensions':
367 if name=='array dimensions':
368 table = gp[name][:]
368 table = gp[name][:]
369 listShapes = {}
369 listShapes = {}
370 for shapes in table:
370 for shapes in table:
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
371 listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]])
372 else:
372 else:
373 data = gp[name].value
373 data = gp[name].value
374 listMetaname.append(name)
374 listMetaname.append(name)
375 listMetadata.append(data)
375 listMetadata.append(data)
376
376
377 # if name=='type':
377 # if name=='type':
378 # self.__initDataOut(data)
378 # self.__initDataOut(data)
379
379
380 self.listShapes = listShapes
380 self.listShapes = listShapes
381 self.listMetaname = listMetaname
381 self.listMetaname = listMetaname
382 self.listMeta = listMetadata
382 self.listMeta = listMetadata
383
383
384 fp.close()
384 fp.close()
385 return
385 return
386
386
387 def __readData(self):
387 def __readData(self):
388 grp = self.fp['Data']
388 grp = self.fp['Data']
389 listdataname = []
389 listdataname = []
390 listdata = []
390 listdata = []
391
391
392 for item in grp.items():
392 for item in grp.items():
393 name = item[0]
393 name = item[0]
394 listdataname.append(name)
394 listdataname.append(name)
395
395
396 array = self.__setDataArray(grp[name],self.listShapes[name])
396 array = self.__setDataArray(grp[name],self.listShapes[name])
397 listdata.append(array)
397 listdata.append(array)
398
398
399 self.listDataname = listdataname
399 self.listDataname = listdataname
400 self.listData = listdata
400 self.listData = listdata
401 return
401 return
402
402
403 def __setDataArray(self, dataset, shapes):
403 def __setDataArray(self, dataset, shapes):
404
404
405 nDims = shapes[0]
405 nDims = shapes[0]
406
406
407 nDim2 = shapes[1] #Dimension 0
407 nDim2 = shapes[1] #Dimension 0
408
408
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
409 nDim1 = shapes[2] #Dimension 1, number of Points or Parameters
410
410
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
411 nDim0 = shapes[3] #Dimension 2, number of samples or ranges
412
412
413 mode = shapes[4] #Mode of storing
413 mode = shapes[4] #Mode of storing
414
414
415 blockList = self.blockList
415 blockList = self.blockList
416
416
417 blocksPerFile = self.blocksPerFile
417 blocksPerFile = self.blocksPerFile
418
418
419 #Depending on what mode the data was stored
419 #Depending on what mode the data was stored
420 if mode == 0: #Divided in channels
420 if mode == 0: #Divided in channels
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
421 arrayData = dataset.value.astype(numpy.float)[0][blockList]
422 if mode == 1: #Divided in parameter
422 if mode == 1: #Divided in parameter
423 strds = 'table'
423 strds = 'table'
424 nDatas = nDim1
424 nDatas = nDim1
425 newShapes = (blocksPerFile,nDim2,nDim0)
425 newShapes = (blocksPerFile,nDim2,nDim0)
426 elif mode==2: #Concatenated in a table
426 elif mode==2: #Concatenated in a table
427 strds = 'table0'
427 strds = 'table0'
428 arrayData = dataset[strds].value
428 arrayData = dataset[strds].value
429 #Selecting part of the dataset
429 #Selecting part of the dataset
430 utctime = arrayData[:,0]
430 utctime = arrayData[:,0]
431 u, indices = numpy.unique(utctime, return_index=True)
431 u, indices = numpy.unique(utctime, return_index=True)
432
432
433 if blockList.size != indices.size:
433 if blockList.size != indices.size:
434 indMin = indices[blockList[0]]
434 indMin = indices[blockList[0]]
435 if blockList[1] + 1 >= indices.size:
435 if blockList[1] + 1 >= indices.size:
436 arrayData = arrayData[indMin:,:]
436 arrayData = arrayData[indMin:,:]
437 else:
437 else:
438 indMax = indices[blockList[1] + 1]
438 indMax = indices[blockList[1] + 1]
439 arrayData = arrayData[indMin:indMax,:]
439 arrayData = arrayData[indMin:indMax,:]
440 return arrayData
440 return arrayData
441
441
442 # One dimension
442 # One dimension
443 if nDims == 0:
443 if nDims == 0:
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
444 arrayData = dataset.value.astype(numpy.float)[0][blockList]
445
445
446 # Two dimensions
446 # Two dimensions
447 elif nDims == 2:
447 elif nDims == 2:
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
448 arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0))
449 newShapes = (blocksPerFile,nDim0)
449 newShapes = (blocksPerFile,nDim0)
450 nDatas = nDim1
450 nDatas = nDim1
451
451
452 for i in range(nDatas):
452 for i in range(nDatas):
453 data = dataset[strds + str(i)].value
453 data = dataset[strds + str(i)].value
454 arrayData[:,i,:] = data[blockList,:]
454 arrayData[:,i,:] = data[blockList,:]
455
455
456 # Three dimensions
456 # Three dimensions
457 else:
457 else:
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
458 arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0))
459 for i in range(nDatas):
459 for i in range(nDatas):
460
460
461 data = dataset[strds + str(i)].value
461 data = dataset[strds + str(i)].value
462
462
463 for b in range(blockList.size):
463 for b in range(blockList.size):
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
464 arrayData[b,:,i,:] = data[:,:,blockList[b]]
465
465
466 return arrayData
466 return arrayData
467
467
468 def __setDataOut(self):
468 def __setDataOut(self):
469 listMeta = self.listMeta
469 listMeta = self.listMeta
470 listMetaname = self.listMetaname
470 listMetaname = self.listMetaname
471 listDataname = self.listDataname
471 listDataname = self.listDataname
472 listData = self.listData
472 listData = self.listData
473 listShapes = self.listShapes
473 listShapes = self.listShapes
474
474
475 blockIndex = self.blockIndex
475 blockIndex = self.blockIndex
476 # blockList = self.blockList
476 # blockList = self.blockList
477
477
478 for i in range(len(listMeta)):
478 for i in range(len(listMeta)):
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
479 setattr(self.dataOut,listMetaname[i],listMeta[i])
480
480
481 for j in range(len(listData)):
481 for j in range(len(listData)):
482 nShapes = listShapes[listDataname[j]][0]
482 nShapes = listShapes[listDataname[j]][0]
483 mode = listShapes[listDataname[j]][4]
483 mode = listShapes[listDataname[j]][4]
484 if nShapes == 1:
484 if nShapes == 1:
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
485 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
486 elif nShapes > 1:
486 elif nShapes > 1:
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
487 setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:])
488 elif mode==0:
488 elif mode==0:
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
489 setattr(self.dataOut,listDataname[j],listData[j][blockIndex])
490 #Mode Meteors
490 #Mode Meteors
491 elif mode ==2:
491 elif mode ==2:
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
492 selectedData = self.__selectDataMode2(listData[j], blockIndex)
493 setattr(self.dataOut, listDataname[j], selectedData)
493 setattr(self.dataOut, listDataname[j], selectedData)
494 return
494 return
495
495
496 def __selectDataMode2(self, data, blockIndex):
496 def __selectDataMode2(self, data, blockIndex):
497 utctime = data[:,0]
497 utctime = data[:,0]
498 aux, indices = numpy.unique(utctime, return_inverse=True)
498 aux, indices = numpy.unique(utctime, return_inverse=True)
499 selInd = numpy.where(indices == blockIndex)[0]
499 selInd = numpy.where(indices == blockIndex)[0]
500 selData = data[selInd,:]
500 selData = data[selInd,:]
501
501
502 return selData
502 return selData
503
503
504 def getData(self):
504 def getData(self):
505
505
506 # if self.flagNoMoreFiles:
506 # if self.flagNoMoreFiles:
507 # self.dataOut.flagNoData = True
507 # self.dataOut.flagNoData = True
508 # print 'Process finished'
508 # print 'Process finished'
509 # return 0
509 # return 0
510 #
510 #
511 if self.blockIndex==self.blocksPerFile:
511 if self.blockIndex==self.blocksPerFile:
512 if not( self.__setNextFileOffline() ):
512 if not( self.__setNextFileOffline() ):
513 self.dataOut.flagNoData = True
513 self.dataOut.flagNoData = True
514 return 0
514 return 0
515
515
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
516 # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers
517 # self.dataOut.flagNoData = True
517 # self.dataOut.flagNoData = True
518 # return 0
518 # return 0
519 # self.__readData()
519 # self.__readData()
520 self.__setDataOut()
520 self.__setDataOut()
521 self.dataOut.flagNoData = False
521 self.dataOut.flagNoData = False
522
522
523 self.blockIndex += 1
523 self.blockIndex += 1
524
524
525 return
525 return
526
526
527 def run(self, **kwargs):
527 def run(self, **kwargs):
528
528
529 if not(self.isConfig):
529 if not(self.isConfig):
530 self.setup(**kwargs)
530 self.setup(**kwargs)
531 # self.setObjProperties()
531 # self.setObjProperties()
532 self.isConfig = True
532 self.isConfig = True
533
533
534 self.getData()
534 self.getData()
535
535
536 return
536 return
537
537
538 class ParamWriter(Operation):
538 class ParamWriter(Operation):
539 '''
539 '''
540 HDF5 Writer, stores parameters data in HDF5 format files
540 HDF5 Writer, stores parameters data in HDF5 format files
541
541
542 path: path where the files will be stored
542 path: path where the files will be stored
543
543
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
544 blocksPerFile: number of blocks that will be saved in per HDF5 format file
545
545
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
546 mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors)
547
547
548 metadataList: list of attributes that will be stored as metadata
548 metadataList: list of attributes that will be stored as metadata
549
549
550 dataList: list of attributes that will be stores as data
550 dataList: list of attributes that will be stores as data
551
551
552 '''
552 '''
553
553
554
554
555 ext = ".hdf5"
555 ext = ".hdf5"
556
556
557 optchar = "D"
557 optchar = "D"
558
558
559 metaoptchar = "M"
559 metaoptchar = "M"
560
560
561 metaFile = None
561 metaFile = None
562
562
563 filename = None
563 filename = None
564
564
565 path = None
565 path = None
566
566
567 setFile = None
567 setFile = None
568
568
569 fp = None
569 fp = None
570
570
571 grp = None
571 grp = None
572
572
573 ds = None
573 ds = None
574
574
575 firsttime = True
575 firsttime = True
576
576
577 #Configurations
577 #Configurations
578
578
579 blocksPerFile = None
579 blocksPerFile = None
580
580
581 blockIndex = None
581 blockIndex = None
582
582
583 dataOut = None
583 dataOut = None
584
584
585 #Data Arrays
585 #Data Arrays
586
586
587 dataList = None
587 dataList = None
588
588
589 metadataList = None
589 metadataList = None
590
590
591 # arrayDim = None
591 # arrayDim = None
592
592
593 dsList = None #List of dictionaries with dataset properties
593 dsList = None #List of dictionaries with dataset properties
594
594
595 tableDim = None
595 tableDim = None
596
596
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
597 # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')]
598
598
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
599 dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')]
600
600
601 currentDay = None
601 currentDay = None
602
602
603 lastTime = None
603 lastTime = None
604
604
605 def __init__(self, **kwargs):
605 def __init__(self, **kwargs):
606 Operation.__init__(self, **kwargs)
606 Operation.__init__(self, **kwargs)
607 self.isConfig = False
607 self.isConfig = False
608 return
608 return
609
609
610 def setup(self, dataOut, **kwargs):
610 def setup(self, dataOut, **kwargs):
611
611
612 self.path = kwargs['path']
612 self.path = kwargs['path']
613
613
614 if kwargs.has_key('blocksPerFile'):
614 if kwargs.has_key('blocksPerFile'):
615 self.blocksPerFile = kwargs['blocksPerFile']
615 self.blocksPerFile = kwargs['blocksPerFile']
616 else:
616 else:
617 self.blocksPerFile = 10
617 self.blocksPerFile = 10
618
618
619 self.metadataList = kwargs['metadataList']
619 self.metadataList = kwargs['metadataList']
620 self.dataList = kwargs['dataList']
620 self.dataList = kwargs['dataList']
621 self.dataOut = dataOut
621 self.dataOut = dataOut
622
622
623 if kwargs.has_key('mode'):
623 if kwargs.has_key('mode'):
624 mode = kwargs['mode']
624 mode = kwargs['mode']
625
625
626 if type(mode) == int:
626 if type(mode) == int:
627 mode = numpy.zeros(len(self.dataList)) + mode
627 mode = numpy.zeros(len(self.dataList)) + mode
628 else:
628 else:
629 mode = numpy.ones(len(self.dataList))
629 mode = numpy.ones(len(self.dataList))
630
630
631 self.mode = mode
631 self.mode = mode
632
632
633 arrayDim = numpy.zeros((len(self.dataList),5))
633 arrayDim = numpy.zeros((len(self.dataList),5))
634
634
635 #Table dimensions
635 #Table dimensions
636 dtype0 = self.dtype
636 dtype0 = self.dtype
637 tableList = []
637 tableList = []
638
638
639 #Dictionary and list of tables
639 #Dictionary and list of tables
640 dsList = []
640 dsList = []
641
641
642 for i in range(len(self.dataList)):
642 for i in range(len(self.dataList)):
643 dsDict = {}
643 dsDict = {}
644 dataAux = getattr(self.dataOut, self.dataList[i])
644 dataAux = getattr(self.dataOut, self.dataList[i])
645 dsDict['variable'] = self.dataList[i]
645 dsDict['variable'] = self.dataList[i]
646 #--------------------- Conditionals ------------------------
646 #--------------------- Conditionals ------------------------
647 #There is no data
647 #There is no data
648 if dataAux is None:
648 if dataAux is None:
649 return 0
649 return 0
650
650
651 #Not array, just a number
651 #Not array, just a number
652 #Mode 0
652 #Mode 0
653 if type(dataAux)==float or type(dataAux)==int:
653 if type(dataAux)==float or type(dataAux)==int:
654 dsDict['mode'] = 0
654 dsDict['mode'] = 0
655 dsDict['nDim'] = 0
655 dsDict['nDim'] = 0
656 arrayDim[i,0] = 0
656 arrayDim[i,0] = 0
657 dsList.append(dsDict)
657 dsList.append(dsDict)
658
658
659 #Mode 2: meteors
659 #Mode 2: meteors
660 elif mode[i] == 2:
660 elif mode[i] == 2:
661 # dsDict['nDim'] = 0
661 # dsDict['nDim'] = 0
662 dsDict['dsName'] = 'table0'
662 dsDict['dsName'] = 'table0'
663 dsDict['mode'] = 2 # Mode meteors
663 dsDict['mode'] = 2 # Mode meteors
664 dsDict['shape'] = dataAux.shape[-1]
664 dsDict['shape'] = dataAux.shape[-1]
665 dsDict['nDim'] = 0
665 dsDict['nDim'] = 0
666 dsDict['dsNumber'] = 1
666 dsDict['dsNumber'] = 1
667
667
668 arrayDim[i,3] = dataAux.shape[-1]
668 arrayDim[i,3] = dataAux.shape[-1]
669 arrayDim[i,4] = mode[i] #Mode the data was stored
669 arrayDim[i,4] = mode[i] #Mode the data was stored
670
670
671 dsList.append(dsDict)
671 dsList.append(dsDict)
672
672
673 #Mode 1
673 #Mode 1
674 else:
674 else:
675 arrayDim0 = dataAux.shape #Data dimensions
675 arrayDim0 = dataAux.shape #Data dimensions
676 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
676 arrayDim[i,0] = len(arrayDim0) #Number of array dimensions
677 arrayDim[i,4] = mode[i] #Mode the data was stored
677 arrayDim[i,4] = mode[i] #Mode the data was stored
678
678
679 strtable = 'table'
679 strtable = 'table'
680 dsDict['mode'] = 1 # Mode parameters
680 dsDict['mode'] = 1 # Mode parameters
681
681
682 # Three-dimension arrays
682 # Three-dimension arrays
683 if len(arrayDim0) == 3:
683 if len(arrayDim0) == 3:
684 arrayDim[i,1:-1] = numpy.array(arrayDim0)
684 arrayDim[i,1:-1] = numpy.array(arrayDim0)
685 nTables = int(arrayDim[i,2])
685 nTables = int(arrayDim[i,2])
686 dsDict['dsNumber'] = nTables
686 dsDict['dsNumber'] = nTables
687 dsDict['shape'] = arrayDim[i,2:4]
687 dsDict['shape'] = arrayDim[i,2:4]
688 dsDict['nDim'] = 3
688 dsDict['nDim'] = 3
689
689
690 for j in range(nTables):
690 for j in range(nTables):
691 dsDict = dsDict.copy()
691 dsDict = dsDict.copy()
692 dsDict['dsName'] = strtable + str(j)
692 dsDict['dsName'] = strtable + str(j)
693 dsList.append(dsDict)
693 dsList.append(dsDict)
694
694
695 # Two-dimension arrays
695 # Two-dimension arrays
696 elif len(arrayDim0) == 2:
696 elif len(arrayDim0) == 2:
697 arrayDim[i,2:-1] = numpy.array(arrayDim0)
697 arrayDim[i,2:-1] = numpy.array(arrayDim0)
698 nTables = int(arrayDim[i,2])
698 nTables = int(arrayDim[i,2])
699 dsDict['dsNumber'] = nTables
699 dsDict['dsNumber'] = nTables
700 dsDict['shape'] = arrayDim[i,3]
700 dsDict['shape'] = arrayDim[i,3]
701 dsDict['nDim'] = 2
701 dsDict['nDim'] = 2
702
702
703 for j in range(nTables):
703 for j in range(nTables):
704 dsDict = dsDict.copy()
704 dsDict = dsDict.copy()
705 dsDict['dsName'] = strtable + str(j)
705 dsDict['dsName'] = strtable + str(j)
706 dsList.append(dsDict)
706 dsList.append(dsDict)
707
707
708 # One-dimension arrays
708 # One-dimension arrays
709 elif len(arrayDim0) == 1:
709 elif len(arrayDim0) == 1:
710 arrayDim[i,3] = arrayDim0[0]
710 arrayDim[i,3] = arrayDim0[0]
711 dsDict['shape'] = arrayDim0[0]
711 dsDict['shape'] = arrayDim0[0]
712 dsDict['dsNumber'] = 1
712 dsDict['dsNumber'] = 1
713 dsDict['dsName'] = strtable + str(0)
713 dsDict['dsName'] = strtable + str(0)
714 dsDict['nDim'] = 1
714 dsDict['nDim'] = 1
715 dsList.append(dsDict)
715 dsList.append(dsDict)
716
716
717 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
717 table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0)
718 tableList.append(table)
718 tableList.append(table)
719
719
720 # self.arrayDim = arrayDim
720 # self.arrayDim = arrayDim
721 self.dsList = dsList
721 self.dsList = dsList
722 self.tableDim = numpy.array(tableList, dtype = dtype0)
722 self.tableDim = numpy.array(tableList, dtype = dtype0)
723 self.blockIndex = 0
723 self.blockIndex = 0
724
724
725 timeTuple = time.localtime(dataOut.utctime)
725 timeTuple = time.localtime(dataOut.utctime)
726 self.currentDay = timeTuple.tm_yday
726 self.currentDay = timeTuple.tm_yday
727 return 1
727 return 1
728
728
729 def putMetadata(self):
729 def putMetadata(self):
730
730
731 fp = self.createMetadataFile()
731 fp = self.createMetadataFile()
732 self.writeMetadata(fp)
732 self.writeMetadata(fp)
733 fp.close()
733 fp.close()
734 return
734 return
735
735
736 def createMetadataFile(self):
736 def createMetadataFile(self):
737 ext = self.ext
737 ext = self.ext
738 path = self.path
738 path = self.path
739 setFile = self.setFile
739 setFile = self.setFile
740
740
741 timeTuple = time.localtime(self.dataOut.utctime)
741 timeTuple = time.localtime(self.dataOut.utctime)
742
742
743 subfolder = ''
743 subfolder = ''
744 fullpath = os.path.join( path, subfolder )
744 fullpath = os.path.join( path, subfolder )
745
745
746 if not( os.path.exists(fullpath) ):
746 if not( os.path.exists(fullpath) ):
747 os.mkdir(fullpath)
747 os.mkdir(fullpath)
748 setFile = -1 #inicializo mi contador de seteo
748 setFile = -1 #inicializo mi contador de seteo
749
749
750 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
750 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
751 fullpath = os.path.join( path, subfolder )
751 fullpath = os.path.join( path, subfolder )
752
752
753 if not( os.path.exists(fullpath) ):
753 if not( os.path.exists(fullpath) ):
754 os.mkdir(fullpath)
754 os.mkdir(fullpath)
755 setFile = -1 #inicializo mi contador de seteo
755 setFile = -1 #inicializo mi contador de seteo
756
756
757 else:
757 else:
758 filesList = os.listdir( fullpath )
758 filesList = os.listdir( fullpath )
759 filesList = sorted( filesList, key=str.lower )
759 filesList = sorted( filesList, key=str.lower )
760 if len( filesList ) > 0:
760 if len( filesList ) > 0:
761 filesList = [k for k in filesList if 'M' in k]
761 filesList = [k for k in filesList if 'M' in k]
762 filen = filesList[-1]
762 filen = filesList[-1]
763 # el filename debera tener el siguiente formato
763 # el filename debera tener el siguiente formato
764 # 0 1234 567 89A BCDE (hex)
764 # 0 1234 567 89A BCDE (hex)
765 # x YYYY DDD SSS .ext
765 # x YYYY DDD SSS .ext
766 if isNumber( filen[8:11] ):
766 if isNumber( filen[8:11] ):
767 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
767 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
768 else:
768 else:
769 setFile = -1
769 setFile = -1
770 else:
770 else:
771 setFile = -1 #inicializo mi contador de seteo
771 setFile = -1 #inicializo mi contador de seteo
772
772
773 setFile += 1
773 setFile += 1
774
774
775 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
775 file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar,
776 timeTuple.tm_year,
776 timeTuple.tm_year,
777 timeTuple.tm_yday,
777 timeTuple.tm_yday,
778 setFile,
778 setFile,
779 ext )
779 ext )
780
780
781 filename = os.path.join( path, subfolder, file )
781 filename = os.path.join( path, subfolder, file )
782 self.metaFile = file
782 self.metaFile = file
783 #Setting HDF5 File
783 #Setting HDF5 File
784 fp = h5py.File(filename,'w')
784 fp = h5py.File(filename,'w')
785
785
786 return fp
786 return fp
787
787
788 def writeMetadata(self, fp):
788 def writeMetadata(self, fp):
789
789
790 grp = fp.create_group("Metadata")
790 grp = fp.create_group("Metadata")
791 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
791 grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype)
792
792
793 for i in range(len(self.metadataList)):
793 for i in range(len(self.metadataList)):
794 print '#####',self.metadataList[i], getattr(self.dataOut, self.metadataList[i])
794 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
795 grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i]))
795 return
796 return
796
797
797 def timeFlag(self):
798 def timeFlag(self):
798 currentTime = self.dataOut.utctime
799 currentTime = self.dataOut.utctime
799
800
800 if self.lastTime is None:
801 if self.lastTime is None:
801 self.lastTime = currentTime
802 self.lastTime = currentTime
802
803
803 #Day
804 #Day
804 timeTuple = time.localtime(currentTime)
805 timeTuple = time.localtime(currentTime)
805 dataDay = timeTuple.tm_yday
806 dataDay = timeTuple.tm_yday
806
807
807 #Time
808 #Time
808 timeDiff = currentTime - self.lastTime
809 timeDiff = currentTime - self.lastTime
809
810
810 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
811 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
811 if dataDay != self.currentDay:
812 if dataDay != self.currentDay:
812 self.currentDay = dataDay
813 self.currentDay = dataDay
813 return True
814 return True
814 elif timeDiff > 3*60*60:
815 elif timeDiff > 3*60*60:
815 self.lastTime = currentTime
816 self.lastTime = currentTime
816 return True
817 return True
817 else:
818 else:
818 self.lastTime = currentTime
819 self.lastTime = currentTime
819 return False
820 return False
820
821
821 def setNextFile(self):
822 def setNextFile(self):
822
823
823 ext = self.ext
824 ext = self.ext
824 path = self.path
825 path = self.path
825 setFile = self.setFile
826 setFile = self.setFile
826 mode = self.mode
827 mode = self.mode
827
828
828 timeTuple = time.localtime(self.dataOut.utctime)
829 timeTuple = time.localtime(self.dataOut.utctime)
829 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
830 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
830
831
831 fullpath = os.path.join( path, subfolder )
832 fullpath = os.path.join( path, subfolder )
832
833
833 if os.path.exists(fullpath):
834 if os.path.exists(fullpath):
834 filesList = os.listdir( fullpath )
835 filesList = os.listdir( fullpath )
835 filesList = [k for k in filesList if 'D' in k]
836 filesList = [k for k in filesList if 'D' in k]
836 if len( filesList ) > 0:
837 if len( filesList ) > 0:
837 filesList = sorted( filesList, key=str.lower )
838 filesList = sorted( filesList, key=str.lower )
838 filen = filesList[-1]
839 filen = filesList[-1]
839 # el filename debera tener el siguiente formato
840 # el filename debera tener el siguiente formato
840 # 0 1234 567 89A BCDE (hex)
841 # 0 1234 567 89A BCDE (hex)
841 # x YYYY DDD SSS .ext
842 # x YYYY DDD SSS .ext
842 if isNumber( filen[8:11] ):
843 if isNumber( filen[8:11] ):
843 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
844 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
844 else:
845 else:
845 setFile = -1
846 setFile = -1
846 else:
847 else:
847 setFile = -1 #inicializo mi contador de seteo
848 setFile = -1 #inicializo mi contador de seteo
848 else:
849 else:
849 os.makedirs(fullpath)
850 os.makedirs(fullpath)
850 setFile = -1 #inicializo mi contador de seteo
851 setFile = -1 #inicializo mi contador de seteo
851
852
852 setFile += 1
853 setFile += 1
853
854
854 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
855 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
855 timeTuple.tm_year,
856 timeTuple.tm_year,
856 timeTuple.tm_yday,
857 timeTuple.tm_yday,
857 setFile,
858 setFile,
858 ext )
859 ext )
859
860
860 filename = os.path.join( path, subfolder, file )
861 filename = os.path.join( path, subfolder, file )
861
862
862 #Setting HDF5 File
863 #Setting HDF5 File
863 fp = h5py.File(filename,'w')
864 fp = h5py.File(filename,'w')
864 #write metadata
865 #write metadata
865 self.writeMetadata(fp)
866 self.writeMetadata(fp)
866 #Write data
867 #Write data
867 grp = fp.create_group("Data")
868 grp = fp.create_group("Data")
868 # grp.attrs['metadata'] = self.metaFile
869 # grp.attrs['metadata'] = self.metaFile
869
870
870 # grp.attrs['blocksPerFile'] = 0
871 # grp.attrs['blocksPerFile'] = 0
871 ds = []
872 ds = []
872 data = []
873 data = []
873 dsList = self.dsList
874 dsList = self.dsList
874 i = 0
875 i = 0
875 while i < len(dsList):
876 while i < len(dsList):
876 dsInfo = dsList[i]
877 dsInfo = dsList[i]
877 #One-dimension data
878 #One-dimension data
878 if dsInfo['mode'] == 0:
879 if dsInfo['mode'] == 0:
879 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
880 # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20')
880 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
881 ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64)
881 ds.append(ds0)
882 ds.append(ds0)
882 data.append([])
883 data.append([])
883 i += 1
884 i += 1
884 continue
885 continue
885 # nDimsForDs.append(nDims[i])
886 # nDimsForDs.append(nDims[i])
886
887
887 elif dsInfo['mode'] == 2:
888 elif dsInfo['mode'] == 2:
888 grp0 = grp.create_group(dsInfo['variable'])
889 grp0 = grp.create_group(dsInfo['variable'])
889 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
890 ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True)
890 ds.append(ds0)
891 ds.append(ds0)
891 data.append([])
892 data.append([])
892 i += 1
893 i += 1
893 continue
894 continue
894
895
895 elif dsInfo['mode'] == 1:
896 elif dsInfo['mode'] == 1:
896 grp0 = grp.create_group(dsInfo['variable'])
897 grp0 = grp.create_group(dsInfo['variable'])
897
898
898 for j in range(dsInfo['dsNumber']):
899 for j in range(dsInfo['dsNumber']):
899 dsInfo = dsList[i]
900 dsInfo = dsList[i]
900 tableName = dsInfo['dsName']
901 tableName = dsInfo['dsName']
901 shape = int(dsInfo['shape'])
902 shape = int(dsInfo['shape'])
902
903
903 if dsInfo['nDim'] == 3:
904 if dsInfo['nDim'] == 3:
904 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True)
905 else:
906 else:
906 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
907 ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True)
907
908
908 ds.append(ds0)
909 ds.append(ds0)
909 data.append([])
910 data.append([])
910 i += 1
911 i += 1
911 # nDimsForDs.append(nDims[i])
912 # nDimsForDs.append(nDims[i])
912
913
913 fp.flush()
914 fp.flush()
914 fp.close()
915 fp.close()
915
916
916 # self.nDatas = nDatas
917 # self.nDatas = nDatas
917 # self.nDims = nDims
918 # self.nDims = nDims
918 # self.nDimsForDs = nDimsForDs
919 # self.nDimsForDs = nDimsForDs
919 #Saving variables
920 #Saving variables
920 print 'Writing the file: %s'%filename
921 print 'Writing the file: %s'%filename
921 self.filename = filename
922 self.filename = filename
922 # self.fp = fp
923 # self.fp = fp
923 # self.grp = grp
924 # self.grp = grp
924 # self.grp.attrs.modify('nRecords', 1)
925 # self.grp.attrs.modify('nRecords', 1)
925 self.ds = ds
926 self.ds = ds
926 self.data = data
927 self.data = data
927 # self.setFile = setFile
928 # self.setFile = setFile
928 self.firsttime = True
929 self.firsttime = True
929 self.blockIndex = 0
930 self.blockIndex = 0
930 return
931 return
931
932
932 def putData(self):
933 def putData(self):
933
934
934 if self.blockIndex == self.blocksPerFile or self.timeFlag():
935 if self.blockIndex == self.blocksPerFile or self.timeFlag():
935 self.setNextFile()
936 self.setNextFile()
936
937
937 # if not self.firsttime:
938 # if not self.firsttime:
938 self.readBlock()
939 self.readBlock()
939 self.setBlock() #Prepare data to be written
940 self.setBlock() #Prepare data to be written
940 self.writeBlock() #Write data
941 self.writeBlock() #Write data
941
942
942 return
943 return
943
944
944 def readBlock(self):
945 def readBlock(self):
945
946
946 '''
947 '''
947 data Array configured
948 data Array configured
948
949
949
950
950 self.data
951 self.data
951 '''
952 '''
952 dsList = self.dsList
953 dsList = self.dsList
953 ds = self.ds
954 ds = self.ds
954 #Setting HDF5 File
955 #Setting HDF5 File
955 fp = h5py.File(self.filename,'r+')
956 fp = h5py.File(self.filename,'r+')
956 grp = fp["Data"]
957 grp = fp["Data"]
957 ind = 0
958 ind = 0
958
959
959 # grp.attrs['blocksPerFile'] = 0
960 # grp.attrs['blocksPerFile'] = 0
960 while ind < len(dsList):
961 while ind < len(dsList):
961 dsInfo = dsList[ind]
962 dsInfo = dsList[ind]
962
963
963 if dsInfo['mode'] == 0:
964 if dsInfo['mode'] == 0:
964 ds0 = grp[dsInfo['variable']]
965 ds0 = grp[dsInfo['variable']]
965 ds[ind] = ds0
966 ds[ind] = ds0
966 ind += 1
967 ind += 1
967 else:
968 else:
968
969
969 grp0 = grp[dsInfo['variable']]
970 grp0 = grp[dsInfo['variable']]
970
971
971 for j in range(dsInfo['dsNumber']):
972 for j in range(dsInfo['dsNumber']):
972 dsInfo = dsList[ind]
973 dsInfo = dsList[ind]
973 ds0 = grp0[dsInfo['dsName']]
974 ds0 = grp0[dsInfo['dsName']]
974 ds[ind] = ds0
975 ds[ind] = ds0
975 ind += 1
976 ind += 1
976
977
977 self.fp = fp
978 self.fp = fp
978 self.grp = grp
979 self.grp = grp
979 self.ds = ds
980 self.ds = ds
980
981
981 return
982 return
982
983
983 def setBlock(self):
984 def setBlock(self):
984 '''
985 '''
985 data Array configured
986 data Array configured
986
987
987
988
988 self.data
989 self.data
989 '''
990 '''
990 #Creating Arrays
991 #Creating Arrays
991 dsList = self.dsList
992 dsList = self.dsList
992 data = self.data
993 data = self.data
993 ind = 0
994 ind = 0
994
995
995 while ind < len(dsList):
996 while ind < len(dsList):
996 dsInfo = dsList[ind]
997 dsInfo = dsList[ind]
997 dataAux = getattr(self.dataOut, dsInfo['variable'])
998 dataAux = getattr(self.dataOut, dsInfo['variable'])
998
999
999 mode = dsInfo['mode']
1000 mode = dsInfo['mode']
1000 nDim = dsInfo['nDim']
1001 nDim = dsInfo['nDim']
1001
1002
1002 if mode == 0 or mode == 2 or nDim == 1:
1003 if mode == 0 or mode == 2 or nDim == 1:
1003 data[ind] = dataAux
1004 data[ind] = dataAux
1004 ind += 1
1005 ind += 1
1005 # elif nDim == 1:
1006 # elif nDim == 1:
1006 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1007 # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1))
1007 # ind += 1
1008 # ind += 1
1008 elif nDim == 2:
1009 elif nDim == 2:
1009 for j in range(dsInfo['dsNumber']):
1010 for j in range(dsInfo['dsNumber']):
1010 data[ind] = dataAux[j,:]
1011 data[ind] = dataAux[j,:]
1011 ind += 1
1012 ind += 1
1012 elif nDim == 3:
1013 elif nDim == 3:
1013 for j in range(dsInfo['dsNumber']):
1014 for j in range(dsInfo['dsNumber']):
1014 data[ind] = dataAux[:,j,:]
1015 data[ind] = dataAux[:,j,:]
1015 ind += 1
1016 ind += 1
1016
1017
1017 self.data = data
1018 self.data = data
1018 return
1019 return
1019
1020
1020 def writeBlock(self):
1021 def writeBlock(self):
1021 '''
1022 '''
1022 Saves the block in the HDF5 file
1023 Saves the block in the HDF5 file
1023 '''
1024 '''
1024 dsList = self.dsList
1025 dsList = self.dsList
1025
1026
1026 for i in range(len(self.ds)):
1027 for i in range(len(self.ds)):
1027 dsInfo = dsList[i]
1028 dsInfo = dsList[i]
1028 nDim = dsInfo['nDim']
1029 nDim = dsInfo['nDim']
1029 mode = dsInfo['mode']
1030 mode = dsInfo['mode']
1030
1031
1031 # First time
1032 # First time
1032 if self.firsttime:
1033 if self.firsttime:
1033 # self.ds[i].resize(self.data[i].shape)
1034 # self.ds[i].resize(self.data[i].shape)
1034 # self.ds[i][self.blockIndex,:] = self.data[i]
1035 # self.ds[i][self.blockIndex,:] = self.data[i]
1035 if type(self.data[i]) == numpy.ndarray:
1036 if type(self.data[i]) == numpy.ndarray:
1036
1037
1037 if nDim == 3:
1038 if nDim == 3:
1038 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1039 self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1))
1039 self.ds[i].resize(self.data[i].shape)
1040 self.ds[i].resize(self.data[i].shape)
1040 if mode == 2:
1041 if mode == 2:
1041 self.ds[i].resize(self.data[i].shape)
1042 self.ds[i].resize(self.data[i].shape)
1042 self.ds[i][:] = self.data[i]
1043 self.ds[i][:] = self.data[i]
1043 else:
1044 else:
1044
1045
1045 # From second time
1046 # From second time
1046 # Meteors!
1047 # Meteors!
1047 if mode == 2:
1048 if mode == 2:
1048 dataShape = self.data[i].shape
1049 dataShape = self.data[i].shape
1049 dsShape = self.ds[i].shape
1050 dsShape = self.ds[i].shape
1050 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1051 self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1]))
1051 self.ds[i][dsShape[0]:,:] = self.data[i]
1052 self.ds[i][dsShape[0]:,:] = self.data[i]
1052 # No dimension
1053 # No dimension
1053 elif mode == 0:
1054 elif mode == 0:
1054 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1055 self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1))
1055 self.ds[i][0,-1] = self.data[i]
1056 self.ds[i][0,-1] = self.data[i]
1056 # One dimension
1057 # One dimension
1057 elif nDim == 1:
1058 elif nDim == 1:
1058 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1059 self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1]))
1059 self.ds[i][-1,:] = self.data[i]
1060 self.ds[i][-1,:] = self.data[i]
1060 # Two dimension
1061 # Two dimension
1061 elif nDim == 2:
1062 elif nDim == 2:
1062 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1063 self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1]))
1063 self.ds[i][self.blockIndex,:] = self.data[i]
1064 self.ds[i][self.blockIndex,:] = self.data[i]
1064 # Three dimensions
1065 # Three dimensions
1065 elif nDim == 3:
1066 elif nDim == 3:
1066 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1067 self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1))
1067 self.ds[i][:,:,-1] = self.data[i]
1068 self.ds[i][:,:,-1] = self.data[i]
1068
1069
1069 self.firsttime = False
1070 self.firsttime = False
1070 self.blockIndex += 1
1071 self.blockIndex += 1
1071
1072
1072 #Close to save changes
1073 #Close to save changes
1073 self.fp.flush()
1074 self.fp.flush()
1074 self.fp.close()
1075 self.fp.close()
1075 return
1076 return
1076
1077
1077 def run(self, dataOut, **kwargs):
1078 def run(self, dataOut, **kwargs):
1078
1079
1079 if not(self.isConfig):
1080 if not(self.isConfig):
1080 flagdata = self.setup(dataOut, **kwargs)
1081 flagdata = self.setup(dataOut, **kwargs)
1081
1082
1082 if not(flagdata):
1083 if not(flagdata):
1083 return
1084 return
1084
1085
1085 self.isConfig = True
1086 self.isConfig = True
1086 # self.putMetadata()
1087 # self.putMetadata()
1087 self.setNextFile()
1088 self.setNextFile()
1088
1089
1089 self.putData()
1090 self.putData()
1090 return
1091 return
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,1064 +1,1068
1 import numpy
1 import numpy
2
2
3 from jroproc_base import ProcessingUnit, Operation
3 from jroproc_base import ProcessingUnit, Operation
4 from schainpy.model.data.jrodata import Spectra
4 from schainpy.model.data.jrodata import Spectra
5 from schainpy.model.data.jrodata import hildebrand_sekhon
5 from schainpy.model.data.jrodata import hildebrand_sekhon
6
6
7 import matplotlib.pyplot as plt
7 import matplotlib.pyplot as plt
8
8
9 class SpectraProc(ProcessingUnit):
9 class SpectraProc(ProcessingUnit):
10
10
11 def __init__(self, **kwargs):
11 def __init__(self, **kwargs):
12
12
13 ProcessingUnit.__init__(self, **kwargs)
13 ProcessingUnit.__init__(self, **kwargs)
14
14
15 self.buffer = None
15 self.buffer = None
16 self.firstdatatime = None
16 self.firstdatatime = None
17 self.profIndex = 0
17 self.profIndex = 0
18 self.dataOut = Spectra()
18 self.dataOut = Spectra()
19 self.id_min = None
19 self.id_min = None
20 self.id_max = None
20 self.id_max = None
21
21
22 def __updateSpecFromVoltage(self):
22 def __updateSpecFromVoltage(self):
23
23
24 self.dataOut.timeZone = self.dataIn.timeZone
24 self.dataOut.timeZone = self.dataIn.timeZone
25 self.dataOut.dstFlag = self.dataIn.dstFlag
25 self.dataOut.dstFlag = self.dataIn.dstFlag
26 self.dataOut.errorCount = self.dataIn.errorCount
26 self.dataOut.errorCount = self.dataIn.errorCount
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
27 self.dataOut.useLocalTime = self.dataIn.useLocalTime
28
28
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
29 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
30 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
31 self.dataOut.channelList = self.dataIn.channelList
31 self.dataOut.channelList = self.dataIn.channelList
32 self.dataOut.heightList = self.dataIn.heightList
32 self.dataOut.heightList = self.dataIn.heightList
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
33 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
34
34
35 self.dataOut.nBaud = self.dataIn.nBaud
35 self.dataOut.nBaud = self.dataIn.nBaud
36 self.dataOut.nCode = self.dataIn.nCode
36 self.dataOut.nCode = self.dataIn.nCode
37 self.dataOut.code = self.dataIn.code
37 self.dataOut.code = self.dataIn.code
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
39
39
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 self.dataOut.utctime = self.firstdatatime
41 self.dataOut.utctime = self.firstdatatime
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 self.dataOut.flagShiftFFT = False
44 self.dataOut.flagShiftFFT = False
45
45
46 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nCohInt = self.dataIn.nCohInt
47 self.dataOut.nIncohInt = 1
47 self.dataOut.nIncohInt = 1
48
48
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
50
50
51 self.dataOut.frequency = self.dataIn.frequency
51 self.dataOut.frequency = self.dataIn.frequency
52 self.dataOut.realtime = self.dataIn.realtime
52 self.dataOut.realtime = self.dataIn.realtime
53
53
54 self.dataOut.azimuth = self.dataIn.azimuth
54 self.dataOut.azimuth = self.dataIn.azimuth
55 self.dataOut.zenith = self.dataIn.zenith
55 self.dataOut.zenith = self.dataIn.zenith
56
56
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
60
60
61 def __getFft(self):
61 def __getFft(self):
62 """
62 """
63 Convierte valores de Voltaje a Spectra
63 Convierte valores de Voltaje a Spectra
64
64
65 Affected:
65 Affected:
66 self.dataOut.data_spc
66 self.dataOut.data_spc
67 self.dataOut.data_cspc
67 self.dataOut.data_cspc
68 self.dataOut.data_dc
68 self.dataOut.data_dc
69 self.dataOut.heightList
69 self.dataOut.heightList
70 self.profIndex
70 self.profIndex
71 self.buffer
71 self.buffer
72 self.dataOut.flagNoData
72 self.dataOut.flagNoData
73 """
73 """
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
75
75 fft_volt = fft_volt.astype(numpy.dtype('complex'))
76 fft_volt = fft_volt.astype(numpy.dtype('complex'))
76 dc = fft_volt[:,0,:]
77 dc = fft_volt[:,0,:]
77
78
78 #calculo de self-spectra
79 #calculo de self-spectra
79 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
80 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
80 spc = fft_volt * numpy.conjugate(fft_volt)
81 spc = fft_volt * numpy.conjugate(fft_volt)
81 spc = spc.real
82 spc = spc.real
82
83
83 blocksize = 0
84 blocksize = 0
84 blocksize += dc.size
85 blocksize += dc.size
85 blocksize += spc.size
86 blocksize += spc.size
86
87
87 cspc = None
88 cspc = None
88 pairIndex = 0
89 pairIndex = 0
89 if self.dataOut.pairsList != None:
90 if self.dataOut.pairsList != None:
90 #calculo de cross-spectra
91 #calculo de cross-spectra
91 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
92 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
92 for pair in self.dataOut.pairsList:
93 for pair in self.dataOut.pairsList:
93 if pair[0] not in self.dataOut.channelList:
94 if pair[0] not in self.dataOut.channelList:
94 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
95 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
95 if pair[1] not in self.dataOut.channelList:
96 if pair[1] not in self.dataOut.channelList:
96 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
97 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
97
98
98 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
99 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
99 pairIndex += 1
100 pairIndex += 1
100 blocksize += cspc.size
101 blocksize += cspc.size
101
102
102 self.dataOut.data_spc = spc
103 self.dataOut.data_spc = spc
103 self.dataOut.data_cspc = cspc
104 self.dataOut.data_cspc = cspc
104 self.dataOut.data_dc = dc
105 self.dataOut.data_dc = dc
105 self.dataOut.blockSize = blocksize
106 self.dataOut.blockSize = blocksize
106 self.dataOut.flagShiftFFT = True
107 self.dataOut.flagShiftFFT = True
107
108
108 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
109 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
109
110
110 self.dataOut.flagNoData = True
111 self.dataOut.flagNoData = True
111
112
112 if self.dataIn.type == "Spectra":
113 if self.dataIn.type == "Spectra":
113 self.dataOut.copy(self.dataIn)
114 self.dataOut.copy(self.dataIn)
114 # self.__selectPairs(pairsList)
115 # self.__selectPairs(pairsList)
115 return True
116 return True
116
117
117 if self.dataIn.type == "Voltage":
118 if self.dataIn.type == "Voltage":
118
119
119 if nFFTPoints == None:
120 if nFFTPoints == None:
120 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
121 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
121
122
122 if nProfiles == None:
123 if nProfiles == None:
123 nProfiles = nFFTPoints
124 nProfiles = nFFTPoints
124
125
125 if ippFactor == None:
126 if ippFactor == None:
126 ippFactor = 1
127 ippFactor = 1
127
128
128 self.dataOut.ippFactor = ippFactor
129 self.dataOut.ippFactor = ippFactor
129
130
130 self.dataOut.nFFTPoints = nFFTPoints
131 self.dataOut.nFFTPoints = nFFTPoints
131 self.dataOut.pairsList = pairsList
132 self.dataOut.pairsList = pairsList
132
133
133 if self.buffer is None:
134 if self.buffer is None:
134 self.buffer = numpy.zeros( (self.dataIn.nChannels,
135 self.buffer = numpy.zeros( (self.dataIn.nChannels,
135 nProfiles,
136 nProfiles,
136 self.dataIn.nHeights),
137 self.dataIn.nHeights),
137 dtype='complex')
138 dtype='complex')
138
139
139 if self.dataIn.flagDataAsBlock:
140 if self.dataIn.flagDataAsBlock:
140 #data dimension: [nChannels, nProfiles, nSamples]
141 #data dimension: [nChannels, nProfiles, nSamples]
142
141 nVoltProfiles = self.dataIn.data.shape[1]
143 nVoltProfiles = self.dataIn.data.shape[1]
142 # nVoltProfiles = self.dataIn.nProfiles
144 # nVoltProfiles = self.dataIn.nProfiles
143
145
144 if nVoltProfiles == nProfiles:
146 if nVoltProfiles == nProfiles:
145 self.buffer = self.dataIn.data.copy()
147 self.buffer = self.dataIn.data.copy()
146 self.profIndex = nVoltProfiles
148 self.profIndex = nVoltProfiles
147
149
148 elif nVoltProfiles < nProfiles:
150 elif nVoltProfiles < nProfiles:
149
151
150 if self.profIndex == 0:
152 if self.profIndex == 0:
151 self.id_min = 0
153 self.id_min = 0
152 self.id_max = nVoltProfiles
154 self.id_max = nVoltProfiles
153
155
154 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
156 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
155 self.profIndex += nVoltProfiles
157 self.profIndex += nVoltProfiles
156 self.id_min += nVoltProfiles
158 self.id_min += nVoltProfiles
157 self.id_max += nVoltProfiles
159 self.id_max += nVoltProfiles
158 else:
160 else:
159 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
161 raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
160 self.dataOut.flagNoData = True
162 self.dataOut.flagNoData = True
161 return 0
163 return 0
162 else:
164 else:
165 print 'DATA shape', self.dataIn.data.shape
166 sadsdf
163 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
167 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
164 self.profIndex += 1
168 self.profIndex += 1
165
169
166 if self.firstdatatime == None:
170 if self.firstdatatime == None:
167 self.firstdatatime = self.dataIn.utctime
171 self.firstdatatime = self.dataIn.utctime
168
172
169 if self.profIndex == nProfiles:
173 if self.profIndex == nProfiles:
170 self.__updateSpecFromVoltage()
174 self.__updateSpecFromVoltage()
171 self.__getFft()
175 self.__getFft()
172
176
173 self.dataOut.flagNoData = False
177 self.dataOut.flagNoData = False
174 self.firstdatatime = None
178 self.firstdatatime = None
175 self.profIndex = 0
179 self.profIndex = 0
176
180
177 return True
181 return True
178
182
179 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
183 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
180
184
181 def __selectPairs(self, pairsList):
185 def __selectPairs(self, pairsList):
182
186
183 if channelList == None:
187 if channelList == None:
184 return
188 return
185
189
186 pairsIndexListSelected = []
190 pairsIndexListSelected = []
187
191
188 for thisPair in pairsList:
192 for thisPair in pairsList:
189
193
190 if thisPair not in self.dataOut.pairsList:
194 if thisPair not in self.dataOut.pairsList:
191 continue
195 continue
192
196
193 pairIndex = self.dataOut.pairsList.index(thisPair)
197 pairIndex = self.dataOut.pairsList.index(thisPair)
194
198
195 pairsIndexListSelected.append(pairIndex)
199 pairsIndexListSelected.append(pairIndex)
196
200
197 if not pairsIndexListSelected:
201 if not pairsIndexListSelected:
198 self.dataOut.data_cspc = None
202 self.dataOut.data_cspc = None
199 self.dataOut.pairsList = []
203 self.dataOut.pairsList = []
200 return
204 return
201
205
202 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
206 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
203 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
207 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
204
208
205 return
209 return
206
210
207 def __selectPairsByChannel(self, channelList=None):
211 def __selectPairsByChannel(self, channelList=None):
208
212
209 if channelList == None:
213 if channelList == None:
210 return
214 return
211
215
212 pairsIndexListSelected = []
216 pairsIndexListSelected = []
213 for pairIndex in self.dataOut.pairsIndexList:
217 for pairIndex in self.dataOut.pairsIndexList:
214 #First pair
218 #First pair
215 if self.dataOut.pairsList[pairIndex][0] not in channelList:
219 if self.dataOut.pairsList[pairIndex][0] not in channelList:
216 continue
220 continue
217 #Second pair
221 #Second pair
218 if self.dataOut.pairsList[pairIndex][1] not in channelList:
222 if self.dataOut.pairsList[pairIndex][1] not in channelList:
219 continue
223 continue
220
224
221 pairsIndexListSelected.append(pairIndex)
225 pairsIndexListSelected.append(pairIndex)
222
226
223 if not pairsIndexListSelected:
227 if not pairsIndexListSelected:
224 self.dataOut.data_cspc = None
228 self.dataOut.data_cspc = None
225 self.dataOut.pairsList = []
229 self.dataOut.pairsList = []
226 return
230 return
227
231
228 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
232 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
229 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
233 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
230
234
231 return
235 return
232
236
233 def selectChannels(self, channelList):
237 def selectChannels(self, channelList):
234
238
235 channelIndexList = []
239 channelIndexList = []
236
240
237 for channel in channelList:
241 for channel in channelList:
238 if channel not in self.dataOut.channelList:
242 if channel not in self.dataOut.channelList:
239 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
243 raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
240
244
241 index = self.dataOut.channelList.index(channel)
245 index = self.dataOut.channelList.index(channel)
242 channelIndexList.append(index)
246 channelIndexList.append(index)
243
247
244 self.selectChannelsByIndex(channelIndexList)
248 self.selectChannelsByIndex(channelIndexList)
245
249
246 def selectChannelsByIndex(self, channelIndexList):
250 def selectChannelsByIndex(self, channelIndexList):
247 """
251 """
248 Selecciona un bloque de datos en base a canales segun el channelIndexList
252 Selecciona un bloque de datos en base a canales segun el channelIndexList
249
253
250 Input:
254 Input:
251 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
255 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
252
256
253 Affected:
257 Affected:
254 self.dataOut.data_spc
258 self.dataOut.data_spc
255 self.dataOut.channelIndexList
259 self.dataOut.channelIndexList
256 self.dataOut.nChannels
260 self.dataOut.nChannels
257
261
258 Return:
262 Return:
259 None
263 None
260 """
264 """
261
265
262 for channelIndex in channelIndexList:
266 for channelIndex in channelIndexList:
263 if channelIndex not in self.dataOut.channelIndexList:
267 if channelIndex not in self.dataOut.channelIndexList:
264 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
268 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
265
269
266 # nChannels = len(channelIndexList)
270 # nChannels = len(channelIndexList)
267
271
268 data_spc = self.dataOut.data_spc[channelIndexList,:]
272 data_spc = self.dataOut.data_spc[channelIndexList,:]
269 data_dc = self.dataOut.data_dc[channelIndexList,:]
273 data_dc = self.dataOut.data_dc[channelIndexList,:]
270
274
271 self.dataOut.data_spc = data_spc
275 self.dataOut.data_spc = data_spc
272 self.dataOut.data_dc = data_dc
276 self.dataOut.data_dc = data_dc
273
277
274 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
278 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
275 # self.dataOut.nChannels = nChannels
279 # self.dataOut.nChannels = nChannels
276
280
277 self.__selectPairsByChannel(self.dataOut.channelList)
281 self.__selectPairsByChannel(self.dataOut.channelList)
278
282
279 return 1
283 return 1
280
284
281
285
282 def selectFFTs(self, minFFT, maxFFT ):
286 def selectFFTs(self, minFFT, maxFFT ):
283 """
287 """
284 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
288 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
285 minFFT<= FFT <= maxFFT
289 minFFT<= FFT <= maxFFT
286 """
290 """
287
291
288 if (minFFT > maxFFT):
292 if (minFFT > maxFFT):
289 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)
293 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT)
290
294
291 if (minFFT < self.dataOut.getFreqRange()[0]):
295 if (minFFT < self.dataOut.getFreqRange()[0]):
292 minFFT = self.dataOut.getFreqRange()[0]
296 minFFT = self.dataOut.getFreqRange()[0]
293
297
294 if (maxFFT > self.dataOut.getFreqRange()[-1]):
298 if (maxFFT > self.dataOut.getFreqRange()[-1]):
295 maxFFT = self.dataOut.getFreqRange()[-1]
299 maxFFT = self.dataOut.getFreqRange()[-1]
296
300
297 minIndex = 0
301 minIndex = 0
298 maxIndex = 0
302 maxIndex = 0
299 FFTs = self.dataOut.getFreqRange()
303 FFTs = self.dataOut.getFreqRange()
300
304
301 inda = numpy.where(FFTs >= minFFT)
305 inda = numpy.where(FFTs >= minFFT)
302 indb = numpy.where(FFTs <= maxFFT)
306 indb = numpy.where(FFTs <= maxFFT)
303
307
304 try:
308 try:
305 minIndex = inda[0][0]
309 minIndex = inda[0][0]
306 except:
310 except:
307 minIndex = 0
311 minIndex = 0
308
312
309 try:
313 try:
310 maxIndex = indb[0][-1]
314 maxIndex = indb[0][-1]
311 except:
315 except:
312 maxIndex = len(FFTs)
316 maxIndex = len(FFTs)
313
317
314 self.selectFFTsByIndex(minIndex, maxIndex)
318 self.selectFFTsByIndex(minIndex, maxIndex)
315
319
316 return 1
320 return 1
317
321
318
322
319
323
320 def selectHeights(self, minHei, maxHei):
324 def selectHeights(self, minHei, maxHei):
321 """
325 """
322 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
326 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
323 minHei <= height <= maxHei
327 minHei <= height <= maxHei
324
328
325 Input:
329 Input:
326 minHei : valor minimo de altura a considerar
330 minHei : valor minimo de altura a considerar
327 maxHei : valor maximo de altura a considerar
331 maxHei : valor maximo de altura a considerar
328
332
329 Affected:
333 Affected:
330 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
334 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
331
335
332 Return:
336 Return:
333 1 si el metodo se ejecuto con exito caso contrario devuelve 0
337 1 si el metodo se ejecuto con exito caso contrario devuelve 0
334 """
338 """
335
339
336
340
337 if (minHei > maxHei):
341 if (minHei > maxHei):
338 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
342 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
339
343
340 if (minHei < self.dataOut.heightList[0]):
344 if (minHei < self.dataOut.heightList[0]):
341 minHei = self.dataOut.heightList[0]
345 minHei = self.dataOut.heightList[0]
342
346
343 if (maxHei > self.dataOut.heightList[-1]):
347 if (maxHei > self.dataOut.heightList[-1]):
344 maxHei = self.dataOut.heightList[-1]
348 maxHei = self.dataOut.heightList[-1]
345
349
346 minIndex = 0
350 minIndex = 0
347 maxIndex = 0
351 maxIndex = 0
348 heights = self.dataOut.heightList
352 heights = self.dataOut.heightList
349
353
350 inda = numpy.where(heights >= minHei)
354 inda = numpy.where(heights >= minHei)
351 indb = numpy.where(heights <= maxHei)
355 indb = numpy.where(heights <= maxHei)
352
356
353 try:
357 try:
354 minIndex = inda[0][0]
358 minIndex = inda[0][0]
355 except:
359 except:
356 minIndex = 0
360 minIndex = 0
357
361
358 try:
362 try:
359 maxIndex = indb[0][-1]
363 maxIndex = indb[0][-1]
360 except:
364 except:
361 maxIndex = len(heights)
365 maxIndex = len(heights)
362
366
363 self.selectHeightsByIndex(minIndex, maxIndex)
367 self.selectHeightsByIndex(minIndex, maxIndex)
364
368
365
369
366 return 1
370 return 1
367
371
368 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
372 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
369 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
373 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
370
374
371 if hei_ref != None:
375 if hei_ref != None:
372 newheis = numpy.where(self.dataOut.heightList>hei_ref)
376 newheis = numpy.where(self.dataOut.heightList>hei_ref)
373
377
374 minIndex = min(newheis[0])
378 minIndex = min(newheis[0])
375 maxIndex = max(newheis[0])
379 maxIndex = max(newheis[0])
376 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
380 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
377 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
381 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
378
382
379 # determina indices
383 # determina indices
380 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
384 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
381 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
385 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
382 beacon_dB = numpy.sort(avg_dB)[-nheis:]
386 beacon_dB = numpy.sort(avg_dB)[-nheis:]
383 beacon_heiIndexList = []
387 beacon_heiIndexList = []
384 for val in avg_dB.tolist():
388 for val in avg_dB.tolist():
385 if val >= beacon_dB[0]:
389 if val >= beacon_dB[0]:
386 beacon_heiIndexList.append(avg_dB.tolist().index(val))
390 beacon_heiIndexList.append(avg_dB.tolist().index(val))
387
391
388 #data_spc = data_spc[:,:,beacon_heiIndexList]
392 #data_spc = data_spc[:,:,beacon_heiIndexList]
389 data_cspc = None
393 data_cspc = None
390 if self.dataOut.data_cspc is not None:
394 if self.dataOut.data_cspc is not None:
391 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
395 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
392 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
396 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
393
397
394 data_dc = None
398 data_dc = None
395 if self.dataOut.data_dc is not None:
399 if self.dataOut.data_dc is not None:
396 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
400 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
397 #data_dc = data_dc[:,beacon_heiIndexList]
401 #data_dc = data_dc[:,beacon_heiIndexList]
398
402
399 self.dataOut.data_spc = data_spc
403 self.dataOut.data_spc = data_spc
400 self.dataOut.data_cspc = data_cspc
404 self.dataOut.data_cspc = data_cspc
401 self.dataOut.data_dc = data_dc
405 self.dataOut.data_dc = data_dc
402 self.dataOut.heightList = heightList
406 self.dataOut.heightList = heightList
403 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
407 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
404
408
405 return 1
409 return 1
406
410
407 def selectFFTsByIndex(self, minIndex, maxIndex):
411 def selectFFTsByIndex(self, minIndex, maxIndex):
408 """
412 """
409
413
410 """
414 """
411
415
412 if (minIndex < 0) or (minIndex > maxIndex):
416 if (minIndex < 0) or (minIndex > maxIndex):
413 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
417 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
414
418
415 if (maxIndex >= self.dataOut.nProfiles):
419 if (maxIndex >= self.dataOut.nProfiles):
416 maxIndex = self.dataOut.nProfiles-1
420 maxIndex = self.dataOut.nProfiles-1
417
421
418 #Spectra
422 #Spectra
419 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
423 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
420
424
421 data_cspc = None
425 data_cspc = None
422 if self.dataOut.data_cspc is not None:
426 if self.dataOut.data_cspc is not None:
423 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
427 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
424
428
425 data_dc = None
429 data_dc = None
426 if self.dataOut.data_dc is not None:
430 if self.dataOut.data_dc is not None:
427 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
431 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
428
432
429 self.dataOut.data_spc = data_spc
433 self.dataOut.data_spc = data_spc
430 self.dataOut.data_cspc = data_cspc
434 self.dataOut.data_cspc = data_cspc
431 self.dataOut.data_dc = data_dc
435 self.dataOut.data_dc = data_dc
432
436
433 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
437 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
434 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
438 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
435 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
439 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
436
440
437 #self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
441 #self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
438
442
439 return 1
443 return 1
440
444
441
445
442
446
443 def selectHeightsByIndex(self, minIndex, maxIndex):
447 def selectHeightsByIndex(self, minIndex, maxIndex):
444 """
448 """
445 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
449 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
446 minIndex <= index <= maxIndex
450 minIndex <= index <= maxIndex
447
451
448 Input:
452 Input:
449 minIndex : valor de indice minimo de altura a considerar
453 minIndex : valor de indice minimo de altura a considerar
450 maxIndex : valor de indice maximo de altura a considerar
454 maxIndex : valor de indice maximo de altura a considerar
451
455
452 Affected:
456 Affected:
453 self.dataOut.data_spc
457 self.dataOut.data_spc
454 self.dataOut.data_cspc
458 self.dataOut.data_cspc
455 self.dataOut.data_dc
459 self.dataOut.data_dc
456 self.dataOut.heightList
460 self.dataOut.heightList
457
461
458 Return:
462 Return:
459 1 si el metodo se ejecuto con exito caso contrario devuelve 0
463 1 si el metodo se ejecuto con exito caso contrario devuelve 0
460 """
464 """
461
465
462 if (minIndex < 0) or (minIndex > maxIndex):
466 if (minIndex < 0) or (minIndex > maxIndex):
463 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
467 raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex)
464
468
465 if (maxIndex >= self.dataOut.nHeights):
469 if (maxIndex >= self.dataOut.nHeights):
466 maxIndex = self.dataOut.nHeights-1
470 maxIndex = self.dataOut.nHeights-1
467
471
468 #Spectra
472 #Spectra
469 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
473 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
470
474
471 data_cspc = None
475 data_cspc = None
472 if self.dataOut.data_cspc is not None:
476 if self.dataOut.data_cspc is not None:
473 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
477 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
474
478
475 data_dc = None
479 data_dc = None
476 if self.dataOut.data_dc is not None:
480 if self.dataOut.data_dc is not None:
477 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
481 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
478
482
479 self.dataOut.data_spc = data_spc
483 self.dataOut.data_spc = data_spc
480 self.dataOut.data_cspc = data_cspc
484 self.dataOut.data_cspc = data_cspc
481 self.dataOut.data_dc = data_dc
485 self.dataOut.data_dc = data_dc
482
486
483 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
487 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
484
488
485 return 1
489 return 1
486
490
487
491
488 def removeDC(self, mode = 2):
492 def removeDC(self, mode = 2):
489 jspectra = self.dataOut.data_spc
493 jspectra = self.dataOut.data_spc
490 jcspectra = self.dataOut.data_cspc
494 jcspectra = self.dataOut.data_cspc
491
495
492
496
493 num_chan = jspectra.shape[0]
497 num_chan = jspectra.shape[0]
494 num_hei = jspectra.shape[2]
498 num_hei = jspectra.shape[2]
495
499
496 if jcspectra is not None:
500 if jcspectra is not None:
497 jcspectraExist = True
501 jcspectraExist = True
498 num_pairs = jcspectra.shape[0]
502 num_pairs = jcspectra.shape[0]
499 else: jcspectraExist = False
503 else: jcspectraExist = False
500
504
501 freq_dc = jspectra.shape[1]/2
505 freq_dc = jspectra.shape[1]/2
502 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
506 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
503
507
504 if ind_vel[0]<0:
508 if ind_vel[0]<0:
505 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
509 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
506
510
507 if mode == 1:
511 if mode == 1:
508 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
512 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
509
513
510 if jcspectraExist:
514 if jcspectraExist:
511 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
515 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
512
516
513 if mode == 2:
517 if mode == 2:
514
518
515 vel = numpy.array([-2,-1,1,2])
519 vel = numpy.array([-2,-1,1,2])
516 xx = numpy.zeros([4,4])
520 xx = numpy.zeros([4,4])
517
521
518 for fil in range(4):
522 for fil in range(4):
519 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
523 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
520
524
521 xx_inv = numpy.linalg.inv(xx)
525 xx_inv = numpy.linalg.inv(xx)
522 xx_aux = xx_inv[0,:]
526 xx_aux = xx_inv[0,:]
523
527
524 for ich in range(num_chan):
528 for ich in range(num_chan):
525 yy = jspectra[ich,ind_vel,:]
529 yy = jspectra[ich,ind_vel,:]
526 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
530 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
527
531
528 junkid = jspectra[ich,freq_dc,:]<=0
532 junkid = jspectra[ich,freq_dc,:]<=0
529 cjunkid = sum(junkid)
533 cjunkid = sum(junkid)
530
534
531 if cjunkid.any():
535 if cjunkid.any():
532 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
536 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
533
537
534 if jcspectraExist:
538 if jcspectraExist:
535 for ip in range(num_pairs):
539 for ip in range(num_pairs):
536 yy = jcspectra[ip,ind_vel,:]
540 yy = jcspectra[ip,ind_vel,:]
537 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
541 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
538
542
539
543
540 self.dataOut.data_spc = jspectra
544 self.dataOut.data_spc = jspectra
541 self.dataOut.data_cspc = jcspectra
545 self.dataOut.data_cspc = jcspectra
542
546
543 return 1
547 return 1
544
548
545 def removeInterference2(self):
549 def removeInterference2(self):
546
550
547 cspc = self.dataOut.data_cspc
551 cspc = self.dataOut.data_cspc
548 spc = self.dataOut.data_spc
552 spc = self.dataOut.data_spc
549 print numpy.shape(spc)
553 print numpy.shape(spc)
550 Heights = numpy.arange(cspc.shape[2])
554 Heights = numpy.arange(cspc.shape[2])
551 realCspc = numpy.abs(cspc)
555 realCspc = numpy.abs(cspc)
552
556
553 for i in range(cspc.shape[0]):
557 for i in range(cspc.shape[0]):
554 LinePower= numpy.sum(realCspc[i], axis=0)
558 LinePower= numpy.sum(realCspc[i], axis=0)
555 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
559 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
556 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
560 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
557 #print numpy.shape(realCspc)
561 #print numpy.shape(realCspc)
558 #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
562 #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
559 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
563 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
560 print SelectedHeights
564 print SelectedHeights
561 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
565 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
562 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
566 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
563
567
564
568
565 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
569 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
566 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
570 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
567 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
571 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
568 cspc[i,InterferenceRange,:] = numpy.NaN
572 cspc[i,InterferenceRange,:] = numpy.NaN
569
573
570 print '########################################################################################'
574 print '########################################################################################'
571 print 'Len interference sum',len(InterferenceSum)
575 print 'Len interference sum',len(InterferenceSum)
572 print 'InterferenceThresholdMin', InterferenceThresholdMin, 'InterferenceThresholdMax', InterferenceThresholdMax
576 print 'InterferenceThresholdMin', InterferenceThresholdMin, 'InterferenceThresholdMax', InterferenceThresholdMax
573 print 'InterferenceRange',InterferenceRange
577 print 'InterferenceRange',InterferenceRange
574 print '########################################################################################'
578 print '########################################################################################'
575
579
576 ''' Ploteo '''
580 ''' Ploteo '''
577
581
578 #for i in range(3):
582 #for i in range(3):
579 #print 'FASE', numpy.shape(phase), y[25]
583 #print 'FASE', numpy.shape(phase), y[25]
580 #print numpy.shape(coherence)
584 #print numpy.shape(coherence)
581 #fig = plt.figure(10+ int(numpy.random.rand()*100))
585 #fig = plt.figure(10+ int(numpy.random.rand()*100))
582 #plt.plot( x[0:256],coherence[:,25] )
586 #plt.plot( x[0:256],coherence[:,25] )
583 #cohAv = numpy.average(coherence[i],1)
587 #cohAv = numpy.average(coherence[i],1)
584 #Pendiente = FrecRange * PhaseSlope[i]
588 #Pendiente = FrecRange * PhaseSlope[i]
585 #plt.plot( InterferenceSum)
589 #plt.plot( InterferenceSum)
586 #plt.plot( numpy.sort(InterferenceSum))
590 #plt.plot( numpy.sort(InterferenceSum))
587 #plt.plot( LinePower )
591 #plt.plot( LinePower )
588 #plt.plot( xFrec,phase[i])
592 #plt.plot( xFrec,phase[i])
589
593
590 #CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
594 #CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0)
591 #plt.plot(xFrec, FitGauss01)
595 #plt.plot(xFrec, FitGauss01)
592 #plt.plot(xFrec, CSPCmean)
596 #plt.plot(xFrec, CSPCmean)
593 #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
597 #plt.plot(xFrec, numpy.abs(CSPCSamples[0]))
594 #plt.plot(xFrec, FitGauss)
598 #plt.plot(xFrec, FitGauss)
595 #plt.plot(xFrec, yMean)
599 #plt.plot(xFrec, yMean)
596 #plt.plot(xFrec, numpy.abs(coherence[0]))
600 #plt.plot(xFrec, numpy.abs(coherence[0]))
597
601
598 #plt.axis([-12, 12, 15, 50])
602 #plt.axis([-12, 12, 15, 50])
599 #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
603 #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i)))
600
604
601
605
602 #fig.savefig('/home/erick/Documents/Pics/nom{}.png'.format(int(numpy.random.rand()*100)))
606 #fig.savefig('/home/erick/Documents/Pics/nom{}.png'.format(int(numpy.random.rand()*100)))
603
607
604 #plt.show()
608 #plt.show()
605 #self.indice=self.indice+1
609 #self.indice=self.indice+1
606 #raise
610 #raise
607
611
608
612
609 self.dataOut.data_cspc = cspc
613 self.dataOut.data_cspc = cspc
610
614
611 # for i in range(spc.shape[0]):
615 # for i in range(spc.shape[0]):
612 # LinePower= numpy.sum(spc[i], axis=0)
616 # LinePower= numpy.sum(spc[i], axis=0)
613 # Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
617 # Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
614 # SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
618 # SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
615 # #print numpy.shape(realCspc)
619 # #print numpy.shape(realCspc)
616 # #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
620 # #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights])
617 # InterferenceSum = numpy.sum( spc[i,:,SelectedHeights], axis=0 )
621 # InterferenceSum = numpy.sum( spc[i,:,SelectedHeights], axis=0 )
618 # InterferenceThreshold = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
622 # InterferenceThreshold = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
619 # InterferenceRange = numpy.where( InterferenceSum > InterferenceThreshold )
623 # InterferenceRange = numpy.where( InterferenceSum > InterferenceThreshold )
620 # if len(InterferenceRange)<int(spc.shape[1]*0.03):
624 # if len(InterferenceRange)<int(spc.shape[1]*0.03):
621 # spc[i,InterferenceRange,:] = numpy.NaN
625 # spc[i,InterferenceRange,:] = numpy.NaN
622
626
623 #self.dataOut.data_spc = spc
627 #self.dataOut.data_spc = spc
624
628
625 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
629 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
626
630
627 jspectra = self.dataOut.data_spc
631 jspectra = self.dataOut.data_spc
628 jcspectra = self.dataOut.data_cspc
632 jcspectra = self.dataOut.data_cspc
629 jnoise = self.dataOut.getNoise()
633 jnoise = self.dataOut.getNoise()
630 num_incoh = self.dataOut.nIncohInt
634 num_incoh = self.dataOut.nIncohInt
631
635
632 num_channel = jspectra.shape[0]
636 num_channel = jspectra.shape[0]
633 num_prof = jspectra.shape[1]
637 num_prof = jspectra.shape[1]
634 num_hei = jspectra.shape[2]
638 num_hei = jspectra.shape[2]
635
639
636 #hei_interf
640 #hei_interf
637 if hei_interf is None:
641 if hei_interf is None:
638 count_hei = num_hei/2 #Como es entero no importa
642 count_hei = num_hei/2 #Como es entero no importa
639 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
643 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
640 hei_interf = numpy.asarray(hei_interf)[0]
644 hei_interf = numpy.asarray(hei_interf)[0]
641 #nhei_interf
645 #nhei_interf
642 if (nhei_interf == None):
646 if (nhei_interf == None):
643 nhei_interf = 5
647 nhei_interf = 5
644 if (nhei_interf < 1):
648 if (nhei_interf < 1):
645 nhei_interf = 1
649 nhei_interf = 1
646 if (nhei_interf > count_hei):
650 if (nhei_interf > count_hei):
647 nhei_interf = count_hei
651 nhei_interf = count_hei
648 if (offhei_interf == None):
652 if (offhei_interf == None):
649 offhei_interf = 0
653 offhei_interf = 0
650
654
651 ind_hei = range(num_hei)
655 ind_hei = range(num_hei)
652 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
656 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
653 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
657 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
654 mask_prof = numpy.asarray(range(num_prof))
658 mask_prof = numpy.asarray(range(num_prof))
655 num_mask_prof = mask_prof.size
659 num_mask_prof = mask_prof.size
656 comp_mask_prof = [0, num_prof/2]
660 comp_mask_prof = [0, num_prof/2]
657
661
658
662
659 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
663 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
660 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
664 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
661 jnoise = numpy.nan
665 jnoise = numpy.nan
662 noise_exist = jnoise[0] < numpy.Inf
666 noise_exist = jnoise[0] < numpy.Inf
663
667
664 #Subrutina de Remocion de la Interferencia
668 #Subrutina de Remocion de la Interferencia
665 for ich in range(num_channel):
669 for ich in range(num_channel):
666 #Se ordena los espectros segun su potencia (menor a mayor)
670 #Se ordena los espectros segun su potencia (menor a mayor)
667 power = jspectra[ich,mask_prof,:]
671 power = jspectra[ich,mask_prof,:]
668 power = power[:,hei_interf]
672 power = power[:,hei_interf]
669 power = power.sum(axis = 0)
673 power = power.sum(axis = 0)
670 psort = power.ravel().argsort()
674 psort = power.ravel().argsort()
671
675
672 #Se estima la interferencia promedio en los Espectros de Potencia empleando
676 #Se estima la interferencia promedio en los Espectros de Potencia empleando
673 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
677 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
674
678
675 if noise_exist:
679 if noise_exist:
676 # tmp_noise = jnoise[ich] / num_prof
680 # tmp_noise = jnoise[ich] / num_prof
677 tmp_noise = jnoise[ich]
681 tmp_noise = jnoise[ich]
678 junkspc_interf = junkspc_interf - tmp_noise
682 junkspc_interf = junkspc_interf - tmp_noise
679 #junkspc_interf[:,comp_mask_prof] = 0
683 #junkspc_interf[:,comp_mask_prof] = 0
680
684
681 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
685 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
682 jspc_interf = jspc_interf.transpose()
686 jspc_interf = jspc_interf.transpose()
683 #Calculando el espectro de interferencia promedio
687 #Calculando el espectro de interferencia promedio
684 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
688 noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh))
685 noiseid = noiseid[0]
689 noiseid = noiseid[0]
686 cnoiseid = noiseid.size
690 cnoiseid = noiseid.size
687 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
691 interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh))
688 interfid = interfid[0]
692 interfid = interfid[0]
689 cinterfid = interfid.size
693 cinterfid = interfid.size
690
694
691 if (cnoiseid > 0): jspc_interf[noiseid] = 0
695 if (cnoiseid > 0): jspc_interf[noiseid] = 0
692
696
693 #Expandiendo los perfiles a limpiar
697 #Expandiendo los perfiles a limpiar
694 if (cinterfid > 0):
698 if (cinterfid > 0):
695 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
699 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
696 new_interfid = numpy.asarray(new_interfid)
700 new_interfid = numpy.asarray(new_interfid)
697 new_interfid = {x for x in new_interfid}
701 new_interfid = {x for x in new_interfid}
698 new_interfid = numpy.array(list(new_interfid))
702 new_interfid = numpy.array(list(new_interfid))
699 new_cinterfid = new_interfid.size
703 new_cinterfid = new_interfid.size
700 else: new_cinterfid = 0
704 else: new_cinterfid = 0
701
705
702 for ip in range(new_cinterfid):
706 for ip in range(new_cinterfid):
703 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
707 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
704 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
708 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
705
709
706
710
707 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
711 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
708
712
709 #Removiendo la interferencia del punto de mayor interferencia
713 #Removiendo la interferencia del punto de mayor interferencia
710 ListAux = jspc_interf[mask_prof].tolist()
714 ListAux = jspc_interf[mask_prof].tolist()
711 maxid = ListAux.index(max(ListAux))
715 maxid = ListAux.index(max(ListAux))
712
716
713
717
714 if cinterfid > 0:
718 if cinterfid > 0:
715 for ip in range(cinterfid*(interf == 2) - 1):
719 for ip in range(cinterfid*(interf == 2) - 1):
716 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
720 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero()
717 cind = len(ind)
721 cind = len(ind)
718
722
719 if (cind > 0):
723 if (cind > 0):
720 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
724 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh))
721
725
722 ind = numpy.array([-2,-1,1,2])
726 ind = numpy.array([-2,-1,1,2])
723 xx = numpy.zeros([4,4])
727 xx = numpy.zeros([4,4])
724
728
725 for id1 in range(4):
729 for id1 in range(4):
726 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
730 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
727
731
728 xx_inv = numpy.linalg.inv(xx)
732 xx_inv = numpy.linalg.inv(xx)
729 xx = xx_inv[:,0]
733 xx = xx_inv[:,0]
730 ind = (ind + maxid + num_mask_prof)%num_mask_prof
734 ind = (ind + maxid + num_mask_prof)%num_mask_prof
731 yy = jspectra[ich,mask_prof[ind],:]
735 yy = jspectra[ich,mask_prof[ind],:]
732 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
736 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
733
737
734
738
735 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
739 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero()
736 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
740 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh))
737
741
738 #Remocion de Interferencia en el Cross Spectra
742 #Remocion de Interferencia en el Cross Spectra
739 if jcspectra is None: return jspectra, jcspectra
743 if jcspectra is None: return jspectra, jcspectra
740 num_pairs = jcspectra.size/(num_prof*num_hei)
744 num_pairs = jcspectra.size/(num_prof*num_hei)
741 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
745 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
742
746
743 for ip in range(num_pairs):
747 for ip in range(num_pairs):
744
748
745 #-------------------------------------------
749 #-------------------------------------------
746
750
747 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
751 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
748 cspower = cspower[:,hei_interf]
752 cspower = cspower[:,hei_interf]
749 cspower = cspower.sum(axis = 0)
753 cspower = cspower.sum(axis = 0)
750
754
751 cspsort = cspower.ravel().argsort()
755 cspsort = cspower.ravel().argsort()
752 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
756 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
753 junkcspc_interf = junkcspc_interf.transpose()
757 junkcspc_interf = junkcspc_interf.transpose()
754 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
758 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
755
759
756 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
760 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
757
761
758 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
762 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
759 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
763 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
760 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
764 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
761
765
762 for iprof in range(num_prof):
766 for iprof in range(num_prof):
763 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
767 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
764 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
768 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
765
769
766 #Removiendo la Interferencia
770 #Removiendo la Interferencia
767 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
771 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
768
772
769 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
773 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
770 maxid = ListAux.index(max(ListAux))
774 maxid = ListAux.index(max(ListAux))
771
775
772 ind = numpy.array([-2,-1,1,2])
776 ind = numpy.array([-2,-1,1,2])
773 xx = numpy.zeros([4,4])
777 xx = numpy.zeros([4,4])
774
778
775 for id1 in range(4):
779 for id1 in range(4):
776 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
780 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
777
781
778 xx_inv = numpy.linalg.inv(xx)
782 xx_inv = numpy.linalg.inv(xx)
779 xx = xx_inv[:,0]
783 xx = xx_inv[:,0]
780
784
781 ind = (ind + maxid + num_mask_prof)%num_mask_prof
785 ind = (ind + maxid + num_mask_prof)%num_mask_prof
782 yy = jcspectra[ip,mask_prof[ind],:]
786 yy = jcspectra[ip,mask_prof[ind],:]
783 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
787 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
784
788
785 #Guardar Resultados
789 #Guardar Resultados
786 self.dataOut.data_spc = jspectra
790 self.dataOut.data_spc = jspectra
787 self.dataOut.data_cspc = jcspectra
791 self.dataOut.data_cspc = jcspectra
788
792
789 return 1
793 return 1
790
794
791 def setRadarFrequency(self, frequency=None):
795 def setRadarFrequency(self, frequency=None):
792
796
793 if frequency != None:
797 if frequency != None:
794 self.dataOut.frequency = frequency
798 self.dataOut.frequency = frequency
795
799
796 return 1
800 return 1
797
801
798 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
802 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
799 #validacion de rango
803 #validacion de rango
800 if minHei == None:
804 if minHei == None:
801 minHei = self.dataOut.heightList[0]
805 minHei = self.dataOut.heightList[0]
802
806
803 if maxHei == None:
807 if maxHei == None:
804 maxHei = self.dataOut.heightList[-1]
808 maxHei = self.dataOut.heightList[-1]
805
809
806 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
810 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
807 print 'minHei: %.2f is out of the heights range'%(minHei)
811 print 'minHei: %.2f is out of the heights range'%(minHei)
808 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
812 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
809 minHei = self.dataOut.heightList[0]
813 minHei = self.dataOut.heightList[0]
810
814
811 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
815 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
812 print 'maxHei: %.2f is out of the heights range'%(maxHei)
816 print 'maxHei: %.2f is out of the heights range'%(maxHei)
813 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
817 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
814 maxHei = self.dataOut.heightList[-1]
818 maxHei = self.dataOut.heightList[-1]
815
819
816 # validacion de velocidades
820 # validacion de velocidades
817 velrange = self.dataOut.getVelRange(1)
821 velrange = self.dataOut.getVelRange(1)
818
822
819 if minVel == None:
823 if minVel == None:
820 minVel = velrange[0]
824 minVel = velrange[0]
821
825
822 if maxVel == None:
826 if maxVel == None:
823 maxVel = velrange[-1]
827 maxVel = velrange[-1]
824
828
825 if (minVel < velrange[0]) or (minVel > maxVel):
829 if (minVel < velrange[0]) or (minVel > maxVel):
826 print 'minVel: %.2f is out of the velocity range'%(minVel)
830 print 'minVel: %.2f is out of the velocity range'%(minVel)
827 print 'minVel is setting to %.2f'%(velrange[0])
831 print 'minVel is setting to %.2f'%(velrange[0])
828 minVel = velrange[0]
832 minVel = velrange[0]
829
833
830 if (maxVel > velrange[-1]) or (maxVel < minVel):
834 if (maxVel > velrange[-1]) or (maxVel < minVel):
831 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
835 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
832 print 'maxVel is setting to %.2f'%(velrange[-1])
836 print 'maxVel is setting to %.2f'%(velrange[-1])
833 maxVel = velrange[-1]
837 maxVel = velrange[-1]
834
838
835 # seleccion de indices para rango
839 # seleccion de indices para rango
836 minIndex = 0
840 minIndex = 0
837 maxIndex = 0
841 maxIndex = 0
838 heights = self.dataOut.heightList
842 heights = self.dataOut.heightList
839
843
840 inda = numpy.where(heights >= minHei)
844 inda = numpy.where(heights >= minHei)
841 indb = numpy.where(heights <= maxHei)
845 indb = numpy.where(heights <= maxHei)
842
846
843 try:
847 try:
844 minIndex = inda[0][0]
848 minIndex = inda[0][0]
845 except:
849 except:
846 minIndex = 0
850 minIndex = 0
847
851
848 try:
852 try:
849 maxIndex = indb[0][-1]
853 maxIndex = indb[0][-1]
850 except:
854 except:
851 maxIndex = len(heights)
855 maxIndex = len(heights)
852
856
853 if (minIndex < 0) or (minIndex > maxIndex):
857 if (minIndex < 0) or (minIndex > maxIndex):
854 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
858 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
855
859
856 if (maxIndex >= self.dataOut.nHeights):
860 if (maxIndex >= self.dataOut.nHeights):
857 maxIndex = self.dataOut.nHeights-1
861 maxIndex = self.dataOut.nHeights-1
858
862
859 # seleccion de indices para velocidades
863 # seleccion de indices para velocidades
860 indminvel = numpy.where(velrange >= minVel)
864 indminvel = numpy.where(velrange >= minVel)
861 indmaxvel = numpy.where(velrange <= maxVel)
865 indmaxvel = numpy.where(velrange <= maxVel)
862 try:
866 try:
863 minIndexVel = indminvel[0][0]
867 minIndexVel = indminvel[0][0]
864 except:
868 except:
865 minIndexVel = 0
869 minIndexVel = 0
866
870
867 try:
871 try:
868 maxIndexVel = indmaxvel[0][-1]
872 maxIndexVel = indmaxvel[0][-1]
869 except:
873 except:
870 maxIndexVel = len(velrange)
874 maxIndexVel = len(velrange)
871
875
872 #seleccion del espectro
876 #seleccion del espectro
873 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
877 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
874 #estimacion de ruido
878 #estimacion de ruido
875 noise = numpy.zeros(self.dataOut.nChannels)
879 noise = numpy.zeros(self.dataOut.nChannels)
876
880
877 for channel in range(self.dataOut.nChannels):
881 for channel in range(self.dataOut.nChannels):
878 daux = data_spc[channel,:,:]
882 daux = data_spc[channel,:,:]
879 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
883 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
880
884
881 self.dataOut.noise_estimation = noise.copy()
885 self.dataOut.noise_estimation = noise.copy()
882
886
883 return 1
887 return 1
884
888
885 class IncohInt(Operation):
889 class IncohInt(Operation):
886
890
887
891
888 __profIndex = 0
892 __profIndex = 0
889 __withOverapping = False
893 __withOverapping = False
890
894
891 __byTime = False
895 __byTime = False
892 __initime = None
896 __initime = None
893 __lastdatatime = None
897 __lastdatatime = None
894 __integrationtime = None
898 __integrationtime = None
895
899
896 __buffer_spc = None
900 __buffer_spc = None
897 __buffer_cspc = None
901 __buffer_cspc = None
898 __buffer_dc = None
902 __buffer_dc = None
899
903
900 __dataReady = False
904 __dataReady = False
901
905
902 __timeInterval = None
906 __timeInterval = None
903
907
904 n = None
908 n = None
905
909
906
910
907
911
908 def __init__(self, **kwargs):
912 def __init__(self, **kwargs):
909
913
910 Operation.__init__(self, **kwargs)
914 Operation.__init__(self, **kwargs)
911 # self.isConfig = False
915 # self.isConfig = False
912
916
913 def setup(self, n=None, timeInterval=None, overlapping=False):
917 def setup(self, n=None, timeInterval=None, overlapping=False):
914 """
918 """
915 Set the parameters of the integration class.
919 Set the parameters of the integration class.
916
920
917 Inputs:
921 Inputs:
918
922
919 n : Number of coherent integrations
923 n : Number of coherent integrations
920 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
924 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
921 overlapping :
925 overlapping :
922
926
923 """
927 """
924
928
925 self.__initime = None
929 self.__initime = None
926 self.__lastdatatime = 0
930 self.__lastdatatime = 0
927
931
928 self.__buffer_spc = 0
932 self.__buffer_spc = 0
929 self.__buffer_cspc = 0
933 self.__buffer_cspc = 0
930 self.__buffer_dc = 0
934 self.__buffer_dc = 0
931
935
932 self.__profIndex = 0
936 self.__profIndex = 0
933 self.__dataReady = False
937 self.__dataReady = False
934 self.__byTime = False
938 self.__byTime = False
935
939
936 if n is None and timeInterval is None:
940 if n is None and timeInterval is None:
937 raise ValueError, "n or timeInterval should be specified ..."
941 raise ValueError, "n or timeInterval should be specified ..."
938
942
939 if n is not None:
943 if n is not None:
940 self.n = int(n)
944 self.n = int(n)
941 else:
945 else:
942 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
946 self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line
943 self.n = None
947 self.n = None
944 self.__byTime = True
948 self.__byTime = True
945
949
946 def putData(self, data_spc, data_cspc, data_dc):
950 def putData(self, data_spc, data_cspc, data_dc):
947
951
948 """
952 """
949 Add a profile to the __buffer_spc and increase in one the __profileIndex
953 Add a profile to the __buffer_spc and increase in one the __profileIndex
950
954
951 """
955 """
952
956
953 self.__buffer_spc += data_spc
957 self.__buffer_spc += data_spc
954
958
955 if data_cspc is None:
959 if data_cspc is None:
956 self.__buffer_cspc = None
960 self.__buffer_cspc = None
957 else:
961 else:
958 self.__buffer_cspc += data_cspc
962 self.__buffer_cspc += data_cspc
959
963
960 if data_dc is None:
964 if data_dc is None:
961 self.__buffer_dc = None
965 self.__buffer_dc = None
962 else:
966 else:
963 self.__buffer_dc += data_dc
967 self.__buffer_dc += data_dc
964
968
965 self.__profIndex += 1
969 self.__profIndex += 1
966
970
967 return
971 return
968
972
969 def pushData(self):
973 def pushData(self):
970 """
974 """
971 Return the sum of the last profiles and the profiles used in the sum.
975 Return the sum of the last profiles and the profiles used in the sum.
972
976
973 Affected:
977 Affected:
974
978
975 self.__profileIndex
979 self.__profileIndex
976
980
977 """
981 """
978
982
979 data_spc = self.__buffer_spc
983 data_spc = self.__buffer_spc
980 data_cspc = self.__buffer_cspc
984 data_cspc = self.__buffer_cspc
981 data_dc = self.__buffer_dc
985 data_dc = self.__buffer_dc
982 n = self.__profIndex
986 n = self.__profIndex
983
987
984 self.__buffer_spc = 0
988 self.__buffer_spc = 0
985 self.__buffer_cspc = 0
989 self.__buffer_cspc = 0
986 self.__buffer_dc = 0
990 self.__buffer_dc = 0
987 self.__profIndex = 0
991 self.__profIndex = 0
988
992
989 return data_spc, data_cspc, data_dc, n
993 return data_spc, data_cspc, data_dc, n
990
994
991 def byProfiles(self, *args):
995 def byProfiles(self, *args):
992
996
993 self.__dataReady = False
997 self.__dataReady = False
994 avgdata_spc = None
998 avgdata_spc = None
995 avgdata_cspc = None
999 avgdata_cspc = None
996 avgdata_dc = None
1000 avgdata_dc = None
997
1001
998 self.putData(*args)
1002 self.putData(*args)
999
1003
1000 if self.__profIndex == self.n:
1004 if self.__profIndex == self.n:
1001
1005
1002 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1006 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1003 self.n = n
1007 self.n = n
1004 self.__dataReady = True
1008 self.__dataReady = True
1005
1009
1006 return avgdata_spc, avgdata_cspc, avgdata_dc
1010 return avgdata_spc, avgdata_cspc, avgdata_dc
1007
1011
1008 def byTime(self, datatime, *args):
1012 def byTime(self, datatime, *args):
1009
1013
1010 self.__dataReady = False
1014 self.__dataReady = False
1011 avgdata_spc = None
1015 avgdata_spc = None
1012 avgdata_cspc = None
1016 avgdata_cspc = None
1013 avgdata_dc = None
1017 avgdata_dc = None
1014
1018
1015 self.putData(*args)
1019 self.putData(*args)
1016
1020
1017 if (datatime - self.__initime) >= self.__integrationtime:
1021 if (datatime - self.__initime) >= self.__integrationtime:
1018 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1022 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1019 self.n = n
1023 self.n = n
1020 self.__dataReady = True
1024 self.__dataReady = True
1021
1025
1022 return avgdata_spc, avgdata_cspc, avgdata_dc
1026 return avgdata_spc, avgdata_cspc, avgdata_dc
1023
1027
1024 def integrate(self, datatime, *args):
1028 def integrate(self, datatime, *args):
1025
1029
1026 if self.__profIndex == 0:
1030 if self.__profIndex == 0:
1027 self.__initime = datatime
1031 self.__initime = datatime
1028
1032
1029 if self.__byTime:
1033 if self.__byTime:
1030 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1034 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1031 else:
1035 else:
1032 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1036 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1033
1037
1034 if not self.__dataReady:
1038 if not self.__dataReady:
1035 return None, None, None, None
1039 return None, None, None, None
1036
1040
1037 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1041 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1038
1042
1039 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1043 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1040
1044
1041 if n==1:
1045 if n==1:
1042 return
1046 return
1043
1047
1044 dataOut.flagNoData = True
1048 dataOut.flagNoData = True
1045
1049
1046 if not self.isConfig:
1050 if not self.isConfig:
1047 self.setup(n, timeInterval, overlapping)
1051 self.setup(n, timeInterval, overlapping)
1048 self.isConfig = True
1052 self.isConfig = True
1049
1053
1050 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1054 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1051 dataOut.data_spc,
1055 dataOut.data_spc,
1052 dataOut.data_cspc,
1056 dataOut.data_cspc,
1053 dataOut.data_dc)
1057 dataOut.data_dc)
1054
1058
1055 if self.__dataReady:
1059 if self.__dataReady:
1056
1060
1057 dataOut.data_spc = avgdata_spc
1061 dataOut.data_spc = avgdata_spc
1058 dataOut.data_cspc = avgdata_cspc
1062 dataOut.data_cspc = avgdata_cspc
1059 dataOut.data_dc = avgdata_dc
1063 dataOut.data_dc = avgdata_dc
1060
1064
1061 dataOut.nIncohInt *= self.n
1065 dataOut.nIncohInt *= self.n
1062 dataOut.utctime = avgdatatime
1066 dataOut.utctime = avgdatatime
1063 dataOut.flagNoData = False
1067 dataOut.flagNoData = False
1064
1068
@@ -1,129 +1,130
1 # DIAS 19 Y 20 FEB 2014
1 # DIAS 19 Y 20 FEB 2014
2 # Comprobacion de Resultados DBS con SA
2 # Comprobacion de Resultados DBS con SA
3
3
4 import os, sys
4 import os, sys
5
5
6 path = os.path.split(os.getcwd())[0]
6 path = os.path.split(os.getcwd())[0]
7 path = os.path.split(path)[0]
7 path = os.path.split(path)[0]
8
8
9 sys.path.insert(0, path)
9 sys.path.insert(0, path)
10
10
11 from schainpy.controller import Project
11 from schainpy.controller import Project
12
12
13 desc = "SA Experiment Test"
13 desc = "SA Experiment Test"
14 filename = "SA2014050.xml"
14 filename = "SA2014050.xml"
15
15
16 controllerObj = Project()
16 controllerObj = Project()
17
17
18 controllerObj.setup(id = '191', name='test01', description=desc)
18 controllerObj.setup(id = '191', name='test01', description=desc)
19
19
20
20
21 #Experimentos
21 #Experimentos
22
22
23 #2014050 19 Feb 2014
23 #2014050 19 Feb 2014
24 path = '/media/joscanoa/84A65E64A65E5730/soporte/Data/MST/SA/d2014050'
24 path = '/media/joscanoa/84A65E64A65E5730/soporte/Data/MST/SA/d2014050'
25 pathFigure = '/media/joscanoa/84A65E64A65E5730/soporte/workspace/Graficos/SA/prueba1/'
25 pathFigure = '/media/joscanoa/84A65E64A65E5730/soporte/workspace/Graficos/SA/prueba1/'
26 xmin = '15.5'
26 xmin = '15.5'
27 xmax = '24'
27 xmax = '24'
28 startTime = '15:30:00'
28 startTime = '15:30:00'
29 filehdf5 = "SA_2014050.hdf5"
29 filehdf5 = "SA_2014050.hdf5"
30
30
31 #2014051 20 Feb 2014
31 #2014051 20 Feb 2014
32 # path = '/home/soporte/Data/MST/SA/d2014051'
32 path = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/' #'/home/soporte/Data/MST/SA/d2014051'
33 # pathFigure = '/home/soporte/workspace/Graficos/SA/new/'
33 # pathFigure = '/home/soporte/workspace/Graficos/SA/new/'
34 # xmin = '0.0'
34 # xmin = '0.0'
35 # xmax = '8.0'
35 # xmax = '8.0'
36 # startTime = '00:00:00'
36 # startTime = '00:00:00'
37 # filehdf5 = "SA_2014051.hdf5"
37 # filehdf5 = "SA_2014051.hdf5"
38
38
39 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
39 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
40 path=path,
40 path=path,
41 startDate='2014/01/01',
41 startDate='2017/08/22',
42 endDate='2014/03/31',
42 endDate='2018/08/22',
43 startTime=startTime,
43 startTime='00:00:00',
44 endTime='23:59:59',
44 endTime='6:00:59',
45 online=0,
45 online=0,
46 delay=5,
46 delay=5,
47 walk=0,
47 walk=1)
48 getblock=1,
48 #getblock=1,
49 blocksize=32768)
49 #blocksize=32768)
50
50
51 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
51 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
52
52
53
53
54 #--------------------------------------------------------------------------------------------------
54 #--------------------------------------------------------------------------------------------------
55
55
56 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
56 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
57
57
58 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
58 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
59
59
60 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
60 opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other')
61 # opObj11.addParameter(name='n', value='600', format='int')
61 # opObj11.addParameter(name='n', value='600', format='int')
62 opObj11.addParameter(name='n', value='256', format='int')
62 opObj11.addParameter(name='n', value='4', format='int')
63
63
64 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
64 opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
65 opObj11.addParameter(name='minIndex', value='10', format='float')
65 opObj11.addParameter(name='minIndex', value='10', format='float')
66 opObj11.addParameter(name='maxIndex', value='60', format='float')
66 opObj11.addParameter(name='maxIndex', value='60', format='float')
67 #---------------------------------------------------------------------------------------------------
67 #---------------------------------------------------------------------------------------------------
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj0.getId())
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj0.getId())
69 procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(1,0),(2,3)', format='pairsList')
69 procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(1,0),(2,3)', format='pairsList')
70
70 # procUnitConfObj1.addParameter(name='removeDC', value='1', format='bool')
71 #procUnitConfObj1.addParameter(name='removeDC', value='1', format='bool')
71 # #procUnitConfObj1.addParameter(name='lagT', value='0,1,2,3', format='intlist')
72 # #procUnitConfObj1.addParameter(name='lagT', value='0,1,2,3', format='intlist')
72 #
73 #
73 # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
74 # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
74 # opObj12.addParameter(name='id', value='1', format='int')
75 # opObj12.addParameter(name='id', value='1', format='int')
75 # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
76 # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
76 # opObj12.addParameter(name='save', value='1', format='bool')
77 # opObj12.addParameter(name='save', value='1', format='bool')
77 # opObj12.addParameter(name='zmin', value='0', format='int')
78 # opObj12.addParameter(name='zmin', value='0', format='int')
78 # opObj12.addParameter(name='zmax', value='1', format='int')
79 # opObj12.addParameter(name='zmax', value='1', format='int')
79 # opObj12.addParameter(name='figpath', value = pathFigure, format='str')
80 # opObj12.addParameter(name='figpath', value = pathFigure, format='str')
80 #
81 #
81 # opObj12 = procUnitConfObj1.addOperation(name='removeNoise')
82 # opObj12 = procUnitConfObj1.addOperation(name='removeNoise')
82 # opObj12.addParameter(name='mode', value='2', format='int')
83 # opObj12.addParameter(name='mode', value='2', format='int')
83 # opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor')
84 # opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor')
84 #
85 #
85 # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
86 # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other')
86 # opObj12.addParameter(name='id', value='2', format='int')
87 # opObj12.addParameter(name='id', value='2', format='int')
87 # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
88 # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str')
88 # opObj12.addParameter(name='save', value='1', format='bool')
89 # opObj12.addParameter(name='save', value='1', format='bool')
89 # opObj12.addParameter(name='zmin', value='0', format='int')
90 # opObj12.addParameter(name='zmin', value='0', format='int')
90 # opObj12.addParameter(name='zmax', value='1', format='int')
91 # opObj12.addParameter(name='zmax', value='1', format='int')
91 # opObj12.addParameter(name='figpath', value = pathFigure, format='str')
92 # opObj12.addParameter(name='figpath', value = pathFigure, format='str')
92 #
93 #
93 # #---------------------------------------------------------------------------------------------------
94 # #---------------------------------------------------------------------------------------------------
94 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
95 procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId())
95
96
96 opObj20 = procUnitConfObj2.addOperation(name='SALags', optype='other')
97 opObj20 = procUnitConfObj2.addOperation(name='SALags', optype='other')
97 #
98 #
98 opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
99 opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other')
99 opObj21.addParameter(name='technique', value='SA', format='str')
100 opObj21.addParameter(name='technique', value='SA', format='str')
100 # # opObj21.addParameter(name='correctFactor', value='-1', format='float')
101 # # opObj21.addParameter(name='correctFactor', value='-1', format='float')
101 opObj21.addParameter(name='positionX', value='36,0,36,0', format='floatlist')
102 opObj21.addParameter(name='positionX', value='1.5,0,1.5', format='floatlist')
102 opObj21.addParameter(name='positionY', value='36,0,0,36', format='floatlist')
103 opObj21.addParameter(name='positionY', value='0.875,0,-0.875', format='floatlist')
103 opObj21.addParameter(name='azimuth', value='51.06', format='float')
104 opObj21.addParameter(name='azimuth', value='0.0', format='float')
104
105
105 # opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
106 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
106 # opObj22.addParameter(name='id', value='4', format='int')
107 opObj22.addParameter(name='id', value='4', format='int')
107 # opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
108 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
108 # opObj22.addParameter(name='save', value='1', format='bool')
109 #opObj22.addParameter(name='save', value='1', format='bool')
109 # opObj22.addParameter(name='figpath', value = pathFigure, format='str')
110 #opObj22.addParameter(name='figpath', value = pathFigure, format='str')
110 # opObj22.addParameter(name='zmin', value='-15', format='int')
111 opObj22.addParameter(name='zmin', value='-15', format='int')
111 # opObj22.addParameter(name='zmax', value='15', format='int')
112 opObj22.addParameter(name='zmax', value='15', format='int')
112 # opObj22.addParameter(name='zmin_ver', value='-80', format='float')
113 opObj22.addParameter(name='zmin_ver', value='-80', format='float')
113 # opObj22.addParameter(name='zmax_ver', value='80', format='float')
114 opObj22.addParameter(name='zmax_ver', value='80', format='float')
114 # opObj22.addParameter(name='SNRmin', value='-20', format='int')
115 opObj22.addParameter(name='SNRmin', value='-20', format='int')
115 # opObj22.addParameter(name='SNRmax', value='40', format='int')
116 opObj22.addParameter(name='SNRmax', value='40', format='int')
116 # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
117 opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
117 # opObj22.addParameter(name='xmin', value=xmin, format='float')
118 opObj22.addParameter(name='xmin', value=xmin, format='float')
118 # opObj22.addParameter(name='xmax', value=xmax, format='float')
119 opObj22.addParameter(name='xmax', value=xmax, format='float')
119
120
120 #-----------------------------------------------------------------------------------
121 #-----------------------------------------------------------------------------------
121
122
122 print "Escribiendo el archivo XML"
123 print "Escribiendo el archivo XML"
123 controllerObj.writeXml(filename)
124 controllerObj.writeXml(filename)
124 print "Leyendo el archivo XML"
125 print "Leyendo el archivo XML"
125 controllerObj.readXml(filename)
126 controllerObj.readXml(filename)
126
127
127 controllerObj.createObjects()
128 controllerObj.createObjects()
128 controllerObj.connectObjects()
129 controllerObj.connectObjects()
129 controllerObj.run()
130 controllerObj.run()
@@ -1,1 +1,1
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/erick/Documents/Data/Claire_Data/raw" /><Parameter format="date" id="191113" name="startDate" value="2017/07/26" /><Parameter format="date" id="191114" name="endDate" value="2017/07/26" /><Parameter format="time" id="191115" name="startTime" value="10:02:00" /><Parameter format="time" id="191116" name="endTime" value="10:11:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="SpectraProc" id="1913" inputId="1912" name="SpectraProc"><Operation id="19131" name="run" priority="1" type="self"><Parameter format="int" id="191311" name="nFFTPoints" value="128" /><Parameter format="pairslist" id="191312" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19132" name="removeDC" priority="2" type="self" /><Operation id="19133" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191331" name="n" value="30" /></Operation><Operation id="19134" name="CrossSpectraPlot" priority="4" type="other"><Parameter format="str" id="191341" name="phase_cmap" value="bwr" /><Parameter format="int" id="191342" name="id" value="2005" /><Parameter format="str" id="191343" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191344" name="xaxis" value="Velocity" /><Parameter format="float" id="191345" name="ymin" value="1" /><Parameter format="int" id="191346" name="ymax" value="7" /><Parameter format="int" id="191347" name="zmin" value="15" /><Parameter format="int" id="191348" name="zmax" value="60" /><Parameter format="int" id="191349" name="save" value="2" /><Parameter format="str" id="191350" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images" /></Operation></ProcUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation><Operation id="19123" name="selectHeights" priority="3" type="self"><Parameter format="float" id="191231" name="minHei" value="0" /><Parameter format="float" id="191232" name="maxHei" value="64" /></Operation></ProcUnit><ProcUnit datatype="Parameters" id="1914" inputId="1913" name="ParametersProc"><Operation id="19141" name="run" priority="1" type="self" /><Operation id="19142" name="GaussianFit" priority="2" type="other" /></ProcUnit></Project> No newline at end of file
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024/d2017234" /><Parameter format="date" id="191113" name="startDate" value="2017/08/22" /><Parameter format="date" id="191114" name="endDate" value="2017/08/22" /><Parameter format="time" id="191115" name="startTime" value="02:00:00" /><Parameter format="time" id="191116" name="endTime" value="06:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="ParamWriter" priority="4" type="other"><Parameter format="str" id="191341" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191342" name="blocksPerFile" value="100" /><Parameter format="list" id="191343" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191344" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self"><Parameter format="pairslist" id="191211" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation><Operation id="19123" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191231" name="n" value="5" /></Operation><Operation id="19124" name="SpectraPlot" priority="4" type="external"><Parameter format="int" id="191241" name="id" value="11" /><Parameter format="str" id="191242" name="wintitle" value="SpectraPlot" /><Parameter format="str" id="191243" name="xaxis" value="frequency" /><Parameter format="float" id="191244" name="ymin" value="1" /><Parameter format="int" id="191245" name="ymax" value="5" /><Parameter format="int" id="191246" name="zmin" value="15" /><Parameter format="int" id="191247" name="zmax" value="50" /><Parameter format="int" id="191248" name="save" value="2" /><Parameter format="int" id="191249" name="save" value="5" /><Parameter format="str" id="191250" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/FirstResults1024" /></Operation><Operation id="19125" name="CrossSpectraPlot" priority="5" type="other"><Parameter format="int" id="191251" name="id" value="2005" /><Parameter format="str" id="191252" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191253" name="xaxis" value="Velocity" /><Parameter format="float" id="191254" name="xmin" value="-10" /><Parameter format="float" id="191255" name="xmax" value="10" /><Parameter format="int" id="191256" name="zmin" value="15" /><Parameter format="int" id="191257" name="zmax" value="50" /><Parameter format="str" id="191258" name="phase_cmap" value="bwr" /><Parameter format="float" id="191259" name="ymin" value="1" /><Parameter format="float" id="191260" name="ymax" value="5" /></Operation></ProcUnit></Project> No newline at end of file
@@ -1,171 +1,63
1 '''
1 '''
2 Created on Nov 09, 2016
2 Created on Nov 09, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6 import os, sys
6 import os, sys
7
7
8
8
9 path = os.path.split(os.getcwd())[0]
9 path = os.path.split(os.getcwd())[0]
10 path = os.path.split(path)[0]
10 path = os.path.split(path)[0]
11
11
12 sys.path.insert(0, path)
12 sys.path.insert(0, path)
13
13
14 from schainpy.controller import Project
14 from schainpy.controller import Project
15
15
16 filename = 'test1.xml'
16 filename = 'test1.xml'
17 # path = '/home/jespinoza/workspace/data/bltr/'
17 # path = '/home/jespinoza/workspace/data/bltr/'
18 path = '/media/erick/6F60F7113095A154/BLTR/'
18 path = '/home/erick/Documents/Data/BLTR_Data/sswma/'#'/media/erick/6F60F7113095A154/BLTR/'
19 desc = "read bltr data sswma file"
19 desc = "read bltr data sswma file"
20 figpath = '/media/erick/6F60F7113095A154/BLTR/'
20 figpath = '/media/erick/6F60F7113095A154/BLTR/'
21 pathhdf5 = '/tmp/'
21 pathhdf5 = '/tmp/'
22
22
23 controllerObj = Project()
23 controllerObj = Project()
24
24
25 controllerObj.setup(id = '191', name='test1', description=desc)
25 controllerObj.setup(id = '191', name='test1', description=desc)
26 readUnitConfObj = controllerObj.addReadUnit(datatype='testBLTRReader',
26 readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRParamReader',
27 path=path,
27 path=path,
28 startDate='2017/01/17',
28 startDate='2017/01/17',
29 endDate='2018/01/01',
29 endDate='2018/01/01',
30 startTime='00:00:00',
30 startTime='06:00:00',
31 endTime='23:59:59',
31 endTime='23:59:59',
32 ext='sswma')
32 verbose=0,
33 )
33
34
34 procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRProcess',
35 procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRParametersProc',
35 inputId=readUnitConfObj.getId())
36 inputId=readUnitConfObj.getId())
36
37
37 '''-------------------------------------------Processing--------------------------------------------'''
38 procUnitConfObj1.addParameter(name='mode', value='1', format='int')
39 # procUnitConfObj1.addParameter(name='snr_threshold', value='10', format='float')
38
40
39 '''MODE 1: LOW ATMOSPHERE: 0- 3 km'''
40 # opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
41 # opObj10.addParameter(name='snr_val', value='-10', format='float')
42 # opObj10.addParameter(name='modetofilter', value='1', format='int')
43 #
44 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
45 # opObj10.addParameter(name='svalue', value='meridional', format='str')
46 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
47 # opObj10.addParameter(name='method', value='0', format='float')
48 # opObj10.addParameter(name='factor', value='1', format='float')
49 # opObj10.addParameter(name='filter', value='0', format='float')
50 # opObj10.addParameter(name='npoints', value='5', format='float')
51 # opObj10.addParameter(name='modetofilter', value='1', format='int')
52 # #
53 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
54 # opObj10.addParameter(name='svalue', value='zonal', format='str')
55 # opObj10.addParameter(name='svalue2', value='inTime', format='str')
56 # opObj10.addParameter(name='method', value='0', format='float')
57 # opObj10.addParameter(name='factor', value='1', format='float')
58 # opObj10.addParameter(name='filter', value='0', format='float')
59 # opObj10.addParameter(name='npoints', value='5', format='float')
60 # opObj10.addParameter(name='modetofilter', value='1', format='int')
61 # #
62 # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
63 # opObj10.addParameter(name='svalue', value='vertical', format='str')
64 # opObj10.addParameter(name='svalue2', value='inHeight', format='str')
65 # opObj10.addParameter(name='method', value='0', format='float')
66 # opObj10.addParameter(name='factor', value='2', format='float')
67 # opObj10.addParameter(name='filter', value='0', format='float')
68 # opObj10.addParameter(name='npoints', value='9', format='float')
69 # opObj10.addParameter(name='modetofilter', value='1', format='int')
70 #
71
41
72 ''' MODE 2: 0 - 10 km '''
73
74 opObj10 = procUnitConfObj1.addOperation(name='SnrFilter')
75 opObj10.addParameter(name='snr_val', value='-20', format='float')
76 opObj10.addParameter(name='modetofilter', value='2', format='int')
77
78 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
79 opObj10.addParameter(name='svalue', value='meridional', format='str')
80 opObj10.addParameter(name='svalue2', value='inTime', format='str')
81 opObj10.addParameter(name='method', value='0', format='float')
82 opObj10.addParameter(name='factor', value='2', format='float')
83 opObj10.addParameter(name='filter', value='0', format='float')
84 opObj10.addParameter(name='npoints', value='9', format='float')
85 opObj10.addParameter(name='modetofilter', value='2', format='int')
86 # #
87 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
88 opObj10.addParameter(name='svalue', value='zonal', format='str')
89 opObj10.addParameter(name='svalue2', value='inTime', format='str')
90 opObj10.addParameter(name='method', value='0', format='float')
91 opObj10.addParameter(name='factor', value='2', format='float')
92 opObj10.addParameter(name='filter', value='0', format='float')
93 opObj10.addParameter(name='npoints', value='9', format='float')
94 opObj10.addParameter(name='modetofilter', value='2', format='int')
95 # #
96 opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter')
97 opObj10.addParameter(name='svalue', value='vertical', format='str')
98 opObj10.addParameter(name='svalue2', value='inHeight', format='str')
99 opObj10.addParameter(name='method', value='0', format='float')
100 opObj10.addParameter(name='factor', value='2', format='float')
101 opObj10.addParameter(name='filter', value='0', format='float')
102 opObj10.addParameter(name='npoints', value='9', format='float')
103 opObj10.addParameter(name='modetofilter', value='2', format='int')
104
105 # '''-----------------------------------------Writing-------------------------------------------'''
106 #
107 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
108 # # opObj10.addParameter(name='path', value = pathhdf5)
109 # # opObj10.addParameter(name='modetowrite', value = '2',format='int')
110 # #
111 # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other')
112 # # opObj10.addParameter(name='path', value = pathhdf5)
113 # # opObj10.addParameter(name='modetowrite', value = '1',format='int')
114 #
115 # '''----------------------------------------Plotting--------------------------------------------'''
116 #
117 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
118 opObj10.addParameter(name='modeselect',value='1',format='int')
119 # #
120 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
42 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
121 opObj10.addParameter(name='id', value='1', format='int')
43 opObj10.addParameter(name='id', value='2', format='int')
122 opObj10.addParameter(name='wintitle', value='', format='str')
44 opObj10.addParameter(name='wintitle', value='', format='str')
123 opObj10.addParameter(name='channelList', value='0', format='intlist')
45
124 #opObj10.addParameter(name='save', value='1', format='bool')
46 # opObj10.addParameter(name='save', value='1', format='bool')
125 #opObj10.addParameter(name='figpath', value=figpath, format='str')
47 # opObj10.addParameter(name='figpath', value=figpath, format='str')
126 opObj10.addParameter(name='SNRmin', value='-10', format='int')
127 opObj10.addParameter(name='SNRmax', value='50', format='int')
128 opObj10.addParameter(name='SNRthresh', value='0', format='float')
129 opObj10.addParameter(name='xmin', value='0', format='float')
130 opObj10.addParameter(name='xmax', value='24', format='float')
131 opObj10.addParameter(name='ymax', value='3', format='float')
132 opObj10.addParameter(name='zmin', value='-20', format='float')
133 opObj10.addParameter(name='zmax', value='20', format='float')
134 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
135 opObj10.addParameter(name='zmax_ver', value='200', format='float')
136 #opObj10.addParameter(name='showprofile', value='1', format='bool')
137 #opObj10.addParameter(name='show', value='1', format='bool')
138
139 opObj10 = procUnitConfObj1.addOperation(name='prePlot')
140 opObj10.addParameter(name='modeselect',value='2',format='int')
141 #
142 opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other')
143 opObj10.addParameter(name='id', value='2', format='int')
144 opObj10.addParameter(name='wintitle', value='', format='str')
145 #opObj10.addParameter(name='channelList', value='0', format='intlist')
146 opObj10.addParameter(name='save', value='1', format='bool')
147 opObj10.addParameter(name='figpath', value=figpath, format='str')
148 opObj10.addParameter(name='SNRmin', value='-20', format='int')
48 opObj10.addParameter(name='SNRmin', value='-20', format='int')
149 opObj10.addParameter(name='SNRmax', value='40', format='int')
49 opObj10.addParameter(name='SNRmax', value='40', format='int')
150 opObj10.addParameter(name='SNRthresh', value='0', format='float')
50 opObj10.addParameter(name='SNRthresh', value='0', format='float')
151 opObj10.addParameter(name='xmin', value='0', format='float')
51 opObj10.addParameter(name='xmin', value='0', format='float')
152 opObj10.addParameter(name='xmax', value='24', format='float')
52 opObj10.addParameter(name='xmax', value='24', format='float')
153 opObj10.addParameter(name='ymin', value='0', format='float')
53 opObj10.addParameter(name='ymin', value='0', format='float')
154 opObj10.addParameter(name='ymax', value='7', format='float')
54 opObj10.addParameter(name='ymax', value='7', format='float')
155 opObj10.addParameter(name='zmin', value='-4', format='float')
55 opObj10.addParameter(name='zmin', value='-4', format='float')
156 opObj10.addParameter(name='zmax', value='4', format='float')
56 opObj10.addParameter(name='zmax', value='4', format='float')
157 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
57 opObj10.addParameter(name='zmin_ver', value='-200', format='float')
158 opObj10.addParameter(name='zmax_ver', value='200', format='float')
58 opObj10.addParameter(name='zmax_ver', value='200', format='float')
159 #opObj10.addParameter(name='showprofile', value='1', format='bool')
59 #opObj10.addParameter(name='showprofile', value='1', format='bool')
160 #opObj10.addParameter(name='show', value='1', format='bool')
60 #opObj10.addParameter(name='show', value='1', format='bool')
161
61
162 # # print "Escribiendo el archivo XML"
163 # controllerObj.writeXml(filename)
164 # # print "Leyendo el archivo XML"
165 # controllerObj.readXml(filename)
166
167 # controllerObj.createObjects()
168 # controllerObj.connectObjects()
169 # controllerObj.run()
170 controllerObj.start()
62 controllerObj.start()
171
63
@@ -1,151 +1,151
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 import os, sys
2 import os, sys
3
3
4 # path = os.path.dirname(os.getcwd())
4 # path = os.path.dirname(os.getcwd())
5 # path = os.path.join(path, 'source')
5 # path = os.path.join(path, 'source')
6 # sys.path.insert(0, '../')
6 # sys.path.insert(0, '../')
7
7
8 from schainpy.controller import Project
8 from schainpy.controller import Project
9
9
10 xmin = '15.5'
10 xmin = '15.5'
11 xmax = '24'
11 xmax = '24'
12
12
13
13
14 desc = "ProcBLTR Test"
14 desc = "ProcBLTR Test"
15 filename = "ProcBLTR.xml"
15 filename = "ProcBLTR.xml"
16 figpath = '/media/erick/6F60F7113095A154/BLTR'
16 figpath = '/media/erick/6F60F7113095A154/BLTR'
17
17
18 controllerObj = Project()
18 controllerObj = Project()
19
19
20
20
21 controllerObj.setup(id='191', name='test01', description=desc)
21 controllerObj.setup(id='191', name='test01', description=desc)
22
22
23 readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRReader',
23 readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRSpectraReader',
24 path='/media/erick/6F60F7113095A154/BLTR/',
24 #path='/media/erick/6F60F7113095A154/BLTR/',
25
25 path='/home/erick/Documents/Data/BLTR_Data/fdt/',
26 endDate='2017/10/19',
26 endDate='2017/10/19',
27 startTime='13:00:00',
27 startTime='13:00:00',
28 startDate='2016/11/8',
28 startDate='2016/11/8',
29 endTime='23:59:59',
29 endTime='23:59:59',
30
30
31
31
32 online=0,
32 online=0,
33 walk=0,
33 walk=0,
34 ReadMode='1')
34 ReadMode='1')
35 # expLabel='')
35 # expLabel='')
36
36
37 # opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
37 # opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
38
38
39 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
39 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
40
40
41
41
42
43 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
42 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
44 opObj11.addParameter(name='n', value='3', format='float')
43 opObj11.addParameter(name='n', value='2', format='float')
45
44
46 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
45 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
46 #opObj10 = procUnitConfObj1.addOperation(name='removeInterference2')
47
47
48 # opObj10 = procUnitConfObj1.addOperation(name='calcMag')
48 # opObj10 = procUnitConfObj1.addOperation(name='calcMag')
49
49
50 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
50 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
51 # opObj11.addParameter(name='id', value='21', format='int')
51 # opObj11.addParameter(name='id', value='21', format='int')
52 # opObj11.addParameter(name='wintitle', value='SpectraCutPlot', format='str')
52 # opObj11.addParameter(name='wintitle', value='SpectraCutPlot', format='str')
53 # opObj11.addParameter(name='xaxis', value='frequency', format='str')
53 # opObj11.addParameter(name='xaxis', value='frequency', format='str')
54 # opObj11.addParameter(name='colormap', value='winter', format='str')
54 # opObj11.addParameter(name='colormap', value='winter', format='str')
55 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
55 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
56 # opObj11.addParameter(name='xmax', value='0.005', format='float')
56 # opObj11.addParameter(name='xmax', value='0.005', format='float')
57 # #opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
57 # #opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
58 # #opObj10.addParameter(name='channelList', value='0,1', format='intlist')
58 # #opObj10.addParameter(name='channelList', value='0,1', format='intlist')
59 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
59 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
60 # opObj11.addParameter(name='id', value='21', format='int')
60 # opObj11.addParameter(name='id', value='21', format='int')
61 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
61 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
62 # #opObj11.addParameter(name='xaxis', value='Velocity', format='str')
62 # #opObj11.addParameter(name='xaxis', value='Velocity', format='str')
63
63
64 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
64 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
65 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
65 # opObj11.addParameter(name='xmin', value='-0.005', format='float')
66 # opObj11.addParameter(name='xmax', value='0.005', format='float')
66 # opObj11.addParameter(name='xmax', value='0.005', format='float')
67
67
68 # opObj11.addParameter(name='ymin', value='225', format='float')
68 # opObj11.addParameter(name='ymin', value='225', format='float')
69 # opObj11.addParameter(name='ymax', value='3000', format='float')
69 # opObj11.addParameter(name='ymax', value='3000', format='float')
70 # opObj11.addParameter(name='zmin', value='-100', format='int')
70 # opObj11.addParameter(name='zmin', value='-100', format='int')
71 # opObj11.addParameter(name='zmax', value='-65', format='int')
71 # opObj11.addParameter(name='zmax', value='-65', format='int')
72
72
73 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
73 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
74 # opObj11.addParameter(name='id', value='10', format='int')
74 # opObj11.addParameter(name='id', value='10', format='int')
75 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
75 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
76 # opObj11.addParameter(name='ymin', value='0', format='float')
76 # opObj11.addParameter(name='ymin', value='0', format='float')
77 # opObj11.addParameter(name='ymax', value='4000', format='float')
77 # opObj11.addParameter(name='ymax', value='4000', format='float')
78 # #opObj11.addParameter(name='zmin', value='-100', format='int')
78 # #opObj11.addParameter(name='zmin', value='-100', format='int')
79 # #opObj11.addParameter(name='zmax', value='-70', format='int')
79 # #opObj11.addParameter(name='zmax', value='-70', format='int')
80 # opObj11.addParameter(name='zmin', value='-90', format='int')
80 # opObj11.addParameter(name='zmin', value='-90', format='int')
81 # opObj11.addParameter(name='zmax', value='-40', format='int')
81 # opObj11.addParameter(name='zmax', value='-40', format='int')
82 # opObj11.addParameter(name='showprofile', value='1', format='int')
82 # opObj11.addParameter(name='showprofile', value='1', format='int')
83 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
83 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
84
84
85 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
85 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
86 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
86 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
87 opObj11.addParameter(name='id', value='2005', format='int')
87 opObj11.addParameter(name='id', value='2005', format='int')
88 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
88 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
89 # opObj11.addParameter(name='exp_code', value='13', format='int')
89 # opObj11.addParameter(name='exp_code', value='13', format='int')
90 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
90 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
91 #opObj11.addParameter(name='xmin', value='-10', format='float')
91 #opObj11.addParameter(name='xmin', value='-10', format='float')
92 #opObj11.addParameter(name='xmax', value='10', format='float')
92 #opObj11.addParameter(name='xmax', value='10', format='float')
93 #opObj11.addParameter(name='ymin', value='225', format='float')
93 #opObj11.addParameter(name='ymin', value='225', format='float')
94 #opObj11.addParameter(name='ymax', value='3000', format='float')
94 #opObj11.addParameter(name='ymax', value='3000', format='float')
95 #opObj11.addParameter(name='phase_min', value='-4', format='int')
95 #opObj11.addParameter(name='phase_min', value='-4', format='int')
96 #opObj11.addParameter(name='phase_max', value='4', format='int')
96 #opObj11.addParameter(name='phase_max', value='4', format='int')
97
97
98 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj1.getId())
98 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj1.getId())
99 # procUnitConfObj2.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
99 # procUnitConfObj2.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
100
100
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
101 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
102 opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
102 opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
103 opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
103 opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
104 opObj22.addParameter(name='SNRlimit', value='-4', format='float')
104 opObj22.addParameter(name='SNRlimit', value='7', format='float')
105 #
105
106 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
106 opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
107 opObj22.addParameter(name='id', value='4', format='int')
107 opObj22.addParameter(name='id', value='4', format='int')
108 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
108 opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
109 opObj22.addParameter(name='save', value='1', format='bool')
109 opObj22.addParameter(name='save', value='1', format='bool')
110 # opObj22.addParameter(name='figpath', value = '/home/erick/Pictures', format='str')
110 # opObj22.addParameter(name='figpath', value = '/home/erick/Pictures', format='str')
111
111
112 opObj22.addParameter(name='zmin', value='-20', format='int')
112 opObj22.addParameter(name='zmin', value='-20', format='int')
113 opObj22.addParameter(name='zmax', value='20', format='int')
113 opObj22.addParameter(name='zmax', value='20', format='int')
114 opObj22.addParameter(name='zmin_ver', value='-250', format='float')
114 opObj22.addParameter(name='zmin_ver', value='-300', format='float')
115 opObj22.addParameter(name='zmax_ver', value='250', format='float')
115 opObj22.addParameter(name='zmax_ver', value='300', format='float')
116 opObj22.addParameter(name='SNRmin', value='-5', format='int')
116 opObj22.addParameter(name='SNRmin', value='-5', format='int')
117 opObj22.addParameter(name='SNRmax', value='30', format='int')
117 opObj22.addParameter(name='SNRmax', value='30', format='int')
118 # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
118 # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float')
119 opObj22.addParameter(name='xmin', value='0', format='float')
119 opObj22.addParameter(name='xmin', value='0', format='float')
120 opObj22.addParameter(name='xmax', value='24', format='float')
120 opObj22.addParameter(name='xmax', value='24', format='float')
121 opObj22.addParameter(name='ymin', value='225', format='float')
121 opObj22.addParameter(name='ymin', value='225', format='float')
122 #opObj22.addParameter(name='ymax', value='2000', format='float')
122 #opObj22.addParameter(name='ymax', value='2000', format='float')
123 opObj22.addParameter(name='save', value='1', format='int')
123 opObj22.addParameter(name='save', value='1', format='int')
124 opObj22.addParameter(name='figpath', value=figpath, format='str')
124 opObj22.addParameter(name='figpath', value=figpath, format='str')
125
125
126
126
127 # opObj11.addParameter(name='pairlist', value='(1,0),(0,2),(1,2)', format='pairsList')
127 # opObj11.addParameter(name='pairlist', value='(1,0),(0,2),(1,2)', format='pairsList')
128 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
128 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
129 #opObj10.addParameter(name='minHei', value='225', format='float')
129 #opObj10.addParameter(name='minHei', value='225', format='float')
130 #opObj10.addParameter(name='maxHei', value='1000', format='float')
130 #opObj10.addParameter(name='maxHei', value='1000', format='float')
131
131
132 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
132 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
133 # opObj11.addParameter(name='id', value='102', format='int')
133 # opObj11.addParameter(name='id', value='102', format='int')
134 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
134 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
135 # opObj11.addParameter(name='ymin', value='225', format='float')
135 # opObj11.addParameter(name='ymin', value='225', format='float')
136 # opObj11.addParameter(name='ymax', value='4000', format='float')
136 # opObj11.addParameter(name='ymax', value='4000', format='float')
137
137
138 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
138 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
139 # opObj11.addParameter(name='xmin', value='8.5', format='float')
139 # opObj11.addParameter(name='xmin', value='8.5', format='float')
140 # opObj11.addParameter(name='xmax', value='9.5', format='float')
140 # opObj11.addParameter(name='xmax', value='9.5', format='float')
141 # opObj11.addParameter(name='figpath', value=figpath, format='str')
141 # opObj11.addParameter(name='figpath', value=figpath, format='str')
142 # opObj11.addParameter(name='save', value=1, format='bool')
142 # opObj11.addParameter(name='save', value=1, format='bool')
143 # opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
143 # opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
144
144
145 # opObj12 = procUnitConfObj1.addOperation(name='PublishData', optype='other')
145 # opObj12 = procUnitConfObj1.addOperation(name='PublishData', optype='other')
146 # opObj12.addParameter(name='zeromq', value=1, format='int')
146 # opObj12.addParameter(name='zeromq', value=1, format='int')
147 # opObj12.addParameter(name='verbose', value=0, format='bool')
147 # opObj12.addParameter(name='verbose', value=0, format='bool')
148 # opObj12.addParameter(name='server', value='erick2', format='str')
148 # opObj12.addParameter(name='server', value='erick2', format='str')
149 controllerObj.start()
149 controllerObj.start()
150
150
151
151
@@ -1,104 +1,112
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 '''
2 '''
3 Created on Jul 7, 2014
3 Created on Jul 7, 2014
4
4
5 @author: roj-idl71
5 @author: roj-idl71
6 '''
6 '''
7 import os, sys
7 import os, sys
8
8
9 from schainpy.controller import Project
9 from schainpy.controller import Project
10
10
11 def main():
11 def main():
12 desc = "Segundo Test"
12 desc = "Segundo Test"
13 filename = "schain.xml"
13 filename = "schain.xml"
14
14
15 controllerObj = Project()
15 controllerObj = Project()
16
16
17 controllerObj.setup(id = '191', name='test01', description=desc)
17 controllerObj.setup(id = '191', name='test01', description=desc)
18
18
19 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
19 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
20 path='/home/erick/Documents/Data/d2015106',
20 path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdata',
21 startDate='2010/12/18',
21 #path='/home/erick/Documents/Data/Claire_Data/raw',
22 endDate='2017/12/22',
22 startDate='2017/07/20',
23 startTime='00:00:00',
23 endDate='2017/07/26',
24 endTime='23:59:59',
24 startTime='10:02:00',
25 endTime='10:11:00',
25 online=0,
26 online=0,
26 walk=0,
27 walk=1)
27 expLabel='')
28 # path='/home/erick/Documents/Data/d2015106',
29 # startDate='2010/12/18',
30 # endDate='2017/12/22',
31 # startTime='00:00:00',
32 # endTime='23:59:59',
33 # online=0,
34 # walk=0,
35 # expLabel='')
28
36
29 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
37 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
30
38
31 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
39 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
32 opObj10.addParameter(name='channelList', value='0,1', format='intlist')
40 opObj10.addParameter(name='channelList', value='0,1', format='intlist')
33
41
34 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
42 #opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
35 #opObj10.addParameter(name='minHei', value='90', format='float')
43 #opObj10.addParameter(name='minHei', value='90', format='float')
36 #opObj10.addParameter(name='maxHei', value='180', format='float')
44 #opObj10.addParameter(name='maxHei', value='180', format='float')
37
45
38 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
46 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
39
47
40 #opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
48 #opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
41 #opObj12.addParameter(name='n', value='1', format='int')
49 #opObj12.addParameter(name='n', value='1', format='int')
42
50
43 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
51 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
44 opObj11.addParameter(name='id', value='1', format='int')
52 opObj11.addParameter(name='id', value='1', format='int')
45 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
53 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
46 opObj11.addParameter(name='xaxis', value='velocity', format='str')
54 opObj11.addParameter(name='xaxis', value='velocity', format='str')
47 opObj11.addParameter(name='showprofile', value='1', format='int')
55 opObj11.addParameter(name='showprofile', value='1', format='int')
48 opObj11.addParameter(name='save', value='1', format='int')
56 opObj11.addParameter(name='save', value='1', format='int')
49 opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
57 opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
50
58
51 #opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
59 #opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
52 #opObj11.addParameter(name='id', value='10', format='int')
60 #opObj11.addParameter(name='id', value='10', format='int')
53 #opObj11.addParameter(name='wintitle', value='RTI', format='str')
61 #opObj11.addParameter(name='wintitle', value='RTI', format='str')
54 # opObj11.addParameter(name='xmin', value='21', format='float')
62 # opObj11.addParameter(name='xmin', value='21', format='float')
55 # opObj11.addParameter(name='xmax', value='22', format='float')
63 # opObj11.addParameter(name='xmax', value='22', format='float')
56 #opObj11.addParameter(name='zmin', value='12', format='int')
64 #opObj11.addParameter(name='zmin', value='12', format='int')
57 #opObj11.addParameter(name='zmax', value='32', format='int')
65 #opObj11.addParameter(name='zmax', value='32', format='int')
58 #opObj11.addParameter(name='showprofile', value='1', format='int')
66 #opObj11.addParameter(name='showprofile', value='1', format='int')
59 #opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
67 #opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
60
68
61 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=readUnitConfObj.getId())
69 procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=readUnitConfObj.getId())
62 opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other')
70 opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other')
63 opObj11.addParameter(name='vel_arr', value='32,0,0,0', format='intList')
71 #opObj11.addParameter(name='vel_arr', value='32,0,0,0', format='intList')
64 opObj11.addParameter(name='SNRlimit', value='-3', format='int')
72 opObj11.addParameter(name='SNRlimit', value='-3', format='int')
65
73
66 #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other')
74 #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other')
67 #opObj12.addParameter(name='id',value='4',format='int')
75 #opObj12.addParameter(name='id',value='4',format='int')
68 #opObj12.addParameter(name='wintitle',value='First_gg',format='str')
76 #opObj12.addParameter(name='wintitle',value='First_gg',format='str')
69
77
70 opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
78 opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
71 opObj11.addParameter(name='id', value='21', format='int')
79 opObj11.addParameter(name='id', value='21', format='int')
72 opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str')
80 opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str')
73 opObj11.addParameter(name='xaxis', value='frequency', format='str')
81 opObj11.addParameter(name='xaxis', value='frequency', format='str')
74 opObj11.addParameter(name='showprofile', value='1', format='int')
82 opObj11.addParameter(name='showprofile', value='1', format='int')
75 opObj11.addParameter(name='zmin', value='-20', format='int')
83 opObj11.addParameter(name='zmin', value='-20', format='int')
76 opObj11.addParameter(name='zmax', value='20', format='int')
84 opObj11.addParameter(name='zmax', value='20', format='int')
77 opObj11.addParameter(name='GauSelector', value='1', format='int')
85 opObj11.addParameter(name='GauSelector', value='1', format='int')
78 #opObj11.addParameter(name='save', value='1', format='int')
86 #opObj11.addParameter(name='save', value='1', format='int')
79 #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
87 #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
80
88
81 opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
89 opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
82 opObj11.addParameter(name='id', value='22', format='int')
90 opObj11.addParameter(name='id', value='22', format='int')
83 opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str')
91 opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str')
84 opObj11.addParameter(name='xaxis', value='frequency', format='str')
92 opObj11.addParameter(name='xaxis', value='frequency', format='str')
85 opObj11.addParameter(name='showprofile', value='1', format='int')
93 opObj11.addParameter(name='showprofile', value='1', format='int')
86 opObj11.addParameter(name='zmin', value='-20', format='int')
94 opObj11.addParameter(name='zmin', value='-20', format='int')
87 opObj11.addParameter(name='zmax', value='20', format='int')
95 opObj11.addParameter(name='zmax', value='20', format='int')
88 opObj11.addParameter(name='GauSelector', value='0', format='int')
96 opObj11.addParameter(name='GauSelector', value='0', format='int')
89
97
90 #opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
98 #opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
91 #opObj11.addParameter(name='id', value='55', format='int')
99 #opObj11.addParameter(name='id', value='55', format='int')
92 #opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str')
100 #opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str')
93 #opObj11.addParameter(name='xaxis', value='velocity', format='str')
101 #opObj11.addParameter(name='xaxis', value='velocity', format='str')
94 #opObj11.addParameter(name='showprofile', value='1', format='int')
102 #opObj11.addParameter(name='showprofile', value='1', format='int')
95 #opObj11.addParameter(name='save', value='1', format='int')
103 #opObj11.addParameter(name='save', value='1', format='int')
96 #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
104 #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
97
105
98 controllerObj.start()
106 controllerObj.start()
99
107
100 if __name__ == '__main__':
108 if __name__ == '__main__':
101 import time
109 import time
102 start_time = time.time()
110 start_time = time.time()
103 main()
111 main()
104 print("--- %s seconds ---" % (time.time() - start_time))
112 print("--- %s seconds ---" % (time.time() - start_time))
@@ -1,93 +1,238
1 import os, sys
1 import os, sys
2
2
3 from schainpy.controller import Project
3 from schainpy.controller import Project
4
4
5 if __name__ == '__main__':
5 if __name__ == '__main__':
6
6
7 desc = "Segundo Test"
7 desc = "Segundo Test"
8 filename = "schain.xml"
8 filename = "schain.xml"
9
9
10 pathW='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024'
11 figpath = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/test1024'
12
10 controllerObj = Project()
13 controllerObj = Project()
11
14
12 controllerObj.setup(id = '191', name='test01', description=desc)
15 controllerObj.setup(id='191', name='test01', description=desc)
13
16
14 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
17 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
15 path='/Volumes/SOUSY/',
18 path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/',
16 startDate='2014/10/28',
19 #path='/home/erick/Documents/Data/Claire_Data/raw',
17 endDate='2014/10/28',
20 startDate='2017/08/22',
18 startTime='15:40:00',
21 endDate='2017/08/22',
19 endTime='16:20:00',
22 startTime='01:00:00',
23 endTime='06:00:00',
20 online=0,
24 online=0,
21 walk=1)
25 walk=1)
22
26
27 opObj00 = readUnitConfObj.addOperation(name='printInfo')
28 #
29 # procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
30 # inputId=readUnitConfObj.getId())
31 #
32 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
33 # opObj10.addParameter(name='minHei', value='0', format='float')
34 # opObj10.addParameter(name='maxHei', value='8', format='float')
35 #
36 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
37 # opObj10.addParameter(name='window', value='2', format='float')
38 #
39 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
40 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
41 # opObj10.addParameter(name='nCode', value='2', format='float')
42 # opObj10.addParameter(name='nBaud', value='1', format='float')
43 #
44 #
45 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
46 # opObj10.addParameter(name='n', value='1296', format='float')
47
23 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
48 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
24
49
25 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
50 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
26 inputId=readUnitConfObj.getId())
51 inputId=readUnitConfObj.getId())
27
52
28 opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
29 opObj10.addParameter(name='minHei', value='0', format='float')
30 opObj10.addParameter(name='maxHei', value='8', format='float')
31
53
32 opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
54 opObj10 = procUnitConfObj0.addOperation(name='setRadarFrequency')
33 opObj10.addParameter(name='window', value='2', format='float')
55 opObj10.addParameter(name='frequency', value='445.09e6', format='float')
34
56
35 opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
57 #opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
36 opObj10.addParameter(name='code', value='1,-1', format='intlist')
58 #opObj10.addParameter(name='n', value='1', format='float')
37 opObj10.addParameter(name='nCode', value='2', format='float')
38 opObj10.addParameter(name='nBaud', value='1', format='float')
39
59
60 #opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
61 #opObj10.addParameter(name='minHei', value='1', format='float')
62 #opObj10.addParameter(name='maxHei', value='15', format='float')
40
63
41 opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
64 #opObj10 = procUnitConfObj0.addOperation(name='selectFFTs')
42 opObj10.addParameter(name='n', value='1296', format='float')
65 #opObj10.addParameter(name='minHei', value='', format='float')
66 #opObj10.addParameter(name='maxHei', value='', format='float')
43
67
44 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
68 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
45 inputId=procUnitConfObj0.getId())
69 inputId=procUnitConfObj0.getId())
46
70
47 #Creating a processing object with its parameters
71 # Creating a processing object with its parameters
48 #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
72 # schainpy.model.proc.jroproc_spectra.SpectraProc.run()
49 #If you need to add more parameters can use the "addParameter method"
73 # If you need to add more parameters can use the "addParameter method"
50 procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
74 procUnitConfObj1.addParameter(name='nFFTPoints', value='1024', format='int')
75
76
77 opObj10 = procUnitConfObj1.addOperation(name='removeDC')
78 #opObj10 = procUnitConfObj1.addOperation(name='removeInterference')
79 #opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
80 #opObj10.addParameter(name='n', value='30', format='float')
81
82
51
83
52 opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
84 #opObj10 = procUnitConfObj1.addOperation(name='selectFFTs')
53 opObj10.addParameter(name='n', value='2', format='float')
85 #opObj10.addParameter(name='minFFT', value='-15', format='float')
86 #opObj10.addParameter(name='maxFFT', value='15', format='float')
54
87
88
89
90 opObj10 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other')
91 opObj10.addParameter(name='blocksPerFile', value='64', format = 'int')
92 opObj10.addParameter(name='path', value=pathW)
55 #Using internal methods
93 # Using internal methods
56 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
94 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
57 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
95 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
58 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
96 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
59
97
60 #Using internal methods
98 # Using internal methods
61 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
99 # schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
62 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
100 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
63 # opObj10.addParameter(name='minHei', value='90', format='float')
101 # opObj10.addParameter(name='minHei', value='90', format='float')
64 # opObj10.addParameter(name='maxHei', value='180', format='float')
102 # opObj10.addParameter(name='maxHei', value='180', format='float')
65
103
66 #Using external methods (new modules)
104 # Using external methods (new modules)
67 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
105 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
68 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
106 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
69 # opObj12.addParameter(name='n', value='1', format='int')
107 # opObj12.addParameter(name='n', value='1', format='int')
70
108
71 #Using external methods (new modules)
109 # Using external methods (new modules)
72 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
110 # schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
73 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
111 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
74 opObj11.addParameter(name='id', value='11', format='int')
112 opObj11.addParameter(name='id', value='11', format='int')
75 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
113 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
76 opObj11.addParameter(name='zmin', value='-60', format='int')
114 opObj11.addParameter(name='xaxis', value='velocity', format='str')
77 opObj11.addParameter(name='zmax', value='10', format='int')
115 # opObj11.addParameter(name='xmin', value='-10', format='int')
78 opObj11.addParameter(name='save', value='1', format='int')
116 # opObj11.addParameter(name='xmax', value='10', format='int')
117
118 # opObj11.addParameter(name='ymin', value='1', format='float')
119 # opObj11.addParameter(name='ymax', value='3', format='int')
120 #opObj11.addParameter(name='zmin', value='10', format='int')
121 #opObj11.addParameter(name='zmax', value='35', format='int')
122 # opObj11.addParameter(name='save', value='2', format='int')
123 # opObj11.addParameter(name='save', value='5', format='int')
124 # opObj11.addParameter(name='figpath', value=figpath, format='str')
125
126
127 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
128 procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList')
129 opObj11.addParameter(name='id', value='2005', format='int')
130 #opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
131 #opObj11.addParameter(name='exp_code', value='13', format='int')
132 opObj11.addParameter(name='xaxis', value='Velocity', format='str')
133 #opObj11.addParameter(name='xmin', value='-6', format='float')
134 #opObj11.addParameter(name='xmax', value='6', format='float')
135 opObj11.addParameter(name='zmin', value='15', format='float')
136 opObj11.addParameter(name='zmax', value='50', format='float')
137 opObj11.addParameter(name='ymin', value='0', format='float')
138 opObj11.addParameter(name='ymax', value='7', format='float')
139 #opObj11.addParameter(name='phase_min', value='-4', format='int')
140 #opObj11.addParameter(name='phase_max', value='4', format='int')
141 #
79
142
80 #Using external methods (new modules)
143 # Using external methods (new modules)
81 #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
144 # schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
82 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
145 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
83 opObj11.addParameter(name='id', value='30', format='int')
146 opObj11.addParameter(name='id', value='30', format='int')
84 opObj11.addParameter(name='wintitle', value='RTI', format='str')
147 opObj11.addParameter(name='wintitle', value='RTI', format='str')
85 opObj11.addParameter(name='zmin', value='-60', format='int')
148 opObj11.addParameter(name='zmin', value='15', format='int')
86 opObj11.addParameter(name='zmax', value='-10', format='int')
149 opObj11.addParameter(name='zmax', value='40', format='int')
150 opObj11.addParameter(name='ymin', value='1', format='int')
151 opObj11.addParameter(name='ymax', value='7', format='int')
87 opObj11.addParameter(name='showprofile', value='1', format='int')
152 opObj11.addParameter(name='showprofile', value='1', format='int')
88 # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int')
153 # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int')
89 opObj11.addParameter(name='xmin', value='14', format='float')
154 opObj11.addParameter(name='xmin', value='1', format='float')
90 opObj11.addParameter(name='xmax', value='23.9', format='float')
155 opObj11.addParameter(name='xmax', value='6', format='float')
91 opObj11.addParameter(name='save', value='1', format='int')
156 opObj11.addParameter(name='save', value='1', format='int')
92
157
158
159 # '''#########################################################################################'''
160 #
161 #
162 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId())
163 # opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other')
164 #
165 # '''
166 # # Discriminacion de ecos
167 # opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other')
168 # opObj11.addParameter(name='SNRlimit', value='0', format='int')
169 # '''
170 #
171 # '''
172 # # Estimacion de Precipitacion
173 # opObj11 = procUnitConfObj2.addOperation(name='PrecipitationProc', optype='other')
174 # '''
175 #
176 # opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other')
177 #
178 # opObj22.addParameter(name='SNRlimit', value='-10', format='float')
179 # opObj22.addParameter(name='E01', value='1.500', format='float')
180 # opObj22.addParameter(name='E02', value='1.500', format='float')
181 # opObj22.addParameter(name='E12', value='0', format='float')
182 # opObj22.addParameter(name='N01', value='0.875', format='float')
183 # opObj22.addParameter(name='N02', value='-0.875', format='float')
184 # opObj22.addParameter(name='N12', value='-1.750', format='float')
185 #
186 #
187 # opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other')
188 # opObj22.addParameter(name='id', value='4', format='int')
189 # opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str')
190 # opObj22.addParameter(name='save', value='1', format='bool')
191 # opObj22.addParameter(name='xmin', value='0', format='float')
192 # opObj22.addParameter(name='xmax', value='6', format='float')
193 # opObj22.addParameter(name='ymin', value='1', format='float')
194 # opObj22.addParameter(name='ymax', value='3.5', format='float')
195 # opObj22.addParameter(name='zmin', value='-1', format='float')
196 # opObj22.addParameter(name='zmax', value='1', format='float')
197 # opObj22.addParameter(name='SNRmin', value='-15', format='float')
198 # opObj22.addParameter(name='SNRmax', value='20', format='float')
199 # opObj22.addParameter(name='zmin_ver', value='-200', format='float')
200 # opObj22.addParameter(name='zmax_ver', value='200', format='float')
201 # opObj22.addParameter(name='save', value='1', format='int')
202 # opObj22.addParameter(name='figpath', value=figpath, format='str')
203 #
204 #
205 #
206 # #opObj11.addParameter(name='zmin', value='75', format='int')
207 #
208 # #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other')
209 # #opObj12.addParameter(name='id',value='4',format='int')
210 # #opObj12.addParameter(name='wintitle',value='First_gg',format='str')
211 # '''
212 # #Ploteo de Discriminacion de Gaussianas
213 #
214 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
215 # opObj11.addParameter(name='id', value='21', format='int')
216 # opObj11.addParameter(name='wintitle', value='Rainfall Gaussian', format='str')
217 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
218 # opObj11.addParameter(name='showprofile', value='1', format='int')
219 # opObj11.addParameter(name='zmin', value='75', format='int')
220 # opObj11.addParameter(name='zmax', value='100', format='int')
221 # opObj11.addParameter(name='GauSelector', value='1', format='int')
222 # #opObj11.addParameter(name='save', value='1', format='int')
223 # #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106')
224 #
225 # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other')
226 # opObj11.addParameter(name='id', value='22', format='int')
227 # opObj11.addParameter(name='wintitle', value='Wind Gaussian', format='str')
228 # opObj11.addParameter(name='xaxis', value='velocity', format='str')
229 # opObj11.addParameter(name='showprofile', value='1', format='int')
230 # opObj11.addParameter(name='zmin', value='75', format='int')
231 # opObj11.addParameter(name='zmax', value='100', format='int')
232 # opObj11.addParameter(name='GauSelector', value='0', format='int')
233 # '''
234 #
235 #
236
237
93 controllerObj.start()
238 controllerObj.start()
General Comments 0
You need to be logged in to leave comments. Login now