##// END OF EJS Templates
The Spectra-1d Plot shows the normalized power.
Daniel Valdez -
r496:c1e2ee842644
parent child
Show More
@@ -1,725 +1,736
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
12
13 def getNumpyDtype(dataTypeCode):
13 def getNumpyDtype(dataTypeCode):
14
14
15 if dataTypeCode == 0:
15 if dataTypeCode == 0:
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
16 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
17 elif dataTypeCode == 1:
17 elif dataTypeCode == 1:
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
18 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
19 elif dataTypeCode == 2:
19 elif dataTypeCode == 2:
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
20 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
21 elif dataTypeCode == 3:
21 elif dataTypeCode == 3:
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
22 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
23 elif dataTypeCode == 4:
23 elif dataTypeCode == 4:
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
24 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
25 elif dataTypeCode == 5:
25 elif dataTypeCode == 5:
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
26 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
27 else:
27 else:
28 raise ValueError, 'dataTypeCode was not defined'
28 raise ValueError, 'dataTypeCode was not defined'
29
29
30 return numpyDtype
30 return numpyDtype
31
31
32 def getDataTypeCode(numpyDtype):
32 def getDataTypeCode(numpyDtype):
33
33
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
34 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
35 datatype = 0
35 datatype = 0
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
36 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
37 datatype = 1
37 datatype = 1
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
38 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
39 datatype = 2
39 datatype = 2
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
40 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
41 datatype = 3
41 datatype = 3
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
42 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
43 datatype = 4
43 datatype = 4
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
44 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
45 datatype = 5
45 datatype = 5
46 else:
46 else:
47 datatype = None
47 datatype = None
48
48
49 return datatype
49 return datatype
50
50
51 def hildebrand_sekhon(data, navg):
51 def hildebrand_sekhon(data, navg):
52
52
53 data = data.copy()
53 data = data.copy()
54
54
55 sortdata = numpy.sort(data,axis=None)
55 sortdata = numpy.sort(data,axis=None)
56 lenOfData = len(sortdata)
56 lenOfData = len(sortdata)
57 nums_min = lenOfData/10
57 nums_min = lenOfData/10
58
58
59 if (lenOfData/10) > 2:
59 if (lenOfData/10) > 2:
60 nums_min = lenOfData/10
60 nums_min = lenOfData/10
61 else:
61 else:
62 nums_min = 2
62 nums_min = 2
63
63
64 sump = 0.
64 sump = 0.
65
65
66 sumq = 0.
66 sumq = 0.
67
67
68 j = 0
68 j = 0
69
69
70 cont = 1
70 cont = 1
71
71
72 while((cont==1)and(j<lenOfData)):
72 while((cont==1)and(j<lenOfData)):
73
73
74 sump += sortdata[j]
74 sump += sortdata[j]
75
75
76 sumq += sortdata[j]**2
76 sumq += sortdata[j]**2
77
77
78 j += 1
78 j += 1
79
79
80 if j > nums_min:
80 if j > nums_min:
81 rtest = float(j)/(j-1) + 1.0/navg
81 rtest = float(j)/(j-1) + 1.0/navg
82 if ((sumq*j) > (rtest*sump**2)):
82 if ((sumq*j) > (rtest*sump**2)):
83 j = j - 1
83 j = j - 1
84 sump = sump - sortdata[j]
84 sump = sump - sortdata[j]
85 sumq = sumq - sortdata[j]**2
85 sumq = sumq - sortdata[j]**2
86 cont = 0
86 cont = 0
87
87
88 lnoise = sump /j
88 lnoise = sump /j
89 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
89 stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
90 return lnoise
90 return lnoise
91
91
92 class GenericData(object):
92 class GenericData(object):
93
93
94 flagNoData = True
94 flagNoData = True
95
95
96 def __init__(self):
96 def __init__(self):
97
97
98 raise ValueError, "This class has not been implemented"
98 raise ValueError, "This class has not been implemented"
99
99
100 def copy(self, inputObj=None):
100 def copy(self, inputObj=None):
101
101
102 if inputObj == None:
102 if inputObj == None:
103 return copy.deepcopy(self)
103 return copy.deepcopy(self)
104
104
105 for key in inputObj.__dict__.keys():
105 for key in inputObj.__dict__.keys():
106 self.__dict__[key] = inputObj.__dict__[key]
106 self.__dict__[key] = inputObj.__dict__[key]
107
107
108 def deepcopy(self):
108 def deepcopy(self):
109
109
110 return copy.deepcopy(self)
110 return copy.deepcopy(self)
111
111
112 def isEmpty(self):
112 def isEmpty(self):
113
113
114 return self.flagNoData
114 return self.flagNoData
115
115
116 class JROData(GenericData):
116 class JROData(GenericData):
117
117
118 # m_BasicHeader = BasicHeader()
118 # m_BasicHeader = BasicHeader()
119 # m_ProcessingHeader = ProcessingHeader()
119 # m_ProcessingHeader = ProcessingHeader()
120
120
121 systemHeaderObj = SystemHeader()
121 systemHeaderObj = SystemHeader()
122
122
123 radarControllerHeaderObj = RadarControllerHeader()
123 radarControllerHeaderObj = RadarControllerHeader()
124
124
125 # data = None
125 # data = None
126
126
127 type = None
127 type = None
128
128
129 datatype = None #dtype but in string
129 datatype = None #dtype but in string
130
130
131 # dtype = None
131 # dtype = None
132
132
133 # nChannels = None
133 # nChannels = None
134
134
135 # nHeights = None
135 # nHeights = None
136
136
137 nProfiles = None
137 nProfiles = None
138
138
139 heightList = None
139 heightList = None
140
140
141 channelList = None
141 channelList = None
142
142
143 flagTimeBlock = False
143 flagTimeBlock = False
144
144
145 useLocalTime = False
145 useLocalTime = False
146
146
147 utctime = None
147 utctime = None
148
148
149 timeZone = None
149 timeZone = None
150
150
151 dstFlag = None
151 dstFlag = None
152
152
153 errorCount = None
153 errorCount = None
154
154
155 blocksize = None
155 blocksize = None
156
156
157 nCode = None
157 nCode = None
158
158
159 nBaud = None
159 nBaud = None
160
160
161 code = None
161 code = None
162
162
163 flagDecodeData = False #asumo q la data no esta decodificada
163 flagDecodeData = False #asumo q la data no esta decodificada
164
164
165 flagDeflipData = False #asumo q la data no esta sin flip
165 flagDeflipData = False #asumo q la data no esta sin flip
166
166
167 flagShiftFFT = False
167 flagShiftFFT = False
168
168
169 # ippSeconds = None
169 # ippSeconds = None
170
170
171 timeInterval = None
171 timeInterval = None
172
172
173 nCohInt = None
173 nCohInt = None
174
174
175 noise = None
175 noise = None
176
176
177 windowOfFilter = 1
177 windowOfFilter = 1
178
178
179 #Speed of ligth
179 #Speed of ligth
180 C = 3e8
180 C = 3e8
181
181
182 frequency = 49.92e6
182 frequency = 49.92e6
183
183
184 realtime = False
184 realtime = False
185
185
186 beacon_heiIndexList = None
186 beacon_heiIndexList = None
187
187
188 last_block = None
188 last_block = None
189
189
190 blocknow = None
190 blocknow = None
191
191
192 def __init__(self):
192 def __init__(self):
193
193
194 raise ValueError, "This class has not been implemented"
194 raise ValueError, "This class has not been implemented"
195
195
196 def getNoise(self):
196 def getNoise(self):
197
197
198 raise ValueError, "Not implemented"
198 raise ValueError, "Not implemented"
199
199
200 def getNChannels(self):
200 def getNChannels(self):
201
201
202 return len(self.channelList)
202 return len(self.channelList)
203
203
204 def getChannelIndexList(self):
204 def getChannelIndexList(self):
205
205
206 return range(self.nChannels)
206 return range(self.nChannels)
207
207
208 def getNHeights(self):
208 def getNHeights(self):
209
209
210 return len(self.heightList)
210 return len(self.heightList)
211
211
212 def getHeiRange(self, extrapoints=0):
212 def getHeiRange(self, extrapoints=0):
213
213
214 heis = self.heightList
214 heis = self.heightList
215 # deltah = self.heightList[1] - self.heightList[0]
215 # deltah = self.heightList[1] - self.heightList[0]
216 #
216 #
217 # heis.append(self.heightList[-1])
217 # heis.append(self.heightList[-1])
218
218
219 return heis
219 return heis
220
220
221 def getltctime(self):
221 def getltctime(self):
222
222
223 if self.useLocalTime:
223 if self.useLocalTime:
224 return self.utctime - self.timeZone*60
224 return self.utctime - self.timeZone*60
225
225
226 return self.utctime
226 return self.utctime
227
227
228 def getDatatime(self):
228 def getDatatime(self):
229
229
230 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
230 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
231 return datatimeValue
231 return datatimeValue
232
232
233 def getTimeRange(self):
233 def getTimeRange(self):
234
234
235 datatime = []
235 datatime = []
236
236
237 datatime.append(self.ltctime)
237 datatime.append(self.ltctime)
238 datatime.append(self.ltctime + self.timeInterval)
238 datatime.append(self.ltctime + self.timeInterval)
239
239
240 datatime = numpy.array(datatime)
240 datatime = numpy.array(datatime)
241
241
242 return datatime
242 return datatime
243
243
244 def getFmax(self):
244 def getFmax(self):
245
245
246 PRF = 1./(self.ippSeconds * self.nCohInt)
246 PRF = 1./(self.ippSeconds * self.nCohInt)
247
247
248 fmax = PRF/2.
248 fmax = PRF/2.
249
249
250 return fmax
250 return fmax
251
251
252 def getVmax(self):
252 def getVmax(self):
253
253
254 _lambda = self.C/self.frequency
254 _lambda = self.C/self.frequency
255
255
256 vmax = self.getFmax() * _lambda
256 vmax = self.getFmax() * _lambda
257
257
258 return vmax
258 return vmax
259
259
260 def get_ippSeconds(self):
260 def get_ippSeconds(self):
261 '''
261 '''
262 '''
262 '''
263 return self.radarControllerHeaderObj.ippSeconds
263 return self.radarControllerHeaderObj.ippSeconds
264
264
265 def set_ippSeconds(self, ippSeconds):
265 def set_ippSeconds(self, ippSeconds):
266 '''
266 '''
267 '''
267 '''
268
268
269 self.radarControllerHeaderObj.ippSeconds = ippSeconds
269 self.radarControllerHeaderObj.ippSeconds = ippSeconds
270
270
271 return
271 return
272
272
273 def get_dtype(self):
273 def get_dtype(self):
274 '''
274 '''
275 '''
275 '''
276 return getNumpyDtype(self.datatype)
276 return getNumpyDtype(self.datatype)
277
277
278 def set_dtype(self, numpyDtype):
278 def set_dtype(self, numpyDtype):
279 '''
279 '''
280 '''
280 '''
281
281
282 self.datatype = getDataTypeCode(numpyDtype)
282 self.datatype = getDataTypeCode(numpyDtype)
283
283
284 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
284 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
285 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
285 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
286 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
286 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
287 #noise = property(getNoise, "I'm the 'nHeights' property.")
287 #noise = property(getNoise, "I'm the 'nHeights' property.")
288 datatime = property(getDatatime, "I'm the 'datatime' property")
288 datatime = property(getDatatime, "I'm the 'datatime' property")
289 ltctime = property(getltctime, "I'm the 'ltctime' property")
289 ltctime = property(getltctime, "I'm the 'ltctime' property")
290 ippSeconds = property(get_ippSeconds, set_ippSeconds)
290 ippSeconds = property(get_ippSeconds, set_ippSeconds)
291 dtype = property(get_dtype, set_dtype)
291 dtype = property(get_dtype, set_dtype)
292
292
293 class Voltage(JROData):
293 class Voltage(JROData):
294
294
295 #data es un numpy array de 2 dmensiones (canales, alturas)
295 #data es un numpy array de 2 dmensiones (canales, alturas)
296 data = None
296 data = None
297
297
298 def __init__(self):
298 def __init__(self):
299 '''
299 '''
300 Constructor
300 Constructor
301 '''
301 '''
302
302
303 self.radarControllerHeaderObj = RadarControllerHeader()
303 self.radarControllerHeaderObj = RadarControllerHeader()
304
304
305 self.systemHeaderObj = SystemHeader()
305 self.systemHeaderObj = SystemHeader()
306
306
307 self.type = "Voltage"
307 self.type = "Voltage"
308
308
309 self.data = None
309 self.data = None
310
310
311 # self.dtype = None
311 # self.dtype = None
312
312
313 # self.nChannels = 0
313 # self.nChannels = 0
314
314
315 # self.nHeights = 0
315 # self.nHeights = 0
316
316
317 self.nProfiles = None
317 self.nProfiles = None
318
318
319 self.heightList = None
319 self.heightList = None
320
320
321 self.channelList = None
321 self.channelList = None
322
322
323 # self.channelIndexList = None
323 # self.channelIndexList = None
324
324
325 self.flagNoData = True
325 self.flagNoData = True
326
326
327 self.flagTimeBlock = False
327 self.flagTimeBlock = False
328
328
329 self.utctime = None
329 self.utctime = None
330
330
331 self.timeZone = None
331 self.timeZone = None
332
332
333 self.dstFlag = None
333 self.dstFlag = None
334
334
335 self.errorCount = None
335 self.errorCount = None
336
336
337 self.nCohInt = None
337 self.nCohInt = None
338
338
339 self.blocksize = None
339 self.blocksize = None
340
340
341 self.flagDecodeData = False #asumo q la data no esta decodificada
341 self.flagDecodeData = False #asumo q la data no esta decodificada
342
342
343 self.flagDeflipData = False #asumo q la data no esta sin flip
343 self.flagDeflipData = False #asumo q la data no esta sin flip
344
344
345 self.flagShiftFFT = False
345 self.flagShiftFFT = False
346
346
347
347
348 def getNoisebyHildebrand(self):
348 def getNoisebyHildebrand(self):
349 """
349 """
350 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
350 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
351
351
352 Return:
352 Return:
353 noiselevel
353 noiselevel
354 """
354 """
355
355
356 for channel in range(self.nChannels):
356 for channel in range(self.nChannels):
357 daux = self.data_spc[channel,:,:]
357 daux = self.data_spc[channel,:,:]
358 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
358 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
359
359
360 return self.noise
360 return self.noise
361
361
362 def getNoise(self, type = 1):
362 def getNoise(self, type = 1):
363
363
364 self.noise = numpy.zeros(self.nChannels)
364 self.noise = numpy.zeros(self.nChannels)
365
365
366 if type == 1:
366 if type == 1:
367 noise = self.getNoisebyHildebrand()
367 noise = self.getNoisebyHildebrand()
368
368
369 return 10*numpy.log10(noise)
369 return 10*numpy.log10(noise)
370
370
371 noise = property(getNoise, "I'm the 'nHeights' property.")
371 noise = property(getNoise, "I'm the 'nHeights' property.")
372
372
373 class Spectra(JROData):
373 class Spectra(JROData):
374
374
375 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
375 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
376 data_spc = None
376 data_spc = None
377
377
378 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
378 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
379 data_cspc = None
379 data_cspc = None
380
380
381 #data es un numpy array de 2 dmensiones (canales, alturas)
381 #data es un numpy array de 2 dmensiones (canales, alturas)
382 data_dc = None
382 data_dc = None
383
383
384 nFFTPoints = None
384 nFFTPoints = None
385
385
386 # nPairs = None
386 # nPairs = None
387
387
388 pairsList = None
388 pairsList = None
389
389
390 nIncohInt = None
390 nIncohInt = None
391
391
392 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
392 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
393
393
394 nCohInt = None #se requiere para determinar el valor de timeInterval
394 nCohInt = None #se requiere para determinar el valor de timeInterval
395
395
396 ippFactor = None
396 ippFactor = None
397
397
398 def __init__(self):
398 def __init__(self):
399 '''
399 '''
400 Constructor
400 Constructor
401 '''
401 '''
402
402
403 self.radarControllerHeaderObj = RadarControllerHeader()
403 self.radarControllerHeaderObj = RadarControllerHeader()
404
404
405 self.systemHeaderObj = SystemHeader()
405 self.systemHeaderObj = SystemHeader()
406
406
407 self.type = "Spectra"
407 self.type = "Spectra"
408
408
409 # self.data = None
409 # self.data = None
410
410
411 # self.dtype = None
411 # self.dtype = None
412
412
413 # self.nChannels = 0
413 # self.nChannels = 0
414
414
415 # self.nHeights = 0
415 # self.nHeights = 0
416
416
417 self.nProfiles = None
417 self.nProfiles = None
418
418
419 self.heightList = None
419 self.heightList = None
420
420
421 self.channelList = None
421 self.channelList = None
422
422
423 # self.channelIndexList = None
423 # self.channelIndexList = None
424
424
425 self.pairsList = None
425 self.pairsList = None
426
426
427 self.flagNoData = True
427 self.flagNoData = True
428
428
429 self.flagTimeBlock = False
429 self.flagTimeBlock = False
430
430
431 self.utctime = None
431 self.utctime = None
432
432
433 self.nCohInt = None
433 self.nCohInt = None
434
434
435 self.nIncohInt = None
435 self.nIncohInt = None
436
436
437 self.blocksize = None
437 self.blocksize = None
438
438
439 self.nFFTPoints = None
439 self.nFFTPoints = None
440
440
441 self.wavelength = None
441 self.wavelength = None
442
442
443 self.flagDecodeData = False #asumo q la data no esta decodificada
443 self.flagDecodeData = False #asumo q la data no esta decodificada
444
444
445 self.flagDeflipData = False #asumo q la data no esta sin flip
445 self.flagDeflipData = False #asumo q la data no esta sin flip
446
446
447 self.flagShiftFFT = False
447 self.flagShiftFFT = False
448
448
449 self.ippFactor = 1
449 self.ippFactor = 1
450
450
451 #self.noise = None
451 #self.noise = None
452
452
453 self.beacon_heiIndexList = []
453 self.beacon_heiIndexList = []
454
454
455 self.noise_estimation = None
455 self.noise_estimation = None
456
456
457
457
458 def getNoisebyHildebrand(self):
458 def getNoisebyHildebrand(self):
459 """
459 """
460 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
460 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
461
461
462 Return:
462 Return:
463 noiselevel
463 noiselevel
464 """
464 """
465
465
466 noise = numpy.zeros(self.nChannels)
466 noise = numpy.zeros(self.nChannels)
467 for channel in range(self.nChannels):
467 for channel in range(self.nChannels):
468 daux = self.data_spc[channel,:,:]
468 daux = self.data_spc[channel,:,:]
469 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
469 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
470
470
471 return noise
471 return noise
472
472
473 def getNoise(self):
473 def getNoise(self):
474 if self.noise_estimation != None:
474 if self.noise_estimation != None:
475 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
475 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
476 else:
476 else:
477 noise = self.getNoisebyHildebrand()
477 noise = self.getNoisebyHildebrand()
478 return noise
478 return noise
479
479
480
480
481 def getFreqRange(self, extrapoints=0):
481 def getFreqRange(self, extrapoints=0):
482
482
483 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
483 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
484 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
484 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
485
485
486 return freqrange
486 return freqrange
487
487
488 def getVelRange(self, extrapoints=0):
488 def getVelRange(self, extrapoints=0):
489
489
490 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
490 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
491 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
491 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
492
492
493 return velrange
493 return velrange
494
494
495 def getNPairs(self):
495 def getNPairs(self):
496
496
497 return len(self.pairsList)
497 return len(self.pairsList)
498
498
499 def getPairsIndexList(self):
499 def getPairsIndexList(self):
500
500
501 return range(self.nPairs)
501 return range(self.nPairs)
502
502
503 def getNormFactor(self):
503 def getNormFactor(self):
504 pwcode = 1
504 pwcode = 1
505 if self.flagDecodeData:
505 if self.flagDecodeData:
506 pwcode = numpy.sum(self.code[0]**2)
506 pwcode = numpy.sum(self.code[0]**2)
507 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
507 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
508 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
508 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
509
509
510 return normFactor
510 return normFactor
511
511
512 def getFlagCspc(self):
512 def getFlagCspc(self):
513
513
514 if self.data_cspc == None:
514 if self.data_cspc == None:
515 return True
515 return True
516
516
517 return False
517 return False
518
518
519 def getFlagDc(self):
519 def getFlagDc(self):
520
520
521 if self.data_dc == None:
521 if self.data_dc == None:
522 return True
522 return True
523
523
524 return False
524 return False
525
525
526 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
526 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
527 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
527 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
528 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
528 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
529 flag_cspc = property(getFlagCspc)
529 flag_cspc = property(getFlagCspc)
530 flag_dc = property(getFlagDc)
530 flag_dc = property(getFlagDc)
531 noise = property(getNoise, "I'm the 'nHeights' property.")
531 noise = property(getNoise, "I'm the 'nHeights' property.")
532
532
533 class SpectraHeis(Spectra):
533 class SpectraHeis(Spectra):
534
534
535 data_spc = None
535 data_spc = None
536
536
537 data_cspc = None
537 data_cspc = None
538
538
539 data_dc = None
539 data_dc = None
540
540
541 nFFTPoints = None
541 nFFTPoints = None
542
542
543 # nPairs = None
543 # nPairs = None
544
544
545 pairsList = None
545 pairsList = None
546
546
547 nIncohInt = None
547 nIncohInt = None
548
548
549 def __init__(self):
549 def __init__(self):
550
550
551 self.radarControllerHeaderObj = RadarControllerHeader()
551 self.radarControllerHeaderObj = RadarControllerHeader()
552
552
553 self.systemHeaderObj = SystemHeader()
553 self.systemHeaderObj = SystemHeader()
554
554
555 self.type = "SpectraHeis"
555 self.type = "SpectraHeis"
556
556
557 # self.dtype = None
557 # self.dtype = None
558
558
559 # self.nChannels = 0
559 # self.nChannels = 0
560
560
561 # self.nHeights = 0
561 # self.nHeights = 0
562
562
563 self.nProfiles = None
563 self.nProfiles = None
564
564
565 self.heightList = None
565 self.heightList = None
566
566
567 self.channelList = None
567 self.channelList = None
568
568
569 # self.channelIndexList = None
569 # self.channelIndexList = None
570
570
571 self.flagNoData = True
571 self.flagNoData = True
572
572
573 self.flagTimeBlock = False
573 self.flagTimeBlock = False
574
574
575 # self.nPairs = 0
575 # self.nPairs = 0
576
576
577 self.utctime = None
577 self.utctime = None
578
578
579 self.blocksize = None
579 self.blocksize = None
580
581 def getNormFactor(self):
582 pwcode = 1
583 if self.flagDecodeData:
584 pwcode = numpy.sum(self.code[0]**2)
585
586 normFactor = self.nIncohInt*self.nCohInt*pwcode
587
588 return normFactor
589
590 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
580
591
581 class Fits:
592 class Fits:
582
593
583 heightList = None
594 heightList = None
584
595
585 channelList = None
596 channelList = None
586
597
587 flagNoData = True
598 flagNoData = True
588
599
589 flagTimeBlock = False
600 flagTimeBlock = False
590
601
591 useLocalTime = False
602 useLocalTime = False
592
603
593 utctime = None
604 utctime = None
594
605
595 timeZone = None
606 timeZone = None
596
607
597 # ippSeconds = None
608 # ippSeconds = None
598
609
599 timeInterval = None
610 timeInterval = None
600
611
601 nCohInt = None
612 nCohInt = None
602
613
603 nIncohInt = None
614 nIncohInt = None
604
615
605 noise = None
616 noise = None
606
617
607 windowOfFilter = 1
618 windowOfFilter = 1
608
619
609 #Speed of ligth
620 #Speed of ligth
610 C = 3e8
621 C = 3e8
611
622
612 frequency = 49.92e6
623 frequency = 49.92e6
613
624
614 realtime = False
625 realtime = False
615
626
616
627
617 def __init__(self):
628 def __init__(self):
618
629
619 self.type = "Fits"
630 self.type = "Fits"
620
631
621 self.nProfiles = None
632 self.nProfiles = None
622
633
623 self.heightList = None
634 self.heightList = None
624
635
625 self.channelList = None
636 self.channelList = None
626
637
627 # self.channelIndexList = None
638 # self.channelIndexList = None
628
639
629 self.flagNoData = True
640 self.flagNoData = True
630
641
631 self.utctime = None
642 self.utctime = None
632
643
633 self.nCohInt = None
644 self.nCohInt = None
634
645
635 self.nIncohInt = None
646 self.nIncohInt = None
636
647
637 self.useLocalTime = True
648 self.useLocalTime = True
638
649
639 # self.utctime = None
650 # self.utctime = None
640 # self.timeZone = None
651 # self.timeZone = None
641 # self.ltctime = None
652 # self.ltctime = None
642 # self.timeInterval = None
653 # self.timeInterval = None
643 # self.header = None
654 # self.header = None
644 # self.data_header = None
655 # self.data_header = None
645 # self.data = None
656 # self.data = None
646 # self.datatime = None
657 # self.datatime = None
647 # self.flagNoData = False
658 # self.flagNoData = False
648 # self.expName = ''
659 # self.expName = ''
649 # self.nChannels = None
660 # self.nChannels = None
650 # self.nSamples = None
661 # self.nSamples = None
651 # self.dataBlocksPerFile = None
662 # self.dataBlocksPerFile = None
652 # self.comments = ''
663 # self.comments = ''
653 #
664 #
654
665
655
666
656 def getltctime(self):
667 def getltctime(self):
657
668
658 if self.useLocalTime:
669 if self.useLocalTime:
659 return self.utctime - self.timeZone*60
670 return self.utctime - self.timeZone*60
660
671
661 return self.utctime
672 return self.utctime
662
673
663 def getDatatime(self):
674 def getDatatime(self):
664
675
665 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
676 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
666 return datatime
677 return datatime
667
678
668 def getTimeRange(self):
679 def getTimeRange(self):
669
680
670 datatime = []
681 datatime = []
671
682
672 datatime.append(self.ltctime)
683 datatime.append(self.ltctime)
673 datatime.append(self.ltctime + self.timeInterval)
684 datatime.append(self.ltctime + self.timeInterval)
674
685
675 datatime = numpy.array(datatime)
686 datatime = numpy.array(datatime)
676
687
677 return datatime
688 return datatime
678
689
679 def getHeiRange(self):
690 def getHeiRange(self):
680
691
681 heis = self.heightList
692 heis = self.heightList
682
693
683 return heis
694 return heis
684
695
685 def isEmpty(self):
696 def isEmpty(self):
686
697
687 return self.flagNoData
698 return self.flagNoData
688
699
689 def getNHeights(self):
700 def getNHeights(self):
690
701
691 return len(self.heightList)
702 return len(self.heightList)
692
703
693 def getNChannels(self):
704 def getNChannels(self):
694
705
695 return len(self.channelList)
706 return len(self.channelList)
696
707
697 def getChannelIndexList(self):
708 def getChannelIndexList(self):
698
709
699 return range(self.nChannels)
710 return range(self.nChannels)
700
711
701 def getNoise(self, type = 1):
712 def getNoise(self, type = 1):
702
713
703 self.noise = numpy.zeros(self.nChannels)
714 self.noise = numpy.zeros(self.nChannels)
704
715
705 if type == 1:
716 if type == 1:
706 noise = self.getNoisebyHildebrand()
717 noise = self.getNoisebyHildebrand()
707
718
708 if type == 2:
719 if type == 2:
709 noise = self.getNoisebySort()
720 noise = self.getNoisebySort()
710
721
711 if type == 3:
722 if type == 3:
712 noise = self.getNoisebyWindow()
723 noise = self.getNoisebyWindow()
713
724
714 return noise
725 return noise
715
726
716 datatime = property(getDatatime, "I'm the 'datatime' property")
727 datatime = property(getDatatime, "I'm the 'datatime' property")
717 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
728 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
718 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
729 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
719 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
730 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
720 noise = property(getNoise, "I'm the 'nHeights' property.")
731 noise = property(getNoise, "I'm the 'nHeights' property.")
721 datatime = property(getDatatime, "I'm the 'datatime' property")
732 datatime = property(getDatatime, "I'm the 'datatime' property")
722 ltctime = property(getltctime, "I'm the 'ltctime' property")
733 ltctime = property(getltctime, "I'm the 'ltctime' property")
723
734
724 ltctime = property(getltctime, "I'm the 'ltctime' property")
735 ltctime = property(getltctime, "I'm the 'ltctime' property")
725
736
@@ -1,324 +1,326
1 '''
1 '''
2
2
3 @author: Daniel Suarez
3 @author: Daniel Suarez
4 '''
4 '''
5
5
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime
10 from figure import Figure, isRealtime
11
11
12 class SpectraHeisScope(Figure):
12 class SpectraHeisScope(Figure):
13
13
14
14
15 isConfig = None
15 isConfig = None
16 __nsubplots = None
16 __nsubplots = None
17
17
18 WIDTHPROF = None
18 WIDTHPROF = None
19 HEIGHTPROF = None
19 HEIGHTPROF = None
20 PREFIX = 'spc'
20 PREFIX = 'spc'
21
21
22 def __init__(self):
22 def __init__(self):
23
23
24 self.isConfig = False
24 self.isConfig = False
25 self.__nsubplots = 1
25 self.__nsubplots = 1
26
26
27 self.WIDTH = 230
27 self.WIDTH = 230
28 self.HEIGHT = 250
28 self.HEIGHT = 250
29 self.WIDTHPROF = 120
29 self.WIDTHPROF = 120
30 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
31 self.counter_imagwr = 0
31 self.counter_imagwr = 0
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, show):
40 def setup(self, id, nplots, wintitle, show):
41
41
42 showprofile = False
42 showprofile = False
43 self.__showprofile = showprofile
43 self.__showprofile = showprofile
44 self.nplots = nplots
44 self.nplots = nplots
45
45
46 ncolspan = 1
46 ncolspan = 1
47 colspan = 1
47 colspan = 1
48 if showprofile:
48 if showprofile:
49 ncolspan = 3
49 ncolspan = 3
50 colspan = 2
50 colspan = 2
51 self.__nsubplots = 2
51 self.__nsubplots = 2
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show = show)
57 show = show)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64
64
65 if counter >= self.nplots:
65 if counter >= self.nplots:
66 break
66 break
67
67
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69
69
70 if showprofile:
70 if showprofile:
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72
72
73 counter += 1
73 counter += 1
74
74
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None,
76 def run(self, dataOut, id, wintitle="", channelList=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
77 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
78 figpath='', figfile=None, ftp=False, wr_period=1, show=True,
79 server=None, folder=None, username=None, password=None):
79 server=None, folder=None, username=None, password=None):
80
80
81 """
81 """
82
82
83 Input:
83 Input:
84 dataOut :
84 dataOut :
85 id :
85 id :
86 wintitle :
86 wintitle :
87 channelList :
87 channelList :
88 xmin : None,
88 xmin : None,
89 xmax : None,
89 xmax : None,
90 ymin : None,
90 ymin : None,
91 ymax : None,
91 ymax : None,
92 """
92 """
93
93
94 if dataOut.realtime:
94 if dataOut.realtime:
95 if not(isRealtime(utcdatatime = dataOut.utctime)):
95 if not(isRealtime(utcdatatime = dataOut.utctime)):
96 print 'Skipping this plot function'
96 print 'Skipping this plot function'
97 return
97 return
98
98
99 if channelList == None:
99 if channelList == None:
100 channelIndexList = dataOut.channelIndexList
100 channelIndexList = dataOut.channelIndexList
101 else:
101 else:
102 channelIndexList = []
102 channelIndexList = []
103 for channel in channelList:
103 for channel in channelList:
104 if channel not in dataOut.channelList:
104 if channel not in dataOut.channelList:
105 raise ValueError, "Channel %d is not in dataOut.channelList"
105 raise ValueError, "Channel %d is not in dataOut.channelList"
106 channelIndexList.append(dataOut.channelList.index(channel))
106 channelIndexList.append(dataOut.channelList.index(channel))
107
107
108 # x = dataOut.heightList
108 # x = dataOut.heightList
109 c = 3E8
109 c = 3E8
110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
110 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
111 #deberia cambiar para el caso de 1Mhz y 100KHz
111 #deberia cambiar para el caso de 1Mhz y 100KHz
112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
112 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
113 #para 1Mhz descomentar la siguiente linea
113 #para 1Mhz descomentar la siguiente linea
114 #x= x/(10000.0)
114 #x= x/(10000.0)
115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
115 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
116 # y = y.real
116 # y = y.real
117 datadB = 10.*numpy.log10(dataOut.data_spc)
117 factor = dataOut.normFactor
118 data = dataOut.data_spc / factor
119 datadB = 10.*numpy.log10(data)
118 y = datadB
120 y = datadB
119
121
120 #thisDatetime = dataOut.datatime
122 #thisDatetime = dataOut.datatime
121 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
123 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
122 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
124 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
123 xlabel = ""
125 xlabel = ""
124 #para 1Mhz descomentar la siguiente linea
126 #para 1Mhz descomentar la siguiente linea
125 #xlabel = "Frequency x 10000"
127 #xlabel = "Frequency x 10000"
126 ylabel = "Intensity (dB)"
128 ylabel = "Intensity (dB)"
127
129
128 if not self.isConfig:
130 if not self.isConfig:
129 nplots = len(channelIndexList)
131 nplots = len(channelIndexList)
130
132
131 self.setup(id=id,
133 self.setup(id=id,
132 nplots=nplots,
134 nplots=nplots,
133 wintitle=wintitle,
135 wintitle=wintitle,
134 show=show)
136 show=show)
135
137
136 if xmin == None: xmin = numpy.nanmin(x)
138 if xmin == None: xmin = numpy.nanmin(x)
137 if xmax == None: xmax = numpy.nanmax(x)
139 if xmax == None: xmax = numpy.nanmax(x)
138 if ymin == None: ymin = numpy.nanmin(y)
140 if ymin == None: ymin = numpy.nanmin(y)
139 if ymax == None: ymax = numpy.nanmax(y)
141 if ymax == None: ymax = numpy.nanmax(y)
140
142
141 self.isConfig = True
143 self.isConfig = True
142
144
143 self.setWinTitle(title)
145 self.setWinTitle(title)
144
146
145 for i in range(len(self.axesList)):
147 for i in range(len(self.axesList)):
146 ychannel = y[i,:]
148 ychannel = y[i,:]
147 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
149 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
148 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
150 title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime)
149 axes = self.axesList[i]
151 axes = self.axesList[i]
150 axes.pline(x, ychannel,
152 axes.pline(x, ychannel,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
153 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
152 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
154 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
153
155
154
156
155 self.draw()
157 self.draw()
156
158
157 if figfile == None:
159 if figfile == None:
158 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
160 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
159 figfile = self.getFilename(name = str_datetime)
161 figfile = self.getFilename(name = str_datetime)
160
162
161 if figpath != '':
163 if figpath != '':
162 self.counter_imagwr += 1
164 self.counter_imagwr += 1
163 if (self.counter_imagwr>=wr_period):
165 if (self.counter_imagwr>=wr_period):
164 # store png plot to local folder
166 # store png plot to local folder
165 self.saveFigure(figpath, figfile)
167 self.saveFigure(figpath, figfile)
166 # store png plot to FTP server according to RT-Web format
168 # store png plot to FTP server according to RT-Web format
167 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
169 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
168 #ftp_filename = os.path.join(figpath, name)
170 #ftp_filename = os.path.join(figpath, name)
169 #self.saveFigure(figpath, ftp_filename)
171 #self.saveFigure(figpath, ftp_filename)
170 self.counter_imagwr = 0
172 self.counter_imagwr = 0
171
173
172 class RTIfromSpectraHeis(Figure):
174 class RTIfromSpectraHeis(Figure):
173
175
174 isConfig = None
176 isConfig = None
175 __nsubplots = None
177 __nsubplots = None
176
178
177 PREFIX = 'rtinoise'
179 PREFIX = 'rtinoise'
178
180
179 def __init__(self):
181 def __init__(self):
180
182
181 self.timerange = 24*60*60
183 self.timerange = 24*60*60
182 self.isConfig = False
184 self.isConfig = False
183 self.__nsubplots = 1
185 self.__nsubplots = 1
184
186
185 self.WIDTH = 820
187 self.WIDTH = 820
186 self.HEIGHT = 200
188 self.HEIGHT = 200
187 self.WIDTHPROF = 120
189 self.WIDTHPROF = 120
188 self.HEIGHTPROF = 0
190 self.HEIGHTPROF = 0
189 self.counter_imagwr = 0
191 self.counter_imagwr = 0
190 self.xdata = None
192 self.xdata = None
191 self.ydata = None
193 self.ydata = None
192 self.figfile = None
194 self.figfile = None
193
195
194 def getSubplots(self):
196 def getSubplots(self):
195
197
196 ncol = 1
198 ncol = 1
197 nrow = 1
199 nrow = 1
198
200
199 return nrow, ncol
201 return nrow, ncol
200
202
201 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
203 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
202
204
203 self.__showprofile = showprofile
205 self.__showprofile = showprofile
204 self.nplots = nplots
206 self.nplots = nplots
205
207
206 ncolspan = 7
208 ncolspan = 7
207 colspan = 6
209 colspan = 6
208 self.__nsubplots = 2
210 self.__nsubplots = 2
209
211
210 self.createFigure(id = id,
212 self.createFigure(id = id,
211 wintitle = wintitle,
213 wintitle = wintitle,
212 widthplot = self.WIDTH+self.WIDTHPROF,
214 widthplot = self.WIDTH+self.WIDTHPROF,
213 heightplot = self.HEIGHT+self.HEIGHTPROF,
215 heightplot = self.HEIGHT+self.HEIGHTPROF,
214 show = show)
216 show = show)
215
217
216 nrow, ncol = self.getSubplots()
218 nrow, ncol = self.getSubplots()
217
219
218 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
220 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
219
221
220
222
221 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
223 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
222 xmin=None, xmax=None, ymin=None, ymax=None,
224 xmin=None, xmax=None, ymin=None, ymax=None,
223 timerange=None,
225 timerange=None,
224 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
226 save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True,
225 server=None, folder=None, username=None, password=None):
227 server=None, folder=None, username=None, password=None):
226
228
227 if channelList == None:
229 if channelList == None:
228 channelIndexList = dataOut.channelIndexList
230 channelIndexList = dataOut.channelIndexList
229 channelList = dataOut.channelList
231 channelList = dataOut.channelList
230 else:
232 else:
231 channelIndexList = []
233 channelIndexList = []
232 for channel in channelList:
234 for channel in channelList:
233 if channel not in dataOut.channelList:
235 if channel not in dataOut.channelList:
234 raise ValueError, "Channel %d is not in dataOut.channelList"
236 raise ValueError, "Channel %d is not in dataOut.channelList"
235 channelIndexList.append(dataOut.channelList.index(channel))
237 channelIndexList.append(dataOut.channelList.index(channel))
236
238
237 if timerange != None:
239 if timerange != None:
238 self.timerange = timerange
240 self.timerange = timerange
239
241
240 tmin = None
242 tmin = None
241 tmax = None
243 tmax = None
242 x = dataOut.getTimeRange()
244 x = dataOut.getTimeRange()
243 y = dataOut.getHeiRange()
245 y = dataOut.getHeiRange()
244
246
245
247
246 data = dataOut.data_spc
248 data = dataOut.data_spc
247 data = numpy.average(data,axis=1)
249 data = numpy.average(data,axis=1)
248 datadB = 10*numpy.log10(data)
250 datadB = 10*numpy.log10(data)
249
251
250 # factor = dataOut.normFactor
252 # factor = dataOut.normFactor
251 # noise = dataOut.getNoise()/factor
253 # noise = dataOut.getNoise()/factor
252 # noisedB = 10*numpy.log10(noise)
254 # noisedB = 10*numpy.log10(noise)
253
255
254 #thisDatetime = dataOut.datatime
256 #thisDatetime = dataOut.datatime
255 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
257 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
256 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
258 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
257 xlabel = "Local Time"
259 xlabel = "Local Time"
258 ylabel = "Intensity (dB)"
260 ylabel = "Intensity (dB)"
259
261
260 if not self.isConfig:
262 if not self.isConfig:
261
263
262 nplots = 1
264 nplots = 1
263
265
264 self.setup(id=id,
266 self.setup(id=id,
265 nplots=nplots,
267 nplots=nplots,
266 wintitle=wintitle,
268 wintitle=wintitle,
267 showprofile=showprofile,
269 showprofile=showprofile,
268 show=show)
270 show=show)
269
271
270 tmin, tmax = self.getTimeLim(x, xmin, xmax)
272 tmin, tmax = self.getTimeLim(x, xmin, xmax)
271 if ymin == None: ymin = numpy.nanmin(datadB)
273 if ymin == None: ymin = numpy.nanmin(datadB)
272 if ymax == None: ymax = numpy.nanmax(datadB)
274 if ymax == None: ymax = numpy.nanmax(datadB)
273
275
274 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
276 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
275 self.isConfig = True
277 self.isConfig = True
276 self.figfile = figfile
278 self.figfile = figfile
277 self.xdata = numpy.array([])
279 self.xdata = numpy.array([])
278 self.ydata = numpy.array([])
280 self.ydata = numpy.array([])
279
281
280 self.setWinTitle(title)
282 self.setWinTitle(title)
281
283
282
284
283 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
285 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
284 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
286 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
285
287
286 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
288 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
287 axes = self.axesList[0]
289 axes = self.axesList[0]
288
290
289 self.xdata = numpy.hstack((self.xdata, x[0:1]))
291 self.xdata = numpy.hstack((self.xdata, x[0:1]))
290
292
291 if len(self.ydata)==0:
293 if len(self.ydata)==0:
292 self.ydata = datadB[channelIndexList].reshape(-1,1)
294 self.ydata = datadB[channelIndexList].reshape(-1,1)
293 else:
295 else:
294 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
296 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
295
297
296
298
297 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
299 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
298 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
300 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
299 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
301 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
300 XAxisAsTime=True
302 XAxisAsTime=True
301 )
303 )
302
304
303 self.draw()
305 self.draw()
304
306
305 if x[1] >= self.axesList[0].xmax:
307 if x[1] >= self.axesList[0].xmax:
306 self.counter_imagwr = wr_period
308 self.counter_imagwr = wr_period
307 del self.xdata
309 del self.xdata
308 del self.ydata
310 del self.ydata
309 self.__isConfig = False
311 self.__isConfig = False
310
312
311 if self.figfile == None:
313 if self.figfile == None:
312 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
314 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
313 self.figfile = self.getFilename(name = str_datetime)
315 self.figfile = self.getFilename(name = str_datetime)
314
316
315 if figpath != '':
317 if figpath != '':
316 self.counter_imagwr += 1
318 self.counter_imagwr += 1
317 if (self.counter_imagwr>=wr_period):
319 if (self.counter_imagwr>=wr_period):
318 # store png plot to local folder
320 # store png plot to local folder
319 self.saveFigure(figpath, self.figfile)
321 self.saveFigure(figpath, self.figfile)
320 # store png plot to FTP server according to RT-Web format
322 # store png plot to FTP server according to RT-Web format
321 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
323 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
322 #ftp_filename = os.path.join(figpath, name)
324 #ftp_filename = os.path.join(figpath, name)
323 #self.saveFigure(figpath, ftp_filename)
325 #self.saveFigure(figpath, ftp_filename)
324 self.counter_imagwr = 0
326 self.counter_imagwr = 0
General Comments 0
You need to be logged in to leave comments. Login now