##// END OF EJS Templates
isr commit
rflores -
r1377:5453f456345b
parent child
Show More
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')
This diff has been collapsed as it changes many lines, (2561 lines changed) Show them Hide them
@@ -0,0 +1,2561
1
2 import matplotlib.pyplot as plt
3
4
5
6 import numpy
7 import time
8 import math
9
10 from datetime import datetime
11
12 from schainpy.utils import log
13
14 import struct
15 import os
16
17 import sys
18
19 from ctypes import *
20
21 from schainpy.model.io.jroIO_voltage import VoltageReader,JRODataReader
22 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
23 from schainpy.model.data.jrodata import Voltage
24
25
26
27
28 @MPDecorator
29 class VoltageLagsProc(ProcessingUnit):
30
31 def __init__(self):
32
33 ProcessingUnit.__init__(self)
34
35 self.dataOut = Voltage()
36 self.bcounter=0
37 self.dataOut.kax=None
38 self.dataOut.kay=None
39 self.dataOut.kbx=None
40 self.dataOut.kby=None
41 self.dataOut.kax2=None
42 self.dataOut.kay2=None
43 self.dataOut.kbx2=None
44 self.dataOut.kby2=None
45 self.dataOut.kaxbx=None
46 self.dataOut.kaxby=None
47 self.dataOut.kaybx=None
48 self.dataOut.kayby=None
49 self.dataOut.kaxay=None
50 self.dataOut.kbxby=None
51 self.aux=1
52
53 self.LP_products_aux=0
54 self.lag_products_LP_median_estimates_aux=0
55
56 #self.dataOut.input_dat_type=0 #06/04/2020
57
58 def get_products_cabxys(self):
59
60
61 if self.aux==1:
62
63
64
65 self.dataOut.read_samples=int(self.dataOut.systemHeaderObj.nSamples/self.dataOut.OSAMP)
66 if self.dataOut.experiment=="DP":
67 self.dataOut.nptsfft1=132 #30/03/2020
68 self.dataOut.nptsfft2=140 #30/03/2020
69 if self.dataOut.experiment=="HP":
70 self.dataOut.nptsfft1=128 #30/03/2020
71 self.dataOut.nptsfft2=150 #30/03/2020
72
73
74 #self.dataOut.noise_final_list=[] #30/03/2020
75
76 padding=numpy.zeros(1,'int32')
77
78 hsize=numpy.zeros(1,'int32')
79 bufsize=numpy.zeros(1,'int32')
80 nr=numpy.zeros(1,'int32')
81 ngates=numpy.zeros(1,'int32') ### ### ### 2
82 time1=numpy.zeros(1,'uint64') # pos 3
83 time2=numpy.zeros(1,'uint64') # pos 4
84 lcounter=numpy.zeros(1,'int32')
85 groups=numpy.zeros(1,'int32')
86 system=numpy.zeros(4,'int8') # pos 7
87 h0=numpy.zeros(1,'float32')
88 dh=numpy.zeros(1,'float32')
89 ipp=numpy.zeros(1,'float32')
90 process=numpy.zeros(1,'int32')
91 tx=numpy.zeros(1,'int32')
92
93 ngates1=numpy.zeros(1,'int32') ### ### ### 13
94 time0=numpy.zeros(1,'uint64') # pos 14
95 nlags=numpy.zeros(1,'int32')
96 nlags1=numpy.zeros(1,'int32')
97 txb=numpy.zeros(1,'float32') ### ### ### 17
98 time3=numpy.zeros(1,'uint64') # pos 18
99 time4=numpy.zeros(1,'uint64') # pos 19
100 h0_=numpy.zeros(1,'float32')
101 dh_=numpy.zeros(1,'float32')
102 ipp_=numpy.zeros(1,'float32')
103 txa_=numpy.zeros(1,'float32')
104
105 pad=numpy.zeros(100,'int32')
106
107 nbytes=numpy.zeros(1,'int32')
108 limits=numpy.zeros(1,'int32')
109 ngroups=numpy.zeros(1,'int32') ### ### ### 27
110
111
112 self.dataOut.header=[hsize,bufsize,nr,ngates,time1,time2,
113 lcounter,groups,system,h0,dh,ipp,
114 process,tx,ngates1,padding,time0,nlags,
115 nlags1,padding,txb,time3,time4,h0_,dh_,
116 ipp_,txa_,pad,nbytes,limits,padding,ngroups]
117
118 if self.dataOut.experiment == "DP":
119 self.dataOut.header[1][0]=81864
120 if self.dataOut.experiment == "HP":
121 self.dataOut.header[1][0]=173216
122
123 self.dataOut.header[3][0]=max(self.dataOut.NRANGE,self.dataOut.NDT)
124 self.dataOut.header[7][0]=self.dataOut.NAVG
125 self.dataOut.header[9][0]=int(self.dataOut.heightList[0])
126 self.dataOut.header[10][0]=self.dataOut.DH
127 self.dataOut.header[17][0]=self.dataOut.DPL
128 self.dataOut.header[18][0]=self.dataOut.NLAG
129 #self.header[5][0]=0
130 self.dataOut.header[15][0]=self.dataOut.NDP
131 self.dataOut.header[2][0]=self.dataOut.NR
132 #time.mktime(time.strptime()
133
134
135
136
137 self.aux=0
138
139
140
141
142
143
144
145
146
147 if self.dataOut.experiment=="DP":
148
149
150 self.dataOut.lags_array=[x / self.dataOut.DH for x in self.dataOut.flags_array]
151 self.cax=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
152 self.cay=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
153 self.cbx=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
154 self.cby=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
155 self.cax2=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
156 self.cay2=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
157 self.cbx2=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
158 self.cby2=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
159 self.caxbx=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
160 self.caxby=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
161 self.caybx=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
162 self.cayby=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
163 self.caxay=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
164 self.cbxby=numpy.zeros((self.dataOut.NDP,self.dataOut.nlags_array,2))
165
166 for i in range(2):
167 for j in range(self.dataOut.NDP):
168 for k in range(int(self.dataOut.NSCAN/2)):
169 n=k%self.dataOut.nlags_array
170 ax=self.dataOut.data[0,2*k+i,j].real
171 ay=self.dataOut.data[0,2*k+i,j].imag
172 if j+self.dataOut.lags_array[n]<self.dataOut.NDP:
173 bx=self.dataOut.data[1,2*k+i,j+int(self.dataOut.lags_array[n])].real
174 by=self.dataOut.data[1,2*k+i,j+int(self.dataOut.lags_array[n])].imag
175 else:
176 if k+1<int(self.dataOut.NSCAN/2):
177 bx=self.dataOut.data[1,2*(k+1)+i,(self.dataOut.NRANGE+self.dataOut.NCAL+j+int(self.dataOut.lags_array[n]))%self.dataOut.NDP].real
178 by=self.dataOut.data[1,2*(k+1)+i,(self.dataOut.NRANGE+self.dataOut.NCAL+j+int(self.dataOut.lags_array[n]))%self.dataOut.NDP].imag
179
180 if k+1==int(self.dataOut.NSCAN/2):
181 bx=self.dataOut.data[1,2*k+i,(self.dataOut.NRANGE+self.dataOut.NCAL+j+int(self.dataOut.lags_array[n]))%self.dataOut.NDP].real
182 by=self.dataOut.data[1,2*k+i,(self.dataOut.NRANGE+self.dataOut.NCAL+j+int(self.dataOut.lags_array[n]))%self.dataOut.NDP].imag
183
184 if(k<self.dataOut.nlags_array):
185 self.cax[j][n][i]=ax
186 self.cay[j][n][i]=ay
187 self.cbx[j][n][i]=bx
188 self.cby[j][n][i]=by
189 self.cax2[j][n][i]=ax*ax
190 self.cay2[j][n][i]=ay*ay
191 self.cbx2[j][n][i]=bx*bx
192 self.cby2[j][n][i]=by*by
193 self.caxbx[j][n][i]=ax*bx
194 self.caxby[j][n][i]=ax*by
195 self.caybx[j][n][i]=ay*bx
196 self.cayby[j][n][i]=ay*by
197 self.caxay[j][n][i]=ax*ay
198 self.cbxby[j][n][i]=bx*by
199 else:
200 self.cax[j][n][i]+=ax
201 self.cay[j][n][i]+=ay
202 self.cbx[j][n][i]+=bx
203 self.cby[j][n][i]+=by
204 self.cax2[j][n][i]+=ax*ax
205 self.cay2[j][n][i]+=ay*ay
206 self.cbx2[j][n][i]+=bx*bx
207 self.cby2[j][n][i]+=by*by
208 self.caxbx[j][n][i]+=ax*bx
209 self.caxby[j][n][i]+=ax*by
210 self.caybx[j][n][i]+=ay*bx
211 self.cayby[j][n][i]+=ay*by
212 self.caxay[j][n][i]+=ax*ay
213 self.cbxby[j][n][i]+=bx*by
214
215
216
217 #return self.cax,self.cay,self.cbx,self.cby,self.cax2,self.cay2,self.cbx2,self.cby2,self.caxbx,self.caxby,self.caybx,self.cayby,self.caxay,self.cbxby
218
219 if self.dataOut.experiment=="HP":
220
221 #lagind=[0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10]
222 #lagfirst=[1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1]
223
224 self.cax=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2
225 self.cay=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
226 self.cbx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
227 self.cby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
228 self.cax2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
229 self.cay2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
230 self.cbx2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
231 self.cby2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
232 self.caxbx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
233 self.caxby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
234 self.caybx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
235 self.cayby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
236 self.caxay=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
237 self.cbxby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2))
238 for i in range(2): # flipped and unflipped
239 for j in range(self.dataOut.NDP): # loop over true ranges # 67
240 for k in range(int(self.dataOut.NSCAN)): # 128
241 #print("flip ",i," NDP ",j, " NSCAN ",k)
242 #print("cdata ",cdata[i:NSCAN:2][k][:,0])
243 n=self.dataOut.lagind[k%self.dataOut.nlags_array] # 128=16x8
244 #print("n ",n)
245 #ind1=nrx*(j+ngates_2*i+ngates_2*2*k)# scan has flip or unflip
246 #ind2=ind1+(1)+nrx*lags_array[n]#jump each lagged
247 #ax=cdata[i:NSCAN:2][k][:,0][NRANGE+NCAL+j].real #cdata[ind1].r
248 #ay=cdata[i:NSCAN:2][k][:,0][NRANGE+NCAL+j].imag #cdata[ind1].i
249 #input()
250 ##ax=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,0][NRANGE+NCAL+j].real #cdata[ind1].r
251 ##ay=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,0][NRANGE+NCAL+j].imag #cdata[ind1].i
252
253 ax=self.dataOut.data[0,k,self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT].real
254 ay=self.dataOut.data[0,k,self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT].imag
255
256 #print("ax ",ax," ay",ay)
257 if self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n<self.dataOut.read_samples:
258 #bx=cdata[i:NSCAN:2][k][:,1][NRANGE+NCAL+j+n].real #cdata[ind2].r
259 #by=cdata[i:NSCAN:2][k][:,1][NRANGE+NCAL+j+n].imag #cdata[ind2].i
260 ##bx=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,1][NRANGE+NCAL+j+2*n].real #cdata[ind2].r
261 ##by=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,1][NRANGE+NCAL+j+2*n].imag #cdata[ind2].i
262
263 bx=self.dataOut.data[1,k,self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n].real
264 by=self.dataOut.data[1,k,self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n].imag
265
266 #bx=self.dataOut.data[0:NSCAN][k][:,1][NRANGE+NCAL+j+i*NDT+2*n].real #cdata[ind2].r
267 #by=self.dataOut.data[0:NSCAN][k][:,1][NRANGE+NCAL+j+i*NDT+2*n].imag #cdata[ind2].i
268 #print("bx ",bx, " by ",by)
269 #input()
270 else:
271 #print("n ",n," k ",k," j ",j," i ",i, " n ",n)
272 #input()
273 if k+1<int(self.dataOut.NSCAN):
274 #print("k+1 ",k+1)
275 #print("int(NSCAN/2) ",int(NSCAN/2))
276 #bx=cdata[i:NSCAN:2][k+1][:,1][(NRANGE+NCAL+j+n)%NDP].real#np.nan
277 #by=cdata[i:NSCAN:2][k+1][:,1][(NRANGE+NCAL+j+n)%NDP].imag#np.nan
278 ##bx=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k+1][:,1][(NRANGE+NCAL+j+2*n)%NDP].real#np.nan
279 ##by=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k+1][:,1][(NRANGE+NCAL+j+2*n)%NDP].imag#np.nan
280 #bx=self.dataOut.data[0:NSCAN][k+1][:,1][(NRANGE+NCAL+j+i*NDT+2*n)%NDP].real#np.nan
281 #by=self.dataOut.data[0:NSCAN][k+1][:,1][(NRANGE+NCAL+j+i*NDT+2*n)%NDP].imag#np.nan
282 bx=self.dataOut.data[1,k+1,(self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n)%self.dataOut.NDP].real
283 by=self.dataOut.data[1,k+1,(self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n)%self.dataOut.NDP].imag
284
285 #print("n ",n," k ",k," j ",j," i ",i, " lags_array[n] ",lags_array[n])
286 #print("bx ",bx, " by ",by)
287 #input()
288 if k+1==int(self.dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE
289 #bx=cdata[i:NSCAN:2][k][:,1][(NRANGE+NCAL+j+n)%NDP].real#np.nan
290 #by=cdata[i:NSCAN:2][k][:,1][(NRANGE+NCAL+j+n)%NDP].imag#np.nan
291 ##bx=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,1][(NRANGE+NCAL+j+2*n)%NDP].real#np.nan
292 ##by=cdata[int(i*NSCAN):int((i+1)*NSCAN)][k][:,1][(NRANGE+NCAL+j+2*n)%NDP].imag#np.nan
293 #print("****n ",n," k ",k," j ",j," i ",i, " lags_array[n] ",lags_array[n])
294 #bx=self.dataOut.data[0:NSCAN][k][:,1][(NRANGE+NCAL+j+i*NDT+2*n)%NDP].real#np.nan
295 #by=self.dataOut.data[0:NSCAN][k][:,1][(NRANGE+NCAL+j+i*NDT+2*n)%NDP].imag#np.nan
296 bx=self.dataOut.data[1,k,(self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n)%self.dataOut.NDP].real
297 by=self.dataOut.data[1,k,(self.dataOut.NRANGE+self.dataOut.NCAL+j+i*self.dataOut.NDT+2*n)%self.dataOut.NDP].imag
298
299 #print("bx ",bx, " by ",by)
300 #input()
301
302 #print("i ",i," j ",j," k ",k," n ",n," ax ",ax)
303 #input()
304 #ip1=j+NDP*(i+2*n)
305 #ip2=ip1*navg+iavg
306 ##if(k<11): # PREVIOUS
307 if(k<self.dataOut.nlags_array and self.dataOut.lagfirst[k%self.dataOut.nlags_array]==1):# if(k<16 && lagfirst[k%16]==1)
308 self.cax[j][n][i]=ax#[int(k/nlags_array)*nlags_array+n]
309 self.cay[j][n][i]=ay#[int(k/nlags_array)*nlags_array+n]
310 self.cbx[j][n][i]=bx#[int(k/nlags_array)*nlags_array+n]
311 self.cby[j][n][i]=by#[int(k/nlags_array)*nlags_array+n]
312 self.cax2[j][n][i]=ax*ax#np.multiply(ax,ax)[int(k/nlags_array)*nlags_array+n]
313 self.cay2[j][n][i]=ay*ay#np.multiply(ay,ay)[int(k/nlags_array)*nlags_array+n]
314 self.cbx2[j][n][i]=bx*bx#np.multiply(bx,bx)[int(k/nlags_array)*nlags_array+n]
315 self.cby2[j][n][i]=by*by#np.multiply(by,by)[int(k/nlags_array)*nlags_array+n]
316 self.caxbx[j][n][i]=ax*bx#np.multiply(ax,bx)[int(k/nlags_array)*nlags_array+n]
317 self.caxby[j][n][i]=ax*by#np.multiply(ax,by)[int(k/nlags_array)*nlags_array+n]
318 self.caybx[j][n][i]=ay*bx#np.multiply(ay,bx)[int(k/nlags_array)*nlags_array+n]
319 self.cayby[j][n][i]=ay*by#np.multiply(ay,by)[int(k/nlags_array)*nlags_array+n]
320 self.caxay[j][n][i]=ax*ay#np.multiply(ax,ay)[int(k/nlags_array)*nlags_array+n]
321 self.cbxby[j][n][i]=bx*by#np.multiply(bx,by)[int(k/nlags_array)*nlags_array+n]
322 else:
323 self.cax[j][n][i]+=ax#[int(k/nlags_array)*nlags_array+n]
324 self.cay[j][n][i]+=ay#[int(k/nlags_array)*nlags_array+n]
325 self.cbx[j][n][i]+=bx#[int(k/nlags_array)*nlags_array+n]
326 self.cby[j][n][i]+=by#[int(k/nlags_array)*nlags_array+n]
327 self.cax2[j][n][i]+=ax*ax#np.multiply(ax,ax)[int(k/nlags_array)*nlags_array+n]
328 self.cay2[j][n][i]+=ay*ay#np.multiply(ay,ay)[int(k/nlags_array)*nlags_array+n]
329 self.cbx2[j][n][i]+=bx*bx#np.multiply(bx,bx)[int(k/nlags_array)*nlags_array+n]
330 self.cby2[j][n][i]+=by*by#np.multiply(by,by)[int(k/nlags_array)*nlags_array+n]
331 self.caxbx[j][n][i]+=ax*bx#np.multiply(ax,bx)[int(k/nlags_array)*nlags_array+n]
332 self.caxby[j][n][i]+=ax*by#np.multiply(ax,by)[int(k/nlags_array)*nlags_array+n]
333 self.caybx[j][n][i]+=ay*bx#np.multiply(ay,bx)[int(k/nlags_array)*nlags_array+n]
334 self.cayby[j][n][i]+=ay*by#np.multiply(ay,by)[int(k/nlags_array)*nlags_array+n]
335 self.caxay[j][n][i]+=ax*ay#np.multiply(ax,ay)[int(k/nlags_array)*nlags_array+n]
336 self.cbxby[j][n][i]+=bx*by#np.multiply(bx,by)[int(k/nlags_array)*nlags_array+n]
337
338
339
340
341
342
343
344
345
346 def medi(self,data_navg):
347 sorts=sorted(data_navg)
348 rsorts=numpy.arange(self.dataOut.NAVG)
349 result=0.0
350 for k in range(self.dataOut.NAVG):
351 if k>=self.dataOut.nkill/2 and k<self.dataOut.NAVG-self.dataOut.nkill/2:
352 result+=sorts[k]*float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill)
353 return result
354
355
356
357 '''
358 def range(self):
359 Range=numpy.arange(0,990,self.DH)
360 return Range
361 '''
362
363
364
365
366
367
368 def cabxys_navg(self):
369
370 #print("blocknow",self.dataOut.CurrentBlock)
371 #bcounter=0
372 #print("self.bcounter",self.bcounter)
373 self.get_products_cabxys()
374
375 self.dataOut.header[5][0]=time.mktime(time.strptime(self.dataOut.TimeBlockDate))
376
377 #if salf.dataOut.CurrentBlock<NAVG:
378 if self.bcounter==0:
379
380 self.dataOut.header[4][0]=self.dataOut.header[5][0]
381 if self.dataOut.CurrentBlock==1:
382 self.dataOut.header[16][0]=self.dataOut.header[5][0]
383
384 self.cax_navg=[]
385 self.cay_navg=[]
386 self.cbx_navg=[]
387 self.cby_navg=[]
388 self.cax2_navg=[]
389 self.cay2_navg=[]
390 self.cbx2_navg=[]
391 self.cby2_navg=[]
392 self.caxbx_navg=[]
393 self.caxby_navg=[]
394 self.caybx_navg=[]
395 self.cayby_navg=[]
396 self.caxay_navg=[]
397 self.cbxby_navg=[]
398 self.dataOut.kax=None
399 self.dataOut.kay=None
400 self.dataOut.kbx=None
401 self.dataOut.kby=None
402 self.dataOut.kax2=None
403 self.dataOut.kay2=None
404 self.dataOut.kbx2=None
405 self.dataOut.kby2=None
406 self.dataOut.kaxbx=None
407 self.dataOut.kaxby=None
408 self.dataOut.kaybx=None
409 self.dataOut.kayby=None
410 self.dataOut.kaxay=None
411 self.dataOut.kbxby=None
412
413 self.dataOut.noisevector=numpy.zeros((self.dataOut.read_samples,self.dataOut.NR,self.dataOut.NAVG),'float32') #30/03/2020
414 self.dataOut.noisevector_=numpy.zeros((self.dataOut.read_samples,self.dataOut.NR,self.dataOut.NAVG),'float32')
415 self.dataOut.dc=numpy.zeros(self.dataOut.NR,dtype=numpy.complex_) #30/03/2020
416 #self.dataOut.noisevector=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
417 #self.dataOut.noisevector_=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
418
419 #self.dataOut.dc=numpy.zeros(2,dtype=numpy.complex_) #31/03/2020
420 #self.dataOut.processingHeaderObj.profilesPerBlock
421 if self.dataOut.experiment=="DP":
422 self.noisevectorizer(self.dataOut.nptsfft1,self.dataOut.nptsfft2) #30/03/2020
423 if self.dataOut.experiment=="HP":
424 self.noisevectorizer(self.dataOut.nptsfft1,self.dataOut.nptsfftx1) #31/03/2020
425 #print(self.dataOut.noisevector[:,:,:])
426 #print("·················································")
427 #print("CAX: ",self.cax)
428 self.cax_navg.append(self.cax)
429 self.cay_navg.append(self.cay)
430 self.cbx_navg.append(self.cbx)
431 self.cby_navg.append(self.cby)
432 self.cax2_navg.append(self.cax2)
433 self.cay2_navg.append(self.cay2)
434 self.cbx2_navg.append(self.cbx2)
435 self.cby2_navg.append(self.cby2)
436 self.caxbx_navg.append(self.caxbx)
437 self.caxby_navg.append(self.caxby)
438 self.caybx_navg.append(self.caybx)
439 self.cayby_navg.append(self.cayby)
440 self.caxay_navg.append(self.caxay)
441 self.cbxby_navg.append(self.cbxby)
442 self.bcounter+=1
443
444 #self.dataOut.data=None
445 #print("bcounter",bcounter)
446 #/#/#/#if self.bcounter==NAVG:
447
448 #/#/#/#print("cax_navg: ",self.cax_navg)
449 #/#/#/#self.bcounter=0
450 #print("blocknow",self.dataOut.current)
451
452
453
454 def kabxys(self,NAVG,nkill):#,NRANGE,NCAL,NDT):
455
456 self.dataOut.NAVG=NAVG
457 self.dataOut.nkill=nkill
458 #print("bcounter_before: ",self.bcounter)
459 #print("kabxys")
460
461 #if self.dataOut.input_dat_type==0:
462 #self.dataOut.NDP=NDP
463 #self.dataOut.nlags_array=nlags_array
464 #self.dataOut.NSCAN=NSCAN
465 #self.dataOut.DH=float(DH)
466 #self.dataOut.flags_array=flags_array
467
468 #self.dataOut.DPL=DPL
469 #self.dataOut.NRANGE=NRANGE
470 #self.dataOut.NCAL=NCAL
471
472 #self.dataOut.NDT=NDT
473 #self.lag_products_LP()
474 ####self.cabxys_navg(NDP,nlags_array,NSCAN,flags_array)
475 self.cabxys_navg()
476 #self.dataOut.kshape=numpy.zeros((numpy.shape(self.cax_navg[0])[0],numpy.shape(self.cax_navg[0])[1],numpy.shape(self.cax_navg[0])[2]))
477 #print("Shape cavg",numpy.shape(self.cax_navg[0])[0])
478 self.dataOut.flag_save=0
479 #self.dataOut.flagNoData = True # new 1
480
481
482 if self.bcounter==self.dataOut.NAVG:
483
484 #self.dataOut.flagNoData = False # new 2
485 self.dataOut.flag_save=1
486 #self.dataOut.kax=None
487
488
489 self.dataOut.noise_final=numpy.zeros(self.dataOut.NR,'float32') #30/03/2020
490 #self.dataOut.noise_final=numpy.zeros(2,'float32') #31/03/2020
491
492 #print("self.dataOut.nChannels: ",self.dataOut.systemHeaderObj.nChannels)
493 self.kax=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
494 self.kay=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
495 self.kbx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
496 self.kby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
497 self.kax2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
498 self.kay2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
499 self.kbx2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
500 self.kby2=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
501 self.kaxbx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
502 self.kaxby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
503 self.kaybx=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
504 self.kayby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
505 self.kaxay=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
506 self.kbxby=numpy.zeros((self.dataOut.NDP,self.dataOut.DPL,2),'float32')
507 #print("Shape K",numpy.shape(self.kax))
508 for i in range(self.cax_navg[0].shape[0]):
509 for j in range(self.cax_navg[0].shape[1]):
510 for k in range(self.cax_navg[0].shape[2]):
511 data_navg=[item[i,j,k] for item in self.cax_navg]
512 self.kax[i,j,k]=self.medi(data_navg)
513 data_navg=[item[i,j,k] for item in self.cay_navg]
514 self.kay[i,j,k]=self.medi(data_navg)
515 data_navg=[item[i,j,k] for item in self.cbx_navg]
516 self.kbx[i,j,k]=self.medi(data_navg)
517 data_navg=[item[i,j,k] for item in self.cby_navg]
518 self.kby[i,j,k]=self.medi(data_navg)
519 data_navg=[item[i,j,k] for item in self.cax2_navg]
520 self.kax2[i,j,k]=self.medi(data_navg)
521 data_navg=[item[i,j,k] for item in self.cay2_navg]
522 self.kay2[i,j,k]=self.medi(data_navg)
523 data_navg=[item[i,j,k] for item in self.cbx2_navg]
524 self.kbx2[i,j,k]=self.medi(data_navg)
525 data_navg=[item[i,j,k] for item in self.cby2_navg]
526 self.kby2[i,j,k]=self.medi(data_navg)
527 data_navg=[item[i,j,k] for item in self.caxbx_navg]
528 self.kaxbx[i,j,k]=self.medi(data_navg)
529 data_navg=[item[i,j,k] for item in self.caxby_navg]
530 self.kaxby[i,j,k]=self.medi(data_navg)
531 data_navg=[item[i,j,k] for item in self.caybx_navg]
532 self.kaybx[i,j,k]=self.medi(data_navg)
533 data_navg=[item[i,j,k] for item in self.cayby_navg]
534 self.kayby[i,j,k]=self.medi(data_navg)
535 data_navg=[item[i,j,k] for item in self.caxay_navg]
536 self.kaxay[i,j,k]=self.medi(data_navg)
537 data_navg=[item[i,j,k] for item in self.cbxby_navg]
538 self.kbxby[i,j,k]=self.medi(data_navg)
539 #self.bcounter=0
540 #print("KAX",self.kax)
541 #self.__buffer=self.kax
542 #print("CurrentBlock: ", self.dataOut.CurrentBlock)
543
544 self.dataOut.kax=self.kax
545 self.dataOut.kay=self.kay
546 self.dataOut.kbx=self.kbx
547 self.dataOut.kby=self.kby
548 self.dataOut.kax2=self.kax2
549 self.dataOut.kay2=self.kay2
550 self.dataOut.kbx2=self.kbx2
551 self.dataOut.kby2=self.kby2
552 self.dataOut.kaxbx=self.kaxbx
553 self.dataOut.kaxby=self.kaxby
554 self.dataOut.kaybx=self.kaybx
555 self.dataOut.kayby=self.kayby
556 self.dataOut.kaxay=self.kaxay
557 self.dataOut.kbxby=self.kbxby
558 self.bcounter=0
559
560 #print("before: ",self.dataOut.noise_final)
561
562 self.noise_estimation4x() #30/03/2020
563
564 #print("after: ", self.dataOut.noise_final)
565 #print(numpy.shape(self.dataOut.data))
566 #input()
567 #self.dataOut.noise_final_list.append(self.dataOut.noise_final[0]) #30/03/2020
568
569
570 '''
571 print("hsize[0] ",self.dataOut.header[0])
572 print("bufsize[1] ",self.dataOut.header[1])
573 print("nr[2] ",self.dataOut.header[2])
574 print("ngates[3] ",self.dataOut.header[3])
575 print("time1[4] ",self.dataOut.header[4])
576 print("time2[5] ",self.dataOut.header[5])
577 print("lcounter[6] ",self.dataOut.header[6])
578 print("groups[7] ",self.dataOut.header[7])
579 print("system[8] ",self.dataOut.header[8])
580 print("h0[9] ",self.dataOut.header[9])
581 print("dh[10] ",self.dataOut.header[10])
582 print("ipp[11] ",self.dataOut.header[11])
583 print("process[12] ",self.dataOut.header[12])
584 print("tx[13] ",self.dataOut.header[13])
585 print("padding[14] ",self.dataOut.header[14])
586 print("ngates1[15] ",self.dataOut.header[15])
587 print("header[16] ",self.dataOut.header[16])
588 print("header[17] ",self.dataOut.header[17])
589 print("header[18] ",self.dataOut.header[18])
590 print("header[19] ",self.dataOut.header[19])
591 print("header[20] ",self.dataOut.header[20])
592 print("header[21] ",self.dataOut.header[21])
593 print("header[22] ",self.dataOut.header[22])
594 print("header[23] ",self.dataOut.header[23])
595 print("header[24] ",self.dataOut.header[24])
596 print("header[25] ",self.dataOut.header[25])
597 print("header[26] ",self.dataOut.header[26])
598 print("header[27] ",self.dataOut.header[27])
599 print("header[28] ",self.dataOut.header[28])
600 print("header[29] ",self.dataOut.header[29])
601 print("header[30] ",self.dataOut.header[30])
602 print("header[31] ",self.dataOut.header[31])
603 '''
604
605
606
607 #print("CurrentBlock: ",self.dataOut.CurrentBlock)
608 ##print("KAX: ",self.dataOut.kax)
609
610
611 '''
612 plt.plot(self.kaxby[:,0,0],self.range(),'m',linewidth=2.0)
613 plt.xlim(min(self.kaxby[12::,0,0]), max(self.kaxby[12::,0,0]))
614 plt.show()
615 '''
616
617
618
619
620
621 #/#/#/#print("CurrentBlock: ",self.dataOut.CurrentBlock)
622 ####self.newdataOut=self.kax
623 #print("shapedataout",numpy.shape(self.dataOut.data))
624 #print("kax",numpy.shape(self.kax))
625 ## return 1
626
627
628 ####def NewData(self):
629 ####print("NewData",self.dataOut.kaxby)
630 ####print("CurrentBlock: ",self.dataOut.CurrentBlock)
631
632
633 '''
634 def PlotVoltageLag(self):
635
636 plt.plot(self.dataOut.data[:,0,0],self.range(),'m',linewidth=2.0)
637 plt.xlim(min(self.dataOut.data[12::,0,0]), max(self.dataOut.data[12::,0,0]))
638 plt.show()
639
640
641 if self.bcounter==self.NAVG:
642 #print("shapedataout",self.dataOut.data)
643 print("CurrentBlock: ",self.dataOut.CurrentBlock)
644 self.bcounter=0
645 '''
646
647 #print("Newdataout",self.dataOut.data)
648 ##
649
650
651 #30/03/2020:
652 def noisevectorizer(self,nptsfft1,nptsfft2):
653
654 rnormalizer= 1./float(nptsfft2 - nptsfft1)
655 for i in range(self.dataOut.NR):
656 for j in range(self.dataOut.read_samples):
657 for k in range(nptsfft1,nptsfft2):
658 #TODO:integrate just 2nd quartile gates
659 if k==nptsfft1:
660 self.dataOut.noisevector[j][i][self.bcounter]=(abs(self.dataOut.data[i][k][j]-self.dataOut.dc[i])**2)*rnormalizer
661 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
662 else:
663 self.dataOut.noisevector[j][i][self.bcounter]+=(abs(self.dataOut.data[i][k][j]-self.dataOut.dc[i])**2)*rnormalizer
664
665 #30/03/2020:
666 def noise_estimation4x(self):
667 snoise=numpy.zeros((self.dataOut.NR,self.dataOut.NAVG),'float32')
668 nvector1=numpy.zeros((self.dataOut.NR,self.dataOut.NAVG,self.dataOut.read_samples),'float32')
669 for i in range(self.dataOut.NR):
670 self.dataOut.noise_final[i]=0.0
671 for k in range(self.dataOut.NAVG):
672 snoise[i][k]=0.0
673 for j in range(self.dataOut.read_samples):
674 nvector1[i][k][j]= self.dataOut.noisevector[j][i][k];
675 snoise[i][k]=self.noise_hs4x(self.dataOut.read_samples, nvector1[i][k])
676 self.dataOut.noise_final[i]=self.noise_hs4x(self.dataOut.NAVG, snoise[i])
677
678
679 #30/03/2020:
680 def noise_hs4x(self, ndatax, datax):
681 #print("datax ",datax)
682 divider=10#divider was originally 10
683 noise=0.0
684 data=numpy.zeros(ndatax,'float32')
685 ndata1=int(ndatax/4)
686 ndata2=int(2.5*(ndatax/4.))
687 ndata=int(ndata2-ndata1)
688 sorts=sorted(datax)
689 for k in range(ndata2): # select just second quartile
690 data[k]=sorts[k+ndata1]
691 nums_min= int(ndata/divider)
692 if(int(ndata/divider)> 2):
693 nums_min= int(ndata/divider)
694 else:
695 nums_min=2
696 sump=0.0
697 sumq=0.0
698 j=0
699 cont=1
700 while ( (cont==1) and (j<ndata)):
701 sump+=data[j]
702 sumq+= data[j]*data[j]
703 j=j+1
704 if (j> nums_min):
705 rtest= float(j/(j-1)) +1.0/ndata
706 if( (sumq*j) > (rtest*sump*sump ) ):
707 j=j-1
708 sump-= data[j]
709 sumq-=data[j]*data[j]
710 cont= 0
711 noise= (sump/j)
712
713 return noise
714
715
716
717 def test(self):
718
719 #print("LP_init")
720 #self.dataOut.flagNoData=1
721 buffer=self.dataOut.data
722 #self.dataOut.flagNoData=0
723 if self.LP_products_aux==0:
724
725 #self.dataOut.nptsfft2=150
726 self.cnorm=float((self.dataOut.nptsfft2LP-self.dataOut.NSCAN)/self.dataOut.NSCAN)
727
728
729 #print("self.bcounter",self.bcounter)
730 self.lagp0=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
731 self.lagp1=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
732 self.lagp2=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
733 self.lagp3=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
734 self.lagp4=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
735 self.LP_products_aux=1
736
737 #print(self.dataOut.data[0,0,0])
738 #self.dataOut.flagNoData =False
739 for i in range(self.dataOut.NR-1):
740 #print("inside i",i)
741 buffer_dc=self.dataOut.dc[i]
742 for j in range(self.dataOut.NRANGE):
743 #print("inside j",j)
744 #print(self.dataOut.read_samples)
745 #input()
746 range_for_n=numpy.min((self.dataOut.NRANGE-j,self.dataOut.NLAG))
747 for k in range(self.dataOut.nptsfft2LP):
748 #print(self.dataOut.data[i][k][j])
749 #input()
750 #print(self.dataOut.dc)
751 #input()
752 #aux_ac=0
753 buffer_aux=numpy.conj(buffer[i][k][j]-buffer_dc)
754 #self.dataOut.flagNoData=0
755 for n in range(range_for_n):
756
757
758 #for n in range(numpy.min((self.dataOut.NRANGE-j,self.dataOut.NLAG))):
759 #print(numpy.shape(self.dataOut.data))
760 #input()
761 #pass
762 #self.dataOut.flagNoData=1
763 #c=2*buffer_aux
764 #c=(self.dataOut.data[i][k][j]-self.dataOut.dc[i])*(numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
765 #c=(buffer[i][k][j]-buffer_dc)*(numpy.conj(buffer[i][k][j+n])-buffer_dc)
766
767 c=(buffer_aux)*(buffer[i][k][j+n]-buffer_dc)
768 #c=(buffer[i][k][j])*(buffer[i][k][j+n])
769 #print("first: ",self.dataOut.data[i][k][j]-self.dataOut.dc[i])
770 #print("second: ",numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
771
772 #print("c: ",c)
773 #input()
774 #print("n: ",n)
775 #print("aux_ac",aux_ac)
776 #print("data1:",self.dataOut.data[i][k][j])
777 #print("data2:",self.dataOut.data[i][k][j+n])
778 #print("dc: ",self.dataOut.dc[i])
779 #if aux_ac==2:
780 #input()
781 #aux_ac+=1
782 #print("GG")
783 #print("inside n",n)
784 #pass
785
786 if k<self.dataOut.NSCAN:
787 if k==0:
788
789 while True:
790 if i==0:
791 self.lagp0[n][j][self.bcounter-1]=c
792 break
793 elif i==1:
794 self.lagp1[n][j][self.bcounter-1]=c
795 break
796 elif i==2:
797 self.lagp2[n][j][self.bcounter-1]=c
798 break
799 else:
800 break
801
802 else:
803
804 while True:
805 if i==0:
806 self.lagp0[n][j][self.bcounter-1]=c+self.lagp0[n][j][self.bcounter-1]
807 break
808 elif i==1:
809 self.lagp1[n][j][self.bcounter-1]=c+self.lagp1[n][j][self.bcounter-1]
810 break
811 elif i==2:
812 self.lagp2[n][j][self.bcounter-1]=c+self.lagp2[n][j][self.bcounter-1]
813 break
814 else:
815 break
816
817 else:
818 #c=c/self.cnorm
819 if i==0:
820 c=c/self.cnorm
821 if k==self.dataOut.NSCAN:
822 #if i==0:
823 self.lagp3[n][j][self.bcounter-1]=c
824 #print("n: ",n,"j: ",j,"iavg: ",self.bcounter-1)
825 #print("lagp3_inside: ",self.lagp3[n][j][self.bcounter-1])
826 else:
827 #if i==0:
828 self.lagp3[n][j][self.bcounter-1]=c+self.lagp3[n][j][self.bcounter-1]
829
830
831
832
833 #print("lagp2: ",self.lagp2[:,0,0])
834 self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1])
835 self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1])
836 self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1])
837 self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1])
838 #self.dataOut.flagNoData=0
839 #print(self.bcounter-1)
840 #print("lagp2_conj: ",self.lagp2[:,0,self.bcounter-1])
841 #input()
842 #self.dataOut.lagp3=self.lagp3
843 print("TEST")
844
845
846
847 def lag_products_LP(self):
848
849 #print("LP_init")
850 #self.dataOut.flagNoData=1
851 buffer=self.dataOut.data
852 #self.dataOut.flagNoData=0
853 if self.LP_products_aux==0:
854
855 #self.dataOut.nptsfft2=150
856 self.cnorm=float((self.dataOut.nptsfft2LP-self.dataOut.NSCAN)/self.dataOut.NSCAN)
857
858
859 #print("self.bcounter",self.bcounter)
860 self.lagp0=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
861 self.lagp1=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
862 self.lagp2=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
863 self.lagp3=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
864 self.lagp4=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
865 self.LP_products_aux=1
866
867 #print(self.dataOut.data[0,0,0])
868 #self.dataOut.flagNoData =False
869 for i in range(self.dataOut.NR):
870 #print("inside i",i)
871 buffer_dc=self.dataOut.dc[i]
872 for j in range(self.dataOut.NRANGE):
873 #print("inside j",j)
874 #print(self.dataOut.read_samples)
875 #input()
876 range_for_n=numpy.min((self.dataOut.NRANGE-j,self.dataOut.NLAG))
877 for k in range(self.dataOut.nptsfft2LP):
878 #print(self.dataOut.data[i][k][j])
879 #input()
880 #print(self.dataOut.dc)
881 #input()
882 #aux_ac=0
883 buffer_aux=numpy.conj(buffer[i][k][j]-buffer_dc)
884 #self.dataOut.flagNoData=0
885 for n in range(range_for_n):
886 #for n in range(numpy.min((self.dataOut.NRANGE-j,self.dataOut.NLAG))):
887 #print(numpy.shape(self.dataOut.data))
888 #input()
889 #pass
890 #self.dataOut.flagNoData=1
891 #c=2*buffer_aux
892 #c=(self.dataOut.data[i][k][j]-self.dataOut.dc[i])*(numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
893 #c=(buffer[i][k][j]-buffer_dc)*(numpy.conj(buffer[i][k][j+n])-buffer_dc)
894
895 c=(buffer_aux)*(buffer[i][k][j+n]-buffer_dc)
896 #c=(buffer[i][k][j])*(buffer[i][k][j+n])
897 #print("first: ",self.dataOut.data[i][k][j]-self.dataOut.dc[i])
898 #print("second: ",numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
899
900 #print("c: ",c)
901 #input()
902 #print("n: ",n)
903 #print("aux_ac",aux_ac)
904 #print("data1:",self.dataOut.data[i][k][j])
905 #print("data2:",self.dataOut.data[i][k][j+n])
906 #print("dc: ",self.dataOut.dc[i])
907 #if aux_ac==2:
908 #input()
909 #aux_ac+=1
910 #print("GG")
911 #print("inside n",n)
912 #pass
913
914 if k<self.dataOut.NSCAN:
915 if k==0:
916 if i==0:
917 self.lagp0[n][j][self.bcounter-1]=c
918 elif i==1:
919 self.lagp1[n][j][self.bcounter-1]=c
920 elif i==2:
921 self.lagp2[n][j][self.bcounter-1]=c
922 else:
923 if i==0:
924 self.lagp0[n][j][self.bcounter-1]=c+self.lagp0[n][j][self.bcounter-1]
925 elif i==1:
926 self.lagp1[n][j][self.bcounter-1]=c+self.lagp1[n][j][self.bcounter-1]
927 elif i==2:
928 self.lagp2[n][j][self.bcounter-1]=c+self.lagp2[n][j][self.bcounter-1]
929
930 else:
931 c=c/self.cnorm
932 if k==self.dataOut.NSCAN:
933 if i==0:
934 self.lagp3[n][j][self.bcounter-1]=c
935 #print("n: ",n,"j: ",j,"iavg: ",self.bcounter-1)
936 #print("lagp3_inside: ",self.lagp3[n][j][self.bcounter-1])
937 else:
938 if i==0:
939 self.lagp3[n][j][self.bcounter-1]=c+self.lagp3[n][j][self.bcounter-1]
940
941
942
943 #print("lagp2: ",self.lagp2[:,0,0])
944 self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1])
945 self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1])
946 self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1])
947 self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1])
948 #self.dataOut.flagNoData=0
949 #print(self.bcounter-1)
950 #print("lagp2_conj: ",self.lagp2[:,0,self.bcounter-1])
951 #input()
952 #self.dataOut.lagp3=self.lagp3
953 print("LP")
954
955
956 def test_2(self):
957
958 #print("LP_init")
959 #self.dataOut.flagNoData=1
960
961 #self.dataOut.flagNoData=0
962 if self.LP_products_aux==0:
963
964 #self.dataOut.nptsfft2=150
965 self.cnorm=float((self.dataOut.nptsfft2LP-self.dataOut.NSCAN)/self.dataOut.NSCAN)
966
967
968 #print("self.bcounter",self.bcounter)
969 self.lagp0=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
970 self.lagp1=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
971 self.lagp2=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
972 self.lagp3=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
973 self.lagp4=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NAVG),'complex64')
974 self.LP_products_aux=1
975
976 #print(self.dataOut.data[0,0,0])
977 #self.dataOut.flagNoData =False
978 for i in range(self.dataOut.NR):
979 #print("inside i",i)
980
981 for j in range(self.dataOut.NRANGE):
982 #print("inside j",j)
983 #print(self.dataOut.read_samples)
984 #input()
985
986 for k in range(self.dataOut.nptsfft2LP):
987 #print(self.dataOut.data[i][k][j])
988 #input()
989 #print(self.dataOut.dc)
990 #input()
991 #aux_ac=0
992
993 #self.dataOut.flagNoData=0
994
995 for n in range(numpy.min((self.dataOut.NRANGE-j,self.dataOut.NLAG))):
996 #print(numpy.shape(self.dataOut.data))
997 #input()
998 #pass
999 #self.dataOut.flagNoData=1
1000 #c=2*buffer_aux
1001 c=(self.dataOut.data[i][k][j]-self.dataOut.dc[i])*(numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
1002 #c=(buffer[i][k][j]-buffer_dc)*(numpy.conj(buffer[i][k][j+n])-buffer_dc)
1003
1004
1005 #c=(buffer[i][k][j])*(buffer[i][k][j+n])
1006 #print("first: ",self.dataOut.data[i][k][j]-self.dataOut.dc[i])
1007 #print("second: ",numpy.conj(self.dataOut.data[i][k][j+n]-self.dataOut.dc[i]))
1008
1009 #print("c: ",c)
1010 #input()
1011 #print("n: ",n)
1012 #print("aux_ac",aux_ac)
1013 #print("data1:",self.dataOut.data[i][k][j])
1014 #print("data2:",self.dataOut.data[i][k][j+n])
1015 #print("dc: ",self.dataOut.dc[i])
1016 #if aux_ac==2:
1017 #input()
1018 #aux_ac+=1
1019 #print("GG")
1020 #print("inside n",n)
1021 #pass
1022
1023 if k<self.dataOut.NSCAN:
1024 if k==0:
1025 if i==0:
1026 self.lagp0[n][j][self.bcounter-1]=c
1027 elif i==1:
1028 self.lagp1[n][j][self.bcounter-1]=c
1029 elif i==2:
1030 self.lagp2[n][j][self.bcounter-1]=c
1031 else:
1032 if i==0:
1033 self.lagp0[n][j][self.bcounter-1]=c+self.lagp0[n][j][self.bcounter-1]
1034 elif i==1:
1035 self.lagp1[n][j][self.bcounter-1]=c+self.lagp1[n][j][self.bcounter-1]
1036 elif i==2:
1037 self.lagp2[n][j][self.bcounter-1]=c+self.lagp2[n][j][self.bcounter-1]
1038
1039 else:
1040 c=c/self.cnorm
1041 if k==self.dataOut.NSCAN:
1042 if i==0:
1043 self.lagp3[n][j][self.bcounter-1]=c
1044 #print("n: ",n,"j: ",j,"iavg: ",self.bcounter-1)
1045 #print("lagp3_inside: ",self.lagp3[n][j][self.bcounter-1])
1046 else:
1047 if i==0:
1048 self.lagp3[n][j][self.bcounter-1]=c+self.lagp3[n][j][self.bcounter-1]
1049
1050
1051
1052 #print("lagp2: ",self.lagp2[:,0,0])
1053
1054 #self.dataOut.flagNoData=0
1055 #print(self.bcounter-1)
1056 #print("lagp2_conj: ",self.lagp2[:,0,self.bcounter-1])
1057 #input()
1058 #self.dataOut.lagp3=self.lagp3
1059 print("LP")
1060
1061
1062 def LP_median_estimates(self):
1063 #print("lagp3: ",self.lagp3[:,0,0])
1064 #print("self.bcounter: ",self.bcounter)
1065 if self.dataOut.flag_save==1:
1066
1067 #print("lagp1: ",self.lagp1[0,0,:])
1068 #input()
1069
1070 if self.lag_products_LP_median_estimates_aux==0:
1071 self.output=numpy.zeros((self.dataOut.NLAG,self.dataOut.NRANGE,self.dataOut.NR),'complex64')
1072 #sorts=numpy.zeros(128,'float32')
1073 #self.dataOut.output_LP=None
1074 self.lag_products_LP_median_estimates_aux=1
1075
1076
1077 for i in range(self.dataOut.NLAG):
1078 for j in range(self.dataOut.NRANGE):
1079 for l in range(4): #four outputs
1080 '''
1081 for k in range(self.dataOut.NAVG):
1082 #rsorts[k]=float(k)
1083 if l==0:
1084 #sorts[k]=self.lagp0[i,j,k].real
1085 self.lagp0[i,j,k].real=sorted(self.lagp0[i,j,k].real)
1086 if l==1:
1087 #sorts[k]=self.lagp1[i,j,k].real
1088 self.lagp1[i,j,k].real=sorted(self.lagp1[i,j,k].real)
1089 if l==2:
1090 #sorts[k]=self.lagp2[i,j,k].real
1091 self.lagp2[i,j,k].real=sorted(self.lagp2[i,j,k].real)
1092 if l==3:
1093 #sorts[k]=self.lagp3[i,j,k].real
1094 self.lagp3[i,j,k].real=sorted(self.lagp3[i,j,k].real)
1095 '''
1096
1097 #sorts=sorted(sorts)
1098 #self.lagp0[i,j,k].real=sorted(self.lagp0[i,j,k].real)
1099 #self.lagp1[i,j,k].real=sorted(self.lagp1[i,j,k].real)
1100 #self.lagp2[i,j,k].real=sorted(self.lagp2[i,j,k].real)
1101 #self.lagp3[i,j,k].real=sorted(self.lagp3[i,j,k].real)
1102
1103 for k in range(self.dataOut.NAVG):
1104
1105
1106
1107 if k==0:
1108 self.output[i,j,l]=0.0+0.j
1109
1110 if l==0:
1111 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
1112
1113 if l==1:
1114 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
1115 if l==2:
1116 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
1117 if l==3:
1118 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
1119
1120
1121 if k>=self.dataOut.nkill/2 and k<self.dataOut.NAVG-self.dataOut.nkill/2:
1122 if l==0:
1123
1124 self.output[i,j,l]=self.output[i,j,l]+((float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill))*self.lagp0[i,j,k])
1125 if l==1:
1126 #print("lagp1: ",self.lagp1[0,0,:])
1127 #input()
1128 self.output[i,j,l]=self.output[i,j,l]+((float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill))*self.lagp1[i,j,k])
1129 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
1130 #input()
1131 if l==2:
1132 self.output[i,j,l]=self.output[i,j,l]+((float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill))*self.lagp2[i,j,k])
1133 if l==3:
1134 #print(numpy.shape(output))
1135 #print(numpy.shape(self.lagp3))
1136 #print("i: ",i,"j: ",j,"k: ",k)
1137
1138 #a=((float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill))*self.lagp3[i,j,k])
1139 #print("self.lagp3[i,j,k]: ",self.lagp3[i,j,k])
1140 #input()
1141 self.output[i,j,l]=self.output[i,j,l]+((float(self.dataOut.NAVG)/(float)(self.dataOut.NAVG-self.dataOut.nkill))*self.lagp3[i,j,k])
1142 #print(a)
1143 #print("output[i,j,l]: ",output[i,j,l])
1144 #input()
1145
1146
1147 self.dataOut.output_LP=self.output
1148 #print(numpy.shape(sefl.dataOut.output_LP))
1149 #input()
1150 #print("output: ",self.dataOut.output_LP[:,0,0])
1151 #input()
1152
1153
1154 def remove_debris_LP(self):
1155
1156 if self.dataOut.flag_save==1:
1157 debris=numpy.zeros(self.dataOut.NRANGE,'float32')
1158 #self.dataOut.debris_activated=0
1159 for j in range(0,3):
1160 for i in range(self.dataOut.NRANGE):
1161 if j==0:
1162 debris[i]=10*numpy.log10(numpy.abs(self.dataOut.output_LP[j,i,0]))
1163 else:
1164 debris[i]+=10*numpy.log10(numpy.abs(self.dataOut.output_LP[j,i,0]))
1165
1166 '''
1167 debris=10*numpy.log10(numpy.abs(self.dataOut.output_LP[0,:,0]))
1168
1169 for j in range(1,3):
1170 for i in range(self.dataOut.NRANGE):
1171 debris[i]+=debris[i]
1172 '''
1173
1174 thresh=8.0+4+4+4
1175 for i in range(47,100):
1176 if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])>
1177 ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+
1178 debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+
1179 thresh)):
1180
1181 self.dataOut.debris_activated=1
1182 #print("LP debris",i)
1183
1184
1185 #print("self.debris",debris)
1186
1187
1188 def remove_debris_DP(self):
1189
1190 if self.dataOut.flag_save==1:
1191 debris=numpy.zeros(self.dataOut.NDP,dtype='float32')
1192 Range=numpy.arange(0,3000,15)
1193 for k in range(2): #flip
1194 for i in range(self.dataOut.NDP): #
1195 debris[i]+=numpy.sqrt((self.dataOut.kaxbx[i,0,k]+self.dataOut.kayby[i,0,k])**2+(self.dataOut.kaybx[i,0,k]-self.dataOut.kaxby[i,0,k])**2)
1196
1197 #print("debris: ",debris)
1198
1199 if time.gmtime(self.dataOut.utctime).tm_hour > 11:
1200 for i in range(2,self.dataOut.NDP-2):
1201 if (debris[i]>3.0*debris[i-2] and
1202 debris[i]>3.0*debris[i+2] and
1203 Range[i]>200.0 and Range[i]<=540.0):
1204
1205 self.dataOut.debris_activated=1
1206 #print("DP debris")
1207
1208
1209
1210
1211
1212
1213 def run(self, experiment="", nlags_array=None, NLAG=None, NR=None, NRANGE=None, NCAL=None, DPL=None,
1214 NDN=None, NDT=None, NDP=None, NLP=None, NSCAN=None, HDR_SIZE=None, DH=15, H0=None, LPMASK=None,
1215 flags_array=None,
1216 NPROFILE1=None, NPROFILE2=None, NPROFILES=None, NPROFILE=None,
1217 lagind=None, lagfirst=None,
1218 nptsfftx1=None):
1219
1220 #self.dataOut.input_dat_type=input_dat_type
1221
1222 self.dataOut.experiment=experiment
1223
1224 #print(self.dataOut.experiment)
1225 self.dataOut.nlags_array=nlags_array
1226 self.dataOut.NLAG=NLAG
1227 self.dataOut.NR=NR
1228 self.dataOut.NRANGE=NRANGE
1229 #print(self.dataOut.NRANGE)
1230 self.dataOut.NCAL=NCAL
1231 self.dataOut.DPL=DPL
1232 self.dataOut.NDN=NDN
1233 self.dataOut.NDT=NDT
1234 self.dataOut.NDP=NDP
1235 self.dataOut.NLP=NLP
1236 self.dataOut.NSCAN=NSCAN
1237 self.dataOut.HDR_SIZE=HDR_SIZE
1238 self.dataOut.DH=float(DH)
1239 self.dataOut.H0=H0
1240 self.dataOut.LPMASK=LPMASK
1241 self.dataOut.flags_array=flags_array
1242
1243 self.dataOut.NPROFILE1=NPROFILE1
1244 self.dataOut.NPROFILE2=NPROFILE2
1245 self.dataOut.NPROFILES=NPROFILES
1246 self.dataOut.NPROFILE=NPROFILE
1247 self.dataOut.lagind=lagind
1248 self.dataOut.lagfirst=lagfirst
1249 self.dataOut.nptsfftx1=nptsfftx1
1250
1251
1252 self.dataOut.copy(self.dataIn)
1253 #print(self.dataOut.datatime)
1254 #print(self.dataOut.ippSeconds_general)
1255 #print("Data: ",numpy.shape(self.dataOut.data))
1256 #print("Data_after: ",self.dataOut.data[0,0,1])
1257 ## (4, 150, 334)
1258 #print(self.dataOut.channelIndexList)
1259
1260 #print(self.dataOut.timeInterval)
1261
1262 ###NEWWWWWWW
1263 self.dataOut.lat=-11.95
1264 self.dataOut.lon=-7687
1265 self.dataOut.debris_activated=0
1266
1267 #print(time.gmtime(self.dataOut.utctime).tm_hour)
1268 #print(numpy.shape(self.dataOut.heightList))
1269
1270
1271
1272 class NewData(Operation):
1273 def __init__(self, **kwargs):
1274
1275 Operation.__init__(self, **kwargs)
1276
1277
1278
1279
1280
1281 def run(self,dataOut):
1282
1283 #print("SHAPE",numpy.shape(dataOut.kaxby))
1284 print("CurrentBlock",dataOut.CurrentBlock)
1285 #print("DATAOUT",dataOut.kaxby)
1286 #print("TRUE OR FALSE",numpy.shape(dataOut.kaxby)==())
1287 #print("SHAPE",numpy.shape(dataOut.kaxby))
1288 if numpy.shape(dataOutF.kax)!=(): ############VER SI SE PUEDE TRABAJAR CON dataOut.kaxby==None ##Puede ser cualquier k...
1289
1290 print("NEWDATA",dataOut.kaxby)
1291
1292
1293
1294
1295
1296 return dataOut
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308 '''
1309
1310 class PlotVoltageLag(Operation):
1311 def __init__(self, **kwargs):
1312
1313 Operation.__init__(self, **kwargs)
1314
1315
1316
1317 self.kax=numpy.zeros((self.NDP,self.nlags_array,2),'float32')
1318 def range(self,DH):
1319 Range=numpy.arange(0,990,DH)
1320 return Range
1321
1322
1323
1324 def run(self,dataOut):
1325
1326
1327
1328 #plt.subplot(1, 4, 1)
1329 plt.plot(kax[:,0,0],Range,'r',linewidth=2.0)
1330 plt.xlim(min(limit_min_plot1[12::,0,0]), max(limit_max_plot1[12::,0,0]))
1331 plt.show()
1332
1333 self.kax=numpy.zeros((self.NDP,self.nlags_array,2),'float32')
1334
1335 return dataOut
1336 '''
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366 class Integration(Operation):
1367 def __init__(self, **kwargs):
1368
1369 Operation.__init__(self, **kwargs)
1370
1371
1372
1373 self.counter=0
1374 self.aux=0
1375 self.aux2=1
1376
1377 def run(self,dataOut,nint=None):
1378
1379 dataOut.nint=nint
1380 dataOut.AUX=0
1381 dataOut.paramInterval=dataOut.nint*dataOut.header[7][0]*2 #GENERALIZAR EL 2
1382 #print("CurrentBlock: ",dataOut.CurrentBlock)
1383 #print("date: ",dataOut.datatime)
1384 #print("self.aux: ",self.aux)
1385 #print("CurrentBlockAAAAAA: ",dataOut.CurrentBlock)
1386 #print(dataOut.input_dat_type)
1387 #print(dataOut.heightList)
1388
1389 #print(dataOut.blocktime.ctime())
1390 '''
1391 if dataOut.input_dat_type: #when .dat data is read
1392 #print(dataOut.realtime)
1393 #print("OKODOKO")
1394 #dataOut.flagNoData = False
1395 #print(dataOut.flagNoData)
1396 if self.aux2:
1397
1398 self.noise=numpy.zeros(dataOut.NR,'float32')
1399
1400
1401 padding=numpy.zeros(1,'int32')
1402
1403 hsize=numpy.zeros(1,'int32')
1404 bufsize=numpy.zeros(1,'int32')
1405 nr=numpy.zeros(1,'int32')
1406 ngates=numpy.zeros(1,'int32') ### ### ### 2
1407 time1=numpy.zeros(1,'uint64') # pos 3
1408 time2=numpy.zeros(1,'uint64') # pos 4
1409 lcounter=numpy.zeros(1,'int32')
1410 groups=numpy.zeros(1,'int32')
1411 system=numpy.zeros(4,'int8') # pos 7
1412 h0=numpy.zeros(1,'float32')
1413 dh=numpy.zeros(1,'float32')
1414 ipp=numpy.zeros(1,'float32')
1415 process=numpy.zeros(1,'int32')
1416 tx=numpy.zeros(1,'int32')
1417
1418 ngates1=numpy.zeros(1,'int32') ### ### ### 13
1419 time0=numpy.zeros(1,'uint64') # pos 14
1420 nlags=numpy.zeros(1,'int32')
1421 nlags1=numpy.zeros(1,'int32')
1422 txb=numpy.zeros(1,'float32') ### ### ### 17
1423 time3=numpy.zeros(1,'uint64') # pos 18
1424 time4=numpy.zeros(1,'uint64') # pos 19
1425 h0_=numpy.zeros(1,'float32')
1426 dh_=numpy.zeros(1,'float32')
1427 ipp_=numpy.zeros(1,'float32')
1428 txa_=numpy.zeros(1,'float32')
1429
1430 pad=numpy.zeros(100,'int32')
1431
1432 nbytes=numpy.zeros(1,'int32')
1433 limits=numpy.zeros(1,'int32')
1434 ngroups=numpy.zeros(1,'int32') ### ### ### 27
1435 #Make the header list
1436 #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]
1437 dataOut.header=[hsize,bufsize,nr,ngates,time1,time2,lcounter,groups,system,h0,dh,ipp,process,tx,ngates1,padding,time0,nlags,nlags1,padding,txb,time3,time4,h0_,dh_,ipp_,txa_,pad,nbytes,limits,padding,ngroups]
1438
1439
1440
1441 dataOut.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1442 dataOut.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1443 dataOut.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1444 dataOut.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1445 dataOut.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1446 dataOut.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1447 dataOut.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1448 dataOut.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1449 dataOut.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1450 dataOut.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1451 dataOut.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1452 dataOut.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1453 dataOut.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1454 dataOut.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1455
1456 self.dataOut.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby]
1457
1458 self.inputfile_DP = open(dataOut.fname,"rb")
1459
1460 ## read header the header first time
1461 for i in range(len(dataOut.header)):
1462 for j in range(len(dataOut.header[i])):
1463 #print("len(header[i]) ",len(header[i]))
1464 #input()
1465 temp=self.inputfile_DP.read(int(dataOut.header[i].itemsize))
1466 if isinstance(dataOut.header[i][0], numpy.int32):
1467 #print(struct.unpack('i', temp)[0])
1468 dataOut.header[i][0]=struct.unpack('i', temp)[0]
1469 if isinstance(dataOut.header[i][0], numpy.uint64):
1470 dataOut.header[i][0]=struct.unpack('q', temp)[0]
1471 if isinstance(dataOut.header[i][0], numpy.int8):
1472 dataOut.header[i][0]=struct.unpack('B', temp)[0]
1473 if isinstance(dataOut.header[i][0], numpy.float32):
1474 dataOut.header[i][0]=struct.unpack('f', temp)[0]
1475
1476
1477
1478
1479 self.activator_No_Data=1
1480
1481 self.inputfile_DP.seek(0,0)
1482
1483 #print("Repositioning to",self.npos," bytes, bufsize ", self.header[1][0])
1484 #self.inputfile.seek(self.npos, 0)
1485 #print("inputfile.tell() ",self.inputfile.tell() ," npos : ", self.npos)
1486
1487 self.npos=0
1488
1489 #if dataOut.nint < 0:
1490 # dataOut.nint=-dataOut.nint
1491 # sfile=os.stat(dataOut.fname)
1492 # if (os.path.exists(dataOut.fname)==0):
1493 # print("ERROR on STAT file: %s\n", dataOut.fname)
1494 # self.npos=sfile.st_size - dataOut.nint*dataOut.header[1][0]# sfile.st_size - nint*header.bufsize
1495
1496 self.start_another_day=False
1497 if dataOut.new_time_date!=" ":
1498 self.start_another_day=True
1499
1500
1501 if self.start_another_day:
1502 #print("Starting_at_another_day")
1503 #new_time_date = "16/08/2013 09:51:43"
1504 #new_time_seconds=time.mktime(time.strptime(new_time_date))
1505 #dataOut.new_time_date = "04/12/2019 09:21:21"
1506 d = datetime.strptime(dataOut.new_time_date, "%d/%m/%Y %H:%M:%S")
1507 new_time_seconds=time.mktime(d.timetuple())
1508
1509 d_2 = datetime.strptime(dataOut.new_ending_time, "%d/%m/%Y %H:%M:%S")
1510 self.new_ending_time_seconds=time.mktime(d_2.timetuple())
1511 #print("new_time_seconds: ",new_time_seconds)
1512 #input()
1513 jumper=0
1514
1515 #if jumper>0 and nint>0:
1516 while True:
1517 sfile=os.stat(dataOut.fname)
1518
1519 if (os.path.exists(dataOut.fname)==0):
1520 print("ERROR on STAT file: %s\n",dataOut.fname)
1521 self.npos=jumper*dataOut.nint*dataOut.header[1][0] #jump_blocks*header,bufsize
1522 self.npos_next=(jumper+1)*dataOut.nint*dataOut.header[1][0]
1523 self.inputfile_DP.seek(self.npos, 0)
1524 jumper+=1
1525 for i in range(len(dataOut.header)):
1526 for j in range(len(dataOut.header[i])):
1527 #print("len(header[i]) ",len(header[i]))
1528 #input()
1529 temp=self.inputfile_DP.read(int(dataOut.header[i].itemsize))
1530 if isinstance(dataOut.header[i][0], numpy.int32):
1531 #print(struct.unpack('i', temp)[0])
1532 dataOut.header[i][0]=struct.unpack('i', temp)[0]
1533 if isinstance(dataOut.header[i][0], numpy.uint64):
1534 dataOut.header[i][0]=struct.unpack('q', temp)[0]
1535 if isinstance(dataOut.header[i][0], numpy.int8):
1536 dataOut.header[i][0]=struct.unpack('B', temp)[0]
1537 if isinstance(dataOut.header[i][0], numpy.float32):
1538 dataOut.header[i][0]=struct.unpack('f', temp)[0]
1539
1540 if self.npos==0:
1541 if new_time_seconds<dataOut.header[4][0]:
1542 break
1543 #dataOut.flagNoData=1
1544 #return dataOut.flagNoData
1545
1546 self.npos_aux=sfile.st_size - dataOut.nint*dataOut.header[1][0]
1547 self.inputfile_DP.seek(self.npos_aux, 0)
1548
1549 for i in range(len(dataOut.header)):
1550 for j in range(len(dataOut.header[i])):
1551 #print("len(header[i]) ",len(header[i]))
1552 #input()
1553 temp=self.inputfile_DP.read(int(dataOut.header[i].itemsize))
1554 if isinstance(dataOut.header[i][0], numpy.int32):
1555 #print(struct.unpack('i', temp)[0])
1556 dataOut.header[i][0]=struct.unpack('i', temp)[0]
1557 if isinstance(dataOut.header[i][0], numpy.uint64):
1558 dataOut.header[i][0]=struct.unpack('q', temp)[0]
1559 if isinstance(dataOut.header[i][0], numpy.int8):
1560 dataOut.header[i][0]=struct.unpack('B', temp)[0]
1561 if isinstance(dataOut.header[i][0], numpy.float32):
1562 dataOut.header[i][0]=struct.unpack('f', temp)[0]
1563
1564 if new_time_seconds>dataOut.header[4][0]:
1565 print("No Data")
1566 self.inputfile_DP.close()
1567 sys.exit(1)
1568
1569 self.inputfile_DP.seek(self.npos, 0)
1570
1571
1572
1573
1574 if new_time_seconds==dataOut.header[4][0]:
1575 #print("EQUALS")
1576 break
1577
1578 self.inputfile_DP.seek(self.npos_next, 0)
1579
1580 for i in range(len(dataOut.header)):
1581 for j in range(len(dataOut.header[i])):
1582 #print("len(header[i]) ",len(header[i]))
1583 #input()
1584 temp=self.inputfile_DP.read(int(dataOut.header[i].itemsize))
1585 if isinstance(dataOut.header[i][0], numpy.int32):
1586 #print(struct.unpack('i', temp)[0])
1587 dataOut.header[i][0]=struct.unpack('i', temp)[0]
1588 if isinstance(dataOut.header[i][0], numpy.uint64):
1589 dataOut.header[i][0]=struct.unpack('q', temp)[0]
1590 if isinstance(dataOut.header[i][0], numpy.int8):
1591 dataOut.header[i][0]=struct.unpack('B', temp)[0]
1592 if isinstance(dataOut.header[i][0], numpy.float32):
1593 dataOut.header[i][0]=struct.unpack('f', temp)[0]
1594
1595
1596 if new_time_seconds<dataOut.header[4][0]:
1597 break
1598
1599
1600
1601
1602
1603
1604
1605
1606 #print("Repositioning to",self.npos," bytes, bufsize ", dataOut.header[1][0])
1607 self.inputfile_DP.seek(self.npos, 0)
1608 #print("inputfile.tell() ",self.inputfile_DP.tell() ," npos : ", self.npos)
1609
1610 self.aux2=0
1611
1612
1613 for ii in range(len(dataOut.header)):
1614 for j in range(len(dataOut.header[ii])):
1615 temp=self.inputfile_DP.read(int(dataOut.header[ii].itemsize))
1616
1617 if(b''==temp):# sizeof(header)
1618 dataOut.flagDiscontinuousBlock=1
1619 #print("EOF \n\n\n\n")
1620 #log.success("")
1621 #self.inputfile_DP.close()
1622 dataOut.error = True
1623 #dataOut.flagNoData = True
1624 #dataOut.stop=True
1625 #return dataOut
1626 #dataOut.
1627 return dataOut
1628
1629 #return dataOut.flagNoData
1630 #writedb_head()
1631 #outputfile.close()
1632 #sys.exit(0)
1633 #THE PROGRAM SHOULD END HERE
1634
1635 if isinstance(dataOut.header[ii][0], numpy.int32):
1636 #print(struct.unpack('i', temp)[0])
1637 dataOut.header[ii][0]=struct.unpack('i', temp)[0]
1638 if isinstance(dataOut.header[ii][0], numpy.uint64):
1639 dataOut.header[ii][0]=struct.unpack('q', temp)[0]
1640 if isinstance(dataOut.header[ii][0], numpy.int8):
1641 dataOut.header[ii][0]=struct.unpack('B', temp)[0]
1642 if isinstance(dataOut.header[ii][0], numpy.float32):
1643 dataOut.header[ii][0]=struct.unpack('f', temp)[0]
1644
1645
1646 if self.start_another_day:
1647
1648 if dataOut.header[4][0]>self.new_ending_time_seconds:
1649 print("EOF \n")
1650 if self.activator_No_Data:
1651 print("No Data")
1652 self.inputfile_DP.close()
1653 #sys.exit(0)
1654 dataOut.error = True
1655 return dataOut
1656 #print(self.activator_No_Data)
1657 self.activator_No_Data=0
1658 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1659 #dataOut.TimeBlockSeconds_for_dp_power=time.mktime(time.strptime(dataOut.TimeBlockDate_for_dp_power))
1660 dataOut.TimeBlockSeconds_for_dp_power = dataOut.header[4][0]-((dataOut.nint-1)*dataOut.NAVG*2)
1661 #print(dataOut.TimeBlockSeconds_for_dp_power)
1662 dataOut.TimeBlockDate_for_dp_power=datetime.fromtimestamp(dataOut.TimeBlockSeconds_for_dp_power).strftime("%a %b %-d %H:%M:%S %Y")
1663 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
1664 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
1665 dataOut.bd_time=time.gmtime(dataOut.TimeBlockSeconds_for_dp_power)
1666 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
1667 dataOut.ut=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
1668
1669
1670 if dataOut.experiment=="HP": # NRANGE*NLAG*NR # np.zeros([total_samples*nprofiles],dtype='complex64')
1671 temp=self.inputfile_DP.read(dataOut.NLAG*dataOut.NR*176*8)
1672 ii=0
1673 for l in range(dataOut.NLAG): #lag
1674 for r in range(dataOut.NR): # unflip and flip
1675 for k in range(176): #RANGE## generalizar
1676 struct.unpack('q', temp[ii:ii+8])[0]
1677 ii=ii+8
1678
1679
1680
1681 #print("A: ",dataOut.kax)
1682 for ind in range(len(self.dataOut.final_cross_products)): #final cross products
1683 temp=self.inputfile_DP.read(dataOut.DPL*2*dataOut.NDT*4) #*4 bytes
1684 ii=0
1685 #print("kabxys.shape ",kabxys.shape)
1686 #print(kabxys)
1687 for l in range(dataOut.DPL): #lag
1688 for fl in range(2): # unflip and flip
1689 for k in range(dataOut.NDT): #RANGE
1690 self.dataOut.final_cross_products[ind][k,l,fl]=struct.unpack('f', temp[ii:ii+4])[0]
1691 ii=ii+4
1692 #print("DPL*2*NDT*4 es: ", DPL*2*NDT*4)
1693 #print("B: ",dataOut.kax)
1694 ## read noise
1695 temp=self.inputfile_DP.read(dataOut.NR*4) #*4 bytes
1696 for ii in range(dataOut.NR):
1697 self.noise[ii]=struct.unpack('f', temp[ii*4:(ii+1)*4])[0]
1698 #print("NR*4 es: ", NR*4)
1699
1700
1701 ################################END input_dat_type################################
1702 '''
1703
1704 #if dataOut.input_dat_type==0:
1705
1706 if self.aux==1:
1707 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
1708 #print(dataOut.datatime)
1709 dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1710
1711 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
1712 dataOut.TimeBlockSeconds_for_dp_power=time.mktime(time.strptime(dataOut.TimeBlockDate_for_dp_power))
1713 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
1714 dataOut.bd_time=time.gmtime(dataOut.TimeBlockSeconds_for_dp_power)
1715 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
1716 dataOut.ut=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
1717 #print("date: ", dataOut.TimeBlockDate)
1718 self.aux=0
1719
1720 if numpy.shape(dataOut.kax)!=():
1721 #print("SELFCOUNTER",self.counter)
1722 #dataOut.flagNoData =True
1723 if self.counter==0:
1724 '''
1725 dataOut.kax_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1726 dataOut.kay_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1727 dataOut.kax2_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1728 dataOut.kay2_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1729 dataOut.kbx_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1730 dataOut.kby_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1731 dataOut.kbx2_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1732 dataOut.kby2_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1733 dataOut.kaxbx_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1734 dataOut.kaxby_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1735 dataOut.kaybx_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1736 dataOut.kayby_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1737 dataOut.kaxay_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1738 dataOut.kbxby_integrated=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1739 '''
1740
1741 tmpx=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0],2),'float32')
1742 dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx]
1743 #self.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby]
1744
1745 #print(numpy.shape(tmpx))
1746 if self.counter < dataOut.nint:
1747 #if dataOut.input_dat_type==0:
1748 dataOut.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby]
1749
1750 '''
1751 dataOut.kax_integrated=dataOut.kax_integrated+dataOut.kax
1752 dataOut.kay_integrated=dataOut.kay_integrated+dataOut.kay
1753 dataOut.kax2_integrated=dataOut.kax2_integrated+dataOut.kax2
1754 dataOut.kay2_integrated=dataOut.kay2_integrated+dataOut.kay2
1755 dataOut.kbx_integrated=dataOut.kbx_integrated+dataOut.kbx
1756 dataOut.kby_integrated=dataOut.kby_integrated+dataOut.kby
1757 dataOut.kbx2_integrated=dataOut.kbx2_integrated+dataOut.kbx2
1758 dataOut.kby2_integrated=dataOut.kby2_integrated+dataOut.kby2
1759 dataOut.kaxbx_integrated=dataOut.kaxbx_integrated+dataOut.kaxbx
1760 dataOut.kaxby_integrated=dataOut.kaxby_integrated+dataOut.kaxby
1761 dataOut.kaybx_integrated=dataOut.kaybx_integrated+dataOut.kaybx
1762 dataOut.kayby_integrated=dataOut.kayby_integrated+dataOut.kayby
1763 dataOut.kaxay_integrated=dataOut.kaxay_integrated+dataOut.kaxbx
1764 dataOut.kbxby_integrated=dataOut.kbxby_integrated+dataOut.kbxby
1765 #print("KAX_BEFORE: ",self.kax_integrated)
1766 '''
1767 #print("self.final_cross_products[0]: ",self.final_cross_products[0])
1768
1769 for ind in range(len(dataOut.kabxys_integrated)): #final cross products
1770 dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind]
1771 #print("ataOut.kabxys_integrated[0]: ",dataOut.kabxys_integrated[0])
1772
1773 self.counter+=1
1774 if self.counter==dataOut.nint-1:
1775 self.aux=1
1776 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1777 if self.counter==dataOut.nint:
1778
1779 #dataOut.flagNoData =False
1780
1781 self.counter=0
1782 dataOut.AUX=1
1783 #self.aux=1
1784 #print("KAXBY_INTEGRATED: ",dataOut.kaxby_integrated)
1785
1786 '''
1787 else :
1788 #dataOut.kax_integrated=self.kax_integrated
1789 self.counter=0
1790
1791
1792 #print("CurrentBlock: ", dataOut.CurrentBlock)
1793 print("KAX_INTEGRATED: ",self.kax_integrated)
1794 #print("nint: ",nint)
1795 '''
1796
1797 ##print("CurrentBlock: ", dataOut.CurrentBlock)
1798 ##print("KAX_INTEGRATED: ",dataOut.kax_integrated)
1799
1800
1801 return dataOut
1802
1803
1804
1805
1806
1807
1808
1809
1810 class SumLagProducts_Old(Operation):
1811 def __init__(self, **kwargs):
1812
1813 Operation.__init__(self, **kwargs)
1814 #dataOut.rnint2=numpy.zeros(dataOut.nlags_array,'float32')
1815
1816
1817 def run(self,dataOut):
1818
1819 if dataOut.AUX: #Solo cuando ya hizo la intregacion se ejecuta
1820
1821
1822 dataOut.rnint2=numpy.zeros(dataOut.header[17][0],'float32')
1823 #print(dataOut.experiment)
1824 if dataOut.experiment=="DP":
1825 for l in range(dataOut.header[17][0]):
1826 dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.header[7][0]*12.0)
1827
1828
1829 if dataOut.experiment=="HP":
1830 for l in range(dataOut.header[17][0]):
1831 if(l==0 or (l>=3 and l <=6)):
1832 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.header[7][0]*16.0)
1833 else:
1834 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.header[7][0]*8.0)
1835 #print(dataOut.rnint2)
1836 for l in range(dataOut.header[17][0]):
1837
1838 dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l]
1839 dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l]
1840 dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l]
1841 dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l]
1842
1843 dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l]
1844 dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l]
1845 dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l]
1846 dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l]
1847
1848
1849 #print("Final Integration: ",dataOut.kabxys_integrated[4][:,l,0])
1850
1851
1852
1853
1854
1855
1856 return dataOut
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866 class BadHeights_Old(Operation):
1867 def __init__(self, **kwargs):
1868
1869 Operation.__init__(self, **kwargs)
1870
1871
1872
1873 def run(self,dataOut):
1874
1875
1876 if dataOut.AUX==1:
1877 dataOut.ibad=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]),'int32')
1878
1879 for j in range(dataOut.header[15][0]):
1880 for l in range(dataOut.header[17][0]):
1881 ip1=j+dataOut.header[15][0]*(0+2*l)
1882 if( (dataOut.kabxys_integrated[5][j,l,0] <= 0.) or (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[7][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)):
1883 dataOut.ibad[j][l]=1
1884 else:
1885 dataOut.ibad[j][l]=0
1886 #print("ibad: ",dataOut.ibad)
1887
1888
1889
1890 return dataOut
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907 class NoisePower_old(Operation):
1908 def __init__(self, **kwargs):
1909
1910 Operation.__init__(self, **kwargs)
1911
1912 def hildebrand(self,dataOut,data):
1913 #print("data ",data )
1914 divider=10 # divider was originally 10
1915 noise=0.0
1916 n1=0
1917 n2=int(dataOut.header[15][0]/2)
1918 sorts= sorted(data)
1919
1920 nums_min= dataOut.header[15][0]/divider
1921 if((dataOut.header[15][0]/divider)> 2):
1922 nums_min= int(dataOut.header[15][0]/divider)
1923 else:
1924 nums_min=2
1925 sump=0.0
1926 sumq=0.0
1927 j=0
1928 cont=1
1929 while( (cont==1) and (j<n2)):
1930 sump+=sorts[j+n1]
1931 sumq+= sorts[j+n1]*sorts[j+n1]
1932 t3= sump/(j+1)
1933 j=j+1
1934 if(j> nums_min):
1935 rtest= float(j/(j-1)) +1.0/dataOut.header[7][0]
1936 t1= (sumq*j)
1937 t2=(rtest*sump*sump)
1938 if( (t1/t2) > 0.990):
1939 j=j-1
1940 sump-= sorts[j+n1]
1941 sumq-=sorts[j+n1]*sorts[j+n1]
1942 cont= 0
1943
1944 noise= sump/j
1945 stdv=numpy.sqrt((sumq- noise*noise)/(j-1))
1946 return noise
1947
1948 def run(self,dataOut):
1949
1950 if dataOut.AUX==1:
1951
1952 #print("ax2 shape ",ax2.shape)
1953 p=numpy.zeros((dataOut.header[2][0],dataOut.header[15][0],dataOut.header[17][0]),'float32')
1954 av=numpy.zeros(dataOut.header[15][0],'float32')
1955 dataOut.pnoise=numpy.zeros(dataOut.header[2][0],'float32')
1956
1957 p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip
1958 p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1
1959
1960 #print("p[0,:,:] ",p[0,:,:])
1961 #print("p[1,:,:] ",p[1,:,:])
1962
1963 for i in range(dataOut.header[2][0]):
1964 dataOut.pnoise[i]=0.0
1965 for k in range(dataOut.header[17][0]):
1966 dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k])
1967 #print("dpl ",k, "pnoise[",i,"] ",pnoise[i] )
1968 dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.header[17][0]
1969
1970
1971 #print("POWERNOISE: ",dataOut.pnoise)
1972 dataOut.pan=1.0*dataOut.pnoise[0] # weights could change
1973 dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change
1974 #print("dataOut.pan ",dataOut.pan, " dataOut.pbn ",dataOut.pbn)
1975 #print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAa")
1976
1977 #print("POWERNOISE: ",dataOut.pnoise)
1978
1979
1980 return dataOut
1981
1982
1983
1984
1985
1986
1987
1988
1989 class double_pulse_ACFs(Operation):
1990 def __init__(self, **kwargs):
1991
1992 Operation.__init__(self, **kwargs)
1993 self.aux=1
1994
1995 def run(self,dataOut):
1996 dataOut.pairsList=None
1997 if dataOut.AUX==1:
1998 dataOut.igcej=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]),'int32')
1999
2000 if self.aux==1:
2001 dataOut.rhor=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2002 dataOut.rhoi=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2003 dataOut.sdp=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2004 dataOut.sd=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2005 #dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.nlags_array),'int32')
2006 dataOut.p=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2007 dataOut.alag=numpy.zeros(dataOut.header[15][0],'float32')
2008 for l in range(dataOut.header[17][0]):
2009 dataOut.alag[l]=l*dataOut.header[10][0]*2.0/150.0
2010 self.aux=0
2011 sn4=dataOut.pan*dataOut.pbn
2012 rhorn=0
2013 rhoin=0
2014 #p=np.zeros((ndt,dpl), dtype=float)
2015 panrm=numpy.zeros((dataOut.header[15][0],dataOut.header[17][0]), dtype=float)
2016
2017
2018 for i in range(dataOut.header[15][0]):
2019 for j in range(dataOut.header[17][0]):
2020 ################# Total power
2021 pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0])
2022 pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0])
2023 #print("PA",pb)
2024 st4=pa*pb
2025 dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn)
2026 dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb))
2027 ## ACF
2028 rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0]
2029 rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0]
2030 if ((pa>dataOut.pan)&(pb>dataOut.pbn)):
2031 #print("dataOut.pnoise[0]: ",dataOut.pnoise[0])
2032 #print("dataOut.pnoise[1]: ",dataOut.pnoise[1])
2033 #print("OKKKKKKKKKKKKKKK")
2034 ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn))
2035 #print("ss4: ",ss4)
2036 #print("OKKKKKKKKKKKKKKK")
2037 panrm[i,j]=math.sqrt(ss4)
2038 rnorm=1/panrm[i,j]
2039 #print("rnorm: ",rnorm)get_number_density
2040 #print("OKKKKKKKKKKKKKKK")
2041
2042 ## ACF
2043 dataOut.rhor[i,j]=rhorp*rnorm
2044 dataOut.rhoi[i,j]=rhoip*rnorm
2045 #print("rhoi: ",dataOut.rhoi)
2046 #print("OKKKKKKKKKKKKKKK")
2047 ############# Compute standard error for ACF
2048 stoss4=st4/ss4
2049 snoss4=sn4/ss4
2050 rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4
2051 rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4
2052 rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j])
2053 st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4)))
2054 stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4)))
2055 dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j]
2056 dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j])
2057 #print("sd: ",dataOut.sd)
2058 #print("OKKKKKKKKKKKKKKK")
2059 else: #default values for bad points
2060 rnorm=1/math.sqrt(st4)
2061 dataOut.sd[i,j]=1.e30
2062 dataOut.ibad[i,j]=4
2063 dataOut.rhor[i,j]=rhorp*rnorm
2064 dataOut.rhoi[i,j]=rhoip*rnorm
2065 if ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)):
2066 dataOut.igcej[i,j]=1
2067
2068 #print("sdp",dataOut.sdp)
2069
2070 return dataOut
2071
2072
2073
2074
2075
2076
2077
2078 class faraday_angle_and_power_double_pulse(Operation):
2079 def __init__(self, **kwargs):
2080
2081 Operation.__init__(self, **kwargs)
2082 self.aux=1
2083
2084 def run(self,dataOut):
2085 #dataOut.NRANGE=NRANGE
2086 #dataOut.H0=H0
2087 ######### H0 Y NRANGE SON PARAMETROS?
2088
2089 if dataOut.AUX==1:
2090 if self.aux==1:
2091 dataOut.h2=numpy.zeros(dataOut.header[15][0],'float32')
2092 dataOut.range1=numpy.zeros(dataOut.header[15][0],order='F',dtype='float32')
2093 dataOut.sdn2=numpy.zeros(dataOut.header[15][0],'float32')
2094 dataOut.ph2=numpy.zeros(dataOut.header[15][0],'float32')
2095 dataOut.sdp2=numpy.zeros(dataOut.header[15][0],'float32')
2096 dataOut.ibd=numpy.zeros(dataOut.header[15][0],'float32')
2097 dataOut.phi=numpy.zeros(dataOut.header[15][0],'float32')
2098 self.aux=0
2099 #print("p: ",dataOut.p)
2100
2101
2102 for i in range(dataOut.header[15][0]):
2103 dataOut.range1[i]=dataOut.header[9][0] + i*dataOut.header[10][0] # (float) header.h0 + (float)i * header.dh
2104 dataOut.h2[i]=dataOut.range1[i]**2
2105
2106 #print("sd: ",dataOut.sd)
2107 #print("OIKKKKKKKKKKKKKKK")
2108 #print("ibad: ",dataOut.ibad)
2109 #print("igcej: ",dataOut.igcej)
2110 for j in range(dataOut.header[15][0]):
2111 dataOut.ph2[j]=0.
2112 dataOut.sdp2[j]=0.
2113 ri=dataOut.rhoi[j][0]/dataOut.sd[j][0]
2114 rr=dataOut.rhor[j][0]/dataOut.sd[j][0]
2115 dataOut.sdn2[j]=1./dataOut.sd[j][0]
2116 #print("sdn2: ",dataOut.sdn2)
2117 #print("OIKKKKKKKKKKKKKKK")
2118 pt=0.# // total power
2119 st=0.# // total signal
2120 ibt=0# // bad lags
2121 ns=0# // no. good lags
2122 for l in range(dataOut.header[17][0]):
2123 #add in other lags if outside of e-jet contamination
2124 if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ):
2125 #print("dataOut.p[j][l]: ",dataOut.p[j][l])
2126 dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l]
2127 dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l]
2128 ns+=1
2129
2130 pt+=dataOut.p[j][l]/dataOut.sdp[j][l]
2131 st+=1./dataOut.sdp[j][l]
2132 ibt|=dataOut.ibad[j][l];
2133 #print("pt: ",pt)
2134 #print("st: ",st)
2135 if(ns!= 0):
2136 dataOut.ibd[j]=0
2137 dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j]
2138 dataOut.sdp2[j]=1./dataOut.sdp2[j]
2139 else:
2140 dataOut.ibd[j]=ibt
2141 dataOut.ph2[j]=pt/st
2142 #print("ph2: ",dataOut.ph2)
2143 dataOut.sdp2[j]=1./st
2144 #print("ph2: ",dataOut.ph2)
2145 dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j]
2146 dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j]
2147 rr=rr/dataOut.sdn2[j]
2148 ri=ri/dataOut.sdn2[j]
2149 #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program
2150 dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri))
2151 if( (ri == 0.) and (rr == 0.) ):
2152 dataOut.phi[j]=0.
2153 else:
2154 dataOut.phi[j]=math.atan2( ri , rr )
2155
2156 #print("ph2: ",dataOut.ph2)
2157 #print("sdp2: ",dataOut.sdp2)
2158 #print("sdn2",dataOut.sdn2)
2159
2160
2161 return dataOut
2162
2163
2164
2165
2166
2167
2168 class get_number_density(Operation):
2169 def __init__(self, **kwargs):
2170
2171 Operation.__init__(self, **kwargs)
2172 self.aux=1
2173
2174 def run(self,dataOut,NSHTS=None,RATE=None):
2175 dataOut.NSHTS=NSHTS
2176 dataOut.RATE=RATE
2177 if dataOut.AUX==1:
2178 #dataOut.TimeBlockSeconds=time.mktime(time.strptime(dataOut.TimeBlockDate))
2179 #dataOut.bd_time=time.gmtime(dataOut.TimeBlockSeconds)
2180 #dataOut.ut=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
2181 if self.aux==1:
2182 dataOut.dphi=numpy.zeros(dataOut.header[15][0],'float32')
2183 dataOut.sdn1=numpy.zeros(dataOut.header[15][0],'float32')
2184 self.aux=0
2185 theta=numpy.zeros(dataOut.header[15][0],dtype=numpy.complex_)
2186 thetai=numpy.zeros(dataOut.header[15][0],dtype=numpy.complex_)
2187 # use complex numbers for phase
2188 for i in range(dataOut.NSHTS):
2189 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
2190 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
2191
2192 # differentiate and convert to number density
2193 ndphi=dataOut.NSHTS-4
2194 #print("dataOut.dphiBEFORE: ",dataOut.dphi)
2195 for i in range(2,dataOut.NSHTS-2):
2196 fact=(-0.5/(dataOut.RATE*dataOut.header[10][0]))*dataOut.bki[i]
2197 #four-point derivative, no phase unwrapping necessary
2198 dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
2199 #print("dataOut.dphi[i]AFTER: ",dataOut.dphi[i])
2200 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
2201 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
2202 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
2203 '''
2204 #print("date: ",dataOut.TimeBlockDate)
2205 #print("CurrentBlock: ", dataOut.CurrentBlock)
2206 #print("NSHTS: ",dataOut.NSHTS)
2207 print("phi: ",dataOut.phi)
2208 #print("header[10][0]: ",dataOut.DH)
2209 print("bkibki: ",dataOut.bki)
2210 #print("RATE: ",dataOut.RATE)
2211 print("sdn2: ",dataOut.sdn2)
2212 print("dphi: ",dataOut.dphi)
2213 print("sdn1: ",dataOut.sdn1)
2214 print("ph2: ",dataOut.ph2)
2215 print("sdp2: ",dataOut.sdp2)
2216 print("sdn1: ",dataOut.sdn1)
2217 '''
2218
2219 '''
2220 Al finallllllllllllllllllllllllllllllllllllllllllllllllllllllllll
2221 for i in range(dataOut.NSHTS):
2222 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
2223 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
2224 #print("dphi ",dphi)
2225 # threshold - values less than 10⁴
2226 for i in range(dataOut.NSHTS):
2227 if dataOut.ph2[i]<10000:
2228 dataOut.ph2[i]=10000
2229
2230 # threshold values more than 10⁷
2231 for i in range(dataOut.NSHTS):
2232 if dataOut.ph2[i]>10000000:#
2233 dataOut.ph2[i]=10000000
2234
2235 ## filter for errors
2236 for i in range(dataOut.NSHTS):
2237 if dataOut.sdp2[i]>100000:#
2238 dataOut.ph2[i]=10000
2239 '''
2240
2241
2242
2243
2244 return dataOut
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256 class normalize_dp_power2(Operation):
2257 def __init__(self, **kwargs):
2258
2259 Operation.__init__(self, **kwargs)
2260 self.aux=1
2261
2262 def normal(self,a,b,n,m):
2263 chmin=1.0e30
2264 chisq=numpy.zeros(150,'float32')
2265 temp=numpy.zeros(150,'float32')
2266
2267 for i in range(2*m-1):
2268 an=al=be=chisq[i]=0.0
2269 for j in range(int(n/m)):
2270 k=int(j+i*n/(2*m))
2271 if(a[k]>0.0 and b[k]>0.0):
2272 al+=a[k]*b[k]
2273 be+=b[k]*b[k]
2274
2275 if(be>0.0):
2276 temp[i]=al/be
2277 else:
2278 temp[i]=1.0
2279
2280 for j in range(int(n/m)):
2281 k=int(j+i*n/(2*m))
2282 if(a[k]>0.0 and b[k]>0.0):
2283 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
2284 an=an+1
2285
2286 if(chisq[i]>0.0):
2287 chisq[i]/=an
2288
2289
2290 for i in range(int(2*m-1)):
2291 if(chisq[i]<chmin and chisq[i]>1.0e-6):
2292 chmin=chisq[i]
2293 cf=temp[i]
2294 return cf
2295
2296
2297
2298 def run(self,dataOut,cut0=None,cut1=None):
2299 dataOut.cut0=float(cut0)
2300 dataOut.cut1=float(cut1)
2301 if dataOut.AUX==1:
2302 #print("dateBefore: ",dataOut.TimeBlockDate_for_dp_power)
2303 #print("dateNow: ",dataOut.TimeBlockDate)
2304 if self.aux==1:
2305 dataOut.cf=numpy.zeros(1,'float32')
2306 dataOut.cflast=numpy.zeros(1,'float32')
2307 self.aux=0
2308
2309 night_first=300.0
2310 night_first1= 310.0
2311 night_end= 450.0
2312 day_first=250.0
2313 day_end=400.0
2314 day_first_sunrise=190.0
2315 day_end_sunrise=280.0
2316
2317 if(dataOut.ut>4.0 and dataOut.ut<11.0): #early
2318 i2=(night_end-dataOut.range1[0])/dataOut.header[10][0]
2319 i1=(night_first -dataOut.range1[0])/dataOut.header[10][0]
2320 elif (dataOut.ut>0.0 and dataOut.ut<4.0): #night
2321 i2=(night_end-dataOut.range1[0])/dataOut.header[10][0]
2322 i1=(night_first1 -dataOut.range1[0])/dataOut.header[10][0]
2323 elif (dataOut.ut>=11.0 and dataOut.ut<13.5): #sunrise
2324 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.header[10][0]
2325 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.header[10][0]
2326 else:
2327 i2=(day_end-dataOut.range1[0])/dataOut.header[10][0]
2328 i1=(day_first -dataOut.range1[0])/dataOut.header[10][0]
2329
2330 i1=int(i1)
2331 i2=int(i2)
2332 #print("ph2: ",dataOut.ph2)
2333 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
2334
2335 #print("n in:",i1,"(",dataOut.range1[i1],"), i2=",i2,"(",dataOut.range1[i2],"), ut=",dataOut.ut,", cf=",dataOut.cf,", cf_last=",
2336 #dataOut.cflast)
2337 # in case of spread F, normalize much higher
2338 if(dataOut.cf<dataOut.cflast[0]/10.0):
2339 i1=(night_first1+100.-dataOut.range1[0])/dataOut.header[10][0]
2340 i2=(night_end+100.0-dataOut.range1[0])/dataOut.header[10][0]
2341 i1=int(i1)
2342 i2=int(i2)
2343 #print("normal over: ",i1,"(",dataOut.range1[i1],") ",i2,"(",dataOut.range1[i2],") => cf: ",dataOut.cf," cflast: ", dataOut.cflast)
2344 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
2345 dataOut.cf=dataOut.cflast[0]
2346
2347 #print(">>>i1=",i1,"(",dataOut.range1[i1],"), i2=",i2,"(",dataOut.range1[i2],"), ut=",dataOut.ut,", cf=",dataOut.cf,", cf_last=",
2348 # dataOut.cflast," (",dataOut.cf/dataOut.cflast,"), cut=",dataOut.cut0," ",dataOut.cut1)
2349 dataOut.cflast[0]=dataOut.cf
2350
2351 ## normalize double pulse power and error bars to Faraday
2352 for i in range(dataOut.NSHTS):
2353 dataOut.ph2[i]*=dataOut.cf
2354 dataOut.sdp2[i]*=dataOut.cf
2355 #print("******* correction factor: ",dataOut.cf)
2356
2357 #print(dataOut.ph2)
2358
2359 for i in range(dataOut.NSHTS):
2360 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
2361 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
2362 #print("dphi ",dphi)
2363 # threshold - values less than 10⁴
2364
2365 '''
2366 for i in range(dataOut.NSHTS):
2367 if dataOut.ph2[i]<10000:
2368 dataOut.ph2[i]=10000
2369
2370 # threshold values more than 10⁷
2371 for i in range(dataOut.NSHTS):
2372 if dataOut.ph2[i]>10000000:#
2373 dataOut.ph2[i]=10000000
2374
2375 ## filter for errors
2376 for i in range(dataOut.NSHTS):
2377 if dataOut.sdp2[i]>100000:#
2378 dataOut.ph2[i]=10000
2379 '''
2380
2381
2382
2383
2384
2385 '''
2386 #print("date: ",dataOut.TimeBlockDate)
2387 #print("CurrentBlock: ", dataOut.CurrentBlock)
2388 #print("NSHTS: ",dataOut.NSHTS)
2389 print("phi: ",dataOut.phi)
2390 #print("header[10][0]: ",dataOut.DH)
2391 print("bkibki: ",dataOut.bki)
2392 #print("RATE: ",dataOut.RATE)
2393 print("sdn2: ",dataOut.sdn2)
2394 print("dphi: ",dataOut.dphi)
2395 print("sdn1: ",dataOut.sdn1)
2396 print("ph2: ",dataOut.ph2)
2397 print("sdp2: ",dataOut.sdp2)
2398 print("sdn1: ",dataOut.sdn1)
2399 '''
2400
2401
2402
2403
2404
2405
2406
2407 return dataOut
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423 '''
2424 from ctypes import *
2425 class IDATE(Structure):
2426 _fields_ = [
2427 ("year", c_int),
2428 ("moda", c_int),
2429 ("hrmn", c_int),
2430 ("sec", c_int),
2431 ("secs", c_int),
2432 ]
2433 #typedef struct IDATE {int year,moda,hrmn,sec,secs;} idate;
2434 '''
2435
2436
2437
2438
2439 '''
2440 class get_number_density(Operation):
2441 def __init__(self, **kwargs):
2442
2443 Operation.__init__(self, **kwargs)
2444
2445 #self.aux=1
2446 '''
2447
2448 '''
2449 def IDATE(Structure):
2450
2451 _fields_ = [
2452 ("year", c_int),
2453 ("moda", c_int),
2454 ("hrmn", c_int),
2455 ("sec", c_int),
2456 ("secs", c_int),
2457 ]
2458
2459 '''
2460
2461
2462
2463
2464 '''
2465 def run(self,dataOut):
2466 '''
2467 '''
2468 if dataOut.CurrentBlock==1 and self.aux==1:
2469
2470 #print("CurrentBlock: ",dataOut.CurrentBlock)
2471
2472 dataOut.TimeBlockSeconds=time.mktime(time.strptime(dataOut.TimeBlockDate))
2473 #print("time1: ",dataOut.TimeBlockSeconds)
2474
2475 #print("date: ",dataOut.TimeBlockDate)
2476 dataOut.bd_time=time.gmtime(dataOut.TimeBlockSeconds)
2477 #print("bd_time: ",dataOut.bd_time)
2478 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
2479 #print("year: ",dataOut.year)
2480 dataOut.ut=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
2481 #print("ut: ",dataOut.ut)
2482 self.aux=0
2483
2484
2485
2486
2487 '''
2488 #print("CurrentBlock: ",dataOut.CurrentBlock)
2489 #print("date: ",dataOut.firsttime)
2490 #print("bd_time: ",time.strptime(dataOut.datatime.ctime()))
2491 #mkfact_short.mkfact(year,h,bfm,thb,bki,dataOut.NDP)
2492 #print("CurrentBlock: ",dataOut.CurrentBlock)
2493 '''
2494 if dataOut.AUX==1:
2495 '''
2496 '''
2497 #begin=IDATE()
2498 #begin.year=dataOut.bd_time.tm_year
2499 #begin.moda=100*(dataOut.bd_time.tm_mon)+dataOut.bd_time.tm_mday
2500 #begin.hrmn=100*dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min
2501 #begin.sec=dataOut.bd_time.tm_sec
2502 #begin.secs=dataOut.bd_time.tm_sec+60*(dataOut.bd_time.tm_min+60*(dataOut.bd_time.tm_hour+24*(dataOut.bd_time.tm_yday-1)))
2503 h=numpy.arange(0.0,15.0*dataOut.NDP,15.0,dtype='float32')
2504 bfm=numpy.zeros(dataOut.NDP,dtype='float32')
2505 bfm=numpy.array(bfm,order='F')
2506 thb=numpy.zeros(dataOut.NDP,dtype='float32')
2507 thb=numpy.array(thb,order='F')
2508 bki=numpy.zeros(dataOut.NDP,dtype='float32')
2509 bki=numpy.array(thb,order='F')
2510 #yearmanually=2019.9285714285713
2511 #print("year manually: ",yearmanually)
2512 #print("year: ",dataOut.year)
2513 mkfact_short.mkfact(dataOut.year,h,bfm,thb,bki,dataOut.NDP)
2514 #print("tm ",tm)
2515 '''
2516 '''
2517 print("year ",dataOut.year)
2518 print("h ", dataOut.h)
2519 print("bfm ", dataOut.bfm)
2520 print("thb ", dataOut.thb)
2521 print("bki ", dataOut.bki)
2522 '''
2523
2524
2525
2526
2527 '''
2528 print("CurrentBlock: ",dataOut.CurrentBlock)
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539 return dataOut
2540 '''
2541
2542
2543
2544
2545
2546
2547 class test(Operation):
2548 def __init__(self, **kwargs):
2549
2550 Operation.__init__(self, **kwargs)
2551
2552
2553
2554
2555 def run(self,dataOut,tt=10):
2556
2557 print("tt: ",tt)
2558
2559
2560
2561 return dataOut
@@ -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
This diff has been collapsed as it changes many lines, (5769 lines changed) Show them Hide them
@@ -4,8 +4,8 from scipy import interpolate
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 from schainpy.utils import log
6 from schainpy.utils import log
7 from time import time
7 from time import time, mktime, strptime, gmtime, ctime
8
8 import os
9
9
10
10
11 class VoltageProc(ProcessingUnit):
11 class VoltageProc(ProcessingUnit):
@@ -17,8 +17,12 class VoltageProc(ProcessingUnit):
17 self.dataOut = Voltage()
17 self.dataOut = Voltage()
18 self.flip = 1
18 self.flip = 1
19 self.setupReq = False
19 self.setupReq = False
20 #self.dataOut.test=1
21
20
22
21 def run(self):
23 def run(self):
24 #import time
25 #time.sleep(3)
22
26
23 if self.dataIn.type == 'AMISR':
27 if self.dataIn.type == 'AMISR':
24 self.__updateObjFromAmisrInput()
28 self.__updateObjFromAmisrInput()
@@ -26,6 +30,31 class VoltageProc(ProcessingUnit):
26 if self.dataIn.type == 'Voltage':
30 if self.dataIn.type == 'Voltage':
27 self.dataOut.copy(self.dataIn)
31 self.dataOut.copy(self.dataIn)
28
32
33
34 #self.dataOut.flagNoData=True
35 #print(self.dataOut.data[-1,:])
36 #print(ctime(self.dataOut.utctime))
37 #print(self.dataOut.heightList)
38 #print(self.dataOut.nHeights)
39 #exit(1)
40 #print(self.dataOut.data[6,:32])
41 #print(self.dataOut.data[0,320-5:320+5-5])
42 ##print(self.dataOut.heightList[-20:])
43 #print(numpy.shape(self.dataOut.data))
44 #print(self.dataOut.code)
45 #print(numpy.shape(self.dataOut.code))
46 #exit(1)
47 #print(self.dataOut.CurrentBlock)
48 #print(self.dataOut.data[0,:,0])
49
50 #print(numpy.shape(self.dataOut.data))
51 #print(self.dataOut.data[0,:,1666:1666+320])
52 #exit(1)
53
54 #print(self.dataOut.utctime)
55 #self.dataOut.test+=1
56
57
29 def __updateObjFromAmisrInput(self):
58 def __updateObjFromAmisrInput(self):
30
59
31 self.dataOut.timeZone = self.dataIn.timeZone
60 self.dataOut.timeZone = self.dataIn.timeZone
@@ -52,11 +81,13 class VoltageProc(ProcessingUnit):
52 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
81 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
53 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
82 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
54
83
55
56 class selectChannels(Operation):
84 class selectChannels(Operation):
57
85
58 def run(self, dataOut, channelList):
86 def run(self, dataOut, channelList):
59
87
88
89
90
60 channelIndexList = []
91 channelIndexList = []
61 self.dataOut = dataOut
92 self.dataOut = dataOut
62 for channel in channelList:
93 for channel in channelList:
@@ -66,8 +97,10 class selectChannels(Operation):
66 index = self.dataOut.channelList.index(channel)
97 index = self.dataOut.channelList.index(channel)
67 channelIndexList.append(index)
98 channelIndexList.append(index)
68 self.selectChannelsByIndex(channelIndexList)
99 self.selectChannelsByIndex(channelIndexList)
100
69 return self.dataOut
101 return self.dataOut
70
102
103
71 def selectChannelsByIndex(self, channelIndexList):
104 def selectChannelsByIndex(self, channelIndexList):
72 """
105 """
73 Selecciona un bloque de datos en base a canales segun el channelIndexList
106 Selecciona un bloque de datos en base a canales segun el channelIndexList
@@ -194,6 +227,8 class selectHeights(Operation):
194 maxIndex = len(heights)
227 maxIndex = len(heights)
195
228
196 self.selectHeightsByIndex(minIndex, maxIndex)
229 self.selectHeightsByIndex(minIndex, maxIndex)
230 #print(self.dataOut.nHeights)
231
197
232
198 return self.dataOut
233 return self.dataOut
199
234
@@ -318,11 +353,21 class setH0(Operation):
318
353
319
354
320 class deFlip(Operation):
355 class deFlip(Operation):
356 def __init__(self):
357
358 self.flip = 1
321
359
322 def run(self, dataOut, channelList = []):
360 def run(self, dataOut, channelList = []):
323
361
324 data = dataOut.data.copy()
362 data = dataOut.data.copy()
363 #print(dataOut.channelList)
364 #exit()
365
366 if channelList==1: #PARCHE
367 channelList=[1]
325
368
369
370 dataOut.FlipChannels=channelList
326 if dataOut.flagDataAsBlock:
371 if dataOut.flagDataAsBlock:
327 flip = self.flip
372 flip = self.flip
328 profileList = list(range(dataOut.nProfiles))
373 profileList = list(range(dataOut.nProfiles))
@@ -342,10 +387,15 class deFlip(Operation):
342
387
343 self.flip = flip
388 self.flip = flip
344
389
390
391
392
345 else:
393 else:
346 if not channelList:
394 if not channelList:
347 data[:,:] = data[:,:]*self.flip
395 data[:,:] = data[:,:]*self.flip
348 else:
396 else:
397 channelList=[1]
398 #print(self.flip)
349 for thisChannel in channelList:
399 for thisChannel in channelList:
350 if thisChannel not in dataOut.channelList:
400 if thisChannel not in dataOut.channelList:
351 continue
401 continue
@@ -354,6 +404,7 class deFlip(Operation):
354
404
355 self.flip *= -1.
405 self.flip *= -1.
356
406
407
357 dataOut.data = data
408 dataOut.data = data
358
409
359 return dataOut
410 return dataOut
@@ -418,879 +469,5459 class interpolateHeights(Operation):
418 return dataOut
469 return dataOut
419
470
420
471
421 class CohInt(Operation):
472 class LagsReshape(Operation):
473 """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction.
474
475 Parameters:
476 -----------
477
478
479 Example
480 --------
481
482 op = proc_unit.addOperation(name='LagsReshape')
422
483
423 isConfig = False
484
424 __profIndex = 0
485 """
425 __byTime = False
426 __initime = None
427 __lastdatatime = None
428 __integrationtime = None
429 __buffer = None
430 __bufferStride = []
431 __dataReady = False
432 __profIndexStride = 0
433 __dataToPutStride = False
434 n = None
435
486
436 def __init__(self, **kwargs):
487 def __init__(self, **kwargs):
437
488
438 Operation.__init__(self, **kwargs)
489 Operation.__init__(self, **kwargs)
439
490
440 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
491 self.buffer=None
441 """
492 self.buffer_HR=None
442 Set the parameters of the integration class.
493 self.buffer_HRonelag=None
443
494
444 Inputs:
495 def LagDistribution(self,dataOut):
445
496
446 n : Number of coherent integrations
497 dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:])
447 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
498 self.buffer = numpy.zeros((dataOut.nChannels,
448 overlapping :
499 int(dataOut.NSCAN/dataOut.DPL),
449 """
500 dataOut.nHeights,dataOut.DPL),
501 dtype='complex')
450
502
451 self.__initime = None
503 for j in range(int(self.buffer.shape[1]/2)):
452 self.__lastdatatime = 0
504 for i in range(dataOut.DPL):
453 self.__buffer = None
505 if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL:
454 self.__dataReady = False
506 self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:]
455 self.byblock = byblock
507 else:
456 self.stride = stride
508 self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:]
457
509
458 if n == None and timeInterval == None:
510 return self.buffer
459 raise ValueError("n or timeInterval should be specified ...")
460
511
461 if n != None:
512 def HeightReconstruction(self,dataOut):
462 self.n = n
463 self.__byTime = False
464 else:
465 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
466 self.n = 9999
467 self.__byTime = True
468
513
469 if overlapping:
514 self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
470 self.__withOverlapping = True
515 dataOut.nHeights,dataOut.DPL),
471 self.__buffer = None
516 dtype='complex')
472 else:
473 self.__withOverlapping = False
474 self.__buffer = 0
475
517
476 self.__profIndex = 0
518 #self.buffer_HR[0,:,:,:]=dataOut.datalags[0,:,:,:] #No Lags
477
519
478 def putData(self, data):
520 for i in range(int(dataOut.DPL)): #Only channel B
521 if i==0:
522 self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i]
523 else:
524 self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i)
479
525
480 """
526 return self.buffer_HR
481 Add a profile to the __buffer and increase in one the __profileIndex
482
527
483 """
484
528
485 if not self.__withOverlapping:
529 def HRonelag(self,dataOut,whichlag):
486 self.__buffer += data.copy()
530 self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
487 self.__profIndex += 1
531 dataOut.nHeights),
488 return
532 dtype='complex')
489
533
490 #Overlapping data
534 for i in range(self.buffer_HRonelag.shape[0]):
491 nChannels, nHeis = data.shape
535 for j in range(dataOut.nHeights):
492 data = numpy.reshape(data, (1, nChannels, nHeis))
536 if j+int(2*whichlag)<dataOut.nHeights:
537 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag]
538 else:
539 if whichlag!=10:
540 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1]
541 else:
542 if i+2<self.buffer_HRonelag.shape[0]:
543 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0]
544 else: #i+1==self.buffer_HRonelag.shape[0]:
545 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag]
493
546
494 #If the buffer is empty then it takes the data value
547 return self.buffer_HRonelag
495 if self.__buffer is None:
496 self.__buffer = data
497 self.__profIndex += 1
498 return
499
548
500 #If the buffer length is lower than n then stakcing the data value
501 if self.__profIndex < self.n:
502 self.__buffer = numpy.vstack((self.__buffer, data))
503 self.__profIndex += 1
504 return
505
549
506 #If the buffer length is equal to n then replacing the last buffer value with the data value
507 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
508 self.__buffer[self.n-1] = data
509 self.__profIndex = self.n
510 return
511
550
551 def run(self,dataOut,DPL=11,NSCAN=132):
512
552
513 def pushData(self):
553 dataOut.DPL=DPL
514 """
554 dataOut.NSCAN=NSCAN
515 Return the sum of the last profiles and the profiles used in the sum.
555 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
556 dataOut.lat=-11.95
557 dataOut.lon=-76.87
558 dataOut.datalags=None
559 #print(dataOut.NSCAN)
516
560
517 Affected:
561 dataOut.datalags=numpy.copy(self.LagDistribution(dataOut))
562 dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut)
518
563
519 self.__profileIndex
564 return dataOut
520
565
521 """
522
566
523 if not self.__withOverlapping:
524 data = self.__buffer
525 n = self.__profIndex
526
567
527 self.__buffer = 0
528 self.__profIndex = 0
529
568
530 return data, n
569 class CrossProdDP(Operation):
570 """Operation to calculate cross products of the Double Pulse Experiment.
571
572 Parameters:
573 -----------
574 NLAG : int
575 Number of lags Long Pulse.
576 NRANGE : int
577 Number of samples for Long Pulse.
578 NCAL : int
579 .*
580 DPL : int
581 Number of lags Double Pulse.
582 NDN : int
583 .*
584 NDT : int
585 Number of heights for Double Pulse.*
586 NDP : int
587 Number of heights for Double Pulse.*
588 NSCAN : int
589 Number of profiles when the transmitter is on.
590 flags_array : intlist
591 .*
592 NAVG : int
593 Number of blocks to be "averaged".
594 nkill : int
595 Number of blocks not to be considered when averaging.
596
597 Example
598 --------
599
600 op = proc_unit.addOperation(name='CrossProdDP', optype='other')
601 op.addParameter(name='NLAG', value='16', format='int')
602 op.addParameter(name='NRANGE', value='0', format='int')
603 op.addParameter(name='NCAL', value='0', format='int')
604 op.addParameter(name='DPL', value='11', format='int')
605 op.addParameter(name='NDN', value='0', format='int')
606 op.addParameter(name='NDT', value='66', format='int')
607 op.addParameter(name='NDP', value='66', format='int')
608 op.addParameter(name='NSCAN', value='132', format='int')
609 op.addParameter(name='flags_array', value='(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)', format='intlist')
610 op.addParameter(name='NAVG', value='16', format='int')
611 op.addParameter(name='nkill', value='6', format='int')
612
613 """
531
614
532 #Integration with Overlapping
615 def __init__(self, **kwargs):
533 data = numpy.sum(self.__buffer, axis=0)
534 # print data
535 # raise
536 n = self.__profIndex
537
616
538 return data, n
617 Operation.__init__(self, **kwargs)
618 self.bcounter=0
619 self.aux=1
620 self.lag_products_LP_median_estimates_aux=0
621
622 def set_header_output(self,dataOut):
623
624 dataOut.read_samples=len(dataOut.heightList)#int(dataOut.systemHeaderObj.nSamples/dataOut.windowOfFilter)
625 padding=numpy.zeros(1,'int32')
626 hsize=numpy.zeros(1,'int32')
627 bufsize=numpy.zeros(1,'int32')
628 nr=numpy.zeros(1,'int32')
629 ngates=numpy.zeros(1,'int32') ### ### ### 2
630 time1=numpy.zeros(1,'uint64') # pos 3
631 time2=numpy.zeros(1,'uint64') # pos 4
632 lcounter=numpy.zeros(1,'int32')
633 groups=numpy.zeros(1,'int32')
634 system=numpy.zeros(4,'int8') # pos 7
635 h0=numpy.zeros(1,'float32')
636 dh=numpy.zeros(1,'float32')
637 ipp=numpy.zeros(1,'float32')
638 process=numpy.zeros(1,'int32')
639 tx=numpy.zeros(1,'int32')
640 ngates1=numpy.zeros(1,'int32') ### ### ### 13
641 time0=numpy.zeros(1,'uint64') # pos 14
642 nlags=numpy.zeros(1,'int32')
643 nlags1=numpy.zeros(1,'int32')
644 txb=numpy.zeros(1,'float32') ### ### ### 17
645 time3=numpy.zeros(1,'uint64') # pos 18
646 time4=numpy.zeros(1,'uint64') # pos 19
647 h0_=numpy.zeros(1,'float32')
648 dh_=numpy.zeros(1,'float32')
649 ipp_=numpy.zeros(1,'float32')
650 txa_=numpy.zeros(1,'float32')
651 pad=numpy.zeros(100,'int32')
652 nbytes=numpy.zeros(1,'int32')
653 limits=numpy.zeros(1,'int32')
654 ngroups=numpy.zeros(1,'int32') ### ### ### 27
655
656 dataOut.header=[hsize,bufsize,nr,ngates,time1,time2,
657 lcounter,groups,system,h0,dh,ipp,
658 process,tx,ngates1,padding,time0,nlags,
659 nlags1,padding,txb,time3,time4,h0_,dh_,
660 ipp_,txa_,pad,nbytes,limits,padding,ngroups]
661
662
663 #dataOut.header[1][0]=81864
664 dataOut.FirstHeight=int(dataOut.heightList[0])
665 dataOut.MAXNRANGENDT=max(dataOut.NRANGE,dataOut.NDT)
666 dataOut.header[3][0]=max(dataOut.NRANGE,dataOut.NDT)
667 dataOut.header[7][0]=dataOut.NAVG
668 dataOut.header[9][0]=int(dataOut.heightList[0])
669 dataOut.header[10][0]=dataOut.DH
670 dataOut.header[17][0]=dataOut.DPL
671 dataOut.header[18][0]=dataOut.NLAG
672 #self.header[5][0]=0
673 dataOut.header[15][0]=dataOut.NDP
674 dataOut.header[2][0]=dataOut.NR
675
676
677 def get_products_cabxys(self,dataOut):
678
679 if self.aux==1:
680 self.set_header_output(dataOut)
681 self.aux=0
682
683
684 dataOut.lags_array=[x / dataOut.DH for x in dataOut.flags_array]
685 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
686 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
687 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
688 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
689 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
690 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
691 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
692 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
693 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
694 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
695 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
696 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
697 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
698 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
699
700 for i in range(2):
701 for j in range(dataOut.NDP):
702 for k in range(int(dataOut.NSCAN/2)):
703 n=k%dataOut.DPL
704 ax=dataOut.data[0,2*k+i,j].real
705 ay=dataOut.data[0,2*k+i,j].imag
706 if j+dataOut.lags_array[n]<dataOut.NDP:
707 bx=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].real
708 by=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].imag
709 else:
710 if k+1<int(dataOut.NSCAN/2):
711 bx=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
712 by=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
713
714 if k+1==int(dataOut.NSCAN/2):
715 bx=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
716 by=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
717
718 if(k<dataOut.DPL):
719 self.cax[j][n][i]=ax
720 self.cay[j][n][i]=ay
721 self.cbx[j][n][i]=bx
722 self.cby[j][n][i]=by
723 self.cax2[j][n][i]=ax*ax
724 self.cay2[j][n][i]=ay*ay
725 self.cbx2[j][n][i]=bx*bx
726 self.cby2[j][n][i]=by*by
727 self.caxbx[j][n][i]=ax*bx
728 self.caxby[j][n][i]=ax*by
729 self.caybx[j][n][i]=ay*bx
730 self.cayby[j][n][i]=ay*by
731 self.caxay[j][n][i]=ax*ay
732 self.cbxby[j][n][i]=bx*by
733 else:
734 self.cax[j][n][i]+=ax
735 self.cay[j][n][i]+=ay
736 self.cbx[j][n][i]+=bx
737 self.cby[j][n][i]+=by
738 self.cax2[j][n][i]+=ax*ax
739 self.cay2[j][n][i]+=ay*ay
740 self.cbx2[j][n][i]+=bx*bx
741 self.cby2[j][n][i]+=by*by
742 self.caxbx[j][n][i]+=ax*bx
743 self.caxby[j][n][i]+=ax*by
744 self.caybx[j][n][i]+=ay*bx
745 self.cayby[j][n][i]+=ay*by
746 self.caxay[j][n][i]+=ax*ay
747 self.cbxby[j][n][i]+=bx*by
748
749
750 def medi(self,data_navg,NAVG,nkill):
751 sorts=sorted(data_navg)
752 rsorts=numpy.arange(NAVG)
753 result=0.0
754 for k in range(NAVG):
755 if k>=nkill/2 and k<NAVG-nkill/2:
756 result+=sorts[k]*float(NAVG)/(float)(NAVG-nkill)
757 return result
758
759
760 def get_dc(self,dataOut):
761 if self.bcounter==0:
762 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
763 def cabxys_navg(self,dataOut):
764
765
766 #dataOut.header[5][0]=mktime(strptime(dataOut.TimeBlockDate))
767 dataOut.header[5][0]=dataOut.TimeBlockSeconds
768 #print(dataOut.TimeBlockDate)
769 #print(dataOut.utctime)
770 #print(dataOut.datatime)
771 #print(mktime(strptime(dataOut.TimeBlockDate)))
772 #print(dataOut.header[5][0])
773
774 #dataOut.LastAVGDate=mktime(strptime(dataOut.TimeBlockDate))
775 dataOut.LastAVGDate=dataOut.TimeBlockSeconds
776 #print(dataOut.TimeBlockDate)
777 #print(TimeBlockSeconds)
778 #input()
779 if self.bcounter==0:
780 #dataOut.FirstAVGDate=mktime(strptime(dataOut.TimeBlockDate))
781 dataOut.FirstAVGDate=dataOut.TimeBlockSeconds
782 dataOut.header[4][0]=dataOut.header[5][0]#firsttimeofNAVG
783 if dataOut.CurrentBlock==1:
784 #dataOut.FirstBlockDate=mktime(strptime(dataOut.TimeBlockDate))
785 dataOut.FirstBlockDate=dataOut.TimeBlockSeconds
786 dataOut.header[16][0]=dataOut.header[5][0]#FirsTimeOfTotalBlocks
787
788 self.cax_navg=[]
789 self.cay_navg=[]
790 self.cbx_navg=[]
791 self.cby_navg=[]
792 self.cax2_navg=[]
793 self.cay2_navg=[]
794 self.cbx2_navg=[]
795 self.cby2_navg=[]
796 self.caxbx_navg=[]
797 self.caxby_navg=[]
798 self.caybx_navg=[]
799 self.cayby_navg=[]
800 self.caxay_navg=[]
801 self.cbxby_navg=[]
802
803 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') #30/03/2020
804
805 dataOut.noisevector_=numpy.zeros((dataOut.read_samples,dataOut.NR,dataOut.NAVG),'float32')
806 #dataOut.dc=numpy.zeros(dataOut.NR,dtype=numpy.complex_) #30/03/2020
807 #self.dataOut.noisevector=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
808 #self.dataOut.noisevector_=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
809 #dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
810 #self.dataOut.dc=numpy.zeros(2,dtype=numpy.complex_) #31/03/2020
811 #self.dataOut.processingHeaderObj.profilesPerBlock
812
813 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
814
815 #print(self.dataOut.noisevector[:,:,:])
816
817 self.cax_navg.append(self.cax)
818 self.cay_navg.append(self.cay)
819 self.cbx_navg.append(self.cbx)
820 self.cby_navg.append(self.cby)
821 self.cax2_navg.append(self.cax2)
822 self.cay2_navg.append(self.cay2)
823 self.cbx2_navg.append(self.cbx2)
824 self.cby2_navg.append(self.cby2)
825 self.caxbx_navg.append(self.caxbx)
826 self.caxby_navg.append(self.caxby)
827 self.caybx_navg.append(self.caybx)
828 self.cayby_navg.append(self.cayby)
829 self.caxay_navg.append(self.caxay)
830 self.cbxby_navg.append(self.cbxby)
831 self.bcounter+=1
832
833 def noise_estimation4x_DP(self,dataOut):
834 if self.bcounter==dataOut.NAVG:
835 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
836 snoise=numpy.zeros((dataOut.NR,dataOut.NAVG),'float32')
837 nvector1=numpy.zeros((dataOut.NR,dataOut.NAVG,dataOut.MAXNRANGENDT),'float32')
838 for i in range(dataOut.NR):
839 dataOut.noise_final[i]=0.0
840 for k in range(dataOut.NAVG):
841 snoise[i][k]=0.0
842 for j in range(dataOut.MAXNRANGENDT):
843 nvector1[i][k][j]= dataOut.noisevector[j][i][k];
844 snoise[i][k]=self.noise_hs4x(dataOut.MAXNRANGENDT, nvector1[i][k])
845 #print("snoise",snoise[3,k])
846 dataOut.noise_final[i]=self.noise_hs4x(dataOut.NAVG, snoise[i])
847
848
849
850
851
852
853
854
855 def kabxys(self,dataOut):
856
857
858 #self.cabxys_navg(dataOut)
859
860
861 if self.bcounter==dataOut.NAVG:
862
863 dataOut.flagNoData = False
864
865
866 #dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') #30/03/2020
867 #self.dataOut.noise_final=numpy.zeros(2,'float32') #31/03/2020
868
869
870 self.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
871 self.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
872 self.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
873 self.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
874 self.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
875 self.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
876 self.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
877 self.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
878 self.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
879 self.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
880 self.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
881 self.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
882 self.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
883 self.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
884
885 for i in range(self.cax_navg[0].shape[0]):
886 for j in range(self.cax_navg[0].shape[1]):
887 for k in range(self.cax_navg[0].shape[2]):
888 data_navg=[item[i,j,k] for item in self.cax_navg]
889 self.kax[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
890 data_navg=[item[i,j,k] for item in self.cay_navg]
891 self.kay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
892 data_navg=[item[i,j,k] for item in self.cbx_navg]
893 self.kbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
894 data_navg=[item[i,j,k] for item in self.cby_navg]
895 self.kby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
896 data_navg=[item[i,j,k] for item in self.cax2_navg]
897 self.kax2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
898 data_navg=[item[i,j,k] for item in self.cay2_navg]
899 self.kay2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
900 data_navg=[item[i,j,k] for item in self.cbx2_navg]
901 self.kbx2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
902 data_navg=[item[i,j,k] for item in self.cby2_navg]
903 self.kby2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
904 data_navg=[item[i,j,k] for item in self.caxbx_navg]
905 self.kaxbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
906 data_navg=[item[i,j,k] for item in self.caxby_navg]
907 self.kaxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
908 data_navg=[item[i,j,k] for item in self.caybx_navg]
909 self.kaybx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
910 data_navg=[item[i,j,k] for item in self.cayby_navg]
911 self.kayby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
912 data_navg=[item[i,j,k] for item in self.caxay_navg]
913 self.kaxay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
914 data_navg=[item[i,j,k] for item in self.cbxby_navg]
915 self.kbxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
916
917
918 dataOut.kax=self.kax
919 dataOut.kay=self.kay
920 dataOut.kbx=self.kbx
921 dataOut.kby=self.kby
922 dataOut.kax2=self.kax2
923 dataOut.kay2=self.kay2
924 dataOut.kbx2=self.kbx2
925 dataOut.kby2=self.kby2
926 dataOut.kaxbx=self.kaxbx
927 dataOut.kaxby=self.kaxby
928 dataOut.kaybx=self.kaybx
929 dataOut.kayby=self.kayby
930 dataOut.kaxay=self.kaxay
931 dataOut.kbxby=self.kbxby
932
933 self.bcounter=0
934
935 dataOut.crossprods=numpy.zeros((3,4,numpy.shape(dataOut.kax)[0],numpy.shape(dataOut.kax)[1],numpy.shape(dataOut.kax)[2]))
936
937 dataOut.crossprods[0]=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby]
938 dataOut.crossprods[1]=[dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2]
939 dataOut.crossprods[2]=[dataOut.kaxay,dataOut.kbxby,dataOut.kaxbx,dataOut.kaxby]
940 #print("before: ",self.dataOut.noise_final)
941 dataOut.data_for_RTI_DP=numpy.zeros((3,dataOut.NDP))
942 dataOut.data_for_RTI_DP[0],dataOut.data_for_RTI_DP[1],dataOut.data_for_RTI_DP[2]=self.RTI_COLUMN(dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kayby,dataOut.kaybx,dataOut.kaxby, dataOut.NDP)
539
943
540 def byProfiles(self, data):
541
944
542 self.__dataReady = False
543 avgdata = None
544 # n = None
545 # print data
546 # raise
547 self.putData(data)
548
945
549 if self.__profIndex == self.n:
946 def RTI_COLUMN(self,kax2,kay2,kbx2,kby2,kaxbx,kayby,kaybx,kaxby, NDP):
550 avgdata, n = self.pushData()
947 x00=numpy.zeros(NDP,dtype='float32')
551 self.__dataReady = True
948 x01=numpy.zeros(NDP,dtype='float32')
949 x02=numpy.zeros(NDP,dtype='float32')
950 for j in range(2):# first couple lags
951 for k in range(2): #flip
952 for i in range(NDP): #
953 fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
954 x00[i]=x00[i]+(kax2[i,j,k]+kay2[i,j,k])
955 x01[i]=x01[i]+(kbx2[i,j,k]+kby2[i,j,k])
956 x02[i]=x02[i]+fx
957
958 x00[i]=10.0*numpy.log10(x00[i]/4.)
959 x01[i]=10.0*numpy.log10(x01[i]/4.)
960 x02[i]=10.0*numpy.log10(x02[i])
961 return x02,x00,x01
962
963
964
965
966
967
968 #30/03/2020:
969 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
970
971 rnormalizer= 1./(float(nProfiles - NSCAN))
972 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
973 for i in range(NR):
974 for j in range(MAXNRANGENDT):
975 for k in range(NSCAN,nProfiles):
976 #TODO:integrate just 2nd quartile gates
977 if k==NSCAN:
978 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
979 else:
980 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
981
982
983
984
985 def noise_hs4x(self, ndatax, datax):
986 divider=10#divider was originally 10
987 noise=0.0
988 data=numpy.zeros(ndatax,'float32')
989 ndata1=int(ndatax/4)
990 ndata2=int(2.5*(ndatax/4.))
991 ndata=int(ndata2-ndata1)
992 sorts=sorted(datax)
993
994 for k in range(ndata2): # select just second quartile
995 data[k]=sorts[k+ndata1]
996 nums_min= int(ndata/divider)
997 if(int(ndata/divider)> 2):
998 nums_min= int(ndata/divider)
999 else:
1000 nums_min=2
1001 sump=0.0
1002 sumq=0.0
1003 j=0
1004 cont=1
1005 while ( (cont==1) and (j<ndata)):
1006 sump+=data[j]
1007 sumq+= data[j]*data[j]
1008 j=j+1
1009 if (j> nums_min):
1010 rtest= float(j/(j-1)) +1.0/ndata
1011 if( (sumq*j) > (rtest*sump*sump ) ):
1012 j=j-1
1013 sump-= data[j]
1014 sumq-=data[j]*data[j]
1015 cont= 0
1016 noise= (sump/j)
1017
1018 return noise
1019
1020
1021
1022 def run(self, dataOut, NLAG=16, NRANGE=0, NCAL=0, DPL=11,
1023 NDN=0, NDT=66, NDP=66, NSCAN=132,
1024 flags_array=(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300), NAVG=16, nkill=6, **kwargs):
1025
1026 dataOut.NLAG=NLAG
1027 dataOut.NR=len(dataOut.channelList)
1028 dataOut.NRANGE=NRANGE
1029 dataOut.NCAL=NCAL
1030 dataOut.DPL=DPL
1031 dataOut.NDN=NDN
1032 dataOut.NDT=NDT
1033 dataOut.NDP=NDP
1034 dataOut.NSCAN=NSCAN
1035 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
1036 dataOut.H0=int(dataOut.heightList[0])
1037 dataOut.flags_array=flags_array
1038 dataOut.NAVG=NAVG
1039 dataOut.nkill=nkill
1040 dataOut.flagNoData = True
1041
1042 self.get_dc(dataOut)
1043 self.get_products_cabxys(dataOut)
1044 self.cabxys_navg(dataOut)
1045 self.noise_estimation4x_DP(dataOut)
1046 self.kabxys(dataOut)
552
1047
553 return avgdata
1048 return dataOut
554
1049
555 def byTime(self, data, datatime):
556
1050
557 self.__dataReady = False
558 avgdata = None
559 n = None
560
1051
561 self.putData(data)
1052 class IntegrationDP(Operation):
1053 """Operation to integrate the Double Pulse data.
562
1054
563 if (datatime - self.__initime) >= self.__integrationtime:
1055 Parameters:
564 avgdata, n = self.pushData()
1056 -----------
565 self.n = n
1057 nint : int
566 self.__dataReady = True
1058 Number of integrations.
567
1059
568 return avgdata
1060 Example
1061 --------
569
1062
570 def integrateByStride(self, data, datatime):
1063 op = proc_unit.addOperation(name='IntegrationDP', optype='other')
571 # print data
1064 op.addParameter(name='nint', value='30', format='int')
572 if self.__profIndex == 0:
573 self.__buffer = [[data.copy(), datatime]]
574 else:
575 self.__buffer.append([data.copy(),datatime])
576 self.__profIndex += 1
577 self.__dataReady = False
578
1065
579 if self.__profIndex == self.n * self.stride :
1066 """
580 self.__dataToPutStride = True
581 self.__profIndexStride = 0
582 self.__profIndex = 0
583 self.__bufferStride = []
584 for i in range(self.stride):
585 current = self.__buffer[i::self.stride]
586 data = numpy.sum([t[0] for t in current], axis=0)
587 avgdatatime = numpy.average([t[1] for t in current])
588 # print data
589 self.__bufferStride.append((data, avgdatatime))
590
1067
591 if self.__dataToPutStride:
1068 def __init__(self, **kwargs):
592 self.__dataReady = True
593 self.__profIndexStride += 1
594 if self.__profIndexStride == self.stride:
595 self.__dataToPutStride = False
596 # print self.__bufferStride[self.__profIndexStride - 1]
597 # raise
598 return self.__bufferStride[self.__profIndexStride - 1]
599
1069
1070 Operation.__init__(self, **kwargs)
600
1071
601 return None, None
1072 self.counter=0
1073 self.aux=0
1074 self.init_time=None
602
1075
603 def integrate(self, data, datatime=None):
1076 def integration_for_double_pulse(self,dataOut):
1077 #print("inside")
1078 #print(self.aux)
1079 if self.aux==1:
1080 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
1081 #print(dataOut.datatime)
604
1082
605 if self.__initime == None:
1083 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
606 self.__initime = datatime
1084 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
1085 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
607
1086
608 if self.__byTime:
1087 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
609 avgdata = self.byTime(data, datatime)
1088 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
610 else:
1089 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
611 avgdata = self.byProfiles(data)
1090 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
1091 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
1092 #print(dataOut.bd_time)
1093 #exit()
1094 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
1095 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
1096 #print("date: ", dataOut.TimeBlockDate)
612
1097
613
1098
614 self.__lastdatatime = datatime
1099 self.aux=0
615
1100
616 if avgdata is None:
1101 #print("after")
617 return None, None
618
1102
619 avgdatatime = self.__initime
1103 if self.counter==0:
620
1104
621 deltatime = datatime - self.__lastdatatime
1105 tmpx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1106 dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx]
1107 self.init_time=dataOut.utctime
622
1108
623 if not self.__withOverlapping:
1109 if self.counter < dataOut.nint:
624 self.__initime = datatime
1110 #print("HERE")
625 else:
626 self.__initime += deltatime
627
1111
628 return avgdata, avgdatatime
1112 dataOut.final_cross_products=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby,dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kaxby,dataOut.kaybx,dataOut.kayby,dataOut.kaxay,dataOut.kbxby]
629
1113
630 def integrateByBlock(self, dataOut):
1114 for ind in range(len(dataOut.kabxys_integrated)): #final cross products
1115 dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind]
631
1116
632 times = int(dataOut.data.shape[1]/self.n)
1117 self.counter+=1
633 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
634
1118
635 id_min = 0
1119 if self.counter==dataOut.nint-1:
636 id_max = self.n
1120 self.aux=1
1121 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1122 if self.counter==dataOut.nint:
637
1123
638 for i in range(times):
1124 dataOut.flagNoData=False
639 junk = dataOut.data[:,id_min:id_max,:]
1125 dataOut.utctime=self.init_time
640 avgdata[:,i,:] = junk.sum(axis=1)
1126 self.counter=0
641 id_min += self.n
642 id_max += self.n
643
1127
644 timeInterval = dataOut.ippSeconds*self.n
645 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
646 self.__dataReady = True
647 return avgdata, avgdatatime
648
1128
649 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
1129 def run(self,dataOut,nint=20):
650
1130
651 if not self.isConfig:
1131 dataOut.flagNoData=True
652 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
1132 dataOut.nint=nint
653 self.isConfig = True
1133 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
1134 dataOut.lat=-11.95
1135 dataOut.lon=-76.87
654
1136
655 if dataOut.flagDataAsBlock:
1137 self.integration_for_double_pulse(dataOut)
656 """
657 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
658 """
659 avgdata, avgdatatime = self.integrateByBlock(dataOut)
660 dataOut.nProfiles /= self.n
661 else:
662 if stride is None:
663 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
664 else:
665 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
666
1138
1139 return dataOut
667
1140
668 # dataOut.timeInterval *= n
669 dataOut.flagNoData = True
670
1141
671 if self.__dataReady:
1142 class SumFlips(Operation):
672 dataOut.data = avgdata
1143 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
673 if not dataOut.flagCohInt:
674 dataOut.nCohInt *= self.n
675 dataOut.flagCohInt = True
676 dataOut.utctime = avgdatatime
677 # print avgdata, avgdatatime
678 # raise
679 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
680 dataOut.flagNoData = False
681 return dataOut
682
1144
683 class Decoder(Operation):
1145 Parameters:
1146 -----------
1147 None
684
1148
685 isConfig = False
1149 Example
686 __profIndex = 0
1150 --------
687
1151
688 code = None
1152 op = proc_unit.addOperation(name='SumFlips', optype='other')
689
1153
690 nCode = None
1154 """
691 nBaud = None
692
1155
693 def __init__(self, **kwargs):
1156 def __init__(self, **kwargs):
694
1157
695 Operation.__init__(self, **kwargs)
1158 Operation.__init__(self, **kwargs)
696
1159
697 self.times = None
698 self.osamp = None
699 # self.__setValues = False
700 self.isConfig = False
701 self.setupReq = False
702 def setup(self, code, osamp, dataOut):
703
1160
704 self.__profIndex = 0
1161 def rint2DP(self,dataOut):
705
1162
706 self.code = code
1163 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
707
1164
708 self.nCode = len(code)
1165 for l in range(dataOut.DPL):
709 self.nBaud = len(code[0])
710
1166
711 if (osamp != None) and (osamp >1):
1167 dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.NAVG*12.0)
712 self.osamp = osamp
713 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
714 self.nBaud = self.nBaud*self.osamp
715
1168
716 self.__nChannels = dataOut.nChannels
717 self.__nProfiles = dataOut.nProfiles
718 self.__nHeis = dataOut.nHeights
719
1169
720 if self.__nHeis < self.nBaud:
1170 def SumLags(self,dataOut):
721 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
722
1171
723 #Frequency
1172 for l in range(dataOut.DPL):
724 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
725
1173
726 __codeBuffer[:,0:self.nBaud] = self.code
1174 dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l]
1175 dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l]
1176 dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l]
1177 dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l]
727
1178
728 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
1179 dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l]
1180 dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l]
1181 dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l]
1182 dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l]
729
1183
730 if dataOut.flagDataAsBlock:
731
1184
732 self.ndatadec = self.__nHeis #- self.nBaud + 1
1185 def run(self,dataOut):
733
1186
734 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
1187 self.rint2DP(dataOut)
1188 self.SumLags(dataOut)
735
1189
736 else:
1190 return dataOut
737
1191
738 #Time
739 self.ndatadec = self.__nHeis #- self.nBaud + 1
740
1192
741 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
1193 class FlagBadHeights(Operation):
1194 """Operation to flag bad heights (bad data) of the Double Pulse.
742
1195
743 def __convolutionInFreq(self, data):
1196 Parameters:
1197 -----------
1198 None
744
1199
745 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
1200 Example
1201 --------
746
1202
747 fft_data = numpy.fft.fft(data, axis=1)
1203 op = proc_unit.addOperation(name='FlagBadHeights', optype='other')
748
1204
749 conv = fft_data*fft_code
1205 """
750
1206
751 data = numpy.fft.ifft(conv,axis=1)
1207 def __init__(self, **kwargs):
752
1208
753 return data
1209 Operation.__init__(self, **kwargs)
754
1210
755 def __convolutionInFreqOpt(self, data):
1211 def run(self,dataOut):
756
1212
757 raise NotImplementedError
1213 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
758
1214
759 def __convolutionInTime(self, data):
1215 for j in range(dataOut.NDP):
1216 for l in range(dataOut.DPL):
1217 ip1=j+dataOut.NDP*(0+2*l)
760
1218
761 code = self.code[self.__profIndex]
1219 if( (dataOut.kabxys_integrated[5][j,l,0] <= 0.) or (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[7][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)):
762 for i in range(self.__nChannels):
1220 dataOut.ibad[j][l]=1
763 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
1221 else:
1222 dataOut.ibad[j][l]=0
764
1223
765 return self.datadecTime
1224 return dataOut
766
1225
767 def __convolutionByBlockInTime(self, data):
1226 class FlagBadHeightsSpectra(Operation):
1227 """Operation to flag bad heights (bad data) of the Double Pulse.
768
1228
769 repetitions = int(self.__nProfiles / self.nCode)
1229 Parameters:
770 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
1230 -----------
771 junk = junk.flatten()
1231 None
772 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
773 profilesList = range(self.__nProfiles)
774
1232
775 for i in range(self.__nChannels):
1233 Example
776 for j in profilesList:
1234 --------
777 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
778 return self.datadecTime
779
1235
780 def __convolutionByBlockInFreq(self, data):
1236 op = proc_unit.addOperation(name='FlagBadHeightsSpectra', optype='other')
781
1237
782 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
1238 """
783
1239
1240 def __init__(self, **kwargs):
784
1241
785 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
1242 Operation.__init__(self, **kwargs)
786
1243
787 fft_data = numpy.fft.fft(data, axis=2)
1244 def run(self,dataOut):
788
1245
789 conv = fft_data*fft_code
1246 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
790
1247
791 data = numpy.fft.ifft(conv,axis=2)
1248 for j in range(dataOut.NDP):
1249 for l in range(dataOut.DPL):
1250 ip1=j+dataOut.NDP*(0+2*l)
792
1251
793 return data
1252 if( (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)):
1253 dataOut.ibad[j][l]=1
1254 else:
1255 dataOut.ibad[j][l]=0
794
1256
1257 return dataOut
795
1258
796 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
1259 class NoisePower(Operation):
1260 """Operation to get noise power from the integrated data of the Double Pulse.
797
1261
798 if dataOut.flagDecodeData:
1262 Parameters:
799 print("This data is already decoded, recoding again ...")
1263 -----------
1264 None
800
1265
801 if not self.isConfig:
1266 Example
1267 --------
802
1268
803 if code is None:
1269 op = proc_unit.addOperation(name='NoisePower', optype='other')
804 if dataOut.code is None:
805 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
806
1270
807 code = dataOut.code
1271 """
1272
1273 def __init__(self, **kwargs):
1274
1275 Operation.__init__(self, **kwargs)
1276
1277 def hildebrand(self,dataOut,data):
1278
1279 divider=10 # divider was originally 10
1280 noise=0.0
1281 n1=0
1282 n2=int(dataOut.NDP/2)
1283 sorts= sorted(data)
1284 nums_min= dataOut.NDP/divider
1285 if((dataOut.NDP/divider)> 2):
1286 nums_min= int(dataOut.NDP/divider)
1287
1288 else:
1289 nums_min=2
1290 sump=0.0
1291 sumq=0.0
1292 j=0
1293 cont=1
1294 while( (cont==1) and (j<n2)):
1295 sump+=sorts[j+n1]
1296 sumq+= sorts[j+n1]*sorts[j+n1]
1297 t3= sump/(j+1)
1298 j=j+1
1299 if(j> nums_min):
1300 rtest= float(j/(j-1)) +1.0/dataOut.NAVG
1301 t1= (sumq*j)
1302 t2=(rtest*sump*sump)
1303 if( (t1/t2) > 0.990):
1304 j=j-1
1305 sump-= sorts[j+n1]
1306 sumq-=sorts[j+n1]*sorts[j+n1]
1307 cont= 0
1308
1309 noise= sump/j
1310 stdv=numpy.sqrt((sumq- noise*noise)/(j-1))
1311 return noise
1312
1313 def run(self,dataOut):
1314
1315 p=numpy.zeros((dataOut.NR,dataOut.NDP,dataOut.DPL),'float32')
1316 av=numpy.zeros(dataOut.NDP,'float32')
1317 dataOut.pnoise=numpy.zeros(dataOut.NR,'float32')
1318
1319 p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip
1320 p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1
1321
1322 for i in range(dataOut.NR):
1323 dataOut.pnoise[i]=0.0
1324 for k in range(dataOut.DPL):
1325 dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k])
1326
1327 dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.DPL
1328
1329
1330 dataOut.pan=1.0*dataOut.pnoise[0] # weights could change
1331 dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change
1332
1333 return dataOut
1334
1335
1336 class DoublePulseACFs(Operation):
1337 """Operation to get the ACFs of the Double Pulse.
1338
1339 Parameters:
1340 -----------
1341 None
1342
1343 Example
1344 --------
1345
1346 op = proc_unit.addOperation(name='DoublePulseACFs', optype='other')
1347
1348 """
1349
1350 def __init__(self, **kwargs):
1351
1352 Operation.__init__(self, **kwargs)
1353 self.aux=1
1354
1355 def run(self,dataOut):
1356
1357 dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1358
1359 if self.aux==1:
1360 dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1361 dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1362 dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1363 dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1364 dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1365 dataOut.alag=numpy.zeros(dataOut.NDP,'float32')
1366 for l in range(dataOut.DPL):
1367 dataOut.alag[l]=l*dataOut.DH*2.0/150.0
1368 self.aux=0
1369 sn4=dataOut.pan*dataOut.pbn
1370 rhorn=0
1371 rhoin=0
1372 panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1373
1374 for i in range(dataOut.NDP):
1375 for j in range(dataOut.DPL):
1376 ################# Total power
1377 pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0])
1378 pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0])
1379 st4=pa*pb
1380 dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn)
1381 dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb))
1382 ## ACF
1383 rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0]
1384 rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0]
1385 if ((pa>dataOut.pan)&(pb>dataOut.pbn)):
1386
1387 ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn))
1388 panrm[i,j]=math.sqrt(ss4)
1389 rnorm=1/panrm[i,j]
1390 ## ACF
1391 dataOut.rhor[i,j]=rhorp*rnorm
1392 dataOut.rhoi[i,j]=rhoip*rnorm
1393 ############# Compute standard error for ACF
1394 stoss4=st4/ss4
1395 snoss4=sn4/ss4
1396 rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4
1397 rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4
1398 rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j])
1399 st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4)))
1400 stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4)))
1401 dataOut.sd[i,j]=((stoss4*((1.0+rp2)*st+(2.0*rp2*rs2*snoss4)-4.0*math.sqrt(rs2*rp2)))+(0.25*snoss4*((1.0+rn2)*stn+(2.0*rn2*rs2*stoss4)-4.0*math.sqrt(rs2*rn2))))*dataOut.rnint2[j]
1402 dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j])
1403
1404 else: #default values for bad points
1405 rnorm=1/math.sqrt(st4)
1406 dataOut.sd[i,j]=1.e30
1407 dataOut.ibad[i,j]=4
1408 dataOut.rhor[i,j]=rhorp*rnorm
1409 dataOut.rhoi[i,j]=rhoip*rnorm
1410
1411 if ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)):
1412 dataOut.igcej[i,j]=1
1413
1414 return dataOut
1415
1416
1417 class FaradayAngleAndDPPower(Operation):
1418 """Operation to calculate Faraday angle and Double Pulse power.
1419
1420 Parameters:
1421 -----------
1422 None
1423
1424 Example
1425 --------
1426
1427 op = proc_unit.addOperation(name='FaradayAngleAndDPPower', optype='other')
1428
1429 """
1430
1431 def __init__(self, **kwargs):
1432
1433 Operation.__init__(self, **kwargs)
1434 self.aux=1
1435
1436 def run(self,dataOut):
1437
1438 if self.aux==1:
1439 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
1440 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
1441 dataOut.sdn2=numpy.zeros(dataOut.NDP,'float32')
1442 dataOut.ph2=numpy.zeros(dataOut.NDP,'float32')
1443 dataOut.sdp2=numpy.zeros(dataOut.NDP,'float32')
1444 dataOut.ibd=numpy.zeros(dataOut.NDP,'float32')
1445 dataOut.phi=numpy.zeros(dataOut.NDP,'float32')
1446
1447 self.aux=0
1448
1449 for i in range(dataOut.MAXNRANGENDT):
1450 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
1451 dataOut.h2[i]=dataOut.range1[i]**2
1452
1453 for j in range(dataOut.NDP):
1454 dataOut.ph2[j]=0.
1455 dataOut.sdp2[j]=0.
1456 ri=dataOut.rhoi[j][0]/dataOut.sd[j][0]
1457 rr=dataOut.rhor[j][0]/dataOut.sd[j][0]
1458 dataOut.sdn2[j]=1./dataOut.sd[j][0]
1459
1460 pt=0.# // total power
1461 st=0.# // total signal
1462 ibt=0# // bad lags
1463 ns=0# // no. good lags
1464 for l in range(dataOut.DPL):
1465 #add in other lags if outside of e-jet contamination
1466 if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ):
1467
1468 dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l]
1469 dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l]
1470 ns+=1
1471
1472
1473 pt+=dataOut.p[j][l]/dataOut.sdp[j][l]
1474 st+=1./dataOut.sdp[j][l]
1475 ibt|=dataOut.ibad[j][l];
1476 if(ns!= 0):
1477 dataOut.ibd[j]=0
1478 dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j]
1479 dataOut.sdp2[j]=1./dataOut.sdp2[j]
808 else:
1480 else:
809 code = numpy.array(code).reshape(nCode,nBaud)
1481 dataOut.ibd[j]=ibt
810 self.setup(code, osamp, dataOut)
1482 dataOut.ph2[j]=pt/st
1483 dataOut.sdp2[j]=1./st
1484
1485 dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j]
1486 dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j]
1487 rr=rr/dataOut.sdn2[j]
1488 ri=ri/dataOut.sdn2[j]
1489 #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program
1490 dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri))
1491 if( (ri == 0.) and (rr == 0.) ):
1492 dataOut.phi[j]=0.
1493 else:
1494 dataOut.phi[j]=math.atan2( ri , rr )
811
1495
812 self.isConfig = True
1496 return dataOut
813
1497
814 if mode == 3:
815 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
816
1498
817 if times != None:
1499 class ElectronDensityFaraday(Operation):
818 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
1500 """Operation to calculate electron density from Faraday angle.
819
1501
820 if self.code is None:
1502 Parameters:
821 print("Fail decoding: Code is not defined.")
1503 -----------
822 return
1504 NSHTS : int
1505 .*
1506 RATE : float
1507 .*
823
1508
824 self.__nProfiles = dataOut.nProfiles
1509 Example
825 datadec = None
1510 --------
826
1511
827 if mode == 3:
1512 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
828 mode = 0
1513 op.addParameter(name='NSHTS', value='50', format='int')
1514 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
829
1515
830 if dataOut.flagDataAsBlock:
1516 """
831 """
832 Decoding when data have been read as block,
833 """
834
1517
835 if mode == 0:
1518 def __init__(self, **kwargs):
836 datadec = self.__convolutionByBlockInTime(dataOut.data)
837 if mode == 1:
838 datadec = self.__convolutionByBlockInFreq(dataOut.data)
839 else:
840 """
841 Decoding when data have been read profile by profile
842 """
843 if mode == 0:
844 datadec = self.__convolutionInTime(dataOut.data)
845
1519
846 if mode == 1:
1520 Operation.__init__(self, **kwargs)
847 datadec = self.__convolutionInFreq(dataOut.data)
1521 self.aux=1
1522
1523 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1524
1525 #print(ctime(dataOut.utctime))
1526 #3print("Faraday Angle",dataOut.phi)
1527
1528 dataOut.NSHTS=NSHTS
1529 dataOut.RATE=RATE
1530
1531 if self.aux==1:
1532 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1533 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1534 self.aux=0
1535 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1536 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1537 # use complex numbers for phase
1538 for i in range(dataOut.NSHTS):
1539 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1540 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1541
1542 # differentiate and convert to number density
1543 ndphi=dataOut.NSHTS-4
1544 for i in range(2,dataOut.NSHTS-2):
1545 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1546 #four-point derivative, no phase unwrapping necessary
1547 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1548 dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1549
1550 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1551 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1552 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
848
1553
849 if mode == 2:
1554 return dataOut
850 datadec = self.__convolutionInFreqOpt(dataOut.data)
851
1555
852 if datadec is None:
1556 class ElectronDensityRobertoTestFaraday(Operation):
853 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
1557 """Operation to calculate electron density from Faraday angle.
854
1558
855 dataOut.code = self.code
1559 Parameters:
856 dataOut.nCode = self.nCode
1560 -----------
857 dataOut.nBaud = self.nBaud
1561 NSHTS : int
1562 .*
1563 RATE : float
1564 .*
858
1565
859 dataOut.data = datadec
1566 Example
1567 --------
860
1568
861 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
1569 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1570 op.addParameter(name='NSHTS', value='50', format='int')
1571 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
862
1572
863 dataOut.flagDecodeData = True #asumo q la data esta decodificada
1573 """
864
1574
865 if self.__profIndex == self.nCode-1:
1575 def __init__(self, **kwargs):
866 self.__profIndex = 0
867 return dataOut
868
1576
869 self.__profIndex += 1
1577 Operation.__init__(self, **kwargs)
1578 self.aux=1
1579
1580 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1581
1582 #print(ctime(dataOut.utctime))
1583 #print("Faraday Angle",dataOut.phi)
1584
1585 dataOut.NSHTS=NSHTS
1586 dataOut.RATE=RATE
1587
1588 if self.aux==1:
1589 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1590 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1591 self.aux=0
1592 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1593 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1594 # use complex numbers for phase
1595 '''
1596 for i in range(dataOut.NSHTS):
1597 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1598 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1599 '''
1600
1601 # differentiate and convert to number density
1602 ndphi=dataOut.NSHTS-4
1603
1604 dataOut.phi=numpy.unwrap(dataOut.phi)
1605
1606 for i in range(2,dataOut.NSHTS-2):
1607 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1608 #four-point derivative, no phase unwrapping necessary
1609 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1610 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1611 dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
1612
1613 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1614 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1615 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
870
1616
871 return dataOut
1617 return dataOut
872 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
873
1618
1619 class ElectronDensityRobertoTest2Faraday(Operation):
1620 """Operation to calculate electron density from Faraday angle.
874
1621
875 class ProfileConcat(Operation):
1622 Parameters:
1623 -----------
1624 NSHTS : int
1625 .*
1626 RATE : float
1627 .*
876
1628
877 isConfig = False
1629 Example
878 buffer = None
1630 --------
1631
1632 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1633 op.addParameter(name='NSHTS', value='50', format='int')
1634 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1635
1636 """
879
1637
880 def __init__(self, **kwargs):
1638 def __init__(self, **kwargs):
881
1639
882 Operation.__init__(self, **kwargs)
1640 Operation.__init__(self, **kwargs)
883 self.profileIndex = 0
1641 self.aux=1
884
1642
885 def reset(self):
1643 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
886 self.buffer = numpy.zeros_like(self.buffer)
887 self.start_index = 0
888 self.times = 1
889
1644
890 def setup(self, data, m, n=1):
1645 #print(ctime(dataOut.utctime))
891 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
1646 #print("Faraday Angle",dataOut.phi)
892 self.nHeights = data.shape[1]#.nHeights
893 self.start_index = 0
894 self.times = 1
895
1647
896 def concat(self, data):
1648 dataOut.NSHTS=NSHTS
1649 dataOut.RATE=RATE
897
1650
898 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
1651 if self.aux==1:
899 self.start_index = self.start_index + self.nHeights
1652 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1653 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1654 self.aux=0
1655 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1656 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1657 # use complex numbers for phase
1658 '''
1659 for i in range(dataOut.NSHTS):
1660 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1661 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1662 '''
900
1663
901 def run(self, dataOut, m):
1664 # differentiate and convert to number density
902 dataOut.flagNoData = True
1665 ndphi=dataOut.NSHTS-4
903
1666
904 if not self.isConfig:
1667 #dataOut.phi=numpy.unwrap(dataOut.phi)
905 self.setup(dataOut.data, m, 1)
1668 f1=numpy.exp((dataOut.phi*1.j)/10)
906 self.isConfig = True
1669 f2=numpy.exp((dataOut.phi*2.j)/10)
907
1670
908 if dataOut.flagDataAsBlock:
1671 for i in range(2,dataOut.NSHTS-2):
909 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
1672 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1673 #four-point derivative, no phase unwrapping necessary
1674 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1675 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1676 ##dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
910
1677
1678 dataOut.dphi[i]=numpy.angle(f1[i+1]*numpy.conjugate(f1[i-1])*f2[i+2]*numpy.conjugate(f2[i-2]))
1679
1680
1681 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1682 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1683 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1684
1685 return dataOut
1686
1687 class NormalizeDPPower(Operation):
1688 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1689
1690 Parameters:
1691 -----------
1692 None
1693
1694 Example
1695 --------
1696
1697 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1698
1699 """
1700
1701 def __init__(self, **kwargs):
1702
1703 Operation.__init__(self, **kwargs)
1704 self.aux=1
1705
1706 def normal(self,a,b,n,m):
1707 chmin=1.0e30
1708 chisq=numpy.zeros(150,'float32')
1709 temp=numpy.zeros(150,'float32')
1710
1711 for i in range(2*m-1):
1712 an=al=be=chisq[i]=0.0
1713 for j in range(int(n/m)):
1714 k=int(j+i*n/(2*m))
1715 if(a[k]>0.0 and b[k]>0.0):
1716 al+=a[k]*b[k]
1717 be+=b[k]*b[k]
1718
1719 if(be>0.0):
1720 temp[i]=al/be
1721 else:
1722 temp[i]=1.0
1723
1724 for j in range(int(n/m)):
1725 k=int(j+i*n/(2*m))
1726 if(a[k]>0.0 and b[k]>0.0):
1727 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1728 an=an+1
1729
1730 if(chisq[i]>0.0):
1731 chisq[i]/=an
1732
1733 for i in range(int(2*m-1)):
1734 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1735 chmin=chisq[i]
1736 cf=temp[i]
1737 return cf
1738
1739 def normalize(self,dataOut):
1740
1741 if self.aux==1:
1742 dataOut.cf=numpy.zeros(1,'float32')
1743 dataOut.cflast=numpy.zeros(1,'float32')
1744 self.aux=0
1745
1746 night_first=300.0
1747 night_first1= 310.0
1748 night_end= 450.0
1749 day_first=250.0
1750 day_end=400.0
1751 day_first_sunrise=190.0
1752 day_end_sunrise=280.0
1753
1754 print(dataOut.ut_Faraday)
1755 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1756 print("EARLY")
1757 i2=(night_end-dataOut.range1[0])/dataOut.DH
1758 i1=(night_first -dataOut.range1[0])/dataOut.DH
1759 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1760 print("NIGHT")
1761 i2=(night_end-dataOut.range1[0])/dataOut.DH
1762 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1763 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1764 print("SUNRISE")
1765 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1766 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
911 else:
1767 else:
912 self.concat(dataOut.data)
1768 print("ELSE")
913 self.times += 1
1769 i2=(day_end-dataOut.range1[0])/dataOut.DH
914 if self.times > m:
1770 i1=(day_first -dataOut.range1[0])/dataOut.DH
915 dataOut.data = self.buffer
1771 #print(i1*dataOut.DH)
916 self.reset()
1772 #print(i2*dataOut.DH)
917 dataOut.flagNoData = False
1773
918 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
1774 i1=int(i1)
919 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1775 i2=int(i2)
920 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
1776
921 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
1777 try:
922 dataOut.ippSeconds *= m
1778 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1779 except:
1780 pass
1781
1782 #print(dataOut.ph2)
1783 #input()
1784 # in case of spread F, normalize much higher
1785 if(dataOut.cf<dataOut.cflast[0]/10.0):
1786 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1787 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1788 i1=int(i1)
1789 i2=int(i2)
1790 try:
1791 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1792 except:
1793 pass
1794
1795 dataOut.cflast[0]=dataOut.cf
1796
1797 ## normalize double pulse power and error bars to Faraday
1798 for i in range(dataOut.NSHTS):
1799 dataOut.ph2[i]*=dataOut.cf
1800 dataOut.sdp2[i]*=dataOut.cf
1801 #print(dataOut.ph2)
1802 #input()
1803
1804 for i in range(dataOut.NSHTS):
1805 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1806 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1807
1808
1809 def run(self,dataOut):
1810
1811 self.normalize(dataOut)
1812 #print(dataOut.ph2)
1813 #print(dataOut.sdp2)
1814 #input()
1815
1816
1817 return dataOut
1818
1819 class NormalizeDPPowerRoberto(Operation):
1820 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1821
1822 Parameters:
1823 -----------
1824 None
1825
1826 Example
1827 --------
1828
1829 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1830
1831 """
1832
1833 def __init__(self, **kwargs):
1834
1835 Operation.__init__(self, **kwargs)
1836 self.aux=1
1837
1838 def normal(self,a,b,n,m):
1839 chmin=1.0e30
1840 chisq=numpy.zeros(150,'float32')
1841 temp=numpy.zeros(150,'float32')
1842
1843 for i in range(2*m-1):
1844 an=al=be=chisq[i]=0.0
1845 for j in range(int(n/m)):
1846 k=int(j+i*n/(2*m))
1847 if(a[k]>0.0 and b[k]>0.0):
1848 al+=a[k]*b[k]
1849 be+=b[k]*b[k]
1850
1851 if(be>0.0):
1852 temp[i]=al/be
1853 else:
1854 temp[i]=1.0
1855
1856 for j in range(int(n/m)):
1857 k=int(j+i*n/(2*m))
1858 if(a[k]>0.0 and b[k]>0.0):
1859 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1860 an=an+1
1861
1862 if(chisq[i]>0.0):
1863 chisq[i]/=an
1864
1865 for i in range(int(2*m-1)):
1866 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1867 chmin=chisq[i]
1868 cf=temp[i]
1869 return cf
1870
1871 def normalize(self,dataOut):
1872
1873 if self.aux==1:
1874 dataOut.cf=numpy.zeros(1,'float32')
1875 dataOut.cflast=numpy.zeros(1,'float32')
1876 self.aux=0
1877
1878 night_first=300.0
1879 night_first1= 310.0
1880 night_end= 450.0
1881 day_first=250.0
1882 day_end=400.0
1883 day_first_sunrise=190.0
1884 day_end_sunrise=350.0
1885
1886 print(dataOut.ut_Faraday)
1887 '''
1888 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1889 print("EARLY")
1890 i2=(night_end-dataOut.range1[0])/dataOut.DH
1891 i1=(night_first -dataOut.range1[0])/dataOut.DH
1892 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1893 print("NIGHT")
1894 i2=(night_end-dataOut.range1[0])/dataOut.DH
1895 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1896 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1897 print("SUNRISE")
1898 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1899 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
1900 else:
1901 print("ELSE")
1902 i2=(day_end-dataOut.range1[0])/dataOut.DH
1903 i1=(day_first -dataOut.range1[0])/dataOut.DH
1904 '''
1905 i2=(420-dataOut.range1[0])/dataOut.DH
1906 i1=(200 -dataOut.range1[0])/dataOut.DH
1907 print(i1*dataOut.DH)
1908 print(i2*dataOut.DH)
1909
1910 i1=int(i1)
1911 i2=int(i2)
1912
1913 try:
1914 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1915 except:
1916 pass
1917
1918 #print(dataOut.ph2)
1919 #input()
1920 # in case of spread F, normalize much higher
1921 if(dataOut.cf<dataOut.cflast[0]/10.0):
1922 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1923 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1924 i1=int(i1)
1925 i2=int(i2)
1926 try:
1927 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1928 except:
1929 pass
1930
1931 dataOut.cflast[0]=dataOut.cf
1932
1933 ## normalize double pulse power and error bars to Faraday
1934 for i in range(dataOut.NSHTS):
1935 dataOut.ph2[i]*=dataOut.cf
1936 dataOut.sdp2[i]*=dataOut.cf
1937 #print(dataOut.ph2)
1938 #input()
1939
1940 for i in range(dataOut.NSHTS):
1941 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1942 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1943
1944
1945 def run(self,dataOut):
1946
1947 self.normalize(dataOut)
1948 #print(dataOut.ph2)
1949 #print(dataOut.sdp2)
1950 #input()
1951
1952
923 return dataOut
1953 return dataOut
924
1954
925 class ProfileSelector(Operation):
926
1955
927 profileIndex = None
1956 class suppress_stdout_stderr(object):
928 # Tamanho total de los perfiles
1957 '''
929 nProfiles = None
1958 A context manager for doing a "deep suppression" of stdout and stderr in
1959 Python, i.e. will suppress all print, even if the print originates in a
1960 compiled C/Fortran sub-function.
1961 This will not suppress raised exceptions, since exceptions are printed
1962 to stderr just before a script exits, and after the context manager has
1963 exited (at least, I think that is why it lets exceptions through).
1964
1965 '''
1966 def __init__(self):
1967 # Open a pair of null files
1968 self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)]
1969 # Save the actual stdout (1) and stderr (2) file descriptors.
1970 self.save_fds = [os.dup(1), os.dup(2)]
1971
1972 def __enter__(self):
1973 # Assign the null pointers to stdout and stderr.
1974 os.dup2(self.null_fds[0],1)
1975 os.dup2(self.null_fds[1],2)
1976
1977 def __exit__(self, *_):
1978 # Re-assign the real stdout/stderr back to (1) and (2)
1979 os.dup2(self.save_fds[0],1)
1980 os.dup2(self.save_fds[1],2)
1981 # Close all file descriptors
1982 for fd in self.null_fds + self.save_fds:
1983 os.close(fd)
1984
1985
1986 from schainpy.model.proc import fitacf_guess
1987 from schainpy.model.proc import fitacf_fit_short
1988 class DPTemperaturesEstimation(Operation):
1989 """Operation to estimate temperatures for Double Pulse data.
1990
1991 Parameters:
1992 -----------
1993 IBITS : int
1994 .*
1995
1996 Example
1997 --------
1998
1999 op = proc_unit.addOperation(name='DPTemperaturesEstimation', optype='other')
2000 op.addParameter(name='IBITS', value='16', format='int')
2001
2002 """
2003
2004 def __init__(self, **kwargs):
2005
2006 Operation.__init__(self, **kwargs)
2007
2008 self.aux=1
2009
2010 def Estimation(self,dataOut):
2011 with suppress_stdout_stderr():
2012 #if True:
2013
2014 if self.aux==1:
2015 dataOut.ifit=numpy.zeros(5,order='F',dtype='int32')
2016 dataOut.m=numpy.zeros(1,order='F',dtype='int32')
2017 dataOut.te2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2018 dataOut.ti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2019 dataOut.ete2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2020 dataOut.eti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2021
2022 self.aux=0
2023
2024 dataOut.phy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2025 dataOut.ephy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2026 dataOut.info2=numpy.zeros(dataOut.NDP,order='F',dtype='float32')
2027 dataOut.params=numpy.zeros(10,order='F',dtype='float32')
2028 dataOut.cov=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2029 dataOut.covinv=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2030
2031 #null_fd = os.open(os.devnull, os.O_RDWR)
2032 #os.dup2(null_fd, 1)
2033
2034 for i in range(10,dataOut.NSHTS): #no point below 150 km
2035
2036 #some definitions
2037 iflag=0 # inicializado a cero?
2038 wl = 3.0
2039 x=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2040 y=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2041 e=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2042 eb=numpy.zeros(5,order='F',dtype='float32')
2043 zero=numpy.zeros(1,order='F',dtype='float32')
2044 depth=numpy.zeros(1,order='F',dtype='float32')
2045 t1=numpy.zeros(1,order='F',dtype='float32')
2046 t2=numpy.zeros(1,order='F',dtype='float32')
2047
2048 if i>10 and l1>=0:
2049 if l1==0:
2050 l1=1
2051
2052 dataOut.cov=numpy.reshape(dataOut.cov,l1*l1)
2053 dataOut.cov=numpy.resize(dataOut.cov,dataOut.DPL*dataOut.DPL)
2054 dataOut.covinv=numpy.reshape(dataOut.covinv,l1*l1)
2055 dataOut.covinv=numpy.resize(dataOut.covinv,dataOut.DPL*dataOut.DPL)
2056
2057 for l in range(dataOut.DPL*dataOut.DPL):
2058 dataOut.cov[l]=0.0
2059 acfm= (dataOut.rhor[i][0])**2 + (dataOut.rhoi[i][0])**2
2060 if acfm> 0.0:
2061 cc=dataOut.rhor[i][0]/acfm
2062 ss=dataOut.rhoi[i][0]/acfm
2063 else:
2064 cc=1.
2065 ss=0.
2066 # keep only uncontaminated data, don't pass zero lag to fitter
2067 l1=0
2068 for l in range(0+1,dataOut.DPL):
2069 if dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0:
2070 y[l1]=dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss
2071 x[l1]=dataOut.alag[l]*1.0e-3
2072 dataOut.sd[i][l]=dataOut.sd[i][l]/((acfm)**2)# important
2073 e[l1]=dataOut.sd[i][l] #this is the variance, not the st. dev.
2074 l1=l1+1
2075
2076 for l in range(l1*(l1+1)):
2077 dataOut.cov[l]=0.0
2078 for l in range(l1):
2079 dataOut.cov[l*(1+l1)]=e[l]
2080 angle=dataOut.thb[i]*0.01745
2081 bm=dataOut.bfm[i]
2082 dataOut.params[0]=1.0 #norm
2083 dataOut.params[1]=1000.0 #te
2084 dataOut.params[2]=800.0 #ti
2085 dataOut.params[3]=0.00 #ph
2086 dataOut.params[4]=0.00 #phe
2087
2088 if l1!=0:
2089 x=numpy.resize(x,l1)
2090 y=numpy.resize(y,l1)
2091 else:
2092 x=numpy.resize(x,1)
2093 y=numpy.resize(y,1)
2094
2095 if True: #len(y)!=0:
2096
2097 fitacf_guess.guess(y,x,zero,depth,t1,t2,len(y))
2098 t2=t1/t2
2099
2100
2101
2102
2103 if (t1<5000.0 and t1> 600.0):
2104 dataOut.params[1]=t1
2105 dataOut.params[2]=min(t2,t1)
2106 dataOut.ifit[1]=dataOut.ifit[2]=1
2107 dataOut.ifit[0]=dataOut.ifit[3]=dataOut.ifit[4]=0
2108 #print(dataOut.ut_Faraday)
2109 if dataOut.ut_Faraday<10.0 and dataOut.ut_Faraday>=0.5:
2110 dataOut.ifit[2]=0
2111
2112 den=dataOut.ph2[i]
2113
2114 if l1!=0:
2115 dataOut.covinv=dataOut.covinv[0:l1*l1].reshape((l1,l1))
2116 dataOut.cov=dataOut.cov[0:l1*l1].reshape((l1,l1))
2117 e=numpy.resize(e,l1)
2118 else:
2119 dataOut.covinv=numpy.resize(dataOut.covinv,1)
2120 dataOut.cov=numpy.resize(dataOut.cov,1)
2121 e=numpy.resize(e,1)
2122
2123 eb=numpy.resize(eb,10)
2124 dataOut.ifit=numpy.resize(dataOut.ifit,10)
2125
2126
2127
2128 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2129
2130 #exit()
2131
2132 if dataOut.params[2]>dataOut.params[1]*1.05:
2133 dataOut.ifit[2]=0
2134 dataOut.params[1]=dataOut.params[2]=t1
2135 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2136
2137 if (dataOut.ifit[2]==0):
2138 dataOut.params[2]=dataOut.params[1]
2139 if (dataOut.ifit[3]==0 and iflag==0):
2140 dataOut.params[3]=0.0
2141 if (dataOut.ifit[4]==0):
2142 dataOut.params[4]=0.0
2143 dataOut.te2[i]=dataOut.params[1]
2144 dataOut.ti2[i]=dataOut.params[2]
2145 dataOut.ete2[i]=eb[1]
2146 dataOut.eti2[i]=eb[2]
2147
2148 if dataOut.eti2[i]==0:
2149 dataOut.eti2[i]=dataOut.ete2[i]
2150
2151 dataOut.phy2[i]=dataOut.params[3]
2152 dataOut.ephy2[i]=eb[3]
2153 if(iflag==1):
2154 dataOut.ephy2[i]=0.0
2155
2156 if (dataOut.m<=3 and dataOut.m!= 0 and dataOut.te2[i]>400.0):
2157 dataOut.info2[i]=1
2158 else:
2159 dataOut.info2[i]=0
2160
2161 def run(self,dataOut,IBITS=16):
2162
2163 dataOut.IBITS = IBITS
2164
2165 self.Estimation(dataOut)
2166
2167
2168 return dataOut
2169
2170 class NeTeTiRecal(NormalizeDPPower,DPTemperaturesEstimation):
2171
2172 def __init__(self, **kwargs):
2173
2174 Operation.__init__(self, **kwargs)
2175 self.aux=0
2176
2177 def run(self,dataOut):
2178
2179 for i in range(dataOut.NSHTS):
2180 print("H: ",i*15)
2181 print(1+(dataOut.te2[i]/dataOut.ti2[i]))
2182 dataOut.ph2[i]*=1+(dataOut.te2[i]/dataOut.ti2[i])
2183
2184 self.normalize(dataOut)
2185 self.Estimation(dataOut)
2186
2187
2188 return dataOut
2189
2190
2191 from schainpy.model.proc import fitacf_acf2
2192 class DenCorrection(Operation):
2193
2194 def __init__(self, **kwargs):
2195
2196 Operation.__init__(self, **kwargs)
2197
2198
2199 def run(self,dataOut):
2200
2201 y=numpy.zeros(dataOut.DPL,order='F',dtype='float32')
2202 #y_aux = numpy.zeros(1,,dtype='float32')
2203 for i in range(dataOut.NSHTS):
2204 y[0]=y[1]=dataOut.range1[i]
2205
2206 y = y.astype(dtype='float64',order='F')
2207 three=int(3)
2208 wl = 3.0
2209 tion=numpy.zeros(three,order='F',dtype='float32')
2210 fion=numpy.zeros(three,order='F',dtype='float32')
2211 nui=numpy.zeros(three,order='F',dtype='float32')
2212 wion=numpy.zeros(three,order='F',dtype='int32')
2213 bline=0.0
2214 #bline=numpy.zeros(1,order='F',dtype='float32')
2215
2216
2217 #print("**** ACF2 WRAPPER ***** ",fitacf_acf2.acf2.__doc__ )
2218 print("BEFORE",dataOut.ph2[10:35])
2219 for i in range(dataOut.NSHTS):
2220 if dataOut.info2[i]==1:
2221 angle=dataOut.thb[i]*0.01745
2222 nue=nui[0]=nui[1]=nui[2]=0.0#nui[3]=0.0
2223 wion[0]=16
2224 wion[1]=1
2225 wion[2]=4
2226 tion[0]=tion[1]=tion[2]=dataOut.ti2[i]
2227 fion[0]=1.0-dataOut.phy2[i]
2228 fion[1]=dataOut.phy2[i]
2229 fion[2]=0.0
2230 for j in range(dataOut.DPL):
2231 tau=dataOut.alag[j]*1.0e-3
2232
2233 '''
2234 print("**** input from acf2 ***** ")
2235 print("wl ",wl)
2236 print("tau ",tau)
2237 print("te2[i] ",dataOut.te2[i])
2238 print("tion ",tion)
2239 print("fion ",fion)
2240 print("nue ",nue)
2241 print("nui ",nui)
2242 print("wion ",wion)
2243 print("angle ",angle)
2244 print("ph2[i] ",dataOut.ph2[i])
2245 print("bfm[i] ",dataOut.bfm[i])
2246 print("y[j] ",y[j])
2247 '''
2248 print("Before y[j] ",y[j])
2249 #with suppress_stdout_stderr():
2250 y[j]=fitacf_acf2.acf2(wl,tau,dataOut.te2[i],tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],y[j],three)
2251 #print("l",l)
2252 print("After y[j] ",y[j])
2253 '''
2254 print("**** output from acf2 ***** ")
2255 print("wl ",wl)
2256 print("tau ",tau)
2257 print("te2[i] ",dataOut.te2[i])
2258 print("tion ",tion)
2259 print("fion ",fion)
2260 print("nue ",nue)
2261 print("nui ",nui)
2262 print("wion ",wion)
2263 print("angle ",angle)
2264 print("ph2[i] ",dataOut.ph2[i])
2265 print("bfm[i] ",dataOut.bfm[i])
2266 print("y[j] ",y[j])
2267 print("i ",i , " j ",j , "y[j] ",y[j])
2268 '''
2269
2270
2271 #exit(1)
2272 if dataOut.ut_Faraday>11.0 and dataOut.range1[i]>150.0 and dataOut.range1[i]<400.0:
2273 tau=0.0
2274 #with suppress_stdout_stderr():
2275 bline=fitacf_acf2.acf2(wl,tau,tion,tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],bline,three)
2276 cf=min(1.2,max(1.0,bline/y[0]))
2277 print("bline: ",bline)
2278 if cf != 1.0:
2279 print("bline: ",bline)
2280 print("cf: ",cf)
2281 #exit(1)
2282 #print("cf: ",cf)
2283 dataOut.ph2[i]=cf*dataOut.ph2[i]
2284 dataOut.sdp2[i]=cf*dataOut.sdp2[i]
2285 for j in range(1,dataOut.DPL):
2286 y[j]=(y[j]/y[0])*dataOut.DH+dataOut.range1[i]
2287 y[0]=dataOut.range1[i]+dataOut.DH
2288 #exit(1)
2289
2290
2291 #exit(1)
2292 print("AFTER",dataOut.ph2[10:35])
2293 #exit(1)
2294
2295
2296
2297
2298
2299 return dataOut
2300
2301 class DataPlotCleaner(Operation):
2302 def __init__(self, **kwargs):
2303
2304 Operation.__init__(self, **kwargs)
2305
2306 def run(self,dataOut):
2307
2308
2309 THRESH_MIN_POW=10000
2310 THRESH_MAX_POW=10000000
2311 THRESH_MIN_TEMP=500
2312 THRESH_MAX_TEMP=4000
2313 dataOut.DensityClean=numpy.zeros((1,dataOut.NDP))
2314 dataOut.EDensityClean=numpy.zeros((1,dataOut.NDP))
2315 dataOut.ElecTempClean=numpy.zeros((1,dataOut.NDP))
2316 dataOut.EElecTempClean=numpy.zeros((1,dataOut.NDP))
2317 dataOut.IonTempClean=numpy.zeros((1,dataOut.NDP))
2318 dataOut.EIonTempClean=numpy.zeros((1,dataOut.NDP))
2319
2320 dataOut.DensityClean[0]=numpy.copy(dataOut.ph2)
2321 dataOut.EDensityClean[0]=numpy.copy(dataOut.sdp2)
2322 dataOut.ElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2323 dataOut.EElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2324 dataOut.IonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2325 dataOut.EIonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2326
2327 for i in range(dataOut.NDP):
2328 if dataOut.DensityClean[0,i]<THRESH_MIN_POW:
2329 dataOut.DensityClean[0,i]=THRESH_MIN_POW
2330
2331 for i in range(dataOut.NDP):
2332 if dataOut.DensityClean[0,i]>THRESH_MAX_POW:
2333 dataOut.DensityClean[0,i]=THRESH_MAX_POW
2334
2335 for i in range(dataOut.NSHTS):
2336 dataOut.ElecTempClean[0,i]=(max(1.0, dataOut.ElecTempClean[0,i]))
2337 dataOut.IonTempClean[0,i]=(max(1.0, dataOut.IonTempClean[0,i]))
2338 for i in range(dataOut.NSHTS):
2339 if dataOut.ElecTempClean[0,i]<THRESH_MIN_TEMP:
2340 dataOut.ElecTempClean[0,i]=THRESH_MIN_TEMP
2341 if dataOut.IonTempClean[0,i]<THRESH_MIN_TEMP:
2342 dataOut.IonTempClean[0,i]=THRESH_MIN_TEMP
2343 for i in range(dataOut.NSHTS):
2344 if dataOut.ElecTempClean[0,i]>THRESH_MAX_TEMP:
2345 dataOut.ElecTempClean[0,i]=THRESH_MAX_TEMP
2346 if dataOut.IonTempClean[0,i]>THRESH_MAX_TEMP:
2347 dataOut.IonTempClean[0,i]=THRESH_MAX_TEMP
2348 for i in range(dataOut.NSHTS):
2349 if dataOut.EElecTempClean[0,i]>500:#
2350 dataOut.ElecTempClean[0,i]=500
2351 if dataOut.EIonTempClean[0,i]>500:#
2352 dataOut.IonTempClean[0,i]=500
2353
2354 missing=numpy.nan
2355
2356 for i in range(dataOut.NSHTS,dataOut.NDP):
2357
2358 dataOut.ElecTempClean[0,i]=missing
2359 dataOut.EElecTempClean[0,i]=missing
2360 dataOut.IonTempClean[0,i]=missing
2361 dataOut.EIonTempClean[0,i]=missing
2362
2363 return dataOut
2364
2365
2366 class DataSaveCleaner(Operation):
2367 def __init__(self, **kwargs):
2368
2369 Operation.__init__(self, **kwargs)
2370
2371
2372 def run(self,dataOut):
2373
2374 dataOut.DensityFinal=numpy.zeros((1,dataOut.NDP))
2375 dataOut.EDensityFinal=numpy.zeros((1,dataOut.NDP))
2376 dataOut.ElecTempFinal=numpy.zeros((1,dataOut.NDP))
2377 dataOut.EElecTempFinal=numpy.zeros((1,dataOut.NDP))
2378 dataOut.IonTempFinal=numpy.zeros((1,dataOut.NDP))
2379 dataOut.EIonTempFinal=numpy.zeros((1,dataOut.NDP))
2380 dataOut.PhyFinal=numpy.zeros((1,dataOut.NDP))
2381 dataOut.EPhyFinal=numpy.zeros((1,dataOut.NDP))
2382
2383 dataOut.DensityFinal[0]=numpy.copy(dataOut.ph2)
2384 dataOut.EDensityFinal[0]=numpy.copy(dataOut.sdp2)
2385 dataOut.ElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2386 dataOut.EElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2387 dataOut.IonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2388 dataOut.EIonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2389 dataOut.PhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.phy2)
2390 dataOut.EPhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ephy2)
2391
2392 missing=numpy.nan
2393
2394 temp_min=100.0
2395 temp_max=3000.0#6000.0e
2396
2397 for i in range(dataOut.NSHTS):
2398
2399 if dataOut.info2[i]!=1:
2400 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2401
2402 if dataOut.ElecTempFinal[0,i]<=temp_min or dataOut.ElecTempFinal[0,i]>temp_max or dataOut.EElecTempFinal[0,i]>temp_max:
2403
2404 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2405
2406
2407 if dataOut.IonTempFinal[0,i]<=temp_min or dataOut.IonTempFinal[0,i]>temp_max or dataOut.EIonTempFinal[0,i]>temp_max:
2408 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2409
2410 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2411 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2412
2413 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2414 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2415 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2416
2417 if dataOut.EPhyFinal[0,i]<0.0 or dataOut.EPhyFinal[0,i]>1.0:
2418 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2419 if dataOut.EDensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]<9.9e6:
2420 dataOut.EDensityFinal[0,i]=max(dataOut.EDensityFinal[0,i],1000.0)
2421 else:
2422 dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing
2423 if dataOut.PhyFinal[0,i]==0 or dataOut.PhyFinal[0,i]>0.4:
2424 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2425 if dataOut.ElecTempFinal[0,i]==dataOut.IonTempFinal[0,i]:
2426 dataOut.EElecTempFinal[0,i]=dataOut.EIonTempFinal[0,i]
2427 if numpy.isnan(dataOut.ElecTempFinal[0,i]):
2428 dataOut.EElecTempFinal[0,i]=missing
2429 if numpy.isnan(dataOut.IonTempFinal[0,i]):
2430 dataOut.EIonTempFinal[0,i]=missing
2431 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2432 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2433
2434 for i in range(12,dataOut.NSHTS-1):
2435
2436 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2437 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2438
2439 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2440 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2441
2442 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2443
2444 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+3]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2445
2446 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2447 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i+2]) and numpy.isnan(dataOut.IonTempFinal[0,i+3]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2448
2449 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2450
2451
2452
2453 if i>25:
2454 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i-3]) and numpy.isnan(dataOut.ElecTempFinal[0,i-4]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2455 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2456 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i-3]) and numpy.isnan(dataOut.IonTempFinal[0,i-4]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2457
2458 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2459
2460 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2461
2462 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2463
2464 for i in range(12,dataOut.NSHTS-1):
2465
2466 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2467 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2468
2469 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2470 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2471
2472
2473 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2474
2475 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2476
2477 if numpy.count_nonzero(~numpy.isnan(dataOut.ElecTempFinal[0,12:50]))<5:
2478 dataOut.ElecTempFinal[0,:]=dataOut.EElecTempFinal[0,:]=missing
2479 if numpy.count_nonzero(~numpy.isnan(dataOut.IonTempFinal[0,12:50]))<5:
2480 dataOut.IonTempFinal[0,:]=dataOut.EIonTempFinal[0,:]=missing
2481
2482 for i in range(dataOut.NSHTS,dataOut.NDP):
2483
2484 dataOut.ElecTempFinal[0,i]=missing
2485 dataOut.EElecTempFinal[0,i]=missing
2486 dataOut.IonTempFinal[0,i]=missing
2487 dataOut.EIonTempFinal[0,i]=missing
2488 dataOut.PhyFinal[0,i]=missing
2489 dataOut.EPhyFinal[0,i]=missing
2490
2491 return dataOut
2492
2493
2494 class DataSaveCleanerHP(Operation):
2495 def __init__(self, **kwargs):
2496
2497 Operation.__init__(self, **kwargs)
2498
2499 def run(self,dataOut):
2500
2501 dataOut.Density_DP=numpy.zeros(dataOut.cut)
2502 dataOut.EDensity_DP=numpy.zeros(dataOut.cut)
2503 dataOut.ElecTemp_DP=numpy.zeros(dataOut.cut)
2504 dataOut.EElecTemp_DP=numpy.zeros(dataOut.cut)
2505 dataOut.IonTemp_DP=numpy.zeros(dataOut.cut)
2506 dataOut.EIonTemp_DP=numpy.zeros(dataOut.cut)
2507 dataOut.Phy_DP=numpy.zeros(dataOut.cut)
2508 dataOut.EPhy_DP=numpy.zeros(dataOut.cut)
2509 dataOut.Phe_DP=numpy.empty(dataOut.cut)
2510 dataOut.EPhe_DP=numpy.empty(dataOut.cut)
2511
2512 dataOut.Density_DP[:]=numpy.copy(dataOut.ph2[:dataOut.cut])
2513 dataOut.EDensity_DP[:]=numpy.copy(dataOut.sdp2[:dataOut.cut])
2514 dataOut.ElecTemp_DP[:]=numpy.copy(dataOut.te2[:dataOut.cut])
2515 dataOut.EElecTemp_DP[:]=numpy.copy(dataOut.ete2[:dataOut.cut])
2516 dataOut.IonTemp_DP[:]=numpy.copy(dataOut.ti2[:dataOut.cut])
2517 dataOut.EIonTemp_DP[:]=numpy.copy(dataOut.eti2[:dataOut.cut])
2518 dataOut.Phy_DP[:]=numpy.copy(dataOut.phy2[:dataOut.cut])
2519 dataOut.EPhy_DP[:]=numpy.copy(dataOut.ephy2[:dataOut.cut])
2520 dataOut.Phe_DP[:]=numpy.nan
2521 dataOut.EPhe_DP[:]=numpy.nan
2522
2523 missing=numpy.nan
2524 temp_min=100.0
2525 temp_max_dp=3000.0
2526
2527 for i in range(dataOut.cut):
2528 if dataOut.info2[i]!=1:
2529 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2530
2531 if dataOut.ElecTemp_DP[i]<=temp_min or dataOut.ElecTemp_DP[i]>temp_max_dp or dataOut.EElecTemp_DP[i]>temp_max_dp:
2532
2533 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=missing
2534
2535 if dataOut.IonTemp_DP[i]<=temp_min or dataOut.IonTemp_DP[i]>temp_max_dp or dataOut.EIonTemp_DP[i]>temp_max_dp:
2536 dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2537
2538 ####################################################################################### CHECK THIS
2539 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2540 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2541
2542 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2543 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2544 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2545 #######################################################################################
2546
2547 if dataOut.EPhy_DP[i]<0.0 or dataOut.EPhy_DP[i]>1.0:
2548 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2549 if dataOut.EDensity_DP[i]>0.0 and dataOut.Density_DP[i]>0.0 and dataOut.Density_DP[i]<9.9e6:
2550 dataOut.EDensity_DP[i]=max(dataOut.EDensity_DP[i],1000.0)
2551 else:
2552 dataOut.Density_DP[i]=dataOut.EDensity_DP[i]=missing
2553 if dataOut.Phy_DP[i]==0 or dataOut.Phy_DP[i]>0.4:
2554 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2555 if dataOut.ElecTemp_DP[i]==dataOut.IonTemp_DP[i]:
2556 dataOut.EElecTemp_DP[i]=dataOut.EIonTemp_DP[i]
2557 if numpy.isnan(dataOut.ElecTemp_DP[i]):
2558 dataOut.EElecTemp_DP[i]=missing
2559 if numpy.isnan(dataOut.IonTemp_DP[i]):
2560 dataOut.EIonTemp_DP[i]=missing
2561 if numpy.isnan(dataOut.ElecTemp_DP[i]) or numpy.isnan(dataOut.EElecTemp_DP[i]):
2562 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2563
2564
2565
2566 dataOut.Density_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2567 dataOut.EDensity_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2568 dataOut.ElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2569 dataOut.EElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2570 dataOut.IonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2571 dataOut.EIonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2572 dataOut.Phy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2573 dataOut.EPhy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2574 dataOut.Phe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2575 dataOut.EPhe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2576
2577 dataOut.Density_LP[:]=numpy.copy(dataOut.ne[dataOut.cut:dataOut.NACF])
2578 dataOut.EDensity_LP[:]=numpy.copy(dataOut.ene[dataOut.cut:dataOut.NACF])
2579 dataOut.ElecTemp_LP[:]=numpy.copy(dataOut.te[dataOut.cut:dataOut.NACF])
2580 dataOut.EElecTemp_LP[:]=numpy.copy(dataOut.ete[dataOut.cut:dataOut.NACF])
2581 dataOut.IonTemp_LP[:]=numpy.copy(dataOut.ti[dataOut.cut:dataOut.NACF])
2582 dataOut.EIonTemp_LP[:]=numpy.copy(dataOut.eti[dataOut.cut:dataOut.NACF])
2583 dataOut.Phy_LP[:]=numpy.copy(dataOut.ph[dataOut.cut:dataOut.NACF])
2584 dataOut.EPhy_LP[:]=numpy.copy(dataOut.eph[dataOut.cut:dataOut.NACF])
2585 dataOut.Phe_LP[:]=numpy.copy(dataOut.phe[dataOut.cut:dataOut.NACF])
2586 dataOut.EPhe_LP[:]=numpy.copy(dataOut.ephe[dataOut.cut:dataOut.NACF])
2587
2588 temp_max_lp=6000.0
2589
2590 for i in range(dataOut.NACF-dataOut.cut):
2591
2592 if dataOut.ElecTemp_LP[i]<=temp_min or dataOut.ElecTemp_LP[i]>temp_max_lp or dataOut.EElecTemp_LP[i]>temp_max_lp:
2593
2594 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=missing
2595
2596 if dataOut.IonTemp_LP[i]<=temp_min or dataOut.IonTemp_LP[i]>temp_max_lp or dataOut.EIonTemp_LP[i]>temp_max_lp:
2597 dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2598 if dataOut.EPhy_LP[i]<0.0 or dataOut.EPhy_LP[i]>1.0:
2599 dataOut.Phy_LP[i]=dataOut.EPhy_LP[i]=missing
2600
2601 if dataOut.EPhe_LP[i]<0.0 or dataOut.EPhe_LP[i]>1.0:
2602 dataOut.Phe_LP[i]=dataOut.EPhe_LP[i]=missing
2603 if dataOut.EDensity_LP[i]>0.0 and dataOut.Density_LP[i]>0.0 and dataOut.Density_LP[i]<9.9e6 and dataOut.EDensity_LP[i]*dataOut.Density_LP[i]<9.9e6:
2604 dataOut.EDensity_LP[i]=max(dataOut.EDensity_LP[i],1000.0/dataOut.Density_LP[i])
2605 else:
2606 dataOut.Density_LP[i]=missing
2607 dataOut.EDensity_LP[i]=1.0
2608
2609 if numpy.isnan(dataOut.Phy_LP[i]):
2610 dataOut.EPhy_LP[i]=missing
2611
2612 if numpy.isnan(dataOut.Phe_LP[i]):
2613 dataOut.EPhe_LP[i]=missing
2614
2615
2616 if dataOut.ElecTemp_LP[i]==dataOut.IonTemp_LP[i]:
2617 dataOut.EElecTemp_LP[i]=dataOut.EIonTemp_LP[i]
2618 if numpy.isnan(dataOut.ElecTemp_LP[i]):
2619 dataOut.EElecTemp_LP[i]=missing
2620 if numpy.isnan(dataOut.IonTemp_LP[i]):
2621 dataOut.EIonTemp_LP[i]=missing
2622 if numpy.isnan(dataOut.ElecTemp_LP[i]) or numpy.isnan(dataOut.EElecTemp_LP[i]):
2623 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2624
2625
2626 dataOut.DensityFinal=numpy.reshape(numpy.concatenate((dataOut.Density_DP,dataOut.Density_LP)),(1,-1))
2627 dataOut.EDensityFinal=numpy.reshape(numpy.concatenate((dataOut.EDensity_DP,dataOut.EDensity_LP)),(1,-1))
2628 dataOut.ElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.ElecTemp_DP,dataOut.ElecTemp_LP)),(1,-1))
2629 dataOut.EElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.EElecTemp_DP,dataOut.EElecTemp_LP)),(1,-1))
2630 dataOut.IonTempFinal=numpy.reshape(numpy.concatenate((dataOut.IonTemp_DP,dataOut.IonTemp_LP)),(1,-1))
2631 dataOut.EIonTempFinal=numpy.reshape(numpy.concatenate((dataOut.EIonTemp_DP,dataOut.EIonTemp_LP)),(1,-1))
2632 dataOut.PhyFinal=numpy.reshape(numpy.concatenate((dataOut.Phy_DP,dataOut.Phy_LP)),(1,-1))
2633 dataOut.EPhyFinal=numpy.reshape(numpy.concatenate((dataOut.EPhy_DP,dataOut.EPhy_LP)),(1,-1))
2634 dataOut.PheFinal=numpy.reshape(numpy.concatenate((dataOut.Phe_DP,dataOut.Phe_LP)),(1,-1))
2635 dataOut.EPheFinal=numpy.reshape(numpy.concatenate((dataOut.EPhe_DP,dataOut.EPhe_LP)),(1,-1))
2636
2637 nan_array_2=numpy.empty(dataOut.NACF-dataOut.NDP)
2638 nan_array_2[:]=numpy.nan
2639
2640 dataOut.acfs_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2641 dataOut.acfs_error_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2642 acfs_dp_aux=dataOut.acfs_to_save.transpose()
2643 acfs_error_dp_aux=dataOut.acfs_error_to_save.transpose()
2644 for i in range(dataOut.DPL):
2645 dataOut.acfs_DP[:,i]=numpy.concatenate((acfs_dp_aux[:,i],nan_array_2))
2646 dataOut.acfs_error_DP[:,i]=numpy.concatenate((acfs_error_dp_aux[:,i],nan_array_2))
2647 dataOut.acfs_DP=dataOut.acfs_DP.transpose()
2648 dataOut.acfs_error_DP=dataOut.acfs_error_DP.transpose()
2649
2650 dataOut.acfs_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2651 dataOut.acfs_error_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2652
2653 for i in range(dataOut.NACF):
2654 for j in range(dataOut.IBITS):
2655 if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0:
2656 dataOut.acfs_LP[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0]
2657 dataOut.acfs_LP[i,j]=max(min(dataOut.acfs_LP[i,j],1.0),-1.0)
2658
2659 dataOut.acfs_error_LP[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0]
2660 else:
2661 dataOut.acfs_LP[i,j]=numpy.nan
2662
2663 dataOut.acfs_error_LP[i,j]=numpy.nan
2664
2665 dataOut.acfs_LP=dataOut.acfs_LP.transpose()
2666 dataOut.acfs_error_LP=dataOut.acfs_error_LP.transpose()
2667
2668 return dataOut
2669
2670
2671 class ACFs(Operation):
2672 def __init__(self, **kwargs):
2673
2674 Operation.__init__(self, **kwargs)
2675
2676 self.aux=1
2677
2678 def run(self,dataOut):
2679
2680 if self.aux:
2681 self.taup=numpy.zeros(dataOut.DPL,'float32')
2682 self.pacf=numpy.zeros(dataOut.DPL,'float32')
2683 self.sacf=numpy.zeros(dataOut.DPL,'float32')
2684
2685 self.taup_full=numpy.zeros(dataOut.DPL,'float32')
2686 self.pacf_full=numpy.zeros(dataOut.DPL,'float32')
2687 self.sacf_full=numpy.zeros(dataOut.DPL,'float32')
2688 self.x_igcej=numpy.zeros(dataOut.DPL,'float32')
2689 self.y_igcej=numpy.zeros(dataOut.DPL,'float32')
2690 self.x_ibad=numpy.zeros(dataOut.DPL,'float32')
2691 self.y_ibad=numpy.zeros(dataOut.DPL,'float32')
2692 self.aux=0
2693
2694 dataOut.acfs_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2695 dataOut.acfs_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2696 dataOut.acfs_error_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2697 dataOut.acfs_error_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2698 dataOut.lags_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2699 dataOut.x_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2700 dataOut.x_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2701 dataOut.y_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2702 dataOut.y_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2703
2704 for i in range(dataOut.NSHTS):
2705
2706 acfm=dataOut.rhor[i][0]**2+dataOut.rhoi[i][0]**2
2707
2708 if acfm>0:
2709 cc=dataOut.rhor[i][0]/acfm
2710 ss=dataOut.rhoi[i][0]/acfm
2711 else:
2712 cc=1.
2713 ss=0.
2714
2715 # keep only uncontaminated data
2716 for l in range(dataOut.DPL):
2717 fact=dataOut.DH
2718 if (dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0):
2719
2720 self.pacf_full[l]=min(1.0,max(-1.0,(dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss)))*fact+dataOut.range1[i]
2721 self.sacf_full[l]=min(1.0,numpy.sqrt(dataOut.sd[i][l]))*fact
2722 self.taup_full[l]=dataOut.alag[l]
2723 self.x_igcej[l]=numpy.nan
2724 self.y_igcej[l]=numpy.nan
2725 self.x_ibad[l]=numpy.nan
2726 self.y_ibad[l]=numpy.nan
2727
2728 else:
2729 self.pacf_full[l]=numpy.nan
2730 self.sacf_full[l]=numpy.nan
2731 self.taup_full[l]=numpy.nan
2732
2733 if dataOut.igcej[i][l]:
2734 self.x_igcej[l]=dataOut.alag[l]
2735 self.y_igcej[l]=dataOut.range1[i]
2736 self.x_ibad[l]=numpy.nan
2737 self.y_ibad[l]=numpy.nan
2738
2739 if dataOut.ibad[i][l]:
2740 self.x_igcej[l]=numpy.nan
2741 self.y_igcej[l]=numpy.nan
2742 self.x_ibad[l]=dataOut.alag[l]
2743 self.y_ibad[l]=dataOut.range1[i]
2744
2745 pacf_new=numpy.copy((self.pacf_full-dataOut.range1[i])/dataOut.DH)
2746 sacf_new=numpy.copy(self.sacf_full/dataOut.DH)
2747 dataOut.acfs_to_save[i,:]=numpy.copy(pacf_new)
2748 dataOut.acfs_error_to_save[i,:]=numpy.copy(sacf_new)
2749 dataOut.acfs_to_plot[i,:]=numpy.copy(self.pacf_full)
2750 dataOut.acfs_error_to_plot[i,:]=numpy.copy(self.sacf_full)
2751 dataOut.lags_to_plot[i,:]=numpy.copy(self.taup_full)
2752 dataOut.x_igcej_to_plot[i,:]=numpy.copy(self.x_igcej)
2753 dataOut.x_ibad_to_plot[i,:]=numpy.copy(self.x_ibad)
2754 dataOut.y_igcej_to_plot[i,:]=numpy.copy(self.y_igcej)
2755 dataOut.y_ibad_to_plot[i,:]=numpy.copy(self.y_ibad)
2756
2757 missing=numpy.nan#-32767
2758
2759 for i in range(dataOut.NSHTS,dataOut.NDP):
2760 for j in range(dataOut.DPL):
2761 dataOut.acfs_to_save[i,j]=missing
2762 dataOut.acfs_error_to_save[i,j]=missing
2763 dataOut.acfs_to_plot[i,j]=missing
2764 dataOut.acfs_error_to_plot[i,j]=missing
2765 dataOut.lags_to_plot[i,j]=missing
2766 dataOut.x_igcej_to_plot[i,j]=missing
2767 dataOut.x_ibad_to_plot[i,j]=missing
2768 dataOut.y_igcej_to_plot[i,j]=missing
2769 dataOut.y_ibad_to_plot[i,j]=missing
2770
2771 dataOut.acfs_to_save=dataOut.acfs_to_save.transpose()
2772 dataOut.acfs_error_to_save=dataOut.acfs_error_to_save.transpose()
2773
2774 return dataOut
2775
2776
2777 class CohInt(Operation):
2778
2779 isConfig = False
2780 __profIndex = 0
2781 __byTime = False
2782 __initime = None
2783 __lastdatatime = None
2784 __integrationtime = None
2785 __buffer = None
2786 __bufferStride = []
2787 __dataReady = False
2788 __profIndexStride = 0
2789 __dataToPutStride = False
2790 n = None
2791
2792 def __init__(self, **kwargs):
2793
2794 Operation.__init__(self, **kwargs)
2795
2796 # self.isConfig = False
2797
2798 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
2799 """
2800 Set the parameters of the integration class.
2801
2802 Inputs:
2803
2804 n : Number of coherent integrations
2805 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
2806 overlapping :
2807 """
2808
2809 self.__initime = None
2810 self.__lastdatatime = 0
2811 self.__buffer = None
2812 self.__dataReady = False
2813 self.byblock = byblock
2814 self.stride = stride
2815
2816 if n == None and timeInterval == None:
2817 raise ValueError("n or timeInterval should be specified ...")
2818
2819 if n != None:
2820 self.n = n
2821 self.__byTime = False
2822 else:
2823 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
2824 self.n = 9999
2825 self.__byTime = True
2826
2827 if overlapping:
2828 self.__withOverlapping = True
2829 self.__buffer = None
2830 else:
2831 self.__withOverlapping = False
2832 self.__buffer = 0
2833
2834 self.__profIndex = 0
2835
2836 def putData(self, data):
2837
2838 """
2839 Add a profile to the __buffer and increase in one the __profileIndex
2840
2841 """
2842
2843 if not self.__withOverlapping:
2844 self.__buffer += data.copy()
2845 self.__profIndex += 1
2846 return
2847
2848 #Overlapping data
2849 nChannels, nHeis = data.shape
2850 data = numpy.reshape(data, (1, nChannels, nHeis))
2851
2852 #If the buffer is empty then it takes the data value
2853 if self.__buffer is None:
2854 self.__buffer = data
2855 self.__profIndex += 1
2856 return
2857
2858 #If the buffer length is lower than n then stakcing the data value
2859 if self.__profIndex < self.n:
2860 self.__buffer = numpy.vstack((self.__buffer, data))
2861 self.__profIndex += 1
2862 return
2863
2864 #If the buffer length is equal to n then replacing the last buffer value with the data value
2865 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
2866 self.__buffer[self.n-1] = data
2867 self.__profIndex = self.n
2868 return
2869
2870
2871 def pushData(self):
2872 """
2873 Return the sum of the last profiles and the profiles used in the sum.
2874
2875 Affected:
2876
2877 self.__profileIndex
2878
2879 """
2880
2881 if not self.__withOverlapping:
2882 data = self.__buffer
2883 n = self.__profIndex
2884
2885 self.__buffer = 0
2886 self.__profIndex = 0
2887
2888 return data, n
2889
2890 #Integration with Overlapping
2891 data = numpy.sum(self.__buffer, axis=0)
2892 # print data
2893 # raise
2894 n = self.__profIndex
2895
2896 return data, n
2897
2898 def byProfiles(self, data):
2899
2900 self.__dataReady = False
2901 avgdata = None
2902 # n = None
2903 # print data
2904 # raise
2905 self.putData(data)
2906
2907 if self.__profIndex == self.n:
2908 avgdata, n = self.pushData()
2909 self.__dataReady = True
2910
2911 return avgdata
2912
2913 def byTime(self, data, datatime):
2914
2915 self.__dataReady = False
2916 avgdata = None
2917 n = None
2918
2919 self.putData(data)
2920
2921 if (datatime - self.__initime) >= self.__integrationtime:
2922 avgdata, n = self.pushData()
2923 self.n = n
2924 self.__dataReady = True
2925
2926 return avgdata
2927
2928 def integrateByStride(self, data, datatime):
2929 # print data
2930 if self.__profIndex == 0:
2931 self.__buffer = [[data.copy(), datatime]]
2932 else:
2933 self.__buffer.append([data.copy(),datatime])
2934 self.__profIndex += 1
2935 self.__dataReady = False
2936
2937 if self.__profIndex == self.n * self.stride :
2938 self.__dataToPutStride = True
2939 self.__profIndexStride = 0
2940 self.__profIndex = 0
2941 self.__bufferStride = []
2942 for i in range(self.stride):
2943 current = self.__buffer[i::self.stride]
2944 data = numpy.sum([t[0] for t in current], axis=0)
2945 avgdatatime = numpy.average([t[1] for t in current])
2946 # print data
2947 self.__bufferStride.append((data, avgdatatime))
2948
2949 if self.__dataToPutStride:
2950 self.__dataReady = True
2951 self.__profIndexStride += 1
2952 if self.__profIndexStride == self.stride:
2953 self.__dataToPutStride = False
2954 # print self.__bufferStride[self.__profIndexStride - 1]
2955 # raise
2956 return self.__bufferStride[self.__profIndexStride - 1]
2957
2958
2959 return None, None
2960
2961 def integrate(self, data, datatime=None):
2962
2963 if self.__initime == None:
2964 self.__initime = datatime
2965
2966 if self.__byTime:
2967 avgdata = self.byTime(data, datatime)
2968 else:
2969 avgdata = self.byProfiles(data)
2970
2971
2972 self.__lastdatatime = datatime
2973
2974 if avgdata is None:
2975 return None, None
2976
2977 avgdatatime = self.__initime
2978
2979 deltatime = datatime - self.__lastdatatime
2980
2981 if not self.__withOverlapping:
2982 self.__initime = datatime
2983 else:
2984 self.__initime += deltatime
2985
2986 return avgdata, avgdatatime
2987
2988 def integrateByBlock(self, dataOut):
2989
2990 times = int(dataOut.data.shape[1]/self.n)
2991 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
2992
2993 id_min = 0
2994 id_max = self.n
2995
2996 for i in range(times):
2997 junk = dataOut.data[:,id_min:id_max,:]
2998 avgdata[:,i,:] = junk.sum(axis=1)
2999 id_min += self.n
3000 id_max += self.n
3001
3002 timeInterval = dataOut.ippSeconds*self.n
3003 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
3004 self.__dataReady = True
3005 return avgdata, avgdatatime
3006
3007 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
3008
3009 if not self.isConfig:
3010 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
3011 self.isConfig = True
3012 print("inside")
3013 if dataOut.flagDataAsBlock:
3014 """
3015 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
3016 """
3017
3018 avgdata, avgdatatime = self.integrateByBlock(dataOut)
3019 dataOut.nProfiles /= self.n
3020 else:
3021 if stride is None:
3022 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
3023 else:
3024 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
3025
3026
3027 # dataOut.timeInterval *= n
3028 dataOut.flagNoData = True
3029
3030 if self.__dataReady:
3031 dataOut.data = avgdata
3032 if not dataOut.flagCohInt:
3033 dataOut.nCohInt *= self.n
3034 dataOut.flagCohInt = True
3035 dataOut.utctime = avgdatatime
3036 # print avgdata, avgdatatime
3037 # raise
3038 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
3039 dataOut.flagNoData = False
3040 return dataOut
3041
3042 class TimesCode(Operation):
3043 """
3044
3045 """
3046
3047 def __init__(self, **kwargs):
3048
3049 Operation.__init__(self, **kwargs)
3050
3051
3052
3053 def run(self,dataOut,code):
3054
3055 #code = numpy.repeat(code, repeats=osamp, axis=1)
3056 nCodes = numpy.shape(code)[1]
3057 #nprofcode = dataOut.nProfiles//nCodes
3058 code = numpy.array(code)
3059 #print("nHeights",dataOut.nHeights)
3060 #print("nheicode",nheicode)
3061 #print("Code.Shape",numpy.shape(code))
3062 #print("Code",code[0,:])
3063 nheicode = dataOut.nHeights//nCodes
3064 res = dataOut.nHeights%nCodes
3065 '''
3066 buffer = numpy.zeros((dataOut.nChannels,
3067 nprofcode,
3068 nCodes,
3069 ndataOut.nHeights),
3070 dtype='complex')
3071 '''
3072 #exit(1)
3073 #for ipr in range(dataOut.nProfiles):
3074 #print(dataOut.nHeights)
3075 #print(dataOut.data[0,384-2:])
3076 #print(dataOut.profileIndex)
3077 #print(dataOut.data[0,:2])
3078 #print(dataOut.data[0,0:64])
3079 #print(dataOut.data[0,64:64+64])
3080 #exit(1)
3081 for ich in range(dataOut.nChannels):
3082 for ihe in range(nheicode):
3083 #print(ihe*nCodes)
3084 #print((ihe+1)*nCodes)
3085 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]
3086 #code[ipr,:]
3087 #print("before",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3088 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)],code[ipr,:]],axis=0)
3089 dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)],code[dataOut.profileIndex,:]],axis=0)
3090
3091 #print("after",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3092 #exit(1)
3093 #print(dataOut.data[0,:2])
3094 #exit(1)
3095 #print(nheicode)
3096 #print((nheicode)*nCodes)
3097 #print(((nheicode)*nCodes)+res)
3098 if res != 0:
3099 for ich in range(dataOut.nChannels):
3100 dataOut.data[ich,nheicode*nCodes:] = numpy.prod([dataOut.data[ich,nheicode*nCodes:],code[dataOut.profileIndex,:res]],axis=0)
3101
3102 #pass
3103 #print(dataOut.data[0,384-2:])
3104 #exit(1)
3105 #dataOut.data = numpy.mean(buffer,axis=1)
3106 #print(numpy.shape(dataOut.data))
3107 #print(dataOut.nHeights)
3108 #dataOut.heightList = dataOut.heightList[0:nheicode]
3109 #print(dataOut.nHeights)
3110 #dataOut.nHeights = numpy.shape(dataOut.data)[2]
3111 #print(numpy.shape(dataOut.data))
3112 #exit(1)
3113
3114 return dataOut
3115
3116 '''
3117 class Spectrogram(Operation):
3118 """
3119
3120 """
3121
3122 def __init__(self, **kwargs):
3123
3124 Operation.__init__(self, **kwargs)
3125
3126
3127
3128 def run(self,dataOut):
3129
3130 import scipy
3131
3132
3133
3134 fs = 3200*1e-6
3135 fs = fs/64
3136 fs = 1/fs
3137
3138 nperseg=64
3139 noverlap=48
3140
3141 f, t, Sxx = signal.spectrogram(x, fs, return_onesided=False, nperseg=nperseg, noverlap=noverlap, mode='complex')
3142
3143
3144 for ich in range(dataOut.nChannels):
3145 for ihe in range(nheicode):
3146
3147
3148 return dataOut
3149 '''
3150
3151
3152 class RemoveDcHae(Operation):
3153
3154 def __init__(self, **kwargs):
3155
3156 Operation.__init__(self, **kwargs)
3157 self.DcCounter = 0
3158
3159 def run(self, dataOut):
3160
3161 if self.DcCounter == 0:
3162 dataOut.DcHae = numpy.zeros((dataOut.data.shape[0],320),dtype='complex')
3163 #dataOut.DcHae = []
3164 self.DcCounter = 1
3165
3166 dataOut.dataaux = numpy.copy(dataOut.data)
3167
3168 #dataOut.DcHae += dataOut.dataaux[:,1666:1666+320]
3169 dataOut.DcHae += dataOut.dataaux[:,0:0+320]
3170 hei = 1666
3171 hei = 2000
3172 hei = 1000
3173 hei = 0
3174 #dataOut.DcHae = numpy.concatenate([dataOut.DcHae,dataOut.dataaux[0,hei]],axis = None)
3175
3176
3177
3178 return dataOut
3179
3180
3181 class SSheightProfiles(Operation):
3182
3183 step = None
3184 nsamples = None
3185 bufferShape = None
3186 profileShape = None
3187 sshProfiles = None
3188 profileIndex = None
3189
3190 def __init__(self, **kwargs):
3191
3192 Operation.__init__(self, **kwargs)
3193 self.isConfig = False
3194
3195 def setup(self,dataOut ,step = None , nsamples = None):
3196
3197 if step == None and nsamples == None:
3198 #pass
3199 raise ValueError("step or nheights should be specified ...")
3200
3201 self.step = step
3202 self.nsamples = nsamples
3203 self.__nChannels = dataOut.nChannels
3204 self.__nProfiles = dataOut.nProfiles
3205 self.__nHeis = dataOut.nHeights
3206 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
3207 '''
3208 print "input nChannels",self.__nChannels
3209 print "input nProfiles",self.__nProfiles
3210 print "input nHeis",self.__nHeis
3211 print "input Shape",shape
3212 '''
3213
3214
3215 residue = (shape[1] - self.nsamples) % self.step
3216 if residue != 0:
3217 print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue))
3218
3219 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3220 numberProfile = self.nsamples
3221 numberSamples = (shape[1] - self.nsamples)/self.step
3222 '''
3223 print "new numberProfile",numberProfile
3224 print "new numberSamples",numberSamples
3225
3226 print "New number of profile: %d, number of height: %d, Resolution %f Km"%(numberProfile,numberSamples,deltaHeight*self.step)
3227 '''
3228 self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles
3229 self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples
3230
3231 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
3232 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
3233
3234 def run(self, dataOut, step, nsamples, code = None, repeat = None):
3235 #print(dataOut.profileIndex)
3236 dataOut.flagNoData = True
3237 dataOut.flagDataAsBlock = False
3238 profileIndex = None
3239
3240 #code = numpy.array(code)
3241 #print(dataOut.data[0,:])
3242 #exit(1)
3243
3244
3245 if not self.isConfig:
3246 #print("STEP",step)
3247 self.setup(dataOut, step=step , nsamples=nsamples)
3248 self.isConfig = True
3249 #print(code[dataOut.profileIndex,:])
3250
3251 #DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3252 DC_Hae = numpy.array([ 0.001025 +0.0516375j, 0.03485 +0.20923125j, -0.168 -0.02720625j,
3253 -0.1105375 +0.0707125j, -0.20309375-0.09670625j, 0.189775 +0.02716875j])*(-3.5)
3254
3255 DC_Hae = numpy.array([ -32.26 +8.66j, -32.26 +8.66j])
3256
3257 DC_Hae = numpy.array([-2.78500000e-01 -1.39175j, -6.63237294e+02+210.4268625j])
3258
3259
3260
3261
3262
3263
3264 #print(dataOut.data[0,13:15])
3265 dataOut.data = dataOut.data - DC_Hae[:,None]
3266 #print(dataOut.data[0,13:15])
3267 #exit(1)
3268
3269
3270
3271 code = numpy.array(code)
3272 roll = 0
3273 code = numpy.roll(code,roll,axis=0)
3274 code = numpy.reshape(code,(5,100,64))
3275 block = dataOut.CurrentBlock%5
3276 #print(block)
3277
3278 #code_block = code[block-1-2,:,:]
3279 day_dif = 1 #day_12
3280 code_block = code[block-1-0,:,:]
3281
3282 if repeat is not None:
3283 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3284
3285
3286
3287 #print(dataOut.data[0:2,13])
3288 for i in range(self.buffer.shape[1]):
3289 #self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3290 '''
3291 print(dataOut.profileIndex)
3292 print(code[dataOut.profileIndex,:])
3293 print("before",dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3294 print("after",dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code[dataOut.profileIndex,:])
3295 exit(1)
3296 '''
3297
3298 #dif = numpy.copy(code)
3299 if code is not None:
3300 '''
3301 code = numpy.array(code)
3302 #print(code[0,:])
3303
3304 #print("There is Code")
3305 #exit(1)
3306 #code = dataOut.code
3307 #print(code[0,:])
3308 #exit(1)
3309
3310 roll = 0
3311 code = numpy.roll(code,roll,axis=0)
3312 code = numpy.reshape(code,(5,100,64))
3313 block = dataOut.CurrentBlock%5
3314 #print(block)
3315
3316 #code_block = code[block-1-2,:,:]
3317 day_dif = 1 #day_12
3318 code_block = code[block-1-0,:,:]
3319
3320
3321
3322 if repeat is not None:
3323 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3324 '''
3325
3326
3327
3328 #code_block = code[0,:,:]
3329
3330 #print(code_block[2,:])
3331 #for l in range(dataOut.data.shape[1]):
3332 #dataOut.data[:,l] = dataOut.data[:,l] - numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3333
3334 ##DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3335
3336 #print(dataOut.data[0:2,13])
3337 ##dataOut.data = dataOut.data - DC_Hae[:,None]
3338 #print(dataOut.data[0:2,13])
3339 #exit(1)
3340 #print(dataOut.data[0,i*self.step:i*self.step + self.nsamples])
3341 #print(dataOut.data[1,i*self.step:i*self.step + self.nsamples])
3342 #print(code_block[dataOut.profileIndex,:])
3343 #print(numpy.shape(code_block[dataOut.profileIndex,:]))
3344 #exit(1)
3345 ###aux = numpy.mean(dataOut.data[:,i*self.step:i*self.step + self.nsamples],axis=1)
3346 ###self.buffer[:,i] = (dataOut.data[:,i*self.step:i*self.step + self.nsamples]-aux[:,None])*code_block[dataOut.profileIndex,:]
3347 '''
3348 if i == 18:
3349 buffer = dataOut.data[0,i*self.step:i*self.step + self.nsamples]
3350 import matplotlib.pyplot as plt
3351 fig, axes = plt.subplots(figsize=(14, 10))
3352 x = numpy.linspace(0,20,numpy.shape(buffer)[0])
3353 x = numpy.fft.fftfreq(numpy.shape(buffer)[0],0.00005)
3354 x = numpy.fft.fftshift(x)
3355
3356 plt.plot(x,buffer)
3357 plt.show()
3358 import time
3359 time.sleep(50)
3360 '''
3361 #for k in range(dataOut.nChannels):
3362 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block[dataOut.profileIndex,:]
3363 #print(dataOut.data[0,:])
3364 #print(code_block[0,:])
3365 #print(self.buffer[1,i])
3366 #exit(1)
3367 else:
3368 #print("There is no Code")
3369 #exit(1)
3370 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:]
3371
3372 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
3373
3374 for j in range(self.buffer.shape[0]):
3375 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
3376
3377 profileIndex = self.nsamples
3378 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3379 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
3380 #print "ippSeconds",ippSeconds
3381 try:
3382 if dataOut.concat_m is not None:
3383 ippSeconds= ippSeconds/float(dataOut.concat_m)
3384 #print "Profile concat %d"%dataOut.concat_m
3385 except:
3386 pass
3387
3388
3389
3390 dataOut.data = self.sshProfiles
3391 dataOut.flagNoData = False
3392 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
3393 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
3394
3395 '''
3396 print(dataOut.profileIndex)
3397 if dataOut.profileIndex == 0:
3398 dataOut.data = dataOut.data*1.e5
3399
3400 buffer_prom =
3401 '''
3402 #dataOut.utctime = dataOut.utctime - dataOut.profileIndex
3403 #print(dataOut.profileIndex)
3404 #print(dataOut.data[0,0,0])
3405 '''
3406 if dataOut.profileIndex == 0:
3407 self.buffer_prom = numpy.copy(dataOut.data)
3408
3409 else:
3410 self.buffer_prom = dataOut.data+self.buffer_prom
3411 if dataOut.profileIndex == 99:
3412 dataOut.data = self.buffer_prom/100
3413 '''
3414
3415 #print(dataOut.data[0,0,0])
3416 #print(dataOut.profileIndex)
3417 dataOut.profileIndex = profileIndex
3418 dataOut.flagDataAsBlock = True
3419 dataOut.ippSeconds = ippSeconds
3420 dataOut.step = self.step
3421 #print(dataOut.profileIndex)
3422 #print(dataOut.heightList)
3423 #exit(1)
3424
3425 #print(dataOut.times)
3426
3427 return dataOut
3428
3429 class Decoder(Operation):
3430
3431 isConfig = False
3432 __profIndex = 0
3433
3434 code = None
3435
3436 nCode = None
3437 nBaud = None
3438
3439 def __init__(self, **kwargs):
3440
3441 Operation.__init__(self, **kwargs)
3442
3443 self.times = None
3444 self.osamp = None
3445 # self.__setValues = False
3446 self.isConfig = False
3447 self.setupReq = False
3448 def setup(self, code, osamp, dataOut):
3449
3450 self.__profIndex = 0
3451
3452 self.code = code
3453
3454 self.nCode = len(code)
3455 self.nBaud = len(code[0])
3456
3457 if (osamp != None) and (osamp >1):
3458 self.osamp = osamp
3459 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3460 self.nBaud = self.nBaud*self.osamp
3461
3462 self.__nChannels = dataOut.nChannels
3463 self.__nProfiles = dataOut.nProfiles
3464 self.__nHeis = dataOut.nHeights
3465
3466 if self.__nHeis < self.nBaud:
3467 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3468
3469 #Frequency
3470 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3471
3472 __codeBuffer[:,0:self.nBaud] = self.code
3473
3474 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3475
3476 if dataOut.flagDataAsBlock:
3477
3478 self.ndatadec = self.__nHeis #- self.nBaud + 1
3479
3480 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3481
3482 else:
3483
3484 #Time
3485 self.ndatadec = self.__nHeis #- self.nBaud + 1
3486
3487
3488 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3489
3490 def __convolutionInFreq(self, data):
3491
3492 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3493
3494 fft_data = numpy.fft.fft(data, axis=1)
3495
3496 conv = fft_data*fft_code
3497
3498 data = numpy.fft.ifft(conv,axis=1)
3499
3500 return data
3501
3502 def __convolutionInFreqOpt(self, data):
3503
3504 raise NotImplementedError
3505
3506 def __convolutionInTime(self, data):
3507
3508 code = self.code[self.__profIndex]
3509 for i in range(self.__nChannels):
3510 #aux=numpy.correlate(data[i,:], code, mode='full')
3511 #print(numpy.shape(aux))
3512 #print(numpy.shape(data[i,:]))
3513 #print(numpy.shape(code))
3514 #exit(1)
3515 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3516
3517 return self.datadecTime
3518
3519 def __convolutionByBlockInTime(self, data):
3520
3521 repetitions = int(self.__nProfiles / self.nCode)
3522 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3523 junk = junk.flatten()
3524 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3525 profilesList = range(self.__nProfiles)
3526 #print(numpy.shape(self.datadecTime))
3527 #print(numpy.shape(data))
3528 for i in range(self.__nChannels):
3529 for j in profilesList:
3530 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3531 return self.datadecTime
3532
3533 def __convolutionByBlockInFreq(self, data):
3534
3535 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3536
3537
3538 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3539
3540 fft_data = numpy.fft.fft(data, axis=2)
3541
3542 conv = fft_data*fft_code
3543
3544 data = numpy.fft.ifft(conv,axis=2)
3545
3546 return data
3547
3548
3549 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3550
3551 if dataOut.flagDecodeData:
3552 print("This data is already decoded, recoding again ...")
3553
3554 if not self.isConfig:
3555
3556 if code is None:
3557 if dataOut.code is None:
3558 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3559
3560 code = dataOut.code
3561 else:
3562 code = numpy.array(code).reshape(nCode,nBaud)
3563 self.setup(code, osamp, dataOut)
3564
3565 self.isConfig = True
3566
3567 if mode == 3:
3568 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3569
3570 if times != None:
3571 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3572
3573 if self.code is None:
3574 print("Fail decoding: Code is not defined.")
3575 return
3576
3577 self.__nProfiles = dataOut.nProfiles
3578 datadec = None
3579
3580 if mode == 3:
3581 mode = 0
3582
3583 if dataOut.flagDataAsBlock:
3584 """
3585 Decoding when data have been read as block,
3586 """
3587
3588 if mode == 0:
3589 datadec = self.__convolutionByBlockInTime(dataOut.data)
3590 if mode == 1:
3591 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3592 else:
3593 """
3594 Decoding when data have been read profile by profile
3595 """
3596 if mode == 0:
3597 datadec = self.__convolutionInTime(dataOut.data)
3598
3599 if mode == 1:
3600 datadec = self.__convolutionInFreq(dataOut.data)
3601
3602 if mode == 2:
3603 datadec = self.__convolutionInFreqOpt(dataOut.data)
3604
3605 if datadec is None:
3606 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3607
3608 dataOut.code = self.code
3609 dataOut.nCode = self.nCode
3610 dataOut.nBaud = self.nBaud
3611
3612 dataOut.data = datadec
3613 #print("before",dataOut.heightList)
3614 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3615 #print("after",dataOut.heightList)
3616
3617 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3618
3619 if self.__profIndex == self.nCode-1:
3620 self.__profIndex = 0
3621 return dataOut
3622
3623 self.__profIndex += 1
3624
3625 #print("SHAPE",numpy.shape(dataOut.data))
3626
3627 return dataOut
3628 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
3629
3630 class DecoderRoll(Operation):
3631
3632 isConfig = False
3633 __profIndex = 0
3634
3635 code = None
3636
3637 nCode = None
3638 nBaud = None
3639
3640 def __init__(self, **kwargs):
3641
3642 Operation.__init__(self, **kwargs)
3643
3644 self.times = None
3645 self.osamp = None
3646 # self.__setValues = False
3647 self.isConfig = False
3648 self.setupReq = False
3649 def setup(self, code, osamp, dataOut):
3650
3651 self.__profIndex = 0
3652
3653
3654 self.code = code
3655
3656 self.nCode = len(code)
3657 self.nBaud = len(code[0])
3658
3659 if (osamp != None) and (osamp >1):
3660 self.osamp = osamp
3661 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3662 self.nBaud = self.nBaud*self.osamp
3663
3664 self.__nChannels = dataOut.nChannels
3665 self.__nProfiles = dataOut.nProfiles
3666 self.__nHeis = dataOut.nHeights
3667
3668 if self.__nHeis < self.nBaud:
3669 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3670
3671 #Frequency
3672 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3673
3674 __codeBuffer[:,0:self.nBaud] = self.code
3675
3676 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3677
3678 if dataOut.flagDataAsBlock:
3679
3680 self.ndatadec = self.__nHeis #- self.nBaud + 1
3681
3682 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3683
3684 else:
3685
3686 #Time
3687 self.ndatadec = self.__nHeis #- self.nBaud + 1
3688
3689
3690 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3691
3692 def __convolutionInFreq(self, data):
3693
3694 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3695
3696 fft_data = numpy.fft.fft(data, axis=1)
3697
3698 conv = fft_data*fft_code
3699
3700 data = numpy.fft.ifft(conv,axis=1)
3701
3702 return data
3703
3704 def __convolutionInFreqOpt(self, data):
3705
3706 raise NotImplementedError
3707
3708 def __convolutionInTime(self, data):
3709
3710 code = self.code[self.__profIndex]
3711 #print("code",code[0,0])
3712 for i in range(self.__nChannels):
3713 #aux=numpy.correlate(data[i,:], code, mode='full')
3714 #print(numpy.shape(aux))
3715 #print(numpy.shape(data[i,:]))
3716 #print(numpy.shape(code))
3717 #exit(1)
3718 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3719
3720 return self.datadecTime
3721
3722 def __convolutionByBlockInTime(self, data):
3723
3724 repetitions = int(self.__nProfiles / self.nCode)
3725 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3726 junk = junk.flatten()
3727 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3728 profilesList = range(self.__nProfiles)
3729 #print(numpy.shape(self.datadecTime))
3730 #print(numpy.shape(data))
3731 for i in range(self.__nChannels):
3732 for j in profilesList:
3733 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3734 return self.datadecTime
3735
3736 def __convolutionByBlockInFreq(self, data):
3737
3738 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3739
3740
3741 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3742
3743 fft_data = numpy.fft.fft(data, axis=2)
3744
3745 conv = fft_data*fft_code
3746
3747 data = numpy.fft.ifft(conv,axis=2)
3748
3749 return data
3750
3751
3752 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3753
3754 if dataOut.flagDecodeData:
3755 print("This data is already decoded, recoding again ...")
3756
3757
3758
3759 #print(dataOut.ippSeconds)
3760 #exit(1)
3761 roll = 0
3762
3763 if self.isConfig:
3764 code = numpy.array(code)
3765
3766 #roll = 29
3767 code = numpy.roll(code,roll,axis=0)
3768 code = numpy.reshape(code,(5,100,64))
3769 block = dataOut.CurrentBlock%5
3770 #code = code[block-1,:,:] #NormalizeDPPower
3771 code = code[block-1-1,:,:] #Next Day
3772 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3773
3774
3775 if not self.isConfig:
3776
3777 if code is None:
3778 if dataOut.code is None:
3779 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3780
3781 code = dataOut.code
3782 else:
3783 code = numpy.array(code)
3784
3785 #roll = 29
3786 code = numpy.roll(code,roll,axis=0)
3787 code = numpy.reshape(code,(5,100,64))
3788 block = dataOut.CurrentBlock%5
3789 code = code[block-1-1,:,:]
3790 #print(code.shape())
3791 #exit(1)
3792
3793 code = numpy.array(code).reshape(nCode,nBaud)
3794 self.setup(code, osamp, dataOut)
3795
3796 self.isConfig = True
3797
3798 if mode == 3:
3799 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3800
3801 if times != None:
3802 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3803
3804 if self.code is None:
3805 print("Fail decoding: Code is not defined.")
3806 return
3807
3808 self.__nProfiles = dataOut.nProfiles
3809 datadec = None
3810
3811 if mode == 3:
3812 mode = 0
3813
3814 if dataOut.flagDataAsBlock:
3815 """
3816 Decoding when data have been read as block,
3817 """
3818
3819 if mode == 0:
3820 datadec = self.__convolutionByBlockInTime(dataOut.data)
3821 if mode == 1:
3822 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3823 else:
3824 """
3825 Decoding when data have been read profile by profile
3826 """
3827 if mode == 0:
3828 datadec = self.__convolutionInTime(dataOut.data)
3829
3830 if mode == 1:
3831 datadec = self.__convolutionInFreq(dataOut.data)
3832
3833 if mode == 2:
3834 datadec = self.__convolutionInFreqOpt(dataOut.data)
3835
3836 if datadec is None:
3837 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3838
3839 dataOut.code = self.code
3840 dataOut.nCode = self.nCode
3841 dataOut.nBaud = self.nBaud
3842
3843 dataOut.data = datadec
3844 #print("before",dataOut.heightList)
3845 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3846 #print("after",dataOut.heightList)
3847
3848 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3849
3850 if self.__profIndex == self.nCode-1:
3851 self.__profIndex = 0
3852 return dataOut
3853
3854 self.__profIndex += 1
3855
3856 #print("SHAPE",numpy.shape(dataOut.data))
3857
3858 return dataOut
3859
3860
3861
3862
3863
3864
3865 class ProfileConcat(Operation):
3866
3867 isConfig = False
3868 buffer = None
3869
3870 def __init__(self, **kwargs):
3871
3872 Operation.__init__(self, **kwargs)
3873 self.profileIndex = 0
3874
3875 def reset(self):
3876 self.buffer = numpy.zeros_like(self.buffer)
3877 self.start_index = 0
3878 self.times = 1
3879
3880 def setup(self, data, m, n=1):
3881 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
3882 self.nHeights = data.shape[1]#.nHeights
3883 self.start_index = 0
3884 self.times = 1
3885
3886 def concat(self, data):
3887
3888 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
3889 self.start_index = self.start_index + self.nHeights
3890
3891 def run(self, dataOut, m):
3892 dataOut.flagNoData = True
3893
3894 if not self.isConfig:
3895 self.setup(dataOut.data, m, 1)
3896 self.isConfig = True
3897
3898 if dataOut.flagDataAsBlock:
3899 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
3900
3901 else:
3902 self.concat(dataOut.data)
3903 self.times += 1
3904 if self.times > m:
3905 dataOut.data = self.buffer
3906 self.reset()
3907 dataOut.flagNoData = False
3908 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
3909 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3910 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
3911 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
3912 dataOut.ippSeconds *= m
3913 return dataOut
3914
3915 class ProfileSelector(Operation):
3916
3917 profileIndex = None
3918 # Tamanho total de los perfiles
3919 nProfiles = None
3920
3921 def __init__(self, **kwargs):
3922
3923 Operation.__init__(self, **kwargs)
3924 self.profileIndex = 0
3925
3926 def incProfileIndex(self):
3927
3928 self.profileIndex += 1
3929
3930 if self.profileIndex >= self.nProfiles:
3931 self.profileIndex = 0
3932
3933 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
3934
3935 if profileIndex < minIndex:
3936 return False
3937
3938 if profileIndex > maxIndex:
3939 return False
3940
3941 return True
3942
3943 def isThisProfileInList(self, profileIndex, profileList):
3944
3945 if profileIndex not in profileList:
3946 return False
3947
3948 return True
3949
3950 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
3951
3952 """
3953 ProfileSelector:
3954
3955 Inputs:
3956 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
3957
3958 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
3959
3960 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
3961
3962 """
3963
3964 if rangeList is not None:
3965 if type(rangeList[0]) not in (tuple, list):
3966 rangeList = [rangeList]
3967
3968 dataOut.flagNoData = True
3969
3970 if dataOut.flagDataAsBlock:
3971 """
3972 data dimension = [nChannels, nProfiles, nHeis]
3973 """
3974 if profileList != None:
3975 dataOut.data = dataOut.data[:,profileList,:]
3976
3977 if profileRangeList != None:
3978 minIndex = profileRangeList[0]
3979 maxIndex = profileRangeList[1]
3980 profileList = list(range(minIndex, maxIndex+1))
3981
3982 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
3983
3984 if rangeList != None:
3985
3986 profileList = []
3987
3988 for thisRange in rangeList:
3989 minIndex = thisRange[0]
3990 maxIndex = thisRange[1]
3991
3992 profileList.extend(list(range(minIndex, maxIndex+1)))
3993
3994 dataOut.data = dataOut.data[:,profileList,:]
3995
3996 dataOut.nProfiles = len(profileList)
3997 dataOut.profileIndex = dataOut.nProfiles - 1
3998 dataOut.flagNoData = False
3999
4000 return dataOut
4001
4002 """
4003 data dimension = [nChannels, nHeis]
4004 """
4005
4006 if profileList != None:
4007
4008 if self.isThisProfileInList(dataOut.profileIndex, profileList):
4009
4010 self.nProfiles = len(profileList)
4011 dataOut.nProfiles = self.nProfiles
4012 dataOut.profileIndex = self.profileIndex
4013 dataOut.flagNoData = False
4014
4015 self.incProfileIndex()
4016 return dataOut
4017
4018 if profileRangeList != None:
4019
4020 minIndex = profileRangeList[0]
4021 maxIndex = profileRangeList[1]
4022
4023 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4024
4025 self.nProfiles = maxIndex - minIndex + 1
4026 dataOut.nProfiles = self.nProfiles
4027 dataOut.profileIndex = self.profileIndex
4028 dataOut.flagNoData = False
4029
4030 self.incProfileIndex()
4031 return dataOut
4032
4033 if rangeList != None:
4034
4035 nProfiles = 0
4036
4037 for thisRange in rangeList:
4038 minIndex = thisRange[0]
4039 maxIndex = thisRange[1]
4040
4041 nProfiles += maxIndex - minIndex + 1
4042
4043 for thisRange in rangeList:
4044
4045 minIndex = thisRange[0]
4046 maxIndex = thisRange[1]
4047
4048 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4049
4050 self.nProfiles = nProfiles
4051 dataOut.nProfiles = self.nProfiles
4052 dataOut.profileIndex = self.profileIndex
4053 dataOut.flagNoData = False
4054
4055 self.incProfileIndex()
4056
4057 break
4058
4059 return dataOut
4060
4061
4062 if beam != None: #beam is only for AMISR data
4063 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
4064 dataOut.flagNoData = False
4065 dataOut.profileIndex = self.profileIndex
4066
4067 self.incProfileIndex()
4068
4069 return dataOut
4070
4071 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
4072
4073 #return False
4074 return dataOut
4075
4076 class Reshaper(Operation):
4077
4078 def __init__(self, **kwargs):
4079
4080 Operation.__init__(self, **kwargs)
4081
4082 self.__buffer = None
4083 self.__nitems = 0
4084
4085 def __appendProfile(self, dataOut, nTxs):
4086
4087 if self.__buffer is None:
4088 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
4089 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
4090
4091 ini = dataOut.nHeights * self.__nitems
4092 end = ini + dataOut.nHeights
4093
4094 self.__buffer[:, ini:end] = dataOut.data
4095
4096 self.__nitems += 1
4097
4098 return int(self.__nitems*nTxs)
4099
4100 def __getBuffer(self):
4101
4102 if self.__nitems == int(1./self.__nTxs):
4103
4104 self.__nitems = 0
4105
4106 return self.__buffer.copy()
4107
4108 return None
4109
4110 def __checkInputs(self, dataOut, shape, nTxs):
4111
4112 if shape is None and nTxs is None:
4113 raise ValueError("Reshaper: shape of factor should be defined")
4114
4115 if nTxs:
4116 if nTxs < 0:
4117 raise ValueError("nTxs should be greater than 0")
4118
4119 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
4120 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
4121
4122 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
4123
4124 return shape, nTxs
4125
4126 if len(shape) != 2 and len(shape) != 3:
4127 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
4128
4129 if len(shape) == 2:
4130 shape_tuple = [dataOut.nChannels]
4131 shape_tuple.extend(shape)
4132 else:
4133 shape_tuple = list(shape)
4134
4135 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
4136
4137 return shape_tuple, nTxs
4138
4139 def run(self, dataOut, shape=None, nTxs=None):
4140
4141 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
4142
4143 dataOut.flagNoData = True
4144 profileIndex = None
4145
4146 if dataOut.flagDataAsBlock:
4147
4148 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
4149 dataOut.flagNoData = False
4150
4151 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
4152
4153 else:
4154
4155
4156 if self.__nTxs < 1:
4157
4158 self.__appendProfile(dataOut, self.__nTxs)
4159 new_data = self.__getBuffer()
4160
4161 if new_data is not None:
4162 dataOut.data = new_data
4163 dataOut.flagNoData = False
4164
4165 profileIndex = dataOut.profileIndex*nTxs
4166
4167 else:
4168 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
4169
4170 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4171
4172 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
4173
4174 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
4175
4176 dataOut.profileIndex = profileIndex
4177
4178 dataOut.ippSeconds /= self.__nTxs
4179
4180 return dataOut
4181
4182 class SplitProfiles(Operation):
4183
4184 def __init__(self, **kwargs):
4185
4186 Operation.__init__(self, **kwargs)
4187
4188 def run(self, dataOut, n):
4189
4190 dataOut.flagNoData = True
4191 profileIndex = None
4192
4193 if dataOut.flagDataAsBlock:
4194
4195 #nchannels, nprofiles, nsamples
4196 shape = dataOut.data.shape
4197
4198 if shape[2] % n != 0:
4199 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
4200
4201 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
4202
4203 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4204 dataOut.flagNoData = False
4205
4206 profileIndex = int(dataOut.nProfiles/n) - 1
4207
4208 else:
4209
4210 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
4211
4212 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4213
4214 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
4215
4216 dataOut.nProfiles = int(dataOut.nProfiles*n)
4217
4218 dataOut.profileIndex = profileIndex
4219
4220 dataOut.ippSeconds /= n
4221
4222 return dataOut
4223
4224 class CombineProfiles(Operation):
4225 def __init__(self, **kwargs):
4226
4227 Operation.__init__(self, **kwargs)
4228
4229 self.__remData = None
4230 self.__profileIndex = 0
4231
4232 def run(self, dataOut, n):
4233
4234 dataOut.flagNoData = True
4235 profileIndex = None
4236
4237 if dataOut.flagDataAsBlock:
4238
4239 #nchannels, nprofiles, nsamples
4240 shape = dataOut.data.shape
4241 new_shape = shape[0], shape[1]/n, shape[2]*n
4242
4243 if shape[1] % n != 0:
4244 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
4245
4246 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4247 dataOut.flagNoData = False
4248
4249 profileIndex = int(dataOut.nProfiles*n) - 1
4250
4251 else:
4252
4253 #nchannels, nsamples
4254 if self.__remData is None:
4255 newData = dataOut.data
4256 else:
4257 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
4258
4259 self.__profileIndex += 1
4260
4261 if self.__profileIndex < n:
4262 self.__remData = newData
4263 #continue
4264 return
4265
4266 self.__profileIndex = 0
4267 self.__remData = None
4268
4269 dataOut.data = newData
4270 dataOut.flagNoData = False
4271
4272 profileIndex = dataOut.profileIndex/n
4273
4274
4275 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4276
4277 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
4278
4279 dataOut.nProfiles = int(dataOut.nProfiles/n)
4280
4281 dataOut.profileIndex = profileIndex
4282
4283 dataOut.ippSeconds *= n
4284
4285 return dataOut
4286 # import collections
4287 # from scipy.stats import mode
4288 #
4289 # class Synchronize(Operation):
4290 #
4291 # isConfig = False
4292 # __profIndex = 0
4293 #
4294 # def __init__(self, **kwargs):
4295 #
4296 # Operation.__init__(self, **kwargs)
4297 # # self.isConfig = False
4298 # self.__powBuffer = None
4299 # self.__startIndex = 0
4300 # self.__pulseFound = False
4301 #
4302 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
4303 #
4304 # #Read data
4305 #
4306 # powerdB = dataOut.getPower(channel = channel)
4307 # noisedB = dataOut.getNoise(channel = channel)[0]
4308 #
4309 # self.__powBuffer.extend(powerdB.flatten())
4310 #
4311 # dataArray = numpy.array(self.__powBuffer)
4312 #
4313 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
4314 #
4315 # maxValue = numpy.nanmax(filteredPower)
4316 #
4317 # if maxValue < noisedB + 10:
4318 # #No se encuentra ningun pulso de transmision
4319 # return None
4320 #
4321 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
4322 #
4323 # if len(maxValuesIndex) < 2:
4324 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
4325 # return None
4326 #
4327 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
4328 #
4329 # #Seleccionar solo valores con un espaciamiento de nSamples
4330 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
4331 #
4332 # if len(pulseIndex) < 2:
4333 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4334 # return None
4335 #
4336 # spacing = pulseIndex[1:] - pulseIndex[:-1]
4337 #
4338 # #remover senales que se distancien menos de 10 unidades o muestras
4339 # #(No deberian existir IPP menor a 10 unidades)
4340 #
4341 # realIndex = numpy.where(spacing > 10 )[0]
4342 #
4343 # if len(realIndex) < 2:
4344 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4345 # return None
4346 #
4347 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
4348 # realPulseIndex = pulseIndex[realIndex]
4349 #
4350 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
4351 #
4352 # print "IPP = %d samples" %period
4353 #
4354 # self.__newNSamples = dataOut.nHeights #int(period)
4355 # self.__startIndex = int(realPulseIndex[0])
4356 #
4357 # return 1
4358 #
4359 #
4360 # def setup(self, nSamples, nChannels, buffer_size = 4):
4361 #
4362 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
4363 # maxlen = buffer_size*nSamples)
4364 #
4365 # bufferList = []
4366 #
4367 # for i in range(nChannels):
4368 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
4369 # maxlen = buffer_size*nSamples)
4370 #
4371 # bufferList.append(bufferByChannel)
4372 #
4373 # self.__nSamples = nSamples
4374 # self.__nChannels = nChannels
4375 # self.__bufferList = bufferList
4376 #
4377 # def run(self, dataOut, channel = 0):
4378 #
4379 # if not self.isConfig:
4380 # nSamples = dataOut.nHeights
4381 # nChannels = dataOut.nChannels
4382 # self.setup(nSamples, nChannels)
4383 # self.isConfig = True
4384 #
4385 # #Append new data to internal buffer
4386 # for thisChannel in range(self.__nChannels):
4387 # bufferByChannel = self.__bufferList[thisChannel]
4388 # bufferByChannel.extend(dataOut.data[thisChannel])
4389 #
4390 # if self.__pulseFound:
4391 # self.__startIndex -= self.__nSamples
4392 #
4393 # #Finding Tx Pulse
4394 # if not self.__pulseFound:
4395 # indexFound = self.__findTxPulse(dataOut, channel)
4396 #
4397 # if indexFound == None:
4398 # dataOut.flagNoData = True
4399 # return
4400 #
4401 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
4402 # self.__pulseFound = True
4403 # self.__startIndex = indexFound
4404 #
4405 # #If pulse was found ...
4406 # for thisChannel in range(self.__nChannels):
4407 # bufferByChannel = self.__bufferList[thisChannel]
4408 # #print self.__startIndex
4409 # x = numpy.array(bufferByChannel)
4410 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
4411 #
4412 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4413 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
4414 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
4415 #
4416 # dataOut.data = self.__arrayBuffer
4417 #
4418 # self.__startIndex += self.__newNSamples
4419 #
4420 # return
4421
4422
4423
4424
4425
4426
4427
4428 ##############################LONG PULSE##############################
4429
4430
4431
4432 class CrossProdHybrid(CrossProdDP):
4433 """Operation to calculate cross products of the Hybrid Experiment.
4434
4435 Parameters:
4436 -----------
4437 NLAG : int
4438 Number of lags for Long Pulse.
4439 NRANGE : int
4440 Number of samples (heights) for Long Pulse.
4441 NCAL : int
4442 .*
4443 DPL : int
4444 Number of lags for Double Pulse.
4445 NDN : int
4446 .*
4447 NDT : int
4448 Number of heights for Double Pulse.*
4449 NDP : int
4450 Number of heights for Double Pulse.*
4451 NSCAN : int
4452 Number of profiles when the transmitter is on.
4453 lagind : intlist
4454 .*
4455 lagfirst : intlist
4456 .*
4457 NAVG : int
4458 Number of blocks to be "averaged".
4459 nkill : int
4460 Number of blocks not to be considered when averaging.
4461
4462 Example
4463 --------
4464
4465 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4466 op.addParameter(name='NLAG', value='16', format='int')
4467 op.addParameter(name='NRANGE', value='200', format='int')
4468 op.addParameter(name='NCAL', value='0', format='int')
4469 op.addParameter(name='DPL', value='11', format='int')
4470 op.addParameter(name='NDN', value='0', format='int')
4471 op.addParameter(name='NDT', value='67', format='int')
4472 op.addParameter(name='NDP', value='67', format='int')
4473 op.addParameter(name='NSCAN', value='128', format='int')
4474 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4475 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4476 op.addParameter(name='NAVG', value='16', format='int')
4477 op.addParameter(name='nkill', value='6', format='int')
4478
4479 """
4480
4481 def __init__(self, **kwargs):
4482
4483 Operation.__init__(self, **kwargs)
4484 self.bcounter=0
4485 self.aux=1
4486 self.aux_cross_lp=1
4487 self.lag_products_LP_median_estimates_aux=1
4488
4489 def get_products_cabxys_HP(self,dataOut):
4490
4491 if self.aux==1:
4492 self.set_header_output(dataOut)
4493 self.aux=0
4494
4495 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2
4496 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4497 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4498 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4499 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4500 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4501 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4502 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4503 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4504 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4505 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4506 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4507 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4508 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4509 for i in range(2): # flipped and unflipped
4510 for j in range(dataOut.NDP): # loop over true ranges # 67
4511 for k in range(int(dataOut.NSCAN)): # 128
4512
4513 n=dataOut.lagind[k%dataOut.NLAG] # 128=16x8
4514
4515 ax=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].real-dataOut.dc.real[0]
4516 ay=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].imag-dataOut.dc.imag[0]
4517
4518 if dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n<dataOut.read_samples:
4519
4520 bx=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].real-dataOut.dc.real[1]
4521 by=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].imag-dataOut.dc.imag[1]
4522
4523 else:
4524
4525 if k+1<int(dataOut.NSCAN):
4526 bx=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4527 by=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4528
4529 if k+1==int(dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE
4530 bx=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4531 by=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4532
4533 if(k<dataOut.NLAG and dataOut.lagfirst[k%dataOut.NLAG]==1):# if(k<16 && lagfirst[k%16]==1)
4534 self.cax[j][n][i]=ax
4535 self.cay[j][n][i]=ay
4536 self.cbx[j][n][i]=bx
4537 self.cby[j][n][i]=by
4538 self.cax2[j][n][i]=ax*ax
4539 self.cay2[j][n][i]=ay*ay
4540 self.cbx2[j][n][i]=bx*bx
4541 self.cby2[j][n][i]=by*by
4542 self.caxbx[j][n][i]=ax*bx
4543 self.caxby[j][n][i]=ax*by
4544 self.caybx[j][n][i]=ay*bx
4545 self.cayby[j][n][i]=ay*by
4546 self.caxay[j][n][i]=ax*ay
4547 self.cbxby[j][n][i]=bx*by
4548 else:
4549 self.cax[j][n][i]+=ax
4550 self.cay[j][n][i]+=ay
4551 self.cbx[j][n][i]+=bx
4552 self.cby[j][n][i]+=by
4553 self.cax2[j][n][i]+=ax*ax
4554 self.cay2[j][n][i]+=ay*ay
4555 self.cbx2[j][n][i]+=bx*bx
4556 self.cby2[j][n][i]+=by*by
4557 self.caxbx[j][n][i]+=ax*bx
4558 self.caxby[j][n][i]+=ax*by
4559 self.caybx[j][n][i]+=ay*bx
4560 self.cayby[j][n][i]+=ay*by
4561 self.caxay[j][n][i]+=ax*ay
4562 self.cbxby[j][n][i]+=bx*by
4563
4564
4565 #print(self.cax2[2,0,1])
4566 #input()
4567
4568
4569 def lag_products_LP(self,dataOut):
4570
4571
4572 buffer=dataOut.data
4573 if self.aux_cross_lp==1:
4574
4575 #self.dataOut.nptsfft2=150
4576 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4577 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4578 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4579 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4580 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4581
4582 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4583 self.aux_cross_lp=0
4584
4585 #print(self.dataOut.data[0,0,0])
4586
4587 for i in range(dataOut.NR):
4588 #print("inside i",i)
4589 buffer_dc=dataOut.dc[i]
4590 for j in range(dataOut.NRANGE):
4591
4592 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4593
4594 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4595 for n in range(range_for_n):
4596
4597 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4598
4599 if i==0:
4600 self.lagp0[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4601 self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4602 elif i==1:
4603 self.lagp1[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4604 elif i==2:
4605 self.lagp2[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4606
4607
4608 self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1])
4609 self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1])
4610 self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1])
4611 self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1])
4612
4613
4614 def LP_median_estimates(self,dataOut):
4615
4616 if self.bcounter==dataOut.NAVG:
4617
4618 if self.lag_products_LP_median_estimates_aux==1:
4619 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4620 self.lag_products_LP_median_estimates_aux=0
4621
4622
4623 for i in range(dataOut.NLAG):
4624 for j in range(dataOut.NRANGE):
4625 for l in range(4): #four outputs
4626
4627 for k in range(dataOut.NAVG):
4628
4629
4630 if k==0:
4631 self.output[i,j,l]=0.0+0.j
4632
4633 if l==0:
4634 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4635
4636 if l==1:
4637 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4638
4639 if l==2:
4640 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4641
4642 if l==3:
4643 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4644
4645
4646
4647 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4648 if l==0:
4649
4650 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4651 if l==1:
4652 #print("lagp1: ",self.lagp1[0,0,:])
4653 #input()
4654 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4655 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4656 #input()
4657 if l==2:
4658 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4659 if l==3:
4660
4661 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4662
4663
4664 dataOut.output_LP=self.output
4665 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4666 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4667
4668
4669 def get_dc(self,dataOut):
4670
4671 if self.bcounter==0:
4672 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4673
4674 #print(numpy.shape(dataOut.data))
4675 #input()
4676
4677 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4678
4679 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4680
4681
4682 #print("dc:",dataOut.dc[0])
4683
4684 def get_dc_new(self,dataOut):
4685
4686 if self.bcounter==0:
4687 dataOut.dc_dp=numpy.zeros(dataOut.NR,dtype='complex64')
4688 dataOut.dc_lp=numpy.zeros(dataOut.NR,dtype='complex64')
4689
4690 #print(numpy.shape(dataOut.data))
4691 #input()
4692
4693 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4694
4695 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4696
4697
4698 #print("dc:",dataOut.dc[0])
4699
4700
4701 def noise_estimation4x_HP(self,dataOut):
4702 if self.bcounter==dataOut.NAVG:
4703 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4704 #snoise=numpy.zeros((NR,NAVG),'float32')
4705 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4706 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4707 for i in range(dataOut.NR):
4708 dataOut.noise_final[i]=0.0
4709 for j in range(dataOut.MAXNRANGENDT):
4710 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
4711 #print(sorted(noisevector[j,i,:]))
4712 #input()
4713 l=dataOut.MAXNRANGENDT-2
4714 for k in range(dataOut.NAVG):
4715 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4716 #print(k)
4717 #print(sorted_data[min(j,l),i,k])
4718 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
4719 #print(dataOut.noise_final[i])
4720 #input()
4721 #print(dataOut.noise_final)
4722 #input()
4723
4724 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
4725
4726 #rnormalizer= 1./(float(nProfiles - NSCAN))
4727 rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
4728 for i in range(NR):
4729 for j in range(MAXNRANGENDT):
4730 for k in range(NSCAN,nProfiles):
4731 #TODO:integrate just 2nd quartile gates
4732 if k==NSCAN:
4733 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4734 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
4735 else:
4736 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4737
4738
4739 def RTI_LP(self,output,NRANGE):
4740 x00=numpy.zeros(NRANGE,dtype='float32')
4741 x01=numpy.zeros(NRANGE,dtype='float32')
4742 x02=numpy.zeros(NRANGE,dtype='float32')
4743 x03=numpy.zeros(NRANGE,dtype='float32')
4744
4745 for i in range(2): #first couple of lags
4746 for j in range(NRANGE): #
4747 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
4748 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
4749 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
4750 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
4751 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
4752 #x02[i]=x02[i]+fx
4753
4754 x00[j]=10.0*numpy.log10(x00[j]/4.)
4755 x01[j]=10.0*numpy.log10(x01[j]/4.)
4756 x02[j]=10.0*numpy.log10(x02[j]/4.)
4757 x03[j]=10.0*numpy.log10(x03[j]/4.)
4758 #x02[i]=10.0*numpy.log10(x02[i])
4759 return x00,x01,x02,x03
4760
4761 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
4762 NDN=None, NDT=None, NDP=None, NSCAN=None,
4763 lagind=None, lagfirst=None,
4764 NAVG=None, nkill=None):
4765
4766 dataOut.NLAG=NLAG
4767 dataOut.NR=len(dataOut.channelList)
4768 dataOut.NRANGE=NRANGE
4769 dataOut.NCAL=NCAL
4770 dataOut.DPL=DPL
4771 dataOut.NDN=NDN
4772 dataOut.NDT=NDT
4773 dataOut.NDP=NDP
4774 dataOut.NSCAN=NSCAN
4775 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
4776 dataOut.H0=int(dataOut.heightList[0])
4777 dataOut.lagind=lagind
4778 dataOut.lagfirst=lagfirst
4779 dataOut.NAVG=NAVG
4780 dataOut.nkill=nkill
4781
4782 dataOut.flagNoData = True
4783
4784 self.get_dc(dataOut)
4785 self.get_products_cabxys_HP(dataOut)
4786 self.cabxys_navg(dataOut)
4787 self.lag_products_LP(dataOut)
4788 self.LP_median_estimates(dataOut)
4789 self.noise_estimation4x_HP(dataOut)
4790 self.kabxys(dataOut)
4791
4792 return dataOut
4793
4794
4795 class CrossProdLP(CrossProdDP):
4796 """Operation to calculate cross products of the Hybrid Experiment.
4797
4798 Parameters:
4799 -----------
4800 NLAG : int
4801 Number of lags for Long Pulse.
4802 NRANGE : int
4803 Number of samples (heights) for Long Pulse.
4804 NCAL : int
4805 .*
4806 DPL : int
4807 Number of lags for Double Pulse.
4808 NDN : int
4809 .*
4810 NDT : int
4811 Number of heights for Double Pulse.*
4812 NDP : int
4813 Number of heights for Double Pulse.*
4814 NSCAN : int
4815 Number of profiles when the transmitter is on.
4816 lagind : intlist
4817 .*
4818 lagfirst : intlist
4819 .*
4820 NAVG : int
4821 Number of blocks to be "averaged".
4822 nkill : int
4823 Number of blocks not to be considered when averaging.
4824
4825 Example
4826 --------
4827
4828 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4829 op.addParameter(name='NLAG', value='16', format='int')
4830 op.addParameter(name='NRANGE', value='200', format='int')
4831 op.addParameter(name='NCAL', value='0', format='int')
4832 op.addParameter(name='DPL', value='11', format='int')
4833 op.addParameter(name='NDN', value='0', format='int')
4834 op.addParameter(name='NDT', value='67', format='int')
4835 op.addParameter(name='NDP', value='67', format='int')
4836 op.addParameter(name='NSCAN', value='128', format='int')
4837 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4838 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4839 op.addParameter(name='NAVG', value='16', format='int')
4840 op.addParameter(name='nkill', value='6', format='int')
4841
4842 """
4843
4844 def __init__(self, **kwargs):
4845
4846 Operation.__init__(self, **kwargs)
4847 self.bcounter=0
4848 self.aux=1
4849 self.aux_cross_lp=1
4850 self.lag_products_LP_median_estimates_aux=1
4851
4852
4853
4854 #print(self.cax2[2,0,1])
4855 #input()
4856
4857
4858 def lag_products_LP(self,dataOut):
4859
4860
4861 buffer=dataOut.data
4862 if self.aux_cross_lp==1:
4863
4864 #self.dataOut.nptsfft2=150
4865 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4866 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4867 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4868 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4869 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4870 self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4871 self.lagp5=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4872
4873 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4874 self.aux_cross_lp=0
4875
4876 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4877
4878 #print(self.dataOut.data[0,0,0])
4879 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
4880
4881
4882 for i in range(dataOut.NR):
4883 #print("inside i",i)
4884 buffer_dc=dataOut.dc[i]
4885 for j in range(dataOut.NRANGE):
4886
4887 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4888
4889 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4890 for n in range(range_for_n):
4891
4892 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4893
4894 if i==0:
4895 self.lagp0[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4896 #self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4897 elif i==1:
4898 self.lagp1[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4899 elif i==2:
4900 self.lagp2[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4901 elif i==3:
4902 self.lagp3[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4903 elif i==4:
4904 self.lagp4[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4905 elif i==5:
4906 self.lagp5[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4907
4908
4909 self.lagp0[:,:,self.bcounter]=numpy.conj(self.lagp0[:,:,self.bcounter])
4910 self.lagp1[:,:,self.bcounter]=numpy.conj(self.lagp1[:,:,self.bcounter])
4911 self.lagp2[:,:,self.bcounter]=numpy.conj(self.lagp2[:,:,self.bcounter])
4912 self.lagp3[:,:,self.bcounter]=numpy.conj(self.lagp3[:,:,self.bcounter])
4913
4914 self.bcounter += 1
4915
4916
4917 def LP_median_estimates(self,dataOut):
4918
4919 if self.bcounter==dataOut.NAVG:
4920 dataOut.flagNoData = False
4921
4922 if self.lag_products_LP_median_estimates_aux==1:
4923 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4924 self.lag_products_LP_median_estimates_aux=0
4925
4926
4927 for i in range(dataOut.NLAG):
4928 for j in range(dataOut.NRANGE):
4929 for l in range(4): #four outputs
4930
4931 for k in range(dataOut.NAVG):
4932
4933
4934 if k==0:
4935 self.output[i,j,l]=0.0+0.j
4936
4937 if l==0:
4938 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4939
4940 if l==1:
4941 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4942
4943 if l==2:
4944 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4945
4946 if l==3:
4947 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4948
4949
4950
4951 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4952 if l==0:
4953
4954 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4955 if l==1:
4956 #print("lagp1: ",self.lagp1[0,0,:])
4957 #input()
4958 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4959 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4960 #input()
4961 if l==2:
4962 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4963 if l==3:
4964
4965 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4966
4967
4968 dataOut.output_LP=self.output
4969 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4970 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4971
4972 self.bcounter = 0
4973
4974 def get_dc(self,dataOut):
4975
4976 if self.bcounter==0:
4977 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4978
4979 #print(numpy.shape(dataOut.data))
4980 #input()
4981
4982 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4983
4984 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4985
4986
4987 #print("dc:",dataOut.dc[0])
4988
4989
4990
4991
4992 def noise_estimation4x_HP(self,dataOut):
4993 if self.bcounter==dataOut.NAVG:
4994 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4995 #snoise=numpy.zeros((NR,NAVG),'float32')
4996 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4997 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4998 for i in range(dataOut.NR):
4999 dataOut.noise_final[i]=0.0
5000 for j in range(dataOut.MAXNRANGENDT):
5001 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
5002 #print(sorted(noisevector[j,i,:]))
5003 #input()
5004 l=dataOut.MAXNRANGENDT-2
5005 for k in range(dataOut.NAVG):
5006 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
5007 #print(k)
5008 #print(sorted_data[min(j,l),i,k])
5009 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
5010 #print(dataOut.noise_final[i])
5011 #input()
5012 #print(dataOut.noise_final)
5013 #input()
5014
5015 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
5016
5017 #rnormalizer= 1./(float(nProfiles - NSCAN))
5018 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
5019 rnormalizer= float(NSCAN)/((float(1))*float(MAXNRANGENDT))
5020 for i in range(NR):
5021 for j in range(MAXNRANGENDT):
5022 for k in range(NSCAN,nProfiles):
5023 #TODO:integrate just 2nd quartile gates
5024 if k==NSCAN:
5025 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5026 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
5027 else:
5028 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5029
5030
5031 def RTI_LP(self,output,NRANGE):
5032 x00=numpy.zeros(NRANGE,dtype='float32')
5033 x01=numpy.zeros(NRANGE,dtype='float32')
5034 x02=numpy.zeros(NRANGE,dtype='float32')
5035 x03=numpy.zeros(NRANGE,dtype='float32')
5036
5037 for i in range(1): #first couple of lags
5038 for j in range(NRANGE): #
5039 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
5040 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
5041 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
5042 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
5043 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
5044 #x02[i]=x02[i]+fx
5045
5046 x00[j]=10.0*numpy.log10(x00[j]/4.)
5047 x01[j]=10.0*numpy.log10(x01[j]/4.)
5048 x02[j]=10.0*numpy.log10(x02[j]/4.)
5049 x03[j]=10.0*numpy.log10(x03[j]/4.)
5050 #x02[i]=10.0*numpy.log10(x02[i])
5051 return x00,x01,x02,x03
5052
5053 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
5054 NDN=None, NDT=None, NDP=None, NSCAN=None,
5055 lagind=None, lagfirst=None,
5056 NAVG=None, nkill=None):
5057
5058 dataOut.NLAG=NLAG
5059 dataOut.NR=len(dataOut.channelList)
5060 #dataOut.NRANGE=NRANGE
5061 dataOut.NRANGE=dataOut.nHeights
5062 dataOut.NCAL=NCAL
5063 dataOut.DPL=DPL
5064 dataOut.NDN=NDN
5065 dataOut.NDT=NDT
5066 dataOut.NDP=NDP
5067 dataOut.NSCAN=NSCAN
5068 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
5069 dataOut.H0=int(dataOut.heightList[0])
5070 dataOut.lagind=lagind
5071 dataOut.lagfirst=lagfirst
5072 dataOut.NAVG=NAVG
5073 dataOut.nkill=nkill
5074
5075 dataOut.MAXNRANGENDT = dataOut.NRANGE
5076
5077 dataOut.flagNoData = True
5078
5079 print(self.bcounter)
5080
5081 self.get_dc(dataOut)
5082 self.lag_products_LP(dataOut)
5083 self.noise_estimation4x_HP(dataOut)
5084 self.LP_median_estimates(dataOut)
5085
5086 print("******************DONE******************")
5087
5088
5089
5090 return dataOut
5091
5092
5093 class RemoveDebris(Operation):
5094 """Operation to remove blocks where an outlier is found for Double (Long) Pulse.
5095
5096 Parameters:
5097 -----------
5098 None
5099
5100 Example
5101 --------
5102
5103 op = proc_unit.addOperation(name='RemoveDebris', optype='other')
5104
5105 """
5106
5107 def __init__(self, **kwargs):
5108
5109 Operation.__init__(self, **kwargs)
5110
5111 def run(self,dataOut):
5112 print("init_debris",dataOut.flagNoData)
5113 #dataOut.debris_activated=0
5114 debris=numpy.zeros(dataOut.NRANGE,'float32')
5115
5116 for j in range(0,3):
5117 for i in range(dataOut.NRANGE):
5118 if j==0:
5119 debris[i]=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5120 else:
5121 debris[i]+=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5122
5123 thresh=8.0+4+4+4
5124 for i in range(47,100):
5125 if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])>
5126 ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+
5127 debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+
5128 thresh)):
5129
5130 dataOut.flagNoData=True
5131 print("LP Debris detected at",i*15,"km")
5132
5133 debris=numpy.zeros(dataOut.NDP,dtype='float32')
5134 Range=numpy.arange(0,3000,15)
5135 for k in range(2): #flip
5136 for i in range(dataOut.NDP): #
5137 debris[i]+=numpy.sqrt((dataOut.kaxbx[i,0,k]+dataOut.kayby[i,0,k])**2+(dataOut.kaybx[i,0,k]-dataOut.kaxby[i,0,k])**2)
5138
5139 if gmtime(dataOut.utctime).tm_hour > 11:
5140 for i in range(2,dataOut.NDP-2):
5141 if (debris[i]>3.0*debris[i-2] and
5142 debris[i]>3.0*debris[i+2] and
5143 Range[i]>200.0 and Range[i]<=540.0):
5144 dataOut.flagNoData=True
5145 print("DP Debris detected at",i*15,"km")
5146
5147 print("inside debris",dataOut.flagNoData)
5148 return dataOut
5149
5150
5151 class IntegrationHP(IntegrationDP):
5152 """Operation to integrate Double Pulse and Long Pulse data.
5153
5154 Parameters:
5155 -----------
5156 nint : int
5157 Number of integrations.
5158
5159 Example
5160 --------
5161
5162 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
5163 op.addParameter(name='nint', value='30', format='int')
5164
5165 """
5166
5167 def __init__(self, **kwargs):
5168
5169 Operation.__init__(self, **kwargs)
5170
5171 self.counter = 0
5172 self.aux = 0
5173
5174 def integration_noise(self,dataOut):
5175
5176 if self.counter == 0:
5177 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
5178
5179 dataOut.tnoise+=dataOut.noise_final
5180
5181 def integration_for_long_pulse(self,dataOut):
930
5182
931 def __init__(self, **kwargs):
5183 if self.counter == 0:
5184 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
932
5185
933 Operation.__init__(self, **kwargs)
5186 dataOut.output_LP_integrated+=dataOut.output_LP
934 self.profileIndex = 0
935
5187
936 def incProfileIndex(self):
5188 def run(self,dataOut,nint=None):
937
5189
938 self.profileIndex += 1
5190 dataOut.flagNoData=True
939
5191
940 if self.profileIndex >= self.nProfiles:
5192 #print("flag_inside",dataOut.flagNoData)
941 self.profileIndex = 0
5193 dataOut.nint=nint
5194 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
5195 dataOut.lat=-11.95
5196 dataOut.lon=-76.87
942
5197
943 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
5198 self.integration_for_long_pulse(dataOut)
944
5199
945 if profileIndex < minIndex:
5200 self.integration_noise(dataOut)
946 return False
947
5201
948 if profileIndex > maxIndex:
949 return False
950
5202
951 return True
5203 if self.counter==dataOut.nint-1:
952
5204
953 def isThisProfileInList(self, profileIndex, profileList):
5205 dataOut.tnoise[0]*=0.995
5206 dataOut.tnoise[1]*=0.995
5207 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5208 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
954
5209
955 if profileIndex not in profileList:
5210 self.integration_for_double_pulse(dataOut)
956 return False
957
5211
958 return True
959
5212
960 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
961
5213
962 """
5214 return dataOut
963 ProfileSelector:
964
5215
965 Inputs:
966 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
967
5216
968 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
5217 class IntegrationLP(Operation):
5218 """Operation to integrate Double Pulse and Long Pulse data.
969
5219
970 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
5220 Parameters:
5221 -----------
5222 nint : int
5223 Number of integrations.
971
5224
972 """
5225 Example
5226 --------
973
5227
974 if rangeList is not None:
5228 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
975 if type(rangeList[0]) not in (tuple, list):
5229 op.addParameter(name='nint', value='30', format='int')
976 rangeList = [rangeList]
977
5230
978 dataOut.flagNoData = True
5231 """
979
5232
980 if dataOut.flagDataAsBlock:
5233 def __init__(self, **kwargs):
981 """
982 data dimension = [nChannels, nProfiles, nHeis]
983 """
984 if profileList != None:
985 dataOut.data = dataOut.data[:,profileList,:]
986
5234
987 if profileRangeList != None:
5235 Operation.__init__(self, **kwargs)
988 minIndex = profileRangeList[0]
989 maxIndex = profileRangeList[1]
990 profileList = list(range(minIndex, maxIndex+1))
991
5236
992 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
5237 self.counter = 0
5238 self.aux = 0
993
5239
994 if rangeList != None:
5240 def integration_noise(self,dataOut):
995
5241
996 profileList = []
5242 if self.counter == 0:
5243 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
997
5244
998 for thisRange in rangeList:
5245 dataOut.tnoise+=dataOut.noise_final
999 minIndex = thisRange[0]
5246 '''
1000 maxIndex = thisRange[1]
5247 def integration_for_long_pulse(self,dataOut):
1001
5248
1002 profileList.extend(list(range(minIndex, maxIndex+1)))
5249 if self.counter == 0:
5250 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
1003
5251
1004 dataOut.data = dataOut.data[:,profileList,:]
5252 dataOut.output_LP_integrated+=dataOut.output_LP
5253 '''
5254 def integration_for_long_pulse(self,dataOut):
5255 #print("inside")
5256 #print(self.aux)
1005
5257
1006 dataOut.nProfiles = len(profileList)
5258 if self.counter == 0:
1007 dataOut.profileIndex = dataOut.nProfiles - 1
5259 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
1008 dataOut.flagNoData = False
1009
5260
1010 return dataOut
5261 dataOut.output_LP_integrated+=dataOut.output_LP
1011
5262
1012 """
5263 if self.aux==1:
1013 data dimension = [nChannels, nHeis]
5264 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
1014 """
5265 #print(dataOut.datatime)
1015
5266
1016 if profileList != None:
5267 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5268 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5269 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
1017
5270
1018 if self.isThisProfileInList(dataOut.profileIndex, profileList):
5271 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
5272 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
5273 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5274 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
5275 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
5276 #print(dataOut.bd_time)
5277 #exit()
5278 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
5279 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
5280 #print("date: ", dataOut.TimeBlockDate)
1019
5281
1020 self.nProfiles = len(profileList)
1021 dataOut.nProfiles = self.nProfiles
1022 dataOut.profileIndex = self.profileIndex
1023 dataOut.flagNoData = False
1024
5282
1025 self.incProfileIndex()
5283 self.aux=0
1026 return dataOut
1027
5284
1028 if profileRangeList != None:
5285 #print("after")
1029
5286
1030 minIndex = profileRangeList[0]
5287 self.integration_noise(dataOut)
1031 maxIndex = profileRangeList[1]
1032
5288
1033 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
5289 if self.counter==0:
1034
5290
1035 self.nProfiles = maxIndex - minIndex + 1
5291 self.init_time=dataOut.utctime
1036 dataOut.nProfiles = self.nProfiles
1037 dataOut.profileIndex = self.profileIndex
1038 dataOut.flagNoData = False
1039
5292
1040 self.incProfileIndex()
5293 if self.counter < dataOut.nint:
1041 return dataOut
5294 #print("HERE")
1042
5295
1043 if rangeList != None:
1044
5296
1045 nProfiles = 0
1046
5297
1047 for thisRange in rangeList:
5298 self.counter+=1
1048 minIndex = thisRange[0]
1049 maxIndex = thisRange[1]
1050
5299
1051 nProfiles += maxIndex - minIndex + 1
5300 if self.counter==dataOut.nint-1:
5301 self.aux=1
5302 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5303 if self.counter==dataOut.nint:
1052
5304
1053 for thisRange in rangeList:
5305 dataOut.flagNoData=False
5306 dataOut.utctime=self.init_time
5307 self.counter=0
1054
5308
1055 minIndex = thisRange[0]
5309 def run(self,dataOut,nint=None):
1056 maxIndex = thisRange[1]
1057
5310
1058 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
5311 dataOut.flagNoData=True
1059
5312
1060 self.nProfiles = nProfiles
5313 #print("flag_inside",dataOut.flagNoData)
1061 dataOut.nProfiles = self.nProfiles
5314 dataOut.nint=nint
1062 dataOut.profileIndex = self.profileIndex
5315 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
1063 dataOut.flagNoData = False
5316 dataOut.lat=-11.95
5317 dataOut.lon=-76.87
1064
5318
1065 self.incProfileIndex()
5319 self.integration_for_long_pulse(dataOut)
1066
5320
1067 break
1068
5321
1069 return dataOut
5322 if self.counter==dataOut.nint:
1070
5323
5324 dataOut.tnoise[0]*=0.995
5325 dataOut.tnoise[1]*=0.995
5326 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5327 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
1071
5328
1072 if beam != None: #beam is only for AMISR data
5329 #self.integration_for_double_pulse(dataOut)
1073 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
5330 print("HERE2")
1074 dataOut.flagNoData = False
1075 dataOut.profileIndex = self.profileIndex
1076
5331
1077 self.incProfileIndex()
1078
5332
1079 return dataOut
1080
5333
1081 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
5334 return dataOut
1082
5335
1083
5336
1084 class Reshaper(Operation):
5337 class SumFlipsHP(SumFlips):
5338 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
5339
5340 Parameters:
5341 -----------
5342 None
5343
5344 Example
5345 --------
5346
5347 op = proc_unit.addOperation(name='SumFlipsHP', optype='other')
5348
5349 """
1085
5350
1086 def __init__(self, **kwargs):
5351 def __init__(self, **kwargs):
1087
5352
1088 Operation.__init__(self, **kwargs)
5353 Operation.__init__(self, **kwargs)
1089
5354
1090 self.__buffer = None
5355 def rint2HP(self,dataOut):
1091 self.__nitems = 0
1092
5356
1093 def __appendProfile(self, dataOut, nTxs):
5357 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
1094
5358
1095 if self.__buffer is None:
5359 for l in range(dataOut.DPL):
1096 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
5360 if(l==0 or (l>=3 and l <=6)):
1097 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
5361 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*16.0)
5362 else:
5363 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*8.0)
1098
5364
1099 ini = dataOut.nHeights * self.__nitems
5365 def run(self,dataOut):
1100 end = ini + dataOut.nHeights
1101
5366
1102 self.__buffer[:, ini:end] = dataOut.data
5367 self.rint2HP(dataOut)
5368 self.SumLags(dataOut)
1103
5369
1104 self.__nitems += 1
5370 return dataOut
1105
5371
1106 return int(self.__nitems*nTxs)
1107
5372
1108 def __getBuffer(self):
5373 from schainpy.model.proc import full_profile_profile
5374 from scipy.optimize import nnls
5375 class LongPulseAnalysis(Operation):
5376 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
1109
5377
1110 if self.__nitems == int(1./self.__nTxs):
5378 Parameters:
5379 -----------
5380 NACF : int
5381 .*
1111
5382
1112 self.__nitems = 0
5383 Example
5384 --------
1113
5385
1114 return self.__buffer.copy()
5386 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5387 op.addParameter(name='NACF', value='16', format='int')
1115
5388
1116 return None
5389 """
1117
5390
1118 def __checkInputs(self, dataOut, shape, nTxs):
5391 def __init__(self, **kwargs):
1119
5392
1120 if shape is None and nTxs is None:
5393 Operation.__init__(self, **kwargs)
1121 raise ValueError("Reshaper: shape of factor should be defined")
5394 self.aux=1
5395
5396 def run(self,dataOut,NACF):
5397
5398 dataOut.NACF=NACF
5399 dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5400 anoise0=dataOut.tnoise[0]
5401 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5402
5403 if self.aux:
5404 #dataOut.cut=31#26#height=31*15=465
5405 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5406 self.drift=numpy.zeros((200),'float32')
5407 self.rdrift=numpy.zeros((200),'float32')
5408 self.ddrift=numpy.zeros((200),'float32')
5409 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5410 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5411 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5412 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5413 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5414 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5415 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5416 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5417 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5418 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5419 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5420 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5421 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5422 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5423 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5424 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5425 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5426 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5427 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5428 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32')
5429 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32')
5430 dataOut.status=numpy.zeros(1,'float32')
5431 dataOut.tx=240.0 #debería provenir del header #hybrid
5432
5433 for i in range(dataOut.IBITS):
5434 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5435
5436 self.aux=0
5437
5438 dataOut.cut=30
5439 for i in range(30,15,-1):
5440 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5441 dataOut.cut=i-1
5442 #print(dataOut.cut)
5443 #print(dataOut.info2[:])
5444 #print(dataOut.te2[:])
5445 #print(dataOut.ti2[:])
5446 for i in range(dataOut.NLAG):
5447 self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5448
5449
5450 self.cal/=float(dataOut.NRANGE)
5451
5452 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
5453
5454 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5455 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
5456
5457 for i in range(1,dataOut.NLAG): #remove cal data from certain lags
5458 dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5459 k=max(j,26) #constant power below range 26
5460 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
5461
5462 ## examine drifts here - based on 60 'indep.' estimates
5463
5464 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
5465 alpha=beta=delta=0.0
5466 nest=0
5467 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5468 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5469 for i in range(1,3):
5470 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5471 for j in range(34,44):
5472 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5473 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5474 dataOut.dphi2*=gamma**2
5475 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
5476
5477 self.drift[nest]=pest
5478 self.ddrift[nest]=dataOut.dphi2
5479 self.rdrift[nest]=float(nest)
5480 nest+=1
5481
5482 sorted(self.drift[:nest])
5483
5484 for j in range(int(nest/4),int(3*nest/4)):
5485 #i=int(self.rdrift[j])
5486 alpha+=self.drift[j]/self.ddrift[j]
5487 delta+=1.0/self.ddrift[j]
5488
5489 alpha/=delta
5490 delta=1./numpy.sqrt(delta)
5491 vdrift=alpha-beta
5492 dvdrift=delta
5493
5494 #need to develop estimate of complete density profile using all
5495 #available data
5496
5497 #estimate sample variances for long-pulse power profile
5498
5499 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
5500
5501 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5502
5503 ioff=1
5504
5505 #deconvolve rectangular pulse shape from profile ==> powerb, perror
5506
5507
5508 ############# START nnlswrap#############
5509
5510 if dataOut.ut_Faraday>14.0:
5511 alpha_nnlswrap=20.0
5512 else:
5513 alpha_nnlswrap=30.0
1122
5514
1123 if nTxs:
5515 range1_nnls=dataOut.NACF
1124 if nTxs < 0:
5516 range2_nnls=dataOut.NACF+dataOut.IBITS-1
1125 raise ValueError("nTxs should be greater than 0")
1126
5517
1127 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
5518 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
1128 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
5519 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
1129
5520
1130 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
5521 for i in range(range1_nnls):
5522 for j in range(range2_nnls):
5523 if j>=i and j<i+dataOut.IBITS:
5524 g_nnlswrap[i,j]=1.0
5525 else:
5526 g_nnlswrap[i,j]=0.0
1131
5527
1132 return shape, nTxs
5528 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
1133
5529
1134 if len(shape) != 2 and len(shape) != 3:
5530 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
1135 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
1136
5531
1137 if len(shape) == 2:
5532 #ERROR ANALYSIS#
1138 shape_tuple = [dataOut.nChannels]
1139 shape_tuple.extend(shape)
1140 else:
1141 shape_tuple = list(shape)
1142
5533
1143 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
5534 self.perror[:range2_nnls]=0.0
5535 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5536 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5537 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
1144
5538
1145 return shape_tuple, nTxs
5539 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5540 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
1146
5541
1147 def run(self, dataOut, shape=None, nTxs=None):
5542 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
5543 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
1148
5544
1149 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
5545 self.powerb[:range2_nnls]=x_nnlswrap
1150
5546
1151 dataOut.flagNoData = True
5547 #############END nnlswrap#############
1152 profileIndex = None
1153
5548
1154 if dataOut.flagDataAsBlock:
5549 #estimate relative error for deconvolved profile (scaling irrelevant)
1155
5550
1156 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
5551 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
1157 dataOut.flagNoData = False
1158
5552
1159 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
5553 aux=0
1160
5554
1161 else:
5555 for i in range(dataOut.IBITS,dataOut.NACF):
5556 self.dpulse[i]=self.lpulse[i]=0.0
5557 for j in range(dataOut.IBITS):
5558 k=int(i-j)
5559 if k<36-aux and k>16:
5560 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5561 elif k>=36-aux:
5562 self.lpulse[i]+=self.powerb[k]
5563 self.lagp[i]=self.powera[i]
1162
5564
1163 if self.__nTxs < 1:
5565 #find scale factor that best merges profiles
1164
5566
1165 self.__appendProfile(dataOut, self.__nTxs)
5567 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
1166 new_data = self.__getBuffer()
5568 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5569 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5570 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5571 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
1167
5572
1168 if new_data is not None:
5573 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
1169 dataOut.data = new_data
5574 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
1170 dataOut.flagNoData = False
1171
5575
1172 profileIndex = dataOut.profileIndex*nTxs
5576 #form density profile estimate, merging rescaled power profiles
1173
5577
1174 else:
5578 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
1175 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
5579 self.powerb[36-aux:dataOut.NACF]*=beta
1176
5580
1177 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
5581 #form Ne estimate, fill in error estimate at low altitudes
1178
5582
1179 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
5583 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5584 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
1180
5585
1181 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
5586 #now do error propagation: store zero lag error covariance in u
1182
5587
1183 dataOut.profileIndex = profileIndex
5588 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
1184
5589
1185 dataOut.ippSeconds /= self.__nTxs
5590 for i in range(dataOut.NACF):
5591 for j in range(i,dataOut.NACF):
5592 if j-i>=dataOut.IBITS:
5593 self.u[i,j]=0.0
5594 else:
5595 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5596 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5597 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5598
5599 self.u[j,i]=self.u[i,j]
5600
5601 #now error analyis for lag product matrix (diag), place in acf_err
5602
5603 for i in range(dataOut.NACF):
5604 for j in range(dataOut.IBITS):
5605 if j==0:
5606 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5607 else:
5608 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5609
5610 #with suppress_stdout_stderr():
5611 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5612
5613 if dataOut.status>=3.5:
5614 dataOut.te[:]=numpy.nan
5615 dataOut.ete[:]=numpy.nan
5616 dataOut.ti[:]=numpy.nan
5617 dataOut.eti[:]=numpy.nan
5618 dataOut.ph[:]=numpy.nan
5619 dataOut.eph[:]=numpy.nan
5620 dataOut.phe[:]=numpy.nan
5621 dataOut.ephe[:]=numpy.nan
1186
5622
1187 return dataOut
5623 return dataOut
1188
5624
1189 class SplitProfiles(Operation):
5625
5626 class LongPulseAnalysisLP(Operation):
5627 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
5628
5629 Parameters:
5630 -----------
5631 NACF : int
5632 .*
5633
5634 Example
5635 --------
5636
5637 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5638 op.addParameter(name='NACF', value='16', format='int')
5639
5640 """
1190
5641
1191 def __init__(self, **kwargs):
5642 def __init__(self, **kwargs):
1192
5643
1193 Operation.__init__(self, **kwargs)
5644 Operation.__init__(self, **kwargs)
5645 self.aux=1
5646
5647 def run(self,dataOut,NACF=None):
5648
5649
5650 dataOut.IBITS = 64
5651 dataOut.NACF = dataOut.nHeights# - (2*dataOut.IBITS+5)
5652 #print(dataOut.heightList[int(dataOut.NACF)])
5653 #exit(1)
5654
5655 #dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5656 anoise0=dataOut.tnoise[0]
5657 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5658
5659 if self.aux:
5660 #dataOut.cut=31#26#height=31*15=465
5661 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5662 self.drift=numpy.zeros((200),'float32')
5663 self.rdrift=numpy.zeros((200),'float32')
5664 self.ddrift=numpy.zeros((200),'float32')
5665 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5666 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5667 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5668 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5669 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5670 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5671 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5672 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5673 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5674 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5675 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5676 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5677 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5678 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5679 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5680 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5681 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5682 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5683 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5684 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,1)),order='F',dtype='float32')
5685 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,1),dataOut.NLAG),order='F',dtype='float32')
5686 dataOut.status=numpy.zeros(1,'float32')
5687 dataOut.tx=480.0 #debería provenir del header #HAE
5688
5689 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
5690 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
5691
5692
5693
5694 for i in range(dataOut.IBITS):
5695 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5696
5697 self.aux=0
5698
5699
5700
5701 for i in range(dataOut.MAXNRANGENDT):
5702 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
5703 dataOut.h2[i]=dataOut.range1[i]**2
5704
5705 dataOut.cut=30
5706 #for i in range(30,15,-1):
5707 # if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5708 # dataOut.cut=i-1
5709 #print(dataOut.cut)
5710 #print(dataOut.info2[:])
5711 #print(dataOut.te2[:])
5712 #print(dataOut.ti2[:])
5713 #for i in range(dataOut.NLAG):
5714 # self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5715
5716
5717 #self.cal/=float(dataOut.NRANGE)
5718
5719 for j in range(dataOut.NACF):#+2*dataOut.IBITS+2):
5720
5721 self.powera[j]=dataOut.output_LP_integrated.real[0,j,0]
5722
5723
5724 print(dataOut.heightList[:dataOut.NACF])
5725 import matplotlib.pyplot as plt
5726 fig, axes = plt.subplots(figsize=(14, 10))
5727 axes.plot(self.powera[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5728 axes.set_xscale("log", nonposx='clip')
5729 #axes.set_xlim(1e18,2e19)
5730 axes.set_ylim(180,470)
5731 import time
5732
5733 plt.title(time.ctime(dataOut.utctime))
5734 plt.show()
5735 time.sleep(50)
5736 exit(1)
5737 '''
5738 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
1194
5739
1195 def run(self, dataOut, n):
5740 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5741 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
1196
5742
1197 dataOut.flagNoData = True
5743 #for i in range(1,dataOut.NLAG): #remove cal data from certain lags
1198 profileIndex = None
5744 # dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5745 k=max(j,26) #constant power below range 26
5746 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
1199
5747
1200 if dataOut.flagDataAsBlock:
5748 ## examine drifts here - based on 60 'indep.' estimates
1201
5749
1202 #nchannels, nprofiles, nsamples
5750 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
1203 shape = dataOut.data.shape
5751 alpha=beta=delta=0.0
5752 nest=0
5753 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5754 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5755 for i in range(1,3):
5756 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5757 for j in range(34,44):
5758 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5759 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5760 dataOut.dphi2*=gamma**2
5761 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
1204
5762
1205 if shape[2] % n != 0:
5763 self.drift[nest]=pest
1206 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
5764 self.ddrift[nest]=dataOut.dphi2
5765 self.rdrift[nest]=float(nest)
5766 nest+=1
1207
5767
1208 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
5768 sorted(self.drift[:nest])
1209
5769
1210 dataOut.data = numpy.reshape(dataOut.data, new_shape)
5770 for j in range(int(nest/4),int(3*nest/4)):
1211 dataOut.flagNoData = False
5771 #i=int(self.rdrift[j])
5772 alpha+=self.drift[j]/self.ddrift[j]
5773 delta+=1.0/self.ddrift[j]
1212
5774
1213 profileIndex = int(dataOut.nProfiles/n) - 1
5775 alpha/=delta
5776 delta=1./numpy.sqrt(delta)
5777 vdrift=alpha-beta
5778 dvdrift=delta
1214
5779
1215 else:
5780 #need to develop estimate of complete density profile using all
5781 #available data
1216
5782
1217 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
5783 #estimate sample variances for long-pulse power profile
1218
5784
1219 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
5785 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
1220
5786
1221 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
5787 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5788 '''
5789 ioff=1
1222
5790
1223 dataOut.nProfiles = int(dataOut.nProfiles*n)
5791 #deconvolve rectangular pulse shape from profile ==> powerb, perror
1224
5792
1225 dataOut.profileIndex = profileIndex
1226
5793
1227 dataOut.ippSeconds /= n
5794 ############# START nnlswrap#############
1228
5795
1229 return dataOut
5796 if dataOut.ut_Faraday>14.0:
5797 alpha_nnlswrap=20.0
5798 else:
5799 alpha_nnlswrap=30.0
1230
5800
1231 class CombineProfiles(Operation):
5801 range1_nnls=dataOut.NACF
1232 def __init__(self, **kwargs):
5802 range2_nnls=dataOut.NACF+dataOut.IBITS-1
1233
5803
1234 Operation.__init__(self, **kwargs)
5804 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
5805 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
1235
5806
1236 self.__remData = None
5807 for i in range(range1_nnls):
1237 self.__profileIndex = 0
5808 for j in range(range2_nnls):
5809 if j>=i and j<i+dataOut.IBITS:
5810 g_nnlswrap[i,j]=1.0
5811 else:
5812 g_nnlswrap[i,j]=0.0
1238
5813
1239 def run(self, dataOut, n):
5814 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
1240
5815
1241 dataOut.flagNoData = True
5816 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
1242 profileIndex = None
1243
5817
1244 if dataOut.flagDataAsBlock:
5818 #ERROR ANALYSIS#
5819 '''
5820 self.perror[:range2_nnls]=0.0
5821 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5822 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5823 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
5824 '''
5825 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5826 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
1245
5827
1246 #nchannels, nprofiles, nsamples
5828 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
1247 shape = dataOut.data.shape
5829 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
1248 new_shape = shape[0], shape[1]/n, shape[2]*n
1249
5830
1250 if shape[1] % n != 0:
5831 self.powerb[:range2_nnls]=x_nnlswrap
1251 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
1252
5832
1253 dataOut.data = numpy.reshape(dataOut.data, new_shape)
1254 dataOut.flagNoData = False
1255
5833
1256 profileIndex = int(dataOut.nProfiles*n) - 1
5834 import matplotlib.pyplot as plt
5835 fig, axes = plt.subplots(figsize=(14, 10))
5836 axes.plot(self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5837 axes.set_xscale("log", nonposx='clip')
5838 #axes.set_xlim(1e10,8e12)
5839 axes.set_ylim(0,300)
5840 plt.show()
5841 import time
5842 time.sleep(60)
5843 exit(1)
1257
5844
1258 else:
1259
5845
1260 #nchannels, nsamples
5846 #############END nnlswrap#############
1261 if self.__remData is None:
1262 newData = dataOut.data
1263 else:
1264 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
1265
5847
1266 self.__profileIndex += 1
5848 #estimate relative error for deconvolved profile (scaling irrelevant)
1267
5849
1268 if self.__profileIndex < n:
5850 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
1269 self.__remData = newData
1270 #continue
1271 return
1272
5851
1273 self.__profileIndex = 0
5852 aux=0
1274 self.__remData = None
1275
5853
1276 dataOut.data = newData
5854 for i in range(dataOut.IBITS,dataOut.NACF):
1277 dataOut.flagNoData = False
5855 self.dpulse[i]=self.lpulse[i]=0.0
5856 for j in range(dataOut.IBITS):
5857 k=int(i-j)
5858 if k<36-aux and k>16:
5859 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5860 elif k>=36-aux:
5861 self.lpulse[i]+=self.powerb[k]
5862 self.lagp[i]=self.powera[i]
1278
5863
1279 profileIndex = dataOut.profileIndex/n
5864 #find scale factor that best merges profiles
1280
5865
5866 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5867 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5868 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5869 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5870 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
1281
5871
1282 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
5872 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
5873 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
1283
5874
1284 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
5875 #form density profile estimate, merging rescaled power profiles
1285
5876
1286 dataOut.nProfiles = int(dataOut.nProfiles/n)
5877 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
5878 self.powerb[36-aux:dataOut.NACF]*=beta
1287
5879
1288 dataOut.profileIndex = profileIndex
5880 #form Ne estimate, fill in error estimate at low altitudes
1289
5881
1290 dataOut.ippSeconds *= n
5882 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5883 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
1291
5884
5885 #now do error propagation: store zero lag error covariance in u
5886
5887 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
5888
5889 for i in range(dataOut.NACF):
5890 for j in range(i,dataOut.NACF):
5891 if j-i>=dataOut.IBITS:
5892 self.u[i,j]=0.0
5893 else:
5894 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5895 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5896 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5897
5898 self.u[j,i]=self.u[i,j]
5899
5900 #now error analyis for lag product matrix (diag), place in acf_err
5901
5902 for i in range(dataOut.NACF):
5903 for j in range(dataOut.IBITS):
5904 if j==0:
5905 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5906 else:
5907 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5908
5909 #with suppress_stdout_stderr():
5910 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5911 '''
5912 if dataOut.status>=3.5:
5913 dataOut.te[:]=numpy.nan
5914 dataOut.ete[:]=numpy.nan
5915 dataOut.ti[:]=numpy.nan
5916 dataOut.eti[:]=numpy.nan
5917 dataOut.ph[:]=numpy.nan
5918 dataOut.eph[:]=numpy.nan
5919 dataOut.phe[:]=numpy.nan
5920 dataOut.ephe[:]=numpy.nan
5921 '''
1292 return dataOut
5922 return dataOut
1293
5923
5924
1294 class PulsePairVoltage(Operation):
5925 class PulsePairVoltage(Operation):
1295 '''
5926 '''
1296 Function PulsePair(Signal Power, Velocity)
5927 Function PulsePair(Signal Power, Velocity)
@@ -61,4 +61,4 class PXParametersProc(ProcessingUnit):
61 meta[attr] = getattr(self.dataOut, attr)
61 meta[attr] = getattr(self.dataOut, attr)
62
62
63 meta['mode'] = mode
63 meta['mode'] = mode
64 self.dataOut.meta = meta No newline at end of file
64 self.dataOut.meta = meta
@@ -1,6 +1,6
1 import argparse
1 import argparse
2
2
3 from schainpy.controller import Project, multiSchain
3 from schainpy.controller import Project#, multiSchain
4
4
5 desc = "HF_EXAMPLE"
5 desc = "HF_EXAMPLE"
6
6
General Comments 0
You need to be logged in to leave comments. Login now