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