##// END OF EJS Templates
Primera version del controlador probada y testeada incluyendo graficos
Miguel Valdez -
r199:83ce53852b6c
parent child
Show More
@@ -10,6 +10,7 import sys
10 10 import datetime
11 11 from model.jrodataIO import *
12 12 from model.jroprocessing import *
13 from model.jroplot import *
13 14
14 15 def prettify(elem):
15 16 """Return a pretty-printed XML string for the Element.
@@ -23,13 +24,13 class ParameterConf():
23 24 id = None
24 25 name = None
25 26 value = None
26 type = None
27 format = None
27 28
28 29 ELEMENTNAME = 'Parameter'
29 30
30 31 def __init__(self):
31 32
32 self.type = 'str'
33 self.format = 'str'
33 34
34 35 def getElementName(self):
35 36
@@ -37,42 +38,42 class ParameterConf():
37 38
38 39 def getValue(self):
39 40
40 if self.type == 'list':
41 if self.format == 'list':
41 42 strList = self.value.split(',')
42 43 return strList
43 44
44 if self.type == 'intlist':
45 if self.format == 'intlist':
45 46 strList = self.value.split(',')
46 47 intList = [int(x) for x in strList]
47 48 return intList
48 49
49 if self.type == 'floatlist':
50 if self.format == 'floatlist':
50 51 strList = self.value.split(',')
51 52 floatList = [float(x) for x in strList]
52 53 return floatList
53 54
54 if self.type == 'date':
55 if self.format == 'date':
55 56 strList = self.value.split('/')
56 57 intList = [int(x) for x in strList]
57 58 date = datetime.date(intList[0], intList[1], intList[2])
58 59 return date
59 60
60 if self.type == 'time':
61 if self.format == 'time':
61 62 strList = self.value.split(':')
62 63 intList = [int(x) for x in strList]
63 64 time = datetime.time(intList[0], intList[1], intList[2])
64 65 return time
65 66
66 func = eval(self.type)
67 func = eval(self.format)
67 68
68 69 return func(self.value)
69 70
70 def setup(self, id, name, value, type='str'):
71 def setup(self, id, name, value, format='str'):
71 72
72 73 self.id = id
73 74 self.name = name
74 75 self.value = str(value)
75 self.type = type
76 self.format = format
76 77
77 78 def makeXml(self, opElement):
78 79
@@ -80,18 +81,18 class ParameterConf():
80 81 parmElement.set('id', str(self.id))
81 82 parmElement.set('name', self.name)
82 83 parmElement.set('value', self.value)
83 parmElement.set('type', self.type)
84 parmElement.set('format', self.format)
84 85
85 86 def readXml(self, parmElement):
86 87
87 88 self.id = parmElement.get('id')
88 89 self.name = parmElement.get('name')
89 90 self.value = parmElement.get('value')
90 self.type = parmElement.get('type')
91 self.format = parmElement.get('format')
91 92
92 93 def printattr(self):
93 94
94 print "Parameter[%s]: name = %s, value = %s, type = %s" %(self.id, self.name, self.value, self.type)
95 print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format)
95 96
96 97 class OperationConf():
97 98
@@ -133,12 +134,12 class OperationConf():
133 134
134 135 self.parmConfObjList = []
135 136
136 def addParameter(self, name, value, type='str'):
137 def addParameter(self, name, value, format='str'):
137 138
138 139 id = self.__getNewId()
139 140
140 141 parmConfObj = ParameterConf()
141 parmConfObj.setup(id, name, value, type)
142 parmConfObj.setup(id, name, value, format)
142 143
143 144 self.parmConfObjList.append(parmConfObj)
144 145
@@ -197,7 +198,7 class ProcUnitConf():
197 198
198 199 id = None
199 200 name = None
200 type = None
201 datatype = None
201 202 inputId = None
202 203
203 204 opConfObjList = []
@@ -210,7 +211,7 class ProcUnitConf():
210 211 def __init__(self):
211 212
212 213 self.id = None
213 self.type = None
214 self.datatype = None
214 215 self.name = None
215 216 self.inputId = None
216 217
@@ -247,11 +248,11 class ProcUnitConf():
247 248
248 249 return self.procUnitObj
249 250
250 def setup(self, id, name, type, inputId):
251 def setup(self, id, name, datatype, inputId):
251 252
252 253 self.id = id
253 254 self.name = name
254 self.type = type
255 self.datatype = datatype
255 256 self.inputId = inputId
256 257
257 258 self.opConfObjList = []
@@ -275,7 +276,7 class ProcUnitConf():
275 276 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
276 277 upElement.set('id', str(self.id))
277 278 upElement.set('name', self.name)
278 upElement.set('type', self.type)
279 upElement.set('datatype', self.datatype)
279 280 upElement.set('inputId', str(self.inputId))
280 281
281 282 for opConfObj in self.opConfObjList:
@@ -285,7 +286,7 class ProcUnitConf():
285 286
286 287 self.id = upElement.get('id')
287 288 self.name = upElement.get('name')
288 self.type = upElement.get('type')
289 self.datatype = upElement.get('datatype')
289 290 self.inputId = upElement.get('inputId')
290 291
291 292 self.opConfObjList = []
@@ -299,10 +300,10 class ProcUnitConf():
299 300
300 301 def printattr(self):
301 302
302 print "%s[%s]: name = %s, type = %s, inputId = %s" %(self.ELEMENTNAME,
303 print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME,
303 304 self.id,
304 305 self.name,
305 self.type,
306 self.datatype,
306 307 self.inputId)
307 308
308 309 for opConfObj in self.opConfObjList:
@@ -329,18 +330,22 class ProcUnitConf():
329 330
330 331 def run(self):
331 332
333 finalSts = False
334
332 335 for opConfObj in self.opConfObjList:
336
333 337 kwargs = {}
334 338 for parmConfObj in opConfObj.getParameterObjList():
335 339 kwargs[parmConfObj.name] = parmConfObj.getValue()
336 340
337 self.procUnitObj.call(opConfObj, **kwargs)
338
341 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
342 sts = self.procUnitObj.call(opConfObj, **kwargs)
343 finalSts = finalSts or sts
339 344
345 return finalSts
340 346
341 347 class ReadUnitConf(ProcUnitConf):
342 348
343
344 349 path = None
345 350 startDate = None
346 351 endDate = None
@@ -355,7 +360,7 class ReadUnitConf(ProcUnitConf):
355 360 def __init__(self):
356 361
357 362 self.id = None
358 self.type = None
363 self.datatype = None
359 364 self.name = None
360 365 self.inputId = 0
361 366
@@ -366,11 +371,11 class ReadUnitConf(ProcUnitConf):
366 371
367 372 return self.ELEMENTNAME
368 373
369 def setup(self, id, name, type, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60):
374 def setup(self, id, name, datatype, path, startDate, endDate, startTime, endTime, online=0, expLabel='', delay=60):
370 375
371 376 self.id = id
372 377 self.name = name
373 self.type = type
378 self.datatype = datatype
374 379
375 380 self.path = path
376 381 self.startDate = startDate
@@ -387,14 +392,14 class ReadUnitConf(ProcUnitConf):
387 392
388 393 opObj = self.addOperation(name = 'run', optype = 'self')
389 394
390 opObj.addParameter(name='path' , value=self.path, type='str')
391 opObj.addParameter(name='startDate' , value=self.startDate, type='date')
392 opObj.addParameter(name='endDate' , value=self.endDate, type='date')
393 opObj.addParameter(name='startTime' , value=self.startTime, type='time')
394 opObj.addParameter(name='endTime' , value=self.endTime, type='time')
395 opObj.addParameter(name='expLabel' , value=self.expLabel, type='str')
396 opObj.addParameter(name='online' , value=self.online, type='bool')
397 opObj.addParameter(name='delay' , value=self.delay, type='float')
395 opObj.addParameter(name='path' , value=self.path, format='str')
396 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
397 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
398 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
399 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
400 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
401 opObj.addParameter(name='online' , value=self.online, format='int')
402 opObj.addParameter(name='delay' , value=self.delay, format='float')
398 403
399 404 return opObj
400 405
@@ -434,25 +439,25 class Controller():
434 439 self.name = name
435 440 self.description = description
436 441
437 def addReadUnit(self, type, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60):
442 def addReadUnit(self, datatype, path, startDate='', endDate='', startTime='', endTime='', online=0, expLabel='', delay=60):
438 443
439 444 id = self.__getNewId()
440 name = '%sReader' %(type)
445 name = '%sReader' %(datatype)
441 446
442 447 readUnitConfObj = ReadUnitConf()
443 readUnitConfObj.setup(id, name, type, path, startDate, endDate, startTime, endTime, online, expLabel, delay)
448 readUnitConfObj.setup(id, name, datatype, path, startDate, endDate, startTime, endTime, online, expLabel, delay)
444 449
445 450 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
446 451
447 452 return readUnitConfObj
448 453
449 def addProcUnit(self, type, inputId):
454 def addProcUnit(self, datatype, inputId):
450 455
451 456 id = self.__getNewId()
452 name = '%sProc' %(type)
457 name = '%sProc' %(datatype)
453 458
454 459 procUnitConfObj = ProcUnitConf()
455 procUnitConfObj.setup(id, name, type, inputId)
460 procUnitConfObj.setup(id, name, datatype, inputId)
456 461
457 462 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
458 463
@@ -556,9 +561,20 class Controller():
556 561
557 562 # for readUnitConfObj in self.readUnitConfObjList:
558 563 # readUnitConfObj.run()
564
559 565 while(True):
566
567 finalSts = False
568
560 569 for procUnitConfObj in self.procUnitConfObjDict.values():
561 procUnitConfObj.run()
570 #print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id)
571 sts = procUnitConfObj.run()
572 finalSts = finalSts or sts
573
574 #If every process unit finished so end process
575 if not(finalSts):
576 print "Every process unit finished"
577 break
562 578
563 579 if __name__ == '__main__':
564 580
@@ -569,29 +585,38 if __name__ == '__main__':
569 585
570 586 controllerObj.setup(id = '191', name='test01', description=desc)
571 587
572 readUnitConfObj = controllerObj.addReadUnit(type='Voltage',
573 path='/home/roj-idl71/Data/RAWDATA/Meteors',
574 startDate='2012/01/01',
588 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
589 path='D:\Data\IMAGING',
590 startDate='2011/01/01',
575 591 endDate='2012/12/31',
576 592 startTime='00:00:00',
577 593 endTime='23:59:59',
578 594 online=0)
579 595
580 procUnitConfObj1 = controllerObj.addProcUnit(type='Voltage', inputId=readUnitConfObj.getId())
596 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
597
598 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
581 599
582 procUnitConfObj2 = controllerObj.addProcUnit(type='Voltage', inputId=procUnitConfObj1.getId())
600 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
601 opObj10.addParameter(name='channelList', value='0,1', format='intlist')
583 602
584 opObj11 = procUnitConfObj1.addOperation(name='selectChannels')
585 opObj11.addParameter(name='channelList', value='1,2', type='intlist')
603 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
604 opObj11.addParameter(name='idfigure', value='1', format='int')
605 opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
606 opObj11.addParameter(name='zmin', value='60', format='int')
607 opObj11.addParameter(name='zmax', value='100', format='int')
586 608
587 609 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
588 # opObj12.addParameter(name='ncode', value='2', type='int')
589 # opObj12.addParameter(name='nbauds', value='8', type='int')
590 # opObj12.addParameter(name='code0', value='001110011', type='int')
591 # opObj12.addParameter(name='code1', value='001110011', type='int')
610 # opObj12.addParameter(name='ncode', value='2', format='int')
611 # opObj12.addParameter(name='nbauds', value='8', format='int')
612 # opObj12.addParameter(name='code0', value='001110011', format='int')
613 # opObj12.addParameter(name='code1', value='001110011', format='int')
614
615 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
616
592 617
593 opObj21 = procUnitConfObj2.addOperation(name='CohInt', optype='other')
594 opObj21.addParameter(name='nCohInt', value='10', type='int')
618 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
619 # opObj21.addParameter(name='nCohInt', value='10', format='int')
595 620
596 621
597 622 print "Escribiendo el archivo XML"
@@ -1,5 +1,5
1 1 import matplotlib
2 matplotlib.use("Agg")
2 matplotlib.use("TKAgg")
3 3 import matplotlib.pyplot
4 4 #import scitools.numpyutils
5 5 from mpl_toolkits.axes_grid1 import make_axes_locatable
@@ -69,6 +69,12 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl
69 69 matplotlib.pyplot.tight_layout()
70 70 return imesh
71 71 else:
72 ax.set_xlim([xmin,xmax])
73 ax.set_ylim([ymin,ymax])
74 ax.set_xlabel(xlabel)
75 ax.set_ylabel(ylabel)
76 ax.set_title(title)
77
72 78 z = z.T
73 79 z = z[0:-1,0:-1]
74 80 mesh.set_array(z.ravel())
@@ -10,6 +10,99 import numpy
10 10
11 11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 12
13 def hildebrand_sekhon(data, navg):
14 """
15 This method is for the objective determination of de noise level in Doppler spectra. This
16 implementation technique is based on the fact that the standard deviation of the spectral
17 densities is equal to the mean spectral density for white Gaussian noise
18
19 Inputs:
20 Data : heights
21 navg : numbers of averages
22
23 Return:
24 -1 : any error
25 anoise : noise's level
26 """
27
28 dataflat = data.reshape(-1)
29 dataflat.sort()
30 npts = dataflat.size #numbers of points of the data
31
32 if npts < 32:
33 print "error in noise - requires at least 32 points"
34 return -1.0
35
36 dataflat2 = numpy.power(dataflat,2)
37
38 cs = numpy.cumsum(dataflat)
39 cs2 = numpy.cumsum(dataflat2)
40
41 # data sorted in ascending order
42 nmin = int((npts + 7.)/8)
43
44 for i in range(nmin, npts):
45 s = cs[i]
46 s2 = cs2[i]
47 p = s / float(i);
48 p2 = p**2;
49 q = s2 / float(i) - p2;
50 leftc = p2;
51 rightc = q * float(navg);
52 R2 = leftc/rightc
53
54 # Signal detect: R2 < 1 (R2 = leftc/rightc)
55 if R2 < 1:
56 npts_noise = i
57 break
58
59
60 anoise = numpy.average(dataflat[0:npts_noise])
61
62 return anoise;
63
64 def sorting_bruce(Data, navg):
65 sortdata = numpy.sort(Data)
66 lenOfData = len(Data)
67 nums_min = lenOfData/10
68
69 if (lenOfData/10) > 0:
70 nums_min = lenOfData/10
71 else:
72 nums_min = 0
73
74 rtest = 1.0 + 1.0/navg
75
76 sum = 0.
77
78 sumq = 0.
79
80 j = 0
81
82 cont = 1
83
84 while((cont==1)and(j<lenOfData)):
85
86 sum += sortdata[j]
87
88 sumq += sortdata[j]**2
89
90 j += 1
91
92 if j > nums_min:
93 if ((sumq*j) <= (rtest*sum**2)):
94 lnoise = sum / j
95 else:
96 j = j - 1
97 sum = sum - sordata[j]
98 sumq = sumq - sordata[j]**2
99 cont = 0
100
101 if j == nums_min:
102 lnoise = sum /j
103
104 return lnoise
105
13 106 class JROData:
14 107
15 108 # m_BasicHeader = BasicHeader()
@@ -61,6 +154,10 class JROData:
61 154
62 155 timeInterval = None
63 156
157 nCohInt = None
158
159 noise = None
160
64 161 def __init__(self):
65 162
66 163 raise ValueError, "This class has not been implemented"
@@ -83,8 +180,6 class JROData:
83 180
84 181 class Voltage(JROData):
85 182
86 nCohInt = None
87
88 183 #data es un numpy array de 2 dmensiones (canales, alturas)
89 184 data = None
90 185
@@ -125,6 +220,29 class Voltage(JROData):
125 220
126 221 self.blocksize = None
127 222
223 def getNoisebyHildebrand(self):
224 """
225 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
226
227 Return:
228 noiselevel
229 """
230
231 for channel in range(self.nChannels):
232 daux = self.data_spc[channel,:,:]
233 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
234
235 return self.noise
236
237 def getNoise(self, type = 1):
238
239 self.noise = numpy.zeros(self.nChannels)
240
241 if type == 1:
242 noise = self.getNoisebyHildebrand()
243
244 return 10*numpy.log10(noise)
245
128 246 class Spectra(JROData):
129 247
130 248 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
@@ -181,6 +299,8 class Spectra(JROData):
181 299
182 300 self.utctime = None
183 301
302 self.nCohInt = None
303
184 304 self.nIncohInt = None
185 305
186 306 self.blocksize = None
@@ -195,6 +315,62 class Spectra(JROData):
195 315 xrange = xrange
196 316 return None
197 317
318 def getNoisebyHildebrand(self):
319 """
320 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
321
322 Return:
323 noiselevel
324 """
325
326 for channel in range(self.nChannels):
327 daux = self.data_spc[channel,:,:]
328 self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
329
330 return self.noise
331
332 def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1):
333 """
334 Determina el ruido del canal utilizando la ventana indicada con las coordenadas:
335 (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx)
336
337 Inputs:
338 heiIndexMin: Limite inferior del eje de alturas
339 heiIndexMax: Limite superior del eje de alturas
340 freqIndexMin: Limite inferior del eje de frecuencia
341 freqIndexMax: Limite supoerior del eje de frecuencia
342 """
343
344 data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax]
345
346 for channel in range(self.nChannels):
347 daux = data[channel,:,:]
348 self.noise[channel] = numpy.average(daux)
349
350 return self.noise
351
352 def getNoisebySort(self):
353
354 for channel in range(self.nChannels):
355 daux = self.data_spc[channel,:,:]
356 self.noise[channel] = sorting_bruce(daux, self.nIncohInt)
357
358 return self.noise
359
360 def getNoise(self, type = 1):
361
362 self.noise = numpy.zeros(self.nChannels)
363
364 if type == 1:
365 noise = self.getNoisebyHildebrand()
366
367 if type == 2:
368 noise = self.getNoisebySort()
369
370 if type == 3:
371 noise = self.getNoisebyWindow()
372
373 return 10*numpy.log10(noise)
198 374
199 375 class SpectraHeis(JROData):
200 376
@@ -185,8 +185,6 class JRODataIO:
185 185
186 186 ext = None
187 187
188 flagNoMoreFiles = 0
189
190 188 flagIsNewFile = 1
191 189
192 190 flagTimeBlock = 0
@@ -247,6 +245,7 class JRODataReader(JRODataIO, ProcessingUnit):
247 245
248 246 nFiles = 3 #number of files for searching
249 247
248 flagNoMoreFiles = 0
250 249
251 250 def __init__(self):
252 251
@@ -721,7 +720,7 class JRODataReader(JRODataIO, ProcessingUnit):
721 720 for nTries in range( self.nTries ):
722 721 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
723 722 time.sleep( self.delay )
724 doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=exp)
723 doypath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext)
725 724 if doypath:
726 725 break
727 726
@@ -770,13 +769,28 class JRODataReader(JRODataIO, ProcessingUnit):
770 769 return self.dataOut
771 770
772 771 def getData():
773 pass
772
773 raise ValueError, "This method has not been implemented"
774 774
775 775 def hasNotDataInBuffer():
776 pass
776
777 raise ValueError, "This method has not been implemented"
777 778
778 779 def readBlock():
779 pass
780
781 raise ValueError, "This method has not been implemented"
782
783 def isEndProcess(self):
784
785 return self.flagNoMoreFiles
786
787 def printReadBlocks(self):
788
789 print "Number of read blocks per file %04d" %self.nReadBlocks
790
791 def printTotalBlocks(self):
792
793 print "Number of read blocks %04d" %self.nTotalBlocks
780 794
781 795 def run(self, **kwargs):
782 796
@@ -1277,7 +1291,11 class VoltageReader(JRODataReader):
1277 1291 self.flagTimeBlock
1278 1292 self.flagIsNewBlock
1279 1293 """
1280 if self.flagNoMoreFiles: return 0
1294
1295 if self.flagNoMoreFiles:
1296 self.dataOut.flagNoData = True
1297 print 'Process finished'
1298 return 0
1281 1299
1282 1300 self.flagTimeBlock = 0
1283 1301 self.flagIsNewBlock = 0
@@ -1289,10 +1307,6 class VoltageReader(JRODataReader):
1289 1307
1290 1308 # self.updateDataHeader()
1291 1309
1292 if self.flagNoMoreFiles == 1:
1293 print 'Process finished'
1294 return 0
1295
1296 1310 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1297 1311
1298 1312 if self.datablock == None:
@@ -1388,16 +1402,12 class VoltageWriter(JRODataWriter):
1388 1402
1389 1403 self.flagIsNewBlock = 0
1390 1404
1391 self.flagNoMoreFiles = 0
1392
1393 1405 self.setFile = None
1394 1406
1395 1407 self.dtype = None
1396 1408
1397 1409 self.path = None
1398 1410
1399 self.noMoreFiles = 0
1400
1401 1411 self.filename = None
1402 1412
1403 1413 self.basicHeaderObj = BasicHeader()
@@ -1503,10 +1513,6 class VoltageWriter(JRODataWriter):
1503 1513 self.writeNextBlock()
1504 1514 # self.getDataHeader()
1505 1515
1506 if self.flagNoMoreFiles:
1507 #print 'Process finished'
1508 return 0
1509
1510 1516 return 1
1511 1517
1512 1518 def __getProcessFlags(self):
@@ -1872,10 +1878,13 class SpectraReader(JRODataReader):
1872 1878
1873 1879
1874 1880 if not(self.processingHeaderObj.shif_fft):
1875 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
1881 #desplaza a la derecha en el eje 2 determinadas posiciones
1882 shift = int(self.processingHeaderObj.profilesPerBlock/2)
1883 spc = numpy.roll( spc, shift , axis=2 )
1876 1884
1877 1885 if self.processingHeaderObj.flag_cspc:
1878 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
1886 #desplaza a la derecha en el eje 2 determinadas posiciones
1887 cspc = numpy.roll( cspc, shift, axis=2 )
1879 1888
1880 1889
1881 1890 spc = numpy.transpose( spc, (0,2,1) )
@@ -1918,7 +1927,10 class SpectraReader(JRODataReader):
1918 1927 self.flagIsNewBlock
1919 1928 """
1920 1929
1921 if self.flagNoMoreFiles: return 0
1930 if self.flagNoMoreFiles:
1931 self.dataOut.flagNoData = True
1932 print 'Process finished'
1933 return 0
1922 1934
1923 1935 self.flagTimeBlock = 0
1924 1936 self.flagIsNewBlock = 0
@@ -1926,21 +1938,17 class SpectraReader(JRODataReader):
1926 1938 if self.__hasNotDataInBuffer():
1927 1939
1928 1940 if not( self.readNextBlock() ):
1941 self.dataOut.flagNoData = True
1929 1942 return 0
1930 1943
1931 1944 # self.updateDataHeader()
1932 1945
1933 if self.flagNoMoreFiles == 1:
1934 print 'Process finished'
1935 return 0
1936
1937 1946 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1938 1947
1939 1948 if self.data_dc == None:
1940 1949 self.dataOut.flagNoData = True
1941 1950 return 0
1942 1951
1943
1944 1952 self.dataOut.data_spc = self.data_spc
1945 1953
1946 1954 self.dataOut.data_cspc = self.data_cspc
@@ -2050,8 +2058,6 class SpectraWriter(JRODataWriter):
2050 2058
2051 2059 self.flagIsNewBlock = 0
2052 2060
2053 self.flagNoMoreFiles = 0
2054
2055 2061 self.setFile = None
2056 2062
2057 2063 self.dtype = None
@@ -2187,10 +2193,6 class SpectraWriter(JRODataWriter):
2187 2193 # self.getDataHeader()
2188 2194 self.writeNextBlock()
2189 2195
2190 if self.flagNoMoreFiles:
2191 #print 'Process finished'
2192 return 0
2193
2194 2196 return 1
2195 2197
2196 2198
@@ -3,20 +3,23 import datetime
3 3 from graphics.figure import *
4 4
5 5 class SpectraPlot(Figure):
6
6 7 __isConfig = None
7 8
8 9 def __init__(self):
10
9 11 self.__isConfig = False
10 12 self.width = 850
11 13 self.height = 800
12 14
13 15 def getSubplots(self):
16
14 17 ncol = int(numpy.sqrt(self.nplots)+0.9)
15 18 nrow = int(self.nplots*1./ncol + 0.9)
16 19 return nrow, ncol
17 20
18
19 21 def setAxesWithOutProfiles(self, nrow, ncol):
22
20 23 colspan = 1
21 24 rowspan = 1
22 25 counter = 0
@@ -28,6 +31,7 class SpectraPlot(Figure):
28 31 counter += 1
29 32
30 33 def setAxesWithProfiles(self, nrow, ncol):
34
31 35 colspan = 1
32 36 rowspan = 1
33 37 factor = 2
@@ -42,6 +46,7 class SpectraPlot(Figure):
42 46 counter += 1
43 47
44 48 def setup(self, idfigure, wintitle, width, height, nplots, profile):
49
45 50 self.init(idfigure, wintitle, width, height, nplots)
46 51
47 52 nrow,ncol = self.getSubplots()
@@ -52,8 +57,6 class SpectraPlot(Figure):
52 57 self.setAxesWithOutProfiles(nrow, ncol)
53 58
54 59 def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, profile=False):
55 if dataOut.isEmpty():
56 return None
57 60
58 61 if channelList == None:
59 62 channelList = dataOut.channelList
@@ -66,6 +69,8 class SpectraPlot(Figure):
66 69
67 70 x = numpy.arange(dataOut.nFFTPoints)
68 71
72 noise = dataOut.getNoise()
73
69 74 if not self.__isConfig:
70 75 self.setup(idfigure=idfigure,
71 76 wintitle=wintitle,
@@ -74,12 +79,19 class SpectraPlot(Figure):
74 79 nplots=nplots,
75 80 profile=profile)
76 81
77 if xmin == None: self.xmin = numpy.min(x)
78 if xmax == None: self.xmax = numpy.max(x)
79 if ymin == None: self.ymin = numpy.min(y)
80 if ymax == None: self.ymax = numpy.max(y)
81 if zmin == None: self.zmin = 0
82 if zmax == None: self.zmax = 90
82 if xmin == None: xmin = numpy.min(x)
83 if xmax == None: xmax = numpy.max(x)
84 if ymin == None: ymin = numpy.min(y)
85 if ymax == None: ymax = numpy.max(y)
86 if zmin == None: zmin = numpy.min(z)
87 if zmax == None: zmax = numpy.max(z)
88
89 self.xmin = xmin
90 self.xmax = xmax
91 self.ymin = ymin
92 self.ymax = ymax
93 self.zmin = zmin
94 self.zmax = zmax
83 95
84 96 self.__isConfig = True
85 97
@@ -95,18 +107,13 class SpectraPlot(Figure):
95 107 xlabel = "m/s"
96 108
97 109 for i in range(len(self.axesList)):
98 title = "Channel %d"%i
110 title = "Channel %d: %4.2fdB" %(i, noise[i])
99 111 axes = self.axesList[i]
100 112 z2 = z[i,:,:]
101 113 axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title)
102 114
103
104 115 self.draw()
105 116
106
107
108
109
110 117 class Scope(Figure):
111 118 __isConfig = None
112 119
@@ -175,7 +182,7 class Scope(Figure):
175 182 xlabel = "Range[Km]"
176 183
177 184 for i in range(len(self.axesList)):
178 title = "Channel %d"%i
185 title = "Channel %d: %4.2fdB" %(i, noise[i])
179 186 axes = self.axesList[i]
180 187 y2 = y[i,:]
181 188 axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title)
@@ -86,15 +86,24 class ProcessingUnit:
86 86 if name != 'run':
87 87
88 88 if name == 'init' and self.dataIn.isEmpty():
89 return
89 self.dataOut.flagNoData = True
90 return False
90 91
91 92 if name != 'init' and self.dataOut.isEmpty():
92 return
93 return False
93 94
94 95 methodToCall = getattr(self, name)
95 96
96 97 methodToCall(**kwargs)
97 98
99 if name != 'run':
100 return True
101
102 if self.dataOut.isEmpty():
103 return False
104
105 return True
106
98 107 def callObject(self, objId, **kwargs):
99 108
100 109 """
@@ -112,17 +121,20 class ProcessingUnit:
112 121 """
113 122
114 123 if self.dataOut.isEmpty():
115 return
124 return False
116 125
117 126 object = self.objectDict[objId]
118 127
119 128 object.run(self.dataOut, **kwargs)
120 129
130 return True
131
121 132 def call(self, operationConf, **kwargs):
122 133
123 134 """
124 Ejecuta la operacion "operationConf.name" con los argumentos "**kwargs". La operacion puede
125 ser de dos tipos:
135 Return True si ejecuta la operacion "operationConf.name" con los
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
126 138
127 139 1. Un metodo propio de esta clase:
128 140
@@ -144,12 +156,12 class ProcessingUnit:
144 156 """
145 157
146 158 if operationConf.type == 'self':
147 self.callMethod(operationConf.name, **kwargs)
148 return
159 sts = self.callMethod(operationConf.name, **kwargs)
149 160
150 161 if operationConf.type == 'other':
151 self.callObject(operationConf.id, **kwargs)
152 return
162 sts = self.callObject(operationConf.id, **kwargs)
163
164 return sts
153 165
154 166 def setInput(self, dataIn):
155 167
@@ -213,9 +225,6 class VoltageProc(ProcessingUnit):
213 225
214 226 def selectChannels(self, channelList):
215 227
216 if self.dataIn.isEmpty():
217 return 0
218
219 228 self.selectChannelsByIndex(channelList)
220 229
221 230 def selectChannelsByIndex(self, channelIndexList):
@@ -451,58 +460,13 class CohInt(Operation):
451 460 class SpectraProc(ProcessingUnit):
452 461
453 462 def __init__(self):
463
454 464 self.objectDict = {}
455 465 self.buffer = None
456 466 self.firstdatatime = None
457 467 self.profIndex = 0
458 468 self.dataOut = Spectra()
459 469
460 def init(self, nFFTPoints=None, pairsList=None):
461 if self.dataIn.type == "Spectra":
462 self.dataOut.copy(self.dataIn)
463 return
464
465 if self.dataIn.type == "Voltage":
466
467 if nFFTPoints == None:
468 raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable"
469
470 if pairsList == None:
471 nPairs = 0
472 else:
473 nPairs = len(pairsList)
474
475 self.dataOut.nFFTPoints = nFFTPoints
476 self.dataOut.pairsList = pairsList
477 self.dataOut.nPairs = nPairs
478
479 if self.buffer == None:
480 self.buffer = numpy.zeros((self.dataIn.nChannels,
481 self.dataOut.nFFTPoints,
482 self.dataIn.nHeights),
483 dtype='complex')
484
485
486 self.buffer[:,self.profIndex,:] = self.dataIn.data
487 self.profIndex += 1
488
489 if self.firstdatatime == None:
490 self.firstdatatime = self.dataIn.utctime
491
492 if self.profIndex == self.dataOut.nFFTPoints:
493 self.__updateObjFromInput()
494 self.__getFft()
495
496 self.dataOut.flagNoData = False
497
498 self.buffer = None
499 self.firstdatatime = None
500 self.profIndex = 0
501
502 return
503
504 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
505
506 470 def __updateObjFromInput(self):
507 471
508 472 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
@@ -581,6 +545,92 class SpectraProc(ProcessingUnit):
581 545 self.dataOut.data_dc = dc
582 546 self.dataOut.blockSize = blocksize
583 547
548 def init(self, nFFTPoints=None, pairsList=None):
549
550 if self.dataIn.type == "Spectra":
551 self.dataOut.copy(self.dataIn)
552 return
553
554 if self.dataIn.type == "Voltage":
555
556 if nFFTPoints == None:
557 raise ValueError, "This SpectraProc.setup() need nFFTPoints input variable"
558
559 if pairsList == None:
560 nPairs = 0
561 else:
562 nPairs = len(pairsList)
563
564 self.dataOut.nFFTPoints = nFFTPoints
565 self.dataOut.pairsList = pairsList
566 self.dataOut.nPairs = nPairs
567
568 if self.buffer == None:
569 self.buffer = numpy.zeros((self.dataIn.nChannels,
570 self.dataOut.nFFTPoints,
571 self.dataIn.nHeights),
572 dtype='complex')
573
574
575 self.buffer[:,self.profIndex,:] = self.dataIn.data
576 self.profIndex += 1
577
578 if self.firstdatatime == None:
579 self.firstdatatime = self.dataIn.utctime
580
581 if self.profIndex == self.dataOut.nFFTPoints:
582 self.__updateObjFromInput()
583 self.__getFft()
584
585 self.dataOut.flagNoData = False
586
587 self.buffer = None
588 self.firstdatatime = None
589 self.profIndex = 0
590
591 return
592
593 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
594
595 def selectChannels(self, channelList):
596
597 self.selectChannelsByIndex(channelList)
598
599 def selectChannelsByIndex(self, channelIndexList):
600 """
601 Selecciona un bloque de datos en base a canales segun el channelIndexList
602
603 Input:
604 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
605
606 Affected:
607 self.dataOut.data
608 self.dataOut.channelIndexList
609 self.dataOut.nChannels
610 self.dataOut.m_ProcessingHeader.totalSpectra
611 self.dataOut.systemHeaderObj.numChannels
612 self.dataOut.m_ProcessingHeader.blockSize
613
614 Return:
615 None
616 """
617
618 for channel in channelIndexList:
619 if channel not in self.dataOut.channelIndexList:
620 print channelIndexList
621 raise ValueError, "The value %d in channelIndexList is not valid" %channel
622
623 nChannels = len(channelIndexList)
624
625 data = self.dataOut.data_spc[channelIndexList,:]
626
627 self.dataOut.data_spc = data
628 self.dataOut.channelIndexList = channelIndexList
629 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
630 self.dataOut.nChannels = nChannels
631
632 return 1
633
584 634
585 635 class IncohInt(Operation):
586 636
General Comments 0
You need to be logged in to leave comments. Login now