##// END OF EJS Templates
isr commit
rflores -
r1377:5453f456345b
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

This diff has been collapsed as it changes many lines, (1156 lines changed) Show them Hide them
@@ -0,0 +1,1156
1
2 import os
3 import datetime
4 import numpy
5 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
6
7 from .jroplot_spectra import RTIPlot, NoisePlot
8
9 from schainpy.utils import log
10 from .plotting_codes import *
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt
13
14 import matplotlib.pyplot as plt
15 import matplotlib.colors as colors
16
17 import time
18 import math
19
20
21 from matplotlib.ticker import MultipleLocator
22
23
24
25 class RTIDPPlot(RTIPlot):
26
27 '''
28 Plot for RTI Double Pulse Experiment
29 '''
30
31 CODE = 'RTIDP'
32 colormap = 'jro'
33 plot_name = 'RTI'
34
35 #cb_label = 'Ne Electron Density (1/cm3)'
36
37 def setup(self):
38 self.xaxis = 'time'
39 self.ncols = 1
40 self.nrows = 3
41 self.nplots = self.nrows
42 #self.height=10
43 if self.showSNR:
44 self.nrows += 1
45 self.nplots += 1
46
47 self.ylabel = 'Height [km]'
48 self.xlabel = 'Time (LT)'
49
50 self.cb_label = 'Intensity (dB)'
51
52
53 #self.cb_label = cb_label
54
55 self.titles = ['{} Channel {}'.format(
56 self.plot_name.upper(), '0x1'),'{} Channel {}'.format(
57 self.plot_name.upper(), '0'),'{} Channel {}'.format(
58 self.plot_name.upper(), '1')]
59
60
61 def plot(self):
62
63 self.data.normalize_heights()
64 self.x = self.data.times
65 self.y = self.data.heights[0:self.data.NDP]
66
67 if self.showSNR:
68 self.z = numpy.concatenate(
69 (self.data[self.CODE], self.data['snr'])
70 )
71 else:
72
73 self.z = self.data[self.CODE]
74 #print(numpy.max(self.z[0,0:]))
75
76 self.z = numpy.ma.masked_invalid(self.z)
77
78 if self.decimation is None:
79 x, y, z = self.fill_gaps(self.x, self.y, self.z)
80 else:
81 x, y, z = self.fill_gaps(*self.decimate())
82
83 for n, ax in enumerate(self.axes):
84
85
86 self.zmax = self.zmax if self.zmax is not None else numpy.max(
87 self.z[1][0,12:40])
88 self.zmin = self.zmin if self.zmin is not None else numpy.min(
89 self.z[1][0,12:40])
90
91
92
93 if ax.firsttime:
94
95 if self.zlimits is not None:
96 self.zmin, self.zmax = self.zlimits[n]
97
98
99 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
100 vmin=self.zmin,
101 vmax=self.zmax,
102 cmap=self.cmaps[n]
103 )
104 #plt.tight_layout()
105 else:
106 if self.zlimits is not None:
107 self.zmin, self.zmax = self.zlimits[n]
108 ax.collections.remove(ax.collections[0])
109 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
110 vmin=self.zmin,
111 vmax=self.zmax,
112 cmap=self.cmaps[n]
113 )
114 #plt.tight_layout()
115
116
117 class RTILPPlot(RTIPlot):
118
119 '''
120 Plot for RTI Long Pulse
121 '''
122
123 CODE = 'RTILP'
124 colormap = 'jro'
125 plot_name = 'RTI LP'
126
127 #cb_label = 'Ne Electron Density (1/cm3)'
128
129 def setup(self):
130 self.xaxis = 'time'
131 self.ncols = 1
132 self.nrows = 4
133 self.nplots = self.nrows
134 if self.showSNR:
135 self.nrows += 1
136 self.nplots += 1
137
138 self.ylabel = 'Height [km]'
139 self.xlabel = 'Time (LT)'
140
141 self.cb_label = 'Intensity (dB)'
142
143
144
145 #self.cb_label = cb_label
146
147 self.titles = ['{} Channel {}'.format(
148 self.plot_name.upper(), '0'),'{} Channel {}'.format(
149 self.plot_name.upper(), '1'),'{} Channel {}'.format(
150 self.plot_name.upper(), '2'),'{} Channel {}'.format(
151 self.plot_name.upper(), '3')]
152
153
154 def plot(self):
155
156 self.data.normalize_heights()
157 self.x = self.data.times
158 self.y = self.data.heights[0:self.data.NRANGE]
159
160 if self.showSNR:
161 self.z = numpy.concatenate(
162 (self.data[self.CODE], self.data['snr'])
163 )
164 else:
165
166 self.z = self.data[self.CODE]
167 #print(numpy.max(self.z[0,0:]))
168
169 self.z = numpy.ma.masked_invalid(self.z)
170
171 if self.decimation is None:
172 x, y, z = self.fill_gaps(self.x, self.y, self.z)
173 else:
174 x, y, z = self.fill_gaps(*self.decimate())
175
176 for n, ax in enumerate(self.axes):
177
178
179 self.zmax = self.zmax if self.zmax is not None else numpy.max(
180 self.z[1][0,12:40])
181 self.zmin = self.zmin if self.zmin is not None else numpy.min(
182 self.z[1][0,12:40])
183
184 if ax.firsttime:
185
186 if self.zlimits is not None:
187 self.zmin, self.zmax = self.zlimits[n]
188
189
190 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
191 vmin=self.zmin,
192 vmax=self.zmax,
193 cmap=self.cmaps[n]
194 )
195 #plt.tight_layout()
196 else:
197 if self.zlimits is not None:
198 self.zmin, self.zmax = self.zlimits[n]
199 ax.collections.remove(ax.collections[0])
200 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
201 vmin=self.zmin,
202 vmax=self.zmax,
203 cmap=self.cmaps[n]
204 )
205 #plt.tight_layout()
206
207
208 class DenRTIPlot(RTIPlot):
209
210 '''
211 Plot for Den
212 '''
213
214 CODE = 'denrti'
215 colormap = 'jro'
216 plot_name = 'Electron Density'
217
218 #cb_label = 'Ne Electron Density (1/cm3)'
219
220 def setup(self):
221 self.xaxis = 'time'
222 self.ncols = 1
223 self.nrows = self.data.shape(self.CODE)[0]
224 self.nplots = self.nrows
225 if self.showSNR:
226 self.nrows += 1
227 self.nplots += 1
228
229 self.ylabel = 'Height [km]'
230 self.xlabel = 'Time (LT)'
231
232 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
233
234 if self.CODE == 'denrti' or self.CODE=='denrtiLP':
235 self.cb_label = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
236
237 #self.cb_label = cb_label
238 if not self.titles:
239 self.titles = self.data.parameters \
240 if self.data.parameters else ['{}'.format(self.plot_name)]
241 if self.showSNR:
242 self.titles.append('SNR')
243
244 def plot(self):
245
246 self.data.normalize_heights()
247 self.x = self.data.times
248 self.y = self.data.heights
249
250
251
252 if self.showSNR:
253 self.z = numpy.concatenate(
254 (self.data[self.CODE], self.data['snr'])
255 )
256 else:
257 self.z = self.data[self.CODE]
258
259 self.z = numpy.ma.masked_invalid(self.z)
260
261 if self.decimation is None:
262 x, y, z = self.fill_gaps(self.x, self.y, self.z)
263 else:
264 x, y, z = self.fill_gaps(*self.decimate())
265
266 for n, ax in enumerate(self.axes):
267
268 self.zmax = self.zmax if self.zmax is not None else numpy.max(
269 self.z[n])
270 self.zmin = self.zmin if self.zmin is not None else numpy.min(
271 self.z[n])
272
273 if ax.firsttime:
274
275 if self.zlimits is not None:
276 self.zmin, self.zmax = self.zlimits[n]
277 if numpy.log10(self.zmin)<0:
278 self.zmin=1
279 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
280 vmin=self.zmin,
281 vmax=self.zmax,
282 cmap=self.cmaps[n],
283 norm=colors.LogNorm()
284 )
285 #plt.tight_layout()
286
287 else:
288 if self.zlimits is not None:
289 self.zmin, self.zmax = self.zlimits[n]
290 ax.collections.remove(ax.collections[0])
291 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
292 vmin=self.zmin,
293 vmax=self.zmax,
294 cmap=self.cmaps[n],
295 norm=colors.LogNorm()
296 )
297 #plt.tight_layout()
298
299
300
301 class DenRTILPPlot(DenRTIPlot):
302
303 '''
304 Plot for Electron Temperature
305 '''
306
307 CODE = 'denrtiLP'
308 colormap = 'jro'
309 plot_name = 'Electron Density'
310
311
312 class ETempRTIPlot(RTIPlot):
313
314 '''
315 Plot for Electron Temperature
316 '''
317
318 CODE = 'ETemp'
319 colormap = 'jet'
320 plot_name = 'Electron Temperature'
321
322 #cb_label = 'Ne Electron Density (1/cm3)'
323
324 def setup(self):
325 self.xaxis = 'time'
326 self.ncols = 1
327 self.nrows = self.data.shape(self.CODE)[0]
328 self.nplots = self.nrows
329 if self.showSNR:
330 self.nrows += 1
331 self.nplots += 1
332
333 self.ylabel = 'Height [km]'
334 self.xlabel = 'Time (LT)'
335 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
336 if self.CODE == 'ETemp' or self.CODE == 'ETempLP':
337 self.cb_label = 'Electron Temperature (K)'
338 if self.CODE == 'ITemp' or self.CODE == 'ITempLP':
339 self.cb_label = 'Ion Temperature (K)'
340
341
342 if not self.titles:
343 self.titles = self.data.parameters \
344 if self.data.parameters else ['{}'.format(self.plot_name)]
345 if self.showSNR:
346 self.titles.append('SNR')
347
348 def plot(self):
349
350 self.data.normalize_heights()
351 self.x = self.data.times
352 self.y = self.data.heights
353
354 if self.showSNR:
355 self.z = numpy.concatenate(
356 (self.data[self.CODE], self.data['snr'])
357 )
358 else:
359 self.z = self.data[self.CODE]
360
361 self.z = numpy.ma.masked_invalid(self.z)
362
363 if self.decimation is None:
364 x, y, z = self.fill_gaps(self.x, self.y, self.z)
365 else:
366 x, y, z = self.fill_gaps(*self.decimate())
367
368 for n, ax in enumerate(self.axes):
369
370 self.zmax = self.zmax if self.zmax is not None else numpy.max(
371 self.z[n])
372 self.zmin = self.zmin if self.zmin is not None else numpy.min(
373 self.z[n])
374
375 if ax.firsttime:
376
377 if self.zlimits is not None:
378 self.zmin, self.zmax = self.zlimits[n]
379
380 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
381 vmin=self.zmin,
382 vmax=self.zmax,
383 cmap=self.cmaps[n]
384 )
385 #plt.tight_layout()
386
387 else:
388 if self.zlimits is not None:
389 self.zmin, self.zmax = self.zlimits[n]
390 ax.collections.remove(ax.collections[0])
391 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
392 vmin=self.zmin,
393 vmax=self.zmax,
394 cmap=self.cmaps[n]
395 )
396 #plt.tight_layout()
397
398
399
400 class ITempRTIPlot(ETempRTIPlot):
401
402 '''
403 Plot for Ion Temperature
404 '''
405
406 CODE = 'ITemp'
407 colormap = 'jet'
408 plot_name = 'Ion Temperature'
409
410
411 class ElectronTempLPPlot(ETempRTIPlot):
412
413 '''
414 Plot for Electron Temperature LP
415 '''
416
417 CODE = 'ETempLP'
418 colormap = 'jet'
419 plot_name = 'Electron Temperature'
420
421
422 class IonTempLPPlot(ETempRTIPlot):
423
424 '''
425 Plot for Ion Temperature LP
426 '''
427
428 CODE = 'ITempLP'
429 colormap = 'jet'
430 plot_name = 'Ion Temperature'
431
432
433 class HFracRTIPlot(ETempRTIPlot):
434
435 '''
436 Plot for H+ LP
437 '''
438
439 CODE = 'HFracLP'
440 colormap = 'jet'
441 plot_name = 'H+ Frac'
442
443
444 class HeFracRTIPlot(ETempRTIPlot):
445
446 '''
447 Plot for He+ LP
448 '''
449
450 CODE = 'HeFracLP'
451 colormap = 'jet'
452 plot_name = 'He+ Frac'
453
454
455 class TempsDPPlot(Plot):
456 '''
457 Plot for Electron - Ion Temperatures
458 '''
459
460 CODE = 'tempsDP'
461 plot_name = 'Temperatures'
462 plot_type = 'scatterbuffer'
463
464
465 def setup(self):
466
467 self.ncols = 1
468 self.nrows = 1
469 self.nplots = 1
470 self.ylabel = 'Range [km]'
471 self.xlabel = 'Temperature (K)'
472 self.width = 3.5
473 self.height = 5.5
474 self.colorbar = False
475 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
476 if not self.titles:
477 self.titles = self.data.parameters \
478 if self.data.parameters else ['{}'.format(self.CODE.upper())]
479
480 def plot(self):
481
482 self.x = self.data['tempsDP'][:,-1]
483 self.y = self.data.heights[0:self.data.NSHTS]
484
485 self.xmin = -100
486 self.xmax = 5000
487 ax = self.axes[0]
488
489 if ax.firsttime:
490
491 ax.errorbar(self.x, self.y, xerr=self.data.ete2, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
492 ax.errorbar(self.data.ti2, self.y, fmt='k^', xerr=self.data.eti2,elinewidth=1.0,color='b',linewidth=2.0, label='Ti')
493 plt.legend(loc='lower right')
494 self.ystep_given = 50
495 ax.yaxis.set_minor_locator(MultipleLocator(15))
496 ax.grid(which='minor')
497 #plt.tight_layout()
498
499
500 else:
501 self.clear_figures()
502 ax.errorbar(self.x, self.y, xerr=self.data.ete2, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
503 ax.errorbar(self.data.ti2, self.y, fmt='k^', xerr=self.data.eti2,elinewidth=1.0,color='b',linewidth=2.0, label='Ti')
504 plt.legend(loc='lower right')
505 ax.yaxis.set_minor_locator(MultipleLocator(15))
506 #plt.tight_layout()
507
508
509 class TempsHPPlot(Plot):
510 '''
511 Plot for Temperatures Hybrid Experiment
512 '''
513
514 CODE = 'temps_LP'
515 plot_name = 'Temperatures'
516 plot_type = 'scatterbuffer'
517
518
519 def setup(self):
520
521 self.ncols = 1
522 self.nrows = 1
523 self.nplots = 1
524 self.ylabel = 'Range [km]'
525 self.xlabel = 'Temperature (K)'
526 self.width = 3.5
527 self.height = 6.5
528 self.colorbar = False
529 if not self.titles:
530 self.titles = self.data.parameters \
531 if self.data.parameters else ['{}'.format(self.CODE.upper())]
532
533 def plot(self):
534
535 self.x = self.data['temps_LP'][:,-1]
536 self.y = self.data.heights[0:self.data.NACF]
537 self.xmin = -100
538 self.xmax = 4500
539 ax = self.axes[0]
540
541 if ax.firsttime:
542
543 ax.errorbar(self.x, self.y, xerr=self.data.ete, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
544 ax.errorbar(self.data.ti, self.y, fmt='k^', xerr=self.data.eti,elinewidth=1.0,color='b',linewidth=2.0, label='Ti')
545 plt.legend(loc='lower right')
546 self.ystep_given = 200
547 ax.yaxis.set_minor_locator(MultipleLocator(15))
548 ax.grid(which='minor')
549 #plt.tight_layout()
550
551
552 else:
553 self.clear_figures()
554 ax.errorbar(self.x, self.y, xerr=self.data.ete, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
555 ax.errorbar(self.data.ti, self.y, fmt='k^', xerr=self.data.eti,elinewidth=1.0,color='b',linewidth=2.0, label='Ti')
556 plt.legend(loc='lower right')
557 ax.yaxis.set_minor_locator(MultipleLocator(15))
558 #plt.tight_layout()
559
560
561 class FracsHPPlot(Plot):
562 '''
563 Plot for Composition LP
564 '''
565
566 CODE = 'fracs_LP'
567 plot_name = 'Composition'
568 plot_type = 'scatterbuffer'
569
570
571 def setup(self):
572
573 self.ncols = 1
574 self.nrows = 1
575 self.nplots = 1
576 self.ylabel = 'Range [km]'
577 self.xlabel = 'Frac'
578 self.width = 3.5
579 self.height = 6.5
580 self.colorbar = False
581 if not self.titles:
582 self.titles = self.data.parameters \
583 if self.data.parameters else ['{}'.format(self.CODE.upper())]
584
585 def plot(self):
586
587 self.x = self.data['fracs_LP'][:,-1]
588 self.y = self.data.heights[0:self.data.NACF]
589
590 self.xmin = 0
591 self.xmax = 1
592 ax = self.axes[0]
593
594 if ax.firsttime:
595
596 ax.errorbar(self.x, self.y[self.data.cut:], xerr=self.data.eph, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='H+')
597 ax.errorbar(self.data.phe, self.y[self.data.cut:], fmt='k^', xerr=self.data.ephe,elinewidth=1.0,color='b',linewidth=2.0, label='He+')
598 plt.legend(loc='lower right')
599 self.xstep_given = 0.2
600 self.ystep_given = 200
601 ax.yaxis.set_minor_locator(MultipleLocator(15))
602 ax.grid(which='minor')
603 #plt.tight_layout()
604
605
606 else:
607 self.clear_figures()
608 ax.errorbar(self.x, self.y[self.data.cut:], xerr=self.data.eph, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='H+')
609 ax.errorbar(self.data.phe, self.y[self.data.cut:], fmt='k^', xerr=self.data.ephe,elinewidth=1.0,color='b',linewidth=2.0, label='He+')
610 plt.legend(loc='lower right')
611 ax.yaxis.set_minor_locator(MultipleLocator(15))
612 #plt.tight_layout()
613
614
615
616 class EDensityPlot(Plot):
617 '''
618 Plot for electron density
619 '''
620
621 CODE = 'den'
622 plot_name = 'Electron Density'
623 plot_type = 'scatterbuffer'
624
625
626 def setup(self):
627
628 self.ncols = 1
629 self.nrows = 1
630 self.nplots = 1
631 self.ylabel = 'Range [km]'
632 self.xlabel = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
633 self.width = 4
634 self.height = 6.5
635 self.colorbar = False
636 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
637 if not self.titles:
638 self.titles = self.data.parameters \
639 if self.data.parameters else ['{}'.format(self.CODE.upper())]
640
641 def plot(self):
642
643
644 self.x = self.data[self.CODE]
645 self.y = self.data.heights
646 self.xmin = 1000
647 self.xmax = 10000000
648 ax = self.axes[0]
649
650 if ax.firsttime:
651 self.autoxticks=False
652 #if self.CODE=='den':
653 ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
654 #ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=self.data.sdn1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
655
656 ax.errorbar(self.x[:,-1], self.y[:self.data.NSHTS], fmt='k^-', xerr=self.data.sdp2,elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2)
657 #else:
658 #ax.errorbar(self.data.dphi[:self.data.cut], self.y[:self.data.cut], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
659 #ax.errorbar(self.x[:self.data.cut,-1], self.y[:self.data.cut], fmt='k^-', xerr=self.data.sdp2[:self.data.cut],elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2)
660
661 if self.CODE=='denLP':
662 ax.errorbar(self.data.ne[self.data.cut:], self.y[self.data.cut:], xerr=self.data.ene[self.data.cut:], fmt='r^-',elinewidth=1.0,color='r',linewidth=1.0, label='LP Profile',markersize=2)
663
664 plt.legend(loc='upper right')
665 ax.set_xscale("log", nonposx='clip')
666 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
667 self.ystep_given=100
668 if self.CODE=='denLP':
669 self.ystep_given=200
670 ax.set_yticks(grid_y_ticks,minor=True)
671 ax.grid(which='minor')
672 #plt.tight_layout()
673
674
675
676 else:
677
678 self.clear_figures()
679 #if self.CODE=='den':
680 ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
681 #ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=self.data.sdn1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
682
683 ax.errorbar(self.x[:,-1], self.y[:self.data.NSHTS], fmt='k^-', xerr=self.data.sdp2,elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2)
684 ax.errorbar(self.x[:,-2], self.y[:self.data.NSHTS], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed")
685 #else:
686 #ax.errorbar(self.data.dphi[:self.data.cut], self.y[:self.data.cut], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2)
687 #ax.errorbar(self.x[:self.data.cut,-1], self.y[:self.data.cut], fmt='k^-', xerr=self.data.sdp2[:self.data.cut],elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2)
688 #ax.errorbar(self.x[:self.data.cut,-2], self.y[:self.data.cut], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed")
689
690 if self.CODE=='denLP':
691 ax.errorbar(self.data.ne[self.data.cut:], self.y[self.data.cut:], fmt='r^-', xerr=self.data.ene[self.data.cut:],elinewidth=1.0,color='r',linewidth=1.0, label='LP Profile',markersize=2)
692
693 ax.set_xscale("log", nonposx='clip')
694 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
695 ax.set_yticks(grid_y_ticks,minor=True)
696 ax.grid(which='minor')
697 plt.legend(loc='upper right')
698 #plt.tight_layout()
699
700 class FaradayAnglePlot(Plot):
701 '''
702 Plot for electron density
703 '''
704
705 CODE = 'FaradayAngle'
706 plot_name = 'Faraday Angle'
707 plot_type = 'scatterbuffer'
708
709
710 def setup(self):
711
712 self.ncols = 1
713 self.nrows = 1
714 self.nplots = 1
715 self.ylabel = 'Range [km]'
716 self.xlabel = 'Faraday Angle (º)'
717 self.width = 4
718 self.height = 6.5
719 self.colorbar = False
720 if not self.titles:
721 self.titles = self.data.parameters \
722 if self.data.parameters else ['{}'.format(self.CODE.upper())]
723
724 def plot(self):
725
726
727 self.x = self.data[self.CODE]
728 self.y = self.data.heights
729 self.xmin = -180
730 self.xmax = 180
731 ax = self.axes[0]
732
733 if ax.firsttime:
734 self.autoxticks=False
735 #if self.CODE=='den':
736 ax.plot(self.x, self.y,marker='o',color='g',linewidth=1.0,markersize=2)
737
738 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
739 self.ystep_given=100
740 if self.CODE=='denLP':
741 self.ystep_given=200
742 ax.set_yticks(grid_y_ticks,minor=True)
743 ax.grid(which='minor')
744 #plt.tight_layout()
745 else:
746
747 self.clear_figures()
748 #if self.CODE=='den':
749 #print(numpy.shape(self.x))
750 ax.plot(self.x[:,-1], self.y, marker='o',color='g',linewidth=1.0, markersize=2)
751
752 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
753 ax.set_yticks(grid_y_ticks,minor=True)
754 ax.grid(which='minor')
755
756 class EDensityHPPlot(EDensityPlot):
757
758 '''
759 Plot for Electron Density Hybrid Experiment
760 '''
761
762 CODE = 'denLP'
763 plot_name = 'Electron Density'
764 plot_type = 'scatterbuffer'
765
766
767 class ACFsPlot(Plot):
768 '''
769 Plot for ACFs Double Pulse Experiment
770 '''
771
772 CODE = 'acfs'
773 plot_name = 'ACF'
774 plot_type = 'scatterbuffer'
775
776
777 def setup(self):
778 #self.xaxis = 'time'
779 self.ncols = 1
780 self.nrows = 1
781 self.nplots = 1
782 self.ylabel = 'Range [km]'
783 self.xlabel = 'lags (ms)'
784 self.width = 3.5
785 self.height = 6
786 self.colorbar = False
787 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
788 if not self.titles:
789 self.titles = self.data.parameters \
790 if self.data.parameters else ['{}'.format(self.CODE.upper())]
791
792 def plot(self):
793
794 self.x = self.data.lags_to_plot
795 self.y = self.data['acfs'][:,-1]
796
797
798 self.xmin = 0.0
799 self.xmax = 2.0
800
801 ax = self.axes[0]
802
803 if ax.firsttime:
804
805 for i in range(self.data.NSHTS):
806 x_aux = numpy.isfinite(self.x[i,:])
807 y_aux = numpy.isfinite(self.y[i,:])
808 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
809 x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:])
810 y_igcej_aux = numpy.isfinite(self.data.y_igcej_to_plot[i,:])
811 x_ibad_aux = numpy.isfinite(self.data.x_ibad_to_plot[i,:])
812 y_ibad_aux = numpy.isfinite(self.data.y_ibad_to_plot[i,:])
813 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
814 ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.acfs_error_to_plot[i,x_aux],color='b',marker='o',linewidth=1.0,markersize=2)
815 ax.plot(self.data.x_igcej_to_plot[i,x_igcej_aux],self.data.y_igcej_to_plot[i,y_igcej_aux],'x',color='red',markersize=2)
816 ax.plot(self.data.x_ibad_to_plot[i,x_ibad_aux],self.data.y_ibad_to_plot[i,y_ibad_aux],'X',color='red',markersize=2)
817
818 self.xstep_given = (self.xmax-self.xmin)/(self.data.DPL-1)
819 self.ystep_given = 50
820 ax.yaxis.set_minor_locator(MultipleLocator(15))
821 ax.grid(which='minor')
822
823
824
825 else:
826 self.clear_figures()
827
828 for i in range(self.data.NSHTS):
829 x_aux = numpy.isfinite(self.x[i,:])
830 y_aux = numpy.isfinite(self.y[i,:])
831 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
832 x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:])
833 y_igcej_aux = numpy.isfinite(self.data.y_igcej_to_plot[i,:])
834 x_ibad_aux = numpy.isfinite(self.data.x_ibad_to_plot[i,:])
835 y_ibad_aux = numpy.isfinite(self.data.y_ibad_to_plot[i,:])
836 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
837 ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.acfs_error_to_plot[i,x_aux],linewidth=1.0,markersize=2,color='b',marker='o')
838 ax.plot(self.data.x_igcej_to_plot[i,x_igcej_aux],self.data.y_igcej_to_plot[i,y_igcej_aux],'x',color='red',markersize=2)
839 ax.plot(self.data.x_ibad_to_plot[i,x_ibad_aux],self.data.y_ibad_to_plot[i,y_ibad_aux],'X',color='red',markersize=2)
840 ax.yaxis.set_minor_locator(MultipleLocator(15))
841
842
843
844
845 class ACFsLPPlot(Plot):
846 '''
847 Plot for ACFs Double Pulse Experiment
848 '''
849
850 CODE = 'acfs_LP'
851 plot_name = 'ACF'
852 plot_type = 'scatterbuffer'
853
854
855 def setup(self):
856 #self.xaxis = 'time'
857 self.ncols = 1
858 self.nrows = 1
859 self.nplots = 1
860 self.ylabel = 'Range [km]'
861 self.xlabel = 'lags (ms)'
862 self.width = 3.5
863 self.height = 7
864 self.colorbar = False
865 if not self.titles:
866 self.titles = self.data.parameters \
867 if self.data.parameters else ['{}'.format(self.CODE.upper())]
868
869
870
871 def plot(self):
872
873 self.x = self.data.lags_LP_to_plot
874 self.y = self.data['acfs_LP'][:,-1]
875
876 self.xmin = 0.0
877 self.xmax = 1.5
878
879 ax = self.axes[0]
880
881 if ax.firsttime:
882
883 for i in range(self.data.NACF):
884 x_aux = numpy.isfinite(self.x[i,:])
885 y_aux = numpy.isfinite(self.y[i,:])
886 yerr_aux = numpy.isfinite(self.data.errors[i,:])
887
888 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
889 ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.errors[i,x_aux],color='b',linewidth=1.0,markersize=2,ecolor='r')
890
891 #self.xstep_given = (self.xmax-self.xmin)/(self.data.NLAG-1)
892 self.xstep_given=0.3
893 self.ystep_given = 200
894 ax.yaxis.set_minor_locator(MultipleLocator(15))
895 ax.grid(which='minor')
896
897 else:
898 self.clear_figures()
899
900 for i in range(self.data.NACF):
901 x_aux = numpy.isfinite(self.x[i,:])
902 y_aux = numpy.isfinite(self.y[i,:])
903 yerr_aux = numpy.isfinite(self.data.errors[i,:])
904
905 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
906 ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.errors[i,x_aux],color='b',linewidth=1.0,markersize=2,ecolor='r')
907
908 ax.yaxis.set_minor_locator(MultipleLocator(15))
909
910
911 class CrossProductsPlot(Plot):
912 '''
913 Plot for cross products
914 '''
915
916 CODE = 'crossprod'
917 plot_name = 'Cross Products'
918 plot_type = 'scatterbuffer'
919
920
921 def setup(self):
922
923 self.ncols = 3
924 self.nrows = 1
925 self.nplots = 3
926 self.ylabel = 'Range [km]'
927
928 self.width = 3.5*self.nplots
929 self.height = 5.5
930 self.colorbar = False
931 self.titles = []
932
933 def plot(self):
934
935 self.x = self.data['crossprod'][:,-1,:,:,:,:]
936
937
938
939
940 self.y = self.data.heights[0:self.data.NDP]
941
942
943
944 for n, ax in enumerate(self.axes):
945
946 self.xmin=numpy.min(numpy.concatenate((self.x[n][0,20:30,0,0],self.x[n][1,20:30,0,0],self.x[n][2,20:30,0,0],self.x[n][3,20:30,0,0])))
947 self.xmax=numpy.max(numpy.concatenate((self.x[n][0,20:30,0,0],self.x[n][1,20:30,0,0],self.x[n][2,20:30,0,0],self.x[n][3,20:30,0,0])))
948
949
950 if ax.firsttime:
951
952 self.autoxticks=False
953 if n==0:
954 label1='kax'
955 label2='kay'
956 label3='kbx'
957 label4='kby'
958 self.xlimits=[(self.xmin,self.xmax)]
959 elif n==1:
960 label1='kax2'
961 label2='kay2'
962 label3='kbx2'
963 label4='kby2'
964 self.xlimits.append((self.xmin,self.xmax))
965 elif n==2:
966 label1='kaxay'
967 label2='kbxby'
968 label3='kaxbx'
969 label4='kaxby'
970 self.xlimits.append((self.xmin,self.xmax))
971
972
973 ax.plotline1 = ax.plot(self.x[n][0,:,0,0], self.y, color='r',linewidth=2.0, label=label1)
974 ax.plotline2 = ax.plot(self.x[n][1,:,0,0], self.y, color='k',linewidth=2.0, label=label2)
975 ax.plotline3 = ax.plot(self.x[n][2,:,0,0], self.y, color='b',linewidth=2.0, label=label3)
976 ax.plotline4 = ax.plot(self.x[n][3,:,0,0], self.y, color='m',linewidth=2.0, label=label4)
977 ax.legend(loc='upper right')
978 ax.set_xlim(self.xmin, self.xmax)
979 self.titles.append('{}'.format(self.plot_name.upper()))
980 #plt.tight_layout()
981
982
983 else:
984
985 if n==0:
986 self.xlimits=[(self.xmin,self.xmax)]
987 else:
988 self.xlimits.append((self.xmin,self.xmax))
989
990 ax.set_xlim(self.xmin, self.xmax)
991
992
993 ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y)
994 ax.plotline2[0].set_data(self.x[n][1,:,0,0],self.y)
995 ax.plotline3[0].set_data(self.x[n][2,:,0,0],self.y)
996 ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y)
997 self.titles.append('{}'.format(self.plot_name.upper()))
998 #plt.tight_layout()
999
1000
1001
1002 class CrossProductsLPPlot(Plot):
1003 '''
1004 Plot for cross products LP
1005 '''
1006
1007 CODE = 'crossprodlp'
1008 plot_name = 'Cross Products LP'
1009 plot_type = 'scatterbuffer'
1010
1011
1012 def setup(self):
1013
1014 self.ncols = 2
1015 self.nrows = 1
1016 self.nplots = 2
1017 self.ylabel = 'Range [km]'
1018 self.xlabel = 'dB'
1019 self.width = 3.5*self.nplots
1020 self.height = 5.5
1021 self.colorbar = False
1022 self.titles = []
1023 self.plotline_array=numpy.zeros((2,self.data.NLAG),dtype=object)
1024 def plot(self):
1025
1026
1027 self.x = self.data[self.CODE][:,-1,:,:]
1028
1029
1030 self.y = self.data.heights[0:self.data.NRANGE]
1031
1032
1033 label_array=numpy.array(['lag '+ str(x) for x in range(self.data.NLAG)])
1034 color_array=['r','k','g','b','c','m','y','orange','steelblue','purple','peru','darksalmon','grey','limegreen','olive','midnightblue']
1035
1036
1037 for n, ax in enumerate(self.axes):
1038
1039 self.xmin=30
1040 self.xmax=70
1041 #print(self.x[0,12:15,n])
1042 #input()
1043 #self.xmin=numpy.min(numpy.concatenate((self.x[0,:,n],self.x[1,:,n])))
1044 #self.xmax=numpy.max(numpy.concatenate((self.x[0,:,n],self.x[1,:,n])))
1045
1046 #print("before",self.plotline_array)
1047
1048 if ax.firsttime:
1049
1050 self.autoxticks=False
1051
1052
1053 for i in range(self.data.NLAG):
1054 #print(i)
1055 #print(numpy.shape(self.x))
1056 self.plotline_array[n,i], = ax.plot(self.x[i,:,n], self.y, color=color_array[i],linewidth=1.0, label=label_array[i])
1057 #ax.plotline1 = ax.plot(self.x[0,:,n], self.y, color='r',linewidth=2.0, label=label_array[0])
1058 #ax.plotline2 = ax.plot(self.x[n][1,:,0,0], self.y, color='k',linewidth=2.0, label=label2)
1059 #ax.plotline3 = ax.plot(self.x[n][2,:,0,0], self.y, color='b',linewidth=2.0, label=label3)
1060 #ax.plotline4 = ax.plot(self.x[n][3,:,0,0], self.y, color='m',linewidth=2.0, label=label4)
1061
1062
1063 #print(self.plotline_array)
1064
1065
1066
1067 ax.legend(loc='upper right')
1068 ax.set_xlim(self.xmin, self.xmax)
1069 if n==0:
1070 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1071 if n==1:
1072 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1073
1074 #plt.tight_layout()
1075
1076 else:
1077 #print(self.plotline_array)
1078 for i in range(self.data.NLAG):
1079
1080 self.plotline_array[n,i].set_data(self.x[i,:,n],self.y)
1081
1082
1083
1084 #ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y)
1085 #ax.plotline2[0].set_data(self.x[n][1,:,0,0],self.y)
1086 #ax.plotline3[0].set_data(self.x[n][2,:,0,0],self.y)
1087 #ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y)
1088
1089 if n==0:
1090 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1091 if n==1:
1092 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1093
1094 #plt.tight_layout()
1095
1096
1097 class NoiseDPPlot(NoisePlot):
1098 '''
1099 Plot for noise Double Pulse
1100 '''
1101
1102 CODE = 'noisedp'
1103 plot_name = 'Noise'
1104 plot_type = 'scatterbuffer'
1105
1106
1107 class XmitWaveformPlot(Plot):
1108 '''
1109 Plot for xmit waveform
1110 '''
1111
1112 CODE = 'xmit'
1113 plot_name = 'Xmit Waveform'
1114 plot_type = 'scatterbuffer'
1115
1116
1117 def setup(self):
1118
1119 self.ncols = 1
1120 self.nrows = 1
1121 self.nplots = 1
1122 self.ylabel = ''
1123 self.xlabel = 'Number of Lag'
1124 self.width = 5.5
1125 self.height = 3.5
1126 self.colorbar = False
1127 if not self.titles:
1128 self.titles = self.data.parameters \
1129 if self.data.parameters else ['{}'.format(self.plot_name.upper())]
1130
1131 def plot(self):
1132
1133 self.x = numpy.arange(0,self.data.NLAG,1,'float32')
1134 self.y = self.data['xmit'][:,-1,:]
1135
1136 self.xmin = 0
1137 self.xmax = self.data.NLAG-1
1138 self.ymin = -1.0
1139 self.ymax = 1.0
1140 ax = self.axes[0]
1141
1142 if ax.firsttime:
1143 ax.plotline0=ax.plot(self.x,self.y[0,:],color='blue')
1144 ax.plotline1=ax.plot(self.x,self.y[1,:],color='red')
1145 secax=ax.secondary_xaxis(location=0.5)
1146 secax.xaxis.tick_bottom()
1147 secax.tick_params( labelleft=False, labeltop=False,
1148 labelright=False, labelbottom=False)
1149
1150 self.xstep_given = 3
1151 self.ystep_given = .25
1152 secax.set_xticks(numpy.linspace(self.xmin, self.xmax, 6)) #only works on matplotlib.version>3.2
1153
1154 else:
1155 ax.plotline0[0].set_data(self.x,self.y[0,:])
1156 ax.plotline1[0].set_data(self.x,self.y[1,:])
This diff has been collapsed as it changes many lines, (683 lines changed) Show them Hide them
@@ -0,0 +1,683
1 '''
2 Created on Jun 9, 2020
3
4 @author: Roberto Flores
5 '''
6
7 import os
8 import sys
9 import time
10
11 import struct
12
13
14 import datetime
15
16 import numpy
17
18
19 import schainpy.admin
20 from schainpy.model.io.jroIO_base import LOCALTIME, Reader
21 from schainpy.model.data.jroheaderIO import BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
22 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
23 from schainpy.model.data.jrodata import Voltage, Parameters
24 from schainpy.utils import log
25
26
27 class DatReader(Reader, ProcessingUnit):
28
29 def __init__(self):
30
31 ProcessingUnit.__init__(self)
32 self.basicHeaderObj = BasicHeader(LOCALTIME)
33 self.systemHeaderObj = SystemHeader()
34 self.radarControllerHeaderObj = RadarControllerHeader()
35 self.processingHeaderObj = ProcessingHeader()
36 self.dataOut = Parameters()
37 #print(self.basicHeaderObj.timezone)
38 #self.counter_block=0
39 self.format='dat'
40 self.flagNoMoreFiles = 0
41 self.filename = None
42 self.intervals = set()
43 #self.datatime = datetime.datetime(1900,1,1)
44
45 self.filefmt = "***%Y%m%d*******"
46
47 self.padding=numpy.zeros(1,'int32')
48 self.hsize=numpy.zeros(1,'int32')
49 self.bufsize=numpy.zeros(1,'int32')
50 self.nr=numpy.zeros(1,'int32')
51 self.ngates=numpy.zeros(1,'int32') ### ### ### 2
52 self.time1=numpy.zeros(1,'uint64') # pos 3
53 self.time2=numpy.zeros(1,'uint64') # pos 4
54 self.lcounter=numpy.zeros(1,'int32')
55 self.groups=numpy.zeros(1,'int32')
56 self.system=numpy.zeros(4,'int8') # pos 7
57 self.h0=numpy.zeros(1,'float32')
58 self.dh=numpy.zeros(1,'float32')
59 self.ipp=numpy.zeros(1,'float32')
60 self.process=numpy.zeros(1,'int32')
61 self.tx=numpy.zeros(1,'int32')
62
63 self.ngates1=numpy.zeros(1,'int32') ### ### ### 13
64 self.time0=numpy.zeros(1,'uint64') # pos 14
65 self.nlags=numpy.zeros(1,'int32')
66 self.nlags1=numpy.zeros(1,'int32')
67 self.txb=numpy.zeros(1,'float32') ### ### ### 17
68 self.time3=numpy.zeros(1,'uint64') # pos 18
69 self.time4=numpy.zeros(1,'uint64') # pos 19
70 self.h0_=numpy.zeros(1,'float32')
71 self.dh_=numpy.zeros(1,'float32')
72 self.ipp_=numpy.zeros(1,'float32')
73 self.txa_=numpy.zeros(1,'float32')
74
75 self.pad=numpy.zeros(100,'int32')
76
77 self.nbytes=numpy.zeros(1,'int32')
78 self.limits=numpy.zeros(1,'int32')
79 self.ngroups=numpy.zeros(1,'int32') ### ### ### 27
80 #Make the header list
81 #header=[hsize,bufsize,nr,ngates,time1,time2,lcounter,groups,system,h0,dh,ipp,process,tx,padding,ngates1,time0,nlags,nlags1,padding,txb,time3,time4,h0_,dh_,ipp_,txa_,pad,nbytes,limits,padding,ngroups]
82 self.header=[self.hsize,self.bufsize,self.nr,self.ngates,self.time1,self.time2,self.lcounter,self.groups,self.system,self.h0,self.dh,self.ipp,self.process,self.tx,self.ngates1,self.padding,self.time0,self.nlags,self.nlags1,self.padding,self.txb,self.time3,self.time4,self.h0_,self.dh_,self.ipp_,self.txa_,self.pad,self.nbytes,self.limits,self.padding,self.ngroups]
83
84
85
86 def setup(self, **kwargs):
87
88 self.set_kwargs(**kwargs)
89
90
91 if self.path is None:
92 raise ValueError('The path is not valid')
93
94 self.open_file = open
95 self.open_mode = 'rb'
96
97
98
99 if self.format is None:
100 raise ValueError('The format is not valid')
101 elif self.format.lower() in ('dat'):
102 self.ext = '.dat'
103 elif self.format.lower() in ('out'):
104 self.ext = '.out'
105
106
107 log.log("Searching files in {}".format(self.path), self.name)
108 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
109 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
110 #print(self.path)
111 #print(self.filenameList)
112 #input()
113
114
115 self.setNextFile()
116
117 def readFirstHeader(self):
118 '''Read header and data'''
119
120 #self.flag_same_file=1
121 self.counter_block=0
122 self.parseHeader()
123 self.parseData()
124 self.blockIndex = 0
125
126 return
127
128 def parseHeader(self):
129 '''
130 '''
131
132 for i in range(len(self.header)):
133 for j in range(len(self.header[i])):
134 #print("len(header[i]) ",len(header[i]))
135 #input()
136 temp=self.fp.read(int(self.header[i].itemsize))
137 if isinstance(self.header[i][0], numpy.int32):
138 #print(struct.unpack('i', temp)[0])
139 self.header[i][0]=struct.unpack('i', temp)[0]
140 if isinstance(self.header[i][0], numpy.uint64):
141 self.header[i][0]=struct.unpack('q', temp)[0]
142 if isinstance(self.header[i][0], numpy.int8):
143 self.header[i][0]=struct.unpack('B', temp)[0]
144 if isinstance(self.header[i][0], numpy.float32):
145 self.header[i][0]=struct.unpack('f', temp)[0]
146
147 self.fp.seek(0,0)
148 if int(self.header[1][0])==int(81864):
149 self.experiment='DP'
150
151 elif int(self.header[1][0])==int(185504):
152 self.experiment='HP'
153
154
155 self.total_blocks=os.stat(self.filename).st_size//self.header[1][0]
156
157
158 def parseData(self):
159 '''
160 '''
161 if self.experiment=='DP':
162 self.header[15][0]=66
163 self.header[18][0]=16
164 self.header[17][0]=11
165 self.header[2][0]=2
166
167
168 self.noise=numpy.zeros(self.header[2][0],'float32') #self.header[2][0]
169 #tmpx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
170 self.kax=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
171 self.kay=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
172 self.kbx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
173 self.kby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
174 self.kax2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
175 self.kay2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
176 self.kbx2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
177 self.kby2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
178 self.kaxbx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
179 self.kaxby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
180 self.kaybx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
181 self.kayby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
182 self.kaxay=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
183 self.kbxby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32')
184 self.output_LP_real=numpy.zeros((self.header[18][0],200,self.header[2][0]),'float32')
185 self.output_LP_imag=numpy.zeros((self.header[18][0],200,self.header[2][0]),'float32')
186 self.final_cross_products=[self.kax,self.kay,self.kbx,self.kby,self.kax2,self.kay2,self.kbx2,self.kby2,self.kaxbx,self.kaxby,self.kaybx,self.kayby,self.kaxay,self.kbxby]
187 #self.final_cross_products=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx]
188
189 #print("pos: ",self.fp.tell())
190
191
192 def readNextBlock(self):
193
194 while True:
195 self.flagDiscontinuousBlock = 0
196 #print(os.stat(self.filename).st_size)
197 #print(os.stat(self.filename).st_size//self.header[1][0])
198 #os.stat(self.fp)
199 if self.counter_block == self.total_blocks:
200
201 self.setNextFile()
202
203 self.readBlock()
204 #self.counter_block+=1
205
206 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
207 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
208
209 #print(self.datatime)
210 #print(datetime.datetime.combine(self.startDate, self.startTime))
211 #print(datetime.datetime.combine(self.endDate, self.endTime))
212 #print("warning")
213 log.warning(
214 'Reading Block No. {}/{} -> {} [Skipping]'.format(
215 self.counter_block,
216 self.total_blocks,
217 self.datatime.ctime()),
218 'DATReader')
219 continue
220 break
221
222 log.log(
223 'Reading Block No. {}/{} -> {}'.format(
224 self.counter_block,
225 self.total_blocks,
226 self.datatime.ctime()),
227 'DATReader')
228
229 return 1
230
231 def readBlock(self):
232 '''
233 '''
234
235 self.npos=self.counter_block*self.header[1][0]
236 #print(self.counter_block)
237 self.fp.seek(self.npos, 0)
238 self.counter_block+=1
239 #print("fpos1: ",self.fp.tell())
240
241 self.read_header()
242
243 #put by hand because old files didn't save it in the header
244 if self.experiment=='DP':
245 self.header[15][0]=66
246 self.header[18][0]=16
247 self.header[17][0]=11
248 self.header[2][0]=2
249 #########################################
250
251 if self.experiment=="HP":
252 self.long_pulse_products()
253
254 self.read_cross_products()
255
256
257 self.read_noise()
258
259
260 return
261
262
263
264 def read_header(self):
265
266
267 for i in range(len(self.header)):
268 for j in range(len(self.header[i])):
269 #print("len(header[i]) ",len(header[i]))
270 #input()
271 temp=self.fp.read(int(self.header[i].itemsize))
272 #if(b''==temp):
273 # self.setNextFile()
274 # self.flag_same_file=0
275 if isinstance(self.header[i][0], numpy.int32):
276 #print(struct.unpack('i', temp)[0])
277 self.header[i][0]=struct.unpack('i', temp)[0]
278 if isinstance(self.header[i][0], numpy.uint64):
279 self.header[i][0]=struct.unpack('q', temp)[0]
280 if isinstance(self.header[i][0], numpy.int8):
281 self.header[i][0]=struct.unpack('B', temp)[0]
282 if isinstance(self.header[i][0], numpy.float32):
283 self.header[i][0]=struct.unpack('f', temp)[0]
284 #else:
285 # continue
286 #self.fp.seek(self.npos_aux, 0)
287 # break
288
289 #print("fpos2: ",self.fp.tell())
290 #log.success('Parameters found: {}'.format(self.parameters),
291 # 'DATReader')
292 #print("Success")
293 #self.TimeBlockSeconds_for_dp_power = self.header[4][0]#-((self.dataOut.nint-1)*self.dataOut.NAVG*2)
294 #print(dataOut.TimeBlockSeconds_for_dp_power)
295
296 #self.datatime=datetime.datetime.fromtimestamp(self.header[4][0]).strftime("%Y-%m-%d %H:%M:%S")
297 #print(self.header[4][0])
298 self.datatime=datetime.datetime.fromtimestamp(self.header[4][0])
299 #print(self.header[1][0])
300
301 def long_pulse_products(self):
302 temp=self.fp.read(self.header[18][0]*self.header[2][0]*200*8)
303 ii=0
304
305 for l in range(self.header[18][0]): #lag
306 for r in range(self.header[2][0]): # channels
307 for k in range(200): #RANGE## generalizar
308 self.output_LP_real[l,k,r]=struct.unpack('f', temp[ii:ii+4])[0]
309 ii=ii+4
310 self.output_LP_imag[l,k,r]=struct.unpack('f', temp[ii:ii+4])[0]
311 ii=ii+4
312
313 #print(self.output_LP_real[1,1,1])
314 #print(self.output_LP_imag[1,1,1])
315 def read_cross_products(self):
316
317 for ind in range(len(self.final_cross_products)): #final cross products
318 temp=self.fp.read(self.header[17][0]*2*self.header[15][0]*4) #*4 bytes
319 #if(b''==temp):
320 # self.setNextFile()
321 # self.flag_same_file=0
322 ii=0
323 #print("kabxys.shape ",kabxys.shape)
324 #print(kabxys)
325 #print("fpos3: ",self.fp.tell())
326 for l in range(self.header[17][0]): #lag
327 #print("fpos3: ",self.fp.tell())
328 for fl in range(2): # unflip and flip
329 for k in range(self.header[15][0]): #RANGE
330 #print("fpos3: ",self.fp.tell())
331 self.final_cross_products[ind][k,l,fl]=struct.unpack('f', temp[ii:ii+4])[0]
332 ii=ii+4
333 #print("fpos2: ",self.fp.tell())
334
335
336
337 def read_noise(self):
338
339 temp=self.fp.read(self.header[2][0]*4) #*4 bytes self.header[2][0]
340 for ii in range(self.header[2][0]): #self.header[2][0]
341 self.noise[ii]=struct.unpack('f', temp[ii*4:(ii+1)*4])[0]
342
343 #print("fpos5: ",self.fp.tell())
344
345
346
347 def set_output(self):
348 '''
349 Storing data from buffer to dataOut object
350 '''
351 #print("fpos2: ",self.fp.tell())
352 ##self.dataOut.header = self.header
353 #this is put by hand because it isn't saved in the header
354 if self.experiment=='DP':
355 self.dataOut.NRANGE=0
356 self.dataOut.NSCAN=132
357 self.dataOut.heightList=self.header[10][0]*(numpy.arange(self.header[15][0]))
358 elif self.experiment=='HP':
359 self.dataOut.output_LP=self.output_LP_real+1.j*self.output_LP_imag
360 self.dataOut.NRANGE=200
361 self.dataOut.NSCAN=128
362 self.dataOut.heightList=self.header[10][0]*(numpy.arange(90)) #NEEEDS TO BE GENERALIZED
363 #########################################
364 #print(self.dataOut.output_LP[1,1,1])
365 self.dataOut.MAXNRANGENDT=self.header[3][0]
366 self.dataOut.NDP=self.header[15][0]
367 self.dataOut.DPL=self.header[17][0]
368 self.dataOut.DH=self.header[10][0]
369 self.dataOut.NAVG=self.header[7][0]
370 self.dataOut.H0=self.header[9][0]
371 self.dataOut.NR=self.header[2][0]
372 self.dataOut.NLAG=self.header[18][0]
373 #self.dataOut.tmpx=self.tmpx
374 #self.dataOut.timeZone = 5
375 #self.dataOut.final_cross_products=self.final_cross_products
376 self.dataOut.kax=self.kax
377 #print(self.dataOut.kax[1,1,1])
378 self.dataOut.kay=self.kay
379 self.dataOut.kbx=self.kbx
380 self.dataOut.kby=self.kby
381 self.dataOut.kax2=self.kax2
382 self.dataOut.kay2=self.kay2
383 self.dataOut.kbx2=self.kbx2
384 self.dataOut.kby2=self.kby2
385 self.dataOut.kaxbx=self.kaxbx
386 self.dataOut.kaxby=self.kaxby
387 self.dataOut.kaybx=self.kaybx
388 self.dataOut.kayby=self.kayby
389 self.dataOut.kaxay=self.kaxay
390 self.dataOut.kbxby=self.kbxby
391 self.dataOut.noise_final=self.noise
392 #print("NOISE",self.noise)
393
394
395 self.dataOut.useLocalTime=True
396
397 #self.dataOut.experiment=self.experiment
398 #print(self.datatime)
399 #print(self.dataOut.datatime)
400
401
402 #self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds()
403 #self.dataOut.utctimeInit = self.dataOut.utctime
404
405
406
407 self.dataOut.lt=self.datatime.hour
408
409
410 #print(RadarControllerHeader().ippSeconds)
411 #print(RadarControllerHeader().ipp)
412 #self.dataOut.utctime=time.gmtime(self.header[4][0])- datetime.datetime(1970, 1, 1)
413 #self.dataOut.utctime=self.dataOut.utctime.total_seconds()
414 #time1 = self.header[4][0] # header.time1
415 #print("time1: ",time1)
416 #print(self.header[4][0])
417 #date = time.ctime(time1)
418 #print("DADSADA",time.strptime(date))
419 #print("date_before: ",date)
420 #bd_time=time.gmtime(time1)
421 #print(time.mktime(bd_time))
422 #self.dataOut.utctime=time.mktime(bd_time)
423 self.dataOut.utctime = self.header[4][0]
424 #self.dataOut.datatime=a
425 #print(datetime.datetime.utcfromtimestamp(self.dataOut.utctime))
426 #self.dataOut.TimeBlockDate=self.datatime.ctime()
427 self.dataOut.TimeBlockSeconds=time.mktime(time.strptime(self.dataOut.datatime.ctime()))
428
429 #self.dataOut.heightList = self.ranges
430 #self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds()
431 #self.dataOut.utctimeInit = self.dataOut.utctime
432 #self.dataOut.paramInterval = min(self.intervals)
433 #self.dataOut.useLocalTime = False
434 self.dataOut.flagNoData = False
435 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
436 #print(self.dataOut.channelIndexList)
437 self.dataOut.channelList=list(range(0,self.header[2][0]))
438 #print(self.dataOut.channelList)
439 #print(self.datatime)
440 #print(self.dataOut.final_cross_products[0])
441
442
443 #self.dataOut.heightList=self.header[10][0]*(numpy.arange(self.header[15][0]))
444
445 #print(numpy.shape(self.dataOut.heightList))
446
447
448 def getData(self):
449 '''
450 Storing data from databuffer to dataOut object
451 '''
452
453 if not self.readNextBlock():
454 self.dataOut.flagNoData = True
455 return 0
456
457 self.set_output()
458
459 return 1
460
461 def run(self, **kwargs):
462
463 if not(self.isConfig):
464 self.setup(**kwargs)
465 self.isConfig = True
466 #print("fpos1: ",self.fp.tell())
467 self.getData()
468
469 return
470
471 @MPDecorator
472 class DatWriter(Operation):
473
474
475 def __init__(self):
476
477 Operation.__init__(self)
478 #self.dataOut = Voltage()
479 self.counter = 0
480 self.path = None
481 self.fp = None
482 return
483 #self.ext= '.dat'
484
485 def run(self, dataOut, path, format='dat', experiment=None, **kwargs):
486 print(dataOut.flagNoData)
487 print(dataOut.datatime.ctime())
488 print(dataOut.TimeBlockDate)
489 input()
490 #if dataOut.flag_save:
491 self.experiment=experiment
492 self.path=path
493 if self.experiment=='DP':
494 dataOut.header[1][0]=81864
495 elif self.experiment=='HP':
496 dataOut.header[1][0]=185504#173216
497 #dataOut.header[1][0]=bufsize
498 self.dataOut = dataOut
499 #print(self.dataOut.nint)
500 #self.bufsize=bufsize
501 if format == 'dat':
502 self.ext = '.dat'
503 if format == 'out':
504 self.ext = '.out'
505 self.putData()
506
507 return
508
509
510
511 def setFile(self):
512 '''
513 Create new out file object
514 '''
515
516 #self.dataOut.TimeBlockSeconds=time.mktime(time.strptime(self.dataOut.TimeBlockDate))
517 date = datetime.datetime.fromtimestamp(self.dataOut.TimeBlockSeconds)
518
519 #print("date",date)
520
521 filename = '{}{}{}'.format('jro',
522 date.strftime('%Y%m%d_%H%M%S'),
523 self.ext)
524 #print(filename)
525 #print(self.path)
526
527 self.fullname = os.path.join(self.path, filename)
528
529 if os.path.isfile(self.fullname) :
530 log.warning(
531 'Destination file {} already exists, previous file deleted.'.format(
532 self.fullname),
533 'DatWriter')
534 os.remove(self.fullname)
535
536 try:
537 log.success(
538 'Creating file: {}'.format(self.fullname),
539 'DatWriter')
540 if not os.path.exists(self.path):
541 os.makedirs(self.path)
542 #self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True)
543 self.fp = open(self.fullname,'wb')
544
545 except ValueError as e:
546 log.error(
547 'Impossible to create *.out file',
548 'DatWriter')
549 return
550
551 return 1
552
553 def writeBlock(self):
554
555 #self.dataOut.paramInterval=2
556 #startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
557 #print(startTime)
558 #endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval)
559
560 self.dataOut.header[0].astype('int32').tofile(self.fp)
561 self.dataOut.header[1].astype('int32').tofile(self.fp)
562 self.dataOut.header[2].astype('int32').tofile(self.fp)
563 self.dataOut.header[3].astype('int32').tofile(self.fp)
564 self.dataOut.header[4].astype('uint64').tofile(self.fp)
565 self.dataOut.header[5].astype('uint64').tofile(self.fp)
566 self.dataOut.header[6].astype('int32').tofile(self.fp)
567 self.dataOut.header[7].astype('int32').tofile(self.fp)
568 #print(dataOut.header[7])
569 self.dataOut.header[8].astype('int8').tofile(self.fp)
570 self.dataOut.header[9].astype('float32').tofile(self.fp)
571 self.dataOut.header[10].astype('float32').tofile(self.fp)
572 self.dataOut.header[11].astype('float32').tofile(self.fp)
573 self.dataOut.header[12].astype('int32').tofile(self.fp)
574 self.dataOut.header[13].astype('int32').tofile(self.fp)
575 self.dataOut.header[14].astype('int32').tofile(self.fp)
576 self.dataOut.header[15].astype('int32').tofile(self.fp)
577 self.dataOut.header[16].astype('uint64').tofile(self.fp)
578 self.dataOut.header[17].astype('int32').tofile(self.fp)
579 self.dataOut.header[18].astype('int32').tofile(self.fp)
580 self.dataOut.header[19].astype('int32').tofile(self.fp)
581 self.dataOut.header[20].astype('float32').tofile(self.fp)
582 self.dataOut.header[21].astype('uint64').tofile(self.fp)
583 self.dataOut.header[22].astype('uint64').tofile(self.fp)
584 self.dataOut.header[23].astype('float32').tofile(self.fp)
585 self.dataOut.header[24].astype('float32').tofile(self.fp)
586 self.dataOut.header[25].astype('float32').tofile(self.fp)
587 self.dataOut.header[26].astype('float32').tofile(self.fp)
588 self.dataOut.header[27].astype('int32').tofile(self.fp)
589 self.dataOut.header[28].astype('int32').tofile(self.fp)
590 self.dataOut.header[29].astype('int32').tofile(self.fp)
591 self.dataOut.header[30].astype('int32').tofile(self.fp)
592 self.dataOut.header[31].astype('int32').tofile(self.fp)
593 #print("tell before 1 ",self.fp.tell())
594 #input()
595
596 if self.experiment=="HP":
597 #print("INSIDE")
598 #tmp=numpy.zeros(1,dtype='complex64')
599 #print("tmp ",tmp)
600 #input()
601 #print(dataOut.NLAG)
602 #print(dataOut.NR)
603 #print(dataOut.NRANGE)
604 for l in range(self.dataOut.NLAG): #lag
605 for r in range(self.dataOut.NR): # unflip and flip
606 for k in range(self.dataOut.NRANGE): #RANGE
607 self.dataOut.output_LP.real[l,k,r].astype('float32').tofile(self.fp)
608 self.dataOut.output_LP.imag[l,k,r].astype('float32').tofile(self.fp)
609
610
611 #print("tell before 2 ",self.outputfile.tell())
612
613
614
615
616
617 #print(self.dataOut.output_LP[1,1,1])
618
619 #print(self.dataOut.kax)
620 final_cross_products=[self.dataOut.kax,self.dataOut.kay,self.dataOut.kbx,self.dataOut.kby,
621 self.dataOut.kax2,self.dataOut.kay2,self.dataOut.kbx2,self.dataOut.kby2,
622 self.dataOut.kaxbx,self.dataOut.kaxby,self.dataOut.kaybx,self.dataOut.kayby,
623 self.dataOut.kaxay,self.dataOut.kbxby]
624
625 #print(self.dataOut.kax)
626 #print("tell before crossp saving ",self.outputfile.tell())
627 for kabxys in final_cross_products:
628
629 for l in range(self.dataOut.DPL): #lag
630 for fl in range(2): # unflip and flip
631 for k in range(self.dataOut.NDT): #RANGE
632 kabxys[k,l,fl].astype('float32').tofile(self.fp)
633
634
635 #print("tell before noise saving ",self.outputfile.tell())
636
637
638 for nch in range(self.dataOut.NR):
639 self.dataOut.noise_final[nch].astype('float32').tofile(self.fp)
640
641 #print("tell before noise saving ",self.fp.tell())
642 #input()
643
644
645
646
647 log.log(
648 'Writing {} blocks'.format(
649 self.counter+1),
650 'DatWriter')
651
652
653
654
655
656
657 def putData(self):
658 #print("flagNoData",self.dataOut.flagNoData)
659 #print("flagDiscontinuousBlock",self.dataOut.flagDiscontinuousBlock)
660 #print(self.dataOut.flagNoData)
661
662 if self.dataOut.flagNoData:
663 return 0
664
665 if self.dataOut.flagDiscontinuousBlock:
666
667 self.counter = 0
668
669 if self.counter == 0:
670 self.setFile()
671 #if self.experiment=="HP":
672 #if self.dataOut.debris_activated==0:
673 #self.writeBlock()
674 #self.counter += 1
675 #else:
676 self.writeBlock()
677 self.counter += 1
678
679 def close(self):
680
681 if self.counter > 0:
682 self.fp.close()
683 log.success('Closing file {}'.format(self.fullname), 'DatWriter')
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
@@ -76,6 +76,8 def hildebrand_sekhon(data, navg):
76 """
76 """
77
77
78 sortdata = numpy.sort(data, axis=None)
78 sortdata = numpy.sort(data, axis=None)
79 #print(numpy.shape(data))
80 #exit()
79 '''
81 '''
80 lenOfData = len(sortdata)
82 lenOfData = len(sortdata)
81 nums_min = lenOfData*0.2
83 nums_min = lenOfData*0.2
@@ -273,13 +275,13 class JROData(GenericData):
273 '''
275 '''
274 '''
276 '''
275 return self.radarControllerHeaderObj.ippSeconds
277 return self.radarControllerHeaderObj.ippSeconds
276
278
277 @ippSeconds.setter
279 @ippSeconds.setter
278 def ippSeconds(self, ippSeconds):
280 def ippSeconds(self, ippSeconds):
279 '''
281 '''
280 '''
282 '''
281 self.radarControllerHeaderObj.ippSeconds = ippSeconds
283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
282
284
283 @property
285 @property
284 def code(self):
286 def code(self):
285 '''
287 '''
@@ -370,7 +372,7 class Voltage(JROData):
370 self.flagShiftFFT = False
372 self.flagShiftFFT = False
371 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
373 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
372 self.profileIndex = 0
374 self.profileIndex = 0
373 self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt',
375 self.metadata_list = ['type', 'heightList', 'timeZone', 'nProfiles', 'channelList', 'nCohInt',
374 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp']
376 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp']
375
377
376 def getNoisebyHildebrand(self, channel=None):
378 def getNoisebyHildebrand(self, channel=None):
@@ -428,6 +430,103 class Voltage(JROData):
428 noise = property(getNoise, "I'm the 'nHeights' property.")
430 noise = property(getNoise, "I'm the 'nHeights' property.")
429
431
430
432
433 class CrossProds(JROData):
434
435 # data es un numpy array de 2 dmensiones (canales, alturas)
436 data = None
437
438 def __init__(self):
439 '''
440 Constructor
441 '''
442
443 self.useLocalTime = True
444 '''
445 self.radarControllerHeaderObj = RadarControllerHeader()
446 self.systemHeaderObj = SystemHeader()
447 self.type = "Voltage"
448 self.data = None
449 # self.dtype = None
450 # self.nChannels = 0
451 # self.nHeights = 0
452 self.nProfiles = None
453 self.heightList = None
454 self.channelList = None
455 # self.channelIndexList = None
456 self.flagNoData = True
457 self.flagDiscontinuousBlock = False
458 self.utctime = None
459 self.timeZone = None
460 self.dstFlag = None
461 self.errorCount = None
462 self.nCohInt = None
463 self.blocksize = None
464 self.flagDecodeData = False # asumo q la data no esta decodificada
465 self.flagDeflipData = False # asumo q la data no esta sin flip
466 self.flagShiftFFT = False
467 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
468 self.profileIndex = 0
469
470
471 def getNoisebyHildebrand(self, channel=None):
472
473
474 if channel != None:
475 data = self.data[channel]
476 nChannels = 1
477 else:
478 data = self.data
479 nChannels = self.nChannels
480
481 noise = numpy.zeros(nChannels)
482 power = data * numpy.conjugate(data)
483
484 for thisChannel in range(nChannels):
485 if nChannels == 1:
486 daux = power[:].real
487 else:
488 daux = power[thisChannel, :].real
489 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
490
491 return noise
492
493 def getNoise(self, type=1, channel=None):
494
495 if type == 1:
496 noise = self.getNoisebyHildebrand(channel)
497
498 return noise
499
500 def getPower(self, channel=None):
501
502 if channel != None:
503 data = self.data[channel]
504 else:
505 data = self.data
506
507 power = data * numpy.conjugate(data)
508 powerdB = 10 * numpy.log10(power.real)
509 powerdB = numpy.squeeze(powerdB)
510
511 return powerdB
512
513 def getTimeInterval(self):
514
515 timeInterval = self.ippSeconds * self.nCohInt
516
517 return timeInterval
518
519 noise = property(getNoise, "I'm the 'nHeights' property.")
520 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
521 '''
522 def getTimeInterval(self):
523
524 timeInterval = self.ippSeconds * self.nCohInt
525
526 return timeInterval
527
528
529
431 class Spectra(JROData):
530 class Spectra(JROData):
432
531
433 def __init__(self):
532 def __init__(self):
@@ -458,7 +557,7 class Spectra(JROData):
458 self.ippFactor = 1
557 self.ippFactor = 1
459 self.beacon_heiIndexList = []
558 self.beacon_heiIndexList = []
460 self.noise_estimation = None
559 self.noise_estimation = None
461 self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt',
560 self.metadata_list = ['type', 'heightList', 'timeZone', 'pairsList', 'channelList', 'nCohInt',
462 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles']
561 'code', 'nCode', 'nBaud', 'ippSeconds', 'ipp','nIncohInt', 'nFFTPoints', 'nProfiles']
463
562
464 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
563 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
@@ -608,7 +707,7 class Spectra(JROData):
608 print("This property should not be initialized")
707 print("This property should not be initialized")
609
708
610 return
709 return
611
710
612 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
711 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
613
712
614
713
@@ -705,7 +804,7 class Fits(JROData):
705 return self.ipp_sec
804 return self.ipp_sec
706
805
707 noise = property(getNoise, "I'm the 'nHeights' property.")
806 noise = property(getNoise, "I'm the 'nHeights' property.")
708
807
709
808
710 class Correlation(JROData):
809 class Correlation(JROData):
711
810
@@ -886,6 +985,7 class Parameters(Spectra):
886 else:
985 else:
887 return self.paramInterval
986 return self.paramInterval
888
987
988
889 def setValue(self, value):
989 def setValue(self, value):
890
990
891 print("This property should not be initialized")
991 print("This property should not be initialized")
@@ -928,6 +1028,10 class PlotterData(object):
928 self.plottypes = ['cspc', 'spc', 'noise', 'rti']
1028 self.plottypes = ['cspc', 'spc', 'noise', 'rti']
929 elif code == 'rti':
1029 elif code == 'rti':
930 self.plottypes = ['noise', 'rti']
1030 self.plottypes = ['noise', 'rti']
1031 elif code == 'crossprod':
1032 self.plottypes = ['crossprod', 'kay']
1033 elif code == 'spectrogram':
1034 self.plottypes = ['spc', 'spectrogram']
931 else:
1035 else:
932 self.plottypes = [code]
1036 self.plottypes = [code]
933
1037
@@ -976,9 +1080,11 class PlotterData(object):
976 plot = 'snr'
1080 plot = 'snr'
977 elif 'spc_moments' == plot:
1081 elif 'spc_moments' == plot:
978 plot = 'moments'
1082 plot = 'moments'
1083 elif 'spc_oblique' == plot:
1084 plot = 'oblique'
979 self.data[plot] = {}
1085 self.data[plot] = {}
980
1086
981 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data:
1087 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data or 'oblique' in self.data:
982 self.data['noise'] = {}
1088 self.data['noise'] = {}
983 self.data['rti'] = {}
1089 self.data['rti'] = {}
984 if 'noise' not in self.plottypes:
1090 if 'noise' not in self.plottypes:
@@ -1020,16 +1126,33 class PlotterData(object):
1020 self.__heights.append(dataOut.heightList)
1126 self.__heights.append(dataOut.heightList)
1021 self.__all_heights.update(dataOut.heightList)
1127 self.__all_heights.update(dataOut.heightList)
1022
1128
1129
1130
1023 for plot in self.plottypes:
1131 for plot in self.plottypes:
1024 if plot in ('spc', 'spc_moments', 'spc_cut'):
1132 if plot in ('spc', 'spc_moments', 'spc_cut', 'spc_oblique'):
1133
1134
1135 self.shift1 = dataOut.Oblique_params[0][1]
1136 self.shift2 = dataOut.Oblique_params[0][4]
1137 self.shift1_error = dataOut.Oblique_param_errors[0][1]
1138 self.shift2_error = dataOut.Oblique_param_errors[0][4]
1139
1025 z = dataOut.data_spc/dataOut.normFactor
1140 z = dataOut.data_spc/dataOut.normFactor
1141 #print(dataOut.normFactor)
1142 #print(z[0,3,15])
1143 #print("here")
1144 #print(dataOut.data_spc[0,0,0])
1145 #exit()
1026 buffer = 10*numpy.log10(z)
1146 buffer = 10*numpy.log10(z)
1027 if plot == 'cspc':
1147 if plot == 'cspc':
1028 buffer = (dataOut.data_spc, dataOut.data_cspc)
1148 buffer = (dataOut.data_spc, dataOut.data_cspc)
1149 self.nFactor=dataOut.normFactor
1029 if plot == 'noise':
1150 if plot == 'noise':
1030 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1151 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1031 if plot in ('rti', 'spcprofile'):
1152 if plot in ('rti', 'spcprofile'):
1032 buffer = dataOut.getPower()
1153 buffer = dataOut.getPower()
1154 #print(buffer[0,0])
1155 #exit()
1033 if plot == 'snr_db':
1156 if plot == 'snr_db':
1034 buffer = dataOut.data_SNR
1157 buffer = dataOut.data_SNR
1035 if plot == 'snr':
1158 if plot == 'snr':
@@ -1048,6 +1171,277 class PlotterData(object):
1048 buffer = dataOut.data_output
1171 buffer = dataOut.data_output
1049 if plot == 'param':
1172 if plot == 'param':
1050 buffer = dataOut.data_param
1173 buffer = dataOut.data_param
1174 if plot == 'spectrogram':
1175 maxHei = 1350 #11
1176 #maxHei = 2500
1177 maxHei = 0
1178 #maxHei = 990 #12
1179 ###maxHei = 990
1180 indb = numpy.where(dataOut.heightList <= maxHei)
1181 hei = indb[0][-1]
1182 #hei = 19
1183 print(hei)
1184 #hei = 0
1185 factor = dataOut.nIncohInt
1186 #print(factor)
1187
1188 #exit(1)
1189 z = dataOut.data_spc[:,:,hei] / factor
1190
1191 #for j in range(z.shape[1]):
1192 #z[:,j] = z[:,j]/hildebrand_sekhon(z[], self.nCohInt)
1193
1194 ##z = z/hildebrand_sekhon(z, factor)
1195 noise = numpy.zeros(dataOut.nChannels)
1196 for i in range(dataOut.nChannels):
1197 #daux = numpy.sort(pair0[i,:,:],axis= None)
1198 noise[i]=hildebrand_sekhon( z[i,:] ,dataOut.nIncohInt)
1199 #for j in range(z.shape[1]):
1200 #z[:,j] = z[:,j]/noise
1201
1202 #print(z.shape[1])
1203 norm_factor = numpy.copy(z[:,int(z.shape[1]/2)])#/z[:,int(z.shape[1]/2)])*8000
1204 #print(norm_factor)
1205 #print(z[0,315:325])
1206 #norm_factor = norm_factor.reshape((z.shape[0],z.shape[1]))
1207 #print(norm_factor)
1208 #exit(1)
1209 #print(z.shape[1])
1210
1211 #for j in range(z.shape[1]):
1212 #z[:,j] = z[:,j]/norm_factor
1213
1214 #print(z[0,315:325])
1215 #exit(1)
1216
1217 #z = numpy.mean(dataOut.data_spc[:,:,:],axis=2) / factor
1218 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1219 #avg = numpy.average(z, axis=1)
1220 #print((dataOut.data_spc.shape))
1221 #exit(1)
1222 self.hei = hei
1223 self.heightList = dataOut.heightList
1224 self.DH = (dataOut.heightList[1] - dataOut.heightList[0])/dataOut.step
1225 self.nProfiles = dataOut.nProfiles
1226 #print(dataOut.heightList)
1227
1228
1229 buffer = 10 * numpy.log10(z)
1230
1231
1232 ###buffer = z
1233 import matplotlib.pyplot as plt
1234 fig, axes = plt.subplots(figsize=(14, 10))
1235 x = numpy.linspace(0,20,numpy.shape(buffer)[1])
1236 x = numpy.fft.fftfreq(numpy.shape(buffer)[1],0.00001)
1237 x = numpy.fft.fftshift(x)
1238
1239 plt.plot(x,buffer[0,:])
1240 axes = plt.gca()
1241 axes.set_xlim([-10000,10000])
1242
1243 #axes.set_xlim([0,30000])
1244 #axes.set_ylim([-100,0.0025*1e10])
1245 plt.show()
1246 import time
1247 #time.sleep(20)
1248 #exit(1)
1249
1250
1251
1252 #if dataOut.profileIndex
1253
1254 if plot == 'xmit':
1255 y_1=numpy.arctan2(dataOut.output_LP[:,0,2].imag,dataOut.output_LP[:,0,2].real)* 180 / (numpy.pi*10)
1256 y_2=numpy.abs(dataOut.output_LP[:,0,2])
1257 norm=numpy.max(y_2)
1258 norm=max(norm,0.1)
1259 y_2=y_2/norm
1260
1261 buffer = numpy.vstack((y_1,y_2))
1262 self.NLAG = dataOut.NLAG
1263
1264 if plot == 'crossprod':
1265 buffer = dataOut.crossprods
1266 self.NDP = dataOut.NDP
1267
1268 if plot == 'crossprodlp':
1269 buffer = 10*numpy.log10(numpy.abs(dataOut.output_LP))
1270 self.NRANGE = dataOut.NRANGE
1271 self.NLAG = dataOut.NLAG
1272
1273
1274 if plot == 'noisedp':
1275 buffer = 10*numpy.log10(dataOut.noise_final)
1276 #print(buffer)
1277
1278 if plot == 'FaradayAngle':
1279 buffer = numpy.degrees(dataOut.phi)
1280 #print(buffer)
1281
1282 if plot == 'RTIDP':
1283 buffer = dataOut.data_for_RTI_DP
1284 self.NDP = dataOut.NDP
1285
1286 if plot == 'RTILP':
1287 buffer = dataOut.data_for_RTI_LP
1288 self.NRANGE = dataOut.NRANGE
1289
1290
1291 if plot == 'denrti':
1292 buffer = dataOut.DensityFinal
1293
1294
1295 if plot == 'denrtiLP':
1296
1297 #buffer = numpy.reshape(numpy.concatenate((dataOut.ph2[:dataOut.cut],dataOut.ne[dataOut.cut:dataOut.NACF])),(1,-1))
1298 buffer = dataOut.DensityFinal
1299 #self.flagDataAsBlock = dataOut.flagDataAsBlock
1300 #self.NDP = dataOut.NDP
1301 if plot == 'den':
1302 buffer = dataOut.ph2[:dataOut.NSHTS]
1303 self.dphi=dataOut.dphi[:dataOut.NSHTS]
1304 self.sdp2=dataOut.sdp2[:dataOut.NSHTS]
1305 self.sdn1=dataOut.sdn1[:dataOut.NSHTS]#/self.dphi
1306 self.NSHTS=dataOut.NSHTS
1307 '''
1308 flag1=False
1309 flag0=True
1310 for i in range(12,dataOut.NSHTS):
1311 print("H: ",i*15)
1312 print(abs((dataOut.sdn1[i]/(dataOut.dphi[i]**2))*100))
1313 if flag0:
1314 if abs((dataOut.sdn1[i]/dataOut.dphi[i]))<0.0005*abs(dataOut.dphi[i]):
1315 print("***************************** FIRST: ",(i)*15,"*****************************")
1316 flag1=True
1317 flag0=False
1318 #pass
1319 #print("****************************************GOOD****************************************")
1320 #else:
1321 #print("****************************************",(i-1)*15,"****************************************")
1322 #break
1323 if flag1:
1324 if abs((dataOut.sdn1[i]/dataOut.dphi[i]))>0.0005*abs(dataOut.dphi[i]):
1325 print("***************************** LAST: ",(i-1)*15,"*****************************")
1326 break
1327 #print("H: ",i*15)
1328 #print(dataOut.sdn1[i])
1329 '''
1330 if plot == 'denLP':
1331 buffer = dataOut.ph2[:dataOut.NSHTS]
1332 self.dphi=dataOut.dphi[:dataOut.NSHTS]
1333 self.sdp2=dataOut.sdp2[:dataOut.NSHTS]
1334 self.ne=dataOut.ne[:dataOut.NACF]
1335 self.ene=dataOut.ene[:dataOut.NACF]*dataOut.ne[:dataOut.NACF]*0.434
1336 #self.ene=10**dataOut.ene[:dataOut.NACF]
1337 self.NSHTS=dataOut.NSHTS
1338 self.cut=dataOut.cut
1339
1340 if plot == 'ETemp':
1341 #buffer = dataOut.ElecTempClean
1342 buffer = dataOut.ElecTempFinal
1343 if plot == 'ITemp':
1344 #buffer = dataOut.IonTempClean
1345 buffer = dataOut.IonTempFinal
1346 if plot == 'ETempLP':
1347 #buffer = dataOut.IonTempClean
1348 #buffer = numpy.reshape(numpy.concatenate((dataOut.te2[:dataOut.cut],dataOut.te[dataOut.cut:])),(1,-1))
1349 buffer = dataOut.ElecTempFinal
1350 #print(buffer)
1351 if plot == 'ITempLP':
1352 #buffer = dataOut.IonTempClean
1353 #buffer = numpy.reshape(numpy.concatenate((dataOut.ti2[:dataOut.cut],dataOut.ti[dataOut.cut:])),(1,-1))
1354 buffer = dataOut.IonTempFinal
1355
1356 if plot == 'HFracLP':
1357 #buffer = dataOut.IonTempClean
1358 #buffer = numpy.reshape(numpy.concatenate((dataOut.phy2[:dataOut.cut],dataOut.ph[dataOut.cut:])),(1,-1))
1359 buffer = dataOut.PhyFinal
1360 if plot == 'HeFracLP':
1361 #buffer = dataOut.IonTempClean
1362 #nan_array=numpy.empty((dataOut.cut))
1363 #nan_array[:]=numpy.nan
1364 #buffer = numpy.reshape(numpy.concatenate((nan_array,dataOut.phe[dataOut.cut:])),(1,-1))
1365 buffer = dataOut.PheFinal
1366
1367
1368
1369
1370
1371 if plot =='acfs':
1372 buffer = dataOut.acfs_to_plot
1373 self.acfs_error_to_plot=dataOut.acfs_error_to_plot
1374 self.lags_to_plot=dataOut.lags_to_plot
1375 self.x_igcej_to_plot=dataOut.x_igcej_to_plot
1376 self.x_ibad_to_plot=dataOut.x_ibad_to_plot
1377 self.y_igcej_to_plot=dataOut.y_igcej_to_plot
1378 self.y_ibad_to_plot=dataOut.y_ibad_to_plot
1379 self.NSHTS = dataOut.NSHTS
1380 self.DPL = dataOut.DPL
1381 if plot =='acfs_LP':
1382
1383 aux=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
1384 self.errors=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
1385 self.lags_LP_to_plot=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
1386 '''
1387 for i in range(dataOut.NACF):
1388 for j in range(dataOut.IBITS):
1389 aux[i,j]=dataOut.fit_array_real[i,j]/dataOut.fit_array_real[i,0]
1390 aux[i,j]=max(min(aux[i,j],1.0),-1.0)*dataOut.DH+dataOut.heightList[i]
1391 '''
1392 for i in range(dataOut.NACF):
1393 for j in range(dataOut.IBITS):
1394 if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0:
1395 aux[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0]
1396 aux[i,j]=max(min(aux[i,j],1.0),-1.0)*dataOut.DH+dataOut.heightList[i]
1397 self.lags_LP_to_plot[i,j]=dataOut.lags_LP[j]
1398 self.errors[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0]*dataOut.DH
1399 else:
1400 aux[i,j]=numpy.nan
1401 self.lags_LP_to_plot[i,j]=numpy.nan
1402 self.errors[i,j]=numpy.nan
1403
1404
1405
1406 buffer = aux
1407
1408 #self.lags_LP_to_plot=dataOut.lags_LP
1409
1410 self.NACF = dataOut.NACF
1411 self.NLAG = dataOut.NLAG
1412
1413 if plot == 'tempsDP':
1414
1415 buffer = dataOut.te2
1416 self.ete2 = dataOut.ete2
1417 self.ti2 = dataOut.ti2
1418 self.eti2 = dataOut.eti2
1419
1420 self.NSHTS = dataOut.NSHTS
1421
1422 if plot == 'temps_LP':
1423
1424 buffer = numpy.concatenate((dataOut.te2[:dataOut.cut],dataOut.te[dataOut.cut:]))
1425 self.ete = numpy.concatenate((dataOut.ete2[:dataOut.cut],dataOut.ete[dataOut.cut:]))
1426 self.ti = numpy.concatenate((dataOut.ti2[:dataOut.cut],dataOut.ti[dataOut.cut:]))
1427 self.eti = numpy.concatenate((dataOut.eti2[:dataOut.cut],dataOut.eti[dataOut.cut:]))
1428
1429 self.NACF = dataOut.NACF
1430
1431
1432 if plot == 'fracs_LP':
1433
1434 aux_nan=numpy.zeros(dataOut.cut,'float32')
1435 aux_nan[:]=numpy.nan
1436 buffer = numpy.concatenate((aux_nan,dataOut.ph[dataOut.cut:]))
1437 self.eph = numpy.concatenate((aux_nan,dataOut.eph[dataOut.cut:]))
1438 self.phe = dataOut.phe[dataOut.cut:]
1439 self.ephe = dataOut.ephe[dataOut.cut:]
1440
1441 self.NACF = dataOut.NACF
1442 self.cut = dataOut.cut
1443
1444
1051 if plot == 'scope':
1445 if plot == 'scope':
1052 buffer = dataOut.data
1446 buffer = dataOut.data
1053 self.flagDataAsBlock = dataOut.flagDataAsBlock
1447 self.flagDataAsBlock = dataOut.flagDataAsBlock
@@ -1076,6 +1470,10 class PlotterData(object):
1076 elif plot == 'spc_moments':
1470 elif plot == 'spc_moments':
1077 self.data['spc'][tm] = buffer
1471 self.data['spc'][tm] = buffer
1078 self.data['moments'][tm] = dataOut.moments
1472 self.data['moments'][tm] = dataOut.moments
1473 elif plot == 'spc_oblique':
1474 self.data['spc'][tm] = buffer
1475 self.data['shift1'][tm] = dataOut.Oblique_params[0]
1476 self.data['shift2'][tm] = dataOut.Oblique_params[3]
1079 else:
1477 else:
1080 if self.buffering:
1478 if self.buffering:
1081 self.data[plot][tm] = buffer
1479 self.data[plot][tm] = buffer
@@ -1141,6 +1539,7 class PlotterData(object):
1141 meta['interval'] = float(self.interval)
1539 meta['interval'] = float(self.interval)
1142 meta['localtime'] = self.localtime
1540 meta['localtime'] = self.localtime
1143 meta['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1541 meta['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1542
1144 if 'spc' in self.data or 'cspc' in self.data:
1543 if 'spc' in self.data or 'cspc' in self.data:
1145 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1544 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1146 else:
1545 else:
@@ -137,7 +137,7 class BasicHeader(Header):
137 timeZone = None
137 timeZone = None
138 dstFlag = None
138 dstFlag = None
139 errorCount = None
139 errorCount = None
140 datatime = None
140 F = None
141 structure = BASIC_STRUCTURE
141 structure = BASIC_STRUCTURE
142 __LOCALTIME = None
142 __LOCALTIME = None
143
143
@@ -363,6 +363,7 class RadarControllerHeader(Header):
363 self.expType = int(header['nExpType'][0])
363 self.expType = int(header['nExpType'][0])
364 self.nTx = int(header['nNTx'][0])
364 self.nTx = int(header['nNTx'][0])
365 self.ipp = float(header['fIpp'][0])
365 self.ipp = float(header['fIpp'][0])
366 #print(self.ipp)
366 self.txA = float(header['fTxA'][0])
367 self.txA = float(header['fTxA'][0])
367 self.txB = float(header['fTxB'][0])
368 self.txB = float(header['fTxB'][0])
368 self.nWindows = int(header['nNumWindows'][0])
369 self.nWindows = int(header['nNumWindows'][0])
@@ -534,6 +535,7 class RadarControllerHeader(Header):
534 def get_ippSeconds(self):
535 def get_ippSeconds(self):
535 '''
536 '''
536 '''
537 '''
538
537 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
539 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
538
540
539 return ippSeconds
541 return ippSeconds
@@ -640,6 +642,7 class ProcessingHeader(Header):
640 self.nWindows = int(header['nNumWindows'][0])
642 self.nWindows = int(header['nNumWindows'][0])
641 self.processFlags = header['nProcessFlags']
643 self.processFlags = header['nProcessFlags']
642 self.nCohInt = int(header['nCoherentIntegrations'][0])
644 self.nCohInt = int(header['nCoherentIntegrations'][0])
645
643 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
646 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
644 self.totalSpectra = int(header['nTotalSpectra'][0])
647 self.totalSpectra = int(header['nTotalSpectra'][0])
645
648
@@ -903,4 +906,4 def get_procflag_dtype(index):
903
906
904 def get_dtype_width(index):
907 def get_dtype_width(index):
905
908
906 return DTYPE_WIDTH[index] No newline at end of file
909 return DTYPE_WIDTH[index]
@@ -3,3 +3,4 from .jroplot_spectra import *
3 from .jroplot_heispectra import *
3 from .jroplot_heispectra import *
4 from .jroplot_correlation import *
4 from .jroplot_correlation import *
5 from .jroplot_parameters import *
5 from .jroplot_parameters import *
6 from .jroplot_voltage_lags import *
@@ -221,6 +221,10 class Plot(Operation):
221 self.zmin = kwargs.get('zmin', None)
221 self.zmin = kwargs.get('zmin', None)
222 self.zmax = kwargs.get('zmax', None)
222 self.zmax = kwargs.get('zmax', None)
223 self.zlimits = kwargs.get('zlimits', None)
223 self.zlimits = kwargs.get('zlimits', None)
224 self.xlimits = kwargs.get('xlimits', None)
225 self.xstep_given = kwargs.get('xstep_given', None)
226 self.ystep_given = kwargs.get('ystep_given', None)
227 self.autoxticks = kwargs.get('autoxticks', True)
224 self.xmin = kwargs.get('xmin', None)
228 self.xmin = kwargs.get('xmin', None)
225 self.xmax = kwargs.get('xmax', None)
229 self.xmax = kwargs.get('xmax', None)
226 self.xrange = kwargs.get('xrange', 12)
230 self.xrange = kwargs.get('xrange', 12)
@@ -253,7 +257,7 class Plot(Operation):
253 self.__throttle_plot = apply_throttle(self.throttle)
257 self.__throttle_plot = apply_throttle(self.throttle)
254 self.data = PlotterData(
258 self.data = PlotterData(
255 self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR)
259 self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR)
256
260
257 if self.server:
261 if self.server:
258 if not self.server.startswith('tcp://'):
262 if not self.server.startswith('tcp://'):
259 self.server = 'tcp://{}'.format(self.server)
263 self.server = 'tcp://{}'.format(self.server)
@@ -269,7 +273,7 class Plot(Operation):
269
273
270 self.setup()
274 self.setup()
271
275
272 self.time_label = 'LT' if self.localtime else 'UTC'
276 self.time_label = 'LT' if self.localtime else 'UTC'
273
277
274 if self.width is None:
278 if self.width is None:
275 self.width = 8
279 self.width = 8
@@ -374,7 +378,7 class Plot(Operation):
374 '''
378 '''
375 Set min and max values, labels, ticks and titles
379 Set min and max values, labels, ticks and titles
376 '''
380 '''
377
381
378 for n, ax in enumerate(self.axes):
382 for n, ax in enumerate(self.axes):
379 if ax.firsttime:
383 if ax.firsttime:
380 if self.xaxis != 'time':
384 if self.xaxis != 'time':
@@ -457,14 +461,14 class Plot(Operation):
457
461
458 self.plot()
462 self.plot()
459 self.format()
463 self.format()
460
464
461 for n, fig in enumerate(self.figures):
465 for n, fig in enumerate(self.figures):
462 if self.nrows == 0 or self.nplots == 0:
466 if self.nrows == 0 or self.nplots == 0:
463 log.warning('No data', self.name)
467 log.warning('No data', self.name)
464 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
468 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
465 fig.canvas.manager.set_window_title(self.CODE)
469 fig.canvas.manager.set_window_title(self.CODE)
466 continue
470 continue
467
471
468 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
472 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
469 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
473 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
470 fig.canvas.draw()
474 fig.canvas.draw()
@@ -474,7 +478,7 class Plot(Operation):
474
478
475 if self.save:
479 if self.save:
476 self.save_figure(n)
480 self.save_figure(n)
477
481
478 if self.server:
482 if self.server:
479 self.send_to_server()
483 self.send_to_server()
480
484
@@ -492,7 +496,7 class Plot(Operation):
492 figname = os.path.join(
496 figname = os.path.join(
493 self.save,
497 self.save,
494 self.save_code,
498 self.save_code,
495 '{}_{}.png'.format(
499 '{}_{}.png'.format(
496 self.save_code,
500 self.save_code,
497 self.getDateTime(self.data.max_time).strftime(
501 self.getDateTime(self.data.max_time).strftime(
498 '%Y%m%d_%H%M%S'
502 '%Y%m%d_%H%M%S'
@@ -525,7 +529,7 class Plot(Operation):
525 return
529 return
526
530
527 self.sender_time = self.data.tm
531 self.sender_time = self.data.tm
528
532
529 attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax']
533 attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax']
530 for attr in attrs:
534 for attr in attrs:
531 value = getattr(self, attr)
535 value = getattr(self, attr)
@@ -546,7 +550,7 class Plot(Operation):
546 except:
550 except:
547 tm = self.sender_queue.get()
551 tm = self.sender_queue.get()
548 self.sender_queue.put(self.data.tm)
552 self.sender_queue.put(self.data.tm)
549
553
550 while True:
554 while True:
551 if self.sender_queue.empty():
555 if self.sender_queue.empty():
552 break
556 break
@@ -588,7 +592,7 class Plot(Operation):
588 self.ncols: number of cols
592 self.ncols: number of cols
589 self.nplots: number of plots (channels or pairs)
593 self.nplots: number of plots (channels or pairs)
590 self.ylabel: label for Y axes
594 self.ylabel: label for Y axes
591 self.titles: list of axes title
595 self.titles: list of axes title
592
596
593 '''
597 '''
594 raise NotImplementedError
598 raise NotImplementedError
@@ -598,12 +602,13 class Plot(Operation):
598 Must be defined in the child class
602 Must be defined in the child class
599 '''
603 '''
600 raise NotImplementedError
604 raise NotImplementedError
601
605
602 def run(self, dataOut, **kwargs):
606 def run(self, dataOut, **kwargs):
603 '''
607 '''
604 Main plotting routine
608 Main plotting routine
605 '''
609 '''
606
610 print("time_inside_plot: ",dataOut.datatime)
611 print(dataOut.flagNoData)
607 if self.isConfig is False:
612 if self.isConfig is False:
608 self.__setup(**kwargs)
613 self.__setup(**kwargs)
609
614
@@ -622,8 +627,8 class Plot(Operation):
622 self.poll.register(self.socket, zmq.POLLIN)
627 self.poll.register(self.socket, zmq.POLLIN)
623
628
624 tm = getattr(dataOut, self.attr_time)
629 tm = getattr(dataOut, self.attr_time)
625
630
626 if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60:
631 if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60:
627 self.save_time = tm
632 self.save_time = tm
628 self.__plot()
633 self.__plot()
629 self.tmin += self.xrange*60*60
634 self.tmin += self.xrange*60*60
@@ -639,7 +644,7 class Plot(Operation):
639 dt = self.getDateTime(tm)
644 dt = self.getDateTime(tm)
640 if self.xmin is None:
645 if self.xmin is None:
641 self.tmin = tm
646 self.tmin = tm
642 self.xmin = dt.hour
647 self.xmin = dt.hour
643 minutes = (self.xmin-int(self.xmin)) * 60
648 minutes = (self.xmin-int(self.xmin)) * 60
644 seconds = (minutes - int(minutes)) * 60
649 seconds = (minutes - int(minutes)) * 60
645 self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) -
650 self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) -
@@ -662,4 +667,3 class Plot(Operation):
662 self.__plot()
667 self.__plot()
663 if self.data and not self.data.flagNoData and self.pause:
668 if self.data and not self.data.flagNoData and self.pause:
664 figpause(10)
669 figpause(10)
665
@@ -38,6 +38,15 class SpectralMomentsPlot(SpectraPlot):
38 colormap = 'jet'
38 colormap = 'jet'
39 plot_type = 'pcolor'
39 plot_type = 'pcolor'
40
40
41 class SpectralFitObliquePlot(SpectraPlot):
42 '''
43 Plot for Spectral Oblique
44 '''
45 CODE = 'spc_moments'
46 colormap = 'jet'
47 plot_type = 'pcolor'
48
49
41
50
42 class SnrPlot(RTIPlot):
51 class SnrPlot(RTIPlot):
43 '''
52 '''
@@ -137,10 +146,10 class ParametersPlot(RTIPlot):
137 self.nrows = self.data.shape(self.CODE)[0]
146 self.nrows = self.data.shape(self.CODE)[0]
138 self.nplots = self.nrows
147 self.nplots = self.nrows
139 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
148 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95, 'top': 0.95})
140
149
141 if not self.xlabel:
150 if not self.xlabel:
142 self.xlabel = 'Time'
151 self.xlabel = 'Time'
143
152
144 if self.showSNR:
153 if self.showSNR:
145 self.nrows += 1
154 self.nrows += 1
146 self.nplots += 1
155 self.nplots += 1
@@ -336,4 +345,3 class PolarMapPlot(Plot):
336 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
345 self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels]
337 self.titles = ['{} {}'.format(
346 self.titles = ['{} {}'.format(
338 self.data.parameters[x], title) for x in self.channels]
347 self.data.parameters[x], title) for x in self.channels]
339
This diff has been collapsed as it changes many lines, (572 lines changed) Show them Hide them
@@ -22,6 +22,7 class SpectraPlot(Plot):
22 plot_type = 'pcolor'
22 plot_type = 'pcolor'
23
23
24 def setup(self):
24 def setup(self):
25
25 self.nplots = len(self.data.channels)
26 self.nplots = len(self.data.channels)
26 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
27 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
27 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
28 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
@@ -31,10 +32,13 class SpectraPlot(Plot):
31 self.width = 4 * self.ncols
32 self.width = 4 * self.ncols
32 else:
33 else:
33 self.width = 3.5 * self.ncols
34 self.width = 3.5 * self.ncols
34 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
35 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
35 self.ylabel = 'Range [km]'
36 self.ylabel = 'Range [km]'
36
37
37 def plot(self):
38 def plot(self):
39
40 #print(self.xaxis)
41 #exit(1)
38 if self.xaxis == "frequency":
42 if self.xaxis == "frequency":
39 x = self.data.xrange[0]
43 x = self.data.xrange[0]
40 self.xlabel = "Frequency (kHz)"
44 self.xlabel = "Frequency (kHz)"
@@ -51,19 +55,25 class SpectraPlot(Plot):
51
55
52 self.titles = []
56 self.titles = []
53
57
58
54 y = self.data.heights
59 y = self.data.heights
55 self.y = y
60 self.y = y
56 z = self.data['spc']
61 z = self.data['spc']
57
62
63 self.CODE2 = 'spc_oblique'
64
65
58 for n, ax in enumerate(self.axes):
66 for n, ax in enumerate(self.axes):
59 noise = self.data['noise'][n][-1]
67 noise = self.data['noise'][n][-1]
60 if self.CODE == 'spc_moments':
68 if self.CODE == 'spc_moments':
61 mean = self.data['moments'][n, :, 1, :][-1]
69 mean = self.data['moments'][n, :, 1, :][-1]
70
62 if ax.firsttime:
71 if ax.firsttime:
63 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
72 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
64 self.xmin = self.xmin if self.xmin else -self.xmax
73 self.xmin = self.xmin if self.xmin else -self.xmax
65 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
74 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
66 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
75 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
76 #print(numpy.shape(x))
67 ax.plt = ax.pcolormesh(x, y, z[n].T,
77 ax.plt = ax.pcolormesh(x, y, z[n].T,
68 vmin=self.zmin,
78 vmin=self.zmin,
69 vmax=self.zmax,
79 vmax=self.zmax,
@@ -77,15 +87,122 class SpectraPlot(Plot):
77 color="k", linestyle="dashed", lw=1)[0]
87 color="k", linestyle="dashed", lw=1)[0]
78 if self.CODE == 'spc_moments':
88 if self.CODE == 'spc_moments':
79 ax.plt_mean = ax.plot(mean, y, color='k')[0]
89 ax.plt_mean = ax.plot(mean, y, color='k')[0]
90
80 else:
91 else:
92
81 ax.plt.set_array(z[n].T.ravel())
93 ax.plt.set_array(z[n].T.ravel())
82 if self.showprofile:
94 if self.showprofile:
83 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
95 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
84 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
96 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
85 if self.CODE == 'spc_moments':
97 if self.CODE == 'spc_moments':
86 ax.plt_mean.set_data(mean, y)
98 ax.plt_mean.set_data(mean, y)
99
87 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
100 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
88
101
102 class SpectraObliquePlot(Plot):
103 '''
104 Plot for Spectra data
105 '''
106
107 CODE = 'spc'
108 colormap = 'jet'
109 plot_type = 'pcolor'
110
111 def setup(self):
112 self.xaxis = "oblique"
113 self.nplots = len(self.data.channels)
114 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
115 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
116 self.height = 2.6 * self.nrows
117 self.cb_label = 'dB'
118 if self.showprofile:
119 self.width = 4 * self.ncols
120 else:
121 self.width = 3.5 * self.ncols
122 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
123 self.ylabel = 'Range [km]'
124
125 def plot(self):
126
127 #print(self.xaxis)
128 #exit(1)
129 if self.xaxis == "frequency":
130 x = self.data.xrange[0]
131 self.xlabel = "Frequency (kHz)"
132 elif self.xaxis == "time":
133 x = self.data.xrange[1]
134 self.xlabel = "Time (ms)"
135 else:
136 x = self.data.xrange[2]
137 self.xlabel = "Velocity (m/s)"
138
139 if self.CODE == 'spc_moments':
140 x = self.data.xrange[2]
141 self.xlabel = "Velocity (m/s)"
142
143 self.titles = []
144 #self.xlabel = "Velocidad (m/s)"
145 #self.ylabel = 'Rango (km)'
146
147
148 y = self.data.heights
149 self.y = y
150 z = self.data['spc']
151
152 self.CODE2 = 'spc_oblique'
153
154
155 for n, ax in enumerate(self.axes):
156 noise = self.data['noise'][n][-1]
157 if self.CODE == 'spc_moments':
158 mean = self.data['moments'][n, :, 1, :][-1]
159 if self.CODE2 == 'spc_oblique':
160 shift1 = self.data.shift1
161 shift2 = self.data.shift2
162 if ax.firsttime:
163 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
164 self.xmin = self.xmin if self.xmin else -self.xmax
165 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
166 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
167 #print(numpy.shape(x))
168 ax.plt = ax.pcolormesh(x, y, z[n].T,
169 vmin=self.zmin,
170 vmax=self.zmax,
171 cmap=plt.get_cmap(self.colormap)
172 )
173
174 if self.showprofile:
175 ax.plt_profile = self.pf_axes[n].plot(
176 self.data['rti'][n][-1], y)[0]
177 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
178 color="k", linestyle="dashed", lw=1)[0]
179 if self.CODE == 'spc_moments':
180 ax.plt_mean = ax.plot(mean, y, color='k')[0]
181
182 if self.CODE2 == 'spc_oblique':
183 #ax.plt_shift1 = ax.plot(shift1, y, color='k', marker='x', linestyle='None', markersize=0.5)[0]
184 #ax.plt_shift2 = ax.plot(shift2, y, color='m', marker='x', linestyle='None', markersize=0.5)[0]
185 self.ploterr1 = ax.errorbar(shift1, y, xerr=self.data.shift1_error,fmt='k^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
186 self.ploterr2 = ax.errorbar(shift2, y, xerr=self.data.shift2_error,fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
187
188 else:
189 self.ploterr1.remove()
190 self.ploterr2.remove()
191 ax.plt.set_array(z[n].T.ravel())
192 if self.showprofile:
193 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
194 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
195 if self.CODE == 'spc_moments':
196 ax.plt_mean.set_data(mean, y)
197 if self.CODE2 == 'spc_oblique':
198 #ax.plt_shift1.set_data(shift1, y)
199 #ax.plt_shift2.set_data(shift2, y)
200 #ax.clf()
201 self.ploterr1 = ax.errorbar(shift1, y, xerr=self.data.shift1_error,fmt='k^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
202 self.ploterr2 = ax.errorbar(shift2, y, xerr=self.data.shift2_error,fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
203
204 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
205 #self.titles.append('{}'.format('Velocidad Doppler'))
89
206
90 class CrossSpectraPlot(Plot):
207 class CrossSpectraPlot(Plot):
91
208
@@ -103,7 +220,7 class CrossSpectraPlot(Plot):
103 self.nrows = len(self.data.pairs)
220 self.nrows = len(self.data.pairs)
104 self.nplots = self.nrows * 4
221 self.nplots = self.nrows * 4
105 self.width = 3.1 * self.ncols
222 self.width = 3.1 * self.ncols
106 self.height = 2.6 * self.nrows
223 self.height = 5 * self.nrows
107 self.ylabel = 'Range [km]'
224 self.ylabel = 'Range [km]'
108 self.showprofile = False
225 self.showprofile = False
109 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
226 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
@@ -119,30 +236,44 class CrossSpectraPlot(Plot):
119 else:
236 else:
120 x = self.data.xrange[2]
237 x = self.data.xrange[2]
121 self.xlabel = "Velocity (m/s)"
238 self.xlabel = "Velocity (m/s)"
122
239
123 self.titles = []
240 self.titles = []
124
241
242
125 y = self.data.heights
243 y = self.data.heights
126 self.y = y
244 self.y = y
127 nspc = self.data['spc']
245 nspc = self.data['spc']
246 #print(numpy.shape(self.data['spc']))
128 spc = self.data['cspc'][0]
247 spc = self.data['cspc'][0]
248 #print(numpy.shape(spc))
249 #exit()
129 cspc = self.data['cspc'][1]
250 cspc = self.data['cspc'][1]
251 #print(numpy.shape(cspc))
252 #exit()
130
253
131 for n in range(self.nrows):
254 for n in range(self.nrows):
132 noise = self.data['noise'][:,-1]
255 noise = self.data['noise'][:,-1]
133 pair = self.data.pairs[n]
256 pair = self.data.pairs[n]
257 #print(pair)
258 #exit()
134 ax = self.axes[4 * n]
259 ax = self.axes[4 * n]
135 if ax.firsttime:
260 if ax.firsttime:
136 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
261 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
137 self.xmin = self.xmin if self.xmin else -self.xmax
262 #self.xmin = self.xmin if self.xmin else -self.xmax
138 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
263 self.xmin = self.xmin if self.xmin else numpy.nanmin(x)
139 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
264 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
265 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
266 #print(numpy.nanmin(x))
267 #print(self.xmax)
268 #print(self.xmin)
269 #exit()
270 #self.xmin=-.1
140 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
271 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
141 vmin=self.zmin,
272 vmin=self.zmin,
142 vmax=self.zmax,
273 vmax=self.zmax,
143 cmap=plt.get_cmap(self.colormap)
274 cmap=plt.get_cmap(self.colormap)
144 )
275 )
145 else:
276 else:
146 ax.plt.set_array(nspc[pair[0]].T.ravel())
277 ax.plt.set_array(nspc[pair[0]].T.ravel())
147 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
278 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
148
279
@@ -153,10 +284,10 class CrossSpectraPlot(Plot):
153 vmax=self.zmax,
284 vmax=self.zmax,
154 cmap=plt.get_cmap(self.colormap)
285 cmap=plt.get_cmap(self.colormap)
155 )
286 )
156 else:
287 else:
157 ax.plt.set_array(nspc[pair[1]].T.ravel())
288 ax.plt.set_array(nspc[pair[1]].T.ravel())
158 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
289 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
159
290
160 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
291 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
161 coh = numpy.abs(out)
292 coh = numpy.abs(out)
162 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
293 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
@@ -172,19 +303,345 class CrossSpectraPlot(Plot):
172 ax.plt.set_array(coh.T.ravel())
303 ax.plt.set_array(coh.T.ravel())
173 self.titles.append(
304 self.titles.append(
174 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
305 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
175
306
176 ax = self.axes[4 * n + 3]
307 ax = self.axes[4 * n + 3]
177 if ax.firsttime:
308 if ax.firsttime:
178 ax.plt = ax.pcolormesh(x, y, phase.T,
309 ax.plt = ax.pcolormesh(x, y, phase.T,
179 vmin=-180,
310 vmin=-180,
180 vmax=180,
311 vmax=180,
181 cmap=plt.get_cmap(self.colormap_phase)
312 cmap=plt.get_cmap(self.colormap_phase)
182 )
313 )
183 else:
314 else:
184 ax.plt.set_array(phase.T.ravel())
315 ax.plt.set_array(phase.T.ravel())
185 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
316 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
186
317
187
318
319 class CrossSpectra4Plot(Plot):
320
321 CODE = 'cspc'
322 colormap = 'jet'
323 plot_type = 'pcolor'
324 zmin_coh = None
325 zmax_coh = None
326 zmin_phase = None
327 zmax_phase = None
328
329 def setup(self):
330
331 self.ncols = 4
332 self.nrows = len(self.data.pairs)
333 self.nplots = self.nrows * 4
334 self.width = 3.1 * self.ncols
335 self.height = 5 * self.nrows
336 self.ylabel = 'Range [km]'
337 self.showprofile = False
338 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
339
340 def plot(self):
341
342 if self.xaxis == "frequency":
343 x = self.data.xrange[0]
344 self.xlabel = "Frequency (kHz)"
345 elif self.xaxis == "time":
346 x = self.data.xrange[1]
347 self.xlabel = "Time (ms)"
348 else:
349 x = self.data.xrange[2]
350 self.xlabel = "Velocity (m/s)"
351
352 self.titles = []
353
354
355 y = self.data.heights
356 self.y = y
357 nspc = self.data['spc']
358 #print(numpy.shape(self.data['spc']))
359 spc = self.data['cspc'][0]
360 #print(numpy.shape(nspc))
361 #exit()
362 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
363 #print(numpy.shape(spc))
364 #exit()
365 cspc = self.data['cspc'][1]
366
367 #xflip=numpy.flip(x)
368 #print(numpy.shape(cspc))
369 #exit()
370
371 for n in range(self.nrows):
372 noise = self.data['noise'][:,-1]
373 pair = self.data.pairs[n]
374 #print(pair)
375 #exit()
376 ax = self.axes[4 * n]
377 if ax.firsttime:
378 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
379 self.xmin = self.xmin if self.xmin else -self.xmax
380 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
381 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
382 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
383 vmin=self.zmin,
384 vmax=self.zmax,
385 cmap=plt.get_cmap(self.colormap)
386 )
387 else:
388 #print(numpy.shape(nspc[pair[0]].T))
389 #exit()
390 ax.plt.set_array(nspc[pair[0]].T.ravel())
391 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
392
393 ax = self.axes[4 * n + 1]
394
395 if ax.firsttime:
396 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
397 vmin=self.zmin,
398 vmax=self.zmax,
399 cmap=plt.get_cmap(self.colormap)
400 )
401 else:
402
403 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
404 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
405
406 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
407 coh = numpy.abs(out)
408 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
409
410 ax = self.axes[4 * n + 2]
411 if ax.firsttime:
412 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
413 vmin=0,
414 vmax=1,
415 cmap=plt.get_cmap(self.colormap_coh)
416 )
417 else:
418 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
419 self.titles.append(
420 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
421
422 ax = self.axes[4 * n + 3]
423 if ax.firsttime:
424 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
425 vmin=-180,
426 vmax=180,
427 cmap=plt.get_cmap(self.colormap_phase)
428 )
429 else:
430 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
431 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
432
433
434 class CrossSpectra2Plot(Plot):
435
436 CODE = 'cspc'
437 colormap = 'jet'
438 plot_type = 'pcolor'
439 zmin_coh = None
440 zmax_coh = None
441 zmin_phase = None
442 zmax_phase = None
443
444 def setup(self):
445
446 self.ncols = 1
447 self.nrows = len(self.data.pairs)
448 self.nplots = self.nrows * 1
449 self.width = 3.1 * self.ncols
450 self.height = 5 * self.nrows
451 self.ylabel = 'Range [km]'
452 self.showprofile = False
453 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
454
455 def plot(self):
456
457 if self.xaxis == "frequency":
458 x = self.data.xrange[0]
459 self.xlabel = "Frequency (kHz)"
460 elif self.xaxis == "time":
461 x = self.data.xrange[1]
462 self.xlabel = "Time (ms)"
463 else:
464 x = self.data.xrange[2]
465 self.xlabel = "Velocity (m/s)"
466
467 self.titles = []
468
469
470 y = self.data.heights
471 self.y = y
472 #nspc = self.data['spc']
473 #print(numpy.shape(self.data['spc']))
474 #spc = self.data['cspc'][0]
475 #print(numpy.shape(spc))
476 #exit()
477 cspc = self.data['cspc'][1]
478 #print(numpy.shape(cspc))
479 #exit()
480
481 for n in range(self.nrows):
482 noise = self.data['noise'][:,-1]
483 pair = self.data.pairs[n]
484 #print(pair) #exit()
485
486
487
488 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
489
490 #print(out[:,53])
491 #exit()
492 cross = numpy.abs(out)
493 z = cross/self.data.nFactor
494 #print("here")
495 #print(dataOut.data_spc[0,0,0])
496 #exit()
497
498 cross = 10*numpy.log10(z)
499 #print(numpy.shape(cross))
500 #print(cross[0,:])
501 #print(self.data.nFactor)
502 #exit()
503 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
504
505 ax = self.axes[1 * n]
506 if ax.firsttime:
507 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
508 self.xmin = self.xmin if self.xmin else -self.xmax
509 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
510 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
511 ax.plt = ax.pcolormesh(x, y, cross.T,
512 vmin=self.zmin,
513 vmax=self.zmax,
514 cmap=plt.get_cmap(self.colormap)
515 )
516 else:
517 ax.plt.set_array(cross.T.ravel())
518 self.titles.append(
519 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
520
521
522 class CrossSpectra3Plot(Plot):
523
524 CODE = 'cspc'
525 colormap = 'jet'
526 plot_type = 'pcolor'
527 zmin_coh = None
528 zmax_coh = None
529 zmin_phase = None
530 zmax_phase = None
531
532 def setup(self):
533
534 self.ncols = 3
535 self.nrows = len(self.data.pairs)
536 self.nplots = self.nrows * 3
537 self.width = 3.1 * self.ncols
538 self.height = 5 * self.nrows
539 self.ylabel = 'Range [km]'
540 self.showprofile = False
541 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
542
543 def plot(self):
544
545 if self.xaxis == "frequency":
546 x = self.data.xrange[0]
547 self.xlabel = "Frequency (kHz)"
548 elif self.xaxis == "time":
549 x = self.data.xrange[1]
550 self.xlabel = "Time (ms)"
551 else:
552 x = self.data.xrange[2]
553 self.xlabel = "Velocity (m/s)"
554
555 self.titles = []
556
557
558 y = self.data.heights
559 self.y = y
560 #nspc = self.data['spc']
561 #print(numpy.shape(self.data['spc']))
562 #spc = self.data['cspc'][0]
563 #print(numpy.shape(spc))
564 #exit()
565 cspc = self.data['cspc'][1]
566 #print(numpy.shape(cspc))
567 #exit()
568
569 for n in range(self.nrows):
570 noise = self.data['noise'][:,-1]
571 pair = self.data.pairs[n]
572 #print(pair) #exit()
573
574
575
576 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
577
578 #print(out[:,53])
579 #exit()
580 cross = numpy.abs(out)
581 z = cross/self.data.nFactor
582 cross = 10*numpy.log10(z)
583
584 out_r= out.real/self.data.nFactor
585 #out_r = 10*numpy.log10(out_r)
586
587 out_i= out.imag/self.data.nFactor
588 #out_i = 10*numpy.log10(out_i)
589 #print(numpy.shape(cross))
590 #print(cross[0,:])
591 #print(self.data.nFactor)
592 #exit()
593 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
594
595 ax = self.axes[3 * n]
596 if ax.firsttime:
597 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
598 self.xmin = self.xmin if self.xmin else -self.xmax
599 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
600 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
601 ax.plt = ax.pcolormesh(x, y, cross.T,
602 vmin=self.zmin,
603 vmax=self.zmax,
604 cmap=plt.get_cmap(self.colormap)
605 )
606 else:
607 ax.plt.set_array(cross.T.ravel())
608 self.titles.append(
609 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
610
611 ax = self.axes[3 * n + 1]
612 if ax.firsttime:
613 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
614 self.xmin = self.xmin if self.xmin else -self.xmax
615 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
616 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
617 ax.plt = ax.pcolormesh(x, y, out_r.T,
618 vmin=-1.e6,
619 vmax=0,
620 cmap=plt.get_cmap(self.colormap)
621 )
622 else:
623 ax.plt.set_array(out_r.T.ravel())
624 self.titles.append(
625 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
626
627 ax = self.axes[3 * n + 2]
628
629
630 if ax.firsttime:
631 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
632 self.xmin = self.xmin if self.xmin else -self.xmax
633 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
634 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
635 ax.plt = ax.pcolormesh(x, y, out_i.T,
636 vmin=-1.e6,
637 vmax=1.e6,
638 cmap=plt.get_cmap(self.colormap)
639 )
640 else:
641 ax.plt.set_array(out_i.T.ravel())
642 self.titles.append(
643 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
644
188 class RTIPlot(Plot):
645 class RTIPlot(Plot):
189 '''
646 '''
190 Plot for RTI data
647 Plot for RTI data
@@ -202,7 +659,7 class RTIPlot(Plot):
202 self.ylabel = 'Range [km]'
659 self.ylabel = 'Range [km]'
203 self.xlabel = 'Time'
660 self.xlabel = 'Time'
204 self.cb_label = 'dB'
661 self.cb_label = 'dB'
205 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
662 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
206 self.titles = ['{} Channel {}'.format(
663 self.titles = ['{} Channel {}'.format(
207 self.CODE.upper(), x) for x in range(self.nrows)]
664 self.CODE.upper(), x) for x in range(self.nrows)]
208
665
@@ -210,6 +667,78 class RTIPlot(Plot):
210 self.x = self.data.times
667 self.x = self.data.times
211 self.y = self.data.heights
668 self.y = self.data.heights
212 self.z = self.data[self.CODE]
669 self.z = self.data[self.CODE]
670
671 self.z = numpy.ma.masked_invalid(self.z)
672
673 if self.decimation is None:
674 x, y, z = self.fill_gaps(self.x, self.y, self.z)
675 else:
676 x, y, z = self.fill_gaps(*self.decimate())
677
678 for n, ax in enumerate(self.axes):
679 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
680 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
681 if ax.firsttime:
682 ax.plt = ax.pcolormesh(x, y, z[n].T,
683 vmin=self.zmin,
684 vmax=self.zmax,
685 cmap=plt.get_cmap(self.colormap)
686 )
687 if self.showprofile:
688 ax.plot_profile = self.pf_axes[n].plot(
689 self.data['rti'][n][-1], self.y)[0]
690 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
691 color="k", linestyle="dashed", lw=1)[0]
692 else:
693 ax.collections.remove(ax.collections[0])
694 ax.plt = ax.pcolormesh(x, y, z[n].T,
695 vmin=self.zmin,
696 vmax=self.zmax,
697 cmap=plt.get_cmap(self.colormap)
698 )
699 if self.showprofile:
700 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
701 ax.plot_noise.set_data(numpy.repeat(
702 self.data['noise'][n][-1], len(self.y)), self.y)
703
704
705 class SpectrogramPlot(Plot):
706 '''
707 Plot for Spectrogram data
708 '''
709
710 CODE = 'spectrogram'
711 colormap = 'binary'
712 plot_type = 'pcolorbuffer'
713
714 def setup(self):
715 self.xaxis = 'time'
716 self.ncols = 1
717 self.nrows = len(self.data.channels)
718 self.nplots = len(self.data.channels)
719 #print(self.dataOut.heightList)
720 #self.ylabel = 'Range [km]'
721 self.xlabel = 'Time'
722 self.cb_label = 'dB'
723 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
724 self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
725 self.CODE.upper(), x, self.data.heightList[self.data.hei], self.data.heightList[self.data.hei],self.data.heightList[self.data.hei]+(self.data.DH*self.data.nProfiles)) for x in range(self.nrows)]
726
727 def plot(self):
728 self.x = self.data.times
729 #self.y = self.data.heights
730 self.z = self.data[self.CODE]
731 self.y = self.data.xrange[0]
732 #import time
733 #print(time.ctime(self.x))
734
735 '''
736 print(numpy.shape(self.x))
737 print(numpy.shape(self.y))
738 print(numpy.shape(self.z))
739 '''
740 self.ylabel = "Frequency (kHz)"
741
213 self.z = numpy.ma.masked_invalid(self.z)
742 self.z = numpy.ma.masked_invalid(self.z)
214
743
215 if self.decimation is None:
744 if self.decimation is None:
@@ -280,7 +809,7 class PhasePlot(CoherencePlot):
280
809
281 class NoisePlot(Plot):
810 class NoisePlot(Plot):
282 '''
811 '''
283 Plot for noise
812 Plot for noise
284 '''
813 '''
285
814
286 CODE = 'noise'
815 CODE = 'noise'
@@ -296,6 +825,7 class NoisePlot(Plot):
296 self.xlabel = 'Time'
825 self.xlabel = 'Time'
297 self.titles = ['Noise']
826 self.titles = ['Noise']
298 self.colorbar = False
827 self.colorbar = False
828 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.17, 'right':0.95})
299
829
300 def plot(self):
830 def plot(self):
301
831
@@ -315,7 +845,7 class NoisePlot(Plot):
315 self.axes[0].lines[ch].set_data(x, y)
845 self.axes[0].lines[ch].set_data(x, y)
316
846
317 self.ymin = numpy.nanmin(Y) - 5
847 self.ymin = numpy.nanmin(Y) - 5
318 self.ymax = numpy.nanmax(Y) + 5
848 self.ymax = numpy.nanmax(Y) + 10
319
849
320
850
321 class PowerProfilePlot(Plot):
851 class PowerProfilePlot(Plot):
@@ -342,10 +872,10 class PowerProfilePlot(Plot):
342 self.y = y
872 self.y = y
343
873
344 x = self.data['spcprofile']
874 x = self.data['spcprofile']
345
875
346 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
876 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
347 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
877 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
348
878
349 if self.axes[0].firsttime:
879 if self.axes[0].firsttime:
350 for ch in self.data.channels:
880 for ch in self.data.channels:
351 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
881 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
@@ -498,7 +1028,7 class BeaconPhase(Plot):
498 server=None, folder=None, username=None, password=None,
1028 server=None, folder=None, username=None, password=None,
499 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1029 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
500
1030
501 if dataOut.flagNoData:
1031 if dataOut.flagNoData:
502 return dataOut
1032 return dataOut
503
1033
504 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1034 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
@@ -638,4 +1168,4 class BeaconPhase(Plot):
638 thisDatetime=thisDatetime,
1168 thisDatetime=thisDatetime,
639 update_figfile=update_figfile)
1169 update_figfile=update_figfile)
640
1170
641 return dataOut No newline at end of file
1171 return dataOut
@@ -21,4 +21,9 from .jroIO_mira35c import *
21 from .julIO_param import *
21 from .julIO_param import *
22
22
23 from .pxIO_param import *
23 from .pxIO_param import *
24 from .jroIO_simulator import * No newline at end of file
24 from .jroIO_simulator import *
25
26 ############DP############
27 from .jroIO_dat import *
28
29 ############DP############
@@ -78,6 +78,7 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
78 basicHeaderObj = BasicHeader(LOCALTIME)
78 basicHeaderObj = BasicHeader(LOCALTIME)
79
79
80 try:
80 try:
81
81 fp = open(filename, 'rb')
82 fp = open(filename, 'rb')
82 except IOError:
83 except IOError:
83 print("The file %s can't be opened" % (filename))
84 print("The file %s can't be opened" % (filename))
@@ -140,6 +141,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
140
141
141 firstBasicHeaderObj = BasicHeader(LOCALTIME)
142 firstBasicHeaderObj = BasicHeader(LOCALTIME)
142 systemHeaderObj = SystemHeader()
143 systemHeaderObj = SystemHeader()
144
143 radarControllerHeaderObj = RadarControllerHeader()
145 radarControllerHeaderObj = RadarControllerHeader()
144 processingHeaderObj = ProcessingHeader()
146 processingHeaderObj = ProcessingHeader()
145
147
@@ -384,7 +386,7 def isRadarFolder(folder):
384
386
385
387
386 def isRadarFile(file):
388 def isRadarFile(file):
387 try:
389 try:
388 year = int(file[1:5])
390 year = int(file[1:5])
389 doy = int(file[5:8])
391 doy = int(file[5:8])
390 set = int(file[8:11])
392 set = int(file[8:11])
@@ -395,10 +397,10 def isRadarFile(file):
395
397
396
398
397 def getDateFromRadarFile(file):
399 def getDateFromRadarFile(file):
398 try:
400 try:
399 year = int(file[1:5])
401 year = int(file[1:5])
400 doy = int(file[5:8])
402 doy = int(file[5:8])
401 set = int(file[8:11])
403 set = int(file[8:11])
402 except:
404 except:
403 return None
405 return None
404
406
@@ -417,7 +419,7 def getDateFromRadarFolder(folder):
417 return thisDate
419 return thisDate
418
420
419 def parse_format(s, fmt):
421 def parse_format(s, fmt):
420
422
421 for i in range(fmt.count('%')):
423 for i in range(fmt.count('%')):
422 x = fmt.index('%')
424 x = fmt.index('%')
423 d = DT_DIRECTIVES[fmt[x:x+2]]
425 d = DT_DIRECTIVES[fmt[x:x+2]]
@@ -484,7 +486,7 class Reader(object):
484
486
485 def run(self):
487 def run(self):
486
488
487 raise NotImplementedError
489 raise NotImplementedError
488
490
489 def getAllowedArgs(self):
491 def getAllowedArgs(self):
490 if hasattr(self, '__attrs__'):
492 if hasattr(self, '__attrs__'):
@@ -496,19 +498,19 class Reader(object):
496
498
497 for key, value in kwargs.items():
499 for key, value in kwargs.items():
498 setattr(self, key, value)
500 setattr(self, key, value)
499
501
500 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
502 def find_folders(self, path, startDate, endDate, folderfmt, last=False):
501
503
502 folders = [x for f in path.split(',')
504 folders = [x for f in path.split(',')
503 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
505 for x in os.listdir(f) if os.path.isdir(os.path.join(f, x))]
504 folders.sort()
506 folders.sort()
505
507
506 if last:
508 if last:
507 folders = [folders[-1]]
509 folders = [folders[-1]]
508
510
509 for folder in folders:
511 for folder in folders:
510 try:
512 try:
511 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
513 dt = datetime.datetime.strptime(parse_format(folder, folderfmt), folderfmt).date()
512 if dt >= startDate and dt <= endDate:
514 if dt >= startDate and dt <= endDate:
513 yield os.path.join(path, folder)
515 yield os.path.join(path, folder)
514 else:
516 else:
@@ -517,38 +519,44 class Reader(object):
517 log.log('Skiping folder {}'.format(folder), self.name)
519 log.log('Skiping folder {}'.format(folder), self.name)
518 continue
520 continue
519 return
521 return
520
522
521 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
523 def find_files(self, folders, ext, filefmt, startDate=None, endDate=None,
522 expLabel='', last=False):
524 expLabel='', last=False):
523
525
524 for path in folders:
526 for path in folders:
525 files = glob.glob1(path, '*{}'.format(ext))
527 files = glob.glob1(path, '*{}'.format(ext))
526 files.sort()
528 files.sort()
527 if last:
529 if last:
528 if files:
530 if files:
529 fo = files[-1]
531 fo = files[-1]
530 try:
532 try:
531 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
533 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
532 yield os.path.join(path, expLabel, fo)
534 yield os.path.join(path, expLabel, fo)
533 except Exception as e:
535 except Exception as e:
534 pass
536 pass
535 return
537 return
536 else:
538 else:
537 return
539 return
538
540
539 for fo in files:
541 for fo in files:
540 try:
542 try:
541 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
543 dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date()
544 #print(dt)
545 #print(startDate)
546 #print(endDate)
542 if dt >= startDate and dt <= endDate:
547 if dt >= startDate and dt <= endDate:
548
543 yield os.path.join(path, expLabel, fo)
549 yield os.path.join(path, expLabel, fo)
550
544 else:
551 else:
552
545 log.log('Skiping file {}'.format(fo), self.name)
553 log.log('Skiping file {}'.format(fo), self.name)
546 except Exception as e:
554 except Exception as e:
547 log.log('Skiping file {}'.format(fo), self.name)
555 log.log('Skiping file {}'.format(fo), self.name)
548 continue
556 continue
549
557
550 def searchFilesOffLine(self, path, startDate, endDate,
558 def searchFilesOffLine(self, path, startDate, endDate,
551 expLabel, ext, walk,
559 expLabel, ext, walk,
552 filefmt, folderfmt):
560 filefmt, folderfmt):
553 """Search files in offline mode for the given arguments
561 """Search files in offline mode for the given arguments
554
562
@@ -561,12 +569,12 class Reader(object):
561 path, startDate, endDate, folderfmt)
569 path, startDate, endDate, folderfmt)
562 else:
570 else:
563 folders = path.split(',')
571 folders = path.split(',')
564
572
565 return self.find_files(
573 return self.find_files(
566 folders, ext, filefmt, startDate, endDate, expLabel)
574 folders, ext, filefmt, startDate, endDate, expLabel)
567
575
568 def searchFilesOnLine(self, path, startDate, endDate,
576 def searchFilesOnLine(self, path, startDate, endDate,
569 expLabel, ext, walk,
577 expLabel, ext, walk,
570 filefmt, folderfmt):
578 filefmt, folderfmt):
571 """Search for the last file of the last folder
579 """Search for the last file of the last folder
572
580
@@ -579,40 +587,54 class Reader(object):
579 Return:
587 Return:
580 generator with the full path of last filename
588 generator with the full path of last filename
581 """
589 """
582
590
583 if walk:
591 if walk:
584 folders = self.find_folders(
592 folders = self.find_folders(
585 path, startDate, endDate, folderfmt, last=True)
593 path, startDate, endDate, folderfmt, last=True)
586 else:
594 else:
587 folders = path.split(',')
595 folders = path.split(',')
588
596
589 return self.find_files(
597 return self.find_files(
590 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
598 folders, ext, filefmt, startDate, endDate, expLabel, last=True)
591
599
592 def setNextFile(self):
600 def setNextFile(self):
593 """Set the next file to be readed open it and parse de file header"""
601 """Set the next file to be readed open it and parse de file header"""
594
602
603 #print("fp: ",self.fp)
595 while True:
604 while True:
605
606 #print(self.fp)
596 if self.fp != None:
607 if self.fp != None:
597 self.fp.close()
608 self.fp.close()
598
609
610 #print("setNextFile")
611 #print("BEFORE OPENING",self.filename)
599 if self.online:
612 if self.online:
600 newFile = self.setNextFileOnline()
613 newFile = self.setNextFileOnline()
614
601 else:
615 else:
616
602 newFile = self.setNextFileOffline()
617 newFile = self.setNextFileOffline()
603
618
619 #print("newFile: ",newFile)
604 if not(newFile):
620 if not(newFile):
621
605 if self.online:
622 if self.online:
606 raise schainpy.admin.SchainError('Time to wait for new files reach')
623 raise schainpy.admin.SchainError('Time to wait for new files reach')
607 else:
624 else:
608 if self.fileIndex == -1:
625 if self.fileIndex == -1:
626 #print("OKK")
609 raise schainpy.admin.SchainWarning('No files found in the given path')
627 raise schainpy.admin.SchainWarning('No files found in the given path')
610 else:
628 else:
629
611 raise schainpy.admin.SchainWarning('No more files to read')
630 raise schainpy.admin.SchainWarning('No more files to read')
612
631
613 if self.verifyFile(self.filename):
632 if self.verifyFile(self.filename):
633
614 break
634 break
615
635
636 ##print("BEFORE OPENING",self.filename)
637
616 log.log('Opening file: %s' % self.filename, self.name)
638 log.log('Opening file: %s' % self.filename, self.name)
617
639
618 self.readFirstHeader()
640 self.readFirstHeader()
@@ -625,15 +647,16 class Reader(object):
625 self.filename
647 self.filename
626 self.fp
648 self.fp
627 self.filesize
649 self.filesize
628
650
629 Return:
651 Return:
630 boolean
652 boolean
631
653
632 """
654 """
655
633 nextFile = True
656 nextFile = True
634 nextDay = False
657 nextDay = False
635
658
636 for nFiles in range(self.nFiles+1):
659 for nFiles in range(self.nFiles+1):
637 for nTries in range(self.nTries):
660 for nTries in range(self.nTries):
638 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
661 fullfilename, filename = self.checkForRealPath(nextFile, nextDay)
639 if fullfilename is not None:
662 if fullfilename is not None:
@@ -643,18 +666,18 class Reader(object):
643 self.name)
666 self.name)
644 time.sleep(self.delay)
667 time.sleep(self.delay)
645 nextFile = False
668 nextFile = False
646 continue
669 continue
647
670
648 if fullfilename is not None:
671 if fullfilename is not None:
649 break
672 break
650
673
651 self.nTries = 1
674 #self.nTries = 1
652 nextFile = True
675 nextFile = True
653
676
654 if nFiles == (self.nFiles - 1):
677 if nFiles == (self.nFiles - 1):
655 log.log('Trying with next day...', self.name)
678 log.log('Trying with next day...', self.name)
656 nextDay = True
679 nextDay = True
657 self.nTries = 3
680 self.nTries = 3
658
681
659 if fullfilename:
682 if fullfilename:
660 self.fileSize = os.path.getsize(fullfilename)
683 self.fileSize = os.path.getsize(fullfilename)
@@ -662,45 +685,48 class Reader(object):
662 self.flagIsNewFile = 1
685 self.flagIsNewFile = 1
663 if self.fp != None:
686 if self.fp != None:
664 self.fp.close()
687 self.fp.close()
688 #print(fullfilename)
665 self.fp = self.open_file(fullfilename, self.open_mode)
689 self.fp = self.open_file(fullfilename, self.open_mode)
690
666 self.flagNoMoreFiles = 0
691 self.flagNoMoreFiles = 0
667 self.fileIndex += 1
692 self.fileIndex += 1
668 return 1
693 return 1
669 else:
694 else:
670 return 0
695 return 0
671
696
672 def setNextFileOffline(self):
697 def setNextFileOffline(self):
673 """Open the next file to be readed in offline mode"""
698 """Open the next file to be readed in offline mode"""
674
699
675 try:
700 try:
676 filename = next(self.filenameList)
701 filename = next(self.filenameList)
677 self.fileIndex +=1
702 self.fileIndex +=1
678 except StopIteration:
703 except StopIteration:
679 self.flagNoMoreFiles = 1
704 self.flagNoMoreFiles = 1
680 return 0
705 return 0
681
706 #print(self.fileIndex)
707 #print(filename)
682 self.filename = filename
708 self.filename = filename
683 self.fileSize = os.path.getsize(filename)
709 self.fileSize = os.path.getsize(filename)
684 self.fp = self.open_file(filename, self.open_mode)
710 self.fp = self.open_file(filename, self.open_mode)
685 self.flagIsNewFile = 1
711 self.flagIsNewFile = 1
686
712
687 return 1
713 return 1
688
714
689 @staticmethod
715 @staticmethod
690 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
716 def isDateTimeInRange(dt, startDate, endDate, startTime, endTime):
691 """Check if the given datetime is in range"""
717 """Check if the given datetime is in range"""
692
718
693 if startDate <= dt.date() <= endDate:
719 if startDate <= dt.date() <= endDate:
694 if startTime <= dt.time() <= endTime:
720 if startTime <= dt.time() <= endTime:
695 return True
721 return True
696 return False
722 return False
697
723
698 def verifyFile(self, filename):
724 def verifyFile(self, filename):
699 """Check for a valid file
725 """Check for a valid file
700
726
701 Arguments:
727 Arguments:
702 filename -- full path filename
728 filename -- full path filename
703
729
704 Return:
730 Return:
705 boolean
731 boolean
706 """
732 """
@@ -711,10 +737,11 class Reader(object):
711 """Check if the next file to be readed exists"""
737 """Check if the next file to be readed exists"""
712
738
713 raise NotImplementedError
739 raise NotImplementedError
714
740
715 def readFirstHeader(self):
741 def readFirstHeader(self):
716 """Parse the file header"""
742 """Parse the file header"""
717
743
744
718 pass
745 pass
719
746
720 def waitDataBlock(self, pointer_location, blocksize=None):
747 def waitDataBlock(self, pointer_location, blocksize=None):
@@ -783,8 +810,8 class JRODataReader(Reader):
783 Return:
810 Return:
784 str -- fullpath of the file
811 str -- fullpath of the file
785 """
812 """
786
813
787
814
788 if nextFile:
815 if nextFile:
789 self.set += 1
816 self.set += 1
790 if nextDay:
817 if nextDay:
@@ -796,7 +823,15 class JRODataReader(Reader):
796 prefixFileList = ['d', 'D']
823 prefixFileList = ['d', 'D']
797 elif self.ext.lower() == ".pdata": # spectra
824 elif self.ext.lower() == ".pdata": # spectra
798 prefixFileList = ['p', 'P']
825 prefixFileList = ['p', 'P']
799
826
827 ##############DP##############
828
829 elif self.ext.lower() == ".dat": # dat
830 prefixFileList = ['z', 'Z']
831
832
833
834 ##############DP##############
800 # barrido por las combinaciones posibles
835 # barrido por las combinaciones posibles
801 for prefixDir in prefixDirList:
836 for prefixDir in prefixDirList:
802 thispath = self.path
837 thispath = self.path
@@ -816,9 +851,9 class JRODataReader(Reader):
816
851
817 if os.path.exists(fullfilename):
852 if os.path.exists(fullfilename):
818 return fullfilename, filename
853 return fullfilename, filename
819
854
820 return None, filename
855 return None, filename
821
856
822 def __waitNewBlock(self):
857 def __waitNewBlock(self):
823 """
858 """
824 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
859 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
@@ -853,6 +888,7 class JRODataReader(Reader):
853 return 0
888 return 0
854
889
855 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
890 print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1))
891 #print(self.filename)
856 time.sleep(self.delay)
892 time.sleep(self.delay)
857
893
858 return 0
894 return 0
@@ -860,9 +896,9 class JRODataReader(Reader):
860 def __setNewBlock(self):
896 def __setNewBlock(self):
861
897
862 if self.fp == None:
898 if self.fp == None:
863 return 0
899 return 0
864
900
865 if self.flagIsNewFile:
901 if self.flagIsNewFile:
866 self.lastUTTime = self.basicHeaderObj.utc
902 self.lastUTTime = self.basicHeaderObj.utc
867 return 1
903 return 1
868
904
@@ -875,12 +911,12 class JRODataReader(Reader):
875
911
876 currentSize = self.fileSize - self.fp.tell()
912 currentSize = self.fileSize - self.fp.tell()
877 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
913 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
878
914
879 if (currentSize >= neededSize):
915 if (currentSize >= neededSize):
880 self.basicHeaderObj.read(self.fp)
916 self.basicHeaderObj.read(self.fp)
881 self.lastUTTime = self.basicHeaderObj.utc
917 self.lastUTTime = self.basicHeaderObj.utc
882 return 1
918 return 1
883
919
884 if self.__waitNewBlock():
920 if self.__waitNewBlock():
885 self.lastUTTime = self.basicHeaderObj.utc
921 self.lastUTTime = self.basicHeaderObj.utc
886 return 1
922 return 1
@@ -921,6 +957,10 class JRODataReader(Reader):
921 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
957 print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
922 self.processingHeaderObj.dataBlocksPerFile,
958 self.processingHeaderObj.dataBlocksPerFile,
923 self.dataOut.datatime.ctime()))
959 self.dataOut.datatime.ctime()))
960 #################DP#################
961 self.dataOut.TimeBlockDate=self.dataOut.datatime.ctime()
962 self.dataOut.TimeBlockSeconds=time.mktime(time.strptime(self.dataOut.datatime.ctime()))
963 #################DP#################
924 return 1
964 return 1
925
965
926 def readFirstHeader(self):
966 def readFirstHeader(self):
@@ -966,10 +1006,10 class JRODataReader(Reader):
966 except IOError:
1006 except IOError:
967 log.error("File {} can't be opened".format(filename), self.name)
1007 log.error("File {} can't be opened".format(filename), self.name)
968 return False
1008 return False
969
1009
970 if self.online and self.waitDataBlock(0):
1010 if self.online and self.waitDataBlock(0):
971 pass
1011 pass
972
1012
973 basicHeaderObj = BasicHeader(LOCALTIME)
1013 basicHeaderObj = BasicHeader(LOCALTIME)
974 systemHeaderObj = SystemHeader()
1014 systemHeaderObj = SystemHeader()
975 radarControllerHeaderObj = RadarControllerHeader()
1015 radarControllerHeaderObj = RadarControllerHeader()
@@ -996,7 +1036,7 class JRODataReader(Reader):
996 dt2 = basicHeaderObj.datatime
1036 dt2 = basicHeaderObj.datatime
997 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
1037 if not self.isDateTimeInRange(dt1, self.startDate, self.endDate, self.startTime, self.endTime) and not \
998 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
1038 self.isDateTimeInRange(dt2, self.startDate, self.endDate, self.startTime, self.endTime):
999 flag = False
1039 flag = False
1000
1040
1001 fp.close()
1041 fp.close()
1002 return flag
1042 return flag
@@ -1105,11 +1145,11 class JRODataReader(Reader):
1105 return dateList
1145 return dateList
1106
1146
1107 def setup(self, **kwargs):
1147 def setup(self, **kwargs):
1108
1148
1109 self.set_kwargs(**kwargs)
1149 self.set_kwargs(**kwargs)
1110 if not self.ext.startswith('.'):
1150 if not self.ext.startswith('.'):
1111 self.ext = '.{}'.format(self.ext)
1151 self.ext = '.{}'.format(self.ext)
1112
1152
1113 if self.server is not None:
1153 if self.server is not None:
1114 if 'tcp://' in self.server:
1154 if 'tcp://' in self.server:
1115 address = server
1155 address = server
@@ -1131,36 +1171,36 class JRODataReader(Reader):
1131
1171
1132 for nTries in range(self.nTries):
1172 for nTries in range(self.nTries):
1133 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1173 fullpath = self.searchFilesOnLine(self.path, self.startDate,
1134 self.endDate, self.expLabel, self.ext, self.walk,
1174 self.endDate, self.expLabel, self.ext, self.walk,
1135 self.filefmt, self.folderfmt)
1175 self.filefmt, self.folderfmt)
1136
1176
1137 try:
1177 try:
1138 fullpath = next(fullpath)
1178 fullpath = next(fullpath)
1139 except:
1179 except:
1140 fullpath = None
1180 fullpath = None
1141
1181
1142 if fullpath:
1182 if fullpath:
1143 break
1183 break
1144
1184
1145 log.warning(
1185 log.warning(
1146 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1186 'Waiting {} sec for a valid file in {}: try {} ...'.format(
1147 self.delay, self.path, nTries + 1),
1187 self.delay, self.path, nTries + 1),
1148 self.name)
1188 self.name)
1149 time.sleep(self.delay)
1189 time.sleep(self.delay)
1150
1190
1151 if not(fullpath):
1191 if not(fullpath):
1152 raise schainpy.admin.SchainError(
1192 raise schainpy.admin.SchainError(
1153 'There isn\'t any valid file in {}'.format(self.path))
1193 'There isn\'t any valid file in {}'.format(self.path))
1154
1194
1155 pathname, filename = os.path.split(fullpath)
1195 pathname, filename = os.path.split(fullpath)
1156 self.year = int(filename[1:5])
1196 self.year = int(filename[1:5])
1157 self.doy = int(filename[5:8])
1197 self.doy = int(filename[5:8])
1158 self.set = int(filename[8:11]) - 1
1198 self.set = int(filename[8:11]) - 1
1159 else:
1199 else:
1160 log.log("Searching files in {}".format(self.path), self.name)
1200 log.log("Searching files in {}".format(self.path), self.name)
1161 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1201 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
1162 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1202 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
1163
1203
1164 self.setNextFile()
1204 self.setNextFile()
1165
1205
1166 return
1206 return
@@ -1181,7 +1221,7 class JRODataReader(Reader):
1181 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1221 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1182
1222
1183 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1223 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1184
1224
1185 def getFirstHeader(self):
1225 def getFirstHeader(self):
1186
1226
1187 raise NotImplementedError
1227 raise NotImplementedError
@@ -1214,8 +1254,8 class JRODataReader(Reader):
1214 """
1254 """
1215
1255
1216 Arguments:
1256 Arguments:
1217 path :
1257 path :
1218 startDate :
1258 startDate :
1219 endDate :
1259 endDate :
1220 startTime :
1260 startTime :
1221 endTime :
1261 endTime :
@@ -1284,7 +1324,7 class JRODataWriter(Reader):
1284 dtype_width = get_dtype_width(dtype_index)
1324 dtype_width = get_dtype_width(dtype_index)
1285
1325
1286 return dtype_width
1326 return dtype_width
1287
1327
1288 def getProcessFlags(self):
1328 def getProcessFlags(self):
1289
1329
1290 processFlags = 0
1330 processFlags = 0
@@ -1322,9 +1362,9 class JRODataWriter(Reader):
1322
1362
1323 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1363 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1324 self.basicHeaderObj.version = self.versionFile
1364 self.basicHeaderObj.version = self.versionFile
1325 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1365 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1326 utc = numpy.floor(self.dataOut.utctime)
1366 utc = numpy.floor(self.dataOut.utctime)
1327 milisecond = (self.dataOut.utctime - utc) * 1000.0
1367 milisecond = (self.dataOut.utctime - utc) * 1000.0
1328 self.basicHeaderObj.utc = utc
1368 self.basicHeaderObj.utc = utc
1329 self.basicHeaderObj.miliSecond = milisecond
1369 self.basicHeaderObj.miliSecond = milisecond
1330 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1370 self.basicHeaderObj.timeZone = self.dataOut.timeZone
@@ -1465,9 +1505,9 class JRODataWriter(Reader):
1465 if self.dataOut.datatime.date() > self.fileDate:
1505 if self.dataOut.datatime.date() > self.fileDate:
1466 setFile = 0
1506 setFile = 0
1467 self.nTotalBlocks = 0
1507 self.nTotalBlocks = 0
1468
1508
1469 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1509 filen = '{}{:04d}{:03d}{:03d}{}'.format(
1470 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1510 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1471
1511
1472 filename = os.path.join(path, subfolder, filen)
1512 filename = os.path.join(path, subfolder, filen)
1473
1513
@@ -1515,11 +1555,11 class JRODataWriter(Reader):
1515 self.ext = ext.lower()
1555 self.ext = ext.lower()
1516
1556
1517 self.path = path
1557 self.path = path
1518
1558
1519 if set is None:
1559 if set is None:
1520 self.setFile = -1
1560 self.setFile = -1
1521 else:
1561 else:
1522 self.setFile = set - 1
1562 self.setFile = set - 1
1523
1563
1524 self.blocksPerFile = blocksPerFile
1564 self.blocksPerFile = blocksPerFile
1525 self.profilesPerBlock = profilesPerBlock
1565 self.profilesPerBlock = profilesPerBlock
@@ -38,7 +38,7 DEF_CATALOG = {
38 'sciRemarks': '',
38 'sciRemarks': '',
39 'instRemarks': ''
39 'instRemarks': ''
40 }
40 }
41
41
42 DEF_HEADER = {
42 DEF_HEADER = {
43 'kindatDesc': '',
43 'kindatDesc': '',
44 'analyst': 'Jicamarca User',
44 'analyst': 'Jicamarca User',
@@ -75,7 +75,7 def load_json(obj):
75 for k, v in list(iterable.items())}
75 for k, v in list(iterable.items())}
76 elif isinstance(iterable, (list, tuple)):
76 elif isinstance(iterable, (list, tuple)):
77 return [str(v) if isinstance(v, basestring) else v for v in iterable]
77 return [str(v) if isinstance(v, basestring) else v for v in iterable]
78
78
79 return iterable
79 return iterable
80
80
81
81
@@ -85,18 +85,18 class MADReader(Reader, ProcessingUnit):
85
85
86 ProcessingUnit.__init__(self)
86 ProcessingUnit.__init__(self)
87
87
88 self.dataOut = Parameters()
88 self.dataOut = Parameters()
89 self.counter_records = 0
89 self.counter_records = 0
90 self.nrecords = None
90 self.nrecords = None
91 self.flagNoMoreFiles = 0
91 self.flagNoMoreFiles = 0
92 self.filename = None
92 self.filename = None
93 self.intervals = set()
93 self.intervals = set()
94 self.datatime = datetime.datetime(1900,1,1)
94 self.datatime = datetime.datetime(1900,1,1)
95 self.format = None
95 self.format = None
96 self.filefmt = "***%Y%m%d*******"
96 self.filefmt = "***%Y%m%d*******"
97
97
98 def setup(self, **kwargs):
98 def setup(self, **kwargs):
99
99
100 self.set_kwargs(**kwargs)
100 self.set_kwargs(**kwargs)
101 self.oneDDict = load_json(self.oneDDict)
101 self.oneDDict = load_json(self.oneDDict)
102 self.twoDDict = load_json(self.twoDDict)
102 self.twoDDict = load_json(self.twoDDict)
@@ -125,32 +125,32 class MADReader(Reader, ProcessingUnit):
125
125
126 for nTries in range(self.nTries):
126 for nTries in range(self.nTries):
127 fullpath = self.searchFilesOnLine(self.path, self.startDate,
127 fullpath = self.searchFilesOnLine(self.path, self.startDate,
128 self.endDate, self.expLabel, self.ext, self.walk,
128 self.endDate, self.expLabel, self.ext, self.walk,
129 self.filefmt, self.folderfmt)
129 self.filefmt, self.folderfmt)
130
130
131 try:
131 try:
132 fullpath = next(fullpath)
132 fullpath = next(fullpath)
133 except:
133 except:
134 fullpath = None
134 fullpath = None
135
135
136 if fullpath:
136 if fullpath:
137 break
137 break
138
138
139 log.warning(
139 log.warning(
140 'Waiting {} sec for a valid file in {}: try {} ...'.format(
140 'Waiting {} sec for a valid file in {}: try {} ...'.format(
141 self.delay, self.path, nTries + 1),
141 self.delay, self.path, nTries + 1),
142 self.name)
142 self.name)
143 time.sleep(self.delay)
143 time.sleep(self.delay)
144
144
145 if not(fullpath):
145 if not(fullpath):
146 raise schainpy.admin.SchainError(
146 raise schainpy.admin.SchainError(
147 'There isn\'t any valid file in {}'.format(self.path))
147 'There isn\'t any valid file in {}'.format(self.path))
148
148
149 else:
149 else:
150 log.log("Searching files in {}".format(self.path), self.name)
150 log.log("Searching files in {}".format(self.path), self.name)
151 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
151 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
152 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
152 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
153
153
154 self.setNextFile()
154 self.setNextFile()
155
155
156 def readFirstHeader(self):
156 def readFirstHeader(self):
@@ -159,8 +159,8 class MADReader(Reader, ProcessingUnit):
159 self.parseHeader()
159 self.parseHeader()
160 self.parseData()
160 self.parseData()
161 self.blockIndex = 0
161 self.blockIndex = 0
162
162
163 return
163 return
164
164
165 def parseHeader(self):
165 def parseHeader(self):
166 '''
166 '''
@@ -183,7 +183,7 class MADReader(Reader, ProcessingUnit):
183 if s_parameters:
183 if s_parameters:
184 log.success('Spatial parameters found: {}'.format(s_parameters),
184 log.success('Spatial parameters found: {}'.format(s_parameters),
185 'MADReader')
185 'MADReader')
186
186
187 for param in list(self.oneDDict.keys()):
187 for param in list(self.oneDDict.keys()):
188 if param.lower() not in self.parameters:
188 if param.lower() not in self.parameters:
189 log.warning(
189 log.warning(
@@ -191,7 +191,7 class MADReader(Reader, ProcessingUnit):
191 param),
191 param),
192 'MADReader')
192 'MADReader')
193 self.oneDDict.pop(param, None)
193 self.oneDDict.pop(param, None)
194
194
195 for param, value in list(self.twoDDict.items()):
195 for param, value in list(self.twoDDict.items()):
196 if param.lower() not in self.parameters:
196 if param.lower() not in self.parameters:
197 log.warning(
197 log.warning(
@@ -226,10 +226,10 class MADReader(Reader, ProcessingUnit):
226 while True:
226 while True:
227 self.flagDiscontinuousBlock = 0
227 self.flagDiscontinuousBlock = 0
228 if self.counter_records == self.nrecords:
228 if self.counter_records == self.nrecords:
229 self.setNextFile()
229 self.setNextFile()
230
230
231 self.readBlock()
231 self.readBlock()
232
232
233 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
233 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
234 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
234 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
235 log.warning(
235 log.warning(
@@ -268,7 +268,7 class MADReader(Reader, ProcessingUnit):
268 if self.counter_records == self.nrecords:
268 if self.counter_records == self.nrecords:
269 break
269 break
270 continue
270 continue
271 self.intervals.add((datatime-self.datatime).seconds)
271 self.intervals.add((datatime-self.datatime).seconds)
272 break
272 break
273 elif self.ext == '.hdf5':
273 elif self.ext == '.hdf5':
274 datatime = datetime.datetime.utcfromtimestamp(
274 datatime = datetime.datetime.utcfromtimestamp(
@@ -278,27 +278,27 class MADReader(Reader, ProcessingUnit):
278 if datatime.date()>self.datatime.date():
278 if datatime.date()>self.datatime.date():
279 self.flagDiscontinuousBlock = 1
279 self.flagDiscontinuousBlock = 1
280 self.datatime = datatime
280 self.datatime = datatime
281 self.counter_records += 1
281 self.counter_records += 1
282
282
283 self.buffer = numpy.array(dum)
283 self.buffer = numpy.array(dum)
284 return
284 return
285
285
286 def set_output(self):
286 def set_output(self):
287 '''
287 '''
288 Storing data from buffer to dataOut object
288 Storing data from buffer to dataOut object
289 '''
289 '''
290
290
291 parameters = [None for __ in self.parameters]
291 parameters = [None for __ in self.parameters]
292
292
293 for param, attr in list(self.oneDDict.items()):
293 for param, attr in list(self.oneDDict.items()):
294 x = self.parameters.index(param.lower())
294 x = self.parameters.index(param.lower())
295 setattr(self.dataOut, attr, self.buffer[0][x])
295 setattr(self.dataOut, attr, self.buffer[0][x])
296
296
297 for param, value in list(self.twoDDict.items()):
297 for param, value in list(self.twoDDict.items()):
298 dummy = numpy.zeros(self.ranges.shape) + numpy.nan
298 dummy = numpy.zeros(self.ranges.shape) + numpy.nan
299 if self.ext == '.txt':
299 if self.ext == '.txt':
300 x = self.parameters.index(param.lower())
300 x = self.parameters.index(param.lower())
301 y = self.parameters.index(self.independentParam.lower())
301 y = self.parameters.index(self.independentParam.lower())
302 ranges = self.buffer[:,y]
302 ranges = self.buffer[:,y]
303 #if self.ranges.size == ranges.size:
303 #if self.ranges.size == ranges.size:
304 # continue
304 # continue
@@ -308,23 +308,23 class MADReader(Reader, ProcessingUnit):
308 ranges = self.buffer[self.independentParam.lower()]
308 ranges = self.buffer[self.independentParam.lower()]
309 index = numpy.where(numpy.in1d(self.ranges, ranges))[0]
309 index = numpy.where(numpy.in1d(self.ranges, ranges))[0]
310 dummy[index] = self.buffer[param.lower()]
310 dummy[index] = self.buffer[param.lower()]
311
311
312 if isinstance(value, str):
312 if isinstance(value, str):
313 if value not in self.independentParam:
313 if value not in self.independentParam:
314 setattr(self.dataOut, value, dummy.reshape(1,-1))
314 setattr(self.dataOut, value, dummy.reshape(1,-1))
315 elif isinstance(value, list):
315 elif isinstance(value, list):
316 self.output[value[0]][value[1]] = dummy
316 self.output[value[0]][value[1]] = dummy
317 parameters[value[1]] = param
317 parameters[value[1]] = param
318 for key, value in list(self.output.items()):
318 for key, value in list(self.output.items()):
319 setattr(self.dataOut, key, numpy.array(value))
319 setattr(self.dataOut, key, numpy.array(value))
320
320
321 self.dataOut.parameters = [s for s in parameters if s]
321 self.dataOut.parameters = [s for s in parameters if s]
322 self.dataOut.heightList = self.ranges
322 self.dataOut.heightList = self.ranges
323 self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds()
323 self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds()
324 self.dataOut.utctimeInit = self.dataOut.utctime
324 self.dataOut.utctimeInit = self.dataOut.utctime
325 self.dataOut.paramInterval = min(self.intervals)
325 self.dataOut.paramInterval = min(self.intervals)
326 self.dataOut.useLocalTime = False
326 self.dataOut.useLocalTime = False
327 self.dataOut.flagNoData = False
327 self.dataOut.flagNoData = False
328 self.dataOut.nrecords = self.nrecords
328 self.dataOut.nrecords = self.nrecords
329 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
329 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
330
330
@@ -354,7 +354,7 class MADReader(Reader, ProcessingUnit):
354 @MPDecorator
354 @MPDecorator
355 class MADWriter(Operation):
355 class MADWriter(Operation):
356 '''Writing module for Madrigal files
356 '''Writing module for Madrigal files
357
357
358 type: external
358 type: external
359
359
360 Inputs:
360 Inputs:
@@ -384,7 +384,7 Inputs:
384
384
385 __attrs__ = ['path', 'oneDDict', 'ind2DList', 'twoDDict','metadata', 'format', 'blocks']
385 __attrs__ = ['path', 'oneDDict', 'ind2DList', 'twoDDict','metadata', 'format', 'blocks']
386 missing = -32767
386 missing = -32767
387
387
388 def __init__(self):
388 def __init__(self):
389
389
390 Operation.__init__(self)
390 Operation.__init__(self)
@@ -395,27 +395,31 Inputs:
395
395
396 def run(self, dataOut, path, oneDDict, ind2DList='[]', twoDDict='{}',
396 def run(self, dataOut, path, oneDDict, ind2DList='[]', twoDDict='{}',
397 metadata='{}', format='cedar', **kwargs):
397 metadata='{}', format='cedar', **kwargs):
398
398
399
400 #if dataOut.AUX==1: #Modified
401
399 if not self.isConfig:
402 if not self.isConfig:
400 self.setup(path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs)
403 self.setup(path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs)
401 self.isConfig = True
404 self.isConfig = True
402
405
403 self.dataOut = dataOut
406 self.dataOut = dataOut
404 self.putData()
407 self.putData()
408
405 return 1
409 return 1
406
410
407 def setup(self, path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs):
411 def setup(self, path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs):
408 '''
412 '''
409 Configure Operation
413 Configure Operation
410 '''
414 '''
411
415
412 self.path = path
416 self.path = path
413 self.blocks = kwargs.get('blocks', None)
417 self.blocks = kwargs.get('blocks', None)
414 self.counter = 0
418 self.counter = 0
415 self.oneDDict = load_json(oneDDict)
419 self.oneDDict = load_json(oneDDict)
416 self.twoDDict = load_json(twoDDict)
420 self.twoDDict = load_json(twoDDict)
417 self.ind2DList = load_json(ind2DList)
421 self.ind2DList = load_json(ind2DList)
418 meta = load_json(metadata)
422 meta = load_json(metadata)
419 self.kinst = meta.get('kinst')
423 self.kinst = meta.get('kinst')
420 self.kindat = meta.get('kindat')
424 self.kindat = meta.get('kindat')
421 self.catalog = meta.get('catalog', DEF_CATALOG)
425 self.catalog = meta.get('catalog', DEF_CATALOG)
@@ -426,8 +430,8 Inputs:
426 elif format == 'hdf5':
430 elif format == 'hdf5':
427 self.ext = '.hdf5'
431 self.ext = '.hdf5'
428 self.extra_args = {'ind2DList': self.ind2DList}
432 self.extra_args = {'ind2DList': self.ind2DList}
429
433
430 self.keys = [k.lower() for k in self.twoDDict]
434 self.keys = [k.lower() for k in self.twoDDict]
431 if 'range' in self.keys:
435 if 'range' in self.keys:
432 self.keys.remove('range')
436 self.keys.remove('range')
433 if 'gdalt' in self.keys:
437 if 'gdalt' in self.keys:
@@ -440,20 +444,23 Inputs:
440
444
441 self.mnemonic = MNEMONICS[self.kinst] #TODO get mnemonic from madrigal
445 self.mnemonic = MNEMONICS[self.kinst] #TODO get mnemonic from madrigal
442 date = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
446 date = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
447 #if self.dataOut.input_dat_type:
448 #date=datetime.datetime.fromtimestamp(self.dataOut.TimeBlockSeconds_for_dp_power)
449 #print("date",date)
443
450
444 filename = '{}{}{}'.format(self.mnemonic,
451 filename = '{}{}{}'.format(self.mnemonic,
445 date.strftime('%Y%m%d_%H%M%S'),
452 date.strftime('%Y%m%d_%H%M%S'),
446 self.ext)
453 self.ext)
447
454
448 self.fullname = os.path.join(self.path, filename)
455 self.fullname = os.path.join(self.path, filename)
449
456
450 if os.path.isfile(self.fullname) :
457 if os.path.isfile(self.fullname) :
451 log.warning(
458 log.warning(
452 'Destination file {} already exists, previous file deleted.'.format(
459 'Destination file {} already exists, previous file deleted.'.format(
453 self.fullname),
460 self.fullname),
454 'MADWriter')
461 'MADWriter')
455 os.remove(self.fullname)
462 os.remove(self.fullname)
456
463
457 try:
464 try:
458 log.success(
465 log.success(
459 'Creating file: {}'.format(self.fullname),
466 'Creating file: {}'.format(self.fullname),
@@ -461,6 +468,8 Inputs:
461 if not os.path.exists(self.path):
468 if not os.path.exists(self.path):
462 os.makedirs(self.path)
469 os.makedirs(self.path)
463 self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True)
470 self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True)
471
472
464 except ValueError as e:
473 except ValueError as e:
465 log.error(
474 log.error(
466 'Impossible to create a cedar object with "madrigal.cedar.MadrigalCedarFile"',
475 'Impossible to create a cedar object with "madrigal.cedar.MadrigalCedarFile"',
@@ -475,11 +484,26 Inputs:
475 attributes.
484 attributes.
476 Allowed parameters in: parcodes.tab
485 Allowed parameters in: parcodes.tab
477 '''
486 '''
478
487 #self.dataOut.paramInterval=2
479 startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
488 startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime)
489
480 endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval)
490 endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval)
491
492 #if self.dataOut.input_dat_type:
493 #if self.dataOut.experiment=="DP":
494 #startTime=datetime.datetime.fromtimestamp(self.dataOut.TimeBlockSeconds_for_dp_power)
495 #endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval)
496
497
498 #print("2: ",startTime)
499 #print(endTime)
481 heights = self.dataOut.heightList
500 heights = self.dataOut.heightList
482
501
502 #print(self.blocks)
503 #print(startTime)
504 #print(endTime)
505 #print(heights)
506 #input()
483 if self.ext == '.dat':
507 if self.ext == '.dat':
484 for key, value in list(self.twoDDict.items()):
508 for key, value in list(self.twoDDict.items()):
485 if isinstance(value, str):
509 if isinstance(value, str):
@@ -505,13 +529,21 Inputs:
505 out[key] = tmp.flatten()[:len(heights)]
529 out[key] = tmp.flatten()[:len(heights)]
506 elif isinstance(value, (tuple, list)):
530 elif isinstance(value, (tuple, list)):
507 attr, x = value
531 attr, x = value
508 data = getattr(self.dataOut, attr)
532 data = getattr(self.dataOut, attr)
533 #print(x)
534 #print(len(heights))
535 #print(data[int(x)][:len(heights)])
536 #print(numpy.shape(out))
537 #print(numpy.shape(data))
538
509 out[key] = data[int(x)][:len(heights)]
539 out[key] = data[int(x)][:len(heights)]
510
540
511 a = numpy.array([out[k] for k in self.keys])
541 a = numpy.array([out[k] for k in self.keys])
542 #print(a)
512 nrows = numpy.array([numpy.isnan(a[:, x]).all() for x in range(len(heights))])
543 nrows = numpy.array([numpy.isnan(a[:, x]).all() for x in range(len(heights))])
513 index = numpy.where(nrows == False)[0]
544 index = numpy.where(nrows == False)[0]
514
545
546 #print(startTime.minute)
515 rec = madrigal.cedar.MadrigalDataRecord(
547 rec = madrigal.cedar.MadrigalDataRecord(
516 self.kinst,
548 self.kinst,
517 self.kindat,
549 self.kindat,
@@ -534,22 +566,24 Inputs:
534 len(index),
566 len(index),
535 **self.extra_args
567 **self.extra_args
536 )
568 )
537
569 #print("rec",rec)
538 # Setting 1d values
570 # Setting 1d values
539 for key in self.oneDDict:
571 for key in self.oneDDict:
540 rec.set1D(key, getattr(self.dataOut, self.oneDDict[key]))
572 rec.set1D(key, getattr(self.dataOut, self.oneDDict[key]))
541
573
542 # Setting 2d values
574 # Setting 2d values
543 nrec = 0
575 nrec = 0
544 for n in index:
576 for n in index:
545 for key in out:
577 for key in out:
546 rec.set2D(key, nrec, out[key][n])
578 rec.set2D(key, nrec, out[key][n])
547 nrec += 1
579 nrec += 1
548
580
549 self.fp.append(rec)
581 self.fp.append(rec)
550 if self.ext == '.hdf5' and self.counter % 500 == 0 and self.counter > 0:
582 if self.ext == '.hdf5' and self.counter %2 == 0 and self.counter > 0:
583 #print("here")
551 self.fp.dump()
584 self.fp.dump()
552 if self.counter % 20 == 0 and self.counter > 0:
585 if self.counter % 20 == 0 and self.counter > 0:
586 #self.fp.write()
553 log.log(
587 log.log(
554 'Writing {} records'.format(
588 'Writing {} records'.format(
555 self.counter),
589 self.counter),
@@ -558,8 +592,8 Inputs:
558 def setHeader(self):
592 def setHeader(self):
559 '''
593 '''
560 Create an add catalog and header to cedar file
594 Create an add catalog and header to cedar file
561 '''
595 '''
562
596
563 log.success('Closing file {}'.format(self.fullname), 'MADWriter')
597 log.success('Closing file {}'.format(self.fullname), 'MADWriter')
564
598
565 if self.ext == '.dat':
599 if self.ext == '.dat':
@@ -567,17 +601,17 Inputs:
567 else:
601 else:
568 self.fp.dump()
602 self.fp.dump()
569 self.fp.close()
603 self.fp.close()
570
604
571 header = madrigal.cedar.CatalogHeaderCreator(self.fullname)
605 header = madrigal.cedar.CatalogHeaderCreator(self.fullname)
572 header.createCatalog(**self.catalog)
606 header.createCatalog(**self.catalog)
573 header.createHeader(**self.header)
607 header.createHeader(**self.header)
574 header.write()
608 header.write()
575
609
576 def putData(self):
610 def putData(self):
577
611
578 if self.dataOut.flagNoData:
612 if self.dataOut.flagNoData:
579 return 0
613 return 0
580
614
581 if self.dataOut.flagDiscontinuousBlock or self.counter == self.blocks:
615 if self.dataOut.flagDiscontinuousBlock or self.counter == self.blocks:
582 if self.counter > 0:
616 if self.counter > 0:
583 self.setHeader()
617 self.setHeader()
@@ -585,11 +619,11 Inputs:
585
619
586 if self.counter == 0:
620 if self.counter == 0:
587 self.setFile()
621 self.setFile()
588
622
589 self.writeBlock()
623 self.writeBlock()
590 self.counter += 1
624 self.counter += 1
591
625
592 def close(self):
626 def close(self):
593
627
594 if self.counter > 0:
628 if self.counter > 0:
595 self.setHeader() No newline at end of file
629 self.setHeader()
@@ -17,7 +17,7 class HDFReader(Reader, ProcessingUnit):
17
17
18 This unit reads HDF5 files created with `HDFWriter` operation contains
18 This unit reads HDF5 files created with `HDFWriter` operation contains
19 by default two groups Data and Metadata all variables would be saved as `dataOut`
19 by default two groups Data and Metadata all variables would be saved as `dataOut`
20 attributes.
20 attributes.
21 It is possible to read any HDF5 file by given the structure in the `description`
21 It is possible to read any HDF5 file by given the structure in the `description`
22 parameter, also you can add extra values to metadata with the parameter `extras`.
22 parameter, also you can add extra values to metadata with the parameter `extras`.
23
23
@@ -37,10 +37,10 class HDFReader(Reader, ProcessingUnit):
37 Dictionary with the description of the HDF5 file
37 Dictionary with the description of the HDF5 file
38 extras : dict, optional
38 extras : dict, optional
39 Dictionary with extra metadata to be be added to `dataOut`
39 Dictionary with extra metadata to be be added to `dataOut`
40
40
41 Examples
41 Examples
42 --------
42 --------
43
43
44 desc = {
44 desc = {
45 'Data': {
45 'Data': {
46 'data_output': ['u', 'v', 'w'],
46 'data_output': ['u', 'v', 'w'],
@@ -64,7 +64,7 class HDFReader(Reader, ProcessingUnit):
64 extras = {
64 extras = {
65 'timeZone': 300
65 'timeZone': 300
66 }
66 }
67
67
68 reader = project.addReadUnit(
68 reader = project.addReadUnit(
69 name='HDFReader',
69 name='HDFReader',
70 path='/path/to/files',
70 path='/path/to/files',
@@ -98,42 +98,42 class HDFReader(Reader, ProcessingUnit):
98
98
99 self.set_kwargs(**kwargs)
99 self.set_kwargs(**kwargs)
100 if not self.ext.startswith('.'):
100 if not self.ext.startswith('.'):
101 self.ext = '.{}'.format(self.ext)
101 self.ext = '.{}'.format(self.ext)
102
102
103 if self.online:
103 if self.online:
104 log.log("Searching files in online mode...", self.name)
104 log.log("Searching files in online mode...", self.name)
105
105
106 for nTries in range(self.nTries):
106 for nTries in range(self.nTries):
107 fullpath = self.searchFilesOnLine(self.path, self.startDate,
107 fullpath = self.searchFilesOnLine(self.path, self.startDate,
108 self.endDate, self.expLabel, self.ext, self.walk,
108 self.endDate, self.expLabel, self.ext, self.walk,
109 self.filefmt, self.folderfmt)
109 self.filefmt, self.folderfmt)
110 try:
110 try:
111 fullpath = next(fullpath)
111 fullpath = next(fullpath)
112 except:
112 except:
113 fullpath = None
113 fullpath = None
114
114
115 if fullpath:
115 if fullpath:
116 break
116 break
117
117
118 log.warning(
118 log.warning(
119 'Waiting {} sec for a valid file in {}: try {} ...'.format(
119 'Waiting {} sec for a valid file in {}: try {} ...'.format(
120 self.delay, self.path, nTries + 1),
120 self.delay, self.path, nTries + 1),
121 self.name)
121 self.name)
122 time.sleep(self.delay)
122 time.sleep(self.delay)
123
123
124 if not(fullpath):
124 if not(fullpath):
125 raise schainpy.admin.SchainError(
125 raise schainpy.admin.SchainError(
126 'There isn\'t any valid file in {}'.format(self.path))
126 'There isn\'t any valid file in {}'.format(self.path))
127
127
128 pathname, filename = os.path.split(fullpath)
128 pathname, filename = os.path.split(fullpath)
129 self.year = int(filename[1:5])
129 self.year = int(filename[1:5])
130 self.doy = int(filename[5:8])
130 self.doy = int(filename[5:8])
131 self.set = int(filename[8:11]) - 1
131 self.set = int(filename[8:11]) - 1
132 else:
132 else:
133 log.log("Searching files in {}".format(self.path), self.name)
133 log.log("Searching files in {}".format(self.path), self.name)
134 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
134 self.filenameList = self.searchFilesOffLine(self.path, self.startDate,
135 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
135 self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt)
136
136
137 self.setNextFile()
137 self.setNextFile()
138
138
139 return
139 return
@@ -141,18 +141,18 class HDFReader(Reader, ProcessingUnit):
141 def readFirstHeader(self):
141 def readFirstHeader(self):
142 '''Read metadata and data'''
142 '''Read metadata and data'''
143
143
144 self.__readMetadata()
144 self.__readMetadata()
145 self.__readData()
145 self.__readData()
146 self.__setBlockList()
146 self.__setBlockList()
147
147
148 if 'type' in self.meta:
148 if 'type' in self.meta:
149 self.dataOut = eval(self.meta['type'])()
149 self.dataOut = eval(self.meta['type'])()
150
150
151 for attr in self.meta:
151 for attr in self.meta:
152 setattr(self.dataOut, attr, self.meta[attr])
152 setattr(self.dataOut, attr, self.meta[attr])
153
153
154 self.blockIndex = 0
154 self.blockIndex = 0
155
155
156 return
156 return
157
157
158 def __setBlockList(self):
158 def __setBlockList(self):
@@ -200,7 +200,7 class HDFReader(Reader, ProcessingUnit):
200 else:
200 else:
201 grp = self.fp['Metadata']
201 grp = self.fp['Metadata']
202 for name in grp:
202 for name in grp:
203 meta[name] = grp[name].value
203 meta[name] = grp[name].value
204
204
205 if self.extras:
205 if self.extras:
206 for key, value in self.extras.items():
206 for key, value in self.extras.items():
@@ -212,7 +212,7 class HDFReader(Reader, ProcessingUnit):
212 def __readData(self):
212 def __readData(self):
213
213
214 data = {}
214 data = {}
215
215
216 if self.description:
216 if self.description:
217 for key, value in self.description['Data'].items():
217 for key, value in self.description['Data'].items():
218 if isinstance(value, str):
218 if isinstance(value, str):
@@ -240,7 +240,7 class HDFReader(Reader, ProcessingUnit):
240 array = numpy.array(array)
240 array = numpy.array(array)
241 else:
241 else:
242 log.warning('Unknown type: {}'.format(name))
242 log.warning('Unknown type: {}'.format(name))
243
243
244 if name in self.description:
244 if name in self.description:
245 key = self.description[name]
245 key = self.description[name]
246 else:
246 else:
@@ -249,7 +249,7 class HDFReader(Reader, ProcessingUnit):
249
249
250 self.data = data
250 self.data = data
251 return
251 return
252
252
253 def getData(self):
253 def getData(self):
254
254
255 for attr in self.data:
255 for attr in self.data:
@@ -288,8 +288,8 class HDFWriter(Operation):
288 The HDF5 file contains by default two groups Data and Metadata where
288 The HDF5 file contains by default two groups Data and Metadata where
289 you can save any `dataOut` attribute specified by `dataList` and `metadataList`
289 you can save any `dataOut` attribute specified by `dataList` and `metadataList`
290 parameters, data attributes are normaly time dependent where the metadata
290 parameters, data attributes are normaly time dependent where the metadata
291 are not.
291 are not.
292 It is possible to customize the structure of the HDF5 file with the
292 It is possible to customize the structure of the HDF5 file with the
293 optional description parameter see the examples.
293 optional description parameter see the examples.
294
294
295 Parameters:
295 Parameters:
@@ -306,10 +306,10 class HDFWriter(Operation):
306 If True the name of the files corresponds to the timestamp of the data
306 If True the name of the files corresponds to the timestamp of the data
307 description : dict, optional
307 description : dict, optional
308 Dictionary with the desired description of the HDF5 file
308 Dictionary with the desired description of the HDF5 file
309
309
310 Examples
310 Examples
311 --------
311 --------
312
312
313 desc = {
313 desc = {
314 'data_output': {'winds': ['z', 'w', 'v']},
314 'data_output': {'winds': ['z', 'w', 'v']},
315 'utctime': 'timestamps',
315 'utctime': 'timestamps',
@@ -329,7 +329,7 class HDFWriter(Operation):
329 'heightList': 'heights'
329 'heightList': 'heights'
330 }
330 }
331 }
331 }
332
332
333 writer = proc_unit.addOperation(name='HDFWriter')
333 writer = proc_unit.addOperation(name='HDFWriter')
334 writer.addParameter(name='path', value='/path/to/file')
334 writer.addParameter(name='path', value='/path/to/file')
335 writer.addParameter(name='blocksPerFile', value='32')
335 writer.addParameter(name='blocksPerFile', value='32')
@@ -357,7 +357,7 class HDFWriter(Operation):
357 lastTime = None
357 lastTime = None
358
358
359 def __init__(self):
359 def __init__(self):
360
360
361 Operation.__init__(self)
361 Operation.__init__(self)
362 return
362 return
363
363
@@ -393,7 +393,7 class HDFWriter(Operation):
393 dsDict['shape'] = dataAux.shape
393 dsDict['shape'] = dataAux.shape
394 dsDict['dsNumber'] = dataAux.shape[0]
394 dsDict['dsNumber'] = dataAux.shape[0]
395 dsDict['dtype'] = dataAux.dtype
395 dsDict['dtype'] = dataAux.dtype
396
396
397 dsList.append(dsDict)
397 dsList.append(dsDict)
398
398
399 self.dsList = dsList
399 self.dsList = dsList
@@ -408,7 +408,7 class HDFWriter(Operation):
408 self.lastTime = currentTime
408 self.lastTime = currentTime
409 self.currentDay = dataDay
409 self.currentDay = dataDay
410 return False
410 return False
411
411
412 timeDiff = currentTime - self.lastTime
412 timeDiff = currentTime - self.lastTime
413
413
414 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
414 #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora
@@ -424,10 +424,11 class HDFWriter(Operation):
424
424
425 def run(self, dataOut, path, blocksPerFile=10, metadataList=None,
425 def run(self, dataOut, path, blocksPerFile=10, metadataList=None,
426 dataList=[], setType=None, description={}):
426 dataList=[], setType=None, description={}):
427
427 print("hdf",dataOut.flagNoData)
428 print(dataOut.datatime.ctime())
428 self.dataOut = dataOut
429 self.dataOut = dataOut
429 if not(self.isConfig):
430 if not(self.isConfig):
430 self.setup(path=path, blocksPerFile=blocksPerFile,
431 self.setup(path=path, blocksPerFile=blocksPerFile,
431 metadataList=metadataList, dataList=dataList,
432 metadataList=metadataList, dataList=dataList,
432 setType=setType, description=description)
433 setType=setType, description=description)
433
434
@@ -436,9 +437,9 class HDFWriter(Operation):
436
437
437 self.putData()
438 self.putData()
438 return
439 return
439
440
440 def setNextFile(self):
441 def setNextFile(self):
441
442
442 ext = self.ext
443 ext = self.ext
443 path = self.path
444 path = self.path
444 setFile = self.setFile
445 setFile = self.setFile
@@ -523,7 +524,7 class HDFWriter(Operation):
523 return 'pair{:02d}'.format(x)
524 return 'pair{:02d}'.format(x)
524 else:
525 else:
525 return 'channel{:02d}'.format(x)
526 return 'channel{:02d}'.format(x)
526
527
527 def writeMetadata(self, fp):
528 def writeMetadata(self, fp):
528
529
529 if self.description:
530 if self.description:
@@ -548,7 +549,7 class HDFWriter(Operation):
548 return
549 return
549
550
550 def writeData(self, fp):
551 def writeData(self, fp):
551
552
552 if self.description:
553 if self.description:
553 if 'Data' in self.description:
554 if 'Data' in self.description:
554 grp = fp.create_group('Data')
555 grp = fp.create_group('Data')
@@ -559,13 +560,13 class HDFWriter(Operation):
559
560
560 dtsets = []
561 dtsets = []
561 data = []
562 data = []
562
563
563 for dsInfo in self.dsList:
564 for dsInfo in self.dsList:
564 if dsInfo['nDim'] == 0:
565 if dsInfo['nDim'] == 0:
565 ds = grp.create_dataset(
566 ds = grp.create_dataset(
566 self.getLabel(dsInfo['variable']),
567 self.getLabel(dsInfo['variable']),
567 (self.blocksPerFile, ),
568 (self.blocksPerFile, ),
568 chunks=True,
569 chunks=True,
569 dtype=numpy.float64)
570 dtype=numpy.float64)
570 dtsets.append(ds)
571 dtsets.append(ds)
571 data.append((dsInfo['variable'], -1))
572 data.append((dsInfo['variable'], -1))
@@ -577,7 +578,7 class HDFWriter(Operation):
577 sgrp = grp
578 sgrp = grp
578 for i in range(dsInfo['dsNumber']):
579 for i in range(dsInfo['dsNumber']):
579 ds = sgrp.create_dataset(
580 ds = sgrp.create_dataset(
580 self.getLabel(dsInfo['variable'], i),
581 self.getLabel(dsInfo['variable'], i),
581 (self.blocksPerFile, ) + dsInfo['shape'][1:],
582 (self.blocksPerFile, ) + dsInfo['shape'][1:],
582 chunks=True,
583 chunks=True,
583 dtype=dsInfo['dtype'])
584 dtype=dsInfo['dtype'])
@@ -586,7 +587,7 class HDFWriter(Operation):
586 fp.flush()
587 fp.flush()
587
588
588 log.log('Creating file: {}'.format(fp.filename), self.name)
589 log.log('Creating file: {}'.format(fp.filename), self.name)
589
590
590 self.ds = dtsets
591 self.ds = dtsets
591 self.data = data
592 self.data = data
592 self.firsttime = True
593 self.firsttime = True
@@ -73,27 +73,28 class VoltageReader(JRODataReader, ProcessingUnit):
73 """
73 """
74
74
75 ProcessingUnit.__init__(self)
75 ProcessingUnit.__init__(self)
76
76
77 self.ext = ".r"
77 self.ext = ".r"
78 self.optchar = "D"
78 self.optchar = "D"
79 self.basicHeaderObj = BasicHeader(LOCALTIME)
79 self.basicHeaderObj = BasicHeader(LOCALTIME)
80 self.systemHeaderObj = SystemHeader()
80 self.systemHeaderObj = SystemHeader()
81 self.radarControllerHeaderObj = RadarControllerHeader()
81 self.radarControllerHeaderObj = RadarControllerHeader()
82
82 self.processingHeaderObj = ProcessingHeader()
83 self.processingHeaderObj = ProcessingHeader()
83 self.lastUTTime = 0
84 self.lastUTTime = 0
84 self.profileIndex = 2**32 - 1
85 self.profileIndex = 2**32 - 1
85 self.dataOut = Voltage()
86 self.dataOut = Voltage()
86 self.selBlocksize = None
87 self.selBlocksize = None
87 self.selBlocktime = None
88 self.selBlocktime = None
88
89 ##print("1--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
89 def createObjByDefault(self):
90 def createObjByDefault(self):
90
91 ##print("2--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
91 dataObj = Voltage()
92 dataObj = Voltage()
92
93
93 return dataObj
94 return dataObj
94
95
95 def __hasNotDataInBuffer(self):
96 def __hasNotDataInBuffer(self):
96
97 ##print("3--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
97 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs:
98 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs:
98 return 1
99 return 1
99
100
@@ -109,11 +110,13 class VoltageReader(JRODataReader, ProcessingUnit):
109 Return:
110 Return:
110 None
111 None
111 """
112 """
113 ##print("4--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
112 pts2read = self.processingHeaderObj.profilesPerBlock * \
114 pts2read = self.processingHeaderObj.profilesPerBlock * \
113 self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
115 self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
114 self.blocksize = pts2read
116 self.blocksize = pts2read
115
117
116 def readBlock(self):
118 def readBlock(self):
119
117 """
120 """
118 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
121 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
119 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
122 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
@@ -133,10 +136,10 class VoltageReader(JRODataReader, ProcessingUnit):
133 self.flagIsNewBlock
136 self.flagIsNewBlock
134 self.nTotalBlocks
137 self.nTotalBlocks
135
138
136 Exceptions:
139 Exceptions:
137 Si un bloque leido no es un bloque valido
140 Si un bloque leido no es un bloque valido
138 """
141 """
139
142 ##print("5--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
140 # if self.server is not None:
143 # if self.server is not None:
141 # self.zBlock = self.receiver.recv()
144 # self.zBlock = self.receiver.recv()
142 # self.zHeader = self.zBlock[:24]
145 # self.zHeader = self.zBlock[:24]
@@ -177,6 +180,7 class VoltageReader(JRODataReader, ProcessingUnit):
177 return 1
180 return 1
178
181
179 def getFirstHeader(self):
182 def getFirstHeader(self):
183 ##print("6--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
180
184
181 self.getBasicHeader()
185 self.getBasicHeader()
182
186
@@ -186,8 +190,12 class VoltageReader(JRODataReader, ProcessingUnit):
186
190
187 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
191 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
188
192
193 #self.dataOut.ippSeconds_general=self.radarControllerHeaderObj.ippSeconds
194 #print(self.nTxs)
189 if self.nTxs > 1:
195 if self.nTxs > 1:
196 #print(self.radarControllerHeaderObj.ippSeconds)
190 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
197 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
198 #print(self.radarControllerHeaderObj.ippSeconds)
191 # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
199 # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
192
200
193 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
201 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
@@ -220,7 +228,7 class VoltageReader(JRODataReader, ProcessingUnit):
220 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
228 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
221
229
222 def reshapeData(self):
230 def reshapeData(self):
223
231 ##print("7--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
224 if self.nTxs < 0:
232 if self.nTxs < 0:
225 return
233 return
226
234
@@ -247,6 +255,7 class VoltageReader(JRODataReader, ProcessingUnit):
247
255
248 def readFirstHeaderFromServer(self):
256 def readFirstHeaderFromServer(self):
249
257
258 ##print("8--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
250 self.getFirstHeader()
259 self.getFirstHeader()
251
260
252 self.firstHeaderSize = self.basicHeaderObj.size
261 self.firstHeaderSize = self.basicHeaderObj.size
@@ -278,6 +287,7 class VoltageReader(JRODataReader, ProcessingUnit):
278 self.getBlockDimension()
287 self.getBlockDimension()
279
288
280 def getFromServer(self):
289 def getFromServer(self):
290 ##print("9--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
281 self.flagDiscontinuousBlock = 0
291 self.flagDiscontinuousBlock = 0
282 self.profileIndex = 0
292 self.profileIndex = 0
283 self.flagIsNewBlock = 1
293 self.flagIsNewBlock = 1
@@ -382,6 +392,8 class VoltageReader(JRODataReader, ProcessingUnit):
382 self.flagDiscontinuousBlock
392 self.flagDiscontinuousBlock
383 self.flagIsNewBlock
393 self.flagIsNewBlock
384 """
394 """
395
396 ##print("10--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK")
385 if self.flagNoMoreFiles:
397 if self.flagNoMoreFiles:
386 self.dataOut.flagNoData = True
398 self.dataOut.flagNoData = True
387 return 0
399 return 0
@@ -410,6 +422,7 class VoltageReader(JRODataReader, ProcessingUnit):
410 self.dataOut.data = self.datablock[:, self.profileIndex, :]
422 self.dataOut.data = self.datablock[:, self.profileIndex, :]
411 self.dataOut.profileIndex = self.profileIndex
423 self.dataOut.profileIndex = self.profileIndex
412
424
425
413 self.profileIndex += 1
426 self.profileIndex += 1
414
427
415 else:
428 else:
@@ -458,9 +471,13 class VoltageReader(JRODataReader, ProcessingUnit):
458 self.dataOut.flagDataAsBlock = True
471 self.dataOut.flagDataAsBlock = True
459 self.dataOut.nProfiles = self.dataOut.data.shape[1]
472 self.dataOut.nProfiles = self.dataOut.data.shape[1]
460
473
474 #######################DP#######################
475 self.dataOut.CurrentBlock=self.nReadBlocks
476 self.dataOut.LastBlock=self.processingHeaderObj.dataBlocksPerFile
477 #######################DP#######################
461 self.dataOut.flagNoData = False
478 self.dataOut.flagNoData = False
462
479
463 self.getBasicHeader()
480 #self.getBasicHeader()
464
481
465 self.dataOut.realtime = self.online
482 self.dataOut.realtime = self.online
466
483
@@ -673,4 +690,3 class VoltageWriter(JRODataWriter, Operation):
673 self.processingHeaderObj.processFlags = self.getProcessFlags()
690 self.processingHeaderObj.processFlags = self.getProcessFlags()
674
691
675 self.setBasicHeader()
692 self.setBasicHeader()
676 No newline at end of file
@@ -14,3 +14,9 from .jroproc_spectra_lags import *
14 from .jroproc_spectra_acf import *
14 from .jroproc_spectra_acf import *
15 from .bltrproc_parameters import *
15 from .bltrproc_parameters import *
16 from .pxproc_parameters import *
16 from .pxproc_parameters import *
17
18
19 ###########DP###########
20 from .jroproc_voltage_lags import *
21 ###########DP###########
22 from .jroproc_spectra_lags_faraday import *
@@ -169,7 +169,7 def MPDecorator(BaseClass):
169 self.op_type = 'external'
169 self.op_type = 'external'
170 self.name = BaseClass.__name__
170 self.name = BaseClass.__name__
171 self.__doc__ = BaseClass.__doc__
171 self.__doc__ = BaseClass.__doc__
172
172
173 if 'plot' in self.name.lower() and not self.name.endswith('_'):
173 if 'plot' in self.name.lower() and not self.name.endswith('_'):
174 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
174 self.name = '{}{}'.format(self.CODE.upper(), 'Plot')
175
175
This diff has been collapsed as it changes many lines, (704 lines changed) Show them Hide them
@@ -302,6 +302,12 class SpectralFilters(Operation):
302 dataOut.spcparam_range[0]=FrecRange
302 dataOut.spcparam_range[0]=FrecRange
303 return dataOut
303 return dataOut
304
304
305
306 from scipy.optimize import fmin
307 import itertools
308 from scipy.optimize import curve_fit
309
310
305 class GaussianFit(Operation):
311 class GaussianFit(Operation):
306
312
307 '''
313 '''
@@ -321,135 +327,198 class GaussianFit(Operation):
321 self.i=0
327 self.i=0
322
328
323
329
324 def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
330 # def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points
331 def run(self, dataOut, SNRdBlimit=-9, method='generalized'):
325 """This routine will find a couple of generalized Gaussians to a power spectrum
332 """This routine will find a couple of generalized Gaussians to a power spectrum
333 methods: generalized, squared
326 input: spc
334 input: spc
327 output:
335 output:
328 Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise
336 noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1
329 """
337 """
330
338 print ('Entering ',method,' double Gaussian fit')
331 self.spc = dataOut.data_pre[0].copy()
339 self.spc = dataOut.data_pre[0].copy()
332 self.Num_Hei = self.spc.shape[2]
340 self.Num_Hei = self.spc.shape[2]
333 self.Num_Bin = self.spc.shape[1]
341 self.Num_Bin = self.spc.shape[1]
334 self.Num_Chn = self.spc.shape[0]
342 self.Num_Chn = self.spc.shape[0]
335 Vrange = dataOut.abscissaList
336
337 GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei])
338 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
339 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
340 SPC_ch1[:] = numpy.NaN
341 SPC_ch2[:] = numpy.NaN
342
343
343
344 start_time = time.time()
344 start_time = time.time()
345
345
346 noise_ = dataOut.spc_noise[0].copy()
347
348
349 pool = Pool(processes=self.Num_Chn)
346 pool = Pool(processes=self.Num_Chn)
350 args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)]
347 args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)]
351 objs = [self for __ in range(self.Num_Chn)]
348 objs = [self for __ in range(self.Num_Chn)]
352 attrs = list(zip(objs, args))
349 attrs = list(zip(objs, args))
353 gauSPC = pool.map(target, attrs)
350 DGauFitParam = pool.map(target, attrs)
354 dataOut.SPCparam = numpy.asarray(SPCparam)
351 # Parameters:
355
352 # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power
356 ''' Parameters:
353 dataOut.DGauFitParams = numpy.asarray(DGauFitParam)
357 1. Amplitude
354
358 2. Shift
355 # Double Gaussian Curves
359 3. Width
356 gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei])
360 4. Power
357 gau0[:] = numpy.NaN
361 '''
358 gau1 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei])
359 gau1[:] = numpy.NaN
360 x_mtr = numpy.transpose(numpy.tile(dataOut.getVelRange(1)[:-1], (self.Num_Hei,1)))
361 for iCh in range(self.Num_Chn):
362 N0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,0]] * self.Num_Bin))
363 N1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][0,:,1]] * self.Num_Bin))
364 A0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,0]] * self.Num_Bin))
365 A1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][1,:,1]] * self.Num_Bin))
366 v0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,0]] * self.Num_Bin))
367 v1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][2,:,1]] * self.Num_Bin))
368 s0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,0]] * self.Num_Bin))
369 s1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][3,:,1]] * self.Num_Bin))
370 if method == 'generalized':
371 p0 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,0]] * self.Num_Bin))
372 p1 = numpy.transpose(numpy.transpose([dataOut.DGauFitParams[iCh][4,:,1]] * self.Num_Bin))
373 elif method == 'squared':
374 p0 = 2.
375 p1 = 2.
376 gau0[iCh] = A0*numpy.exp(-0.5*numpy.abs((x_mtr-v0)/s0)**p0)+N0
377 gau1[iCh] = A1*numpy.exp(-0.5*numpy.abs((x_mtr-v1)/s1)**p1)+N1
378 dataOut.GaussFit0 = gau0
379 dataOut.GaussFit1 = gau1
380 print(numpy.shape(gau0))
381 hei = 26
382 print(dataOut.heightList[hei])
383 #import matplotlib.pyplot as plt
384 plt.plot(self.spc[0,:,hei])
385 plt.plot(dataOut.GaussFit0[0,:,hei])
386 plt.plot(dataOut.GaussFit1[0,:,hei])
387 plt.plot(dataOut.GaussFit0[0,:,hei]+dataOut.GaussFit1[0,:,hei])
388
389 plt.show()
390 time.sleep(60)
391 #print(gau0)
392
393 print('Leaving ',method ,' double Gaussian fit')
394 return dataOut
362
395
363 def FitGau(self, X):
396 def FitGau(self, X):
364
397 # print('Entering FitGau')
365 Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X
398 # Assigning the variables
366
399 Vrange, ch, wnoise, num_intg, SNRlimit = X
367 SPCparam = []
400 # Noise Limits
368 SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei])
401 noisebl = wnoise * 0.9
369 SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei])
402 noisebh = wnoise * 1.1
370 SPC_ch1[:] = 0#numpy.NaN
403 # Radar Velocity
371 SPC_ch2[:] = 0#numpy.NaN
404 Va = max(Vrange)
372
405 deltav = Vrange[1] - Vrange[0]
373
406 x = numpy.arange(self.Num_Bin)
374
407
408 # print ('stop 0')
409
410 # 5 parameters, 2 Gaussians
411 DGauFitParam = numpy.zeros([5, self.Num_Hei,2])
412 DGauFitParam[:] = numpy.NaN
413
414 # SPCparam = []
415 # SPC_ch1 = numpy.zeros([self.Num_Bin,self.Num_Hei])
416 # SPC_ch2 = numpy.zeros([self.Num_Bin,self.Num_Hei])
417 # SPC_ch1[:] = 0 #numpy.NaN
418 # SPC_ch2[:] = 0 #numpy.NaN
419 # print ('stop 1')
375 for ht in range(self.Num_Hei):
420 for ht in range(self.Num_Hei):
376
421 # print (ht)
377
422 # print ('stop 2')
423 # Spectra at each range
378 spc = numpy.asarray(self.spc)[ch,:,ht]
424 spc = numpy.asarray(self.spc)[ch,:,ht]
425 snr = ( spc.mean() - wnoise ) / wnoise
426 snrdB = 10.*numpy.log10(snr)
379
427
428 #print ('stop 3')
429 if snrdB < SNRlimit :
430 # snr = numpy.NaN
431 # SPC_ch1[:,ht] = 0#numpy.NaN
432 # SPC_ch1[:,ht] = 0#numpy.NaN
433 # SPCparam = (SPC_ch1,SPC_ch2)
434 # print ('SNR less than SNRth')
435 continue
436 # wnoise = hildebrand_sekhon(spc,num_intg)
437 # print ('stop 2.01')
380 #############################################
438 #############################################
381 # normalizing spc and noise
439 # normalizing spc and noise
382 # This part differs from gg1
440 # This part differs from gg1
383 spc_norm_max = max(spc)
441 # spc_norm_max = max(spc) #commented by D. Scipión 19.03.2021
384 #spc = spc / spc_norm_max
442 #spc = spc / spc_norm_max
385 pnoise = pnoise #/ spc_norm_max
443 # pnoise = pnoise #/ spc_norm_max #commented by D. Scipión 19.03.2021
386 #############################################
444 #############################################
387
445
446 # print ('stop 2.1')
388 fatspectra=1.0
447 fatspectra=1.0
448 # noise per channel.... we might want to use the noise at each range
389
449
390 wnoise = noise_ #/ spc_norm_max
450 # wnoise = noise_ #/ spc_norm_max #commented by D. Scipión 19.03.2021
391 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
451 #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used
392 #if wnoise>1.1*pnoise: # to be tested later
452 #if wnoise>1.1*pnoise: # to be tested later
393 # wnoise=pnoise
453 # wnoise=pnoise
394 noisebl=wnoise*0.9;
454 # noisebl = wnoise*0.9
395 noisebh=wnoise*1.1
455 # noisebh = wnoise*1.1
396 spc=spc-wnoise
456 spc = spc - wnoise # signal
397
457
398 minx=numpy.argmin(spc)
458 # print ('stop 2.2')
459 minx = numpy.argmin(spc)
399 #spcs=spc.copy()
460 #spcs=spc.copy()
400 spcs=numpy.roll(spc,-minx)
461 spcs = numpy.roll(spc,-minx)
401 cum=numpy.cumsum(spcs)
462 cum = numpy.cumsum(spcs)
402 tot_noise=wnoise * self.Num_Bin #64;
463 # tot_noise = wnoise * self.Num_Bin #64;
403
464
404 snr = sum(spcs)/tot_noise
465 # print ('stop 2.3')
405 snrdB=10.*numpy.log10(snr)
466 # snr = sum(spcs) / tot_noise
406
467 # snrdB = 10.*numpy.log10(snr)
407 if snrdB < SNRlimit :
468 #print ('stop 3')
408 snr = numpy.NaN
469 # if snrdB < SNRlimit :
409 SPC_ch1[:,ht] = 0#numpy.NaN
470 # snr = numpy.NaN
410 SPC_ch1[:,ht] = 0#numpy.NaN
471 # SPC_ch1[:,ht] = 0#numpy.NaN
411 SPCparam = (SPC_ch1,SPC_ch2)
472 # SPC_ch1[:,ht] = 0#numpy.NaN
412 continue
473 # SPCparam = (SPC_ch1,SPC_ch2)
474 # print ('SNR less than SNRth')
475 # continue
413
476
414
477
415 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
478 #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4:
416 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
479 # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None
417
480 # print ('stop 4')
418 cummax=max(cum);
481 cummax = max(cum)
419 epsi=0.08*fatspectra # cumsum to narrow down the energy region
482 epsi = 0.08 * fatspectra # cumsum to narrow down the energy region
420 cumlo=cummax*epsi;
483 cumlo = cummax * epsi
421 cumhi=cummax*(1-epsi)
484 cumhi = cummax * (1-epsi)
422 powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
485 powerindex = numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0])
423
486
424
487 # print ('stop 5')
425 if len(powerindex) < 1:# case for powerindex 0
488 if len(powerindex) < 1:# case for powerindex 0
489 # print ('powerindex < 1')
490 continue
491 powerlo = powerindex[0]
492 powerhi = powerindex[-1]
493 powerwidth = powerhi-powerlo
494 if powerwidth <= 1:
495 # print('powerwidth <= 1')
426 continue
496 continue
427 powerlo=powerindex[0]
428 powerhi=powerindex[-1]
429 powerwidth=powerhi-powerlo
430
497
431 firstpeak=powerlo+powerwidth/10.# first gaussian energy location
498 # print ('stop 6')
432 secondpeak=powerhi-powerwidth/10.#second gaussian energy location
499 firstpeak = powerlo + powerwidth/10.# first gaussian energy location
433 midpeak=(firstpeak+secondpeak)/2.
500 secondpeak = powerhi - powerwidth/10. #second gaussian energy location
434 firstamp=spcs[int(firstpeak)]
501 midpeak = (firstpeak + secondpeak)/2.
435 secondamp=spcs[int(secondpeak)]
502 firstamp = spcs[int(firstpeak)]
436 midamp=spcs[int(midpeak)]
503 secondamp = spcs[int(secondpeak)]
504 midamp = spcs[int(midpeak)]
437
505
438 x=numpy.arange( self.Num_Bin )
506 y_data = spc + wnoise
439 y_data=spc+wnoise
440
507
441 ''' single Gaussian '''
508 ''' single Gaussian '''
442 shift0=numpy.mod(midpeak+minx, self.Num_Bin )
509 shift0 = numpy.mod(midpeak+minx, self.Num_Bin )
443 width0=powerwidth/4.#Initialization entire power of spectrum divided by 4
510 width0 = powerwidth/4.#Initialization entire power of spectrum divided by 4
444 power0=2.
511 power0 = 2.
445 amplitude0=midamp
512 amplitude0 = midamp
446 state0=[shift0,width0,amplitude0,power0,wnoise]
513 state0 = [shift0,width0,amplitude0,power0,wnoise]
447 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
514 bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh))
448 lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True)
515 lsq1 = fmin_l_bfgs_b(self.misfit1, state0, args=(y_data,x,num_intg), bounds=bnds, approx_grad=True)
449
516 # print ('stop 7.1')
450 chiSq1=lsq1[1];
517 # print (bnds)
451
518
452
519 chiSq1=lsq1[1]
520
521 # print ('stop 8')
453 if fatspectra<1.0 and powerwidth<4:
522 if fatspectra<1.0 and powerwidth<4:
454 choice=0
523 choice=0
455 Amplitude0=lsq1[0][2]
524 Amplitude0=lsq1[0][2]
@@ -464,133 +533,378 class GaussianFit(Operation):
464 #return (numpy.array([shift0,width0,Amplitude0,p0]),
533 #return (numpy.array([shift0,width0,Amplitude0,p0]),
465 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
534 # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice)
466
535
467 ''' two gaussians '''
536 # print ('stop 9')
537 ''' two Gaussians '''
468 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
538 #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64)
469 shift0=numpy.mod(firstpeak+minx, self.Num_Bin );
539 shift0 = numpy.mod(firstpeak+minx, self.Num_Bin )
470 shift1=numpy.mod(secondpeak+minx, self.Num_Bin )
540 shift1 = numpy.mod(secondpeak+minx, self.Num_Bin )
471 width0=powerwidth/6.;
541 width0 = powerwidth/6.
472 width1=width0
542 width1 = width0
473 power0=2.;
543 power0 = 2.
474 power1=power0
544 power1 = power0
475 amplitude0=firstamp;
545 amplitude0 = firstamp
476 amplitude1=secondamp
546 amplitude1 = secondamp
477 state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
547 state0 = [shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise]
478 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
548 #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
479 bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
549 bnds=((0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(0,self.Num_Bin-1),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh))
480 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
550 #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5))
481
551
552 # print ('stop 10')
482 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
553 lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True )
483
554
555 # print ('stop 11')
556 chiSq2 = lsq2[1]
484
557
485 chiSq2=lsq2[1];
558 # print ('stop 12')
486
487
488
559
489 oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
560 oneG = (chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10)
490
561
562 # print ('stop 13')
491 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
563 if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error
492 if oneG:
564 if oneG:
493 choice=0
565 choice = 0
494 else:
566 else:
495 w1=lsq2[0][1]; w2=lsq2[0][5]
567 w1 = lsq2[0][1]; w2 = lsq2[0][5]
496 a1=lsq2[0][2]; a2=lsq2[0][6]
568 a1 = lsq2[0][2]; a2 = lsq2[0][6]
497 p1=lsq2[0][3]; p2=lsq2[0][7]
569 p1 = lsq2[0][3]; p2 = lsq2[0][7]
498 s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1;
570 s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1
499 s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2;
571 s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2
500 gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling
572 gp1 = a1*w1*s1; gp2 = a2*w2*s2 # power content of each ggaussian with proper p scaling
501
573
502 if gp1>gp2:
574 if gp1>gp2:
503 if a1>0.7*a2:
575 if a1>0.7*a2:
504 choice=1
576 choice = 1
505 else:
577 else:
506 choice=2
578 choice = 2
507 elif gp2>gp1:
579 elif gp2>gp1:
508 if a2>0.7*a1:
580 if a2>0.7*a1:
509 choice=2
581 choice = 2
510 else:
582 else:
511 choice=1
583 choice = 1
512 else:
584 else:
513 choice=numpy.argmax([a1,a2])+1
585 choice = numpy.argmax([a1,a2])+1
514 #else:
586 #else:
515 #choice=argmin([std2a,std2b])+1
587 #choice=argmin([std2a,std2b])+1
516
588
517 else: # with low SNR go to the most energetic peak
589 else: # with low SNR go to the most energetic peak
518 choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
590 choice = numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]])
519
591
520
592 # print ('stop 14')
521 shift0=lsq2[0][0];
593 shift0 = lsq2[0][0]
522 vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0])
594 vel0 = Vrange[0] + shift0 * deltav
523 shift1=lsq2[0][4];
595 shift1 = lsq2[0][4]
524 vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0])
596 # vel1=Vrange[0] + shift1 * deltav
525
597
526 max_vel = 1.0
598 # max_vel = 1.0
527
599 # Va = max(Vrange)
600 # deltav = Vrange[1]-Vrange[0]
601 # print ('stop 15')
528 #first peak will be 0, second peak will be 1
602 #first peak will be 0, second peak will be 1
529 if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range
603 # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.Scipión 19.03.2021
530 shift0=lsq2[0][0]
604 if vel0 > -Va and vel0 < Va : #first peak is in the correct range
531 width0=lsq2[0][1]
605 shift0 = lsq2[0][0]
532 Amplitude0=lsq2[0][2]
606 width0 = lsq2[0][1]
533 p0=lsq2[0][3]
607 Amplitude0 = lsq2[0][2]
534
608 p0 = lsq2[0][3]
535 shift1=lsq2[0][4]
609
536 width1=lsq2[0][5]
610 shift1 = lsq2[0][4]
537 Amplitude1=lsq2[0][6]
611 width1 = lsq2[0][5]
538 p1=lsq2[0][7]
612 Amplitude1 = lsq2[0][6]
539 noise=lsq2[0][8]
613 p1 = lsq2[0][7]
614 noise = lsq2[0][8]
540 else:
615 else:
541 shift1=lsq2[0][0]
616 shift1 = lsq2[0][0]
542 width1=lsq2[0][1]
617 width1 = lsq2[0][1]
543 Amplitude1=lsq2[0][2]
618 Amplitude1 = lsq2[0][2]
544 p1=lsq2[0][3]
619 p1 = lsq2[0][3]
545
620
546 shift0=lsq2[0][4]
621 shift0 = lsq2[0][4]
547 width0=lsq2[0][5]
622 width0 = lsq2[0][5]
548 Amplitude0=lsq2[0][6]
623 Amplitude0 = lsq2[0][6]
549 p0=lsq2[0][7]
624 p0 = lsq2[0][7]
550 noise=lsq2[0][8]
625 noise = lsq2[0][8]
551
626
552 if Amplitude0<0.05: # in case the peak is noise
627 if Amplitude0<0.05: # in case the peak is noise
553 shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN]
628 shift0,width0,Amplitude0,p0 = 4*[numpy.NaN]
554 if Amplitude1<0.05:
629 if Amplitude1<0.05:
555 shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN]
630 shift1,width1,Amplitude1,p1 = 4*[numpy.NaN]
631
632 # print ('stop 16 ')
633 # SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0)/width0)**p0)
634 # SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1)/width1)**p1)
635 # SPCparam = (SPC_ch1,SPC_ch2)
636
637 DGauFitParam[0,ht,0] = noise
638 DGauFitParam[0,ht,1] = noise
639 DGauFitParam[1,ht,0] = Amplitude0
640 DGauFitParam[1,ht,1] = Amplitude1
641 DGauFitParam[2,ht,0] = Vrange[0] + shift0 * deltav
642 DGauFitParam[2,ht,1] = Vrange[0] + shift1 * deltav
643 DGauFitParam[3,ht,0] = width0 * deltav
644 DGauFitParam[3,ht,1] = width1 * deltav
645 DGauFitParam[4,ht,0] = p0
646 DGauFitParam[4,ht,1] = p1
647
648 # print (DGauFitParam.shape)
649 # print ('Leaving FitGau')
650 return DGauFitParam
651 # return SPCparam
652 # return GauSPC
556
653
654 def y_model1(self,x,state):
655 shift0, width0, amplitude0, power0, noise = state
656 model0 = amplitude0*numpy.exp(-0.5*abs((x - shift0)/width0)**power0)
657 model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0)
658 model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0)
659 return model0 + model0u + model0d + noise
557
660
558 SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0
661 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
559 SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1
662 shift0, width0, amplitude0, power0, shift1, width1, amplitude1, power1, noise = state
560 SPCparam = (SPC_ch1,SPC_ch2)
663 model0 = amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
664 model0u = amplitude0*numpy.exp(-0.5*abs((x - shift0 - self.Num_Bin)/width0)**power0)
665 model0d = amplitude0*numpy.exp(-0.5*abs((x - shift0 + self.Num_Bin)/width0)**power0)
561
666
667 model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1)
668 model1u = amplitude1*numpy.exp(-0.5*abs((x - shift1 - self.Num_Bin)/width1)**power1)
669 model1d = amplitude1*numpy.exp(-0.5*abs((x - shift1 + self.Num_Bin)/width1)**power1)
670 return model0 + model0u + model0d + model1 + model1u + model1d + noise
562
671
563 return GauSPC
672 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
564
673
565 def y_model1(self,x,state):
674 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
566 shift0,width0,amplitude0,power0,noise=state
567 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
568
675
569 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
676 def misfit2(self,state,y_data,x,num_intg):
677 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
570
678
571 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
572 return model0+model0u+model0d+noise
573
679
574 def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist
680 class Oblique_Gauss_Fit(Operation):
575 shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state
681
576 model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0)
682 def __init__(self):
683 Operation.__init__(self)
577
684
578 model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0)
579
685
580 model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0)
581 model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1)
582
686
583 model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1)
687 def Gauss_fit(self,spc,x,nGauss):
584
688
585 model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1)
586 return model0+model0u+model0d+model1+model1u+model1d+noise
587
689
588 def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is.
690 def gaussian(x, a, b, c, d):
691 val = a * numpy.exp(-(x - b)**2 / (2*c**2)) + d
692 return val
589
693
590 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented
694 if nGauss == 'first':
695 spc_1_aux = numpy.copy(spc[:numpy.argmax(spc)+1])
696 spc_2_aux = numpy.flip(spc_1_aux)
697 spc_3_aux = numpy.concatenate((spc_1_aux,spc_2_aux[1:]))
698
699 len_dif = len(x)-len(spc_3_aux)
700
701 spc_zeros = numpy.ones(len_dif)*spc_1_aux[0]
702
703 spc_new = numpy.concatenate((spc_3_aux,spc_zeros))
704
705 y = spc_new
706
707 elif nGauss == 'second':
708 y = spc
709
710
711 # estimate starting values from the data
712 a = y.max()
713 b = x[numpy.argmax(y)]
714 if nGauss == 'first':
715 c = 1.#b#b#numpy.std(spc)
716 elif nGauss == 'second':
717 c = b
718 else:
719 print("ERROR")
720
721 d = numpy.mean(y[-100:])
722
723 # define a least squares function to optimize
724 def minfunc(params):
725 return sum((y-gaussian(x,params[0],params[1],params[2],params[3]))**2)
726
727 # fit
728 popt = fmin(minfunc,[a,b,c,d],disp=False)
729 #popt,fopt,niter,funcalls = fmin(minfunc,[a,b,c,d])
730
731
732 return gaussian(x, popt[0], popt[1], popt[2], popt[3]), popt[0], popt[1], popt[2], popt[3]
733
734
735 def Gauss_fit_2(self,spc,x,nGauss):
736
737
738 def gaussian(x, a, b, c, d):
739 val = a * numpy.exp(-(x - b)**2 / (2*c**2)) + d
740 return val
741
742 if nGauss == 'first':
743 spc_1_aux = numpy.copy(spc[:numpy.argmax(spc)+1])
744 spc_2_aux = numpy.flip(spc_1_aux)
745 spc_3_aux = numpy.concatenate((spc_1_aux,spc_2_aux[1:]))
746
747 len_dif = len(x)-len(spc_3_aux)
748
749 spc_zeros = numpy.ones(len_dif)*spc_1_aux[0]
750
751 spc_new = numpy.concatenate((spc_3_aux,spc_zeros))
752
753 y = spc_new
754
755 elif nGauss == 'second':
756 y = spc
757
758
759 # estimate starting values from the data
760 a = y.max()
761 b = x[numpy.argmax(y)]
762 if nGauss == 'first':
763 c = 1.#b#b#numpy.std(spc)
764 elif nGauss == 'second':
765 c = b
766 else:
767 print("ERROR")
768
769 d = numpy.mean(y[-100:])
770
771 # define a least squares function to optimize
772 popt,pcov = curve_fit(gaussian,x,y,p0=[a,b,c,d])
773 #popt,fopt,niter,funcalls = fmin(minfunc,[a,b,c,d])
774
775
776 #return gaussian(x, popt[0], popt[1], popt[2], popt[3]), popt[0], popt[1], popt[2], popt[3]
777 return gaussian(x, popt[0], popt[1], popt[2], popt[3]),popt[0], popt[1], popt[2], popt[3]
778
779 def Double_Gauss_fit(self,spc,x,A1,B1,C1,A2,B2,C2,D):
780
781 def double_gaussian(x, a1, b1, c1, a2, b2, c2, d):
782 val = a1 * numpy.exp(-(x - b1)**2 / (2*c1**2)) + a2 * numpy.exp(-(x - b2)**2 / (2*c2**2)) + d
783 return val
784
785
786 y = spc
787
788 # estimate starting values from the data
789 a1 = A1
790 b1 = B1
791 c1 = C1#numpy.std(spc)
792
793 a2 = A2#y.max()
794 b2 = B2#x[numpy.argmax(y)]
795 c2 = C2#numpy.std(spc)
796 d = D
797
798 # define a least squares function to optimize
799 def minfunc(params):
800 return sum((y-double_gaussian(x,params[0],params[1],params[2],params[3],params[4],params[5],params[6]))**2)
801
802 # fit
803 popt = fmin(minfunc,[a1,b1,c1,a2,b2,c2,d],disp=False)
804
805 return double_gaussian(x, popt[0], popt[1], popt[2], popt[3], popt[4], popt[5], popt[6]), popt[0], popt[1], popt[2], popt[3], popt[4], popt[5], popt[6]
806
807 def Double_Gauss_fit_2(self,spc,x,A1,B1,C1,A2,B2,C2,D):
808
809 def double_gaussian(x, a1, b1, c1, a2, b2, c2, d):
810 val = a1 * numpy.exp(-(x - b1)**2 / (2*c1**2)) + a2 * numpy.exp(-(x - b2)**2 / (2*c2**2)) + d
811 return val
812
813
814 y = spc
815
816 # estimate starting values from the data
817 a1 = A1
818 b1 = B1
819 c1 = C1#numpy.std(spc)
820
821 a2 = A2#y.max()
822 b2 = B2#x[numpy.argmax(y)]
823 c2 = C2#numpy.std(spc)
824 d = D
825
826 # fit
827
828 popt,pcov = curve_fit(double_gaussian,x,y,p0=[a1,b1,c1,a2,b2,c2,d])
829
830 error = numpy.sqrt(numpy.diag(pcov))
831
832 return popt[0], popt[1], popt[2], popt[3], popt[4], popt[5], popt[6], error[0], error[1], error[2], error[3], error[4], error[5], error[6]
833
834
835
836
837 def run(self, dataOut):
838
839 pwcode = 1
840
841 if dataOut.flagDecodeData:
842 pwcode = numpy.sum(dataOut.code[0]**2)
843 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
844 normFactor = dataOut.nProfiles * dataOut.nIncohInt * dataOut.nCohInt * pwcode * dataOut.windowOfFilter
845 factor = normFactor
846 z = dataOut.data_spc / factor
847 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
848 dataOut.power = numpy.average(z, axis=1)
849 dataOut.powerdB = 10 * numpy.log10(dataOut.power)
850
851
852 x = dataOut.getVelRange(0)
853 #print(aux)
854 #print(numpy.shape(aux))
855 #exit(1)
856
857 #print(numpy.shape(dataOut.data_spc))
858
859 dataOut.Oblique_params = numpy.ones((1,7,dataOut.nHeights))*numpy.NAN
860 dataOut.Oblique_param_errors = numpy.ones((1,7,dataOut.nHeights))*numpy.NAN
861
862 dataOut.VelRange = x
863
864
865 l1=range(22,36)
866 l2=range(58,99)
867
868 for hei in itertools.chain(l1, l2):
869 #print("INIT")
870 #print(hei)
871
872 try:
873 spc = dataOut.data_spc[0,:,hei]
874
875 spc_fit, A1, B1, C1, D1 = self.Gauss_fit_2(spc,x,'first')
876
877 spc_diff = spc - spc_fit
878 spc_diff[spc_diff < 0] = 0
879
880 spc_fit_diff, A2, B2, C2, D2 = self.Gauss_fit_2(spc_diff,x,'second')
881
882 D = (D1+D2)
883
884 dataOut.Oblique_params[0,0,hei],dataOut.Oblique_params[0,1,hei],dataOut.Oblique_params[0,2,hei],dataOut.Oblique_params[0,3,hei],dataOut.Oblique_params[0,4,hei],dataOut.Oblique_params[0,5,hei],dataOut.Oblique_params[0,6,hei],dataOut.Oblique_param_errors[0,0,hei],dataOut.Oblique_param_errors[0,1,hei],dataOut.Oblique_param_errors[0,2,hei],dataOut.Oblique_param_errors[0,3,hei],dataOut.Oblique_param_errors[0,4,hei],dataOut.Oblique_param_errors[0,5,hei],dataOut.Oblique_param_errors[0,6,hei] = self.Double_Gauss_fit_2(spc,x,A1,B1,C1,A2,B2,C2,D)
885 #spc_double_fit,dataOut.Oblique_params = self.Double_Gauss_fit(spc,x,A1,B1,C1,A2,B2,C2,D)
886 #print(dataOut.Oblique_params)
887 except:
888 ###dataOut.Oblique_params[0,:,hei] = dataOut.Oblique_params[0,:,hei]*numpy.NAN
889 pass
890 #print("DONE")
891 '''
892 print(dataOut.Oblique_params[1])
893 print(dataOut.Oblique_params[4])
894 import matplotlib.pyplot as plt
895 plt.plot(x,spc_double_fit)
896 plt.show()
897 import time
898 time.sleep(5)
899 plt.close()
900 '''
901
902
903
904
905
906 return dataOut
591
907
592 def misfit2(self,state,y_data,x,num_intg):
593 return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.)
594
908
595
909
596
910
@@ -3998,3 +4312,55 class SMOperations():
3998 # error[indInvalid1] = 13
4312 # error[indInvalid1] = 13
3999 #
4313 #
4000 # return heights, error
4314 # return heights, error
4315
4316
4317
4318 class IGRFModel(Operation):
4319 """Operation to calculate Geomagnetic parameters.
4320
4321 Parameters:
4322 -----------
4323 None
4324
4325 Example
4326 --------
4327
4328 op = proc_unit.addOperation(name='IGRFModel', optype='other')
4329
4330 """
4331
4332 def __init__(self, **kwargs):
4333
4334 Operation.__init__(self, **kwargs)
4335
4336 self.aux=1
4337
4338 def run(self,dataOut):
4339
4340 try:
4341 from schainpy.model.proc import mkfact_short_2020
4342 except:
4343 log.warning('You should install "mkfact_short_2020" module to process IGRF Model')
4344
4345 if self.aux==1:
4346
4347 #dataOut.TimeBlockSeconds_First_Time=time.mktime(time.strptime(dataOut.TimeBlockDate))
4348 #### we do not use dataOut.datatime.ctime() because it's the time of the second (next) block
4349 dataOut.TimeBlockSeconds_First_Time=dataOut.TimeBlockSeconds
4350 dataOut.bd_time=time.gmtime(dataOut.TimeBlockSeconds_First_Time)
4351 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
4352 dataOut.ut=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
4353
4354 self.aux=0
4355
4356 dataOut.h=numpy.arange(0.0,15.0*dataOut.MAXNRANGENDT,15.0,dtype='float32')
4357 dataOut.bfm=numpy.zeros(dataOut.MAXNRANGENDT,dtype='float32')
4358 dataOut.bfm=numpy.array(dataOut.bfm,order='F')
4359 dataOut.thb=numpy.zeros(dataOut.MAXNRANGENDT,dtype='float32')
4360 dataOut.thb=numpy.array(dataOut.thb,order='F')
4361 dataOut.bki=numpy.zeros(dataOut.MAXNRANGENDT,dtype='float32')
4362 dataOut.bki=numpy.array(dataOut.bki,order='F')
4363
4364 mkfact_short_2020.mkfact(dataOut.year,dataOut.h,dataOut.bfm,dataOut.thb,dataOut.bki,dataOut.MAXNRANGENDT)
4365
4366 return dataOut
@@ -873,4 +873,4 class IncohInt(Operation):
873 dataOut.utctime = avgdatatime
873 dataOut.utctime = avgdatatime
874 dataOut.flagNoData = False
874 dataOut.flagNoData = False
875
875
876 return dataOut No newline at end of file
876 return dataOut
@@ -736,4 +736,4 class SpectraLagsProc(ProcessingUnit):
736
736
737 self.dataOut.noise_estimation = noise.copy()
737 self.dataOut.noise_estimation = noise.copy()
738
738
739 return 1 No newline at end of file
739 return 1
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now