##// END OF EJS Templates
Se agrega a JROData el flag realtime, para este caso se da prioridad al procesamiento de datos. Los graficos se generan solo cuando el tiempo de procesamiento es cercano al tiempo de adquisición.
Daniel Valdez -
r360:31a78476b797
parent child
Show More
@@ -1,624 +1,626
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 useLocalTime = False
140 useLocalTime = False
141
141
142 utctime = None
142 utctime = None
143
143
144 timeZone = None
144 timeZone = None
145
145
146 dstFlag = None
146 dstFlag = None
147
147
148 errorCount = None
148 errorCount = None
149
149
150 blocksize = None
150 blocksize = None
151
151
152 nCode = None
152 nCode = None
153
153
154 nBaud = None
154 nBaud = None
155
155
156 code = None
156 code = None
157
157
158 flagDecodeData = False #asumo q la data no esta decodificada
158 flagDecodeData = False #asumo q la data no esta decodificada
159
159
160 flagDeflipData = False #asumo q la data no esta sin flip
160 flagDeflipData = False #asumo q la data no esta sin flip
161
161
162 flagShiftFFT = False
162 flagShiftFFT = False
163
163
164 ippSeconds = None
164 ippSeconds = None
165
165
166 timeInterval = None
166 timeInterval = None
167
167
168 nCohInt = None
168 nCohInt = None
169
169
170 noise = None
170 noise = None
171
171
172 windowOfFilter = 1
172 windowOfFilter = 1
173
173
174 #Speed of ligth
174 #Speed of ligth
175 C = 3e8
175 C = 3e8
176
176
177 frequency = 49.92e6
177 frequency = 49.92e6
178
179 realtime = False
178
180
179 def __init__(self):
181 def __init__(self):
180
182
181 raise ValueError, "This class has not been implemented"
183 raise ValueError, "This class has not been implemented"
182
184
183 def copy(self, inputObj=None):
185 def copy(self, inputObj=None):
184
186
185 if inputObj == None:
187 if inputObj == None:
186 return copy.deepcopy(self)
188 return copy.deepcopy(self)
187
189
188 for key in inputObj.__dict__.keys():
190 for key in inputObj.__dict__.keys():
189 self.__dict__[key] = inputObj.__dict__[key]
191 self.__dict__[key] = inputObj.__dict__[key]
190
192
191 def deepcopy(self):
193 def deepcopy(self):
192
194
193 return copy.deepcopy(self)
195 return copy.deepcopy(self)
194
196
195 def isEmpty(self):
197 def isEmpty(self):
196
198
197 return self.flagNoData
199 return self.flagNoData
198
200
199 def getNoise(self):
201 def getNoise(self):
200
202
201 raise ValueError, "Not implemented"
203 raise ValueError, "Not implemented"
202
204
203 def getNChannels(self):
205 def getNChannels(self):
204
206
205 return len(self.channelList)
207 return len(self.channelList)
206
208
207 def getChannelIndexList(self):
209 def getChannelIndexList(self):
208
210
209 return range(self.nChannels)
211 return range(self.nChannels)
210
212
211 def getNHeights(self):
213 def getNHeights(self):
212
214
213 return len(self.heightList)
215 return len(self.heightList)
214
216
215 def getHeiRange(self, extrapoints=0):
217 def getHeiRange(self, extrapoints=0):
216
218
217 heis = self.heightList
219 heis = self.heightList
218 # deltah = self.heightList[1] - self.heightList[0]
220 # deltah = self.heightList[1] - self.heightList[0]
219 #
221 #
220 # heis.append(self.heightList[-1])
222 # heis.append(self.heightList[-1])
221
223
222 return heis
224 return heis
223
225
224 def getltctime(self):
226 def getltctime(self):
225
227
226 if self.useLocalTime:
228 if self.useLocalTime:
227 return self.utctime - self.timeZone*60
229 return self.utctime - self.timeZone*60
228
230
229 return self.utctime
231 return self.utctime
230
232
231 def getDatatime(self):
233 def getDatatime(self):
232
234
233 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
235 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
234 return datatime
236 return datatime
235
237
236 def getTimeRange(self):
238 def getTimeRange(self):
237
239
238 datatime = []
240 datatime = []
239
241
240 datatime.append(self.ltctime)
242 datatime.append(self.ltctime)
241 datatime.append(self.ltctime + self.timeInterval)
243 datatime.append(self.ltctime + self.timeInterval)
242
244
243 datatime = numpy.array(datatime)
245 datatime = numpy.array(datatime)
244
246
245 return datatime
247 return datatime
246
248
247 def getFmax(self):
249 def getFmax(self):
248
250
249 PRF = 1./(self.ippSeconds * self.nCohInt)
251 PRF = 1./(self.ippSeconds * self.nCohInt)
250
252
251 fmax = PRF/2.
253 fmax = PRF/2.
252
254
253 return fmax
255 return fmax
254
256
255 def getVmax(self):
257 def getVmax(self):
256
258
257 _lambda = self.C/self.frequency
259 _lambda = self.C/self.frequency
258
260
259 vmax = self.getFmax() * _lambda
261 vmax = self.getFmax() * _lambda
260
262
261 return vmax
263 return vmax
262
264
263 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
265 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
264 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
266 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
265 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
267 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
266 noise = property(getNoise, "I'm the 'nHeights' property.")
268 noise = property(getNoise, "I'm the 'nHeights' property.")
267 datatime = property(getDatatime, "I'm the 'datatime' property")
269 datatime = property(getDatatime, "I'm the 'datatime' property")
268 ltctime = property(getltctime, "I'm the 'ltctime' property")
270 ltctime = property(getltctime, "I'm the 'ltctime' property")
269
271
270 class Voltage(JROData):
272 class Voltage(JROData):
271
273
272 #data es un numpy array de 2 dmensiones (canales, alturas)
274 #data es un numpy array de 2 dmensiones (canales, alturas)
273 data = None
275 data = None
274
276
275 def __init__(self):
277 def __init__(self):
276 '''
278 '''
277 Constructor
279 Constructor
278 '''
280 '''
279
281
280 self.radarControllerHeaderObj = RadarControllerHeader()
282 self.radarControllerHeaderObj = RadarControllerHeader()
281
283
282 self.systemHeaderObj = SystemHeader()
284 self.systemHeaderObj = SystemHeader()
283
285
284 self.type = "Voltage"
286 self.type = "Voltage"
285
287
286 self.data = None
288 self.data = None
287
289
288 self.dtype = None
290 self.dtype = None
289
291
290 # self.nChannels = 0
292 # self.nChannels = 0
291
293
292 # self.nHeights = 0
294 # self.nHeights = 0
293
295
294 self.nProfiles = None
296 self.nProfiles = None
295
297
296 self.heightList = None
298 self.heightList = None
297
299
298 self.channelList = None
300 self.channelList = None
299
301
300 # self.channelIndexList = None
302 # self.channelIndexList = None
301
303
302 self.flagNoData = True
304 self.flagNoData = True
303
305
304 self.flagTimeBlock = False
306 self.flagTimeBlock = False
305
307
306 self.utctime = None
308 self.utctime = None
307
309
308 self.timeZone = None
310 self.timeZone = None
309
311
310 self.dstFlag = None
312 self.dstFlag = None
311
313
312 self.errorCount = None
314 self.errorCount = None
313
315
314 self.nCohInt = None
316 self.nCohInt = None
315
317
316 self.blocksize = None
318 self.blocksize = None
317
319
318 self.flagDecodeData = False #asumo q la data no esta decodificada
320 self.flagDecodeData = False #asumo q la data no esta decodificada
319
321
320 self.flagDeflipData = False #asumo q la data no esta sin flip
322 self.flagDeflipData = False #asumo q la data no esta sin flip
321
323
322 self.flagShiftFFT = False
324 self.flagShiftFFT = False
323
325
324
326
325 def getNoisebyHildebrand(self):
327 def getNoisebyHildebrand(self):
326 """
328 """
327 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
329 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
328
330
329 Return:
331 Return:
330 noiselevel
332 noiselevel
331 """
333 """
332
334
333 for channel in range(self.nChannels):
335 for channel in range(self.nChannels):
334 daux = self.data_spc[channel,:,:]
336 daux = self.data_spc[channel,:,:]
335 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
337 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
336
338
337 return self.noise
339 return self.noise
338
340
339 def getNoise(self, type = 1):
341 def getNoise(self, type = 1):
340
342
341 self.noise = numpy.zeros(self.nChannels)
343 self.noise = numpy.zeros(self.nChannels)
342
344
343 if type == 1:
345 if type == 1:
344 noise = self.getNoisebyHildebrand()
346 noise = self.getNoisebyHildebrand()
345
347
346 return 10*numpy.log10(noise)
348 return 10*numpy.log10(noise)
347
349
348 class Spectra(JROData):
350 class Spectra(JROData):
349
351
350 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
352 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
351 data_spc = None
353 data_spc = None
352
354
353 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
355 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
354 data_cspc = None
356 data_cspc = None
355
357
356 #data es un numpy array de 2 dmensiones (canales, alturas)
358 #data es un numpy array de 2 dmensiones (canales, alturas)
357 data_dc = None
359 data_dc = None
358
360
359 nFFTPoints = None
361 nFFTPoints = None
360
362
361 nPairs = None
363 nPairs = None
362
364
363 pairsList = None
365 pairsList = None
364
366
365 nIncohInt = None
367 nIncohInt = None
366
368
367 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
369 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
368
370
369 nCohInt = None #se requiere para determinar el valor de timeInterval
371 nCohInt = None #se requiere para determinar el valor de timeInterval
370
372
371 def __init__(self):
373 def __init__(self):
372 '''
374 '''
373 Constructor
375 Constructor
374 '''
376 '''
375
377
376 self.radarControllerHeaderObj = RadarControllerHeader()
378 self.radarControllerHeaderObj = RadarControllerHeader()
377
379
378 self.systemHeaderObj = SystemHeader()
380 self.systemHeaderObj = SystemHeader()
379
381
380 self.type = "Spectra"
382 self.type = "Spectra"
381
383
382 # self.data = None
384 # self.data = None
383
385
384 self.dtype = None
386 self.dtype = None
385
387
386 # self.nChannels = 0
388 # self.nChannels = 0
387
389
388 # self.nHeights = 0
390 # self.nHeights = 0
389
391
390 self.nProfiles = None
392 self.nProfiles = None
391
393
392 self.heightList = None
394 self.heightList = None
393
395
394 self.channelList = None
396 self.channelList = None
395
397
396 # self.channelIndexList = None
398 # self.channelIndexList = None
397
399
398 self.flagNoData = True
400 self.flagNoData = True
399
401
400 self.flagTimeBlock = False
402 self.flagTimeBlock = False
401
403
402 self.utctime = None
404 self.utctime = None
403
405
404 self.nCohInt = None
406 self.nCohInt = None
405
407
406 self.nIncohInt = None
408 self.nIncohInt = None
407
409
408 self.blocksize = None
410 self.blocksize = None
409
411
410 self.nFFTPoints = None
412 self.nFFTPoints = None
411
413
412 self.wavelength = None
414 self.wavelength = None
413
415
414 self.flagDecodeData = False #asumo q la data no esta decodificada
416 self.flagDecodeData = False #asumo q la data no esta decodificada
415
417
416 self.flagDeflipData = False #asumo q la data no esta sin flip
418 self.flagDeflipData = False #asumo q la data no esta sin flip
417
419
418 self.flagShiftFFT = False
420 self.flagShiftFFT = False
419
421
420 def getNoisebyHildebrand(self):
422 def getNoisebyHildebrand(self):
421 """
423 """
422 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
424 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
423
425
424 Return:
426 Return:
425 noiselevel
427 noiselevel
426 """
428 """
427
429
428 for channel in range(self.nChannels):
430 for channel in range(self.nChannels):
429 daux = self.data_spc[channel,:,:]
431 daux = self.data_spc[channel,:,:]
430 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
432 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
431
433
432 return self.noise
434 return self.noise
433
435
434 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
436 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
435 """
437 """
436 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
438 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
437 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
439 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
438
440
439 Inputs:
441 Inputs:
440 heiIndexMin: Limite inferior del eje de alturas
442 heiIndexMin: Limite inferior del eje de alturas
441 heiIndexMax: Limite superior del eje de alturas
443 heiIndexMax: Limite superior del eje de alturas
442 freqIndexMin: Limite inferior del eje de frecuencia
444 freqIndexMin: Limite inferior del eje de frecuencia
443 freqIndexMax: Limite supoerior del eje de frecuencia
445 freqIndexMax: Limite supoerior del eje de frecuencia
444 """
446 """
445
447
446 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
448 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
447
449
448 for channel in range(self.nChannels):
450 for channel in range(self.nChannels):
449 daux = data[channel,:,:]
451 daux = data[channel,:,:]
450 self.noise[channel] = numpy.average(daux)
452 self.noise[channel] = numpy.average(daux)
451
453
452 return self.noise
454 return self.noise
453
455
454 def getNoisebySort(self):
456 def getNoisebySort(self):
455
457
456 for channel in range(self.nChannels):
458 for channel in range(self.nChannels):
457 daux = self.data_spc[channel,:,:]
459 daux = self.data_spc[channel,:,:]
458 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
460 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
459
461
460 return self.noise
462 return self.noise
461
463
462 def getNoise(self, type = 1):
464 def getNoise(self, type = 1):
463
465
464 self.noise = numpy.zeros(self.nChannels)
466 self.noise = numpy.zeros(self.nChannels)
465
467
466 if type == 1:
468 if type == 1:
467 noise = self.getNoisebyHildebrand()
469 noise = self.getNoisebyHildebrand()
468
470
469 if type == 2:
471 if type == 2:
470 noise = self.getNoisebySort()
472 noise = self.getNoisebySort()
471
473
472 if type == 3:
474 if type == 3:
473 noise = self.getNoisebyWindow()
475 noise = self.getNoisebyWindow()
474
476
475 return noise
477 return noise
476
478
477
479
478 def getFreqRange(self, extrapoints=0):
480 def getFreqRange(self, extrapoints=0):
479
481
480 deltafreq = self.getFmax() / self.nFFTPoints
482 deltafreq = self.getFmax() / self.nFFTPoints
481 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
483 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
482
484
483 return freqrange
485 return freqrange
484
486
485 def getVelRange(self, extrapoints=0):
487 def getVelRange(self, extrapoints=0):
486
488
487 deltav = self.getVmax() / self.nFFTPoints
489 deltav = self.getVmax() / self.nFFTPoints
488 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
490 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
489
491
490 return velrange
492 return velrange
491
493
492 def getNPairs(self):
494 def getNPairs(self):
493
495
494 return len(self.pairsList)
496 return len(self.pairsList)
495
497
496 def getPairsIndexList(self):
498 def getPairsIndexList(self):
497
499
498 return range(self.nPairs)
500 return range(self.nPairs)
499
501
500 def getNormFactor(self):
502 def getNormFactor(self):
501 pwcode = 1
503 pwcode = 1
502 if self.flagDecodeData:
504 if self.flagDecodeData:
503 pwcode = numpy.sum(self.code[0]**2)
505 pwcode = numpy.sum(self.code[0]**2)
504 normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode
506 normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode
505
507
506 return normFactor
508 return normFactor
507
509
508 def getFlagCspc(self):
510 def getFlagCspc(self):
509
511
510 if self.data_cspc == None:
512 if self.data_cspc == None:
511 return True
513 return True
512
514
513 return False
515 return False
514
516
515 def getFlagDc(self):
517 def getFlagDc(self):
516
518
517 if self.data_dc == None:
519 if self.data_dc == None:
518 return True
520 return True
519
521
520 return False
522 return False
521
523
522 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
524 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
523 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
525 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
524 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
526 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
525 flag_cspc = property(getFlagCspc)
527 flag_cspc = property(getFlagCspc)
526 flag_dc = property(getFlagDc)
528 flag_dc = property(getFlagDc)
527
529
528 class SpectraHeis(JROData):
530 class SpectraHeis(JROData):
529
531
530 data_spc = None
532 data_spc = None
531
533
532 data_cspc = None
534 data_cspc = None
533
535
534 data_dc = None
536 data_dc = None
535
537
536 nFFTPoints = None
538 nFFTPoints = None
537
539
538 nPairs = None
540 nPairs = None
539
541
540 pairsList = None
542 pairsList = None
541
543
542 nIncohInt = None
544 nIncohInt = None
543
545
544 def __init__(self):
546 def __init__(self):
545
547
546 self.radarControllerHeaderObj = RadarControllerHeader()
548 self.radarControllerHeaderObj = RadarControllerHeader()
547
549
548 self.systemHeaderObj = SystemHeader()
550 self.systemHeaderObj = SystemHeader()
549
551
550 self.type = "SpectraHeis"
552 self.type = "SpectraHeis"
551
553
552 self.dtype = None
554 self.dtype = None
553
555
554 # self.nChannels = 0
556 # self.nChannels = 0
555
557
556 # self.nHeights = 0
558 # self.nHeights = 0
557
559
558 self.nProfiles = None
560 self.nProfiles = None
559
561
560 self.heightList = None
562 self.heightList = None
561
563
562 self.channelList = None
564 self.channelList = None
563
565
564 # self.channelIndexList = None
566 # self.channelIndexList = None
565
567
566 self.flagNoData = True
568 self.flagNoData = True
567
569
568 self.flagTimeBlock = False
570 self.flagTimeBlock = False
569
571
570 self.nPairs = 0
572 self.nPairs = 0
571
573
572 self.utctime = None
574 self.utctime = None
573
575
574 self.blocksize = None
576 self.blocksize = None
575
577
576 class Fits:
578 class Fits:
577
579
578 def __init__(self):
580 def __init__(self):
579 self.useLocalTime = False
581 self.useLocalTime = False
580 self.utctime = None
582 self.utctime = None
581 self.timeZone = None
583 self.timeZone = None
582 self.ltctime = None
584 self.ltctime = None
583 self.timeInterval = None
585 self.timeInterval = None
584 self.header = None
586 self.header = None
585 self.data_header = None
587 self.data_header = None
586 self.data = None
588 self.data = None
587 self.datatime = None
589 self.datatime = None
588 self.flagNoData = False
590 self.flagNoData = False
589 self.expName = ''
591 self.expName = ''
590 self.nChannels = None
592 self.nChannels = None
591 self.nSamples = None
593 self.nSamples = None
592 self.dataBlocksPerFile = None
594 self.dataBlocksPerFile = None
593 self.comments = ''
595 self.comments = ''
594
596
595
597
596 def getltctime(self):
598 def getltctime(self):
597
599
598 if self.useLocalTime:
600 if self.useLocalTime:
599 return self.utctime - self.timeZone*60
601 return self.utctime - self.timeZone*60
600
602
601 return self.utctime
603 return self.utctime
602
604
603 def getDatatime(self):
605 def getDatatime(self):
604
606
605 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
607 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
606 return datatime
608 return datatime
607
609
608 def getTimeRange(self):
610 def getTimeRange(self):
609
611
610 datatime = []
612 datatime = []
611
613
612 datatime.append(self.ltctime)
614 datatime.append(self.ltctime)
613 datatime.append(self.ltctime + self.timeInterval)
615 datatime.append(self.ltctime + self.timeInterval)
614
616
615 datatime = numpy.array(datatime)
617 datatime = numpy.array(datatime)
616
618
617 return datatime
619 return datatime
618
620
619 def isEmpty(self):
621 def isEmpty(self):
620
622
621 return self.flagNoData
623 return self.flagNoData
622
624
623 datatime = property(getDatatime, "I'm the 'datatime' property")
625 datatime = property(getDatatime, "I'm the 'datatime' property")
624 ltctime = property(getltctime, "I'm the 'ltctime' property") No newline at end of file
626 ltctime = property(getltctime, "I'm the 'ltctime' property")
@@ -1,3313 +1,3317
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 from xml.etree.ElementTree import Element, SubElement, ElementTree
13 from xml.etree.ElementTree import Element, SubElement, ElementTree
14 try:
14 try:
15 import pyfits
15 import pyfits
16 except:
16 except:
17 print "pyfits module has not been imported, it should be installed to save files in fits format"
17 print "pyfits module has not been imported, it should be installed to save files in fits format"
18
18
19 from jrodata import *
19 from jrodata import *
20 from jroheaderIO import *
20 from jroheaderIO import *
21 from jroprocessing import *
21 from jroprocessing import *
22
22
23 LOCALTIME = True #-18000
23 LOCALTIME = True #-18000
24
24
25 def isNumber(str):
25 def isNumber(str):
26 """
26 """
27 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
27 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
28
28
29 Excepciones:
29 Excepciones:
30 Si un determinado string no puede ser convertido a numero
30 Si un determinado string no puede ser convertido a numero
31 Input:
31 Input:
32 str, string al cual se le analiza para determinar si convertible a un numero o no
32 str, string al cual se le analiza para determinar si convertible a un numero o no
33
33
34 Return:
34 Return:
35 True : si el string es uno numerico
35 True : si el string es uno numerico
36 False : no es un string numerico
36 False : no es un string numerico
37 """
37 """
38 try:
38 try:
39 float( str )
39 float( str )
40 return True
40 return True
41 except:
41 except:
42 return False
42 return False
43
43
44 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
44 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
45 """
45 """
46 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
46 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
47
47
48 Inputs:
48 Inputs:
49 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
49 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
50
50
51 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
51 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
52 segundos contados desde 01/01/1970.
52 segundos contados desde 01/01/1970.
53 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
53 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
54 segundos contados desde 01/01/1970.
54 segundos contados desde 01/01/1970.
55
55
56 Return:
56 Return:
57 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
57 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
58 fecha especificado, de lo contrario retorna False.
58 fecha especificado, de lo contrario retorna False.
59
59
60 Excepciones:
60 Excepciones:
61 Si el archivo no existe o no puede ser abierto
61 Si el archivo no existe o no puede ser abierto
62 Si la cabecera no puede ser leida.
62 Si la cabecera no puede ser leida.
63
63
64 """
64 """
65 basicHeaderObj = BasicHeader(LOCALTIME)
65 basicHeaderObj = BasicHeader(LOCALTIME)
66
66
67 try:
67 try:
68 fp = open(filename,'rb')
68 fp = open(filename,'rb')
69 except:
69 except:
70 raise IOError, "The file %s can't be opened" %(filename)
70 raise IOError, "The file %s can't be opened" %(filename)
71
71
72 sts = basicHeaderObj.read(fp)
72 sts = basicHeaderObj.read(fp)
73 fp.close()
73 fp.close()
74
74
75 if not(sts):
75 if not(sts):
76 print "Skipping the file %s because it has not a valid header" %(filename)
76 print "Skipping the file %s because it has not a valid header" %(filename)
77 return 0
77 return 0
78
78
79 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
79 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
80 return 0
80 return 0
81
81
82 return 1
82 return 1
83
83
84 def isFileinThisTime(filename, startTime, endTime):
84 def isFileinThisTime(filename, startTime, endTime):
85 """
85 """
86 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
86 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
87
87
88 Inputs:
88 Inputs:
89 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
89 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
90
90
91 startTime : tiempo inicial del rango seleccionado en formato datetime.time
91 startTime : tiempo inicial del rango seleccionado en formato datetime.time
92
92
93 endTime : tiempo final del rango seleccionado en formato datetime.time
93 endTime : tiempo final del rango seleccionado en formato datetime.time
94
94
95 Return:
95 Return:
96 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
96 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
97 fecha especificado, de lo contrario retorna False.
97 fecha especificado, de lo contrario retorna False.
98
98
99 Excepciones:
99 Excepciones:
100 Si el archivo no existe o no puede ser abierto
100 Si el archivo no existe o no puede ser abierto
101 Si la cabecera no puede ser leida.
101 Si la cabecera no puede ser leida.
102
102
103 """
103 """
104
104
105
105
106 try:
106 try:
107 fp = open(filename,'rb')
107 fp = open(filename,'rb')
108 except:
108 except:
109 raise IOError, "The file %s can't be opened" %(filename)
109 raise IOError, "The file %s can't be opened" %(filename)
110
110
111 basicHeaderObj = BasicHeader(LOCALTIME)
111 basicHeaderObj = BasicHeader(LOCALTIME)
112 sts = basicHeaderObj.read(fp)
112 sts = basicHeaderObj.read(fp)
113 fp.close()
113 fp.close()
114
114
115 thisDatetime = basicHeaderObj.datatime
115 thisDatetime = basicHeaderObj.datatime
116 thisTime = basicHeaderObj.datatime.time()
116 thisTime = basicHeaderObj.datatime.time()
117
117
118 if not(sts):
118 if not(sts):
119 print "Skipping the file %s because it has not a valid header" %(filename)
119 print "Skipping the file %s because it has not a valid header" %(filename)
120 return None
120 return None
121
121
122 if not ((startTime <= thisTime) and (endTime > thisTime)):
122 if not ((startTime <= thisTime) and (endTime > thisTime)):
123 return None
123 return None
124
124
125 return thisDatetime
125 return thisDatetime
126
126
127 def getlastFileFromPath(path, ext):
127 def getlastFileFromPath(path, ext):
128 """
128 """
129 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
129 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
130 al final de la depuracion devuelve el ultimo file de la lista que quedo.
130 al final de la depuracion devuelve el ultimo file de la lista que quedo.
131
131
132 Input:
132 Input:
133 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
133 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
134 ext : extension de los files contenidos en una carpeta
134 ext : extension de los files contenidos en una carpeta
135
135
136 Return:
136 Return:
137 El ultimo file de una determinada carpeta, no se considera el path.
137 El ultimo file de una determinada carpeta, no se considera el path.
138 """
138 """
139 validFilelist = []
139 validFilelist = []
140 fileList = os.listdir(path)
140 fileList = os.listdir(path)
141
141
142 # 0 1234 567 89A BCDE
142 # 0 1234 567 89A BCDE
143 # H YYYY DDD SSS .ext
143 # H YYYY DDD SSS .ext
144
144
145 for file in fileList:
145 for file in fileList:
146 try:
146 try:
147 year = int(file[1:5])
147 year = int(file[1:5])
148 doy = int(file[5:8])
148 doy = int(file[5:8])
149
149
150
150
151 except:
151 except:
152 continue
152 continue
153
153
154 if (os.path.splitext(file)[-1].lower() != ext.lower()):
154 if (os.path.splitext(file)[-1].lower() != ext.lower()):
155 continue
155 continue
156
156
157 validFilelist.append(file)
157 validFilelist.append(file)
158
158
159 if validFilelist:
159 if validFilelist:
160 validFilelist = sorted( validFilelist, key=str.lower )
160 validFilelist = sorted( validFilelist, key=str.lower )
161 return validFilelist[-1]
161 return validFilelist[-1]
162
162
163 return None
163 return None
164
164
165 def checkForRealPath(path, foldercounter, year, doy, set, ext):
165 def checkForRealPath(path, foldercounter, year, doy, set, ext):
166 """
166 """
167 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
167 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
168 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
168 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
169 el path exacto de un determinado file.
169 el path exacto de un determinado file.
170
170
171 Example :
171 Example :
172 nombre correcto del file es .../.../D2009307/P2009307367.ext
172 nombre correcto del file es .../.../D2009307/P2009307367.ext
173
173
174 Entonces la funcion prueba con las siguientes combinaciones
174 Entonces la funcion prueba con las siguientes combinaciones
175 .../.../y2009307367.ext
175 .../.../y2009307367.ext
176 .../.../Y2009307367.ext
176 .../.../Y2009307367.ext
177 .../.../x2009307/y2009307367.ext
177 .../.../x2009307/y2009307367.ext
178 .../.../x2009307/Y2009307367.ext
178 .../.../x2009307/Y2009307367.ext
179 .../.../X2009307/y2009307367.ext
179 .../.../X2009307/y2009307367.ext
180 .../.../X2009307/Y2009307367.ext
180 .../.../X2009307/Y2009307367.ext
181 siendo para este caso, la ultima combinacion de letras, identica al file buscado
181 siendo para este caso, la ultima combinacion de letras, identica al file buscado
182
182
183 Return:
183 Return:
184 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
184 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
185 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
185 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
186 para el filename
186 para el filename
187 """
187 """
188 fullfilename = None
188 fullfilename = None
189 find_flag = False
189 find_flag = False
190 filename = None
190 filename = None
191
191
192 prefixDirList = [None,'d','D']
192 prefixDirList = [None,'d','D']
193 if ext.lower() == ".r": #voltage
193 if ext.lower() == ".r": #voltage
194 prefixFileList = ['d','D']
194 prefixFileList = ['d','D']
195 elif ext.lower() == ".pdata": #spectra
195 elif ext.lower() == ".pdata": #spectra
196 prefixFileList = ['p','P']
196 prefixFileList = ['p','P']
197 else:
197 else:
198 return None, filename
198 return None, filename
199
199
200 #barrido por las combinaciones posibles
200 #barrido por las combinaciones posibles
201 for prefixDir in prefixDirList:
201 for prefixDir in prefixDirList:
202 thispath = path
202 thispath = path
203 if prefixDir != None:
203 if prefixDir != None:
204 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
204 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
205 if foldercounter == 0:
205 if foldercounter == 0:
206 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
206 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
207 else:
207 else:
208 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
208 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
209 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
209 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
210 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
210 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
211 fullfilename = os.path.join( thispath, filename ) #formo el path completo
211 fullfilename = os.path.join( thispath, filename ) #formo el path completo
212
212
213 if os.path.exists( fullfilename ): #verifico que exista
213 if os.path.exists( fullfilename ): #verifico que exista
214 find_flag = True
214 find_flag = True
215 break
215 break
216 if find_flag:
216 if find_flag:
217 break
217 break
218
218
219 if not(find_flag):
219 if not(find_flag):
220 return None, filename
220 return None, filename
221
221
222 return fullfilename, filename
222 return fullfilename, filename
223
223
224 def isDoyFolder(folder):
224 def isDoyFolder(folder):
225 try:
225 try:
226 year = int(folder[1:5])
226 year = int(folder[1:5])
227 except:
227 except:
228 return 0
228 return 0
229
229
230 try:
230 try:
231 doy = int(folder[5:8])
231 doy = int(folder[5:8])
232 except:
232 except:
233 return 0
233 return 0
234
234
235 return 1
235 return 1
236
236
237 class JRODataIO:
237 class JRODataIO:
238
238
239 c = 3E8
239 c = 3E8
240
240
241 isConfig = False
241 isConfig = False
242
242
243 basicHeaderObj = BasicHeader(LOCALTIME)
243 basicHeaderObj = BasicHeader(LOCALTIME)
244
244
245 systemHeaderObj = SystemHeader()
245 systemHeaderObj = SystemHeader()
246
246
247 radarControllerHeaderObj = RadarControllerHeader()
247 radarControllerHeaderObj = RadarControllerHeader()
248
248
249 processingHeaderObj = ProcessingHeader()
249 processingHeaderObj = ProcessingHeader()
250
250
251 online = 0
251 online = 0
252
252
253 dtype = None
253 dtype = None
254
254
255 pathList = []
255 pathList = []
256
256
257 filenameList = []
257 filenameList = []
258
258
259 filename = None
259 filename = None
260
260
261 ext = None
261 ext = None
262
262
263 flagIsNewFile = 1
263 flagIsNewFile = 1
264
264
265 flagTimeBlock = 0
265 flagTimeBlock = 0
266
266
267 flagIsNewBlock = 0
267 flagIsNewBlock = 0
268
268
269 fp = None
269 fp = None
270
270
271 firstHeaderSize = 0
271 firstHeaderSize = 0
272
272
273 basicHeaderSize = 24
273 basicHeaderSize = 24
274
274
275 versionFile = 1103
275 versionFile = 1103
276
276
277 fileSize = None
277 fileSize = None
278
278
279 ippSeconds = None
279 ippSeconds = None
280
280
281 fileSizeByHeader = None
281 fileSizeByHeader = None
282
282
283 fileIndex = None
283 fileIndex = None
284
284
285 profileIndex = None
285 profileIndex = None
286
286
287 blockIndex = None
287 blockIndex = None
288
288
289 nTotalBlocks = None
289 nTotalBlocks = None
290
290
291 maxTimeStep = 30
291 maxTimeStep = 30
292
292
293 lastUTTime = None
293 lastUTTime = None
294
294
295 datablock = None
295 datablock = None
296
296
297 dataOut = None
297 dataOut = None
298
298
299 blocksize = None
299 blocksize = None
300
300
301 def __init__(self):
301 def __init__(self):
302
302
303 raise ValueError, "Not implemented"
303 raise ValueError, "Not implemented"
304
304
305 def run(self):
305 def run(self):
306
306
307 raise ValueError, "Not implemented"
307 raise ValueError, "Not implemented"
308
308
309 def getOutput(self):
309 def getOutput(self):
310
310
311 return self.dataOut
311 return self.dataOut
312
312
313 class JRODataReader(JRODataIO, ProcessingUnit):
313 class JRODataReader(JRODataIO, ProcessingUnit):
314
314
315 nReadBlocks = 0
315 nReadBlocks = 0
316
316
317 delay = 10 #number of seconds waiting a new file
317 delay = 10 #number of seconds waiting a new file
318
318
319 nTries = 3 #quantity tries
319 nTries = 3 #quantity tries
320
320
321 nFiles = 3 #number of files for searching
321 nFiles = 3 #number of files for searching
322
322
323 path = None
323 path = None
324
324
325 foldercounter = 0
325 foldercounter = 0
326
326
327 flagNoMoreFiles = 0
327 flagNoMoreFiles = 0
328
328
329 datetimeList = []
329 datetimeList = []
330
330
331 __isFirstTimeOnline = 1
331 __isFirstTimeOnline = 1
332
332
333 __printInfo = True
333 __printInfo = True
334
334
335 profileIndex = None
335 profileIndex = None
336
336
337 def __init__(self):
337 def __init__(self):
338
338
339 """
339 """
340
340
341 """
341 """
342
342
343 raise ValueError, "This method has not been implemented"
343 raise ValueError, "This method has not been implemented"
344
344
345
345
346 def createObjByDefault(self):
346 def createObjByDefault(self):
347 """
347 """
348
348
349 """
349 """
350 raise ValueError, "This method has not been implemented"
350 raise ValueError, "This method has not been implemented"
351
351
352 def getBlockDimension(self):
352 def getBlockDimension(self):
353
353
354 raise ValueError, "No implemented"
354 raise ValueError, "No implemented"
355
355
356 def __searchFilesOffLine(self,
356 def __searchFilesOffLine(self,
357 path,
357 path,
358 startDate,
358 startDate,
359 endDate,
359 endDate,
360 startTime=datetime.time(0,0,0),
360 startTime=datetime.time(0,0,0),
361 endTime=datetime.time(23,59,59),
361 endTime=datetime.time(23,59,59),
362 set=None,
362 set=None,
363 expLabel='',
363 expLabel='',
364 ext='.r',
364 ext='.r',
365 walk=True):
365 walk=True):
366
366
367 pathList = []
367 pathList = []
368
368
369 if not walk:
369 if not walk:
370 pathList.append(path)
370 pathList.append(path)
371
371
372 else:
372 else:
373 dirList = []
373 dirList = []
374 for thisPath in os.listdir(path):
374 for thisPath in os.listdir(path):
375 if not os.path.isdir(os.path.join(path,thisPath)):
375 if not os.path.isdir(os.path.join(path,thisPath)):
376 continue
376 continue
377 if not isDoyFolder(thisPath):
377 if not isDoyFolder(thisPath):
378 continue
378 continue
379
379
380 dirList.append(thisPath)
380 dirList.append(thisPath)
381
381
382 if not(dirList):
382 if not(dirList):
383 return None, None
383 return None, None
384
384
385 thisDate = startDate
385 thisDate = startDate
386
386
387 while(thisDate <= endDate):
387 while(thisDate <= endDate):
388 year = thisDate.timetuple().tm_year
388 year = thisDate.timetuple().tm_year
389 doy = thisDate.timetuple().tm_yday
389 doy = thisDate.timetuple().tm_yday
390
390
391 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
391 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
392 if len(matchlist) == 0:
392 if len(matchlist) == 0:
393 thisDate += datetime.timedelta(1)
393 thisDate += datetime.timedelta(1)
394 continue
394 continue
395 for match in matchlist:
395 for match in matchlist:
396 pathList.append(os.path.join(path,match,expLabel))
396 pathList.append(os.path.join(path,match,expLabel))
397
397
398 thisDate += datetime.timedelta(1)
398 thisDate += datetime.timedelta(1)
399
399
400 if pathList == []:
400 if pathList == []:
401 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
401 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
402 return None, None
402 return None, None
403
403
404 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
404 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
405
405
406 filenameList = []
406 filenameList = []
407 datetimeList = []
407 datetimeList = []
408
408
409 for i in range(len(pathList)):
409 for i in range(len(pathList)):
410
410
411 thisPath = pathList[i]
411 thisPath = pathList[i]
412
412
413 fileList = glob.glob1(thisPath, "*%s" %ext)
413 fileList = glob.glob1(thisPath, "*%s" %ext)
414 fileList.sort()
414 fileList.sort()
415
415
416 for file in fileList:
416 for file in fileList:
417
417
418 filename = os.path.join(thisPath,file)
418 filename = os.path.join(thisPath,file)
419 thisDatetime = isFileinThisTime(filename, startTime, endTime)
419 thisDatetime = isFileinThisTime(filename, startTime, endTime)
420
420
421 if not(thisDatetime):
421 if not(thisDatetime):
422 continue
422 continue
423
423
424 filenameList.append(filename)
424 filenameList.append(filename)
425 datetimeList.append(thisDatetime)
425 datetimeList.append(thisDatetime)
426
426
427 if not(filenameList):
427 if not(filenameList):
428 print "Any file was found for the time range %s - %s" %(startTime, endTime)
428 print "Any file was found for the time range %s - %s" %(startTime, endTime)
429 return None, None
429 return None, None
430
430
431 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
431 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
432 print
432 print
433
433
434 for i in range(len(filenameList)):
434 for i in range(len(filenameList)):
435 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
435 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
436
436
437 self.filenameList = filenameList
437 self.filenameList = filenameList
438 self.datetimeList = datetimeList
438 self.datetimeList = datetimeList
439
439
440 return pathList, filenameList
440 return pathList, filenameList
441
441
442 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
442 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True):
443
443
444 """
444 """
445 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
445 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
446 devuelve el archivo encontrado ademas de otros datos.
446 devuelve el archivo encontrado ademas de otros datos.
447
447
448 Input:
448 Input:
449 path : carpeta donde estan contenidos los files que contiene data
449 path : carpeta donde estan contenidos los files que contiene data
450
450
451 expLabel : Nombre del subexperimento (subfolder)
451 expLabel : Nombre del subexperimento (subfolder)
452
452
453 ext : extension de los files
453 ext : extension de los files
454
454
455 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
455 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
456
456
457 Return:
457 Return:
458 directory : eL directorio donde esta el file encontrado
458 directory : eL directorio donde esta el file encontrado
459 filename : el ultimo file de una determinada carpeta
459 filename : el ultimo file de una determinada carpeta
460 year : el anho
460 year : el anho
461 doy : el numero de dia del anho
461 doy : el numero de dia del anho
462 set : el set del archivo
462 set : el set del archivo
463
463
464
464
465 """
465 """
466 dirList = []
466 dirList = []
467
467
468 if not walk:
468 if not walk:
469 fullpath = path
469 fullpath = path
470
470 foldercounter = ''
471 else:
471 else:
472 #Filtra solo los directorios
472 #Filtra solo los directorios
473 for thisPath in os.listdir(path):
473 for thisPath in os.listdir(path):
474 if not os.path.isdir(os.path.join(path,thisPath)):
474 if not os.path.isdir(os.path.join(path,thisPath)):
475 continue
475 continue
476 if not isDoyFolder(thisPath):
476 if not isDoyFolder(thisPath):
477 continue
477 continue
478
478
479 dirList.append(thisPath)
479 dirList.append(thisPath)
480
480
481 if not(dirList):
481 if not(dirList):
482 return None, None, None, None, None
482 return None, None, None, None, None, None
483
483
484 dirList = sorted( dirList, key=str.lower )
484 dirList = sorted( dirList, key=str.lower )
485
485
486 doypath = dirList[-1]
486 doypath = dirList[-1]
487 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
487 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
488 fullpath = os.path.join(path, doypath, expLabel)
488 fullpath = os.path.join(path, doypath, expLabel)
489
489
490
490
491 print "%s folder was found: " %(fullpath )
491 print "%s folder was found: " %(fullpath )
492
492
493 filename = getlastFileFromPath(fullpath, ext)
493 filename = getlastFileFromPath(fullpath, ext)
494
494
495 if not(filename):
495 if not(filename):
496 return None, None, None, None, None
496 return None, None, None, None, None
497
497
498 print "%s file was found" %(filename)
498 print "%s file was found" %(filename)
499
499
500 if not(self.__verifyFile(os.path.join(fullpath, filename))):
500 if not(self.__verifyFile(os.path.join(fullpath, filename))):
501 return None, None, None, None, None
501 return None, None, None, None, None
502
502
503 year = int( filename[1:5] )
503 year = int( filename[1:5] )
504 doy = int( filename[5:8] )
504 doy = int( filename[5:8] )
505 set = int( filename[8:11] )
505 set = int( filename[8:11] )
506
506
507 return fullpath, foldercounter, filename, year, doy, set
507 return fullpath, foldercounter, filename, year, doy, set
508
508
509 def __setNextFileOffline(self):
509 def __setNextFileOffline(self):
510
510
511 idFile = self.fileIndex
511 idFile = self.fileIndex
512
512
513 while (True):
513 while (True):
514 idFile += 1
514 idFile += 1
515 if not(idFile < len(self.filenameList)):
515 if not(idFile < len(self.filenameList)):
516 self.flagNoMoreFiles = 1
516 self.flagNoMoreFiles = 1
517 print "No more Files"
517 print "No more Files"
518 return 0
518 return 0
519
519
520 filename = self.filenameList[idFile]
520 filename = self.filenameList[idFile]
521
521
522 if not(self.__verifyFile(filename)):
522 if not(self.__verifyFile(filename)):
523 continue
523 continue
524
524
525 fileSize = os.path.getsize(filename)
525 fileSize = os.path.getsize(filename)
526 fp = open(filename,'rb')
526 fp = open(filename,'rb')
527 break
527 break
528
528
529 self.flagIsNewFile = 1
529 self.flagIsNewFile = 1
530 self.fileIndex = idFile
530 self.fileIndex = idFile
531 self.filename = filename
531 self.filename = filename
532 self.fileSize = fileSize
532 self.fileSize = fileSize
533 self.fp = fp
533 self.fp = fp
534
534
535 print "Setting the file: %s"%self.filename
535 print "Setting the file: %s"%self.filename
536
536
537 return 1
537 return 1
538
538
539 def __setNextFileOnline(self):
539 def __setNextFileOnline(self):
540 """
540 """
541 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
541 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
542 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
542 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
543 siguientes.
543 siguientes.
544
544
545 Affected:
545 Affected:
546 self.flagIsNewFile
546 self.flagIsNewFile
547 self.filename
547 self.filename
548 self.fileSize
548 self.fileSize
549 self.fp
549 self.fp
550 self.set
550 self.set
551 self.flagNoMoreFiles
551 self.flagNoMoreFiles
552
552
553 Return:
553 Return:
554 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
554 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
555 1 : si el file fue abierto con exito y esta listo a ser leido
555 1 : si el file fue abierto con exito y esta listo a ser leido
556
556
557 Excepciones:
557 Excepciones:
558 Si un determinado file no puede ser abierto
558 Si un determinado file no puede ser abierto
559 """
559 """
560 nFiles = 0
560 nFiles = 0
561 fileOk_flag = False
561 fileOk_flag = False
562 firstTime_flag = True
562 firstTime_flag = True
563
563
564 self.set += 1
564 self.set += 1
565
565
566 if self.set > 999:
566 if self.set > 999:
567 self.set = 0
567 self.set = 0
568 self.foldercounter += 1
568 self.foldercounter += 1
569
569
570 #busca el 1er file disponible
570 #busca el 1er file disponible
571 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
571 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
572 if fullfilename:
572 if fullfilename:
573 if self.__verifyFile(fullfilename, False):
573 if self.__verifyFile(fullfilename, False):
574 fileOk_flag = True
574 fileOk_flag = True
575
575
576 #si no encuentra un file entonces espera y vuelve a buscar
576 #si no encuentra un file entonces espera y vuelve a buscar
577 if not(fileOk_flag):
577 if not(fileOk_flag):
578 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
578 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
579
579
580 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
580 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
581 tries = self.nTries
581 tries = self.nTries
582 else:
582 else:
583 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
583 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
584
584
585 for nTries in range( tries ):
585 for nTries in range( tries ):
586 if firstTime_flag:
586 if firstTime_flag:
587 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
587 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
588 time.sleep( self.delay )
588 time.sleep( self.delay )
589 else:
589 else:
590 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
590 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
591
591
592 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
592 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
593 if fullfilename:
593 if fullfilename:
594 if self.__verifyFile(fullfilename):
594 if self.__verifyFile(fullfilename):
595 fileOk_flag = True
595 fileOk_flag = True
596 break
596 break
597
597
598 if fileOk_flag:
598 if fileOk_flag:
599 break
599 break
600
600
601 firstTime_flag = False
601 firstTime_flag = False
602
602
603 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
603 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
604 self.set += 1
604 self.set += 1
605
605
606 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
606 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
607 self.set = 0
607 self.set = 0
608 self.doy += 1
608 self.doy += 1
609 self.foldercounter = 0
609 self.foldercounter = 0
610
610
611 if fileOk_flag:
611 if fileOk_flag:
612 self.fileSize = os.path.getsize( fullfilename )
612 self.fileSize = os.path.getsize( fullfilename )
613 self.filename = fullfilename
613 self.filename = fullfilename
614 self.flagIsNewFile = 1
614 self.flagIsNewFile = 1
615 if self.fp != None: self.fp.close()
615 if self.fp != None: self.fp.close()
616 self.fp = open(fullfilename, 'rb')
616 self.fp = open(fullfilename, 'rb')
617 self.flagNoMoreFiles = 0
617 self.flagNoMoreFiles = 0
618 print 'Setting the file: %s' % fullfilename
618 print 'Setting the file: %s' % fullfilename
619 else:
619 else:
620 self.fileSize = 0
620 self.fileSize = 0
621 self.filename = None
621 self.filename = None
622 self.flagIsNewFile = 0
622 self.flagIsNewFile = 0
623 self.fp = None
623 self.fp = None
624 self.flagNoMoreFiles = 1
624 self.flagNoMoreFiles = 1
625 print 'No more Files'
625 print 'No more Files'
626
626
627 return fileOk_flag
627 return fileOk_flag
628
628
629
629
630 def setNextFile(self):
630 def setNextFile(self):
631 if self.fp != None:
631 if self.fp != None:
632 self.fp.close()
632 self.fp.close()
633
633
634 if self.online:
634 if self.online:
635 newFile = self.__setNextFileOnline()
635 newFile = self.__setNextFileOnline()
636 else:
636 else:
637 newFile = self.__setNextFileOffline()
637 newFile = self.__setNextFileOffline()
638
638
639 if not(newFile):
639 if not(newFile):
640 return 0
640 return 0
641
641
642 self.__readFirstHeader()
642 self.__readFirstHeader()
643 self.nReadBlocks = 0
643 self.nReadBlocks = 0
644 return 1
644 return 1
645
645
646 def __waitNewBlock(self):
646 def __waitNewBlock(self):
647 """
647 """
648 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
648 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
649
649
650 Si el modo de lectura es OffLine siempre retorn 0
650 Si el modo de lectura es OffLine siempre retorn 0
651 """
651 """
652 if not self.online:
652 if not self.online:
653 return 0
653 return 0
654
654
655 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
655 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
656 return 0
656 return 0
657
657
658 currentPointer = self.fp.tell()
658 currentPointer = self.fp.tell()
659
659
660 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
660 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
661
661
662 for nTries in range( self.nTries ):
662 for nTries in range( self.nTries ):
663
663
664 self.fp.close()
664 self.fp.close()
665 self.fp = open( self.filename, 'rb' )
665 self.fp = open( self.filename, 'rb' )
666 self.fp.seek( currentPointer )
666 self.fp.seek( currentPointer )
667
667
668 self.fileSize = os.path.getsize( self.filename )
668 self.fileSize = os.path.getsize( self.filename )
669 currentSize = self.fileSize - currentPointer
669 currentSize = self.fileSize - currentPointer
670
670
671 if ( currentSize >= neededSize ):
671 if ( currentSize >= neededSize ):
672 self.__rdBasicHeader()
672 self.__rdBasicHeader()
673 return 1
673 return 1
674
674
675 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
675 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
676 time.sleep( self.delay )
676 time.sleep( self.delay )
677
677
678
678
679 return 0
679 return 0
680
680
681 def __jumpToLastBlock(self):
681 def __jumpToLastBlock(self):
682
682
683 if not(self.__isFirstTimeOnline):
683 if not(self.__isFirstTimeOnline):
684 return
684 return
685
685
686 csize = self.fileSize - self.fp.tell()
686 csize = self.fileSize - self.fp.tell()
687
687
688 #sata el primer bloque de datos
688 #sata el primer bloque de datos
689 if csize > self.processingHeaderObj.blockSize:
689 if csize > self.processingHeaderObj.blockSize:
690 self.fp.seek(self.fp.tell() + self.processingHeaderObj.blockSize)
690 self.fp.seek(self.fp.tell() + self.processingHeaderObj.blockSize)
691 else:
691 else:
692 return
692 return
693
693
694 csize = self.fileSize - self.fp.tell()
694 csize = self.fileSize - self.fp.tell()
695 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
695 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
696 factor = int(csize/neededsize)
696 factor = int(csize/neededsize)
697 if factor > 0:
697 if factor > 0:
698 self.fp.seek(self.fp.tell() + factor*neededsize)
698 self.fp.seek(self.fp.tell() + factor*neededsize)
699
699
700 self.flagIsNewFile = 0
700 self.flagIsNewFile = 0
701 self.__isFirstTimeOnline = 0
701 self.__isFirstTimeOnline = 0
702
702
703
703
704 def __setNewBlock(self):
704 def __setNewBlock(self):
705
705
706 if self.fp == None:
706 if self.fp == None:
707 return 0
707 return 0
708
708
709 if self.online:
709 if self.online:
710 self.__jumpToLastBlock()
710 self.__jumpToLastBlock()
711
711
712 if self.flagIsNewFile:
712 if self.flagIsNewFile:
713 return 1
713 return 1
714
714
715 self.lastUTTime = self.basicHeaderObj.utc
715 self.lastUTTime = self.basicHeaderObj.utc
716 currentSize = self.fileSize - self.fp.tell()
716 currentSize = self.fileSize - self.fp.tell()
717 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
717 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
718
718
719 if (currentSize >= neededSize):
719 if (currentSize >= neededSize):
720 self.__rdBasicHeader()
720 self.__rdBasicHeader()
721 return 1
721 return 1
722
722
723 if self.__waitNewBlock():
723 if self.__waitNewBlock():
724 return 1
724 return 1
725
725
726 if not(self.setNextFile()):
726 if not(self.setNextFile()):
727 return 0
727 return 0
728
728
729 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
729 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
730
730
731 self.flagTimeBlock = 0
731 self.flagTimeBlock = 0
732
732
733 if deltaTime > self.maxTimeStep:
733 if deltaTime > self.maxTimeStep:
734 self.flagTimeBlock = 1
734 self.flagTimeBlock = 1
735
735
736 return 1
736 return 1
737
737
738
738
739 def readNextBlock(self):
739 def readNextBlock(self):
740 if not(self.__setNewBlock()):
740 if not(self.__setNewBlock()):
741 return 0
741 return 0
742
742
743 if not(self.readBlock()):
743 if not(self.readBlock()):
744 return 0
744 return 0
745
745
746 return 1
746 return 1
747
747
748 def __rdProcessingHeader(self, fp=None):
748 def __rdProcessingHeader(self, fp=None):
749 if fp == None:
749 if fp == None:
750 fp = self.fp
750 fp = self.fp
751
751
752 self.processingHeaderObj.read(fp)
752 self.processingHeaderObj.read(fp)
753
753
754 def __rdRadarControllerHeader(self, fp=None):
754 def __rdRadarControllerHeader(self, fp=None):
755 if fp == None:
755 if fp == None:
756 fp = self.fp
756 fp = self.fp
757
757
758 self.radarControllerHeaderObj.read(fp)
758 self.radarControllerHeaderObj.read(fp)
759
759
760 def __rdSystemHeader(self, fp=None):
760 def __rdSystemHeader(self, fp=None):
761 if fp == None:
761 if fp == None:
762 fp = self.fp
762 fp = self.fp
763
763
764 self.systemHeaderObj.read(fp)
764 self.systemHeaderObj.read(fp)
765
765
766 def __rdBasicHeader(self, fp=None):
766 def __rdBasicHeader(self, fp=None):
767 if fp == None:
767 if fp == None:
768 fp = self.fp
768 fp = self.fp
769
769
770 self.basicHeaderObj.read(fp)
770 self.basicHeaderObj.read(fp)
771
771
772
772
773 def __readFirstHeader(self):
773 def __readFirstHeader(self):
774 self.__rdBasicHeader()
774 self.__rdBasicHeader()
775 self.__rdSystemHeader()
775 self.__rdSystemHeader()
776 self.__rdRadarControllerHeader()
776 self.__rdRadarControllerHeader()
777 self.__rdProcessingHeader()
777 self.__rdProcessingHeader()
778
778
779 self.firstHeaderSize = self.basicHeaderObj.size
779 self.firstHeaderSize = self.basicHeaderObj.size
780
780
781 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
781 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
782 if datatype == 0:
782 if datatype == 0:
783 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
783 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
784 elif datatype == 1:
784 elif datatype == 1:
785 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
785 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
786 elif datatype == 2:
786 elif datatype == 2:
787 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
787 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
788 elif datatype == 3:
788 elif datatype == 3:
789 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
789 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
790 elif datatype == 4:
790 elif datatype == 4:
791 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
791 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
792 elif datatype == 5:
792 elif datatype == 5:
793 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
793 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
794 else:
794 else:
795 raise ValueError, 'Data type was not defined'
795 raise ValueError, 'Data type was not defined'
796
796
797 self.dtype = datatype_str
797 self.dtype = datatype_str
798 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
798 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
799 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
799 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
800 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
800 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
801 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
801 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
802 self.getBlockDimension()
802 self.getBlockDimension()
803
803
804
804
805 def __verifyFile(self, filename, msgFlag=True):
805 def __verifyFile(self, filename, msgFlag=True):
806 msg = None
806 msg = None
807 try:
807 try:
808 fp = open(filename, 'rb')
808 fp = open(filename, 'rb')
809 currentPosition = fp.tell()
809 currentPosition = fp.tell()
810 except:
810 except:
811 if msgFlag:
811 if msgFlag:
812 print "The file %s can't be opened" % (filename)
812 print "The file %s can't be opened" % (filename)
813 return False
813 return False
814
814
815 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
815 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
816
816
817 if neededSize == 0:
817 if neededSize == 0:
818 basicHeaderObj = BasicHeader(LOCALTIME)
818 basicHeaderObj = BasicHeader(LOCALTIME)
819 systemHeaderObj = SystemHeader()
819 systemHeaderObj = SystemHeader()
820 radarControllerHeaderObj = RadarControllerHeader()
820 radarControllerHeaderObj = RadarControllerHeader()
821 processingHeaderObj = ProcessingHeader()
821 processingHeaderObj = ProcessingHeader()
822
822
823 try:
823 try:
824 if not( basicHeaderObj.read(fp) ): raise IOError
824 if not( basicHeaderObj.read(fp) ): raise IOError
825 if not( systemHeaderObj.read(fp) ): raise IOError
825 if not( systemHeaderObj.read(fp) ): raise IOError
826 if not( radarControllerHeaderObj.read(fp) ): raise IOError
826 if not( radarControllerHeaderObj.read(fp) ): raise IOError
827 if not( processingHeaderObj.read(fp) ): raise IOError
827 if not( processingHeaderObj.read(fp) ): raise IOError
828 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
828 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
829
829
830 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
830 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
831
831
832 except:
832 except:
833 if msgFlag:
833 if msgFlag:
834 print "\tThe file %s is empty or it hasn't enough data" % filename
834 print "\tThe file %s is empty or it hasn't enough data" % filename
835
835
836 fp.close()
836 fp.close()
837 return False
837 return False
838 else:
838 else:
839 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
839 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
840
840
841 fp.close()
841 fp.close()
842 fileSize = os.path.getsize(filename)
842 fileSize = os.path.getsize(filename)
843 currentSize = fileSize - currentPosition
843 currentSize = fileSize - currentPosition
844 if currentSize < neededSize:
844 if currentSize < neededSize:
845 if msgFlag and (msg != None):
845 if msgFlag and (msg != None):
846 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
846 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
847 return False
847 return False
848
848
849 return True
849 return True
850
850
851 def setup(self,
851 def setup(self,
852 path=None,
852 path=None,
853 startDate=None,
853 startDate=None,
854 endDate=None,
854 endDate=None,
855 startTime=datetime.time(0,0,0),
855 startTime=datetime.time(0,0,0),
856 endTime=datetime.time(23,59,59),
856 endTime=datetime.time(23,59,59),
857 set=0,
857 set=0,
858 expLabel = "",
858 expLabel = "",
859 ext = None,
859 ext = None,
860 online = False,
860 online = False,
861 delay = 60,
861 delay = 60,
862 walk = True):
862 walk = True):
863
863
864 if path == None:
864 if path == None:
865 raise ValueError, "The path is not valid"
865 raise ValueError, "The path is not valid"
866
866
867 if ext == None:
867 if ext == None:
868 ext = self.ext
868 ext = self.ext
869
869
870 if online:
870 if online:
871 print "Searching files in online mode..."
871 print "Searching files in online mode..."
872
872
873 for nTries in range( self.nTries ):
873 for nTries in range( self.nTries ):
874 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
874 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk)
875
875
876 if fullpath:
876 if fullpath:
877 break
877 break
878
878
879 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
879 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
880 time.sleep( self.delay )
880 time.sleep( self.delay )
881
881
882 if not(fullpath):
882 if not(fullpath):
883 print "There 'isn't valied files in %s" % path
883 print "There 'isn't valied files in %s" % path
884 return None
884 return None
885
885
886 self.year = year
886 self.year = year
887 self.doy = doy
887 self.doy = doy
888 self.set = set - 1
888 self.set = set - 1
889 self.path = path
889 self.path = path
890 self.foldercounter = foldercounter
890 self.foldercounter = foldercounter
891
891
892 else:
892 else:
893 print "Searching files in offline mode ..."
893 print "Searching files in offline mode ..."
894 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
894 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
895 startTime=startTime, endTime=endTime,
895 startTime=startTime, endTime=endTime,
896 set=set, expLabel=expLabel, ext=ext,
896 set=set, expLabel=expLabel, ext=ext,
897 walk=walk)
897 walk=walk)
898
898
899 if not(pathList):
899 if not(pathList):
900 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
900 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
901 datetime.datetime.combine(startDate,startTime).ctime(),
901 datetime.datetime.combine(startDate,startTime).ctime(),
902 datetime.datetime.combine(endDate,endTime).ctime())
902 datetime.datetime.combine(endDate,endTime).ctime())
903
903
904 sys.exit(-1)
904 sys.exit(-1)
905
905
906
906
907 self.fileIndex = -1
907 self.fileIndex = -1
908 self.pathList = pathList
908 self.pathList = pathList
909 self.filenameList = filenameList
909 self.filenameList = filenameList
910
910
911 self.online = online
911 self.online = online
912 self.delay = delay
912 self.delay = delay
913 ext = ext.lower()
913 ext = ext.lower()
914 self.ext = ext
914 self.ext = ext
915
915
916 if not(self.setNextFile()):
916 if not(self.setNextFile()):
917 if (startDate!=None) and (endDate!=None):
917 if (startDate!=None) and (endDate!=None):
918 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
918 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
919 elif startDate != None:
919 elif startDate != None:
920 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
920 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
921 else:
921 else:
922 print "No files"
922 print "No files"
923
923
924 sys.exit(-1)
924 sys.exit(-1)
925
925
926 # self.updateDataHeader()
926 # self.updateDataHeader()
927
927
928 return self.dataOut
928 return self.dataOut
929
929
930 def getBasicHeader(self):
930 def getBasicHeader(self):
931
931
932 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
932 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
933
933
934 self.dataOut.flagTimeBlock = self.flagTimeBlock
934 self.dataOut.flagTimeBlock = self.flagTimeBlock
935
935
936 self.dataOut.timeZone = self.basicHeaderObj.timeZone
936 self.dataOut.timeZone = self.basicHeaderObj.timeZone
937
937
938 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
938 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
939
939
940 self.dataOut.errorCount = self.basicHeaderObj.errorCount
940 self.dataOut.errorCount = self.basicHeaderObj.errorCount
941
941
942 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
942 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
943
943
944 def getFirstHeader(self):
944 def getFirstHeader(self):
945
945
946 raise ValueError, "This method has not been implemented"
946 raise ValueError, "This method has not been implemented"
947
947
948 def getData():
948 def getData():
949
949
950 raise ValueError, "This method has not been implemented"
950 raise ValueError, "This method has not been implemented"
951
951
952 def hasNotDataInBuffer():
952 def hasNotDataInBuffer():
953
953
954 raise ValueError, "This method has not been implemented"
954 raise ValueError, "This method has not been implemented"
955
955
956 def readBlock():
956 def readBlock():
957
957
958 raise ValueError, "This method has not been implemented"
958 raise ValueError, "This method has not been implemented"
959
959
960 def isEndProcess(self):
960 def isEndProcess(self):
961
961
962 return self.flagNoMoreFiles
962 return self.flagNoMoreFiles
963
963
964 def printReadBlocks(self):
964 def printReadBlocks(self):
965
965
966 print "Number of read blocks per file %04d" %self.nReadBlocks
966 print "Number of read blocks per file %04d" %self.nReadBlocks
967
967
968 def printTotalBlocks(self):
968 def printTotalBlocks(self):
969
969
970 print "Number of read blocks %04d" %self.nTotalBlocks
970 print "Number of read blocks %04d" %self.nTotalBlocks
971
971
972 def printNumberOfBlock(self):
972 def printNumberOfBlock(self):
973
973
974 if self.flagIsNewBlock:
974 if self.flagIsNewBlock:
975 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
975 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
976
976
977 def printInfo(self):
977 def printInfo(self):
978
978
979 if self.__printInfo == False:
979 if self.__printInfo == False:
980 return
980 return
981
981
982 self.basicHeaderObj.printInfo()
982 self.basicHeaderObj.printInfo()
983 self.systemHeaderObj.printInfo()
983 self.systemHeaderObj.printInfo()
984 self.radarControllerHeaderObj.printInfo()
984 self.radarControllerHeaderObj.printInfo()
985 self.processingHeaderObj.printInfo()
985 self.processingHeaderObj.printInfo()
986
986
987 self.__printInfo = False
987 self.__printInfo = False
988
988
989
989
990 def run(self, **kwargs):
990 def run(self, **kwargs):
991
991
992 if not(self.isConfig):
992 if not(self.isConfig):
993
993
994 # self.dataOut = dataOut
994 # self.dataOut = dataOut
995 self.setup(**kwargs)
995 self.setup(**kwargs)
996 self.isConfig = True
996 self.isConfig = True
997
997
998 self.getData()
998 self.getData()
999
999
1000 class JRODataWriter(JRODataIO, Operation):
1000 class JRODataWriter(JRODataIO, Operation):
1001
1001
1002 """
1002 """
1003 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1003 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1004 de los datos siempre se realiza por bloques.
1004 de los datos siempre se realiza por bloques.
1005 """
1005 """
1006
1006
1007 blockIndex = 0
1007 blockIndex = 0
1008
1008
1009 path = None
1009 path = None
1010
1010
1011 setFile = None
1011 setFile = None
1012
1012
1013 profilesPerBlock = None
1013 profilesPerBlock = None
1014
1014
1015 blocksPerFile = None
1015 blocksPerFile = None
1016
1016
1017 nWriteBlocks = 0
1017 nWriteBlocks = 0
1018
1018
1019 def __init__(self, dataOut=None):
1019 def __init__(self, dataOut=None):
1020 raise ValueError, "Not implemented"
1020 raise ValueError, "Not implemented"
1021
1021
1022
1022
1023 def hasAllDataInBuffer(self):
1023 def hasAllDataInBuffer(self):
1024 raise ValueError, "Not implemented"
1024 raise ValueError, "Not implemented"
1025
1025
1026
1026
1027 def setBlockDimension(self):
1027 def setBlockDimension(self):
1028 raise ValueError, "Not implemented"
1028 raise ValueError, "Not implemented"
1029
1029
1030
1030
1031 def writeBlock(self):
1031 def writeBlock(self):
1032 raise ValueError, "No implemented"
1032 raise ValueError, "No implemented"
1033
1033
1034
1034
1035 def putData(self):
1035 def putData(self):
1036 raise ValueError, "No implemented"
1036 raise ValueError, "No implemented"
1037
1037
1038
1038
1039 def setBasicHeader(self):
1039 def setBasicHeader(self):
1040
1040
1041 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1041 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1042 self.basicHeaderObj.version = self.versionFile
1042 self.basicHeaderObj.version = self.versionFile
1043 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1043 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1044
1044
1045 utc = numpy.floor(self.dataOut.utctime)
1045 utc = numpy.floor(self.dataOut.utctime)
1046 milisecond = (self.dataOut.utctime - utc)* 1000.0
1046 milisecond = (self.dataOut.utctime - utc)* 1000.0
1047
1047
1048 self.basicHeaderObj.utc = utc
1048 self.basicHeaderObj.utc = utc
1049 self.basicHeaderObj.miliSecond = milisecond
1049 self.basicHeaderObj.miliSecond = milisecond
1050 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1050 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1051 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1051 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1052 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1052 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1053
1053
1054 def setFirstHeader(self):
1054 def setFirstHeader(self):
1055 """
1055 """
1056 Obtiene una copia del First Header
1056 Obtiene una copia del First Header
1057
1057
1058 Affected:
1058 Affected:
1059
1059
1060 self.basicHeaderObj
1060 self.basicHeaderObj
1061 self.systemHeaderObj
1061 self.systemHeaderObj
1062 self.radarControllerHeaderObj
1062 self.radarControllerHeaderObj
1063 self.processingHeaderObj self.
1063 self.processingHeaderObj self.
1064
1064
1065 Return:
1065 Return:
1066 None
1066 None
1067 """
1067 """
1068
1068
1069 raise ValueError, "No implemented"
1069 raise ValueError, "No implemented"
1070
1070
1071 def __writeFirstHeader(self):
1071 def __writeFirstHeader(self):
1072 """
1072 """
1073 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1073 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1074
1074
1075 Affected:
1075 Affected:
1076 __dataType
1076 __dataType
1077
1077
1078 Return:
1078 Return:
1079 None
1079 None
1080 """
1080 """
1081
1081
1082 # CALCULAR PARAMETROS
1082 # CALCULAR PARAMETROS
1083
1083
1084 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1084 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1085 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1085 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1086
1086
1087 self.basicHeaderObj.write(self.fp)
1087 self.basicHeaderObj.write(self.fp)
1088 self.systemHeaderObj.write(self.fp)
1088 self.systemHeaderObj.write(self.fp)
1089 self.radarControllerHeaderObj.write(self.fp)
1089 self.radarControllerHeaderObj.write(self.fp)
1090 self.processingHeaderObj.write(self.fp)
1090 self.processingHeaderObj.write(self.fp)
1091
1091
1092 self.dtype = self.dataOut.dtype
1092 self.dtype = self.dataOut.dtype
1093
1093
1094 def __setNewBlock(self):
1094 def __setNewBlock(self):
1095 """
1095 """
1096 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1096 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1097
1097
1098 Return:
1098 Return:
1099 0 : si no pudo escribir nada
1099 0 : si no pudo escribir nada
1100 1 : Si escribio el Basic el First Header
1100 1 : Si escribio el Basic el First Header
1101 """
1101 """
1102 if self.fp == None:
1102 if self.fp == None:
1103 self.setNextFile()
1103 self.setNextFile()
1104
1104
1105 if self.flagIsNewFile:
1105 if self.flagIsNewFile:
1106 return 1
1106 return 1
1107
1107
1108 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1108 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1109 self.basicHeaderObj.write(self.fp)
1109 self.basicHeaderObj.write(self.fp)
1110 return 1
1110 return 1
1111
1111
1112 if not( self.setNextFile() ):
1112 if not( self.setNextFile() ):
1113 return 0
1113 return 0
1114
1114
1115 return 1
1115 return 1
1116
1116
1117
1117
1118 def writeNextBlock(self):
1118 def writeNextBlock(self):
1119 """
1119 """
1120 Selecciona el bloque siguiente de datos y los escribe en un file
1120 Selecciona el bloque siguiente de datos y los escribe en un file
1121
1121
1122 Return:
1122 Return:
1123 0 : Si no hizo pudo escribir el bloque de datos
1123 0 : Si no hizo pudo escribir el bloque de datos
1124 1 : Si no pudo escribir el bloque de datos
1124 1 : Si no pudo escribir el bloque de datos
1125 """
1125 """
1126 if not( self.__setNewBlock() ):
1126 if not( self.__setNewBlock() ):
1127 return 0
1127 return 0
1128
1128
1129 self.writeBlock()
1129 self.writeBlock()
1130
1130
1131 return 1
1131 return 1
1132
1132
1133 def setNextFile(self):
1133 def setNextFile(self):
1134 """
1134 """
1135 Determina el siguiente file que sera escrito
1135 Determina el siguiente file que sera escrito
1136
1136
1137 Affected:
1137 Affected:
1138 self.filename
1138 self.filename
1139 self.subfolder
1139 self.subfolder
1140 self.fp
1140 self.fp
1141 self.setFile
1141 self.setFile
1142 self.flagIsNewFile
1142 self.flagIsNewFile
1143
1143
1144 Return:
1144 Return:
1145 0 : Si el archivo no puede ser escrito
1145 0 : Si el archivo no puede ser escrito
1146 1 : Si el archivo esta listo para ser escrito
1146 1 : Si el archivo esta listo para ser escrito
1147 """
1147 """
1148 ext = self.ext
1148 ext = self.ext
1149 path = self.path
1149 path = self.path
1150
1150
1151 if self.fp != None:
1151 if self.fp != None:
1152 self.fp.close()
1152 self.fp.close()
1153
1153
1154 timeTuple = time.localtime( self.dataOut.utctime)
1154 timeTuple = time.localtime( self.dataOut.utctime)
1155 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1155 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1156
1156
1157 fullpath = os.path.join( path, subfolder )
1157 fullpath = os.path.join( path, subfolder )
1158 if not( os.path.exists(fullpath) ):
1158 if not( os.path.exists(fullpath) ):
1159 os.mkdir(fullpath)
1159 os.mkdir(fullpath)
1160 self.setFile = -1 #inicializo mi contador de seteo
1160 self.setFile = -1 #inicializo mi contador de seteo
1161 else:
1161 else:
1162 filesList = os.listdir( fullpath )
1162 filesList = os.listdir( fullpath )
1163 if len( filesList ) > 0:
1163 if len( filesList ) > 0:
1164 filesList = sorted( filesList, key=str.lower )
1164 filesList = sorted( filesList, key=str.lower )
1165 filen = filesList[-1]
1165 filen = filesList[-1]
1166 # el filename debera tener el siguiente formato
1166 # el filename debera tener el siguiente formato
1167 # 0 1234 567 89A BCDE (hex)
1167 # 0 1234 567 89A BCDE (hex)
1168 # x YYYY DDD SSS .ext
1168 # x YYYY DDD SSS .ext
1169 if isNumber( filen[8:11] ):
1169 if isNumber( filen[8:11] ):
1170 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1170 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1171 else:
1171 else:
1172 self.setFile = -1
1172 self.setFile = -1
1173 else:
1173 else:
1174 self.setFile = -1 #inicializo mi contador de seteo
1174 self.setFile = -1 #inicializo mi contador de seteo
1175
1175
1176 setFile = self.setFile
1176 setFile = self.setFile
1177 setFile += 1
1177 setFile += 1
1178
1178
1179 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1179 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1180 timeTuple.tm_year,
1180 timeTuple.tm_year,
1181 timeTuple.tm_yday,
1181 timeTuple.tm_yday,
1182 setFile,
1182 setFile,
1183 ext )
1183 ext )
1184
1184
1185 filename = os.path.join( path, subfolder, file )
1185 filename = os.path.join( path, subfolder, file )
1186
1186
1187 fp = open( filename,'wb' )
1187 fp = open( filename,'wb' )
1188
1188
1189 self.blockIndex = 0
1189 self.blockIndex = 0
1190
1190
1191 #guardando atributos
1191 #guardando atributos
1192 self.filename = filename
1192 self.filename = filename
1193 self.subfolder = subfolder
1193 self.subfolder = subfolder
1194 self.fp = fp
1194 self.fp = fp
1195 self.setFile = setFile
1195 self.setFile = setFile
1196 self.flagIsNewFile = 1
1196 self.flagIsNewFile = 1
1197
1197
1198 self.setFirstHeader()
1198 self.setFirstHeader()
1199
1199
1200 print 'Writing the file: %s'%self.filename
1200 print 'Writing the file: %s'%self.filename
1201
1201
1202 self.__writeFirstHeader()
1202 self.__writeFirstHeader()
1203
1203
1204 return 1
1204 return 1
1205
1205
1206 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1206 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
1207 """
1207 """
1208 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1208 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1209
1209
1210 Inputs:
1210 Inputs:
1211 path : el path destino en el cual se escribiran los files a crear
1211 path : el path destino en el cual se escribiran los files a crear
1212 format : formato en el cual sera salvado un file
1212 format : formato en el cual sera salvado un file
1213 set : el setebo del file
1213 set : el setebo del file
1214
1214
1215 Return:
1215 Return:
1216 0 : Si no realizo un buen seteo
1216 0 : Si no realizo un buen seteo
1217 1 : Si realizo un buen seteo
1217 1 : Si realizo un buen seteo
1218 """
1218 """
1219
1219
1220 if ext == None:
1220 if ext == None:
1221 ext = self.ext
1221 ext = self.ext
1222
1222
1223 ext = ext.lower()
1223 ext = ext.lower()
1224
1224
1225 self.ext = ext
1225 self.ext = ext
1226
1226
1227 self.path = path
1227 self.path = path
1228
1228
1229 self.setFile = set - 1
1229 self.setFile = set - 1
1230
1230
1231 self.blocksPerFile = blocksPerFile
1231 self.blocksPerFile = blocksPerFile
1232
1232
1233 self.profilesPerBlock = profilesPerBlock
1233 self.profilesPerBlock = profilesPerBlock
1234
1234
1235 self.dataOut = dataOut
1235 self.dataOut = dataOut
1236
1236
1237 if not(self.setNextFile()):
1237 if not(self.setNextFile()):
1238 print "There isn't a next file"
1238 print "There isn't a next file"
1239 return 0
1239 return 0
1240
1240
1241 self.setBlockDimension()
1241 self.setBlockDimension()
1242
1242
1243 return 1
1243 return 1
1244
1244
1245 def run(self, dataOut, **kwargs):
1245 def run(self, dataOut, **kwargs):
1246
1246
1247 if not(self.isConfig):
1247 if not(self.isConfig):
1248
1248
1249 self.setup(dataOut, **kwargs)
1249 self.setup(dataOut, **kwargs)
1250 self.isConfig = True
1250 self.isConfig = True
1251
1251
1252 self.putData()
1252 self.putData()
1253
1253
1254 class VoltageReader(JRODataReader):
1254 class VoltageReader(JRODataReader):
1255 """
1255 """
1256 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1256 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
1257 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1257 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
1258 perfiles*alturas*canales) son almacenados en la variable "buffer".
1258 perfiles*alturas*canales) son almacenados en la variable "buffer".
1259
1259
1260 perfiles * alturas * canales
1260 perfiles * alturas * canales
1261
1261
1262 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1262 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1263 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1263 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
1264 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1264 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
1265 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1265 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1266
1266
1267 Example:
1267 Example:
1268
1268
1269 dpath = "/home/myuser/data"
1269 dpath = "/home/myuser/data"
1270
1270
1271 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1271 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1272
1272
1273 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1273 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1274
1274
1275 readerObj = VoltageReader()
1275 readerObj = VoltageReader()
1276
1276
1277 readerObj.setup(dpath, startTime, endTime)
1277 readerObj.setup(dpath, startTime, endTime)
1278
1278
1279 while(True):
1279 while(True):
1280
1280
1281 #to get one profile
1281 #to get one profile
1282 profile = readerObj.getData()
1282 profile = readerObj.getData()
1283
1283
1284 #print the profile
1284 #print the profile
1285 print profile
1285 print profile
1286
1286
1287 #If you want to see all datablock
1287 #If you want to see all datablock
1288 print readerObj.datablock
1288 print readerObj.datablock
1289
1289
1290 if readerObj.flagNoMoreFiles:
1290 if readerObj.flagNoMoreFiles:
1291 break
1291 break
1292
1292
1293 """
1293 """
1294
1294
1295 ext = ".r"
1295 ext = ".r"
1296
1296
1297 optchar = "D"
1297 optchar = "D"
1298 dataOut = None
1298 dataOut = None
1299
1299
1300
1300
1301 def __init__(self):
1301 def __init__(self):
1302 """
1302 """
1303 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1303 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
1304
1304
1305 Input:
1305 Input:
1306 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1306 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
1307 almacenar un perfil de datos cada vez que se haga un requerimiento
1307 almacenar un perfil de datos cada vez que se haga un requerimiento
1308 (getData). El perfil sera obtenido a partir del buffer de datos,
1308 (getData). El perfil sera obtenido a partir del buffer de datos,
1309 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1309 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1310 bloque de datos.
1310 bloque de datos.
1311 Si este parametro no es pasado se creara uno internamente.
1311 Si este parametro no es pasado se creara uno internamente.
1312
1312
1313 Variables afectadas:
1313 Variables afectadas:
1314 self.dataOut
1314 self.dataOut
1315
1315
1316 Return:
1316 Return:
1317 None
1317 None
1318 """
1318 """
1319
1319
1320 self.isConfig = False
1320 self.isConfig = False
1321
1321
1322 self.datablock = None
1322 self.datablock = None
1323
1323
1324 self.utc = 0
1324 self.utc = 0
1325
1325
1326 self.ext = ".r"
1326 self.ext = ".r"
1327
1327
1328 self.optchar = "D"
1328 self.optchar = "D"
1329
1329
1330 self.basicHeaderObj = BasicHeader(LOCALTIME)
1330 self.basicHeaderObj = BasicHeader(LOCALTIME)
1331
1331
1332 self.systemHeaderObj = SystemHeader()
1332 self.systemHeaderObj = SystemHeader()
1333
1333
1334 self.radarControllerHeaderObj = RadarControllerHeader()
1334 self.radarControllerHeaderObj = RadarControllerHeader()
1335
1335
1336 self.processingHeaderObj = ProcessingHeader()
1336 self.processingHeaderObj = ProcessingHeader()
1337
1337
1338 self.online = 0
1338 self.online = 0
1339
1339
1340 self.fp = None
1340 self.fp = None
1341
1341
1342 self.idFile = None
1342 self.idFile = None
1343
1343
1344 self.dtype = None
1344 self.dtype = None
1345
1345
1346 self.fileSizeByHeader = None
1346 self.fileSizeByHeader = None
1347
1347
1348 self.filenameList = []
1348 self.filenameList = []
1349
1349
1350 self.filename = None
1350 self.filename = None
1351
1351
1352 self.fileSize = None
1352 self.fileSize = None
1353
1353
1354 self.firstHeaderSize = 0
1354 self.firstHeaderSize = 0
1355
1355
1356 self.basicHeaderSize = 24
1356 self.basicHeaderSize = 24
1357
1357
1358 self.pathList = []
1358 self.pathList = []
1359
1359
1360 self.filenameList = []
1360 self.filenameList = []
1361
1361
1362 self.lastUTTime = 0
1362 self.lastUTTime = 0
1363
1363
1364 self.maxTimeStep = 30
1364 self.maxTimeStep = 30
1365
1365
1366 self.flagNoMoreFiles = 0
1366 self.flagNoMoreFiles = 0
1367
1367
1368 self.set = 0
1368 self.set = 0
1369
1369
1370 self.path = None
1370 self.path = None
1371
1371
1372 self.profileIndex = 2**32-1
1372 self.profileIndex = 2**32-1
1373
1373
1374 self.delay = 3 #seconds
1374 self.delay = 3 #seconds
1375
1375
1376 self.nTries = 3 #quantity tries
1376 self.nTries = 3 #quantity tries
1377
1377
1378 self.nFiles = 3 #number of files for searching
1378 self.nFiles = 3 #number of files for searching
1379
1379
1380 self.nReadBlocks = 0
1380 self.nReadBlocks = 0
1381
1381
1382 self.flagIsNewFile = 1
1382 self.flagIsNewFile = 1
1383
1383
1384 self.__isFirstTimeOnline = 1
1384 self.__isFirstTimeOnline = 1
1385
1385
1386 self.ippSeconds = 0
1386 self.ippSeconds = 0
1387
1387
1388 self.flagTimeBlock = 0
1388 self.flagTimeBlock = 0
1389
1389
1390 self.flagIsNewBlock = 0
1390 self.flagIsNewBlock = 0
1391
1391
1392 self.nTotalBlocks = 0
1392 self.nTotalBlocks = 0
1393
1393
1394 self.blocksize = 0
1394 self.blocksize = 0
1395
1395
1396 self.dataOut = self.createObjByDefault()
1396 self.dataOut = self.createObjByDefault()
1397
1397
1398 def createObjByDefault(self):
1398 def createObjByDefault(self):
1399
1399
1400 dataObj = Voltage()
1400 dataObj = Voltage()
1401
1401
1402 return dataObj
1402 return dataObj
1403
1403
1404 def __hasNotDataInBuffer(self):
1404 def __hasNotDataInBuffer(self):
1405 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1405 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1406 return 1
1406 return 1
1407 return 0
1407 return 0
1408
1408
1409
1409
1410 def getBlockDimension(self):
1410 def getBlockDimension(self):
1411 """
1411 """
1412 Obtiene la cantidad de puntos a leer por cada bloque de datos
1412 Obtiene la cantidad de puntos a leer por cada bloque de datos
1413
1413
1414 Affected:
1414 Affected:
1415 self.blocksize
1415 self.blocksize
1416
1416
1417 Return:
1417 Return:
1418 None
1418 None
1419 """
1419 """
1420 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1420 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
1421 self.blocksize = pts2read
1421 self.blocksize = pts2read
1422
1422
1423
1423
1424 def readBlock(self):
1424 def readBlock(self):
1425 """
1425 """
1426 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1426 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
1427 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1427 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
1428 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1428 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
1429 es seteado a 0
1429 es seteado a 0
1430
1430
1431 Inputs:
1431 Inputs:
1432 None
1432 None
1433
1433
1434 Return:
1434 Return:
1435 None
1435 None
1436
1436
1437 Affected:
1437 Affected:
1438 self.profileIndex
1438 self.profileIndex
1439 self.datablock
1439 self.datablock
1440 self.flagIsNewFile
1440 self.flagIsNewFile
1441 self.flagIsNewBlock
1441 self.flagIsNewBlock
1442 self.nTotalBlocks
1442 self.nTotalBlocks
1443
1443
1444 Exceptions:
1444 Exceptions:
1445 Si un bloque leido no es un bloque valido
1445 Si un bloque leido no es un bloque valido
1446 """
1446 """
1447
1447
1448 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1448 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
1449
1449
1450 try:
1450 try:
1451 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1451 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
1452 except:
1452 except:
1453 print "The read block (%3d) has not enough data" %self.nReadBlocks
1453 print "The read block (%3d) has not enough data" %self.nReadBlocks
1454 return 0
1454 return 0
1455
1455
1456 junk = numpy.transpose(junk, (2,0,1))
1456 junk = numpy.transpose(junk, (2,0,1))
1457 self.datablock = junk['real'] + junk['imag']*1j
1457 self.datablock = junk['real'] + junk['imag']*1j
1458
1458
1459 self.profileIndex = 0
1459 self.profileIndex = 0
1460
1460
1461 self.flagIsNewFile = 0
1461 self.flagIsNewFile = 0
1462 self.flagIsNewBlock = 1
1462 self.flagIsNewBlock = 1
1463
1463
1464 self.nTotalBlocks += 1
1464 self.nTotalBlocks += 1
1465 self.nReadBlocks += 1
1465 self.nReadBlocks += 1
1466
1466
1467 return 1
1467 return 1
1468
1468
1469 def getFirstHeader(self):
1469 def getFirstHeader(self):
1470
1470
1471 self.dataOut.dtype = self.dtype
1471 self.dataOut.dtype = self.dtype
1472
1472
1473 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1473 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
1474
1474
1475 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1475 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
1476
1476
1477 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1477 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
1478
1478
1479 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1479 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
1480
1480
1481 self.dataOut.ippSeconds = self.ippSeconds
1481 self.dataOut.ippSeconds = self.ippSeconds
1482
1482
1483 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1483 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt
1484
1484
1485 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1485 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
1486
1486
1487 self.dataOut.flagShiftFFT = False
1487 self.dataOut.flagShiftFFT = False
1488
1488
1489 if self.radarControllerHeaderObj.code != None:
1489 if self.radarControllerHeaderObj.code != None:
1490
1490
1491 self.dataOut.nCode = self.radarControllerHeaderObj.nCode
1491 self.dataOut.nCode = self.radarControllerHeaderObj.nCode
1492
1492
1493 self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
1493 self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
1494
1494
1495 self.dataOut.code = self.radarControllerHeaderObj.code
1495 self.dataOut.code = self.radarControllerHeaderObj.code
1496
1496
1497 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1497 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
1498
1498
1499 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1499 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
1500
1500
1501 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1501 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
1502
1502
1503 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1503 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
1504
1504
1505 self.dataOut.flagShiftFFT = False
1505 self.dataOut.flagShiftFFT = False
1506
1506
1507 def getData(self):
1507 def getData(self):
1508 """
1508 """
1509 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1509 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
1510 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1510 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
1511 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1511 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
1512
1512
1513 Ademas incrementa el contador del buffer en 1.
1513 Ademas incrementa el contador del buffer en 1.
1514
1514
1515 Return:
1515 Return:
1516 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1516 data : retorna un perfil de voltages (alturas * canales) copiados desde el
1517 buffer. Si no hay mas archivos a leer retorna None.
1517 buffer. Si no hay mas archivos a leer retorna None.
1518
1518
1519 Variables afectadas:
1519 Variables afectadas:
1520 self.dataOut
1520 self.dataOut
1521 self.profileIndex
1521 self.profileIndex
1522
1522
1523 Affected:
1523 Affected:
1524 self.dataOut
1524 self.dataOut
1525 self.profileIndex
1525 self.profileIndex
1526 self.flagTimeBlock
1526 self.flagTimeBlock
1527 self.flagIsNewBlock
1527 self.flagIsNewBlock
1528 """
1528 """
1529
1529
1530 if self.flagNoMoreFiles:
1530 if self.flagNoMoreFiles:
1531 self.dataOut.flagNoData = True
1531 self.dataOut.flagNoData = True
1532 print 'Process finished'
1532 print 'Process finished'
1533 return 0
1533 return 0
1534
1534
1535 self.flagTimeBlock = 0
1535 self.flagTimeBlock = 0
1536 self.flagIsNewBlock = 0
1536 self.flagIsNewBlock = 0
1537
1537
1538 if self.__hasNotDataInBuffer():
1538 if self.__hasNotDataInBuffer():
1539
1539
1540 if not( self.readNextBlock() ):
1540 if not( self.readNextBlock() ):
1541 return 0
1541 return 0
1542
1542
1543 self.getFirstHeader()
1543 self.getFirstHeader()
1544
1544
1545 if self.datablock == None:
1545 if self.datablock == None:
1546 self.dataOut.flagNoData = True
1546 self.dataOut.flagNoData = True
1547 return 0
1547 return 0
1548
1548
1549 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1549 self.dataOut.data = self.datablock[:,self.profileIndex,:]
1550
1550
1551 self.dataOut.flagNoData = False
1551 self.dataOut.flagNoData = False
1552
1552
1553 self.getBasicHeader()
1553 self.getBasicHeader()
1554
1554
1555 self.profileIndex += 1
1555 self.profileIndex += 1
1556
1556
1557 self.dataOut.realtime = self.online
1558
1557 return self.dataOut.data
1559 return self.dataOut.data
1558
1560
1559
1561
1560 class VoltageWriter(JRODataWriter):
1562 class VoltageWriter(JRODataWriter):
1561 """
1563 """
1562 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1564 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
1563 de los datos siempre se realiza por bloques.
1565 de los datos siempre se realiza por bloques.
1564 """
1566 """
1565
1567
1566 ext = ".r"
1568 ext = ".r"
1567
1569
1568 optchar = "D"
1570 optchar = "D"
1569
1571
1570 shapeBuffer = None
1572 shapeBuffer = None
1571
1573
1572
1574
1573 def __init__(self):
1575 def __init__(self):
1574 """
1576 """
1575 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1577 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
1576
1578
1577 Affected:
1579 Affected:
1578 self.dataOut
1580 self.dataOut
1579
1581
1580 Return: None
1582 Return: None
1581 """
1583 """
1582
1584
1583 self.nTotalBlocks = 0
1585 self.nTotalBlocks = 0
1584
1586
1585 self.profileIndex = 0
1587 self.profileIndex = 0
1586
1588
1587 self.isConfig = False
1589 self.isConfig = False
1588
1590
1589 self.fp = None
1591 self.fp = None
1590
1592
1591 self.flagIsNewFile = 1
1593 self.flagIsNewFile = 1
1592
1594
1593 self.nTotalBlocks = 0
1595 self.nTotalBlocks = 0
1594
1596
1595 self.flagIsNewBlock = 0
1597 self.flagIsNewBlock = 0
1596
1598
1597 self.setFile = None
1599 self.setFile = None
1598
1600
1599 self.dtype = None
1601 self.dtype = None
1600
1602
1601 self.path = None
1603 self.path = None
1602
1604
1603 self.filename = None
1605 self.filename = None
1604
1606
1605 self.basicHeaderObj = BasicHeader(LOCALTIME)
1607 self.basicHeaderObj = BasicHeader(LOCALTIME)
1606
1608
1607 self.systemHeaderObj = SystemHeader()
1609 self.systemHeaderObj = SystemHeader()
1608
1610
1609 self.radarControllerHeaderObj = RadarControllerHeader()
1611 self.radarControllerHeaderObj = RadarControllerHeader()
1610
1612
1611 self.processingHeaderObj = ProcessingHeader()
1613 self.processingHeaderObj = ProcessingHeader()
1612
1614
1613 def hasAllDataInBuffer(self):
1615 def hasAllDataInBuffer(self):
1614 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1616 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
1615 return 1
1617 return 1
1616 return 0
1618 return 0
1617
1619
1618
1620
1619 def setBlockDimension(self):
1621 def setBlockDimension(self):
1620 """
1622 """
1621 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1623 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
1622
1624
1623 Affected:
1625 Affected:
1624 self.shape_spc_Buffer
1626 self.shape_spc_Buffer
1625 self.shape_cspc_Buffer
1627 self.shape_cspc_Buffer
1626 self.shape_dc_Buffer
1628 self.shape_dc_Buffer
1627
1629
1628 Return: None
1630 Return: None
1629 """
1631 """
1630 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1632 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
1631 self.processingHeaderObj.nHeights,
1633 self.processingHeaderObj.nHeights,
1632 self.systemHeaderObj.nChannels)
1634 self.systemHeaderObj.nChannels)
1633
1635
1634 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1636 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
1635 self.processingHeaderObj.profilesPerBlock,
1637 self.processingHeaderObj.profilesPerBlock,
1636 self.processingHeaderObj.nHeights),
1638 self.processingHeaderObj.nHeights),
1637 dtype=numpy.dtype('complex64'))
1639 dtype=numpy.dtype('complex64'))
1638
1640
1639
1641
1640 def writeBlock(self):
1642 def writeBlock(self):
1641 """
1643 """
1642 Escribe el buffer en el file designado
1644 Escribe el buffer en el file designado
1643
1645
1644 Affected:
1646 Affected:
1645 self.profileIndex
1647 self.profileIndex
1646 self.flagIsNewFile
1648 self.flagIsNewFile
1647 self.flagIsNewBlock
1649 self.flagIsNewBlock
1648 self.nTotalBlocks
1650 self.nTotalBlocks
1649 self.blockIndex
1651 self.blockIndex
1650
1652
1651 Return: None
1653 Return: None
1652 """
1654 """
1653 data = numpy.zeros( self.shapeBuffer, self.dtype )
1655 data = numpy.zeros( self.shapeBuffer, self.dtype )
1654
1656
1655 junk = numpy.transpose(self.datablock, (1,2,0))
1657 junk = numpy.transpose(self.datablock, (1,2,0))
1656
1658
1657 data['real'] = junk.real
1659 data['real'] = junk.real
1658 data['imag'] = junk.imag
1660 data['imag'] = junk.imag
1659
1661
1660 data = data.reshape( (-1) )
1662 data = data.reshape( (-1) )
1661
1663
1662 data.tofile( self.fp )
1664 data.tofile( self.fp )
1663
1665
1664 self.datablock.fill(0)
1666 self.datablock.fill(0)
1665
1667
1666 self.profileIndex = 0
1668 self.profileIndex = 0
1667 self.flagIsNewFile = 0
1669 self.flagIsNewFile = 0
1668 self.flagIsNewBlock = 1
1670 self.flagIsNewBlock = 1
1669
1671
1670 self.blockIndex += 1
1672 self.blockIndex += 1
1671 self.nTotalBlocks += 1
1673 self.nTotalBlocks += 1
1672
1674
1673 def putData(self):
1675 def putData(self):
1674 """
1676 """
1675 Setea un bloque de datos y luego los escribe en un file
1677 Setea un bloque de datos y luego los escribe en un file
1676
1678
1677 Affected:
1679 Affected:
1678 self.flagIsNewBlock
1680 self.flagIsNewBlock
1679 self.profileIndex
1681 self.profileIndex
1680
1682
1681 Return:
1683 Return:
1682 0 : Si no hay data o no hay mas files que puedan escribirse
1684 0 : Si no hay data o no hay mas files que puedan escribirse
1683 1 : Si se escribio la data de un bloque en un file
1685 1 : Si se escribio la data de un bloque en un file
1684 """
1686 """
1685 if self.dataOut.flagNoData:
1687 if self.dataOut.flagNoData:
1686 return 0
1688 return 0
1687
1689
1688 self.flagIsNewBlock = 0
1690 self.flagIsNewBlock = 0
1689
1691
1690 if self.dataOut.flagTimeBlock:
1692 if self.dataOut.flagTimeBlock:
1691
1693
1692 self.datablock.fill(0)
1694 self.datablock.fill(0)
1693 self.profileIndex = 0
1695 self.profileIndex = 0
1694 self.setNextFile()
1696 self.setNextFile()
1695
1697
1696 if self.profileIndex == 0:
1698 if self.profileIndex == 0:
1697 self.setBasicHeader()
1699 self.setBasicHeader()
1698
1700
1699 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1701 self.datablock[:,self.profileIndex,:] = self.dataOut.data
1700
1702
1701 self.profileIndex += 1
1703 self.profileIndex += 1
1702
1704
1703 if self.hasAllDataInBuffer():
1705 if self.hasAllDataInBuffer():
1704 #if self.flagIsNewFile:
1706 #if self.flagIsNewFile:
1705 self.writeNextBlock()
1707 self.writeNextBlock()
1706 # self.setFirstHeader()
1708 # self.setFirstHeader()
1707
1709
1708 return 1
1710 return 1
1709
1711
1710 def __getProcessFlags(self):
1712 def __getProcessFlags(self):
1711
1713
1712 processFlags = 0
1714 processFlags = 0
1713
1715
1714 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1716 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1715 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1717 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1716 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1718 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1717 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1719 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1718 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1720 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1719 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1721 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1720
1722
1721 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1723 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1722
1724
1723
1725
1724
1726
1725 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1727 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
1726 PROCFLAG.DATATYPE_SHORT,
1728 PROCFLAG.DATATYPE_SHORT,
1727 PROCFLAG.DATATYPE_LONG,
1729 PROCFLAG.DATATYPE_LONG,
1728 PROCFLAG.DATATYPE_INT64,
1730 PROCFLAG.DATATYPE_INT64,
1729 PROCFLAG.DATATYPE_FLOAT,
1731 PROCFLAG.DATATYPE_FLOAT,
1730 PROCFLAG.DATATYPE_DOUBLE]
1732 PROCFLAG.DATATYPE_DOUBLE]
1731
1733
1732
1734
1733 for index in range(len(dtypeList)):
1735 for index in range(len(dtypeList)):
1734 if self.dataOut.dtype == dtypeList[index]:
1736 if self.dataOut.dtype == dtypeList[index]:
1735 dtypeValue = datatypeValueList[index]
1737 dtypeValue = datatypeValueList[index]
1736 break
1738 break
1737
1739
1738 processFlags += dtypeValue
1740 processFlags += dtypeValue
1739
1741
1740 if self.dataOut.flagDecodeData:
1742 if self.dataOut.flagDecodeData:
1741 processFlags += PROCFLAG.DECODE_DATA
1743 processFlags += PROCFLAG.DECODE_DATA
1742
1744
1743 if self.dataOut.flagDeflipData:
1745 if self.dataOut.flagDeflipData:
1744 processFlags += PROCFLAG.DEFLIP_DATA
1746 processFlags += PROCFLAG.DEFLIP_DATA
1745
1747
1746 if self.dataOut.code != None:
1748 if self.dataOut.code != None:
1747 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1749 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1748
1750
1749 if self.dataOut.nCohInt > 1:
1751 if self.dataOut.nCohInt > 1:
1750 processFlags += PROCFLAG.COHERENT_INTEGRATION
1752 processFlags += PROCFLAG.COHERENT_INTEGRATION
1751
1753
1752 return processFlags
1754 return processFlags
1753
1755
1754
1756
1755 def __getBlockSize(self):
1757 def __getBlockSize(self):
1756 '''
1758 '''
1757 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1759 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
1758 '''
1760 '''
1759
1761
1760 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1762 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
1761 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1763 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
1762 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1764 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
1763 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1765 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
1764 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1766 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
1765 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1767 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
1766
1768
1767 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1769 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
1768 datatypeValueList = [1,2,4,8,4,8]
1770 datatypeValueList = [1,2,4,8,4,8]
1769 for index in range(len(dtypeList)):
1771 for index in range(len(dtypeList)):
1770 if self.dataOut.dtype == dtypeList[index]:
1772 if self.dataOut.dtype == dtypeList[index]:
1771 datatypeValue = datatypeValueList[index]
1773 datatypeValue = datatypeValueList[index]
1772 break
1774 break
1773
1775
1774 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1776 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2)
1775
1777
1776 return blocksize
1778 return blocksize
1777
1779
1778 def setFirstHeader(self):
1780 def setFirstHeader(self):
1779
1781
1780 """
1782 """
1781 Obtiene una copia del First Header
1783 Obtiene una copia del First Header
1782
1784
1783 Affected:
1785 Affected:
1784 self.systemHeaderObj
1786 self.systemHeaderObj
1785 self.radarControllerHeaderObj
1787 self.radarControllerHeaderObj
1786 self.dtype
1788 self.dtype
1787
1789
1788 Return:
1790 Return:
1789 None
1791 None
1790 """
1792 """
1791
1793
1792 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1794 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
1793 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1795 self.systemHeaderObj.nChannels = self.dataOut.nChannels
1794 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1796 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
1795
1797
1796 self.setBasicHeader()
1798 self.setBasicHeader()
1797
1799
1798 processingHeaderSize = 40 # bytes
1800 processingHeaderSize = 40 # bytes
1799 self.processingHeaderObj.dtype = 0 # Voltage
1801 self.processingHeaderObj.dtype = 0 # Voltage
1800 self.processingHeaderObj.blockSize = self.__getBlockSize()
1802 self.processingHeaderObj.blockSize = self.__getBlockSize()
1801 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1803 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
1802 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1804 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
1803 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1805 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
1804 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1806 self.processingHeaderObj.processFlags = self.__getProcessFlags()
1805 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1807 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
1806 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1808 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
1807 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1809 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
1808
1810
1809 if self.dataOut.code != None:
1811 if self.dataOut.code != None:
1810 self.processingHeaderObj.code = self.dataOut.code
1812 self.processingHeaderObj.code = self.dataOut.code
1811 self.processingHeaderObj.nCode = self.dataOut.nCode
1813 self.processingHeaderObj.nCode = self.dataOut.nCode
1812 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1814 self.processingHeaderObj.nBaud = self.dataOut.nBaud
1813 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1815 codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
1814 processingHeaderSize += codesize
1816 processingHeaderSize += codesize
1815
1817
1816 if self.processingHeaderObj.nWindows != 0:
1818 if self.processingHeaderObj.nWindows != 0:
1817 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1819 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
1818 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1820 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
1819 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1821 self.processingHeaderObj.nHeights = self.dataOut.nHeights
1820 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1822 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
1821 processingHeaderSize += 12
1823 processingHeaderSize += 12
1822
1824
1823 self.processingHeaderObj.size = processingHeaderSize
1825 self.processingHeaderObj.size = processingHeaderSize
1824
1826
1825 class SpectraReader(JRODataReader):
1827 class SpectraReader(JRODataReader):
1826 """
1828 """
1827 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1829 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
1828 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1830 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
1829 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1831 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
1830
1832
1831 paresCanalesIguales * alturas * perfiles (Self Spectra)
1833 paresCanalesIguales * alturas * perfiles (Self Spectra)
1832 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1834 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
1833 canales * alturas (DC Channels)
1835 canales * alturas (DC Channels)
1834
1836
1835 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1837 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
1836 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1838 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
1837 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1839 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
1838 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1840 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
1839
1841
1840 Example:
1842 Example:
1841 dpath = "/home/myuser/data"
1843 dpath = "/home/myuser/data"
1842
1844
1843 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1845 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
1844
1846
1845 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1847 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
1846
1848
1847 readerObj = SpectraReader()
1849 readerObj = SpectraReader()
1848
1850
1849 readerObj.setup(dpath, startTime, endTime)
1851 readerObj.setup(dpath, startTime, endTime)
1850
1852
1851 while(True):
1853 while(True):
1852
1854
1853 readerObj.getData()
1855 readerObj.getData()
1854
1856
1855 print readerObj.data_spc
1857 print readerObj.data_spc
1856
1858
1857 print readerObj.data_cspc
1859 print readerObj.data_cspc
1858
1860
1859 print readerObj.data_dc
1861 print readerObj.data_dc
1860
1862
1861 if readerObj.flagNoMoreFiles:
1863 if readerObj.flagNoMoreFiles:
1862 break
1864 break
1863
1865
1864 """
1866 """
1865
1867
1866 pts2read_SelfSpectra = 0
1868 pts2read_SelfSpectra = 0
1867
1869
1868 pts2read_CrossSpectra = 0
1870 pts2read_CrossSpectra = 0
1869
1871
1870 pts2read_DCchannels = 0
1872 pts2read_DCchannels = 0
1871
1873
1872 ext = ".pdata"
1874 ext = ".pdata"
1873
1875
1874 optchar = "P"
1876 optchar = "P"
1875
1877
1876 dataOut = None
1878 dataOut = None
1877
1879
1878 nRdChannels = None
1880 nRdChannels = None
1879
1881
1880 nRdPairs = None
1882 nRdPairs = None
1881
1883
1882 rdPairList = []
1884 rdPairList = []
1883
1885
1884 def __init__(self):
1886 def __init__(self):
1885 """
1887 """
1886 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1888 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
1887
1889
1888 Inputs:
1890 Inputs:
1889 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1891 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
1890 almacenar un perfil de datos cada vez que se haga un requerimiento
1892 almacenar un perfil de datos cada vez que se haga un requerimiento
1891 (getData). El perfil sera obtenido a partir del buffer de datos,
1893 (getData). El perfil sera obtenido a partir del buffer de datos,
1892 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1894 si el buffer esta vacio se hara un nuevo proceso de lectura de un
1893 bloque de datos.
1895 bloque de datos.
1894 Si este parametro no es pasado se creara uno internamente.
1896 Si este parametro no es pasado se creara uno internamente.
1895
1897
1896 Affected:
1898 Affected:
1897 self.dataOut
1899 self.dataOut
1898
1900
1899 Return : None
1901 Return : None
1900 """
1902 """
1901
1903
1902 self.isConfig = False
1904 self.isConfig = False
1903
1905
1904 self.pts2read_SelfSpectra = 0
1906 self.pts2read_SelfSpectra = 0
1905
1907
1906 self.pts2read_CrossSpectra = 0
1908 self.pts2read_CrossSpectra = 0
1907
1909
1908 self.pts2read_DCchannels = 0
1910 self.pts2read_DCchannels = 0
1909
1911
1910 self.datablock = None
1912 self.datablock = None
1911
1913
1912 self.utc = None
1914 self.utc = None
1913
1915
1914 self.ext = ".pdata"
1916 self.ext = ".pdata"
1915
1917
1916 self.optchar = "P"
1918 self.optchar = "P"
1917
1919
1918 self.basicHeaderObj = BasicHeader(LOCALTIME)
1920 self.basicHeaderObj = BasicHeader(LOCALTIME)
1919
1921
1920 self.systemHeaderObj = SystemHeader()
1922 self.systemHeaderObj = SystemHeader()
1921
1923
1922 self.radarControllerHeaderObj = RadarControllerHeader()
1924 self.radarControllerHeaderObj = RadarControllerHeader()
1923
1925
1924 self.processingHeaderObj = ProcessingHeader()
1926 self.processingHeaderObj = ProcessingHeader()
1925
1927
1926 self.online = 0
1928 self.online = 0
1927
1929
1928 self.fp = None
1930 self.fp = None
1929
1931
1930 self.idFile = None
1932 self.idFile = None
1931
1933
1932 self.dtype = None
1934 self.dtype = None
1933
1935
1934 self.fileSizeByHeader = None
1936 self.fileSizeByHeader = None
1935
1937
1936 self.filenameList = []
1938 self.filenameList = []
1937
1939
1938 self.filename = None
1940 self.filename = None
1939
1941
1940 self.fileSize = None
1942 self.fileSize = None
1941
1943
1942 self.firstHeaderSize = 0
1944 self.firstHeaderSize = 0
1943
1945
1944 self.basicHeaderSize = 24
1946 self.basicHeaderSize = 24
1945
1947
1946 self.pathList = []
1948 self.pathList = []
1947
1949
1948 self.lastUTTime = 0
1950 self.lastUTTime = 0
1949
1951
1950 self.maxTimeStep = 30
1952 self.maxTimeStep = 30
1951
1953
1952 self.flagNoMoreFiles = 0
1954 self.flagNoMoreFiles = 0
1953
1955
1954 self.set = 0
1956 self.set = 0
1955
1957
1956 self.path = None
1958 self.path = None
1957
1959
1958 self.delay = 60 #seconds
1960 self.delay = 60 #seconds
1959
1961
1960 self.nTries = 3 #quantity tries
1962 self.nTries = 3 #quantity tries
1961
1963
1962 self.nFiles = 3 #number of files for searching
1964 self.nFiles = 3 #number of files for searching
1963
1965
1964 self.nReadBlocks = 0
1966 self.nReadBlocks = 0
1965
1967
1966 self.flagIsNewFile = 1
1968 self.flagIsNewFile = 1
1967
1969
1968 self.__isFirstTimeOnline = 1
1970 self.__isFirstTimeOnline = 1
1969
1971
1970 self.ippSeconds = 0
1972 self.ippSeconds = 0
1971
1973
1972 self.flagTimeBlock = 0
1974 self.flagTimeBlock = 0
1973
1975
1974 self.flagIsNewBlock = 0
1976 self.flagIsNewBlock = 0
1975
1977
1976 self.nTotalBlocks = 0
1978 self.nTotalBlocks = 0
1977
1979
1978 self.blocksize = 0
1980 self.blocksize = 0
1979
1981
1980 self.dataOut = self.createObjByDefault()
1982 self.dataOut = self.createObjByDefault()
1981
1983
1982 self.profileIndex = 1 #Always
1984 self.profileIndex = 1 #Always
1983
1985
1984
1986
1985 def createObjByDefault(self):
1987 def createObjByDefault(self):
1986
1988
1987 dataObj = Spectra()
1989 dataObj = Spectra()
1988
1990
1989 return dataObj
1991 return dataObj
1990
1992
1991 def __hasNotDataInBuffer(self):
1993 def __hasNotDataInBuffer(self):
1992 return 1
1994 return 1
1993
1995
1994
1996
1995 def getBlockDimension(self):
1997 def getBlockDimension(self):
1996 """
1998 """
1997 Obtiene la cantidad de puntos a leer por cada bloque de datos
1999 Obtiene la cantidad de puntos a leer por cada bloque de datos
1998
2000
1999 Affected:
2001 Affected:
2000 self.nRdChannels
2002 self.nRdChannels
2001 self.nRdPairs
2003 self.nRdPairs
2002 self.pts2read_SelfSpectra
2004 self.pts2read_SelfSpectra
2003 self.pts2read_CrossSpectra
2005 self.pts2read_CrossSpectra
2004 self.pts2read_DCchannels
2006 self.pts2read_DCchannels
2005 self.blocksize
2007 self.blocksize
2006 self.dataOut.nChannels
2008 self.dataOut.nChannels
2007 self.dataOut.nPairs
2009 self.dataOut.nPairs
2008
2010
2009 Return:
2011 Return:
2010 None
2012 None
2011 """
2013 """
2012 self.nRdChannels = 0
2014 self.nRdChannels = 0
2013 self.nRdPairs = 0
2015 self.nRdPairs = 0
2014 self.rdPairList = []
2016 self.rdPairList = []
2015
2017
2016 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
2018 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
2017 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
2019 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
2018 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
2020 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
2019 else:
2021 else:
2020 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
2022 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
2021 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
2023 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
2022
2024
2023 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
2025 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
2024
2026
2025 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
2027 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
2026 self.blocksize = self.pts2read_SelfSpectra
2028 self.blocksize = self.pts2read_SelfSpectra
2027
2029
2028 if self.processingHeaderObj.flag_cspc:
2030 if self.processingHeaderObj.flag_cspc:
2029 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
2031 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
2030 self.blocksize += self.pts2read_CrossSpectra
2032 self.blocksize += self.pts2read_CrossSpectra
2031
2033
2032 if self.processingHeaderObj.flag_dc:
2034 if self.processingHeaderObj.flag_dc:
2033 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
2035 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
2034 self.blocksize += self.pts2read_DCchannels
2036 self.blocksize += self.pts2read_DCchannels
2035
2037
2036 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
2038 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
2037
2039
2038
2040
2039 def readBlock(self):
2041 def readBlock(self):
2040 """
2042 """
2041 Lee el bloque de datos desde la posicion actual del puntero del archivo
2043 Lee el bloque de datos desde la posicion actual del puntero del archivo
2042 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
2044 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
2043 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
2045 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
2044 es seteado a 0
2046 es seteado a 0
2045
2047
2046 Return: None
2048 Return: None
2047
2049
2048 Variables afectadas:
2050 Variables afectadas:
2049
2051
2050 self.flagIsNewFile
2052 self.flagIsNewFile
2051 self.flagIsNewBlock
2053 self.flagIsNewBlock
2052 self.nTotalBlocks
2054 self.nTotalBlocks
2053 self.data_spc
2055 self.data_spc
2054 self.data_cspc
2056 self.data_cspc
2055 self.data_dc
2057 self.data_dc
2056
2058
2057 Exceptions:
2059 Exceptions:
2058 Si un bloque leido no es un bloque valido
2060 Si un bloque leido no es un bloque valido
2059 """
2061 """
2060 blockOk_flag = False
2062 blockOk_flag = False
2061 fpointer = self.fp.tell()
2063 fpointer = self.fp.tell()
2062
2064
2063 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
2065 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
2064 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2066 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2065
2067
2066 if self.processingHeaderObj.flag_cspc:
2068 if self.processingHeaderObj.flag_cspc:
2067 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
2069 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
2068 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2070 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
2069
2071
2070 if self.processingHeaderObj.flag_dc:
2072 if self.processingHeaderObj.flag_dc:
2071 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
2073 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
2072 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
2074 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
2073
2075
2074
2076
2075 if not(self.processingHeaderObj.shif_fft):
2077 if not(self.processingHeaderObj.shif_fft):
2076 #desplaza a la derecha en el eje 2 determinadas posiciones
2078 #desplaza a la derecha en el eje 2 determinadas posiciones
2077 shift = int(self.processingHeaderObj.profilesPerBlock/2)
2079 shift = int(self.processingHeaderObj.profilesPerBlock/2)
2078 spc = numpy.roll( spc, shift , axis=2 )
2080 spc = numpy.roll( spc, shift , axis=2 )
2079
2081
2080 if self.processingHeaderObj.flag_cspc:
2082 if self.processingHeaderObj.flag_cspc:
2081 #desplaza a la derecha en el eje 2 determinadas posiciones
2083 #desplaza a la derecha en el eje 2 determinadas posiciones
2082 cspc = numpy.roll( cspc, shift, axis=2 )
2084 cspc = numpy.roll( cspc, shift, axis=2 )
2083
2085
2084 # self.processingHeaderObj.shif_fft = True
2086 # self.processingHeaderObj.shif_fft = True
2085
2087
2086 spc = numpy.transpose( spc, (0,2,1) )
2088 spc = numpy.transpose( spc, (0,2,1) )
2087 self.data_spc = spc
2089 self.data_spc = spc
2088
2090
2089 if self.processingHeaderObj.flag_cspc:
2091 if self.processingHeaderObj.flag_cspc:
2090 cspc = numpy.transpose( cspc, (0,2,1) )
2092 cspc = numpy.transpose( cspc, (0,2,1) )
2091 self.data_cspc = cspc['real'] + cspc['imag']*1j
2093 self.data_cspc = cspc['real'] + cspc['imag']*1j
2092 else:
2094 else:
2093 self.data_cspc = None
2095 self.data_cspc = None
2094
2096
2095 if self.processingHeaderObj.flag_dc:
2097 if self.processingHeaderObj.flag_dc:
2096 self.data_dc = dc['real'] + dc['imag']*1j
2098 self.data_dc = dc['real'] + dc['imag']*1j
2097 else:
2099 else:
2098 self.data_dc = None
2100 self.data_dc = None
2099
2101
2100 self.flagIsNewFile = 0
2102 self.flagIsNewFile = 0
2101 self.flagIsNewBlock = 1
2103 self.flagIsNewBlock = 1
2102
2104
2103 self.nTotalBlocks += 1
2105 self.nTotalBlocks += 1
2104 self.nReadBlocks += 1
2106 self.nReadBlocks += 1
2105
2107
2106 return 1
2108 return 1
2107
2109
2108 def getFirstHeader(self):
2110 def getFirstHeader(self):
2109
2111
2110 self.dataOut.dtype = self.dtype
2112 self.dataOut.dtype = self.dtype
2111
2113
2112 self.dataOut.nPairs = self.nRdPairs
2114 self.dataOut.nPairs = self.nRdPairs
2113
2115
2114 self.dataOut.pairsList = self.rdPairList
2116 self.dataOut.pairsList = self.rdPairList
2115
2117
2116 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2118 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
2117
2119
2118 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2120 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
2119
2121
2120 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2122 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
2121
2123
2122 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2124 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
2123
2125
2124 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2126 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
2125
2127
2126 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2128 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
2127
2129
2128 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2130 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
2129
2131
2130 self.dataOut.ippSeconds = self.ippSeconds
2132 self.dataOut.ippSeconds = self.ippSeconds
2131
2133
2132 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2134 self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints
2133
2135
2134 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2136 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
2135
2137
2136 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2138 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
2137
2139
2138 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2140 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
2139
2141
2140 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
2142 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
2141
2143
2142 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2144 self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip
2143
2145
2144 if self.processingHeaderObj.code != None:
2146 if self.processingHeaderObj.code != None:
2145
2147
2146 self.dataOut.nCode = self.processingHeaderObj.nCode
2148 self.dataOut.nCode = self.processingHeaderObj.nCode
2147
2149
2148 self.dataOut.nBaud = self.processingHeaderObj.nBaud
2150 self.dataOut.nBaud = self.processingHeaderObj.nBaud
2149
2151
2150 self.dataOut.code = self.processingHeaderObj.code
2152 self.dataOut.code = self.processingHeaderObj.code
2151
2153
2152 self.dataOut.flagDecodeData = True
2154 self.dataOut.flagDecodeData = True
2153
2155
2154 def getData(self):
2156 def getData(self):
2155 """
2157 """
2156 Copia el buffer de lectura a la clase "Spectra",
2158 Copia el buffer de lectura a la clase "Spectra",
2157 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
2159 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
2158 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
2160 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
2159
2161
2160 Return:
2162 Return:
2161 0 : Si no hay mas archivos disponibles
2163 0 : Si no hay mas archivos disponibles
2162 1 : Si hizo una buena copia del buffer
2164 1 : Si hizo una buena copia del buffer
2163
2165
2164 Affected:
2166 Affected:
2165 self.dataOut
2167 self.dataOut
2166
2168
2167 self.flagTimeBlock
2169 self.flagTimeBlock
2168 self.flagIsNewBlock
2170 self.flagIsNewBlock
2169 """
2171 """
2170
2172
2171 if self.flagNoMoreFiles:
2173 if self.flagNoMoreFiles:
2172 self.dataOut.flagNoData = True
2174 self.dataOut.flagNoData = True
2173 print 'Process finished'
2175 print 'Process finished'
2174 return 0
2176 return 0
2175
2177
2176 self.flagTimeBlock = 0
2178 self.flagTimeBlock = 0
2177 self.flagIsNewBlock = 0
2179 self.flagIsNewBlock = 0
2178
2180
2179 if self.__hasNotDataInBuffer():
2181 if self.__hasNotDataInBuffer():
2180
2182
2181 if not( self.readNextBlock() ):
2183 if not( self.readNextBlock() ):
2182 self.dataOut.flagNoData = True
2184 self.dataOut.flagNoData = True
2183 return 0
2185 return 0
2184
2186
2185 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2187 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
2186
2188
2187 if self.data_dc == None:
2189 if self.data_dc == None:
2188 self.dataOut.flagNoData = True
2190 self.dataOut.flagNoData = True
2189 return 0
2191 return 0
2190
2192
2191 self.getBasicHeader()
2193 self.getBasicHeader()
2192
2194
2193 self.getFirstHeader()
2195 self.getFirstHeader()
2194
2196
2195 self.dataOut.data_spc = self.data_spc
2197 self.dataOut.data_spc = self.data_spc
2196
2198
2197 self.dataOut.data_cspc = self.data_cspc
2199 self.dataOut.data_cspc = self.data_cspc
2198
2200
2199 self.dataOut.data_dc = self.data_dc
2201 self.dataOut.data_dc = self.data_dc
2200
2202
2201 self.dataOut.flagNoData = False
2203 self.dataOut.flagNoData = False
2202
2204
2205 self.dataOut.realtime = self.online
2206
2203 return self.dataOut.data_spc
2207 return self.dataOut.data_spc
2204
2208
2205
2209
2206 class SpectraWriter(JRODataWriter):
2210 class SpectraWriter(JRODataWriter):
2207
2211
2208 """
2212 """
2209 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2213 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
2210 de los datos siempre se realiza por bloques.
2214 de los datos siempre se realiza por bloques.
2211 """
2215 """
2212
2216
2213 ext = ".pdata"
2217 ext = ".pdata"
2214
2218
2215 optchar = "P"
2219 optchar = "P"
2216
2220
2217 shape_spc_Buffer = None
2221 shape_spc_Buffer = None
2218
2222
2219 shape_cspc_Buffer = None
2223 shape_cspc_Buffer = None
2220
2224
2221 shape_dc_Buffer = None
2225 shape_dc_Buffer = None
2222
2226
2223 data_spc = None
2227 data_spc = None
2224
2228
2225 data_cspc = None
2229 data_cspc = None
2226
2230
2227 data_dc = None
2231 data_dc = None
2228
2232
2229 # dataOut = None
2233 # dataOut = None
2230
2234
2231 def __init__(self):
2235 def __init__(self):
2232 """
2236 """
2233 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2237 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
2234
2238
2235 Affected:
2239 Affected:
2236 self.dataOut
2240 self.dataOut
2237 self.basicHeaderObj
2241 self.basicHeaderObj
2238 self.systemHeaderObj
2242 self.systemHeaderObj
2239 self.radarControllerHeaderObj
2243 self.radarControllerHeaderObj
2240 self.processingHeaderObj
2244 self.processingHeaderObj
2241
2245
2242 Return: None
2246 Return: None
2243 """
2247 """
2244
2248
2245 self.isConfig = False
2249 self.isConfig = False
2246
2250
2247 self.nTotalBlocks = 0
2251 self.nTotalBlocks = 0
2248
2252
2249 self.data_spc = None
2253 self.data_spc = None
2250
2254
2251 self.data_cspc = None
2255 self.data_cspc = None
2252
2256
2253 self.data_dc = None
2257 self.data_dc = None
2254
2258
2255 self.fp = None
2259 self.fp = None
2256
2260
2257 self.flagIsNewFile = 1
2261 self.flagIsNewFile = 1
2258
2262
2259 self.nTotalBlocks = 0
2263 self.nTotalBlocks = 0
2260
2264
2261 self.flagIsNewBlock = 0
2265 self.flagIsNewBlock = 0
2262
2266
2263 self.setFile = None
2267 self.setFile = None
2264
2268
2265 self.dtype = None
2269 self.dtype = None
2266
2270
2267 self.path = None
2271 self.path = None
2268
2272
2269 self.noMoreFiles = 0
2273 self.noMoreFiles = 0
2270
2274
2271 self.filename = None
2275 self.filename = None
2272
2276
2273 self.basicHeaderObj = BasicHeader(LOCALTIME)
2277 self.basicHeaderObj = BasicHeader(LOCALTIME)
2274
2278
2275 self.systemHeaderObj = SystemHeader()
2279 self.systemHeaderObj = SystemHeader()
2276
2280
2277 self.radarControllerHeaderObj = RadarControllerHeader()
2281 self.radarControllerHeaderObj = RadarControllerHeader()
2278
2282
2279 self.processingHeaderObj = ProcessingHeader()
2283 self.processingHeaderObj = ProcessingHeader()
2280
2284
2281
2285
2282 def hasAllDataInBuffer(self):
2286 def hasAllDataInBuffer(self):
2283 return 1
2287 return 1
2284
2288
2285
2289
2286 def setBlockDimension(self):
2290 def setBlockDimension(self):
2287 """
2291 """
2288 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2292 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
2289
2293
2290 Affected:
2294 Affected:
2291 self.shape_spc_Buffer
2295 self.shape_spc_Buffer
2292 self.shape_cspc_Buffer
2296 self.shape_cspc_Buffer
2293 self.shape_dc_Buffer
2297 self.shape_dc_Buffer
2294
2298
2295 Return: None
2299 Return: None
2296 """
2300 """
2297 self.shape_spc_Buffer = (self.dataOut.nChannels,
2301 self.shape_spc_Buffer = (self.dataOut.nChannels,
2298 self.processingHeaderObj.nHeights,
2302 self.processingHeaderObj.nHeights,
2299 self.processingHeaderObj.profilesPerBlock)
2303 self.processingHeaderObj.profilesPerBlock)
2300
2304
2301 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2305 self.shape_cspc_Buffer = (self.dataOut.nPairs,
2302 self.processingHeaderObj.nHeights,
2306 self.processingHeaderObj.nHeights,
2303 self.processingHeaderObj.profilesPerBlock)
2307 self.processingHeaderObj.profilesPerBlock)
2304
2308
2305 self.shape_dc_Buffer = (self.dataOut.nChannels,
2309 self.shape_dc_Buffer = (self.dataOut.nChannels,
2306 self.processingHeaderObj.nHeights)
2310 self.processingHeaderObj.nHeights)
2307
2311
2308
2312
2309 def writeBlock(self):
2313 def writeBlock(self):
2310 """
2314 """
2311 Escribe el buffer en el file designado
2315 Escribe el buffer en el file designado
2312
2316
2313 Affected:
2317 Affected:
2314 self.data_spc
2318 self.data_spc
2315 self.data_cspc
2319 self.data_cspc
2316 self.data_dc
2320 self.data_dc
2317 self.flagIsNewFile
2321 self.flagIsNewFile
2318 self.flagIsNewBlock
2322 self.flagIsNewBlock
2319 self.nTotalBlocks
2323 self.nTotalBlocks
2320 self.nWriteBlocks
2324 self.nWriteBlocks
2321
2325
2322 Return: None
2326 Return: None
2323 """
2327 """
2324
2328
2325 spc = numpy.transpose( self.data_spc, (0,2,1) )
2329 spc = numpy.transpose( self.data_spc, (0,2,1) )
2326 if not( self.processingHeaderObj.shif_fft ):
2330 if not( self.processingHeaderObj.shif_fft ):
2327 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2331 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2328 data = spc.reshape((-1))
2332 data = spc.reshape((-1))
2329 data = data.astype(self.dtype[0])
2333 data = data.astype(self.dtype[0])
2330 data.tofile(self.fp)
2334 data.tofile(self.fp)
2331
2335
2332 if self.data_cspc != None:
2336 if self.data_cspc != None:
2333 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2337 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
2334 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2338 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
2335 if not( self.processingHeaderObj.shif_fft ):
2339 if not( self.processingHeaderObj.shif_fft ):
2336 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2340 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
2337 data['real'] = cspc.real
2341 data['real'] = cspc.real
2338 data['imag'] = cspc.imag
2342 data['imag'] = cspc.imag
2339 data = data.reshape((-1))
2343 data = data.reshape((-1))
2340 data.tofile(self.fp)
2344 data.tofile(self.fp)
2341
2345
2342 if self.data_dc != None:
2346 if self.data_dc != None:
2343 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2347 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
2344 dc = self.data_dc
2348 dc = self.data_dc
2345 data['real'] = dc.real
2349 data['real'] = dc.real
2346 data['imag'] = dc.imag
2350 data['imag'] = dc.imag
2347 data = data.reshape((-1))
2351 data = data.reshape((-1))
2348 data.tofile(self.fp)
2352 data.tofile(self.fp)
2349
2353
2350 self.data_spc.fill(0)
2354 self.data_spc.fill(0)
2351 self.data_dc.fill(0)
2355 self.data_dc.fill(0)
2352 if self.data_cspc != None:
2356 if self.data_cspc != None:
2353 self.data_cspc.fill(0)
2357 self.data_cspc.fill(0)
2354
2358
2355 self.flagIsNewFile = 0
2359 self.flagIsNewFile = 0
2356 self.flagIsNewBlock = 1
2360 self.flagIsNewBlock = 1
2357 self.nTotalBlocks += 1
2361 self.nTotalBlocks += 1
2358 self.nWriteBlocks += 1
2362 self.nWriteBlocks += 1
2359 self.blockIndex += 1
2363 self.blockIndex += 1
2360
2364
2361
2365
2362 def putData(self):
2366 def putData(self):
2363 """
2367 """
2364 Setea un bloque de datos y luego los escribe en un file
2368 Setea un bloque de datos y luego los escribe en un file
2365
2369
2366 Affected:
2370 Affected:
2367 self.data_spc
2371 self.data_spc
2368 self.data_cspc
2372 self.data_cspc
2369 self.data_dc
2373 self.data_dc
2370
2374
2371 Return:
2375 Return:
2372 0 : Si no hay data o no hay mas files que puedan escribirse
2376 0 : Si no hay data o no hay mas files que puedan escribirse
2373 1 : Si se escribio la data de un bloque en un file
2377 1 : Si se escribio la data de un bloque en un file
2374 """
2378 """
2375
2379
2376 if self.dataOut.flagNoData:
2380 if self.dataOut.flagNoData:
2377 return 0
2381 return 0
2378
2382
2379 self.flagIsNewBlock = 0
2383 self.flagIsNewBlock = 0
2380
2384
2381 if self.dataOut.flagTimeBlock:
2385 if self.dataOut.flagTimeBlock:
2382 self.data_spc.fill(0)
2386 self.data_spc.fill(0)
2383 self.data_cspc.fill(0)
2387 self.data_cspc.fill(0)
2384 self.data_dc.fill(0)
2388 self.data_dc.fill(0)
2385 self.setNextFile()
2389 self.setNextFile()
2386
2390
2387 if self.flagIsNewFile == 0:
2391 if self.flagIsNewFile == 0:
2388 self.setBasicHeader()
2392 self.setBasicHeader()
2389
2393
2390 self.data_spc = self.dataOut.data_spc.copy()
2394 self.data_spc = self.dataOut.data_spc.copy()
2391 self.data_cspc = self.dataOut.data_cspc.copy()
2395 self.data_cspc = self.dataOut.data_cspc.copy()
2392 self.data_dc = self.dataOut.data_dc.copy()
2396 self.data_dc = self.dataOut.data_dc.copy()
2393
2397
2394 # #self.processingHeaderObj.dataBlocksPerFile)
2398 # #self.processingHeaderObj.dataBlocksPerFile)
2395 if self.hasAllDataInBuffer():
2399 if self.hasAllDataInBuffer():
2396 # self.setFirstHeader()
2400 # self.setFirstHeader()
2397 self.writeNextBlock()
2401 self.writeNextBlock()
2398
2402
2399 return 1
2403 return 1
2400
2404
2401
2405
2402 def __getProcessFlags(self):
2406 def __getProcessFlags(self):
2403
2407
2404 processFlags = 0
2408 processFlags = 0
2405
2409
2406 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2410 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2407 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2411 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2408 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2412 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2409 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2413 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2410 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2414 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2411 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2415 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2412
2416
2413 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2417 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2414
2418
2415
2419
2416
2420
2417 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2421 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
2418 PROCFLAG.DATATYPE_SHORT,
2422 PROCFLAG.DATATYPE_SHORT,
2419 PROCFLAG.DATATYPE_LONG,
2423 PROCFLAG.DATATYPE_LONG,
2420 PROCFLAG.DATATYPE_INT64,
2424 PROCFLAG.DATATYPE_INT64,
2421 PROCFLAG.DATATYPE_FLOAT,
2425 PROCFLAG.DATATYPE_FLOAT,
2422 PROCFLAG.DATATYPE_DOUBLE]
2426 PROCFLAG.DATATYPE_DOUBLE]
2423
2427
2424
2428
2425 for index in range(len(dtypeList)):
2429 for index in range(len(dtypeList)):
2426 if self.dataOut.dtype == dtypeList[index]:
2430 if self.dataOut.dtype == dtypeList[index]:
2427 dtypeValue = datatypeValueList[index]
2431 dtypeValue = datatypeValueList[index]
2428 break
2432 break
2429
2433
2430 processFlags += dtypeValue
2434 processFlags += dtypeValue
2431
2435
2432 if self.dataOut.flagDecodeData:
2436 if self.dataOut.flagDecodeData:
2433 processFlags += PROCFLAG.DECODE_DATA
2437 processFlags += PROCFLAG.DECODE_DATA
2434
2438
2435 if self.dataOut.flagDeflipData:
2439 if self.dataOut.flagDeflipData:
2436 processFlags += PROCFLAG.DEFLIP_DATA
2440 processFlags += PROCFLAG.DEFLIP_DATA
2437
2441
2438 if self.dataOut.code != None:
2442 if self.dataOut.code != None:
2439 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2443 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
2440
2444
2441 if self.dataOut.nIncohInt > 1:
2445 if self.dataOut.nIncohInt > 1:
2442 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2446 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
2443
2447
2444 if self.dataOut.data_dc != None:
2448 if self.dataOut.data_dc != None:
2445 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2449 processFlags += PROCFLAG.SAVE_CHANNELS_DC
2446
2450
2447 return processFlags
2451 return processFlags
2448
2452
2449
2453
2450 def __getBlockSize(self):
2454 def __getBlockSize(self):
2451 '''
2455 '''
2452 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2456 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
2453 '''
2457 '''
2454
2458
2455 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2459 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
2456 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2460 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
2457 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2461 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
2458 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2462 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
2459 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2463 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
2460 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2464 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
2461
2465
2462 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2466 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
2463 datatypeValueList = [1,2,4,8,4,8]
2467 datatypeValueList = [1,2,4,8,4,8]
2464 for index in range(len(dtypeList)):
2468 for index in range(len(dtypeList)):
2465 if self.dataOut.dtype == dtypeList[index]:
2469 if self.dataOut.dtype == dtypeList[index]:
2466 datatypeValue = datatypeValueList[index]
2470 datatypeValue = datatypeValueList[index]
2467 break
2471 break
2468
2472
2469
2473
2470 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2474 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
2471
2475
2472 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2476 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
2473 blocksize = (pts2write_SelfSpectra*datatypeValue)
2477 blocksize = (pts2write_SelfSpectra*datatypeValue)
2474
2478
2475 if self.dataOut.data_cspc != None:
2479 if self.dataOut.data_cspc != None:
2476 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2480 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
2477 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2481 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
2478
2482
2479 if self.dataOut.data_dc != None:
2483 if self.dataOut.data_dc != None:
2480 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2484 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
2481 blocksize += (pts2write_DCchannels*datatypeValue*2)
2485 blocksize += (pts2write_DCchannels*datatypeValue*2)
2482
2486
2483 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2487 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
2484
2488
2485 return blocksize
2489 return blocksize
2486
2490
2487 def setFirstHeader(self):
2491 def setFirstHeader(self):
2488
2492
2489 """
2493 """
2490 Obtiene una copia del First Header
2494 Obtiene una copia del First Header
2491
2495
2492 Affected:
2496 Affected:
2493 self.systemHeaderObj
2497 self.systemHeaderObj
2494 self.radarControllerHeaderObj
2498 self.radarControllerHeaderObj
2495 self.dtype
2499 self.dtype
2496
2500
2497 Return:
2501 Return:
2498 None
2502 None
2499 """
2503 """
2500
2504
2501 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2505 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
2502 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2506 self.systemHeaderObj.nChannels = self.dataOut.nChannels
2503 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2507 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
2504
2508
2505 self.setBasicHeader()
2509 self.setBasicHeader()
2506
2510
2507 processingHeaderSize = 40 # bytes
2511 processingHeaderSize = 40 # bytes
2508 self.processingHeaderObj.dtype = 1 # Spectra
2512 self.processingHeaderObj.dtype = 1 # Spectra
2509 self.processingHeaderObj.blockSize = self.__getBlockSize()
2513 self.processingHeaderObj.blockSize = self.__getBlockSize()
2510 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2514 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
2511 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2515 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
2512 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2516 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
2513 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2517 self.processingHeaderObj.processFlags = self.__getProcessFlags()
2514 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2518 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
2515 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2519 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
2516 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2520 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
2517 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
2521 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
2518
2522
2519 if self.processingHeaderObj.totalSpectra > 0:
2523 if self.processingHeaderObj.totalSpectra > 0:
2520 channelList = []
2524 channelList = []
2521 for channel in range(self.dataOut.nChannels):
2525 for channel in range(self.dataOut.nChannels):
2522 channelList.append(channel)
2526 channelList.append(channel)
2523 channelList.append(channel)
2527 channelList.append(channel)
2524
2528
2525 pairsList = []
2529 pairsList = []
2526 for pair in self.dataOut.pairsList:
2530 for pair in self.dataOut.pairsList:
2527 pairsList.append(pair[0])
2531 pairsList.append(pair[0])
2528 pairsList.append(pair[1])
2532 pairsList.append(pair[1])
2529 spectraComb = channelList + pairsList
2533 spectraComb = channelList + pairsList
2530 spectraComb = numpy.array(spectraComb,dtype="u1")
2534 spectraComb = numpy.array(spectraComb,dtype="u1")
2531 self.processingHeaderObj.spectraComb = spectraComb
2535 self.processingHeaderObj.spectraComb = spectraComb
2532 sizeOfSpcComb = len(spectraComb)
2536 sizeOfSpcComb = len(spectraComb)
2533 processingHeaderSize += sizeOfSpcComb
2537 processingHeaderSize += sizeOfSpcComb
2534
2538
2535 # The processing header should not have information about code
2539 # The processing header should not have information about code
2536 # if self.dataOut.code != None:
2540 # if self.dataOut.code != None:
2537 # self.processingHeaderObj.code = self.dataOut.code
2541 # self.processingHeaderObj.code = self.dataOut.code
2538 # self.processingHeaderObj.nCode = self.dataOut.nCode
2542 # self.processingHeaderObj.nCode = self.dataOut.nCode
2539 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
2543 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
2540 # nCodeSize = 4 # bytes
2544 # nCodeSize = 4 # bytes
2541 # nBaudSize = 4 # bytes
2545 # nBaudSize = 4 # bytes
2542 # codeSize = 4 # bytes
2546 # codeSize = 4 # bytes
2543 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2547 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
2544 # processingHeaderSize += sizeOfCode
2548 # processingHeaderSize += sizeOfCode
2545
2549
2546 if self.processingHeaderObj.nWindows != 0:
2550 if self.processingHeaderObj.nWindows != 0:
2547 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2551 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
2548 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2552 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2549 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2553 self.processingHeaderObj.nHeights = self.dataOut.nHeights
2550 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2554 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
2551 sizeOfFirstHeight = 4
2555 sizeOfFirstHeight = 4
2552 sizeOfdeltaHeight = 4
2556 sizeOfdeltaHeight = 4
2553 sizeOfnHeights = 4
2557 sizeOfnHeights = 4
2554 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2558 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
2555 processingHeaderSize += sizeOfWindows
2559 processingHeaderSize += sizeOfWindows
2556
2560
2557 self.processingHeaderObj.size = processingHeaderSize
2561 self.processingHeaderObj.size = processingHeaderSize
2558
2562
2559 class SpectraHeisWriter(Operation):
2563 class SpectraHeisWriter(Operation):
2560 # set = None
2564 # set = None
2561 setFile = None
2565 setFile = None
2562 idblock = None
2566 idblock = None
2563 doypath = None
2567 doypath = None
2564 subfolder = None
2568 subfolder = None
2565
2569
2566 def __init__(self):
2570 def __init__(self):
2567 self.wrObj = FITS()
2571 self.wrObj = FITS()
2568 # self.dataOut = dataOut
2572 # self.dataOut = dataOut
2569 self.nTotalBlocks=0
2573 self.nTotalBlocks=0
2570 # self.set = None
2574 # self.set = None
2571 self.setFile = None
2575 self.setFile = None
2572 self.idblock = 0
2576 self.idblock = 0
2573 self.wrpath = None
2577 self.wrpath = None
2574 self.doypath = None
2578 self.doypath = None
2575 self.subfolder = None
2579 self.subfolder = None
2576 self.isConfig = False
2580 self.isConfig = False
2577
2581
2578 def isNumber(str):
2582 def isNumber(str):
2579 """
2583 """
2580 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2584 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
2581
2585
2582 Excepciones:
2586 Excepciones:
2583 Si un determinado string no puede ser convertido a numero
2587 Si un determinado string no puede ser convertido a numero
2584 Input:
2588 Input:
2585 str, string al cual se le analiza para determinar si convertible a un numero o no
2589 str, string al cual se le analiza para determinar si convertible a un numero o no
2586
2590
2587 Return:
2591 Return:
2588 True : si el string es uno numerico
2592 True : si el string es uno numerico
2589 False : no es un string numerico
2593 False : no es un string numerico
2590 """
2594 """
2591 try:
2595 try:
2592 float( str )
2596 float( str )
2593 return True
2597 return True
2594 except:
2598 except:
2595 return False
2599 return False
2596
2600
2597 def setup(self, dataOut, wrpath):
2601 def setup(self, dataOut, wrpath):
2598
2602
2599 if not(os.path.exists(wrpath)):
2603 if not(os.path.exists(wrpath)):
2600 os.mkdir(wrpath)
2604 os.mkdir(wrpath)
2601
2605
2602 self.wrpath = wrpath
2606 self.wrpath = wrpath
2603 # self.setFile = 0
2607 # self.setFile = 0
2604 self.dataOut = dataOut
2608 self.dataOut = dataOut
2605
2609
2606 def putData(self):
2610 def putData(self):
2607 name= time.localtime( self.dataOut.utctime)
2611 name= time.localtime( self.dataOut.utctime)
2608 ext=".fits"
2612 ext=".fits"
2609
2613
2610 if self.doypath == None:
2614 if self.doypath == None:
2611 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
2615 self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple()))
2612 self.doypath = os.path.join( self.wrpath, self.subfolder )
2616 self.doypath = os.path.join( self.wrpath, self.subfolder )
2613 os.mkdir(self.doypath)
2617 os.mkdir(self.doypath)
2614
2618
2615 if self.setFile == None:
2619 if self.setFile == None:
2616 # self.set = self.dataOut.set
2620 # self.set = self.dataOut.set
2617 self.setFile = 0
2621 self.setFile = 0
2618 # if self.set != self.dataOut.set:
2622 # if self.set != self.dataOut.set:
2619 ## self.set = self.dataOut.set
2623 ## self.set = self.dataOut.set
2620 # self.setFile = 0
2624 # self.setFile = 0
2621
2625
2622 #make the filename
2626 #make the filename
2623 file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2627 file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext)
2624
2628
2625 filename = os.path.join(self.wrpath,self.subfolder, file)
2629 filename = os.path.join(self.wrpath,self.subfolder, file)
2626
2630
2627 idblock = numpy.array([self.idblock],dtype="int64")
2631 idblock = numpy.array([self.idblock],dtype="int64")
2628 header=self.wrObj.cFImage(idblock=idblock,
2632 header=self.wrObj.cFImage(idblock=idblock,
2629 year=time.gmtime(self.dataOut.utctime).tm_year,
2633 year=time.gmtime(self.dataOut.utctime).tm_year,
2630 month=time.gmtime(self.dataOut.utctime).tm_mon,
2634 month=time.gmtime(self.dataOut.utctime).tm_mon,
2631 day=time.gmtime(self.dataOut.utctime).tm_mday,
2635 day=time.gmtime(self.dataOut.utctime).tm_mday,
2632 hour=time.gmtime(self.dataOut.utctime).tm_hour,
2636 hour=time.gmtime(self.dataOut.utctime).tm_hour,
2633 minute=time.gmtime(self.dataOut.utctime).tm_min,
2637 minute=time.gmtime(self.dataOut.utctime).tm_min,
2634 second=time.gmtime(self.dataOut.utctime).tm_sec)
2638 second=time.gmtime(self.dataOut.utctime).tm_sec)
2635
2639
2636 c=3E8
2640 c=3E8
2637 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2641 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
2638 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
2642 freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000))
2639
2643
2640 colList = []
2644 colList = []
2641
2645
2642 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2646 colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq)
2643
2647
2644 colList.append(colFreq)
2648 colList.append(colFreq)
2645
2649
2646 nchannel=self.dataOut.nChannels
2650 nchannel=self.dataOut.nChannels
2647
2651
2648 for i in range(nchannel):
2652 for i in range(nchannel):
2649 col = self.wrObj.writeData(name="PCh"+str(i+1),
2653 col = self.wrObj.writeData(name="PCh"+str(i+1),
2650 format=str(self.dataOut.nFFTPoints)+'E',
2654 format=str(self.dataOut.nFFTPoints)+'E',
2651 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
2655 data=10*numpy.log10(self.dataOut.data_spc[i,:]))
2652
2656
2653 colList.append(col)
2657 colList.append(col)
2654
2658
2655 data=self.wrObj.Ctable(colList=colList)
2659 data=self.wrObj.Ctable(colList=colList)
2656
2660
2657 self.wrObj.CFile(header,data)
2661 self.wrObj.CFile(header,data)
2658
2662
2659 self.wrObj.wFile(filename)
2663 self.wrObj.wFile(filename)
2660
2664
2661 #update the setFile
2665 #update the setFile
2662 self.setFile += 1
2666 self.setFile += 1
2663 self.idblock += 1
2667 self.idblock += 1
2664
2668
2665 return 1
2669 return 1
2666
2670
2667 def run(self, dataOut, **kwargs):
2671 def run(self, dataOut, **kwargs):
2668
2672
2669 if not(self.isConfig):
2673 if not(self.isConfig):
2670
2674
2671 self.setup(dataOut, **kwargs)
2675 self.setup(dataOut, **kwargs)
2672 self.isConfig = True
2676 self.isConfig = True
2673
2677
2674 self.putData()
2678 self.putData()
2675
2679
2676
2680
2677 class FITS:
2681 class FITS:
2678 name=None
2682 name=None
2679 format=None
2683 format=None
2680 array =None
2684 array =None
2681 data =None
2685 data =None
2682 thdulist=None
2686 thdulist=None
2683 prihdr=None
2687 prihdr=None
2684 hdu=None
2688 hdu=None
2685
2689
2686 def __init__(self):
2690 def __init__(self):
2687
2691
2688 pass
2692 pass
2689
2693
2690 def setColF(self,name,format,array):
2694 def setColF(self,name,format,array):
2691 self.name=name
2695 self.name=name
2692 self.format=format
2696 self.format=format
2693 self.array=array
2697 self.array=array
2694 a1=numpy.array([self.array],dtype=numpy.float32)
2698 a1=numpy.array([self.array],dtype=numpy.float32)
2695 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2699 self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1)
2696 return self.col1
2700 return self.col1
2697
2701
2698 # def setColP(self,name,format,data):
2702 # def setColP(self,name,format,data):
2699 # self.name=name
2703 # self.name=name
2700 # self.format=format
2704 # self.format=format
2701 # self.data=data
2705 # self.data=data
2702 # a2=numpy.array([self.data],dtype=numpy.float32)
2706 # a2=numpy.array([self.data],dtype=numpy.float32)
2703 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2707 # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2704 # return self.col2
2708 # return self.col2
2705
2709
2706
2710
2707 def writeData(self,name,format,data):
2711 def writeData(self,name,format,data):
2708 self.name=name
2712 self.name=name
2709 self.format=format
2713 self.format=format
2710 self.data=data
2714 self.data=data
2711 a2=numpy.array([self.data],dtype=numpy.float32)
2715 a2=numpy.array([self.data],dtype=numpy.float32)
2712 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2716 self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2)
2713 return self.col2
2717 return self.col2
2714
2718
2715 def cFImage(self,idblock,year,month,day,hour,minute,second):
2719 def cFImage(self,idblock,year,month,day,hour,minute,second):
2716 self.hdu= pyfits.PrimaryHDU(idblock)
2720 self.hdu= pyfits.PrimaryHDU(idblock)
2717 self.hdu.header.set("Year",year)
2721 self.hdu.header.set("Year",year)
2718 self.hdu.header.set("Month",month)
2722 self.hdu.header.set("Month",month)
2719 self.hdu.header.set("Day",day)
2723 self.hdu.header.set("Day",day)
2720 self.hdu.header.set("Hour",hour)
2724 self.hdu.header.set("Hour",hour)
2721 self.hdu.header.set("Minute",minute)
2725 self.hdu.header.set("Minute",minute)
2722 self.hdu.header.set("Second",second)
2726 self.hdu.header.set("Second",second)
2723 return self.hdu
2727 return self.hdu
2724
2728
2725
2729
2726 def Ctable(self,colList):
2730 def Ctable(self,colList):
2727 self.cols=pyfits.ColDefs(colList)
2731 self.cols=pyfits.ColDefs(colList)
2728 self.tbhdu = pyfits.new_table(self.cols)
2732 self.tbhdu = pyfits.new_table(self.cols)
2729 return self.tbhdu
2733 return self.tbhdu
2730
2734
2731
2735
2732 def CFile(self,hdu,tbhdu):
2736 def CFile(self,hdu,tbhdu):
2733 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2737 self.thdulist=pyfits.HDUList([hdu,tbhdu])
2734
2738
2735 def wFile(self,filename):
2739 def wFile(self,filename):
2736 if os.path.isfile(filename):
2740 if os.path.isfile(filename):
2737 os.remove(filename)
2741 os.remove(filename)
2738 self.thdulist.writeto(filename)
2742 self.thdulist.writeto(filename)
2739
2743
2740
2744
2741 class ParameterConf:
2745 class ParameterConf:
2742 ELEMENTNAME = 'Parameter'
2746 ELEMENTNAME = 'Parameter'
2743 def __init__(self):
2747 def __init__(self):
2744 self.name = ''
2748 self.name = ''
2745 self.value = ''
2749 self.value = ''
2746
2750
2747 def readXml(self, parmElement):
2751 def readXml(self, parmElement):
2748 self.name = parmElement.get('name')
2752 self.name = parmElement.get('name')
2749 self.value = parmElement.get('value')
2753 self.value = parmElement.get('value')
2750
2754
2751 def getElementName(self):
2755 def getElementName(self):
2752 return self.ELEMENTNAME
2756 return self.ELEMENTNAME
2753
2757
2754 class Metadata:
2758 class Metadata:
2755
2759
2756 def __init__(self, filename):
2760 def __init__(self, filename):
2757 self.parmConfObjList = []
2761 self.parmConfObjList = []
2758 self.readXml(filename)
2762 self.readXml(filename)
2759
2763
2760 def readXml(self, filename):
2764 def readXml(self, filename):
2761 self.projectElement = None
2765 self.projectElement = None
2762 self.procUnitConfObjDict = {}
2766 self.procUnitConfObjDict = {}
2763 self.projectElement = ElementTree().parse(filename)
2767 self.projectElement = ElementTree().parse(filename)
2764 self.project = self.projectElement.tag
2768 self.project = self.projectElement.tag
2765
2769
2766 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
2770 parmElementList = self.projectElement.getiterator(ParameterConf().getElementName())
2767
2771
2768 for parmElement in parmElementList:
2772 for parmElement in parmElementList:
2769 parmConfObj = ParameterConf()
2773 parmConfObj = ParameterConf()
2770 parmConfObj.readXml(parmElement)
2774 parmConfObj.readXml(parmElement)
2771 self.parmConfObjList.append(parmConfObj)
2775 self.parmConfObjList.append(parmConfObj)
2772
2776
2773 class FitsWriter(Operation):
2777 class FitsWriter(Operation):
2774
2778
2775 def __init__(self):
2779 def __init__(self):
2776 self.isConfig = False
2780 self.isConfig = False
2777 self.dataBlocksPerFile = None
2781 self.dataBlocksPerFile = None
2778 self.blockIndex = 0
2782 self.blockIndex = 0
2779 self.flagIsNewFile = 1
2783 self.flagIsNewFile = 1
2780 self.fitsObj = None
2784 self.fitsObj = None
2781 self.optchar = 'P'
2785 self.optchar = 'P'
2782 self.ext = '.fits'
2786 self.ext = '.fits'
2783 self.setFile = 0
2787 self.setFile = 0
2784
2788
2785 def setFitsHeader(self, dataOut, metadatafile):
2789 def setFitsHeader(self, dataOut, metadatafile):
2786
2790
2787 header_data = pyfits.PrimaryHDU()
2791 header_data = pyfits.PrimaryHDU()
2788
2792
2789 metadata4fits = Metadata(metadatafile)
2793 metadata4fits = Metadata(metadatafile)
2790 for parameter in metadata4fits.parmConfObjList:
2794 for parameter in metadata4fits.parmConfObjList:
2791 parm_name = parameter.name
2795 parm_name = parameter.name
2792 parm_value = parameter.value
2796 parm_value = parameter.value
2793
2797
2794 if parm_value == 'fromdatadatetime':
2798 if parm_value == 'fromdatadatetime':
2795 value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
2799 value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple())
2796 elif parm_value == 'fromdataheights':
2800 elif parm_value == 'fromdataheights':
2797 value = dataOut.nHeights
2801 value = dataOut.nHeights
2798 elif parm_value == 'fromdatachannel':
2802 elif parm_value == 'fromdatachannel':
2799 value = dataOut.nChannels
2803 value = dataOut.nChannels
2800 elif parm_value == 'fromdatasamples':
2804 elif parm_value == 'fromdatasamples':
2801 value = dataOut.nFFTPoints
2805 value = dataOut.nFFTPoints
2802 else:
2806 else:
2803 value = parm_value
2807 value = parm_value
2804
2808
2805 header_data.header[parm_name] = value
2809 header_data.header[parm_name] = value
2806
2810
2807 header_data.header['NBLOCK'] = self.blockIndex
2811 header_data.header['NBLOCK'] = self.blockIndex
2808
2812
2809 header_data.writeto(self.filename)
2813 header_data.writeto(self.filename)
2810
2814
2811
2815
2812 def setup(self, dataOut, path, dataBlocksPerFile, metadatafile):
2816 def setup(self, dataOut, path, dataBlocksPerFile, metadatafile):
2813
2817
2814 self.path = path
2818 self.path = path
2815 self.dataOut = dataOut
2819 self.dataOut = dataOut
2816 self.metadatafile = metadatafile
2820 self.metadatafile = metadatafile
2817 self.dataBlocksPerFile = dataBlocksPerFile
2821 self.dataBlocksPerFile = dataBlocksPerFile
2818
2822
2819 def open(self):
2823 def open(self):
2820 self.fitsObj = pyfits.open(self.filename, mode='update')
2824 self.fitsObj = pyfits.open(self.filename, mode='update')
2821
2825
2822
2826
2823 def addData(self, data):
2827 def addData(self, data):
2824 self.open()
2828 self.open()
2825 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATA'])
2829 extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATA'])
2826 extension.header['UTCTIME'] = self.dataOut.utctime
2830 extension.header['UTCTIME'] = self.dataOut.utctime
2827 self.fitsObj.append(extension)
2831 self.fitsObj.append(extension)
2828 self.blockIndex += 1
2832 self.blockIndex += 1
2829 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
2833 self.fitsObj[0].header['NBLOCK'] = self.blockIndex
2830
2834
2831 self.write()
2835 self.write()
2832
2836
2833 def write(self):
2837 def write(self):
2834
2838
2835 self.fitsObj.flush(verbose=True)
2839 self.fitsObj.flush(verbose=True)
2836 self.fitsObj.close()
2840 self.fitsObj.close()
2837
2841
2838
2842
2839 def setNextFile(self):
2843 def setNextFile(self):
2840
2844
2841 ext = self.ext
2845 ext = self.ext
2842 path = self.path
2846 path = self.path
2843
2847
2844 timeTuple = time.localtime( self.dataOut.utctime)
2848 timeTuple = time.localtime( self.dataOut.utctime)
2845 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
2849 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
2846
2850
2847 fullpath = os.path.join( path, subfolder )
2851 fullpath = os.path.join( path, subfolder )
2848 if not( os.path.exists(fullpath) ):
2852 if not( os.path.exists(fullpath) ):
2849 os.mkdir(fullpath)
2853 os.mkdir(fullpath)
2850 self.setFile = -1 #inicializo mi contador de seteo
2854 self.setFile = -1 #inicializo mi contador de seteo
2851 else:
2855 else:
2852 filesList = os.listdir( fullpath )
2856 filesList = os.listdir( fullpath )
2853 if len( filesList ) > 0:
2857 if len( filesList ) > 0:
2854 filesList = sorted( filesList, key=str.lower )
2858 filesList = sorted( filesList, key=str.lower )
2855 filen = filesList[-1]
2859 filen = filesList[-1]
2856
2860
2857 if isNumber( filen[8:11] ):
2861 if isNumber( filen[8:11] ):
2858 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
2862 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
2859 else:
2863 else:
2860 self.setFile = -1
2864 self.setFile = -1
2861 else:
2865 else:
2862 self.setFile = -1 #inicializo mi contador de seteo
2866 self.setFile = -1 #inicializo mi contador de seteo
2863
2867
2864 setFile = self.setFile
2868 setFile = self.setFile
2865 setFile += 1
2869 setFile += 1
2866
2870
2867 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
2871 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
2868 timeTuple.tm_year,
2872 timeTuple.tm_year,
2869 timeTuple.tm_yday,
2873 timeTuple.tm_yday,
2870 setFile,
2874 setFile,
2871 ext )
2875 ext )
2872
2876
2873 filename = os.path.join( path, subfolder, file )
2877 filename = os.path.join( path, subfolder, file )
2874
2878
2875 self.blockIndex = 0
2879 self.blockIndex = 0
2876 self.filename = filename
2880 self.filename = filename
2877 self.setFile = setFile
2881 self.setFile = setFile
2878 self.flagIsNewFile = 1
2882 self.flagIsNewFile = 1
2879
2883
2880 print 'Writing the file: %s'%self.filename
2884 print 'Writing the file: %s'%self.filename
2881
2885
2882 self.setFitsHeader(self.dataOut, self.metadatafile)
2886 self.setFitsHeader(self.dataOut, self.metadatafile)
2883
2887
2884 return 1
2888 return 1
2885
2889
2886 def writeBlock(self):
2890 def writeBlock(self):
2887 self.addData(self.dataOut.data_spc)
2891 self.addData(self.dataOut.data_spc)
2888 self.flagIsNewFile = 0
2892 self.flagIsNewFile = 0
2889
2893
2890
2894
2891 def __setNewBlock(self):
2895 def __setNewBlock(self):
2892
2896
2893 if self.flagIsNewFile:
2897 if self.flagIsNewFile:
2894 return 1
2898 return 1
2895
2899
2896 if self.blockIndex < self.dataBlocksPerFile:
2900 if self.blockIndex < self.dataBlocksPerFile:
2897 return 1
2901 return 1
2898
2902
2899 if not( self.setNextFile() ):
2903 if not( self.setNextFile() ):
2900 return 0
2904 return 0
2901
2905
2902 return 1
2906 return 1
2903
2907
2904 def writeNextBlock(self):
2908 def writeNextBlock(self):
2905 if not( self.__setNewBlock() ):
2909 if not( self.__setNewBlock() ):
2906 return 0
2910 return 0
2907 self.writeBlock()
2911 self.writeBlock()
2908 return 1
2912 return 1
2909
2913
2910 def putData(self):
2914 def putData(self):
2911 if self.flagIsNewFile:
2915 if self.flagIsNewFile:
2912 self.setNextFile()
2916 self.setNextFile()
2913 self.writeNextBlock()
2917 self.writeNextBlock()
2914
2918
2915 def run(self, dataOut, **kwargs):
2919 def run(self, dataOut, **kwargs):
2916 if not(self.isConfig):
2920 if not(self.isConfig):
2917 self.setup(dataOut, **kwargs)
2921 self.setup(dataOut, **kwargs)
2918 self.isConfig = True
2922 self.isConfig = True
2919 self.putData()
2923 self.putData()
2920
2924
2921
2925
2922 class FitsReader(ProcessingUnit):
2926 class FitsReader(ProcessingUnit):
2923
2927
2924 __TIMEZONE = time.timezone
2928 __TIMEZONE = time.timezone
2925
2929
2926 expName = None
2930 expName = None
2927 datetimestr = None
2931 datetimestr = None
2928 utc = None
2932 utc = None
2929 nChannels = None
2933 nChannels = None
2930 nSamples = None
2934 nSamples = None
2931 dataBlocksPerFile = None
2935 dataBlocksPerFile = None
2932 comments = None
2936 comments = None
2933 lastUTTime = None
2937 lastUTTime = None
2934 header_dict = None
2938 header_dict = None
2935 data = None
2939 data = None
2936 data_header_dict = None
2940 data_header_dict = None
2937
2941
2938 def __init__(self):
2942 def __init__(self):
2939 self.isConfig = False
2943 self.isConfig = False
2940 self.ext = '.fits'
2944 self.ext = '.fits'
2941 self.setFile = 0
2945 self.setFile = 0
2942 self.flagNoMoreFiles = 0
2946 self.flagNoMoreFiles = 0
2943 self.flagIsNewFile = 1
2947 self.flagIsNewFile = 1
2944 self.flagTimeBlock = None
2948 self.flagTimeBlock = None
2945 self.fileIndex = None
2949 self.fileIndex = None
2946 self.filename = None
2950 self.filename = None
2947 self.fileSize = None
2951 self.fileSize = None
2948 self.fitsObj = None
2952 self.fitsObj = None
2949 self.nReadBlocks = 0
2953 self.nReadBlocks = 0
2950 self.nTotalBlocks = 0
2954 self.nTotalBlocks = 0
2951 self.dataOut = self.createObjByDefault()
2955 self.dataOut = self.createObjByDefault()
2952 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
2956 self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup()
2953 self.blockIndex = 1
2957 self.blockIndex = 1
2954
2958
2955 def createObjByDefault(self):
2959 def createObjByDefault(self):
2956
2960
2957 dataObj = Fits()
2961 dataObj = Fits()
2958
2962
2959 return dataObj
2963 return dataObj
2960
2964
2961 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
2965 def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False):
2962 try:
2966 try:
2963 fitsObj = pyfits.open(filename,'readonly')
2967 fitsObj = pyfits.open(filename,'readonly')
2964 except:
2968 except:
2965 raise IOError, "The file %s can't be opened" %(filename)
2969 raise IOError, "The file %s can't be opened" %(filename)
2966
2970
2967 header = fitsObj[0].header
2971 header = fitsObj[0].header
2968 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
2972 struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S")
2969 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
2973 utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS
2970
2974
2971 ltc = utc
2975 ltc = utc
2972 if useLocalTime:
2976 if useLocalTime:
2973 ltc -= time.timezone
2977 ltc -= time.timezone
2974 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
2978 thisDatetime = datetime.datetime.utcfromtimestamp(ltc)
2975 thisTime = thisDatetime.time()
2979 thisTime = thisDatetime.time()
2976
2980
2977 if not ((startTime <= thisTime) and (endTime > thisTime)):
2981 if not ((startTime <= thisTime) and (endTime > thisTime)):
2978 return None
2982 return None
2979
2983
2980 return thisDatetime
2984 return thisDatetime
2981
2985
2982 def __setNextFileOnline(self):
2986 def __setNextFileOnline(self):
2983 raise ValueError, "No implemented"
2987 raise ValueError, "No implemented"
2984
2988
2985 def __setNextFileOffline(self):
2989 def __setNextFileOffline(self):
2986 idFile = self.fileIndex
2990 idFile = self.fileIndex
2987
2991
2988 while (True):
2992 while (True):
2989 idFile += 1
2993 idFile += 1
2990 if not(idFile < len(self.filenameList)):
2994 if not(idFile < len(self.filenameList)):
2991 self.flagNoMoreFiles = 1
2995 self.flagNoMoreFiles = 1
2992 print "No more Files"
2996 print "No more Files"
2993 return 0
2997 return 0
2994
2998
2995 filename = self.filenameList[idFile]
2999 filename = self.filenameList[idFile]
2996
3000
2997 # if not(self.__verifyFile(filename)):
3001 # if not(self.__verifyFile(filename)):
2998 # continue
3002 # continue
2999
3003
3000 fileSize = os.path.getsize(filename)
3004 fileSize = os.path.getsize(filename)
3001 fitsObj = pyfits.open(filename,'readonly')
3005 fitsObj = pyfits.open(filename,'readonly')
3002 break
3006 break
3003
3007
3004 self.flagIsNewFile = 1
3008 self.flagIsNewFile = 1
3005 self.fileIndex = idFile
3009 self.fileIndex = idFile
3006 self.filename = filename
3010 self.filename = filename
3007 self.fileSize = fileSize
3011 self.fileSize = fileSize
3008 self.fitsObj = fitsObj
3012 self.fitsObj = fitsObj
3009
3013
3010 print "Setting the file: %s"%self.filename
3014 print "Setting the file: %s"%self.filename
3011
3015
3012 return 1
3016 return 1
3013
3017
3014 def readHeader(self):
3018 def readHeader(self):
3015 headerObj = self.fitsObj[0]
3019 headerObj = self.fitsObj[0]
3016
3020
3017 self.header_dict = headerObj.header
3021 self.header_dict = headerObj.header
3018 self.expName = headerObj.header['EXPNAME']
3022 self.expName = headerObj.header['EXPNAME']
3019 self.datetimestr = headerObj.header['DATETIME']
3023 self.datetimestr = headerObj.header['DATETIME']
3020 struct_time = time.strptime(headerObj.header['DATETIME'], "%b %d %Y %H:%M:%S")
3024 struct_time = time.strptime(headerObj.header['DATETIME'], "%b %d %Y %H:%M:%S")
3021 # self.utc = time.mktime(struct_time) - self.__TIMEZONE
3025 # self.utc = time.mktime(struct_time) - self.__TIMEZONE
3022 self.nChannels = headerObj.header['NCHANNEL']
3026 self.nChannels = headerObj.header['NCHANNEL']
3023 self.nSamples = headerObj.header['NSAMPLE']
3027 self.nSamples = headerObj.header['NSAMPLE']
3024 self.dataBlocksPerFile = headerObj.header['NBLOCK']
3028 self.dataBlocksPerFile = headerObj.header['NBLOCK']
3025 self.comments = headerObj.header['COMMENT']
3029 self.comments = headerObj.header['COMMENT']
3026
3030
3027
3031
3028 def setNextFile(self):
3032 def setNextFile(self):
3029
3033
3030 if self.online:
3034 if self.online:
3031 newFile = self.__setNextFileOnline()
3035 newFile = self.__setNextFileOnline()
3032 else:
3036 else:
3033 newFile = self.__setNextFileOffline()
3037 newFile = self.__setNextFileOffline()
3034
3038
3035 if not(newFile):
3039 if not(newFile):
3036 return 0
3040 return 0
3037
3041
3038 self.readHeader()
3042 self.readHeader()
3039
3043
3040 self.nReadBlocks = 0
3044 self.nReadBlocks = 0
3041 self.blockIndex = 1
3045 self.blockIndex = 1
3042 return 1
3046 return 1
3043
3047
3044 def __searchFilesOffLine(self,
3048 def __searchFilesOffLine(self,
3045 path,
3049 path,
3046 startDate,
3050 startDate,
3047 endDate,
3051 endDate,
3048 startTime=datetime.time(0,0,0),
3052 startTime=datetime.time(0,0,0),
3049 endTime=datetime.time(23,59,59),
3053 endTime=datetime.time(23,59,59),
3050 set=None,
3054 set=None,
3051 expLabel='',
3055 expLabel='',
3052 ext='.fits',
3056 ext='.fits',
3053 walk=True):
3057 walk=True):
3054
3058
3055 pathList = []
3059 pathList = []
3056
3060
3057 if not walk:
3061 if not walk:
3058 pathList.append(path)
3062 pathList.append(path)
3059
3063
3060 else:
3064 else:
3061 dirList = []
3065 dirList = []
3062 for thisPath in os.listdir(path):
3066 for thisPath in os.listdir(path):
3063 if not os.path.isdir(os.path.join(path,thisPath)):
3067 if not os.path.isdir(os.path.join(path,thisPath)):
3064 continue
3068 continue
3065 if not isDoyFolder(thisPath):
3069 if not isDoyFolder(thisPath):
3066 continue
3070 continue
3067
3071
3068 dirList.append(thisPath)
3072 dirList.append(thisPath)
3069
3073
3070 if not(dirList):
3074 if not(dirList):
3071 return None, None
3075 return None, None
3072
3076
3073 thisDate = startDate
3077 thisDate = startDate
3074
3078
3075 while(thisDate <= endDate):
3079 while(thisDate <= endDate):
3076 year = thisDate.timetuple().tm_year
3080 year = thisDate.timetuple().tm_year
3077 doy = thisDate.timetuple().tm_yday
3081 doy = thisDate.timetuple().tm_yday
3078
3082
3079 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
3083 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
3080 if len(matchlist) == 0:
3084 if len(matchlist) == 0:
3081 thisDate += datetime.timedelta(1)
3085 thisDate += datetime.timedelta(1)
3082 continue
3086 continue
3083 for match in matchlist:
3087 for match in matchlist:
3084 pathList.append(os.path.join(path,match,expLabel))
3088 pathList.append(os.path.join(path,match,expLabel))
3085
3089
3086 thisDate += datetime.timedelta(1)
3090 thisDate += datetime.timedelta(1)
3087
3091
3088 if pathList == []:
3092 if pathList == []:
3089 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
3093 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
3090 return None, None
3094 return None, None
3091
3095
3092 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
3096 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
3093
3097
3094 filenameList = []
3098 filenameList = []
3095 datetimeList = []
3099 datetimeList = []
3096
3100
3097 for i in range(len(pathList)):
3101 for i in range(len(pathList)):
3098
3102
3099 thisPath = pathList[i]
3103 thisPath = pathList[i]
3100
3104
3101 fileList = glob.glob1(thisPath, "*%s" %ext)
3105 fileList = glob.glob1(thisPath, "*%s" %ext)
3102 fileList.sort()
3106 fileList.sort()
3103
3107
3104 for file in fileList:
3108 for file in fileList:
3105
3109
3106 filename = os.path.join(thisPath,file)
3110 filename = os.path.join(thisPath,file)
3107 thisDatetime = self.isFileinThisTime(filename, startTime, endTime, useLocalTime=True)
3111 thisDatetime = self.isFileinThisTime(filename, startTime, endTime, useLocalTime=True)
3108
3112
3109 if not(thisDatetime):
3113 if not(thisDatetime):
3110 continue
3114 continue
3111
3115
3112 filenameList.append(filename)
3116 filenameList.append(filename)
3113 datetimeList.append(thisDatetime)
3117 datetimeList.append(thisDatetime)
3114
3118
3115 if not(filenameList):
3119 if not(filenameList):
3116 print "Any file was found for the time range %s - %s" %(startTime, endTime)
3120 print "Any file was found for the time range %s - %s" %(startTime, endTime)
3117 return None, None
3121 return None, None
3118
3122
3119 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
3123 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
3120 print
3124 print
3121
3125
3122 for i in range(len(filenameList)):
3126 for i in range(len(filenameList)):
3123 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
3127 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
3124
3128
3125 self.filenameList = filenameList
3129 self.filenameList = filenameList
3126 self.datetimeList = datetimeList
3130 self.datetimeList = datetimeList
3127
3131
3128 return pathList, filenameList
3132 return pathList, filenameList
3129
3133
3130 def setup(self, path=None,
3134 def setup(self, path=None,
3131 startDate=None,
3135 startDate=None,
3132 endDate=None,
3136 endDate=None,
3133 startTime=datetime.time(0,0,0),
3137 startTime=datetime.time(0,0,0),
3134 endTime=datetime.time(23,59,59),
3138 endTime=datetime.time(23,59,59),
3135 set=0,
3139 set=0,
3136 expLabel = "",
3140 expLabel = "",
3137 ext = None,
3141 ext = None,
3138 online = False,
3142 online = False,
3139 delay = 60,
3143 delay = 60,
3140 walk = True):
3144 walk = True):
3141
3145
3142 if path == None:
3146 if path == None:
3143 raise ValueError, "The path is not valid"
3147 raise ValueError, "The path is not valid"
3144
3148
3145 if ext == None:
3149 if ext == None:
3146 ext = self.ext
3150 ext = self.ext
3147
3151
3148 if not(online):
3152 if not(online):
3149 print "Searching files in offline mode ..."
3153 print "Searching files in offline mode ..."
3150 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
3154 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
3151 startTime=startTime, endTime=endTime,
3155 startTime=startTime, endTime=endTime,
3152 set=set, expLabel=expLabel, ext=ext,
3156 set=set, expLabel=expLabel, ext=ext,
3153 walk=walk)
3157 walk=walk)
3154
3158
3155 if not(pathList):
3159 if not(pathList):
3156 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
3160 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
3157 datetime.datetime.combine(startDate,startTime).ctime(),
3161 datetime.datetime.combine(startDate,startTime).ctime(),
3158 datetime.datetime.combine(endDate,endTime).ctime())
3162 datetime.datetime.combine(endDate,endTime).ctime())
3159
3163
3160 sys.exit(-1)
3164 sys.exit(-1)
3161
3165
3162 self.fileIndex = -1
3166 self.fileIndex = -1
3163 self.pathList = pathList
3167 self.pathList = pathList
3164 self.filenameList = filenameList
3168 self.filenameList = filenameList
3165
3169
3166 self.online = online
3170 self.online = online
3167 self.delay = delay
3171 self.delay = delay
3168 ext = ext.lower()
3172 ext = ext.lower()
3169 self.ext = ext
3173 self.ext = ext
3170
3174
3171 if not(self.setNextFile()):
3175 if not(self.setNextFile()):
3172 if (startDate!=None) and (endDate!=None):
3176 if (startDate!=None) and (endDate!=None):
3173 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
3177 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
3174 elif startDate != None:
3178 elif startDate != None:
3175 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
3179 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
3176 else:
3180 else:
3177 print "No files"
3181 print "No files"
3178
3182
3179 sys.exit(-1)
3183 sys.exit(-1)
3180
3184
3181
3185
3182
3186
3183 def readBlock(self):
3187 def readBlock(self):
3184 dataObj = self.fitsObj[self.blockIndex]
3188 dataObj = self.fitsObj[self.blockIndex]
3185
3189
3186 self.data = dataObj.data
3190 self.data = dataObj.data
3187 self.data_header_dict = dataObj.header
3191 self.data_header_dict = dataObj.header
3188 self.utc = self.data_header_dict['UTCTIME']
3192 self.utc = self.data_header_dict['UTCTIME']
3189
3193
3190 self.flagIsNewFile = 0
3194 self.flagIsNewFile = 0
3191 self.blockIndex += 1
3195 self.blockIndex += 1
3192 self.nTotalBlocks += 1
3196 self.nTotalBlocks += 1
3193 self.nReadBlocks += 1
3197 self.nReadBlocks += 1
3194
3198
3195 return 1
3199 return 1
3196
3200
3197 def __jumpToLastBlock(self):
3201 def __jumpToLastBlock(self):
3198 raise ValueError, "No implemented"
3202 raise ValueError, "No implemented"
3199
3203
3200 def __waitNewBlock(self):
3204 def __waitNewBlock(self):
3201 """
3205 """
3202 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
3206 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
3203
3207
3204 Si el modo de lectura es OffLine siempre retorn 0
3208 Si el modo de lectura es OffLine siempre retorn 0
3205 """
3209 """
3206 if not self.online:
3210 if not self.online:
3207 return 0
3211 return 0
3208
3212
3209 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
3213 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
3210 return 0
3214 return 0
3211
3215
3212 currentPointer = self.fp.tell()
3216 currentPointer = self.fp.tell()
3213
3217
3214 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
3218 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
3215
3219
3216 for nTries in range( self.nTries ):
3220 for nTries in range( self.nTries ):
3217
3221
3218 self.fp.close()
3222 self.fp.close()
3219 self.fp = open( self.filename, 'rb' )
3223 self.fp = open( self.filename, 'rb' )
3220 self.fp.seek( currentPointer )
3224 self.fp.seek( currentPointer )
3221
3225
3222 self.fileSize = os.path.getsize( self.filename )
3226 self.fileSize = os.path.getsize( self.filename )
3223 currentSize = self.fileSize - currentPointer
3227 currentSize = self.fileSize - currentPointer
3224
3228
3225 if ( currentSize >= neededSize ):
3229 if ( currentSize >= neededSize ):
3226 self.__rdBasicHeader()
3230 self.__rdBasicHeader()
3227 return 1
3231 return 1
3228
3232
3229 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
3233 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
3230 time.sleep( self.delay )
3234 time.sleep( self.delay )
3231
3235
3232
3236
3233 return 0
3237 return 0
3234
3238
3235 def __setNewBlock(self):
3239 def __setNewBlock(self):
3236
3240
3237 if self.online:
3241 if self.online:
3238 self.__jumpToLastBlock()
3242 self.__jumpToLastBlock()
3239
3243
3240 if self.flagIsNewFile:
3244 if self.flagIsNewFile:
3241 return 1
3245 return 1
3242
3246
3243 self.lastUTTime = self.utc
3247 self.lastUTTime = self.utc
3244
3248
3245 if self.online:
3249 if self.online:
3246 if self.__waitNewBlock():
3250 if self.__waitNewBlock():
3247 return 1
3251 return 1
3248
3252
3249 if self.nReadBlocks < self.dataBlocksPerFile:
3253 if self.nReadBlocks < self.dataBlocksPerFile:
3250 return 1
3254 return 1
3251
3255
3252 if not(self.setNextFile()):
3256 if not(self.setNextFile()):
3253 return 0
3257 return 0
3254
3258
3255 deltaTime = self.utc - self.lastUTTime
3259 deltaTime = self.utc - self.lastUTTime
3256
3260
3257 self.flagTimeBlock = 0
3261 self.flagTimeBlock = 0
3258
3262
3259 if deltaTime > self.maxTimeStep:
3263 if deltaTime > self.maxTimeStep:
3260 self.flagTimeBlock = 1
3264 self.flagTimeBlock = 1
3261
3265
3262 return 1
3266 return 1
3263
3267
3264
3268
3265 def readNextBlock(self):
3269 def readNextBlock(self):
3266 if not(self.__setNewBlock()):
3270 if not(self.__setNewBlock()):
3267 return 0
3271 return 0
3268
3272
3269 if not(self.readBlock()):
3273 if not(self.readBlock()):
3270 return 0
3274 return 0
3271
3275
3272 return 1
3276 return 1
3273
3277
3274
3278
3275 def getData(self):
3279 def getData(self):
3276
3280
3277 if self.flagNoMoreFiles:
3281 if self.flagNoMoreFiles:
3278 self.dataOut.flagNoData = True
3282 self.dataOut.flagNoData = True
3279 print 'Process finished'
3283 print 'Process finished'
3280 return 0
3284 return 0
3281
3285
3282 self.flagTimeBlock = 0
3286 self.flagTimeBlock = 0
3283 self.flagIsNewBlock = 0
3287 self.flagIsNewBlock = 0
3284
3288
3285 if not(self.readNextBlock()):
3289 if not(self.readNextBlock()):
3286 return 0
3290 return 0
3287
3291
3288 if self.data == None:
3292 if self.data == None:
3289 self.dataOut.flagNoData = True
3293 self.dataOut.flagNoData = True
3290 return 0
3294 return 0
3291
3295
3292 self.dataOut.data = self.data
3296 self.dataOut.data = self.data
3293 self.dataOut.data_header = self.data_header_dict
3297 self.dataOut.data_header = self.data_header_dict
3294 self.dataOut.utctime = self.utc
3298 self.dataOut.utctime = self.utc
3295
3299
3296 self.dataOut.header = self.header_dict
3300 self.dataOut.header = self.header_dict
3297 self.dataOut.expName = self.expName
3301 self.dataOut.expName = self.expName
3298 self.dataOut.nChannels = self.nChannels
3302 self.dataOut.nChannels = self.nChannels
3299 self.dataOut.nSamples = self.nSamples
3303 self.dataOut.nSamples = self.nSamples
3300 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
3304 self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile
3301 self.dataOut.comments = self.comments
3305 self.dataOut.comments = self.comments
3302
3306
3303 self.dataOut.flagNoData = False
3307 self.dataOut.flagNoData = False
3304
3308
3305 return self.dataOut.data
3309 return self.dataOut.data
3306
3310
3307 def run(self, **kwargs):
3311 def run(self, **kwargs):
3308
3312
3309 if not(self.isConfig):
3313 if not(self.isConfig):
3310 self.setup(**kwargs)
3314 self.setup(**kwargs)
3311 self.isConfig = True
3315 self.isConfig = True
3312
3316
3313 self.getData() No newline at end of file
3317 self.getData()
@@ -1,1343 +1,1354
1 import numpy
1 import numpy
2 import time, datetime, os
2 import time, datetime, os
3 from graphics.figure import *
3 from graphics.figure import *
4 def isRealtime(utcdatatime):
5 utcnow = time.mktime(datetime.datetime.utcnow().timetuple())
6 delta = utcnow - utcdatatime # abs
7 if delta >= 5*60.:
8 return False
9 return True
4
10
5 class CrossSpectraPlot(Figure):
11 class CrossSpectraPlot(Figure):
6
12
7 __isConfig = None
13 __isConfig = None
8 __nsubplots = None
14 __nsubplots = None
9
15
10 WIDTH = None
16 WIDTH = None
11 HEIGHT = None
17 HEIGHT = None
12 WIDTHPROF = None
18 WIDTHPROF = None
13 HEIGHTPROF = None
19 HEIGHTPROF = None
14 PREFIX = 'cspc'
20 PREFIX = 'cspc'
15
21
16 def __init__(self):
22 def __init__(self):
17
23
18 self.__isConfig = False
24 self.__isConfig = False
19 self.__nsubplots = 4
25 self.__nsubplots = 4
20
26
21 self.WIDTH = 250
27 self.WIDTH = 250
22 self.HEIGHT = 250
28 self.HEIGHT = 250
23 self.WIDTHPROF = 0
29 self.WIDTHPROF = 0
24 self.HEIGHTPROF = 0
30 self.HEIGHTPROF = 0
25
31
26 def getSubplots(self):
32 def getSubplots(self):
27
33
28 ncol = 4
34 ncol = 4
29 nrow = self.nplots
35 nrow = self.nplots
30
36
31 return nrow, ncol
37 return nrow, ncol
32
38
33 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
39 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
34
40
35 self.__showprofile = showprofile
41 self.__showprofile = showprofile
36 self.nplots = nplots
42 self.nplots = nplots
37
43
38 ncolspan = 1
44 ncolspan = 1
39 colspan = 1
45 colspan = 1
40
46
41 self.createFigure(idfigure = idfigure,
47 self.createFigure(idfigure = idfigure,
42 wintitle = wintitle,
48 wintitle = wintitle,
43 widthplot = self.WIDTH + self.WIDTHPROF,
49 widthplot = self.WIDTH + self.WIDTHPROF,
44 heightplot = self.HEIGHT + self.HEIGHTPROF,
50 heightplot = self.HEIGHT + self.HEIGHTPROF,
45 show=True)
51 show=True)
46
52
47 nrow, ncol = self.getSubplots()
53 nrow, ncol = self.getSubplots()
48
54
49 counter = 0
55 counter = 0
50 for y in range(nrow):
56 for y in range(nrow):
51 for x in range(ncol):
57 for x in range(ncol):
52 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
53
59
54 counter += 1
60 counter += 1
55
61
56 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
62 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
57 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
58 save=False, figpath='./', figfile=None,
64 save=False, figpath='./', figfile=None,
59 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
65 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
60
66
61 """
67 """
62
68
63 Input:
69 Input:
64 dataOut :
70 dataOut :
65 idfigure :
71 idfigure :
66 wintitle :
72 wintitle :
67 channelList :
73 channelList :
68 showProfile :
74 showProfile :
69 xmin : None,
75 xmin : None,
70 xmax : None,
76 xmax : None,
71 ymin : None,
77 ymin : None,
72 ymax : None,
78 ymax : None,
73 zmin : None,
79 zmin : None,
74 zmax : None
80 zmax : None
75 """
81 """
76
82
77 if pairsList == None:
83 if pairsList == None:
78 pairsIndexList = dataOut.pairsIndexList
84 pairsIndexList = dataOut.pairsIndexList
79 else:
85 else:
80 pairsIndexList = []
86 pairsIndexList = []
81 for pair in pairsList:
87 for pair in pairsList:
82 if pair not in dataOut.pairsList:
88 if pair not in dataOut.pairsList:
83 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
89 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
84 pairsIndexList.append(dataOut.pairsList.index(pair))
90 pairsIndexList.append(dataOut.pairsList.index(pair))
85
91
86 if pairsIndexList == []:
92 if pairsIndexList == []:
87 return
93 return
88
94
89 if len(pairsIndexList) > 4:
95 if len(pairsIndexList) > 4:
90 pairsIndexList = pairsIndexList[0:4]
96 pairsIndexList = pairsIndexList[0:4]
91 factor = dataOut.normFactor
97 factor = dataOut.normFactor
92 x = dataOut.getVelRange(1)
98 x = dataOut.getVelRange(1)
93 y = dataOut.getHeiRange()
99 y = dataOut.getHeiRange()
94 z = dataOut.data_spc[:,:,:]/factor
100 z = dataOut.data_spc[:,:,:]/factor
95 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
101 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
96 avg = numpy.abs(numpy.average(z, axis=1))
102 avg = numpy.abs(numpy.average(z, axis=1))
97 noise = dataOut.getNoise()/factor
103 noise = dataOut.getNoise()/factor
98
104
99 zdB = 10*numpy.log10(z)
105 zdB = 10*numpy.log10(z)
100 avgdB = 10*numpy.log10(avg)
106 avgdB = 10*numpy.log10(avg)
101 noisedB = 10*numpy.log10(noise)
107 noisedB = 10*numpy.log10(noise)
102
108
103
109
104 thisDatetime = dataOut.datatime
110 thisDatetime = dataOut.datatime
105 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
111 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
106 xlabel = "Velocity (m/s)"
112 xlabel = "Velocity (m/s)"
107 ylabel = "Range (Km)"
113 ylabel = "Range (Km)"
108
114
109 if not self.__isConfig:
115 if not self.__isConfig:
110
116
111 nplots = len(pairsIndexList)
117 nplots = len(pairsIndexList)
112
118
113 self.setup(idfigure=idfigure,
119 self.setup(idfigure=idfigure,
114 nplots=nplots,
120 nplots=nplots,
115 wintitle=wintitle,
121 wintitle=wintitle,
116 showprofile=showprofile,
122 showprofile=showprofile,
117 show=show)
123 show=show)
118
124
119 if xmin == None: xmin = numpy.nanmin(x)
125 if xmin == None: xmin = numpy.nanmin(x)
120 if xmax == None: xmax = numpy.nanmax(x)
126 if xmax == None: xmax = numpy.nanmax(x)
121 if ymin == None: ymin = numpy.nanmin(y)
127 if ymin == None: ymin = numpy.nanmin(y)
122 if ymax == None: ymax = numpy.nanmax(y)
128 if ymax == None: ymax = numpy.nanmax(y)
123 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
129 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
124 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
130 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
125
131
126 self.__isConfig = True
132 self.__isConfig = True
127
133
128 self.setWinTitle(title)
134 self.setWinTitle(title)
129
135
130 for i in range(self.nplots):
136 for i in range(self.nplots):
131 pair = dataOut.pairsList[pairsIndexList[i]]
137 pair = dataOut.pairsList[pairsIndexList[i]]
132
138
133 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
139 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
134 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
135 axes0 = self.axesList[i*self.__nsubplots]
141 axes0 = self.axesList[i*self.__nsubplots]
136 axes0.pcolor(x, y, zdB,
142 axes0.pcolor(x, y, zdB,
137 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
138 xlabel=xlabel, ylabel=ylabel, title=title,
144 xlabel=xlabel, ylabel=ylabel, title=title,
139 ticksize=9, colormap=power_cmap, cblabel='')
145 ticksize=9, colormap=power_cmap, cblabel='')
140
146
141 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
147 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
142 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
148 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
143 axes0 = self.axesList[i*self.__nsubplots+1]
149 axes0 = self.axesList[i*self.__nsubplots+1]
144 axes0.pcolor(x, y, zdB,
150 axes0.pcolor(x, y, zdB,
145 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
151 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
146 xlabel=xlabel, ylabel=ylabel, title=title,
152 xlabel=xlabel, ylabel=ylabel, title=title,
147 ticksize=9, colormap=power_cmap, cblabel='')
153 ticksize=9, colormap=power_cmap, cblabel='')
148
154
149 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
155 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
150 coherence = numpy.abs(coherenceComplex)
156 coherence = numpy.abs(coherenceComplex)
151 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
157 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
152 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
158 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
153
159
154 title = "Coherence %d%d" %(pair[0], pair[1])
160 title = "Coherence %d%d" %(pair[0], pair[1])
155 axes0 = self.axesList[i*self.__nsubplots+2]
161 axes0 = self.axesList[i*self.__nsubplots+2]
156 axes0.pcolor(x, y, coherence,
162 axes0.pcolor(x, y, coherence,
157 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
158 xlabel=xlabel, ylabel=ylabel, title=title,
164 xlabel=xlabel, ylabel=ylabel, title=title,
159 ticksize=9, colormap=coherence_cmap, cblabel='')
165 ticksize=9, colormap=coherence_cmap, cblabel='')
160
166
161 title = "Phase %d%d" %(pair[0], pair[1])
167 title = "Phase %d%d" %(pair[0], pair[1])
162 axes0 = self.axesList[i*self.__nsubplots+3]
168 axes0 = self.axesList[i*self.__nsubplots+3]
163 axes0.pcolor(x, y, phase,
169 axes0.pcolor(x, y, phase,
164 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
170 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
165 xlabel=xlabel, ylabel=ylabel, title=title,
171 xlabel=xlabel, ylabel=ylabel, title=title,
166 ticksize=9, colormap=phase_cmap, cblabel='')
172 ticksize=9, colormap=phase_cmap, cblabel='')
167
173
168
174
169
175
170 self.draw()
176 self.draw()
171
177
172 if save:
178 if save:
173 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
179 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
174 if figfile == None:
180 if figfile == None:
175 figfile = self.getFilename(name = date)
181 figfile = self.getFilename(name = date)
176
182
177 self.saveFigure(figpath, figfile)
183 self.saveFigure(figpath, figfile)
178
184
179
185
180 class RTIPlot(Figure):
186 class RTIPlot(Figure):
181
187
182 __isConfig = None
188 __isConfig = None
183 __nsubplots = None
189 __nsubplots = None
184
190
185 WIDTHPROF = None
191 WIDTHPROF = None
186 HEIGHTPROF = None
192 HEIGHTPROF = None
187 PREFIX = 'rti'
193 PREFIX = 'rti'
188
194
189 def __init__(self):
195 def __init__(self):
190
196
191 self.timerange = 2*60*60
197 self.timerange = 2*60*60
192 self.__isConfig = False
198 self.__isConfig = False
193 self.__nsubplots = 1
199 self.__nsubplots = 1
194
200
195 self.WIDTH = 800
201 self.WIDTH = 800
196 self.HEIGHT = 150
202 self.HEIGHT = 150
197 self.WIDTHPROF = 120
203 self.WIDTHPROF = 120
198 self.HEIGHTPROF = 0
204 self.HEIGHTPROF = 0
199 self.counterftp = 0
205 self.counterftp = 0
200
206
201 def getSubplots(self):
207 def getSubplots(self):
202
208
203 ncol = 1
209 ncol = 1
204 nrow = self.nplots
210 nrow = self.nplots
205
211
206 return nrow, ncol
212 return nrow, ncol
207
213
208 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
214 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
209
215
210 self.__showprofile = showprofile
216 self.__showprofile = showprofile
211 self.nplots = nplots
217 self.nplots = nplots
212
218
213 ncolspan = 1
219 ncolspan = 1
214 colspan = 1
220 colspan = 1
215 if showprofile:
221 if showprofile:
216 ncolspan = 7
222 ncolspan = 7
217 colspan = 6
223 colspan = 6
218 self.__nsubplots = 2
224 self.__nsubplots = 2
219
225
220 self.createFigure(idfigure = idfigure,
226 self.createFigure(idfigure = idfigure,
221 wintitle = wintitle,
227 wintitle = wintitle,
222 widthplot = self.WIDTH + self.WIDTHPROF,
228 widthplot = self.WIDTH + self.WIDTHPROF,
223 heightplot = self.HEIGHT + self.HEIGHTPROF,
229 heightplot = self.HEIGHT + self.HEIGHTPROF,
224 show=show)
230 show=show)
225
231
226 nrow, ncol = self.getSubplots()
232 nrow, ncol = self.getSubplots()
227
233
228 counter = 0
234 counter = 0
229 for y in range(nrow):
235 for y in range(nrow):
230 for x in range(ncol):
236 for x in range(ncol):
231
237
232 if counter >= self.nplots:
238 if counter >= self.nplots:
233 break
239 break
234
240
235 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
241 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
236
242
237 if showprofile:
243 if showprofile:
238 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
244 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
239
245
240 counter += 1
246 counter += 1
241
247
242 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
248 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
243 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
249 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
244 timerange=None,
250 timerange=None,
245 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
251 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
246
252
247 """
253 """
248
254
249 Input:
255 Input:
250 dataOut :
256 dataOut :
251 idfigure :
257 idfigure :
252 wintitle :
258 wintitle :
253 channelList :
259 channelList :
254 showProfile :
260 showProfile :
255 xmin : None,
261 xmin : None,
256 xmax : None,
262 xmax : None,
257 ymin : None,
263 ymin : None,
258 ymax : None,
264 ymax : None,
259 zmin : None,
265 zmin : None,
260 zmax : None
266 zmax : None
261 """
267 """
262
268
263 if channelList == None:
269 if channelList == None:
264 channelIndexList = dataOut.channelIndexList
270 channelIndexList = dataOut.channelIndexList
265 else:
271 else:
266 channelIndexList = []
272 channelIndexList = []
267 for channel in channelList:
273 for channel in channelList:
268 if channel not in dataOut.channelList:
274 if channel not in dataOut.channelList:
269 raise ValueError, "Channel %d is not in dataOut.channelList"
275 raise ValueError, "Channel %d is not in dataOut.channelList"
270 channelIndexList.append(dataOut.channelList.index(channel))
276 channelIndexList.append(dataOut.channelList.index(channel))
271
277
272 if timerange != None:
278 if timerange != None:
273 self.timerange = timerange
279 self.timerange = timerange
274
280
275 tmin = None
281 tmin = None
276 tmax = None
282 tmax = None
277 factor = dataOut.normFactor
283 factor = dataOut.normFactor
278 x = dataOut.getTimeRange()
284 x = dataOut.getTimeRange()
279 y = dataOut.getHeiRange()
285 y = dataOut.getHeiRange()
280
286
281 z = dataOut.data_spc[channelIndexList,:,:]/factor
287 z = dataOut.data_spc[channelIndexList,:,:]/factor
282 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
288 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
283 avg = numpy.average(z, axis=1)
289 avg = numpy.average(z, axis=1)
284
290
285 avgdB = 10.*numpy.log10(avg)
291 avgdB = 10.*numpy.log10(avg)
286
292
287
293
288 thisDatetime = dataOut.datatime
294 thisDatetime = dataOut.datatime
289 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
295 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
290 xlabel = ""
296 xlabel = ""
291 ylabel = "Range (Km)"
297 ylabel = "Range (Km)"
292
298
293 if not self.__isConfig:
299 if not self.__isConfig:
294
300
295 nplots = len(channelIndexList)
301 nplots = len(channelIndexList)
296
302
297 self.setup(idfigure=idfigure,
303 self.setup(idfigure=idfigure,
298 nplots=nplots,
304 nplots=nplots,
299 wintitle=wintitle,
305 wintitle=wintitle,
300 showprofile=showprofile,
306 showprofile=showprofile,
301 show=show)
307 show=show)
302
308
303 tmin, tmax = self.getTimeLim(x, xmin, xmax)
309 tmin, tmax = self.getTimeLim(x, xmin, xmax)
304 if ymin == None: ymin = numpy.nanmin(y)
310 if ymin == None: ymin = numpy.nanmin(y)
305 if ymax == None: ymax = numpy.nanmax(y)
311 if ymax == None: ymax = numpy.nanmax(y)
306 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
312 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
307 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
313 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
308
314
309 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
315 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
310 self.__isConfig = True
316 self.__isConfig = True
311
317
312
318
313 self.setWinTitle(title)
319 self.setWinTitle(title)
314
320
315 for i in range(self.nplots):
321 for i in range(self.nplots):
316 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
322 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
317 axes = self.axesList[i*self.__nsubplots]
323 axes = self.axesList[i*self.__nsubplots]
318 zdB = avgdB[i].reshape((1,-1))
324 zdB = avgdB[i].reshape((1,-1))
319 axes.pcolorbuffer(x, y, zdB,
325 axes.pcolorbuffer(x, y, zdB,
320 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
326 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
321 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
327 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
322 ticksize=9, cblabel='', cbsize="1%")
328 ticksize=9, cblabel='', cbsize="1%")
323
329
324 if self.__showprofile:
330 if self.__showprofile:
325 axes = self.axesList[i*self.__nsubplots +1]
331 axes = self.axesList[i*self.__nsubplots +1]
326 axes.pline(avgdB[i], y,
332 axes.pline(avgdB[i], y,
327 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
333 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
328 xlabel='dB', ylabel='', title='',
334 xlabel='dB', ylabel='', title='',
329 ytick_visible=False,
335 ytick_visible=False,
330 grid='x')
336 grid='x')
331
337
332 self.draw()
338 self.draw()
333
339
334 if save:
340 if save:
335
341
336 if figfile == None:
342 if figfile == None:
337 figfile = self.getFilename(name = self.name)
343 figfile = self.getFilename(name = self.name)
338
344
339 self.saveFigure(figpath, figfile)
345 self.saveFigure(figpath, figfile)
340
346
341 self.counterftp += 1
347 self.counterftp += 1
342 if (ftp and (self.counterftp==ftpratio)):
348 if (ftp and (self.counterftp==ftpratio)):
343 figfilename = os.path.join(figpath,figfile)
349 figfilename = os.path.join(figpath,figfile)
344 self.sendByFTP(figfilename)
350 self.sendByFTP(figfilename)
345 self.counterftp = 0
351 self.counterftp = 0
346
352
347 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
353 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
348 self.__isConfig = False
354 self.__isConfig = False
349
355
350 class SpectraPlot(Figure):
356 class SpectraPlot(Figure):
351
357
352 __isConfig = None
358 __isConfig = None
353 __nsubplots = None
359 __nsubplots = None
354
360
355 WIDTHPROF = None
361 WIDTHPROF = None
356 HEIGHTPROF = None
362 HEIGHTPROF = None
357 PREFIX = 'spc'
363 PREFIX = 'spc'
358
364
359 def __init__(self):
365 def __init__(self):
360
366
361 self.__isConfig = False
367 self.__isConfig = False
362 self.__nsubplots = 1
368 self.__nsubplots = 1
363
369
364 self.WIDTH = 230
370 self.WIDTH = 230
365 self.HEIGHT = 250
371 self.HEIGHT = 250
366 self.WIDTHPROF = 120
372 self.WIDTHPROF = 120
367 self.HEIGHTPROF = 0
373 self.HEIGHTPROF = 0
368
374
369 def getSubplots(self):
375 def getSubplots(self):
370
376
371 ncol = int(numpy.sqrt(self.nplots)+0.9)
377 ncol = int(numpy.sqrt(self.nplots)+0.9)
372 nrow = int(self.nplots*1./ncol + 0.9)
378 nrow = int(self.nplots*1./ncol + 0.9)
373
379
374 return nrow, ncol
380 return nrow, ncol
375
381
376 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
382 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
377
383
378 self.__showprofile = showprofile
384 self.__showprofile = showprofile
379 self.nplots = nplots
385 self.nplots = nplots
380
386
381 ncolspan = 1
387 ncolspan = 1
382 colspan = 1
388 colspan = 1
383 if showprofile:
389 if showprofile:
384 ncolspan = 3
390 ncolspan = 3
385 colspan = 2
391 colspan = 2
386 self.__nsubplots = 2
392 self.__nsubplots = 2
387
393
388 self.createFigure(idfigure = idfigure,
394 self.createFigure(idfigure = idfigure,
389 wintitle = wintitle,
395 wintitle = wintitle,
390 widthplot = self.WIDTH + self.WIDTHPROF,
396 widthplot = self.WIDTH + self.WIDTHPROF,
391 heightplot = self.HEIGHT + self.HEIGHTPROF,
397 heightplot = self.HEIGHT + self.HEIGHTPROF,
392 show=show)
398 show=show)
393
399
394 nrow, ncol = self.getSubplots()
400 nrow, ncol = self.getSubplots()
395
401
396 counter = 0
402 counter = 0
397 for y in range(nrow):
403 for y in range(nrow):
398 for x in range(ncol):
404 for x in range(ncol):
399
405
400 if counter >= self.nplots:
406 if counter >= self.nplots:
401 break
407 break
402
408
403 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
409 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
404
410
405 if showprofile:
411 if showprofile:
406 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
412 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
407
413
408 counter += 1
414 counter += 1
409
415
410 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
416 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
411 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
417 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
412 save=False, figpath='./', figfile=None, show=True):
418 save=False, figpath='./', figfile=None, show=True):
413
419
414 """
420 """
415
421
416 Input:
422 Input:
417 dataOut :
423 dataOut :
418 idfigure :
424 idfigure :
419 wintitle :
425 wintitle :
420 channelList :
426 channelList :
421 showProfile :
427 showProfile :
422 xmin : None,
428 xmin : None,
423 xmax : None,
429 xmax : None,
424 ymin : None,
430 ymin : None,
425 ymax : None,
431 ymax : None,
426 zmin : None,
432 zmin : None,
427 zmax : None
433 zmax : None
428 """
434 """
429
435
430 if channelList == None:
436 if channelList == None:
431 channelIndexList = dataOut.channelIndexList
437 channelIndexList = dataOut.channelIndexList
432 else:
438 else:
433 channelIndexList = []
439 channelIndexList = []
434 for channel in channelList:
440 for channel in channelList:
435 if channel not in dataOut.channelList:
441 if channel not in dataOut.channelList:
436 raise ValueError, "Channel %d is not in dataOut.channelList"
442 raise ValueError, "Channel %d is not in dataOut.channelList"
437 channelIndexList.append(dataOut.channelList.index(channel))
443 channelIndexList.append(dataOut.channelList.index(channel))
438 factor = dataOut.normFactor
444 factor = dataOut.normFactor
439 x = dataOut.getVelRange(1)
445 x = dataOut.getVelRange(1)
440 y = dataOut.getHeiRange()
446 y = dataOut.getHeiRange()
441
447
442 z = dataOut.data_spc[channelIndexList,:,:]/factor
448 z = dataOut.data_spc[channelIndexList,:,:]/factor
443 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
449 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
444 avg = numpy.average(z, axis=1)
450 avg = numpy.average(z, axis=1)
445 noise = dataOut.getNoise()/factor
451 noise = dataOut.getNoise()/factor
446
452
447 zdB = 10*numpy.log10(z)
453 zdB = 10*numpy.log10(z)
448 avgdB = 10*numpy.log10(avg)
454 avgdB = 10*numpy.log10(avg)
449 noisedB = 10*numpy.log10(noise)
455 noisedB = 10*numpy.log10(noise)
450
456
451 thisDatetime = dataOut.datatime
457 thisDatetime = dataOut.datatime
452 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
458 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
453 xlabel = "Velocity (m/s)"
459 xlabel = "Velocity (m/s)"
454 ylabel = "Range (Km)"
460 ylabel = "Range (Km)"
455
461
456 if not self.__isConfig:
462 if not self.__isConfig:
457
463
458 nplots = len(channelIndexList)
464 nplots = len(channelIndexList)
459
465
460 self.setup(idfigure=idfigure,
466 self.setup(idfigure=idfigure,
461 nplots=nplots,
467 nplots=nplots,
462 wintitle=wintitle,
468 wintitle=wintitle,
463 showprofile=showprofile,
469 showprofile=showprofile,
464 show=show)
470 show=show)
465
471
466 if xmin == None: xmin = numpy.nanmin(x)
472 if xmin == None: xmin = numpy.nanmin(x)
467 if xmax == None: xmax = numpy.nanmax(x)
473 if xmax == None: xmax = numpy.nanmax(x)
468 if ymin == None: ymin = numpy.nanmin(y)
474 if ymin == None: ymin = numpy.nanmin(y)
469 if ymax == None: ymax = numpy.nanmax(y)
475 if ymax == None: ymax = numpy.nanmax(y)
470 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
476 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
471 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
477 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
472
478
473 self.__isConfig = True
479 self.__isConfig = True
474
480
475 self.setWinTitle(title)
481 self.setWinTitle(title)
476
482
477 for i in range(self.nplots):
483 for i in range(self.nplots):
478 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
484 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
479 axes = self.axesList[i*self.__nsubplots]
485 axes = self.axesList[i*self.__nsubplots]
480 axes.pcolor(x, y, zdB[i,:,:],
486 axes.pcolor(x, y, zdB[i,:,:],
481 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
487 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
482 xlabel=xlabel, ylabel=ylabel, title=title,
488 xlabel=xlabel, ylabel=ylabel, title=title,
483 ticksize=9, cblabel='')
489 ticksize=9, cblabel='')
484
490
485 if self.__showprofile:
491 if self.__showprofile:
486 axes = self.axesList[i*self.__nsubplots +1]
492 axes = self.axesList[i*self.__nsubplots +1]
487 axes.pline(avgdB[i], y,
493 axes.pline(avgdB[i], y,
488 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
494 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
489 xlabel='dB', ylabel='', title='',
495 xlabel='dB', ylabel='', title='',
490 ytick_visible=False,
496 ytick_visible=False,
491 grid='x')
497 grid='x')
492
498
493 noiseline = numpy.repeat(noisedB[i], len(y))
499 noiseline = numpy.repeat(noisedB[i], len(y))
494 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
500 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
495
501
496 self.draw()
502 self.draw()
497
503
498 if save:
504 if save:
499 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
505 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
500 if figfile == None:
506 if figfile == None:
501 figfile = self.getFilename(name = date)
507 figfile = self.getFilename(name = date)
502
508
503 self.saveFigure(figpath, figfile)
509 self.saveFigure(figpath, figfile)
504
510
505 class Scope(Figure):
511 class Scope(Figure):
506
512
507 __isConfig = None
513 __isConfig = None
508
514
509 def __init__(self):
515 def __init__(self):
510
516
511 self.__isConfig = False
517 self.__isConfig = False
512 self.WIDTH = 600
518 self.WIDTH = 600
513 self.HEIGHT = 200
519 self.HEIGHT = 200
514
520
515 def getSubplots(self):
521 def getSubplots(self):
516
522
517 nrow = self.nplots
523 nrow = self.nplots
518 ncol = 3
524 ncol = 3
519 return nrow, ncol
525 return nrow, ncol
520
526
521 def setup(self, idfigure, nplots, wintitle, show):
527 def setup(self, idfigure, nplots, wintitle, show):
522
528
523 self.nplots = nplots
529 self.nplots = nplots
524
530
525 self.createFigure(idfigure=idfigure,
531 self.createFigure(idfigure=idfigure,
526 wintitle=wintitle,
532 wintitle=wintitle,
527 show=show)
533 show=show)
528
534
529 nrow,ncol = self.getSubplots()
535 nrow,ncol = self.getSubplots()
530 colspan = 3
536 colspan = 3
531 rowspan = 1
537 rowspan = 1
532
538
533 for i in range(nplots):
539 for i in range(nplots):
534 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
540 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
535
541
536
542
537
543
538 def run(self, dataOut, idfigure, wintitle="", channelList=None,
544 def run(self, dataOut, idfigure, wintitle="", channelList=None,
539 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
545 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
540 figpath='./', figfile=None, show=True):
546 figpath='./', figfile=None, show=True):
541
547
542 """
548 """
543
549
544 Input:
550 Input:
545 dataOut :
551 dataOut :
546 idfigure :
552 idfigure :
547 wintitle :
553 wintitle :
548 channelList :
554 channelList :
549 xmin : None,
555 xmin : None,
550 xmax : None,
556 xmax : None,
551 ymin : None,
557 ymin : None,
552 ymax : None,
558 ymax : None,
553 """
559 """
554
560
555 if channelList == None:
561 if channelList == None:
556 channelIndexList = dataOut.channelIndexList
562 channelIndexList = dataOut.channelIndexList
557 else:
563 else:
558 channelIndexList = []
564 channelIndexList = []
559 for channel in channelList:
565 for channel in channelList:
560 if channel not in dataOut.channelList:
566 if channel not in dataOut.channelList:
561 raise ValueError, "Channel %d is not in dataOut.channelList"
567 raise ValueError, "Channel %d is not in dataOut.channelList"
562 channelIndexList.append(dataOut.channelList.index(channel))
568 channelIndexList.append(dataOut.channelList.index(channel))
563
569
564 x = dataOut.heightList
570 x = dataOut.heightList
565 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
571 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
566 y = y.real
572 y = y.real
567
573
568 thisDatetime = dataOut.datatime
574 thisDatetime = dataOut.datatime
569 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
575 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
570 xlabel = "Range (Km)"
576 xlabel = "Range (Km)"
571 ylabel = "Intensity"
577 ylabel = "Intensity"
572
578
573 if not self.__isConfig:
579 if not self.__isConfig:
574 nplots = len(channelIndexList)
580 nplots = len(channelIndexList)
575
581
576 self.setup(idfigure=idfigure,
582 self.setup(idfigure=idfigure,
577 nplots=nplots,
583 nplots=nplots,
578 wintitle=wintitle,
584 wintitle=wintitle,
579 show=show)
585 show=show)
580
586
581 if xmin == None: xmin = numpy.nanmin(x)
587 if xmin == None: xmin = numpy.nanmin(x)
582 if xmax == None: xmax = numpy.nanmax(x)
588 if xmax == None: xmax = numpy.nanmax(x)
583 if ymin == None: ymin = numpy.nanmin(y)
589 if ymin == None: ymin = numpy.nanmin(y)
584 if ymax == None: ymax = numpy.nanmax(y)
590 if ymax == None: ymax = numpy.nanmax(y)
585
591
586 self.__isConfig = True
592 self.__isConfig = True
587
593
588 self.setWinTitle(title)
594 self.setWinTitle(title)
589
595
590 for i in range(len(self.axesList)):
596 for i in range(len(self.axesList)):
591 title = "Channel %d" %(i)
597 title = "Channel %d" %(i)
592 axes = self.axesList[i]
598 axes = self.axesList[i]
593 ychannel = y[i,:]
599 ychannel = y[i,:]
594 axes.pline(x, ychannel,
600 axes.pline(x, ychannel,
595 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
601 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
596 xlabel=xlabel, ylabel=ylabel, title=title)
602 xlabel=xlabel, ylabel=ylabel, title=title)
597
603
598 self.draw()
604 self.draw()
599
605
600 if save:
606 if save:
601 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
607 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
602 if figfile == None:
608 if figfile == None:
603 figfile = self.getFilename(name = date)
609 figfile = self.getFilename(name = date)
604
610
605 self.saveFigure(figpath, figfile)
611 self.saveFigure(figpath, figfile)
606
612
607 class ProfilePlot(Figure):
613 class ProfilePlot(Figure):
608 __isConfig = None
614 __isConfig = None
609 __nsubplots = None
615 __nsubplots = None
610
616
611 WIDTHPROF = None
617 WIDTHPROF = None
612 HEIGHTPROF = None
618 HEIGHTPROF = None
613 PREFIX = 'spcprofile'
619 PREFIX = 'spcprofile'
614
620
615 def __init__(self):
621 def __init__(self):
616 self.__isConfig = False
622 self.__isConfig = False
617 self.__nsubplots = 1
623 self.__nsubplots = 1
618
624
619 self.WIDTH = 300
625 self.WIDTH = 300
620 self.HEIGHT = 500
626 self.HEIGHT = 500
621
627
622 def getSubplots(self):
628 def getSubplots(self):
623 ncol = 1
629 ncol = 1
624 nrow = 1
630 nrow = 1
625
631
626 return nrow, ncol
632 return nrow, ncol
627
633
628 def setup(self, idfigure, nplots, wintitle, show):
634 def setup(self, idfigure, nplots, wintitle, show):
629
635
630 self.nplots = nplots
636 self.nplots = nplots
631
637
632 ncolspan = 1
638 ncolspan = 1
633 colspan = 1
639 colspan = 1
634
640
635 self.createFigure(idfigure = idfigure,
641 self.createFigure(idfigure = idfigure,
636 wintitle = wintitle,
642 wintitle = wintitle,
637 widthplot = self.WIDTH,
643 widthplot = self.WIDTH,
638 heightplot = self.HEIGHT,
644 heightplot = self.HEIGHT,
639 show=show)
645 show=show)
640
646
641 nrow, ncol = self.getSubplots()
647 nrow, ncol = self.getSubplots()
642
648
643 counter = 0
649 counter = 0
644 for y in range(nrow):
650 for y in range(nrow):
645 for x in range(ncol):
651 for x in range(ncol):
646 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
652 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
647
653
648 def run(self, dataOut, idfigure, wintitle="", channelList=None,
654 def run(self, dataOut, idfigure, wintitle="", channelList=None,
649 xmin=None, xmax=None, ymin=None, ymax=None,
655 xmin=None, xmax=None, ymin=None, ymax=None,
650 save=False, figpath='./', figfile=None, show=True):
656 save=False, figpath='./', figfile=None, show=True):
651
657
652 if channelList == None:
658 if channelList == None:
653 channelIndexList = dataOut.channelIndexList
659 channelIndexList = dataOut.channelIndexList
654 channelList = dataOut.channelList
660 channelList = dataOut.channelList
655 else:
661 else:
656 channelIndexList = []
662 channelIndexList = []
657 for channel in channelList:
663 for channel in channelList:
658 if channel not in dataOut.channelList:
664 if channel not in dataOut.channelList:
659 raise ValueError, "Channel %d is not in dataOut.channelList"
665 raise ValueError, "Channel %d is not in dataOut.channelList"
660 channelIndexList.append(dataOut.channelList.index(channel))
666 channelIndexList.append(dataOut.channelList.index(channel))
661
667
662 factor = dataOut.normFactor
668 factor = dataOut.normFactor
663 y = dataOut.getHeiRange()
669 y = dataOut.getHeiRange()
664 x = dataOut.data_spc[channelIndexList,:,:]/factor
670 x = dataOut.data_spc[channelIndexList,:,:]/factor
665 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
671 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
666 avg = numpy.average(x, axis=1)
672 avg = numpy.average(x, axis=1)
667
673
668 avgdB = 10*numpy.log10(avg)
674 avgdB = 10*numpy.log10(avg)
669
675
670 thisDatetime = dataOut.datatime
676 thisDatetime = dataOut.datatime
671 title = "Power Profile"
677 title = "Power Profile"
672 xlabel = "dB"
678 xlabel = "dB"
673 ylabel = "Range (Km)"
679 ylabel = "Range (Km)"
674
680
675 if not self.__isConfig:
681 if not self.__isConfig:
676
682
677 nplots = 1
683 nplots = 1
678
684
679 self.setup(idfigure=idfigure,
685 self.setup(idfigure=idfigure,
680 nplots=nplots,
686 nplots=nplots,
681 wintitle=wintitle,
687 wintitle=wintitle,
682 show=show)
688 show=show)
683
689
684 if ymin == None: ymin = numpy.nanmin(y)
690 if ymin == None: ymin = numpy.nanmin(y)
685 if ymax == None: ymax = numpy.nanmax(y)
691 if ymax == None: ymax = numpy.nanmax(y)
686 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
692 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
687 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
693 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
688
694
689 self.__isConfig = True
695 self.__isConfig = True
690
696
691 self.setWinTitle(title)
697 self.setWinTitle(title)
692
698
693
699
694 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
700 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
695 axes = self.axesList[0]
701 axes = self.axesList[0]
696
702
697 legendlabels = ["channel %d"%x for x in channelList]
703 legendlabels = ["channel %d"%x for x in channelList]
698 axes.pmultiline(avgdB, y,
704 axes.pmultiline(avgdB, y,
699 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
705 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
700 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
706 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
701 ytick_visible=True, nxticks=5,
707 ytick_visible=True, nxticks=5,
702 grid='x')
708 grid='x')
703
709
704 self.draw()
710 self.draw()
705
711
706 if save:
712 if save:
707 date = thisDatetime.strftime("%Y%m%d")
713 date = thisDatetime.strftime("%Y%m%d")
708 if figfile == None:
714 if figfile == None:
709 figfile = self.getFilename(name = date)
715 figfile = self.getFilename(name = date)
710
716
711 self.saveFigure(figpath, figfile)
717 self.saveFigure(figpath, figfile)
712
718
713 class CoherenceMap(Figure):
719 class CoherenceMap(Figure):
714 __isConfig = None
720 __isConfig = None
715 __nsubplots = None
721 __nsubplots = None
716
722
717 WIDTHPROF = None
723 WIDTHPROF = None
718 HEIGHTPROF = None
724 HEIGHTPROF = None
719 PREFIX = 'cmap'
725 PREFIX = 'cmap'
720
726
721 def __init__(self):
727 def __init__(self):
722 self.timerange = 2*60*60
728 self.timerange = 2*60*60
723 self.__isConfig = False
729 self.__isConfig = False
724 self.__nsubplots = 1
730 self.__nsubplots = 1
725
731
726 self.WIDTH = 800
732 self.WIDTH = 800
727 self.HEIGHT = 150
733 self.HEIGHT = 150
728 self.WIDTHPROF = 120
734 self.WIDTHPROF = 120
729 self.HEIGHTPROF = 0
735 self.HEIGHTPROF = 0
730 self.counterftp = 0
736 self.counterftp = 0
731
737
732 def getSubplots(self):
738 def getSubplots(self):
733 ncol = 1
739 ncol = 1
734 nrow = self.nplots*2
740 nrow = self.nplots*2
735
741
736 return nrow, ncol
742 return nrow, ncol
737
743
738 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
744 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
739 self.__showprofile = showprofile
745 self.__showprofile = showprofile
740 self.nplots = nplots
746 self.nplots = nplots
741
747
742 ncolspan = 1
748 ncolspan = 1
743 colspan = 1
749 colspan = 1
744 if showprofile:
750 if showprofile:
745 ncolspan = 7
751 ncolspan = 7
746 colspan = 6
752 colspan = 6
747 self.__nsubplots = 2
753 self.__nsubplots = 2
748
754
749 self.createFigure(idfigure = idfigure,
755 self.createFigure(idfigure = idfigure,
750 wintitle = wintitle,
756 wintitle = wintitle,
751 widthplot = self.WIDTH + self.WIDTHPROF,
757 widthplot = self.WIDTH + self.WIDTHPROF,
752 heightplot = self.HEIGHT + self.HEIGHTPROF,
758 heightplot = self.HEIGHT + self.HEIGHTPROF,
753 show=True)
759 show=True)
754
760
755 nrow, ncol = self.getSubplots()
761 nrow, ncol = self.getSubplots()
756
762
757 for y in range(nrow):
763 for y in range(nrow):
758 for x in range(ncol):
764 for x in range(ncol):
759
765
760 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
766 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
761
767
762 if showprofile:
768 if showprofile:
763 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
769 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
764
770
765 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
771 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
766 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
772 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
767 timerange=None,
773 timerange=None,
768 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
774 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
769 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
775 coherence_cmap='jet', phase_cmap='RdBu_r', show=True):
770
776
771 if pairsList == None:
777 if pairsList == None:
772 pairsIndexList = dataOut.pairsIndexList
778 pairsIndexList = dataOut.pairsIndexList
773 else:
779 else:
774 pairsIndexList = []
780 pairsIndexList = []
775 for pair in pairsList:
781 for pair in pairsList:
776 if pair not in dataOut.pairsList:
782 if pair not in dataOut.pairsList:
777 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
783 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
778 pairsIndexList.append(dataOut.pairsList.index(pair))
784 pairsIndexList.append(dataOut.pairsList.index(pair))
779
785
780 if timerange != None:
786 if timerange != None:
781 self.timerange = timerange
787 self.timerange = timerange
782
788
783 if pairsIndexList == []:
789 if pairsIndexList == []:
784 return
790 return
785
791
786 if len(pairsIndexList) > 4:
792 if len(pairsIndexList) > 4:
787 pairsIndexList = pairsIndexList[0:4]
793 pairsIndexList = pairsIndexList[0:4]
788
794
789 tmin = None
795 tmin = None
790 tmax = None
796 tmax = None
791 x = dataOut.getTimeRange()
797 x = dataOut.getTimeRange()
792 y = dataOut.getHeiRange()
798 y = dataOut.getHeiRange()
793
799
794 thisDatetime = dataOut.datatime
800 thisDatetime = dataOut.datatime
795 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
801 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
796 xlabel = ""
802 xlabel = ""
797 ylabel = "Range (Km)"
803 ylabel = "Range (Km)"
798
804
799 if not self.__isConfig:
805 if not self.__isConfig:
800 nplots = len(pairsIndexList)
806 nplots = len(pairsIndexList)
801 self.setup(idfigure=idfigure,
807 self.setup(idfigure=idfigure,
802 nplots=nplots,
808 nplots=nplots,
803 wintitle=wintitle,
809 wintitle=wintitle,
804 showprofile=showprofile,
810 showprofile=showprofile,
805 show=show)
811 show=show)
806
812
807 tmin, tmax = self.getTimeLim(x, xmin, xmax)
813 tmin, tmax = self.getTimeLim(x, xmin, xmax)
808 if ymin == None: ymin = numpy.nanmin(y)
814 if ymin == None: ymin = numpy.nanmin(y)
809 if ymax == None: ymax = numpy.nanmax(y)
815 if ymax == None: ymax = numpy.nanmax(y)
810
816
811 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
817 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
812
818
813 self.__isConfig = True
819 self.__isConfig = True
814
820
815 self.setWinTitle(title)
821 self.setWinTitle(title)
816
822
817 for i in range(self.nplots):
823 for i in range(self.nplots):
818
824
819 pair = dataOut.pairsList[pairsIndexList[i]]
825 pair = dataOut.pairsList[pairsIndexList[i]]
820 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
826 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
821 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
827 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
822 coherence = numpy.abs(avgcoherenceComplex)
828 coherence = numpy.abs(avgcoherenceComplex)
823 # coherence = numpy.abs(coherenceComplex)
829 # coherence = numpy.abs(coherenceComplex)
824 # avg = numpy.average(coherence, axis=0)
830 # avg = numpy.average(coherence, axis=0)
825
831
826 z = coherence.reshape((1,-1))
832 z = coherence.reshape((1,-1))
827
833
828 counter = 0
834 counter = 0
829
835
830 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
836 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
831 axes = self.axesList[i*self.__nsubplots*2]
837 axes = self.axesList[i*self.__nsubplots*2]
832 axes.pcolorbuffer(x, y, z,
838 axes.pcolorbuffer(x, y, z,
833 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
839 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
834 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
840 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
835 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
841 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
836
842
837 if self.__showprofile:
843 if self.__showprofile:
838 counter += 1
844 counter += 1
839 axes = self.axesList[i*self.__nsubplots*2 + counter]
845 axes = self.axesList[i*self.__nsubplots*2 + counter]
840 axes.pline(coherence, y,
846 axes.pline(coherence, y,
841 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
847 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
842 xlabel='', ylabel='', title='', ticksize=7,
848 xlabel='', ylabel='', title='', ticksize=7,
843 ytick_visible=False, nxticks=5,
849 ytick_visible=False, nxticks=5,
844 grid='x')
850 grid='x')
845
851
846 counter += 1
852 counter += 1
847 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
853 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
848 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
854 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
849 # avg = numpy.average(phase, axis=0)
855 # avg = numpy.average(phase, axis=0)
850 z = phase.reshape((1,-1))
856 z = phase.reshape((1,-1))
851
857
852 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
858 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
853 axes = self.axesList[i*self.__nsubplots*2 + counter]
859 axes = self.axesList[i*self.__nsubplots*2 + counter]
854 axes.pcolorbuffer(x, y, z,
860 axes.pcolorbuffer(x, y, z,
855 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
861 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
856 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
862 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
857 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
863 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
858
864
859 if self.__showprofile:
865 if self.__showprofile:
860 counter += 1
866 counter += 1
861 axes = self.axesList[i*self.__nsubplots*2 + counter]
867 axes = self.axesList[i*self.__nsubplots*2 + counter]
862 axes.pline(phase, y,
868 axes.pline(phase, y,
863 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
869 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
864 xlabel='', ylabel='', title='', ticksize=7,
870 xlabel='', ylabel='', title='', ticksize=7,
865 ytick_visible=False, nxticks=4,
871 ytick_visible=False, nxticks=4,
866 grid='x')
872 grid='x')
867
873
868 self.draw()
874 self.draw()
869
875
870 if save:
876 if save:
871
877
872 if figfile == None:
878 if figfile == None:
873 figfile = self.getFilename(name = self.name)
879 figfile = self.getFilename(name = self.name)
874
880
875 self.saveFigure(figpath, figfile)
881 self.saveFigure(figpath, figfile)
876
882
877 self.counterftp += 1
883 self.counterftp += 1
878 if (ftp and (self.counterftp==ftpratio)):
884 if (ftp and (self.counterftp==ftpratio)):
879 figfilename = os.path.join(figpath,figfile)
885 figfilename = os.path.join(figpath,figfile)
880 self.sendByFTP(figfilename)
886 self.sendByFTP(figfilename)
881 self.counterftp = 0
887 self.counterftp = 0
882
888
883 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
889 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
884 self.__isConfig = False
890 self.__isConfig = False
885
891
886 class RTIfromNoise(Figure):
892 class RTIfromNoise(Figure):
887
893
888 __isConfig = None
894 __isConfig = None
889 __nsubplots = None
895 __nsubplots = None
890
896
891 PREFIX = 'rtinoise'
897 PREFIX = 'rtinoise'
892
898
893 def __init__(self):
899 def __init__(self):
894
900
895 self.timerange = 24*60*60
901 self.timerange = 24*60*60
896 self.__isConfig = False
902 self.__isConfig = False
897 self.__nsubplots = 1
903 self.__nsubplots = 1
898
904
899 self.WIDTH = 820
905 self.WIDTH = 820
900 self.HEIGHT = 200
906 self.HEIGHT = 200
901 self.WIDTHPROF = 120
907 self.WIDTHPROF = 120
902 self.HEIGHTPROF = 0
908 self.HEIGHTPROF = 0
903 self.xdata = None
909 self.xdata = None
904 self.ydata = None
910 self.ydata = None
905
911
906 def getSubplots(self):
912 def getSubplots(self):
907
913
908 ncol = 1
914 ncol = 1
909 nrow = 1
915 nrow = 1
910
916
911 return nrow, ncol
917 return nrow, ncol
912
918
913 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
919 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
914
920
915 self.__showprofile = showprofile
921 self.__showprofile = showprofile
916 self.nplots = nplots
922 self.nplots = nplots
917
923
918 ncolspan = 7
924 ncolspan = 7
919 colspan = 6
925 colspan = 6
920 self.__nsubplots = 2
926 self.__nsubplots = 2
921
927
922 self.createFigure(idfigure = idfigure,
928 self.createFigure(idfigure = idfigure,
923 wintitle = wintitle,
929 wintitle = wintitle,
924 widthplot = self.WIDTH+self.WIDTHPROF,
930 widthplot = self.WIDTH+self.WIDTHPROF,
925 heightplot = self.HEIGHT+self.HEIGHTPROF,
931 heightplot = self.HEIGHT+self.HEIGHTPROF,
926 show=show)
932 show=show)
927
933
928 nrow, ncol = self.getSubplots()
934 nrow, ncol = self.getSubplots()
929
935
930 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
936 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
931
937
932
938
933 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
939 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
934 xmin=None, xmax=None, ymin=None, ymax=None,
940 xmin=None, xmax=None, ymin=None, ymax=None,
935 timerange=None,
941 timerange=None,
936 save=False, figpath='./', figfile=None, show=True):
942 save=False, figpath='./', figfile=None, show=True):
937
943
938 if channelList == None:
944 if channelList == None:
939 channelIndexList = dataOut.channelIndexList
945 channelIndexList = dataOut.channelIndexList
940 channelList = dataOut.channelList
946 channelList = dataOut.channelList
941 else:
947 else:
942 channelIndexList = []
948 channelIndexList = []
943 for channel in channelList:
949 for channel in channelList:
944 if channel not in dataOut.channelList:
950 if channel not in dataOut.channelList:
945 raise ValueError, "Channel %d is not in dataOut.channelList"
951 raise ValueError, "Channel %d is not in dataOut.channelList"
946 channelIndexList.append(dataOut.channelList.index(channel))
952 channelIndexList.append(dataOut.channelList.index(channel))
947
953
948 if timerange != None:
954 if timerange != None:
949 self.timerange = timerange
955 self.timerange = timerange
950
956
951 tmin = None
957 tmin = None
952 tmax = None
958 tmax = None
953 x = dataOut.getTimeRange()
959 x = dataOut.getTimeRange()
954 y = dataOut.getHeiRange()
960 y = dataOut.getHeiRange()
955 factor = dataOut.normFactor
961 factor = dataOut.normFactor
956 noise = dataOut.getNoise()/factor
962 noise = dataOut.getNoise()/factor
957 noisedB = 10*numpy.log10(noise)
963 noisedB = 10*numpy.log10(noise)
958
964
959 thisDatetime = dataOut.datatime
965 thisDatetime = dataOut.datatime
960 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
966 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
961 xlabel = ""
967 xlabel = ""
962 ylabel = "Range (Km)"
968 ylabel = "Range (Km)"
963
969
964 if not self.__isConfig:
970 if not self.__isConfig:
965
971
966 nplots = 1
972 nplots = 1
967
973
968 self.setup(idfigure=idfigure,
974 self.setup(idfigure=idfigure,
969 nplots=nplots,
975 nplots=nplots,
970 wintitle=wintitle,
976 wintitle=wintitle,
971 showprofile=showprofile,
977 showprofile=showprofile,
972 show=show)
978 show=show)
973
979
974 tmin, tmax = self.getTimeLim(x, xmin, xmax)
980 tmin, tmax = self.getTimeLim(x, xmin, xmax)
975 if ymin == None: ymin = numpy.nanmin(noisedB)
981 if ymin == None: ymin = numpy.nanmin(noisedB)
976 if ymax == None: ymax = numpy.nanmax(noisedB)
982 if ymax == None: ymax = numpy.nanmax(noisedB)
977
983
978 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
984 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
979 self.__isConfig = True
985 self.__isConfig = True
980
986
981 self.xdata = numpy.array([])
987 self.xdata = numpy.array([])
982 self.ydata = numpy.array([])
988 self.ydata = numpy.array([])
983
989
984 self.setWinTitle(title)
990 self.setWinTitle(title)
985
991
986
992
987 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
993 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
988
994
989 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
995 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
990 axes = self.axesList[0]
996 axes = self.axesList[0]
991
997
992 self.xdata = numpy.hstack((self.xdata, x[0:1]))
998 self.xdata = numpy.hstack((self.xdata, x[0:1]))
993
999
994 if len(self.ydata)==0:
1000 if len(self.ydata)==0:
995 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1001 self.ydata = noisedB[channelIndexList].reshape(-1,1)
996 else:
1002 else:
997 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1003 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
998
1004
999
1005
1000 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1006 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1001 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1007 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1002 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1008 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1003 XAxisAsTime=True
1009 XAxisAsTime=True
1004 )
1010 )
1005
1011
1006 self.draw()
1012 self.draw()
1007
1013
1008 if save:
1014 if save:
1009
1015
1010 if figfile == None:
1016 if figfile == None:
1011 figfile = self.getFilename(name = self.name)
1017 figfile = self.getFilename(name = self.name)
1012
1018
1013 self.saveFigure(figpath, figfile)
1019 self.saveFigure(figpath, figfile)
1014
1020
1015 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1021 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1016 self.__isConfig = False
1022 self.__isConfig = False
1017 del self.xdata
1023 del self.xdata
1018 del self.ydata
1024 del self.ydata
1019
1025
1020
1026
1021 class SpectraHeisScope(Figure):
1027 class SpectraHeisScope(Figure):
1022
1028
1023
1029
1024 __isConfig = None
1030 __isConfig = None
1025 __nsubplots = None
1031 __nsubplots = None
1026
1032
1027 WIDTHPROF = None
1033 WIDTHPROF = None
1028 HEIGHTPROF = None
1034 HEIGHTPROF = None
1029 PREFIX = 'spc'
1035 PREFIX = 'spc'
1030
1036
1031 def __init__(self):
1037 def __init__(self):
1032
1038
1033 self.__isConfig = False
1039 self.__isConfig = False
1034 self.__nsubplots = 1
1040 self.__nsubplots = 1
1035
1041
1036 self.WIDTH = 230
1042 self.WIDTH = 230
1037 self.HEIGHT = 250
1043 self.HEIGHT = 250
1038 self.WIDTHPROF = 120
1044 self.WIDTHPROF = 120
1039 self.HEIGHTPROF = 0
1045 self.HEIGHTPROF = 0
1040 self.counterftp = 0
1046 self.counterftp = 0
1041
1047
1042 def getSubplots(self):
1048 def getSubplots(self):
1043
1049
1044 ncol = int(numpy.sqrt(self.nplots)+0.9)
1050 ncol = int(numpy.sqrt(self.nplots)+0.9)
1045 nrow = int(self.nplots*1./ncol + 0.9)
1051 nrow = int(self.nplots*1./ncol + 0.9)
1046
1052
1047 return nrow, ncol
1053 return nrow, ncol
1048
1054
1049 def setup(self, idfigure, nplots, wintitle, show):
1055 def setup(self, idfigure, nplots, wintitle, show):
1050
1056
1051 showprofile = False
1057 showprofile = False
1052 self.__showprofile = showprofile
1058 self.__showprofile = showprofile
1053 self.nplots = nplots
1059 self.nplots = nplots
1054
1060
1055 ncolspan = 1
1061 ncolspan = 1
1056 colspan = 1
1062 colspan = 1
1057 if showprofile:
1063 if showprofile:
1058 ncolspan = 3
1064 ncolspan = 3
1059 colspan = 2
1065 colspan = 2
1060 self.__nsubplots = 2
1066 self.__nsubplots = 2
1061
1067
1062 self.createFigure(idfigure = idfigure,
1068 self.createFigure(idfigure = idfigure,
1063 wintitle = wintitle,
1069 wintitle = wintitle,
1064 widthplot = self.WIDTH + self.WIDTHPROF,
1070 widthplot = self.WIDTH + self.WIDTHPROF,
1065 heightplot = self.HEIGHT + self.HEIGHTPROF,
1071 heightplot = self.HEIGHT + self.HEIGHTPROF,
1066 show = show)
1072 show = show)
1067
1073
1068 nrow, ncol = self.getSubplots()
1074 nrow, ncol = self.getSubplots()
1069
1075
1070 counter = 0
1076 counter = 0
1071 for y in range(nrow):
1077 for y in range(nrow):
1072 for x in range(ncol):
1078 for x in range(ncol):
1073
1079
1074 if counter >= self.nplots:
1080 if counter >= self.nplots:
1075 break
1081 break
1076
1082
1077 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1083 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1078
1084
1079 if showprofile:
1085 if showprofile:
1080 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1086 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1081
1087
1082 counter += 1
1088 counter += 1
1083
1089
1084 # __isConfig = None
1090 # __isConfig = None
1085 # def __init__(self):
1091 # def __init__(self):
1086 #
1092 #
1087 # self.__isConfig = False
1093 # self.__isConfig = False
1088 # self.WIDTH = 600
1094 # self.WIDTH = 600
1089 # self.HEIGHT = 200
1095 # self.HEIGHT = 200
1090 #
1096 #
1091 # def getSubplots(self):
1097 # def getSubplots(self):
1092 #
1098 #
1093 # nrow = self.nplots
1099 # nrow = self.nplots
1094 # ncol = 3
1100 # ncol = 3
1095 # return nrow, ncol
1101 # return nrow, ncol
1096 #
1102 #
1097 # def setup(self, idfigure, nplots, wintitle):
1103 # def setup(self, idfigure, nplots, wintitle):
1098 #
1104 #
1099 # self.nplots = nplots
1105 # self.nplots = nplots
1100 #
1106 #
1101 # self.createFigure(idfigure, wintitle)
1107 # self.createFigure(idfigure, wintitle)
1102 #
1108 #
1103 # nrow,ncol = self.getSubplots()
1109 # nrow,ncol = self.getSubplots()
1104 # colspan = 3
1110 # colspan = 3
1105 # rowspan = 1
1111 # rowspan = 1
1106 #
1112 #
1107 # for i in range(nplots):
1113 # for i in range(nplots):
1108 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1114 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1109
1115
1110 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1116 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1111 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1117 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1112 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1118 figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1113
1119
1114 """
1120 """
1115
1121
1116 Input:
1122 Input:
1117 dataOut :
1123 dataOut :
1118 idfigure :
1124 idfigure :
1119 wintitle :
1125 wintitle :
1120 channelList :
1126 channelList :
1121 xmin : None,
1127 xmin : None,
1122 xmax : None,
1128 xmax : None,
1123 ymin : None,
1129 ymin : None,
1124 ymax : None,
1130 ymax : None,
1125 """
1131 """
1126
1132
1133 if dataOut.realtime:
1134 if not(isRealtime(utcdatatime = dataOut.utctime)):
1135 print 'Skipping this plot function'
1136 return
1137
1127 if channelList == None:
1138 if channelList == None:
1128 channelIndexList = dataOut.channelIndexList
1139 channelIndexList = dataOut.channelIndexList
1129 else:
1140 else:
1130 channelIndexList = []
1141 channelIndexList = []
1131 for channel in channelList:
1142 for channel in channelList:
1132 if channel not in dataOut.channelList:
1143 if channel not in dataOut.channelList:
1133 raise ValueError, "Channel %d is not in dataOut.channelList"
1144 raise ValueError, "Channel %d is not in dataOut.channelList"
1134 channelIndexList.append(dataOut.channelList.index(channel))
1145 channelIndexList.append(dataOut.channelList.index(channel))
1135
1146
1136 # x = dataOut.heightList
1147 # x = dataOut.heightList
1137 c = 3E8
1148 c = 3E8
1138 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1149 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1139 #deberia cambiar para el caso de 1Mhz y 100KHz
1150 #deberia cambiar para el caso de 1Mhz y 100KHz
1140 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1151 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1141 x= x/(10000.0)
1152 x= x/(10000.0)
1142 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1153 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1143 # y = y.real
1154 # y = y.real
1144 datadB = 10.*numpy.log10(dataOut.data_spc)
1155 datadB = 10.*numpy.log10(dataOut.data_spc)
1145 y = datadB
1156 y = datadB
1146
1157
1147 thisDatetime = dataOut.datatime
1158 thisDatetime = dataOut.datatime
1148 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1159 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1149 xlabel = "Frequency x 10000"
1160 xlabel = "Frequency x 10000"
1150 ylabel = "Intensity (dB)"
1161 ylabel = "Intensity (dB)"
1151
1162
1152 if not self.__isConfig:
1163 if not self.__isConfig:
1153 nplots = len(channelIndexList)
1164 nplots = len(channelIndexList)
1154
1165
1155 self.setup(idfigure=idfigure,
1166 self.setup(idfigure=idfigure,
1156 nplots=nplots,
1167 nplots=nplots,
1157 wintitle=wintitle,
1168 wintitle=wintitle,
1158 show=show)
1169 show=show)
1159
1170
1160 if xmin == None: xmin = numpy.nanmin(x)
1171 if xmin == None: xmin = numpy.nanmin(x)
1161 if xmax == None: xmax = numpy.nanmax(x)
1172 if xmax == None: xmax = numpy.nanmax(x)
1162 if ymin == None: ymin = numpy.nanmin(y)
1173 if ymin == None: ymin = numpy.nanmin(y)
1163 if ymax == None: ymax = numpy.nanmax(y)
1174 if ymax == None: ymax = numpy.nanmax(y)
1164
1175
1165 self.__isConfig = True
1176 self.__isConfig = True
1166
1177
1167 self.setWinTitle(title)
1178 self.setWinTitle(title)
1168
1179
1169 for i in range(len(self.axesList)):
1180 for i in range(len(self.axesList)):
1170 ychannel = y[i,:]
1181 ychannel = y[i,:]
1171 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1182 title = "Channel %d - peak:%.2f" %(i,numpy.max(ychannel))
1172 axes = self.axesList[i]
1183 axes = self.axesList[i]
1173 axes.pline(x, ychannel,
1184 axes.pline(x, ychannel,
1174 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1185 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1175 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1186 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
1176
1187
1177
1188
1178 self.draw()
1189 self.draw()
1179
1190
1180 if save:
1191 if save:
1181 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1192 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1182 if figfile == None:
1193 if figfile == None:
1183 figfile = self.getFilename(name = date)
1194 figfile = self.getFilename(name = date)
1184
1195
1185 self.saveFigure(figpath, figfile)
1196 self.saveFigure(figpath, figfile)
1186
1197
1187 self.counterftp += 1
1198 self.counterftp += 1
1188 if (ftp and (self.counterftp==ftpratio)):
1199 if (ftp and (self.counterftp==ftpratio)):
1189 figfilename = os.path.join(figpath,figfile)
1200 figfilename = os.path.join(figpath,figfile)
1190 self.sendByFTP(figfilename)
1201 self.sendByFTP(figfilename)
1191 self.counterftp = 0
1202 self.counterftp = 0
1192
1203
1193
1204
1194 class RTIfromSpectraHeis(Figure):
1205 class RTIfromSpectraHeis(Figure):
1195
1206
1196 __isConfig = None
1207 __isConfig = None
1197 __nsubplots = None
1208 __nsubplots = None
1198
1209
1199 PREFIX = 'rtinoise'
1210 PREFIX = 'rtinoise'
1200
1211
1201 def __init__(self):
1212 def __init__(self):
1202
1213
1203 self.timerange = 24*60*60
1214 self.timerange = 24*60*60
1204 self.__isConfig = False
1215 self.__isConfig = False
1205 self.__nsubplots = 1
1216 self.__nsubplots = 1
1206
1217
1207 self.WIDTH = 820
1218 self.WIDTH = 820
1208 self.HEIGHT = 200
1219 self.HEIGHT = 200
1209 self.WIDTHPROF = 120
1220 self.WIDTHPROF = 120
1210 self.HEIGHTPROF = 0
1221 self.HEIGHTPROF = 0
1211 self.counterftp = 0
1222 self.counterftp = 0
1212 self.xdata = None
1223 self.xdata = None
1213 self.ydata = None
1224 self.ydata = None
1214
1225
1215 def getSubplots(self):
1226 def getSubplots(self):
1216
1227
1217 ncol = 1
1228 ncol = 1
1218 nrow = 1
1229 nrow = 1
1219
1230
1220 return nrow, ncol
1231 return nrow, ncol
1221
1232
1222 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1233 def setup(self, idfigure, nplots, wintitle, showprofile=True, show=True):
1223
1234
1224 self.__showprofile = showprofile
1235 self.__showprofile = showprofile
1225 self.nplots = nplots
1236 self.nplots = nplots
1226
1237
1227 ncolspan = 7
1238 ncolspan = 7
1228 colspan = 6
1239 colspan = 6
1229 self.__nsubplots = 2
1240 self.__nsubplots = 2
1230
1241
1231 self.createFigure(idfigure = idfigure,
1242 self.createFigure(idfigure = idfigure,
1232 wintitle = wintitle,
1243 wintitle = wintitle,
1233 widthplot = self.WIDTH+self.WIDTHPROF,
1244 widthplot = self.WIDTH+self.WIDTHPROF,
1234 heightplot = self.HEIGHT+self.HEIGHTPROF,
1245 heightplot = self.HEIGHT+self.HEIGHTPROF,
1235 show = show)
1246 show = show)
1236
1247
1237 nrow, ncol = self.getSubplots()
1248 nrow, ncol = self.getSubplots()
1238
1249
1239 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1250 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1240
1251
1241
1252
1242 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1253 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1243 xmin=None, xmax=None, ymin=None, ymax=None,
1254 xmin=None, xmax=None, ymin=None, ymax=None,
1244 timerange=None,
1255 timerange=None,
1245 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1256 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1, show=True):
1246
1257
1247 if channelList == None:
1258 if channelList == None:
1248 channelIndexList = dataOut.channelIndexList
1259 channelIndexList = dataOut.channelIndexList
1249 channelList = dataOut.channelList
1260 channelList = dataOut.channelList
1250 else:
1261 else:
1251 channelIndexList = []
1262 channelIndexList = []
1252 for channel in channelList:
1263 for channel in channelList:
1253 if channel not in dataOut.channelList:
1264 if channel not in dataOut.channelList:
1254 raise ValueError, "Channel %d is not in dataOut.channelList"
1265 raise ValueError, "Channel %d is not in dataOut.channelList"
1255 channelIndexList.append(dataOut.channelList.index(channel))
1266 channelIndexList.append(dataOut.channelList.index(channel))
1256
1267
1257 if timerange != None:
1268 if timerange != None:
1258 self.timerange = timerange
1269 self.timerange = timerange
1259
1270
1260 tmin = None
1271 tmin = None
1261 tmax = None
1272 tmax = None
1262 x = dataOut.getTimeRange()
1273 x = dataOut.getTimeRange()
1263 y = dataOut.getHeiRange()
1274 y = dataOut.getHeiRange()
1264
1275
1265 factor = 1
1276 factor = 1
1266 data = dataOut.data_spc/factor
1277 data = dataOut.data_spc/factor
1267 data = numpy.average(data,axis=1)
1278 data = numpy.average(data,axis=1)
1268 datadB = 10*numpy.log10(data)
1279 datadB = 10*numpy.log10(data)
1269
1280
1270 # factor = dataOut.normFactor
1281 # factor = dataOut.normFactor
1271 # noise = dataOut.getNoise()/factor
1282 # noise = dataOut.getNoise()/factor
1272 # noisedB = 10*numpy.log10(noise)
1283 # noisedB = 10*numpy.log10(noise)
1273
1284
1274 thisDatetime = dataOut.datatime
1285 thisDatetime = dataOut.datatime
1275 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1276 xlabel = "Local Time"
1287 xlabel = "Local Time"
1277 ylabel = "Intensity (dB)"
1288 ylabel = "Intensity (dB)"
1278
1289
1279 if not self.__isConfig:
1290 if not self.__isConfig:
1280
1291
1281 nplots = 1
1292 nplots = 1
1282
1293
1283 self.setup(idfigure=idfigure,
1294 self.setup(idfigure=idfigure,
1284 nplots=nplots,
1295 nplots=nplots,
1285 wintitle=wintitle,
1296 wintitle=wintitle,
1286 showprofile=showprofile,
1297 showprofile=showprofile,
1287 show=show)
1298 show=show)
1288
1299
1289 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1300 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1290 if ymin == None: ymin = numpy.nanmin(datadB)
1301 if ymin == None: ymin = numpy.nanmin(datadB)
1291 if ymax == None: ymax = numpy.nanmax(datadB)
1302 if ymax == None: ymax = numpy.nanmax(datadB)
1292
1303
1293 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1304 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1294 self.__isConfig = True
1305 self.__isConfig = True
1295
1306
1296 self.xdata = numpy.array([])
1307 self.xdata = numpy.array([])
1297 self.ydata = numpy.array([])
1308 self.ydata = numpy.array([])
1298
1309
1299 self.setWinTitle(title)
1310 self.setWinTitle(title)
1300
1311
1301
1312
1302 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1313 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
1303 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1314 title = "RTI-Noise - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1304
1315
1305 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1316 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1306 axes = self.axesList[0]
1317 axes = self.axesList[0]
1307
1318
1308 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1309
1320
1310 if len(self.ydata)==0:
1321 if len(self.ydata)==0:
1311 self.ydata = datadB[channelIndexList].reshape(-1,1)
1322 self.ydata = datadB[channelIndexList].reshape(-1,1)
1312 else:
1323 else:
1313 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1324 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1314
1325
1315
1326
1316 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1317 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1328 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1318 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
1319 XAxisAsTime=True
1330 XAxisAsTime=True
1320 )
1331 )
1321
1332
1322 self.draw()
1333 self.draw()
1323
1334
1324 if save:
1335 if save:
1325
1336
1326 if figfile == None:
1337 if figfile == None:
1327 figfile = self.getFilename(name = self.name)
1338 figfile = self.getFilename(name = self.name)
1328
1339
1329 self.saveFigure(figpath, figfile)
1340 self.saveFigure(figpath, figfile)
1330
1341
1331 self.counterftp += 1
1342 self.counterftp += 1
1332 if (ftp and (self.counterftp==ftpratio)):
1343 if (ftp and (self.counterftp==ftpratio)):
1333 figfilename = os.path.join(figpath,figfile)
1344 figfilename = os.path.join(figpath,figfile)
1334 self.sendByFTP(figfilename)
1345 self.sendByFTP(figfilename)
1335 self.counterftp = 0
1346 self.counterftp = 0
1336
1347
1337 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1348 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1338 self.__isConfig = False
1349 self.__isConfig = False
1339 del self.xdata
1350 del self.xdata
1340 del self.ydata
1351 del self.ydata
1341
1352
1342
1353
1343 No newline at end of file
1354
General Comments 0
You need to be logged in to leave comments. Login now