##// 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 import datetime
10 import datetime
11 from model.jrodataIO import *
11 from model.jrodataIO import *
12 from model.jroprocessing import *
12 from model.jroprocessing import *
13 from model.jroplot import *
13
14
14 def prettify(elem):
15 def prettify(elem):
15 """Return a pretty-printed XML string for the Element.
16 """Return a pretty-printed XML string for the Element.
@@ -23,13 +24,13 class ParameterConf():
23 id = None
24 id = None
24 name = None
25 name = None
25 value = None
26 value = None
26 type = None
27 format = None
27
28
28 ELEMENTNAME = 'Parameter'
29 ELEMENTNAME = 'Parameter'
29
30
30 def __init__(self):
31 def __init__(self):
31
32
32 self.type = 'str'
33 self.format = 'str'
33
34
34 def getElementName(self):
35 def getElementName(self):
35
36
@@ -37,42 +38,42 class ParameterConf():
37
38
38 def getValue(self):
39 def getValue(self):
39
40
40 if self.type == 'list':
41 if self.format == 'list':
41 strList = self.value.split(',')
42 strList = self.value.split(',')
42 return strList
43 return strList
43
44
44 if self.type == 'intlist':
45 if self.format == 'intlist':
45 strList = self.value.split(',')
46 strList = self.value.split(',')
46 intList = [int(x) for x in strList]
47 intList = [int(x) for x in strList]
47 return intList
48 return intList
48
49
49 if self.type == 'floatlist':
50 if self.format == 'floatlist':
50 strList = self.value.split(',')
51 strList = self.value.split(',')
51 floatList = [float(x) for x in strList]
52 floatList = [float(x) for x in strList]
52 return floatList
53 return floatList
53
54
54 if self.type == 'date':
55 if self.format == 'date':
55 strList = self.value.split('/')
56 strList = self.value.split('/')
56 intList = [int(x) for x in strList]
57 intList = [int(x) for x in strList]
57 date = datetime.date(intList[0], intList[1], intList[2])
58 date = datetime.date(intList[0], intList[1], intList[2])
58 return date
59 return date
59
60
60 if self.type == 'time':
61 if self.format == 'time':
61 strList = self.value.split(':')
62 strList = self.value.split(':')
62 intList = [int(x) for x in strList]
63 intList = [int(x) for x in strList]
63 time = datetime.time(intList[0], intList[1], intList[2])
64 time = datetime.time(intList[0], intList[1], intList[2])
64 return time
65 return time
65
66
66 func = eval(self.type)
67 func = eval(self.format)
67
68
68 return func(self.value)
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 self.id = id
73 self.id = id
73 self.name = name
74 self.name = name
74 self.value = str(value)
75 self.value = str(value)
75 self.type = type
76 self.format = format
76
77
77 def makeXml(self, opElement):
78 def makeXml(self, opElement):
78
79
@@ -80,18 +81,18 class ParameterConf():
80 parmElement.set('id', str(self.id))
81 parmElement.set('id', str(self.id))
81 parmElement.set('name', self.name)
82 parmElement.set('name', self.name)
82 parmElement.set('value', self.value)
83 parmElement.set('value', self.value)
83 parmElement.set('type', self.type)
84 parmElement.set('format', self.format)
84
85
85 def readXml(self, parmElement):
86 def readXml(self, parmElement):
86
87
87 self.id = parmElement.get('id')
88 self.id = parmElement.get('id')
88 self.name = parmElement.get('name')
89 self.name = parmElement.get('name')
89 self.value = parmElement.get('value')
90 self.value = parmElement.get('value')
90 self.type = parmElement.get('type')
91 self.format = parmElement.get('format')
91
92
92 def printattr(self):
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 class OperationConf():
97 class OperationConf():
97
98
@@ -133,12 +134,12 class OperationConf():
133
134
134 self.parmConfObjList = []
135 self.parmConfObjList = []
135
136
136 def addParameter(self, name, value, type='str'):
137 def addParameter(self, name, value, format='str'):
137
138
138 id = self.__getNewId()
139 id = self.__getNewId()
139
140
140 parmConfObj = ParameterConf()
141 parmConfObj = ParameterConf()
141 parmConfObj.setup(id, name, value, type)
142 parmConfObj.setup(id, name, value, format)
142
143
143 self.parmConfObjList.append(parmConfObj)
144 self.parmConfObjList.append(parmConfObj)
144
145
@@ -197,7 +198,7 class ProcUnitConf():
197
198
198 id = None
199 id = None
199 name = None
200 name = None
200 type = None
201 datatype = None
201 inputId = None
202 inputId = None
202
203
203 opConfObjList = []
204 opConfObjList = []
@@ -210,7 +211,7 class ProcUnitConf():
210 def __init__(self):
211 def __init__(self):
211
212
212 self.id = None
213 self.id = None
213 self.type = None
214 self.datatype = None
214 self.name = None
215 self.name = None
215 self.inputId = None
216 self.inputId = None
216
217
@@ -247,11 +248,11 class ProcUnitConf():
247
248
248 return self.procUnitObj
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 self.id = id
253 self.id = id
253 self.name = name
254 self.name = name
254 self.type = type
255 self.datatype = datatype
255 self.inputId = inputId
256 self.inputId = inputId
256
257
257 self.opConfObjList = []
258 self.opConfObjList = []
@@ -275,7 +276,7 class ProcUnitConf():
275 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
276 upElement = SubElement(procUnitElement, self.ELEMENTNAME)
276 upElement.set('id', str(self.id))
277 upElement.set('id', str(self.id))
277 upElement.set('name', self.name)
278 upElement.set('name', self.name)
278 upElement.set('type', self.type)
279 upElement.set('datatype', self.datatype)
279 upElement.set('inputId', str(self.inputId))
280 upElement.set('inputId', str(self.inputId))
280
281
281 for opConfObj in self.opConfObjList:
282 for opConfObj in self.opConfObjList:
@@ -285,7 +286,7 class ProcUnitConf():
285
286
286 self.id = upElement.get('id')
287 self.id = upElement.get('id')
287 self.name = upElement.get('name')
288 self.name = upElement.get('name')
288 self.type = upElement.get('type')
289 self.datatype = upElement.get('datatype')
289 self.inputId = upElement.get('inputId')
290 self.inputId = upElement.get('inputId')
290
291
291 self.opConfObjList = []
292 self.opConfObjList = []
@@ -299,10 +300,10 class ProcUnitConf():
299
300
300 def printattr(self):
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 self.id,
304 self.id,
304 self.name,
305 self.name,
305 self.type,
306 self.datatype,
306 self.inputId)
307 self.inputId)
307
308
308 for opConfObj in self.opConfObjList:
309 for opConfObj in self.opConfObjList:
@@ -329,18 +330,22 class ProcUnitConf():
329
330
330 def run(self):
331 def run(self):
331
332
333 finalSts = False
334
332 for opConfObj in self.opConfObjList:
335 for opConfObj in self.opConfObjList:
336
333 kwargs = {}
337 kwargs = {}
334 for parmConfObj in opConfObj.getParameterObjList():
338 for parmConfObj in opConfObj.getParameterObjList():
335 kwargs[parmConfObj.name] = parmConfObj.getValue()
339 kwargs[parmConfObj.name] = parmConfObj.getValue()
336
337 self.procUnitObj.call(opConfObj, **kwargs)
338
340
339
341 #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id)
340
342 sts = self.procUnitObj.call(opConfObj, **kwargs)
343 finalSts = finalSts or sts
344
345 return finalSts
346
341 class ReadUnitConf(ProcUnitConf):
347 class ReadUnitConf(ProcUnitConf):
342
348
343
344 path = None
349 path = None
345 startDate = None
350 startDate = None
346 endDate = None
351 endDate = None
@@ -355,7 +360,7 class ReadUnitConf(ProcUnitConf):
355 def __init__(self):
360 def __init__(self):
356
361
357 self.id = None
362 self.id = None
358 self.type = None
363 self.datatype = None
359 self.name = None
364 self.name = None
360 self.inputId = 0
365 self.inputId = 0
361
366
@@ -366,11 +371,11 class ReadUnitConf(ProcUnitConf):
366
371
367 return self.ELEMENTNAME
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 self.id = id
376 self.id = id
372 self.name = name
377 self.name = name
373 self.type = type
378 self.datatype = datatype
374
379
375 self.path = path
380 self.path = path
376 self.startDate = startDate
381 self.startDate = startDate
@@ -387,14 +392,14 class ReadUnitConf(ProcUnitConf):
387
392
388 opObj = self.addOperation(name = 'run', optype = 'self')
393 opObj = self.addOperation(name = 'run', optype = 'self')
389
394
390 opObj.addParameter(name='path' , value=self.path, type='str')
395 opObj.addParameter(name='path' , value=self.path, format='str')
391 opObj.addParameter(name='startDate' , value=self.startDate, type='date')
396 opObj.addParameter(name='startDate' , value=self.startDate, format='date')
392 opObj.addParameter(name='endDate' , value=self.endDate, type='date')
397 opObj.addParameter(name='endDate' , value=self.endDate, format='date')
393 opObj.addParameter(name='startTime' , value=self.startTime, type='time')
398 opObj.addParameter(name='startTime' , value=self.startTime, format='time')
394 opObj.addParameter(name='endTime' , value=self.endTime, type='time')
399 opObj.addParameter(name='endTime' , value=self.endTime, format='time')
395 opObj.addParameter(name='expLabel' , value=self.expLabel, type='str')
400 opObj.addParameter(name='expLabel' , value=self.expLabel, format='str')
396 opObj.addParameter(name='online' , value=self.online, type='bool')
401 opObj.addParameter(name='online' , value=self.online, format='int')
397 opObj.addParameter(name='delay' , value=self.delay, type='float')
402 opObj.addParameter(name='delay' , value=self.delay, format='float')
398
403
399 return opObj
404 return opObj
400
405
@@ -434,25 +439,25 class Controller():
434 self.name = name
439 self.name = name
435 self.description = description
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 id = self.__getNewId()
444 id = self.__getNewId()
440 name = '%sReader' %(type)
445 name = '%sReader' %(datatype)
441
446
442 readUnitConfObj = ReadUnitConf()
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 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
450 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
446
451
447 return readUnitConfObj
452 return readUnitConfObj
448
453
449 def addProcUnit(self, type, inputId):
454 def addProcUnit(self, datatype, inputId):
450
455
451 id = self.__getNewId()
456 id = self.__getNewId()
452 name = '%sProc' %(type)
457 name = '%sProc' %(datatype)
453
458
454 procUnitConfObj = ProcUnitConf()
459 procUnitConfObj = ProcUnitConf()
455 procUnitConfObj.setup(id, name, type, inputId)
460 procUnitConfObj.setup(id, name, datatype, inputId)
456
461
457 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
462 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
458
463
@@ -556,9 +561,20 class Controller():
556
561
557 # for readUnitConfObj in self.readUnitConfObjList:
562 # for readUnitConfObj in self.readUnitConfObjList:
558 # readUnitConfObj.run()
563 # readUnitConfObj.run()
564
559 while(True):
565 while(True):
566
567 finalSts = False
568
560 for procUnitConfObj in self.procUnitConfObjDict.values():
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 if __name__ == '__main__':
579 if __name__ == '__main__':
564
580
@@ -569,29 +585,38 if __name__ == '__main__':
569
585
570 controllerObj.setup(id = '191', name='test01', description=desc)
586 controllerObj.setup(id = '191', name='test01', description=desc)
571
587
572 readUnitConfObj = controllerObj.addReadUnit(type='Voltage',
588 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
573 path='/home/roj-idl71/Data/RAWDATA/Meteors',
589 path='D:\Data\IMAGING',
574 startDate='2012/01/01',
590 startDate='2011/01/01',
575 endDate='2012/12/31',
591 endDate='2012/12/31',
576 startTime='00:00:00',
592 startTime='00:00:00',
577 endTime='23:59:59',
593 endTime='23:59:59',
578 online=0)
594 online=0)
579
595
580 procUnitConfObj1 = controllerObj.addProcUnit(type='Voltage', inputId=readUnitConfObj.getId())
596 opObj00 = readUnitConfObj.addOperation(name='printTotalBlocks')
581
597
582 procUnitConfObj2 = controllerObj.addProcUnit(type='Voltage', inputId=procUnitConfObj1.getId())
598 procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
583
599
584 opObj11 = procUnitConfObj1.addOperation(name='selectChannels')
600 opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
585 opObj11.addParameter(name='channelList', value='1,2', type='intlist')
601 opObj10.addParameter(name='channelList', value='0,1', format='intlist')
586
602
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')
608
587 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
609 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
588 # opObj12.addParameter(name='ncode', value='2', type='int')
610 # opObj12.addParameter(name='ncode', value='2', format='int')
589 # opObj12.addParameter(name='nbauds', value='8', type='int')
611 # opObj12.addParameter(name='nbauds', value='8', format='int')
590 # opObj12.addParameter(name='code0', value='001110011', type='int')
612 # opObj12.addParameter(name='code0', value='001110011', format='int')
591 # opObj12.addParameter(name='code1', value='001110011', type='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')
618 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
594 opObj21.addParameter(name='nCohInt', value='10', type='int')
619 # opObj21.addParameter(name='nCohInt', value='10', format='int')
595
620
596
621
597 print "Escribiendo el archivo XML"
622 print "Escribiendo el archivo XML"
@@ -1,5 +1,5
1 import matplotlib
1 import matplotlib
2 matplotlib.use("Agg")
2 matplotlib.use("TKAgg")
3 import matplotlib.pyplot
3 import matplotlib.pyplot
4 #import scitools.numpyutils
4 #import scitools.numpyutils
5 from mpl_toolkits.axes_grid1 import make_axes_locatable
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 matplotlib.pyplot.tight_layout()
69 matplotlib.pyplot.tight_layout()
70 return imesh
70 return imesh
71 else:
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 z = z.T
78 z = z.T
73 z = z[0:-1,0:-1]
79 z = z[0:-1,0:-1]
74 mesh.set_array(z.ravel())
80 mesh.set_array(z.ravel())
@@ -10,6 +10,99 import numpy
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
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 class JROData:
106 class JROData:
14
107
15 # m_BasicHeader = BasicHeader()
108 # m_BasicHeader = BasicHeader()
@@ -60,6 +153,10 class JROData:
60 ippSeconds = None
153 ippSeconds = None
61
154
62 timeInterval = None
155 timeInterval = None
156
157 nCohInt = None
158
159 noise = None
63
160
64 def __init__(self):
161 def __init__(self):
65
162
@@ -83,8 +180,6 class JROData:
83
180
84 class Voltage(JROData):
181 class Voltage(JROData):
85
182
86 nCohInt = None
87
88 #data es un numpy array de 2 dmensiones (canales, alturas)
183 #data es un numpy array de 2 dmensiones (canales, alturas)
89 data = None
184 data = None
90
185
@@ -124,7 +219,30 class Voltage(JROData):
124 self.nCohInt = None
219 self.nCohInt = None
125
220
126 self.blocksize = None
221 self.blocksize = None
222
223 def getNoisebyHildebrand(self):
224 """
225 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
226
227 Return:
228 noiselevel
229 """
127
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 class Spectra(JROData):
246 class Spectra(JROData):
129
247
130 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
248 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
@@ -181,6 +299,8 class Spectra(JROData):
181
299
182 self.utctime = None
300 self.utctime = None
183
301
302 self.nCohInt = None
303
184 self.nIncohInt = None
304 self.nIncohInt = None
185
305
186 self.blocksize = None
306 self.blocksize = None
@@ -194,7 +314,63 class Spectra(JROData):
194 xrange = numpy.arange(self.nFFTPoints)
314 xrange = numpy.arange(self.nFFTPoints)
195 xrange = xrange
315 xrange = xrange
196 return None
316 return None
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()
197
372
373 return 10*numpy.log10(noise)
198
374
199 class SpectraHeis(JROData):
375 class SpectraHeis(JROData):
200
376
@@ -185,8 +185,6 class JRODataIO:
185
185
186 ext = None
186 ext = None
187
187
188 flagNoMoreFiles = 0
189
190 flagIsNewFile = 1
188 flagIsNewFile = 1
191
189
192 flagTimeBlock = 0
190 flagTimeBlock = 0
@@ -246,7 +244,8 class JRODataReader(JRODataIO, ProcessingUnit):
246 nTries = 3 #quantity tries
244 nTries = 3 #quantity tries
247
245
248 nFiles = 3 #number of files for searching
246 nFiles = 3 #number of files for searching
249
247
248 flagNoMoreFiles = 0
250
249
251 def __init__(self):
250 def __init__(self):
252
251
@@ -721,7 +720,7 class JRODataReader(JRODataIO, ProcessingUnit):
721 for nTries in range( self.nTries ):
720 for nTries in range( self.nTries ):
722 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
721 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
723 time.sleep( self.delay )
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 if doypath:
724 if doypath:
726 break
725 break
727
726
@@ -770,14 +769,29 class JRODataReader(JRODataIO, ProcessingUnit):
770 return self.dataOut
769 return self.dataOut
771
770
772 def getData():
771 def getData():
773 pass
772
773 raise ValueError, "This method has not been implemented"
774
774
775 def hasNotDataInBuffer():
775 def hasNotDataInBuffer():
776 pass
776
777 raise ValueError, "This method has not been implemented"
777
778
778 def readBlock():
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
780
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
794
781 def run(self, **kwargs):
795 def run(self, **kwargs):
782
796
783 if not(self.isConfig):
797 if not(self.isConfig):
@@ -1277,8 +1291,12 class VoltageReader(JRODataReader):
1277 self.flagTimeBlock
1291 self.flagTimeBlock
1278 self.flagIsNewBlock
1292 self.flagIsNewBlock
1279 """
1293 """
1280 if self.flagNoMoreFiles: return 0
1294
1281
1295 if self.flagNoMoreFiles:
1296 self.dataOut.flagNoData = True
1297 print 'Process finished'
1298 return 0
1299
1282 self.flagTimeBlock = 0
1300 self.flagTimeBlock = 0
1283 self.flagIsNewBlock = 0
1301 self.flagIsNewBlock = 0
1284
1302
@@ -1288,10 +1306,6 class VoltageReader(JRODataReader):
1288 return 0
1306 return 0
1289
1307
1290 # self.updateDataHeader()
1308 # self.updateDataHeader()
1291
1292 if self.flagNoMoreFiles == 1:
1293 print 'Process finished'
1294 return 0
1295
1309
1296 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1310 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1297
1311
@@ -1387,8 +1401,6 class VoltageWriter(JRODataWriter):
1387 self.nTotalBlocks = 0
1401 self.nTotalBlocks = 0
1388
1402
1389 self.flagIsNewBlock = 0
1403 self.flagIsNewBlock = 0
1390
1391 self.flagNoMoreFiles = 0
1392
1404
1393 self.setFile = None
1405 self.setFile = None
1394
1406
@@ -1396,8 +1408,6 class VoltageWriter(JRODataWriter):
1396
1408
1397 self.path = None
1409 self.path = None
1398
1410
1399 self.noMoreFiles = 0
1400
1401 self.filename = None
1411 self.filename = None
1402
1412
1403 self.basicHeaderObj = BasicHeader()
1413 self.basicHeaderObj = BasicHeader()
@@ -1503,10 +1513,6 class VoltageWriter(JRODataWriter):
1503 self.writeNextBlock()
1513 self.writeNextBlock()
1504 # self.getDataHeader()
1514 # self.getDataHeader()
1505
1515
1506 if self.flagNoMoreFiles:
1507 #print 'Process finished'
1508 return 0
1509
1510 return 1
1516 return 1
1511
1517
1512 def __getProcessFlags(self):
1518 def __getProcessFlags(self):
@@ -1872,10 +1878,13 class SpectraReader(JRODataReader):
1872
1878
1873
1879
1874 if not(self.processingHeaderObj.shif_fft):
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 if self.processingHeaderObj.flag_cspc:
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 spc = numpy.transpose( spc, (0,2,1) )
1890 spc = numpy.transpose( spc, (0,2,1) )
@@ -1918,7 +1927,10 class SpectraReader(JRODataReader):
1918 self.flagIsNewBlock
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 self.flagTimeBlock = 0
1935 self.flagTimeBlock = 0
1924 self.flagIsNewBlock = 0
1936 self.flagIsNewBlock = 0
@@ -1926,21 +1938,17 class SpectraReader(JRODataReader):
1926 if self.__hasNotDataInBuffer():
1938 if self.__hasNotDataInBuffer():
1927
1939
1928 if not( self.readNextBlock() ):
1940 if not( self.readNextBlock() ):
1941 self.dataOut.flagNoData = True
1929 return 0
1942 return 0
1930
1943
1931 # self.updateDataHeader()
1944 # self.updateDataHeader()
1932
1945
1933 if self.flagNoMoreFiles == 1:
1934 print 'Process finished'
1935 return 0
1936
1937 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1946 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
1938
1947
1939 if self.data_dc == None:
1948 if self.data_dc == None:
1940 self.dataOut.flagNoData = True
1949 self.dataOut.flagNoData = True
1941 return 0
1950 return 0
1942
1951
1943
1944 self.dataOut.data_spc = self.data_spc
1952 self.dataOut.data_spc = self.data_spc
1945
1953
1946 self.dataOut.data_cspc = self.data_cspc
1954 self.dataOut.data_cspc = self.data_cspc
@@ -2049,8 +2057,6 class SpectraWriter(JRODataWriter):
2049 self.nTotalBlocks = 0
2057 self.nTotalBlocks = 0
2050
2058
2051 self.flagIsNewBlock = 0
2059 self.flagIsNewBlock = 0
2052
2053 self.flagNoMoreFiles = 0
2054
2060
2055 self.setFile = None
2061 self.setFile = None
2056
2062
@@ -2187,10 +2193,6 class SpectraWriter(JRODataWriter):
2187 # self.getDataHeader()
2193 # self.getDataHeader()
2188 self.writeNextBlock()
2194 self.writeNextBlock()
2189
2195
2190 if self.flagNoMoreFiles:
2191 #print 'Process finished'
2192 return 0
2193
2194 return 1
2196 return 1
2195
2197
2196
2198
@@ -3,20 +3,23 import datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class SpectraPlot(Figure):
5 class SpectraPlot(Figure):
6
6 __isConfig = None
7 __isConfig = None
7
8
8 def __init__(self):
9 def __init__(self):
10
9 self.__isConfig = False
11 self.__isConfig = False
10 self.width = 850
12 self.width = 850
11 self.height = 800
13 self.height = 800
12
14
13 def getSubplots(self):
15 def getSubplots(self):
16
14 ncol = int(numpy.sqrt(self.nplots)+0.9)
17 ncol = int(numpy.sqrt(self.nplots)+0.9)
15 nrow = int(self.nplots*1./ncol + 0.9)
18 nrow = int(self.nplots*1./ncol + 0.9)
16 return nrow, ncol
19 return nrow, ncol
17
20
18
19 def setAxesWithOutProfiles(self, nrow, ncol):
21 def setAxesWithOutProfiles(self, nrow, ncol):
22
20 colspan = 1
23 colspan = 1
21 rowspan = 1
24 rowspan = 1
22 counter = 0
25 counter = 0
@@ -28,6 +31,7 class SpectraPlot(Figure):
28 counter += 1
31 counter += 1
29
32
30 def setAxesWithProfiles(self, nrow, ncol):
33 def setAxesWithProfiles(self, nrow, ncol):
34
31 colspan = 1
35 colspan = 1
32 rowspan = 1
36 rowspan = 1
33 factor = 2
37 factor = 2
@@ -42,6 +46,7 class SpectraPlot(Figure):
42 counter += 1
46 counter += 1
43
47
44 def setup(self, idfigure, wintitle, width, height, nplots, profile):
48 def setup(self, idfigure, wintitle, width, height, nplots, profile):
49
45 self.init(idfigure, wintitle, width, height, nplots)
50 self.init(idfigure, wintitle, width, height, nplots)
46
51
47 nrow,ncol = self.getSubplots()
52 nrow,ncol = self.getSubplots()
@@ -52,8 +57,6 class SpectraPlot(Figure):
52 self.setAxesWithOutProfiles(nrow, ncol)
57 self.setAxesWithOutProfiles(nrow, ncol)
53
58
54 def run(self, dataOut, idfigure, wintitle="", channelList=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, profile=False):
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 if channelList == None:
61 if channelList == None:
59 channelList = dataOut.channelList
62 channelList = dataOut.channelList
@@ -66,6 +69,8 class SpectraPlot(Figure):
66
69
67 x = numpy.arange(dataOut.nFFTPoints)
70 x = numpy.arange(dataOut.nFFTPoints)
68
71
72 noise = dataOut.getNoise()
73
69 if not self.__isConfig:
74 if not self.__isConfig:
70 self.setup(idfigure=idfigure,
75 self.setup(idfigure=idfigure,
71 wintitle=wintitle,
76 wintitle=wintitle,
@@ -74,13 +79,20 class SpectraPlot(Figure):
74 nplots=nplots,
79 nplots=nplots,
75 profile=profile)
80 profile=profile)
76
81
77 if xmin == None: self.xmin = numpy.min(x)
82 if xmin == None: xmin = numpy.min(x)
78 if xmax == None: self.xmax = numpy.max(x)
83 if xmax == None: xmax = numpy.max(x)
79 if ymin == None: self.ymin = numpy.min(y)
84 if ymin == None: ymin = numpy.min(y)
80 if ymax == None: self.ymax = numpy.max(y)
85 if ymax == None: ymax = numpy.max(y)
81 if zmin == None: self.zmin = 0
86 if zmin == None: zmin = numpy.min(z)
82 if zmax == None: self.zmax = 90
87 if zmax == None: zmax = numpy.max(z)
83
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
95
84 self.__isConfig = True
96 self.__isConfig = True
85
97
86 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
98 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
@@ -95,17 +107,12 class SpectraPlot(Figure):
95 xlabel = "m/s"
107 xlabel = "m/s"
96
108
97 for i in range(len(self.axesList)):
109 for i in range(len(self.axesList)):
98 title = "Channel %d"%i
110 title = "Channel %d: %4.2fdB" %(i, noise[i])
99 axes = self.axesList[i]
111 axes = self.axesList[i]
100 z2 = z[i,:,:]
112 z2 = z[i,:,:]
101 axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title)
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 self.draw()
115 self.draw()
105
106
107
108
109
116
110 class Scope(Figure):
117 class Scope(Figure):
111 __isConfig = None
118 __isConfig = None
@@ -175,7 +182,7 class Scope(Figure):
175 xlabel = "Range[Km]"
182 xlabel = "Range[Km]"
176
183
177 for i in range(len(self.axesList)):
184 for i in range(len(self.axesList)):
178 title = "Channel %d"%i
185 title = "Channel %d: %4.2fdB" %(i, noise[i])
179 axes = self.axesList[i]
186 axes = self.axesList[i]
180 y2 = y[i,:]
187 y2 = y[i,:]
181 axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title)
188 axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title)
@@ -86,15 +86,24 class ProcessingUnit:
86 if name != 'run':
86 if name != 'run':
87
87
88 if name == 'init' and self.dataIn.isEmpty():
88 if name == 'init' and self.dataIn.isEmpty():
89 return
89 self.dataOut.flagNoData = True
90 return False
90
91
91 if name != 'init' and self.dataOut.isEmpty():
92 if name != 'init' and self.dataOut.isEmpty():
92 return
93 return False
93
94
94 methodToCall = getattr(self, name)
95 methodToCall = getattr(self, name)
95
96
96 methodToCall(**kwargs)
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 def callObject(self, objId, **kwargs):
107 def callObject(self, objId, **kwargs):
99
108
100 """
109 """
@@ -112,17 +121,20 class ProcessingUnit:
112 """
121 """
113
122
114 if self.dataOut.isEmpty():
123 if self.dataOut.isEmpty():
115 return
124 return False
116
125
117 object = self.objectDict[objId]
126 object = self.objectDict[objId]
118
127
119 object.run(self.dataOut, **kwargs)
128 object.run(self.dataOut, **kwargs)
129
130 return True
120
131
121 def call(self, operationConf, **kwargs):
132 def call(self, operationConf, **kwargs):
122
133
123 """
134 """
124 Ejecuta la operacion "operationConf.name" con los argumentos "**kwargs". La operacion puede
135 Return True si ejecuta la operacion "operationConf.name" con los
125 ser de dos tipos:
136 argumentos "**kwargs". False si la operacion no se ha ejecutado.
137 La operacion puede ser de dos tipos:
126
138
127 1. Un metodo propio de esta clase:
139 1. Un metodo propio de esta clase:
128
140
@@ -144,12 +156,12 class ProcessingUnit:
144 """
156 """
145
157
146 if operationConf.type == 'self':
158 if operationConf.type == 'self':
147 self.callMethod(operationConf.name, **kwargs)
159 sts = self.callMethod(operationConf.name, **kwargs)
148 return
149
160
150 if operationConf.type == 'other':
161 if operationConf.type == 'other':
151 self.callObject(operationConf.id, **kwargs)
162 sts = self.callObject(operationConf.id, **kwargs)
152 return
163
164 return sts
153
165
154 def setInput(self, dataIn):
166 def setInput(self, dataIn):
155
167
@@ -213,9 +225,6 class VoltageProc(ProcessingUnit):
213
225
214 def selectChannels(self, channelList):
226 def selectChannels(self, channelList):
215
227
216 if self.dataIn.isEmpty():
217 return 0
218
219 self.selectChannelsByIndex(channelList)
228 self.selectChannelsByIndex(channelList)
220
229
221 def selectChannelsByIndex(self, channelIndexList):
230 def selectChannelsByIndex(self, channelIndexList):
@@ -451,58 +460,13 class CohInt(Operation):
451 class SpectraProc(ProcessingUnit):
460 class SpectraProc(ProcessingUnit):
452
461
453 def __init__(self):
462 def __init__(self):
463
454 self.objectDict = {}
464 self.objectDict = {}
455 self.buffer = None
465 self.buffer = None
456 self.firstdatatime = None
466 self.firstdatatime = None
457 self.profIndex = 0
467 self.profIndex = 0
458 self.dataOut = Spectra()
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 def __updateObjFromInput(self):
470 def __updateObjFromInput(self):
507
471
508 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
472 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
@@ -526,7 +490,7 class SpectraProc(ProcessingUnit):
526 self.dataOut.nIncohInt = 1
490 self.dataOut.nIncohInt = 1
527 self.dataOut.ippSeconds = self.dataIn.ippSeconds
491 self.dataOut.ippSeconds = self.dataIn.ippSeconds
528 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints
492 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints
529
493
530 def __getFft(self):
494 def __getFft(self):
531 """
495 """
532 Convierte valores de Voltaje a Spectra
496 Convierte valores de Voltaje a Spectra
@@ -580,6 +544,92 class SpectraProc(ProcessingUnit):
580 self.dataOut.data_cspc = cspc
544 self.dataOut.data_cspc = cspc
581 self.dataOut.data_dc = dc
545 self.dataOut.data_dc = dc
582 self.dataOut.blockSize = blocksize
546 self.dataOut.blockSize = blocksize
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
583
633
584
634
585 class IncohInt(Operation):
635 class IncohInt(Operation):
General Comments 0
You need to be logged in to leave comments. Login now