@@ -1,288 +1,372 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author$ |
|
4 | 4 | $Id$ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os |
|
8 | 8 | import sys |
|
9 | 9 | import numpy |
|
10 | 10 | import datetime |
|
11 | 11 | import time |
|
12 | 12 | |
|
13 | 13 | path = os.path.split(os.getcwd())[0] |
|
14 | 14 | sys.path.append(path) |
|
15 | 15 | |
|
16 | 16 | from Data.JROData import Voltage |
|
17 | 17 | from IO.VoltageIO import VoltageWriter |
|
18 | 18 | from Graphics.schainPlotTypes import ScopeFigure, RTIFigure |
|
19 | 19 | |
|
20 | 20 | class VoltageProcessor: |
|
21 | 21 | |
|
22 | 22 | dataInObj = None |
|
23 | 23 | dataOutObj = None |
|
24 | 24 | integratorObjIndex = None |
|
25 | 25 | writerObjIndex = None |
|
26 | 26 | integratorObjList = None |
|
27 | 27 | writerObjList = None |
|
28 | 28 | |
|
29 | 29 | def __init__(self): |
|
30 | 30 | self.integratorObjIndex = None |
|
31 | 31 | self.writerObjIndex = None |
|
32 | 32 | self.plotObjIndex = None |
|
33 | 33 | self.integratorObjList = [] |
|
34 | 34 | self.writerObjList = [] |
|
35 | 35 | self.plotObjList = [] |
|
36 | 36 | |
|
37 | 37 | def setup(self,dataInObj=None,dataOutObj=None): |
|
38 | 38 | self.dataInObj = dataInObj |
|
39 | 39 | |
|
40 | 40 | if self.dataOutObj == None: |
|
41 | 41 | dataOutObj = Voltage() |
|
42 | 42 | |
|
43 | 43 | self.dataOutObj = dataOutObj |
|
44 | 44 | |
|
45 | 45 | return self.dataOutObj |
|
46 | 46 | |
|
47 | 47 | def init(self): |
|
48 | 48 | self.integratorObjIndex = 0 |
|
49 | 49 | self.writerObjIndex = 0 |
|
50 | 50 | self.plotObjIndex = 0 |
|
51 | 51 | |
|
52 | 52 | if not(self.dataInObj.flagNoData): |
|
53 | 53 | self.dataOutObj.copy(self.dataInObj) |
|
54 | 54 | # No necesita copiar en cada init() los atributos de dataInObj |
|
55 | 55 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
56 | 56 | |
|
57 | 57 | def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile): |
|
58 | 58 | rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
59 | 59 | self.plotObjList.append(rtiObj) |
|
60 | 60 | |
|
61 | 61 | def plotRti(self, idfigure=None, |
|
62 | 62 | starttime=None, |
|
63 | 63 | endtime=None, |
|
64 | 64 | rangemin=None, |
|
65 | 65 | rangemax=None, |
|
66 | 66 | minvalue=None, |
|
67 | 67 | maxvalue=None, |
|
68 | 68 | wintitle='', |
|
69 | 69 | driver='plplot', |
|
70 | 70 | colormap='br_greeen', |
|
71 | 71 | colorbar=True, |
|
72 | 72 | showprofile=False, |
|
73 | 73 | xrangestep=None, |
|
74 | 74 | save=False, |
|
75 | 75 | gpath=None): |
|
76 | 76 | |
|
77 | 77 | if self.dataOutObj.flagNoData: |
|
78 | 78 | return 0 |
|
79 | 79 | |
|
80 | 80 | nframes = len(self.dataOutObj.channelList) |
|
81 | 81 | |
|
82 | 82 | if len(self.plotObjList) <= self.plotObjIndex: |
|
83 | 83 | self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile) |
|
84 | 84 | |
|
85 | 85 | data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
86 | 86 | data = 10*numpy.log10(data.real) |
|
87 | 87 | |
|
88 | 88 | # currenttime = self.dataOutObj.dataUtcTime |
|
89 | 89 | # if timezone == "lt": |
|
90 | 90 | currenttime = self.dataOutObj.dataUtcTime - time.timezone |
|
91 | 91 | |
|
92 | 92 | range = self.dataOutObj.heightList |
|
93 | 93 | |
|
94 | 94 | channelList = self.dataOutObj.channelList |
|
95 | 95 | |
|
96 | 96 | thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) |
|
97 | 97 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
98 | 98 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
99 | 99 | |
|
100 | 100 | figuretitle = "RTI Plot Radar Data" #+ date |
|
101 | 101 | |
|
102 | 102 | plotObj = self.plotObjList[self.plotObjIndex] |
|
103 | 103 | |
|
104 | 104 | cleardata = False |
|
105 | 105 | |
|
106 | 106 | plotObj.plotPcolor(data, |
|
107 | 107 | currenttime, |
|
108 | 108 | range, |
|
109 | 109 | channelList, |
|
110 | 110 | starttime, |
|
111 | 111 | endtime, |
|
112 | 112 | rangemin, |
|
113 | 113 | rangemax, |
|
114 | 114 | minvalue, |
|
115 | 115 | maxvalue, |
|
116 | 116 | figuretitle, |
|
117 | 117 | xrangestep, |
|
118 | 118 | save, |
|
119 | 119 | gpath, |
|
120 | 120 | cleardata) |
|
121 | 121 | |
|
122 | 122 | self.plotObjIndex += 1 |
|
123 | 123 | |
|
124 | 124 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
125 | 125 | if idfigure==None: |
|
126 | 126 | idfigure = self.plotObjIndex |
|
127 | 127 | |
|
128 | 128 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
129 | 129 | self.plotObjList.append(scopeObj) |
|
130 | 130 | |
|
131 | 131 | def plotScope(self, |
|
132 | 132 | idfigure=None, |
|
133 | 133 | minvalue=None, |
|
134 | 134 | maxvalue=None, |
|
135 | 135 | xmin=None, |
|
136 | 136 | xmax=None, |
|
137 | 137 | wintitle='', |
|
138 | 138 | driver='plplot', |
|
139 | 139 | save=False, |
|
140 | 140 | gpath=None, |
|
141 | 141 | titleList=None, |
|
142 | 142 | xlabelList=None, |
|
143 | 143 | ylabelList=None, |
|
144 | 144 | type="power"): |
|
145 | 145 | |
|
146 | 146 | if self.dataOutObj.flagNoData: |
|
147 | 147 | return 0 |
|
148 | 148 | |
|
149 | 149 | nframes = len(self.dataOutObj.channelList) |
|
150 | 150 | |
|
151 | 151 | if len(self.plotObjList) <= self.plotObjIndex: |
|
152 | 152 | self.addScope(idfigure, nframes, wintitle, driver) |
|
153 | 153 | |
|
154 | 154 | |
|
155 | 155 | if type=="power": |
|
156 | 156 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
157 | 157 | data1D = data1D.real |
|
158 | 158 | |
|
159 | 159 | if type =="iq": |
|
160 | 160 | data1D = self.dataOutObj.data |
|
161 | 161 | |
|
162 | 162 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime) |
|
163 | 163 | |
|
164 | 164 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
165 | 165 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
166 | 166 | |
|
167 | 167 | figureTitle = "Scope Plot Radar Data: " + date |
|
168 | 168 | |
|
169 | 169 | plotObj = self.plotObjList[self.plotObjIndex] |
|
170 | 170 | |
|
171 | 171 | plotObj.plot1DArray(data1D, |
|
172 | 172 | self.dataOutObj.heightList, |
|
173 | 173 | self.dataOutObj.channelList, |
|
174 | 174 | xmin, |
|
175 | 175 | xmax, |
|
176 | 176 | minvalue, |
|
177 | 177 | maxvalue, |
|
178 | 178 | figureTitle, |
|
179 | 179 | save, |
|
180 | 180 | gpath) |
|
181 | 181 | |
|
182 | 182 | self.plotObjIndex += 1 |
|
183 | 183 | |
|
184 | 184 | |
|
185 |
def addIntegrator(self, |
|
|
186 |
objCohInt = CoherentIntegrator( |
|
|
185 | def addIntegrator(self, *args): | |
|
186 | objCohInt = CoherentIntegrator(*args) | |
|
187 | 187 | self.integratorObjList.append(objCohInt) |
|
188 | 188 | |
|
189 | def addWriter(self, wrpath, blocksPerFile, profilesPerBlock): | |
|
189 | def addWriter(self, *args): | |
|
190 | 190 | writerObj = VoltageWriter(self.dataOutObj) |
|
191 | writerObj.setup(wrpath,blocksPerFile,profilesPerBlock) | |
|
191 | writerObj.setup(*args) | |
|
192 | 192 | self.writerObjList.append(writerObj) |
|
193 | 193 | |
|
194 | 194 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
195 | 195 | |
|
196 | 196 | if self.dataOutObj.flagNoData: |
|
197 | 197 | return 0 |
|
198 | 198 | |
|
199 | 199 | if len(self.writerObjList) <= self.writerObjIndex: |
|
200 | 200 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
201 | 201 | |
|
202 | 202 | self.writerObjList[self.writerObjIndex].putData() |
|
203 | 203 | |
|
204 | 204 | self.writerObjIndex += 1 |
|
205 | 205 | |
|
206 |
def integrator(self, |
|
|
206 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): | |
|
207 | ||
|
207 | 208 | if self.dataOutObj.flagNoData: |
|
208 | 209 | return 0 |
|
210 | ||
|
209 | 211 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
210 |
self.addIntegrator( |
|
|
212 | self.addIntegrator(nCohInt, timeInterval, overlapping) | |
|
211 | 213 | |
|
212 | 214 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
213 |
myCohIntObj.exe(data=self.dataOutObj.data,time |
|
|
215 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) | |
|
216 | ||
|
217 | self.dataOutObj.flagNoData = True | |
|
218 | ||
|
219 | if myCohIntObj.isReady: | |
|
220 | self.dataOutObj.flagNoData = False | |
|
214 | 221 | |
|
215 | 222 | |
|
216 | 223 | |
|
217 | 224 | class CoherentIntegrator: |
|
218 | 225 | |
|
219 | integ_counter = None | |
|
220 | data = None | |
|
221 | navg = None | |
|
222 | buffer = None | |
|
226 | ||
|
227 | __profIndex = 0 | |
|
228 | __withOverapping = False | |
|
229 | ||
|
230 | __isByTime = False | |
|
231 | __initime = None | |
|
232 | __integrationtime = None | |
|
233 | ||
|
234 | __buffer = None | |
|
235 | ||
|
236 | isReady = False | |
|
223 | 237 | nCohInt = None |
|
224 | 238 | |
|
225 | def __init__(self, N=None,timeInterval=None): | |
|
226 | 239 |
|
|
227 | self.data = None | |
|
228 | self.navg = None | |
|
229 | self.buffer = None | |
|
230 | self.timeOut = None | |
|
231 | self.exitCondition = False | |
|
232 | self.isReady = False | |
|
233 | self.nCohInt = N | |
|
234 | self.integ_counter = 0 | |
|
235 | if timeInterval!=None: | |
|
236 | self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
|
240 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): | |
|
237 | 241 |
|
|
238 | if ((timeInterval==None) and (N==None)): | |
|
239 | raise ValueError, "N = None ; timeInterval = None" | |
|
242 | """ | |
|
243 | Set the parameters of the integration class. | |
|
240 | 244 |
|
|
241 | if timeInterval == None: | |
|
242 | self.timeFlag = False | |
|
243 | else: | |
|
244 | self.timeFlag = True | |
|
245 | Inputs: | |
|
245 | 246 |
|
|
246 | def exe(self, data, timeOfData): | |
|
247 | nCohInt : Number of coherent integrations | |
|
248 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work | |
|
249 | overlapping : | |
|
247 | 250 | |
|
248 | if self.timeFlag: | |
|
249 | if self.timeOut == None: | |
|
250 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
|
251 | """ | |
|
251 | 252 |
|
|
252 | if timeOfData < self.timeOut: | |
|
253 | if self.buffer == None: | |
|
254 | self.buffer = data | |
|
255 | else: | |
|
256 | self.buffer = self.buffer + data | |
|
257 | self.integ_counter += 1 | |
|
258 | else: | |
|
259 | self.exitCondition = True | |
|
253 | self.__buffer = None | |
|
254 | self.isReady = False | |
|
260 | 255 |
|
|
256 | if nCohInt == None and timeInterval == None: | |
|
257 | raise ValueError, "nCohInt or timeInterval should be specified ..." | |
|
258 | ||
|
259 | if nCohInt != None: | |
|
260 | self.nCohInt = nCohInt | |
|
261 | self.__isByTime = False | |
|
261 | 262 | else: |
|
262 | if self.integ_counter < self.nCohInt: | |
|
263 |
|
|
|
264 | self.buffer = data | |
|
263 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
|
264 | self.__isByTime = True | |
|
265 | ||
|
266 | if overlapping: | |
|
267 | self.__withOverapping = True | |
|
268 | self.__buffer = None | |
|
265 | 269 |
|
|
266 | self.buffer = self.buffer + data | |
|
270 | self.__withOverapping = False | |
|
271 | self.__buffer = 0 | |
|
272 | ||
|
273 | self.__profIndex = 0 | |
|
274 | ||
|
275 | def putData(self, data): | |
|
276 | ||
|
277 | """ | |
|
278 | Add a profile to the __buffer and increase in one the __profileIndex | |
|
279 | ||
|
280 | """ | |
|
281 | if not self.__withOverapping: | |
|
282 | self.__buffer += data | |
|
283 | self.__profIndex += 1 | |
|
284 | return | |
|
285 | ||
|
286 | #Overlapping data | |
|
287 | nChannels, nProfiles = data.shape | |
|
288 | data = numpy.reshape(data, (1, nChannels, nProfiles)) | |
|
289 | ||
|
290 | if self.__buffer == None: | |
|
291 | self.__buffer = data | |
|
292 | self.__profIndex += 1 | |
|
293 | return | |
|
294 | ||
|
295 | if self.__profIndex < self.nCohInt: | |
|
296 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
|
297 | self.__profIndex += 1 | |
|
298 | return | |
|
299 | ||
|
300 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
|
301 | self.__buffer[self.nCohInt-1] = data | |
|
302 | #self.__profIndex = self.nCohInt | |
|
303 | return | |
|
304 | ||
|
305 | ||
|
306 | def pushData(self): | |
|
307 | """ | |
|
308 | Return the sum of the last profiles and the profiles used in the sum. | |
|
267 | 309 |
|
|
268 | self.integ_counter += 1 | |
|
310 | Affected: | |
|
269 | 311 | |
|
270 | if self.integ_counter == self.nCohInt: | |
|
271 | self.exitCondition = True | |
|
312 | self.__profileIndex | |
|
272 | 313 |
|
|
273 | if self.exitCondition: | |
|
274 | self.data = self.buffer | |
|
275 | self.navg = self.integ_counter | |
|
314 | """ | |
|
315 | ||
|
316 | if not self.__withOverapping: | |
|
317 | data = self.__buffer | |
|
318 | nCohInt = self.__profIndex | |
|
319 | ||
|
320 | self.__buffer = 0 | |
|
321 | self.__profIndex = 0 | |
|
322 | ||
|
323 | return data, nCohInt | |
|
324 | ||
|
325 | #Overlapping data | |
|
326 | data = numpy.sum(self.__buffer, axis=0) | |
|
327 | nCohInt = self.__profIndex | |
|
328 | ||
|
329 | return data, nCohInt | |
|
330 | ||
|
331 | def byProfiles(self, data): | |
|
332 | ||
|
333 | self.isReady = False | |
|
334 | avg_data = None | |
|
335 | ||
|
336 | self.putData(data) | |
|
337 | ||
|
338 | if self.__profIndex == self.nCohInt: | |
|
339 | avg_data, nCohInt = self.pushData() | |
|
276 | 340 | self.isReady = True |
|
277 | self.buffer = None | |
|
278 | self.timeOut = None | |
|
279 | self.integ_counter = 0 | |
|
280 | self.exitCondition = False | |
|
281 |
|
|
|
282 | if self.timeFlag: | |
|
283 | self.buffer = data | |
|
284 | self.timeOut = timeOfData + self.timeIntervalInSeconds | |
|
285 | else: | |
|
341 | ||
|
342 | return avg_data | |
|
343 | ||
|
344 | def byTime(self, data, datatime): | |
|
345 | ||
|
286 | 346 |
|
|
347 | avg_data = None | |
|
348 | ||
|
349 | if self.__initime == None: | |
|
350 | self.__initime = datatime | |
|
351 | ||
|
352 | self.putData(data) | |
|
353 | ||
|
354 | if (datatime - self.__initime) >= self.__integrationtime: | |
|
355 | avg_data, nCohInt = self.pushData() | |
|
356 | self.nCohInt = nCohInt | |
|
357 | self.isReady = True | |
|
358 | ||
|
359 | return avg_data | |
|
360 | ||
|
361 | def exe(self, data, datatime=None): | |
|
362 | ||
|
363 | if not self.__isByTime: | |
|
364 | avg_data = self.byProfiles(data) | |
|
365 | else: | |
|
366 | avg_data = self.byTime(data, datatime) | |
|
367 | ||
|
368 | self.data = avg_data | |
|
369 | ||
|
370 | return avg_data | |
|
287 | 371 | |
|
288 | 372 |
General Comments 0
You need to be logged in to leave comments.
Login now