##// END OF EJS Templates
RTI plots only last channel with 'Time' label
joabAM -
r1592:60f9ebea7e3b
parent child
Show More
@@ -1,1464 +1,1470
1 1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 2 # All rights reserved.
3 3 #
4 4 # Distributed under the terms of the BSD 3-clause license.
5 5 """Classes to plot Spectra data
6 6
7 7 """
8 8
9 9 import os
10 10 import numpy
11 11
12 12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
13 13 from itertools import combinations
14 14 from matplotlib.ticker import LinearLocator
15 15
16 16 from matplotlib import __version__ as plt_version
17 17
18 18 if plt_version >='3.3.4':
19 19 EXTRA_POINTS = 0
20 20 else:
21 21 EXTRA_POINTS = 1
22 22
23 23 class SpectraPlot(Plot):
24 24 '''
25 25 Plot for Spectra data
26 26 '''
27 27
28 28 CODE = 'spc'
29 29 colormap = 'jet'
30 30 plot_type = 'pcolor'
31 31 buffering = False
32 32 channelList = []
33 33 elevationList = []
34 34 azimuthList = []
35 35
36 36 def setup(self):
37 37
38 38 self.nplots = len(self.data.channels)
39 39 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
40 40 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
41 41 self.height = 3.4 * self.nrows
42 42
43 43 self.cb_label = 'dB'
44 44 if self.showprofile:
45 45 self.width = 5.2 * self.ncols
46 46 else:
47 47 self.width = 4.2* self.ncols
48 48 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.12})
49 49 self.ylabel = 'Range [km]'
50 50
51 51
52 52 def update_list(self,dataOut):
53 53 if len(self.channelList) == 0:
54 54 self.channelList = dataOut.channelList
55 55 if len(self.elevationList) == 0:
56 56 self.elevationList = dataOut.elevationList
57 57 if len(self.azimuthList) == 0:
58 58 self.azimuthList = dataOut.azimuthList
59 59
60 60 def update(self, dataOut):
61 61
62 62 self.update_list(dataOut)
63 63 data = {}
64 64 meta = {}
65 65
66 66 #data['rti'] = dataOut.getPower()
67 67 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
68 68 noise = 10*numpy.log10(dataOut.getNoise()/norm)
69 69
70 70
71 71 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
72 72 for ch in range(dataOut.nChannels):
73 73 if hasattr(dataOut.normFactor,'ndim'):
74 74 if dataOut.normFactor.ndim > 1:
75 75 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
76 76
77 77 else:
78 78 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
79 79 else:
80 80 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
81 81
82 82
83 83 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
84 84 spc = 10*numpy.log10(z)
85 85
86 86 data['spc'] = spc
87 87 #print(spc[0].shape)
88 88 data['rti'] = spc.mean(axis=1)
89 89 data['noise'] = noise
90 90 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
91 91 if self.CODE == 'spc_moments':
92 92 data['moments'] = dataOut.moments
93 93
94 94 return data, meta
95 95
96 96 def plot(self):
97 97 if self.xaxis == "frequency":
98 98 x = self.data.xrange[0]
99 99 self.xlabel = "Frequency (kHz)"
100 100 elif self.xaxis == "time":
101 101 x = self.data.xrange[1]
102 102 self.xlabel = "Time (ms)"
103 103 else:
104 104 x = self.data.xrange[2]
105 105 self.xlabel = "Velocity (m/s)"
106 106
107 107 if self.CODE == 'spc_moments':
108 108 x = self.data.xrange[2]
109 109 self.xlabel = "Velocity (m/s)"
110 110
111 111 self.titles = []
112 112 y = self.data.yrange
113 113 self.y = y
114 114
115 115 data = self.data[-1]
116 116 z = data['spc']
117 117 #print(z.shape, x.shape, y.shape)
118 118 for n, ax in enumerate(self.axes):
119 119 noise = self.data['noise'][n][0]
120 120 #print(noise)
121 121 if self.CODE == 'spc_moments':
122 122 mean = data['moments'][n, 1]
123 123 if ax.firsttime:
124 124 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
125 125 self.xmin = self.xmin if self.xmin else -self.xmax
126 126 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
127 127 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
128 128 ax.plt = ax.pcolormesh(x, y, z[n].T,
129 129 vmin=self.zmin,
130 130 vmax=self.zmax,
131 131 cmap=plt.get_cmap(self.colormap)
132 132 )
133 133
134 134 if self.showprofile:
135 135 ax.plt_profile = self.pf_axes[n].plot(
136 136 data['rti'][n], y)[0]
137 137 # ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
138 138 # color="k", linestyle="dashed", lw=1)[0]
139 139 if self.CODE == 'spc_moments':
140 140 ax.plt_mean = ax.plot(mean, y, color='k')[0]
141 141 else:
142 142 ax.plt.set_array(z[n].T.ravel())
143 143 if self.showprofile:
144 144 ax.plt_profile.set_data(data['rti'][n], y)
145 145 #ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
146 146 if self.CODE == 'spc_moments':
147 147 ax.plt_mean.set_data(mean, y)
148 148 if len(self.azimuthList) > 0 and len(self.elevationList) > 0:
149 149 self.titles.append('CH {}: {:2.1f}elv {:2.1f}az {:3.2f}dB'.format(self.channelList[n], noise, self.elevationList[n], self.azimuthList[n]))
150 150 else:
151 151 self.titles.append('CH {}: {:3.2f}dB'.format(self.channelList[n], noise))
152 152
153 153
154 154 class CrossSpectraPlot(Plot):
155 155
156 156 CODE = 'cspc'
157 157 colormap = 'jet'
158 158 plot_type = 'pcolor'
159 159 zmin_coh = None
160 160 zmax_coh = None
161 161 zmin_phase = None
162 162 zmax_phase = None
163 163 realChannels = None
164 164 crossPairs = None
165 165
166 166 def setup(self):
167 167
168 168 self.ncols = 4
169 169 self.nplots = len(self.data.pairs) * 2
170 170 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
171 171 self.width = 3.1 * self.ncols
172 172 self.height = 2.6 * self.nrows
173 173 self.ylabel = 'Range [km]'
174 174 self.showprofile = False
175 175 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
176 176
177 177 def update(self, dataOut):
178 178
179 179 data = {}
180 180 meta = {}
181 181
182 182 spc = dataOut.data_spc
183 183 cspc = dataOut.data_cspc
184 184 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
185 185 rawPairs = list(combinations(list(range(dataOut.nChannels)), 2))
186 186 meta['pairs'] = rawPairs
187 187
188 188 if self.crossPairs == None:
189 189 self.crossPairs = dataOut.pairsList
190 190
191 191 tmp = []
192 192
193 193 for n, pair in enumerate(meta['pairs']):
194 194
195 195 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
196 196 coh = numpy.abs(out)
197 197 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
198 198 tmp.append(coh)
199 199 tmp.append(phase)
200 200
201 201 data['cspc'] = numpy.array(tmp)
202 202
203 203 return data, meta
204 204
205 205 def plot(self):
206 206
207 207 if self.xaxis == "frequency":
208 208 x = self.data.xrange[0]
209 209 self.xlabel = "Frequency (kHz)"
210 210 elif self.xaxis == "time":
211 211 x = self.data.xrange[1]
212 212 self.xlabel = "Time (ms)"
213 213 else:
214 214 x = self.data.xrange[2]
215 215 self.xlabel = "Velocity (m/s)"
216 216
217 217 self.titles = []
218 218
219 219 y = self.data.yrange
220 220 self.y = y
221 221
222 222 data = self.data[-1]
223 223 cspc = data['cspc']
224 224
225 225 for n in range(len(self.data.pairs)):
226 226
227 227 pair = self.crossPairs[n]
228 228
229 229 coh = cspc[n*2]
230 230 phase = cspc[n*2+1]
231 231 ax = self.axes[2 * n]
232 232
233 233 if ax.firsttime:
234 234 ax.plt = ax.pcolormesh(x, y, coh.T,
235 235 vmin=self.zmin_coh,
236 236 vmax=self.zmax_coh,
237 237 cmap=plt.get_cmap(self.colormap_coh)
238 238 )
239 239 else:
240 240 ax.plt.set_array(coh.T.ravel())
241 241 self.titles.append(
242 242 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
243 243
244 244 ax = self.axes[2 * n + 1]
245 245 if ax.firsttime:
246 246 ax.plt = ax.pcolormesh(x, y, phase.T,
247 247 vmin=-180,
248 248 vmax=180,
249 249 cmap=plt.get_cmap(self.colormap_phase)
250 250 )
251 251 else:
252 252 ax.plt.set_array(phase.T.ravel())
253 253
254 254 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
255 255
256 256
257 257 class RTIPlot(Plot):
258 258 '''
259 259 Plot for RTI data
260 260 '''
261 261
262 262 CODE = 'rti'
263 263 colormap = 'jet'
264 264 plot_type = 'pcolorbuffer'
265 265 titles = None
266 266 channelList = []
267 267 elevationList = []
268 268 azimuthList = []
269 269
270 270 def setup(self):
271 271 self.xaxis = 'time'
272 272 self.ncols = 1
273 273 #print("dataChannels ",self.data.channels)
274 274 self.nrows = len(self.data.channels)
275 275 self.nplots = len(self.data.channels)
276 276 self.ylabel = 'Range [km]'
277 self.xlabel = 'Time'
277 #self.xlabel = 'Time'
278 278 self.cb_label = 'dB'
279 279 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
280 280 self.titles = ['{} Channel {}'.format(
281 281 self.CODE.upper(), x) for x in range(self.nplots)]
282 282
283 283 def update_list(self,dataOut):
284 284
285 285 if len(self.channelList) == 0:
286 286 self.channelList = dataOut.channelList
287 287 if len(self.elevationList) == 0:
288 288 self.elevationList = dataOut.elevationList
289 289 if len(self.azimuthList) == 0:
290 290 self.azimuthList = dataOut.azimuthList
291 291
292 292
293 293 def update(self, dataOut):
294 294 if len(self.channelList) == 0:
295 295 self.update_list(dataOut)
296 296 data = {}
297 297 meta = {}
298 298
299 299 data['rti'] = dataOut.getPower()
300 300
301 301 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
302 302 noise = 10*numpy.log10(dataOut.getNoise()/norm)
303 303 data['noise'] = noise
304 304
305 305 return data, meta
306 306
307 307 def plot(self):
308 308
309 309 self.x = self.data.times
310 310 self.y = self.data.yrange
311 311 #print(" x, y: ",self.x, self.y)
312 312 self.z = self.data[self.CODE]
313 313 self.z = numpy.array(self.z, dtype=float)
314 314 self.z = numpy.ma.masked_invalid(self.z)
315 315
316 316 try:
317 317 if self.channelList != None:
318 318 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
319 319 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
320 320 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
321 321 else:
322 322 self.titles = ['{} Channel {}'.format(
323 323 self.CODE.upper(), x) for x in self.channelList]
324 324 except:
325 325 if self.channelList.any() != None:
326 326 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
327 327 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
328 328 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
329 329 else:
330 330 self.titles = ['{} Channel {}'.format(
331 331 self.CODE.upper(), x) for x in self.channelList]
332 332
333 333 if self.decimation is None:
334 334 x, y, z = self.fill_gaps(self.x, self.y, self.z)
335 335 else:
336 336 x, y, z = self.fill_gaps(*self.decimate())
337 337
338 338 #dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
339 339 for n, ax in enumerate(self.axes):
340 340 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
341 341 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
342 342 data = self.data[-1]
343 343
344 344 if ax.firsttime:
345 if (n+1) == len(self.channelList):
346 ax.set_xlabel('Time')
345 347 ax.plt = ax.pcolormesh(x, y, z[n].T,
346 348 vmin=self.zmin,
347 349 vmax=self.zmax,
348 350 cmap=plt.get_cmap(self.colormap)
349 351 )
350 352 if self.showprofile:
351 353 ax.plot_profile = self.pf_axes[n].plot(data[self.CODE][n], self.y)[0]
352 354 if "noise" in self.data:
353 355
354 356 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
355 357 color="k", linestyle="dashed", lw=1)[0]
356 358 else:
357 359 ax.collections.remove(ax.collections[0])
358 360 ax.plt = ax.pcolormesh(x, y, z[n].T,
359 361 vmin=self.zmin,
360 362 vmax=self.zmax,
361 363 cmap=plt.get_cmap(self.colormap)
362 364 )
363 365 if self.showprofile:
364 366 ax.plot_profile.set_data(data[self.CODE][n], self.y)
365 367 if "noise" in self.data:
366 368 ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
367 369
368 370
369 371 class CoherencePlot(RTIPlot):
370 372 '''
371 373 Plot for Coherence data
372 374 '''
373 375
374 376 CODE = 'coh'
375 377 titles = None
376 378
377 379 def setup(self):
378 380 self.xaxis = 'time'
379 381 self.ncols = 1
380 382 self.nrows = len(self.data.pairs)
381 383 self.nplots = len(self.data.pairs)
382 384 self.ylabel = 'Range [km]'
383 self.xlabel = 'Time'
385 #self.xlabel = 'Time'
384 386 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
385 387 if self.CODE == 'coh':
386 388 self.cb_label = ''
387 389 self.titles = [
388 390 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
389 391 else:
390 392 self.cb_label = 'Degrees'
391 393 self.titles = [
392 394 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
393 395
394 396
395 397 def update(self, dataOut):
396 398
397 399 data = {}
398 400 meta = {}
399 401 data['coh'] = dataOut.getCoherence()
400 402 meta['pairs'] = dataOut.pairsList
401 403
402 404
403 405 return data, meta
404 406
405 407 def plot(self):
406 408
407 409 self.x = self.data.times
408 410 self.y = self.data.yrange
409 411 self.z = self.data[self.CODE]
410 412
411 413 self.z = numpy.ma.masked_invalid(self.z)
412 414
413 415 if self.decimation is None:
414 416 x, y, z = self.fill_gaps(self.x, self.y, self.z)
415 417 else:
416 418 x, y, z = self.fill_gaps(*self.decimate())
417 419
418 420 for n, ax in enumerate(self.axes):
419 421 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
420 422 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
421 423 if ax.firsttime:
424 if (n+1) == len(self.channelList):
425 ax.set_xlabel('Time')
422 426 ax.plt = ax.pcolormesh(x, y, z[n].T,
423 427 vmin=self.zmin,
424 428 vmax=self.zmax,
425 429 cmap=plt.get_cmap(self.colormap)
426 430 )
427 431 if self.showprofile:
428 432 ax.plot_profile = self.pf_axes[n].plot(
429 433 self.data[self.CODE][n][-1], self.y)[0]
430 434 # ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
431 435 # color="k", linestyle="dashed", lw=1)[0]
432 436 else:
433 437 ax.collections.remove(ax.collections[0])
434 438 ax.plt = ax.pcolormesh(x, y, z[n].T,
435 439 vmin=self.zmin,
436 440 vmax=self.zmax,
437 441 cmap=plt.get_cmap(self.colormap)
438 442 )
439 443 if self.showprofile:
440 444 ax.plot_profile.set_data(self.data[self.CODE][n][-1], self.y)
441 445 # ax.plot_noise.set_data(numpy.repeat(
442 446 # self.data['noise'][n][-1], len(self.y)), self.y)
443 447
444 448
445 449
446 450 class PhasePlot(CoherencePlot):
447 451 '''
448 452 Plot for Phase map data
449 453 '''
450 454
451 455 CODE = 'phase'
452 456 colormap = 'seismic'
453 457
454 458 def update(self, dataOut):
455 459
456 460 data = {}
457 461 meta = {}
458 462 data['phase'] = dataOut.getCoherence(phase=True)
459 463 meta['pairs'] = dataOut.pairsList
460 464
461 465 return data, meta
462 466
463 467 class NoisePlot(Plot):
464 468 '''
465 469 Plot for noise
466 470 '''
467 471
468 472 CODE = 'noise'
469 473 plot_type = 'scatterbuffer'
470 474
471 475 def setup(self):
472 476 self.xaxis = 'time'
473 477 self.ncols = 1
474 478 self.nrows = 1
475 479 self.nplots = 1
476 480 self.ylabel = 'Intensity [dB]'
477 481 self.xlabel = 'Time'
478 482 self.titles = ['Noise']
479 483 self.colorbar = False
480 484 self.plots_adjust.update({'right': 0.85 })
481 485 #if not self.titles:
482 486 self.titles = ['Noise Plot']
483 487
484 488 def update(self, dataOut):
485 489
486 490 data = {}
487 491 meta = {}
488 492 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
489 493 noise = 10*numpy.log10(dataOut.getNoise())
490 494 noise = noise.reshape(dataOut.nChannels, 1)
491 495 data['noise'] = noise
492 496 meta['yrange'] = numpy.array([])
493 497
494 498 return data, meta
495 499
496 500 def plot(self):
497 501
498 502 x = self.data.times
499 503 xmin = self.data.min_time
500 504 xmax = xmin + self.xrange * 60 * 60
501 505 Y = self.data['noise']
502 506
503 507 if self.axes[0].firsttime:
504 508 if self.ymin is None: self.ymin = numpy.nanmin(Y) - 5
505 509 if self.ymax is None: self.ymax = numpy.nanmax(Y) + 5
506 510 for ch in self.data.channels:
507 511 y = Y[ch]
508 512 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
509 513 plt.legend(bbox_to_anchor=(1.18, 1.0))
510 514 else:
511 515 for ch in self.data.channels:
512 516 y = Y[ch]
513 517 self.axes[0].lines[ch].set_data(x, y)
514 518
515 519
516 520 class PowerProfilePlot(Plot):
517 521
518 522 CODE = 'pow_profile'
519 523 plot_type = 'scatter'
520 524
521 525 def setup(self):
522 526
523 527 self.ncols = 1
524 528 self.nrows = 1
525 529 self.nplots = 1
526 530 self.height = 4
527 531 self.width = 3
528 532 self.ylabel = 'Range [km]'
529 533 self.xlabel = 'Intensity [dB]'
530 534 self.titles = ['Power Profile']
531 535 self.colorbar = False
532 536
533 537 def update(self, dataOut):
534 538
535 539 data = {}
536 540 meta = {}
537 541 data[self.CODE] = dataOut.getPower()
538 542
539 543 return data, meta
540 544
541 545 def plot(self):
542 546
543 547 y = self.data.yrange
544 548 self.y = y
545 549
546 550 x = self.data[-1][self.CODE]
547 551
548 552 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
549 553 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
550 554
551 555 if self.axes[0].firsttime:
552 556 for ch in self.data.channels:
553 557 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
554 558 plt.legend()
555 559 else:
556 560 for ch in self.data.channels:
557 561 self.axes[0].lines[ch].set_data(x[ch], y)
558 562
559 563
560 564 class SpectraCutPlot(Plot):
561 565
562 566 CODE = 'spc_cut'
563 567 plot_type = 'scatter'
564 568 buffering = False
565 569 heights = []
566 570 channelList = []
567 571 maintitle = "Spectra Cuts"
568 572 flag_setIndex = False
569 573
570 574 def setup(self):
571 575
572 576 self.nplots = len(self.data.channels)
573 577 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
574 578 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
575 579 self.width = 4.5 * self.ncols + 2.5
576 580 self.height = 4.8 * self.nrows
577 581 self.ylabel = 'Power [dB]'
578 582 self.colorbar = False
579 583 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.9, 'bottom':0.08})
580 584
581 585 if len(self.selectedHeightsList) > 0:
582 586 self.maintitle = "Spectra Cut"# for %d km " %(int(self.selectedHeight))
583 587
584 588
585 589
586 590 def update(self, dataOut):
587 591 if len(self.channelList) == 0:
588 592 self.channelList = dataOut.channelList
589 593
590 594 self.heights = dataOut.heightList
591 595 #print("sels: ",self.selectedHeightsList)
592 596 if len(self.selectedHeightsList)>0 and not self.flag_setIndex:
593 597
594 598 for sel_height in self.selectedHeightsList:
595 599 index_list = numpy.where(self.heights >= sel_height)
596 600 index_list = index_list[0]
597 601 self.height_index.append(index_list[0])
598 602 #print("sels i:"", self.height_index)
599 603 self.flag_setIndex = True
600 604 #print(self.height_index)
601 605 data = {}
602 606 meta = {}
603 607
604 608 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter#*dataOut.nFFTPoints
605 609 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
606 610 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
607 611
608 612
609 613 z = []
610 614 for ch in range(dataOut.nChannels):
611 615 if hasattr(dataOut.normFactor,'shape'):
612 616 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
613 617 else:
614 618 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
615 619
616 620 z = numpy.asarray(z)
617 621 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
618 622 spc = 10*numpy.log10(z)
619 623
620 624
621 625 data['spc'] = spc - noise
622 626 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
623 627
624 628 return data, meta
625 629
626 630 def plot(self):
627 631 if self.xaxis == "frequency":
628 632 x = self.data.xrange[0][1:]
629 633 self.xlabel = "Frequency (kHz)"
630 634 elif self.xaxis == "time":
631 635 x = self.data.xrange[1]
632 636 self.xlabel = "Time (ms)"
633 637 else:
634 638 x = self.data.xrange[2]
635 639 self.xlabel = "Velocity (m/s)"
636 640
637 641 self.titles = []
638 642
639 643 y = self.data.yrange
640 644 z = self.data[-1]['spc']
641 645 #print(z.shape)
642 646 if len(self.height_index) > 0:
643 647 index = self.height_index
644 648 else:
645 649 index = numpy.arange(0, len(y), int((len(y))/9))
646 650 #print("inde x ", index, self.axes)
647 651
648 652 for n, ax in enumerate(self.axes):
649 653
650 654 if ax.firsttime:
651 655
652 656
653 657 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
654 658 self.xmin = self.xmin if self.xmin else -self.xmax
655 659 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
656 660 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
657 661
658 662
659 663 ax.plt = ax.plot(x, z[n, :, index].T)
660 664 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
661 665 self.figures[0].legend(ax.plt, labels, loc='center right', prop={'size': 8})
662 666 ax.minorticks_on()
663 667 ax.grid(which='major', axis='both')
664 668 ax.grid(which='minor', axis='x')
665 669 else:
666 670 for i, line in enumerate(ax.plt):
667 671 line.set_data(x, z[n, :, index[i]])
668 672
669 673
670 674 self.titles.append('CH {}'.format(self.channelList[n]))
671 675 plt.suptitle(self.maintitle, fontsize=10)
672 676
673 677
674 678 class BeaconPhase(Plot):
675 679
676 680 __isConfig = None
677 681 __nsubplots = None
678 682
679 683 PREFIX = 'beacon_phase'
680 684
681 685 def __init__(self):
682 686 Plot.__init__(self)
683 687 self.timerange = 24*60*60
684 688 self.isConfig = False
685 689 self.__nsubplots = 1
686 690 self.counter_imagwr = 0
687 691 self.WIDTH = 800
688 692 self.HEIGHT = 400
689 693 self.WIDTHPROF = 120
690 694 self.HEIGHTPROF = 0
691 695 self.xdata = None
692 696 self.ydata = None
693 697
694 698 self.PLOT_CODE = BEACON_CODE
695 699
696 700 self.FTP_WEI = None
697 701 self.EXP_CODE = None
698 702 self.SUB_EXP_CODE = None
699 703 self.PLOT_POS = None
700 704
701 705 self.filename_phase = None
702 706
703 707 self.figfile = None
704 708
705 709 self.xmin = None
706 710 self.xmax = None
707 711
708 712 def getSubplots(self):
709 713
710 714 ncol = 1
711 715 nrow = 1
712 716
713 717 return nrow, ncol
714 718
715 719 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
716 720
717 721 self.__showprofile = showprofile
718 722 self.nplots = nplots
719 723
720 724 ncolspan = 7
721 725 colspan = 6
722 726 self.__nsubplots = 2
723 727
724 728 self.createFigure(id = id,
725 729 wintitle = wintitle,
726 730 widthplot = self.WIDTH+self.WIDTHPROF,
727 731 heightplot = self.HEIGHT+self.HEIGHTPROF,
728 732 show=show)
729 733
730 734 nrow, ncol = self.getSubplots()
731 735
732 736 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
733 737
734 738 def save_phase(self, filename_phase):
735 739 f = open(filename_phase,'w+')
736 740 f.write('\n\n')
737 741 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
738 742 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
739 743 f.close()
740 744
741 745 def save_data(self, filename_phase, data, data_datetime):
742 746 f=open(filename_phase,'a')
743 747 timetuple_data = data_datetime.timetuple()
744 748 day = str(timetuple_data.tm_mday)
745 749 month = str(timetuple_data.tm_mon)
746 750 year = str(timetuple_data.tm_year)
747 751 hour = str(timetuple_data.tm_hour)
748 752 minute = str(timetuple_data.tm_min)
749 753 second = str(timetuple_data.tm_sec)
750 754 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
751 755 f.close()
752 756
753 757 def plot(self):
754 758 log.warning('TODO: Not yet implemented...')
755 759
756 760 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
757 761 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
758 762 timerange=None,
759 763 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
760 764 server=None, folder=None, username=None, password=None,
761 765 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
762 766
763 767 if dataOut.flagNoData:
764 768 return dataOut
765 769
766 770 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
767 771 return
768 772
769 773 if pairsList == None:
770 774 pairsIndexList = dataOut.pairsIndexList[:10]
771 775 else:
772 776 pairsIndexList = []
773 777 for pair in pairsList:
774 778 if pair not in dataOut.pairsList:
775 779 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
776 780 pairsIndexList.append(dataOut.pairsList.index(pair))
777 781
778 782 if pairsIndexList == []:
779 783 return
780 784
781 785 # if len(pairsIndexList) > 4:
782 786 # pairsIndexList = pairsIndexList[0:4]
783 787
784 788 hmin_index = None
785 789 hmax_index = None
786 790
787 791 if hmin != None and hmax != None:
788 792 indexes = numpy.arange(dataOut.nHeights)
789 793 hmin_list = indexes[dataOut.heightList >= hmin]
790 794 hmax_list = indexes[dataOut.heightList <= hmax]
791 795
792 796 if hmin_list.any():
793 797 hmin_index = hmin_list[0]
794 798
795 799 if hmax_list.any():
796 800 hmax_index = hmax_list[-1]+1
797 801
798 802 x = dataOut.getTimeRange()
799 803
800 804 thisDatetime = dataOut.datatime
801 805
802 806 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
803 807 xlabel = "Local Time"
804 808 ylabel = "Phase (degrees)"
805 809
806 810 update_figfile = False
807 811
808 812 nplots = len(pairsIndexList)
809 813 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
810 814 phase_beacon = numpy.zeros(len(pairsIndexList))
811 815 for i in range(nplots):
812 816 pair = dataOut.pairsList[pairsIndexList[i]]
813 817 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
814 818 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
815 819 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
816 820 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
817 821 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
818 822
819 823 if dataOut.beacon_heiIndexList:
820 824 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
821 825 else:
822 826 phase_beacon[i] = numpy.average(phase)
823 827
824 828 if not self.isConfig:
825 829
826 830 nplots = len(pairsIndexList)
827 831
828 832 self.setup(id=id,
829 833 nplots=nplots,
830 834 wintitle=wintitle,
831 835 showprofile=showprofile,
832 836 show=show)
833 837
834 838 if timerange != None:
835 839 self.timerange = timerange
836 840
837 841 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
838 842
839 843 if ymin == None: ymin = 0
840 844 if ymax == None: ymax = 360
841 845
842 846 self.FTP_WEI = ftp_wei
843 847 self.EXP_CODE = exp_code
844 848 self.SUB_EXP_CODE = sub_exp_code
845 849 self.PLOT_POS = plot_pos
846 850
847 851 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
848 852 self.isConfig = True
849 853 self.figfile = figfile
850 854 self.xdata = numpy.array([])
851 855 self.ydata = numpy.array([])
852 856
853 857 update_figfile = True
854 858
855 859 #open file beacon phase
856 860 path = '%s%03d' %(self.PREFIX, self.id)
857 861 beacon_file = os.path.join(path,'%s.txt'%self.name)
858 862 self.filename_phase = os.path.join(figpath,beacon_file)
859 863 #self.save_phase(self.filename_phase)
860 864
861 865
862 866 #store data beacon phase
863 867 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
864 868
865 869 self.setWinTitle(title)
866 870
867 871
868 872 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
869 873
870 874 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
871 875
872 876 axes = self.axesList[0]
873 877
874 878 self.xdata = numpy.hstack((self.xdata, x[0:1]))
875 879
876 880 if len(self.ydata)==0:
877 881 self.ydata = phase_beacon.reshape(-1,1)
878 882 else:
879 883 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
880 884
881 885
882 886 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
883 887 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
884 888 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
885 889 XAxisAsTime=True, grid='both'
886 890 )
887 891
888 892 self.draw()
889 893
890 894 if dataOut.ltctime >= self.xmax:
891 895 self.counter_imagwr = wr_period
892 896 self.isConfig = False
893 897 update_figfile = True
894 898
895 899 self.save(figpath=figpath,
896 900 figfile=figfile,
897 901 save=save,
898 902 ftp=ftp,
899 903 wr_period=wr_period,
900 904 thisDatetime=thisDatetime,
901 905 update_figfile=update_figfile)
902 906
903 907 return dataOut
904 908
905 909 class NoiselessSpectraPlot(Plot):
906 910 '''
907 911 Plot for Spectra data, subtracting
908 912 the noise in all channels, using for
909 913 amisr-14 data
910 914 '''
911 915
912 916 CODE = 'noiseless_spc'
913 917 colormap = 'jet'
914 918 plot_type = 'pcolor'
915 919 buffering = False
916 920 channelList = []
917 921 last_noise = None
918 922
919 923 def setup(self):
920 924
921 925 self.nplots = len(self.data.channels)
922 926 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
923 927 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
924 928 self.height = 3.5 * self.nrows
925 929
926 930 self.cb_label = 'dB'
927 931 if self.showprofile:
928 932 self.width = 5.8 * self.ncols
929 933 else:
930 934 self.width = 4.8* self.ncols
931 935 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.92, 'bottom': 0.12})
932 936
933 937 self.ylabel = 'Range [km]'
934 938
935 939
936 940 def update_list(self,dataOut):
937 941 if len(self.channelList) == 0:
938 942 self.channelList = dataOut.channelList
939 943
940 944 def update(self, dataOut):
941 945
942 946 self.update_list(dataOut)
943 947 data = {}
944 948 meta = {}
945 949
946 950 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
947 951 n0 = (dataOut.getNoise()/norm)
948 952 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
949 953 noise = 10*numpy.log10(noise)
950 954
951 955 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
952 956 for ch in range(dataOut.nChannels):
953 957 if hasattr(dataOut.normFactor,'ndim'):
954 958 if dataOut.normFactor.ndim > 1:
955 959 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
956 960 else:
957 961 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
958 962 else:
959 963 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
960 964
961 965 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
962 966 spc = 10*numpy.log10(z)
963 967
964 968
965 969 data['spc'] = spc - noise
966 970 #print(spc.shape)
967 971 data['rti'] = spc.mean(axis=1)
968 972 data['noise'] = noise
969 973
970 974
971 975
972 976 # data['noise'] = noise
973 977 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
974 978
975 979 return data, meta
976 980
977 981 def plot(self):
978 982 if self.xaxis == "frequency":
979 983 x = self.data.xrange[0]
980 984 self.xlabel = "Frequency (kHz)"
981 985 elif self.xaxis == "time":
982 986 x = self.data.xrange[1]
983 987 self.xlabel = "Time (ms)"
984 988 else:
985 989 x = self.data.xrange[2]
986 990 self.xlabel = "Velocity (m/s)"
987 991
988 992 self.titles = []
989 993 y = self.data.yrange
990 994 self.y = y
991 995
992 996 data = self.data[-1]
993 997 z = data['spc']
994 998
995 999 for n, ax in enumerate(self.axes):
996 1000 #noise = data['noise'][n]
997 1001
998 1002 if ax.firsttime:
999 1003 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1000 1004 self.xmin = self.xmin if self.xmin else -self.xmax
1001 1005 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1002 1006 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1003 1007 ax.plt = ax.pcolormesh(x, y, z[n].T,
1004 1008 vmin=self.zmin,
1005 1009 vmax=self.zmax,
1006 1010 cmap=plt.get_cmap(self.colormap)
1007 1011 )
1008 1012
1009 1013 if self.showprofile:
1010 1014 ax.plt_profile = self.pf_axes[n].plot(
1011 1015 data['rti'][n], y)[0]
1012 1016
1013 1017
1014 1018 else:
1015 1019 ax.plt.set_array(z[n].T.ravel())
1016 1020 if self.showprofile:
1017 1021 ax.plt_profile.set_data(data['rti'][n], y)
1018 1022
1019 1023
1020 1024 self.titles.append('CH {}'.format(self.channelList[n]))
1021 1025
1022 1026
1023 1027 class NoiselessRTIPlot(RTIPlot):
1024 1028 '''
1025 1029 Plot for RTI data
1026 1030 '''
1027 1031
1028 1032 CODE = 'noiseless_rti'
1029 1033 colormap = 'jet'
1030 1034 plot_type = 'pcolorbuffer'
1031 1035 titles = None
1032 1036 channelList = []
1033 1037 elevationList = []
1034 1038 azimuthList = []
1035 1039 last_noise = None
1036 1040
1037 1041 def setup(self):
1038 1042 self.xaxis = 'time'
1039 1043 self.ncols = 1
1040 1044 #print("dataChannels ",self.data.channels)
1041 1045 self.nrows = len(self.data.channels)
1042 1046 self.nplots = len(self.data.channels)
1043 1047 self.ylabel = 'Range [km]'
1044 self.xlabel = 'Time'
1048 #self.xlabel = 'Time'
1045 1049 self.cb_label = 'dB'
1046 1050 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1047 1051 self.titles = ['{} Channel {}'.format(
1048 1052 self.CODE.upper(), x) for x in range(self.nplots)]
1049 1053
1050 1054 def update_list(self,dataOut):
1051 1055 if len(self.channelList) == 0:
1052 1056 self.channelList = dataOut.channelList
1053 1057 if len(self.elevationList) == 0:
1054 1058 self.elevationList = dataOut.elevationList
1055 1059 if len(self.azimuthList) == 0:
1056 1060 self.azimuthList = dataOut.azimuthList
1057 1061
1058 1062 def update(self, dataOut):
1059 1063 if len(self.channelList) == 0:
1060 1064 self.update_list(dataOut)
1061 1065
1062 1066 data = {}
1063 1067 meta = {}
1064 1068 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1065 1069 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt
1066 1070 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1067 1071 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1068 1072 data['noise'] = n0
1069 1073 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1070 1074 noiseless_data = dataOut.getPower() - noise
1071 1075
1072 1076 #print("power, noise:", dataOut.getPower(), n0)
1073 1077 #print(noise)
1074 1078 #print(noiseless_data)
1075 1079
1076 1080 data['noiseless_rti'] = noiseless_data
1077 1081
1078 1082 return data, meta
1079 1083
1080 1084 def plot(self):
1081 1085 from matplotlib import pyplot as plt
1082 1086 self.x = self.data.times
1083 1087 self.y = self.data.yrange
1084 1088 self.z = self.data['noiseless_rti']
1085 1089 self.z = numpy.array(self.z, dtype=float)
1086 1090 self.z = numpy.ma.masked_invalid(self.z)
1087 1091
1088 1092
1089 1093 try:
1090 1094 if self.channelList != None:
1091 1095 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1092 1096 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1093 1097 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1094 1098 else:
1095 1099 self.titles = ['{} Channel {}'.format(
1096 1100 self.CODE.upper(), x) for x in self.channelList]
1097 1101 except:
1098 1102 if self.channelList.any() != None:
1099 1103 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1100 1104 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1101 1105 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1102 1106 else:
1103 1107 self.titles = ['{} Channel {}'.format(
1104 1108 self.CODE.upper(), x) for x in self.channelList]
1105 1109
1106 1110
1107 1111 if self.decimation is None:
1108 1112 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1109 1113 else:
1110 1114 x, y, z = self.fill_gaps(*self.decimate())
1111 1115
1112 1116 dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
1113 1117 #print("plot shapes ", z.shape, x.shape, y.shape)
1114 1118 #print(self.axes)
1115 1119 for n, ax in enumerate(self.axes):
1116 1120
1117 1121
1118 1122 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
1119 1123 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
1120 1124 data = self.data[-1]
1121 1125 if ax.firsttime:
1126 if (n+1) == len(self.channelList):
1127 ax.set_xlabel('Time')
1122 1128 ax.plt = ax.pcolormesh(x, y, z[n].T,
1123 1129 vmin=self.zmin,
1124 1130 vmax=self.zmax,
1125 1131 cmap=plt.get_cmap(self.colormap)
1126 1132 )
1127 1133 if self.showprofile:
1128 1134 ax.plot_profile = self.pf_axes[n].plot(data['noiseless_rti'][n], self.y)[0]
1129 1135
1130 1136 else:
1131 1137 ax.collections.remove(ax.collections[0])
1132 1138 ax.plt = ax.pcolormesh(x, y, z[n].T,
1133 1139 vmin=self.zmin,
1134 1140 vmax=self.zmax,
1135 1141 cmap=plt.get_cmap(self.colormap)
1136 1142 )
1137 1143 if self.showprofile:
1138 1144 ax.plot_profile.set_data(data['noiseless_rti'][n], self.y)
1139 1145 # if "noise" in self.data:
1140 1146 # #ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
1141 1147 # ax.plot_noise.set_data(data['noise'][n], self.y)
1142 1148
1143 1149
1144 1150 class OutliersRTIPlot(Plot):
1145 1151 '''
1146 1152 Plot for data_xxxx object
1147 1153 '''
1148 1154
1149 1155 CODE = 'outlier_rtc' # Range Time Counts
1150 1156 colormap = 'cool'
1151 1157 plot_type = 'pcolorbuffer'
1152 1158
1153 1159 def setup(self):
1154 1160 self.xaxis = 'time'
1155 1161 self.ncols = 1
1156 1162 self.nrows = self.data.shape('outlier_rtc')[0]
1157 1163 self.nplots = self.nrows
1158 1164 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1159 1165
1160 1166
1161 1167 if not self.xlabel:
1162 1168 self.xlabel = 'Time'
1163 1169
1164 1170 self.ylabel = 'Height [km]'
1165 1171 if not self.titles:
1166 1172 self.titles = ['Outliers Ch:{}'.format(x) for x in range(self.nrows)]
1167 1173
1168 1174 def update(self, dataOut):
1169 1175
1170 1176 data = {}
1171 1177 data['outlier_rtc'] = dataOut.data_outlier
1172 1178
1173 1179 meta = {}
1174 1180
1175 1181 return data, meta
1176 1182
1177 1183 def plot(self):
1178 1184 # self.data.normalize_heights()
1179 1185 self.x = self.data.times
1180 1186 self.y = self.data.yrange
1181 1187 self.z = self.data['outlier_rtc']
1182 1188
1183 1189 #self.z = numpy.ma.masked_invalid(self.z)
1184 1190
1185 1191 if self.decimation is None:
1186 1192 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1187 1193 else:
1188 1194 x, y, z = self.fill_gaps(*self.decimate())
1189 1195
1190 1196 for n, ax in enumerate(self.axes):
1191 1197
1192 1198 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1193 1199 self.z[n])
1194 1200 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1195 1201 self.z[n])
1196 1202 data = self.data[-1]
1197 1203 if ax.firsttime:
1198 1204 if self.zlimits is not None:
1199 1205 self.zmin, self.zmax = self.zlimits[n]
1200 1206
1201 1207 ax.plt = ax.pcolormesh(x, y, z[n].T,
1202 1208 vmin=self.zmin,
1203 1209 vmax=self.zmax,
1204 1210 cmap=self.cmaps[n]
1205 1211 )
1206 1212 if self.showprofile:
1207 1213 ax.plot_profile = self.pf_axes[n].plot(data['outlier_rtc'][n], self.y)[0]
1208 1214 self.pf_axes[n].set_xlabel('')
1209 1215 else:
1210 1216 if self.zlimits is not None:
1211 1217 self.zmin, self.zmax = self.zlimits[n]
1212 1218 ax.collections.remove(ax.collections[0])
1213 1219 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1214 1220 vmin=self.zmin,
1215 1221 vmax=self.zmax,
1216 1222 cmap=self.cmaps[n]
1217 1223 )
1218 1224 if self.showprofile:
1219 1225 ax.plot_profile.set_data(data['outlier_rtc'][n], self.y)
1220 1226 self.pf_axes[n].set_xlabel('')
1221 1227
1222 1228 class NIncohIntRTIPlot(Plot):
1223 1229 '''
1224 1230 Plot for data_xxxx object
1225 1231 '''
1226 1232
1227 1233 CODE = 'integrations_rtc' # Range Time Counts
1228 1234 colormap = 'BuGn'
1229 1235 plot_type = 'pcolorbuffer'
1230 1236
1231 1237 def setup(self):
1232 1238 self.xaxis = 'time'
1233 1239 self.ncols = 1
1234 1240 self.nrows = self.data.shape('integrations_rtc')[0]
1235 1241 self.nplots = self.nrows
1236 1242 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1237 1243
1238 1244
1239 1245 if not self.xlabel:
1240 1246 self.xlabel = 'Time'
1241 1247
1242 1248 self.ylabel = 'Height [km]'
1243 1249 if not self.titles:
1244 1250 self.titles = ['Integration Ch:{}'.format(x) for x in range(self.nrows)]
1245 1251
1246 1252 def update(self, dataOut):
1247 1253
1248 1254 data = {}
1249 1255 data['integrations_rtc'] = dataOut.nIncohInt
1250 1256
1251 1257 meta = {}
1252 1258
1253 1259 return data, meta
1254 1260
1255 1261 def plot(self):
1256 1262 # self.data.normalize_heights()
1257 1263 self.x = self.data.times
1258 1264 self.y = self.data.yrange
1259 1265 self.z = self.data['integrations_rtc']
1260 1266
1261 1267 #self.z = numpy.ma.masked_invalid(self.z)
1262 1268
1263 1269 if self.decimation is None:
1264 1270 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1265 1271 else:
1266 1272 x, y, z = self.fill_gaps(*self.decimate())
1267 1273
1268 1274 for n, ax in enumerate(self.axes):
1269 1275
1270 1276 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1271 1277 self.z[n])
1272 1278 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1273 1279 self.z[n])
1274 1280 data = self.data[-1]
1275 1281 if ax.firsttime:
1276 1282 if self.zlimits is not None:
1277 1283 self.zmin, self.zmax = self.zlimits[n]
1278 1284
1279 1285 ax.plt = ax.pcolormesh(x, y, z[n].T,
1280 1286 vmin=self.zmin,
1281 1287 vmax=self.zmax,
1282 1288 cmap=self.cmaps[n]
1283 1289 )
1284 1290 if self.showprofile:
1285 1291 ax.plot_profile = self.pf_axes[n].plot(data['integrations_rtc'][n], self.y)[0]
1286 1292 self.pf_axes[n].set_xlabel('')
1287 1293 else:
1288 1294 if self.zlimits is not None:
1289 1295 self.zmin, self.zmax = self.zlimits[n]
1290 1296 ax.collections.remove(ax.collections[0])
1291 1297 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1292 1298 vmin=self.zmin,
1293 1299 vmax=self.zmax,
1294 1300 cmap=self.cmaps[n]
1295 1301 )
1296 1302 if self.showprofile:
1297 1303 ax.plot_profile.set_data(data['integrations_rtc'][n], self.y)
1298 1304 self.pf_axes[n].set_xlabel('')
1299 1305
1300 1306
1301 1307 import datetime
1302 1308 class NoiselessRTILinePlot(Plot):
1303 1309 '''
1304 1310 Plot for RTI data
1305 1311 '''
1306 1312
1307 1313 CODE = 'noiseless_rtiLine'
1308 1314
1309 1315 plot_type = 'scatter'
1310 1316 titles = None
1311 1317 channelList = []
1312 1318 elevationList = []
1313 1319 azimuthList = []
1314 1320 last_noise = None
1315 1321
1316 1322 def setup(self):
1317 1323 self.xaxis = 'Range (Km)'
1318 1324 self.nplots = len(self.data.channels)
1319 1325 self.nrows = int(numpy.ceil(self.nplots/2))
1320 1326 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1321 1327 self.ylabel = 'Intensity [dB]'
1322 1328 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1323 1329 self.colorbar = False
1324 1330 self.width = 6
1325 1331 self.height = 4
1326 1332
1327 1333 def update_list(self,dataOut):
1328 1334 if len(self.channelList) == 0:
1329 1335 self.channelList = dataOut.channelList
1330 1336 if len(self.elevationList) == 0:
1331 1337 self.elevationList = dataOut.elevationList
1332 1338 if len(self.azimuthList) == 0:
1333 1339 self.azimuthList = dataOut.azimuthList
1334 1340
1335 1341 def update(self, dataOut):
1336 1342 if len(self.channelList) == 0:
1337 1343 self.update_list(dataOut)
1338 1344
1339 1345 data = {}
1340 1346 meta = {}
1341 1347 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1342 1348 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt)
1343 1349 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1344 1350
1345 1351 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1346 1352 data['noise'] = n0
1347 1353
1348 1354 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1349 1355 noiseless_data = dataOut.getPower() - noise
1350 1356
1351 1357 #print("power, noise:", dataOut.getPower(), n0)
1352 1358 #print(noise)
1353 1359 #print(noiseless_data)
1354 1360
1355 1361 data['noiseless_rtiLine'] = noiseless_data
1356 1362
1357 1363 #print(noiseless_data.shape, self.name)
1358 1364 data['time'] = dataOut.utctime
1359 1365
1360 1366 return data, meta
1361 1367
1362 1368 def plot(self):
1363 1369
1364 1370 self.x = self.data.times
1365 1371 self.y = self.data.yrange
1366 1372 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1367 1373 #ts = self.data['time'][0].squeeze()
1368 1374 if len(self.data['noiseless_rtiLine'])>2 :
1369 1375 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1370 1376 else:
1371 1377 self.z = self.data['noiseless_rtiLine']
1372 1378 #print(self.z.shape, self.y.shape, ts)
1373 1379 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1374 1380
1375 1381 for i,ax in enumerate(self.axes):
1376 1382 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1377 1383
1378 1384
1379 1385 if ax.firsttime:
1380 1386 #self.xmin = min(self.z)
1381 1387 #self.xmax = max(self.z)
1382 1388 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1383 1389 else:
1384 1390 ax.plt_r.set_data(self.z[i], self.y)
1385 1391
1386 1392
1387 1393
1388 1394 class GeneralProfilePlot(Plot):
1389 1395 '''
1390 1396 Plot for RTI data
1391 1397 '''
1392 1398
1393 1399 CODE = 'general_profilePlot'
1394 1400
1395 1401 plot_type = 'scatter'
1396 1402 titles = None
1397 1403 channelList = []
1398 1404 elevationList = []
1399 1405 azimuthList = []
1400 1406 last_noise = None
1401 1407
1402 1408 def setup(self):
1403 1409 self.xaxis = 'Range (Km)'
1404 1410 self.nplots = len(self.data.channels)
1405 1411 self.nrows = int(numpy.ceil(self.nplots/2))
1406 1412 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1407 1413 self.ylabel = 'Intensity [dB]'
1408 1414 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1409 1415 self.colorbar = False
1410 1416 self.width = 6
1411 1417 self.height = 4
1412 1418
1413 1419 def update_list(self,dataOut):
1414 1420 if len(self.channelList) == 0:
1415 1421 self.channelList = dataOut.channelList
1416 1422 if len(self.elevationList) == 0:
1417 1423 self.elevationList = dataOut.elevationList
1418 1424 if len(self.azimuthList) == 0:
1419 1425 self.azimuthList = dataOut.azimuthList
1420 1426
1421 1427 def update(self, dataOut):
1422 1428 if len(self.channelList) == 0:
1423 1429 self.update_list(dataOut)
1424 1430
1425 1431 data = {}
1426 1432 meta = {}
1427 1433
1428 1434 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1429 1435 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1430 1436 data['noise'] = n0
1431 1437
1432 1438 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1433 1439 noiseless_data = dataOut.getPower() - noise
1434 1440
1435 1441 data['noiseless_rtiLine'] = noiseless_data
1436 1442
1437 1443 #print(noiseless_data.shape, self.name)
1438 1444 data['time'] = dataOut.utctime
1439 1445
1440 1446 return data, meta
1441 1447
1442 1448 def plot(self):
1443 1449
1444 1450 self.x = self.data.times
1445 1451 self.y = self.data.yrange
1446 1452 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1447 1453 #ts = self.data['time'][0].squeeze()
1448 1454 if len(self.data['noiseless_rtiLine'])>2 :
1449 1455 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1450 1456 else:
1451 1457 self.z = self.data['noiseless_rtiLine']
1452 1458 #print(self.z.shape, self.y.shape, ts)
1453 1459 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1454 1460
1455 1461 for i,ax in enumerate(self.axes):
1456 1462 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1457 1463
1458 1464
1459 1465 if ax.firsttime:
1460 1466 #self.xmin = min(self.z)
1461 1467 #self.xmax = max(self.z)
1462 1468 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1463 1469 else:
1464 1470 ax.plt_r.set_data(self.z[i], self.y) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now