##// END OF EJS Templates
Miguel Valdez -
r232:13e5ede6a371
parent child
Show More
@@ -1,512 +1,525
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 os, sys
7 import os, sys
8 import copy
8 import copy
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11
11
12 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from jroheaderIO import SystemHeader, RadarControllerHeader
13
13
14 def hildebrand_sekhon(data, navg):
14 def hildebrand_sekhon(data, navg):
15 """
15 """
16 This method is for the objective determination of de noise level in Doppler spectra. This
16 This method is for the objective determination of de noise level in Doppler spectra. This
17 implementation technique is based on the fact that the standard deviation of the spectral
17 implementation technique is based on the fact that the standard deviation of the spectral
18 densities is equal to the mean spectral density for white Gaussian noise
18 densities is equal to the mean spectral density for white Gaussian noise
19
19
20 Inputs:
20 Inputs:
21 Data : heights
21 Data : heights
22 navg : numbers of averages
22 navg : numbers of averages
23
23
24 Return:
24 Return:
25 -1 : any error
25 -1 : any error
26 anoise : noise's level
26 anoise : noise's level
27 """
27 """
28
28
29 dataflat = data.copy().reshape(-1)
29 dataflat = data.copy().reshape(-1)
30 dataflat.sort()
30 dataflat.sort()
31 npts = dataflat.size #numbers of points of the data
31 npts = dataflat.size #numbers of points of the data
32 npts_noise = 0.2*npts
32 npts_noise = 0.2*npts
33
33
34 if npts < 32:
34 if npts < 32:
35 print "error in noise - requires at least 32 points"
35 print "error in noise - requires at least 32 points"
36 return -1.0
36 return -1.0
37
37
38 dataflat2 = numpy.power(dataflat,2)
38 dataflat2 = numpy.power(dataflat,2)
39
39
40 cs = numpy.cumsum(dataflat)
40 cs = numpy.cumsum(dataflat)
41 cs2 = numpy.cumsum(dataflat2)
41 cs2 = numpy.cumsum(dataflat2)
42
42
43 # data sorted in ascending order
43 # data sorted in ascending order
44 nmin = int((npts + 7.)/8)
44 nmin = int((npts + 7.)/8)
45
45
46 for i in range(nmin, npts):
46 for i in range(nmin, npts):
47 s = cs[i]
47 s = cs[i]
48 s2 = cs2[i]
48 s2 = cs2[i]
49 p = s / float(i);
49 p = s / float(i);
50 p2 = p**2;
50 p2 = p**2;
51 q = s2 / float(i) - p2;
51 q = s2 / float(i) - p2;
52 leftc = p2;
52 leftc = p2;
53 rightc = q * float(navg);
53 rightc = q * float(navg);
54 R2 = leftc/rightc
54 R2 = leftc/rightc
55
55
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
56 # Signal detect: R2 < 1 (R2 = leftc/rightc)
57 if R2 < 1:
57 if R2 < 1:
58 npts_noise = i
58 npts_noise = i
59 break
59 break
60
60
61
61
62 anoise = numpy.average(dataflat[0:npts_noise])
62 anoise = numpy.average(dataflat[0:npts_noise])
63
63
64 return anoise;
64 return anoise;
65
65
66 def sorting_bruce(data, navg):
66 def sorting_bruce(data, navg):
67
67
68 data = data.copy()
68 data = data.copy()
69
69
70 sortdata = numpy.sort(data)
70 sortdata = numpy.sort(data)
71 lenOfData = len(data)
71 lenOfData = len(data)
72 nums_min = lenOfData/10
72 nums_min = lenOfData/10
73
73
74 if (lenOfData/10) > 0:
74 if (lenOfData/10) > 0:
75 nums_min = lenOfData/10
75 nums_min = lenOfData/10
76 else:
76 else:
77 nums_min = 0
77 nums_min = 0
78
78
79 rtest = 1.0 + 1.0/navg
79 rtest = 1.0 + 1.0/navg
80
80
81 sum = 0.
81 sum = 0.
82
82
83 sumq = 0.
83 sumq = 0.
84
84
85 j = 0
85 j = 0
86
86
87 cont = 1
87 cont = 1
88
88
89 while((cont==1)and(j<lenOfData)):
89 while((cont==1)and(j<lenOfData)):
90
90
91 sum += sortdata[j]
91 sum += sortdata[j]
92
92
93 sumq += sortdata[j]**2
93 sumq += sortdata[j]**2
94
94
95 j += 1
95 j += 1
96
96
97 if j > nums_min:
97 if j > nums_min:
98 if ((sumq*j) <= (rtest*sum**2)):
98 if ((sumq*j) <= (rtest*sum**2)):
99 lnoise = sum / j
99 lnoise = sum / j
100 else:
100 else:
101 j = j - 1
101 j = j - 1
102 sum = sum - sordata[j]
102 sum = sum - sordata[j]
103 sumq = sumq - sordata[j]**2
103 sumq = sumq - sordata[j]**2
104 cont = 0
104 cont = 0
105
105
106 if j == nums_min:
106 if j == nums_min:
107 lnoise = sum /j
107 lnoise = sum /j
108
108
109 return lnoise
109 return lnoise
110
110
111 class JROData:
111 class JROData:
112
112
113 # m_BasicHeader = BasicHeader()
113 # m_BasicHeader = BasicHeader()
114 # m_ProcessingHeader = ProcessingHeader()
114 # m_ProcessingHeader = ProcessingHeader()
115
115
116 systemHeaderObj = SystemHeader()
116 systemHeaderObj = SystemHeader()
117
117
118 radarControllerHeaderObj = RadarControllerHeader()
118 radarControllerHeaderObj = RadarControllerHeader()
119
119
120 # data = None
120 # data = None
121
121
122 type = None
122 type = None
123
123
124 dtype = None
124 dtype = None
125
125
126 # nChannels = None
126 # nChannels = None
127
127
128 # nHeights = None
128 # nHeights = None
129
129
130 nProfiles = None
130 nProfiles = None
131
131
132 heightList = None
132 heightList = None
133
133
134 channelList = None
134 channelList = None
135
135
136 flagNoData = True
136 flagNoData = True
137
137
138 flagTimeBlock = False
138 flagTimeBlock = False
139
139
140 utctime = None
140 utctime = None
141
141
142 blocksize = None
142 blocksize = None
143
143
144 nCode = None
144 nCode = None
145
145
146 nBaud = None
146 nBaud = None
147
147
148 code = None
148 code = None
149
149
150 flagDecodeData = True #asumo q la data esta decodificada
150 flagDecodeData = False #asumo q la data no esta decodificada
151
151
152 flagDeflipData = True #asumo q la data esta sin flip
152 flagDeflipData = False #asumo q la data no esta sin flip
153
153
154 flagShiftFFT = False
154 flagShiftFFT = False
155
155
156 ippSeconds = None
156 ippSeconds = None
157
157
158 timeInterval = None
158 timeInterval = None
159
159
160 nCohInt = None
160 nCohInt = None
161
161
162 noise = None
162 noise = None
163
163
164 #Speed of ligth
164 #Speed of ligth
165 C = 3e8
165 C = 3e8
166
166
167 frequency = 49.92e6
167 frequency = 49.92e6
168
168
169 def __init__(self):
169 def __init__(self):
170
170
171 raise ValueError, "This class has not been implemented"
171 raise ValueError, "This class has not been implemented"
172
172
173 def copy(self, inputObj=None):
173 def copy(self, inputObj=None):
174
174
175 if inputObj == None:
175 if inputObj == None:
176 return copy.deepcopy(self)
176 return copy.deepcopy(self)
177
177
178 for key in inputObj.__dict__.keys():
178 for key in inputObj.__dict__.keys():
179 self.__dict__[key] = inputObj.__dict__[key]
179 self.__dict__[key] = inputObj.__dict__[key]
180
180
181 def deepcopy(self):
181 def deepcopy(self):
182
182
183 return copy.deepcopy(self)
183 return copy.deepcopy(self)
184
184
185 def isEmpty(self):
185 def isEmpty(self):
186
186
187 return self.flagNoData
187 return self.flagNoData
188
188
189 def getNoise(self):
189 def getNoise(self):
190
190
191 raise ValueError, "Not implemented"
191 raise ValueError, "Not implemented"
192
192
193 def getNChannels(self):
193 def getNChannels(self):
194
194
195 return len(self.channelList)
195 return len(self.channelList)
196
196
197 def getChannelIndexList(self):
197 def getChannelIndexList(self):
198
198
199 return range(self.nChannels)
199 return range(self.nChannels)
200
200
201 def getNHeights(self):
201 def getNHeights(self):
202
202
203 return len(self.heightList)
203 return len(self.heightList)
204
204
205 def getHeiRange(self, extrapoints=0):
205 def getHeiRange(self, extrapoints=0):
206
206
207 heis = self.heightList
207 heis = self.heightList
208 # deltah = self.heightList[1] - self.heightList[0]
208 # deltah = self.heightList[1] - self.heightList[0]
209 #
209 #
210 # heis.append(self.heightList[-1])
210 # heis.append(self.heightList[-1])
211
211
212 return heis
212 return heis
213
213
214 def getDatatime(self):
214 def getDatatime(self):
215
215
216 datatime = datetime.datetime.utcfromtimestamp(self.utctime)
216 datatime = datetime.datetime.utcfromtimestamp(self.utctime)
217 return datatime
217 return datatime
218
218
219 def getTimeRange(self):
219 def getTimeRange(self):
220
220
221 datatime = []
221 datatime = []
222
222
223 datatime.append(self.utctime)
223 datatime.append(self.utctime)
224 datatime.append(self.utctime + self.timeInterval)
224 datatime.append(self.utctime + self.timeInterval)
225
225
226 datatime = numpy.array(datatime)
226 datatime = numpy.array(datatime)
227
227
228 return datatime
228 return datatime
229
229
230 def getFmax(self):
230 def getFmax(self):
231
231
232 PRF = 1./(self.ippSeconds * self.nCohInt)
232 PRF = 1./(self.ippSeconds * self.nCohInt)
233
233
234 fmax = PRF/2.
234 fmax = PRF/2.
235
235
236 return fmax
236 return fmax
237
237
238 def getVmax(self):
238 def getVmax(self):
239
239
240 _lambda = self.C/self.frequency
240 _lambda = self.C/self.frequency
241
241
242 vmax = self.getFmax() * _lambda
242 vmax = self.getFmax() * _lambda
243
243
244 return vmax
244 return vmax
245
245
246 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
246 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
247 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
247 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
248 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
248 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
249 noise = property(getNoise, "I'm the 'nHeights' property.")
249 noise = property(getNoise, "I'm the 'nHeights' property.")
250 datatime = property(getDatatime, "I'm the 'datatime' property")
250 datatime = property(getDatatime, "I'm the 'datatime' property")
251
251
252 class Voltage(JROData):
252 class Voltage(JROData):
253
253
254 #data es un numpy array de 2 dmensiones (canales, alturas)
254 #data es un numpy array de 2 dmensiones (canales, alturas)
255 data = None
255 data = None
256
256
257 def __init__(self):
257 def __init__(self):
258 '''
258 '''
259 Constructor
259 Constructor
260 '''
260 '''
261
261
262 self.radarControllerHeaderObj = RadarControllerHeader()
262 self.radarControllerHeaderObj = RadarControllerHeader()
263
263
264 self.systemHeaderObj = SystemHeader()
264 self.systemHeaderObj = SystemHeader()
265
265
266 self.type = "Voltage"
266 self.type = "Voltage"
267
267
268 self.data = None
268 self.data = None
269
269
270 self.dtype = None
270 self.dtype = None
271
271
272 # self.nChannels = 0
272 # self.nChannels = 0
273
273
274 # self.nHeights = 0
274 # self.nHeights = 0
275
275
276 self.nProfiles = None
276 self.nProfiles = None
277
277
278 self.heightList = None
278 self.heightList = None
279
279
280 self.channelList = None
280 self.channelList = None
281
281
282 # self.channelIndexList = None
282 # self.channelIndexList = None
283
283
284 self.flagNoData = True
284 self.flagNoData = True
285
285
286 self.flagTimeBlock = False
286 self.flagTimeBlock = False
287
287
288 self.utctime = None
288 self.utctime = None
289
289
290 self.nCohInt = None
290 self.nCohInt = None
291
291
292 self.blocksize = None
292 self.blocksize = None
293
294 self.flagDecodeData = False #asumo q la data no esta decodificada
295
296 self.flagDeflipData = False #asumo q la data no esta sin flip
297
298 self.flagShiftFFT = False
299
293
300
294 def getNoisebyHildebrand(self):
301 def getNoisebyHildebrand(self):
295 """
302 """
296 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
303 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
297
304
298 Return:
305 Return:
299 noiselevel
306 noiselevel
300 """
307 """
301
308
302 for channel in range(self.nChannels):
309 for channel in range(self.nChannels):
303 daux = self.data_spc[channel,:,:]
310 daux = self.data_spc[channel,:,:]
304 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
311 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
305
312
306 return self.noise
313 return self.noise
307
314
308 def getNoise(self, type = 1):
315 def getNoise(self, type = 1):
309
316
310 self.noise = numpy.zeros(self.nChannels)
317 self.noise = numpy.zeros(self.nChannels)
311
318
312 if type == 1:
319 if type == 1:
313 noise = self.getNoisebyHildebrand()
320 noise = self.getNoisebyHildebrand()
314
321
315 return 10*numpy.log10(noise)
322 return 10*numpy.log10(noise)
316
323
317 class Spectra(JROData):
324 class Spectra(JROData):
318
325
319 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
326 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
320 data_spc = None
327 data_spc = None
321
328
322 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
329 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
323 data_cspc = None
330 data_cspc = None
324
331
325 #data es un numpy array de 2 dmensiones (canales, alturas)
332 #data es un numpy array de 2 dmensiones (canales, alturas)
326 data_dc = None
333 data_dc = None
327
334
328 nFFTPoints = None
335 nFFTPoints = None
329
336
330 nPairs = None
337 nPairs = None
331
338
332 pairsList = None
339 pairsList = None
333
340
334 nIncohInt = None
341 nIncohInt = None
335
342
336 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
343 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
337
344
338 nCohInt = None #se requiere para determinar el valor de timeInterval
345 nCohInt = None #se requiere para determinar el valor de timeInterval
339
346
340 def __init__(self):
347 def __init__(self):
341 '''
348 '''
342 Constructor
349 Constructor
343 '''
350 '''
344
351
345 self.radarControllerHeaderObj = RadarControllerHeader()
352 self.radarControllerHeaderObj = RadarControllerHeader()
346
353
347 self.systemHeaderObj = SystemHeader()
354 self.systemHeaderObj = SystemHeader()
348
355
349 self.type = "Spectra"
356 self.type = "Spectra"
350
357
351 # self.data = None
358 # self.data = None
352
359
353 self.dtype = None
360 self.dtype = None
354
361
355 # self.nChannels = 0
362 # self.nChannels = 0
356
363
357 # self.nHeights = 0
364 # self.nHeights = 0
358
365
359 self.nProfiles = None
366 self.nProfiles = None
360
367
361 self.heightList = None
368 self.heightList = None
362
369
363 self.channelList = None
370 self.channelList = None
364
371
365 # self.channelIndexList = None
372 # self.channelIndexList = None
366
373
367 self.flagNoData = True
374 self.flagNoData = True
368
375
369 self.flagTimeBlock = False
376 self.flagTimeBlock = False
370
377
371 self.utctime = None
378 self.utctime = None
372
379
373 self.nCohInt = None
380 self.nCohInt = None
374
381
375 self.nIncohInt = None
382 self.nIncohInt = None
376
383
377 self.blocksize = None
384 self.blocksize = None
378
385
379 self.nFFTPoints = None
386 self.nFFTPoints = None
380
387
381 self.wavelength = None
388 self.wavelength = None
389
390 self.flagDecodeData = False #asumo q la data no esta decodificada
391
392 self.flagDeflipData = False #asumo q la data no esta sin flip
393
394 self.flagShiftFFT = False
382
395
383 def getNoisebyHildebrand(self):
396 def getNoisebyHildebrand(self):
384 """
397 """
385 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
398 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
386
399
387 Return:
400 Return:
388 noiselevel
401 noiselevel
389 """
402 """
390
403
391 for channel in range(self.nChannels):
404 for channel in range(self.nChannels):
392 daux = self.data_spc[channel,:,:]
405 daux = self.data_spc[channel,:,:]
393 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
406 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
394
407
395 return self.noise
408 return self.noise
396
409
397 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
410 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
398 """
411 """
399 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
412 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
400 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
413 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
401
414
402 Inputs:
415 Inputs:
403 heiIndexMin: Limite inferior del eje de alturas
416 heiIndexMin: Limite inferior del eje de alturas
404 heiIndexMax: Limite superior del eje de alturas
417 heiIndexMax: Limite superior del eje de alturas
405 freqIndexMin: Limite inferior del eje de frecuencia
418 freqIndexMin: Limite inferior del eje de frecuencia
406 freqIndexMax: Limite supoerior del eje de frecuencia
419 freqIndexMax: Limite supoerior del eje de frecuencia
407 """
420 """
408
421
409 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
422 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
410
423
411 for channel in range(self.nChannels):
424 for channel in range(self.nChannels):
412 daux = data[channel,:,:]
425 daux = data[channel,:,:]
413 self.noise[channel] = numpy.average(daux)
426 self.noise[channel] = numpy.average(daux)
414
427
415 return self.noise
428 return self.noise
416
429
417 def getNoisebySort(self):
430 def getNoisebySort(self):
418
431
419 for channel in range(self.nChannels):
432 for channel in range(self.nChannels):
420 daux = self.data_spc[channel,:,:]
433 daux = self.data_spc[channel,:,:]
421 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
434 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
422
435
423 return self.noise
436 return self.noise
424
437
425 def getNoise(self, type = 1):
438 def getNoise(self, type = 1):
426
439
427 self.noise = numpy.zeros(self.nChannels)
440 self.noise = numpy.zeros(self.nChannels)
428
441
429 if type == 1:
442 if type == 1:
430 noise = self.getNoisebyHildebrand()
443 noise = self.getNoisebyHildebrand()
431
444
432 if type == 2:
445 if type == 2:
433 noise = self.getNoisebySort()
446 noise = self.getNoisebySort()
434
447
435 if type == 3:
448 if type == 3:
436 noise = self.getNoisebyWindow()
449 noise = self.getNoisebyWindow()
437
450
438 return 10*numpy.log10(noise)
451 return 10*numpy.log10(noise)
439
452
440
453
441 def getFreqRange(self, extrapoints=0):
454 def getFreqRange(self, extrapoints=0):
442
455
443 deltafreq = self.getFmax() / self.nFFTPoints
456 deltafreq = self.getFmax() / self.nFFTPoints
444 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
457 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
445
458
446 return freqrange
459 return freqrange
447
460
448 def getVelRange(self, extrapoints=0):
461 def getVelRange(self, extrapoints=0):
449
462
450 deltav = self.getVmax() / self.nFFTPoints
463 deltav = self.getVmax() / self.nFFTPoints
451 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
464 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
452
465
453 return velrange
466 return velrange
454
467
455 def getNPairs(self):
468 def getNPairs(self):
456
469
457 return len(self.pairsList)
470 return len(self.pairsList)
458
471
459 def getPairsIndexList(self):
472 def getPairsIndexList(self):
460
473
461 return range(self.nPairs)
474 return range(self.nPairs)
462
475
463 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
476 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
464 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
477 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
465
478
466 class SpectraHeis(JROData):
479 class SpectraHeis(JROData):
467
480
468 data_spc = None
481 data_spc = None
469
482
470 data_cspc = None
483 data_cspc = None
471
484
472 data_dc = None
485 data_dc = None
473
486
474 nFFTPoints = None
487 nFFTPoints = None
475
488
476 nPairs = None
489 nPairs = None
477
490
478 pairsList = None
491 pairsList = None
479
492
480 nIncohInt = None
493 nIncohInt = None
481
494
482 def __init__(self):
495 def __init__(self):
483
496
484 self.radarControllerHeaderObj = RadarControllerHeader()
497 self.radarControllerHeaderObj = RadarControllerHeader()
485
498
486 self.systemHeaderObj = SystemHeader()
499 self.systemHeaderObj = SystemHeader()
487
500
488 self.type = "SpectraHeis"
501 self.type = "SpectraHeis"
489
502
490 self.dtype = None
503 self.dtype = None
491
504
492 # self.nChannels = 0
505 # self.nChannels = 0
493
506
494 # self.nHeights = 0
507 # self.nHeights = 0
495
508
496 self.nProfiles = None
509 self.nProfiles = None
497
510
498 self.heightList = None
511 self.heightList = None
499
512
500 self.channelList = None
513 self.channelList = None
501
514
502 # self.channelIndexList = None
515 # self.channelIndexList = None
503
516
504 self.flagNoData = True
517 self.flagNoData = True
505
518
506 self.flagTimeBlock = False
519 self.flagTimeBlock = False
507
520
508 self.nPairs = 0
521 self.nPairs = 0
509
522
510 self.utctime = None
523 self.utctime = None
511
524
512 self.blocksize = None
525 self.blocksize = None
@@ -1,2547 +1,2560
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 import os, sys
7 import os, sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import time, datetime
12 import time, datetime
13
13
14 from jrodata import *
14 from jrodata import *
15 from jroheaderIO import *
15 from jroheaderIO import *
16 from jroprocessing import *
16 from jroprocessing import *
17
17
18 def isNumber(str):
18 def isNumber(str):
19 """
19 """
20 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
20 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
21
21
22 Excepciones:
22 Excepciones:
23 Si un determinado string no puede ser convertido a numero
23 Si un determinado string no puede ser convertido a numero
24 Input:
24 Input:
25 str, string al cual se le analiza para determinar si convertible a un numero o no
25 str, string al cual se le analiza para determinar si convertible a un numero o no
26
26
27 Return:
27 Return:
28 True : si el string es uno numerico
28 True : si el string es uno numerico
29 False : no es un string numerico
29 False : no es un string numerico
30 """
30 """
31 try:
31 try:
32 float( str )
32 float( str )
33 return True
33 return True
34 except:
34 except:
35 return False
35 return False
36
36
37 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
37 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
38 """
38 """
39 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
39 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
40
40
41 Inputs:
41 Inputs:
42 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
42 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
43
43
44 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
44 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
45 segundos contados desde 01/01/1970.
45 segundos contados desde 01/01/1970.
46 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
46 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
47 segundos contados desde 01/01/1970.
47 segundos contados desde 01/01/1970.
48
48
49 Return:
49 Return:
50 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
50 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
51 fecha especificado, de lo contrario retorna False.
51 fecha especificado, de lo contrario retorna False.
52
52
53 Excepciones:
53 Excepciones:
54 Si el archivo no existe o no puede ser abierto
54 Si el archivo no existe o no puede ser abierto
55 Si la cabecera no puede ser leida.
55 Si la cabecera no puede ser leida.
56
56
57 """
57 """
58 basicHeaderObj = BasicHeader()
58 basicHeaderObj = BasicHeader()
59
59
60 try:
60 try:
61 fp = open(filename,'rb')
61 fp = open(filename,'rb')
62 except:
62 except:
63 raise IOError, "The file %s can't be opened" %(filename)
63 raise IOError, "The file %s can't be opened" %(filename)
64
64
65 sts = basicHeaderObj.read(fp)
65 sts = basicHeaderObj.read(fp)
66 fp.close()
66 fp.close()
67
67
68 if not(sts):
68 if not(sts):
69 print "Skipping the file %s because it has not a valid header" %(filename)
69 print "Skipping the file %s because it has not a valid header" %(filename)
70 return 0
70 return 0
71
71
72 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
72 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
73 return 0
73 return 0
74
74
75 return 1
75 return 1
76
76
77 def isFileinThisTime(filename, startTime, endTime):
77 def isFileinThisTime(filename, startTime, endTime):
78 """
78 """
79 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
79 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
80
80
81 Inputs:
81 Inputs:
82 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
82 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
83
83
84 startTime : tiempo inicial del rango seleccionado en formato datetime.time
84 startTime : tiempo inicial del rango seleccionado en formato datetime.time
85
85
86 endTime : tiempo final del rango seleccionado en formato datetime.time
86 endTime : tiempo final del rango seleccionado en formato datetime.time
87
87
88 Return:
88 Return:
89 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
89 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
90 fecha especificado, de lo contrario retorna False.
90 fecha especificado, de lo contrario retorna False.
91
91
92 Excepciones:
92 Excepciones:
93 Si el archivo no existe o no puede ser abierto
93 Si el archivo no existe o no puede ser abierto
94 Si la cabecera no puede ser leida.
94 Si la cabecera no puede ser leida.
95
95
96 """
96 """
97
97
98
98
99 try:
99 try:
100 fp = open(filename,'rb')
100 fp = open(filename,'rb')
101 except:
101 except:
102 raise IOError, "The file %s can't be opened" %(filename)
102 raise IOError, "The file %s can't be opened" %(filename)
103
103
104 basicHeaderObj = BasicHeader()
104 basicHeaderObj = BasicHeader()
105 sts = basicHeaderObj.read(fp)
105 sts = basicHeaderObj.read(fp)
106 fp.close()
106 fp.close()
107
107
108 thisTime = basicHeaderObj.datatime.time()
108 thisTime = basicHeaderObj.datatime.time()
109
109
110 if not(sts):
110 if not(sts):
111 print "Skipping the file %s because it has not a valid header" %(filename)
111 print "Skipping the file %s because it has not a valid header" %(filename)
112 return 0
112 return 0
113
113
114 if not ((startTime <= thisTime) and (endTime > thisTime)):
114 if not ((startTime <= thisTime) and (endTime > thisTime)):
115 return 0
115 return 0
116
116
117 return 1
117 return 1
118
118
119 def getlastFileFromPath(path, ext):
119 def getlastFileFromPath(path, ext):
120 """
120 """
121 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
121 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
122 al final de la depuracion devuelve el ultimo file de la lista que quedo.
122 al final de la depuracion devuelve el ultimo file de la lista que quedo.
123
123
124 Input:
124 Input:
125 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
125 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
126 ext : extension de los files contenidos en una carpeta
126 ext : extension de los files contenidos en una carpeta
127
127
128 Return:
128 Return:
129 El ultimo file de una determinada carpeta, no se considera el path.
129 El ultimo file de una determinada carpeta, no se considera el path.
130 """
130 """
131 validFilelist = []
131 validFilelist = []
132 fileList = os.listdir(path)
132 fileList = os.listdir(path)
133
133
134 # 0 1234 567 89A BCDE
134 # 0 1234 567 89A BCDE
135 # H YYYY DDD SSS .ext
135 # H YYYY DDD SSS .ext
136
136
137 for file in fileList:
137 for file in fileList:
138 try:
138 try:
139 year = int(file[1:5])
139 year = int(file[1:5])
140 doy = int(file[5:8])
140 doy = int(file[5:8])
141
141
142
142
143 except:
143 except:
144 continue
144 continue
145
145
146 if (os.path.splitext(file)[-1].lower() != ext.lower()):
146 if (os.path.splitext(file)[-1].lower() != ext.lower()):
147 continue
147 continue
148
148
149 validFilelist.append(file)
149 validFilelist.append(file)
150
150
151 if validFilelist:
151 if validFilelist:
152 validFilelist = sorted( validFilelist, key=str.lower )
152 validFilelist = sorted( validFilelist, key=str.lower )
153 return validFilelist[-1]
153 return validFilelist[-1]
154
154
155 return None
155 return None
156
156
157 def checkForRealPath(path, year, doy, set, ext):
157 def checkForRealPath(path, year, doy, set, ext):
158 """
158 """
159 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
159 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
160 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
160 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
161 el path exacto de un determinado file.
161 el path exacto de un determinado file.
162
162
163 Example :
163 Example :
164 nombre correcto del file es .../.../D2009307/P2009307367.ext
164 nombre correcto del file es .../.../D2009307/P2009307367.ext
165
165
166 Entonces la funcion prueba con las siguientes combinaciones
166 Entonces la funcion prueba con las siguientes combinaciones
167 .../.../y2009307367.ext
167 .../.../y2009307367.ext
168 .../.../Y2009307367.ext
168 .../.../Y2009307367.ext
169 .../.../x2009307/y2009307367.ext
169 .../.../x2009307/y2009307367.ext
170 .../.../x2009307/Y2009307367.ext
170 .../.../x2009307/Y2009307367.ext
171 .../.../X2009307/y2009307367.ext
171 .../.../X2009307/y2009307367.ext
172 .../.../X2009307/Y2009307367.ext
172 .../.../X2009307/Y2009307367.ext
173 siendo para este caso, la ultima combinacion de letras, identica al file buscado
173 siendo para este caso, la ultima combinacion de letras, identica al file buscado
174
174
175 Return:
175 Return:
176 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
176 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
177 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
177 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
178 para el filename
178 para el filename
179 """
179 """
180 fullfilename = None
180 fullfilename = None
181 find_flag = False
181 find_flag = False
182 filename = None
182 filename = None
183
183
184 prefixDirList = [None,'d','D']
184 prefixDirList = [None,'d','D']
185 if ext.lower() == ".r": #voltage
185 if ext.lower() == ".r": #voltage
186 prefixFileList = ['d','D']
186 prefixFileList = ['d','D']
187 elif ext.lower() == ".pdata": #spectra
187 elif ext.lower() == ".pdata": #spectra
188 prefixFileList = ['p','P']
188 prefixFileList = ['p','P']
189 else:
189 else:
190 return None, filename
190 return None, filename
191
191
192 #barrido por las combinaciones posibles
192 #barrido por las combinaciones posibles
193 for prefixDir in prefixDirList:
193 for prefixDir in prefixDirList:
194 thispath = path
194 thispath = path
195 if prefixDir != None:
195 if prefixDir != None:
196 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
196 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
197 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
197 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
198
198
199 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
199 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
200 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
200 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
201 fullfilename = os.path.join( thispath, filename ) #formo el path completo
201 fullfilename = os.path.join( thispath, filename ) #formo el path completo
202
202
203 if os.path.exists( fullfilename ): #verifico que exista
203 if os.path.exists( fullfilename ): #verifico que exista
204 find_flag = True
204 find_flag = True
205 break
205 break
206 if find_flag:
206 if find_flag:
207 break
207 break
208
208
209 if not(find_flag):
209 if not(find_flag):
210 return None, filename
210 return None, filename
211
211
212 return fullfilename, filename
212 return fullfilename, filename
213
213
214 class JRODataIO:
214 class JRODataIO:
215
215
216 c = 3E8
216 c = 3E8
217
217
218 isConfig = False
218 isConfig = False
219
219
220 basicHeaderObj = BasicHeader()
220 basicHeaderObj = BasicHeader()
221
221
222 systemHeaderObj = SystemHeader()
222 systemHeaderObj = SystemHeader()
223
223
224 radarControllerHeaderObj = RadarControllerHeader()
224 radarControllerHeaderObj = RadarControllerHeader()
225
225
226 processingHeaderObj = ProcessingHeader()
226 processingHeaderObj = ProcessingHeader()
227
227
228 online = 0
228 online = 0
229
229
230 dtype = None
230 dtype = None
231
231
232 pathList = []
232 pathList = []
233
233
234 filenameList = []
234 filenameList = []
235
235
236 filename = None
236 filename = None
237
237
238 ext = None
238 ext = None
239
239
240 flagIsNewFile = 1
240 flagIsNewFile = 1
241
241
242 flagTimeBlock = 0
242 flagTimeBlock = 0
243
243
244 flagIsNewBlock = 0
244 flagIsNewBlock = 0
245
245
246 fp = None
246 fp = None
247
247
248 firstHeaderSize = 0
248 firstHeaderSize = 0
249
249
250 basicHeaderSize = 24
250 basicHeaderSize = 24
251
251
252 versionFile = 1103
252 versionFile = 1103
253
253
254 fileSize = None
254 fileSize = None
255
255
256 ippSeconds = None
256 ippSeconds = None
257
257
258 fileSizeByHeader = None
258 fileSizeByHeader = None
259
259
260 fileIndex = None
260 fileIndex = None
261
261
262 profileIndex = None
262 profileIndex = None
263
263
264 blockIndex = None
264 blockIndex = None
265
265
266 nTotalBlocks = None
266 nTotalBlocks = None
267
267
268 maxTimeStep = 30
268 maxTimeStep = 30
269
269
270 lastUTTime = None
270 lastUTTime = None
271
271
272 datablock = None
272 datablock = None
273
273
274 dataOut = None
274 dataOut = None
275
275
276 blocksize = None
276 blocksize = None
277
277
278 def __init__(self):
278 def __init__(self):
279
279
280 raise ValueError, "Not implemented"
280 raise ValueError, "Not implemented"
281
281
282 def run(self):
282 def run(self):
283
283
284 raise ValueError, "Not implemented"
284 raise ValueError, "Not implemented"
285
285
286 def getOutput(self):
286 def getOutput(self):
287
287
288 return self.dataOut
288 return self.dataOut
289
289
290 class JRODataReader(JRODataIO, ProcessingUnit):
290 class JRODataReader(JRODataIO, ProcessingUnit):
291
291
292 nReadBlocks = 0
292 nReadBlocks = 0
293
293
294 delay = 10 #number of seconds waiting a new file
294 delay = 10 #number of seconds waiting a new file
295
295
296 nTries = 3 #quantity tries
296 nTries = 3 #quantity tries
297
297
298 nFiles = 3 #number of files for searching
298 nFiles = 3 #number of files for searching
299
299
300 flagNoMoreFiles = 0
300 flagNoMoreFiles = 0
301
301
302 def __init__(self):
302 def __init__(self):
303
303
304 """
304 """
305
305
306 """
306 """
307
307
308 raise ValueError, "This method has not been implemented"
308 raise ValueError, "This method has not been implemented"
309
309
310
310
311 def createObjByDefault(self):
311 def createObjByDefault(self):
312 """
312 """
313
313
314 """
314 """
315 raise ValueError, "This method has not been implemented"
315 raise ValueError, "This method has not been implemented"
316
316
317 def getBlockDimension(self):
317 def getBlockDimension(self):
318
318
319 raise ValueError, "No implemented"
319 raise ValueError, "No implemented"
320
320
321 def __searchFilesOffLine(self,
321 def __searchFilesOffLine(self,
322 path,
322 path,
323 startDate,
323 startDate,
324 endDate,
324 endDate,
325 startTime=datetime.time(0,0,0),
325 startTime=datetime.time(0,0,0),
326 endTime=datetime.time(23,59,59),
326 endTime=datetime.time(23,59,59),
327 set=None,
327 set=None,
328 expLabel='',
328 expLabel='',
329 ext='.r',
329 ext='.r',
330 walk=True):
330 walk=True):
331
331
332 pathList = []
332 pathList = []
333
333
334 if not walk:
334 if not walk:
335 pathList.append(path)
335 pathList.append(path)
336
336
337 else:
337 else:
338 dirList = []
338 dirList = []
339 for thisPath in os.listdir(path):
339 for thisPath in os.listdir(path):
340 if os.path.isdir(os.path.join(path,thisPath)):
340 if os.path.isdir(os.path.join(path,thisPath)):
341 dirList.append(thisPath)
341 dirList.append(thisPath)
342
342
343 if not(dirList):
343 if not(dirList):
344 return None, None
344 return None, None
345
345
346 thisDate = startDate
346 thisDate = startDate
347
347
348 while(thisDate <= endDate):
348 while(thisDate <= endDate):
349 year = thisDate.timetuple().tm_year
349 year = thisDate.timetuple().tm_year
350 doy = thisDate.timetuple().tm_yday
350 doy = thisDate.timetuple().tm_yday
351
351
352 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
352 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
353 if len(match) == 0:
353 if len(match) == 0:
354 thisDate += datetime.timedelta(1)
354 thisDate += datetime.timedelta(1)
355 continue
355 continue
356
356
357 pathList.append(os.path.join(path,match[0],expLabel))
357 pathList.append(os.path.join(path,match[0],expLabel))
358 thisDate += datetime.timedelta(1)
358 thisDate += datetime.timedelta(1)
359
359
360 if pathList == []:
360 if pathList == []:
361 print "Any folder found into date range %s-%s" %(startDate, endDate)
361 print "Any folder found into date range %s-%s" %(startDate, endDate)
362 return None, None
362 return None, None
363
363
364 print "%d folder(s) found [%s, ...]" %(len(pathList), pathList[0])
364 print "%d folder(s) found [%s, ...]" %(len(pathList), pathList[0])
365
365
366 filenameList = []
366 filenameList = []
367 for thisPath in pathList:
367 for thisPath in pathList:
368
368
369 fileList = glob.glob1(thisPath, "*%s" %ext)
369 fileList = glob.glob1(thisPath, "*%s" %ext)
370 fileList.sort()
370 fileList.sort()
371
371
372 for file in fileList:
372 for file in fileList:
373
373
374 filename = os.path.join(thisPath,file)
374 filename = os.path.join(thisPath,file)
375
375
376 if isFileinThisTime(filename, startTime, endTime):
376 if isFileinThisTime(filename, startTime, endTime):
377 filenameList.append(filename)
377 filenameList.append(filename)
378
378
379 if not(filenameList):
379 if not(filenameList):
380 print "Any file found into time range %s-%s" %(startTime, endTime)
380 print "Any file found into time range %s-%s" %(startTime, endTime)
381 return None, None
381 return None, None
382
382
383 self.filenameList = filenameList
383 self.filenameList = filenameList
384
384
385 return pathList, filenameList
385 return pathList, filenameList
386
386
387 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
387 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
388
388
389 """
389 """
390 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
390 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
391 devuelve el archivo encontrado ademas de otros datos.
391 devuelve el archivo encontrado ademas de otros datos.
392
392
393 Input:
393 Input:
394 path : carpeta donde estan contenidos los files que contiene data
394 path : carpeta donde estan contenidos los files que contiene data
395
395
396 expLabel : Nombre del subexperimento (subfolder)
396 expLabel : Nombre del subexperimento (subfolder)
397
397
398 ext : extension de los files
398 ext : extension de los files
399
399
400 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
400 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
401
401
402 Return:
402 Return:
403 directory : eL directorio donde esta el file encontrado
403 directory : eL directorio donde esta el file encontrado
404 filename : el ultimo file de una determinada carpeta
404 filename : el ultimo file de una determinada carpeta
405 year : el anho
405 year : el anho
406 doy : el numero de dia del anho
406 doy : el numero de dia del anho
407 set : el set del archivo
407 set : el set del archivo
408
408
409
409
410 """
410 """
411 dirList = []
411 dirList = []
412
412
413 if walk:
413 if walk:
414
414
415 #Filtra solo los directorios
415 #Filtra solo los directorios
416 for thisPath in os.listdir(path):
416 for thisPath in os.listdir(path):
417 if os.path.isdir(os.path.join(path, thisPath)):
417 if os.path.isdir(os.path.join(path, thisPath)):
418 dirList.append(thisPath)
418 dirList.append(thisPath)
419
419
420 if not(dirList):
420 if not(dirList):
421 return None, None, None, None, None
421 return None, None, None, None, None
422
422
423 dirList = sorted( dirList, key=str.lower )
423 dirList = sorted( dirList, key=str.lower )
424
424
425 doypath = dirList[-1]
425 doypath = dirList[-1]
426 fullpath = os.path.join(path, doypath, expLabel)
426 fullpath = os.path.join(path, doypath, expLabel)
427
427
428 else:
428 else:
429 fullpath = path
429 fullpath = path
430
430
431 filename = getlastFileFromPath(fullpath, ext)
431 filename = getlastFileFromPath(fullpath, ext)
432
432
433 if not(filename):
433 if not(filename):
434 return None, None, None, None, None
434 return None, None, None, None, None
435
435
436 if not(self.__verifyFile(os.path.join(fullpath, filename))):
436 if not(self.__verifyFile(os.path.join(fullpath, filename))):
437 return None, None, None, None, None
437 return None, None, None, None, None
438
438
439 year = int( filename[1:5] )
439 year = int( filename[1:5] )
440 doy = int( filename[5:8] )
440 doy = int( filename[5:8] )
441 set = int( filename[8:11] )
441 set = int( filename[8:11] )
442
442
443 return fullpath, filename, year, doy, set
443 return fullpath, filename, year, doy, set
444
444
445
445
446
446
447 def __setNextFileOffline(self):
447 def __setNextFileOffline(self):
448
448
449 idFile = self.fileIndex
449 idFile = self.fileIndex
450
450
451 while (True):
451 while (True):
452 idFile += 1
452 idFile += 1
453 if not(idFile < len(self.filenameList)):
453 if not(idFile < len(self.filenameList)):
454 self.flagNoMoreFiles = 1
454 self.flagNoMoreFiles = 1
455 print "No more Files"
455 print "No more Files"
456 return 0
456 return 0
457
457
458 filename = self.filenameList[idFile]
458 filename = self.filenameList[idFile]
459
459
460 if not(self.__verifyFile(filename)):
460 if not(self.__verifyFile(filename)):
461 continue
461 continue
462
462
463 fileSize = os.path.getsize(filename)
463 fileSize = os.path.getsize(filename)
464 fp = open(filename,'rb')
464 fp = open(filename,'rb')
465 break
465 break
466
466
467 self.flagIsNewFile = 1
467 self.flagIsNewFile = 1
468 self.fileIndex = idFile
468 self.fileIndex = idFile
469 self.filename = filename
469 self.filename = filename
470 self.fileSize = fileSize
470 self.fileSize = fileSize
471 self.fp = fp
471 self.fp = fp
472
472
473 print "Setting the file: %s"%self.filename
473 print "Setting the file: %s"%self.filename
474
474
475 return 1
475 return 1
476
476
477 def __setNextFileOnline(self):
477 def __setNextFileOnline(self):
478 """
478 """
479 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
479 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
480 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
480 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
481 siguientes.
481 siguientes.
482
482
483 Affected:
483 Affected:
484 self.flagIsNewFile
484 self.flagIsNewFile
485 self.filename
485 self.filename
486 self.fileSize
486 self.fileSize
487 self.fp
487 self.fp
488 self.set
488 self.set
489 self.flagNoMoreFiles
489 self.flagNoMoreFiles
490
490
491 Return:
491 Return:
492 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
492 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
493 1 : si el file fue abierto con exito y esta listo a ser leido
493 1 : si el file fue abierto con exito y esta listo a ser leido
494
494
495 Excepciones:
495 Excepciones:
496 Si un determinado file no puede ser abierto
496 Si un determinado file no puede ser abierto
497 """
497 """
498 nFiles = 0
498 nFiles = 0
499 fileOk_flag = False
499 fileOk_flag = False
500 firstTime_flag = True
500 firstTime_flag = True
501
501
502 self.set += 1
502 self.set += 1
503
503
504 #busca el 1er file disponible
504 #busca el 1er file disponible
505 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
505 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
506 if fullfilename:
506 if fullfilename:
507 if self.__verifyFile(fullfilename, False):
507 if self.__verifyFile(fullfilename, False):
508 fileOk_flag = True
508 fileOk_flag = True
509
509
510 #si no encuentra un file entonces espera y vuelve a buscar
510 #si no encuentra un file entonces espera y vuelve a buscar
511 if not(fileOk_flag):
511 if not(fileOk_flag):
512 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
512 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
513
513
514 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
514 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
515 tries = self.nTries
515 tries = self.nTries
516 else:
516 else:
517 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
517 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
518
518
519 for nTries in range( tries ):
519 for nTries in range( tries ):
520 if firstTime_flag:
520 if firstTime_flag:
521 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
521 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
522 time.sleep( self.delay )
522 time.sleep( self.delay )
523 else:
523 else:
524 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
524 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
525
525
526 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
526 fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext )
527 if fullfilename:
527 if fullfilename:
528 if self.__verifyFile(fullfilename):
528 if self.__verifyFile(fullfilename):
529 fileOk_flag = True
529 fileOk_flag = True
530 break
530 break
531
531
532 if fileOk_flag:
532 if fileOk_flag:
533 break
533 break
534
534
535 firstTime_flag = False
535 firstTime_flag = False
536
536
537 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
537 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
538 self.set += 1
538 self.set += 1
539
539
540 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
540 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
541 self.set = 0
541 self.set = 0
542 self.doy += 1
542 self.doy += 1
543
543
544 if fileOk_flag:
544 if fileOk_flag:
545 self.fileSize = os.path.getsize( fullfilename )
545 self.fileSize = os.path.getsize( fullfilename )
546 self.filename = fullfilename
546 self.filename = fullfilename
547 self.flagIsNewFile = 1
547 self.flagIsNewFile = 1
548 if self.fp != None: self.fp.close()
548 if self.fp != None: self.fp.close()
549 self.fp = open(fullfilename, 'rb')
549 self.fp = open(fullfilename, 'rb')
550 self.flagNoMoreFiles = 0
550 self.flagNoMoreFiles = 0
551 print 'Setting the file: %s' % fullfilename
551 print 'Setting the file: %s' % fullfilename
552 else:
552 else:
553 self.fileSize = 0
553 self.fileSize = 0
554 self.filename = None
554 self.filename = None
555 self.flagIsNewFile = 0
555 self.flagIsNewFile = 0
556 self.fp = None
556 self.fp = None
557 self.flagNoMoreFiles = 1
557 self.flagNoMoreFiles = 1
558 print 'No more Files'
558 print 'No more Files'
559
559
560 return fileOk_flag
560 return fileOk_flag
561
561
562
562
563 def setNextFile(self):
563 def setNextFile(self):
564 if self.fp != None:
564 if self.fp != None:
565 self.fp.close()
565 self.fp.close()
566
566
567 if self.online:
567 if self.online:
568 newFile = self.__setNextFileOnline()
568 newFile = self.__setNextFileOnline()
569 else:
569 else:
570 newFile = self.__setNextFileOffline()
570 newFile = self.__setNextFileOffline()
571
571
572 if not(newFile):
572 if not(newFile):
573 return 0
573 return 0
574
574
575 self.__readFirstHeader()
575 self.__readFirstHeader()
576 self.nReadBlocks = 0
576 self.nReadBlocks = 0
577 return 1
577 return 1
578
578
579 def __waitNewBlock(self):
579 def __waitNewBlock(self):
580 """
580 """
581 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
581 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
582
582
583 Si el modo de lectura es OffLine siempre retorn 0
583 Si el modo de lectura es OffLine siempre retorn 0
584 """
584 """
585 if not self.online:
585 if not self.online:
586 return 0
586 return 0
587
587
588 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
588 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
589 return 0
589 return 0
590
590
591 currentPointer = self.fp.tell()
591 currentPointer = self.fp.tell()
592
592
593 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
593 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
594
594
595 for nTries in range( self.nTries ):
595 for nTries in range( self.nTries ):
596
596
597 self.fp.close()
597 self.fp.close()
598 self.fp = open( self.filename, 'rb' )
598 self.fp = open( self.filename, 'rb' )
599 self.fp.seek( currentPointer )
599 self.fp.seek( currentPointer )
600
600
601 self.fileSize = os.path.getsize( self.filename )
601 self.fileSize = os.path.getsize( self.filename )
602 currentSize = self.fileSize - currentPointer
602 currentSize = self.fileSize - currentPointer
603
603
604 if ( currentSize >= neededSize ):
604 if ( currentSize >= neededSize ):
605 self.__rdBasicHeader()
605 self.__rdBasicHeader()
606 return 1
606 return 1
607
607
608 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
608 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
609 time.sleep( self.delay )
609 time.sleep( self.delay )
610
610
611
611
612 return 0
612 return 0
613
613
614 def __setNewBlock(self):
614 def __setNewBlock(self):
615
615
616 if self.fp == None:
616 if self.fp == None:
617 return 0
617 return 0
618
618
619 if self.flagIsNewFile:
619 if self.flagIsNewFile:
620 return 1
620 return 1
621
621
622 self.lastUTTime = self.basicHeaderObj.utc
622 self.lastUTTime = self.basicHeaderObj.utc
623 currentSize = self.fileSize - self.fp.tell()
623 currentSize = self.fileSize - self.fp.tell()
624 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
624 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
625
625
626 if (currentSize >= neededSize):
626 if (currentSize >= neededSize):
627 self.__rdBasicHeader()
627 self.__rdBasicHeader()
628 return 1
628 return 1
629
629
630 if self.__waitNewBlock():
630 if self.__waitNewBlock():
631 return 1
631 return 1
632
632
633 if not(self.setNextFile()):
633 if not(self.setNextFile()):
634 return 0
634 return 0
635
635
636 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
636 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
637
637
638 self.flagTimeBlock = 0
638 self.flagTimeBlock = 0
639
639
640 if deltaTime > self.maxTimeStep:
640 if deltaTime > self.maxTimeStep:
641 self.flagTimeBlock = 1
641 self.flagTimeBlock = 1
642
642
643 return 1
643 return 1
644
644
645
645
646 def readNextBlock(self):
646 def readNextBlock(self):
647 if not(self.__setNewBlock()):
647 if not(self.__setNewBlock()):
648 return 0
648 return 0
649
649
650 if not(self.readBlock()):
650 if not(self.readBlock()):
651 return 0
651 return 0
652
652
653 return 1
653 return 1
654
654
655 def __rdProcessingHeader(self, fp=None):
655 def __rdProcessingHeader(self, fp=None):
656 if fp == None:
656 if fp == None:
657 fp = self.fp
657 fp = self.fp
658
658
659 self.processingHeaderObj.read(fp)
659 self.processingHeaderObj.read(fp)
660
660
661 def __rdRadarControllerHeader(self, fp=None):
661 def __rdRadarControllerHeader(self, fp=None):
662 if fp == None:
662 if fp == None:
663 fp = self.fp
663 fp = self.fp
664
664
665 self.radarControllerHeaderObj.read(fp)
665 self.radarControllerHeaderObj.read(fp)
666
666
667 def __rdSystemHeader(self, fp=None):
667 def __rdSystemHeader(self, fp=None):
668 if fp == None:
668 if fp == None:
669 fp = self.fp
669 fp = self.fp
670
670
671 self.systemHeaderObj.read(fp)
671 self.systemHeaderObj.read(fp)
672
672
673 def __rdBasicHeader(self, fp=None):
673 def __rdBasicHeader(self, fp=None):
674 if fp == None:
674 if fp == None:
675 fp = self.fp
675 fp = self.fp
676
676
677 self.basicHeaderObj.read(fp)
677 self.basicHeaderObj.read(fp)
678
678
679
679
680 def __readFirstHeader(self):
680 def __readFirstHeader(self):
681 self.__rdBasicHeader()
681 self.__rdBasicHeader()
682 self.__rdSystemHeader()
682 self.__rdSystemHeader()
683 self.__rdRadarControllerHeader()
683 self.__rdRadarControllerHeader()
684 self.__rdProcessingHeader()
684 self.__rdProcessingHeader()
685
685
686 self.firstHeaderSize = self.basicHeaderObj.size
686 self.firstHeaderSize = self.basicHeaderObj.size
687
687
688 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
688 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
689 if datatype == 0:
689 if datatype == 0:
690 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
690 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
691 elif datatype == 1:
691 elif datatype == 1:
692 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
692 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
693 elif datatype == 2:
693 elif datatype == 2:
694 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
694 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
695 elif datatype == 3:
695 elif datatype == 3:
696 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
696 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
697 elif datatype == 4:
697 elif datatype == 4:
698 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
698 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
699 elif datatype == 5:
699 elif datatype == 5:
700 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
700 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
701 else:
701 else:
702 raise ValueError, 'Data type was not defined'
702 raise ValueError, 'Data type was not defined'
703
703
704 self.dtype = datatype_str
704 self.dtype = datatype_str
705 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
705 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
706 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
706 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
707 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
707 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
708 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
708 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
709 self.getBlockDimension()
709 self.getBlockDimension()
710
710
711
711
712 def __verifyFile(self, filename, msgFlag=True):
712 def __verifyFile(self, filename, msgFlag=True):
713 msg = None
713 msg = None
714 try:
714 try:
715 fp = open(filename, 'rb')
715 fp = open(filename, 'rb')
716 currentPosition = fp.tell()
716 currentPosition = fp.tell()
717 except:
717 except:
718 if msgFlag:
718 if msgFlag:
719 print "The file %s can't be opened" % (filename)
719 print "The file %s can't be opened" % (filename)
720 return False
720 return False
721
721
722 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
722 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
723
723
724 if neededSize == 0:
724 if neededSize == 0:
725 basicHeaderObj = BasicHeader()
725 basicHeaderObj = BasicHeader()
726 systemHeaderObj = SystemHeader()
726 systemHeaderObj = SystemHeader()
727 radarControllerHeaderObj = RadarControllerHeader()
727 radarControllerHeaderObj = RadarControllerHeader()
728 processingHeaderObj = ProcessingHeader()
728 processingHeaderObj = ProcessingHeader()
729
729
730 try:
730 try:
731 if not( basicHeaderObj.read(fp) ): raise IOError
731 if not( basicHeaderObj.read(fp) ): raise IOError
732 if not( systemHeaderObj.read(fp) ): raise IOError
732 if not( systemHeaderObj.read(fp) ): raise IOError
733 if not( radarControllerHeaderObj.read(fp) ): raise IOError
733 if not( radarControllerHeaderObj.read(fp) ): raise IOError
734 if not( processingHeaderObj.read(fp) ): raise IOError
734 if not( processingHeaderObj.read(fp) ): raise IOError
735 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
735 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
736
736
737 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
737 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
738
738
739 except:
739 except:
740 if msgFlag:
740 if msgFlag:
741 print "\tThe file %s is empty or it hasn't enough data" % filename
741 print "\tThe file %s is empty or it hasn't enough data" % filename
742
742
743 fp.close()
743 fp.close()
744 return False
744 return False
745 else:
745 else:
746 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
746 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
747
747
748 fp.close()
748 fp.close()
749 fileSize = os.path.getsize(filename)
749 fileSize = os.path.getsize(filename)
750 currentSize = fileSize - currentPosition
750 currentSize = fileSize - currentPosition
751 if currentSize < neededSize:
751 if currentSize < neededSize:
752 if msgFlag and (msg != None):
752 if msgFlag and (msg != None):
753 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
753 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
754 return False
754 return False
755
755
756 return True
756 return True
757
757
758 def setup(self,
758 def setup(self,
759 path=None,
759 path=None,
760 startDate=None,
760 startDate=None,
761 endDate=None,
761 endDate=None,
762 startTime=datetime.time(0,0,0),
762 startTime=datetime.time(0,0,0),
763 endTime=datetime.time(23,59,59),
763 endTime=datetime.time(23,59,59),
764 set=0,
764 set=0,
765 expLabel = "",
765 expLabel = "",
766 ext = None,
766 ext = None,
767 online = False,
767 online = False,
768 delay = 60,
768 delay = 60,
769 walk = True):
769 walk = True):
770
770
771 if path == None:
771 if path == None:
772 raise ValueError, "The path is not valid"
772 raise ValueError, "The path is not valid"
773
773
774 if ext == None:
774 if ext == None:
775 ext = self.ext
775 ext = self.ext
776
776
777 if online:
777 if online:
778 print "Searching files in online mode..."
778 print "Searching files in online mode..."
779
779
780 for nTries in range( self.nTries ):
780 for nTries in range( self.nTries ):
781 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
781 fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
782
782
783 if fullpath:
783 if fullpath:
784 break
784 break
785
785
786 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
786 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
787 time.sleep( self.delay )
787 time.sleep( self.delay )
788
788
789 if not(fullpath):
789 if not(fullpath):
790 print "There 'isn't valied files in %s" % path
790 print "There 'isn't valied files in %s" % path
791 return None
791 return None
792
792
793 self.year = year
793 self.year = year
794 self.doy = doy
794 self.doy = doy
795 self.set = set - 1
795 self.set = set - 1
796 self.path = path
796 self.path = path
797
797
798 else:
798 else:
799 print "Searching files in offline mode ..."
799 print "Searching files in offline mode ..."
800 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
800 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
801 startTime=startTime, endTime=endTime,
801 startTime=startTime, endTime=endTime,
802 set=set, expLabel=expLabel, ext=ext,
802 set=set, expLabel=expLabel, ext=ext,
803 walk=walk)
803 walk=walk)
804
804
805 if not(pathList):
805 if not(pathList):
806 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
806 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
807 datetime.datetime.combine(startDate,startTime).ctime(),
807 datetime.datetime.combine(startDate,startTime).ctime(),
808 datetime.datetime.combine(endDate,endTime).ctime())
808 datetime.datetime.combine(endDate,endTime).ctime())
809
809
810 sys.exit(-1)
810 sys.exit(-1)
811
811
812
812
813 self.fileIndex = -1
813 self.fileIndex = -1
814 self.pathList = pathList
814 self.pathList = pathList
815 self.filenameList = filenameList
815 self.filenameList = filenameList
816
816
817 self.online = online
817 self.online = online
818 self.delay = delay
818 self.delay = delay
819 ext = ext.lower()
819 ext = ext.lower()
820 self.ext = ext
820 self.ext = ext
821
821
822 if not(self.setNextFile()):
822 if not(self.setNextFile()):
823 if (startDate!=None) and (endDate!=None):
823 if (startDate!=None) and (endDate!=None):
824 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
824 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
825 elif startDate != None:
825 elif startDate != None:
826 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
826 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
827 else:
827 else:
828 print "No files"
828 print "No files"
829
829
830 sys.exit(-1)
830 sys.exit(-1)
831
831
832 # self.updateDataHeader()
832 # self.updateDataHeader()
833
833
834 return self.dataOut
834 return self.dataOut
835
835
836 def getData():
836 def getData():
837
837
838 raise ValueError, "This method has not been implemented"
838 raise ValueError, "This method has not been implemented"
839
839
840 def hasNotDataInBuffer():
840 def hasNotDataInBuffer():
841
841
842 raise ValueError, "This method has not been implemented"
842 raise ValueError, "This method has not been implemented"
843
843
844 def readBlock():
844 def readBlock():
845
845
846 raise ValueError, "This method has not been implemented"
846 raise ValueError, "This method has not been implemented"
847
847
848 def isEndProcess(self):
848 def isEndProcess(self):
849
849
850 return self.flagNoMoreFiles
850 return self.flagNoMoreFiles
851
851
852 def printReadBlocks(self):
852 def printReadBlocks(self):
853
853
854 print "Number of read blocks per file %04d" %self.nReadBlocks
854 print "Number of read blocks per file %04d" %self.nReadBlocks
855
855
856 def printTotalBlocks(self):
856 def printTotalBlocks(self):
857
857
858 print "Number of read blocks %04d" %self.nTotalBlocks
858 print "Number of read blocks %04d" %self.nTotalBlocks
859
859
860 def printInfo(self):
860 def printInfo(self):
861
861
862 print self.basicHeaderObj.printInfo()
862 print self.basicHeaderObj.printInfo()
863 print self.systemHeaderObj.printInfo()
863 print self.systemHeaderObj.printInfo()
864 print self.radarControllerHeaderObj.printInfo()
864 print self.radarControllerHeaderObj.printInfo()
865 print self.processingHeaderObj.printInfo()
865 print self.processingHeaderObj.printInfo()
866
866
867
867
868 def run(self, **kwargs):
868 def run(self, **kwargs):
869
869
870 if not(self.isConfig):
870 if not(self.isConfig):
871
871
872 # self.dataOut = dataOut
872 # self.dataOut = dataOut
873 self.setup(**kwargs)
873 self.setup(**kwargs)
874 self.isConfig = True
874 self.isConfig = True
875
875
876 self.getData()
876 self.getData()
877
877
878 class JRODataWriter(JRODataIO, Operation):
878 class JRODataWriter(JRODataIO, Operation):
879
879
880 """
880 """
881 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
881 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
882 de los datos siempre se realiza por bloques.
882 de los datos siempre se realiza por bloques.
883 """
883 """
884
884
885 blockIndex = 0
885 blockIndex = 0
886
886
887 path = None
887 path = None
888
888
889 setFile = None
889 setFile = None
890
890
891 profilesPerBlock = None
891 profilesPerBlock = None
892
892
893 blocksPerFile = None
893 blocksPerFile = None
894
894
895 nWriteBlocks = 0
895 nWriteBlocks = 0
896
896
897 def __init__(self, dataOut=None):
897 def __init__(self, dataOut=None):
898 raise ValueError, "Not implemented"
898 raise ValueError, "Not implemented"
899
899
900
900
901 def hasAllDataInBuffer(self):
901 def hasAllDataInBuffer(self):
902 raise ValueError, "Not implemented"
902 raise ValueError, "Not implemented"
903
903
904
904
905 def setBlockDimension(self):
905 def setBlockDimension(self):
906 raise ValueError, "Not implemented"
906 raise ValueError, "Not implemented"
907
907
908
908
909 def writeBlock(self):
909 def writeBlock(self):
910 raise ValueError, "No implemented"
910 raise ValueError, "No implemented"
911
911
912
912
913 def putData(self):
913 def putData(self):
914 raise ValueError, "No implemented"
914 raise ValueError, "No implemented"
915
915
916 def getDataHeader(self):
916 def getDataHeader(self):
917 """
917 """
918 Obtiene una copia del First Header
918 Obtiene una copia del First Header
919
919
920 Affected:
920 Affected:
921
921
922 self.basicHeaderObj
922 self.basicHeaderObj
923 self.systemHeaderObj
923 self.systemHeaderObj
924 self.radarControllerHeaderObj
924 self.radarControllerHeaderObj
925 self.processingHeaderObj self.
925 self.processingHeaderObj self.
926
926
927 Return:
927 Return:
928 None
928 None
929 """
929 """
930
930
931 raise ValueError, "No implemented"
931 raise ValueError, "No implemented"
932
932
933 def getBasicHeader(self):
933 def getBasicHeader(self):
934
934
935 self.basicHeaderObj.size = self.basicHeaderSize #bytes
935 self.basicHeaderObj.size = self.basicHeaderSize #bytes
936 self.basicHeaderObj.version = self.versionFile
936 self.basicHeaderObj.version = self.versionFile
937 self.basicHeaderObj.dataBlock = self.nTotalBlocks
937 self.basicHeaderObj.dataBlock = self.nTotalBlocks
938
938
939 utc = numpy.floor(self.dataOut.utctime)
939 utc = numpy.floor(self.dataOut.utctime)
940 milisecond = (self.dataOut.utctime - utc)* 1000.0
940 milisecond = (self.dataOut.utctime - utc)* 1000.0
941
941
942 self.basicHeaderObj.utc = utc
942 self.basicHeaderObj.utc = utc
943 self.basicHeaderObj.miliSecond = milisecond
943 self.basicHeaderObj.miliSecond = milisecond
944 self.basicHeaderObj.timeZone = 0
944 self.basicHeaderObj.timeZone = 0
945 self.basicHeaderObj.dstFlag = 0
945 self.basicHeaderObj.dstFlag = 0
946 self.basicHeaderObj.errorCount = 0
946 self.basicHeaderObj.errorCount = 0
947
947
948 def __writeFirstHeader(self):
948 def __writeFirstHeader(self):
949 """
949 """
950 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
950 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
951
951
952 Affected:
952 Affected:
953 __dataType
953 __dataType
954
954
955 Return:
955 Return:
956 None
956 None
957 """
957 """
958
958
959 # CALCULAR PARAMETROS
959 # CALCULAR PARAMETROS
960
960
961 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
961 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
962 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
962 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
963
963
964 self.basicHeaderObj.write(self.fp)
964 self.basicHeaderObj.write(self.fp)
965 self.systemHeaderObj.write(self.fp)
965 self.systemHeaderObj.write(self.fp)
966 self.radarControllerHeaderObj.write(self.fp)
966 self.radarControllerHeaderObj.write(self.fp)
967 self.processingHeaderObj.write(self.fp)
967 self.processingHeaderObj.write(self.fp)
968
968
969 self.dtype = self.dataOut.dtype
969 self.dtype = self.dataOut.dtype
970
970
971 def __setNewBlock(self):
971 def __setNewBlock(self):
972 """
972 """
973 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
973 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
974
974
975 Return:
975 Return:
976 0 : si no pudo escribir nada
976 0 : si no pudo escribir nada
977 1 : Si escribio el Basic el First Header
977 1 : Si escribio el Basic el First Header
978 """
978 """
979 if self.fp == None:
979 if self.fp == None:
980 self.setNextFile()
980 self.setNextFile()
981
981
982 if self.flagIsNewFile:
982 if self.flagIsNewFile:
983 return 1
983 return 1
984
984
985 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
985 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
986 self.basicHeaderObj.write(self.fp)
986 self.basicHeaderObj.write(self.fp)
987 return 1
987 return 1
988
988
989 if not( self.setNextFile() ):
989 if not( self.setNextFile() ):
990 return 0
990 return 0
991
991
992 return 1
992 return 1
993
993
994
994
995 def writeNextBlock(self):
995 def writeNextBlock(self):
996 """
996 """
997 Selecciona el bloque siguiente de datos y los escribe en un file
997 Selecciona el bloque siguiente de datos y los escribe en un file
998
998
999 Return:
999 Return:
1000 0 : Si no hizo pudo escribir el bloque de datos
1000 0 : Si no hizo pudo escribir el bloque de datos
1001 1 : Si no pudo escribir el bloque de datos
1001 1 : Si no pudo escribir el bloque de datos
1002 """
1002 """
1003 if not( self.__setNewBlock() ):
1003 if not( self.__setNewBlock() ):
1004 return 0
1004 return 0
1005
1005
1006 self.writeBlock()
1006 self.writeBlock()
1007
1007
1008 return 1
1008 return 1
1009
1009
1010 def setNextFile(self):
1010 def setNextFile(self):
1011 """
1011 """
1012 Determina el siguiente file que sera escrito
1012 Determina el siguiente file que sera escrito
1013
1013
1014 Affected:
1014 Affected:
1015 self.filename
1015 self.filename
1016 self.subfolder
1016 self.subfolder
1017 self.fp
1017 self.fp
1018 self.setFile
1018 self.setFile
1019 self.flagIsNewFile
1019 self.flagIsNewFile
1020
1020
1021 Return:
1021 Return:
1022 0 : Si el archivo no puede ser escrito
1022 0 : Si el archivo no puede ser escrito
1023 1 : Si el archivo esta listo para ser escrito
1023 1 : Si el archivo esta listo para ser escrito
1024 """
1024 """
1025 ext = self.ext
1025 ext = self.ext
1026 path = self.path
1026 path = self.path
1027
1027
1028 if self.fp != None:
1028 if self.fp != None:
1029 self.fp.close()
1029 self.fp.close()
1030
1030
1031 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1031 timeTuple = time.localtime( self.dataOut.dataUtcTime)
1032 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1032 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1033
1033
1034 fullpath = os.path.join( path, subfolder )
1034 fullpath = os.path.join( path, subfolder )
1035 if not( os.path.exists(fullpath) ):
1035 if not( os.path.exists(fullpath) ):
1036 os.mkdir(fullpath)
1036 os.mkdir(fullpath)
1037 self.setFile = -1 #inicializo mi contador de seteo
1037 self.setFile = -1 #inicializo mi contador de seteo
1038 else:
1038 else:
1039 filesList = os.listdir( fullpath )
1039 filesList = os.listdir( fullpath )
1040 if len( filesList ) > 0:
1040 if len( filesList ) > 0:
1041 filesList = sorted( filesList, key=str.lower )
1041 filesList = sorted( filesList, key=str.lower )
1042 filen = filesList[-1]
1042 filen = filesList[-1]
1043 # el filename debera tener el siguiente formato
1043 # el filename debera tener el siguiente formato
1044 # 0 1234 567 89A BCDE (hex)
1044 # 0 1234 567 89A BCDE (hex)
1045 # x YYYY DDD SSS .ext
1045 # x YYYY DDD SSS .ext
1046 if isNumber( filen[8:11] ):
1046 if isNumber( filen[8:11] ):
1047 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1047 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1048 else:
1048 else:
1049 self.setFile = -1
1049 self.setFile = -1
1050 else:
1050 else:
1051 self.setFile = -1 #inicializo mi contador de seteo
1051 self.setFile = -1 #inicializo mi contador de seteo
1052
1052
1053 setFile = self.setFile
1053 setFile = self.setFile
1054 setFile += 1
1054 setFile += 1
1055
1055
1056 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1056 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1057 timeTuple.tm_year,
1057 timeTuple.tm_year,
1058 timeTuple.tm_yday,
1058 timeTuple.tm_yday,
1059 setFile,
1059 setFile,
1060 ext )
1060 ext )
1061
1061
1062 filename = os.path.join( path, subfolder, file )
1062 filename = os.path.join( path, subfolder, file )
1063
1063
1064 fp = open( filename,'wb' )
1064 fp = open( filename,'wb' )
1065
1065
1066 self.blockIndex = 0
1066 self.blockIndex = 0
1067
1067
1068 #guardando atributos
1068 #guardando atributos
1069 self.filename = filename
1069 self.filename = filename
1070 self.subfolder = subfolder
1070 self.subfolder = subfolder
1071 self.fp = fp
1071 self.fp = fp
1072 self.setFile = setFile
1072 self.setFile = setFile
1073 self.flagIsNewFile = 1
1073 self.flagIsNewFile = 1
1074
1074
1075 self.getDataHeader()
1075 self.getDataHeader()
1076
1076
1077 print 'Writing the file: %s'%self.filename
1077 print 'Writing the file: %s'%self.filename
1078
1078
1079 self.__writeFirstHeader()
1079 self.__writeFirstHeader()
1080
1080
1081 return 1
1081 return 1
1082
1082
1083 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1083 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1084 """
1084 """
1085 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1085 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1086
1086
1087 Inputs:
1087 Inputs:
1088 path : el path destino en el cual se escribiran los files a crear
1088 path : el path destino en el cual se escribiran los files a crear
1089 format : formato en el cual sera salvado un file
1089 format : formato en el cual sera salvado un file
1090 set : el setebo del file
1090 set : el setebo del file
1091
1091
1092 Return:
1092 Return:
1093 0 : Si no realizo un buen seteo
1093 0 : Si no realizo un buen seteo
1094 1 : Si realizo un buen seteo
1094 1 : Si realizo un buen seteo
1095 """
1095 """
1096
1096
1097 if ext == None:
1097 if ext == None:
1098 ext = self.ext
1098 ext = self.ext
1099
1099
1100 ext = ext.lower()
1100 ext = ext.lower()
1101
1101
1102 self.ext = ext
1102 self.ext = ext
1103
1103
1104 self.path = path
1104 self.path = path
1105
1105
1106 self.setFile = set - 1
1106 self.setFile = set - 1
1107
1107
1108 self.blocksPerFile = blocksPerFile
1108 self.blocksPerFile = blocksPerFile
1109
1109
1110 self.profilesPerBlock = profilesPerBlock
1110 self.profilesPerBlock = profilesPerBlock
1111
1111
1112 self.dataOut = dataOut
1112 self.dataOut = dataOut
1113
1113
1114 if not(self.setNextFile()):
1114 if not(self.setNextFile()):
1115 print "There isn't a next file"
1115 print "There isn't a next file"
1116 return 0
1116 return 0
1117
1117
1118 self.setBlockDimension()
1118 self.setBlockDimension()
1119
1119
1120 return 1
1120 return 1
1121
1121
1122 def run(self, dataOut, **kwargs):
1122 def run(self, dataOut, **kwargs):
1123
1123
1124 if not(self.isConfig):
1124 if not(self.isConfig):
1125
1125
1126 self.setup(dataOut, **kwargs)
1126 self.setup(dataOut, **kwargs)
1127 self.isConfig = True
1127 self.isConfig = True
1128
1128
1129 self.putData()
1129 self.putData()
1130
1130
1131 class VoltageReader(JRODataReader):
1131 class VoltageReader(JRODataReader):
1132 """
1132 """
1133 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1133 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1134 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1134 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1135 perfiles*alturas*canales) son almacenados en la variable "buffer".
1135 perfiles*alturas*canales) son almacenados en la variable "buffer".
1136
1136
1137 perfiles * alturas * canales
1137 perfiles * alturas * canales
1138
1138
1139 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1139 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1140 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1140 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1141 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1141 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1142 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1142 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1143
1143
1144 Example:
1144 Example:
1145
1145
1146 dpath = "/home/myuser/data"
1146 dpath = "/home/myuser/data"
1147
1147
1148 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1148 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1149
1149
1150 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1150 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1151
1151
1152 readerObj = VoltageReader()
1152 readerObj = VoltageReader()
1153
1153
1154 readerObj.setup(dpath, startTime, endTime)
1154 readerObj.setup(dpath, startTime, endTime)
1155
1155
1156 while(True):
1156 while(True):
1157
1157
1158 #to get one profile
1158 #to get one profile
1159 profile = readerObj.getData()
1159 profile = readerObj.getData()
1160
1160
1161 #print the profile
1161 #print the profile
1162 print profile
1162 print profile
1163
1163
1164 #If you want to see all datablock
1164 #If you want to see all datablock
1165 print readerObj.datablock
1165 print readerObj.datablock
1166
1166
1167 if readerObj.flagNoMoreFiles:
1167 if readerObj.flagNoMoreFiles:
1168 break
1168 break
1169
1169
1170 """
1170 """
1171
1171
1172 ext = ".r"
1172 ext = ".r"
1173
1173
1174 optchar = "D"
1174 optchar = "D"
1175 dataOut = None
1175 dataOut = None
1176
1176
1177
1177
1178 def __init__(self):
1178 def __init__(self):
1179 """
1179 """
1180 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1180 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1181
1181
1182 Input:
1182 Input:
1183 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1183 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1184 almacenar un perfil de datos cada vez que se haga un requerimiento
1184 almacenar un perfil de datos cada vez que se haga un requerimiento
1185 (getData). El perfil sera obtenido a partir del buffer de datos,
1185 (getData). El perfil sera obtenido a partir del buffer de datos,
1186 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1186 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1187 bloque de datos.
1187 bloque de datos.
1188 Si este parametro no es pasado se creara uno internamente.
1188 Si este parametro no es pasado se creara uno internamente.
1189
1189
1190 Variables afectadas:
1190 Variables afectadas:
1191 self.dataOut
1191 self.dataOut
1192
1192
1193 Return:
1193 Return:
1194 None
1194 None
1195 """
1195 """
1196
1196
1197 self.isConfig = False
1197 self.isConfig = False
1198
1198
1199 self.datablock = None
1199 self.datablock = None
1200
1200
1201 self.utc = 0
1201 self.utc = 0
1202
1202
1203 self.ext = ".r"
1203 self.ext = ".r"
1204
1204
1205 self.optchar = "D"
1205 self.optchar = "D"
1206
1206
1207 self.basicHeaderObj = BasicHeader()
1207 self.basicHeaderObj = BasicHeader()
1208
1208
1209 self.systemHeaderObj = SystemHeader()
1209 self.systemHeaderObj = SystemHeader()
1210
1210
1211 self.radarControllerHeaderObj = RadarControllerHeader()
1211 self.radarControllerHeaderObj = RadarControllerHeader()
1212
1212
1213 self.processingHeaderObj = ProcessingHeader()
1213 self.processingHeaderObj = ProcessingHeader()
1214
1214
1215 self.online = 0
1215 self.online = 0
1216
1216
1217 self.fp = None
1217 self.fp = None
1218
1218
1219 self.idFile = None
1219 self.idFile = None
1220
1220
1221 self.dtype = None
1221 self.dtype = None
1222
1222
1223 self.fileSizeByHeader = None
1223 self.fileSizeByHeader = None
1224
1224
1225 self.filenameList = []
1225 self.filenameList = []
1226
1226
1227 self.filename = None
1227 self.filename = None
1228
1228
1229 self.fileSize = None
1229 self.fileSize = None
1230
1230
1231 self.firstHeaderSize = 0
1231 self.firstHeaderSize = 0
1232
1232
1233 self.basicHeaderSize = 24
1233 self.basicHeaderSize = 24
1234
1234
1235 self.pathList = []
1235 self.pathList = []
1236
1236
1237 self.filenameList = []
1237 self.filenameList = []
1238
1238
1239 self.lastUTTime = 0
1239 self.lastUTTime = 0
1240
1240
1241 self.maxTimeStep = 30
1241 self.maxTimeStep = 30
1242
1242
1243 self.flagNoMoreFiles = 0
1243 self.flagNoMoreFiles = 0
1244
1244
1245 self.set = 0
1245 self.set = 0
1246
1246
1247 self.path = None
1247 self.path = None
1248
1248
1249 self.profileIndex = 9999
1249 self.profileIndex = 9999
1250
1250
1251 self.delay = 3 #seconds
1251 self.delay = 3 #seconds
1252
1252
1253 self.nTries = 3 #quantity tries
1253 self.nTries = 3 #quantity tries
1254
1254
1255 self.nFiles = 3 #number of files for searching
1255 self.nFiles = 3 #number of files for searching
1256
1256
1257 self.nReadBlocks = 0
1257 self.nReadBlocks = 0
1258
1258
1259 self.flagIsNewFile = 1
1259 self.flagIsNewFile = 1
1260
1260
1261 self.ippSeconds = 0
1261 self.ippSeconds = 0
1262
1262
1263 self.flagTimeBlock = 0
1263 self.flagTimeBlock = 0
1264
1264
1265 self.flagIsNewBlock = 0
1265 self.flagIsNewBlock = 0
1266
1266
1267 self.nTotalBlocks = 0
1267 self.nTotalBlocks = 0
1268
1268
1269 self.blocksize = 0
1269 self.blocksize = 0
1270
1270
1271 self.dataOut = self.createObjByDefault()
1271 self.dataOut = self.createObjByDefault()
1272
1272
1273 def createObjByDefault(self):
1273 def createObjByDefault(self):
1274
1274
1275 dataObj = Voltage()
1275 dataObj = Voltage()
1276
1276
1277 return dataObj
1277 return dataObj
1278
1278
1279 def __hasNotDataInBuffer(self):
1279 def __hasNotDataInBuffer(self):
1280 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1280 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1281 return 1
1281 return 1
1282 return 0
1282 return 0
1283
1283
1284
1284
1285 def getBlockDimension(self):
1285 def getBlockDimension(self):
1286 """
1286 """
1287 Obtiene la cantidad de puntos a leer por cada bloque de datos
1287 Obtiene la cantidad de puntos a leer por cada bloque de datos
1288
1288
1289 Affected:
1289 Affected:
1290 self.blocksize
1290 self.blocksize
1291
1291
1292 Return:
1292 Return:
1293 None
1293 None
1294 """
1294 """
1295 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1295 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1296 self.blocksize = pts2read
1296 self.blocksize = pts2read
1297
1297
1298
1298
1299 def readBlock(self):
1299 def readBlock(self):
1300 """
1300 """
1301 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1301 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1302 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1302 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1303 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1303 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1304 es seteado a 0
1304 es seteado a 0
1305
1305
1306 Inputs:
1306 Inputs:
1307 None
1307 None
1308
1308
1309 Return:
1309 Return:
1310 None
1310 None
1311
1311
1312 Affected:
1312 Affected:
1313 self.profileIndex
1313 self.profileIndex
1314 self.datablock
1314 self.datablock
1315 self.flagIsNewFile
1315 self.flagIsNewFile
1316 self.flagIsNewBlock
1316 self.flagIsNewBlock
1317 self.nTotalBlocks
1317 self.nTotalBlocks
1318
1318
1319 Exceptions:
1319 Exceptions:
1320 Si un bloque leido no es un bloque valido
1320 Si un bloque leido no es un bloque valido
1321 """
1321 """
1322
1322
1323 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1323 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1324
1324
1325 try:
1325 try:
1326 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1326 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1327 except:
1327 except:
1328 print "The read block (%3d) has not enough data" %self.nReadBlocks
1328 print "The read block (%3d) has not enough data" %self.nReadBlocks
1329 return 0
1329 return 0
1330
1330
1331 junk = numpy.transpose(junk, (2,0,1))
1331 junk = numpy.transpose(junk, (2,0,1))
1332 self.datablock = junk['real'] + junk['imag']*1j
1332 self.datablock = junk['real'] + junk['imag']*1j
1333
1333
1334 self.profileIndex = 0
1334 self.profileIndex = 0
1335
1335
1336 self.flagIsNewFile = 0
1336 self.flagIsNewFile = 0
1337 self.flagIsNewBlock = 1
1337 self.flagIsNewBlock = 1
1338
1338
1339 self.nTotalBlocks += 1
1339 self.nTotalBlocks += 1
1340 self.nReadBlocks += 1
1340 self.nReadBlocks += 1
1341
1341
1342 return 1
1342 return 1
1343
1343
1344
1344
1345 def getData(self):
1345 def getData(self):
1346 """
1346 """
1347 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1347 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1348 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1348 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1349 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1349 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1350
1350
1351 Ademas incrementa el contador del buffer en 1.
1351 Ademas incrementa el contador del buffer en 1.
1352
1352
1353 Return:
1353 Return:
1354 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1354 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1355 buffer. Si no hay mas archivos a leer retorna None.
1355 buffer. Si no hay mas archivos a leer retorna None.
1356
1356
1357 Variables afectadas:
1357 Variables afectadas:
1358 self.dataOut
1358 self.dataOut
1359 self.profileIndex
1359 self.profileIndex
1360
1360
1361 Affected:
1361 Affected:
1362 self.dataOut
1362 self.dataOut
1363 self.profileIndex
1363 self.profileIndex
1364 self.flagTimeBlock
1364 self.flagTimeBlock
1365 self.flagIsNewBlock
1365 self.flagIsNewBlock
1366 """
1366 """
1367
1367
1368 if self.flagNoMoreFiles:
1368 if self.flagNoMoreFiles:
1369 self.dataOut.flagNoData = True
1369 self.dataOut.flagNoData = True
1370 print 'Process finished'
1370 print 'Process finished'
1371 return 0
1371 return 0
1372
1372
1373 self.flagTimeBlock = 0
1373 self.flagTimeBlock = 0
1374 self.flagIsNewBlock = 0
1374 self.flagIsNewBlock = 0
1375
1375
1376 if self.__hasNotDataInBuffer():
1376 if self.__hasNotDataInBuffer():
1377
1377
1378 if not( self.readNextBlock() ):
1378 if not( self.readNextBlock() ):
1379 return 0
1379 return 0
1380
1380
1381 self.dataOut.dtype = self.dtype
1381 self.dataOut.dtype = self.dtype
1382
1382
1383 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1383 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1384
1384
1385 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1385 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1386
1386
1387 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1387 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1388
1388
1389 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1389 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1390
1390
1391 self.dataOut.flagTimeBlock = self.flagTimeBlock
1391 self.dataOut.flagTimeBlock = self.flagTimeBlock
1392
1392
1393 self.dataOut.ippSeconds = self.ippSeconds
1393 self.dataOut.ippSeconds = self.ippSeconds
1394
1394
1395 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1395 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1396
1396
1397 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1397 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1398
1398
1399 self.dataOut.flagShiftFFT = False
1399 self.dataOut.flagShiftFFT = False
1400
1400
1401 if self.processingHeaderObj.code != None:
1401 if self.processingHeaderObj.code != None:
1402
1402 self.dataOut.nCode = self.processingHeaderObj.nCode
1403 self.dataOut.nCode = self.processingHeaderObj.nCode
1403
1404
1404 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1405 self.dataOut.nBaud = self.processingHeaderObj.nBaud
1405
1406
1406 self.dataOut.code = self.processingHeaderObj.code
1407 self.dataOut.code = self.processingHeaderObj.code
1407
1408
1408 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1409 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1409
1410
1410 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1411 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1412
1413 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1414
1415 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1416
1417 self.dataOut.flagShiftFFT = False
1418
1411
1419
1412 # self.updateDataHeader()
1420 # self.updateDataHeader()
1413
1421
1414 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1422 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1415
1423
1416 if self.datablock == None:
1424 if self.datablock == None:
1417 self.dataOut.flagNoData = True
1425 self.dataOut.flagNoData = True
1418 return 0
1426 return 0
1419
1427
1420 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1428 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1421
1429
1422 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1430 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
1423
1431
1424 self.profileIndex += 1
1432 self.profileIndex += 1
1425
1433
1426 self.dataOut.flagNoData = False
1434 self.dataOut.flagNoData = False
1427
1435
1428 # print self.profileIndex, self.dataOut.utctime
1436 # print self.profileIndex, self.dataOut.utctime
1429 # if self.profileIndex == 800:
1437 # if self.profileIndex == 800:
1430 # a=1
1438 # a=1
1431
1439
1432
1440
1433 return self.dataOut.data
1441 return self.dataOut.data
1434
1442
1435
1443
1436 class VoltageWriter(JRODataWriter):
1444 class VoltageWriter(JRODataWriter):
1437 """
1445 """
1438 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1446 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1439 de los datos siempre se realiza por bloques.
1447 de los datos siempre se realiza por bloques.
1440 """
1448 """
1441
1449
1442 ext = ".r"
1450 ext = ".r"
1443
1451
1444 optchar = "D"
1452 optchar = "D"
1445
1453
1446 shapeBuffer = None
1454 shapeBuffer = None
1447
1455
1448
1456
1449 def __init__(self):
1457 def __init__(self):
1450 """
1458 """
1451 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1459 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1452
1460
1453 Affected:
1461 Affected:
1454 self.dataOut
1462 self.dataOut
1455
1463
1456 Return: None
1464 Return: None
1457 """
1465 """
1458
1466
1459 self.nTotalBlocks = 0
1467 self.nTotalBlocks = 0
1460
1468
1461 self.profileIndex = 0
1469 self.profileIndex = 0
1462
1470
1463 self.isConfig = False
1471 self.isConfig = False
1464
1472
1465 self.fp = None
1473 self.fp = None
1466
1474
1467 self.flagIsNewFile = 1
1475 self.flagIsNewFile = 1
1468
1476
1469 self.nTotalBlocks = 0
1477 self.nTotalBlocks = 0
1470
1478
1471 self.flagIsNewBlock = 0
1479 self.flagIsNewBlock = 0
1472
1480
1473 self.setFile = None
1481 self.setFile = None
1474
1482
1475 self.dtype = None
1483 self.dtype = None
1476
1484
1477 self.path = None
1485 self.path = None
1478
1486
1479 self.filename = None
1487 self.filename = None
1480
1488
1481 self.basicHeaderObj = BasicHeader()
1489 self.basicHeaderObj = BasicHeader()
1482
1490
1483 self.systemHeaderObj = SystemHeader()
1491 self.systemHeaderObj = SystemHeader()
1484
1492
1485 self.radarControllerHeaderObj = RadarControllerHeader()
1493 self.radarControllerHeaderObj = RadarControllerHeader()
1486
1494
1487 self.processingHeaderObj = ProcessingHeader()
1495 self.processingHeaderObj = ProcessingHeader()
1488
1496
1489 def hasAllDataInBuffer(self):
1497 def hasAllDataInBuffer(self):
1490 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1498 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1491 return 1
1499 return 1
1492 return 0
1500 return 0
1493
1501
1494
1502
1495 def setBlockDimension(self):
1503 def setBlockDimension(self):
1496 """
1504 """
1497 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1505 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1498
1506
1499 Affected:
1507 Affected:
1500 self.shape_spc_Buffer
1508 self.shape_spc_Buffer
1501 self.shape_cspc_Buffer
1509 self.shape_cspc_Buffer
1502 self.shape_dc_Buffer
1510 self.shape_dc_Buffer
1503
1511
1504 Return: None
1512 Return: None
1505 """
1513 """
1506 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1514 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1507 self.processingHeaderObj.nHeights,
1515 self.processingHeaderObj.nHeights,
1508 self.systemHeaderObj.nChannels)
1516 self.systemHeaderObj.nChannels)
1509
1517
1510 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1518 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1511 self.processingHeaderObj.profilesPerBlock,
1519 self.processingHeaderObj.profilesPerBlock,
1512 self.processingHeaderObj.nHeights),
1520 self.processingHeaderObj.nHeights),
1513 dtype=numpy.dtype('complex'))
1521 dtype=numpy.dtype('complex'))
1514
1522
1515
1523
1516 def writeBlock(self):
1524 def writeBlock(self):
1517 """
1525 """
1518 Escribe el buffer en el file designado
1526 Escribe el buffer en el file designado
1519
1527
1520 Affected:
1528 Affected:
1521 self.profileIndex
1529 self.profileIndex
1522 self.flagIsNewFile
1530 self.flagIsNewFile
1523 self.flagIsNewBlock
1531 self.flagIsNewBlock
1524 self.nTotalBlocks
1532 self.nTotalBlocks
1525 self.blockIndex
1533 self.blockIndex
1526
1534
1527 Return: None
1535 Return: None
1528 """
1536 """
1529 data = numpy.zeros( self.shapeBuffer, self.dtype )
1537 data = numpy.zeros( self.shapeBuffer, self.dtype )
1530
1538
1531 junk = numpy.transpose(self.datablock, (1,2,0))
1539 junk = numpy.transpose(self.datablock, (1,2,0))
1532
1540
1533 data['real'] = junk.real
1541 data['real'] = junk.real
1534 data['imag'] = junk.imag
1542 data['imag'] = junk.imag
1535
1543
1536 data = data.reshape( (-1) )
1544 data = data.reshape( (-1) )
1537
1545
1538 data.tofile( self.fp )
1546 data.tofile( self.fp )
1539
1547
1540 self.datablock.fill(0)
1548 self.datablock.fill(0)
1541
1549
1542 self.profileIndex = 0
1550 self.profileIndex = 0
1543 self.flagIsNewFile = 0
1551 self.flagIsNewFile = 0
1544 self.flagIsNewBlock = 1
1552 self.flagIsNewBlock = 1
1545
1553
1546 self.blockIndex += 1
1554 self.blockIndex += 1
1547 self.nTotalBlocks += 1
1555 self.nTotalBlocks += 1
1548
1556
1549 def putData(self):
1557 def putData(self):
1550 """
1558 """
1551 Setea un bloque de datos y luego los escribe en un file
1559 Setea un bloque de datos y luego los escribe en un file
1552
1560
1553 Affected:
1561 Affected:
1554 self.flagIsNewBlock
1562 self.flagIsNewBlock
1555 self.profileIndex
1563 self.profileIndex
1556
1564
1557 Return:
1565 Return:
1558 0 : Si no hay data o no hay mas files que puedan escribirse
1566 0 : Si no hay data o no hay mas files que puedan escribirse
1559 1 : Si se escribio la data de un bloque en un file
1567 1 : Si se escribio la data de un bloque en un file
1560 """
1568 """
1561 if self.dataOut.flagNoData:
1569 if self.dataOut.flagNoData:
1562 return 0
1570 return 0
1563
1571
1564 self.flagIsNewBlock = 0
1572 self.flagIsNewBlock = 0
1565
1573
1566 if self.dataOut.flagTimeBlock:
1574 if self.dataOut.flagTimeBlock:
1567
1575
1568 self.datablock.fill(0)
1576 self.datablock.fill(0)
1569 self.profileIndex = 0
1577 self.profileIndex = 0
1570 self.setNextFile()
1578 self.setNextFile()
1571
1579
1572 if self.profileIndex == 0:
1580 if self.profileIndex == 0:
1573 self.getBasicHeader()
1581 self.getBasicHeader()
1574
1582
1575 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1583 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1576
1584
1577 self.profileIndex += 1
1585 self.profileIndex += 1
1578
1586
1579 if self.hasAllDataInBuffer():
1587 if self.hasAllDataInBuffer():
1580 #if self.flagIsNewFile:
1588 #if self.flagIsNewFile:
1581 self.writeNextBlock()
1589 self.writeNextBlock()
1582 # self.getDataHeader()
1590 # self.getDataHeader()
1583
1591
1584 return 1
1592 return 1
1585
1593
1586 def __getProcessFlags(self):
1594 def __getProcessFlags(self):
1587
1595
1588 processFlags = 0
1596 processFlags = 0
1589
1597
1590 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1598 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1591 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1599 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1592 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1600 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1593 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1601 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1594 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1602 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1595 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1603 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1596
1604
1597 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1605 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1598
1606
1599
1607
1600
1608
1601 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1609 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1602 PROCFLAG.DATATYPE_SHORT,
1610 PROCFLAG.DATATYPE_SHORT,
1603 PROCFLAG.DATATYPE_LONG,
1611 PROCFLAG.DATATYPE_LONG,
1604 PROCFLAG.DATATYPE_INT64,
1612 PROCFLAG.DATATYPE_INT64,
1605 PROCFLAG.DATATYPE_FLOAT,
1613 PROCFLAG.DATATYPE_FLOAT,
1606 PROCFLAG.DATATYPE_DOUBLE]
1614 PROCFLAG.DATATYPE_DOUBLE]
1607
1615
1608
1616
1609 for index in range(len(dtypeList)):
1617 for index in range(len(dtypeList)):
1610 if self.dataOut.dtype == dtypeList[index]:
1618 if self.dataOut.dtype == dtypeList[index]:
1611 dtypeValue = datatypeValueList[index]
1619 dtypeValue = datatypeValueList[index]
1612 break
1620 break
1613
1621
1614 processFlags += dtypeValue
1622 processFlags += dtypeValue
1615
1623
1616 if self.dataOut.flagDecodeData:
1624 if self.dataOut.flagDecodeData:
1617 processFlags += PROCFLAG.DECODE_DATA
1625 processFlags += PROCFLAG.DECODE_DATA
1618
1626
1619 if self.dataOut.flagDeflipData:
1627 if self.dataOut.flagDeflipData:
1620 processFlags += PROCFLAG.DEFLIP_DATA
1628 processFlags += PROCFLAG.DEFLIP_DATA
1621
1629
1622 if self.dataOut.code != None:
1630 if self.dataOut.code != None:
1623 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1631 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1624
1632
1625 if self.dataOut.nCohInt > 1:
1633 if self.dataOut.nCohInt > 1:
1626 processFlags += PROCFLAG.COHERENT_INTEGRATION
1634 processFlags += PROCFLAG.COHERENT_INTEGRATION
1627
1635
1628 return processFlags
1636 return processFlags
1629
1637
1630
1638
1631 def __getBlockSize(self):
1639 def __getBlockSize(self):
1632 '''
1640 '''
1633 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1641 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1634 '''
1642 '''
1635
1643
1636 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1644 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1637 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1645 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1638 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1646 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1639 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1647 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1640 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1648 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1641 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1649 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1642
1650
1643 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1651 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1644 datatypeValueList = [1,2,4,8,4,8]
1652 datatypeValueList = [1,2,4,8,4,8]
1645 for index in range(len(dtypeList)):
1653 for index in range(len(dtypeList)):
1646 if self.dataOut.dtype == dtypeList[index]:
1654 if self.dataOut.dtype == dtypeList[index]:
1647 datatypeValue = datatypeValueList[index]
1655 datatypeValue = datatypeValueList[index]
1648 break
1656 break
1649
1657
1650 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1658 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1651
1659
1652 return blocksize
1660 return blocksize
1653
1661
1654 def getDataHeader(self):
1662 def getDataHeader(self):
1655
1663
1656 """
1664 """
1657 Obtiene una copia del First Header
1665 Obtiene una copia del First Header
1658
1666
1659 Affected:
1667 Affected:
1660 self.systemHeaderObj
1668 self.systemHeaderObj
1661 self.radarControllerHeaderObj
1669 self.radarControllerHeaderObj
1662 self.dtype
1670 self.dtype
1663
1671
1664 Return:
1672 Return:
1665 None
1673 None
1666 """
1674 """
1667
1675
1668 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1676 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1669 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1677 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1670 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1678 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1671
1679
1672 self.getBasicHeader()
1680 self.getBasicHeader()
1673
1681
1674 processingHeaderSize = 40 # bytes
1682 processingHeaderSize = 40 # bytes
1675 self.processingHeaderObj.dtype = 0 # Voltage
1683 self.processingHeaderObj.dtype = 0 # Voltage
1676 self.processingHeaderObj.blockSize = self.__getBlockSize()
1684 self.processingHeaderObj.blockSize = self.__getBlockSize()
1677 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1685 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1678 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1686 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1679 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1687 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1680 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1688 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1681 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1689 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1682 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1690 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1683 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1691 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1684
1692
1685 if self.dataOut.code != None:
1693 if self.dataOut.code != None:
1686 self.processingHeaderObj.code = self.dataOut.code
1694 self.processingHeaderObj.code = self.dataOut.code
1687 self.processingHeaderObj.nCode = self.dataOut.nCode
1695 self.processingHeaderObj.nCode = self.dataOut.nCode
1688 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1696 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1689 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1697 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1690 processingHeaderSize += codesize
1698 processingHeaderSize += codesize
1691
1699
1692 if self.processingHeaderObj.nWindows != 0:
1700 if self.processingHeaderObj.nWindows != 0:
1693 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1701 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1694 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1702 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1695 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1703 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1696 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1704 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1697 processingHeaderSize += 12
1705 processingHeaderSize += 12
1698
1706
1699 self.processingHeaderObj.size = processingHeaderSize
1707 self.processingHeaderObj.size = processingHeaderSize
1700
1708
1701 class SpectraReader(JRODataReader):
1709 class SpectraReader(JRODataReader):
1702 """
1710 """
1703 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1711 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1704 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1712 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1705 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1713 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1706
1714
1707 paresCanalesIguales * alturas * perfiles (Self Spectra)
1715 paresCanalesIguales * alturas * perfiles (Self Spectra)
1708 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1716 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1709 canales * alturas (DC Channels)
1717 canales * alturas (DC Channels)
1710
1718
1711 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1719 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1712 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1720 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1713 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1721 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1714 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1722 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1715
1723
1716 Example:
1724 Example:
1717 dpath = "/home/myuser/data"
1725 dpath = "/home/myuser/data"
1718
1726
1719 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1727 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1720
1728
1721 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1729 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1722
1730
1723 readerObj = SpectraReader()
1731 readerObj = SpectraReader()
1724
1732
1725 readerObj.setup(dpath, startTime, endTime)
1733 readerObj.setup(dpath, startTime, endTime)
1726
1734
1727 while(True):
1735 while(True):
1728
1736
1729 readerObj.getData()
1737 readerObj.getData()
1730
1738
1731 print readerObj.data_spc
1739 print readerObj.data_spc
1732
1740
1733 print readerObj.data_cspc
1741 print readerObj.data_cspc
1734
1742
1735 print readerObj.data_dc
1743 print readerObj.data_dc
1736
1744
1737 if readerObj.flagNoMoreFiles:
1745 if readerObj.flagNoMoreFiles:
1738 break
1746 break
1739
1747
1740 """
1748 """
1741
1749
1742 pts2read_SelfSpectra = 0
1750 pts2read_SelfSpectra = 0
1743
1751
1744 pts2read_CrossSpectra = 0
1752 pts2read_CrossSpectra = 0
1745
1753
1746 pts2read_DCchannels = 0
1754 pts2read_DCchannels = 0
1747
1755
1748 ext = ".pdata"
1756 ext = ".pdata"
1749
1757
1750 optchar = "P"
1758 optchar = "P"
1751
1759
1752 dataOut = None
1760 dataOut = None
1753
1761
1754 nRdChannels = None
1762 nRdChannels = None
1755
1763
1756 nRdPairs = None
1764 nRdPairs = None
1757
1765
1758 rdPairList = []
1766 rdPairList = []
1759
1767
1760
1768
1761 def __init__(self):
1769 def __init__(self):
1762 """
1770 """
1763 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1771 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1764
1772
1765 Inputs:
1773 Inputs:
1766 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1774 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1767 almacenar un perfil de datos cada vez que se haga un requerimiento
1775 almacenar un perfil de datos cada vez que se haga un requerimiento
1768 (getData). El perfil sera obtenido a partir del buffer de datos,
1776 (getData). El perfil sera obtenido a partir del buffer de datos,
1769 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1777 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1770 bloque de datos.
1778 bloque de datos.
1771 Si este parametro no es pasado se creara uno internamente.
1779 Si este parametro no es pasado se creara uno internamente.
1772
1780
1773 Affected:
1781 Affected:
1774 self.dataOut
1782 self.dataOut
1775
1783
1776 Return : None
1784 Return : None
1777 """
1785 """
1778
1786
1779 self.isConfig = False
1787 self.isConfig = False
1780
1788
1781 self.pts2read_SelfSpectra = 0
1789 self.pts2read_SelfSpectra = 0
1782
1790
1783 self.pts2read_CrossSpectra = 0
1791 self.pts2read_CrossSpectra = 0
1784
1792
1785 self.pts2read_DCchannels = 0
1793 self.pts2read_DCchannels = 0
1786
1794
1787 self.datablock = None
1795 self.datablock = None
1788
1796
1789 self.utc = None
1797 self.utc = None
1790
1798
1791 self.ext = ".pdata"
1799 self.ext = ".pdata"
1792
1800
1793 self.optchar = "P"
1801 self.optchar = "P"
1794
1802
1795 self.basicHeaderObj = BasicHeader()
1803 self.basicHeaderObj = BasicHeader()
1796
1804
1797 self.systemHeaderObj = SystemHeader()
1805 self.systemHeaderObj = SystemHeader()
1798
1806
1799 self.radarControllerHeaderObj = RadarControllerHeader()
1807 self.radarControllerHeaderObj = RadarControllerHeader()
1800
1808
1801 self.processingHeaderObj = ProcessingHeader()
1809 self.processingHeaderObj = ProcessingHeader()
1802
1810
1803 self.online = 0
1811 self.online = 0
1804
1812
1805 self.fp = None
1813 self.fp = None
1806
1814
1807 self.idFile = None
1815 self.idFile = None
1808
1816
1809 self.dtype = None
1817 self.dtype = None
1810
1818
1811 self.fileSizeByHeader = None
1819 self.fileSizeByHeader = None
1812
1820
1813 self.filenameList = []
1821 self.filenameList = []
1814
1822
1815 self.filename = None
1823 self.filename = None
1816
1824
1817 self.fileSize = None
1825 self.fileSize = None
1818
1826
1819 self.firstHeaderSize = 0
1827 self.firstHeaderSize = 0
1820
1828
1821 self.basicHeaderSize = 24
1829 self.basicHeaderSize = 24
1822
1830
1823 self.pathList = []
1831 self.pathList = []
1824
1832
1825 self.lastUTTime = 0
1833 self.lastUTTime = 0
1826
1834
1827 self.maxTimeStep = 30
1835 self.maxTimeStep = 30
1828
1836
1829 self.flagNoMoreFiles = 0
1837 self.flagNoMoreFiles = 0
1830
1838
1831 self.set = 0
1839 self.set = 0
1832
1840
1833 self.path = None
1841 self.path = None
1834
1842
1835 self.delay = 3 #seconds
1843 self.delay = 3 #seconds
1836
1844
1837 self.nTries = 3 #quantity tries
1845 self.nTries = 3 #quantity tries
1838
1846
1839 self.nFiles = 3 #number of files for searching
1847 self.nFiles = 3 #number of files for searching
1840
1848
1841 self.nReadBlocks = 0
1849 self.nReadBlocks = 0
1842
1850
1843 self.flagIsNewFile = 1
1851 self.flagIsNewFile = 1
1844
1852
1845 self.ippSeconds = 0
1853 self.ippSeconds = 0
1846
1854
1847 self.flagTimeBlock = 0
1855 self.flagTimeBlock = 0
1848
1856
1849 self.flagIsNewBlock = 0
1857 self.flagIsNewBlock = 0
1850
1858
1851 self.nTotalBlocks = 0
1859 self.nTotalBlocks = 0
1852
1860
1853 self.blocksize = 0
1861 self.blocksize = 0
1854
1862
1855 self.dataOut = self.createObjByDefault()
1863 self.dataOut = self.createObjByDefault()
1856
1864
1857
1865
1858 def createObjByDefault(self):
1866 def createObjByDefault(self):
1859
1867
1860 dataObj = Spectra()
1868 dataObj = Spectra()
1861
1869
1862 return dataObj
1870 return dataObj
1863
1871
1864 def __hasNotDataInBuffer(self):
1872 def __hasNotDataInBuffer(self):
1865 return 1
1873 return 1
1866
1874
1867
1875
1868 def getBlockDimension(self):
1876 def getBlockDimension(self):
1869 """
1877 """
1870 Obtiene la cantidad de puntos a leer por cada bloque de datos
1878 Obtiene la cantidad de puntos a leer por cada bloque de datos
1871
1879
1872 Affected:
1880 Affected:
1873 self.nRdChannels
1881 self.nRdChannels
1874 self.nRdPairs
1882 self.nRdPairs
1875 self.pts2read_SelfSpectra
1883 self.pts2read_SelfSpectra
1876 self.pts2read_CrossSpectra
1884 self.pts2read_CrossSpectra
1877 self.pts2read_DCchannels
1885 self.pts2read_DCchannels
1878 self.blocksize
1886 self.blocksize
1879 self.dataOut.nChannels
1887 self.dataOut.nChannels
1880 self.dataOut.nPairs
1888 self.dataOut.nPairs
1881
1889
1882 Return:
1890 Return:
1883 None
1891 None
1884 """
1892 """
1885 self.nRdChannels = 0
1893 self.nRdChannels = 0
1886 self.nRdPairs = 0
1894 self.nRdPairs = 0
1887 self.rdPairList = []
1895 self.rdPairList = []
1888
1896
1889 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1897 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
1890 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1898 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
1891 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1899 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
1892 else:
1900 else:
1893 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1901 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
1894 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1902 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
1895
1903
1896 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1904 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
1897
1905
1898 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1906 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
1899 self.blocksize = self.pts2read_SelfSpectra
1907 self.blocksize = self.pts2read_SelfSpectra
1900
1908
1901 if self.processingHeaderObj.flag_cspc:
1909 if self.processingHeaderObj.flag_cspc:
1902 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1910 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
1903 self.blocksize += self.pts2read_CrossSpectra
1911 self.blocksize += self.pts2read_CrossSpectra
1904
1912
1905 if self.processingHeaderObj.flag_dc:
1913 if self.processingHeaderObj.flag_dc:
1906 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1914 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
1907 self.blocksize += self.pts2read_DCchannels
1915 self.blocksize += self.pts2read_DCchannels
1908
1916
1909 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1917 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
1910
1918
1911
1919
1912 def readBlock(self):
1920 def readBlock(self):
1913 """
1921 """
1914 Lee el bloque de datos desde la posicion actual del puntero del archivo
1922 Lee el bloque de datos desde la posicion actual del puntero del archivo
1915 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1923 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1916 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1924 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1917 es seteado a 0
1925 es seteado a 0
1918
1926
1919 Return: None
1927 Return: None
1920
1928
1921 Variables afectadas:
1929 Variables afectadas:
1922
1930
1923 self.flagIsNewFile
1931 self.flagIsNewFile
1924 self.flagIsNewBlock
1932 self.flagIsNewBlock
1925 self.nTotalBlocks
1933 self.nTotalBlocks
1926 self.data_spc
1934 self.data_spc
1927 self.data_cspc
1935 self.data_cspc
1928 self.data_dc
1936 self.data_dc
1929
1937
1930 Exceptions:
1938 Exceptions:
1931 Si un bloque leido no es un bloque valido
1939 Si un bloque leido no es un bloque valido
1932 """
1940 """
1933 blockOk_flag = False
1941 blockOk_flag = False
1934 fpointer = self.fp.tell()
1942 fpointer = self.fp.tell()
1935
1943
1936 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1944 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
1937 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1945 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1938
1946
1939 if self.processingHeaderObj.flag_cspc:
1947 if self.processingHeaderObj.flag_cspc:
1940 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1948 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
1941 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1949 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
1942
1950
1943 if self.processingHeaderObj.flag_dc:
1951 if self.processingHeaderObj.flag_dc:
1944 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1952 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
1945 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1953 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
1946
1954
1947
1955
1948 if not(self.processingHeaderObj.shif_fft):
1956 if not(self.processingHeaderObj.shif_fft):
1949 #desplaza a la derecha en el eje 2 determinadas posiciones
1957 #desplaza a la derecha en el eje 2 determinadas posiciones
1950 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1958 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1951 spc = numpy.roll( spc, shift , axis=2 )
1959 spc = numpy.roll( spc, shift , axis=2 )
1952
1960
1953 if self.processingHeaderObj.flag_cspc:
1961 if self.processingHeaderObj.flag_cspc:
1954 #desplaza a la derecha en el eje 2 determinadas posiciones
1962 #desplaza a la derecha en el eje 2 determinadas posiciones
1955 cspc = numpy.roll( cspc, shift, axis=2 )
1963 cspc = numpy.roll( cspc, shift, axis=2 )
1956
1964
1957
1965
1958 spc = numpy.transpose( spc, (0,2,1) )
1966 spc = numpy.transpose( spc, (0,2,1) )
1959 self.data_spc = spc
1967 self.data_spc = spc
1960
1968
1961 if self.processingHeaderObj.flag_cspc:
1969 if self.processingHeaderObj.flag_cspc:
1962 cspc = numpy.transpose( cspc, (0,2,1) )
1970 cspc = numpy.transpose( cspc, (0,2,1) )
1963 self.data_cspc = cspc['real'] + cspc['imag']*1j
1971 self.data_cspc = cspc['real'] + cspc['imag']*1j
1964 else:
1972 else:
1965 self.data_cspc = None
1973 self.data_cspc = None
1966
1974
1967 if self.processingHeaderObj.flag_dc:
1975 if self.processingHeaderObj.flag_dc:
1968 self.data_dc = dc['real'] + dc['imag']*1j
1976 self.data_dc = dc['real'] + dc['imag']*1j
1969 else:
1977 else:
1970 self.data_dc = None
1978 self.data_dc = None
1971
1979
1972 self.flagIsNewFile = 0
1980 self.flagIsNewFile = 0
1973 self.flagIsNewBlock = 1
1981 self.flagIsNewBlock = 1
1974
1982
1975 self.nTotalBlocks += 1
1983 self.nTotalBlocks += 1
1976 self.nReadBlocks += 1
1984 self.nReadBlocks += 1
1977
1985
1978 return 1
1986 return 1
1979
1987
1980
1988
1981 def getData(self):
1989 def getData(self):
1982 """
1990 """
1983 Copia el buffer de lectura a la clase "Spectra",
1991 Copia el buffer de lectura a la clase "Spectra",
1984 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1992 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1985 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1993 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1986
1994
1987 Return:
1995 Return:
1988 0 : Si no hay mas archivos disponibles
1996 0 : Si no hay mas archivos disponibles
1989 1 : Si hizo una buena copia del buffer
1997 1 : Si hizo una buena copia del buffer
1990
1998
1991 Affected:
1999 Affected:
1992 self.dataOut
2000 self.dataOut
1993
2001
1994 self.flagTimeBlock
2002 self.flagTimeBlock
1995 self.flagIsNewBlock
2003 self.flagIsNewBlock
1996 """
2004 """
1997
2005
1998 if self.flagNoMoreFiles:
2006 if self.flagNoMoreFiles:
1999 self.dataOut.flagNoData = True
2007 self.dataOut.flagNoData = True
2000 print 'Process finished'
2008 print 'Process finished'
2001 return 0
2009 return 0
2002
2010
2003 self.flagTimeBlock = 0
2011 self.flagTimeBlock = 0
2004 self.flagIsNewBlock = 0
2012 self.flagIsNewBlock = 0
2005
2013
2006 if self.__hasNotDataInBuffer():
2014 if self.__hasNotDataInBuffer():
2007
2015
2008 if not( self.readNextBlock() ):
2016 if not( self.readNextBlock() ):
2009 self.dataOut.flagNoData = True
2017 self.dataOut.flagNoData = True
2010 return 0
2018 return 0
2011
2019
2012 # self.updateDataHeader()
2020 # self.updateDataHeader()
2013
2021
2014 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2022 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2015
2023
2016 if self.data_dc == None:
2024 if self.data_dc == None:
2017 self.dataOut.flagNoData = True
2025 self.dataOut.flagNoData = True
2018 return 0
2026 return 0
2019
2027
2020 self.dataOut.data_spc = self.data_spc
2028 self.dataOut.data_spc = self.data_spc
2021
2029
2022 self.dataOut.data_cspc = self.data_cspc
2030 self.dataOut.data_cspc = self.data_cspc
2023
2031
2024 self.dataOut.data_dc = self.data_dc
2032 self.dataOut.data_dc = self.data_dc
2025
2033
2026 self.dataOut.flagTimeBlock = self.flagTimeBlock
2034 self.dataOut.flagTimeBlock = self.flagTimeBlock
2027
2035
2028 self.dataOut.flagNoData = False
2036 self.dataOut.flagNoData = False
2029
2037
2030 self.dataOut.dtype = self.dtype
2038 self.dataOut.dtype = self.dtype
2031
2039
2032 # self.dataOut.nChannels = self.nRdChannels
2040 # self.dataOut.nChannels = self.nRdChannels
2033
2041
2034 self.dataOut.nPairs = self.nRdPairs
2042 self.dataOut.nPairs = self.nRdPairs
2035
2043
2036 self.dataOut.pairsList = self.rdPairList
2044 self.dataOut.pairsList = self.rdPairList
2037
2045
2038 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2046 # self.dataOut.nHeights = self.processingHeaderObj.nHeights
2039
2047
2040 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2048 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2041
2049
2042 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2050 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2043
2051
2044 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2052 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2045
2053
2046 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2054 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2047
2055
2048 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2056 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2049
2057
2050 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2058 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2051
2059
2052 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2060 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2053
2061
2054 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2062 # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels)
2055
2063
2056 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2064 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
2057
2065
2058 self.dataOut.ippSeconds = self.ippSeconds
2066 self.dataOut.ippSeconds = self.ippSeconds
2059
2067
2060 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2068 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2061
2069
2062 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2063
2064 # self.profileIndex += 1
2070 # self.profileIndex += 1
2065
2071
2066 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2072 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2067
2073
2068 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2074 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2075
2076 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2077
2078 self.dataOut.flagDecodeData = True #asumo q la data no esta decodificada
2079
2080 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2081
2069
2082
2070 return self.dataOut.data_spc
2083 return self.dataOut.data_spc
2071
2084
2072
2085
2073 class SpectraWriter(JRODataWriter):
2086 class SpectraWriter(JRODataWriter):
2074
2087
2075 """
2088 """
2076 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2089 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2077 de los datos siempre se realiza por bloques.
2090 de los datos siempre se realiza por bloques.
2078 """
2091 """
2079
2092
2080 ext = ".pdata"
2093 ext = ".pdata"
2081
2094
2082 optchar = "P"
2095 optchar = "P"
2083
2096
2084 shape_spc_Buffer = None
2097 shape_spc_Buffer = None
2085
2098
2086 shape_cspc_Buffer = None
2099 shape_cspc_Buffer = None
2087
2100
2088 shape_dc_Buffer = None
2101 shape_dc_Buffer = None
2089
2102
2090 data_spc = None
2103 data_spc = None
2091
2104
2092 data_cspc = None
2105 data_cspc = None
2093
2106
2094 data_dc = None
2107 data_dc = None
2095
2108
2096 # dataOut = None
2109 # dataOut = None
2097
2110
2098 def __init__(self):
2111 def __init__(self):
2099 """
2112 """
2100 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2113 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2101
2114
2102 Affected:
2115 Affected:
2103 self.dataOut
2116 self.dataOut
2104 self.basicHeaderObj
2117 self.basicHeaderObj
2105 self.systemHeaderObj
2118 self.systemHeaderObj
2106 self.radarControllerHeaderObj
2119 self.radarControllerHeaderObj
2107 self.processingHeaderObj
2120 self.processingHeaderObj
2108
2121
2109 Return: None
2122 Return: None
2110 """
2123 """
2111
2124
2112 self.isConfig = False
2125 self.isConfig = False
2113
2126
2114 self.nTotalBlocks = 0
2127 self.nTotalBlocks = 0
2115
2128
2116 self.data_spc = None
2129 self.data_spc = None
2117
2130
2118 self.data_cspc = None
2131 self.data_cspc = None
2119
2132
2120 self.data_dc = None
2133 self.data_dc = None
2121
2134
2122 self.fp = None
2135 self.fp = None
2123
2136
2124 self.flagIsNewFile = 1
2137 self.flagIsNewFile = 1
2125
2138
2126 self.nTotalBlocks = 0
2139 self.nTotalBlocks = 0
2127
2140
2128 self.flagIsNewBlock = 0
2141 self.flagIsNewBlock = 0
2129
2142
2130 self.setFile = None
2143 self.setFile = None
2131
2144
2132 self.dtype = None
2145 self.dtype = None
2133
2146
2134 self.path = None
2147 self.path = None
2135
2148
2136 self.noMoreFiles = 0
2149 self.noMoreFiles = 0
2137
2150
2138 self.filename = None
2151 self.filename = None
2139
2152
2140 self.basicHeaderObj = BasicHeader()
2153 self.basicHeaderObj = BasicHeader()
2141
2154
2142 self.systemHeaderObj = SystemHeader()
2155 self.systemHeaderObj = SystemHeader()
2143
2156
2144 self.radarControllerHeaderObj = RadarControllerHeader()
2157 self.radarControllerHeaderObj = RadarControllerHeader()
2145
2158
2146 self.processingHeaderObj = ProcessingHeader()
2159 self.processingHeaderObj = ProcessingHeader()
2147
2160
2148
2161
2149 def hasAllDataInBuffer(self):
2162 def hasAllDataInBuffer(self):
2150 return 1
2163 return 1
2151
2164
2152
2165
2153 def setBlockDimension(self):
2166 def setBlockDimension(self):
2154 """
2167 """
2155 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2168 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2156
2169
2157 Affected:
2170 Affected:
2158 self.shape_spc_Buffer
2171 self.shape_spc_Buffer
2159 self.shape_cspc_Buffer
2172 self.shape_cspc_Buffer
2160 self.shape_dc_Buffer
2173 self.shape_dc_Buffer
2161
2174
2162 Return: None
2175 Return: None
2163 """
2176 """
2164 self.shape_spc_Buffer = (self.dataOut.nChannels,
2177 self.shape_spc_Buffer = (self.dataOut.nChannels,
2165 self.processingHeaderObj.nHeights,
2178 self.processingHeaderObj.nHeights,
2166 self.processingHeaderObj.profilesPerBlock)
2179 self.processingHeaderObj.profilesPerBlock)
2167
2180
2168 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2181 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2169 self.processingHeaderObj.nHeights,
2182 self.processingHeaderObj.nHeights,
2170 self.processingHeaderObj.profilesPerBlock)
2183 self.processingHeaderObj.profilesPerBlock)
2171
2184
2172 self.shape_dc_Buffer = (self.dataOut.nChannels,
2185 self.shape_dc_Buffer = (self.dataOut.nChannels,
2173 self.processingHeaderObj.nHeights)
2186 self.processingHeaderObj.nHeights)
2174
2187
2175
2188
2176 def writeBlock(self):
2189 def writeBlock(self):
2177 """
2190 """
2178 Escribe el buffer en el file designado
2191 Escribe el buffer en el file designado
2179
2192
2180 Affected:
2193 Affected:
2181 self.data_spc
2194 self.data_spc
2182 self.data_cspc
2195 self.data_cspc
2183 self.data_dc
2196 self.data_dc
2184 self.flagIsNewFile
2197 self.flagIsNewFile
2185 self.flagIsNewBlock
2198 self.flagIsNewBlock
2186 self.nTotalBlocks
2199 self.nTotalBlocks
2187 self.nWriteBlocks
2200 self.nWriteBlocks
2188
2201
2189 Return: None
2202 Return: None
2190 """
2203 """
2191
2204
2192 spc = numpy.transpose( self.data_spc, (0,2,1) )
2205 spc = numpy.transpose( self.data_spc, (0,2,1) )
2193 if not( self.processingHeaderObj.shif_fft ):
2206 if not( self.processingHeaderObj.shif_fft ):
2194 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2207 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2195 data = spc.reshape((-1))
2208 data = spc.reshape((-1))
2196 data.tofile(self.fp)
2209 data.tofile(self.fp)
2197
2210
2198 if self.data_cspc != None:
2211 if self.data_cspc != None:
2199 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2212 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2200 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2213 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2201 if not( self.processingHeaderObj.shif_fft ):
2214 if not( self.processingHeaderObj.shif_fft ):
2202 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2215 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2203 data['real'] = cspc.real
2216 data['real'] = cspc.real
2204 data['imag'] = cspc.imag
2217 data['imag'] = cspc.imag
2205 data = data.reshape((-1))
2218 data = data.reshape((-1))
2206 data.tofile(self.fp)
2219 data.tofile(self.fp)
2207
2220
2208 if self.data_dc != None:
2221 if self.data_dc != None:
2209 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2222 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2210 dc = self.data_dc
2223 dc = self.data_dc
2211 data['real'] = dc.real
2224 data['real'] = dc.real
2212 data['imag'] = dc.imag
2225 data['imag'] = dc.imag
2213 data = data.reshape((-1))
2226 data = data.reshape((-1))
2214 data.tofile(self.fp)
2227 data.tofile(self.fp)
2215
2228
2216 self.data_spc.fill(0)
2229 self.data_spc.fill(0)
2217 self.data_dc.fill(0)
2230 self.data_dc.fill(0)
2218 if self.data_cspc != None:
2231 if self.data_cspc != None:
2219 self.data_cspc.fill(0)
2232 self.data_cspc.fill(0)
2220
2233
2221 self.flagIsNewFile = 0
2234 self.flagIsNewFile = 0
2222 self.flagIsNewBlock = 1
2235 self.flagIsNewBlock = 1
2223 self.nTotalBlocks += 1
2236 self.nTotalBlocks += 1
2224 self.nWriteBlocks += 1
2237 self.nWriteBlocks += 1
2225 self.blockIndex += 1
2238 self.blockIndex += 1
2226
2239
2227
2240
2228 def putData(self):
2241 def putData(self):
2229 """
2242 """
2230 Setea un bloque de datos y luego los escribe en un file
2243 Setea un bloque de datos y luego los escribe en un file
2231
2244
2232 Affected:
2245 Affected:
2233 self.data_spc
2246 self.data_spc
2234 self.data_cspc
2247 self.data_cspc
2235 self.data_dc
2248 self.data_dc
2236
2249
2237 Return:
2250 Return:
2238 0 : Si no hay data o no hay mas files que puedan escribirse
2251 0 : Si no hay data o no hay mas files que puedan escribirse
2239 1 : Si se escribio la data de un bloque en un file
2252 1 : Si se escribio la data de un bloque en un file
2240 """
2253 """
2241
2254
2242 if self.dataOut.flagNoData:
2255 if self.dataOut.flagNoData:
2243 return 0
2256 return 0
2244
2257
2245 self.flagIsNewBlock = 0
2258 self.flagIsNewBlock = 0
2246
2259
2247 if self.dataOut.flagTimeBlock:
2260 if self.dataOut.flagTimeBlock:
2248 self.data_spc.fill(0)
2261 self.data_spc.fill(0)
2249 self.data_cspc.fill(0)
2262 self.data_cspc.fill(0)
2250 self.data_dc.fill(0)
2263 self.data_dc.fill(0)
2251 self.setNextFile()
2264 self.setNextFile()
2252
2265
2253 if self.flagIsNewFile == 0:
2266 if self.flagIsNewFile == 0:
2254 self.getBasicHeader()
2267 self.getBasicHeader()
2255
2268
2256 self.data_spc = self.dataOut.data_spc
2269 self.data_spc = self.dataOut.data_spc
2257 self.data_cspc = self.dataOut.data_cspc
2270 self.data_cspc = self.dataOut.data_cspc
2258 self.data_dc = self.dataOut.data_dc
2271 self.data_dc = self.dataOut.data_dc
2259
2272
2260 # #self.processingHeaderObj.dataBlocksPerFile)
2273 # #self.processingHeaderObj.dataBlocksPerFile)
2261 if self.hasAllDataInBuffer():
2274 if self.hasAllDataInBuffer():
2262 # self.getDataHeader()
2275 # self.getDataHeader()
2263 self.writeNextBlock()
2276 self.writeNextBlock()
2264
2277
2265 return 1
2278 return 1
2266
2279
2267
2280
2268 def __getProcessFlags(self):
2281 def __getProcessFlags(self):
2269
2282
2270 processFlags = 0
2283 processFlags = 0
2271
2284
2272 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2285 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2273 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2286 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2274 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2287 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2275 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2288 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2276 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2289 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2277 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2290 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2278
2291
2279 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2292 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2280
2293
2281
2294
2282
2295
2283 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2296 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2284 PROCFLAG.DATATYPE_SHORT,
2297 PROCFLAG.DATATYPE_SHORT,
2285 PROCFLAG.DATATYPE_LONG,
2298 PROCFLAG.DATATYPE_LONG,
2286 PROCFLAG.DATATYPE_INT64,
2299 PROCFLAG.DATATYPE_INT64,
2287 PROCFLAG.DATATYPE_FLOAT,
2300 PROCFLAG.DATATYPE_FLOAT,
2288 PROCFLAG.DATATYPE_DOUBLE]
2301 PROCFLAG.DATATYPE_DOUBLE]
2289
2302
2290
2303
2291 for index in range(len(dtypeList)):
2304 for index in range(len(dtypeList)):
2292 if self.dataOut.dtype == dtypeList[index]:
2305 if self.dataOut.dtype == dtypeList[index]:
2293 dtypeValue = datatypeValueList[index]
2306 dtypeValue = datatypeValueList[index]
2294 break
2307 break
2295
2308
2296 processFlags += dtypeValue
2309 processFlags += dtypeValue
2297
2310
2298 if self.dataOut.flagDecodeData:
2311 if self.dataOut.flagDecodeData:
2299 processFlags += PROCFLAG.DECODE_DATA
2312 processFlags += PROCFLAG.DECODE_DATA
2300
2313
2301 if self.dataOut.flagDeflipData:
2314 if self.dataOut.flagDeflipData:
2302 processFlags += PROCFLAG.DEFLIP_DATA
2315 processFlags += PROCFLAG.DEFLIP_DATA
2303
2316
2304 if self.dataOut.code != None:
2317 if self.dataOut.code != None:
2305 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2318 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2306
2319
2307 if self.dataOut.nIncohInt > 1:
2320 if self.dataOut.nIncohInt > 1:
2308 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2321 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2309
2322
2310 if self.dataOut.data_dc != None:
2323 if self.dataOut.data_dc != None:
2311 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2324 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2312
2325
2313 return processFlags
2326 return processFlags
2314
2327
2315
2328
2316 def __getBlockSize(self):
2329 def __getBlockSize(self):
2317 '''
2330 '''
2318 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2331 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2319 '''
2332 '''
2320
2333
2321 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2334 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2322 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2335 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2323 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2336 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2324 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2337 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2325 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2338 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2326 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2339 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2327
2340
2328 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2341 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2329 datatypeValueList = [1,2,4,8,4,8]
2342 datatypeValueList = [1,2,4,8,4,8]
2330 for index in range(len(dtypeList)):
2343 for index in range(len(dtypeList)):
2331 if self.dataOut.dtype == dtypeList[index]:
2344 if self.dataOut.dtype == dtypeList[index]:
2332 datatypeValue = datatypeValueList[index]
2345 datatypeValue = datatypeValueList[index]
2333 break
2346 break
2334
2347
2335
2348
2336 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2349 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2337
2350
2338 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2351 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2339 blocksize = (pts2write_SelfSpectra*datatypeValue)
2352 blocksize = (pts2write_SelfSpectra*datatypeValue)
2340
2353
2341 if self.dataOut.data_cspc != None:
2354 if self.dataOut.data_cspc != None:
2342 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2355 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2343 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2356 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2344
2357
2345 if self.dataOut.data_dc != None:
2358 if self.dataOut.data_dc != None:
2346 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2359 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2347 blocksize += (pts2write_DCchannels*datatypeValue*2)
2360 blocksize += (pts2write_DCchannels*datatypeValue*2)
2348
2361
2349 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2362 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2350
2363
2351 return blocksize
2364 return blocksize
2352
2365
2353 def getDataHeader(self):
2366 def getDataHeader(self):
2354
2367
2355 """
2368 """
2356 Obtiene una copia del First Header
2369 Obtiene una copia del First Header
2357
2370
2358 Affected:
2371 Affected:
2359 self.systemHeaderObj
2372 self.systemHeaderObj
2360 self.radarControllerHeaderObj
2373 self.radarControllerHeaderObj
2361 self.dtype
2374 self.dtype
2362
2375
2363 Return:
2376 Return:
2364 None
2377 None
2365 """
2378 """
2366
2379
2367 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2380 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2368 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2381 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2369 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2382 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2370
2383
2371 self.getBasicHeader()
2384 self.getBasicHeader()
2372
2385
2373 processingHeaderSize = 40 # bytes
2386 processingHeaderSize = 40 # bytes
2374 self.processingHeaderObj.dtype = 0 # Voltage
2387 self.processingHeaderObj.dtype = 0 # Voltage
2375 self.processingHeaderObj.blockSize = self.__getBlockSize()
2388 self.processingHeaderObj.blockSize = self.__getBlockSize()
2376 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2389 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2377 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2390 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2378 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2391 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2379 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2392 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2380 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2393 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2381 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2394 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2382 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2395 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2383
2396
2384 if self.processingHeaderObj.totalSpectra > 0:
2397 if self.processingHeaderObj.totalSpectra > 0:
2385 channelList = []
2398 channelList = []
2386 for channel in range(self.dataOut.nChannels):
2399 for channel in range(self.dataOut.nChannels):
2387 channelList.append(channel)
2400 channelList.append(channel)
2388 channelList.append(channel)
2401 channelList.append(channel)
2389
2402
2390 pairsList = []
2403 pairsList = []
2391 for pair in self.dataOut.pairsList:
2404 for pair in self.dataOut.pairsList:
2392 pairsList.append(pair[0])
2405 pairsList.append(pair[0])
2393 pairsList.append(pair[1])
2406 pairsList.append(pair[1])
2394 spectraComb = channelList + pairsList
2407 spectraComb = channelList + pairsList
2395 spectraComb = numpy.array(spectraComb,dtype="u1")
2408 spectraComb = numpy.array(spectraComb,dtype="u1")
2396 self.processingHeaderObj.spectraComb = spectraComb
2409 self.processingHeaderObj.spectraComb = spectraComb
2397 sizeOfSpcComb = len(spectraComb)
2410 sizeOfSpcComb = len(spectraComb)
2398 processingHeaderSize += sizeOfSpcComb
2411 processingHeaderSize += sizeOfSpcComb
2399
2412
2400 if self.dataOut.code != None:
2413 if self.dataOut.code != None:
2401 self.processingHeaderObj.code = self.dataOut.code
2414 self.processingHeaderObj.code = self.dataOut.code
2402 self.processingHeaderObj.nCode = self.dataOut.nCode
2415 self.processingHeaderObj.nCode = self.dataOut.nCode
2403 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2416 self.processingHeaderObj.nBaud = self.dataOut.nBaud
2404 nCodeSize = 4 # bytes
2417 nCodeSize = 4 # bytes
2405 nBaudSize = 4 # bytes
2418 nBaudSize = 4 # bytes
2406 codeSize = 4 # bytes
2419 codeSize = 4 # bytes
2407 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2420 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2408 processingHeaderSize += sizeOfCode
2421 processingHeaderSize += sizeOfCode
2409
2422
2410 if self.processingHeaderObj.nWindows != 0:
2423 if self.processingHeaderObj.nWindows != 0:
2411 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2424 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2412 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2425 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2413 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2426 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2414 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2427 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2415 sizeOfFirstHeight = 4
2428 sizeOfFirstHeight = 4
2416 sizeOfdeltaHeight = 4
2429 sizeOfdeltaHeight = 4
2417 sizeOfnHeights = 4
2430 sizeOfnHeights = 4
2418 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2431 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2419 processingHeaderSize += sizeOfWindows
2432 processingHeaderSize += sizeOfWindows
2420
2433
2421 self.processingHeaderObj.size = processingHeaderSize
2434 self.processingHeaderObj.size = processingHeaderSize
2422
2435
2423 class SpectraHeisWriter():
2436 class SpectraHeisWriter():
2424
2437
2425 i=0
2438 i=0
2426
2439
2427 def __init__(self, dataOut):
2440 def __init__(self, dataOut):
2428
2441
2429 self.wrObj = FITS()
2442 self.wrObj = FITS()
2430 self.dataOut = dataOut
2443 self.dataOut = dataOut
2431
2444
2432 def isNumber(str):
2445 def isNumber(str):
2433 """
2446 """
2434 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2447 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2435
2448
2436 Excepciones:
2449 Excepciones:
2437 Si un determinado string no puede ser convertido a numero
2450 Si un determinado string no puede ser convertido a numero
2438 Input:
2451 Input:
2439 str, string al cual se le analiza para determinar si convertible a un numero o no
2452 str, string al cual se le analiza para determinar si convertible a un numero o no
2440
2453
2441 Return:
2454 Return:
2442 True : si el string es uno numerico
2455 True : si el string es uno numerico
2443 False : no es un string numerico
2456 False : no es un string numerico
2444 """
2457 """
2445 try:
2458 try:
2446 float( str )
2459 float( str )
2447 return True
2460 return True
2448 except:
2461 except:
2449 return False
2462 return False
2450
2463
2451 def setup(self, wrpath,):
2464 def setup(self, wrpath,):
2452
2465
2453 if not(os.path.exists(wrpath)):
2466 if not(os.path.exists(wrpath)):
2454 os.mkdir(wrpath)
2467 os.mkdir(wrpath)
2455
2468
2456 self.wrpath = wrpath
2469 self.wrpath = wrpath
2457 self.setFile = 0
2470 self.setFile = 0
2458
2471
2459 def putData(self):
2472 def putData(self):
2460 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2473 # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints)
2461 #name = self.dataOut.utctime
2474 #name = self.dataOut.utctime
2462 name= time.localtime( self.dataOut.utctime)
2475 name= time.localtime( self.dataOut.utctime)
2463 ext=".fits"
2476 ext=".fits"
2464 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2477 #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday)
2465 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2478 subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday)
2466
2479
2467 fullpath = os.path.join( self.wrpath, subfolder )
2480 fullpath = os.path.join( self.wrpath, subfolder )
2468 if not( os.path.exists(fullpath) ):
2481 if not( os.path.exists(fullpath) ):
2469 os.mkdir(fullpath)
2482 os.mkdir(fullpath)
2470 self.setFile += 1
2483 self.setFile += 1
2471 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2484 file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2472
2485
2473 filename = os.path.join(self.wrpath,subfolder, file)
2486 filename = os.path.join(self.wrpath,subfolder, file)
2474
2487
2475 # print self.dataOut.ippSeconds
2488 # print self.dataOut.ippSeconds
2476 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2489 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds)
2477
2490
2478 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2491 col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2479 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2492 col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:]))
2480 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2493 col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:]))
2481 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2494 col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:]))
2482 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2495 col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:]))
2483 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2496 col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:]))
2484 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2497 col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:]))
2485 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2498 col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:]))
2486 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2499 col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:]))
2487 #n=numpy.arange((100))
2500 #n=numpy.arange((100))
2488 n=self.dataOut.data_spc[6,:]
2501 n=self.dataOut.data_spc[6,:]
2489 a=self.wrObj.cFImage(n)
2502 a=self.wrObj.cFImage(n)
2490 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2503 b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9)
2491 self.wrObj.CFile(a,b)
2504 self.wrObj.CFile(a,b)
2492 self.wrObj.wFile(filename)
2505 self.wrObj.wFile(filename)
2493 return 1
2506 return 1
2494
2507
2495 class FITS:
2508 class FITS:
2496
2509
2497 name=None
2510 name=None
2498 format=None
2511 format=None
2499 array =None
2512 array =None
2500 data =None
2513 data =None
2501 thdulist=None
2514 thdulist=None
2502
2515
2503 def __init__(self):
2516 def __init__(self):
2504
2517
2505 pass
2518 pass
2506
2519
2507 def setColF(self,name,format,array):
2520 def setColF(self,name,format,array):
2508 self.name=name
2521 self.name=name
2509 self.format=format
2522 self.format=format
2510 self.array=array
2523 self.array=array
2511 a1=numpy.array([self.array],dtype=numpy.float32)
2524 a1=numpy.array([self.array],dtype=numpy.float32)
2512 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2525 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2513 return self.col1
2526 return self.col1
2514
2527
2515 # def setColP(self,name,format,data):
2528 # def setColP(self,name,format,data):
2516 # self.name=name
2529 # self.name=name
2517 # self.format=format
2530 # self.format=format
2518 # self.data=data
2531 # self.data=data
2519 # a2=numpy.array([self.data],dtype=numpy.float32)
2532 # a2=numpy.array([self.data],dtype=numpy.float32)
2520 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2533 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2521 # return self.col2
2534 # return self.col2
2522
2535
2523 def writeHeader(self,):
2536 def writeHeader(self,):
2524 pass
2537 pass
2525
2538
2526 def writeData(self,name,format,data):
2539 def writeData(self,name,format,data):
2527 self.name=name
2540 self.name=name
2528 self.format=format
2541 self.format=format
2529 self.data=data
2542 self.data=data
2530 a2=numpy.array([self.data],dtype=numpy.float32)
2543 a2=numpy.array([self.data],dtype=numpy.float32)
2531 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2544 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2532 return self.col2
2545 return self.col2
2533
2546
2534 def cFImage(self,n):
2547 def cFImage(self,n):
2535 self.hdu= pyfits.PrimaryHDU(n)
2548 self.hdu= pyfits.PrimaryHDU(n)
2536 return self.hdu
2549 return self.hdu
2537
2550
2538 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2551 def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9):
2539 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2552 self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9])
2540 self.tbhdu = pyfits.new_table(self.cols)
2553 self.tbhdu = pyfits.new_table(self.cols)
2541 return self.tbhdu
2554 return self.tbhdu
2542
2555
2543 def CFile(self,hdu,tbhdu):
2556 def CFile(self,hdu,tbhdu):
2544 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2557 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2545
2558
2546 def wFile(self,filename):
2559 def wFile(self,filename):
2547 self.thdulist.writeto(filename) No newline at end of file
2560 self.thdulist.writeto(filename)
@@ -1,519 +1,519
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10
10
11 class Header:
11 class Header:
12
12
13 def __init__(self):
13 def __init__(self):
14 raise
14 raise
15
15
16 def copy(self):
16 def copy(self):
17 return copy.deepcopy(self)
17 return copy.deepcopy(self)
18
18
19 def read():
19 def read():
20 pass
20 pass
21
21
22 def write():
22 def write():
23 pass
23 pass
24
24
25 def printInfo(self):
25 def printInfo(self):
26
26
27 for key in self.__dict__.keys():
27 for key in self.__dict__.keys():
28 print "%s = %s" %(key, self.__dict__[key])
28 print "%s = %s" %(key, self.__dict__[key])
29
29
30 class BasicHeader(Header):
30 class BasicHeader(Header):
31
31
32 size = None
32 size = None
33 version = None
33 version = None
34 dataBlock = None
34 dataBlock = None
35 utc = None
35 utc = None
36 miliSecond = None
36 miliSecond = None
37 timeZone = None
37 timeZone = None
38 dstFlag = None
38 dstFlag = None
39 errorCount = None
39 errorCount = None
40 struct = None
40 struct = None
41 datatime = None
41 datatime = None
42
42
43 def __init__(self):
43 def __init__(self):
44
44
45 self.size = 0
45 self.size = 0
46 self.version = 0
46 self.version = 0
47 self.dataBlock = 0
47 self.dataBlock = 0
48 self.utc = 0
48 self.utc = 0
49 self.miliSecond = 0
49 self.miliSecond = 0
50 self.timeZone = 0
50 self.timeZone = 0
51 self.dstFlag = 0
51 self.dstFlag = 0
52 self.errorCount = 0
52 self.errorCount = 0
53 self.struct = numpy.dtype([
53 self.struct = numpy.dtype([
54 ('nSize','<u4'),
54 ('nSize','<u4'),
55 ('nVersion','<u2'),
55 ('nVersion','<u2'),
56 ('nDataBlockId','<u4'),
56 ('nDataBlockId','<u4'),
57 ('nUtime','<u4'),
57 ('nUtime','<u4'),
58 ('nMilsec','<u2'),
58 ('nMilsec','<u2'),
59 ('nTimezone','<i2'),
59 ('nTimezone','<i2'),
60 ('nDstflag','<i2'),
60 ('nDstflag','<i2'),
61 ('nErrorCount','<u4')
61 ('nErrorCount','<u4')
62 ])
62 ])
63
63
64
64
65 def read(self, fp):
65 def read(self, fp):
66 try:
66 try:
67 header = numpy.fromfile(fp, self.struct,1)
67 header = numpy.fromfile(fp, self.struct,1)
68 self.size = int(header['nSize'][0])
68 self.size = int(header['nSize'][0])
69 self.version = int(header['nVersion'][0])
69 self.version = int(header['nVersion'][0])
70 self.dataBlock = int(header['nDataBlockId'][0])
70 self.dataBlock = int(header['nDataBlockId'][0])
71 self.utc = int(header['nUtime'][0])
71 self.utc = int(header['nUtime'][0])
72 self.miliSecond = int(header['nMilsec'][0])
72 self.miliSecond = int(header['nMilsec'][0])
73 self.timeZone = int(header['nTimezone'][0])
73 self.timeZone = int(header['nTimezone'][0])
74 self.dstFlag = int(header['nDstflag'][0])
74 self.dstFlag = int(header['nDstflag'][0])
75 self.errorCount = int(header['nErrorCount'][0])
75 self.errorCount = int(header['nErrorCount'][0])
76
76
77 self.datatime = datetime.datetime.utcfromtimestamp(self.utc)
77 self.datatime = datetime.datetime.utcfromtimestamp(self.utc)
78 except Exception, e:
78 except Exception, e:
79 print "BasicHeader: " + e
79 print "BasicHeader: " + e
80 return 0
80 return 0
81
81
82 return 1
82 return 1
83
83
84 def write(self, fp):
84 def write(self, fp):
85 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
85 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
86 header = numpy.array(headerTuple,self.struct)
86 header = numpy.array(headerTuple,self.struct)
87 header.tofile(fp)
87 header.tofile(fp)
88
88
89 return 1
89 return 1
90
90
91 class SystemHeader(Header):
91 class SystemHeader(Header):
92
92
93 size = None
93 size = None
94 nSamples = None
94 nSamples = None
95 nProfiles = None
95 nProfiles = None
96 nChannels = None
96 nChannels = None
97 adcResolution = None
97 adcResolution = None
98 pciDioBusWidth = None
98 pciDioBusWidth = None
99 struct = None
99 struct = None
100
100
101 def __init__(self):
101 def __init__(self):
102 self.size = 0
102 self.size = 0
103 self.nSamples = 0
103 self.nSamples = 0
104 self.nProfiles = 0
104 self.nProfiles = 0
105 self.nChannels = 0
105 self.nChannels = 0
106 self.adcResolution = 0
106 self.adcResolution = 0
107 self.pciDioBusWidth = 0
107 self.pciDioBusWidth = 0
108 self.struct = numpy.dtype([
108 self.struct = numpy.dtype([
109 ('nSize','<u4'),
109 ('nSize','<u4'),
110 ('nNumSamples','<u4'),
110 ('nNumSamples','<u4'),
111 ('nNumProfiles','<u4'),
111 ('nNumProfiles','<u4'),
112 ('nNumChannels','<u4'),
112 ('nNumChannels','<u4'),
113 ('nADCResolution','<u4'),
113 ('nADCResolution','<u4'),
114 ('nPCDIOBusWidth','<u4'),
114 ('nPCDIOBusWidth','<u4'),
115 ])
115 ])
116
116
117
117
118 def read(self, fp):
118 def read(self, fp):
119 try:
119 try:
120 header = numpy.fromfile(fp,self.struct,1)
120 header = numpy.fromfile(fp,self.struct,1)
121 self.size = header['nSize'][0]
121 self.size = header['nSize'][0]
122 self.nSamples = header['nNumSamples'][0]
122 self.nSamples = header['nNumSamples'][0]
123 self.nProfiles = header['nNumProfiles'][0]
123 self.nProfiles = header['nNumProfiles'][0]
124 self.nChannels = header['nNumChannels'][0]
124 self.nChannels = header['nNumChannels'][0]
125 self.adcResolution = header['nADCResolution'][0]
125 self.adcResolution = header['nADCResolution'][0]
126 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
126 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
127
127
128 except Exception, e:
128 except Exception, e:
129 print "SystemHeader: " + e
129 print "SystemHeader: " + e
130 return 0
130 return 0
131
131
132 return 1
132 return 1
133
133
134 def write(self, fp):
134 def write(self, fp):
135 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
135 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
136 header = numpy.array(headerTuple,self.struct)
136 header = numpy.array(headerTuple,self.struct)
137 header.tofile(fp)
137 header.tofile(fp)
138
138
139 return 1
139 return 1
140
140
141 class RadarControllerHeader(Header):
141 class RadarControllerHeader(Header):
142
142
143 size = None
143 size = None
144 expType = None
144 expType = None
145 nTx = None
145 nTx = None
146 ipp = None
146 ipp = None
147 txA = None
147 txA = None
148 txB = None
148 txB = None
149 nWindows = None
149 nWindows = None
150 numTaus = None
150 numTaus = None
151 codeType = None
151 codeType = None
152 line6Function = None
152 line6Function = None
153 line5Function = None
153 line5Function = None
154 fClock = None
154 fClock = None
155 prePulseBefore = None
155 prePulseBefore = None
156 prePulserAfter = None
156 prePulserAfter = None
157 rangeIpp = None
157 rangeIpp = None
158 rangeTxA = None
158 rangeTxA = None
159 rangeTxB = None
159 rangeTxB = None
160 struct = None
160 struct = None
161
161
162 def __init__(self):
162 def __init__(self):
163 self.size = 0
163 self.size = 0
164 self.expType = 0
164 self.expType = 0
165 self.nTx = 0
165 self.nTx = 0
166 self.ipp = 0
166 self.ipp = 0
167 self.txA = 0
167 self.txA = 0
168 self.txB = 0
168 self.txB = 0
169 self.nWindows = 0
169 self.nWindows = 0
170 self.numTaus = 0
170 self.numTaus = 0
171 self.codeType = 0
171 self.codeType = 0
172 self.line6Function = 0
172 self.line6Function = 0
173 self.line5Function = 0
173 self.line5Function = 0
174 self.fClock = 0
174 self.fClock = 0
175 self.prePulseBefore = 0
175 self.prePulseBefore = 0
176 self.prePulserAfter = 0
176 self.prePulserAfter = 0
177 self.rangeIpp = 0
177 self.rangeIpp = 0
178 self.rangeTxA = 0
178 self.rangeTxA = 0
179 self.rangeTxB = 0
179 self.rangeTxB = 0
180 self.struct = numpy.dtype([
180 self.struct = numpy.dtype([
181 ('nSize','<u4'),
181 ('nSize','<u4'),
182 ('nExpType','<u4'),
182 ('nExpType','<u4'),
183 ('nNTx','<u4'),
183 ('nNTx','<u4'),
184 ('fIpp','<f4'),
184 ('fIpp','<f4'),
185 ('fTxA','<f4'),
185 ('fTxA','<f4'),
186 ('fTxB','<f4'),
186 ('fTxB','<f4'),
187 ('nNumWindows','<u4'),
187 ('nNumWindows','<u4'),
188 ('nNumTaus','<u4'),
188 ('nNumTaus','<u4'),
189 ('nCodeType','<u4'),
189 ('nCodeType','<u4'),
190 ('nLine6Function','<u4'),
190 ('nLine6Function','<u4'),
191 ('nLine5Function','<u4'),
191 ('nLine5Function','<u4'),
192 ('fClock','<f4'),
192 ('fClock','<f4'),
193 ('nPrePulseBefore','<u4'),
193 ('nPrePulseBefore','<u4'),
194 ('nPrePulseAfter','<u4'),
194 ('nPrePulseAfter','<u4'),
195 ('sRangeIPP','<a20'),
195 ('sRangeIPP','<a20'),
196 ('sRangeTxA','<a20'),
196 ('sRangeTxA','<a20'),
197 ('sRangeTxB','<a20'),
197 ('sRangeTxB','<a20'),
198 ])
198 ])
199
199
200 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
200 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
201
201
202 self.samplingWindow = None
202 self.samplingWindow = None
203 self.nHeights = None
203 self.nHeights = None
204 self.firstHeight = None
204 self.firstHeight = None
205 self.deltaHeight = None
205 self.deltaHeight = None
206 self.samplesWin = None
206 self.samplesWin = None
207
207
208 self.nCode = None
208 self.nCode = None
209 self.nBaud = None
209 self.nBaud = None
210 self.code = None
210 self.code = None
211 self.flip1 = None
211 self.flip1 = None
212 self.flip2 = None
212 self.flip2 = None
213
213
214 self.dynamic = numpy.array([],numpy.dtype('byte'))
214 self.dynamic = numpy.array([],numpy.dtype('byte'))
215
215
216
216
217 def read(self, fp):
217 def read(self, fp):
218 try:
218 try:
219 startFp = fp.tell()
219 startFp = fp.tell()
220 header = numpy.fromfile(fp,self.struct,1)
220 header = numpy.fromfile(fp,self.struct,1)
221 self.size = int(header['nSize'][0])
221 self.size = int(header['nSize'][0])
222 self.expType = int(header['nExpType'][0])
222 self.expType = int(header['nExpType'][0])
223 self.nTx = int(header['nNTx'][0])
223 self.nTx = int(header['nNTx'][0])
224 self.ipp = float(header['fIpp'][0])
224 self.ipp = float(header['fIpp'][0])
225 self.txA = float(header['fTxA'][0])
225 self.txA = float(header['fTxA'][0])
226 self.txB = float(header['fTxB'][0])
226 self.txB = float(header['fTxB'][0])
227 self.nWindows = int(header['nNumWindows'][0])
227 self.nWindows = int(header['nNumWindows'][0])
228 self.numTaus = int(header['nNumTaus'][0])
228 self.numTaus = int(header['nNumTaus'][0])
229 self.codeType = int(header['nCodeType'][0])
229 self.codeType = int(header['nCodeType'][0])
230 self.line6Function = int(header['nLine6Function'][0])
230 self.line6Function = int(header['nLine6Function'][0])
231 self.line5Function = int(header['nLine5Function'][0])
231 self.line5Function = int(header['nLine5Function'][0])
232 self.fClock = float(header['fClock'][0])
232 self.fClock = float(header['fClock'][0])
233 self.prePulseBefore = int(header['nPrePulseBefore'][0])
233 self.prePulseBefore = int(header['nPrePulseBefore'][0])
234 self.prePulserAfter = int(header['nPrePulseAfter'][0])
234 self.prePulserAfter = int(header['nPrePulseAfter'][0])
235 self.rangeIpp = header['sRangeIPP'][0]
235 self.rangeIpp = header['sRangeIPP'][0]
236 self.rangeTxA = header['sRangeTxA'][0]
236 self.rangeTxA = header['sRangeTxA'][0]
237 self.rangeTxB = header['sRangeTxB'][0]
237 self.rangeTxB = header['sRangeTxB'][0]
238 # jump Dynamic Radar Controller Header
238 # jump Dynamic Radar Controller Header
239 jumpFp = self.size - 116
239 jumpFp = self.size - 116
240 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
240 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
241 #pointer backward to dynamic header and read
241 #pointer backward to dynamic header and read
242 backFp = fp.tell() - jumpFp
242 backFp = fp.tell() - jumpFp
243 fp.seek(backFp)
243 fp.seek(backFp)
244
244
245 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
245 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
246 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
246 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
247 self.firstHeight = self.samplingWindow['h0']
247 self.firstHeight = self.samplingWindow['h0']
248 self.deltaHeight = self.samplingWindow['dh']
248 self.deltaHeight = self.samplingWindow['dh']
249 self.samplesWin = self.samplingWindow['nsa']
249 self.samplesWin = self.samplingWindow['nsa']
250
250
251 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
251 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
252
252
253 if self.codeType != 0:
253 if self.codeType != 0:
254 self.nCode = int(numpy.fromfile(fp,'<u4',1))
254 self.nCode = int(numpy.fromfile(fp,'<u4',1))
255 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
255 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
256 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
256 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
257 tempList = []
257 tempList = []
258 for ic in range(self.nCode):
258 for ic in range(self.nCode):
259 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
259 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
260 tempList.append(temp)
260 tempList.append(temp)
261 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
261 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
262 self.code = 2.0*self.code - 1.0
262 self.code = 2.0*self.code - 1.0
263
263
264 if self.line5Function == RCfunction.FLIP:
264 if self.line5Function == RCfunction.FLIP:
265 self.flip1 = numpy.fromfile(fp,'<u4',1)
265 self.flip1 = numpy.fromfile(fp,'<u4',1)
266
266
267 if self.line6Function == RCfunction.FLIP:
267 if self.line6Function == RCfunction.FLIP:
268 self.flip2 = numpy.fromfile(fp,'<u4',1)
268 self.flip2 = numpy.fromfile(fp,'<u4',1)
269
269
270 endFp = self.size + startFp
270 endFp = self.size + startFp
271 jumpFp = endFp - fp.tell()
271 jumpFp = endFp - fp.tell()
272 if jumpFp > 0:
272 if jumpFp > 0:
273 fp.seek(jumpFp)
273 fp.seek(jumpFp)
274
274
275 except Exception, e:
275 except Exception, e:
276 print "RadarControllerHeader: " + e
276 print "RadarControllerHeader: " + e
277 return 0
277 return 0
278
278
279 return 1
279 return 1
280
280
281 def write(self, fp):
281 def write(self, fp):
282 headerTuple = (self.size,
282 headerTuple = (self.size,
283 self.expType,
283 self.expType,
284 self.nTx,
284 self.nTx,
285 self.ipp,
285 self.ipp,
286 self.txA,
286 self.txA,
287 self.txB,
287 self.txB,
288 self.nWindows,
288 self.nWindows,
289 self.numTaus,
289 self.numTaus,
290 self.codeType,
290 self.codeType,
291 self.line6Function,
291 self.line6Function,
292 self.line5Function,
292 self.line5Function,
293 self.fClock,
293 self.fClock,
294 self.prePulseBefore,
294 self.prePulseBefore,
295 self.prePulserAfter,
295 self.prePulserAfter,
296 self.rangeIpp,
296 self.rangeIpp,
297 self.rangeTxA,
297 self.rangeTxA,
298 self.rangeTxB)
298 self.rangeTxB)
299
299
300 header = numpy.array(headerTuple,self.struct)
300 header = numpy.array(headerTuple,self.struct)
301 header.tofile(fp)
301 header.tofile(fp)
302
302
303 dynamic = self.dynamic
303 dynamic = self.dynamic
304 dynamic.tofile(fp)
304 dynamic.tofile(fp)
305
305
306 return 1
306 return 1
307
307
308
308
309
309
310 class ProcessingHeader(Header):
310 class ProcessingHeader(Header):
311
311
312 size = None
312 size = None
313 dtype = None
313 dtype = None
314 blockSize = None
314 blockSize = None
315 profilesPerBlock = None
315 profilesPerBlock = None
316 dataBlocksPerFile = None
316 dataBlocksPerFile = None
317 nWindows = None
317 nWindows = None
318 processFlags = None
318 processFlags = None
319 nCohInt = None
319 nCohInt = None
320 nIncohInt = None
320 nIncohInt = None
321 totalSpectra = None
321 totalSpectra = None
322 struct = None
322 struct = None
323 flag_dc = None
323 flag_dc = None
324 flag_cspc = None
324 flag_cspc = None
325
325
326 def __init__(self):
326 def __init__(self):
327 self.size = 0
327 self.size = 0
328 self.dtype = 0
328 self.dtype = 0
329 self.blockSize = 0
329 self.blockSize = 0
330 self.profilesPerBlock = 0
330 self.profilesPerBlock = 0
331 self.dataBlocksPerFile = 0
331 self.dataBlocksPerFile = 0
332 self.nWindows = 0
332 self.nWindows = 0
333 self.processFlags = 0
333 self.processFlags = 0
334 self.nCohInt = 0
334 self.nCohInt = 0
335 self.nIncohInt = 0
335 self.nIncohInt = 0
336 self.totalSpectra = 0
336 self.totalSpectra = 0
337 self.struct = numpy.dtype([
337 self.struct = numpy.dtype([
338 ('nSize','<u4'),
338 ('nSize','<u4'),
339 ('nDataType','<u4'),
339 ('nDataType','<u4'),
340 ('nSizeOfDataBlock','<u4'),
340 ('nSizeOfDataBlock','<u4'),
341 ('nProfilesperBlock','<u4'),
341 ('nProfilesperBlock','<u4'),
342 ('nDataBlocksperFile','<u4'),
342 ('nDataBlocksperFile','<u4'),
343 ('nNumWindows','<u4'),
343 ('nNumWindows','<u4'),
344 ('nProcessFlags','<u4'),
344 ('nProcessFlags','<u4'),
345 ('nCoherentIntegrations','<u4'),
345 ('nCoherentIntegrations','<u4'),
346 ('nIncoherentIntegrations','<u4'),
346 ('nIncoherentIntegrations','<u4'),
347 ('nTotalSpectra','<u4')
347 ('nTotalSpectra','<u4')
348 ])
348 ])
349 self.samplingWindow = 0
349 self.samplingWindow = 0
350 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
350 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
351 self.nHeights = 0
351 self.nHeights = 0
352 self.firstHeight = 0
352 self.firstHeight = 0
353 self.deltaHeight = 0
353 self.deltaHeight = 0
354 self.samplesWin = 0
354 self.samplesWin = 0
355 self.spectraComb = 0
355 self.spectraComb = 0
356 self.nCode = None
356 self.nCode = None
357 self.code = None
357 self.code = None
358 self.nBaud = None
358 self.nBaud = None
359 self.shif_fft = False
359 self.shif_fft = False
360 self.flag_dc = False
360 self.flag_dc = False
361 self.flag_cspc = False
361 self.flag_cspc = False
362
362
363 def read(self, fp):
363 def read(self, fp):
364 try:
364 try:
365 header = numpy.fromfile(fp,self.struct,1)
365 header = numpy.fromfile(fp,self.struct,1)
366 self.size = int(header['nSize'][0])
366 self.size = int(header['nSize'][0])
367 self.dtype = int(header['nDataType'][0])
367 self.dtype = int(header['nDataType'][0])
368 self.blockSize = int(header['nSizeOfDataBlock'][0])
368 self.blockSize = int(header['nSizeOfDataBlock'][0])
369 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
369 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
370 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
370 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
371 self.nWindows = int(header['nNumWindows'][0])
371 self.nWindows = int(header['nNumWindows'][0])
372 self.processFlags = int(header['nProcessFlags'])
372 self.processFlags = header['nProcessFlags']
373 self.nCohInt = int(header['nCoherentIntegrations'][0])
373 self.nCohInt = int(header['nCoherentIntegrations'][0])
374 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
374 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
375 self.totalSpectra = int(header['nTotalSpectra'][0])
375 self.totalSpectra = int(header['nTotalSpectra'][0])
376 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
376 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
377 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
377 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
378 self.firstHeight = float(self.samplingWindow['h0'][0])
378 self.firstHeight = float(self.samplingWindow['h0'][0])
379 self.deltaHeight = float(self.samplingWindow['dh'][0])
379 self.deltaHeight = float(self.samplingWindow['dh'][0])
380 self.samplesWin = self.samplingWindow['nsa']
380 self.samplesWin = self.samplingWindow['nsa']
381 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
381 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
382
382
383 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
383 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
384 self.nCode = int(numpy.fromfile(fp,'<u4',1))
384 self.nCode = int(numpy.fromfile(fp,'<u4',1))
385 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
385 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
386 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
386 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nBaud,self.nCode)
387
387
388 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
388 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
389 self.shif_fft = True
389 self.shif_fft = True
390 else:
390 else:
391 self.shif_fft = False
391 self.shif_fft = False
392
392
393 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
393 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
394 self.flag_dc = True
394 self.flag_dc = True
395
395
396 nChannels = 0
396 nChannels = 0
397 nPairs = 0
397 nPairs = 0
398 pairList = []
398 pairList = []
399
399
400 for i in range( 0, self.totalSpectra*2, 2 ):
400 for i in range( 0, self.totalSpectra*2, 2 ):
401 if self.spectraComb[i] == self.spectraComb[i+1]:
401 if self.spectraComb[i] == self.spectraComb[i+1]:
402 nChannels = nChannels + 1 #par de canales iguales
402 nChannels = nChannels + 1 #par de canales iguales
403 else:
403 else:
404 nPairs = nPairs + 1 #par de canales diferentes
404 nPairs = nPairs + 1 #par de canales diferentes
405 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
405 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
406
406
407 self.flag_cspc = False
407 self.flag_cspc = False
408 if nPairs > 0:
408 if nPairs > 0:
409 self.flag_cspc = True
409 self.flag_cspc = True
410
410
411 except Exception, e:
411 except Exception, e:
412 print "ProcessingHeader: " + e
412 print "ProcessingHeader: " + e
413 return 0
413 return 0
414
414
415 return 1
415 return 1
416
416
417 def write(self, fp):
417 def write(self, fp):
418 headerTuple = (self.size,
418 headerTuple = (self.size,
419 self.dtype,
419 self.dtype,
420 self.blockSize,
420 self.blockSize,
421 self.profilesPerBlock,
421 self.profilesPerBlock,
422 self.dataBlocksPerFile,
422 self.dataBlocksPerFile,
423 self.nWindows,
423 self.nWindows,
424 self.processFlags,
424 self.processFlags,
425 self.nCohInt,
425 self.nCohInt,
426 self.nIncohInt,
426 self.nIncohInt,
427 self.totalSpectra)
427 self.totalSpectra)
428
428
429 header = numpy.array(headerTuple,self.struct)
429 header = numpy.array(headerTuple,self.struct)
430 header.tofile(fp)
430 header.tofile(fp)
431
431
432 if self.nWindows != 0:
432 if self.nWindows != 0:
433 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
433 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
434 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
434 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
435 samplingWindow.tofile(fp)
435 samplingWindow.tofile(fp)
436
436
437
437
438 if self.totalSpectra != 0:
438 if self.totalSpectra != 0:
439 spectraComb = numpy.array([],numpy.dtype('u1'))
439 spectraComb = numpy.array([],numpy.dtype('u1'))
440 spectraComb = self.spectraComb
440 spectraComb = self.spectraComb
441 spectraComb.tofile(fp)
441 spectraComb.tofile(fp)
442
442
443
443
444 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
444 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
445 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
445 nCode = self.nCode #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
446 nCode.tofile(fp)
446 nCode.tofile(fp)
447
447
448 nBaud = self.nBaud
448 nBaud = self.nBaud
449 nBaud.tofile(fp)
449 nBaud.tofile(fp)
450
450
451 code = self.code.reshape(nCode*nBaud)
451 code = self.code.reshape(nCode*nBaud)
452 code.tofile(fp)
452 code.tofile(fp)
453
453
454 return 1
454 return 1
455
455
456 class RCfunction:
456 class RCfunction:
457 NONE=0
457 NONE=0
458 FLIP=1
458 FLIP=1
459 CODE=2
459 CODE=2
460 SAMPLING=3
460 SAMPLING=3
461 LIN6DIV256=4
461 LIN6DIV256=4
462 SYNCHRO=5
462 SYNCHRO=5
463
463
464 class nCodeType:
464 class nCodeType:
465 NONE=0
465 NONE=0
466 USERDEFINE=1
466 USERDEFINE=1
467 BARKER2=2
467 BARKER2=2
468 BARKER3=3
468 BARKER3=3
469 BARKER4=4
469 BARKER4=4
470 BARKER5=5
470 BARKER5=5
471 BARKER7=6
471 BARKER7=6
472 BARKER11=7
472 BARKER11=7
473 BARKER13=8
473 BARKER13=8
474 AC128=9
474 AC128=9
475 COMPLEMENTARYCODE2=10
475 COMPLEMENTARYCODE2=10
476 COMPLEMENTARYCODE4=11
476 COMPLEMENTARYCODE4=11
477 COMPLEMENTARYCODE8=12
477 COMPLEMENTARYCODE8=12
478 COMPLEMENTARYCODE16=13
478 COMPLEMENTARYCODE16=13
479 COMPLEMENTARYCODE32=14
479 COMPLEMENTARYCODE32=14
480 COMPLEMENTARYCODE64=15
480 COMPLEMENTARYCODE64=15
481 COMPLEMENTARYCODE128=16
481 COMPLEMENTARYCODE128=16
482 CODE_BINARY28=17
482 CODE_BINARY28=17
483
483
484 class PROCFLAG:
484 class PROCFLAG:
485 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
485 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
486 DECODE_DATA = numpy.uint32(0x00000002)
486 DECODE_DATA = numpy.uint32(0x00000002)
487 SPECTRA_CALC = numpy.uint32(0x00000004)
487 SPECTRA_CALC = numpy.uint32(0x00000004)
488 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
488 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
489 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
489 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
490 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
490 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
491
491
492 DATATYPE_CHAR = numpy.uint32(0x00000040)
492 DATATYPE_CHAR = numpy.uint32(0x00000040)
493 DATATYPE_SHORT = numpy.uint32(0x00000080)
493 DATATYPE_SHORT = numpy.uint32(0x00000080)
494 DATATYPE_LONG = numpy.uint32(0x00000100)
494 DATATYPE_LONG = numpy.uint32(0x00000100)
495 DATATYPE_INT64 = numpy.uint32(0x00000200)
495 DATATYPE_INT64 = numpy.uint32(0x00000200)
496 DATATYPE_FLOAT = numpy.uint32(0x00000400)
496 DATATYPE_FLOAT = numpy.uint32(0x00000400)
497 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
497 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
498
498
499 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
499 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
500 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
500 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
501 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
501 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
502
502
503 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
503 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
504 DEFLIP_DATA = numpy.uint32(0x00010000)
504 DEFLIP_DATA = numpy.uint32(0x00010000)
505 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
505 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
506
506
507 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
507 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
508 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
508 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
509 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
509 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
510 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
510 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
511 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
511 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
512
512
513 EXP_NAME_ESP = numpy.uint32(0x00200000)
513 EXP_NAME_ESP = numpy.uint32(0x00200000)
514 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
514 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
515
515
516 OPERATION_MASK = numpy.uint32(0x0000003F)
516 OPERATION_MASK = numpy.uint32(0x0000003F)
517 DATATYPE_MASK = numpy.uint32(0x00000FC0)
517 DATATYPE_MASK = numpy.uint32(0x00000FC0)
518 DATAARRANGE_MASK = numpy.uint32(0x00007000)
518 DATAARRANGE_MASK = numpy.uint32(0x00007000)
519 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
519 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
@@ -1,818 +1,823
1 import numpy
1 import numpy
2 import time, datetime
2 import time, datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTHPROF = None
10 WIDTHPROF = None
11 HEIGHTPROF = None
11 HEIGHTPROF = None
12 PREFIX = 'cspc'
12 PREFIX = 'cspc'
13
13
14 def __init__(self):
14 def __init__(self):
15
15
16 self.__isConfig = False
16 self.__isConfig = False
17 self.__nsubplots = 4
17 self.__nsubplots = 4
18
18
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 400
20 self.HEIGHT = 400
21 self.WIDTHPROF = 0
21 self.WIDTHPROF = 0
22 self.HEIGHTPROF = 0
22 self.HEIGHTPROF = 0
23
23
24 def getSubplots(self):
24 def getSubplots(self):
25
25
26 ncol = 4
26 ncol = 4
27 nrow = self.nplots
27 nrow = self.nplots
28
28
29 return nrow, ncol
29 return nrow, ncol
30
30
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
31 def setup(self, idfigure, nplots, wintitle, showprofile=True):
32
32
33 self.__showprofile = showprofile
33 self.__showprofile = showprofile
34 self.nplots = nplots
34 self.nplots = nplots
35
35
36 ncolspan = 1
36 ncolspan = 1
37 colspan = 1
37 colspan = 1
38
38
39 self.createFigure(idfigure = idfigure,
39 self.createFigure(idfigure = idfigure,
40 wintitle = wintitle,
40 wintitle = wintitle,
41 widthplot = self.WIDTH + self.WIDTHPROF,
41 widthplot = self.WIDTH + self.WIDTHPROF,
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
42 heightplot = self.HEIGHT + self.HEIGHTPROF)
43
43
44 nrow, ncol = self.getSubplots()
44 nrow, ncol = self.getSubplots()
45
45
46 counter = 0
46 counter = 0
47 for y in range(nrow):
47 for y in range(nrow):
48 for x in range(ncol):
48 for x in range(ncol):
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
49 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
50
50
51 counter += 1
51 counter += 1
52
52
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
53 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
54 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
55 save=False, figpath='./', figfile=None):
55 save=False, figpath='./', figfile=None):
56
56
57 """
57 """
58
58
59 Input:
59 Input:
60 dataOut :
60 dataOut :
61 idfigure :
61 idfigure :
62 wintitle :
62 wintitle :
63 channelList :
63 channelList :
64 showProfile :
64 showProfile :
65 xmin : None,
65 xmin : None,
66 xmax : None,
66 xmax : None,
67 ymin : None,
67 ymin : None,
68 ymax : None,
68 ymax : None,
69 zmin : None,
69 zmin : None,
70 zmax : None
70 zmax : None
71 """
71 """
72
72
73 if pairsList == None:
73 if pairsList == None:
74 pairsIndexList = dataOut.pairsIndexList
74 pairsIndexList = dataOut.pairsIndexList
75 else:
75 else:
76 pairsIndexList = []
76 pairsIndexList = []
77 for pair in pairsList:
77 for pair in pairsList:
78 if pair not in dataOut.pairsList:
78 if pair not in dataOut.pairsList:
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
79 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
80 pairsIndexList.append(dataOut.pairsList.index(pair))
80 pairsIndexList.append(dataOut.pairsList.index(pair))
81
81
82 if pairsIndexList == []:
82 if pairsIndexList == []:
83 return
83 return
84
84
85 if len(pairsIndexList) > 4:
85 if len(pairsIndexList) > 4:
86 pairsIndexList = pairsIndexList[0:4]
86 pairsIndexList = pairsIndexList[0:4]
87
87
88 x = dataOut.getFreqRange(1)
88 x = dataOut.getFreqRange(1)
89 y = dataOut.getHeiRange()
89 y = dataOut.getHeiRange()
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
90 z = 10.*numpy.log10(dataOut.data_spc[:,:,:])
91 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
91 avg = numpy.average(numpy.abs(z), axis=1)
92 avg = numpy.average(numpy.abs(z), axis=1)
92
93
93 noise = dataOut.getNoise()
94 noise = dataOut.getNoise()
94
95
95 if not self.__isConfig:
96 if not self.__isConfig:
96
97
97 nplots = len(pairsIndexList)
98 nplots = len(pairsIndexList)
98
99
99 self.setup(idfigure=idfigure,
100 self.setup(idfigure=idfigure,
100 nplots=nplots,
101 nplots=nplots,
101 wintitle=wintitle,
102 wintitle=wintitle,
102 showprofile=showprofile)
103 showprofile=showprofile)
103
104
104 if xmin == None: xmin = numpy.nanmin(x)
105 if xmin == None: xmin = numpy.nanmin(x)
105 if xmax == None: xmax = numpy.nanmax(x)
106 if xmax == None: xmax = numpy.nanmax(x)
106 if ymin == None: ymin = numpy.nanmin(y)
107 if ymin == None: ymin = numpy.nanmin(y)
107 if ymax == None: ymax = numpy.nanmax(y)
108 if ymax == None: ymax = numpy.nanmax(y)
108 if zmin == None: zmin = numpy.nanmin(avg)*0.9
109 if zmin == None: zmin = numpy.nanmin(avg)*0.9
109 if zmax == None: zmax = numpy.nanmax(avg)*0.9
110 if zmax == None: zmax = numpy.nanmax(avg)*0.9
110
111
111 self.__isConfig = True
112 self.__isConfig = True
112
113
113 thisDatetime = dataOut.datatime
114 thisDatetime = dataOut.datatime
114 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
115 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
115 xlabel = "Velocity (m/s)"
116 xlabel = "Velocity (m/s)"
116 ylabel = "Range (Km)"
117 ylabel = "Range (Km)"
117
118
118 self.setWinTitle(title)
119 self.setWinTitle(title)
119
120
120 for i in range(self.nplots):
121 for i in range(self.nplots):
121 pair = dataOut.pairsList[pairsIndexList[i]]
122 pair = dataOut.pairsList[pairsIndexList[i]]
122
123
123 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
124 title = "Channel %d: %4.2fdB" %(pair[0], noise[pair[0]])
124 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
125 z = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:])
125 axes0 = self.axesList[i*self.__nsubplots]
126 axes0 = self.axesList[i*self.__nsubplots]
126 axes0.pcolor(x, y, z,
127 axes0.pcolor(x, y, z,
127 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
128 xlabel=xlabel, ylabel=ylabel, title=title,
129 xlabel=xlabel, ylabel=ylabel, title=title,
129 ticksize=9, cblabel='')
130 ticksize=9, cblabel='')
130
131
131 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
132 title = "Channel %d: %4.2fdB" %(pair[1], noise[pair[1]])
132 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
133 z = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:])
133 axes0 = self.axesList[i*self.__nsubplots+1]
134 axes0 = self.axesList[i*self.__nsubplots+1]
134 axes0.pcolor(x, y, z,
135 axes0.pcolor(x, y, z,
135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 xlabel=xlabel, ylabel=ylabel, title=title,
137 xlabel=xlabel, ylabel=ylabel, title=title,
137 ticksize=9, cblabel='')
138 ticksize=9, cblabel='')
138
139
139 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
140 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
140 coherence = numpy.abs(coherenceComplex)
141 coherence = numpy.abs(coherenceComplex)
141 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
142 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
142
143
143
144
144 title = "Coherence %d%d" %(pair[0], pair[1])
145 title = "Coherence %d%d" %(pair[0], pair[1])
145 axes0 = self.axesList[i*self.__nsubplots+2]
146 axes0 = self.axesList[i*self.__nsubplots+2]
146 axes0.pcolor(x, y, coherence,
147 axes0.pcolor(x, y, coherence,
147 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
148 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
148 xlabel=xlabel, ylabel=ylabel, title=title,
149 xlabel=xlabel, ylabel=ylabel, title=title,
149 ticksize=9, cblabel='')
150 ticksize=9, cblabel='')
150
151
151 title = "Phase %d%d" %(pair[0], pair[1])
152 title = "Phase %d%d" %(pair[0], pair[1])
152 axes0 = self.axesList[i*self.__nsubplots+3]
153 axes0 = self.axesList[i*self.__nsubplots+3]
153 axes0.pcolor(x, y, phase,
154 axes0.pcolor(x, y, phase,
154 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
155 xlabel=xlabel, ylabel=ylabel, title=title,
156 xlabel=xlabel, ylabel=ylabel, title=title,
156 ticksize=9, cblabel='', colormap='RdBu')
157 ticksize=9, cblabel='', colormap='RdBu')
157
158
158
159
159
160
160 self.draw()
161 self.draw()
161
162
162 if save:
163 if save:
163 date = thisDatetime.strftime("%Y%m%d")
164 date = thisDatetime.strftime("%Y%m%d")
164 if figfile == None:
165 if figfile == None:
165 figfile = self.getFilename(name = date)
166 figfile = self.getFilename(name = date)
166
167
167 self.saveFigure(figpath, figfile)
168 self.saveFigure(figpath, figfile)
168
169
169
170
170 class RTIPlot(Figure):
171 class RTIPlot(Figure):
171
172
172 __isConfig = None
173 __isConfig = None
173 __nsubplots = None
174 __nsubplots = None
174
175
175 WIDTHPROF = None
176 WIDTHPROF = None
176 HEIGHTPROF = None
177 HEIGHTPROF = None
177 PREFIX = 'rti'
178 PREFIX = 'rti'
178
179
179 def __init__(self):
180 def __init__(self):
180
181
181 self.timerange = 24*60*60
182 self.timerange = 24*60*60
182 self.__isConfig = False
183 self.__isConfig = False
183 self.__nsubplots = 1
184 self.__nsubplots = 1
184
185
185 self.WIDTH = 800
186 self.WIDTH = 800
186 self.HEIGHT = 200
187 self.HEIGHT = 200
187 self.WIDTHPROF = 120
188 self.WIDTHPROF = 120
188 self.HEIGHTPROF = 0
189 self.HEIGHTPROF = 0
189
190
190 def getSubplots(self):
191 def getSubplots(self):
191
192
192 ncol = 1
193 ncol = 1
193 nrow = self.nplots
194 nrow = self.nplots
194
195
195 return nrow, ncol
196 return nrow, ncol
196
197
197 def setup(self, idfigure, nplots, wintitle, showprofile=True):
198 def setup(self, idfigure, nplots, wintitle, showprofile=True):
198
199
199 self.__showprofile = showprofile
200 self.__showprofile = showprofile
200 self.nplots = nplots
201 self.nplots = nplots
201
202
202 ncolspan = 1
203 ncolspan = 1
203 colspan = 1
204 colspan = 1
204 if showprofile:
205 if showprofile:
205 ncolspan = 7
206 ncolspan = 7
206 colspan = 6
207 colspan = 6
207 self.__nsubplots = 2
208 self.__nsubplots = 2
208
209
209 self.createFigure(idfigure = idfigure,
210 self.createFigure(idfigure = idfigure,
210 wintitle = wintitle,
211 wintitle = wintitle,
211 widthplot = self.WIDTH + self.WIDTHPROF,
212 widthplot = self.WIDTH + self.WIDTHPROF,
212 heightplot = self.HEIGHT + self.HEIGHTPROF)
213 heightplot = self.HEIGHT + self.HEIGHTPROF)
213
214
214 nrow, ncol = self.getSubplots()
215 nrow, ncol = self.getSubplots()
215
216
216 counter = 0
217 counter = 0
217 for y in range(nrow):
218 for y in range(nrow):
218 for x in range(ncol):
219 for x in range(ncol):
219
220
220 if counter >= self.nplots:
221 if counter >= self.nplots:
221 break
222 break
222
223
223 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
224 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
224
225
225 if showprofile:
226 if showprofile:
226 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
227 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
227
228
228 counter += 1
229 counter += 1
229
230
230 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
231 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
231 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
232 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
232 timerange=None,
233 timerange=None,
233 save=False, figpath='./', figfile=None):
234 save=False, figpath='./', figfile=None):
234
235
235 """
236 """
236
237
237 Input:
238 Input:
238 dataOut :
239 dataOut :
239 idfigure :
240 idfigure :
240 wintitle :
241 wintitle :
241 channelList :
242 channelList :
242 showProfile :
243 showProfile :
243 xmin : None,
244 xmin : None,
244 xmax : None,
245 xmax : None,
245 ymin : None,
246 ymin : None,
246 ymax : None,
247 ymax : None,
247 zmin : None,
248 zmin : None,
248 zmax : None
249 zmax : None
249 """
250 """
250
251
251 if channelList == None:
252 if channelList == None:
252 channelIndexList = dataOut.channelIndexList
253 channelIndexList = dataOut.channelIndexList
253 else:
254 else:
254 channelIndexList = []
255 channelIndexList = []
255 for channel in channelList:
256 for channel in channelList:
256 if channel not in dataOut.channelList:
257 if channel not in dataOut.channelList:
257 raise ValueError, "Channel %d is not in dataOut.channelList"
258 raise ValueError, "Channel %d is not in dataOut.channelList"
258 channelIndexList.append(dataOut.channelList.index(channel))
259 channelIndexList.append(dataOut.channelList.index(channel))
259
260
260 if timerange != None:
261 if timerange != None:
261 self.timerange = timerange
262 self.timerange = timerange
262
263
263 tmin = None
264 tmin = None
264 tmax = None
265 tmax = None
265 x = dataOut.getTimeRange()
266 x = dataOut.getTimeRange()
266 y = dataOut.getHeiRange()
267 y = dataOut.getHeiRange()
267 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
268 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
269 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
268 avg = numpy.average(z, axis=1)
270 avg = numpy.average(z, axis=1)
269
271
270 noise = dataOut.getNoise()
272 noise = dataOut.getNoise()
271
273
272 if not self.__isConfig:
274 if not self.__isConfig:
273
275
274 nplots = len(channelIndexList)
276 nplots = len(channelIndexList)
275
277
276 self.setup(idfigure=idfigure,
278 self.setup(idfigure=idfigure,
277 nplots=nplots,
279 nplots=nplots,
278 wintitle=wintitle,
280 wintitle=wintitle,
279 showprofile=showprofile)
281 showprofile=showprofile)
280
282
281 tmin, tmax = self.getTimeLim(x, xmin, xmax)
283 tmin, tmax = self.getTimeLim(x, xmin, xmax)
282 if ymin == None: ymin = numpy.nanmin(y)
284 if ymin == None: ymin = numpy.nanmin(y)
283 if ymax == None: ymax = numpy.nanmax(y)
285 if ymax == None: ymax = numpy.nanmax(y)
284 if zmin == None: zmin = numpy.nanmin(avg)*0.9
286 if zmin == None: zmin = numpy.nanmin(avg)*0.9
285 if zmax == None: zmax = numpy.nanmax(avg)*0.9
287 if zmax == None: zmax = numpy.nanmax(avg)*0.9
286
288
289 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
287 self.__isConfig = True
290 self.__isConfig = True
288
291
289 thisDatetime = dataOut.datatime
292 thisDatetime = dataOut.datatime
290 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
293 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
291 xlabel = "Velocity (m/s)"
294 xlabel = "Velocity (m/s)"
292 ylabel = "Range (Km)"
295 ylabel = "Range (Km)"
293
296
294 self.setWinTitle(title)
297 self.setWinTitle(title)
295
298
296 for i in range(self.nplots):
299 for i in range(self.nplots):
297 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
300 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
298 axes = self.axesList[i*self.__nsubplots]
301 axes = self.axesList[i*self.__nsubplots]
299 z = avg[i].reshape((1,-1))
302 z = avg[i].reshape((1,-1))
300 axes.pcolor(x, y, z,
303 axes.pcolor(x, y, z,
301 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
304 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
302 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
305 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
303 ticksize=9, cblabel='', cbsize="1%")
306 ticksize=9, cblabel='', cbsize="1%")
304
307
305 if self.__showprofile:
308 if self.__showprofile:
306 axes = self.axesList[i*self.__nsubplots +1]
309 axes = self.axesList[i*self.__nsubplots +1]
307 axes.pline(avg[i], y,
310 axes.pline(avg[i], y,
308 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
311 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
309 xlabel='dB', ylabel='', title='',
312 xlabel='dB', ylabel='', title='',
310 ytick_visible=False,
313 ytick_visible=False,
311 grid='x')
314 grid='x')
312
315
313 self.draw()
316 self.draw()
314
317
315 if save:
318 if save:
316 date = thisDatetime.strftime("%Y%m%d")
319
317 if figfile == None:
320 if figfile == None:
318 figfile = self.getFilename(name = date)
321 figfile = self.getFilename(name = self.name)
319
322
320 self.saveFigure(figpath, figfile)
323 self.saveFigure(figpath, figfile)
321
324
322 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
325 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
323 self.__isConfig = False
326 self.__isConfig = False
324
327
325 class SpectraPlot(Figure):
328 class SpectraPlot(Figure):
326
329
327 __isConfig = None
330 __isConfig = None
328 __nsubplots = None
331 __nsubplots = None
329
332
330 WIDTHPROF = None
333 WIDTHPROF = None
331 HEIGHTPROF = None
334 HEIGHTPROF = None
332 PREFIX = 'spc'
335 PREFIX = 'spc'
333
336
334 def __init__(self):
337 def __init__(self):
335
338
336 self.__isConfig = False
339 self.__isConfig = False
337 self.__nsubplots = 1
340 self.__nsubplots = 1
338
341
339 self.WIDTH = 300
342 self.WIDTH = 300
340 self.HEIGHT = 400
343 self.HEIGHT = 400
341 self.WIDTHPROF = 120
344 self.WIDTHPROF = 120
342 self.HEIGHTPROF = 0
345 self.HEIGHTPROF = 0
343
346
344 def getSubplots(self):
347 def getSubplots(self):
345
348
346 ncol = int(numpy.sqrt(self.nplots)+0.9)
349 ncol = int(numpy.sqrt(self.nplots)+0.9)
347 nrow = int(self.nplots*1./ncol + 0.9)
350 nrow = int(self.nplots*1./ncol + 0.9)
348
351
349 return nrow, ncol
352 return nrow, ncol
350
353
351 def setup(self, idfigure, nplots, wintitle, showprofile=True):
354 def setup(self, idfigure, nplots, wintitle, showprofile=True):
352
355
353 self.__showprofile = showprofile
356 self.__showprofile = showprofile
354 self.nplots = nplots
357 self.nplots = nplots
355
358
356 ncolspan = 1
359 ncolspan = 1
357 colspan = 1
360 colspan = 1
358 if showprofile:
361 if showprofile:
359 ncolspan = 3
362 ncolspan = 3
360 colspan = 2
363 colspan = 2
361 self.__nsubplots = 2
364 self.__nsubplots = 2
362
365
363 self.createFigure(idfigure = idfigure,
366 self.createFigure(idfigure = idfigure,
364 wintitle = wintitle,
367 wintitle = wintitle,
365 widthplot = self.WIDTH + self.WIDTHPROF,
368 widthplot = self.WIDTH + self.WIDTHPROF,
366 heightplot = self.HEIGHT + self.HEIGHTPROF)
369 heightplot = self.HEIGHT + self.HEIGHTPROF)
367
370
368 nrow, ncol = self.getSubplots()
371 nrow, ncol = self.getSubplots()
369
372
370 counter = 0
373 counter = 0
371 for y in range(nrow):
374 for y in range(nrow):
372 for x in range(ncol):
375 for x in range(ncol):
373
376
374 if counter >= self.nplots:
377 if counter >= self.nplots:
375 break
378 break
376
379
377 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
378
381
379 if showprofile:
382 if showprofile:
380 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
383 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
381
384
382 counter += 1
385 counter += 1
383
386
384 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
387 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
385 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
388 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
386 save=False, figpath='./', figfile=None):
389 save=False, figpath='./', figfile=None):
387
390
388 """
391 """
389
392
390 Input:
393 Input:
391 dataOut :
394 dataOut :
392 idfigure :
395 idfigure :
393 wintitle :
396 wintitle :
394 channelList :
397 channelList :
395 showProfile :
398 showProfile :
396 xmin : None,
399 xmin : None,
397 xmax : None,
400 xmax : None,
398 ymin : None,
401 ymin : None,
399 ymax : None,
402 ymax : None,
400 zmin : None,
403 zmin : None,
401 zmax : None
404 zmax : None
402 """
405 """
403
406
404 if channelList == None:
407 if channelList == None:
405 channelIndexList = dataOut.channelIndexList
408 channelIndexList = dataOut.channelIndexList
406 else:
409 else:
407 channelIndexList = []
410 channelIndexList = []
408 for channel in channelList:
411 for channel in channelList:
409 if channel not in dataOut.channelList:
412 if channel not in dataOut.channelList:
410 raise ValueError, "Channel %d is not in dataOut.channelList"
413 raise ValueError, "Channel %d is not in dataOut.channelList"
411 channelIndexList.append(dataOut.channelList.index(channel))
414 channelIndexList.append(dataOut.channelList.index(channel))
412
415
413 x = dataOut.getVelRange(1)
416 x = dataOut.getVelRange(1)
414 y = dataOut.getHeiRange()
417 y = dataOut.getHeiRange()
418
415 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
419 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
420 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
416 avg = numpy.average(z, axis=1)
421 avg = numpy.average(z, axis=1)
417
422
418 noise = dataOut.getNoise()
423 noise = dataOut.getNoise()
419
424
420 if not self.__isConfig:
425 if not self.__isConfig:
421
426
422 nplots = len(channelIndexList)
427 nplots = len(channelIndexList)
423
428
424 self.setup(idfigure=idfigure,
429 self.setup(idfigure=idfigure,
425 nplots=nplots,
430 nplots=nplots,
426 wintitle=wintitle,
431 wintitle=wintitle,
427 showprofile=showprofile)
432 showprofile=showprofile)
428
433
429 if xmin == None: xmin = numpy.nanmin(x)
434 if xmin == None: xmin = numpy.nanmin(x)
430 if xmax == None: xmax = numpy.nanmax(x)
435 if xmax == None: xmax = numpy.nanmax(x)
431 if ymin == None: ymin = numpy.nanmin(y)
436 if ymin == None: ymin = numpy.nanmin(y)
432 if ymax == None: ymax = numpy.nanmax(y)
437 if ymax == None: ymax = numpy.nanmax(y)
433 if zmin == None: zmin = numpy.nanmin(avg)*0.9
438 if zmin == None: zmin = numpy.nanmin(avg)*0.9
434 if zmax == None: zmax = numpy.nanmax(avg)*0.9
439 if zmax == None: zmax = numpy.nanmax(avg)*0.9
435
440
436 self.__isConfig = True
441 self.__isConfig = True
437
442
438 thisDatetime = dataOut.datatime
443 thisDatetime = dataOut.datatime
439 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
444 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
440 xlabel = "Velocity (m/s)"
445 xlabel = "Velocity (m/s)"
441 ylabel = "Range (Km)"
446 ylabel = "Range (Km)"
442
447
443 self.setWinTitle(title)
448 self.setWinTitle(title)
444
449
445 for i in range(self.nplots):
450 for i in range(self.nplots):
446 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
451 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
447 axes = self.axesList[i*self.__nsubplots]
452 axes = self.axesList[i*self.__nsubplots]
448 axes.pcolor(x, y, z[i,:,:],
453 axes.pcolor(x, y, z[i,:,:],
449 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
454 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
450 xlabel=xlabel, ylabel=ylabel, title=title,
455 xlabel=xlabel, ylabel=ylabel, title=title,
451 ticksize=9, cblabel='')
456 ticksize=9, cblabel='')
452
457
453 if self.__showprofile:
458 if self.__showprofile:
454 axes = self.axesList[i*self.__nsubplots +1]
459 axes = self.axesList[i*self.__nsubplots +1]
455 axes.pline(avg[i], y,
460 axes.pline(avg[i], y,
456 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
461 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
457 xlabel='dB', ylabel='', title='',
462 xlabel='dB', ylabel='', title='',
458 ytick_visible=False,
463 ytick_visible=False,
459 grid='x')
464 grid='x')
460
465
461 self.draw()
466 self.draw()
462
467
463 if save:
468 if save:
464 date = thisDatetime.strftime("%Y%m%d")
469 date = thisDatetime.strftime("%Y%m%d")
465 if figfile == None:
470 if figfile == None:
466 figfile = self.getFilename(name = date)
471 figfile = self.getFilename(name = date)
467
472
468 self.saveFigure(figpath, figfile)
473 self.saveFigure(figpath, figfile)
469
474
470 class Scope(Figure):
475 class Scope(Figure):
471
476
472 __isConfig = None
477 __isConfig = None
473
478
474 def __init__(self):
479 def __init__(self):
475
480
476 self.__isConfig = False
481 self.__isConfig = False
477 self.WIDTH = 600
482 self.WIDTH = 600
478 self.HEIGHT = 200
483 self.HEIGHT = 200
479
484
480 def getSubplots(self):
485 def getSubplots(self):
481
486
482 nrow = self.nplots
487 nrow = self.nplots
483 ncol = 3
488 ncol = 3
484 return nrow, ncol
489 return nrow, ncol
485
490
486 def setup(self, idfigure, nplots, wintitle):
491 def setup(self, idfigure, nplots, wintitle):
487
492
493 self.nplots = nplots
494
488 self.createFigure(idfigure, wintitle)
495 self.createFigure(idfigure, wintitle)
489
496
490 nrow,ncol = self.getSubplots()
497 nrow,ncol = self.getSubplots()
491 colspan = 3
498 colspan = 3
492 rowspan = 1
499 rowspan = 1
493
500
494 for i in range(nplots):
501 for i in range(nplots):
495 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
502 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
496
503
497 self.nplots = nplots
504
498
505
499 def run(self, dataOut, idfigure, wintitle="", channelList=None,
506 def run(self, dataOut, idfigure, wintitle="", channelList=None,
500 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
507 xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None):
501
508
502 """
509 """
503
510
504 Input:
511 Input:
505 dataOut :
512 dataOut :
506 idfigure :
513 idfigure :
507 wintitle :
514 wintitle :
508 channelList :
515 channelList :
509 xmin : None,
516 xmin : None,
510 xmax : None,
517 xmax : None,
511 ymin : None,
518 ymin : None,
512 ymax : None,
519 ymax : None,
513 """
520 """
514
521
515 if channelList == None:
522 if channelList == None:
516 channelIndexList = dataOut.channelIndexList
523 channelIndexList = dataOut.channelIndexList
517 else:
524 else:
518 channelIndexList = []
525 channelIndexList = []
519 for channel in channelList:
526 for channel in channelList:
520 if channel not in dataOut.channelList:
527 if channel not in dataOut.channelList:
521 raise ValueError, "Channel %d is not in dataOut.channelList"
528 raise ValueError, "Channel %d is not in dataOut.channelList"
522 channelIndexList.append(dataOut.channelList.index(channel))
529 channelIndexList.append(dataOut.channelList.index(channel))
523
530
524 x = dataOut.heightList
531 x = dataOut.heightList
525 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
532 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
526 y = y.real
533 y = y.real
527
534
528 noise = dataOut.getNoise()
529
530 if not self.__isConfig:
535 if not self.__isConfig:
531 nplots = len(channelList)
536 nplots = len(channelIndexList)
532
537
533 self.setup(idfigure=idfigure,
538 self.setup(idfigure=idfigure,
534 nplots=nplots,
539 nplots=nplots,
535 wintitle=wintitle)
540 wintitle=wintitle)
536
541
537 if xmin == None: xmin = numpy.nanmin(x)
542 if xmin == None: xmin = numpy.nanmin(x)
538 if xmax == None: xmax = numpy.nanmax(x)
543 if xmax == None: xmax = numpy.nanmax(x)
539 if ymin == None: ymin = numpy.nanmin(y)
544 if ymin == None: ymin = numpy.nanmin(y)
540 if ymax == None: ymax = numpy.nanmax(y)
545 if ymax == None: ymax = numpy.nanmax(y)
541
546
542 self.__isConfig = True
547 self.__isConfig = True
543
548
544
549
545 thisDatetime = dataOut.datatime
550 thisDatetime = dataOut.datatime
546 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
551 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
547 xlabel = "Range (Km)"
552 xlabel = "Range (Km)"
548 ylabel = "Intensity"
553 ylabel = "Intensity"
549
554
550 self.setWinTitle(title)
555 self.setWinTitle(title)
551
556
552 for i in range(len(self.axesList)):
557 for i in range(len(self.axesList)):
553 title = "Channel %d: %4.2fdB" %(i, noise[i])
558 title = "Channel %d" %(i)
554 axes = self.axesList[i]
559 axes = self.axesList[i]
555 ychannel = y[i,:]
560 ychannel = y[i,:]
556 axes.pline(x, ychannel,
561 axes.pline(x, ychannel,
557 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
562 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
558 xlabel=xlabel, ylabel=ylabel, title=title)
563 xlabel=xlabel, ylabel=ylabel, title=title)
559
564
560 self.draw()
565 self.draw()
561
566
562 if save:
567 if save:
563 self.saveFigure(filename)
568 self.saveFigure(filename)
564
569
565 class ProfilePlot(Figure):
570 class ProfilePlot(Figure):
566 __isConfig = None
571 __isConfig = None
567 __nsubplots = None
572 __nsubplots = None
568
573
569 WIDTHPROF = None
574 WIDTHPROF = None
570 HEIGHTPROF = None
575 HEIGHTPROF = None
571 PREFIX = 'spcprofile'
576 PREFIX = 'spcprofile'
572
577
573 def __init__(self):
578 def __init__(self):
574 self.__isConfig = False
579 self.__isConfig = False
575 self.__nsubplots = 1
580 self.__nsubplots = 1
576
581
577 self.WIDTH = 300
582 self.WIDTH = 300
578 self.HEIGHT = 500
583 self.HEIGHT = 500
579
584
580 def getSubplots(self):
585 def getSubplots(self):
581 ncol = 1
586 ncol = 1
582 nrow = 1
587 nrow = 1
583
588
584 return nrow, ncol
589 return nrow, ncol
585
590
586 def setup(self, idfigure, nplots, wintitle):
591 def setup(self, idfigure, nplots, wintitle):
587
592
588 self.nplots = nplots
593 self.nplots = nplots
589
594
590 ncolspan = 1
595 ncolspan = 1
591 colspan = 1
596 colspan = 1
592
597
593 self.createFigure(idfigure = idfigure,
598 self.createFigure(idfigure = idfigure,
594 wintitle = wintitle,
599 wintitle = wintitle,
595 widthplot = self.WIDTH,
600 widthplot = self.WIDTH,
596 heightplot = self.HEIGHT)
601 heightplot = self.HEIGHT)
597
602
598 nrow, ncol = self.getSubplots()
603 nrow, ncol = self.getSubplots()
599
604
600 counter = 0
605 counter = 0
601 for y in range(nrow):
606 for y in range(nrow):
602 for x in range(ncol):
607 for x in range(ncol):
603 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
608 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
604
609
605 def run(self, dataOut, idfigure, wintitle="", channelList=None,
610 def run(self, dataOut, idfigure, wintitle="", channelList=None,
606 xmin=None, xmax=None, ymin=None, ymax=None,
611 xmin=None, xmax=None, ymin=None, ymax=None,
607 save=False, figpath='./', figfile=None):
612 save=False, figpath='./', figfile=None):
608
613
609 if channelList == None:
614 if channelList == None:
610 channelIndexList = dataOut.channelIndexList
615 channelIndexList = dataOut.channelIndexList
611 channelList = dataOut.channelList
616 channelList = dataOut.channelList
612 else:
617 else:
613 channelIndexList = []
618 channelIndexList = []
614 for channel in channelList:
619 for channel in channelList:
615 if channel not in dataOut.channelList:
620 if channel not in dataOut.channelList:
616 raise ValueError, "Channel %d is not in dataOut.channelList"
621 raise ValueError, "Channel %d is not in dataOut.channelList"
617 channelIndexList.append(dataOut.channelList.index(channel))
622 channelIndexList.append(dataOut.channelList.index(channel))
618
623
619
624
620 y = dataOut.getHeiRange()
625 y = dataOut.getHeiRange()
621 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
626 x = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
622 avg = numpy.average(x, axis=1)
627 avg = numpy.average(x, axis=1)
623
628
624
629
625 if not self.__isConfig:
630 if not self.__isConfig:
626
631
627 nplots = 1
632 nplots = 1
628
633
629 self.setup(idfigure=idfigure,
634 self.setup(idfigure=idfigure,
630 nplots=nplots,
635 nplots=nplots,
631 wintitle=wintitle)
636 wintitle=wintitle)
632
637
633 if ymin == None: ymin = numpy.nanmin(y)
638 if ymin == None: ymin = numpy.nanmin(y)
634 if ymax == None: ymax = numpy.nanmax(y)
639 if ymax == None: ymax = numpy.nanmax(y)
635 if xmin == None: xmin = numpy.nanmin(avg)*0.9
640 if xmin == None: xmin = numpy.nanmin(avg)*0.9
636 if xmax == None: xmax = numpy.nanmax(avg)*0.9
641 if xmax == None: xmax = numpy.nanmax(avg)*0.9
637
642
638 self.__isConfig = True
643 self.__isConfig = True
639
644
640 thisDatetime = dataOut.datatime
645 thisDatetime = dataOut.datatime
641 title = "Power Profile"
646 title = "Power Profile"
642 xlabel = "dB"
647 xlabel = "dB"
643 ylabel = "Range (Km)"
648 ylabel = "Range (Km)"
644
649
645 self.setWinTitle(title)
650 self.setWinTitle(title)
646
651
647
652
648 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
653 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
649 axes = self.axesList[0]
654 axes = self.axesList[0]
650
655
651 legendlabels = ["channel %d"%x for x in channelList]
656 legendlabels = ["channel %d"%x for x in channelList]
652 axes.pmultiline(avg, y,
657 axes.pmultiline(avg, y,
653 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
658 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
654 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
659 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
655 ytick_visible=True, nxticks=5,
660 ytick_visible=True, nxticks=5,
656 grid='x')
661 grid='x')
657
662
658 self.draw()
663 self.draw()
659
664
660 if save:
665 if save:
661 date = thisDatetime.strftime("%Y%m%d")
666 date = thisDatetime.strftime("%Y%m%d")
662 if figfile == None:
667 if figfile == None:
663 figfile = self.getFilename(name = date)
668 figfile = self.getFilename(name = date)
664
669
665 self.saveFigure(figpath, figfile)
670 self.saveFigure(figpath, figfile)
666
671
667 class CoherencePlot(Figure):
672 class CoherencePlot(Figure):
668 __isConfig = None
673 __isConfig = None
669 __nsubplots = None
674 __nsubplots = None
670
675
671 WIDTHPROF = None
676 WIDTHPROF = None
672 HEIGHTPROF = None
677 HEIGHTPROF = None
673 PREFIX = 'coherencemap'
678 PREFIX = 'coherencemap'
674
679
675 def __init__(self):
680 def __init__(self):
676 self.timerange = 24*60*60
681 self.timerange = 24*60*60
677 self.__isConfig = False
682 self.__isConfig = False
678 self.__nsubplots = 1
683 self.__nsubplots = 1
679
684
680 self.WIDTH = 800
685 self.WIDTH = 800
681 self.HEIGHT = 200
686 self.HEIGHT = 200
682 self.WIDTHPROF = 120
687 self.WIDTHPROF = 120
683 self.HEIGHTPROF = 0
688 self.HEIGHTPROF = 0
684
689
685 def getSubplots(self):
690 def getSubplots(self):
686 ncol = 1
691 ncol = 1
687 nrow = self.nplots*2
692 nrow = self.nplots*2
688
693
689 return nrow, ncol
694 return nrow, ncol
690
695
691 def setup(self, idfigure, nplots, wintitle, showprofile=True):
696 def setup(self, idfigure, nplots, wintitle, showprofile=True):
692 self.__showprofile = showprofile
697 self.__showprofile = showprofile
693 self.nplots = nplots
698 self.nplots = nplots
694
699
695 ncolspan = 1
700 ncolspan = 1
696 colspan = 1
701 colspan = 1
697 if showprofile:
702 if showprofile:
698 ncolspan = 7
703 ncolspan = 7
699 colspan = 6
704 colspan = 6
700 self.__nsubplots = 2
705 self.__nsubplots = 2
701
706
702 self.createFigure(idfigure = idfigure,
707 self.createFigure(idfigure = idfigure,
703 wintitle = wintitle,
708 wintitle = wintitle,
704 widthplot = self.WIDTH + self.WIDTHPROF,
709 widthplot = self.WIDTH + self.WIDTHPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF)
710 heightplot = self.HEIGHT + self.HEIGHTPROF)
706
711
707 nrow, ncol = self.getSubplots()
712 nrow, ncol = self.getSubplots()
708
713
709 for y in range(nrow):
714 for y in range(nrow):
710 for x in range(ncol):
715 for x in range(ncol):
711
716
712 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
717 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
713
718
714 if showprofile:
719 if showprofile:
715 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
720 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
716
721
717 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
722 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
718 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
723 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
719 timerange=None,
724 timerange=None,
720 save=False, figpath='./', figfile=None):
725 save=False, figpath='./', figfile=None):
721
726
722 if pairsList == None:
727 if pairsList == None:
723 pairsIndexList = dataOut.pairsIndexList
728 pairsIndexList = dataOut.pairsIndexList
724 else:
729 else:
725 pairsIndexList = []
730 pairsIndexList = []
726 for pair in pairsList:
731 for pair in pairsList:
727 if pair not in dataOut.pairsList:
732 if pair not in dataOut.pairsList:
728 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
733 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
729 pairsIndexList.append(dataOut.pairsList.index(pair))
734 pairsIndexList.append(dataOut.pairsList.index(pair))
730
735
731 if timerange != None:
736 if timerange != None:
732 self.timerange = timerange
737 self.timerange = timerange
733
738
734 tmin = None
739 tmin = None
735 tmax = None
740 tmax = None
736 x = dataOut.getTimeRange()
741 x = dataOut.getTimeRange()
737 y = dataOut.getHeiRange()
742 y = dataOut.getHeiRange()
738
743
739 if not self.__isConfig:
744 if not self.__isConfig:
740 nplots = len(pairsIndexList)
745 nplots = len(pairsIndexList)
741 self.setup(idfigure=idfigure,
746 self.setup(idfigure=idfigure,
742 nplots=nplots,
747 nplots=nplots,
743 wintitle=wintitle,
748 wintitle=wintitle,
744 showprofile=showprofile)
749 showprofile=showprofile)
745
750
746 tmin, tmax = self.getTimeLim(x, xmin, xmax)
751 tmin, tmax = self.getTimeLim(x, xmin, xmax)
747 if ymin == None: ymin = numpy.nanmin(y)
752 if ymin == None: ymin = numpy.nanmin(y)
748 if ymax == None: ymax = numpy.nanmax(y)
753 if ymax == None: ymax = numpy.nanmax(y)
749
754
750 self.__isConfig = True
755 self.__isConfig = True
751
756
752 thisDatetime = dataOut.datatime
757 thisDatetime = dataOut.datatime
753 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
758 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
754 xlabel = ""
759 xlabel = ""
755 ylabel = "Range (Km)"
760 ylabel = "Range (Km)"
756
761
757 self.setWinTitle(title)
762 self.setWinTitle(title)
758
763
759 for i in range(self.nplots):
764 for i in range(self.nplots):
760
765
761 pair = dataOut.pairsList[pairsIndexList[i]]
766 pair = dataOut.pairsList[pairsIndexList[i]]
762 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
767 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
763 coherence = numpy.abs(coherenceComplex)
768 coherence = numpy.abs(coherenceComplex)
764 avg = numpy.average(coherence, axis=0)
769 avg = numpy.average(coherence, axis=0)
765 z = avg.reshape((1,-1))
770 z = avg.reshape((1,-1))
766
771
767 counter = 0
772 counter = 0
768
773
769 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
774 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
770 axes = self.axesList[i*self.__nsubplots*2]
775 axes = self.axesList[i*self.__nsubplots*2]
771 axes.pcolor(x, y, z,
776 axes.pcolor(x, y, z,
772 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
777 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
773 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
778 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
774 ticksize=9, cblabel='', cbsize="1%")
779 ticksize=9, cblabel='', cbsize="1%")
775
780
776 if self.__showprofile:
781 if self.__showprofile:
777 counter += 1
782 counter += 1
778 axes = self.axesList[i*self.__nsubplots*2 + counter]
783 axes = self.axesList[i*self.__nsubplots*2 + counter]
779 axes.pline(avg, y,
784 axes.pline(avg, y,
780 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
785 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
781 xlabel='', ylabel='', title='', ticksize=7,
786 xlabel='', ylabel='', title='', ticksize=7,
782 ytick_visible=False, nxticks=5,
787 ytick_visible=False, nxticks=5,
783 grid='x')
788 grid='x')
784
789
785 counter += 1
790 counter += 1
786 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
791 phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
787 avg = numpy.average(phase, axis=0)
792 avg = numpy.average(phase, axis=0)
788 z = avg.reshape((1,-1))
793 z = avg.reshape((1,-1))
789
794
790 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
795 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
791 axes = self.axesList[i*self.__nsubplots*2 + counter]
796 axes = self.axesList[i*self.__nsubplots*2 + counter]
792 axes.pcolor(x, y, z,
797 axes.pcolor(x, y, z,
793 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
798 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
794 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
799 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
795 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
800 ticksize=9, cblabel='', colormap='RdBu', cbsize="1%")
796
801
797 if self.__showprofile:
802 if self.__showprofile:
798 counter += 1
803 counter += 1
799 axes = self.axesList[i*self.__nsubplots*2 + counter]
804 axes = self.axesList[i*self.__nsubplots*2 + counter]
800 axes.pline(avg, y,
805 axes.pline(avg, y,
801 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
806 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
802 xlabel='', ylabel='', title='', ticksize=7,
807 xlabel='', ylabel='', title='', ticksize=7,
803 ytick_visible=False, nxticks=4,
808 ytick_visible=False, nxticks=4,
804 grid='x')
809 grid='x')
805
810
806 self.draw()
811 self.draw()
807
812
808 if save:
813 if save:
809 date = thisDatetime.strftime("%Y%m%d")
814 date = thisDatetime.strftime("%Y%m%d")
810 if figfile == None:
815 if figfile == None:
811 figfile = self.getFilename(name = date)
816 figfile = self.getFilename(name = date)
812
817
813 self.saveFigure(figpath, figfile)
818 self.saveFigure(figpath, figfile)
814
819
815 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
820 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
816 self.__isConfig = False
821 self.__isConfig = False
817
822
818 No newline at end of file
823
@@ -1,1145 +1,1074
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 class ProcessingUnit:
15 class ProcessingUnit:
16
16
17 """
17 """
18 Esta es la clase base para el procesamiento de datos.
18 Esta es la clase base para el procesamiento de datos.
19
19
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
20 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
21 - Metodos internos (callMethod)
21 - Metodos internos (callMethod)
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
22 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
23 tienen que ser agreagados con el metodo "add".
23 tienen que ser agreagados con el metodo "add".
24
24
25 """
25 """
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
26 # objeto de datos de entrada (Voltage, Spectra o Correlation)
27 dataIn = None
27 dataIn = None
28
28
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
29 # objeto de datos de entrada (Voltage, Spectra o Correlation)
30 dataOut = None
30 dataOut = None
31
31
32
32
33 objectDict = None
33 objectDict = None
34
34
35 def __init__(self):
35 def __init__(self):
36
36
37 self.objectDict = {}
37 self.objectDict = {}
38
38
39 def init(self):
39 def init(self):
40
40
41 raise ValueError, "Not implemented"
41 raise ValueError, "Not implemented"
42
42
43 def addOperation(self, object, objId):
43 def addOperation(self, object, objId):
44
44
45 """
45 """
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
46 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
47 identificador asociado a este objeto.
47 identificador asociado a este objeto.
48
48
49 Input:
49 Input:
50
50
51 object : objeto de la clase "Operation"
51 object : objeto de la clase "Operation"
52
52
53 Return:
53 Return:
54
54
55 objId : identificador del objeto, necesario para ejecutar la operacion
55 objId : identificador del objeto, necesario para ejecutar la operacion
56 """
56 """
57
57
58 self.objectDict[objId] = object
58 self.objectDict[objId] = object
59
59
60 return objId
60 return objId
61
61
62 def operation(self, **kwargs):
62 def operation(self, **kwargs):
63
63
64 """
64 """
65 Operacion directa sobre la data (dataout.data). Es necesario actualizar los valores de los
65 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
66 atributos del objeto dataOut
66 atributos del objeto dataOut
67
67
68 Input:
68 Input:
69
69
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
70 **kwargs : Diccionario de argumentos de la funcion a ejecutar
71 """
71 """
72
72
73 raise ValueError, "ImplementedError"
73 raise ValueError, "ImplementedError"
74
74
75 def callMethod(self, name, **kwargs):
75 def callMethod(self, name, **kwargs):
76
76
77 """
77 """
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
78 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
79
79
80 Input:
80 Input:
81 name : nombre del metodo a ejecutar
81 name : nombre del metodo a ejecutar
82
82
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
83 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
84
84
85 """
85 """
86 if name != 'run':
86 if name != 'run':
87
87
88 if name == 'init' and self.dataIn.isEmpty():
88 if name == 'init' and self.dataIn.isEmpty():
89 self.dataOut.flagNoData = True
89 self.dataOut.flagNoData = True
90 return False
90 return False
91
91
92 if name != 'init' and self.dataOut.isEmpty():
92 if name != 'init' and self.dataOut.isEmpty():
93 return False
93 return False
94
94
95 methodToCall = getattr(self, name)
95 methodToCall = getattr(self, name)
96
96
97 methodToCall(**kwargs)
97 methodToCall(**kwargs)
98
98
99 if name != 'run':
99 if name != 'run':
100 return True
100 return True
101
101
102 if self.dataOut.isEmpty():
102 if self.dataOut.isEmpty():
103 return False
103 return False
104
104
105 return True
105 return True
106
106
107 def callObject(self, objId, **kwargs):
107 def callObject(self, objId, **kwargs):
108
108
109 """
109 """
110 Ejecuta la operacion asociada al identificador del objeto "objId"
110 Ejecuta la operacion asociada al identificador del objeto "objId"
111
111
112 Input:
112 Input:
113
113
114 objId : identificador del objeto a ejecutar
114 objId : identificador del objeto a ejecutar
115
115
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
116 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
117
117
118 Return:
118 Return:
119
119
120 None
120 None
121 """
121 """
122
122
123 if self.dataOut.isEmpty():
123 if self.dataOut.isEmpty():
124 return False
124 return False
125
125
126 object = self.objectDict[objId]
126 object = self.objectDict[objId]
127
127
128 object.run(self.dataOut, **kwargs)
128 object.run(self.dataOut, **kwargs)
129
129
130 return True
130 return True
131
131
132 def call(self, operationConf, **kwargs):
132 def call(self, operationConf, **kwargs):
133
133
134 """
134 """
135 Return True si ejecuta la operacion "operationConf.name" con los
135 Return True si ejecuta la operacion "operationConf.name" con los
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
137 La operacion puede ser de dos tipos:
138
138
139 1. Un metodo propio de esta clase:
139 1. Un metodo propio de esta clase:
140
140
141 operation.type = "self"
141 operation.type = "self"
142
142
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
143 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
144 operation.type = "other".
144 operation.type = "other".
145
145
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
146 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
147 "addOperation" e identificado con el operation.id
147 "addOperation" e identificado con el operation.id
148
148
149
149
150 con el id de la operacion.
150 con el id de la operacion.
151
151
152 Input:
152 Input:
153
153
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
154 Operation : Objeto del tipo operacion con los atributos: name, type y id.
155
155
156 """
156 """
157
157
158 if operationConf.type == 'self':
158 if operationConf.type == 'self':
159 sts = self.callMethod(operationConf.name, **kwargs)
159 sts = self.callMethod(operationConf.name, **kwargs)
160
160
161 if operationConf.type == 'other':
161 if operationConf.type == 'other':
162 sts = self.callObject(operationConf.id, **kwargs)
162 sts = self.callObject(operationConf.id, **kwargs)
163
163
164 return sts
164 return sts
165
165
166 def setInput(self, dataIn):
166 def setInput(self, dataIn):
167
167
168 self.dataIn = dataIn
168 self.dataIn = dataIn
169
169
170 def getOutput(self):
170 def getOutput(self):
171
171
172 return self.dataOut
172 return self.dataOut
173
173
174 class Operation():
174 class Operation():
175
175
176 """
176 """
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
177 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
178 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
179 acumulacion dentro de esta clase
179 acumulacion dentro de esta clase
180
180
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
181 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
182
182
183 """
183 """
184
184
185 __buffer = None
185 __buffer = None
186 __isConfig = False
186 __isConfig = False
187
187
188 def __init__(self):
188 def __init__(self):
189
189
190 pass
190 pass
191
191
192 def run(self, dataIn, **kwargs):
192 def run(self, dataIn, **kwargs):
193
193
194 """
194 """
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
195 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
196
196
197 Input:
197 Input:
198
198
199 dataIn : objeto del tipo JROData
199 dataIn : objeto del tipo JROData
200
200
201 Return:
201 Return:
202
202
203 None
203 None
204
204
205 Affected:
205 Affected:
206 __buffer : buffer de recepcion de datos.
206 __buffer : buffer de recepcion de datos.
207
207
208 """
208 """
209
209
210 raise ValueError, "ImplementedError"
210 raise ValueError, "ImplementedError"
211
211
212 class VoltageProc(ProcessingUnit):
212 class VoltageProc(ProcessingUnit):
213
213
214
214
215 def __init__(self):
215 def __init__(self):
216
216
217 self.objectDict = {}
217 self.objectDict = {}
218 self.dataOut = Voltage()
218 self.dataOut = Voltage()
219
219
220 def init(self):
220 def init(self):
221
221
222 self.dataOut.copy(self.dataIn)
222 self.dataOut.copy(self.dataIn)
223 # No necesita copiar en cada init() los atributos de dataIn
223 # No necesita copiar en cada init() los atributos de dataIn
224 # la copia deberia hacerse por cada nuevo bloque de datos
224 # la copia deberia hacerse por cada nuevo bloque de datos
225
225
226 def selectChannels(self, channelList):
226 def selectChannels(self, channelList):
227
227
228 channelIndexList = []
228 channelIndexList = []
229
229
230 for channel in channelList:
230 for channel in channelList:
231 index = self.dataOut.channelList.index(channel)
231 index = self.dataOut.channelList.index(channel)
232 channelIndexList.append(index)
232 channelIndexList.append(index)
233
233
234 self.selectChannelsByIndex(channelIndexList)
234 self.selectChannelsByIndex(channelIndexList)
235
235
236 def selectChannelsByIndex(self, channelIndexList):
236 def selectChannelsByIndex(self, channelIndexList):
237 """
237 """
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
238 Selecciona un bloque de datos en base a canales segun el channelIndexList
239
239
240 Input:
240 Input:
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
241 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
242
242
243 Affected:
243 Affected:
244 self.dataOut.data
244 self.dataOut.data
245 self.dataOut.channelIndexList
245 self.dataOut.channelIndexList
246 self.dataOut.nChannels
246 self.dataOut.nChannels
247 self.dataOut.m_ProcessingHeader.totalSpectra
247 self.dataOut.m_ProcessingHeader.totalSpectra
248 self.dataOut.systemHeaderObj.numChannels
248 self.dataOut.systemHeaderObj.numChannels
249 self.dataOut.m_ProcessingHeader.blockSize
249 self.dataOut.m_ProcessingHeader.blockSize
250
250
251 Return:
251 Return:
252 None
252 None
253 """
253 """
254
254
255 for channelIndex in channelIndexList:
255 for channelIndex in channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
256 if channelIndex not in self.dataOut.channelIndexList:
257 print channelIndexList
257 print channelIndexList
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
258 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
259
259
260 nChannels = len(channelIndexList)
260 nChannels = len(channelIndexList)
261
261
262 data = self.dataOut.data[channelIndexList,:]
262 data = self.dataOut.data[channelIndexList,:]
263
263
264 self.dataOut.data = data
264 self.dataOut.data = data
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
265 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
266 # self.dataOut.nChannels = nChannels
266 # self.dataOut.nChannels = nChannels
267
267
268 return 1
268 return 1
269
269
270 def selectHeights(self, minHei, maxHei):
270 def selectHeights(self, minHei, maxHei):
271 """
271 """
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
272 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
273 minHei <= height <= maxHei
273 minHei <= height <= maxHei
274
274
275 Input:
275 Input:
276 minHei : valor minimo de altura a considerar
276 minHei : valor minimo de altura a considerar
277 maxHei : valor maximo de altura a considerar
277 maxHei : valor maximo de altura a considerar
278
278
279 Affected:
279 Affected:
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
280 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
281
281
282 Return:
282 Return:
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
283 1 si el metodo se ejecuto con exito caso contrario devuelve 0
284 """
284 """
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
285 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
286 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
287
287
288 if (maxHei > self.dataOut.heightList[-1]):
288 if (maxHei > self.dataOut.heightList[-1]):
289 maxHei = self.dataOut.heightList[-1]
289 maxHei = self.dataOut.heightList[-1]
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
290 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
291
291
292 minIndex = 0
292 minIndex = 0
293 maxIndex = 0
293 maxIndex = 0
294 data = self.dataOut.heightList
294 data = self.dataOut.heightList
295
295
296 for i,val in enumerate(data):
296 for i,val in enumerate(data):
297 if val < minHei:
297 if val < minHei:
298 continue
298 continue
299 else:
299 else:
300 minIndex = i;
300 minIndex = i;
301 break
301 break
302
302
303 for i,val in enumerate(data):
303 for i,val in enumerate(data):
304 if val <= maxHei:
304 if val <= maxHei:
305 maxIndex = i;
305 maxIndex = i;
306 else:
306 else:
307 break
307 break
308
308
309 self.selectHeightsByIndex(minIndex, maxIndex)
309 self.selectHeightsByIndex(minIndex, maxIndex)
310
310
311 return 1
311 return 1
312
312
313
313
314 def selectHeightsByIndex(self, minIndex, maxIndex):
314 def selectHeightsByIndex(self, minIndex, maxIndex):
315 """
315 """
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
316 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
317 minIndex <= index <= maxIndex
317 minIndex <= index <= maxIndex
318
318
319 Input:
319 Input:
320 minIndex : valor de indice minimo de altura a considerar
320 minIndex : valor de indice minimo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
321 maxIndex : valor de indice maximo de altura a considerar
322
322
323 Affected:
323 Affected:
324 self.dataOut.data
324 self.dataOut.data
325 self.dataOut.heightList
325 self.dataOut.heightList
326
326
327 Return:
327 Return:
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
328 1 si el metodo se ejecuto con exito caso contrario devuelve 0
329 """
329 """
330
330
331 if (minIndex < 0) or (minIndex > maxIndex):
331 if (minIndex < 0) or (minIndex > maxIndex):
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
332 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
333
333
334 if (maxIndex >= self.dataOut.nHeights):
334 if (maxIndex >= self.dataOut.nHeights):
335 maxIndex = self.dataOut.nHeights-1
335 maxIndex = self.dataOut.nHeights-1
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
336 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
337
337
338 nHeights = maxIndex - minIndex + 1
338 nHeights = maxIndex - minIndex + 1
339
339
340 #voltage
340 #voltage
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
341 data = self.dataOut.data[:,minIndex:maxIndex+1]
342
342
343 firstHeight = self.dataOut.heightList[minIndex]
343 firstHeight = self.dataOut.heightList[minIndex]
344
344
345 self.dataOut.data = data
345 self.dataOut.data = data
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
346 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
347
347
348 return 1
348 return 1
349
349
350
351 def filterByHeights(self, window):
352 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
353
354 if window == None:
355 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
356
357 newdelta = deltaHeight * window
358 r = self.dataOut.data.shape[1] % window
359 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
360 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
361 buffer = numpy.sum(buffer,2)
362 self.dataOut.data = buffer
363 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window,newdelta)
364
365
350
366 class CohInt(Operation):
351 class CohInt(Operation):
367
352
353 __isConfig = False
354
368 __profIndex = 0
355 __profIndex = 0
369 __withOverapping = False
356 __withOverapping = False
370
357
371 __byTime = False
358 __byTime = False
372 __initime = None
359 __initime = None
373 __lastdatatime = None
360 __lastdatatime = None
374 __integrationtime = None
361 __integrationtime = None
375
362
376 __buffer = None
363 __buffer = None
377
364
378 __dataReady = False
365 __dataReady = False
379
366
380 n = None
367 n = None
381
368
382
369
383 def __init__(self):
370 def __init__(self):
384
371
385 self.__isConfig = False
372 self.__isConfig = False
386
373
387 def setup(self, n=None, timeInterval=None, overlapping=False):
374 def setup(self, n=None, timeInterval=None, overlapping=False):
388 """
375 """
389 Set the parameters of the integration class.
376 Set the parameters of the integration class.
390
377
391 Inputs:
378 Inputs:
392
379
393 n : Number of coherent integrations
380 n : Number of coherent integrations
394 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
381 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
395 overlapping :
382 overlapping :
396
383
397 """
384 """
398
385
399 self.__initime = None
386 self.__initime = None
400 self.__lastdatatime = 0
387 self.__lastdatatime = 0
401 self.__buffer = None
388 self.__buffer = None
402 self.__dataReady = False
389 self.__dataReady = False
403
390
404
391
405 if n == None and timeInterval == None:
392 if n == None and timeInterval == None:
406 raise ValueError, "n or timeInterval should be specified ..."
393 raise ValueError, "n or timeInterval should be specified ..."
407
394
408 if n != None:
395 if n != None:
409 self.n = n
396 self.n = n
410 self.__byTime = False
397 self.__byTime = False
411 else:
398 else:
412 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
399 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
413 self.n = 9999
400 self.n = 9999
414 self.__byTime = True
401 self.__byTime = True
415
402
416 if overlapping:
403 if overlapping:
417 self.__withOverapping = True
404 self.__withOverapping = True
418 self.__buffer = None
405 self.__buffer = None
419 else:
406 else:
420 self.__withOverapping = False
407 self.__withOverapping = False
421 self.__buffer = 0
408 self.__buffer = 0
422
409
423 self.__profIndex = 0
410 self.__profIndex = 0
424
411
425 def putData(self, data):
412 def putData(self, data):
426
413
427 """
414 """
428 Add a profile to the __buffer and increase in one the __profileIndex
415 Add a profile to the __buffer and increase in one the __profileIndex
429
416
430 """
417 """
431
418
432 if not self.__withOverapping:
419 if not self.__withOverapping:
433 self.__buffer += data.copy()
420 self.__buffer += data.copy()
434 self.__profIndex += 1
421 self.__profIndex += 1
435 return
422 return
436
423
437 #Overlapping data
424 #Overlapping data
438 nChannels, nHeis = data.shape
425 nChannels, nHeis = data.shape
439 data = numpy.reshape(data, (1, nChannels, nHeis))
426 data = numpy.reshape(data, (1, nChannels, nHeis))
440
427
441 #If the buffer is empty then it takes the data value
428 #If the buffer is empty then it takes the data value
442 if self.__buffer == None:
429 if self.__buffer == None:
443 self.__buffer = data
430 self.__buffer = data
444 self.__profIndex += 1
431 self.__profIndex += 1
445 return
432 return
446
433
447 #If the buffer length is lower than n then stakcing the data value
434 #If the buffer length is lower than n then stakcing the data value
448 if self.__profIndex < self.n:
435 if self.__profIndex < self.n:
449 self.__buffer = numpy.vstack((self.__buffer, data))
436 self.__buffer = numpy.vstack((self.__buffer, data))
450 self.__profIndex += 1
437 self.__profIndex += 1
451 return
438 return
452
439
453 #If the buffer length is equal to n then replacing the last buffer value with the data value
440 #If the buffer length is equal to n then replacing the last buffer value with the data value
454 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
441 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
455 self.__buffer[self.n-1] = data
442 self.__buffer[self.n-1] = data
456 self.__profIndex = self.n
443 self.__profIndex = self.n
457 return
444 return
458
445
459
446
460 def pushData(self):
447 def pushData(self):
461 """
448 """
462 Return the sum of the last profiles and the profiles used in the sum.
449 Return the sum of the last profiles and the profiles used in the sum.
463
450
464 Affected:
451 Affected:
465
452
466 self.__profileIndex
453 self.__profileIndex
467
454
468 """
455 """
469
456
470 if not self.__withOverapping:
457 if not self.__withOverapping:
471 data = self.__buffer
458 data = self.__buffer
472 n = self.__profIndex
459 n = self.__profIndex
473
460
474 self.__buffer = 0
461 self.__buffer = 0
475 self.__profIndex = 0
462 self.__profIndex = 0
476
463
477 return data, n
464 return data, n
478
465
479 #Integration with Overlapping
466 #Integration with Overlapping
480 data = numpy.sum(self.__buffer, axis=0)
467 data = numpy.sum(self.__buffer, axis=0)
481 n = self.__profIndex
468 n = self.__profIndex
482
469
483 return data, n
470 return data, n
484
471
485 def byProfiles(self, data):
472 def byProfiles(self, data):
486
473
487 self.__dataReady = False
474 self.__dataReady = False
488 avgdata = None
475 avgdata = None
489 n = None
476 n = None
490
477
491 self.putData(data)
478 self.putData(data)
492
479
493 if self.__profIndex == self.n:
480 if self.__profIndex == self.n:
494
481
495 avgdata, n = self.pushData()
482 avgdata, n = self.pushData()
496 self.__dataReady = True
483 self.__dataReady = True
497
484
498 return avgdata
485 return avgdata
499
486
500 def byTime(self, data, datatime):
487 def byTime(self, data, datatime):
501
488
502 self.__dataReady = False
489 self.__dataReady = False
503 avgdata = None
490 avgdata = None
504 n = None
491 n = None
505
492
506 self.putData(data)
493 self.putData(data)
507
494
508 if (datatime - self.__initime) >= self.__integrationtime:
495 if (datatime - self.__initime) >= self.__integrationtime:
509 avgdata, n = self.pushData()
496 avgdata, n = self.pushData()
510 self.n = n
497 self.n = n
511 self.__dataReady = True
498 self.__dataReady = True
512
499
513 return avgdata
500 return avgdata
514
501
515 def integrate(self, data, datatime=None):
502 def integrate(self, data, datatime=None):
516
503
517 if self.__initime == None:
504 if self.__initime == None:
518 self.__initime = datatime
505 self.__initime = datatime
519
506
520 if self.__byTime:
507 if self.__byTime:
521 avgdata = self.byTime(data, datatime)
508 avgdata = self.byTime(data, datatime)
522 else:
509 else:
523 avgdata = self.byProfiles(data)
510 avgdata = self.byProfiles(data)
524
511
525
512
526 self.__lastdatatime = datatime
513 self.__lastdatatime = datatime
527
514
528 if avgdata == None:
515 if avgdata == None:
529 return None, None
516 return None, None
530
517
531 avgdatatime = self.__initime
518 avgdatatime = self.__initime
532
519
533 deltatime = datatime -self.__lastdatatime
520 deltatime = datatime -self.__lastdatatime
534
521
535 if not self.__withOverapping:
522 if not self.__withOverapping:
536 self.__initime = datatime
523 self.__initime = datatime
537 else:
524 else:
538 self.__initime += deltatime
525 self.__initime += deltatime
539
526
540 return avgdata, avgdatatime
527 return avgdata, avgdatatime
541
528
542 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
529 def run(self, dataOut, **kwargs):
543
530
544 if not self.__isConfig:
531 if not self.__isConfig:
545 self.setup(n, timeInterval, overlapping)
532 self.setup(**kwargs)
546 self.__isConfig = True
533 self.__isConfig = True
547
534
548 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
535 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
549
536
550 # dataOut.timeInterval *= n
537 # dataOut.timeInterval *= n
551 dataOut.flagNoData = True
538 dataOut.flagNoData = True
552
539
553 if self.__dataReady:
540 if self.__dataReady:
554 dataOut.data = avgdata
541 dataOut.data = avgdata
555 dataOut.nCohInt *= self.n
542 dataOut.nCohInt *= self.n
556 dataOut.utctime = avgdatatime
543 dataOut.utctime = avgdatatime
557 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
544 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
558 dataOut.flagNoData = False
545 dataOut.flagNoData = False
546
547 class Decoder(Operation):
548
549 __isConfig = False
550 __profIndex = 0
551
552 code = None
553
554 nCode = None
555 nBaud = None
556
557 def __init__(self):
558
559 self.__isConfig = False
560
561 def setup(self, code):
562
563 self.__profIndex = 0
564
565 self.code = code
566
567 self.nCode = len(code)
568 self.nBaud = len(code[0])
569
570 def convolutionInFreq(self, data):
571
572 ndata = data.shape[1]
573 newcode = numpy.zeros(ndata)
574 newcode[0:self.nBaud] = self.code[self.__profIndex]
575
576 fft_data = numpy.fft.fft(data, axis=1)
577 fft_code = numpy.conj(numpy.fft.fft(newcode))
578 fft_code = fft_code.reshape(1,len(fft_code))
579
580 # conv = fft_data.copy()
581 # conv.fill(0)
582
583 conv = fft_data*fft_code
584
585 data = numpy.fft.ifft(conv,axis=1)
586
587 datadec = data[:,:-self.nBaud+1]
588 ndatadec = ndata - self.nBaud + 1
589
590 if self.__profIndex == self.nCode:
591 self.__profIndex = 0
592
593 self.__profIndex += 1
594
595 return ndatadec, datadec
596
597
598 def convolutionInTime(self, data):
599
600 nchannel = data.shape[1]
601 newcode = self.code[self.__profIndex]
602
603 datadec = data.copy()
604
605 for i in range(nchannel):
606 datadec[i,:] = numpy.correlate(data[i,:], newcode)
607
608 ndatadec = ndata - self.nBaud + 1
609
610 if self.__profIndex == self.nCode:
611 self.__profIndex = 0
612
613 self.__profIndex += 1
614
615 return ndatadec, datadec
616
617 def run(self, dataOut, code=None, mode = 0):
618
619 if not self.__isConfig:
559
620
621 if code == None:
622 code = dataOut.code
623
624 self.setup(code)
625 self.__isConfig = True
626
627 if mode == 0:
628 ndatadec, datadec = self.convolutionInFreq(data)
629
630 if mode == 1:
631 ndatadec, datadec = self.convolutionInTime(data)
632
633 dataOut.data = datadec
634
635 dataOut.heightList = dataOut.heightList[0:ndatadec+1]
636
637 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
638
639 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
640
641
560
642
561 class SpectraProc(ProcessingUnit):
643 class SpectraProc(ProcessingUnit):
562
644
563 def __init__(self):
645 def __init__(self):
564
646
565 self.objectDict = {}
647 self.objectDict = {}
566 self.buffer = None
648 self.buffer = None
567 self.firstdatatime = None
649 self.firstdatatime = None
568 self.profIndex = 0
650 self.profIndex = 0
569 self.dataOut = Spectra()
651 self.dataOut = Spectra()
570
652
571 def __updateObjFromInput(self):
653 def __updateObjFromInput(self):
572
654
573 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
655 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
574 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
656 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
575 self.dataOut.channelList = self.dataIn.channelList
657 self.dataOut.channelList = self.dataIn.channelList
576 self.dataOut.heightList = self.dataIn.heightList
658 self.dataOut.heightList = self.dataIn.heightList
577 self.dataOut.dtype = self.dataIn.dtype
659 self.dataOut.dtype = self.dataIn.dtype
578 # self.dataOut.nHeights = self.dataIn.nHeights
660 # self.dataOut.nHeights = self.dataIn.nHeights
579 # self.dataOut.nChannels = self.dataIn.nChannels
661 # self.dataOut.nChannels = self.dataIn.nChannels
580 self.dataOut.nBaud = self.dataIn.nBaud
662 self.dataOut.nBaud = self.dataIn.nBaud
581 self.dataOut.nCode = self.dataIn.nCode
663 self.dataOut.nCode = self.dataIn.nCode
582 self.dataOut.code = self.dataIn.code
664 self.dataOut.code = self.dataIn.code
583 self.dataOut.nProfiles = self.dataOut.nFFTPoints
665 self.dataOut.nProfiles = self.dataOut.nFFTPoints
584 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
666 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
585 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
667 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
586 self.dataOut.utctime = self.firstdatatime
668 self.dataOut.utctime = self.firstdatatime
587 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
669 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
588 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
670 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
589 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
671 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
590 self.dataOut.nCohInt = self.dataIn.nCohInt
672 self.dataOut.nCohInt = self.dataIn.nCohInt
591 self.dataOut.nIncohInt = 1
673 self.dataOut.nIncohInt = 1
592 self.dataOut.ippSeconds = self.dataIn.ippSeconds
674 self.dataOut.ippSeconds = self.dataIn.ippSeconds
593
675
594 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
676 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
595
677
596 def __getFft(self):
678 def __getFft(self):
597 """
679 """
598 Convierte valores de Voltaje a Spectra
680 Convierte valores de Voltaje a Spectra
599
681
600 Affected:
682 Affected:
601 self.dataOut.data_spc
683 self.dataOut.data_spc
602 self.dataOut.data_cspc
684 self.dataOut.data_cspc
603 self.dataOut.data_dc
685 self.dataOut.data_dc
604 self.dataOut.heightList
686 self.dataOut.heightList
605 self.profIndex
687 self.profIndex
606 self.buffer
688 self.buffer
607 self.dataOut.flagNoData
689 self.dataOut.flagNoData
608 """
690 """
609 fft_volt = numpy.fft.fft(self.buffer,axis=1)/numpy.sqrt(self.dataOut.nFFTPoints)
691 fft_volt = numpy.fft.fft(self.buffer,axis=1)
610 dc = fft_volt[:,0,:]
692 dc = fft_volt[:,0,:]
611
693
612 #calculo de self-spectra
694 #calculo de self-spectra
613 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
695 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
614 spc = fft_volt * numpy.conjugate(fft_volt)
696 spc = fft_volt * numpy.conjugate(fft_volt)
615 spc = spc.real
697 spc = spc.real
616
698
617 blocksize = 0
699 blocksize = 0
618 blocksize += dc.size
700 blocksize += dc.size
619 blocksize += spc.size
701 blocksize += spc.size
620
702
621 cspc = None
703 cspc = None
622 pairIndex = 0
704 pairIndex = 0
623 if self.dataOut.pairsList != None:
705 if self.dataOut.pairsList != None:
624 #calculo de cross-spectra
706 #calculo de cross-spectra
625 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
707 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
626 for pair in self.dataOut.pairsList:
708 for pair in self.dataOut.pairsList:
627 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
709 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
628 pairIndex += 1
710 pairIndex += 1
629 blocksize += cspc.size
711 blocksize += cspc.size
630
712
631 self.dataOut.data_spc = spc
713 self.dataOut.data_spc = spc
632 self.dataOut.data_cspc = cspc
714 self.dataOut.data_cspc = cspc
633 self.dataOut.data_dc = dc
715 self.dataOut.data_dc = dc
634 self.dataOut.blockSize = blocksize
716 self.dataOut.blockSize = blocksize
635
717
636 def init(self, nFFTPoints=None, pairsList=None):
718 def init(self, nFFTPoints=None, pairsList=None):
637
719
720 self.dataOut.flagNoData = True
721
638 if self.dataIn.type == "Spectra":
722 if self.dataIn.type == "Spectra":
639 self.dataOut.copy(self.dataIn)
723 self.dataOut.copy(self.dataIn)
640 return
724 return
641
725
642 if self.dataIn.type == "Voltage":
726 if self.dataIn.type == "Voltage":
643
727
644 if nFFTPoints == None:
728 if nFFTPoints == None:
645 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
729 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
646
730
647 if pairsList == None:
731 if pairsList == None:
648 nPairs = 0
732 nPairs = 0
649 else:
733 else:
650 nPairs = len(pairsList)
734 nPairs = len(pairsList)
651
735
652 self.dataOut.nFFTPoints = nFFTPoints
736 self.dataOut.nFFTPoints = nFFTPoints
653 self.dataOut.pairsList = pairsList
737 self.dataOut.pairsList = pairsList
654 self.dataOut.nPairs = nPairs
738 self.dataOut.nPairs = nPairs
655
739
656 if self.buffer == None:
740 if self.buffer == None:
657 self.buffer = numpy.zeros((self.dataIn.nChannels,
741 self.buffer = numpy.zeros((self.dataIn.nChannels,
658 self.dataOut.nFFTPoints,
742 self.dataOut.nFFTPoints,
659 self.dataIn.nHeights),
743 self.dataIn.nHeights),
660 dtype='complex')
744 dtype='complex')
661
745
662
746
663 self.buffer[:,self.profIndex,:] = self.dataIn.data
747 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
664 self.profIndex += 1
748 self.profIndex += 1
665
749
666 if self.firstdatatime == None:
750 if self.firstdatatime == None:
667 self.firstdatatime = self.dataIn.utctime
751 self.firstdatatime = self.dataIn.utctime
668
752
669 if self.profIndex == self.dataOut.nFFTPoints:
753 if self.profIndex == self.dataOut.nFFTPoints:
670 self.__updateObjFromInput()
754 self.__updateObjFromInput()
671 self.__getFft()
755 self.__getFft()
672
756
673 self.dataOut.flagNoData = False
757 self.dataOut.flagNoData = False
674
758
675 self.buffer = None
759 self.buffer = None
676 self.firstdatatime = None
760 self.firstdatatime = None
677 self.profIndex = 0
761 self.profIndex = 0
678
762
679 return
763 return
680
764
681 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
765 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
682
766
683 def selectChannels(self, channelList):
767 def selectChannels(self, channelList):
684
768
685 channelIndexList = []
769 channelIndexList = []
686
770
687 for channel in channelList:
771 for channel in channelList:
688 index = self.dataOut.channelList.index(channel)
772 index = self.dataOut.channelList.index(channel)
689 channelIndexList.append(index)
773 channelIndexList.append(index)
690
774
691 self.selectChannelsByIndex(channelIndexList)
775 self.selectChannelsByIndex(channelIndexList)
692
776
693 def selectChannelsByIndex(self, channelIndexList):
777 def selectChannelsByIndex(self, channelIndexList):
694 """
778 """
695 Selecciona un bloque de datos en base a canales segun el channelIndexList
779 Selecciona un bloque de datos en base a canales segun el channelIndexList
696
780
697 Input:
781 Input:
698 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
782 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
699
783
700 Affected:
784 Affected:
701 self.dataOut.data_spc
785 self.dataOut.data_spc
702 self.dataOut.channelIndexList
786 self.dataOut.channelIndexList
703 self.dataOut.nChannels
787 self.dataOut.nChannels
704
788
705 Return:
789 Return:
706 None
790 None
707 """
791 """
708
792
709 for channelIndex in channelIndexList:
793 for channelIndex in channelIndexList:
710 if channelIndex not in self.dataOut.channelIndexList:
794 if channelIndex not in self.dataOut.channelIndexList:
711 print channelIndexList
795 print channelIndexList
712 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
796 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
713
797
714 nChannels = len(channelIndexList)
798 nChannels = len(channelIndexList)
715
799
716 data_spc = self.dataOut.data_spc[channelIndexList,:]
800 data_spc = self.dataOut.data_spc[channelIndexList,:]
717
801
718 self.dataOut.data_spc = data_spc
802 self.dataOut.data_spc = data_spc
719 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
803 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
720 # self.dataOut.nChannels = nChannels
804 # self.dataOut.nChannels = nChannels
721
805
722 return 1
806 return 1
723
807
724
808
725 class IncohInt(Operation):
809 class IncohInt(Operation):
726
810
727
811
728 __profIndex = 0
812 __profIndex = 0
729 __withOverapping = False
813 __withOverapping = False
730
814
731 __byTime = False
815 __byTime = False
732 __initime = None
816 __initime = None
733 __lastdatatime = None
817 __lastdatatime = None
734 __integrationtime = None
818 __integrationtime = None
735
819
736 __buffer_spc = None
820 __buffer_spc = None
737 __buffer_cspc = None
821 __buffer_cspc = None
738 __buffer_dc = None
822 __buffer_dc = None
739
823
740 __dataReady = False
824 __dataReady = False
741
825
742 n = None
826 n = None
743
827
744
828
745 def __init__(self):
829 def __init__(self):
746
830
747 self.__isConfig = False
831 self.__isConfig = False
748
832
749 def setup(self, n=None, timeInterval=None, overlapping=False):
833 def setup(self, n=None, timeInterval=None, overlapping=False):
750 """
834 """
751 Set the parameters of the integration class.
835 Set the parameters of the integration class.
752
836
753 Inputs:
837 Inputs:
754
838
755 n : Number of coherent integrations
839 n : Number of coherent integrations
756 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
840 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
757 overlapping :
841 overlapping :
758
842
759 """
843 """
760
844
761 self.__initime = None
845 self.__initime = None
762 self.__lastdatatime = 0
846 self.__lastdatatime = 0
763 self.__buffer_spc = None
847 self.__buffer_spc = None
764 self.__buffer_cspc = None
848 self.__buffer_cspc = None
765 self.__buffer_dc = None
849 self.__buffer_dc = None
766 self.__dataReady = False
850 self.__dataReady = False
767
851
768
852
769 if n == None and timeInterval == None:
853 if n == None and timeInterval == None:
770 raise ValueError, "n or timeInterval should be specified ..."
854 raise ValueError, "n or timeInterval should be specified ..."
771
855
772 if n != None:
856 if n != None:
773 self.n = n
857 self.n = n
774 self.__byTime = False
858 self.__byTime = False
775 else:
859 else:
776 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
860 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
777 self.n = 9999
861 self.n = 9999
778 self.__byTime = True
862 self.__byTime = True
779
863
780 if overlapping:
864 if overlapping:
781 self.__withOverapping = True
865 self.__withOverapping = True
782 else:
866 else:
783 self.__withOverapping = False
867 self.__withOverapping = False
784 self.__buffer_spc = 0
868 self.__buffer_spc = 0
785 self.__buffer_cspc = 0
869 self.__buffer_cspc = 0
786 self.__buffer_dc = 0
870 self.__buffer_dc = 0
787
871
788 self.__profIndex = 0
872 self.__profIndex = 0
789
873
790 def putData(self, data_spc, data_cspc, data_dc):
874 def putData(self, data_spc, data_cspc, data_dc):
791
875
792 """
876 """
793 Add a profile to the __buffer_spc and increase in one the __profileIndex
877 Add a profile to the __buffer_spc and increase in one the __profileIndex
794
878
795 """
879 """
796
880
797 if not self.__withOverapping:
881 if not self.__withOverapping:
798 self.__buffer_spc += data_spc
882 self.__buffer_spc += data_spc
799
883
800 if data_cspc == None:
884 if data_cspc == None:
801 self.__buffer_cspc = None
885 self.__buffer_cspc = None
802 else:
886 else:
803 self.__buffer_cspc += data_cspc
887 self.__buffer_cspc += data_cspc
804
888
805 if data_dc == None:
889 if data_dc == None:
806 self.__buffer_dc = None
890 self.__buffer_dc = None
807 else:
891 else:
808 self.__buffer_dc += data_dc
892 self.__buffer_dc += data_dc
809
893
810 self.__profIndex += 1
894 self.__profIndex += 1
811 return
895 return
812
896
813 #Overlapping data
897 #Overlapping data
814 nChannels, nFFTPoints, nHeis = data_spc.shape
898 nChannels, nFFTPoints, nHeis = data_spc.shape
815 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
899 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
816 if data_cspc != None:
900 if data_cspc != None:
817 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
901 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
818 if data_dc != None:
902 if data_dc != None:
819 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
903 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
820
904
821 #If the buffer is empty then it takes the data value
905 #If the buffer is empty then it takes the data value
822 if self.__buffer_spc == None:
906 if self.__buffer_spc == None:
823 self.__buffer_spc = data_spc
907 self.__buffer_spc = data_spc
824
908
825 if data_cspc == None:
909 if data_cspc == None:
826 self.__buffer_cspc = None
910 self.__buffer_cspc = None
827 else:
911 else:
828 self.__buffer_cspc += data_cspc
912 self.__buffer_cspc += data_cspc
829
913
830 if data_dc == None:
914 if data_dc == None:
831 self.__buffer_dc = None
915 self.__buffer_dc = None
832 else:
916 else:
833 self.__buffer_dc += data_dc
917 self.__buffer_dc += data_dc
834
918
835 self.__profIndex += 1
919 self.__profIndex += 1
836 return
920 return
837
921
838 #If the buffer length is lower than n then stakcing the data value
922 #If the buffer length is lower than n then stakcing the data value
839 if self.__profIndex < self.n:
923 if self.__profIndex < self.n:
840 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
924 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
841
925
842 if data_cspc != None:
926 if data_cspc != None:
843 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
927 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
844
928
845 if data_dc != None:
929 if data_dc != None:
846 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
930 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
847
931
848 self.__profIndex += 1
932 self.__profIndex += 1
849 return
933 return
850
934
851 #If the buffer length is equal to n then replacing the last buffer value with the data value
935 #If the buffer length is equal to n then replacing the last buffer value with the data value
852 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
936 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
853 self.__buffer_spc[self.n-1] = data_spc
937 self.__buffer_spc[self.n-1] = data_spc
854
938
855 if data_cspc != None:
939 if data_cspc != None:
856 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
940 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
857 self.__buffer_cspc[self.n-1] = data_cspc
941 self.__buffer_cspc[self.n-1] = data_cspc
858
942
859 if data_dc != None:
943 if data_dc != None:
860 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
944 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
861 self.__buffer_dc[self.n-1] = data_dc
945 self.__buffer_dc[self.n-1] = data_dc
862
946
863 self.__profIndex = self.n
947 self.__profIndex = self.n
864 return
948 return
865
949
866
950
867 def pushData(self):
951 def pushData(self):
868 """
952 """
869 Return the sum of the last profiles and the profiles used in the sum.
953 Return the sum of the last profiles and the profiles used in the sum.
870
954
871 Affected:
955 Affected:
872
956
873 self.__profileIndex
957 self.__profileIndex
874
958
875 """
959 """
876 data_spc = None
960 data_spc = None
877 data_cspc = None
961 data_cspc = None
878 data_dc = None
962 data_dc = None
879
963
880 if not self.__withOverapping:
964 if not self.__withOverapping:
881 data_spc = self.__buffer_spc
965 data_spc = self.__buffer_spc
882 data_cspc = self.__buffer_cspc
966 data_cspc = self.__buffer_cspc
883 data_dc = self.__buffer_dc
967 data_dc = self.__buffer_dc
884
968
885 n = self.__profIndex
969 n = self.__profIndex
886
970
887 self.__buffer_spc = 0
971 self.__buffer_spc = 0
888 self.__buffer_cspc = 0
972 self.__buffer_cspc = 0
889 self.__buffer_dc = 0
973 self.__buffer_dc = 0
890 self.__profIndex = 0
974 self.__profIndex = 0
891
975
892 return data_spc, data_cspc, data_dc, n
976 return data_spc, data_cspc, data_dc, n
893
977
894 #Integration with Overlapping
978 #Integration with Overlapping
895 data_spc = numpy.sum(self.__buffer_spc, axis=0)
979 data_spc = numpy.sum(self.__buffer_spc, axis=0)
896
980
897 if self.__buffer_cspc != None:
981 if self.__buffer_cspc != None:
898 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
982 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
899
983
900 if self.__buffer_dc != None:
984 if self.__buffer_dc != None:
901 data_dc = numpy.sum(self.__buffer_dc, axis=0)
985 data_dc = numpy.sum(self.__buffer_dc, axis=0)
902
986
903 n = self.__profIndex
987 n = self.__profIndex
904
988
905 return data_spc, data_cspc, data_dc, n
989 return data_spc, data_cspc, data_dc, n
906
990
907 def byProfiles(self, *args):
991 def byProfiles(self, *args):
908
992
909 self.__dataReady = False
993 self.__dataReady = False
910 avgdata_spc = None
994 avgdata_spc = None
911 avgdata_cspc = None
995 avgdata_cspc = None
912 avgdata_dc = None
996 avgdata_dc = None
913 n = None
997 n = None
914
998
915 self.putData(*args)
999 self.putData(*args)
916
1000
917 if self.__profIndex == self.n:
1001 if self.__profIndex == self.n:
918
1002
919 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1003 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
920 self.__dataReady = True
1004 self.__dataReady = True
921
1005
922 return avgdata_spc, avgdata_cspc, avgdata_dc
1006 return avgdata_spc, avgdata_cspc, avgdata_dc
923
1007
924 def byTime(self, datatime, *args):
1008 def byTime(self, datatime, *args):
925
1009
926 self.__dataReady = False
1010 self.__dataReady = False
927 avgdata_spc = None
1011 avgdata_spc = None
928 avgdata_cspc = None
1012 avgdata_cspc = None
929 avgdata_dc = None
1013 avgdata_dc = None
930 n = None
1014 n = None
931
1015
932 self.putData(*args)
1016 self.putData(*args)
933
1017
934 if (datatime - self.__initime) >= self.__integrationtime:
1018 if (datatime - self.__initime) >= self.__integrationtime:
935 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1019 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
936 self.n = n
1020 self.n = n
937 self.__dataReady = True
1021 self.__dataReady = True
938
1022
939 return avgdata_spc, avgdata_cspc, avgdata_dc
1023 return avgdata_spc, avgdata_cspc, avgdata_dc
940
1024
941 def integrate(self, datatime, *args):
1025 def integrate(self, datatime, *args):
942
1026
943 if self.__initime == None:
1027 if self.__initime == None:
944 self.__initime = datatime
1028 self.__initime = datatime
945
1029
946 if self.__byTime:
1030 if self.__byTime:
947 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1031 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
948 else:
1032 else:
949 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1033 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
950
1034
951 self.__lastdatatime = datatime
1035 self.__lastdatatime = datatime
952
1036
953 if avgdata_spc == None:
1037 if avgdata_spc == None:
954 return None, None, None, None
1038 return None, None, None, None
955
1039
956 avgdatatime = self.__initime
1040 avgdatatime = self.__initime
957
1041
958 deltatime = datatime -self.__lastdatatime
1042 deltatime = datatime -self.__lastdatatime
959
1043
960 if not self.__withOverapping:
1044 if not self.__withOverapping:
961 self.__initime = datatime
1045 self.__initime = datatime
962 else:
1046 else:
963 self.__initime += deltatime
1047 self.__initime += deltatime
964
1048
965 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1049 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
966
1050
967 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1051 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
968
1052
969 if not self.__isConfig:
1053 if not self.__isConfig:
970 self.setup(n, timeInterval, overlapping)
1054 self.setup(n, timeInterval, overlapping)
971 self.__isConfig = True
1055 self.__isConfig = True
972
1056
973 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1057 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
974 dataOut.data_spc,
1058 dataOut.data_spc,
975 dataOut.data_cspc,
1059 dataOut.data_cspc,
976 dataOut.data_dc)
1060 dataOut.data_dc)
977
1061
978 # dataOut.timeInterval *= n
1062 # dataOut.timeInterval *= n
979 dataOut.flagNoData = True
1063 dataOut.flagNoData = True
980
1064
981 if self.__dataReady:
1065 if self.__dataReady:
982 dataOut.data_spc = avgdata_spc
1066 dataOut.data_spc = avgdata_spc
983 dataOut.data_cspc = avgdata_cspc
1067 dataOut.data_cspc = avgdata_cspc
984 dataOut.data_dc = avgdata_dc
1068 dataOut.data_dc = avgdata_dc
985
1069
986 dataOut.nIncohInt *= self.n
1070 dataOut.nIncohInt *= self.n
987 dataOut.utctime = avgdatatime
1071 dataOut.utctime = avgdatatime
988 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1072 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
989 dataOut.flagNoData = False
1073 dataOut.flagNoData = False
990
1074 No newline at end of file
991
992 class ProfileSelector(Operation):
993
994 profileIndex = None
995 # Tamanho total de los perfiles
996 nProfiles = None
997
998 def __init__(self):
999
1000 self.profileIndex = 0
1001
1002 def incIndex(self):
1003 self.profileIndex += 1
1004
1005 if self.profileIndex >= self.nProfiles:
1006 self.profileIndex = 0
1007
1008 def isProfileInRange(self, minIndex, maxIndex):
1009
1010 if self.profileIndex < minIndex:
1011 return False
1012
1013 if self.profileIndex > maxIndex:
1014 return False
1015
1016 return True
1017
1018 def isProfileInList(self, profileList):
1019
1020 if self.profileIndex not in profileList:
1021 return False
1022
1023 return True
1024
1025 def run(self, dataOut, profileList=None, profileRangeList=None):
1026
1027 self.nProfiles = dataOut.nProfiles
1028
1029 if profileList != None:
1030 if not(self.isProfileInList(profileList)):
1031 dataOut.flagNoData = True
1032 else:
1033 dataOut.flagNoData = False
1034 self.incIndex()
1035 return 1
1036
1037
1038 elif profileRangeList != None:
1039 minIndex = profileRangeList[0]
1040 maxIndex = profileRangeList[1]
1041 if not(self.isProfileInRange(minIndex, maxIndex)):
1042 dataOut.flagNoData = True
1043 else:
1044 dataOut.flagNoData = False
1045 self.incIndex()
1046 return 1
1047 else:
1048 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1049
1050 return 0
1051
1052 class Decoder:
1053
1054 data = None
1055 profCounter = None
1056 code = None
1057 ncode = None
1058 nbaud = None
1059 codeIndex = None
1060 flag = False
1061
1062 def __init__(self):
1063
1064 self.data = None
1065 self.ndata = None
1066 self.profCounter = 1
1067 self.codeIndex = 0
1068 self.flag = False
1069 self.code = None
1070 self.ncode = None
1071 self.nbaud = None
1072 self.__isConfig = False
1073
1074 def convolutionInFreq(self, data, ndata):
1075
1076 newcode = numpy.zeros(ndata)
1077 newcode[0:self.nbaud] = self.code[self.codeIndex]
1078
1079 self.codeIndex += 1
1080
1081 fft_data = numpy.fft.fft(data, axis=1)
1082 fft_code = numpy.conj(numpy.fft.fft(newcode))
1083 fft_code = fft_code.reshape(1,len(fft_code))
1084
1085 conv = fft_data.copy()
1086 conv.fill(0)
1087
1088 conv = fft_data*fft_code
1089
1090 data = numpy.fft.ifft(conv,axis=1)
1091 self.data = data[:,:-self.nbaud+1]
1092 self.flag = True
1093
1094 if self.profCounter == self.ncode:
1095 self.profCounter = 0
1096 self.codeIndex = 0
1097
1098 self.profCounter += 1
1099
1100 def convolutionInTime(self, data, ndata):
1101
1102 nchannel = data.shape[1]
1103 newcode = self.code[self.codeIndex]
1104 self.codeIndex += 1
1105 conv = data.copy()
1106 for i in range(nchannel):
1107 conv[i,:] = numpy.correlate(data[i,:], newcode)
1108
1109 self.data = conv
1110 self.flag = True
1111
1112 if self.profCounter == self.ncode:
1113 self.profCounter = 0
1114 self.codeIndex = 0
1115
1116 self.profCounter += 1
1117
1118 def run(self, dataOut, code=None, mode = 0):
1119
1120 if not(self.__isConfig):
1121 if code == None:
1122 code = dataOut.radarControllerHeaderObj.code
1123 # code = dataOut.code
1124
1125 ncode, nbaud = code.shape
1126 self.code = code
1127 self.ncode = ncode
1128 self.nbaud = nbaud
1129 self.__isConfig = True
1130
1131 ndata = dataOut.data.shape[1]
1132
1133 if mode == 0:
1134 self.convolutionInFreq(dataOut.data, ndata)
1135
1136 if mode == 1:
1137 self.convolutionInTime(dataOut.data, ndata)
1138
1139 self.ndata = ndata - self.nbaud + 1
1140
1141 dataOut.data = self.data
1142
1143 dataOut.heightList = dataOut.heightList[:self.ndata]
1144
1145 dataOut.flagNoData = False No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now