##// END OF EJS Templates
Adding the first version of Controller, including some changes in Voltage and Spectra Processors.
Daniel Valdez -
r103:f9ca22364023
parent child
Show More
@@ -0,0 +1,276
1 '''
2 Created on June 5, 2012
3
4 $Author$
5 $Id$
6 '''
7
8 import os
9 import sys
10 import datetime
11 import ConfigParser
12
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
15
16 from Model.Voltage import Voltage
17 from IO.VoltageIO import *
18
19 from Model.Spectra import Spectra
20 from IO.SpectraIO import *
21
22 from Processing.VoltageProcessor import *
23 from Processing.SpectraProcessor import *
24
25 class Operation:
26 def __init__(self,name,parameters):
27 self.name = name
28 self.parameters = []
29 parametersList = parameters.split(',')
30 nparms = len(parametersList)/2
31 for id in range(nparms):
32 parmtype = parametersList[id*2]
33 value = parametersList[id*2+1]
34 if value == 'None':
35 value = None
36 else:
37 if parmtype == 'int':
38 value = int(value)
39 elif parmtype == 'float':
40 value = float(value)
41 elif parmtype == 'str':
42 value = str(value)
43 elif parmtype == 'datetime':
44 value = value.split('-'); value = numpy.asarray(value,dtype=numpy.int32)
45 value = datetime.datetime(value[0],value[1],value[2],value[3],value[4],value[5])
46 else:
47 value = None
48
49 self.parameters.append(value)
50
51
52 class ExecUnit:
53 def __init__(self,):
54 self.id = None
55 self.type = None
56 self.execObjIn = None
57 self.execObjOut = None
58 self.execProcObj = None
59 self.input = None
60 self.operationList = []
61 self.flagSetIO = False
62
63 def setIO(self):
64 self.execProcObj.setIO(self.execObjIn,self.execObjOut)
65 self.flagSetIO = True
66
67
68 def Pfunction(self,name):
69
70 def setup(*args):
71 inputs = args[0]
72 if self.type == 'VoltageReader':
73 path = inputs[0]
74 startDateTime = inputs[1]
75 endDateTime = inputs[2]
76 set = inputs[3]
77 expLabel = inputs[4]
78 ext = inputs[5]
79 online = inputs[6]
80
81 return self.execProcObj.setup(path,startDateTime,endDateTime,set,expLabel,ext,online)
82
83 if self.type == 'Voltage':
84 return self.execProcObj.setup()
85
86 if self.type == 'Spectra':
87 nFFTPoints = inputs[0]
88 pairList = inputs[1]
89 return self.execProcObj.setup(nFFTPoints,pairList)
90
91 def getData(*args):
92
93 return self.execProcObj.getData()
94
95 def init(*args):
96 inputs = args[0]
97
98 parm1 = inputs[0]
99
100 if self.type == 'Voltage':
101 return self.execProcObj.init()
102
103 if self.type == 'Spectra':
104 return self.execProcObj.init()
105
106
107 def plotData(*args):
108 inputs = args[0]
109
110 if self.type == 'Voltage':
111 xmin = inputs[0]
112 xmax = inputs[1]
113 ymin = inputs[2]
114 ymax = inputs[3]
115 type = inputs[4]
116 winTitle = inputs[5]
117 index = inputs[6]
118
119 return self.execProcObj.plotData(xmin,xmax,ymin,ymax,type,winTitle,index)
120
121 if self.type == 'Spectra':
122 xmin = inputs[0]
123 xmax = inputs[1]
124 ymin = inputs[2]
125 ymax = inputs[3]
126 winTitle = inputs[4]
127 index = inputs[5]
128
129 return self.execProcObj.plotData(xmin,xmax,ymin,ymax,winTitle,index)
130
131 def integrator(*args):
132 inputs = args[0]
133 N = inputs[0]
134 self.execProcObj.integrator(N)
135
136 pfuncDict = { "setup": setup,
137 "getdata": getData,
138 "init": init,
139 "plotdata": plotData,
140 "integrator": integrator}
141
142 return pfuncDict[name]
143
144
145 def run(self):
146 nopers = len(self.operationList)
147 for idOper in range(nopers):
148 operObj = self.operationList[idOper]
149 self.Pfunction(operObj.name)(operObj.parameters)
150
151
152 class Controller:
153
154 def __init__(self):
155 self.sectionList = None
156 self.execUnitList = None
157 self.execObjList = None
158 self.readConfigFile()
159 self.createObjects()
160 self.setupOjects()
161 self.start()
162
163 def readConfigFile(self, filename='experiment.cfg'):
164
165 parser = ConfigParser.SafeConfigParser()
166 parser.read(filename)
167 self.sectionList = parser.sections()
168 self.execUnitList = []
169
170 for section_name in self.sectionList:
171 itemList = parser.items(section_name)
172 self.execUnitList.append(itemList)
173
174 print
175
176 def createObjects(self):
177 self.execObjList = []
178
179 for itemList in self.execUnitList:
180 execObj = ExecUnit()
181 for item in itemList:
182 name, value = item[0], item[1]
183
184 if name == 'id':
185 execObj.id = int(value)
186 continue
187
188 if name == 'type':
189 execObj.type = value
190
191 if value == 'VoltageReader':
192 execObj.execObjOut = Voltage()
193 execObj.execProcObj = VoltageReader(execObj.execObjOut)
194
195
196 if value == 'SpectraReader':
197 execObj.execObjOut = Spectra()
198 execObj.execProcObj = SpectraReader(execObj.execObjOut)
199
200
201 if value == 'CorrelationReader':
202 execObj.execObjOut = Correlation()
203 execObj.execProcObj = CorrelationReader(execObj.execObjOut)
204
205
206 if value == 'Voltage':
207 execObj.execProcObj = VoltageProcessor()
208 execObj.execObjOut = Voltage()
209
210 if value == 'Spectra':
211 execObj.execProcObj = SpectraProcessor()
212 execObj.execObjOut = Spectra()
213
214 if value == 'Correlation':
215 execObj.execProcObj = CorrelationProcessor()
216 execObj.execObjOut = Correlation()
217
218 elif name == 'input':
219 execObj.input = int(value)
220
221 else:
222 operObj = Operation(name,value)
223
224 if name != 'setup':
225 execObj.operationList.append(operObj)
226 else:
227 execObj.Pfunction(name)(operObj.parameters)
228
229 del(operObj)
230
231 self.execObjList.append(execObj)
232 del(execObj)
233
234
235
236 def setupOjects(self):
237 for objIndex in range(len(self.execObjList)):
238 currExecObj = self.execObjList[objIndex]
239
240 if not(currExecObj.type in ['VoltageReader','SpectraReader','CorrelationReader']):
241
242 idSearch = currExecObj.input
243
244 for objIndex2 in range(len(self.execObjList)):
245
246 lastExecObj = self.execObjList[objIndex2] # este objeto si puede ser un readerl
247
248 if lastExecObj.id == idSearch and currExecObj.flagSetIO == False:
249 currExecObj.execObjIn = lastExecObj.execObjOut
250 currExecObj.setIO()
251
252
253
254
255
256
257 def start(self):
258
259 while(True):
260 for indexObj in range(len(self.execObjList)):
261 ExecObj = self.execObjList[indexObj]
262 ExecObj.run()
263
264 readExecObj = self.execObjList[0] # se asume que el primer elemento es un Reader
265 if readExecObj.execProcObj.flagNoMoreFiles:
266 break
267 if readExecObj.execProcObj.flagIsNewBlock:
268 print 'Block No %04d, Time: %s' %(readExecObj.execProcObj.nTotalBlocks,
269 datetime.datetime.fromtimestamp(readExecObj.execProcObj.m_BasicHeader.utc),)
270
271
272
273
274 if __name__ == '__main__':
275 Controller()
276 No newline at end of file
@@ -0,0 +1,23
1 [Read0]
2 id = 0
3 type = VoltageReader
4 setup = str,/Users/jro/Documents/RadarData/EW_Drifts,datetime,2011-11-20-0-0-1,datetime,2011-12-31-0-0-1,int,0,str,,str,None,int,0
5 getData = None,None
6
7 [Processing0]
8 id = 1
9 type = Voltage
10 input = 0
11 setup = None,None
12 init = None,None
13 integrator = int,10
14
15
16 [Processing1]
17 id = 2
18 type = Spectra
19 input = 1
20 setup = int,1024,None,None
21 init = None,None
22 integrator = int,2
23 plotData = float,None,float,None,float,None,float,None,str,Test Spectra Data,int,1
@@ -1,548 +1,569
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import numpy
9 9
10 10 path = os.path.split(os.getcwd())[0]
11 11 sys.path.append(path)
12 12
13 13 from Model.Spectra import Spectra
14 14 from IO.SpectraIO import SpectraWriter
15 15 from Graphics.SpectraPlot import Spectrum
16 16
17 17
18 18 class SpectraProcessor:
19 19 '''
20 20 classdocs
21 21 '''
22 22
23 23 dataInObj = None
24 24
25 25 dataOutObj = None
26 26
27 27 integratorObjIndex = None
28 28
29 29 decoderObjIndex = None
30 30
31 31 writerObjIndex = None
32 32
33 33 plotterObjIndex = None
34 34
35 35 integratorObjList = []
36 36
37 37 decoderObjList = []
38 38
39 39 writerObjList = []
40 40
41 41 plotterObjList = []
42 42
43 43 buffer = None
44 44
45 45 ptsId = 0
46 46
47 47 nFFTPoints = None
48 48
49 49 pairList = None
50 50
51 51
52 def __init__(self, dataInObj, dataOutObj=None):
52 def __init__(self, dataInObj=None, dataOutObj=None):
53 53 '''
54 54 Constructor
55 55 '''
56 56 self.dataInObj = dataInObj
57 57
58 58 if dataOutObj == None:
59 59 self.dataOutObj = Spectra()
60 60 else:
61 61 self.dataOutObj = dataOutObj
62 62
63 63 self.integratorObjIndex = None
64 64 self.decoderObjIndex = None
65 65 self.writerObjIndex = None
66 66 self.plotterObjIndex = None
67 67
68 68 self.integratorObjList = []
69 69 self.decoderObjList = []
70 70 self.writerObjList = []
71 71 self.plotterObjList = []
72 72
73 73 self.buffer = None
74 74 self.ptsId = 0
75 75
76 def init(self, nFFTPoints, pairList=None):
76 def setIO(self,inputObject, outputObject):
77 77
78 self.integratorObjIndex = 0
79 self.decoderObjIndex = 0
80 self.writerObjIndex = 0
81 self.plotterObjIndex = 0
78 # if not( isinstance(inputObject, Voltage) ):
79 # print 'InputObject must be an instance from Voltage()'
80 # sys.exit(0)
82 81
82 if not( isinstance(outputObject, Spectra) ):
83 print 'OutputObject must be an instance from Spectra()'
84 sys.exit(0)
85
86 self.dataInObj = inputObject
87 self.dataOutObj = outputObject
88
89 def setup(self,nFFTPoints=None, pairList=None):
83 90 if nFFTPoints == None:
84 91 nFFTPoints = self.dataOutObj.nFFTPoints
85 92
86 93 self.nFFTPoints = nFFTPoints
87 94 self.pairList = pairList
88
95
96 # def init(self, nFFTPoints, pairList=None):
97 def init(self):
98
99 self.integratorObjIndex = 0
100 self.decoderObjIndex = 0
101 self.writerObjIndex = 0
102 self.plotterObjIndex = 0
103
104 # if nFFTPoints == None:
105 # nFFTPoints = self.dataOutObj.nFFTPoints
106 #
107 # self.nFFTPoints = nFFTPoints
108 # self.pairList = pairList
109 #
89 110 if not( isinstance(self.dataInObj, Spectra) ):
90 111 self.__getFft()
91 112 else:
92 113 self.dataOutObj.copy(self.dataInObj)
93 114
94 115
95 116 def __getFft(self):
96 117 """
97 118 Convierte valores de Voltaje a Spectra
98 119
99 120 Affected:
100 121 self.dataOutObj.data_spc
101 122 self.dataOutObj.data_cspc
102 123 self.dataOutObj.data_dc
103 124 self.dataOutObj.heightList
104 125 self.dataOutObj.m_BasicHeader
105 126 self.dataOutObj.m_ProcessingHeader
106 127 self.dataOutObj.m_RadarControllerHeader
107 128 self.dataOutObj.m_SystemHeader
108 129 self.ptsId
109 130 self.buffer
110 131 self.dataOutObj.flagNoData
111 132 self.dataOutObj.dataType
112 133 self.dataOutObj.nPairs
113 134 self.dataOutObj.nChannels
114 135 self.dataOutObj.nProfiles
115 136 self.dataOutObj.m_SystemHeader.numChannels
116 137 self.dataOutObj.m_ProcessingHeader.totalSpectra
117 138 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
118 139 self.dataOutObj.m_ProcessingHeader.numHeights
119 140 self.dataOutObj.m_ProcessingHeader.spectraComb
120 141 self.dataOutObj.m_ProcessingHeader.shif_fft
121 142 """
122 143 blocksize = 0
123 144 nFFTPoints = self.nFFTPoints
124 145 nChannels, nheis = self.dataInObj.data.shape
125 146
126 147 if self.buffer == None:
127 148 self.buffer = numpy.zeros((nChannels, nFFTPoints, nheis), dtype='complex')
128 149
129 150 self.buffer[:,self.ptsId,:] = self.dataInObj.data
130 151 self.ptsId += 1
131 152
132 153 if self.ptsId < self.dataOutObj.nFFTPoints:
133 154 self.dataOutObj.flagNoData = True
134 155 return
135 156
136 157 fft_volt = numpy.fft.fft(self.buffer,axis=1)
137 158 dc = fft_volt[:,0,:]
138 159
139 160 #calculo de self-spectra
140 161 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
141 162 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
142 163
143 164 blocksize += dc.size
144 165 blocksize += spc.size
145 166
146 167 cspc = None
147 168 nPair = 0
148 169 if self.pairList != None:
149 170 #calculo de cross-spectra
150 171 nPairs = len(self.pairList)
151 172 cspc = numpy.zeros((nPairs, nFFTPoints, nheis), dtype='complex')
152 173 for pair in self.pairList:
153 174 cspc[nPair,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
154 175 nPair += 1
155 176 blocksize += cspc.size
156 177
157 178 self.dataOutObj.data_spc = spc
158 179 self.dataOutObj.data_cspc = cspc
159 180 self.dataOutObj.data_dc = dc
160 181
161 182 self.ptsId = 0
162 183 self.buffer = None
163 184 self.dataOutObj.flagNoData = False
164 185
165 186 self.dataOutObj.heightList = self.dataInObj.heightList
166 187 self.dataOutObj.channelList = self.dataInObj.channelList
167 188 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
168 189 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
169 190 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
170 191 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
171 192
172 193 self.dataOutObj.dataType = self.dataInObj.dataType
173 194 self.dataOutObj.nPairs = nPair
174 195 self.dataOutObj.nChannels = nChannels
175 196 self.dataOutObj.nProfiles = nFFTPoints
176 197 self.dataOutObj.nHeights = nheis
177 198 self.dataOutObj.nFFTPoints = nFFTPoints
178 199 #self.dataOutObj.data = None
179 200
180 201 self.dataOutObj.m_SystemHeader.numChannels = nChannels
181 202 self.dataOutObj.m_SystemHeader.nProfiles = nFFTPoints
182 203
183 204 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
184 205 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPair
185 206 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = nFFTPoints
186 207 self.dataOutObj.m_ProcessingHeader.numHeights = nheis
187 208 self.dataOutObj.m_ProcessingHeader.shif_fft = True
188 209
189 210 spectraComb = numpy.zeros( (nChannels+nPair)*2,numpy.dtype('u1'))
190 211 k = 0
191 212 for i in range( 0,nChannels*2,2 ):
192 213 spectraComb[i] = k
193 214 spectraComb[i+1] = k
194 215 k += 1
195 216
196 217 k *= 2
197 218
198 219 if self.pairList != None:
199 220
200 221 for pair in self.pairList:
201 222 spectraComb[k] = pair[0]
202 223 spectraComb[k+1] = pair[1]
203 224 k += 2
204 225
205 226 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
206 227
207 228
208 229 def addWriter(self,wrpath):
209 230 objWriter = SpectraWriter(self.dataOutObj)
210 231 objWriter.setup(wrpath)
211 232 self.writerObjList.append(objWriter)
212 233
213 234
214 235 def addPlotter(self, index=None):
215 236
216 237 if index==None:
217 238 index = self.plotterObjIndex
218 239
219 240 plotObj = Spectrum(self.dataOutObj, index)
220 241 self.plotterObjList.append(plotObj)
221 242
222 243
223 244 def addIntegrator(self,N):
224 245
225 246 objIncohInt = IncoherentIntegration(N)
226 247 self.integratorObjList.append(objIncohInt)
227 248
228 249
229 250 def writeData(self, wrpath):
230 251 if self.dataOutObj.flagNoData:
231 252 return 0
232 253
233 254 if len(self.writerObjList) <= self.writerObjIndex:
234 255 self.addWriter(wrpath)
235 256
236 257 self.writerObjList[self.writerObjIndex].putData()
237 258
238 259 self.writerObjIndex += 1
239 260
240 261 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None):
241 262 if self.dataOutObj.flagNoData:
242 263 return 0
243 264
244 265 if len(self.plotterObjList) <= self.plotterObjIndex:
245 266 self.addPlotter(index)
246 267
247 268 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
248 269
249 270 self.plotterObjIndex += 1
250 271
251 272 def integrator(self, N):
252 273 if self.dataOutObj.flagNoData:
253 274 return 0
254 275
255 276 if len(self.integratorObjList) <= self.integratorObjIndex:
256 277 self.addIntegrator(N)
257 278
258 279 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
259 280 myCohIntObj.exe(self.dataOutObj.data_spc)
260 281
261 282 if myCohIntObj.flag:
262 283 self.dataOutObj.data_spc = myCohIntObj.data
263 284 self.dataOutObj.m_ProcessingHeader.incoherentInt *= N
264 285 self.dataOutObj.flagNoData = False
265 286
266 287 else:
267 288 self.dataOutObj.flagNoData = True
268 289
269 290 self.integratorObjIndex += 1
270 291
271 292 def removeDC(self, type):
272 293
273 294 if self.dataOutObj.flagNoData:
274 295 return 0
275 296 pass
276 297
277 298 def removeInterference(self):
278 299
279 300 if self.dataOutObj.flagNoData:
280 301 return 0
281 302 pass
282 303
283 304 def removeSatellites(self):
284 305
285 306 if self.dataOutObj.flagNoData:
286 307 return 0
287 308 pass
288 309
289 310 def selectChannels(self, channelList, pairList=None):
290 311 """
291 312 Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList
292 313
293 314 Input:
294 315 channelList : lista sencilla de canales a seleccionar por ej. (2,3,7)
295 316 pairList : tupla de pares que se desea selecionar por ej. ( (0,1), (0,2) )
296 317
297 318 Affected:
298 319 self.dataOutObj.data_spc
299 320 self.dataOutObj.data_cspc
300 321 self.dataOutObj.data_dc
301 322 self.dataOutObj.nChannels
302 323 self.dataOutObj.nPairs
303 324 self.dataOutObj.m_ProcessingHeader.spectraComb
304 325 self.dataOutObj.m_SystemHeader.numChannels
305 326
306 327 Return:
307 328 None
308 329 """
309 330
310 331 if self.dataOutObj.flagNoData:
311 332 return 0
312 333
313 334 channelIndexList = []
314 335 for channel in channelList:
315 336 if channel in self.dataOutObj.channelList:
316 337 index = self.dataOutObj.channelList.index(channel)
317 338 channelIndexList.append(index)
318 339 continue
319 340
320 341 raise ValueError, "The value %d in channelList is not valid" %channel
321 342
322 343 nProfiles = self.dataOutObj.nProfiles
323 344 #dataType = self.dataOutObj.dataType
324 345 nHeights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights
325 346 blocksize = 0
326 347
327 348 #self spectra
328 349 nChannels = len(channelIndexList)
329 350 spc = numpy.zeros( (nChannels,nProfiles,nHeights), dtype='float' ) #dataType[0] )
330 351
331 352 for index, channel in enumerate(channelIndexList):
332 353 spc[index,:,:] = self.dataOutObj.data_spc[index,:,:]
333 354
334 355 #DC channel
335 356 dc = numpy.zeros( (nChannels,nHeights), dtype='complex' )
336 357 for index, channel in enumerate(channelIndexList):
337 358 dc[index,:] = self.dataOutObj.data_dc[channel,:]
338 359
339 360 blocksize += dc.size
340 361 blocksize += spc.size
341 362
342 363 nPairs = 0
343 364 cspc = None
344 365
345 366 if pairList == None:
346 367 pairList = self.pairList
347 368
348 369 if (pairList != None) and (self.dataOutObj.data_cspc != None):
349 370 #cross spectra
350 371 nPairs = len(pairList)
351 372 cspc = numpy.zeros( (nPairs,nProfiles,nHeights), dtype='complex' )
352 373
353 374 spectraComb = self.dataOutObj.m_ProcessingHeader.spectraComb
354 375 totalSpectra = len(spectraComb)
355 376 nchan = self.dataOutObj.nChannels
356 377 pairIndexList = []
357 378
358 379 for pair in pairList: #busco el par en la lista de pares del Spectra Combinations
359 380 for index in range(0,totalSpectra,2):
360 381 if pair[0] == spectraComb[index] and pair[1] == spectraComb[index+1]:
361 382 pairIndexList.append( index/2 - nchan )
362 383
363 384 for index, pair in enumerate(pairIndexList):
364 385 cspc[index,:,:] = self.dataOutObj.data_cspc[pair,:,:]
365 386 blocksize += cspc.size
366 387
367 388 else:
368 389 pairList = self.pairList
369 390 cspc = self.dataOutObj.data_cspc
370 391 if cspc != None:
371 392 blocksize += cspc.size
372 393
373 394 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
374 395 i = 0
375 396 for val in channelList:
376 397 spectraComb[i] = val
377 398 spectraComb[i+1] = val
378 399 i += 2
379 400
380 401 if pairList != None:
381 402 for pair in pairList:
382 403 spectraComb[i] = pair[0]
383 404 spectraComb[i+1] = pair[1]
384 405 i += 2
385 406
386 407 self.dataOutObj.data_spc = spc
387 408 self.dataOutObj.data_cspc = cspc
388 409 self.dataOutObj.data_dc = dc
389 410 self.dataOutObj.nChannels = nChannels
390 411 self.dataOutObj.nPairs = nPairs
391 412
392 413 self.dataOutObj.channelList = channelList
393 414
394 415 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
395 416 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
396 417 self.dataOutObj.m_SystemHeader.numChannels = nChannels
397 418 self.dataOutObj.nChannels = nChannels
398 419 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
399 420
400 421
401 422 def selectHeightsByValue(self, minHei, maxHei):
402 423 """
403 424 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
404 425 minHei <= height <= maxHei
405 426
406 427 Input:
407 428 minHei : valor minimo de altura a considerar
408 429 maxHei : valor maximo de altura a considerar
409 430
410 431 Affected:
411 432 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
412 433
413 434 Return:
414 435 None
415 436 """
416 437
417 438 if self.dataOutObj.flagNoData:
418 439 return 0
419 440
420 441 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
421 442 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
422 443
423 444 if (maxHei > self.dataOutObj.heightList[-1]):
424 445 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
425 446
426 447 minIndex = 0
427 448 maxIndex = 0
428 449 data = self.dataOutObj.heightList
429 450
430 451 for i,val in enumerate(data):
431 452 if val < minHei:
432 453 continue
433 454 else:
434 455 minIndex = i;
435 456 break
436 457
437 458 for i,val in enumerate(data):
438 459 if val <= maxHei:
439 460 maxIndex = i;
440 461 else:
441 462 break
442 463
443 464 self.selectHeightsByIndex(minIndex, maxIndex)
444 465
445 466
446 467 def selectHeightsByIndex(self, minIndex, maxIndex):
447 468 """
448 469 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
449 470 minIndex <= index <= maxIndex
450 471
451 472 Input:
452 473 minIndex : valor minimo de altura a considerar
453 474 maxIndex : valor maximo de altura a considerar
454 475
455 476 Affected:
456 477 self.dataOutObj.data_spc
457 478 self.dataOutObj.data_cspc
458 479 self.dataOutObj.data_dc
459 480 self.dataOutObj.heightList
460 481 self.dataOutObj.nHeights
461 482 self.dataOutObj.m_ProcessingHeader.numHeights
462 483 self.dataOutObj.m_ProcessingHeader.blockSize
463 484 self.dataOutObj.m_ProcessingHeader.firstHeight
464 485 self.dataOutObj.m_RadarControllerHeader.numHeights
465 486
466 487 Return:
467 488 None
468 489 """
469 490
470 491 if self.dataOutObj.flagNoData:
471 492 return 0
472 493
473 494 if (minIndex < 0) or (minIndex > maxIndex):
474 495 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
475 496
476 497 if (maxIndex >= self.dataOutObj.nHeights):
477 498 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
478 499
479 500 nChannels = self.dataOutObj.nChannels
480 501 nPairs = self.dataOutObj.nPairs
481 502 nProfiles = self.dataOutObj.nProfiles
482 503 dataType = self.dataOutObj.dataType
483 504 nHeights = maxIndex - minIndex + 1
484 505 blockSize = 0
485 506
486 507 #self spectra
487 508 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
488 509 blockSize += spc.size
489 510
490 511 #cross spectra
491 512 cspc = None
492 513 if self.dataOutObj.data_cspc != None:
493 514 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
494 515 blockSize += cspc.size
495 516
496 517 #DC channel
497 518 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
498 519 blockSize += dc.size
499 520
500 521 self.dataOutObj.data_spc = spc
501 522 if cspc != None:
502 523 self.dataOutObj.data_cspc = cspc
503 524 self.dataOutObj.data_dc = dc
504 525
505 526 firstHeight = self.dataOutObj.heightList[minIndex]
506 527
507 528 self.dataOutObj.nHeights = nHeights
508 529 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
509 530 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
510 531 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
511 532 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
512 533
513 534 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
514 535
515 536
516 537 class IncoherentIntegration:
517 538
518 539 profCounter = 1
519 540 data = None
520 541 buffer = None
521 542 flag = False
522 543 nIncohInt = None
523 544
524 545 def __init__(self, N):
525 546
526 547 self.profCounter = 1
527 548 self.data = None
528 549 self.buffer = None
529 550 self.flag = False
530 551 self.nIncohInt = N
531 552
532 553 def exe(self,data):
533 554
534 555 if self.buffer == None:
535 556 self.buffer = data
536 557 else:
537 558 self.buffer = self.buffer + data
538 559
539 560 if self.profCounter == self.nIncohInt:
540 561 self.data = self.buffer
541 562 self.buffer = None
542 563 self.profCounter = 0
543 564 self.flag = True
544 565 else:
545 566 self.flag = False
546 567
547 568 self.profCounter += 1
548 569
@@ -1,531 +1,549
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from Model.Voltage import Voltage
15 15 from IO.VoltageIO import VoltageWriter
16 16 from Graphics.VoltagePlot import Osciloscope
17 17
18 18 class VoltageProcessor:
19 19 '''
20 20 classdocs
21 21 '''
22 22
23 23 dataInObj = None
24 24 dataOutObj = None
25 25
26 26 integratorObjIndex = None
27 27 decoderObjIndex = None
28 28 profSelectorObjIndex = None
29 29 writerObjIndex = None
30 30 plotterObjIndex = None
31 31 flipIndex = None
32 32
33 33 integratorObjList = []
34 34 decoderObjList = []
35 35 profileSelectorObjList = []
36 36 writerObjList = []
37 37 plotterObjList = []
38 38 m_Voltage= Voltage()
39 39
40 def __init__(self, dataInObj, dataOutObj=None):
40 def __init__(self, dataInObj=None, dataOutObj=None):
41 41 '''
42 42 Constructor
43 43 '''
44 44
45 45 self.dataInObj = dataInObj
46 46
47 47 if dataOutObj == None:
48 48 self.dataOutObj = Voltage()
49 49 else:
50 50 self.dataOutObj = dataOutObj
51 51
52 52 self.integratorObjIndex = None
53 53 self.decoderObjIndex = None
54 54 self.profSelectorObjIndex = None
55 55 self.writerObjIndex = None
56 56 self.plotterObjIndex = None
57 57 self.flipIndex = 1
58 58 self.integratorObjList = []
59 59 self.decoderObjList = []
60 60 self.profileSelectorObjList = []
61 61 self.writerObjList = []
62 62 self.plotterObjList = []
63 63
64 def setIO(self,inputObject, outputObject):
65
66 if not( isinstance(inputObject, Voltage) ):
67 print 'InputObject must be an instance from Voltage()'
68 sys.exit(0)
69
70 if not( isinstance(outputObject, Voltage) ):
71 print 'OutputObject must be an instance from Voltage()'
72 sys.exit(0)
73
74 self.dataInObj = inputObject
75 self.dataOutObj = outputObject
76
77 def setup(self):
78 pass
79
64 80 def init(self):
65 81
66 82 self.integratorObjIndex = 0
67 83 self.decoderObjIndex = 0
68 84 self.profSelectorObjIndex = 0
69 85 self.writerObjIndex = 0
70 86 self.plotterObjIndex = 0
71 87 self.dataOutObj.copy(self.dataInObj)
72 88
73 89 if self.profSelectorObjIndex != None:
74 90 for profSelObj in self.profileSelectorObjList:
75 91 profSelObj.incIndex()
76 92
77 93 def addWriter(self, wrpath):
78 94 objWriter = VoltageWriter(self.dataOutObj)
79 95 objWriter.setup(wrpath)
80 96 self.writerObjList.append(objWriter)
81 97
82 def addPlotter(self):
98 def addPlotter(self, index=None):
99 if index==None:
100 index = self.plotterObjIndex
83 101
84 plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex)
102 plotObj = Osciloscope(self.dataOutObj, index)
85 103 self.plotterObjList.append(plotObj)
86
104
87 105 def addIntegrator(self, nCohInt):
88 106
89 107 objCohInt = CoherentIntegrator(nCohInt)
90 108 self.integratorObjList.append(objCohInt)
91 109
92 110 def addDecoder(self, code, ncode, nbaud):
93 111
94 112 objDecoder = Decoder(code,ncode,nbaud)
95 113 self.decoderObjList.append(objDecoder)
96 114
97 115 def addProfileSelector(self, nProfiles):
98 116
99 117 objProfSelector = ProfileSelector(nProfiles)
100 118 self.profileSelectorObjList.append(objProfSelector)
101 119
102 120 def writeData(self,wrpath):
103 121
104 122 if self.dataOutObj.flagNoData:
105 123 return 0
106 124
107 125 if len(self.writerObjList) <= self.writerObjIndex:
108 126 self.addWriter(wrpath)
109 127
110 128 self.writerObjList[self.writerObjIndex].putData()
111 129
112 130 # myWrObj = self.writerObjList[self.writerObjIndex]
113 131 # myWrObj.putData()
114 132
115 133 self.writerObjIndex += 1
116 134
117 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
135 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
118 136 if self.dataOutObj.flagNoData:
119 137 return 0
120
138
121 139 if len(self.plotterObjList) <= self.plotterObjIndex:
122 self.addPlotter()
140 self.addPlotter(index)
123 141
124 self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
142 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
125 143
126 144 self.plotterObjIndex += 1
127 145
128 146 def integrator(self, N):
129 147
130 148 if self.dataOutObj.flagNoData:
131 149 return 0
132 150
133 151 if len(self.integratorObjList) <= self.integratorObjIndex:
134 152 self.addIntegrator(N)
135 153
136 154 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
137 155 myCohIntObj.exe(self.dataOutObj.data)
138 156
139 157 if myCohIntObj.flag:
140 158 self.dataOutObj.data = myCohIntObj.data
141 159 self.dataOutObj.m_ProcessingHeader.coherentInt *= N
142 160 self.dataOutObj.flagNoData = False
143 161
144 162 else:
145 163 self.dataOutObj.flagNoData = True
146 164
147 165 self.integratorObjIndex += 1
148 166
149 167 def decoder(self,code=None,type = 0):
150 168
151 169 if self.dataOutObj.flagNoData:
152 170 return 0
153 171
154 172 if code == None:
155 173 code = self.dataOutObj.m_RadarControllerHeader.code
156 174 ncode, nbaud = code.shape
157 175
158 176 if len(self.decoderObjList) <= self.decoderObjIndex:
159 177 self.addDecoder(code,ncode,nbaud)
160 178
161 179 myDecodObj = self.decoderObjList[self.decoderObjIndex]
162 180 myDecodObj.exe(data=self.dataOutObj.data,type=type)
163 181
164 182 if myDecodObj.flag:
165 183 self.dataOutObj.data = myDecodObj.data
166 184 self.dataOutObj.flagNoData = False
167 185 else:
168 186 self.dataOutObj.flagNoData = True
169 187
170 188 self.decoderObjIndex += 1
171 189
172 190
173 191 def filterByHei(self, window):
174 192 if window == None:
175 193 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
176 194
177 195 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
178 196 dim1 = self.dataOutObj.data.shape[0]
179 197 dim2 = self.dataOutObj.data.shape[1]
180 198 r = dim2 % window
181 199
182 200 buffer = self.dataOutObj.data[:,0:dim2-r]
183 201 buffer = buffer.reshape(dim1,dim2/window,window)
184 202 buffer = numpy.sum(buffer,2)
185 203 self.dataOutObj.data = buffer
186 204
187 205 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
188 206 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
189 207
190 208 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
191 209
192 210 #self.dataOutObj.heightList es un numpy.array
193 211 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
194 212
195 213 def deFlip(self):
196 214 self.dataOutObj.data *= self.flipIndex
197 215 self.flipIndex *= -1.
198 216
199 217 def selectChannels(self, channelList):
200 218 """
201 219 Selecciona un bloque de datos en base a canales segun el channelList
202 220
203 221 Input:
204 222 channelList : lista sencilla de canales a seleccionar por ej. [2,3,7]
205 223
206 224 Affected:
207 225 self.dataOutObj.data
208 226 self.dataOutObj.channelList
209 227 self.dataOutObj.nChannels
210 228 self.dataOutObj.m_ProcessingHeader.totalSpectra
211 229 self.dataOutObj.m_SystemHeader.numChannels
212 230 self.dataOutObj.m_ProcessingHeader.blockSize
213 231
214 232 Return:
215 233 None
216 234 """
217 235 if self.dataOutObj.flagNoData:
218 236 return 0
219 237
220 238 for channel in channelList:
221 239 if channel not in self.dataOutObj.channelList:
222 240 raise ValueError, "The value %d in channelList is not valid" %channel
223 241
224 242 nChannels = len(channelList)
225 243
226 244 data = self.dataOutObj.data[channelList,:]
227 245
228 246 self.dataOutObj.data = data
229 247 self.dataOutObj.channelList = channelList
230 248 self.dataOutObj.nChannels = nChannels
231 249
232 250 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels
233 251 self.dataOutObj.m_SystemHeader.numChannels = nChannels
234 252 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
235 253 return 1
236 254
237 255
238 256 def selectHeightsByValue(self, minHei, maxHei):
239 257 """
240 258 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
241 259 minHei <= height <= maxHei
242 260
243 261 Input:
244 262 minHei : valor minimo de altura a considerar
245 263 maxHei : valor maximo de altura a considerar
246 264
247 265 Affected:
248 266 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
249 267
250 268 Return:
251 269 1 si el metodo se ejecuto con exito caso contrario devuelve 0
252 270 """
253 271 if self.dataOutObj.flagNoData:
254 272 return 0
255 273
256 274 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
257 275 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
258 276
259 277 if (maxHei > self.dataOutObj.heightList[-1]):
260 278 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
261 279
262 280 minIndex = 0
263 281 maxIndex = 0
264 282 data = self.dataOutObj.heightList
265 283
266 284 for i,val in enumerate(data):
267 285 if val < minHei:
268 286 continue
269 287 else:
270 288 minIndex = i;
271 289 break
272 290
273 291 for i,val in enumerate(data):
274 292 if val <= maxHei:
275 293 maxIndex = i;
276 294 else:
277 295 break
278 296
279 297 self.selectHeightsByIndex(minIndex, maxIndex)
280 298 return 1
281 299
282 300
283 301 def selectHeightsByIndex(self, minIndex, maxIndex):
284 302 """
285 303 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
286 304 minIndex <= index <= maxIndex
287 305
288 306 Input:
289 307 minIndex : valor de indice minimo de altura a considerar
290 308 maxIndex : valor de indice maximo de altura a considerar
291 309
292 310 Affected:
293 311 self.dataOutObj.data
294 312 self.dataOutObj.heightList
295 313 self.dataOutObj.nHeights
296 314 self.dataOutObj.m_ProcessingHeader.blockSize
297 315 self.dataOutObj.m_ProcessingHeader.numHeights
298 316 self.dataOutObj.m_ProcessingHeader.firstHeight
299 317 self.dataOutObj.m_RadarControllerHeader
300 318
301 319 Return:
302 320 1 si el metodo se ejecuto con exito caso contrario devuelve 0
303 321 """
304 322 if self.dataOutObj.flagNoData:
305 323 return 0
306 324
307 325 if (minIndex < 0) or (minIndex > maxIndex):
308 326 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
309 327
310 328 if (maxIndex >= self.dataOutObj.nHeights):
311 329 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
312 330
313 331 nHeights = maxIndex - minIndex + 1
314 332
315 333 #voltage
316 334 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
317 335
318 336 firstHeight = self.dataOutObj.heightList[minIndex]
319 337
320 338 self.dataOutObj.data = data
321 339 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
322 340 self.dataOutObj.nHeights = nHeights
323 341 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
324 342 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
325 343 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
326 344 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
327 345 return 1
328 346
329 347 def selectProfilesByValue(self,indexList, nProfiles):
330 348 if self.dataOutObj.flagNoData:
331 349 return 0
332 350
333 351 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
334 352 self.addProfileSelector(nProfiles)
335 353
336 354 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
337 355
338 356 if not(profileSelectorObj.isProfileInList(indexList)):
339 357 self.dataOutObj.flagNoData = True
340 358 self.profSelectorObjIndex += 1
341 359 return 0
342 360
343 361 self.dataOutObj.flagNoData = False
344 362 self.profSelectorObjIndex += 1
345 363
346 364 return 1
347 365
348 366
349 367 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
350 368 """
351 369 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
352 370 minIndex <= index <= maxIndex
353 371
354 372 Input:
355 373 minIndex : valor de indice minimo de perfil a considerar
356 374 maxIndex : valor de indice maximo de perfil a considerar
357 375 nProfiles : numero de profiles
358 376
359 377 Affected:
360 378 self.dataOutObj.flagNoData
361 379 self.profSelectorObjIndex
362 380
363 381 Return:
364 382 1 si el metodo se ejecuto con exito caso contrario devuelve 0
365 383 """
366 384
367 385 if self.dataOutObj.flagNoData:
368 386 return 0
369 387
370 388 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
371 389 self.addProfileSelector(nProfiles)
372 390
373 391 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
374 392
375 393 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
376 394 self.dataOutObj.flagNoData = True
377 395 self.profSelectorObjIndex += 1
378 396 return 0
379 397
380 398 self.dataOutObj.flagNoData = False
381 399 self.profSelectorObjIndex += 1
382 400
383 401 return 1
384 402
385 403 def selectNtxs(self, ntx):
386 404 pass
387 405
388 406
389 407 class Decoder:
390 408
391 409 data = None
392 410 profCounter = 1
393 411 nCode = None
394 412 nBaud = None
395 413 codeIndex = 0
396 414 code = None
397 415 flag = False
398 416
399 417 def __init__(self,code, ncode, nbaud):
400 418
401 419 self.data = None
402 420 self.profCounter = 1
403 421 self.nCode = ncode
404 422 self.nBaud = nbaud
405 423 self.codeIndex = 0
406 424 self.code = code #this is a List
407 425 self.flag = False
408 426
409 427 def exe(self, data, ndata=None, type = 0):
410 428
411 429 if ndata == None: ndata = data.shape[1]
412 430
413 431 if type == 0:
414 432 self.convolutionInFreq(data,ndata)
415 433
416 434 if type == 1:
417 435 self.convolutionInTime(data, ndata)
418 436
419 437 def convolutionInFreq(self,data, ndata):
420 438
421 439 newcode = numpy.zeros(ndata)
422 440 newcode[0:self.nBaud] = self.code[self.codeIndex]
423 441
424 442 self.codeIndex += 1
425 443
426 444 fft_data = numpy.fft.fft(data, axis=1)
427 445 fft_code = numpy.conj(numpy.fft.fft(newcode))
428 446 fft_code = fft_code.reshape(1,len(fft_code))
429 447
430 448 conv = fft_data.copy()
431 449 conv.fill(0)
432 450
433 451 conv = fft_data*fft_code
434 452
435 453 self.data = numpy.fft.ifft(conv,axis=1)
436 454 self.flag = True
437 455
438 456 if self.profCounter == self.nCode:
439 457 self.profCounter = 0
440 458 self.codeIndex = 0
441 459
442 460 self.profCounter += 1
443 461
444 462 def convolutionInTime(self, data, ndata):
445 463
446 464 nchannel = data.shape[1]
447 465 newcode = self.code[self.codeIndex]
448 466 self.codeIndex += 1
449 467 conv = data.copy()
450 468 for i in range(nchannel):
451 469 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
452 470
453 471 self.data = conv
454 472 self.flag = True
455 473
456 474 if self.profCounter == self.nCode:
457 475 self.profCounter = 0
458 476 self.codeIndex = 0
459 477
460 478 self.profCounter += 1
461 479
462 480
463 481 class CoherentIntegrator:
464 482
465 483 profCounter = 1
466 484 data = None
467 485 buffer = None
468 486 flag = False
469 487 nCohInt = None
470 488
471 489 def __init__(self, N):
472 490
473 491 self.profCounter = 1
474 492 self.data = None
475 493 self.buffer = None
476 494 self.flag = False
477 495 self.nCohInt = N
478 496
479 497 def exe(self, data):
480 498
481 499 if self.buffer == None:
482 500 self.buffer = data
483 501 else:
484 502 self.buffer = self.buffer + data
485 503
486 504 if self.profCounter == self.nCohInt:
487 505 self.data = self.buffer
488 506 self.buffer = None
489 507 self.profCounter = 0
490 508 self.flag = True
491 509 else:
492 510 self.flag = False
493 511
494 512 self.profCounter += 1
495 513
496 514 class ProfileSelector:
497 515
498 516 profileIndex = None
499 517 # Tamanho total de los perfiles
500 518 nProfiles = None
501 519
502 520 def __init__(self, nProfiles):
503 521
504 522 self.profileIndex = 0
505 523 self.nProfiles = nProfiles
506 524
507 525 def incIndex(self):
508 526 self.profileIndex += 1
509 527
510 528 if self.profileIndex >= self.nProfiles:
511 529 self.profileIndex = 0
512 530
513 531 def isProfileInRange(self, minIndex, maxIndex):
514 532
515 533 if self.profileIndex < minIndex:
516 534 return False
517 535
518 536 if self.profileIndex > maxIndex:
519 537 return False
520 538
521 539 return True
522 540
523 541 def isProfileInList(self, profileList):
524 542
525 543 if self.profileIndex not in profileList:
526 544 return False
527 545
528 546 return True
529 547
530 548
531 549 No newline at end of file
@@ -1,102 +1,102
1 1 '''
2 2 Created on 27/03/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7 import os, sys
8 8 import time, datetime
9 9
10 10 from Model.Voltage import Voltage
11 11 from IO.VoltageIO import *
12 12 #from Graphics.VoltagePlot import Osciloscope
13 13
14 14 from Model.Spectra import Spectra
15 15 from IO.SpectraIO import *
16 16
17 17 from Processing.VoltageProcessor import *
18 18 from Processing.SpectraProcessor import *
19 19
20 20 class TestSChain():
21 21
22 22 def __init__(self):
23 23 self.setValues()
24 24 self.createObjects()
25 25 self.testSChain()
26 26
27 27
28 28 def setValues( self ):
29 29
30 30 self.path = "/home/dsuarez/Projects" #1
31 self.path = "/home/roj-idl71/Data/RAWDATA/IMAGING"
31 self.path = "/Users/jro/Documents/RadarData/EW_Drifts"
32 32 # self.startDateTime = datetime.datetime(2007,5,1,15,49,0)
33 33 # self.endDateTime = datetime.datetime(2007,5,1,23,0,0)
34 34
35 self.startDateTime = datetime.datetime(2011,10,4,0,0,0)
36 self.endDateTime = datetime.datetime(2011,10,4,0,20,0)
35 self.startDateTime = datetime.datetime(2011,11,20,0,0,0)
36 self.endDateTime = datetime.datetime(2011,12,31,0,20,0)
37 37 self.N = 10
38 38 self.npts = 1024
39 39
40 40 def createObjects( self ):
41 41
42 42 self.voltObj1 = Voltage()
43 43 self.voltObj2 = Voltage()
44 44 self.specObj1 = Spectra()
45 45
46 46 self.readerObj = VoltageReader(self.voltObj1)
47 47 self.voltProcObj = VoltageProcessor(self.voltObj1, self.voltObj2)
48 48 self.specProcObj = SpectraProcessor(self.voltObj2, self.specObj1)
49 49
50 50
51 51 #self.plotObj = Osciloscope(self.voltObj1)
52 52
53 53 if not(self.readerObj.setup( self.path, self.startDateTime, self.endDateTime, expLabel='', online =0) ):
54 54 sys.exit(0)
55 55
56 56 # if not(self.readerObj.setup(self.path, self.startDateTime, self.endDateTime)):
57 57 # sys.exit(0)
58 58
59 59 def testSChain( self ):
60 60
61 61 ini = time.time()
62 62 while(True):
63 63 self.readerObj.getData()
64 64
65 65 self.voltProcObj.init()
66 66
67 67 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-25000, ymax=25000, winTitle='sin decodificar')
68 68
69 self.voltProcObj.decoder(type=0)
69 # self.voltProcObj.decoder(type=0)
70 70
71 71 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-70000, ymax=70000,winTitle='Decodificado')
72 72 #
73 73 self.voltProcObj.integrator(self.N)
74 74
75 75 # self.voltProcObj.plotData(idProfile = 1, type='iq', ymin=-700000, ymax=700000,winTitle='figura 3')
76 76
77 77 self.specProcObj.init(self.npts)
78 78
79 79 self.specProcObj.integrator(2)
80 80
81 81 self.specProcObj.plotData(winTitle='Spectra 1', index=0)
82 82
83 83 # if self.readerObj.getData():
84 84 # self.plotObj.plotData(idProfile=0, type='power' )
85 85 #
86 86 #
87 87 if self.readerObj.flagNoMoreFiles:
88 88 break
89 89 #
90 90 if self.readerObj.flagIsNewBlock:
91 91 print 'Block No %04d, Time: %s' %(self.readerObj.nTotalBlocks,
92 92 datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc),)
93 93
94 94 # fin = time.time()
95 95 # print 'Tiempo de un bloque leido y escrito: [%6.5f]' %(fin - ini)
96 96 # ini = time.time()
97 97
98 98 #time.sleep(0.5)
99 99 # self.plotObj.end()
100 100
101 101 if __name__ == '__main__':
102 102 TestSChain() No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now