@@ -1,1363 +1,1363 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from figure import Figure, isRealtime |
|
6 | 6 | from plotting_codes import * |
|
7 | 7 | |
|
8 | 8 | class MomentsPlot(Figure): |
|
9 | 9 | |
|
10 | 10 | isConfig = None |
|
11 | 11 | __nsubplots = None |
|
12 | 12 | |
|
13 | 13 | WIDTHPROF = None |
|
14 | 14 | HEIGHTPROF = None |
|
15 | 15 | PREFIX = 'prm' |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | |
|
19 | 19 | self.isConfig = False |
|
20 | 20 | self.__nsubplots = 1 |
|
21 | 21 | |
|
22 | 22 | self.WIDTH = 280 |
|
23 | 23 | self.HEIGHT = 250 |
|
24 | 24 | self.WIDTHPROF = 120 |
|
25 | 25 | self.HEIGHTPROF = 0 |
|
26 | 26 | self.counter_imagwr = 0 |
|
27 | 27 | |
|
28 | 28 | self.PLOT_CODE = MOMENTS_CODE |
|
29 | 29 | |
|
30 | 30 | self.FTP_WEI = None |
|
31 | 31 | self.EXP_CODE = None |
|
32 | 32 | self.SUB_EXP_CODE = None |
|
33 | 33 | self.PLOT_POS = None |
|
34 | 34 | |
|
35 | 35 | def getSubplots(self): |
|
36 | 36 | |
|
37 | 37 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
38 | 38 | nrow = int(self.nplots*1./ncol + 0.9) |
|
39 | 39 | |
|
40 | 40 | return nrow, ncol |
|
41 | 41 | |
|
42 | 42 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
43 | 43 | |
|
44 | 44 | self.__showprofile = showprofile |
|
45 | 45 | self.nplots = nplots |
|
46 | 46 | |
|
47 | 47 | ncolspan = 1 |
|
48 | 48 | colspan = 1 |
|
49 | 49 | if showprofile: |
|
50 | 50 | ncolspan = 3 |
|
51 | 51 | colspan = 2 |
|
52 | 52 | self.__nsubplots = 2 |
|
53 | 53 | |
|
54 | 54 | self.createFigure(id = id, |
|
55 | 55 | wintitle = wintitle, |
|
56 | 56 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
57 | 57 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
58 | 58 | show=show) |
|
59 | 59 | |
|
60 | 60 | nrow, ncol = self.getSubplots() |
|
61 | 61 | |
|
62 | 62 | counter = 0 |
|
63 | 63 | for y in range(nrow): |
|
64 | 64 | for x in range(ncol): |
|
65 | 65 | |
|
66 | 66 | if counter >= self.nplots: |
|
67 | 67 | break |
|
68 | 68 | |
|
69 | 69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
70 | 70 | |
|
71 | 71 | if showprofile: |
|
72 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
73 | 73 | |
|
74 | 74 | counter += 1 |
|
75 | 75 | |
|
76 | 76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
77 | 77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
78 | 78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
79 | 79 | server=None, folder=None, username=None, password=None, |
|
80 | 80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | Input: |
|
85 | 85 | dataOut : |
|
86 | 86 | id : |
|
87 | 87 | wintitle : |
|
88 | 88 | channelList : |
|
89 | 89 | showProfile : |
|
90 | 90 | xmin : None, |
|
91 | 91 | xmax : None, |
|
92 | 92 | ymin : None, |
|
93 | 93 | ymax : None, |
|
94 | 94 | zmin : None, |
|
95 | 95 | zmax : None |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | if dataOut.flagNoData: |
|
99 | 99 | return None |
|
100 | 100 | |
|
101 | 101 | if realtime: |
|
102 | 102 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
103 | 103 | print 'Skipping this plot function' |
|
104 | 104 | return |
|
105 | 105 | |
|
106 | 106 | if channelList == None: |
|
107 | 107 | channelIndexList = dataOut.channelIndexList |
|
108 | 108 | else: |
|
109 | 109 | channelIndexList = [] |
|
110 | 110 | for channel in channelList: |
|
111 | 111 | if channel not in dataOut.channelList: |
|
112 | 112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
113 | 113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
114 | 114 | |
|
115 | 115 | factor = dataOut.normFactor |
|
116 | 116 | x = dataOut.abscissaList |
|
117 | 117 | y = dataOut.heightList |
|
118 | 118 | |
|
119 | 119 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
120 | 120 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
121 | 121 | avg = numpy.average(z, axis=1) |
|
122 | 122 | noise = dataOut.noise/factor |
|
123 | 123 | |
|
124 | 124 | zdB = 10*numpy.log10(z) |
|
125 | 125 | avgdB = 10*numpy.log10(avg) |
|
126 | 126 | noisedB = 10*numpy.log10(noise) |
|
127 | 127 | |
|
128 | 128 | #thisDatetime = dataOut.datatime |
|
129 | 129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
130 | 130 | title = wintitle + " Parameters" |
|
131 | 131 | xlabel = "Velocity (m/s)" |
|
132 | 132 | ylabel = "Range (Km)" |
|
133 | 133 | |
|
134 | 134 | if not self.isConfig: |
|
135 | 135 | |
|
136 | 136 | nplots = len(channelIndexList) |
|
137 | 137 | |
|
138 | 138 | self.setup(id=id, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | showprofile=showprofile, |
|
142 | 142 | show=show) |
|
143 | 143 | |
|
144 | 144 | if xmin == None: xmin = numpy.nanmin(x) |
|
145 | 145 | if xmax == None: xmax = numpy.nanmax(x) |
|
146 | 146 | if ymin == None: ymin = numpy.nanmin(y) |
|
147 | 147 | if ymax == None: ymax = numpy.nanmax(y) |
|
148 | 148 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
149 | 149 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
150 | 150 | |
|
151 | 151 | self.FTP_WEI = ftp_wei |
|
152 | 152 | self.EXP_CODE = exp_code |
|
153 | 153 | self.SUB_EXP_CODE = sub_exp_code |
|
154 | 154 | self.PLOT_POS = plot_pos |
|
155 | 155 | |
|
156 | 156 | self.isConfig = True |
|
157 | 157 | |
|
158 | 158 | self.setWinTitle(title) |
|
159 | 159 | |
|
160 | 160 | for i in range(self.nplots): |
|
161 | 161 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
162 | 162 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
163 | 163 | axes = self.axesList[i*self.__nsubplots] |
|
164 | 164 | axes.pcolor(x, y, zdB[i,:,:], |
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, cblabel='') |
|
168 | 168 | #Mean Line |
|
169 | 169 | mean = dataOut.data_param[i, 1, :] |
|
170 | 170 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
171 | 171 | |
|
172 | 172 | if self.__showprofile: |
|
173 | 173 | axes = self.axesList[i*self.__nsubplots +1] |
|
174 | 174 | axes.pline(avgdB[i], y, |
|
175 | 175 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
176 | 176 | xlabel='dB', ylabel='', title='', |
|
177 | 177 | ytick_visible=False, |
|
178 | 178 | grid='x') |
|
179 | 179 | |
|
180 | 180 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
181 | 181 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
182 | 182 | |
|
183 | 183 | self.draw() |
|
184 | 184 | |
|
185 | 185 | self.save(figpath=figpath, |
|
186 | 186 | figfile=figfile, |
|
187 | 187 | save=save, |
|
188 | 188 | ftp=ftp, |
|
189 | 189 | wr_period=wr_period, |
|
190 | 190 | thisDatetime=thisDatetime) |
|
191 | 191 | |
|
192 | 192 | |
|
193 | 193 | |
|
194 | 194 | class SkyMapPlot(Figure): |
|
195 | 195 | |
|
196 | 196 | __isConfig = None |
|
197 | 197 | __nsubplots = None |
|
198 | 198 | |
|
199 | 199 | WIDTHPROF = None |
|
200 | 200 | HEIGHTPROF = None |
|
201 | 201 | PREFIX = 'mmap' |
|
202 | 202 | |
|
203 | 203 | def __init__(self): |
|
204 | 204 | |
|
205 | 205 | self.__isConfig = False |
|
206 | 206 | self.__nsubplots = 1 |
|
207 | 207 | |
|
208 | 208 | # self.WIDTH = 280 |
|
209 | 209 | # self.HEIGHT = 250 |
|
210 | 210 | self.WIDTH = 600 |
|
211 | 211 | self.HEIGHT = 600 |
|
212 | 212 | self.WIDTHPROF = 120 |
|
213 | 213 | self.HEIGHTPROF = 0 |
|
214 | 214 | self.counter_imagwr = 0 |
|
215 | 215 | |
|
216 | 216 | self.PLOT_CODE = MSKYMAP_CODE |
|
217 | 217 | |
|
218 | 218 | self.FTP_WEI = None |
|
219 | 219 | self.EXP_CODE = None |
|
220 | 220 | self.SUB_EXP_CODE = None |
|
221 | 221 | self.PLOT_POS = None |
|
222 | 222 | |
|
223 | 223 | def getSubplots(self): |
|
224 | 224 | |
|
225 | 225 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
226 | 226 | nrow = int(self.nplots*1./ncol + 0.9) |
|
227 | 227 | |
|
228 | 228 | return nrow, ncol |
|
229 | 229 | |
|
230 | 230 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
231 | 231 | |
|
232 | 232 | self.__showprofile = showprofile |
|
233 | 233 | self.nplots = nplots |
|
234 | 234 | |
|
235 | 235 | ncolspan = 1 |
|
236 | 236 | colspan = 1 |
|
237 | 237 | |
|
238 | 238 | self.createFigure(id = id, |
|
239 | 239 | wintitle = wintitle, |
|
240 | 240 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
241 | 241 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
242 | 242 | show=show) |
|
243 | 243 | |
|
244 | 244 | nrow, ncol = 1,1 |
|
245 | 245 | counter = 0 |
|
246 | 246 | x = 0 |
|
247 | 247 | y = 0 |
|
248 | 248 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
249 | 249 | |
|
250 | 250 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
251 | 251 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
252 | 252 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
253 | 253 | server=None, folder=None, username=None, password=None, |
|
254 | 254 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
255 | 255 | |
|
256 | 256 | """ |
|
257 | 257 | |
|
258 | 258 | Input: |
|
259 | 259 | dataOut : |
|
260 | 260 | id : |
|
261 | 261 | wintitle : |
|
262 | 262 | channelList : |
|
263 | 263 | showProfile : |
|
264 | 264 | xmin : None, |
|
265 | 265 | xmax : None, |
|
266 | 266 | ymin : None, |
|
267 | 267 | ymax : None, |
|
268 | 268 | zmin : None, |
|
269 | 269 | zmax : None |
|
270 | 270 | """ |
|
271 | 271 | |
|
272 | 272 | arrayParameters = dataOut.data_param[0,:] |
|
273 | 273 | error = arrayParameters[:,-1] |
|
274 | 274 | indValid = numpy.where(error == 0)[0] |
|
275 | 275 | finalMeteor = arrayParameters[indValid,:] |
|
276 | 276 | finalAzimuth = finalMeteor[:,4] |
|
277 | 277 | finalZenith = finalMeteor[:,5] |
|
278 | 278 | |
|
279 | 279 | x = finalAzimuth*numpy.pi/180 |
|
280 | 280 | y = finalZenith |
|
281 | 281 | |
|
282 | 282 | |
|
283 | 283 | #thisDatetime = dataOut.datatime |
|
284 | 284 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
285 | 285 | title = wintitle + " Parameters" |
|
286 | 286 | xlabel = "Zonal Zenith Angle (deg) " |
|
287 | 287 | ylabel = "Meridional Zenith Angle (deg)" |
|
288 | 288 | |
|
289 | 289 | if not self.__isConfig: |
|
290 | 290 | |
|
291 | 291 | nplots = 1 |
|
292 | 292 | |
|
293 | 293 | self.setup(id=id, |
|
294 | 294 | nplots=nplots, |
|
295 | 295 | wintitle=wintitle, |
|
296 | 296 | showprofile=showprofile, |
|
297 | 297 | show=show) |
|
298 | 298 | |
|
299 | 299 | self.FTP_WEI = ftp_wei |
|
300 | 300 | self.EXP_CODE = exp_code |
|
301 | 301 | self.SUB_EXP_CODE = sub_exp_code |
|
302 | 302 | self.PLOT_POS = plot_pos |
|
303 | 303 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
304 | 304 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
305 | 305 | self.__isConfig = True |
|
306 | 306 | |
|
307 | 307 | self.setWinTitle(title) |
|
308 | 308 | |
|
309 | 309 | i = 0 |
|
310 | 310 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
311 | 311 | |
|
312 | 312 | axes = self.axesList[i*self.__nsubplots] |
|
313 | 313 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
314 | 314 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
315 | 315 | axes.polar(x, y, |
|
316 | 316 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
317 | 317 | ticksize=9, cblabel='') |
|
318 | 318 | |
|
319 | 319 | self.draw() |
|
320 | 320 | |
|
321 | 321 | self.save(figpath=figpath, |
|
322 | 322 | figfile=figfile, |
|
323 | 323 | save=save, |
|
324 | 324 | ftp=ftp, |
|
325 | 325 | wr_period=wr_period, |
|
326 | 326 | thisDatetime=thisDatetime) |
|
327 | 327 | |
|
328 | 328 | |
|
329 | 329 | class WindProfilerPlot(Figure): |
|
330 | 330 | |
|
331 | 331 | __isConfig = None |
|
332 | 332 | __nsubplots = None |
|
333 | 333 | |
|
334 | 334 | WIDTHPROF = None |
|
335 | 335 | HEIGHTPROF = None |
|
336 | 336 | PREFIX = 'wind' |
|
337 | 337 | |
|
338 | 338 | def __init__(self): |
|
339 | 339 | |
|
340 | 340 | self.timerange = None |
|
341 | 341 | self.__isConfig = False |
|
342 | 342 | self.__nsubplots = 1 |
|
343 | 343 | |
|
344 | 344 | self.WIDTH = 800 |
|
345 | 345 | self.HEIGHT = 150 |
|
346 | 346 | self.WIDTHPROF = 120 |
|
347 | 347 | self.HEIGHTPROF = 0 |
|
348 | 348 | self.counter_imagwr = 0 |
|
349 | 349 | |
|
350 | 350 | self.PLOT_CODE = WIND_CODE |
|
351 | 351 | |
|
352 | 352 | self.FTP_WEI = None |
|
353 | 353 | self.EXP_CODE = None |
|
354 | 354 | self.SUB_EXP_CODE = None |
|
355 | 355 | self.PLOT_POS = None |
|
356 | 356 | self.tmin = None |
|
357 | 357 | self.tmax = None |
|
358 | 358 | |
|
359 | 359 | self.xmin = None |
|
360 | 360 | self.xmax = None |
|
361 | 361 | |
|
362 | 362 | self.figfile = None |
|
363 | 363 | |
|
364 | 364 | def getSubplots(self): |
|
365 | 365 | |
|
366 | 366 | ncol = 1 |
|
367 | 367 | nrow = self.nplots |
|
368 | 368 | |
|
369 | 369 | return nrow, ncol |
|
370 | 370 | |
|
371 | 371 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
372 | 372 | |
|
373 | 373 | self.__showprofile = showprofile |
|
374 | 374 | self.nplots = nplots |
|
375 | 375 | |
|
376 | 376 | ncolspan = 1 |
|
377 | 377 | colspan = 1 |
|
378 | 378 | |
|
379 | 379 | self.createFigure(id = id, |
|
380 | 380 | wintitle = wintitle, |
|
381 | 381 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
382 | 382 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
383 | 383 | show=show) |
|
384 | 384 | |
|
385 | 385 | nrow, ncol = self.getSubplots() |
|
386 | 386 | |
|
387 | 387 | counter = 0 |
|
388 | 388 | for y in range(nrow): |
|
389 | 389 | if counter >= self.nplots: |
|
390 | 390 | break |
|
391 | 391 | |
|
392 | 392 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
393 | 393 | counter += 1 |
|
394 | 394 | |
|
395 | 395 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
396 | 396 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
397 | 397 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
398 | 398 | timerange=None, SNRthresh = None, |
|
399 | 399 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
400 | 400 | server=None, folder=None, username=None, password=None, |
|
401 | 401 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
402 | 402 | """ |
|
403 | 403 | |
|
404 | 404 | Input: |
|
405 | 405 | dataOut : |
|
406 | 406 | id : |
|
407 | 407 | wintitle : |
|
408 | 408 | channelList : |
|
409 | 409 | showProfile : |
|
410 | 410 | xmin : None, |
|
411 | 411 | xmax : None, |
|
412 | 412 | ymin : None, |
|
413 | 413 | ymax : None, |
|
414 | 414 | zmin : None, |
|
415 | 415 | zmax : None |
|
416 | 416 | """ |
|
417 | 417 | |
|
418 | 418 | if channelList == None: |
|
419 | 419 | channelIndexList = dataOut.channelIndexList |
|
420 | 420 | else: |
|
421 | 421 | channelIndexList = [] |
|
422 | 422 | for channel in channelList: |
|
423 | 423 | if channel not in dataOut.channelList: |
|
424 | 424 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
425 | 425 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
426 | 426 | |
|
427 |
# if timerange |
|
|
427 | # if timerange is not None: | |
|
428 | 428 | # self.timerange = timerange |
|
429 | 429 | # |
|
430 | 430 | # tmin = None |
|
431 | 431 | # tmax = None |
|
432 | 432 | |
|
433 | 433 | x = dataOut.getTimeRange1() |
|
434 | 434 | # y = dataOut.heightList |
|
435 | 435 | y = dataOut.heightList |
|
436 | 436 | |
|
437 | 437 | z = dataOut.data_output.copy() |
|
438 | 438 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
439 | 439 | nplotsw = nplots |
|
440 | 440 | |
|
441 | 441 | #If there is a SNR function defined |
|
442 |
if dataOut.data_SNR |
|
|
442 | if dataOut.data_SNR is not None: | |
|
443 | 443 | nplots += 1 |
|
444 | 444 | SNR = dataOut.data_SNR |
|
445 | 445 | SNRavg = numpy.average(SNR, axis=0) |
|
446 | 446 | |
|
447 | 447 | SNRdB = 10*numpy.log10(SNR) |
|
448 | 448 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
449 | 449 | |
|
450 | 450 | if SNRthresh == None: SNRthresh = -5.0 |
|
451 | 451 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
452 | 452 | |
|
453 | 453 | for i in range(nplotsw): |
|
454 | 454 | z[i,ind] = numpy.nan |
|
455 | 455 | |
|
456 | 456 | |
|
457 | 457 | # showprofile = False |
|
458 | 458 | # thisDatetime = dataOut.datatime |
|
459 | 459 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
460 | 460 | title = wintitle + "Wind" |
|
461 | 461 | xlabel = "" |
|
462 | 462 | ylabel = "Range (Km)" |
|
463 | 463 | |
|
464 | 464 | if not self.__isConfig: |
|
465 | 465 | |
|
466 | 466 | self.setup(id=id, |
|
467 | 467 | nplots=nplots, |
|
468 | 468 | wintitle=wintitle, |
|
469 | 469 | showprofile=showprofile, |
|
470 | 470 | show=show) |
|
471 | 471 | |
|
472 |
if timerange |
|
|
472 | if timerange is not None: | |
|
473 | 473 | self.timerange = timerange |
|
474 | 474 | |
|
475 | 475 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
476 | 476 | |
|
477 | 477 | if ymin == None: ymin = numpy.nanmin(y) |
|
478 | 478 | if ymax == None: ymax = numpy.nanmax(y) |
|
479 | 479 | |
|
480 | 480 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
481 | 481 | #if numpy.isnan(zmax): zmax = 50 |
|
482 | 482 | if zmin == None: zmin = -zmax |
|
483 | 483 | |
|
484 | 484 | if nplotsw == 3: |
|
485 | 485 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
486 | 486 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
487 | 487 | |
|
488 |
if dataOut.data_SNR |
|
|
488 | if dataOut.data_SNR is not None: | |
|
489 | 489 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
490 | 490 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
491 | 491 | |
|
492 | 492 | |
|
493 | 493 | self.FTP_WEI = ftp_wei |
|
494 | 494 | self.EXP_CODE = exp_code |
|
495 | 495 | self.SUB_EXP_CODE = sub_exp_code |
|
496 | 496 | self.PLOT_POS = plot_pos |
|
497 | 497 | |
|
498 | 498 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
499 | 499 | self.__isConfig = True |
|
500 | 500 | self.figfile = figfile |
|
501 | 501 | |
|
502 | 502 | self.setWinTitle(title) |
|
503 | 503 | |
|
504 | 504 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
505 | 505 | x[1] = self.xmax |
|
506 | 506 | |
|
507 | 507 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
508 | 508 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
509 | 509 | zmaxVector = [zmax, zmax, zmax_ver] |
|
510 | 510 | zminVector = [zmin, zmin, zmin_ver] |
|
511 | 511 | windFactor = [1,1,100] |
|
512 | 512 | |
|
513 | 513 | for i in range(nplotsw): |
|
514 | 514 | |
|
515 | 515 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
516 | 516 | axes = self.axesList[i*self.__nsubplots] |
|
517 | 517 | |
|
518 | 518 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
519 | 519 | |
|
520 | 520 | axes.pcolorbuffer(x, y, z1, |
|
521 | 521 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
522 | 522 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
523 | 523 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) |
|
524 | 524 | |
|
525 |
if dataOut.data_SNR |
|
|
525 | if dataOut.data_SNR is not None: | |
|
526 | 526 | i += 1 |
|
527 | 527 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
528 | 528 | axes = self.axesList[i*self.__nsubplots] |
|
529 | 529 | |
|
530 | 530 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
531 | 531 | |
|
532 | 532 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
533 | 533 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
534 | 534 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
535 | 535 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
536 | 536 | |
|
537 | 537 | self.draw() |
|
538 | 538 | |
|
539 | 539 | if x[1] >= self.axesList[0].xmax: |
|
540 | 540 | self.counter_imagwr = wr_period |
|
541 | 541 | self.__isConfig = False |
|
542 | 542 | self.figfile = None |
|
543 | 543 | |
|
544 | 544 | self.save(figpath=figpath, |
|
545 | 545 | figfile=figfile, |
|
546 | 546 | save=save, |
|
547 | 547 | ftp=ftp, |
|
548 | 548 | wr_period=wr_period, |
|
549 | 549 | thisDatetime=thisDatetime, |
|
550 | 550 | update_figfile=False) |
|
551 | 551 | |
|
552 | 552 | |
|
553 | 553 | class ParametersPlot(Figure): |
|
554 | 554 | |
|
555 | 555 | __isConfig = None |
|
556 | 556 | __nsubplots = None |
|
557 | 557 | |
|
558 | 558 | WIDTHPROF = None |
|
559 | 559 | HEIGHTPROF = None |
|
560 | 560 | PREFIX = 'prm' |
|
561 | 561 | |
|
562 | 562 | def __init__(self): |
|
563 | 563 | |
|
564 | 564 | self.timerange = 2*60*60 |
|
565 | 565 | self.__isConfig = False |
|
566 | 566 | self.__nsubplots = 1 |
|
567 | 567 | |
|
568 | 568 | self.WIDTH = 800 |
|
569 | 569 | self.HEIGHT = 150 |
|
570 | 570 | self.WIDTHPROF = 120 |
|
571 | 571 | self.HEIGHTPROF = 0 |
|
572 | 572 | self.counter_imagwr = 0 |
|
573 | 573 | |
|
574 | 574 | self.PLOT_CODE = PARMS_CODE |
|
575 | 575 | |
|
576 | 576 | self.FTP_WEI = None |
|
577 | 577 | self.EXP_CODE = None |
|
578 | 578 | self.SUB_EXP_CODE = None |
|
579 | 579 | self.PLOT_POS = None |
|
580 | 580 | self.tmin = None |
|
581 | 581 | self.tmax = None |
|
582 | 582 | |
|
583 | 583 | self.xmin = None |
|
584 | 584 | self.xmax = None |
|
585 | 585 | |
|
586 | 586 | self.figfile = None |
|
587 | 587 | |
|
588 | 588 | def getSubplots(self): |
|
589 | 589 | |
|
590 | 590 | ncol = 1 |
|
591 | 591 | nrow = self.nplots |
|
592 | 592 | |
|
593 | 593 | return nrow, ncol |
|
594 | 594 | |
|
595 | 595 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
596 | 596 | |
|
597 | 597 | self.__showprofile = showprofile |
|
598 | 598 | self.nplots = nplots |
|
599 | 599 | |
|
600 | 600 | ncolspan = 1 |
|
601 | 601 | colspan = 1 |
|
602 | 602 | |
|
603 | 603 | self.createFigure(id = id, |
|
604 | 604 | wintitle = wintitle, |
|
605 | 605 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
606 | 606 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
607 | 607 | show=show) |
|
608 | 608 | |
|
609 | 609 | nrow, ncol = self.getSubplots() |
|
610 | 610 | |
|
611 | 611 | counter = 0 |
|
612 | 612 | for y in range(nrow): |
|
613 | 613 | for x in range(ncol): |
|
614 | 614 | |
|
615 | 615 | if counter >= self.nplots: |
|
616 | 616 | break |
|
617 | 617 | |
|
618 | 618 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
619 | 619 | |
|
620 | 620 | if showprofile: |
|
621 | 621 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
622 | 622 | |
|
623 | 623 | counter += 1 |
|
624 | 624 | |
|
625 | 625 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
626 | 626 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
627 | 627 | parameterIndex = None, onlyPositive = False, |
|
628 | 628 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
629 | 629 | DOP = True, |
|
630 | 630 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
631 | 631 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
632 | 632 | server=None, folder=None, username=None, password=None, |
|
633 | 633 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
634 | 634 | |
|
635 | 635 | """ |
|
636 | 636 | |
|
637 | 637 | Input: |
|
638 | 638 | dataOut : |
|
639 | 639 | id : |
|
640 | 640 | wintitle : |
|
641 | 641 | channelList : |
|
642 | 642 | showProfile : |
|
643 | 643 | xmin : None, |
|
644 | 644 | xmax : None, |
|
645 | 645 | ymin : None, |
|
646 | 646 | ymax : None, |
|
647 | 647 | zmin : None, |
|
648 | 648 | zmax : None |
|
649 | 649 | """ |
|
650 | 650 | |
|
651 | 651 | data_param = getattr(dataOut, parameterObject) |
|
652 | 652 | |
|
653 | 653 | if channelList == None: |
|
654 | 654 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
655 | 655 | else: |
|
656 | 656 | channelIndexList = numpy.array(channelList) |
|
657 | 657 | |
|
658 | 658 | nchan = len(channelIndexList) #Number of channels being plotted |
|
659 | 659 | |
|
660 | 660 | if nchan < 1: |
|
661 | 661 | return |
|
662 | 662 | |
|
663 | 663 | nGraphsByChannel = 0 |
|
664 | 664 | |
|
665 | 665 | if SNR: |
|
666 | 666 | nGraphsByChannel += 1 |
|
667 | 667 | if DOP: |
|
668 | 668 | nGraphsByChannel += 1 |
|
669 | 669 | |
|
670 | 670 | if nGraphsByChannel < 1: |
|
671 | 671 | return |
|
672 | 672 | |
|
673 | 673 | nplots = nGraphsByChannel*nchan |
|
674 | 674 | |
|
675 |
if timerange |
|
|
675 | if timerange is not None: | |
|
676 | 676 | self.timerange = timerange |
|
677 | 677 | |
|
678 | 678 | #tmin = None |
|
679 | 679 | #tmax = None |
|
680 | 680 | if parameterIndex == None: |
|
681 | 681 | parameterIndex = 1 |
|
682 | 682 | |
|
683 | 683 | x = dataOut.getTimeRange1() |
|
684 | 684 | y = dataOut.heightList |
|
685 | 685 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
686 | 686 | |
|
687 | 687 | zRange = dataOut.abscissaList |
|
688 | 688 | # nChannels = z.shape[0] #Number of wind dimensions estimated |
|
689 | 689 | # thisDatetime = dataOut.datatime |
|
690 | 690 | |
|
691 |
if dataOut.data_SNR |
|
|
691 | if dataOut.data_SNR is not None: | |
|
692 | 692 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
693 | 693 | SNRdB = 10*numpy.log10(SNRarray) |
|
694 | 694 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
695 | 695 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
696 | 696 | z[ind] = numpy.nan |
|
697 | 697 | |
|
698 | 698 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
699 | 699 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
700 | 700 | xlabel = "" |
|
701 | 701 | ylabel = "Range (Km)" |
|
702 | 702 | |
|
703 | 703 | if (SNR and not onlySNR): nplots = 2*nplots |
|
704 | 704 | |
|
705 | 705 | if onlyPositive: |
|
706 | 706 | colormap = "jet" |
|
707 | 707 | zmin = 0 |
|
708 | 708 | else: colormap = "RdBu_r" |
|
709 | 709 | |
|
710 | 710 | if not self.__isConfig: |
|
711 | 711 | |
|
712 | 712 | self.setup(id=id, |
|
713 | 713 | nplots=nplots, |
|
714 | 714 | wintitle=wintitle, |
|
715 | 715 | showprofile=showprofile, |
|
716 | 716 | show=show) |
|
717 | 717 | |
|
718 | 718 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
719 | 719 | |
|
720 | 720 | if ymin == None: ymin = numpy.nanmin(y) |
|
721 | 721 | if ymax == None: ymax = numpy.nanmax(y) |
|
722 | 722 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
723 | 723 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
724 | 724 | |
|
725 | 725 | if SNR: |
|
726 | 726 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
727 | 727 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
728 | 728 | |
|
729 | 729 | self.FTP_WEI = ftp_wei |
|
730 | 730 | self.EXP_CODE = exp_code |
|
731 | 731 | self.SUB_EXP_CODE = sub_exp_code |
|
732 | 732 | self.PLOT_POS = plot_pos |
|
733 | 733 | |
|
734 | 734 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
735 | 735 | self.__isConfig = True |
|
736 | 736 | self.figfile = figfile |
|
737 | 737 | |
|
738 | 738 | self.setWinTitle(title) |
|
739 | 739 | |
|
740 | 740 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
741 | 741 | x[1] = self.xmax |
|
742 | 742 | |
|
743 | 743 | for i in range(nchan): |
|
744 | 744 | |
|
745 | 745 | if (SNR and not onlySNR): j = 2*i |
|
746 | 746 | else: j = i |
|
747 | 747 | |
|
748 | 748 | j = nGraphsByChannel*i |
|
749 | 749 | |
|
750 | 750 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
751 | 751 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
752 | 752 | |
|
753 | 753 | if not onlySNR: |
|
754 | 754 | axes = self.axesList[j*self.__nsubplots] |
|
755 | 755 | z1 = z[i,:].reshape((1,-1)) |
|
756 | 756 | axes.pcolorbuffer(x, y, z1, |
|
757 | 757 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
758 | 758 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
759 | 759 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
760 | 760 | |
|
761 | 761 | if DOP: |
|
762 | 762 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
763 | 763 | |
|
764 | 764 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
765 | 765 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
766 | 766 | axes = self.axesList[j] |
|
767 | 767 | z1 = z[i,:].reshape((1,-1)) |
|
768 | 768 | axes.pcolorbuffer(x, y, z1, |
|
769 | 769 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
770 | 770 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
771 | 771 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
772 | 772 | |
|
773 | 773 | if SNR: |
|
774 | 774 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
775 | 775 | axes = self.axesList[(j)*self.__nsubplots] |
|
776 | 776 | if not onlySNR: |
|
777 | 777 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
778 | 778 | |
|
779 | 779 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
780 | 780 | |
|
781 | 781 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
782 | 782 | axes.pcolorbuffer(x, y, z1, |
|
783 | 783 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
784 | 784 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
785 | 785 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
786 | 786 | |
|
787 | 787 | |
|
788 | 788 | |
|
789 | 789 | self.draw() |
|
790 | 790 | |
|
791 | 791 | if x[1] >= self.axesList[0].xmax: |
|
792 | 792 | self.counter_imagwr = wr_period |
|
793 | 793 | self.__isConfig = False |
|
794 | 794 | self.figfile = None |
|
795 | 795 | |
|
796 | 796 | self.save(figpath=figpath, |
|
797 | 797 | figfile=figfile, |
|
798 | 798 | save=save, |
|
799 | 799 | ftp=ftp, |
|
800 | 800 | wr_period=wr_period, |
|
801 | 801 | thisDatetime=thisDatetime, |
|
802 | 802 | update_figfile=False) |
|
803 | 803 | |
|
804 | 804 | class SpectralFittingPlot(Figure): |
|
805 | 805 | |
|
806 | 806 | __isConfig = None |
|
807 | 807 | __nsubplots = None |
|
808 | 808 | |
|
809 | 809 | WIDTHPROF = None |
|
810 | 810 | HEIGHTPROF = None |
|
811 | 811 | PREFIX = 'prm' |
|
812 | 812 | |
|
813 | 813 | |
|
814 | 814 | N = None |
|
815 | 815 | ippSeconds = None |
|
816 | 816 | |
|
817 | 817 | def __init__(self): |
|
818 | 818 | self.__isConfig = False |
|
819 | 819 | self.__nsubplots = 1 |
|
820 | 820 | |
|
821 | 821 | self.PLOT_CODE = SPECFIT_CODE |
|
822 | 822 | |
|
823 | 823 | self.WIDTH = 450 |
|
824 | 824 | self.HEIGHT = 250 |
|
825 | 825 | self.WIDTHPROF = 0 |
|
826 | 826 | self.HEIGHTPROF = 0 |
|
827 | 827 | |
|
828 | 828 | def getSubplots(self): |
|
829 | 829 | |
|
830 | 830 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
831 | 831 | nrow = int(self.nplots*1./ncol + 0.9) |
|
832 | 832 | |
|
833 | 833 | return nrow, ncol |
|
834 | 834 | |
|
835 | 835 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
836 | 836 | |
|
837 | 837 | showprofile = False |
|
838 | 838 | self.__showprofile = showprofile |
|
839 | 839 | self.nplots = nplots |
|
840 | 840 | |
|
841 | 841 | ncolspan = 5 |
|
842 | 842 | colspan = 4 |
|
843 | 843 | if showprofile: |
|
844 | 844 | ncolspan = 5 |
|
845 | 845 | colspan = 4 |
|
846 | 846 | self.__nsubplots = 2 |
|
847 | 847 | |
|
848 | 848 | self.createFigure(id = id, |
|
849 | 849 | wintitle = wintitle, |
|
850 | 850 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
851 | 851 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
852 | 852 | show=show) |
|
853 | 853 | |
|
854 | 854 | nrow, ncol = self.getSubplots() |
|
855 | 855 | |
|
856 | 856 | counter = 0 |
|
857 | 857 | for y in range(nrow): |
|
858 | 858 | for x in range(ncol): |
|
859 | 859 | |
|
860 | 860 | if counter >= self.nplots: |
|
861 | 861 | break |
|
862 | 862 | |
|
863 | 863 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
864 | 864 | |
|
865 | 865 | if showprofile: |
|
866 | 866 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
867 | 867 | |
|
868 | 868 | counter += 1 |
|
869 | 869 | |
|
870 | 870 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
871 | 871 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
872 | 872 | save=False, figpath='./', figfile=None, show=True): |
|
873 | 873 | |
|
874 | 874 | """ |
|
875 | 875 | |
|
876 | 876 | Input: |
|
877 | 877 | dataOut : |
|
878 | 878 | id : |
|
879 | 879 | wintitle : |
|
880 | 880 | channelList : |
|
881 | 881 | showProfile : |
|
882 | 882 | xmin : None, |
|
883 | 883 | xmax : None, |
|
884 | 884 | zmin : None, |
|
885 | 885 | zmax : None |
|
886 | 886 | """ |
|
887 | 887 | |
|
888 | 888 | if cutHeight==None: |
|
889 | 889 | h=270 |
|
890 | 890 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
891 | 891 | cutHeight = dataOut.heightList[heightindex] |
|
892 | 892 | |
|
893 | 893 | factor = dataOut.normFactor |
|
894 | 894 | x = dataOut.abscissaList[:-1] |
|
895 | 895 | #y = dataOut.getHeiRange() |
|
896 | 896 | |
|
897 | 897 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
898 | 898 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
899 | 899 | avg = numpy.average(z, axis=1) |
|
900 | 900 | listChannels = z.shape[0] |
|
901 | 901 | |
|
902 | 902 | #Reconstruct Function |
|
903 | 903 | if fit==True: |
|
904 | 904 | groupArray = dataOut.groupList |
|
905 | 905 | listChannels = groupArray.reshape((groupArray.size)) |
|
906 | 906 | listChannels.sort() |
|
907 | 907 | spcFitLine = numpy.zeros(z.shape) |
|
908 | 908 | constants = dataOut.constants |
|
909 | 909 | |
|
910 | 910 | nGroups = groupArray.shape[0] |
|
911 | 911 | nChannels = groupArray.shape[1] |
|
912 | 912 | nProfiles = z.shape[1] |
|
913 | 913 | |
|
914 | 914 | for f in range(nGroups): |
|
915 | 915 | groupChann = groupArray[f,:] |
|
916 | 916 | p = dataOut.data_param[f,:,heightindex] |
|
917 | 917 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
918 | 918 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
919 | 919 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
920 | 920 | spcFitLine[groupChann,:] = fitLineAux |
|
921 | 921 | # spcFitLine = spcFitLine/factor |
|
922 | 922 | |
|
923 | 923 | z = z[listChannels,:] |
|
924 | 924 | spcFitLine = spcFitLine[listChannels,:] |
|
925 | 925 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
926 | 926 | |
|
927 | 927 | zdB = 10*numpy.log10(z) |
|
928 | 928 | #thisDatetime = dataOut.datatime |
|
929 | 929 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
930 | 930 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
931 | 931 | xlabel = "Velocity (m/s)" |
|
932 | 932 | ylabel = "Spectrum" |
|
933 | 933 | |
|
934 | 934 | if not self.__isConfig: |
|
935 | 935 | |
|
936 | 936 | nplots = listChannels.size |
|
937 | 937 | |
|
938 | 938 | self.setup(id=id, |
|
939 | 939 | nplots=nplots, |
|
940 | 940 | wintitle=wintitle, |
|
941 | 941 | showprofile=showprofile, |
|
942 | 942 | show=show) |
|
943 | 943 | |
|
944 | 944 | if xmin == None: xmin = numpy.nanmin(x) |
|
945 | 945 | if xmax == None: xmax = numpy.nanmax(x) |
|
946 | 946 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
947 | 947 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
948 | 948 | |
|
949 | 949 | self.__isConfig = True |
|
950 | 950 | |
|
951 | 951 | self.setWinTitle(title) |
|
952 | 952 | for i in range(self.nplots): |
|
953 | 953 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
954 | 954 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1) |
|
955 | 955 | axes = self.axesList[i*self.__nsubplots] |
|
956 | 956 | if fit == False: |
|
957 | 957 | axes.pline(x, zdB[i,:], |
|
958 | 958 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
959 | 959 | xlabel=xlabel, ylabel=ylabel, title=title |
|
960 | 960 | ) |
|
961 | 961 | if fit == True: |
|
962 | 962 | fitline=spcFitLinedB[i,:] |
|
963 | 963 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
964 | 964 | legendlabels=['Data','Fitting'] |
|
965 | 965 | axes.pmultilineyaxis(x, y, |
|
966 | 966 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
967 | 967 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
968 | 968 | legendlabels=legendlabels, marker=None, |
|
969 | 969 | linestyle='solid', grid='both') |
|
970 | 970 | |
|
971 | 971 | self.draw() |
|
972 | 972 | |
|
973 | 973 | self.save(figpath=figpath, |
|
974 | 974 | figfile=figfile, |
|
975 | 975 | save=save, |
|
976 | 976 | ftp=ftp, |
|
977 | 977 | wr_period=wr_period, |
|
978 | 978 | thisDatetime=thisDatetime) |
|
979 | 979 | |
|
980 | 980 | |
|
981 | 981 | class EWDriftsPlot(Figure): |
|
982 | 982 | |
|
983 | 983 | __isConfig = None |
|
984 | 984 | __nsubplots = None |
|
985 | 985 | |
|
986 | 986 | WIDTHPROF = None |
|
987 | 987 | HEIGHTPROF = None |
|
988 | 988 | PREFIX = 'drift' |
|
989 | 989 | |
|
990 | 990 | def __init__(self): |
|
991 | 991 | |
|
992 | 992 | self.timerange = 2*60*60 |
|
993 | 993 | self.isConfig = False |
|
994 | 994 | self.__nsubplots = 1 |
|
995 | 995 | |
|
996 | 996 | self.WIDTH = 800 |
|
997 | 997 | self.HEIGHT = 150 |
|
998 | 998 | self.WIDTHPROF = 120 |
|
999 | 999 | self.HEIGHTPROF = 0 |
|
1000 | 1000 | self.counter_imagwr = 0 |
|
1001 | 1001 | |
|
1002 | 1002 | self.PLOT_CODE = EWDRIFT_CODE |
|
1003 | 1003 | |
|
1004 | 1004 | self.FTP_WEI = None |
|
1005 | 1005 | self.EXP_CODE = None |
|
1006 | 1006 | self.SUB_EXP_CODE = None |
|
1007 | 1007 | self.PLOT_POS = None |
|
1008 | 1008 | self.tmin = None |
|
1009 | 1009 | self.tmax = None |
|
1010 | 1010 | |
|
1011 | 1011 | self.xmin = None |
|
1012 | 1012 | self.xmax = None |
|
1013 | 1013 | |
|
1014 | 1014 | self.figfile = None |
|
1015 | 1015 | |
|
1016 | 1016 | def getSubplots(self): |
|
1017 | 1017 | |
|
1018 | 1018 | ncol = 1 |
|
1019 | 1019 | nrow = self.nplots |
|
1020 | 1020 | |
|
1021 | 1021 | return nrow, ncol |
|
1022 | 1022 | |
|
1023 | 1023 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1024 | 1024 | |
|
1025 | 1025 | self.__showprofile = showprofile |
|
1026 | 1026 | self.nplots = nplots |
|
1027 | 1027 | |
|
1028 | 1028 | ncolspan = 1 |
|
1029 | 1029 | colspan = 1 |
|
1030 | 1030 | |
|
1031 | 1031 | self.createFigure(id = id, |
|
1032 | 1032 | wintitle = wintitle, |
|
1033 | 1033 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1034 | 1034 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1035 | 1035 | show=show) |
|
1036 | 1036 | |
|
1037 | 1037 | nrow, ncol = self.getSubplots() |
|
1038 | 1038 | |
|
1039 | 1039 | counter = 0 |
|
1040 | 1040 | for y in range(nrow): |
|
1041 | 1041 | if counter >= self.nplots: |
|
1042 | 1042 | break |
|
1043 | 1043 | |
|
1044 | 1044 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1045 | 1045 | counter += 1 |
|
1046 | 1046 | |
|
1047 | 1047 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1048 | 1048 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1049 | 1049 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1050 | 1050 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1051 | 1051 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1052 | 1052 | server=None, folder=None, username=None, password=None, |
|
1053 | 1053 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1054 | 1054 | """ |
|
1055 | 1055 | |
|
1056 | 1056 | Input: |
|
1057 | 1057 | dataOut : |
|
1058 | 1058 | id : |
|
1059 | 1059 | wintitle : |
|
1060 | 1060 | channelList : |
|
1061 | 1061 | showProfile : |
|
1062 | 1062 | xmin : None, |
|
1063 | 1063 | xmax : None, |
|
1064 | 1064 | ymin : None, |
|
1065 | 1065 | ymax : None, |
|
1066 | 1066 | zmin : None, |
|
1067 | 1067 | zmax : None |
|
1068 | 1068 | """ |
|
1069 | 1069 | |
|
1070 |
if timerange |
|
|
1070 | if timerange is not None: | |
|
1071 | 1071 | self.timerange = timerange |
|
1072 | 1072 | |
|
1073 | 1073 | tmin = None |
|
1074 | 1074 | tmax = None |
|
1075 | 1075 | |
|
1076 | 1076 | x = dataOut.getTimeRange1() |
|
1077 | 1077 | # y = dataOut.heightList |
|
1078 | 1078 | y = dataOut.heightList |
|
1079 | 1079 | |
|
1080 | 1080 | z = dataOut.data_output |
|
1081 | 1081 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1082 | 1082 | nplotsw = nplots |
|
1083 | 1083 | |
|
1084 | 1084 | #If there is a SNR function defined |
|
1085 |
if dataOut.data_SNR |
|
|
1085 | if dataOut.data_SNR is not None: | |
|
1086 | 1086 | nplots += 1 |
|
1087 | 1087 | SNR = dataOut.data_SNR |
|
1088 | 1088 | |
|
1089 | 1089 | if SNR_1: |
|
1090 | 1090 | SNR += 1 |
|
1091 | 1091 | |
|
1092 | 1092 | SNRavg = numpy.average(SNR, axis=0) |
|
1093 | 1093 | |
|
1094 | 1094 | SNRdB = 10*numpy.log10(SNR) |
|
1095 | 1095 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1096 | 1096 | |
|
1097 | 1097 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1098 | 1098 | |
|
1099 | 1099 | for i in range(nplotsw): |
|
1100 | 1100 | z[i,ind] = numpy.nan |
|
1101 | 1101 | |
|
1102 | 1102 | |
|
1103 | 1103 | showprofile = False |
|
1104 | 1104 | # thisDatetime = dataOut.datatime |
|
1105 | 1105 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1106 | 1106 | title = wintitle + " EW Drifts" |
|
1107 | 1107 | xlabel = "" |
|
1108 | 1108 | ylabel = "Height (Km)" |
|
1109 | 1109 | |
|
1110 | 1110 | if not self.__isConfig: |
|
1111 | 1111 | |
|
1112 | 1112 | self.setup(id=id, |
|
1113 | 1113 | nplots=nplots, |
|
1114 | 1114 | wintitle=wintitle, |
|
1115 | 1115 | showprofile=showprofile, |
|
1116 | 1116 | show=show) |
|
1117 | 1117 | |
|
1118 | 1118 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1119 | 1119 | |
|
1120 | 1120 | if ymin == None: ymin = numpy.nanmin(y) |
|
1121 | 1121 | if ymax == None: ymax = numpy.nanmax(y) |
|
1122 | 1122 | |
|
1123 | 1123 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1124 | 1124 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1125 | 1125 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1126 | 1126 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1127 | 1127 | |
|
1128 |
if dataOut.data_SNR |
|
|
1128 | if dataOut.data_SNR is not None: | |
|
1129 | 1129 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1130 | 1130 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1131 | 1131 | |
|
1132 | 1132 | self.FTP_WEI = ftp_wei |
|
1133 | 1133 | self.EXP_CODE = exp_code |
|
1134 | 1134 | self.SUB_EXP_CODE = sub_exp_code |
|
1135 | 1135 | self.PLOT_POS = plot_pos |
|
1136 | 1136 | |
|
1137 | 1137 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1138 | 1138 | self.__isConfig = True |
|
1139 | 1139 | |
|
1140 | 1140 | |
|
1141 | 1141 | self.setWinTitle(title) |
|
1142 | 1142 | |
|
1143 | 1143 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1144 | 1144 | x[1] = self.xmax |
|
1145 | 1145 | |
|
1146 | 1146 | strWind = ['Zonal','Vertical'] |
|
1147 | 1147 | strCb = 'Velocity (m/s)' |
|
1148 | 1148 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1149 | 1149 | zminVector = [zminZonal, zminVertical] |
|
1150 | 1150 | |
|
1151 | 1151 | for i in range(nplotsw): |
|
1152 | 1152 | |
|
1153 | 1153 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1154 | 1154 | axes = self.axesList[i*self.__nsubplots] |
|
1155 | 1155 | |
|
1156 | 1156 | z1 = z[i,:].reshape((1,-1)) |
|
1157 | 1157 | |
|
1158 | 1158 | axes.pcolorbuffer(x, y, z1, |
|
1159 | 1159 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1160 | 1160 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1161 | 1161 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1162 | 1162 | |
|
1163 |
if dataOut.data_SNR |
|
|
1163 | if dataOut.data_SNR is not None: | |
|
1164 | 1164 | i += 1 |
|
1165 | 1165 | if SNR_1: |
|
1166 | 1166 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1167 | 1167 | else: |
|
1168 | 1168 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1169 | 1169 | axes = self.axesList[i*self.__nsubplots] |
|
1170 | 1170 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1171 | 1171 | |
|
1172 | 1172 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1173 | 1173 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1174 | 1174 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1175 | 1175 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1176 | 1176 | |
|
1177 | 1177 | self.draw() |
|
1178 | 1178 | |
|
1179 | 1179 | if x[1] >= self.axesList[0].xmax: |
|
1180 | 1180 | self.counter_imagwr = wr_period |
|
1181 | 1181 | self.__isConfig = False |
|
1182 | 1182 | self.figfile = None |
|
1183 | 1183 | |
|
1184 | 1184 | |
|
1185 | 1185 | |
|
1186 | 1186 | |
|
1187 | 1187 | class PhasePlot(Figure): |
|
1188 | 1188 | |
|
1189 | 1189 | __isConfig = None |
|
1190 | 1190 | __nsubplots = None |
|
1191 | 1191 | |
|
1192 | 1192 | PREFIX = 'mphase' |
|
1193 | 1193 | |
|
1194 | 1194 | def __init__(self): |
|
1195 | 1195 | |
|
1196 | 1196 | self.timerange = 24*60*60 |
|
1197 | 1197 | self.__isConfig = False |
|
1198 | 1198 | self.__nsubplots = 1 |
|
1199 | 1199 | self.counter_imagwr = 0 |
|
1200 | 1200 | self.WIDTH = 600 |
|
1201 | 1201 | self.HEIGHT = 300 |
|
1202 | 1202 | self.WIDTHPROF = 120 |
|
1203 | 1203 | self.HEIGHTPROF = 0 |
|
1204 | 1204 | self.xdata = None |
|
1205 | 1205 | self.ydata = None |
|
1206 | 1206 | |
|
1207 | 1207 | self.PLOT_CODE = MPHASE_CODE |
|
1208 | 1208 | |
|
1209 | 1209 | self.FTP_WEI = None |
|
1210 | 1210 | self.EXP_CODE = None |
|
1211 | 1211 | self.SUB_EXP_CODE = None |
|
1212 | 1212 | self.PLOT_POS = None |
|
1213 | 1213 | |
|
1214 | 1214 | |
|
1215 | 1215 | self.filename_phase = None |
|
1216 | 1216 | |
|
1217 | 1217 | self.figfile = None |
|
1218 | 1218 | |
|
1219 | 1219 | def getSubplots(self): |
|
1220 | 1220 | |
|
1221 | 1221 | ncol = 1 |
|
1222 | 1222 | nrow = 1 |
|
1223 | 1223 | |
|
1224 | 1224 | return nrow, ncol |
|
1225 | 1225 | |
|
1226 | 1226 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1227 | 1227 | |
|
1228 | 1228 | self.__showprofile = showprofile |
|
1229 | 1229 | self.nplots = nplots |
|
1230 | 1230 | |
|
1231 | 1231 | ncolspan = 7 |
|
1232 | 1232 | colspan = 6 |
|
1233 | 1233 | self.__nsubplots = 2 |
|
1234 | 1234 | |
|
1235 | 1235 | self.createFigure(id = id, |
|
1236 | 1236 | wintitle = wintitle, |
|
1237 | 1237 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1238 | 1238 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1239 | 1239 | show=show) |
|
1240 | 1240 | |
|
1241 | 1241 | nrow, ncol = self.getSubplots() |
|
1242 | 1242 | |
|
1243 | 1243 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1244 | 1244 | |
|
1245 | 1245 | |
|
1246 | 1246 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1247 | 1247 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1248 | 1248 | timerange=None, |
|
1249 | 1249 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1250 | 1250 | server=None, folder=None, username=None, password=None, |
|
1251 | 1251 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1252 | 1252 | |
|
1253 | 1253 | |
|
1254 | 1254 | tmin = None |
|
1255 | 1255 | tmax = None |
|
1256 | 1256 | x = dataOut.getTimeRange1() |
|
1257 | 1257 | y = dataOut.getHeiRange() |
|
1258 | 1258 | |
|
1259 | 1259 | |
|
1260 | 1260 | #thisDatetime = dataOut.datatime |
|
1261 | 1261 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1262 | 1262 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1263 | 1263 | xlabel = "Local Time" |
|
1264 | 1264 | ylabel = "Phase" |
|
1265 | 1265 | |
|
1266 | 1266 | |
|
1267 | 1267 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1268 | 1268 | phase_beacon = dataOut.data_output |
|
1269 | 1269 | |
|
1270 | 1270 | |
|
1271 | 1271 | if not self.__isConfig: |
|
1272 | 1272 | |
|
1273 | 1273 | self.nplots = phase_beacon.size |
|
1274 | 1274 | |
|
1275 | 1275 | self.setup(id=id, |
|
1276 | 1276 | nplots=self.nplots, |
|
1277 | 1277 | wintitle=wintitle, |
|
1278 | 1278 | showprofile=showprofile, |
|
1279 | 1279 | show=show) |
|
1280 | 1280 | |
|
1281 |
if timerange |
|
|
1281 | if timerange is not None: | |
|
1282 | 1282 | self.timerange = timerange |
|
1283 | 1283 | |
|
1284 | 1284 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1285 | 1285 | |
|
1286 | 1286 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1287 | 1287 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1288 | 1288 | |
|
1289 | 1289 | self.FTP_WEI = ftp_wei |
|
1290 | 1290 | self.EXP_CODE = exp_code |
|
1291 | 1291 | self.SUB_EXP_CODE = sub_exp_code |
|
1292 | 1292 | self.PLOT_POS = plot_pos |
|
1293 | 1293 | |
|
1294 | 1294 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1295 | 1295 | self.__isConfig = True |
|
1296 | 1296 | self.figfile = figfile |
|
1297 | 1297 | self.xdata = numpy.array([]) |
|
1298 | 1298 | self.ydata = numpy.array([]) |
|
1299 | 1299 | |
|
1300 | 1300 | #open file beacon phase |
|
1301 | 1301 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1302 | 1302 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1303 | 1303 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1304 | 1304 | #self.save_phase(self.filename_phase) |
|
1305 | 1305 | |
|
1306 | 1306 | |
|
1307 | 1307 | #store data beacon phase |
|
1308 | 1308 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1309 | 1309 | |
|
1310 | 1310 | self.setWinTitle(title) |
|
1311 | 1311 | |
|
1312 | 1312 | |
|
1313 | 1313 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1314 | 1314 | |
|
1315 | 1315 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1316 | 1316 | |
|
1317 | 1317 | axes = self.axesList[0] |
|
1318 | 1318 | |
|
1319 | 1319 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1320 | 1320 | |
|
1321 | 1321 | if len(self.ydata)==0: |
|
1322 | 1322 | self.ydata = phase_beacon.reshape(-1,1) |
|
1323 | 1323 | else: |
|
1324 | 1324 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1325 | 1325 | |
|
1326 | 1326 | |
|
1327 | 1327 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1328 | 1328 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1329 | 1329 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1330 | 1330 | XAxisAsTime=True, grid='both' |
|
1331 | 1331 | ) |
|
1332 | 1332 | |
|
1333 | 1333 | self.draw() |
|
1334 | 1334 | |
|
1335 | 1335 | if x[1] >= self.axesList[0].xmax: |
|
1336 | 1336 | self.counter_imagwr = wr_period |
|
1337 | 1337 | del self.xdata |
|
1338 | 1338 | del self.ydata |
|
1339 | 1339 | self.__isConfig = False |
|
1340 | 1340 | |
|
1341 | 1341 | if self.figfile == None: |
|
1342 | 1342 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1343 | 1343 | self.figfile = self.getFilename(name = str_datetime) |
|
1344 | 1344 | |
|
1345 | 1345 | if figpath != '': |
|
1346 | 1346 | self.counter_imagwr += 1 |
|
1347 | 1347 | if (self.counter_imagwr>=wr_period): |
|
1348 | 1348 | # store png plot to local folder |
|
1349 | 1349 | self.saveFigure(figpath, self.figfile) |
|
1350 | 1350 | # store png plot to FTP server according to RT-Web format |
|
1351 | 1351 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1352 | 1352 | ftp_filename = os.path.join(figpath, name) |
|
1353 | 1353 | self.saveFigure(figpath, ftp_filename) |
|
1354 | 1354 | self.counter_imagwr = 0 |
|
1355 | 1355 | self.figfile = None |
|
1356 | 1356 | |
|
1357 | 1357 | self.save(figpath=figpath, |
|
1358 | 1358 | figfile=figfile, |
|
1359 | 1359 | save=save, |
|
1360 | 1360 | ftp=ftp, |
|
1361 | 1361 | wr_period=wr_period, |
|
1362 | 1362 | thisDatetime=thisDatetime, |
|
1363 | 1363 | update_figfile=False) |
@@ -1,764 +1,764 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 2, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import numpy |
|
7 | 7 | |
|
8 | 8 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
9 | 9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | 10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
11 | 11 | from schainpy.model.data.jrodata import Spectra |
|
12 | 12 | |
|
13 | 13 | class SpectraReader(JRODataReader, ProcessingUnit): |
|
14 | 14 | """ |
|
15 | 15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
16 | 16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
17 | 17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
18 | 18 | |
|
19 | 19 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
20 | 20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
21 | 21 | canales * alturas (DC Channels) |
|
22 | 22 | |
|
23 | 23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
24 | 24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
25 | 25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
26 | 26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
27 | 27 | |
|
28 | 28 | Example: |
|
29 | 29 | dpath = "/home/myuser/data" |
|
30 | 30 | |
|
31 | 31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
32 | 32 | |
|
33 | 33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
34 | 34 | |
|
35 | 35 | readerObj = SpectraReader() |
|
36 | 36 | |
|
37 | 37 | readerObj.setup(dpath, startTime, endTime) |
|
38 | 38 | |
|
39 | 39 | while(True): |
|
40 | 40 | |
|
41 | 41 | readerObj.getData() |
|
42 | 42 | |
|
43 | 43 | print readerObj.data_spc |
|
44 | 44 | |
|
45 | 45 | print readerObj.data_cspc |
|
46 | 46 | |
|
47 | 47 | print readerObj.data_dc |
|
48 | 48 | |
|
49 | 49 | if readerObj.flagNoMoreFiles: |
|
50 | 50 | break |
|
51 | 51 | |
|
52 | 52 | """ |
|
53 | 53 | |
|
54 | 54 | pts2read_SelfSpectra = 0 |
|
55 | 55 | |
|
56 | 56 | pts2read_CrossSpectra = 0 |
|
57 | 57 | |
|
58 | 58 | pts2read_DCchannels = 0 |
|
59 | 59 | |
|
60 | 60 | ext = ".pdata" |
|
61 | 61 | |
|
62 | 62 | optchar = "P" |
|
63 | 63 | |
|
64 | 64 | dataOut = None |
|
65 | 65 | |
|
66 | 66 | nRdChannels = None |
|
67 | 67 | |
|
68 | 68 | nRdPairs = None |
|
69 | 69 | |
|
70 | 70 | rdPairList = [] |
|
71 | 71 | |
|
72 | 72 | def __init__(self): |
|
73 | 73 | """ |
|
74 | 74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
75 | 75 | |
|
76 | 76 | Inputs: |
|
77 | 77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
78 | 78 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
79 | 79 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
80 | 80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
81 | 81 | bloque de datos. |
|
82 | 82 | Si este parametro no es pasado se creara uno internamente. |
|
83 | 83 | |
|
84 | 84 | Affected: |
|
85 | 85 | self.dataOut |
|
86 | 86 | |
|
87 | 87 | Return : None |
|
88 | 88 | """ |
|
89 | 89 | |
|
90 | 90 | #Eliminar de la base la herencia |
|
91 | 91 | ProcessingUnit.__init__(self) |
|
92 | 92 | |
|
93 | 93 | # self.isConfig = False |
|
94 | 94 | |
|
95 | 95 | self.pts2read_SelfSpectra = 0 |
|
96 | 96 | |
|
97 | 97 | self.pts2read_CrossSpectra = 0 |
|
98 | 98 | |
|
99 | 99 | self.pts2read_DCchannels = 0 |
|
100 | 100 | |
|
101 | 101 | self.datablock = None |
|
102 | 102 | |
|
103 | 103 | self.utc = None |
|
104 | 104 | |
|
105 | 105 | self.ext = ".pdata" |
|
106 | 106 | |
|
107 | 107 | self.optchar = "P" |
|
108 | 108 | |
|
109 | 109 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
110 | 110 | |
|
111 | 111 | self.systemHeaderObj = SystemHeader() |
|
112 | 112 | |
|
113 | 113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
114 | 114 | |
|
115 | 115 | self.processingHeaderObj = ProcessingHeader() |
|
116 | 116 | |
|
117 | 117 | self.online = 0 |
|
118 | 118 | |
|
119 | 119 | self.fp = None |
|
120 | 120 | |
|
121 | 121 | self.idFile = None |
|
122 | 122 | |
|
123 | 123 | self.dtype = None |
|
124 | 124 | |
|
125 | 125 | self.fileSizeByHeader = None |
|
126 | 126 | |
|
127 | 127 | self.filenameList = [] |
|
128 | 128 | |
|
129 | 129 | self.filename = None |
|
130 | 130 | |
|
131 | 131 | self.fileSize = None |
|
132 | 132 | |
|
133 | 133 | self.firstHeaderSize = 0 |
|
134 | 134 | |
|
135 | 135 | self.basicHeaderSize = 24 |
|
136 | 136 | |
|
137 | 137 | self.pathList = [] |
|
138 | 138 | |
|
139 | 139 | self.lastUTTime = 0 |
|
140 | 140 | |
|
141 | 141 | self.maxTimeStep = 30 |
|
142 | 142 | |
|
143 | 143 | self.flagNoMoreFiles = 0 |
|
144 | 144 | |
|
145 | 145 | self.set = 0 |
|
146 | 146 | |
|
147 | 147 | self.path = None |
|
148 | 148 | |
|
149 | 149 | self.delay = 60 #seconds |
|
150 | 150 | |
|
151 | 151 | self.nTries = 3 #quantity tries |
|
152 | 152 | |
|
153 | 153 | self.nFiles = 3 #number of files for searching |
|
154 | 154 | |
|
155 | 155 | self.nReadBlocks = 0 |
|
156 | 156 | |
|
157 | 157 | self.flagIsNewFile = 1 |
|
158 | 158 | |
|
159 | 159 | self.__isFirstTimeOnline = 1 |
|
160 | 160 | |
|
161 | 161 | # self.ippSeconds = 0 |
|
162 | 162 | |
|
163 | 163 | self.flagDiscontinuousBlock = 0 |
|
164 | 164 | |
|
165 | 165 | self.flagIsNewBlock = 0 |
|
166 | 166 | |
|
167 | 167 | self.nTotalBlocks = 0 |
|
168 | 168 | |
|
169 | 169 | self.blocksize = 0 |
|
170 | 170 | |
|
171 | 171 | self.dataOut = self.createObjByDefault() |
|
172 | 172 | |
|
173 | 173 | self.profileIndex = 1 #Always |
|
174 | 174 | |
|
175 | 175 | |
|
176 | 176 | def createObjByDefault(self): |
|
177 | 177 | |
|
178 | 178 | dataObj = Spectra() |
|
179 | 179 | |
|
180 | 180 | return dataObj |
|
181 | 181 | |
|
182 | 182 | def __hasNotDataInBuffer(self): |
|
183 | 183 | return 1 |
|
184 | 184 | |
|
185 | 185 | |
|
186 | 186 | def getBlockDimension(self): |
|
187 | 187 | """ |
|
188 | 188 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
189 | 189 | |
|
190 | 190 | Affected: |
|
191 | 191 | self.nRdChannels |
|
192 | 192 | self.nRdPairs |
|
193 | 193 | self.pts2read_SelfSpectra |
|
194 | 194 | self.pts2read_CrossSpectra |
|
195 | 195 | self.pts2read_DCchannels |
|
196 | 196 | self.blocksize |
|
197 | 197 | self.dataOut.nChannels |
|
198 | 198 | self.dataOut.nPairs |
|
199 | 199 | |
|
200 | 200 | Return: |
|
201 | 201 | None |
|
202 | 202 | """ |
|
203 | 203 | self.nRdChannels = 0 |
|
204 | 204 | self.nRdPairs = 0 |
|
205 | 205 | self.rdPairList = [] |
|
206 | 206 | |
|
207 | 207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
208 | 208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
209 | 209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
210 | 210 | else: |
|
211 | 211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
212 | 212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
213 | 213 | |
|
214 | 214 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
215 | 215 | |
|
216 | 216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
217 | 217 | self.blocksize = self.pts2read_SelfSpectra |
|
218 | 218 | |
|
219 | 219 | if self.processingHeaderObj.flag_cspc: |
|
220 | 220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
221 | 221 | self.blocksize += self.pts2read_CrossSpectra |
|
222 | 222 | |
|
223 | 223 | if self.processingHeaderObj.flag_dc: |
|
224 | 224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
225 | 225 | self.blocksize += self.pts2read_DCchannels |
|
226 | 226 | |
|
227 | 227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
228 | 228 | |
|
229 | 229 | |
|
230 | 230 | def readBlock(self): |
|
231 | 231 | """ |
|
232 | 232 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
233 | 233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
234 | 234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
235 | 235 | es seteado a 0 |
|
236 | 236 | |
|
237 | 237 | Return: None |
|
238 | 238 | |
|
239 | 239 | Variables afectadas: |
|
240 | 240 | |
|
241 | 241 | self.flagIsNewFile |
|
242 | 242 | self.flagIsNewBlock |
|
243 | 243 | self.nTotalBlocks |
|
244 | 244 | self.data_spc |
|
245 | 245 | self.data_cspc |
|
246 | 246 | self.data_dc |
|
247 | 247 | |
|
248 | 248 | Exceptions: |
|
249 | 249 | Si un bloque leido no es un bloque valido |
|
250 | 250 | """ |
|
251 | 251 | blockOk_flag = False |
|
252 | 252 | fpointer = self.fp.tell() |
|
253 | 253 | |
|
254 | 254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
255 | 255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
256 | 256 | |
|
257 | 257 | if self.processingHeaderObj.flag_cspc: |
|
258 | 258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
259 | 259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
260 | 260 | |
|
261 | 261 | if self.processingHeaderObj.flag_dc: |
|
262 | 262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
263 | 263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
264 | 264 | |
|
265 | 265 | |
|
266 | 266 | if not(self.processingHeaderObj.shif_fft): |
|
267 | 267 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
268 | 268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
269 | 269 | spc = numpy.roll( spc, shift , axis=2 ) |
|
270 | 270 | |
|
271 | 271 | if self.processingHeaderObj.flag_cspc: |
|
272 | 272 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
273 | 273 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
274 | 274 | |
|
275 | 275 | # self.processingHeaderObj.shif_fft = True |
|
276 | 276 | |
|
277 | 277 | spc = numpy.transpose( spc, (0,2,1) ) |
|
278 | 278 | self.data_spc = spc |
|
279 | 279 | |
|
280 | 280 | if self.processingHeaderObj.flag_cspc: |
|
281 | 281 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
282 | 282 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
283 | 283 | else: |
|
284 | 284 | self.data_cspc = None |
|
285 | 285 | |
|
286 | 286 | if self.processingHeaderObj.flag_dc: |
|
287 | 287 | self.data_dc = dc['real'] + dc['imag']*1j |
|
288 | 288 | else: |
|
289 | 289 | self.data_dc = None |
|
290 | 290 | |
|
291 | 291 | self.flagIsNewFile = 0 |
|
292 | 292 | self.flagIsNewBlock = 1 |
|
293 | 293 | |
|
294 | 294 | self.nTotalBlocks += 1 |
|
295 | 295 | self.nReadBlocks += 1 |
|
296 | 296 | |
|
297 | 297 | return 1 |
|
298 | 298 | |
|
299 | 299 | def getFirstHeader(self): |
|
300 | 300 | |
|
301 | 301 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
302 | 302 | |
|
303 | 303 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
304 | 304 | |
|
305 | 305 | # self.dataOut.ippSeconds = self.ippSeconds |
|
306 | 306 | |
|
307 | 307 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock |
|
308 | 308 | |
|
309 | 309 | self.dataOut.dtype = self.dtype |
|
310 | 310 | |
|
311 | 311 | # self.dataOut.nPairs = self.nPairs |
|
312 | 312 | |
|
313 | 313 | self.dataOut.pairsList = self.rdPairList |
|
314 | 314 | |
|
315 | 315 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
316 | 316 | |
|
317 | 317 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
318 | 318 | |
|
319 | 319 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
320 | 320 | |
|
321 | 321 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
322 | 322 | |
|
323 | 323 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
324 | 324 | |
|
325 | 325 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
326 | 326 | |
|
327 | 327 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
328 | 328 | |
|
329 | 329 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
330 | 330 | |
|
331 | 331 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
332 | 332 | |
|
333 | 333 | self.dataOut.flagDeflipData = False #asumo q la data esta sin flip |
|
334 | 334 | |
|
335 |
if self.radarControllerHeaderObj.code |
|
|
335 | if self.radarControllerHeaderObj.code is not None: | |
|
336 | 336 | |
|
337 | 337 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
338 | 338 | # |
|
339 | 339 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
340 | 340 | # |
|
341 | 341 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
342 | 342 | |
|
343 | 343 | self.dataOut.flagDecodeData = True |
|
344 | 344 | |
|
345 | 345 | def getData(self): |
|
346 | 346 | """ |
|
347 | 347 | First method to execute before "RUN" is called. |
|
348 | 348 | |
|
349 | 349 | Copia el buffer de lectura a la clase "Spectra", |
|
350 | 350 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
351 | 351 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
352 | 352 | |
|
353 | 353 | Return: |
|
354 | 354 | 0 : Si no hay mas archivos disponibles |
|
355 | 355 | 1 : Si hizo una buena copia del buffer |
|
356 | 356 | |
|
357 | 357 | Affected: |
|
358 | 358 | self.dataOut |
|
359 | 359 | |
|
360 | 360 | self.flagDiscontinuousBlock |
|
361 | 361 | self.flagIsNewBlock |
|
362 | 362 | """ |
|
363 | 363 | |
|
364 | 364 | if self.flagNoMoreFiles: |
|
365 | 365 | self.dataOut.flagNoData = True |
|
366 | 366 | print 'Process finished' |
|
367 | 367 | return 0 |
|
368 | 368 | |
|
369 | 369 | self.flagDiscontinuousBlock = 0 |
|
370 | 370 | self.flagIsNewBlock = 0 |
|
371 | 371 | |
|
372 | 372 | if self.__hasNotDataInBuffer(): |
|
373 | 373 | |
|
374 | 374 | if not( self.readNextBlock() ): |
|
375 | 375 | self.dataOut.flagNoData = True |
|
376 | 376 | return 0 |
|
377 | 377 | |
|
378 | 378 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
379 | 379 | |
|
380 |
if self.data_dc |
|
|
380 | if self.data_dc is None: | |
|
381 | 381 | self.dataOut.flagNoData = True |
|
382 | 382 | return 0 |
|
383 | 383 | |
|
384 | 384 | self.getBasicHeader() |
|
385 | 385 | |
|
386 | 386 | self.getFirstHeader() |
|
387 | 387 | |
|
388 | 388 | self.dataOut.data_spc = self.data_spc |
|
389 | 389 | |
|
390 | 390 | self.dataOut.data_cspc = self.data_cspc |
|
391 | 391 | |
|
392 | 392 | self.dataOut.data_dc = self.data_dc |
|
393 | 393 | |
|
394 | 394 | self.dataOut.flagNoData = False |
|
395 | 395 | |
|
396 | 396 | self.dataOut.realtime = self.online |
|
397 | 397 | |
|
398 | 398 | return self.dataOut.data_spc |
|
399 | 399 | |
|
400 | 400 | class SpectraWriter(JRODataWriter, Operation): |
|
401 | 401 | |
|
402 | 402 | """ |
|
403 | 403 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
404 | 404 | de los datos siempre se realiza por bloques. |
|
405 | 405 | """ |
|
406 | 406 | |
|
407 | 407 | ext = ".pdata" |
|
408 | 408 | |
|
409 | 409 | optchar = "P" |
|
410 | 410 | |
|
411 | 411 | shape_spc_Buffer = None |
|
412 | 412 | |
|
413 | 413 | shape_cspc_Buffer = None |
|
414 | 414 | |
|
415 | 415 | shape_dc_Buffer = None |
|
416 | 416 | |
|
417 | 417 | data_spc = None |
|
418 | 418 | |
|
419 | 419 | data_cspc = None |
|
420 | 420 | |
|
421 | 421 | data_dc = None |
|
422 | 422 | |
|
423 | 423 | # dataOut = None |
|
424 | 424 | |
|
425 | 425 | def __init__(self): |
|
426 | 426 | """ |
|
427 | 427 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
428 | 428 | |
|
429 | 429 | Affected: |
|
430 | 430 | self.dataOut |
|
431 | 431 | self.basicHeaderObj |
|
432 | 432 | self.systemHeaderObj |
|
433 | 433 | self.radarControllerHeaderObj |
|
434 | 434 | self.processingHeaderObj |
|
435 | 435 | |
|
436 | 436 | Return: None |
|
437 | 437 | """ |
|
438 | 438 | |
|
439 | 439 | Operation.__init__(self) |
|
440 | 440 | |
|
441 | 441 | self.isConfig = False |
|
442 | 442 | |
|
443 | 443 | self.nTotalBlocks = 0 |
|
444 | 444 | |
|
445 | 445 | self.data_spc = None |
|
446 | 446 | |
|
447 | 447 | self.data_cspc = None |
|
448 | 448 | |
|
449 | 449 | self.data_dc = None |
|
450 | 450 | |
|
451 | 451 | self.fp = None |
|
452 | 452 | |
|
453 | 453 | self.flagIsNewFile = 1 |
|
454 | 454 | |
|
455 | 455 | self.nTotalBlocks = 0 |
|
456 | 456 | |
|
457 | 457 | self.flagIsNewBlock = 0 |
|
458 | 458 | |
|
459 | 459 | self.setFile = None |
|
460 | 460 | |
|
461 | 461 | self.dtype = None |
|
462 | 462 | |
|
463 | 463 | self.path = None |
|
464 | 464 | |
|
465 | 465 | self.noMoreFiles = 0 |
|
466 | 466 | |
|
467 | 467 | self.filename = None |
|
468 | 468 | |
|
469 | 469 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
470 | 470 | |
|
471 | 471 | self.systemHeaderObj = SystemHeader() |
|
472 | 472 | |
|
473 | 473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
474 | 474 | |
|
475 | 475 | self.processingHeaderObj = ProcessingHeader() |
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | def hasAllDataInBuffer(self): |
|
479 | 479 | return 1 |
|
480 | 480 | |
|
481 | 481 | |
|
482 | 482 | def setBlockDimension(self): |
|
483 | 483 | """ |
|
484 | 484 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
485 | 485 | |
|
486 | 486 | Affected: |
|
487 | 487 | self.shape_spc_Buffer |
|
488 | 488 | self.shape_cspc_Buffer |
|
489 | 489 | self.shape_dc_Buffer |
|
490 | 490 | |
|
491 | 491 | Return: None |
|
492 | 492 | """ |
|
493 | 493 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
494 | 494 | self.processingHeaderObj.nHeights, |
|
495 | 495 | self.processingHeaderObj.profilesPerBlock) |
|
496 | 496 | |
|
497 | 497 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
498 | 498 | self.processingHeaderObj.nHeights, |
|
499 | 499 | self.processingHeaderObj.profilesPerBlock) |
|
500 | 500 | |
|
501 | 501 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
502 | 502 | self.processingHeaderObj.nHeights) |
|
503 | 503 | |
|
504 | 504 | |
|
505 | 505 | def writeBlock(self): |
|
506 | 506 | """ |
|
507 | 507 | Escribe el buffer en el file designado |
|
508 | 508 | |
|
509 | 509 | Affected: |
|
510 | 510 | self.data_spc |
|
511 | 511 | self.data_cspc |
|
512 | 512 | self.data_dc |
|
513 | 513 | self.flagIsNewFile |
|
514 | 514 | self.flagIsNewBlock |
|
515 | 515 | self.nTotalBlocks |
|
516 | 516 | self.nWriteBlocks |
|
517 | 517 | |
|
518 | 518 | Return: None |
|
519 | 519 | """ |
|
520 | 520 | |
|
521 | 521 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
522 | 522 | if not( self.processingHeaderObj.shif_fft ): |
|
523 | 523 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
524 | 524 | data = spc.reshape((-1)) |
|
525 | 525 | data = data.astype(self.dtype[0]) |
|
526 | 526 | data.tofile(self.fp) |
|
527 | 527 | |
|
528 |
if self.data_cspc |
|
|
528 | if self.data_cspc is not None: | |
|
529 | 529 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
530 | 530 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
531 | 531 | if not( self.processingHeaderObj.shif_fft ): |
|
532 | 532 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
533 | 533 | data['real'] = cspc.real |
|
534 | 534 | data['imag'] = cspc.imag |
|
535 | 535 | data = data.reshape((-1)) |
|
536 | 536 | data.tofile(self.fp) |
|
537 | 537 | |
|
538 |
if self.data_dc |
|
|
538 | if self.data_dc is not None: | |
|
539 | 539 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
540 | 540 | dc = self.data_dc |
|
541 | 541 | data['real'] = dc.real |
|
542 | 542 | data['imag'] = dc.imag |
|
543 | 543 | data = data.reshape((-1)) |
|
544 | 544 | data.tofile(self.fp) |
|
545 | 545 | |
|
546 | 546 | self.data_spc.fill(0) |
|
547 | 547 | |
|
548 |
if self.data_dc |
|
|
548 | if self.data_dc is not None: | |
|
549 | 549 | self.data_dc.fill(0) |
|
550 | 550 | |
|
551 |
if self.data_cspc |
|
|
551 | if self.data_cspc is not None: | |
|
552 | 552 | self.data_cspc.fill(0) |
|
553 | 553 | |
|
554 | 554 | self.flagIsNewFile = 0 |
|
555 | 555 | self.flagIsNewBlock = 1 |
|
556 | 556 | self.nTotalBlocks += 1 |
|
557 | 557 | self.nWriteBlocks += 1 |
|
558 | 558 | self.blockIndex += 1 |
|
559 | 559 | |
|
560 | 560 | # print "[Writing] Block = %d04" %self.blockIndex |
|
561 | 561 | |
|
562 | 562 | def putData(self): |
|
563 | 563 | """ |
|
564 | 564 | Setea un bloque de datos y luego los escribe en un file |
|
565 | 565 | |
|
566 | 566 | Affected: |
|
567 | 567 | self.data_spc |
|
568 | 568 | self.data_cspc |
|
569 | 569 | self.data_dc |
|
570 | 570 | |
|
571 | 571 | Return: |
|
572 | 572 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
573 | 573 | 1 : Si se escribio la data de un bloque en un file |
|
574 | 574 | """ |
|
575 | 575 | |
|
576 | 576 | if self.dataOut.flagNoData: |
|
577 | 577 | return 0 |
|
578 | 578 | |
|
579 | 579 | self.flagIsNewBlock = 0 |
|
580 | 580 | |
|
581 | 581 | if self.dataOut.flagDiscontinuousBlock: |
|
582 | 582 | self.data_spc.fill(0) |
|
583 | 583 | self.data_cspc.fill(0) |
|
584 | 584 | self.data_dc.fill(0) |
|
585 | 585 | self.setNextFile() |
|
586 | 586 | |
|
587 | 587 | if self.flagIsNewFile == 0: |
|
588 | 588 | self.setBasicHeader() |
|
589 | 589 | |
|
590 | 590 | self.data_spc = self.dataOut.data_spc.copy() |
|
591 |
if self.dataOut.data_cspc |
|
|
591 | if self.dataOut.data_cspc is not None: | |
|
592 | 592 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
593 | 593 | self.data_dc = self.dataOut.data_dc.copy() |
|
594 | 594 | |
|
595 | 595 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
596 | 596 | if self.hasAllDataInBuffer(): |
|
597 | 597 | # self.setFirstHeader() |
|
598 | 598 | self.writeNextBlock() |
|
599 | 599 | |
|
600 | 600 | return 1 |
|
601 | 601 | |
|
602 | 602 | |
|
603 | 603 | def __getProcessFlags(self): |
|
604 | 604 | |
|
605 | 605 | processFlags = 0 |
|
606 | 606 | |
|
607 | 607 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
608 | 608 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
609 | 609 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
610 | 610 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
611 | 611 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
612 | 612 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
613 | 613 | |
|
614 | 614 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
615 | 615 | |
|
616 | 616 | |
|
617 | 617 | |
|
618 | 618 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
619 | 619 | PROCFLAG.DATATYPE_SHORT, |
|
620 | 620 | PROCFLAG.DATATYPE_LONG, |
|
621 | 621 | PROCFLAG.DATATYPE_INT64, |
|
622 | 622 | PROCFLAG.DATATYPE_FLOAT, |
|
623 | 623 | PROCFLAG.DATATYPE_DOUBLE] |
|
624 | 624 | |
|
625 | 625 | |
|
626 | 626 | for index in range(len(dtypeList)): |
|
627 | 627 | if self.dataOut.dtype == dtypeList[index]: |
|
628 | 628 | dtypeValue = datatypeValueList[index] |
|
629 | 629 | break |
|
630 | 630 | |
|
631 | 631 | processFlags += dtypeValue |
|
632 | 632 | |
|
633 | 633 | if self.dataOut.flagDecodeData: |
|
634 | 634 | processFlags += PROCFLAG.DECODE_DATA |
|
635 | 635 | |
|
636 | 636 | if self.dataOut.flagDeflipData: |
|
637 | 637 | processFlags += PROCFLAG.DEFLIP_DATA |
|
638 | 638 | |
|
639 |
if self.dataOut.code |
|
|
639 | if self.dataOut.code is not None: | |
|
640 | 640 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
641 | 641 | |
|
642 | 642 | if self.dataOut.nIncohInt > 1: |
|
643 | 643 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
644 | 644 | |
|
645 |
if self.dataOut.data_dc |
|
|
645 | if self.dataOut.data_dc is not None: | |
|
646 | 646 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
647 | 647 | |
|
648 | 648 | return processFlags |
|
649 | 649 | |
|
650 | 650 | |
|
651 | 651 | def __getBlockSize(self): |
|
652 | 652 | ''' |
|
653 | 653 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
654 | 654 | ''' |
|
655 | 655 | |
|
656 | 656 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
657 | 657 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
658 | 658 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
659 | 659 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
660 | 660 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
661 | 661 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
662 | 662 | |
|
663 | 663 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
664 | 664 | datatypeValueList = [1,2,4,8,4,8] |
|
665 | 665 | for index in range(len(dtypeList)): |
|
666 | 666 | if self.dataOut.dtype == dtypeList[index]: |
|
667 | 667 | datatypeValue = datatypeValueList[index] |
|
668 | 668 | break |
|
669 | 669 | |
|
670 | 670 | |
|
671 | 671 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
672 | 672 | |
|
673 | 673 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
674 | 674 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
675 | 675 | |
|
676 |
if self.dataOut.data_cspc |
|
|
676 | if self.dataOut.data_cspc is not None: | |
|
677 | 677 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
678 | 678 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
679 | 679 | |
|
680 |
if self.dataOut.data_dc |
|
|
680 | if self.dataOut.data_dc is not None: | |
|
681 | 681 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
682 | 682 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
683 | 683 | |
|
684 | 684 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
685 | 685 | |
|
686 | 686 | return blocksize |
|
687 | 687 | |
|
688 | 688 | def setFirstHeader(self): |
|
689 | 689 | |
|
690 | 690 | """ |
|
691 | 691 | Obtiene una copia del First Header |
|
692 | 692 | |
|
693 | 693 | Affected: |
|
694 | 694 | self.systemHeaderObj |
|
695 | 695 | self.radarControllerHeaderObj |
|
696 | 696 | self.dtype |
|
697 | 697 | |
|
698 | 698 | Return: |
|
699 | 699 | None |
|
700 | 700 | """ |
|
701 | 701 | |
|
702 | 702 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
703 | 703 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
704 | 704 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
705 | 705 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size |
|
706 | 706 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 |
|
707 | 707 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size |
|
708 | 708 | |
|
709 | 709 | self.setBasicHeader() |
|
710 | 710 | |
|
711 | 711 | processingHeaderSize = 40 # bytes |
|
712 | 712 | self.processingHeaderObj.dtype = 1 # Spectra |
|
713 | 713 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
714 | 714 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
715 | 715 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
716 | 716 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
717 | 717 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
718 | 718 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
719 | 719 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
720 | 720 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
721 | 721 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
722 | 722 | |
|
723 | 723 | if self.processingHeaderObj.totalSpectra > 0: |
|
724 | 724 | channelList = [] |
|
725 | 725 | for channel in range(self.dataOut.nChannels): |
|
726 | 726 | channelList.append(channel) |
|
727 | 727 | channelList.append(channel) |
|
728 | 728 | |
|
729 | 729 | pairsList = [] |
|
730 | 730 | if self.dataOut.nPairs > 0: |
|
731 | 731 | for pair in self.dataOut.pairsList: |
|
732 | 732 | pairsList.append(pair[0]) |
|
733 | 733 | pairsList.append(pair[1]) |
|
734 | 734 | |
|
735 | 735 | spectraComb = channelList + pairsList |
|
736 | 736 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
737 | 737 | self.processingHeaderObj.spectraComb = spectraComb |
|
738 | 738 | sizeOfSpcComb = len(spectraComb) |
|
739 | 739 | processingHeaderSize += sizeOfSpcComb |
|
740 | 740 | |
|
741 | 741 | # The processing header should not have information about code |
|
742 |
# if self.dataOut.code |
|
|
742 | # if self.dataOut.code is not None: | |
|
743 | 743 | # self.processingHeaderObj.code = self.dataOut.code |
|
744 | 744 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
745 | 745 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
746 | 746 | # nCodeSize = 4 # bytes |
|
747 | 747 | # nBaudSize = 4 # bytes |
|
748 | 748 | # codeSize = 4 # bytes |
|
749 | 749 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
750 | 750 | # processingHeaderSize += sizeOfCode |
|
751 | 751 | |
|
752 | 752 | if self.processingHeaderObj.nWindows != 0: |
|
753 | 753 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
754 | 754 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
755 | 755 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
756 | 756 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
757 | 757 | sizeOfFirstHeight = 4 |
|
758 | 758 | sizeOfdeltaHeight = 4 |
|
759 | 759 | sizeOfnHeights = 4 |
|
760 | 760 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
761 | 761 | processingHeaderSize += sizeOfWindows |
|
762 | 762 | |
|
763 | 763 | self.processingHeaderObj.size = processingHeaderSize |
|
764 | 764 |
@@ -1,652 +1,652 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 2, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import numpy |
|
8 | 8 | |
|
9 | 9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
10 | 10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
11 | 11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
12 | 12 | from schainpy.model.data.jrodata import Voltage |
|
13 | 13 | |
|
14 | 14 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
15 | 15 | """ |
|
16 | 16 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
17 | 17 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
18 | 18 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
19 | 19 | |
|
20 | 20 | perfiles * alturas * canales |
|
21 | 21 | |
|
22 | 22 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
23 | 23 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
24 | 24 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
25 | 25 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
26 | 26 | |
|
27 | 27 | Example: |
|
28 | 28 | |
|
29 | 29 | dpath = "/home/myuser/data" |
|
30 | 30 | |
|
31 | 31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
32 | 32 | |
|
33 | 33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
34 | 34 | |
|
35 | 35 | readerObj = VoltageReader() |
|
36 | 36 | |
|
37 | 37 | readerObj.setup(dpath, startTime, endTime) |
|
38 | 38 | |
|
39 | 39 | while(True): |
|
40 | 40 | |
|
41 | 41 | #to get one profile |
|
42 | 42 | profile = readerObj.getData() |
|
43 | 43 | |
|
44 | 44 | #print the profile |
|
45 | 45 | print profile |
|
46 | 46 | |
|
47 | 47 | #If you want to see all datablock |
|
48 | 48 | print readerObj.datablock |
|
49 | 49 | |
|
50 | 50 | if readerObj.flagNoMoreFiles: |
|
51 | 51 | break |
|
52 | 52 | |
|
53 | 53 | """ |
|
54 | 54 | |
|
55 | 55 | ext = ".r" |
|
56 | 56 | |
|
57 | 57 | optchar = "D" |
|
58 | 58 | dataOut = None |
|
59 | 59 | |
|
60 | 60 | |
|
61 | 61 | def __init__(self): |
|
62 | 62 | """ |
|
63 | 63 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
64 | 64 | |
|
65 | 65 | Input: |
|
66 | 66 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
67 | 67 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
68 | 68 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
69 | 69 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
70 | 70 | bloque de datos. |
|
71 | 71 | Si este parametro no es pasado se creara uno internamente. |
|
72 | 72 | |
|
73 | 73 | Variables afectadas: |
|
74 | 74 | self.dataOut |
|
75 | 75 | |
|
76 | 76 | Return: |
|
77 | 77 | None |
|
78 | 78 | """ |
|
79 | 79 | |
|
80 | 80 | ProcessingUnit.__init__(self) |
|
81 | 81 | |
|
82 | 82 | self.isConfig = False |
|
83 | 83 | |
|
84 | 84 | self.datablock = None |
|
85 | 85 | |
|
86 | 86 | self.utc = 0 |
|
87 | 87 | |
|
88 | 88 | self.ext = ".r" |
|
89 | 89 | |
|
90 | 90 | self.optchar = "D" |
|
91 | 91 | |
|
92 | 92 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
93 | 93 | |
|
94 | 94 | self.systemHeaderObj = SystemHeader() |
|
95 | 95 | |
|
96 | 96 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
97 | 97 | |
|
98 | 98 | self.processingHeaderObj = ProcessingHeader() |
|
99 | 99 | |
|
100 | 100 | self.online = 0 |
|
101 | 101 | |
|
102 | 102 | self.fp = None |
|
103 | 103 | |
|
104 | 104 | self.idFile = None |
|
105 | 105 | |
|
106 | 106 | self.dtype = None |
|
107 | 107 | |
|
108 | 108 | self.fileSizeByHeader = None |
|
109 | 109 | |
|
110 | 110 | self.filenameList = [] |
|
111 | 111 | |
|
112 | 112 | self.filename = None |
|
113 | 113 | |
|
114 | 114 | self.fileSize = None |
|
115 | 115 | |
|
116 | 116 | self.firstHeaderSize = 0 |
|
117 | 117 | |
|
118 | 118 | self.basicHeaderSize = 24 |
|
119 | 119 | |
|
120 | 120 | self.pathList = [] |
|
121 | 121 | |
|
122 | 122 | self.filenameList = [] |
|
123 | 123 | |
|
124 | 124 | self.lastUTTime = 0 |
|
125 | 125 | |
|
126 | 126 | self.maxTimeStep = 30 |
|
127 | 127 | |
|
128 | 128 | self.flagNoMoreFiles = 0 |
|
129 | 129 | |
|
130 | 130 | self.set = 0 |
|
131 | 131 | |
|
132 | 132 | self.path = None |
|
133 | 133 | |
|
134 | 134 | self.profileIndex = 2**32-1 |
|
135 | 135 | |
|
136 | 136 | self.delay = 3 #seconds |
|
137 | 137 | |
|
138 | 138 | self.nTries = 3 #quantity tries |
|
139 | 139 | |
|
140 | 140 | self.nFiles = 3 #number of files for searching |
|
141 | 141 | |
|
142 | 142 | self.nReadBlocks = 0 |
|
143 | 143 | |
|
144 | 144 | self.flagIsNewFile = 1 |
|
145 | 145 | |
|
146 | 146 | self.__isFirstTimeOnline = 1 |
|
147 | 147 | |
|
148 | 148 | # self.ippSeconds = 0 |
|
149 | 149 | |
|
150 | 150 | self.flagDiscontinuousBlock = 0 |
|
151 | 151 | |
|
152 | 152 | self.flagIsNewBlock = 0 |
|
153 | 153 | |
|
154 | 154 | self.nTotalBlocks = 0 |
|
155 | 155 | |
|
156 | 156 | self.blocksize = 0 |
|
157 | 157 | |
|
158 | 158 | self.dataOut = self.createObjByDefault() |
|
159 | 159 | |
|
160 | 160 | self.nTxs = 1 |
|
161 | 161 | |
|
162 | 162 | self.txIndex = 0 |
|
163 | 163 | |
|
164 | 164 | def createObjByDefault(self): |
|
165 | 165 | |
|
166 | 166 | dataObj = Voltage() |
|
167 | 167 | |
|
168 | 168 | return dataObj |
|
169 | 169 | |
|
170 | 170 | def __hasNotDataInBuffer(self): |
|
171 | 171 | |
|
172 | 172 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
173 | 173 | return 1 |
|
174 | 174 | |
|
175 | 175 | return 0 |
|
176 | 176 | |
|
177 | 177 | |
|
178 | 178 | def getBlockDimension(self): |
|
179 | 179 | """ |
|
180 | 180 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
181 | 181 | |
|
182 | 182 | Affected: |
|
183 | 183 | self.blocksize |
|
184 | 184 | |
|
185 | 185 | Return: |
|
186 | 186 | None |
|
187 | 187 | """ |
|
188 | 188 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
189 | 189 | self.blocksize = pts2read |
|
190 | 190 | |
|
191 | 191 | |
|
192 | 192 | def readBlock(self): |
|
193 | 193 | """ |
|
194 | 194 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
195 | 195 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
196 | 196 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
197 | 197 | es seteado a 0 |
|
198 | 198 | |
|
199 | 199 | Inputs: |
|
200 | 200 | None |
|
201 | 201 | |
|
202 | 202 | Return: |
|
203 | 203 | None |
|
204 | 204 | |
|
205 | 205 | Affected: |
|
206 | 206 | self.profileIndex |
|
207 | 207 | self.datablock |
|
208 | 208 | self.flagIsNewFile |
|
209 | 209 | self.flagIsNewBlock |
|
210 | 210 | self.nTotalBlocks |
|
211 | 211 | |
|
212 | 212 | Exceptions: |
|
213 | 213 | Si un bloque leido no es un bloque valido |
|
214 | 214 | """ |
|
215 | 215 | current_pointer_location = self.fp.tell() |
|
216 | 216 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
217 | 217 | |
|
218 | 218 | try: |
|
219 | 219 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
220 | 220 | except: |
|
221 | 221 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
222 | 222 | |
|
223 | 223 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
224 | 224 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
225 | 225 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
226 | 226 | # return 0 |
|
227 | 227 | |
|
228 | 228 | junk = numpy.transpose(junk, (2,0,1)) |
|
229 | 229 | self.datablock = junk['real'] + junk['imag']*1j |
|
230 | 230 | |
|
231 | 231 | self.profileIndex = 0 |
|
232 | 232 | |
|
233 | 233 | self.flagIsNewFile = 0 |
|
234 | 234 | self.flagIsNewBlock = 1 |
|
235 | 235 | |
|
236 | 236 | self.nTotalBlocks += 1 |
|
237 | 237 | self.nReadBlocks += 1 |
|
238 | 238 | |
|
239 | 239 | return 1 |
|
240 | 240 | |
|
241 | 241 | def getFirstHeader(self): |
|
242 | 242 | |
|
243 | 243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
244 | 244 | |
|
245 | 245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
246 | 246 | |
|
247 | 247 | if self.nTxs > 1: |
|
248 | 248 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
249 | 249 | |
|
250 | 250 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
251 | 251 | # |
|
252 |
# if self.radarControllerHeaderObj.code |
|
|
252 | # if self.radarControllerHeaderObj.code is not None: | |
|
253 | 253 | # |
|
254 | 254 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
255 | 255 | # |
|
256 | 256 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
257 | 257 | # |
|
258 | 258 | # self.dataOut.code = self.radarControllerHeaderObj.code |
|
259 | 259 | |
|
260 | 260 | self.dataOut.dtype = self.dtype |
|
261 | 261 | |
|
262 | 262 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
263 | 263 | |
|
264 | 264 | if self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
265 | 265 | raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights) |
|
266 | 266 | |
|
267 | 267 | xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight |
|
268 | 268 | |
|
269 | 269 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
270 | 270 | |
|
271 | 271 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
272 | 272 | |
|
273 | 273 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
274 | 274 | |
|
275 | 275 | self.dataOut.flagShiftFFT = False |
|
276 | 276 | |
|
277 | 277 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
278 | 278 | |
|
279 | 279 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
280 | 280 | |
|
281 | 281 | self.dataOut.flagShiftFFT = False |
|
282 | 282 | |
|
283 | 283 | def getData(self): |
|
284 | 284 | """ |
|
285 | 285 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
286 | 286 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
287 | 287 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
288 | 288 | "readNextBlock" |
|
289 | 289 | |
|
290 | 290 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
291 | 291 | |
|
292 | 292 | Return: |
|
293 | 293 | |
|
294 | 294 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
295 | 295 | es igual al total de perfiles leidos desde el archivo. |
|
296 | 296 | |
|
297 | 297 | Si self.getByBlock == False: |
|
298 | 298 | |
|
299 | 299 | self.dataOut.data = buffer[:, thisProfile, :] |
|
300 | 300 | |
|
301 | 301 | shape = [nChannels, nHeis] |
|
302 | 302 | |
|
303 | 303 | Si self.getByBlock == True: |
|
304 | 304 | |
|
305 | 305 | self.dataOut.data = buffer[:, :, :] |
|
306 | 306 | |
|
307 | 307 | shape = [nChannels, nProfiles, nHeis] |
|
308 | 308 | |
|
309 | 309 | Variables afectadas: |
|
310 | 310 | self.dataOut |
|
311 | 311 | self.profileIndex |
|
312 | 312 | |
|
313 | 313 | Affected: |
|
314 | 314 | self.dataOut |
|
315 | 315 | self.profileIndex |
|
316 | 316 | self.flagDiscontinuousBlock |
|
317 | 317 | self.flagIsNewBlock |
|
318 | 318 | """ |
|
319 | 319 | |
|
320 | 320 | if self.flagNoMoreFiles: |
|
321 | 321 | self.dataOut.flagNoData = True |
|
322 | 322 | print 'Process finished' |
|
323 | 323 | return 0 |
|
324 | 324 | |
|
325 | 325 | self.flagDiscontinuousBlock = 0 |
|
326 | 326 | self.flagIsNewBlock = 0 |
|
327 | 327 | |
|
328 | 328 | if self.__hasNotDataInBuffer(): |
|
329 | 329 | |
|
330 | 330 | if not( self.readNextBlock() ): |
|
331 | 331 | return 0 |
|
332 | 332 | |
|
333 | 333 | self.getFirstHeader() |
|
334 | 334 | |
|
335 | 335 | if self.datablock is None: |
|
336 | 336 | self.dataOut.flagNoData = True |
|
337 | 337 | return 0 |
|
338 | 338 | |
|
339 | 339 | if not self.getByBlock: |
|
340 | 340 | |
|
341 | 341 | """ |
|
342 | 342 | Return profile by profile |
|
343 | 343 | |
|
344 | 344 | If nTxs > 1 then one profile is divided by nTxs and number of total |
|
345 | 345 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
346 | 346 | """ |
|
347 | 347 | self.dataOut.flagDataAsBlock = False |
|
348 | 348 | |
|
349 | 349 | if self.nTxs == 1: |
|
350 | 350 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
351 | 351 | self.dataOut.profileIndex = self.profileIndex |
|
352 | 352 | |
|
353 | 353 | self.profileIndex += 1 |
|
354 | 354 | |
|
355 | 355 | else: |
|
356 | 356 | iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
357 | 357 | endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
358 | 358 | |
|
359 | 359 | # print iniHei_ForThisTx, endHei_ForThisTx |
|
360 | 360 | |
|
361 | 361 | self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx] |
|
362 | 362 | self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex |
|
363 | 363 | |
|
364 | 364 | self.txIndex += 1 |
|
365 | 365 | |
|
366 | 366 | if self.txIndex == self.nTxs: |
|
367 | 367 | self.txIndex = 0 |
|
368 | 368 | self.profileIndex += 1 |
|
369 | 369 | |
|
370 | 370 | else: |
|
371 | 371 | """ |
|
372 | 372 | Return all block |
|
373 | 373 | """ |
|
374 | 374 | self.dataOut.flagDataAsBlock = True |
|
375 | 375 | self.dataOut.data = self.datablock |
|
376 | 376 | self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock |
|
377 | 377 | |
|
378 | 378 | self.profileIndex = self.processingHeaderObj.profilesPerBlock |
|
379 | 379 | |
|
380 | 380 | self.dataOut.flagNoData = False |
|
381 | 381 | |
|
382 | 382 | self.getBasicHeader() |
|
383 | 383 | |
|
384 | 384 | self.dataOut.realtime = self.online |
|
385 | 385 | |
|
386 | 386 | return self.dataOut.data |
|
387 | 387 | |
|
388 | 388 | class VoltageWriter(JRODataWriter, Operation): |
|
389 | 389 | """ |
|
390 | 390 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
391 | 391 | de los datos siempre se realiza por bloques. |
|
392 | 392 | """ |
|
393 | 393 | |
|
394 | 394 | ext = ".r" |
|
395 | 395 | |
|
396 | 396 | optchar = "D" |
|
397 | 397 | |
|
398 | 398 | shapeBuffer = None |
|
399 | 399 | |
|
400 | 400 | |
|
401 | 401 | def __init__(self): |
|
402 | 402 | """ |
|
403 | 403 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
404 | 404 | |
|
405 | 405 | Affected: |
|
406 | 406 | self.dataOut |
|
407 | 407 | |
|
408 | 408 | Return: None |
|
409 | 409 | """ |
|
410 | 410 | Operation.__init__(self) |
|
411 | 411 | |
|
412 | 412 | self.nTotalBlocks = 0 |
|
413 | 413 | |
|
414 | 414 | self.profileIndex = 0 |
|
415 | 415 | |
|
416 | 416 | self.isConfig = False |
|
417 | 417 | |
|
418 | 418 | self.fp = None |
|
419 | 419 | |
|
420 | 420 | self.flagIsNewFile = 1 |
|
421 | 421 | |
|
422 | 422 | self.nTotalBlocks = 0 |
|
423 | 423 | |
|
424 | 424 | self.flagIsNewBlock = 0 |
|
425 | 425 | |
|
426 | 426 | self.setFile = None |
|
427 | 427 | |
|
428 | 428 | self.dtype = None |
|
429 | 429 | |
|
430 | 430 | self.path = None |
|
431 | 431 | |
|
432 | 432 | self.filename = None |
|
433 | 433 | |
|
434 | 434 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
435 | 435 | |
|
436 | 436 | self.systemHeaderObj = SystemHeader() |
|
437 | 437 | |
|
438 | 438 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
439 | 439 | |
|
440 | 440 | self.processingHeaderObj = ProcessingHeader() |
|
441 | 441 | |
|
442 | 442 | def hasAllDataInBuffer(self): |
|
443 | 443 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
444 | 444 | return 1 |
|
445 | 445 | return 0 |
|
446 | 446 | |
|
447 | 447 | |
|
448 | 448 | def setBlockDimension(self): |
|
449 | 449 | """ |
|
450 | 450 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
451 | 451 | |
|
452 | 452 | Affected: |
|
453 | 453 | self.shape_spc_Buffer |
|
454 | 454 | self.shape_cspc_Buffer |
|
455 | 455 | self.shape_dc_Buffer |
|
456 | 456 | |
|
457 | 457 | Return: None |
|
458 | 458 | """ |
|
459 | 459 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
460 | 460 | self.processingHeaderObj.nHeights, |
|
461 | 461 | self.systemHeaderObj.nChannels) |
|
462 | 462 | |
|
463 | 463 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
464 | 464 | self.processingHeaderObj.profilesPerBlock, |
|
465 | 465 | self.processingHeaderObj.nHeights), |
|
466 | 466 | dtype=numpy.dtype('complex64')) |
|
467 | 467 | |
|
468 | 468 | def writeBlock(self): |
|
469 | 469 | """ |
|
470 | 470 | Escribe el buffer en el file designado |
|
471 | 471 | |
|
472 | 472 | Affected: |
|
473 | 473 | self.profileIndex |
|
474 | 474 | self.flagIsNewFile |
|
475 | 475 | self.flagIsNewBlock |
|
476 | 476 | self.nTotalBlocks |
|
477 | 477 | self.blockIndex |
|
478 | 478 | |
|
479 | 479 | Return: None |
|
480 | 480 | """ |
|
481 | 481 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
482 | 482 | |
|
483 | 483 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
484 | 484 | |
|
485 | 485 | data['real'] = junk.real |
|
486 | 486 | data['imag'] = junk.imag |
|
487 | 487 | |
|
488 | 488 | data = data.reshape( (-1) ) |
|
489 | 489 | |
|
490 | 490 | data.tofile( self.fp ) |
|
491 | 491 | |
|
492 | 492 | self.datablock.fill(0) |
|
493 | 493 | |
|
494 | 494 | self.profileIndex = 0 |
|
495 | 495 | self.flagIsNewFile = 0 |
|
496 | 496 | self.flagIsNewBlock = 1 |
|
497 | 497 | |
|
498 | 498 | self.blockIndex += 1 |
|
499 | 499 | self.nTotalBlocks += 1 |
|
500 | 500 | |
|
501 | 501 | # print "[Writing] Block = %04d" %self.blockIndex |
|
502 | 502 | |
|
503 | 503 | def putData(self): |
|
504 | 504 | """ |
|
505 | 505 | Setea un bloque de datos y luego los escribe en un file |
|
506 | 506 | |
|
507 | 507 | Affected: |
|
508 | 508 | self.flagIsNewBlock |
|
509 | 509 | self.profileIndex |
|
510 | 510 | |
|
511 | 511 | Return: |
|
512 | 512 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
513 | 513 | 1 : Si se escribio la data de un bloque en un file |
|
514 | 514 | """ |
|
515 | 515 | if self.dataOut.flagNoData: |
|
516 | 516 | return 0 |
|
517 | 517 | |
|
518 | 518 | self.flagIsNewBlock = 0 |
|
519 | 519 | |
|
520 | 520 | if self.dataOut.flagDiscontinuousBlock: |
|
521 | 521 | self.datablock.fill(0) |
|
522 | 522 | self.profileIndex = 0 |
|
523 | 523 | self.setNextFile() |
|
524 | 524 | |
|
525 | 525 | if self.profileIndex == 0: |
|
526 | 526 | self.setBasicHeader() |
|
527 | 527 | |
|
528 | 528 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
529 | 529 | |
|
530 | 530 | self.profileIndex += 1 |
|
531 | 531 | |
|
532 | 532 | if self.hasAllDataInBuffer(): |
|
533 | 533 | #if self.flagIsNewFile: |
|
534 | 534 | self.writeNextBlock() |
|
535 | 535 | # self.setFirstHeader() |
|
536 | 536 | |
|
537 | 537 | return 1 |
|
538 | 538 | |
|
539 | 539 | def __getProcessFlags(self): |
|
540 | 540 | |
|
541 | 541 | processFlags = 0 |
|
542 | 542 | |
|
543 | 543 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
544 | 544 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
545 | 545 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
546 | 546 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
547 | 547 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
548 | 548 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
549 | 549 | |
|
550 | 550 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
551 | 551 | |
|
552 | 552 | |
|
553 | 553 | |
|
554 | 554 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
555 | 555 | PROCFLAG.DATATYPE_SHORT, |
|
556 | 556 | PROCFLAG.DATATYPE_LONG, |
|
557 | 557 | PROCFLAG.DATATYPE_INT64, |
|
558 | 558 | PROCFLAG.DATATYPE_FLOAT, |
|
559 | 559 | PROCFLAG.DATATYPE_DOUBLE] |
|
560 | 560 | |
|
561 | 561 | |
|
562 | 562 | for index in range(len(dtypeList)): |
|
563 | 563 | if self.dataOut.dtype == dtypeList[index]: |
|
564 | 564 | dtypeValue = datatypeValueList[index] |
|
565 | 565 | break |
|
566 | 566 | |
|
567 | 567 | processFlags += dtypeValue |
|
568 | 568 | |
|
569 | 569 | if self.dataOut.flagDecodeData: |
|
570 | 570 | processFlags += PROCFLAG.DECODE_DATA |
|
571 | 571 | |
|
572 | 572 | if self.dataOut.flagDeflipData: |
|
573 | 573 | processFlags += PROCFLAG.DEFLIP_DATA |
|
574 | 574 | |
|
575 |
if self.dataOut.code |
|
|
575 | if self.dataOut.code is not None: | |
|
576 | 576 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
577 | 577 | |
|
578 | 578 | if self.dataOut.nCohInt > 1: |
|
579 | 579 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
580 | 580 | |
|
581 | 581 | return processFlags |
|
582 | 582 | |
|
583 | 583 | |
|
584 | 584 | def __getBlockSize(self): |
|
585 | 585 | ''' |
|
586 | 586 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
587 | 587 | ''' |
|
588 | 588 | |
|
589 | 589 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
590 | 590 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
591 | 591 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
592 | 592 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
593 | 593 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
594 | 594 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
595 | 595 | |
|
596 | 596 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
597 | 597 | datatypeValueList = [1,2,4,8,4,8] |
|
598 | 598 | for index in range(len(dtypeList)): |
|
599 | 599 | if self.dataOut.dtype == dtypeList[index]: |
|
600 | 600 | datatypeValue = datatypeValueList[index] |
|
601 | 601 | break |
|
602 | 602 | |
|
603 | 603 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2) |
|
604 | 604 | |
|
605 | 605 | return blocksize |
|
606 | 606 | |
|
607 | 607 | def setFirstHeader(self): |
|
608 | 608 | |
|
609 | 609 | """ |
|
610 | 610 | Obtiene una copia del First Header |
|
611 | 611 | |
|
612 | 612 | Affected: |
|
613 | 613 | self.systemHeaderObj |
|
614 | 614 | self.radarControllerHeaderObj |
|
615 | 615 | self.dtype |
|
616 | 616 | |
|
617 | 617 | Return: |
|
618 | 618 | None |
|
619 | 619 | """ |
|
620 | 620 | |
|
621 | 621 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
622 | 622 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
623 | 623 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
624 | 624 | |
|
625 | 625 | self.setBasicHeader() |
|
626 | 626 | |
|
627 | 627 | processingHeaderSize = 40 # bytes |
|
628 | 628 | self.processingHeaderObj.dtype = 0 # Voltage |
|
629 | 629 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
630 | 630 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
631 | 631 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
632 | 632 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
633 | 633 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
634 | 634 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
635 | 635 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
636 | 636 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
637 | 637 | |
|
638 |
# if self.dataOut.code |
|
|
638 | # if self.dataOut.code is not None: | |
|
639 | 639 | # self.processingHeaderObj.code = self.dataOut.code |
|
640 | 640 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
641 | 641 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
642 | 642 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
643 | 643 | # processingHeaderSize += codesize |
|
644 | 644 | |
|
645 | 645 | if self.processingHeaderObj.nWindows != 0: |
|
646 | 646 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
647 | 647 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
648 | 648 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
649 | 649 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
650 | 650 | processingHeaderSize += 12 |
|
651 | 651 | |
|
652 | 652 | self.processingHeaderObj.size = processingHeaderSize No newline at end of file |
@@ -1,978 +1,978 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import math |
|
3 | 3 | |
|
4 | 4 | from jroproc_base import ProcessingUnit, Operation |
|
5 | 5 | from schainpy.model.data.jrodata import Spectra |
|
6 | 6 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
7 | 7 | |
|
8 | 8 | class SpectraProc(ProcessingUnit): |
|
9 | 9 | |
|
10 | 10 | def __init__(self): |
|
11 | 11 | |
|
12 | 12 | ProcessingUnit.__init__(self) |
|
13 | 13 | |
|
14 | 14 | self.buffer = None |
|
15 | 15 | self.firstdatatime = None |
|
16 | 16 | self.profIndex = 0 |
|
17 | 17 | self.dataOut = Spectra() |
|
18 | 18 | self.id_min = None |
|
19 | 19 | self.id_max = None |
|
20 | 20 | |
|
21 | 21 | def __updateObjFromInput(self): |
|
22 | 22 | |
|
23 | 23 | self.dataOut.timeZone = self.dataIn.timeZone |
|
24 | 24 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
25 | 25 | self.dataOut.errorCount = self.dataIn.errorCount |
|
26 | 26 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
27 | 27 | |
|
28 | 28 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
29 | 29 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
30 | 30 | self.dataOut.channelList = self.dataIn.channelList |
|
31 | 31 | self.dataOut.heightList = self.dataIn.heightList |
|
32 | 32 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
33 | 33 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
34 | 34 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
35 | 35 | self.dataOut.nBaud = self.dataIn.nBaud |
|
36 | 36 | self.dataOut.nCode = self.dataIn.nCode |
|
37 | 37 | self.dataOut.code = self.dataIn.code |
|
38 | 38 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
39 | 39 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
40 | 40 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
41 | 41 | self.dataOut.utctime = self.firstdatatime |
|
42 | 42 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
43 | 43 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
44 | 44 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
45 | 45 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
46 | 46 | self.dataOut.nIncohInt = 1 |
|
47 | 47 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
48 | 48 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
49 | 49 | |
|
50 | 50 | # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
51 | 51 | self.dataOut.frequency = self.dataIn.frequency |
|
52 | 52 | self.dataOut.realtime = self.dataIn.realtime |
|
53 | 53 | |
|
54 | 54 | self.dataOut.azimuth = self.dataIn.azimuth |
|
55 | 55 | self.dataOut.zenith = self.dataIn.zenith |
|
56 | 56 | |
|
57 | 57 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
58 | 58 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
59 | 59 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
60 | 60 | |
|
61 | 61 | def __getFft(self): |
|
62 | 62 | """ |
|
63 | 63 | Convierte valores de Voltaje a Spectra |
|
64 | 64 | |
|
65 | 65 | Affected: |
|
66 | 66 | self.dataOut.data_spc |
|
67 | 67 | self.dataOut.data_cspc |
|
68 | 68 | self.dataOut.data_dc |
|
69 | 69 | self.dataOut.heightList |
|
70 | 70 | self.profIndex |
|
71 | 71 | self.buffer |
|
72 | 72 | self.dataOut.flagNoData |
|
73 | 73 | """ |
|
74 | 74 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
75 | 75 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
76 | 76 | dc = fft_volt[:,0,:] |
|
77 | 77 | |
|
78 | 78 | #calculo de self-spectra |
|
79 | 79 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
80 | 80 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
81 | 81 | spc = spc.real |
|
82 | 82 | |
|
83 | 83 | blocksize = 0 |
|
84 | 84 | blocksize += dc.size |
|
85 | 85 | blocksize += spc.size |
|
86 | 86 | |
|
87 | 87 | cspc = None |
|
88 | 88 | pairIndex = 0 |
|
89 | 89 | if self.dataOut.pairsList != None: |
|
90 | 90 | #calculo de cross-spectra |
|
91 | 91 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
92 | 92 | for pair in self.dataOut.pairsList: |
|
93 | 93 | if pair[0] not in self.dataOut.channelList: |
|
94 | 94 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
95 | 95 | if pair[1] not in self.dataOut.channelList: |
|
96 | 96 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
97 | 97 | |
|
98 | 98 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
99 | 99 | pairIndex += 1 |
|
100 | 100 | blocksize += cspc.size |
|
101 | 101 | |
|
102 | 102 | self.dataOut.data_spc = spc |
|
103 | 103 | self.dataOut.data_cspc = cspc |
|
104 | 104 | self.dataOut.data_dc = dc |
|
105 | 105 | self.dataOut.blockSize = blocksize |
|
106 | 106 | self.dataOut.flagShiftFFT = False |
|
107 | 107 | |
|
108 | 108 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): |
|
109 | 109 | |
|
110 | 110 | self.dataOut.flagNoData = True |
|
111 | 111 | |
|
112 | 112 | if self.dataIn.type == "Spectra": |
|
113 | 113 | self.dataOut.copy(self.dataIn) |
|
114 | 114 | return True |
|
115 | 115 | |
|
116 | 116 | if self.dataIn.type == "Voltage": |
|
117 | 117 | |
|
118 | 118 | if nFFTPoints == None: |
|
119 | 119 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
120 | 120 | |
|
121 | 121 | if nProfiles == None: |
|
122 | 122 | nProfiles = nFFTPoints |
|
123 | 123 | # raise ValueError, "This SpectraProc.run() need nProfiles input variable" |
|
124 | 124 | |
|
125 | 125 | |
|
126 | 126 | if ippFactor == None: |
|
127 | 127 | ippFactor = 1 |
|
128 | 128 | self.dataOut.ippFactor = ippFactor |
|
129 | 129 | |
|
130 | 130 | self.dataOut.nFFTPoints = nFFTPoints |
|
131 | 131 | self.dataOut.pairsList = pairsList |
|
132 | 132 | |
|
133 | 133 | if self.buffer is None: |
|
134 | 134 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
135 | 135 | nProfiles, |
|
136 | 136 | self.dataIn.nHeights), |
|
137 | 137 | dtype='complex') |
|
138 | 138 | self.id_min = 0 |
|
139 | 139 | self.id_max = self.dataIn.data.shape[1] |
|
140 | 140 | |
|
141 | 141 | if len(self.dataIn.data.shape) == 2: |
|
142 | 142 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
143 | 143 | self.profIndex += 1 |
|
144 | 144 | else: |
|
145 | 145 | if self.dataIn.data.shape[1] == nProfiles: |
|
146 | 146 | self.buffer = self.dataIn.data.copy() |
|
147 | 147 | self.profIndex = nProfiles |
|
148 | 148 | elif self.dataIn.data.shape[1] < nProfiles: |
|
149 | 149 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data |
|
150 | 150 | self.profIndex += self.dataIn.data.shape[1] |
|
151 | 151 | self.id_min += self.dataIn.data.shape[1] |
|
152 | 152 | self.id_max += self.dataIn.data.shape[1] |
|
153 | 153 | else: |
|
154 | 154 | raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) |
|
155 | 155 | self.dataOut.flagNoData = True |
|
156 | 156 | return 0 |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | if self.firstdatatime == None: |
|
160 | 160 | self.firstdatatime = self.dataIn.utctime |
|
161 | 161 | |
|
162 | 162 | if self.profIndex == nProfiles: |
|
163 | 163 | self.__updateObjFromInput() |
|
164 | 164 | self.__getFft() |
|
165 | 165 | |
|
166 | 166 | self.dataOut.flagNoData = False |
|
167 | 167 | |
|
168 | 168 | self.buffer = None |
|
169 | 169 | self.firstdatatime = None |
|
170 | 170 | self.profIndex = 0 |
|
171 | 171 | |
|
172 | 172 | return True |
|
173 | 173 | |
|
174 | 174 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) |
|
175 | 175 | |
|
176 | 176 | def __selectPairs(self, channelList=None): |
|
177 | 177 | |
|
178 | 178 | if channelList == None: |
|
179 | 179 | return |
|
180 | 180 | |
|
181 | 181 | pairsIndexListSelected = [] |
|
182 | 182 | for pairIndex in self.dataOut.pairsIndexList: |
|
183 | 183 | #First pair |
|
184 | 184 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
185 | 185 | continue |
|
186 | 186 | #Second pair |
|
187 | 187 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
188 | 188 | continue |
|
189 | 189 | |
|
190 | 190 | pairsIndexListSelected.append(pairIndex) |
|
191 | 191 | |
|
192 | 192 | if not pairsIndexListSelected: |
|
193 | 193 | self.dataOut.data_cspc = None |
|
194 | 194 | self.dataOut.pairsList = [] |
|
195 | 195 | return |
|
196 | 196 | |
|
197 | 197 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
198 | self.dataOut.pairsList = self.dataOut.pairsList[pairsIndexListSelected] | |
|
199 |
|
|
|
198 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] | |
|
199 | ||
|
200 | 200 | return |
|
201 | 201 | |
|
202 | 202 | def selectChannels(self, channelList): |
|
203 | 203 | |
|
204 | 204 | channelIndexList = [] |
|
205 | 205 | |
|
206 | 206 | for channel in channelList: |
|
207 | 207 | if channel not in self.dataOut.channelList: |
|
208 | 208 | raise ValueError, "Error selecting channels: The value %d in channelList is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) |
|
209 | 209 | |
|
210 | 210 | index = self.dataOut.channelList.index(channel) |
|
211 | 211 | channelIndexList.append(index) |
|
212 | 212 | |
|
213 | 213 | self.selectChannelsByIndex(channelIndexList) |
|
214 | 214 | |
|
215 | 215 | def selectChannelsByIndex(self, channelIndexList): |
|
216 | 216 | """ |
|
217 | 217 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
218 | 218 | |
|
219 | 219 | Input: |
|
220 | 220 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
221 | 221 | |
|
222 | 222 | Affected: |
|
223 | 223 | self.dataOut.data_spc |
|
224 | 224 | self.dataOut.channelIndexList |
|
225 | 225 | self.dataOut.nChannels |
|
226 | 226 | |
|
227 | 227 | Return: |
|
228 | 228 | None |
|
229 | 229 | """ |
|
230 | 230 | |
|
231 | 231 | for channelIndex in channelIndexList: |
|
232 | 232 | if channelIndex not in self.dataOut.channelIndexList: |
|
233 | 233 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) |
|
234 | 234 | |
|
235 | 235 | # nChannels = len(channelIndexList) |
|
236 | 236 | |
|
237 | 237 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
238 | 238 | data_dc = self.dataOut.data_dc[channelIndexList,:] |
|
239 | 239 | |
|
240 | 240 | self.dataOut.data_spc = data_spc |
|
241 | 241 | self.dataOut.data_dc = data_dc |
|
242 | 242 | |
|
243 | 243 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
244 | 244 | # self.dataOut.nChannels = nChannels |
|
245 | 245 | |
|
246 | 246 | self.__selectPairs(self.dataOut.channelList) |
|
247 | 247 | |
|
248 | 248 | return 1 |
|
249 | 249 | |
|
250 | 250 | def selectHeights(self, minHei, maxHei): |
|
251 | 251 | """ |
|
252 | 252 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
253 | 253 | minHei <= height <= maxHei |
|
254 | 254 | |
|
255 | 255 | Input: |
|
256 | 256 | minHei : valor minimo de altura a considerar |
|
257 | 257 | maxHei : valor maximo de altura a considerar |
|
258 | 258 | |
|
259 | 259 | Affected: |
|
260 | 260 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
261 | 261 | |
|
262 | 262 | Return: |
|
263 | 263 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
264 | 264 | """ |
|
265 | 265 | |
|
266 | 266 | if (minHei > maxHei): |
|
267 | 267 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) |
|
268 | 268 | |
|
269 | 269 | if (minHei < self.dataOut.heightList[0]): |
|
270 | 270 | minHei = self.dataOut.heightList[0] |
|
271 | 271 | |
|
272 | 272 | if (maxHei > self.dataOut.heightList[-1]): |
|
273 | 273 | maxHei = self.dataOut.heightList[-1] |
|
274 | 274 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
275 | 275 | |
|
276 | 276 | minIndex = 0 |
|
277 | 277 | maxIndex = 0 |
|
278 | 278 | heights = self.dataOut.heightList |
|
279 | 279 | |
|
280 | 280 | inda = numpy.where(heights >= minHei) |
|
281 | 281 | indb = numpy.where(heights <= maxHei) |
|
282 | 282 | |
|
283 | 283 | try: |
|
284 | 284 | minIndex = inda[0][0] |
|
285 | 285 | except: |
|
286 | 286 | minIndex = 0 |
|
287 | 287 | |
|
288 | 288 | try: |
|
289 | 289 | maxIndex = indb[0][-1] |
|
290 | 290 | except: |
|
291 | 291 | maxIndex = len(heights) |
|
292 | 292 | |
|
293 | 293 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
294 | 294 | |
|
295 | 295 | return 1 |
|
296 | 296 | |
|
297 | 297 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
298 | 298 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
299 | 299 | |
|
300 | 300 | if hei_ref != None: |
|
301 | 301 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
302 | 302 | |
|
303 | 303 | minIndex = min(newheis[0]) |
|
304 | 304 | maxIndex = max(newheis[0]) |
|
305 | 305 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
306 | 306 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
307 | 307 | |
|
308 | 308 | # determina indices |
|
309 | 309 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
310 | 310 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
311 | 311 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
312 | 312 | beacon_heiIndexList = [] |
|
313 | 313 | for val in avg_dB.tolist(): |
|
314 | 314 | if val >= beacon_dB[0]: |
|
315 | 315 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
316 | 316 | |
|
317 | 317 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
318 | 318 | data_cspc = None |
|
319 |
if self.dataOut.data_cspc |
|
|
319 | if self.dataOut.data_cspc is not None: | |
|
320 | 320 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
321 | 321 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
322 | 322 | |
|
323 | 323 | data_dc = None |
|
324 |
if self.dataOut.data_dc |
|
|
324 | if self.dataOut.data_dc is not None: | |
|
325 | 325 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
326 | 326 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
327 | 327 | |
|
328 | 328 | self.dataOut.data_spc = data_spc |
|
329 | 329 | self.dataOut.data_cspc = data_cspc |
|
330 | 330 | self.dataOut.data_dc = data_dc |
|
331 | 331 | self.dataOut.heightList = heightList |
|
332 | 332 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
333 | 333 | |
|
334 | 334 | return 1 |
|
335 | 335 | |
|
336 | 336 | |
|
337 | 337 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
338 | 338 | """ |
|
339 | 339 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
340 | 340 | minIndex <= index <= maxIndex |
|
341 | 341 | |
|
342 | 342 | Input: |
|
343 | 343 | minIndex : valor de indice minimo de altura a considerar |
|
344 | 344 | maxIndex : valor de indice maximo de altura a considerar |
|
345 | 345 | |
|
346 | 346 | Affected: |
|
347 | 347 | self.dataOut.data_spc |
|
348 | 348 | self.dataOut.data_cspc |
|
349 | 349 | self.dataOut.data_dc |
|
350 | 350 | self.dataOut.heightList |
|
351 | 351 | |
|
352 | 352 | Return: |
|
353 | 353 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
354 | 354 | """ |
|
355 | 355 | |
|
356 | 356 | if (minIndex < 0) or (minIndex > maxIndex): |
|
357 | 357 | raise ValueError, "Error selecting heights by index: Index range in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
358 | 358 | |
|
359 | 359 | if (maxIndex >= self.dataOut.nHeights): |
|
360 | 360 | maxIndex = self.dataOut.nHeights-1 |
|
361 | 361 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
362 | 362 | |
|
363 | 363 | # nHeights = maxIndex - minIndex + 1 |
|
364 | 364 | |
|
365 | 365 | #Spectra |
|
366 | 366 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
367 | 367 | |
|
368 | 368 | data_cspc = None |
|
369 |
if self.dataOut.data_cspc |
|
|
369 | if self.dataOut.data_cspc is not None: | |
|
370 | 370 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
371 | 371 | |
|
372 | 372 | data_dc = None |
|
373 |
if self.dataOut.data_dc |
|
|
373 | if self.dataOut.data_dc is not None: | |
|
374 | 374 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
375 | 375 | |
|
376 | 376 | self.dataOut.data_spc = data_spc |
|
377 | 377 | self.dataOut.data_cspc = data_cspc |
|
378 | 378 | self.dataOut.data_dc = data_dc |
|
379 | 379 | |
|
380 | 380 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
381 | 381 | |
|
382 | 382 | return 1 |
|
383 | 383 | |
|
384 | 384 | def removeDC(self, mode = 2): |
|
385 | 385 | jspectra = self.dataOut.data_spc |
|
386 | 386 | jcspectra = self.dataOut.data_cspc |
|
387 | 387 | |
|
388 | 388 | |
|
389 | 389 | num_chan = jspectra.shape[0] |
|
390 | 390 | num_hei = jspectra.shape[2] |
|
391 | 391 | |
|
392 |
if jcspectra |
|
|
392 | if jcspectra is not None: | |
|
393 | 393 | jcspectraExist = True |
|
394 | 394 | num_pairs = jcspectra.shape[0] |
|
395 | 395 | else: jcspectraExist = False |
|
396 | 396 | |
|
397 | 397 | freq_dc = jspectra.shape[1]/2 |
|
398 | 398 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
399 | 399 | |
|
400 | 400 | if ind_vel[0]<0: |
|
401 | 401 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
402 | 402 | |
|
403 | 403 | if mode == 1: |
|
404 | 404 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
405 | 405 | |
|
406 | 406 | if jcspectraExist: |
|
407 | 407 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
408 | 408 | |
|
409 | 409 | if mode == 2: |
|
410 | 410 | |
|
411 | 411 | vel = numpy.array([-2,-1,1,2]) |
|
412 | 412 | xx = numpy.zeros([4,4]) |
|
413 | 413 | |
|
414 | 414 | for fil in range(4): |
|
415 | 415 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
416 | 416 | |
|
417 | 417 | xx_inv = numpy.linalg.inv(xx) |
|
418 | 418 | xx_aux = xx_inv[0,:] |
|
419 | 419 | |
|
420 | 420 | for ich in range(num_chan): |
|
421 | 421 | yy = jspectra[ich,ind_vel,:] |
|
422 | 422 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
423 | 423 | |
|
424 | 424 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
425 | 425 | cjunkid = sum(junkid) |
|
426 | 426 | |
|
427 | 427 | if cjunkid.any(): |
|
428 | 428 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
429 | 429 | |
|
430 | 430 | if jcspectraExist: |
|
431 | 431 | for ip in range(num_pairs): |
|
432 | 432 | yy = jcspectra[ip,ind_vel,:] |
|
433 | 433 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | self.dataOut.data_spc = jspectra |
|
437 | 437 | self.dataOut.data_cspc = jcspectra |
|
438 | 438 | |
|
439 | 439 | return 1 |
|
440 | 440 | |
|
441 | 441 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
442 | 442 | |
|
443 | 443 | jspectra = self.dataOut.data_spc |
|
444 | 444 | jcspectra = self.dataOut.data_cspc |
|
445 | 445 | jnoise = self.dataOut.getNoise() |
|
446 | 446 | num_incoh = self.dataOut.nIncohInt |
|
447 | 447 | |
|
448 | 448 | num_channel = jspectra.shape[0] |
|
449 | 449 | num_prof = jspectra.shape[1] |
|
450 | 450 | num_hei = jspectra.shape[2] |
|
451 | 451 | |
|
452 | 452 | #hei_interf |
|
453 |
if hei_interf |
|
|
453 | if hei_interf is None: | |
|
454 | 454 | count_hei = num_hei/2 #Como es entero no importa |
|
455 | 455 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
456 | 456 | hei_interf = numpy.asarray(hei_interf)[0] |
|
457 | 457 | #nhei_interf |
|
458 | 458 | if (nhei_interf == None): |
|
459 | 459 | nhei_interf = 5 |
|
460 | 460 | if (nhei_interf < 1): |
|
461 | 461 | nhei_interf = 1 |
|
462 | 462 | if (nhei_interf > count_hei): |
|
463 | 463 | nhei_interf = count_hei |
|
464 | 464 | if (offhei_interf == None): |
|
465 | 465 | offhei_interf = 0 |
|
466 | 466 | |
|
467 | 467 | ind_hei = range(num_hei) |
|
468 | 468 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
469 | 469 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
470 | 470 | mask_prof = numpy.asarray(range(num_prof)) |
|
471 | 471 | num_mask_prof = mask_prof.size |
|
472 | 472 | comp_mask_prof = [0, num_prof/2] |
|
473 | 473 | |
|
474 | 474 | |
|
475 | 475 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
476 | 476 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
477 | 477 | jnoise = numpy.nan |
|
478 | 478 | noise_exist = jnoise[0] < numpy.Inf |
|
479 | 479 | |
|
480 | 480 | #Subrutina de Remocion de la Interferencia |
|
481 | 481 | for ich in range(num_channel): |
|
482 | 482 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
483 | 483 | power = jspectra[ich,mask_prof,:] |
|
484 | 484 | power = power[:,hei_interf] |
|
485 | 485 | power = power.sum(axis = 0) |
|
486 | 486 | psort = power.ravel().argsort() |
|
487 | 487 | |
|
488 | 488 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
489 | 489 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
490 | 490 | |
|
491 | 491 | if noise_exist: |
|
492 | 492 | # tmp_noise = jnoise[ich] / num_prof |
|
493 | 493 | tmp_noise = jnoise[ich] |
|
494 | 494 | junkspc_interf = junkspc_interf - tmp_noise |
|
495 | 495 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
496 | 496 | |
|
497 | 497 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
498 | 498 | jspc_interf = jspc_interf.transpose() |
|
499 | 499 | #Calculando el espectro de interferencia promedio |
|
500 | 500 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
501 | 501 | noiseid = noiseid[0] |
|
502 | 502 | cnoiseid = noiseid.size |
|
503 | 503 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
504 | 504 | interfid = interfid[0] |
|
505 | 505 | cinterfid = interfid.size |
|
506 | 506 | |
|
507 | 507 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
508 | 508 | |
|
509 | 509 | #Expandiendo los perfiles a limpiar |
|
510 | 510 | if (cinterfid > 0): |
|
511 | 511 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
512 | 512 | new_interfid = numpy.asarray(new_interfid) |
|
513 | 513 | new_interfid = {x for x in new_interfid} |
|
514 | 514 | new_interfid = numpy.array(list(new_interfid)) |
|
515 | 515 | new_cinterfid = new_interfid.size |
|
516 | 516 | else: new_cinterfid = 0 |
|
517 | 517 | |
|
518 | 518 | for ip in range(new_cinterfid): |
|
519 | 519 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
520 | 520 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
521 | 521 | |
|
522 | 522 | |
|
523 | 523 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
524 | 524 | |
|
525 | 525 | #Removiendo la interferencia del punto de mayor interferencia |
|
526 | 526 | ListAux = jspc_interf[mask_prof].tolist() |
|
527 | 527 | maxid = ListAux.index(max(ListAux)) |
|
528 | 528 | |
|
529 | 529 | |
|
530 | 530 | if cinterfid > 0: |
|
531 | 531 | for ip in range(cinterfid*(interf == 2) - 1): |
|
532 | 532 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
533 | 533 | cind = len(ind) |
|
534 | 534 | |
|
535 | 535 | if (cind > 0): |
|
536 | 536 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
537 | 537 | |
|
538 | 538 | ind = numpy.array([-2,-1,1,2]) |
|
539 | 539 | xx = numpy.zeros([4,4]) |
|
540 | 540 | |
|
541 | 541 | for id1 in range(4): |
|
542 | 542 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
543 | 543 | |
|
544 | 544 | xx_inv = numpy.linalg.inv(xx) |
|
545 | 545 | xx = xx_inv[:,0] |
|
546 | 546 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
547 | 547 | yy = jspectra[ich,mask_prof[ind],:] |
|
548 | 548 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
549 | 549 | |
|
550 | 550 | |
|
551 | 551 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
552 | 552 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
553 | 553 | |
|
554 | 554 | #Remocion de Interferencia en el Cross Spectra |
|
555 |
if jcspectra |
|
|
555 | if jcspectra is None: return jspectra, jcspectra | |
|
556 | 556 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
557 | 557 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
558 | 558 | |
|
559 | 559 | for ip in range(num_pairs): |
|
560 | 560 | |
|
561 | 561 | #------------------------------------------- |
|
562 | 562 | |
|
563 | 563 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
564 | 564 | cspower = cspower[:,hei_interf] |
|
565 | 565 | cspower = cspower.sum(axis = 0) |
|
566 | 566 | |
|
567 | 567 | cspsort = cspower.ravel().argsort() |
|
568 | 568 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
569 | 569 | junkcspc_interf = junkcspc_interf.transpose() |
|
570 | 570 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
571 | 571 | |
|
572 | 572 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
573 | 573 | |
|
574 | 574 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
575 | 575 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
576 | 576 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
577 | 577 | |
|
578 | 578 | for iprof in range(num_prof): |
|
579 | 579 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
580 | 580 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
581 | 581 | |
|
582 | 582 | #Removiendo la Interferencia |
|
583 | 583 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
584 | 584 | |
|
585 | 585 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
586 | 586 | maxid = ListAux.index(max(ListAux)) |
|
587 | 587 | |
|
588 | 588 | ind = numpy.array([-2,-1,1,2]) |
|
589 | 589 | xx = numpy.zeros([4,4]) |
|
590 | 590 | |
|
591 | 591 | for id1 in range(4): |
|
592 | 592 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
593 | 593 | |
|
594 | 594 | xx_inv = numpy.linalg.inv(xx) |
|
595 | 595 | xx = xx_inv[:,0] |
|
596 | 596 | |
|
597 | 597 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
598 | 598 | yy = jcspectra[ip,mask_prof[ind],:] |
|
599 | 599 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
600 | 600 | |
|
601 | 601 | #Guardar Resultados |
|
602 | 602 | self.dataOut.data_spc = jspectra |
|
603 | 603 | self.dataOut.data_cspc = jcspectra |
|
604 | 604 | |
|
605 | 605 | return 1 |
|
606 | 606 | |
|
607 | 607 | def setRadarFrequency(self, frequency=None): |
|
608 | 608 | if frequency != None: |
|
609 | 609 | self.dataOut.frequency = frequency |
|
610 | 610 | |
|
611 | 611 | return 1 |
|
612 | 612 | |
|
613 | 613 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
614 | 614 | #validacion de rango |
|
615 | 615 | if minHei == None: |
|
616 | 616 | minHei = self.dataOut.heightList[0] |
|
617 | 617 | |
|
618 | 618 | if maxHei == None: |
|
619 | 619 | maxHei = self.dataOut.heightList[-1] |
|
620 | 620 | |
|
621 | 621 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
622 | 622 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
623 | 623 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
624 | 624 | minHei = self.dataOut.heightList[0] |
|
625 | 625 | |
|
626 | 626 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
627 | 627 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
628 | 628 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
629 | 629 | maxHei = self.dataOut.heightList[-1] |
|
630 | 630 | |
|
631 | 631 | # validacion de velocidades |
|
632 | 632 | velrange = self.dataOut.getVelRange(1) |
|
633 | 633 | |
|
634 | 634 | if minVel == None: |
|
635 | 635 | minVel = velrange[0] |
|
636 | 636 | |
|
637 | 637 | if maxVel == None: |
|
638 | 638 | maxVel = velrange[-1] |
|
639 | 639 | |
|
640 | 640 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
641 | 641 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
642 | 642 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
643 | 643 | minVel = velrange[0] |
|
644 | 644 | |
|
645 | 645 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
646 | 646 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
647 | 647 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
648 | 648 | maxVel = velrange[-1] |
|
649 | 649 | |
|
650 | 650 | # seleccion de indices para rango |
|
651 | 651 | minIndex = 0 |
|
652 | 652 | maxIndex = 0 |
|
653 | 653 | heights = self.dataOut.heightList |
|
654 | 654 | |
|
655 | 655 | inda = numpy.where(heights >= minHei) |
|
656 | 656 | indb = numpy.where(heights <= maxHei) |
|
657 | 657 | |
|
658 | 658 | try: |
|
659 | 659 | minIndex = inda[0][0] |
|
660 | 660 | except: |
|
661 | 661 | minIndex = 0 |
|
662 | 662 | |
|
663 | 663 | try: |
|
664 | 664 | maxIndex = indb[0][-1] |
|
665 | 665 | except: |
|
666 | 666 | maxIndex = len(heights) |
|
667 | 667 | |
|
668 | 668 | if (minIndex < 0) or (minIndex > maxIndex): |
|
669 | 669 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
670 | 670 | |
|
671 | 671 | if (maxIndex >= self.dataOut.nHeights): |
|
672 | 672 | maxIndex = self.dataOut.nHeights-1 |
|
673 | 673 | |
|
674 | 674 | # seleccion de indices para velocidades |
|
675 | 675 | indminvel = numpy.where(velrange >= minVel) |
|
676 | 676 | indmaxvel = numpy.where(velrange <= maxVel) |
|
677 | 677 | try: |
|
678 | 678 | minIndexVel = indminvel[0][0] |
|
679 | 679 | except: |
|
680 | 680 | minIndexVel = 0 |
|
681 | 681 | |
|
682 | 682 | try: |
|
683 | 683 | maxIndexVel = indmaxvel[0][-1] |
|
684 | 684 | except: |
|
685 | 685 | maxIndexVel = len(velrange) |
|
686 | 686 | |
|
687 | 687 | #seleccion del espectro |
|
688 | 688 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
689 | 689 | #estimacion de ruido |
|
690 | 690 | noise = numpy.zeros(self.dataOut.nChannels) |
|
691 | 691 | |
|
692 | 692 | for channel in range(self.dataOut.nChannels): |
|
693 | 693 | daux = data_spc[channel,:,:] |
|
694 | 694 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
695 | 695 | |
|
696 | 696 | self.dataOut.noise_estimation = noise.copy() |
|
697 | 697 | |
|
698 | 698 | return 1 |
|
699 | 699 | |
|
700 | 700 | class IncohInt(Operation): |
|
701 | 701 | |
|
702 | 702 | |
|
703 | 703 | __profIndex = 0 |
|
704 | 704 | __withOverapping = False |
|
705 | 705 | |
|
706 | 706 | __byTime = False |
|
707 | 707 | __initime = None |
|
708 | 708 | __lastdatatime = None |
|
709 | 709 | __integrationtime = None |
|
710 | 710 | |
|
711 | 711 | __buffer_spc = None |
|
712 | 712 | __buffer_cspc = None |
|
713 | 713 | __buffer_dc = None |
|
714 | 714 | |
|
715 | 715 | __dataReady = False |
|
716 | 716 | |
|
717 | 717 | __timeInterval = None |
|
718 | 718 | |
|
719 | 719 | n = None |
|
720 | 720 | |
|
721 | 721 | |
|
722 | 722 | |
|
723 | 723 | def __init__(self): |
|
724 | 724 | |
|
725 | 725 | Operation.__init__(self) |
|
726 | 726 | # self.isConfig = False |
|
727 | 727 | |
|
728 | 728 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
729 | 729 | """ |
|
730 | 730 | Set the parameters of the integration class. |
|
731 | 731 | |
|
732 | 732 | Inputs: |
|
733 | 733 | |
|
734 | 734 | n : Number of coherent integrations |
|
735 | 735 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
736 | 736 | overlapping : |
|
737 | 737 | |
|
738 | 738 | """ |
|
739 | 739 | |
|
740 | 740 | self.__initime = None |
|
741 | 741 | self.__lastdatatime = 0 |
|
742 | 742 | self.__buffer_spc = None |
|
743 | 743 | self.__buffer_cspc = None |
|
744 | 744 | self.__buffer_dc = None |
|
745 | 745 | self.__dataReady = False |
|
746 | 746 | |
|
747 | 747 | |
|
748 | 748 | if n == None and timeInterval == None: |
|
749 | 749 | raise ValueError, "n or timeInterval should be specified ..." |
|
750 | 750 | |
|
751 | 751 | if n != None: |
|
752 | 752 | self.n = n |
|
753 | 753 | self.__byTime = False |
|
754 | 754 | else: |
|
755 | 755 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
756 | 756 | self.n = 9999 |
|
757 | 757 | self.__byTime = True |
|
758 | 758 | |
|
759 | 759 | if overlapping: |
|
760 | 760 | self.__withOverapping = True |
|
761 | 761 | else: |
|
762 | 762 | self.__withOverapping = False |
|
763 | 763 | self.__buffer_spc = 0 |
|
764 | 764 | self.__buffer_cspc = 0 |
|
765 | 765 | self.__buffer_dc = 0 |
|
766 | 766 | |
|
767 | 767 | self.__profIndex = 0 |
|
768 | 768 | |
|
769 | 769 | def putData(self, data_spc, data_cspc, data_dc): |
|
770 | 770 | |
|
771 | 771 | """ |
|
772 | 772 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
773 | 773 | |
|
774 | 774 | """ |
|
775 | 775 | |
|
776 | 776 | if not self.__withOverapping: |
|
777 | 777 | self.__buffer_spc += data_spc |
|
778 | 778 | |
|
779 | 779 | if data_cspc is None: |
|
780 | 780 | self.__buffer_cspc = None |
|
781 | 781 | else: |
|
782 | 782 | self.__buffer_cspc += data_cspc |
|
783 | 783 | |
|
784 | 784 | if data_dc is None: |
|
785 | 785 | self.__buffer_dc = None |
|
786 | 786 | else: |
|
787 | 787 | self.__buffer_dc += data_dc |
|
788 | 788 | |
|
789 | 789 | self.__profIndex += 1 |
|
790 | 790 | return |
|
791 | 791 | |
|
792 | 792 | #Overlapping data |
|
793 | 793 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
794 | 794 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
795 |
if data_cspc |
|
|
795 | if data_cspc is not None: | |
|
796 | 796 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
797 |
if data_dc |
|
|
797 | if data_dc is not None: | |
|
798 | 798 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
799 | 799 | |
|
800 | 800 | #If the buffer is empty then it takes the data value |
|
801 | 801 | if self.__buffer_spc is None: |
|
802 | 802 | self.__buffer_spc = data_spc |
|
803 | 803 | |
|
804 | 804 | if data_cspc is None: |
|
805 | 805 | self.__buffer_cspc = None |
|
806 | 806 | else: |
|
807 | 807 | self.__buffer_cspc += data_cspc |
|
808 | 808 | |
|
809 | 809 | if data_dc is None: |
|
810 | 810 | self.__buffer_dc = None |
|
811 | 811 | else: |
|
812 | 812 | self.__buffer_dc += data_dc |
|
813 | 813 | |
|
814 | 814 | self.__profIndex += 1 |
|
815 | 815 | return |
|
816 | 816 | |
|
817 | 817 | #If the buffer length is lower than n then stakcing the data value |
|
818 | 818 | if self.__profIndex < self.n: |
|
819 | 819 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
820 | 820 | |
|
821 |
if data_cspc |
|
|
821 | if data_cspc is not None: | |
|
822 | 822 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
823 | 823 | |
|
824 |
if data_dc |
|
|
824 | if data_dc is not None: | |
|
825 | 825 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
826 | 826 | |
|
827 | 827 | self.__profIndex += 1 |
|
828 | 828 | return |
|
829 | 829 | |
|
830 | 830 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
831 | 831 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
832 | 832 | self.__buffer_spc[self.n-1] = data_spc |
|
833 | 833 | |
|
834 |
if data_cspc |
|
|
834 | if data_cspc is not None: | |
|
835 | 835 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
836 | 836 | self.__buffer_cspc[self.n-1] = data_cspc |
|
837 | 837 | |
|
838 |
if data_dc |
|
|
838 | if data_dc is not None: | |
|
839 | 839 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
840 | 840 | self.__buffer_dc[self.n-1] = data_dc |
|
841 | 841 | |
|
842 | 842 | self.__profIndex = self.n |
|
843 | 843 | return |
|
844 | 844 | |
|
845 | 845 | |
|
846 | 846 | def pushData(self): |
|
847 | 847 | """ |
|
848 | 848 | Return the sum of the last profiles and the profiles used in the sum. |
|
849 | 849 | |
|
850 | 850 | Affected: |
|
851 | 851 | |
|
852 | 852 | self.__profileIndex |
|
853 | 853 | |
|
854 | 854 | """ |
|
855 | 855 | data_spc = None |
|
856 | 856 | data_cspc = None |
|
857 | 857 | data_dc = None |
|
858 | 858 | |
|
859 | 859 | if not self.__withOverapping: |
|
860 | 860 | data_spc = self.__buffer_spc |
|
861 | 861 | data_cspc = self.__buffer_cspc |
|
862 | 862 | data_dc = self.__buffer_dc |
|
863 | 863 | |
|
864 | 864 | n = self.__profIndex |
|
865 | 865 | |
|
866 | 866 | self.__buffer_spc = 0 |
|
867 | 867 | self.__buffer_cspc = 0 |
|
868 | 868 | self.__buffer_dc = 0 |
|
869 | 869 | self.__profIndex = 0 |
|
870 | 870 | |
|
871 | 871 | return data_spc, data_cspc, data_dc, n |
|
872 | 872 | |
|
873 | 873 | #Integration with Overlapping |
|
874 | 874 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
875 | 875 | |
|
876 |
if self.__buffer_cspc |
|
|
876 | if self.__buffer_cspc is not None: | |
|
877 | 877 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
878 | 878 | |
|
879 |
if self.__buffer_dc |
|
|
879 | if self.__buffer_dc is not None: | |
|
880 | 880 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
881 | 881 | |
|
882 | 882 | n = self.__profIndex |
|
883 | 883 | |
|
884 | 884 | return data_spc, data_cspc, data_dc, n |
|
885 | 885 | |
|
886 | 886 | def byProfiles(self, *args): |
|
887 | 887 | |
|
888 | 888 | self.__dataReady = False |
|
889 | 889 | avgdata_spc = None |
|
890 | 890 | avgdata_cspc = None |
|
891 | 891 | avgdata_dc = None |
|
892 | 892 | # n = None |
|
893 | 893 | |
|
894 | 894 | self.putData(*args) |
|
895 | 895 | |
|
896 | 896 | if self.__profIndex == self.n: |
|
897 | 897 | |
|
898 | 898 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
899 | 899 | self.__dataReady = True |
|
900 | 900 | |
|
901 | 901 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
902 | 902 | |
|
903 | 903 | def byTime(self, datatime, *args): |
|
904 | 904 | |
|
905 | 905 | self.__dataReady = False |
|
906 | 906 | avgdata_spc = None |
|
907 | 907 | avgdata_cspc = None |
|
908 | 908 | avgdata_dc = None |
|
909 | 909 | n = None |
|
910 | 910 | |
|
911 | 911 | self.putData(*args) |
|
912 | 912 | |
|
913 | 913 | if (datatime - self.__initime) >= self.__integrationtime: |
|
914 | 914 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
915 | 915 | self.n = n |
|
916 | 916 | self.__dataReady = True |
|
917 | 917 | |
|
918 | 918 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
919 | 919 | |
|
920 | 920 | def integrate(self, datatime, *args): |
|
921 | 921 | |
|
922 | 922 | if self.__initime == None: |
|
923 | 923 | self.__initime = datatime |
|
924 | 924 | |
|
925 | 925 | if self.__byTime: |
|
926 | 926 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
927 | 927 | else: |
|
928 | 928 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
929 | 929 | |
|
930 | 930 | self.__lastdatatime = datatime |
|
931 | 931 | |
|
932 | 932 | if avgdata_spc is None: |
|
933 | 933 | return None, None, None, None |
|
934 | 934 | |
|
935 | 935 | avgdatatime = self.__initime |
|
936 | 936 | try: |
|
937 | 937 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
938 | 938 | except: |
|
939 | 939 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
940 | 940 | |
|
941 | 941 | deltatime = datatime -self.__lastdatatime |
|
942 | 942 | |
|
943 | 943 | if not self.__withOverapping: |
|
944 | 944 | self.__initime = datatime |
|
945 | 945 | else: |
|
946 | 946 | self.__initime += deltatime |
|
947 | 947 | |
|
948 | 948 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
949 | 949 | |
|
950 | 950 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
951 | 951 | |
|
952 | 952 | if n==1: |
|
953 | 953 | dataOut.flagNoData = False |
|
954 | 954 | return |
|
955 | 955 | |
|
956 | 956 | if not self.isConfig: |
|
957 | 957 | self.setup(n, timeInterval, overlapping) |
|
958 | 958 | self.isConfig = True |
|
959 | 959 | |
|
960 | 960 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
961 | 961 | dataOut.data_spc, |
|
962 | 962 | dataOut.data_cspc, |
|
963 | 963 | dataOut.data_dc) |
|
964 | 964 | |
|
965 | 965 | # dataOut.timeInterval *= n |
|
966 | 966 | dataOut.flagNoData = True |
|
967 | 967 | |
|
968 | 968 | if self.__dataReady: |
|
969 | 969 | |
|
970 | 970 | dataOut.data_spc = avgdata_spc |
|
971 | 971 | dataOut.data_cspc = avgdata_cspc |
|
972 | 972 | dataOut.data_dc = avgdata_dc |
|
973 | 973 | |
|
974 | 974 | dataOut.nIncohInt *= self.n |
|
975 | 975 | dataOut.utctime = avgdatatime |
|
976 | 976 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
977 | 977 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
978 | 978 | dataOut.flagNoData = False |
@@ -1,31 +1,31 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 16, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | from distutils.core import setup, Extension |
|
8 | 8 | |
|
9 | 9 | setup(name="schainpy", |
|
10 | version="2.0", | |
|
10 | version="2.1.0", | |
|
11 | 11 | description="Python tools to read, write and process Jicamarca data", |
|
12 | 12 | author="Miguel Urco", |
|
13 | 13 | author_email="miguel.urco@jro.igp.gob.pe", |
|
14 | 14 | url="http://jro.igp.gob.pe", |
|
15 | 15 | packages = {'schainpy', |
|
16 | 16 | 'schainpy.model', |
|
17 | 17 | 'schainpy.model.data', |
|
18 | 18 | 'schainpy.model.graphics', |
|
19 | 19 | 'schainpy.model.io', |
|
20 | 20 | 'schainpy.model.proc', |
|
21 | 21 | 'schainpy.model.utils', |
|
22 | 22 | 'schainpy.gui', |
|
23 | 23 | 'schainpy.gui.figures', |
|
24 | 24 | 'schainpy.gui.viewcontroller', |
|
25 | 25 | 'schainpy.gui.viewer', |
|
26 | 26 | 'schainpy.gui.viewer.windows'}, |
|
27 | 27 | py_modules=['schainpy.serializer.DataTranslate', |
|
28 | 28 | 'schainpy.serializer.JROSerializer'], |
|
29 | 29 | package_data={'schainpy.gui.figures': ['*.jpg', '*.jpeg', '*.png', '*.gif']}, |
|
30 | 30 | include_package_data=True, |
|
31 | 31 | scripts =['schainpy/gui/schainGUI']) No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now