@@ -1,377 +1,416 | |||
|
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.utctime |
|
89 | 89 | # if timezone == "lt": |
|
90 | 90 | currenttime = self.dataOutObj.utctime - 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.utctime) |
|
97 | 97 | dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
98 | 98 | date = "%s"%(thisdatetime.strftime("%d-%b-%Y")) |
|
99 | ||
|
99 | print thisdatetime | |
|
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 | deltax = self.dataOutObj.timeInterval |
|
107 | 107 | |
|
108 | 108 | plotObj.plotPcolor(data=data, |
|
109 | 109 | x=currenttime, |
|
110 | 110 | y=range, |
|
111 | 111 | channelList=channelList, |
|
112 | 112 | xmin=starttime, |
|
113 | 113 | xmax=endtime, |
|
114 | 114 | ymin=rangemin, |
|
115 | 115 | ymax=rangemax, |
|
116 | 116 | minvalue=minvalue, |
|
117 | 117 | maxvalue=maxvalue, |
|
118 | 118 | figuretitle=figuretitle, |
|
119 | 119 | xrangestep=xrangestep, |
|
120 | 120 | deltax=deltax, |
|
121 | 121 | save=save, |
|
122 | 122 | gpath=gpath, |
|
123 | 123 | cleardata=cleardata) |
|
124 | 124 | |
|
125 | 125 | |
|
126 | 126 | self.plotObjIndex += 1 |
|
127 | 127 | |
|
128 | 128 | def addScope(self, idfigure, nframes, wintitle, driver): |
|
129 | 129 | if idfigure==None: |
|
130 | 130 | idfigure = self.plotObjIndex |
|
131 | 131 | |
|
132 | 132 | scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver) |
|
133 | 133 | self.plotObjList.append(scopeObj) |
|
134 | 134 | |
|
135 | 135 | def plotScope(self, |
|
136 | 136 | idfigure=None, |
|
137 | 137 | minvalue=None, |
|
138 | 138 | maxvalue=None, |
|
139 | 139 | xmin=None, |
|
140 | 140 | xmax=None, |
|
141 | 141 | wintitle='', |
|
142 | 142 | driver='plplot', |
|
143 | 143 | save=False, |
|
144 | 144 | gpath=None, |
|
145 | 145 | titleList=None, |
|
146 | 146 | xlabelList=None, |
|
147 | 147 | ylabelList=None, |
|
148 | 148 | type="power"): |
|
149 | 149 | |
|
150 | 150 | if self.dataOutObj.flagNoData: |
|
151 | 151 | return 0 |
|
152 | 152 | |
|
153 | 153 | nframes = len(self.dataOutObj.channelList) |
|
154 | 154 | |
|
155 | 155 | if len(self.plotObjList) <= self.plotObjIndex: |
|
156 | 156 | self.addScope(idfigure, nframes, wintitle, driver) |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | if type=="power": |
|
160 | 160 | data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data) |
|
161 | 161 | data1D = data1D.real |
|
162 | 162 | |
|
163 | 163 | if type =="iq": |
|
164 | 164 | data1D = self.dataOutObj.data |
|
165 | 165 | |
|
166 | 166 | thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime) |
|
167 | 167 | |
|
168 | 168 | dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
169 | 169 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
170 | 170 | |
|
171 |
figure |
|
|
171 | figuretitle = "Scope Plot Radar Data: " + date | |
|
172 | 172 | |
|
173 | 173 | plotObj = self.plotObjList[self.plotObjIndex] |
|
174 | 174 | |
|
175 | 175 | plotObj.plot1DArray(data1D=data1D, |
|
176 | 176 | x=self.dataOutObj.heightList, |
|
177 | 177 | channelList=self.dataOutObj.channelList, |
|
178 | 178 | xmin=xmin, |
|
179 | 179 | xmax=xmax, |
|
180 | 180 | minvalue=minvalue, |
|
181 | 181 | maxvalue=maxvalue, |
|
182 |
figure |
|
|
182 | figuretitle=figuretitle, | |
|
183 | 183 | save=save, |
|
184 | 184 | gpath=gpath) |
|
185 | 185 | |
|
186 | 186 | |
|
187 | 187 | self.plotObjIndex += 1 |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | def addIntegrator(self, *args): |
|
191 | 191 | objCohInt = CoherentIntegrator(*args) |
|
192 | 192 | self.integratorObjList.append(objCohInt) |
|
193 | 193 | |
|
194 | 194 | def addWriter(self, *args): |
|
195 | 195 | writerObj = VoltageWriter(self.dataOutObj) |
|
196 | 196 | writerObj.setup(*args) |
|
197 | 197 | self.writerObjList.append(writerObj) |
|
198 | 198 | |
|
199 | 199 | def writeData(self, wrpath, blocksPerFile, profilesPerBlock): |
|
200 | 200 | |
|
201 | 201 | if self.dataOutObj.flagNoData: |
|
202 | 202 | return 0 |
|
203 | 203 | |
|
204 | 204 | if len(self.writerObjList) <= self.writerObjIndex: |
|
205 | 205 | self.addWriter(wrpath, blocksPerFile, profilesPerBlock) |
|
206 | 206 | |
|
207 | 207 | self.writerObjList[self.writerObjIndex].putData() |
|
208 | 208 | |
|
209 | 209 | self.writerObjIndex += 1 |
|
210 | 210 | |
|
211 | 211 | def integrator(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
212 | 212 | |
|
213 | 213 | if self.dataOutObj.flagNoData: |
|
214 | 214 | return 0 |
|
215 | 215 | |
|
216 | 216 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
217 | 217 | self.addIntegrator(nCohInt, timeInterval, overlapping) |
|
218 | 218 | |
|
219 | 219 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
220 | 220 | myCohIntObj.exe(data = self.dataOutObj.data, datatime=None) |
|
221 | 221 | |
|
222 | self.dataOutObj.timeInterval *= nCohInt | |
|
222 | 223 | self.dataOutObj.flagNoData = True |
|
223 | 224 | |
|
224 | 225 | if myCohIntObj.isReady: |
|
225 | 226 | self.dataOutObj.flagNoData = False |
|
227 | ||
|
228 | def selectChannels(self, channelList): | |
|
229 | ||
|
230 | self.selectChannelsByIndex(channelList) | |
|
231 | ||
|
232 | def selectChannelsByIndex(self, channelIndexList): | |
|
233 | """ | |
|
234 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
|
226 | 235 |
|
|
236 | Input: | |
|
237 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
|
238 | ||
|
239 | Affected: | |
|
240 | self.dataOutObj.data | |
|
241 | self.dataOutObj.channelIndexList | |
|
242 | self.dataOutObj.nChannels | |
|
243 | self.dataOutObj.m_ProcessingHeader.totalSpectra | |
|
244 | self.dataOutObj.systemHeaderObj.numChannels | |
|
245 | self.dataOutObj.m_ProcessingHeader.blockSize | |
|
246 | ||
|
247 | Return: | |
|
248 | None | |
|
249 | """ | |
|
250 | if self.dataOutObj.flagNoData: | |
|
251 | return 0 | |
|
227 | 252 | |
|
253 | for channel in channelIndexList: | |
|
254 | if channel not in self.dataOutObj.channelIndexList: | |
|
255 | raise ValueError, "The value %d in channelIndexList is not valid" %channel | |
|
256 | ||
|
257 | nChannels = len(channelIndexList) | |
|
258 | ||
|
259 | data = self.dataOutObj.data[channelIndexList,:] | |
|
260 | ||
|
261 | self.dataOutObj.data = data | |
|
262 | self.dataOutObj.channelIndexList = channelIndexList | |
|
263 | self.dataOutObj.channelList = [self.dataOutObj.channelList[i] for i in channelIndexList] | |
|
264 | self.dataOutObj.nChannels = nChannels | |
|
265 | ||
|
266 | return 1 | |
|
228 | 267 | |
|
229 | 268 | class CoherentIntegrator: |
|
230 | 269 | |
|
231 | 270 | |
|
232 | 271 | __profIndex = 0 |
|
233 | 272 | __withOverapping = False |
|
234 | 273 | |
|
235 | 274 | __isByTime = False |
|
236 | 275 | __initime = None |
|
237 | 276 | __integrationtime = None |
|
238 | 277 | |
|
239 | 278 | __buffer = None |
|
240 | 279 | |
|
241 | 280 | isReady = False |
|
242 | 281 | nCohInt = None |
|
243 | 282 | |
|
244 | 283 | |
|
245 | 284 | def __init__(self, nCohInt=None, timeInterval=None, overlapping=False): |
|
246 | 285 | |
|
247 | 286 | """ |
|
248 | 287 | Set the parameters of the integration class. |
|
249 | 288 | |
|
250 | 289 | Inputs: |
|
251 | 290 | |
|
252 | 291 | nCohInt : Number of coherent integrations |
|
253 | 292 | timeInterval : Time of integration. If nCohInt is selected this parameter does not work |
|
254 | 293 | overlapping : |
|
255 | 294 | |
|
256 | 295 | """ |
|
257 | 296 | |
|
258 | 297 | self.__buffer = None |
|
259 | 298 | self.isReady = False |
|
260 | 299 | |
|
261 | 300 | if nCohInt == None and timeInterval == None: |
|
262 | 301 | raise ValueError, "nCohInt or timeInterval should be specified ..." |
|
263 | 302 | |
|
264 | 303 | if nCohInt != None: |
|
265 | 304 | self.nCohInt = nCohInt |
|
266 | 305 | self.__isByTime = False |
|
267 | 306 | else: |
|
268 | 307 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
269 | 308 | self.__isByTime = True |
|
270 | 309 | |
|
271 | 310 | if overlapping: |
|
272 | 311 | self.__withOverapping = True |
|
273 | 312 | self.__buffer = None |
|
274 | 313 | else: |
|
275 | 314 | self.__withOverapping = False |
|
276 | 315 | self.__buffer = 0 |
|
277 | 316 | |
|
278 | 317 | self.__profIndex = 0 |
|
279 | 318 | |
|
280 | 319 | def putData(self, data): |
|
281 | 320 | |
|
282 | 321 | """ |
|
283 | 322 | Add a profile to the __buffer and increase in one the __profileIndex |
|
284 | 323 | |
|
285 | 324 | """ |
|
286 | 325 | if not self.__withOverapping: |
|
287 | 326 | self.__buffer += data |
|
288 | 327 | self.__profIndex += 1 |
|
289 | 328 | return |
|
290 | 329 | |
|
291 | 330 | #Overlapping data |
|
292 | 331 | nChannels, nHeis = data.shape |
|
293 | 332 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
294 | 333 | |
|
295 | 334 | if self.__buffer == None: |
|
296 | 335 | self.__buffer = data |
|
297 | 336 | self.__profIndex += 1 |
|
298 | 337 | return |
|
299 | 338 | |
|
300 | 339 | if self.__profIndex < self.nCohInt: |
|
301 | 340 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
302 | 341 | self.__profIndex += 1 |
|
303 | 342 | return |
|
304 | 343 | |
|
305 | 344 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
306 | 345 | self.__buffer[self.nCohInt-1] = data |
|
307 | 346 | #self.__profIndex = self.nCohInt |
|
308 | 347 | return |
|
309 | 348 | |
|
310 | 349 | |
|
311 | 350 | def pushData(self): |
|
312 | 351 | """ |
|
313 | 352 | Return the sum of the last profiles and the profiles used in the sum. |
|
314 | 353 | |
|
315 | 354 | Affected: |
|
316 | 355 | |
|
317 | 356 | self.__profileIndex |
|
318 | 357 | |
|
319 | 358 | """ |
|
320 | 359 | |
|
321 | 360 | if not self.__withOverapping: |
|
322 | 361 | data = self.__buffer |
|
323 | 362 | nCohInt = self.__profIndex |
|
324 | 363 | |
|
325 | 364 | self.__buffer = 0 |
|
326 | 365 | self.__profIndex = 0 |
|
327 | 366 | |
|
328 | 367 | return data, nCohInt |
|
329 | 368 | |
|
330 | 369 | #Overlapping data |
|
331 | 370 | data = numpy.sum(self.__buffer, axis=0) |
|
332 | 371 | nCohInt = self.__profIndex |
|
333 | 372 | |
|
334 | 373 | return data, nCohInt |
|
335 | 374 | |
|
336 | 375 | def byProfiles(self, data): |
|
337 | 376 | |
|
338 | 377 | self.isReady = False |
|
339 | 378 | avg_data = None |
|
340 | 379 | |
|
341 | 380 | self.putData(data) |
|
342 | 381 | |
|
343 | 382 | if self.__profIndex == self.nCohInt: |
|
344 | 383 | avg_data, nCohInt = self.pushData() |
|
345 | 384 | self.isReady = True |
|
346 | 385 | |
|
347 | 386 | return avg_data |
|
348 | 387 | |
|
349 | 388 | def byTime(self, data, datatime): |
|
350 | 389 | |
|
351 | 390 | self.isReady = False |
|
352 | 391 | avg_data = None |
|
353 | 392 | |
|
354 | 393 | if self.__initime == None: |
|
355 | 394 | self.__initime = datatime |
|
356 | 395 | |
|
357 | 396 | self.putData(data) |
|
358 | 397 | |
|
359 | 398 | if (datatime - self.__initime) >= self.__integrationtime: |
|
360 | 399 | avg_data, nCohInt = self.pushData() |
|
361 | 400 | self.nCohInt = nCohInt |
|
362 | 401 | self.isReady = True |
|
363 | 402 | |
|
364 | 403 | return avg_data |
|
365 | 404 | |
|
366 | 405 | def exe(self, data, datatime=None): |
|
367 | 406 | |
|
368 | 407 | if not self.__isByTime: |
|
369 | 408 | avg_data = self.byProfiles(data) |
|
370 | 409 | else: |
|
371 | 410 | avg_data = self.byTime(data, datatime) |
|
372 | 411 | |
|
373 | 412 | self.data = avg_data |
|
374 | 413 | |
|
375 | 414 | return avg_data |
|
376 | 415 | |
|
377 | 416 |
General Comments 0
You need to be logged in to leave comments.
Login now