##// END OF EJS Templates
Se agrega el metodo plotScope
Daniel Valdez -
r136:281987d46ec5
parent child
Show More
@@ -1,200 +1,219
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os
7 import os
8 import sys
8 import sys
9 import numpy
9 import numpy
10 import datetime
10
11
11 path = os.path.split(os.getcwd())[0]
12 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
13 sys.path.append(path)
13
14
14 from Data.Voltage import Voltage
15 from Data.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
16 from IO.VoltageIO import VoltageWriter
16 from Graphics.schainPlotTypes import ScopeFigure
17 from Graphics2.schainPlotTypes import ScopeFigure
17
18
18 class VoltageProcessor:
19 class VoltageProcessor:
19 dataInObj = None
20 dataInObj = None
20 dataOutObj = None
21 dataOutObj = None
21 integratorObjIndex = None
22 integratorObjIndex = None
22 writerObjIndex = None
23 writerObjIndex = None
23 integratorObjList = None
24 integratorObjList = None
24 writerObjList = None
25 writerObjList = None
25
26
26 def __init__(self):
27 def __init__(self):
27 self.integratorObjIndex = None
28 self.integratorObjIndex = None
28 self.writerObjIndex = None
29 self.writerObjIndex = None
29 self.plotObjIndex = None
30 self.plotObjIndex = None
30 self.integratorObjList = []
31 self.integratorObjList = []
31 self.writerObjList = []
32 self.writerObjList = []
32 self.plotObjList = []
33 self.plotObjList = []
33
34
34 def setup(self,dataInObj=None,dataOutObj=None):
35 def setup(self,dataInObj=None,dataOutObj=None):
35 self.dataInObj = dataInObj
36 self.dataInObj = dataInObj
36
37
37 if self.dataOutObj == None:
38 if self.dataOutObj == None:
38 dataOutObj = Voltage()
39 dataOutObj = Voltage()
39
40
40 self.dataOutObj = dataOutObj
41 self.dataOutObj = dataOutObj
41
42
42 return self.dataOutObj
43 return self.dataOutObj
43
44
44 def init(self):
45 def init(self):
45 self.integratorObjIndex = 0
46 self.integratorObjIndex = 0
46 self.writerObjIndex = 0
47 self.writerObjIndex = 0
47 self.plotObjIndex = 0
48 self.plotObjIndex = 0
48
49
49 if not(self.dataInObj.flagNoData):
50 if not(self.dataInObj.flagNoData):
50 self.dataOutObj.copy(self.dataInObj)
51 self.dataOutObj.copy(self.dataInObj)
51 # No necesita copiar en cada init() los atributos de dataInObj
52 # No necesita copiar en cada init() los atributos de dataInObj
52 # la copia deberia hacerse por cada nuevo bloque de datos
53 # la copia deberia hacerse por cada nuevo bloque de datos
53
54
54 def addScope(self, idfigure, nframes, wintitle, driver):
55 def addScope(self, idfigure, nframes, wintitle, driver):
55 if idfigure==None:
56 if idfigure==None:
56 idfigure = self.plotObjIndex
57 idfigure = self.plotObjIndex
57
58
58 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
59 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
59 self.plotObjList.append(scopeObj)
60 self.plotObjList.append(scopeObj)
60
61
61 def plotScope(self,
62 def plotScope(self,
62 idfigure=None,
63 idfigure=None,
63 minvalue=None,
64 minvalue=None,
64 maxvalue=None,
65 maxvalue=None,
65 xmin=None,
66 xmin=None,
66 xmax=None,
67 xmax=None,
67 wintitle='',
68 wintitle='',
68 driver='plplot',
69 driver='plplot',
69 save=False,
70 save=False,
70 gpath=None,
71 gpath=None,
71 titleList=None,
72 titleList=None,
72 xlabelList=None,
73 xlabelList=None,
73 ylabelList=None,
74 ylabelList=None,
74 type="power"):
75 type="power"):
75
76
76 if self.dataOutObj.flagNoData:
77 if self.dataOutObj.flagNoData:
77 return 0
78 return 0
78
79
79 nframes = len(self.dataOutObj.channelList)
80 nframes = len(self.dataOutObj.channelList)
80
81
81 if len(self.plotObjList) <= self.plotObjIndex:
82 if len(self.plotObjList) <= self.plotObjIndex:
82 self.addScope(idfigure, nframes, wintitle, driver)
83 self.addScope(idfigure, nframes, wintitle, driver)
84
85
86 if type=="power":
87 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
88 data1D = data1D.real
89
90 if type =="iq":
91 data1D = self.dataOutObj.data
92
93 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
83
94
84 self.plotObjList[self.plotObjIndex].plot1DArray(data1D=self.dataOutObj.data,
95 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
85 x=self.dataOutObj.heightList,
96 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
86 channelList=self.dataOutObj.channelList,
87 xmin=xmin,
88 xmax=xmax,
89 minvalue=minvalue,
90 maxvlaue=maxvalue,
91 save=save,
92 gpath=gpath)
93
97
98 figureTitle = "Scope Plot Radar Data: " + date
99
100 plotObj = self.plotObjList[self.plotObjIndex]
101
102 plotObj.plot1DArray(data1D,
103 self.dataOutObj.heightList,
104 self.dataOutObj.channelList,
105 xmin,
106 xmax,
107 minvalue,
108 maxvalue,
109 figureTitle,
110 save,
111 gpath)
112
94 self.plotObjIndex += 1
113 self.plotObjIndex += 1
95
114
96
115
97 def addIntegrator(self,N,timeInterval):
116 def addIntegrator(self,N,timeInterval):
98 objCohInt = CoherentIntegrator(N,timeInterval)
117 objCohInt = CoherentIntegrator(N,timeInterval)
99 self.integratorObjList.append(objCohInt)
118 self.integratorObjList.append(objCohInt)
100
119
101 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
120 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
102 writerObj = VoltageWriter(self.dataOutObj)
121 writerObj = VoltageWriter(self.dataOutObj)
103 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
122 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
104 self.writerObjList.append(writerObj)
123 self.writerObjList.append(writerObj)
105
124
106 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
125 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
107
126
108 if self.dataOutObj.flagNoData:
127 if self.dataOutObj.flagNoData:
109 return 0
128 return 0
110
129
111 if len(self.writerObjList) <= self.writerObjIndex:
130 if len(self.writerObjList) <= self.writerObjIndex:
112 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
131 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
113
132
114 self.writerObjList[self.writerObjIndex].putData()
133 self.writerObjList[self.writerObjIndex].putData()
115
134
116 self.writerObjIndex += 1
135 self.writerObjIndex += 1
117
136
118 def integrator(self, N=None, timeInterval=None):
137 def integrator(self, N=None, timeInterval=None):
119 if self.dataOutObj.flagNoData:
138 if self.dataOutObj.flagNoData:
120 return 0
139 return 0
121 if len(self.integratorObjList) <= self.integratorObjIndex:
140 if len(self.integratorObjList) <= self.integratorObjIndex:
122 self.addIntegrator(N,timeInterval)
141 self.addIntegrator(N,timeInterval)
123
142
124 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
143 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
125 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
144 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
126
145
127
146
128
147
129 class CoherentIntegrator:
148 class CoherentIntegrator:
130
149
131 integ_counter = None
150 integ_counter = None
132 data = None
151 data = None
133 navg = None
152 navg = None
134 buffer = None
153 buffer = None
135 nCohInt = None
154 nCohInt = None
136
155
137 def __init__(self, N=None,timeInterval=None):
156 def __init__(self, N=None,timeInterval=None):
138
157
139 self.data = None
158 self.data = None
140 self.navg = None
159 self.navg = None
141 self.buffer = None
160 self.buffer = None
142 self.timeOut = None
161 self.timeOut = None
143 self.exitCondition = False
162 self.exitCondition = False
144 self.isReady = False
163 self.isReady = False
145 self.nCohInt = N
164 self.nCohInt = N
146 self.integ_counter = 0
165 self.integ_counter = 0
147 if timeInterval!=None:
166 if timeInterval!=None:
148 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
167 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
149
168
150 if ((timeInterval==None) and (N==None)):
169 if ((timeInterval==None) and (N==None)):
151 raise ValueError, "N = None ; timeInterval = None"
170 raise ValueError, "N = None ; timeInterval = None"
152
171
153 if timeInterval == None:
172 if timeInterval == None:
154 self.timeFlag = False
173 self.timeFlag = False
155 else:
174 else:
156 self.timeFlag = True
175 self.timeFlag = True
157
176
158 def exe(self, data, timeOfData):
177 def exe(self, data, timeOfData):
159
178
160 if self.timeFlag:
179 if self.timeFlag:
161 if self.timeOut == None:
180 if self.timeOut == None:
162 self.timeOut = timeOfData + self.timeIntervalInSeconds
181 self.timeOut = timeOfData + self.timeIntervalInSeconds
163
182
164 if timeOfData < self.timeOut:
183 if timeOfData < self.timeOut:
165 if self.buffer == None:
184 if self.buffer == None:
166 self.buffer = data
185 self.buffer = data
167 else:
186 else:
168 self.buffer = self.buffer + data
187 self.buffer = self.buffer + data
169 self.integ_counter += 1
188 self.integ_counter += 1
170 else:
189 else:
171 self.exitCondition = True
190 self.exitCondition = True
172
191
173 else:
192 else:
174 if self.integ_counter < self.nCohInt:
193 if self.integ_counter < self.nCohInt:
175 if self.buffer == None:
194 if self.buffer == None:
176 self.buffer = data
195 self.buffer = data
177 else:
196 else:
178 self.buffer = self.buffer + data
197 self.buffer = self.buffer + data
179
198
180 self.integ_counter += 1
199 self.integ_counter += 1
181
200
182 if self.integ_counter == self.nCohInt:
201 if self.integ_counter == self.nCohInt:
183 self.exitCondition = True
202 self.exitCondition = True
184
203
185 if self.exitCondition:
204 if self.exitCondition:
186 self.data = self.buffer
205 self.data = self.buffer
187 self.navg = self.integ_counter
206 self.navg = self.integ_counter
188 self.isReady = True
207 self.isReady = True
189 self.buffer = None
208 self.buffer = None
190 self.timeOut = None
209 self.timeOut = None
191 self.integ_counter = 0
210 self.integ_counter = 0
192 self.exitCondition = False
211 self.exitCondition = False
193
212
194 if self.timeFlag:
213 if self.timeFlag:
195 self.buffer = data
214 self.buffer = data
196 self.timeOut = timeOfData + self.timeIntervalInSeconds
215 self.timeOut = timeOfData + self.timeIntervalInSeconds
197 else:
216 else:
198 self.isReady = False
217 self.isReady = False
199
218
200
219
General Comments 0
You need to be logged in to leave comments. Login now