##// END OF EJS Templates
jrodata.py: plotting attribute added to SpectraData
Miguel Valdez -
r773:45e0100d584a
parent child
Show More
@@ -1,1165 +1,1167
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 This method is for the objective determination of the noise level in Doppler spectra. This
53 This method is for the objective determination of the noise level in Doppler spectra. This
54 implementation technique is based on the fact that the standard deviation of the spectral
54 implementation technique is based on the fact that the standard deviation of the spectral
55 densities is equal to the mean spectral density for white Gaussian noise
55 densities is equal to the mean spectral density for white Gaussian noise
56
56
57 Inputs:
57 Inputs:
58 Data : heights
58 Data : heights
59 navg : numbers of averages
59 navg : numbers of averages
60
60
61 Return:
61 Return:
62 -1 : any error
62 -1 : any error
63 anoise : noise's level
63 anoise : noise's level
64 """
64 """
65
65
66 sortdata = numpy.sort(data,axis=None)
66 sortdata = numpy.sort(data,axis=None)
67 lenOfData = len(sortdata)
67 lenOfData = len(sortdata)
68 nums_min = lenOfData*0.2
68 nums_min = lenOfData*0.2
69
69
70 if nums_min <= 5:
70 if nums_min <= 5:
71 nums_min = 5
71 nums_min = 5
72
72
73 sump = 0.
73 sump = 0.
74
74
75 sumq = 0.
75 sumq = 0.
76
76
77 j = 0
77 j = 0
78
78
79 cont = 1
79 cont = 1
80
80
81 while((cont==1)and(j<lenOfData)):
81 while((cont==1)and(j<lenOfData)):
82
82
83 sump += sortdata[j]
83 sump += sortdata[j]
84
84
85 sumq += sortdata[j]**2
85 sumq += sortdata[j]**2
86
86
87 if j > nums_min:
87 if j > nums_min:
88 rtest = float(j)/(j-1) + 1.0/navg
88 rtest = float(j)/(j-1) + 1.0/navg
89 if ((sumq*j) > (rtest*sump**2)):
89 if ((sumq*j) > (rtest*sump**2)):
90 j = j - 1
90 j = j - 1
91 sump = sump - sortdata[j]
91 sump = sump - sortdata[j]
92 sumq = sumq - sortdata[j]**2
92 sumq = sumq - sortdata[j]**2
93 cont = 0
93 cont = 0
94
94
95 j += 1
95 j += 1
96
96
97 lnoise = sump /j
97 lnoise = sump /j
98 # stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
98 # stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1))
99 return lnoise
99 return lnoise
100
100
101 class Beam:
101 class Beam:
102 def __init__(self):
102 def __init__(self):
103 self.codeList = []
103 self.codeList = []
104 self.azimuthList = []
104 self.azimuthList = []
105 self.zenithList = []
105 self.zenithList = []
106
106
107 class GenericData(object):
107 class GenericData(object):
108
108
109 flagNoData = True
109 flagNoData = True
110
110
111 def __init__(self):
111 def __init__(self):
112
112
113 raise NotImplementedError
113 raise NotImplementedError
114
114
115 def copy(self, inputObj=None):
115 def copy(self, inputObj=None):
116
116
117 if inputObj == None:
117 if inputObj == None:
118 return copy.deepcopy(self)
118 return copy.deepcopy(self)
119
119
120 for key in inputObj.__dict__.keys():
120 for key in inputObj.__dict__.keys():
121
121
122 attribute = inputObj.__dict__[key]
122 attribute = inputObj.__dict__[key]
123
123
124 #If this attribute is a tuple or list
124 #If this attribute is a tuple or list
125 if type(inputObj.__dict__[key]) in (tuple, list):
125 if type(inputObj.__dict__[key]) in (tuple, list):
126 self.__dict__[key] = attribute[:]
126 self.__dict__[key] = attribute[:]
127 continue
127 continue
128
128
129 #If this attribute is another object or instance
129 #If this attribute is another object or instance
130 if hasattr(attribute, '__dict__'):
130 if hasattr(attribute, '__dict__'):
131 self.__dict__[key] = attribute.copy()
131 self.__dict__[key] = attribute.copy()
132 continue
132 continue
133
133
134 self.__dict__[key] = inputObj.__dict__[key]
134 self.__dict__[key] = inputObj.__dict__[key]
135
135
136 def deepcopy(self):
136 def deepcopy(self):
137
137
138 return copy.deepcopy(self)
138 return copy.deepcopy(self)
139
139
140 def isEmpty(self):
140 def isEmpty(self):
141
141
142 return self.flagNoData
142 return self.flagNoData
143
143
144 class JROData(GenericData):
144 class JROData(GenericData):
145
145
146 # m_BasicHeader = BasicHeader()
146 # m_BasicHeader = BasicHeader()
147 # m_ProcessingHeader = ProcessingHeader()
147 # m_ProcessingHeader = ProcessingHeader()
148
148
149 systemHeaderObj = SystemHeader()
149 systemHeaderObj = SystemHeader()
150
150
151 radarControllerHeaderObj = RadarControllerHeader()
151 radarControllerHeaderObj = RadarControllerHeader()
152
152
153 # data = None
153 # data = None
154
154
155 type = None
155 type = None
156
156
157 datatype = None #dtype but in string
157 datatype = None #dtype but in string
158
158
159 # dtype = None
159 # dtype = None
160
160
161 # nChannels = None
161 # nChannels = None
162
162
163 # nHeights = None
163 # nHeights = None
164
164
165 nProfiles = None
165 nProfiles = None
166
166
167 heightList = None
167 heightList = None
168
168
169 channelList = None
169 channelList = None
170
170
171 flagDiscontinuousBlock = False
171 flagDiscontinuousBlock = False
172
172
173 useLocalTime = False
173 useLocalTime = False
174
174
175 utctime = None
175 utctime = None
176
176
177 timeZone = None
177 timeZone = None
178
178
179 dstFlag = None
179 dstFlag = None
180
180
181 errorCount = None
181 errorCount = None
182
182
183 blocksize = None
183 blocksize = None
184
184
185 # nCode = None
185 # nCode = None
186 #
186 #
187 # nBaud = None
187 # nBaud = None
188 #
188 #
189 # code = None
189 # code = None
190
190
191 flagDecodeData = False #asumo q la data no esta decodificada
191 flagDecodeData = False #asumo q la data no esta decodificada
192
192
193 flagDeflipData = False #asumo q la data no esta sin flip
193 flagDeflipData = False #asumo q la data no esta sin flip
194
194
195 flagShiftFFT = False
195 flagShiftFFT = False
196
196
197 # ippSeconds = None
197 # ippSeconds = None
198
198
199 # timeInterval = None
199 # timeInterval = None
200
200
201 nCohInt = None
201 nCohInt = None
202
202
203 # noise = None
203 # noise = None
204
204
205 windowOfFilter = 1
205 windowOfFilter = 1
206
206
207 #Speed of ligth
207 #Speed of ligth
208 C = 3e8
208 C = 3e8
209
209
210 frequency = 49.92e6
210 frequency = 49.92e6
211
211
212 realtime = False
212 realtime = False
213
213
214 beacon_heiIndexList = None
214 beacon_heiIndexList = None
215
215
216 last_block = None
216 last_block = None
217
217
218 blocknow = None
218 blocknow = None
219
219
220 azimuth = None
220 azimuth = None
221
221
222 zenith = None
222 zenith = None
223
223
224 beam = Beam()
224 beam = Beam()
225
225
226 profileIndex = None
226 profileIndex = None
227
227
228 def __init__(self):
228 def __init__(self):
229
229
230 raise NotImplementedError
230 raise NotImplementedError
231
231
232 def getNoise(self):
232 def getNoise(self):
233
233
234 raise NotImplementedError
234 raise NotImplementedError
235
235
236 def getNChannels(self):
236 def getNChannels(self):
237
237
238 return len(self.channelList)
238 return len(self.channelList)
239
239
240 def getChannelIndexList(self):
240 def getChannelIndexList(self):
241
241
242 return range(self.nChannels)
242 return range(self.nChannels)
243
243
244 def getNHeights(self):
244 def getNHeights(self):
245
245
246 return len(self.heightList)
246 return len(self.heightList)
247
247
248 def getHeiRange(self, extrapoints=0):
248 def getHeiRange(self, extrapoints=0):
249
249
250 heis = self.heightList
250 heis = self.heightList
251 # deltah = self.heightList[1] - self.heightList[0]
251 # deltah = self.heightList[1] - self.heightList[0]
252 #
252 #
253 # heis.append(self.heightList[-1])
253 # heis.append(self.heightList[-1])
254
254
255 return heis
255 return heis
256
256
257 def getDeltaH(self):
257 def getDeltaH(self):
258
258
259 delta = self.heightList[1] - self.heightList[0]
259 delta = self.heightList[1] - self.heightList[0]
260
260
261 return delta
261 return delta
262
262
263 def getltctime(self):
263 def getltctime(self):
264
264
265 if self.useLocalTime:
265 if self.useLocalTime:
266 return self.utctime - self.timeZone*60
266 return self.utctime - self.timeZone*60
267
267
268 return self.utctime
268 return self.utctime
269
269
270 def getDatatime(self):
270 def getDatatime(self):
271
271
272 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
272 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
273 return datatimeValue
273 return datatimeValue
274
274
275 def getTimeRange(self):
275 def getTimeRange(self):
276
276
277 datatime = []
277 datatime = []
278
278
279 datatime.append(self.ltctime)
279 datatime.append(self.ltctime)
280 datatime.append(self.ltctime + self.timeInterval+60)
280 datatime.append(self.ltctime + self.timeInterval+60)
281
281
282 datatime = numpy.array(datatime)
282 datatime = numpy.array(datatime)
283
283
284 return datatime
284 return datatime
285
285
286 def getFmaxTimeResponse(self):
286 def getFmaxTimeResponse(self):
287
287
288 period = (10**-6)*self.getDeltaH()/(0.15)
288 period = (10**-6)*self.getDeltaH()/(0.15)
289
289
290 PRF = 1./(period * self.nCohInt)
290 PRF = 1./(period * self.nCohInt)
291
291
292 fmax = PRF
292 fmax = PRF
293
293
294 return fmax
294 return fmax
295
295
296 def getFmax(self):
296 def getFmax(self):
297
297
298 PRF = 1./(self.ippSeconds * self.nCohInt)
298 PRF = 1./(self.ippSeconds * self.nCohInt)
299
299
300 fmax = PRF
300 fmax = PRF
301
301
302 return fmax
302 return fmax
303
303
304 def getVmax(self):
304 def getVmax(self):
305
305
306 _lambda = self.C/self.frequency
306 _lambda = self.C/self.frequency
307
307
308 vmax = self.getFmax() * _lambda
308 vmax = self.getFmax() * _lambda
309
309
310 return vmax
310 return vmax
311
311
312 def get_ippSeconds(self):
312 def get_ippSeconds(self):
313 '''
313 '''
314 '''
314 '''
315 return self.radarControllerHeaderObj.ippSeconds
315 return self.radarControllerHeaderObj.ippSeconds
316
316
317 def set_ippSeconds(self, ippSeconds):
317 def set_ippSeconds(self, ippSeconds):
318 '''
318 '''
319 '''
319 '''
320
320
321 self.radarControllerHeaderObj.ippSeconds = ippSeconds
321 self.radarControllerHeaderObj.ippSeconds = ippSeconds
322
322
323 return
323 return
324
324
325 def get_dtype(self):
325 def get_dtype(self):
326 '''
326 '''
327 '''
327 '''
328 return getNumpyDtype(self.datatype)
328 return getNumpyDtype(self.datatype)
329
329
330 def set_dtype(self, numpyDtype):
330 def set_dtype(self, numpyDtype):
331 '''
331 '''
332 '''
332 '''
333
333
334 self.datatype = getDataTypeCode(numpyDtype)
334 self.datatype = getDataTypeCode(numpyDtype)
335
335
336 def get_code(self):
336 def get_code(self):
337 '''
337 '''
338 '''
338 '''
339 return self.radarControllerHeaderObj.code
339 return self.radarControllerHeaderObj.code
340
340
341 def set_code(self, code):
341 def set_code(self, code):
342 '''
342 '''
343 '''
343 '''
344 self.radarControllerHeaderObj.code = code
344 self.radarControllerHeaderObj.code = code
345
345
346 return
346 return
347
347
348 def get_ncode(self):
348 def get_ncode(self):
349 '''
349 '''
350 '''
350 '''
351 return self.radarControllerHeaderObj.nCode
351 return self.radarControllerHeaderObj.nCode
352
352
353 def set_ncode(self, nCode):
353 def set_ncode(self, nCode):
354 '''
354 '''
355 '''
355 '''
356 self.radarControllerHeaderObj.nCode = nCode
356 self.radarControllerHeaderObj.nCode = nCode
357
357
358 return
358 return
359
359
360 def get_nbaud(self):
360 def get_nbaud(self):
361 '''
361 '''
362 '''
362 '''
363 return self.radarControllerHeaderObj.nBaud
363 return self.radarControllerHeaderObj.nBaud
364
364
365 def set_nbaud(self, nBaud):
365 def set_nbaud(self, nBaud):
366 '''
366 '''
367 '''
367 '''
368 self.radarControllerHeaderObj.nBaud = nBaud
368 self.radarControllerHeaderObj.nBaud = nBaud
369
369
370 return
370 return
371
371
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
373 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
373 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
374 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
374 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
375 #noise = property(getNoise, "I'm the 'nHeights' property.")
375 #noise = property(getNoise, "I'm the 'nHeights' property.")
376 datatime = property(getDatatime, "I'm the 'datatime' property")
376 datatime = property(getDatatime, "I'm the 'datatime' property")
377 ltctime = property(getltctime, "I'm the 'ltctime' property")
377 ltctime = property(getltctime, "I'm the 'ltctime' property")
378 ippSeconds = property(get_ippSeconds, set_ippSeconds)
378 ippSeconds = property(get_ippSeconds, set_ippSeconds)
379 dtype = property(get_dtype, set_dtype)
379 dtype = property(get_dtype, set_dtype)
380 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
380 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
381 code = property(get_code, set_code)
381 code = property(get_code, set_code)
382 nCode = property(get_ncode, set_ncode)
382 nCode = property(get_ncode, set_ncode)
383 nBaud = property(get_nbaud, set_nbaud)
383 nBaud = property(get_nbaud, set_nbaud)
384
384
385 class Voltage(JROData):
385 class Voltage(JROData):
386
386
387 #data es un numpy array de 2 dmensiones (canales, alturas)
387 #data es un numpy array de 2 dmensiones (canales, alturas)
388 data = None
388 data = None
389
389
390 def __init__(self):
390 def __init__(self):
391 '''
391 '''
392 Constructor
392 Constructor
393 '''
393 '''
394
394
395 self.useLocalTime = True
395 self.useLocalTime = True
396
396
397 self.radarControllerHeaderObj = RadarControllerHeader()
397 self.radarControllerHeaderObj = RadarControllerHeader()
398
398
399 self.systemHeaderObj = SystemHeader()
399 self.systemHeaderObj = SystemHeader()
400
400
401 self.type = "Voltage"
401 self.type = "Voltage"
402
402
403 self.data = None
403 self.data = None
404
404
405 # self.dtype = None
405 # self.dtype = None
406
406
407 # self.nChannels = 0
407 # self.nChannels = 0
408
408
409 # self.nHeights = 0
409 # self.nHeights = 0
410
410
411 self.nProfiles = None
411 self.nProfiles = None
412
412
413 self.heightList = None
413 self.heightList = None
414
414
415 self.channelList = None
415 self.channelList = None
416
416
417 # self.channelIndexList = None
417 # self.channelIndexList = None
418
418
419 self.flagNoData = True
419 self.flagNoData = True
420
420
421 self.flagDiscontinuousBlock = False
421 self.flagDiscontinuousBlock = False
422
422
423 self.utctime = None
423 self.utctime = None
424
424
425 self.timeZone = None
425 self.timeZone = None
426
426
427 self.dstFlag = None
427 self.dstFlag = None
428
428
429 self.errorCount = None
429 self.errorCount = None
430
430
431 self.nCohInt = None
431 self.nCohInt = None
432
432
433 self.blocksize = None
433 self.blocksize = None
434
434
435 self.flagDecodeData = False #asumo q la data no esta decodificada
435 self.flagDecodeData = False #asumo q la data no esta decodificada
436
436
437 self.flagDeflipData = False #asumo q la data no esta sin flip
437 self.flagDeflipData = False #asumo q la data no esta sin flip
438
438
439 self.flagShiftFFT = False
439 self.flagShiftFFT = False
440
440
441 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
441 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
442
442
443 self.profileIndex = 0
443 self.profileIndex = 0
444
444
445 def getNoisebyHildebrand(self, channel = None):
445 def getNoisebyHildebrand(self, channel = None):
446 """
446 """
447 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
447 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
448
448
449 Return:
449 Return:
450 noiselevel
450 noiselevel
451 """
451 """
452
452
453 if channel != None:
453 if channel != None:
454 data = self.data[channel]
454 data = self.data[channel]
455 nChannels = 1
455 nChannels = 1
456 else:
456 else:
457 data = self.data
457 data = self.data
458 nChannels = self.nChannels
458 nChannels = self.nChannels
459
459
460 noise = numpy.zeros(nChannels)
460 noise = numpy.zeros(nChannels)
461 power = data * numpy.conjugate(data)
461 power = data * numpy.conjugate(data)
462
462
463 for thisChannel in range(nChannels):
463 for thisChannel in range(nChannels):
464 if nChannels == 1:
464 if nChannels == 1:
465 daux = power[:].real
465 daux = power[:].real
466 else:
466 else:
467 daux = power[thisChannel,:].real
467 daux = power[thisChannel,:].real
468 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
468 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
469
469
470 return noise
470 return noise
471
471
472 def getNoise(self, type = 1, channel = None):
472 def getNoise(self, type = 1, channel = None):
473
473
474 if type == 1:
474 if type == 1:
475 noise = self.getNoisebyHildebrand(channel)
475 noise = self.getNoisebyHildebrand(channel)
476
476
477 return noise
477 return noise
478
478
479 def getPower(self, channel = None):
479 def getPower(self, channel = None):
480
480
481 if channel != None:
481 if channel != None:
482 data = self.data[channel]
482 data = self.data[channel]
483 else:
483 else:
484 data = self.data
484 data = self.data
485
485
486 power = data * numpy.conjugate(data)
486 power = data * numpy.conjugate(data)
487
487
488 return 10*numpy.log10(power.real)
488 return 10*numpy.log10(power.real)
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 es un numpy array de 2 dmensiones (canales, perfiles, alturas)
501 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
502 data_spc = None
502 data_spc = None
503
503
504 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
504 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
505 data_cspc = None
505 data_cspc = None
506
506
507 #data es un numpy array de 2 dmensiones (canales, alturas)
507 #data es un numpy array de 2 dmensiones (canales, alturas)
508 data_dc = None
508 data_dc = None
509
509
510 nFFTPoints = None
510 nFFTPoints = None
511
511
512 # nPairs = None
512 # nPairs = None
513
513
514 pairsList = None
514 pairsList = None
515
515
516 nIncohInt = None
516 nIncohInt = None
517
517
518 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
518 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
519
519
520 nCohInt = None #se requiere para determinar el valor de timeInterval
520 nCohInt = None #se requiere para determinar el valor de timeInterval
521
521
522 ippFactor = None
522 ippFactor = None
523
523
524 profileIndex = 0
524 profileIndex = 0
525
525
526 plotting = "spectra"
527
526 def __init__(self):
528 def __init__(self):
527 '''
529 '''
528 Constructor
530 Constructor
529 '''
531 '''
530
532
531 self.useLocalTime = True
533 self.useLocalTime = True
532
534
533 self.radarControllerHeaderObj = RadarControllerHeader()
535 self.radarControllerHeaderObj = RadarControllerHeader()
534
536
535 self.systemHeaderObj = SystemHeader()
537 self.systemHeaderObj = SystemHeader()
536
538
537 self.type = "Spectra"
539 self.type = "Spectra"
538
540
539 # self.data = None
541 # self.data = None
540
542
541 # self.dtype = None
543 # self.dtype = None
542
544
543 # self.nChannels = 0
545 # self.nChannels = 0
544
546
545 # self.nHeights = 0
547 # self.nHeights = 0
546
548
547 self.nProfiles = None
549 self.nProfiles = None
548
550
549 self.heightList = None
551 self.heightList = None
550
552
551 self.channelList = None
553 self.channelList = None
552
554
553 # self.channelIndexList = None
555 # self.channelIndexList = None
554
556
555 self.pairsList = None
557 self.pairsList = None
556
558
557 self.flagNoData = True
559 self.flagNoData = True
558
560
559 self.flagDiscontinuousBlock = False
561 self.flagDiscontinuousBlock = False
560
562
561 self.utctime = None
563 self.utctime = None
562
564
563 self.nCohInt = None
565 self.nCohInt = None
564
566
565 self.nIncohInt = None
567 self.nIncohInt = None
566
568
567 self.blocksize = None
569 self.blocksize = None
568
570
569 self.nFFTPoints = None
571 self.nFFTPoints = None
570
572
571 self.wavelength = None
573 self.wavelength = None
572
574
573 self.flagDecodeData = False #asumo q la data no esta decodificada
575 self.flagDecodeData = False #asumo q la data no esta decodificada
574
576
575 self.flagDeflipData = False #asumo q la data no esta sin flip
577 self.flagDeflipData = False #asumo q la data no esta sin flip
576
578
577 self.flagShiftFFT = False
579 self.flagShiftFFT = False
578
580
579 self.ippFactor = 1
581 self.ippFactor = 1
580
582
581 #self.noise = None
583 #self.noise = None
582
584
583 self.beacon_heiIndexList = []
585 self.beacon_heiIndexList = []
584
586
585 self.noise_estimation = None
587 self.noise_estimation = None
586
588
587
589
588 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
590 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
589 """
591 """
590 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
592 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
591
593
592 Return:
594 Return:
593 noiselevel
595 noiselevel
594 """
596 """
595
597
596 noise = numpy.zeros(self.nChannels)
598 noise = numpy.zeros(self.nChannels)
597
599
598 for channel in range(self.nChannels):
600 for channel in range(self.nChannels):
599 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
601 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
600 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
602 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
601
603
602 return noise
604 return noise
603
605
604 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
606 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
605
607
606 if self.noise_estimation is not None:
608 if self.noise_estimation is not None:
607 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
609 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
608 else:
610 else:
609 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
611 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
610 return noise
612 return noise
611
613
612 def getFreqRangeTimeResponse(self, extrapoints=0):
614 def getFreqRangeTimeResponse(self, extrapoints=0):
613
615
614 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
616 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
615 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
617 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
616
618
617 return freqrange
619 return freqrange
618
620
619 def getAcfRange(self, extrapoints=0):
621 def getAcfRange(self, extrapoints=0):
620
622
621 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
623 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
622 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
624 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
623
625
624 return freqrange
626 return freqrange
625
627
626 def getFreqRange(self, extrapoints=0):
628 def getFreqRange(self, extrapoints=0):
627
629
628 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
630 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
629 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
631 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
630
632
631 return freqrange
633 return freqrange
632
634
633 def getVelRange(self, extrapoints=0):
635 def getVelRange(self, extrapoints=0):
634
636
635 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
637 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
636 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
638 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
637
639
638 return velrange
640 return velrange
639
641
640 def getNPairs(self):
642 def getNPairs(self):
641
643
642 return len(self.pairsList)
644 return len(self.pairsList)
643
645
644 def getPairsIndexList(self):
646 def getPairsIndexList(self):
645
647
646 return range(self.nPairs)
648 return range(self.nPairs)
647
649
648 def getNormFactor(self):
650 def getNormFactor(self):
649
651
650 pwcode = 1
652 pwcode = 1
651
653
652 if self.flagDecodeData:
654 if self.flagDecodeData:
653 pwcode = numpy.sum(self.code[0]**2)
655 pwcode = numpy.sum(self.code[0]**2)
654 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
656 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
655 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
657 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
656
658
657 return normFactor
659 return normFactor
658
660
659 def getFlagCspc(self):
661 def getFlagCspc(self):
660
662
661 if self.data_cspc is None:
663 if self.data_cspc is None:
662 return True
664 return True
663
665
664 return False
666 return False
665
667
666 def getFlagDc(self):
668 def getFlagDc(self):
667
669
668 if self.data_dc is None:
670 if self.data_dc is None:
669 return True
671 return True
670
672
671 return False
673 return False
672
674
673 def getTimeInterval(self):
675 def getTimeInterval(self):
674
676
675 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
677 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
676
678
677 return timeInterval
679 return timeInterval
678
680
679 def setValue(self, value):
681 def setValue(self, value):
680
682
681 print "This property should not be initialized"
683 print "This property should not be initialized"
682
684
683 return
685 return
684
686
685 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
687 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
686 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
688 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
687 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
689 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
688 flag_cspc = property(getFlagCspc, setValue)
690 flag_cspc = property(getFlagCspc, setValue)
689 flag_dc = property(getFlagDc, setValue)
691 flag_dc = property(getFlagDc, setValue)
690 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
692 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
691 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
693 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
692
694
693 class SpectraHeis(Spectra):
695 class SpectraHeis(Spectra):
694
696
695 data_spc = None
697 data_spc = None
696
698
697 data_cspc = None
699 data_cspc = None
698
700
699 data_dc = None
701 data_dc = None
700
702
701 nFFTPoints = None
703 nFFTPoints = None
702
704
703 # nPairs = None
705 # nPairs = None
704
706
705 pairsList = None
707 pairsList = None
706
708
707 nCohInt = None
709 nCohInt = None
708
710
709 nIncohInt = None
711 nIncohInt = None
710
712
711 def __init__(self):
713 def __init__(self):
712
714
713 self.radarControllerHeaderObj = RadarControllerHeader()
715 self.radarControllerHeaderObj = RadarControllerHeader()
714
716
715 self.systemHeaderObj = SystemHeader()
717 self.systemHeaderObj = SystemHeader()
716
718
717 self.type = "SpectraHeis"
719 self.type = "SpectraHeis"
718
720
719 # self.dtype = None
721 # self.dtype = None
720
722
721 # self.nChannels = 0
723 # self.nChannels = 0
722
724
723 # self.nHeights = 0
725 # self.nHeights = 0
724
726
725 self.nProfiles = None
727 self.nProfiles = None
726
728
727 self.heightList = None
729 self.heightList = None
728
730
729 self.channelList = None
731 self.channelList = None
730
732
731 # self.channelIndexList = None
733 # self.channelIndexList = None
732
734
733 self.flagNoData = True
735 self.flagNoData = True
734
736
735 self.flagDiscontinuousBlock = False
737 self.flagDiscontinuousBlock = False
736
738
737 # self.nPairs = 0
739 # self.nPairs = 0
738
740
739 self.utctime = None
741 self.utctime = None
740
742
741 self.blocksize = None
743 self.blocksize = None
742
744
743 self.profileIndex = 0
745 self.profileIndex = 0
744
746
745 self.nCohInt = 1
747 self.nCohInt = 1
746
748
747 self.nIncohInt = 1
749 self.nIncohInt = 1
748
750
749 def getNormFactor(self):
751 def getNormFactor(self):
750 pwcode = 1
752 pwcode = 1
751 if self.flagDecodeData:
753 if self.flagDecodeData:
752 pwcode = numpy.sum(self.code[0]**2)
754 pwcode = numpy.sum(self.code[0]**2)
753
755
754 normFactor = self.nIncohInt*self.nCohInt*pwcode
756 normFactor = self.nIncohInt*self.nCohInt*pwcode
755
757
756 return normFactor
758 return normFactor
757
759
758 def getTimeInterval(self):
760 def getTimeInterval(self):
759
761
760 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
762 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
761
763
762 return timeInterval
764 return timeInterval
763
765
764 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
766 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
765 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
767 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
766
768
767 class Fits(JROData):
769 class Fits(JROData):
768
770
769 heightList = None
771 heightList = None
770
772
771 channelList = None
773 channelList = None
772
774
773 flagNoData = True
775 flagNoData = True
774
776
775 flagDiscontinuousBlock = False
777 flagDiscontinuousBlock = False
776
778
777 useLocalTime = False
779 useLocalTime = False
778
780
779 utctime = None
781 utctime = None
780
782
781 timeZone = None
783 timeZone = None
782
784
783 # ippSeconds = None
785 # ippSeconds = None
784
786
785 # timeInterval = None
787 # timeInterval = None
786
788
787 nCohInt = None
789 nCohInt = None
788
790
789 nIncohInt = None
791 nIncohInt = None
790
792
791 noise = None
793 noise = None
792
794
793 windowOfFilter = 1
795 windowOfFilter = 1
794
796
795 #Speed of ligth
797 #Speed of ligth
796 C = 3e8
798 C = 3e8
797
799
798 frequency = 49.92e6
800 frequency = 49.92e6
799
801
800 realtime = False
802 realtime = False
801
803
802
804
803 def __init__(self):
805 def __init__(self):
804
806
805 self.type = "Fits"
807 self.type = "Fits"
806
808
807 self.nProfiles = None
809 self.nProfiles = None
808
810
809 self.heightList = None
811 self.heightList = None
810
812
811 self.channelList = None
813 self.channelList = None
812
814
813 # self.channelIndexList = None
815 # self.channelIndexList = None
814
816
815 self.flagNoData = True
817 self.flagNoData = True
816
818
817 self.utctime = None
819 self.utctime = None
818
820
819 self.nCohInt = 1
821 self.nCohInt = 1
820
822
821 self.nIncohInt = 1
823 self.nIncohInt = 1
822
824
823 self.useLocalTime = True
825 self.useLocalTime = True
824
826
825 self.profileIndex = 0
827 self.profileIndex = 0
826
828
827 # self.utctime = None
829 # self.utctime = None
828 # self.timeZone = None
830 # self.timeZone = None
829 # self.ltctime = None
831 # self.ltctime = None
830 # self.timeInterval = None
832 # self.timeInterval = None
831 # self.header = None
833 # self.header = None
832 # self.data_header = None
834 # self.data_header = None
833 # self.data = None
835 # self.data = None
834 # self.datatime = None
836 # self.datatime = None
835 # self.flagNoData = False
837 # self.flagNoData = False
836 # self.expName = ''
838 # self.expName = ''
837 # self.nChannels = None
839 # self.nChannels = None
838 # self.nSamples = None
840 # self.nSamples = None
839 # self.dataBlocksPerFile = None
841 # self.dataBlocksPerFile = None
840 # self.comments = ''
842 # self.comments = ''
841 #
843 #
842
844
843
845
844 def getltctime(self):
846 def getltctime(self):
845
847
846 if self.useLocalTime:
848 if self.useLocalTime:
847 return self.utctime - self.timeZone*60
849 return self.utctime - self.timeZone*60
848
850
849 return self.utctime
851 return self.utctime
850
852
851 def getDatatime(self):
853 def getDatatime(self):
852
854
853 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
855 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
854 return datatime
856 return datatime
855
857
856 def getTimeRange(self):
858 def getTimeRange(self):
857
859
858 datatime = []
860 datatime = []
859
861
860 datatime.append(self.ltctime)
862 datatime.append(self.ltctime)
861 datatime.append(self.ltctime + self.timeInterval)
863 datatime.append(self.ltctime + self.timeInterval)
862
864
863 datatime = numpy.array(datatime)
865 datatime = numpy.array(datatime)
864
866
865 return datatime
867 return datatime
866
868
867 def getHeiRange(self):
869 def getHeiRange(self):
868
870
869 heis = self.heightList
871 heis = self.heightList
870
872
871 return heis
873 return heis
872
874
873 def getNHeights(self):
875 def getNHeights(self):
874
876
875 return len(self.heightList)
877 return len(self.heightList)
876
878
877 def getNChannels(self):
879 def getNChannels(self):
878
880
879 return len(self.channelList)
881 return len(self.channelList)
880
882
881 def getChannelIndexList(self):
883 def getChannelIndexList(self):
882
884
883 return range(self.nChannels)
885 return range(self.nChannels)
884
886
885 def getNoise(self, type = 1):
887 def getNoise(self, type = 1):
886
888
887 #noise = numpy.zeros(self.nChannels)
889 #noise = numpy.zeros(self.nChannels)
888
890
889 if type == 1:
891 if type == 1:
890 noise = self.getNoisebyHildebrand()
892 noise = self.getNoisebyHildebrand()
891
893
892 if type == 2:
894 if type == 2:
893 noise = self.getNoisebySort()
895 noise = self.getNoisebySort()
894
896
895 if type == 3:
897 if type == 3:
896 noise = self.getNoisebyWindow()
898 noise = self.getNoisebyWindow()
897
899
898 return noise
900 return noise
899
901
900 def getTimeInterval(self):
902 def getTimeInterval(self):
901
903
902 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
904 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
903
905
904 return timeInterval
906 return timeInterval
905
907
906 datatime = property(getDatatime, "I'm the 'datatime' property")
908 datatime = property(getDatatime, "I'm the 'datatime' property")
907 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
909 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
908 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
910 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
909 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
911 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
910 noise = property(getNoise, "I'm the 'nHeights' property.")
912 noise = property(getNoise, "I'm the 'nHeights' property.")
911
913
912 ltctime = property(getltctime, "I'm the 'ltctime' property")
914 ltctime = property(getltctime, "I'm the 'ltctime' property")
913 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
915 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
914
916
915 class Correlation(JROData):
917 class Correlation(JROData):
916
918
917 noise = None
919 noise = None
918
920
919 SNR = None
921 SNR = None
920
922
921 pairsAutoCorr = None #Pairs of Autocorrelation
923 pairsAutoCorr = None #Pairs of Autocorrelation
922
924
923 #--------------------------------------------------
925 #--------------------------------------------------
924
926
925 data_corr = None
927 data_corr = None
926
928
927 data_volt = None
929 data_volt = None
928
930
929 lagT = None # each element value is a profileIndex
931 lagT = None # each element value is a profileIndex
930
932
931 lagR = None # each element value is in km
933 lagR = None # each element value is in km
932
934
933 pairsList = None
935 pairsList = None
934
936
935 calculateVelocity = None
937 calculateVelocity = None
936
938
937 nPoints = None
939 nPoints = None
938
940
939 nAvg = None
941 nAvg = None
940
942
941 bufferSize = None
943 bufferSize = None
942
944
943 def __init__(self):
945 def __init__(self):
944 '''
946 '''
945 Constructor
947 Constructor
946 '''
948 '''
947 self.radarControllerHeaderObj = RadarControllerHeader()
949 self.radarControllerHeaderObj = RadarControllerHeader()
948
950
949 self.systemHeaderObj = SystemHeader()
951 self.systemHeaderObj = SystemHeader()
950
952
951 self.type = "Correlation"
953 self.type = "Correlation"
952
954
953 self.data = None
955 self.data = None
954
956
955 self.dtype = None
957 self.dtype = None
956
958
957 self.nProfiles = None
959 self.nProfiles = None
958
960
959 self.heightList = None
961 self.heightList = None
960
962
961 self.channelList = None
963 self.channelList = None
962
964
963 self.flagNoData = True
965 self.flagNoData = True
964
966
965 self.flagDiscontinuousBlock = False
967 self.flagDiscontinuousBlock = False
966
968
967 self.utctime = None
969 self.utctime = None
968
970
969 self.timeZone = None
971 self.timeZone = None
970
972
971 self.dstFlag = None
973 self.dstFlag = None
972
974
973 self.errorCount = None
975 self.errorCount = None
974
976
975 self.blocksize = None
977 self.blocksize = None
976
978
977 self.flagDecodeData = False #asumo q la data no esta decodificada
979 self.flagDecodeData = False #asumo q la data no esta decodificada
978
980
979 self.flagDeflipData = False #asumo q la data no esta sin flip
981 self.flagDeflipData = False #asumo q la data no esta sin flip
980
982
981 self.pairsList = None
983 self.pairsList = None
982
984
983 self.nPoints = None
985 self.nPoints = None
984
986
985 def getLagTRange(self, extrapoints=0):
987 def getLagTRange(self, extrapoints=0):
986
988
987 lagTRange = self.lagT
989 lagTRange = self.lagT
988 diff = lagTRange[1] - lagTRange[0]
990 diff = lagTRange[1] - lagTRange[0]
989 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
991 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
990 lagTRange = numpy.hstack((lagTRange, extra))
992 lagTRange = numpy.hstack((lagTRange, extra))
991
993
992 return lagTRange
994 return lagTRange
993
995
994 def getLagRRange(self, extrapoints=0):
996 def getLagRRange(self, extrapoints=0):
995
997
996 return self.lagR
998 return self.lagR
997
999
998 def getPairsList(self):
1000 def getPairsList(self):
999
1001
1000 return self.pairsList
1002 return self.pairsList
1001
1003
1002 def getCalculateVelocity(self):
1004 def getCalculateVelocity(self):
1003
1005
1004 return self.calculateVelocity
1006 return self.calculateVelocity
1005
1007
1006 def getNPoints(self):
1008 def getNPoints(self):
1007
1009
1008 return self.nPoints
1010 return self.nPoints
1009
1011
1010 def getNAvg(self):
1012 def getNAvg(self):
1011
1013
1012 return self.nAvg
1014 return self.nAvg
1013
1015
1014 def getBufferSize(self):
1016 def getBufferSize(self):
1015
1017
1016 return self.bufferSize
1018 return self.bufferSize
1017
1019
1018 def getPairsAutoCorr(self):
1020 def getPairsAutoCorr(self):
1019 pairsList = self.pairsList
1021 pairsList = self.pairsList
1020 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
1022 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
1021
1023
1022 for l in range(len(pairsList)):
1024 for l in range(len(pairsList)):
1023 firstChannel = pairsList[l][0]
1025 firstChannel = pairsList[l][0]
1024 secondChannel = pairsList[l][1]
1026 secondChannel = pairsList[l][1]
1025
1027
1026 #Obteniendo pares de Autocorrelacion
1028 #Obteniendo pares de Autocorrelacion
1027 if firstChannel == secondChannel:
1029 if firstChannel == secondChannel:
1028 pairsAutoCorr[firstChannel] = int(l)
1030 pairsAutoCorr[firstChannel] = int(l)
1029
1031
1030 pairsAutoCorr = pairsAutoCorr.astype(int)
1032 pairsAutoCorr = pairsAutoCorr.astype(int)
1031
1033
1032 return pairsAutoCorr
1034 return pairsAutoCorr
1033
1035
1034 def getNoise(self, mode = 2):
1036 def getNoise(self, mode = 2):
1035
1037
1036 indR = numpy.where(self.lagR == 0)[0][0]
1038 indR = numpy.where(self.lagR == 0)[0][0]
1037 indT = numpy.where(self.lagT == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1038
1040
1039 jspectra0 = self.data_corr[:,:,indR,:]
1041 jspectra0 = self.data_corr[:,:,indR,:]
1040 jspectra = copy.copy(jspectra0)
1042 jspectra = copy.copy(jspectra0)
1041
1043
1042 num_chan = jspectra.shape[0]
1044 num_chan = jspectra.shape[0]
1043 num_hei = jspectra.shape[2]
1045 num_hei = jspectra.shape[2]
1044
1046
1045 freq_dc = jspectra.shape[1]/2
1047 freq_dc = jspectra.shape[1]/2
1046 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1047
1049
1048 if ind_vel[0]<0:
1050 if ind_vel[0]<0:
1049 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1050
1052
1051 if mode == 1:
1053 if mode == 1:
1052 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1053
1055
1054 if mode == 2:
1056 if mode == 2:
1055
1057
1056 vel = numpy.array([-2,-1,1,2])
1058 vel = numpy.array([-2,-1,1,2])
1057 xx = numpy.zeros([4,4])
1059 xx = numpy.zeros([4,4])
1058
1060
1059 for fil in range(4):
1061 for fil in range(4):
1060 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1061
1063
1062 xx_inv = numpy.linalg.inv(xx)
1064 xx_inv = numpy.linalg.inv(xx)
1063 xx_aux = xx_inv[0,:]
1065 xx_aux = xx_inv[0,:]
1064
1066
1065 for ich in range(num_chan):
1067 for ich in range(num_chan):
1066 yy = jspectra[ich,ind_vel,:]
1068 yy = jspectra[ich,ind_vel,:]
1067 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1068
1070
1069 junkid = jspectra[ich,freq_dc,:]<=0
1071 junkid = jspectra[ich,freq_dc,:]<=0
1070 cjunkid = sum(junkid)
1072 cjunkid = sum(junkid)
1071
1073
1072 if cjunkid.any():
1074 if cjunkid.any():
1073 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1074
1076
1075 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1076
1078
1077 return noise
1079 return noise
1078
1080
1079 def getTimeInterval(self):
1081 def getTimeInterval(self):
1080
1082
1081 timeInterval = self.ippSeconds * self.nCohInt * self.nPoints
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nPoints
1082
1084
1083 return timeInterval
1085 return timeInterval
1084
1086
1085 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1087 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1086 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
1088 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
1087 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
1089 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
1088 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
1090 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
1089 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
1091 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
1090 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
1092 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
1091
1093
1092
1094
1093 class Parameters(JROData):
1095 class Parameters(JROData):
1094
1096
1095 #Information from previous data
1097 #Information from previous data
1096
1098
1097 inputUnit = None #Type of data to be processed
1099 inputUnit = None #Type of data to be processed
1098
1100
1099 operation = None #Type of operation to parametrize
1101 operation = None #Type of operation to parametrize
1100
1102
1101 normFactor = None #Normalization Factor
1103 normFactor = None #Normalization Factor
1102
1104
1103 groupList = None #List of Pairs, Groups, etc
1105 groupList = None #List of Pairs, Groups, etc
1104
1106
1105 #Parameters
1107 #Parameters
1106
1108
1107 data_param = None #Parameters obtained
1109 data_param = None #Parameters obtained
1108
1110
1109 data_pre = None #Data Pre Parametrization
1111 data_pre = None #Data Pre Parametrization
1110
1112
1111 data_SNR = None #Signal to Noise Ratio
1113 data_SNR = None #Signal to Noise Ratio
1112
1114
1113 # heightRange = None #Heights
1115 # heightRange = None #Heights
1114
1116
1115 abscissaList = None #Abscissa, can be velocities, lags or time
1117 abscissaList = None #Abscissa, can be velocities, lags or time
1116
1118
1117 noise = None #Noise Potency
1119 noise = None #Noise Potency
1118
1120
1119 utctimeInit = None #Initial UTC time
1121 utctimeInit = None #Initial UTC time
1120
1122
1121 paramInterval = None #Time interval to calculate Parameters in seconds
1123 paramInterval = None #Time interval to calculate Parameters in seconds
1122
1124
1123 #Fitting
1125 #Fitting
1124
1126
1125 data_error = None #Error of the estimation
1127 data_error = None #Error of the estimation
1126
1128
1127 constants = None
1129 constants = None
1128
1130
1129 library = None
1131 library = None
1130
1132
1131 #Output signal
1133 #Output signal
1132
1134
1133 outputInterval = None #Time interval to calculate output signal in seconds
1135 outputInterval = None #Time interval to calculate output signal in seconds
1134
1136
1135 data_output = None #Out signal
1137 data_output = None #Out signal
1136
1138
1137
1139
1138
1140
1139 def __init__(self):
1141 def __init__(self):
1140 '''
1142 '''
1141 Constructor
1143 Constructor
1142 '''
1144 '''
1143 self.radarControllerHeaderObj = RadarControllerHeader()
1145 self.radarControllerHeaderObj = RadarControllerHeader()
1144
1146
1145 self.systemHeaderObj = SystemHeader()
1147 self.systemHeaderObj = SystemHeader()
1146
1148
1147 self.type = "Parameters"
1149 self.type = "Parameters"
1148
1150
1149 def getTimeRange1(self):
1151 def getTimeRange1(self):
1150
1152
1151 datatime = []
1153 datatime = []
1152
1154
1153 if self.useLocalTime:
1155 if self.useLocalTime:
1154 time1 = self.utctimeInit - self.timeZone*60
1156 time1 = self.utctimeInit - self.timeZone*60
1155 else:
1157 else:
1156 time1 = utctimeInit
1158 time1 = utctimeInit
1157
1159
1158 # datatime.append(self.utctimeInit)
1160 # datatime.append(self.utctimeInit)
1159 # datatime.append(self.utctimeInit + self.outputInterval)
1161 # datatime.append(self.utctimeInit + self.outputInterval)
1160 datatime.append(time1)
1162 datatime.append(time1)
1161 datatime.append(time1 + self.outputInterval)
1163 datatime.append(time1 + self.outputInterval)
1162
1164
1163 datatime = numpy.array(datatime)
1165 datatime = numpy.array(datatime)
1164
1166
1165 return datatime
1167 return datatime
General Comments 0
You need to be logged in to leave comments. Login now