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