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