The requested changes are too big and content was truncated. Show full diff
This diff has been collapsed as it changes many lines, (1156 lines changed) Show them Hide them | |||
@@ -0,0 +1,1156 | |||
|
1 | ||
|
2 | import os | |
|
3 | import datetime | |
|
4 | import numpy | |
|
5 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG | |
|
6 | ||
|
7 | from .jroplot_spectra import RTIPlot, NoisePlot | |
|
8 | ||
|
9 | from schainpy.utils import log | |
|
10 | from .plotting_codes import * | |
|
11 | ||
|
12 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
|
13 | ||
|
14 | import matplotlib.pyplot as plt | |
|
15 | import matplotlib.colors as colors | |
|
16 | ||
|
17 | import time | |
|
18 | import math | |
|
19 | ||
|
20 | ||
|
21 | from matplotlib.ticker import MultipleLocator | |
|
22 | ||
|
23 | ||
|
24 | ||
|
25 | class RTIDPPlot(RTIPlot): | |
|
26 | ||
|
27 | ''' | |
|
28 | Plot for RTI Double Pulse Experiment | |
|
29 | ''' | |
|
30 | ||
|
31 | CODE = 'RTIDP' | |
|
32 | colormap = 'jro' | |
|
33 | plot_name = 'RTI' | |
|
34 | ||
|
35 | #cb_label = 'Ne Electron Density (1/cm3)' | |
|
36 | ||
|
37 | def setup(self): | |
|
38 | self.xaxis = 'time' | |
|
39 | self.ncols = 1 | |
|
40 | self.nrows = 3 | |
|
41 | self.nplots = self.nrows | |
|
42 | #self.height=10 | |
|
43 | if self.showSNR: | |
|
44 | self.nrows += 1 | |
|
45 | self.nplots += 1 | |
|
46 | ||
|
47 | self.ylabel = 'Height [km]' | |
|
48 | self.xlabel = 'Time (LT)' | |
|
49 | ||
|
50 | self.cb_label = 'Intensity (dB)' | |
|
51 | ||
|
52 | ||
|
53 | #self.cb_label = cb_label | |
|
54 | ||
|
55 | self.titles = ['{} Channel {}'.format( | |
|
56 | self.plot_name.upper(), '0x1'),'{} Channel {}'.format( | |
|
57 | self.plot_name.upper(), '0'),'{} Channel {}'.format( | |
|
58 | self.plot_name.upper(), '1')] | |
|
59 | ||
|
60 | ||
|
61 | def plot(self): | |
|
62 | ||
|
63 | self.data.normalize_heights() | |
|
64 | self.x = self.data.times | |
|
65 | self.y = self.data.heights[0:self.data.NDP] | |
|
66 | ||
|
67 | if self.showSNR: | |
|
68 | self.z = numpy.concatenate( | |
|
69 | (self.data[self.CODE], self.data['snr']) | |
|
70 | ) | |
|
71 | else: | |
|
72 | ||
|
73 | self.z = self.data[self.CODE] | |
|
74 | #print(numpy.max(self.z[0,0:])) | |
|
75 | ||
|
76 | self.z = numpy.ma.masked_invalid(self.z) | |
|
77 | ||
|
78 | if self.decimation is None: | |
|
79 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
|
80 | else: | |
|
81 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
82 | ||
|
83 | for n, ax in enumerate(self.axes): | |
|
84 | ||
|
85 | ||
|
86 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
|
87 | self.z[1][0,12:40]) | |
|
88 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
|
89 | self.z[1][0,12:40]) | |
|
90 | ||
|
91 | ||
|
92 | ||
|
93 | if ax.firsttime: | |
|
94 | ||
|
95 | if self.zlimits is not None: | |
|
96 | self.zmin, self.zmax = self.zlimits[n] | |
|
97 | ||
|
98 | ||
|
99 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
100 | vmin=self.zmin, | |
|
101 | vmax=self.zmax, | |
|
102 | cmap=self.cmaps[n] | |
|
103 | ) | |
|
104 | #plt.tight_layout() | |
|
105 | else: | |
|
106 | if self.zlimits is not None: | |
|
107 | self.zmin, self.zmax = self.zlimits[n] | |
|
108 | ax.collections.remove(ax.collections[0]) | |
|
109 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
110 | vmin=self.zmin, | |
|
111 | vmax=self.zmax, | |
|
112 | cmap=self.cmaps[n] | |
|
113 | ) | |
|
114 | #plt.tight_layout() | |
|
115 | ||
|
116 | ||
|
117 | class RTILPPlot(RTIPlot): | |
|
118 | ||
|
119 | ''' | |
|
120 | Plot for RTI Long Pulse | |
|
121 | ''' | |
|
122 | ||
|
123 | CODE = 'RTILP' | |
|
124 | colormap = 'jro' | |
|
125 | plot_name = 'RTI LP' | |
|
126 | ||
|
127 | #cb_label = 'Ne Electron Density (1/cm3)' | |
|
128 | ||
|
129 | def setup(self): | |
|
130 | self.xaxis = 'time' | |
|
131 | self.ncols = 1 | |
|
132 | self.nrows = 4 | |
|
133 | self.nplots = self.nrows | |
|
134 | if self.showSNR: | |
|
135 | self.nrows += 1 | |
|
136 | self.nplots += 1 | |
|
137 | ||
|
138 | self.ylabel = 'Height [km]' | |
|
139 | self.xlabel = 'Time (LT)' | |
|
140 | ||
|
141 | self.cb_label = 'Intensity (dB)' | |
|
142 | ||
|
143 | ||
|
144 | ||
|
145 | #self.cb_label = cb_label | |
|
146 | ||
|
147 | self.titles = ['{} Channel {}'.format( | |
|
148 | self.plot_name.upper(), '0'),'{} Channel {}'.format( | |
|
149 | self.plot_name.upper(), '1'),'{} Channel {}'.format( | |
|
150 | self.plot_name.upper(), '2'),'{} Channel {}'.format( | |
|
151 | self.plot_name.upper(), '3')] | |
|
152 | ||
|
153 | ||
|
154 | def plot(self): | |
|
155 | ||
|
156 | self.data.normalize_heights() | |
|
157 | self.x = self.data.times | |
|
158 | self.y = self.data.heights[0:self.data.NRANGE] | |
|
159 | ||
|
160 | if self.showSNR: | |
|
161 | self.z = numpy.concatenate( | |
|
162 | (self.data[self.CODE], self.data['snr']) | |
|
163 | ) | |
|
164 | else: | |
|
165 | ||
|
166 | self.z = self.data[self.CODE] | |
|
167 | #print(numpy.max(self.z[0,0:])) | |
|
168 | ||
|
169 | self.z = numpy.ma.masked_invalid(self.z) | |
|
170 | ||
|
171 | if self.decimation is None: | |
|
172 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
|
173 | else: | |
|
174 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
175 | ||
|
176 | for n, ax in enumerate(self.axes): | |
|
177 | ||
|
178 | ||
|
179 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
|
180 | self.z[1][0,12:40]) | |
|
181 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
|
182 | self.z[1][0,12:40]) | |
|
183 | ||
|
184 | if ax.firsttime: | |
|
185 | ||
|
186 | if self.zlimits is not None: | |
|
187 | self.zmin, self.zmax = self.zlimits[n] | |
|
188 | ||
|
189 | ||
|
190 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
191 | vmin=self.zmin, | |
|
192 | vmax=self.zmax, | |
|
193 | cmap=self.cmaps[n] | |
|
194 | ) | |
|
195 | #plt.tight_layout() | |
|
196 | else: | |
|
197 | if self.zlimits is not None: | |
|
198 | self.zmin, self.zmax = self.zlimits[n] | |
|
199 | ax.collections.remove(ax.collections[0]) | |
|
200 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
201 | vmin=self.zmin, | |
|
202 | vmax=self.zmax, | |
|
203 | cmap=self.cmaps[n] | |
|
204 | ) | |
|
205 | #plt.tight_layout() | |
|
206 | ||
|
207 | ||
|
208 | class DenRTIPlot(RTIPlot): | |
|
209 | ||
|
210 | ''' | |
|
211 | Plot for Den | |
|
212 | ''' | |
|
213 | ||
|
214 | CODE = 'denrti' | |
|
215 | colormap = 'jro' | |
|
216 | plot_name = 'Electron Density' | |
|
217 | ||
|
218 | #cb_label = 'Ne Electron Density (1/cm3)' | |
|
219 | ||
|
220 | def setup(self): | |
|
221 | self.xaxis = 'time' | |
|
222 | self.ncols = 1 | |
|
223 | self.nrows = self.data.shape(self.CODE)[0] | |
|
224 | self.nplots = self.nrows | |
|
225 | if self.showSNR: | |
|
226 | self.nrows += 1 | |
|
227 | self.nplots += 1 | |
|
228 | ||
|
229 | self.ylabel = 'Height [km]' | |
|
230 | self.xlabel = 'Time (LT)' | |
|
231 | ||
|
232 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
233 | ||
|
234 | if self.CODE == 'denrti' or self.CODE=='denrtiLP': | |
|
235 | self.cb_label = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)' | |
|
236 | ||
|
237 | #self.cb_label = cb_label | |
|
238 | if not self.titles: | |
|
239 | self.titles = self.data.parameters \ | |
|
240 | if self.data.parameters else ['{}'.format(self.plot_name)] | |
|
241 | if self.showSNR: | |
|
242 | self.titles.append('SNR') | |
|
243 | ||
|
244 | def plot(self): | |
|
245 | ||
|
246 | self.data.normalize_heights() | |
|
247 | self.x = self.data.times | |
|
248 | self.y = self.data.heights | |
|
249 | ||
|
250 | ||
|
251 | ||
|
252 | if self.showSNR: | |
|
253 | self.z = numpy.concatenate( | |
|
254 | (self.data[self.CODE], self.data['snr']) | |
|
255 | ) | |
|
256 | else: | |
|
257 | self.z = self.data[self.CODE] | |
|
258 | ||
|
259 | self.z = numpy.ma.masked_invalid(self.z) | |
|
260 | ||
|
261 | if self.decimation is None: | |
|
262 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
|
263 | else: | |
|
264 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
265 | ||
|
266 | for n, ax in enumerate(self.axes): | |
|
267 | ||
|
268 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
|
269 | self.z[n]) | |
|
270 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
|
271 | self.z[n]) | |
|
272 | ||
|
273 | if ax.firsttime: | |
|
274 | ||
|
275 | if self.zlimits is not None: | |
|
276 | self.zmin, self.zmax = self.zlimits[n] | |
|
277 | if numpy.log10(self.zmin)<0: | |
|
278 | self.zmin=1 | |
|
279 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
280 | vmin=self.zmin, | |
|
281 | vmax=self.zmax, | |
|
282 | cmap=self.cmaps[n], | |
|
283 | norm=colors.LogNorm() | |
|
284 | ) | |
|
285 | #plt.tight_layout() | |
|
286 | ||
|
287 | else: | |
|
288 | if self.zlimits is not None: | |
|
289 | self.zmin, self.zmax = self.zlimits[n] | |
|
290 | ax.collections.remove(ax.collections[0]) | |
|
291 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
292 | vmin=self.zmin, | |
|
293 | vmax=self.zmax, | |
|
294 | cmap=self.cmaps[n], | |
|
295 | norm=colors.LogNorm() | |
|
296 | ) | |
|
297 | #plt.tight_layout() | |
|
298 | ||
|
299 | ||
|
300 | ||
|
301 | class DenRTILPPlot(DenRTIPlot): | |
|
302 | ||
|
303 | ''' | |
|
304 | Plot for Electron Temperature | |
|
305 | ''' | |
|
306 | ||
|
307 | CODE = 'denrtiLP' | |
|
308 | colormap = 'jro' | |
|
309 | plot_name = 'Electron Density' | |
|
310 | ||
|
311 | ||
|
312 | class ETempRTIPlot(RTIPlot): | |
|
313 | ||
|
314 | ''' | |
|
315 | Plot for Electron Temperature | |
|
316 | ''' | |
|
317 | ||
|
318 | CODE = 'ETemp' | |
|
319 | colormap = 'jet' | |
|
320 | plot_name = 'Electron Temperature' | |
|
321 | ||
|
322 | #cb_label = 'Ne Electron Density (1/cm3)' | |
|
323 | ||
|
324 | def setup(self): | |
|
325 | self.xaxis = 'time' | |
|
326 | self.ncols = 1 | |
|
327 | self.nrows = self.data.shape(self.CODE)[0] | |
|
328 | self.nplots = self.nrows | |
|
329 | if self.showSNR: | |
|
330 | self.nrows += 1 | |
|
331 | self.nplots += 1 | |
|
332 | ||
|
333 | self.ylabel = 'Height [km]' | |
|
334 | self.xlabel = 'Time (LT)' | |
|
335 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
336 | if self.CODE == 'ETemp' or self.CODE == 'ETempLP': | |
|
337 | self.cb_label = 'Electron Temperature (K)' | |
|
338 | if self.CODE == 'ITemp' or self.CODE == 'ITempLP': | |
|
339 | self.cb_label = 'Ion Temperature (K)' | |
|
340 | ||
|
341 | ||
|
342 | if not self.titles: | |
|
343 | self.titles = self.data.parameters \ | |
|
344 | if self.data.parameters else ['{}'.format(self.plot_name)] | |
|
345 | if self.showSNR: | |
|
346 | self.titles.append('SNR') | |
|
347 | ||
|
348 | def plot(self): | |
|
349 | ||
|
350 | self.data.normalize_heights() | |
|
351 | self.x = self.data.times | |
|
352 | self.y = self.data.heights | |
|
353 | ||
|
354 | if self.showSNR: | |
|
355 | self.z = numpy.concatenate( | |
|
356 | (self.data[self.CODE], self.data['snr']) | |
|
357 | ) | |
|
358 | else: | |
|
359 | self.z = self.data[self.CODE] | |
|
360 | ||
|
361 | self.z = numpy.ma.masked_invalid(self.z) | |
|
362 | ||
|
363 | if self.decimation is None: | |
|
364 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
|
365 | else: | |
|
366 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
367 | ||
|
368 | for n, ax in enumerate(self.axes): | |
|
369 | ||
|
370 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
|
371 | self.z[n]) | |
|
372 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
|
373 | self.z[n]) | |
|
374 | ||
|
375 | if ax.firsttime: | |
|
376 | ||
|
377 | if self.zlimits is not None: | |
|
378 | self.zmin, self.zmax = self.zlimits[n] | |
|
379 | ||
|
380 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
381 | vmin=self.zmin, | |
|
382 | vmax=self.zmax, | |
|
383 | cmap=self.cmaps[n] | |
|
384 | ) | |
|
385 | #plt.tight_layout() | |
|
386 | ||
|
387 | else: | |
|
388 | if self.zlimits is not None: | |
|
389 | self.zmin, self.zmax = self.zlimits[n] | |
|
390 | ax.collections.remove(ax.collections[0]) | |
|
391 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
|
392 | vmin=self.zmin, | |
|
393 | vmax=self.zmax, | |
|
394 | cmap=self.cmaps[n] | |
|
395 | ) | |
|
396 | #plt.tight_layout() | |
|
397 | ||
|
398 | ||
|
399 | ||
|
400 | class ITempRTIPlot(ETempRTIPlot): | |
|
401 | ||
|
402 | ''' | |
|
403 | Plot for Ion Temperature | |
|
404 | ''' | |
|
405 | ||
|
406 | CODE = 'ITemp' | |
|
407 | colormap = 'jet' | |
|
408 | plot_name = 'Ion Temperature' | |
|
409 | ||
|
410 | ||
|
411 | class ElectronTempLPPlot(ETempRTIPlot): | |
|
412 | ||
|
413 | ''' | |
|
414 | Plot for Electron Temperature LP | |
|
415 | ''' | |
|
416 | ||
|
417 | CODE = 'ETempLP' | |
|
418 | colormap = 'jet' | |
|
419 | plot_name = 'Electron Temperature' | |
|
420 | ||
|
421 | ||
|
422 | class IonTempLPPlot(ETempRTIPlot): | |
|
423 | ||
|
424 | ''' | |
|
425 | Plot for Ion Temperature LP | |
|
426 | ''' | |
|
427 | ||
|
428 | CODE = 'ITempLP' | |
|
429 | colormap = 'jet' | |
|
430 | plot_name = 'Ion Temperature' | |
|
431 | ||
|
432 | ||
|
433 | class HFracRTIPlot(ETempRTIPlot): | |
|
434 | ||
|
435 | ''' | |
|
436 | Plot for H+ LP | |
|
437 | ''' | |
|
438 | ||
|
439 | CODE = 'HFracLP' | |
|
440 | colormap = 'jet' | |
|
441 | plot_name = 'H+ Frac' | |
|
442 | ||
|
443 | ||
|
444 | class HeFracRTIPlot(ETempRTIPlot): | |
|
445 | ||
|
446 | ''' | |
|
447 | Plot for He+ LP | |
|
448 | ''' | |
|
449 | ||
|
450 | CODE = 'HeFracLP' | |
|
451 | colormap = 'jet' | |
|
452 | plot_name = 'He+ Frac' | |
|
453 | ||
|
454 | ||
|
455 | class TempsDPPlot(Plot): | |
|
456 | ''' | |
|
457 | Plot for Electron - Ion Temperatures | |
|
458 | ''' | |
|
459 | ||
|
460 | CODE = 'tempsDP' | |
|
461 | plot_name = 'Temperatures' | |
|
462 | plot_type = 'scatterbuffer' | |
|
463 | ||
|
464 | ||
|
465 | def setup(self): | |
|
466 | ||
|
467 | self.ncols = 1 | |
|
468 | self.nrows = 1 | |
|
469 | self.nplots = 1 | |
|
470 | self.ylabel = 'Range [km]' | |
|
471 | self.xlabel = 'Temperature (K)' | |
|
472 | self.width = 3.5 | |
|
473 | self.height = 5.5 | |
|
474 | self.colorbar = False | |
|
475 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
476 | if not self.titles: | |
|
477 | self.titles = self.data.parameters \ | |
|
478 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
479 | ||
|
480 | def plot(self): | |
|
481 | ||
|
482 | self.x = self.data['tempsDP'][:,-1] | |
|
483 | self.y = self.data.heights[0:self.data.NSHTS] | |
|
484 | ||
|
485 | self.xmin = -100 | |
|
486 | self.xmax = 5000 | |
|
487 | ax = self.axes[0] | |
|
488 | ||
|
489 | if ax.firsttime: | |
|
490 | ||
|
491 | ax.errorbar(self.x, self.y, xerr=self.data.ete2, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te') | |
|
492 | ax.errorbar(self.data.ti2, self.y, fmt='k^', xerr=self.data.eti2,elinewidth=1.0,color='b',linewidth=2.0, label='Ti') | |
|
493 | plt.legend(loc='lower right') | |
|
494 | self.ystep_given = 50 | |
|
495 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
496 | ax.grid(which='minor') | |
|
497 | #plt.tight_layout() | |
|
498 | ||
|
499 | ||
|
500 | else: | |
|
501 | self.clear_figures() | |
|
502 | ax.errorbar(self.x, self.y, xerr=self.data.ete2, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te') | |
|
503 | ax.errorbar(self.data.ti2, self.y, fmt='k^', xerr=self.data.eti2,elinewidth=1.0,color='b',linewidth=2.0, label='Ti') | |
|
504 | plt.legend(loc='lower right') | |
|
505 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
506 | #plt.tight_layout() | |
|
507 | ||
|
508 | ||
|
509 | class TempsHPPlot(Plot): | |
|
510 | ''' | |
|
511 | Plot for Temperatures Hybrid Experiment | |
|
512 | ''' | |
|
513 | ||
|
514 | CODE = 'temps_LP' | |
|
515 | plot_name = 'Temperatures' | |
|
516 | plot_type = 'scatterbuffer' | |
|
517 | ||
|
518 | ||
|
519 | def setup(self): | |
|
520 | ||
|
521 | self.ncols = 1 | |
|
522 | self.nrows = 1 | |
|
523 | self.nplots = 1 | |
|
524 | self.ylabel = 'Range [km]' | |
|
525 | self.xlabel = 'Temperature (K)' | |
|
526 | self.width = 3.5 | |
|
527 | self.height = 6.5 | |
|
528 | self.colorbar = False | |
|
529 | if not self.titles: | |
|
530 | self.titles = self.data.parameters \ | |
|
531 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
532 | ||
|
533 | def plot(self): | |
|
534 | ||
|
535 | self.x = self.data['temps_LP'][:,-1] | |
|
536 | self.y = self.data.heights[0:self.data.NACF] | |
|
537 | self.xmin = -100 | |
|
538 | self.xmax = 4500 | |
|
539 | ax = self.axes[0] | |
|
540 | ||
|
541 | if ax.firsttime: | |
|
542 | ||
|
543 | ax.errorbar(self.x, self.y, xerr=self.data.ete, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te') | |
|
544 | ax.errorbar(self.data.ti, self.y, fmt='k^', xerr=self.data.eti,elinewidth=1.0,color='b',linewidth=2.0, label='Ti') | |
|
545 | plt.legend(loc='lower right') | |
|
546 | self.ystep_given = 200 | |
|
547 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
548 | ax.grid(which='minor') | |
|
549 | #plt.tight_layout() | |
|
550 | ||
|
551 | ||
|
552 | else: | |
|
553 | self.clear_figures() | |
|
554 | ax.errorbar(self.x, self.y, xerr=self.data.ete, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te') | |
|
555 | ax.errorbar(self.data.ti, self.y, fmt='k^', xerr=self.data.eti,elinewidth=1.0,color='b',linewidth=2.0, label='Ti') | |
|
556 | plt.legend(loc='lower right') | |
|
557 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
558 | #plt.tight_layout() | |
|
559 | ||
|
560 | ||
|
561 | class FracsHPPlot(Plot): | |
|
562 | ''' | |
|
563 | Plot for Composition LP | |
|
564 | ''' | |
|
565 | ||
|
566 | CODE = 'fracs_LP' | |
|
567 | plot_name = 'Composition' | |
|
568 | plot_type = 'scatterbuffer' | |
|
569 | ||
|
570 | ||
|
571 | def setup(self): | |
|
572 | ||
|
573 | self.ncols = 1 | |
|
574 | self.nrows = 1 | |
|
575 | self.nplots = 1 | |
|
576 | self.ylabel = 'Range [km]' | |
|
577 | self.xlabel = 'Frac' | |
|
578 | self.width = 3.5 | |
|
579 | self.height = 6.5 | |
|
580 | self.colorbar = False | |
|
581 | if not self.titles: | |
|
582 | self.titles = self.data.parameters \ | |
|
583 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
584 | ||
|
585 | def plot(self): | |
|
586 | ||
|
587 | self.x = self.data['fracs_LP'][:,-1] | |
|
588 | self.y = self.data.heights[0:self.data.NACF] | |
|
589 | ||
|
590 | self.xmin = 0 | |
|
591 | self.xmax = 1 | |
|
592 | ax = self.axes[0] | |
|
593 | ||
|
594 | if ax.firsttime: | |
|
595 | ||
|
596 | ax.errorbar(self.x, self.y[self.data.cut:], xerr=self.data.eph, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='H+') | |
|
597 | ax.errorbar(self.data.phe, self.y[self.data.cut:], fmt='k^', xerr=self.data.ephe,elinewidth=1.0,color='b',linewidth=2.0, label='He+') | |
|
598 | plt.legend(loc='lower right') | |
|
599 | self.xstep_given = 0.2 | |
|
600 | self.ystep_given = 200 | |
|
601 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
602 | ax.grid(which='minor') | |
|
603 | #plt.tight_layout() | |
|
604 | ||
|
605 | ||
|
606 | else: | |
|
607 | self.clear_figures() | |
|
608 | ax.errorbar(self.x, self.y[self.data.cut:], xerr=self.data.eph, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='H+') | |
|
609 | ax.errorbar(self.data.phe, self.y[self.data.cut:], fmt='k^', xerr=self.data.ephe,elinewidth=1.0,color='b',linewidth=2.0, label='He+') | |
|
610 | plt.legend(loc='lower right') | |
|
611 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
612 | #plt.tight_layout() | |
|
613 | ||
|
614 | ||
|
615 | ||
|
616 | class EDensityPlot(Plot): | |
|
617 | ''' | |
|
618 | Plot for electron density | |
|
619 | ''' | |
|
620 | ||
|
621 | CODE = 'den' | |
|
622 | plot_name = 'Electron Density' | |
|
623 | plot_type = 'scatterbuffer' | |
|
624 | ||
|
625 | ||
|
626 | def setup(self): | |
|
627 | ||
|
628 | self.ncols = 1 | |
|
629 | self.nrows = 1 | |
|
630 | self.nplots = 1 | |
|
631 | self.ylabel = 'Range [km]' | |
|
632 | self.xlabel = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)' | |
|
633 | self.width = 4 | |
|
634 | self.height = 6.5 | |
|
635 | self.colorbar = False | |
|
636 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
637 | if not self.titles: | |
|
638 | self.titles = self.data.parameters \ | |
|
639 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
640 | ||
|
641 | def plot(self): | |
|
642 | ||
|
643 | ||
|
644 | self.x = self.data[self.CODE] | |
|
645 | self.y = self.data.heights | |
|
646 | self.xmin = 1000 | |
|
647 | self.xmax = 10000000 | |
|
648 | ax = self.axes[0] | |
|
649 | ||
|
650 | if ax.firsttime: | |
|
651 | self.autoxticks=False | |
|
652 | #if self.CODE=='den': | |
|
653 | ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
654 | #ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=self.data.sdn1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
655 | ||
|
656 | ax.errorbar(self.x[:,-1], self.y[:self.data.NSHTS], fmt='k^-', xerr=self.data.sdp2,elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2) | |
|
657 | #else: | |
|
658 | #ax.errorbar(self.data.dphi[:self.data.cut], self.y[:self.data.cut], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
659 | #ax.errorbar(self.x[:self.data.cut,-1], self.y[:self.data.cut], fmt='k^-', xerr=self.data.sdp2[:self.data.cut],elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2) | |
|
660 | ||
|
661 | if self.CODE=='denLP': | |
|
662 | ax.errorbar(self.data.ne[self.data.cut:], self.y[self.data.cut:], xerr=self.data.ene[self.data.cut:], fmt='r^-',elinewidth=1.0,color='r',linewidth=1.0, label='LP Profile',markersize=2) | |
|
663 | ||
|
664 | plt.legend(loc='upper right') | |
|
665 | ax.set_xscale("log", nonposx='clip') | |
|
666 | grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50) | |
|
667 | self.ystep_given=100 | |
|
668 | if self.CODE=='denLP': | |
|
669 | self.ystep_given=200 | |
|
670 | ax.set_yticks(grid_y_ticks,minor=True) | |
|
671 | ax.grid(which='minor') | |
|
672 | #plt.tight_layout() | |
|
673 | ||
|
674 | ||
|
675 | ||
|
676 | else: | |
|
677 | ||
|
678 | self.clear_figures() | |
|
679 | #if self.CODE=='den': | |
|
680 | ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
681 | #ax.errorbar(self.data.dphi, self.y[:self.data.NSHTS], xerr=self.data.sdn1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
682 | ||
|
683 | ax.errorbar(self.x[:,-1], self.y[:self.data.NSHTS], fmt='k^-', xerr=self.data.sdp2,elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2) | |
|
684 | ax.errorbar(self.x[:,-2], self.y[:self.data.NSHTS], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed") | |
|
685 | #else: | |
|
686 | #ax.errorbar(self.data.dphi[:self.data.cut], self.y[:self.data.cut], xerr=1, fmt='h-',elinewidth=1.0,color='g',linewidth=1.0, label='Faraday Profile',markersize=2) | |
|
687 | #ax.errorbar(self.x[:self.data.cut,-1], self.y[:self.data.cut], fmt='k^-', xerr=self.data.sdp2[:self.data.cut],elinewidth=1.0,color='b',linewidth=1.0, label='Power Profile',markersize=2) | |
|
688 | #ax.errorbar(self.x[:self.data.cut,-2], self.y[:self.data.cut], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed") | |
|
689 | ||
|
690 | if self.CODE=='denLP': | |
|
691 | ax.errorbar(self.data.ne[self.data.cut:], self.y[self.data.cut:], fmt='r^-', xerr=self.data.ene[self.data.cut:],elinewidth=1.0,color='r',linewidth=1.0, label='LP Profile',markersize=2) | |
|
692 | ||
|
693 | ax.set_xscale("log", nonposx='clip') | |
|
694 | grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50) | |
|
695 | ax.set_yticks(grid_y_ticks,minor=True) | |
|
696 | ax.grid(which='minor') | |
|
697 | plt.legend(loc='upper right') | |
|
698 | #plt.tight_layout() | |
|
699 | ||
|
700 | class FaradayAnglePlot(Plot): | |
|
701 | ''' | |
|
702 | Plot for electron density | |
|
703 | ''' | |
|
704 | ||
|
705 | CODE = 'FaradayAngle' | |
|
706 | plot_name = 'Faraday Angle' | |
|
707 | plot_type = 'scatterbuffer' | |
|
708 | ||
|
709 | ||
|
710 | def setup(self): | |
|
711 | ||
|
712 | self.ncols = 1 | |
|
713 | self.nrows = 1 | |
|
714 | self.nplots = 1 | |
|
715 | self.ylabel = 'Range [km]' | |
|
716 | self.xlabel = 'Faraday Angle (º)' | |
|
717 | self.width = 4 | |
|
718 | self.height = 6.5 | |
|
719 | self.colorbar = False | |
|
720 | if not self.titles: | |
|
721 | self.titles = self.data.parameters \ | |
|
722 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
723 | ||
|
724 | def plot(self): | |
|
725 | ||
|
726 | ||
|
727 | self.x = self.data[self.CODE] | |
|
728 | self.y = self.data.heights | |
|
729 | self.xmin = -180 | |
|
730 | self.xmax = 180 | |
|
731 | ax = self.axes[0] | |
|
732 | ||
|
733 | if ax.firsttime: | |
|
734 | self.autoxticks=False | |
|
735 | #if self.CODE=='den': | |
|
736 | ax.plot(self.x, self.y,marker='o',color='g',linewidth=1.0,markersize=2) | |
|
737 | ||
|
738 | grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50) | |
|
739 | self.ystep_given=100 | |
|
740 | if self.CODE=='denLP': | |
|
741 | self.ystep_given=200 | |
|
742 | ax.set_yticks(grid_y_ticks,minor=True) | |
|
743 | ax.grid(which='minor') | |
|
744 | #plt.tight_layout() | |
|
745 | else: | |
|
746 | ||
|
747 | self.clear_figures() | |
|
748 | #if self.CODE=='den': | |
|
749 | #print(numpy.shape(self.x)) | |
|
750 | ax.plot(self.x[:,-1], self.y, marker='o',color='g',linewidth=1.0, markersize=2) | |
|
751 | ||
|
752 | grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50) | |
|
753 | ax.set_yticks(grid_y_ticks,minor=True) | |
|
754 | ax.grid(which='minor') | |
|
755 | ||
|
756 | class EDensityHPPlot(EDensityPlot): | |
|
757 | ||
|
758 | ''' | |
|
759 | Plot for Electron Density Hybrid Experiment | |
|
760 | ''' | |
|
761 | ||
|
762 | CODE = 'denLP' | |
|
763 | plot_name = 'Electron Density' | |
|
764 | plot_type = 'scatterbuffer' | |
|
765 | ||
|
766 | ||
|
767 | class ACFsPlot(Plot): | |
|
768 | ''' | |
|
769 | Plot for ACFs Double Pulse Experiment | |
|
770 | ''' | |
|
771 | ||
|
772 | CODE = 'acfs' | |
|
773 | plot_name = 'ACF' | |
|
774 | plot_type = 'scatterbuffer' | |
|
775 | ||
|
776 | ||
|
777 | def setup(self): | |
|
778 | #self.xaxis = 'time' | |
|
779 | self.ncols = 1 | |
|
780 | self.nrows = 1 | |
|
781 | self.nplots = 1 | |
|
782 | self.ylabel = 'Range [km]' | |
|
783 | self.xlabel = 'lags (ms)' | |
|
784 | self.width = 3.5 | |
|
785 | self.height = 6 | |
|
786 | self.colorbar = False | |
|
787 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
788 | if not self.titles: | |
|
789 | self.titles = self.data.parameters \ | |
|
790 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
791 | ||
|
792 | def plot(self): | |
|
793 | ||
|
794 | self.x = self.data.lags_to_plot | |
|
795 | self.y = self.data['acfs'][:,-1] | |
|
796 | ||
|
797 | ||
|
798 | self.xmin = 0.0 | |
|
799 | self.xmax = 2.0 | |
|
800 | ||
|
801 | ax = self.axes[0] | |
|
802 | ||
|
803 | if ax.firsttime: | |
|
804 | ||
|
805 | for i in range(self.data.NSHTS): | |
|
806 | x_aux = numpy.isfinite(self.x[i,:]) | |
|
807 | y_aux = numpy.isfinite(self.y[i,:]) | |
|
808 | yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:]) | |
|
809 | x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:]) | |
|
810 | y_igcej_aux = numpy.isfinite(self.data.y_igcej_to_plot[i,:]) | |
|
811 | x_ibad_aux = numpy.isfinite(self.data.x_ibad_to_plot[i,:]) | |
|
812 | y_ibad_aux = numpy.isfinite(self.data.y_ibad_to_plot[i,:]) | |
|
813 | if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2: | |
|
814 | ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.acfs_error_to_plot[i,x_aux],color='b',marker='o',linewidth=1.0,markersize=2) | |
|
815 | ax.plot(self.data.x_igcej_to_plot[i,x_igcej_aux],self.data.y_igcej_to_plot[i,y_igcej_aux],'x',color='red',markersize=2) | |
|
816 | ax.plot(self.data.x_ibad_to_plot[i,x_ibad_aux],self.data.y_ibad_to_plot[i,y_ibad_aux],'X',color='red',markersize=2) | |
|
817 | ||
|
818 | self.xstep_given = (self.xmax-self.xmin)/(self.data.DPL-1) | |
|
819 | self.ystep_given = 50 | |
|
820 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
821 | ax.grid(which='minor') | |
|
822 | ||
|
823 | ||
|
824 | ||
|
825 | else: | |
|
826 | self.clear_figures() | |
|
827 | ||
|
828 | for i in range(self.data.NSHTS): | |
|
829 | x_aux = numpy.isfinite(self.x[i,:]) | |
|
830 | y_aux = numpy.isfinite(self.y[i,:]) | |
|
831 | yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:]) | |
|
832 | x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:]) | |
|
833 | y_igcej_aux = numpy.isfinite(self.data.y_igcej_to_plot[i,:]) | |
|
834 | x_ibad_aux = numpy.isfinite(self.data.x_ibad_to_plot[i,:]) | |
|
835 | y_ibad_aux = numpy.isfinite(self.data.y_ibad_to_plot[i,:]) | |
|
836 | if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2: | |
|
837 | ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.acfs_error_to_plot[i,x_aux],linewidth=1.0,markersize=2,color='b',marker='o') | |
|
838 | ax.plot(self.data.x_igcej_to_plot[i,x_igcej_aux],self.data.y_igcej_to_plot[i,y_igcej_aux],'x',color='red',markersize=2) | |
|
839 | ax.plot(self.data.x_ibad_to_plot[i,x_ibad_aux],self.data.y_ibad_to_plot[i,y_ibad_aux],'X',color='red',markersize=2) | |
|
840 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
841 | ||
|
842 | ||
|
843 | ||
|
844 | ||
|
845 | class ACFsLPPlot(Plot): | |
|
846 | ''' | |
|
847 | Plot for ACFs Double Pulse Experiment | |
|
848 | ''' | |
|
849 | ||
|
850 | CODE = 'acfs_LP' | |
|
851 | plot_name = 'ACF' | |
|
852 | plot_type = 'scatterbuffer' | |
|
853 | ||
|
854 | ||
|
855 | def setup(self): | |
|
856 | #self.xaxis = 'time' | |
|
857 | self.ncols = 1 | |
|
858 | self.nrows = 1 | |
|
859 | self.nplots = 1 | |
|
860 | self.ylabel = 'Range [km]' | |
|
861 | self.xlabel = 'lags (ms)' | |
|
862 | self.width = 3.5 | |
|
863 | self.height = 7 | |
|
864 | self.colorbar = False | |
|
865 | if not self.titles: | |
|
866 | self.titles = self.data.parameters \ | |
|
867 | if self.data.parameters else ['{}'.format(self.CODE.upper())] | |
|
868 | ||
|
869 | ||
|
870 | ||
|
871 | def plot(self): | |
|
872 | ||
|
873 | self.x = self.data.lags_LP_to_plot | |
|
874 | self.y = self.data['acfs_LP'][:,-1] | |
|
875 | ||
|
876 | self.xmin = 0.0 | |
|
877 | self.xmax = 1.5 | |
|
878 | ||
|
879 | ax = self.axes[0] | |
|
880 | ||
|
881 | if ax.firsttime: | |
|
882 | ||
|
883 | for i in range(self.data.NACF): | |
|
884 | x_aux = numpy.isfinite(self.x[i,:]) | |
|
885 | y_aux = numpy.isfinite(self.y[i,:]) | |
|
886 | yerr_aux = numpy.isfinite(self.data.errors[i,:]) | |
|
887 | ||
|
888 | if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2: | |
|
889 | ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.errors[i,x_aux],color='b',linewidth=1.0,markersize=2,ecolor='r') | |
|
890 | ||
|
891 | #self.xstep_given = (self.xmax-self.xmin)/(self.data.NLAG-1) | |
|
892 | self.xstep_given=0.3 | |
|
893 | self.ystep_given = 200 | |
|
894 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
895 | ax.grid(which='minor') | |
|
896 | ||
|
897 | else: | |
|
898 | self.clear_figures() | |
|
899 | ||
|
900 | for i in range(self.data.NACF): | |
|
901 | x_aux = numpy.isfinite(self.x[i,:]) | |
|
902 | y_aux = numpy.isfinite(self.y[i,:]) | |
|
903 | yerr_aux = numpy.isfinite(self.data.errors[i,:]) | |
|
904 | ||
|
905 | if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2: | |
|
906 | ax.errorbar(self.x[i,x_aux], self.y[i,y_aux], yerr=self.data.errors[i,x_aux],color='b',linewidth=1.0,markersize=2,ecolor='r') | |
|
907 | ||
|
908 | ax.yaxis.set_minor_locator(MultipleLocator(15)) | |
|
909 | ||
|
910 | ||
|
911 | class CrossProductsPlot(Plot): | |
|
912 | ''' | |
|
913 | Plot for cross products | |
|
914 | ''' | |
|
915 | ||
|
916 | CODE = 'crossprod' | |
|
917 | plot_name = 'Cross Products' | |
|
918 | plot_type = 'scatterbuffer' | |
|
919 | ||
|
920 | ||
|
921 | def setup(self): | |
|
922 | ||
|
923 | self.ncols = 3 | |
|
924 | self.nrows = 1 | |
|
925 | self.nplots = 3 | |
|
926 | self.ylabel = 'Range [km]' | |
|
927 | ||
|
928 | self.width = 3.5*self.nplots | |
|
929 | self.height = 5.5 | |
|
930 | self.colorbar = False | |
|
931 | self.titles = [] | |
|
932 | ||
|
933 | def plot(self): | |
|
934 | ||
|
935 | self.x = self.data['crossprod'][:,-1,:,:,:,:] | |
|
936 | ||
|
937 | ||
|
938 | ||
|
939 | ||
|
940 | self.y = self.data.heights[0:self.data.NDP] | |
|
941 | ||
|
942 | ||
|
943 | ||
|
944 | for n, ax in enumerate(self.axes): | |
|
945 | ||
|
946 | self.xmin=numpy.min(numpy.concatenate((self.x[n][0,20:30,0,0],self.x[n][1,20:30,0,0],self.x[n][2,20:30,0,0],self.x[n][3,20:30,0,0]))) | |
|
947 | self.xmax=numpy.max(numpy.concatenate((self.x[n][0,20:30,0,0],self.x[n][1,20:30,0,0],self.x[n][2,20:30,0,0],self.x[n][3,20:30,0,0]))) | |
|
948 | ||
|
949 | ||
|
950 | if ax.firsttime: | |
|
951 | ||
|
952 | self.autoxticks=False | |
|
953 | if n==0: | |
|
954 | label1='kax' | |
|
955 | label2='kay' | |
|
956 | label3='kbx' | |
|
957 | label4='kby' | |
|
958 | self.xlimits=[(self.xmin,self.xmax)] | |
|
959 | elif n==1: | |
|
960 | label1='kax2' | |
|
961 | label2='kay2' | |
|
962 | label3='kbx2' | |
|
963 | label4='kby2' | |
|
964 | self.xlimits.append((self.xmin,self.xmax)) | |
|
965 | elif n==2: | |
|
966 | label1='kaxay' | |
|
967 | label2='kbxby' | |
|
968 | label3='kaxbx' | |
|
969 | label4='kaxby' | |
|
970 | self.xlimits.append((self.xmin,self.xmax)) | |
|
971 | ||
|
972 | ||
|
973 | ax.plotline1 = ax.plot(self.x[n][0,:,0,0], self.y, color='r',linewidth=2.0, label=label1) | |
|
974 | ax.plotline2 = ax.plot(self.x[n][1,:,0,0], self.y, color='k',linewidth=2.0, label=label2) | |
|
975 | ax.plotline3 = ax.plot(self.x[n][2,:,0,0], self.y, color='b',linewidth=2.0, label=label3) | |
|
976 | ax.plotline4 = ax.plot(self.x[n][3,:,0,0], self.y, color='m',linewidth=2.0, label=label4) | |
|
977 | ax.legend(loc='upper right') | |
|
978 | ax.set_xlim(self.xmin, self.xmax) | |
|
979 | self.titles.append('{}'.format(self.plot_name.upper())) | |
|
980 | #plt.tight_layout() | |
|
981 | ||
|
982 | ||
|
983 | else: | |
|
984 | ||
|
985 | if n==0: | |
|
986 | self.xlimits=[(self.xmin,self.xmax)] | |
|
987 | else: | |
|
988 | self.xlimits.append((self.xmin,self.xmax)) | |
|
989 | ||
|
990 | ax.set_xlim(self.xmin, self.xmax) | |
|
991 | ||
|
992 | ||
|
993 | ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y) | |
|
994 | ax.plotline2[0].set_data(self.x[n][1,:,0,0],self.y) | |
|
995 | ax.plotline3[0].set_data(self.x[n][2,:,0,0],self.y) | |
|
996 | ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y) | |
|
997 | self.titles.append('{}'.format(self.plot_name.upper())) | |
|
998 | #plt.tight_layout() | |
|
999 | ||
|
1000 | ||
|
1001 | ||
|
1002 | class CrossProductsLPPlot(Plot): | |
|
1003 | ''' | |
|
1004 | Plot for cross products LP | |
|
1005 | ''' | |
|
1006 | ||
|
1007 | CODE = 'crossprodlp' | |
|
1008 | plot_name = 'Cross Products LP' | |
|
1009 | plot_type = 'scatterbuffer' | |
|
1010 | ||
|
1011 | ||
|
1012 | def setup(self): | |
|
1013 | ||
|
1014 | self.ncols = 2 | |
|
1015 | self.nrows = 1 | |
|
1016 | self.nplots = 2 | |
|
1017 | self.ylabel = 'Range [km]' | |
|
1018 | self.xlabel = 'dB' | |
|
1019 | self.width = 3.5*self.nplots | |
|
1020 | self.height = 5.5 | |
|
1021 | self.colorbar = False | |
|
1022 | self.titles = [] | |
|
1023 | self.plotline_array=numpy.zeros((2,self.data.NLAG),dtype=object) | |
|
1024 | def plot(self): | |
|
1025 | ||
|
1026 | ||
|
1027 | self.x = self.data[self.CODE][:,-1,:,:] | |
|
1028 | ||
|
1029 | ||
|
1030 | self.y = self.data.heights[0:self.data.NRANGE] | |
|
1031 | ||
|
1032 | ||
|
1033 | label_array=numpy.array(['lag '+ str(x) for x in range(self.data.NLAG)]) | |
|
1034 | color_array=['r','k','g','b','c','m','y','orange','steelblue','purple','peru','darksalmon','grey','limegreen','olive','midnightblue'] | |
|
1035 | ||
|
1036 | ||
|
1037 | for n, ax in enumerate(self.axes): | |
|
1038 | ||
|
1039 | self.xmin=30 | |
|
1040 | self.xmax=70 | |
|
1041 | #print(self.x[0,12:15,n]) | |
|
1042 | #input() | |
|
1043 | #self.xmin=numpy.min(numpy.concatenate((self.x[0,:,n],self.x[1,:,n]))) | |
|
1044 | #self.xmax=numpy.max(numpy.concatenate((self.x[0,:,n],self.x[1,:,n]))) | |
|
1045 | ||
|
1046 | #print("before",self.plotline_array) | |
|
1047 | ||
|
1048 | if ax.firsttime: | |
|
1049 | ||
|
1050 | self.autoxticks=False | |
|
1051 | ||
|
1052 | ||
|
1053 | for i in range(self.data.NLAG): | |
|
1054 | #print(i) | |
|
1055 | #print(numpy.shape(self.x)) | |
|
1056 | self.plotline_array[n,i], = ax.plot(self.x[i,:,n], self.y, color=color_array[i],linewidth=1.0, label=label_array[i]) | |
|
1057 | #ax.plotline1 = ax.plot(self.x[0,:,n], self.y, color='r',linewidth=2.0, label=label_array[0]) | |
|
1058 | #ax.plotline2 = ax.plot(self.x[n][1,:,0,0], self.y, color='k',linewidth=2.0, label=label2) | |
|
1059 | #ax.plotline3 = ax.plot(self.x[n][2,:,0,0], self.y, color='b',linewidth=2.0, label=label3) | |
|
1060 | #ax.plotline4 = ax.plot(self.x[n][3,:,0,0], self.y, color='m',linewidth=2.0, label=label4) | |
|
1061 | ||
|
1062 | ||
|
1063 | #print(self.plotline_array) | |
|
1064 | ||
|
1065 | ||
|
1066 | ||
|
1067 | ax.legend(loc='upper right') | |
|
1068 | ax.set_xlim(self.xmin, self.xmax) | |
|
1069 | if n==0: | |
|
1070 | self.titles.append('{} CH0'.format(self.plot_name.upper())) | |
|
1071 | if n==1: | |
|
1072 | self.titles.append('{} CH1'.format(self.plot_name.upper())) | |
|
1073 | ||
|
1074 | #plt.tight_layout() | |
|
1075 | ||
|
1076 | else: | |
|
1077 | #print(self.plotline_array) | |
|
1078 | for i in range(self.data.NLAG): | |
|
1079 | ||
|
1080 | self.plotline_array[n,i].set_data(self.x[i,:,n],self.y) | |
|
1081 | ||
|
1082 | ||
|
1083 | ||
|
1084 | #ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y) | |
|
1085 | #ax.plotline2[0].set_data(self.x[n][1,:,0,0],self.y) | |
|
1086 | #ax.plotline3[0].set_data(self.x[n][2,:,0,0],self.y) | |
|
1087 | #ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y) | |
|
1088 | ||
|
1089 | if n==0: | |
|
1090 | self.titles.append('{} CH0'.format(self.plot_name.upper())) | |
|
1091 | if n==1: | |
|
1092 | self.titles.append('{} CH1'.format(self.plot_name.upper())) | |
|
1093 | ||
|
1094 | #plt.tight_layout() | |
|
1095 | ||
|
1096 | ||
|
1097 | class NoiseDPPlot(NoisePlot): | |
|
1098 | ''' | |
|
1099 | Plot for noise Double Pulse | |
|
1100 | ''' | |
|
1101 | ||
|
1102 | CODE = 'noisedp' | |
|
1103 | plot_name = 'Noise' | |
|
1104 | plot_type = 'scatterbuffer' | |
|
1105 | ||
|
1106 | ||
|
1107 | class XmitWaveformPlot(Plot): | |
|
1108 | ''' | |
|
1109 | Plot for xmit waveform | |
|
1110 | ''' | |
|
1111 | ||
|
1112 | CODE = 'xmit' | |
|
1113 | plot_name = 'Xmit Waveform' | |
|
1114 | plot_type = 'scatterbuffer' | |
|
1115 | ||
|
1116 | ||
|
1117 | def setup(self): | |
|
1118 | ||
|
1119 | self.ncols = 1 | |
|
1120 | self.nrows = 1 | |
|
1121 | self.nplots = 1 | |
|
1122 | self.ylabel = '' | |
|
1123 | self.xlabel = 'Number of Lag' | |
|
1124 | self.width = 5.5 | |
|
1125 | self.height = 3.5 | |
|
1126 | self.colorbar = False | |
|
1127 | if not self.titles: | |
|
1128 | self.titles = self.data.parameters \ | |
|
1129 | if self.data.parameters else ['{}'.format(self.plot_name.upper())] | |
|
1130 | ||
|
1131 | def plot(self): | |
|
1132 | ||
|
1133 | self.x = numpy.arange(0,self.data.NLAG,1,'float32') | |
|
1134 | self.y = self.data['xmit'][:,-1,:] | |
|
1135 | ||
|
1136 | self.xmin = 0 | |
|
1137 | self.xmax = self.data.NLAG-1 | |
|
1138 | self.ymin = -1.0 | |
|
1139 | self.ymax = 1.0 | |
|
1140 | ax = self.axes[0] | |
|
1141 | ||
|
1142 | if ax.firsttime: | |
|
1143 | ax.plotline0=ax.plot(self.x,self.y[0,:],color='blue') | |
|
1144 | ax.plotline1=ax.plot(self.x,self.y[1,:],color='red') | |
|
1145 | secax=ax.secondary_xaxis(location=0.5) | |
|
1146 | secax.xaxis.tick_bottom() | |
|
1147 | secax.tick_params( labelleft=False, labeltop=False, | |
|
1148 | labelright=False, labelbottom=False) | |
|
1149 | ||
|
1150 | self.xstep_given = 3 | |
|
1151 | self.ystep_given = .25 | |
|
1152 | secax.set_xticks(numpy.linspace(self.xmin, self.xmax, 6)) #only works on matplotlib.version>3.2 | |
|
1153 | ||
|
1154 | else: | |
|
1155 | ax.plotline0[0].set_data(self.x,self.y[0,:]) | |
|
1156 | ax.plotline1[0].set_data(self.x,self.y[1,:]) |
This diff has been collapsed as it changes many lines, (683 lines changed) Show them Hide them | |||
@@ -0,0 +1,683 | |||
|
1 | ''' | |
|
2 | Created on Jun 9, 2020 | |
|
3 | ||
|
4 | @author: Roberto Flores | |
|
5 | ''' | |
|
6 | ||
|
7 | import os | |
|
8 | import sys | |
|
9 | import time | |
|
10 | ||
|
11 | import struct | |
|
12 | ||
|
13 | ||
|
14 | import datetime | |
|
15 | ||
|
16 | import numpy | |
|
17 | ||
|
18 | ||
|
19 | import schainpy.admin | |
|
20 | from schainpy.model.io.jroIO_base import LOCALTIME, Reader | |
|
21 | from schainpy.model.data.jroheaderIO import BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
22 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
|
23 | from schainpy.model.data.jrodata import Voltage, Parameters | |
|
24 | from schainpy.utils import log | |
|
25 | ||
|
26 | ||
|
27 | class DatReader(Reader, ProcessingUnit): | |
|
28 | ||
|
29 | def __init__(self): | |
|
30 | ||
|
31 | ProcessingUnit.__init__(self) | |
|
32 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
|
33 | self.systemHeaderObj = SystemHeader() | |
|
34 | self.radarControllerHeaderObj = RadarControllerHeader() | |
|
35 | self.processingHeaderObj = ProcessingHeader() | |
|
36 | self.dataOut = Parameters() | |
|
37 | #print(self.basicHeaderObj.timezone) | |
|
38 | #self.counter_block=0 | |
|
39 | self.format='dat' | |
|
40 | self.flagNoMoreFiles = 0 | |
|
41 | self.filename = None | |
|
42 | self.intervals = set() | |
|
43 | #self.datatime = datetime.datetime(1900,1,1) | |
|
44 | ||
|
45 | self.filefmt = "***%Y%m%d*******" | |
|
46 | ||
|
47 | self.padding=numpy.zeros(1,'int32') | |
|
48 | self.hsize=numpy.zeros(1,'int32') | |
|
49 | self.bufsize=numpy.zeros(1,'int32') | |
|
50 | self.nr=numpy.zeros(1,'int32') | |
|
51 | self.ngates=numpy.zeros(1,'int32') ### ### ### 2 | |
|
52 | self.time1=numpy.zeros(1,'uint64') # pos 3 | |
|
53 | self.time2=numpy.zeros(1,'uint64') # pos 4 | |
|
54 | self.lcounter=numpy.zeros(1,'int32') | |
|
55 | self.groups=numpy.zeros(1,'int32') | |
|
56 | self.system=numpy.zeros(4,'int8') # pos 7 | |
|
57 | self.h0=numpy.zeros(1,'float32') | |
|
58 | self.dh=numpy.zeros(1,'float32') | |
|
59 | self.ipp=numpy.zeros(1,'float32') | |
|
60 | self.process=numpy.zeros(1,'int32') | |
|
61 | self.tx=numpy.zeros(1,'int32') | |
|
62 | ||
|
63 | self.ngates1=numpy.zeros(1,'int32') ### ### ### 13 | |
|
64 | self.time0=numpy.zeros(1,'uint64') # pos 14 | |
|
65 | self.nlags=numpy.zeros(1,'int32') | |
|
66 | self.nlags1=numpy.zeros(1,'int32') | |
|
67 | self.txb=numpy.zeros(1,'float32') ### ### ### 17 | |
|
68 | self.time3=numpy.zeros(1,'uint64') # pos 18 | |
|
69 | self.time4=numpy.zeros(1,'uint64') # pos 19 | |
|
70 | self.h0_=numpy.zeros(1,'float32') | |
|
71 | self.dh_=numpy.zeros(1,'float32') | |
|
72 | self.ipp_=numpy.zeros(1,'float32') | |
|
73 | self.txa_=numpy.zeros(1,'float32') | |
|
74 | ||
|
75 | self.pad=numpy.zeros(100,'int32') | |
|
76 | ||
|
77 | self.nbytes=numpy.zeros(1,'int32') | |
|
78 | self.limits=numpy.zeros(1,'int32') | |
|
79 | self.ngroups=numpy.zeros(1,'int32') ### ### ### 27 | |
|
80 | #Make the header list | |
|
81 | #header=[hsize,bufsize,nr,ngates,time1,time2,lcounter,groups,system,h0,dh,ipp,process,tx,padding,ngates1,time0,nlags,nlags1,padding,txb,time3,time4,h0_,dh_,ipp_,txa_,pad,nbytes,limits,padding,ngroups] | |
|
82 | self.header=[self.hsize,self.bufsize,self.nr,self.ngates,self.time1,self.time2,self.lcounter,self.groups,self.system,self.h0,self.dh,self.ipp,self.process,self.tx,self.ngates1,self.padding,self.time0,self.nlags,self.nlags1,self.padding,self.txb,self.time3,self.time4,self.h0_,self.dh_,self.ipp_,self.txa_,self.pad,self.nbytes,self.limits,self.padding,self.ngroups] | |
|
83 | ||
|
84 | ||
|
85 | ||
|
86 | def setup(self, **kwargs): | |
|
87 | ||
|
88 | self.set_kwargs(**kwargs) | |
|
89 | ||
|
90 | ||
|
91 | if self.path is None: | |
|
92 | raise ValueError('The path is not valid') | |
|
93 | ||
|
94 | self.open_file = open | |
|
95 | self.open_mode = 'rb' | |
|
96 | ||
|
97 | ||
|
98 | ||
|
99 | if self.format is None: | |
|
100 | raise ValueError('The format is not valid') | |
|
101 | elif self.format.lower() in ('dat'): | |
|
102 | self.ext = '.dat' | |
|
103 | elif self.format.lower() in ('out'): | |
|
104 | self.ext = '.out' | |
|
105 | ||
|
106 | ||
|
107 | log.log("Searching files in {}".format(self.path), self.name) | |
|
108 | self.filenameList = self.searchFilesOffLine(self.path, self.startDate, | |
|
109 | self.endDate, self.expLabel, self.ext, self.walk, self.filefmt, self.folderfmt) | |
|
110 | #print(self.path) | |
|
111 | #print(self.filenameList) | |
|
112 | #input() | |
|
113 | ||
|
114 | ||
|
115 | self.setNextFile() | |
|
116 | ||
|
117 | def readFirstHeader(self): | |
|
118 | '''Read header and data''' | |
|
119 | ||
|
120 | #self.flag_same_file=1 | |
|
121 | self.counter_block=0 | |
|
122 | self.parseHeader() | |
|
123 | self.parseData() | |
|
124 | self.blockIndex = 0 | |
|
125 | ||
|
126 | return | |
|
127 | ||
|
128 | def parseHeader(self): | |
|
129 | ''' | |
|
130 | ''' | |
|
131 | ||
|
132 | for i in range(len(self.header)): | |
|
133 | for j in range(len(self.header[i])): | |
|
134 | #print("len(header[i]) ",len(header[i])) | |
|
135 | #input() | |
|
136 | temp=self.fp.read(int(self.header[i].itemsize)) | |
|
137 | if isinstance(self.header[i][0], numpy.int32): | |
|
138 | #print(struct.unpack('i', temp)[0]) | |
|
139 | self.header[i][0]=struct.unpack('i', temp)[0] | |
|
140 | if isinstance(self.header[i][0], numpy.uint64): | |
|
141 | self.header[i][0]=struct.unpack('q', temp)[0] | |
|
142 | if isinstance(self.header[i][0], numpy.int8): | |
|
143 | self.header[i][0]=struct.unpack('B', temp)[0] | |
|
144 | if isinstance(self.header[i][0], numpy.float32): | |
|
145 | self.header[i][0]=struct.unpack('f', temp)[0] | |
|
146 | ||
|
147 | self.fp.seek(0,0) | |
|
148 | if int(self.header[1][0])==int(81864): | |
|
149 | self.experiment='DP' | |
|
150 | ||
|
151 | elif int(self.header[1][0])==int(185504): | |
|
152 | self.experiment='HP' | |
|
153 | ||
|
154 | ||
|
155 | self.total_blocks=os.stat(self.filename).st_size//self.header[1][0] | |
|
156 | ||
|
157 | ||
|
158 | def parseData(self): | |
|
159 | ''' | |
|
160 | ''' | |
|
161 | if self.experiment=='DP': | |
|
162 | self.header[15][0]=66 | |
|
163 | self.header[18][0]=16 | |
|
164 | self.header[17][0]=11 | |
|
165 | self.header[2][0]=2 | |
|
166 | ||
|
167 | ||
|
168 | self.noise=numpy.zeros(self.header[2][0],'float32') #self.header[2][0] | |
|
169 | #tmpx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
170 | self.kax=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
171 | self.kay=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
172 | self.kbx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
173 | self.kby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
174 | self.kax2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
175 | self.kay2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
176 | self.kbx2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
177 | self.kby2=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
178 | self.kaxbx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
179 | self.kaxby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
180 | self.kaybx=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
181 | self.kayby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
182 | self.kaxay=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
183 | self.kbxby=numpy.zeros((self.header[15][0],self.header[17][0],2),'float32') | |
|
184 | self.output_LP_real=numpy.zeros((self.header[18][0],200,self.header[2][0]),'float32') | |
|
185 | self.output_LP_imag=numpy.zeros((self.header[18][0],200,self.header[2][0]),'float32') | |
|
186 | self.final_cross_products=[self.kax,self.kay,self.kbx,self.kby,self.kax2,self.kay2,self.kbx2,self.kby2,self.kaxbx,self.kaxby,self.kaybx,self.kayby,self.kaxay,self.kbxby] | |
|
187 | #self.final_cross_products=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx] | |
|
188 | ||
|
189 | #print("pos: ",self.fp.tell()) | |
|
190 | ||
|
191 | ||
|
192 | def readNextBlock(self): | |
|
193 | ||
|
194 | while True: | |
|
195 | self.flagDiscontinuousBlock = 0 | |
|
196 | #print(os.stat(self.filename).st_size) | |
|
197 | #print(os.stat(self.filename).st_size//self.header[1][0]) | |
|
198 | #os.stat(self.fp) | |
|
199 | if self.counter_block == self.total_blocks: | |
|
200 | ||
|
201 | self.setNextFile() | |
|
202 | ||
|
203 | self.readBlock() | |
|
204 | #self.counter_block+=1 | |
|
205 | ||
|
206 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ | |
|
207 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
|
208 | ||
|
209 | #print(self.datatime) | |
|
210 | #print(datetime.datetime.combine(self.startDate, self.startTime)) | |
|
211 | #print(datetime.datetime.combine(self.endDate, self.endTime)) | |
|
212 | #print("warning") | |
|
213 | log.warning( | |
|
214 | 'Reading Block No. {}/{} -> {} [Skipping]'.format( | |
|
215 | self.counter_block, | |
|
216 | self.total_blocks, | |
|
217 | self.datatime.ctime()), | |
|
218 | 'DATReader') | |
|
219 | continue | |
|
220 | break | |
|
221 | ||
|
222 | log.log( | |
|
223 | 'Reading Block No. {}/{} -> {}'.format( | |
|
224 | self.counter_block, | |
|
225 | self.total_blocks, | |
|
226 | self.datatime.ctime()), | |
|
227 | 'DATReader') | |
|
228 | ||
|
229 | return 1 | |
|
230 | ||
|
231 | def readBlock(self): | |
|
232 | ''' | |
|
233 | ''' | |
|
234 | ||
|
235 | self.npos=self.counter_block*self.header[1][0] | |
|
236 | #print(self.counter_block) | |
|
237 | self.fp.seek(self.npos, 0) | |
|
238 | self.counter_block+=1 | |
|
239 | #print("fpos1: ",self.fp.tell()) | |
|
240 | ||
|
241 | self.read_header() | |
|
242 | ||
|
243 | #put by hand because old files didn't save it in the header | |
|
244 | if self.experiment=='DP': | |
|
245 | self.header[15][0]=66 | |
|
246 | self.header[18][0]=16 | |
|
247 | self.header[17][0]=11 | |
|
248 | self.header[2][0]=2 | |
|
249 | ######################################### | |
|
250 | ||
|
251 | if self.experiment=="HP": | |
|
252 | self.long_pulse_products() | |
|
253 | ||
|
254 | self.read_cross_products() | |
|
255 | ||
|
256 | ||
|
257 | self.read_noise() | |
|
258 | ||
|
259 | ||
|
260 | return | |
|
261 | ||
|
262 | ||
|
263 | ||
|
264 | def read_header(self): | |
|
265 | ||
|
266 | ||
|
267 | for i in range(len(self.header)): | |
|
268 | for j in range(len(self.header[i])): | |
|
269 | #print("len(header[i]) ",len(header[i])) | |
|
270 | #input() | |
|
271 | temp=self.fp.read(int(self.header[i].itemsize)) | |
|
272 | #if(b''==temp): | |
|
273 | # self.setNextFile() | |
|
274 | # self.flag_same_file=0 | |
|
275 | if isinstance(self.header[i][0], numpy.int32): | |
|
276 | #print(struct.unpack('i', temp)[0]) | |
|
277 | self.header[i][0]=struct.unpack('i', temp)[0] | |
|
278 | if isinstance(self.header[i][0], numpy.uint64): | |
|
279 | self.header[i][0]=struct.unpack('q', temp)[0] | |
|
280 | if isinstance(self.header[i][0], numpy.int8): | |
|
281 | self.header[i][0]=struct.unpack('B', temp)[0] | |
|
282 | if isinstance(self.header[i][0], numpy.float32): | |
|
283 | self.header[i][0]=struct.unpack('f', temp)[0] | |
|
284 | #else: | |
|
285 | # continue | |
|
286 | #self.fp.seek(self.npos_aux, 0) | |
|
287 | # break | |
|
288 | ||
|
289 | #print("fpos2: ",self.fp.tell()) | |
|
290 | #log.success('Parameters found: {}'.format(self.parameters), | |
|
291 | # 'DATReader') | |
|
292 | #print("Success") | |
|
293 | #self.TimeBlockSeconds_for_dp_power = self.header[4][0]#-((self.dataOut.nint-1)*self.dataOut.NAVG*2) | |
|
294 | #print(dataOut.TimeBlockSeconds_for_dp_power) | |
|
295 | ||
|
296 | #self.datatime=datetime.datetime.fromtimestamp(self.header[4][0]).strftime("%Y-%m-%d %H:%M:%S") | |
|
297 | #print(self.header[4][0]) | |
|
298 | self.datatime=datetime.datetime.fromtimestamp(self.header[4][0]) | |
|
299 | #print(self.header[1][0]) | |
|
300 | ||
|
301 | def long_pulse_products(self): | |
|
302 | temp=self.fp.read(self.header[18][0]*self.header[2][0]*200*8) | |
|
303 | ii=0 | |
|
304 | ||
|
305 | for l in range(self.header[18][0]): #lag | |
|
306 | for r in range(self.header[2][0]): # channels | |
|
307 | for k in range(200): #RANGE## generalizar | |
|
308 | self.output_LP_real[l,k,r]=struct.unpack('f', temp[ii:ii+4])[0] | |
|
309 | ii=ii+4 | |
|
310 | self.output_LP_imag[l,k,r]=struct.unpack('f', temp[ii:ii+4])[0] | |
|
311 | ii=ii+4 | |
|
312 | ||
|
313 | #print(self.output_LP_real[1,1,1]) | |
|
314 | #print(self.output_LP_imag[1,1,1]) | |
|
315 | def read_cross_products(self): | |
|
316 | ||
|
317 | for ind in range(len(self.final_cross_products)): #final cross products | |
|
318 | temp=self.fp.read(self.header[17][0]*2*self.header[15][0]*4) #*4 bytes | |
|
319 | #if(b''==temp): | |
|
320 | # self.setNextFile() | |
|
321 | # self.flag_same_file=0 | |
|
322 | ii=0 | |
|
323 | #print("kabxys.shape ",kabxys.shape) | |
|
324 | #print(kabxys) | |
|
325 | #print("fpos3: ",self.fp.tell()) | |
|
326 | for l in range(self.header[17][0]): #lag | |
|
327 | #print("fpos3: ",self.fp.tell()) | |
|
328 | for fl in range(2): # unflip and flip | |
|
329 | for k in range(self.header[15][0]): #RANGE | |
|
330 | #print("fpos3: ",self.fp.tell()) | |
|
331 | self.final_cross_products[ind][k,l,fl]=struct.unpack('f', temp[ii:ii+4])[0] | |
|
332 | ii=ii+4 | |
|
333 | #print("fpos2: ",self.fp.tell()) | |
|
334 | ||
|
335 | ||
|
336 | ||
|
337 | def read_noise(self): | |
|
338 | ||
|
339 | temp=self.fp.read(self.header[2][0]*4) #*4 bytes self.header[2][0] | |
|
340 | for ii in range(self.header[2][0]): #self.header[2][0] | |
|
341 | self.noise[ii]=struct.unpack('f', temp[ii*4:(ii+1)*4])[0] | |
|
342 | ||
|
343 | #print("fpos5: ",self.fp.tell()) | |
|
344 | ||
|
345 | ||
|
346 | ||
|
347 | def set_output(self): | |
|
348 | ''' | |
|
349 | Storing data from buffer to dataOut object | |
|
350 | ''' | |
|
351 | #print("fpos2: ",self.fp.tell()) | |
|
352 | ##self.dataOut.header = self.header | |
|
353 | #this is put by hand because it isn't saved in the header | |
|
354 | if self.experiment=='DP': | |
|
355 | self.dataOut.NRANGE=0 | |
|
356 | self.dataOut.NSCAN=132 | |
|
357 | self.dataOut.heightList=self.header[10][0]*(numpy.arange(self.header[15][0])) | |
|
358 | elif self.experiment=='HP': | |
|
359 | self.dataOut.output_LP=self.output_LP_real+1.j*self.output_LP_imag | |
|
360 | self.dataOut.NRANGE=200 | |
|
361 | self.dataOut.NSCAN=128 | |
|
362 | self.dataOut.heightList=self.header[10][0]*(numpy.arange(90)) #NEEEDS TO BE GENERALIZED | |
|
363 | ######################################### | |
|
364 | #print(self.dataOut.output_LP[1,1,1]) | |
|
365 | self.dataOut.MAXNRANGENDT=self.header[3][0] | |
|
366 | self.dataOut.NDP=self.header[15][0] | |
|
367 | self.dataOut.DPL=self.header[17][0] | |
|
368 | self.dataOut.DH=self.header[10][0] | |
|
369 | self.dataOut.NAVG=self.header[7][0] | |
|
370 | self.dataOut.H0=self.header[9][0] | |
|
371 | self.dataOut.NR=self.header[2][0] | |
|
372 | self.dataOut.NLAG=self.header[18][0] | |
|
373 | #self.dataOut.tmpx=self.tmpx | |
|
374 | #self.dataOut.timeZone = 5 | |
|
375 | #self.dataOut.final_cross_products=self.final_cross_products | |
|
376 | self.dataOut.kax=self.kax | |
|
377 | #print(self.dataOut.kax[1,1,1]) | |
|
378 | self.dataOut.kay=self.kay | |
|
379 | self.dataOut.kbx=self.kbx | |
|
380 | self.dataOut.kby=self.kby | |
|
381 | self.dataOut.kax2=self.kax2 | |
|
382 | self.dataOut.kay2=self.kay2 | |
|
383 | self.dataOut.kbx2=self.kbx2 | |
|
384 | self.dataOut.kby2=self.kby2 | |
|
385 | self.dataOut.kaxbx=self.kaxbx | |
|
386 | self.dataOut.kaxby=self.kaxby | |
|
387 | self.dataOut.kaybx=self.kaybx | |
|
388 | self.dataOut.kayby=self.kayby | |
|
389 | self.dataOut.kaxay=self.kaxay | |
|
390 | self.dataOut.kbxby=self.kbxby | |
|
391 | self.dataOut.noise_final=self.noise | |
|
392 | #print("NOISE",self.noise) | |
|
393 | ||
|
394 | ||
|
395 | self.dataOut.useLocalTime=True | |
|
396 | ||
|
397 | #self.dataOut.experiment=self.experiment | |
|
398 | #print(self.datatime) | |
|
399 | #print(self.dataOut.datatime) | |
|
400 | ||
|
401 | ||
|
402 | #self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds() | |
|
403 | #self.dataOut.utctimeInit = self.dataOut.utctime | |
|
404 | ||
|
405 | ||
|
406 | ||
|
407 | self.dataOut.lt=self.datatime.hour | |
|
408 | ||
|
409 | ||
|
410 | #print(RadarControllerHeader().ippSeconds) | |
|
411 | #print(RadarControllerHeader().ipp) | |
|
412 | #self.dataOut.utctime=time.gmtime(self.header[4][0])- datetime.datetime(1970, 1, 1) | |
|
413 | #self.dataOut.utctime=self.dataOut.utctime.total_seconds() | |
|
414 | #time1 = self.header[4][0] # header.time1 | |
|
415 | #print("time1: ",time1) | |
|
416 | #print(self.header[4][0]) | |
|
417 | #date = time.ctime(time1) | |
|
418 | #print("DADSADA",time.strptime(date)) | |
|
419 | #print("date_before: ",date) | |
|
420 | #bd_time=time.gmtime(time1) | |
|
421 | #print(time.mktime(bd_time)) | |
|
422 | #self.dataOut.utctime=time.mktime(bd_time) | |
|
423 | self.dataOut.utctime = self.header[4][0] | |
|
424 | #self.dataOut.datatime=a | |
|
425 | #print(datetime.datetime.utcfromtimestamp(self.dataOut.utctime)) | |
|
426 | #self.dataOut.TimeBlockDate=self.datatime.ctime() | |
|
427 | self.dataOut.TimeBlockSeconds=time.mktime(time.strptime(self.dataOut.datatime.ctime())) | |
|
428 | ||
|
429 | #self.dataOut.heightList = self.ranges | |
|
430 | #self.dataOut.utctime = (self.datatime - datetime.datetime(1970, 1, 1)).total_seconds() | |
|
431 | #self.dataOut.utctimeInit = self.dataOut.utctime | |
|
432 | #self.dataOut.paramInterval = min(self.intervals) | |
|
433 | #self.dataOut.useLocalTime = False | |
|
434 | self.dataOut.flagNoData = False | |
|
435 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
|
436 | #print(self.dataOut.channelIndexList) | |
|
437 | self.dataOut.channelList=list(range(0,self.header[2][0])) | |
|
438 | #print(self.dataOut.channelList) | |
|
439 | #print(self.datatime) | |
|
440 | #print(self.dataOut.final_cross_products[0]) | |
|
441 | ||
|
442 | ||
|
443 | #self.dataOut.heightList=self.header[10][0]*(numpy.arange(self.header[15][0])) | |
|
444 | ||
|
445 | #print(numpy.shape(self.dataOut.heightList)) | |
|
446 | ||
|
447 | ||
|
448 | def getData(self): | |
|
449 | ''' | |
|
450 | Storing data from databuffer to dataOut object | |
|
451 | ''' | |
|
452 | ||
|
453 | if not self.readNextBlock(): | |
|
454 | self.dataOut.flagNoData = True | |
|
455 | return 0 | |
|
456 | ||
|
457 | self.set_output() | |
|
458 | ||
|
459 | return 1 | |
|
460 | ||
|
461 | def run(self, **kwargs): | |
|
462 | ||
|
463 | if not(self.isConfig): | |
|
464 | self.setup(**kwargs) | |
|
465 | self.isConfig = True | |
|
466 | #print("fpos1: ",self.fp.tell()) | |
|
467 | self.getData() | |
|
468 | ||
|
469 | return | |
|
470 | ||
|
471 | @MPDecorator | |
|
472 | class DatWriter(Operation): | |
|
473 | ||
|
474 | ||
|
475 | def __init__(self): | |
|
476 | ||
|
477 | Operation.__init__(self) | |
|
478 | #self.dataOut = Voltage() | |
|
479 | self.counter = 0 | |
|
480 | self.path = None | |
|
481 | self.fp = None | |
|
482 | return | |
|
483 | #self.ext= '.dat' | |
|
484 | ||
|
485 | def run(self, dataOut, path, format='dat', experiment=None, **kwargs): | |
|
486 | print(dataOut.flagNoData) | |
|
487 | print(dataOut.datatime.ctime()) | |
|
488 | print(dataOut.TimeBlockDate) | |
|
489 | input() | |
|
490 | #if dataOut.flag_save: | |
|
491 | self.experiment=experiment | |
|
492 | self.path=path | |
|
493 | if self.experiment=='DP': | |
|
494 | dataOut.header[1][0]=81864 | |
|
495 | elif self.experiment=='HP': | |
|
496 | dataOut.header[1][0]=185504#173216 | |
|
497 | #dataOut.header[1][0]=bufsize | |
|
498 | self.dataOut = dataOut | |
|
499 | #print(self.dataOut.nint) | |
|
500 | #self.bufsize=bufsize | |
|
501 | if format == 'dat': | |
|
502 | self.ext = '.dat' | |
|
503 | if format == 'out': | |
|
504 | self.ext = '.out' | |
|
505 | self.putData() | |
|
506 | ||
|
507 | return | |
|
508 | ||
|
509 | ||
|
510 | ||
|
511 | def setFile(self): | |
|
512 | ''' | |
|
513 | Create new out file object | |
|
514 | ''' | |
|
515 | ||
|
516 | #self.dataOut.TimeBlockSeconds=time.mktime(time.strptime(self.dataOut.TimeBlockDate)) | |
|
517 | date = datetime.datetime.fromtimestamp(self.dataOut.TimeBlockSeconds) | |
|
518 | ||
|
519 | #print("date",date) | |
|
520 | ||
|
521 | filename = '{}{}{}'.format('jro', | |
|
522 | date.strftime('%Y%m%d_%H%M%S'), | |
|
523 | self.ext) | |
|
524 | #print(filename) | |
|
525 | #print(self.path) | |
|
526 | ||
|
527 | self.fullname = os.path.join(self.path, filename) | |
|
528 | ||
|
529 | if os.path.isfile(self.fullname) : | |
|
530 | log.warning( | |
|
531 | 'Destination file {} already exists, previous file deleted.'.format( | |
|
532 | self.fullname), | |
|
533 | 'DatWriter') | |
|
534 | os.remove(self.fullname) | |
|
535 | ||
|
536 | try: | |
|
537 | log.success( | |
|
538 | 'Creating file: {}'.format(self.fullname), | |
|
539 | 'DatWriter') | |
|
540 | if not os.path.exists(self.path): | |
|
541 | os.makedirs(self.path) | |
|
542 | #self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True) | |
|
543 | self.fp = open(self.fullname,'wb') | |
|
544 | ||
|
545 | except ValueError as e: | |
|
546 | log.error( | |
|
547 | 'Impossible to create *.out file', | |
|
548 | 'DatWriter') | |
|
549 | return | |
|
550 | ||
|
551 | return 1 | |
|
552 | ||
|
553 | def writeBlock(self): | |
|
554 | ||
|
555 | #self.dataOut.paramInterval=2 | |
|
556 | #startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime) | |
|
557 | #print(startTime) | |
|
558 | #endTime = startTime + datetime.timedelta(seconds=self.dataOut.paramInterval) | |
|
559 | ||
|
560 | self.dataOut.header[0].astype('int32').tofile(self.fp) | |
|
561 | self.dataOut.header[1].astype('int32').tofile(self.fp) | |
|
562 | self.dataOut.header[2].astype('int32').tofile(self.fp) | |
|
563 | self.dataOut.header[3].astype('int32').tofile(self.fp) | |
|
564 | self.dataOut.header[4].astype('uint64').tofile(self.fp) | |
|
565 | self.dataOut.header[5].astype('uint64').tofile(self.fp) | |
|
566 | self.dataOut.header[6].astype('int32').tofile(self.fp) | |
|
567 | self.dataOut.header[7].astype('int32').tofile(self.fp) | |
|
568 | #print(dataOut.header[7]) | |
|
569 | self.dataOut.header[8].astype('int8').tofile(self.fp) | |
|
570 | self.dataOut.header[9].astype('float32').tofile(self.fp) | |
|
571 | self.dataOut.header[10].astype('float32').tofile(self.fp) | |
|
572 | self.dataOut.header[11].astype('float32').tofile(self.fp) | |
|
573 | self.dataOut.header[12].astype('int32').tofile(self.fp) | |
|
574 | self.dataOut.header[13].astype('int32').tofile(self.fp) | |
|
575 | self.dataOut.header[14].astype('int32').tofile(self.fp) | |
|
576 | self.dataOut.header[15].astype('int32').tofile(self.fp) | |
|
577 | self.dataOut.header[16].astype('uint64').tofile(self.fp) | |
|
578 | self.dataOut.header[17].astype('int32').tofile(self.fp) | |
|
579 | self.dataOut.header[18].astype('int32').tofile(self.fp) | |
|
580 | self.dataOut.header[19].astype('int32').tofile(self.fp) | |
|
581 | self.dataOut.header[20].astype('float32').tofile(self.fp) | |
|
582 | self.dataOut.header[21].astype('uint64').tofile(self.fp) | |
|
583 | self.dataOut.header[22].astype('uint64').tofile(self.fp) | |
|
584 | self.dataOut.header[23].astype('float32').tofile(self.fp) | |
|
585 | self.dataOut.header[24].astype('float32').tofile(self.fp) | |
|
586 | self.dataOut.header[25].astype('float32').tofile(self.fp) | |
|
587 | self.dataOut.header[26].astype('float32').tofile(self.fp) | |
|
588 | self.dataOut.header[27].astype('int32').tofile(self.fp) | |
|
589 | self.dataOut.header[28].astype('int32').tofile(self.fp) | |
|
590 | self.dataOut.header[29].astype('int32').tofile(self.fp) | |
|
591 | self.dataOut.header[30].astype('int32').tofile(self.fp) | |
|
592 | self.dataOut.header[31].astype('int32').tofile(self.fp) | |
|
593 | #print("tell before 1 ",self.fp.tell()) | |
|
594 | #input() | |
|
595 | ||
|
596 | if self.experiment=="HP": | |
|
597 | #print("INSIDE") | |
|
598 | #tmp=numpy.zeros(1,dtype='complex64') | |
|
599 | #print("tmp ",tmp) | |
|
600 | #input() | |
|
601 | #print(dataOut.NLAG) | |
|
602 | #print(dataOut.NR) | |
|
603 | #print(dataOut.NRANGE) | |
|
604 | for l in range(self.dataOut.NLAG): #lag | |
|
605 | for r in range(self.dataOut.NR): # unflip and flip | |
|
606 | for k in range(self.dataOut.NRANGE): #RANGE | |
|
607 | self.dataOut.output_LP.real[l,k,r].astype('float32').tofile(self.fp) | |
|
608 | self.dataOut.output_LP.imag[l,k,r].astype('float32').tofile(self.fp) | |
|
609 | ||
|
610 | ||
|
611 | #print("tell before 2 ",self.outputfile.tell()) | |
|
612 | ||
|
613 | ||
|
614 | ||
|
615 | ||
|
616 | ||
|
617 | #print(self.dataOut.output_LP[1,1,1]) | |
|
618 | ||
|
619 | #print(self.dataOut.kax) | |
|
620 | final_cross_products=[self.dataOut.kax,self.dataOut.kay,self.dataOut.kbx,self.dataOut.kby, | |
|
621 | self.dataOut.kax2,self.dataOut.kay2,self.dataOut.kbx2,self.dataOut.kby2, | |
|
622 | self.dataOut.kaxbx,self.dataOut.kaxby,self.dataOut.kaybx,self.dataOut.kayby, | |
|
623 | self.dataOut.kaxay,self.dataOut.kbxby] | |
|
624 | ||
|
625 | #print(self.dataOut.kax) | |
|
626 | #print("tell before crossp saving ",self.outputfile.tell()) | |
|
627 | for kabxys in final_cross_products: | |
|
628 | ||
|
629 | for l in range(self.dataOut.DPL): #lag | |
|
630 | for fl in range(2): # unflip and flip | |
|
631 | for k in range(self.dataOut.NDT): #RANGE | |
|
632 | kabxys[k,l,fl].astype('float32').tofile(self.fp) | |
|
633 | ||
|
634 | ||
|
635 | #print("tell before noise saving ",self.outputfile.tell()) | |
|
636 | ||
|
637 | ||
|
638 | for nch in range(self.dataOut.NR): | |
|
639 | self.dataOut.noise_final[nch].astype('float32').tofile(self.fp) | |
|
640 | ||
|
641 | #print("tell before noise saving ",self.fp.tell()) | |
|
642 | #input() | |
|
643 | ||
|
644 | ||
|
645 | ||
|
646 | ||
|
647 | log.log( | |
|
648 | 'Writing {} blocks'.format( | |
|
649 | self.counter+1), | |
|
650 | 'DatWriter') | |
|
651 | ||
|
652 | ||
|
653 | ||
|
654 | ||
|
655 | ||
|
656 | ||
|
657 | def putData(self): | |
|
658 | #print("flagNoData",self.dataOut.flagNoData) | |
|
659 | #print("flagDiscontinuousBlock",self.dataOut.flagDiscontinuousBlock) | |
|
660 | #print(self.dataOut.flagNoData) | |
|
661 | ||
|
662 | if self.dataOut.flagNoData: | |
|
663 | return 0 | |
|
664 | ||
|
665 | if self.dataOut.flagDiscontinuousBlock: | |
|
666 | ||
|
667 | self.counter = 0 | |
|
668 | ||
|
669 | if self.counter == 0: | |
|
670 | self.setFile() | |
|
671 | #if self.experiment=="HP": | |
|
672 | #if self.dataOut.debris_activated==0: | |
|
673 | #self.writeBlock() | |
|
674 | #self.counter += 1 | |
|
675 | #else: | |
|
676 | self.writeBlock() | |
|
677 | self.counter += 1 | |
|
678 | ||
|
679 | def close(self): | |
|
680 | ||
|
681 | if self.counter > 0: | |
|
682 | self.fp.close() | |
|
683 | log.success('Closing file {}'.format(self.fullname), 'DatWriter') |
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 | 78 | sortdata = numpy.sort(data, axis=None) |
|
79 | #print(numpy.shape(data)) | |
|
80 | #exit() | |
|
79 | 81 | ''' |
|
80 | 82 | lenOfData = len(sortdata) |
|
81 | 83 | nums_min = lenOfData*0.2 |
@@ -428,6 +430,103 class Voltage(JROData): | |||
|
428 | 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 | 530 | class Spectra(JROData): |
|
432 | 531 | |
|
433 | 532 | def __init__(self): |
@@ -886,6 +985,7 class Parameters(Spectra): | |||
|
886 | 985 | else: |
|
887 | 986 | return self.paramInterval |
|
888 | 987 | |
|
988 | ||
|
889 | 989 | def setValue(self, value): |
|
890 | 990 | |
|
891 | 991 | print("This property should not be initialized") |
@@ -928,6 +1028,10 class PlotterData(object): | |||
|
928 | 1028 | self.plottypes = ['cspc', 'spc', 'noise', 'rti'] |
|
929 | 1029 | elif code == 'rti': |
|
930 | 1030 | self.plottypes = ['noise', 'rti'] |
|
1031 | elif code == 'crossprod': | |
|
1032 | self.plottypes = ['crossprod', 'kay'] | |
|
1033 | elif code == 'spectrogram': | |
|
1034 | self.plottypes = ['spc', 'spectrogram'] | |
|
931 | 1035 | else: |
|
932 | 1036 | self.plottypes = [code] |
|
933 | 1037 | |
@@ -976,9 +1080,11 class PlotterData(object): | |||
|
976 | 1080 | plot = 'snr' |
|
977 | 1081 | elif 'spc_moments' == plot: |
|
978 | 1082 | plot = 'moments' |
|
1083 | elif 'spc_oblique' == plot: | |
|
1084 | plot = 'oblique' | |
|
979 | 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 | 1088 | self.data['noise'] = {} |
|
983 | 1089 | self.data['rti'] = {} |
|
984 | 1090 | if 'noise' not in self.plottypes: |
@@ -1020,16 +1126,33 class PlotterData(object): | |||
|
1020 | 1126 | self.__heights.append(dataOut.heightList) |
|
1021 | 1127 | self.__all_heights.update(dataOut.heightList) |
|
1022 | 1128 | |
|
1129 | ||
|
1130 | ||
|
1023 | 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 | 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 | 1146 | buffer = 10*numpy.log10(z) |
|
1027 | 1147 | if plot == 'cspc': |
|
1028 | 1148 | buffer = (dataOut.data_spc, dataOut.data_cspc) |
|
1149 | self.nFactor=dataOut.normFactor | |
|
1029 | 1150 | if plot == 'noise': |
|
1030 | 1151 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
1031 | 1152 | if plot in ('rti', 'spcprofile'): |
|
1032 | 1153 | buffer = dataOut.getPower() |
|
1154 | #print(buffer[0,0]) | |
|
1155 | #exit() | |
|
1033 | 1156 | if plot == 'snr_db': |
|
1034 | 1157 | buffer = dataOut.data_SNR |
|
1035 | 1158 | if plot == 'snr': |
@@ -1048,6 +1171,277 class PlotterData(object): | |||
|
1048 | 1171 | buffer = dataOut.data_output |
|
1049 | 1172 | if plot == 'param': |
|
1050 | 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 | 1445 | if plot == 'scope': |
|
1052 | 1446 | buffer = dataOut.data |
|
1053 | 1447 | self.flagDataAsBlock = dataOut.flagDataAsBlock |
@@ -1076,6 +1470,10 class PlotterData(object): | |||
|
1076 | 1470 | elif plot == 'spc_moments': |
|
1077 | 1471 | self.data['spc'][tm] = buffer |
|
1078 | 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 | 1477 | else: |
|
1080 | 1478 | if self.buffering: |
|
1081 | 1479 | self.data[plot][tm] = buffer |
@@ -1141,6 +1539,7 class PlotterData(object): | |||
|
1141 | 1539 | meta['interval'] = float(self.interval) |
|
1142 | 1540 | meta['localtime'] = self.localtime |
|
1143 | 1541 | meta['yrange'] = self.roundFloats(self.heights[::dy].tolist()) |
|
1542 | ||
|
1144 | 1543 | if 'spc' in self.data or 'cspc' in self.data: |
|
1145 | 1544 | meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) |
|
1146 | 1545 | else: |
@@ -137,7 +137,7 class BasicHeader(Header): | |||
|
137 | 137 | timeZone = None |
|
138 | 138 | dstFlag = None |
|
139 | 139 | errorCount = None |
|
140 |
|
|
|
140 | F = None | |
|
141 | 141 | structure = BASIC_STRUCTURE |
|
142 | 142 | __LOCALTIME = None |
|
143 | 143 | |
@@ -363,6 +363,7 class RadarControllerHeader(Header): | |||
|
363 | 363 | self.expType = int(header['nExpType'][0]) |
|
364 | 364 | self.nTx = int(header['nNTx'][0]) |
|
365 | 365 | self.ipp = float(header['fIpp'][0]) |
|
366 | #print(self.ipp) | |
|
366 | 367 | self.txA = float(header['fTxA'][0]) |
|
367 | 368 | self.txB = float(header['fTxB'][0]) |
|
368 | 369 | self.nWindows = int(header['nNumWindows'][0]) |
@@ -534,6 +535,7 class RadarControllerHeader(Header): | |||
|
534 | 535 | def get_ippSeconds(self): |
|
535 | 536 | ''' |
|
536 | 537 | ''' |
|
538 | ||
|
537 | 539 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT |
|
538 | 540 | |
|
539 | 541 | return ippSeconds |
@@ -640,6 +642,7 class ProcessingHeader(Header): | |||
|
640 | 642 | self.nWindows = int(header['nNumWindows'][0]) |
|
641 | 643 | self.processFlags = header['nProcessFlags'] |
|
642 | 644 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
645 | ||
|
643 | 646 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
644 | 647 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
645 | 648 |
@@ -3,3 +3,4 from .jroplot_spectra import * | |||
|
3 | 3 | from .jroplot_heispectra import * |
|
4 | 4 | from .jroplot_correlation import * |
|
5 | 5 | from .jroplot_parameters import * |
|
6 | from .jroplot_voltage_lags import * |
@@ -221,6 +221,10 class Plot(Operation): | |||
|
221 | 221 | self.zmin = kwargs.get('zmin', None) |
|
222 | 222 | self.zmax = kwargs.get('zmax', None) |
|
223 | 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 | 228 | self.xmin = kwargs.get('xmin', None) |
|
225 | 229 | self.xmax = kwargs.get('xmax', None) |
|
226 | 230 | self.xrange = kwargs.get('xrange', 12) |
@@ -603,7 +607,8 class Plot(Operation): | |||
|
603 | 607 | ''' |
|
604 | 608 | Main plotting routine |
|
605 | 609 | ''' |
|
606 | ||
|
610 | print("time_inside_plot: ",dataOut.datatime) | |
|
611 | print(dataOut.flagNoData) | |
|
607 | 612 | if self.isConfig is False: |
|
608 | 613 | self.__setup(**kwargs) |
|
609 | 614 | |
@@ -662,4 +667,3 class Plot(Operation): | |||
|
662 | 667 | self.__plot() |
|
663 | 668 | if self.data and not self.data.flagNoData and self.pause: |
|
664 | 669 | figpause(10) |
|
665 |
@@ -38,6 +38,15 class SpectralMomentsPlot(SpectraPlot): | |||
|
38 | 38 | colormap = 'jet' |
|
39 | 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 | 51 | class SnrPlot(RTIPlot): |
|
43 | 52 | ''' |
@@ -336,4 +345,3 class PolarMapPlot(Plot): | |||
|
336 | 345 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
337 | 346 | self.titles = ['{} {}'.format( |
|
338 | 347 | self.data.parameters[x], title) for x in self.channels] |
|
339 |
This diff has been collapsed as it changes many lines, (540 lines changed) Show them Hide them | |||
@@ -22,6 +22,7 class SpectraPlot(Plot): | |||
|
22 | 22 | plot_type = 'pcolor' |
|
23 | 23 | |
|
24 | 24 | def setup(self): |
|
25 | ||
|
25 | 26 | self.nplots = len(self.data.channels) |
|
26 | 27 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
27 | 28 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
@@ -31,10 +32,13 class SpectraPlot(Plot): | |||
|
31 | 32 | self.width = 4 * self.ncols |
|
32 | 33 | else: |
|
33 | 34 | self.width = 3.5 * self.ncols |
|
34 |
self.plots_adjust.update({'wspace': 0. |
|
|
35 | self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18}) | |
|
35 | 36 | self.ylabel = 'Range [km]' |
|
36 | 37 | |
|
37 | 38 | def plot(self): |
|
39 | ||
|
40 | #print(self.xaxis) | |
|
41 | #exit(1) | |
|
38 | 42 | if self.xaxis == "frequency": |
|
39 | 43 | x = self.data.xrange[0] |
|
40 | 44 | self.xlabel = "Frequency (kHz)" |
@@ -51,19 +55,25 class SpectraPlot(Plot): | |||
|
51 | 55 | |
|
52 | 56 | self.titles = [] |
|
53 | 57 | |
|
58 | ||
|
54 | 59 | y = self.data.heights |
|
55 | 60 | self.y = y |
|
56 | 61 | z = self.data['spc'] |
|
57 | 62 | |
|
63 | self.CODE2 = 'spc_oblique' | |
|
64 | ||
|
65 | ||
|
58 | 66 | for n, ax in enumerate(self.axes): |
|
59 | 67 | noise = self.data['noise'][n][-1] |
|
60 | 68 | if self.CODE == 'spc_moments': |
|
61 | 69 | mean = self.data['moments'][n, :, 1, :][-1] |
|
70 | ||
|
62 | 71 | if ax.firsttime: |
|
63 | 72 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
64 | 73 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
65 | 74 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
66 | 75 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
76 | #print(numpy.shape(x)) | |
|
67 | 77 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
68 | 78 | vmin=self.zmin, |
|
69 | 79 | vmax=self.zmax, |
@@ -77,15 +87,122 class SpectraPlot(Plot): | |||
|
77 | 87 | color="k", linestyle="dashed", lw=1)[0] |
|
78 | 88 | if self.CODE == 'spc_moments': |
|
79 | 89 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
90 | ||
|
80 | 91 | else: |
|
92 | ||
|
81 | 93 | ax.plt.set_array(z[n].T.ravel()) |
|
82 | 94 | if self.showprofile: |
|
83 | 95 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) |
|
84 | 96 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
85 | 97 | if self.CODE == 'spc_moments': |
|
86 | 98 | ax.plt_mean.set_data(mean, y) |
|
99 | ||
|
87 | 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 | 207 | class CrossSpectraPlot(Plot): |
|
91 | 208 | |
@@ -103,7 +220,7 class CrossSpectraPlot(Plot): | |||
|
103 | 220 | self.nrows = len(self.data.pairs) |
|
104 | 221 | self.nplots = self.nrows * 4 |
|
105 | 222 | self.width = 3.1 * self.ncols |
|
106 |
self.height = |
|
|
223 | self.height = 5 * self.nrows | |
|
107 | 224 | self.ylabel = 'Range [km]' |
|
108 | 225 | self.showprofile = False |
|
109 | 226 | self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08}) |
@@ -122,21 +239,35 class CrossSpectraPlot(Plot): | |||
|
122 | 239 | |
|
123 | 240 | self.titles = [] |
|
124 | 241 | |
|
242 | ||
|
125 | 243 | y = self.data.heights |
|
126 | 244 | self.y = y |
|
127 | 245 | nspc = self.data['spc'] |
|
246 | #print(numpy.shape(self.data['spc'])) | |
|
128 | 247 | spc = self.data['cspc'][0] |
|
248 | #print(numpy.shape(spc)) | |
|
249 | #exit() | |
|
129 | 250 | cspc = self.data['cspc'][1] |
|
251 | #print(numpy.shape(cspc)) | |
|
252 | #exit() | |
|
130 | 253 | |
|
131 | 254 | for n in range(self.nrows): |
|
132 | 255 | noise = self.data['noise'][:,-1] |
|
133 | 256 | pair = self.data.pairs[n] |
|
257 | #print(pair) | |
|
258 | #exit() | |
|
134 | 259 | ax = self.axes[4 * n] |
|
135 | 260 | if ax.firsttime: |
|
136 | 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 | |
|
263 | self.xmin = self.xmin if self.xmin else numpy.nanmin(x) | |
|
138 | 264 |
self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc) |
|
139 | 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 | 271 | ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T, |
|
141 | 272 | vmin=self.zmin, |
|
142 | 273 | vmax=self.zmax, |
@@ -185,6 +316,332 class CrossSpectraPlot(Plot): | |||
|
185 | 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 | 645 | class RTIPlot(Plot): |
|
189 | 646 | ''' |
|
190 | 647 | Plot for RTI data |
@@ -202,7 +659,7 class RTIPlot(Plot): | |||
|
202 | 659 | self.ylabel = 'Range [km]' |
|
203 | 660 | self.xlabel = 'Time' |
|
204 | 661 | self.cb_label = 'dB' |
|
205 |
self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0. |
|
|
662 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95}) | |
|
206 | 663 | self.titles = ['{} Channel {}'.format( |
|
207 | 664 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
208 | 665 | |
@@ -210,6 +667,78 class RTIPlot(Plot): | |||
|
210 | 667 | self.x = self.data.times |
|
211 | 668 | self.y = self.data.heights |
|
212 | 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 | 742 | self.z = numpy.ma.masked_invalid(self.z) |
|
214 | 743 | |
|
215 | 744 | if self.decimation is None: |
@@ -296,6 +825,7 class NoisePlot(Plot): | |||
|
296 | 825 | self.xlabel = 'Time' |
|
297 | 826 | self.titles = ['Noise'] |
|
298 | 827 | self.colorbar = False |
|
828 | self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.17, 'right':0.95}) | |
|
299 | 829 | |
|
300 | 830 | def plot(self): |
|
301 | 831 | |
@@ -315,7 +845,7 class NoisePlot(Plot): | |||
|
315 | 845 | self.axes[0].lines[ch].set_data(x, y) |
|
316 | 846 | |
|
317 | 847 | self.ymin = numpy.nanmin(Y) - 5 |
|
318 |
self.ymax = numpy.nanmax(Y) + |
|
|
848 | self.ymax = numpy.nanmax(Y) + 10 | |
|
319 | 849 | |
|
320 | 850 | |
|
321 | 851 | class PowerProfilePlot(Plot): |
@@ -22,3 +22,8 from .julIO_param import * | |||
|
22 | 22 | |
|
23 | 23 | from .pxIO_param import * |
|
24 | 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 | 78 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
79 | 79 | |
|
80 | 80 | try: |
|
81 | ||
|
81 | 82 | fp = open(filename, 'rb') |
|
82 | 83 | except IOError: |
|
83 | 84 | print("The file %s can't be opened" % (filename)) |
@@ -140,6 +141,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
140 | 141 | |
|
141 | 142 | firstBasicHeaderObj = BasicHeader(LOCALTIME) |
|
142 | 143 | systemHeaderObj = SystemHeader() |
|
144 | ||
|
143 | 145 | radarControllerHeaderObj = RadarControllerHeader() |
|
144 | 146 | processingHeaderObj = ProcessingHeader() |
|
145 | 147 | |
@@ -539,9 +541,15 class Reader(object): | |||
|
539 | 541 | for fo in files: |
|
540 | 542 |
try: |
|
541 | 543 |
dt = datetime.datetime.strptime(parse_format(fo, filefmt), filefmt).date() |
|
544 | #print(dt) | |
|
545 | #print(startDate) | |
|
546 | #print(endDate) | |
|
542 | 547 | if dt >= startDate and dt <= endDate: |
|
548 | ||
|
543 | 549 | yield os.path.join(path, expLabel, fo) |
|
550 | ||
|
544 | 551 | else: |
|
552 | ||
|
545 | 553 | log.log('Skiping file {}'.format(fo), self.name) |
|
546 | 554 | except Exception as e: |
|
547 | 555 | log.log('Skiping file {}'.format(fo), self.name) |
@@ -592,27 +600,41 class Reader(object): | |||
|
592 | 600 | def setNextFile(self): |
|
593 | 601 | """Set the next file to be readed open it and parse de file header""" |
|
594 | 602 | |
|
603 | #print("fp: ",self.fp) | |
|
595 | 604 | while True: |
|
605 | ||
|
606 | #print(self.fp) | |
|
596 | 607 | if self.fp != None: |
|
597 | 608 |
self.fp.close() |
|
598 | 609 | |
|
610 | #print("setNextFile") | |
|
611 | #print("BEFORE OPENING",self.filename) | |
|
599 | 612 | if self.online: |
|
600 | 613 | newFile = self.setNextFileOnline() |
|
614 | ||
|
601 | 615 | else: |
|
616 | ||
|
602 | 617 | newFile = self.setNextFileOffline() |
|
603 | 618 | |
|
619 | #print("newFile: ",newFile) | |
|
604 | 620 | if not(newFile): |
|
621 | ||
|
605 | 622 | if self.online: |
|
606 | 623 | raise schainpy.admin.SchainError('Time to wait for new files reach') |
|
607 | 624 | else: |
|
608 | 625 | if self.fileIndex == -1: |
|
626 | #print("OKK") | |
|
609 | 627 | raise schainpy.admin.SchainWarning('No files found in the given path') |
|
610 | 628 | else: |
|
629 | ||
|
611 | 630 | raise schainpy.admin.SchainWarning('No more files to read') |
|
612 | 631 | |
|
613 | 632 | if self.verifyFile(self.filename): |
|
633 | ||
|
614 | 634 | break |
|
615 | 635 | |
|
636 | ##print("BEFORE OPENING",self.filename) | |
|
637 | ||
|
616 | 638 | log.log('Opening file: %s' % self.filename, self.name) |
|
617 | 639 | |
|
618 | 640 | self.readFirstHeader() |
@@ -630,6 +652,7 class Reader(object): | |||
|
630 | 652 | boolean |
|
631 | 653 | |
|
632 | 654 | """ |
|
655 | ||
|
633 | 656 | nextFile = True |
|
634 | 657 | nextDay = False |
|
635 | 658 | |
@@ -648,7 +671,7 class Reader(object): | |||
|
648 | 671 | if fullfilename is not None: |
|
649 | 672 | break |
|
650 | 673 | |
|
651 | self.nTries = 1 | |
|
674 | #self.nTries = 1 | |
|
652 | 675 |
nextFile = True |
|
653 | 676 | |
|
654 | 677 | if nFiles == (self.nFiles - 1): |
@@ -662,7 +685,9 class Reader(object): | |||
|
662 | 685 | self.flagIsNewFile = 1 |
|
663 | 686 | if self.fp != None: |
|
664 | 687 | self.fp.close() |
|
688 | #print(fullfilename) | |
|
665 | 689 | self.fp = self.open_file(fullfilename, self.open_mode) |
|
690 | ||
|
666 | 691 | self.flagNoMoreFiles = 0 |
|
667 | 692 | self.fileIndex += 1 |
|
668 | 693 | return 1 |
@@ -678,7 +703,8 class Reader(object): | |||
|
678 | 703 | except StopIteration: |
|
679 | 704 | self.flagNoMoreFiles = 1 |
|
680 | 705 |
return 0 |
|
681 | ||
|
706 | #print(self.fileIndex) | |
|
707 | #print(filename) | |
|
682 | 708 | self.filename = filename |
|
683 | 709 | self.fileSize = os.path.getsize(filename) |
|
684 | 710 | self.fp = self.open_file(filename, self.open_mode) |
@@ -715,6 +741,7 class Reader(object): | |||
|
715 | 741 | def readFirstHeader(self): |
|
716 | 742 | """Parse the file header""" |
|
717 | 743 | |
|
744 | ||
|
718 | 745 | pass |
|
719 | 746 | |
|
720 | 747 | def waitDataBlock(self, pointer_location, blocksize=None): |
@@ -797,6 +824,14 class JRODataReader(Reader): | |||
|
797 | 824 | elif self.ext.lower() == ".pdata": # spectra |
|
798 | 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 | 835 | # barrido por las combinaciones posibles |
|
801 | 836 | for prefixDir in prefixDirList: |
|
802 | 837 | thispath = self.path |
@@ -853,6 +888,7 class JRODataReader(Reader): | |||
|
853 | 888 | return 0 |
|
854 | 889 | |
|
855 | 890 | print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)) |
|
891 | #print(self.filename) | |
|
856 | 892 | time.sleep(self.delay) |
|
857 | 893 | |
|
858 | 894 | return 0 |
@@ -921,6 +957,10 class JRODataReader(Reader): | |||
|
921 | 957 | print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, |
|
922 | 958 | self.processingHeaderObj.dataBlocksPerFile, |
|
923 | 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 | 964 | return 1 |
|
925 | 965 | |
|
926 | 966 | def readFirstHeader(self): |
@@ -396,12 +396,16 Inputs: | |||
|
396 | 396 | def run(self, dataOut, path, oneDDict, ind2DList='[]', twoDDict='{}', |
|
397 | 397 | metadata='{}', format='cedar', **kwargs): |
|
398 | 398 | |
|
399 | ||
|
400 | #if dataOut.AUX==1: #Modified | |
|
401 | ||
|
399 | 402 | if not self.isConfig: |
|
400 | 403 | self.setup(path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs) |
|
401 | 404 | self.isConfig = True |
|
402 | 405 | |
|
403 | 406 |
self.dataOut = dataOut |
|
404 | 407 |
self.putData() |
|
408 | ||
|
405 | 409 | return 1 |
|
406 | 410 | |
|
407 | 411 | def setup(self, path, oneDDict, ind2DList, twoDDict, metadata, format, **kwargs): |
@@ -440,6 +444,9 Inputs: | |||
|
440 | 444 | |
|
441 | 445 | self.mnemonic = MNEMONICS[self.kinst] #TODO get mnemonic from madrigal |
|
442 | 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 | 451 | filename = '{}{}{}'.format(self.mnemonic, |
|
445 | 452 | date.strftime('%Y%m%d_%H%M%S'), |
@@ -461,6 +468,8 Inputs: | |||
|
461 | 468 | if not os.path.exists(self.path): |
|
462 | 469 | os.makedirs(self.path) |
|
463 | 470 | self.fp = madrigal.cedar.MadrigalCedarFile(self.fullname, True) |
|
471 | ||
|
472 | ||
|
464 | 473 | except ValueError as e: |
|
465 | 474 | log.error( |
|
466 | 475 | 'Impossible to create a cedar object with "madrigal.cedar.MadrigalCedarFile"', |
@@ -475,11 +484,26 Inputs: | |||
|
475 | 484 | attributes. |
|
476 | 485 | Allowed parameters in: parcodes.tab |
|
477 | 486 | ''' |
|
478 | ||
|
487 | #self.dataOut.paramInterval=2 | |
|
479 | 488 | startTime = datetime.datetime.utcfromtimestamp(self.dataOut.utctime) |
|
489 | ||
|
480 | 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 | 500 | heights = self.dataOut.heightList |
|
482 | 501 | |
|
502 | #print(self.blocks) | |
|
503 | #print(startTime) | |
|
504 | #print(endTime) | |
|
505 | #print(heights) | |
|
506 | #input() | |
|
483 | 507 | if self.ext == '.dat': |
|
484 | 508 | for key, value in list(self.twoDDict.items()): |
|
485 | 509 | if isinstance(value, str): |
@@ -506,12 +530,20 Inputs: | |||
|
506 | 530 | elif isinstance(value, (tuple, list)): |
|
507 | 531 | attr, x = value |
|
508 | 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 | 539 | out[key] = data[int(x)][:len(heights)] |
|
510 | 540 | |
|
511 | 541 | a = numpy.array([out[k] for k in self.keys]) |
|
542 | #print(a) | |
|
512 | 543 | nrows = numpy.array([numpy.isnan(a[:, x]).all() for x in range(len(heights))]) |
|
513 | 544 | index = numpy.where(nrows == False)[0] |
|
514 | 545 | |
|
546 | #print(startTime.minute) | |
|
515 | 547 | rec = madrigal.cedar.MadrigalDataRecord( |
|
516 | 548 | self.kinst, |
|
517 | 549 | self.kindat, |
@@ -534,7 +566,7 Inputs: | |||
|
534 | 566 | len(index), |
|
535 | 567 | **self.extra_args |
|
536 | 568 | ) |
|
537 | ||
|
569 | #print("rec",rec) | |
|
538 | 570 |
# Setting 1d values |
|
539 | 571 | for key in self.oneDDict: |
|
540 | 572 | rec.set1D(key, getattr(self.dataOut, self.oneDDict[key])) |
@@ -547,9 +579,11 Inputs: | |||
|
547 | 579 |
nrec += 1 |
|
548 | 580 | |
|
549 | 581 | self.fp.append(rec) |
|
550 |
if self.ext == '.hdf5' and self.counter % |
|
|
582 | if self.ext == '.hdf5' and self.counter %2 == 0 and self.counter > 0: | |
|
583 | #print("here") | |
|
551 | 584 | self.fp.dump() |
|
552 | 585 | if self.counter % 20 == 0 and self.counter > 0: |
|
586 | #self.fp.write() | |
|
553 | 587 | log.log( |
|
554 | 588 | 'Writing {} records'.format( |
|
555 | 589 | self.counter), |
@@ -424,7 +424,8 class HDFWriter(Operation): | |||
|
424 | 424 | |
|
425 | 425 | def run(self, dataOut, path, blocksPerFile=10, metadataList=None, |
|
426 | 426 | dataList=[], setType=None, description={}): |
|
427 | ||
|
427 | print("hdf",dataOut.flagNoData) | |
|
428 | print(dataOut.datatime.ctime()) | |
|
428 | 429 | self.dataOut = dataOut |
|
429 | 430 | if not(self.isConfig): |
|
430 | 431 |
self.setup(path=path, blocksPerFile=blocksPerFile, |
@@ -79,21 +79,22 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
79 | 79 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
80 | 80 | self.systemHeaderObj = SystemHeader() |
|
81 | 81 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
82 | ||
|
82 | 83 | self.processingHeaderObj = ProcessingHeader() |
|
83 | 84 | self.lastUTTime = 0 |
|
84 | 85 |
self.profileIndex = 2**32 - 1 |
|
85 | 86 | self.dataOut = Voltage() |
|
86 | 87 | self.selBlocksize = None |
|
87 | 88 | self.selBlocktime = None |
|
88 | ||
|
89 | ##print("1--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
89 | 90 | def createObjByDefault(self): |
|
90 | ||
|
91 | ##print("2--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
91 | 92 | dataObj = Voltage() |
|
92 | 93 | |
|
93 | 94 | return dataObj |
|
94 | 95 | |
|
95 | 96 | def __hasNotDataInBuffer(self): |
|
96 | ||
|
97 | ##print("3--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
97 | 98 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs: |
|
98 | 99 | return 1 |
|
99 | 100 | |
@@ -109,11 +110,13 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
109 | 110 | Return: |
|
110 | 111 | None |
|
111 | 112 | """ |
|
113 | ##print("4--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
112 | 114 | pts2read = self.processingHeaderObj.profilesPerBlock * \ |
|
113 | 115 | self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
114 | 116 | self.blocksize = pts2read |
|
115 | 117 | |
|
116 | 118 | def readBlock(self): |
|
119 | ||
|
117 | 120 | """ |
|
118 | 121 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
119 | 122 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
@@ -136,7 +139,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
136 | 139 |
Exceptions: |
|
137 | 140 | Si un bloque leido no es un bloque valido |
|
138 | 141 | """ |
|
139 | ||
|
142 | ##print("5--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
140 | 143 | # if self.server is not None: |
|
141 | 144 | # self.zBlock = self.receiver.recv() |
|
142 | 145 | # self.zHeader = self.zBlock[:24] |
@@ -177,6 +180,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
177 | 180 | return 1 |
|
178 | 181 | |
|
179 | 182 | def getFirstHeader(self): |
|
183 | ##print("6--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
180 | 184 | |
|
181 | 185 | self.getBasicHeader() |
|
182 | 186 | |
@@ -186,8 +190,12 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
186 | 190 | |
|
187 | 191 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
188 | 192 | |
|
193 | #self.dataOut.ippSeconds_general=self.radarControllerHeaderObj.ippSeconds | |
|
194 | #print(self.nTxs) | |
|
189 | 195 | if self.nTxs > 1: |
|
196 | #print(self.radarControllerHeaderObj.ippSeconds) | |
|
190 | 197 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
198 | #print(self.radarControllerHeaderObj.ippSeconds) | |
|
191 | 199 | # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. |
|
192 | 200 | |
|
193 | 201 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
@@ -220,7 +228,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
220 | 228 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
221 | 229 | |
|
222 | 230 | def reshapeData(self): |
|
223 | ||
|
231 | ##print("7--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
224 | 232 | if self.nTxs < 0: |
|
225 | 233 | return |
|
226 | 234 | |
@@ -247,6 +255,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
247 | 255 | |
|
248 | 256 | def readFirstHeaderFromServer(self): |
|
249 | 257 | |
|
258 | ##print("8--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
250 | 259 | self.getFirstHeader() |
|
251 | 260 | |
|
252 | 261 | self.firstHeaderSize = self.basicHeaderObj.size |
@@ -278,6 +287,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
278 | 287 | self.getBlockDimension() |
|
279 | 288 | |
|
280 | 289 | def getFromServer(self): |
|
290 | ##print("9--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
281 | 291 | self.flagDiscontinuousBlock = 0 |
|
282 | 292 | self.profileIndex = 0 |
|
283 | 293 | self.flagIsNewBlock = 1 |
@@ -382,6 +392,8 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
382 | 392 | self.flagDiscontinuousBlock |
|
383 | 393 | self.flagIsNewBlock |
|
384 | 394 | """ |
|
395 | ||
|
396 | ##print("10--OKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK") | |
|
385 | 397 | if self.flagNoMoreFiles: |
|
386 | 398 | self.dataOut.flagNoData = True |
|
387 | 399 | return 0 |
@@ -410,6 +422,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
410 | 422 | self.dataOut.data = self.datablock[:, self.profileIndex, :] |
|
411 | 423 | self.dataOut.profileIndex = self.profileIndex |
|
412 | 424 | |
|
425 | ||
|
413 | 426 | self.profileIndex += 1 |
|
414 | 427 | |
|
415 | 428 | else: |
@@ -458,9 +471,13 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
458 | 471 | self.dataOut.flagDataAsBlock = True |
|
459 | 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 | 478 | self.dataOut.flagNoData = False |
|
462 | 479 | |
|
463 | self.getBasicHeader() | |
|
480 | #self.getBasicHeader() | |
|
464 | 481 | |
|
465 | 482 | self.dataOut.realtime = self.online |
|
466 | 483 | |
@@ -673,4 +690,3 class VoltageWriter(JRODataWriter, Operation): | |||
|
673 | 690 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
674 | 691 | |
|
675 | 692 | self.setBasicHeader() |
|
676 | No newline at end of file |
@@ -14,3 +14,9 from .jroproc_spectra_lags import * | |||
|
14 | 14 | from .jroproc_spectra_acf import * |
|
15 | 15 | from .bltrproc_parameters import * |
|
16 | 16 | from .pxproc_parameters import * |
|
17 | ||
|
18 | ||
|
19 | ###########DP########### | |
|
20 | from .jroproc_voltage_lags import * | |
|
21 | ###########DP########### | |
|
22 | from .jroproc_spectra_lags_faraday import * |
|
1 | NO CONTENT: modified file |
This diff has been collapsed as it changes many lines, (552 lines changed) Show them Hide them | |||
@@ -302,6 +302,12 class SpectralFilters(Operation): | |||
|
302 | 302 |
|
|
303 | 303 |
|
|
304 | 304 | |
|
305 | ||
|
306 | from scipy.optimize import fmin | |
|
307 | import itertools | |
|
308 | from scipy.optimize import curve_fit | |
|
309 | ||
|
310 | ||
|
305 | 311 |
|
|
306 | 312 | |
|
307 | 313 |
|
@@ -321,113 +327,175 class GaussianFit(Operation): | |||
|
321 | 327 |
|
|
322 | 328 | |
|
323 | 329 | |
|
324 |
|
|
|
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 | 332 |
|
|
333 | methods: generalized, squared | |
|
326 | 334 | input: spc |
|
327 | 335 | output: |
|
328 |
|
|
|
336 | noise, amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1 | |
|
329 | 337 | """ |
|
330 | ||
|
338 | print ('Entering ',method,' double Gaussian fit') | |
|
331 | 339 |
|
|
332 | 340 |
|
|
333 | 341 |
|
|
334 | 342 |
|
|
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 | 344 |
|
|
345 | 345 | |
|
346 | noise_ = dataOut.spc_noise[0].copy() | |
|
347 | ||
|
348 | ||
|
349 | 346 |
|
|
350 |
|
|
|
347 | args = [(dataOut.spc_range[2], ich, dataOut.spc_noise[ich], dataOut.nIncohInt, SNRdBlimit) for ich in range(self.Num_Chn)] | |
|
351 | 348 |
|
|
352 | 349 |
|
|
353 |
|
|
|
354 | dataOut.SPCparam = numpy.asarray(SPCparam) | |
|
355 | ||
|
356 | ''' Parameters: | |
|
357 | 1. Amplitude | |
|
358 | 2. Shift | |
|
359 | 3. Width | |
|
360 | 4. Power | |
|
361 | ''' | |
|
350 | DGauFitParam = pool.map(target, attrs) | |
|
351 | # Parameters: | |
|
352 | # 0. Noise, 1. Amplitude, 2. Shift, 3. Width 4. Power | |
|
353 | dataOut.DGauFitParams = numpy.asarray(DGauFitParam) | |
|
354 | ||
|
355 | # Double Gaussian Curves | |
|
356 | gau0 = numpy.zeros([self.Num_Chn,self.Num_Bin,self.Num_Hei]) | |
|
357 | gau0[:] = numpy.NaN | |
|
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 | 396 |
|
|
397 | # print('Entering FitGau') | |
|
398 | # Assigning the variables | |
|
399 | Vrange, ch, wnoise, num_intg, SNRlimit = X | |
|
400 | # Noise Limits | |
|
401 | noisebl = wnoise * 0.9 | |
|
402 | noisebh = wnoise * 1.1 | |
|
403 | # Radar Velocity | |
|
404 | Va = max(Vrange) | |
|
405 | deltav = Vrange[1] - Vrange[0] | |
|
406 | x = numpy.arange(self.Num_Bin) | |
|
364 | 407 | |
|
365 | Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X | |
|
366 | ||
|
367 | SPCparam = [] | |
|
368 | SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
369 | SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei]) | |
|
370 | SPC_ch1[:] = 0#numpy.NaN | |
|
371 | SPC_ch2[:] = 0#numpy.NaN | |
|
372 | ||
|
408 | # print ('stop 0') | |
|
373 | 409 | |
|
410 | # 5 parameters, 2 Gaussians | |
|
411 | DGauFitParam = numpy.zeros([5, self.Num_Hei,2]) | |
|
412 | DGauFitParam[:] = numpy.NaN | |
|
374 | 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 | 420 |
|
|
376 | ||
|
377 | ||
|
421 | # print (ht) | |
|
422 | # print ('stop 2') | |
|
423 | # Spectra at each range | |
|
378 | 424 |
|
|
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 | 439 |
|
|
382 | 440 |
|
|
383 |
|
|
|
441 | # spc_norm_max = max(spc) #commented by D. Scipión 19.03.2021 | |
|
384 | 442 |
|
|
385 |
|
|
|
443 | # pnoise = pnoise #/ spc_norm_max #commented by D. Scipión 19.03.2021 | |
|
386 | 444 |
|
|
387 | 445 | |
|
446 | # print ('stop 2.1') | |
|
388 | 447 |
|
|
448 | # noise per channel.... we might want to use the noise at each range | |
|
389 | 449 | |
|
390 |
|
|
|
450 | # wnoise = noise_ #/ spc_norm_max #commented by D. Scipión 19.03.2021 | |
|
391 | 451 |
|
|
392 | 452 |
|
|
393 | 453 |
|
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
|
454 | # noisebl = wnoise*0.9 | |
|
455 | # noisebh = wnoise*1.1 | |
|
456 | spc = spc - wnoise # signal | |
|
397 | 457 | |
|
458 | # print ('stop 2.2') | |
|
398 | 459 |
|
|
399 | 460 |
|
|
400 | 461 |
|
|
401 | 462 |
|
|
402 |
|
|
|
403 | ||
|
404 | snr = sum(spcs)/tot_noise | |
|
405 | snrdB=10.*numpy.log10(snr) | |
|
463 | # tot_noise = wnoise * self.Num_Bin #64; | |
|
406 | 464 | |
|
407 | if snrdB < SNRlimit : | |
|
408 |
|
|
|
409 | SPC_ch1[:,ht] = 0#numpy.NaN | |
|
410 | SPC_ch1[:,ht] = 0#numpy.NaN | |
|
411 | SPCparam = (SPC_ch1,SPC_ch2) | |
|
412 |
|
|
|
465 | # print ('stop 2.3') | |
|
466 | # snr = sum(spcs) / tot_noise | |
|
467 | # snrdB = 10.*numpy.log10(snr) | |
|
468 | #print ('stop 3') | |
|
469 | # if snrdB < SNRlimit : | |
|
470 | # snr = numpy.NaN | |
|
471 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
|
472 | # SPC_ch1[:,ht] = 0#numpy.NaN | |
|
473 | # SPCparam = (SPC_ch1,SPC_ch2) | |
|
474 | # print ('SNR less than SNRth') | |
|
475 | # continue | |
|
413 | 476 | |
|
414 | 477 | |
|
415 | 478 |
|
|
416 | 479 |
|
|
417 | ||
|
418 |
|
|
|
480 | # print ('stop 4') | |
|
481 | cummax = max(cum) | |
|
419 | 482 |
|
|
420 |
|
|
|
483 | cumlo = cummax * epsi | |
|
421 | 484 |
|
|
422 | 485 |
|
|
423 | 486 | |
|
424 | ||
|
487 | # print ('stop 5') | |
|
425 | 488 |
|
|
489 | # print ('powerindex < 1') | |
|
426 | 490 |
|
|
427 | 491 |
|
|
428 | 492 |
|
|
429 | 493 |
|
|
494 | if powerwidth <= 1: | |
|
495 | # print('powerwidth <= 1') | |
|
496 | continue | |
|
430 | 497 | |
|
498 | # print ('stop 6') | |
|
431 | 499 |
|
|
432 | 500 |
|
|
433 | 501 |
|
@@ -435,7 +503,6 class GaussianFit(Operation): | |||
|
435 | 503 |
|
|
436 | 504 |
|
|
437 | 505 | |
|
438 | x=numpy.arange( self.Num_Bin ) | |
|
439 | 506 |
|
|
440 | 507 | |
|
441 | 508 |
|
@@ -444,12 +511,14 class GaussianFit(Operation): | |||
|
444 | 511 |
|
|
445 | 512 |
|
|
446 | 513 |
|
|
447 |
|
|
|
514 | bnds = ((0,self.Num_Bin-1),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) | |
|
448 | 515 |
|
|
516 | # print ('stop 7.1') | |
|
517 | # print (bnds) | |
|
449 | 518 | |
|
450 |
|
|
|
451 | ||
|
519 | chiSq1=lsq1[1] | |
|
452 | 520 | |
|
521 | # print ('stop 8') | |
|
453 | 522 |
|
|
454 | 523 |
|
|
455 | 524 |
|
@@ -464,30 +533,33 class GaussianFit(Operation): | |||
|
464 | 533 |
|
|
465 | 534 |
|
|
466 | 535 | |
|
467 | ''' two gaussians ''' | |
|
536 | # print ('stop 9') | |
|
537 | ''' two Gaussians ''' | |
|
468 | 538 |
|
|
469 |
|
|
|
539 | shift0 = numpy.mod(firstpeak+minx, self.Num_Bin ) | |
|
470 | 540 |
|
|
471 |
|
|
|
541 | width0 = powerwidth/6. | |
|
472 | 542 |
|
|
473 |
|
|
|
543 | power0 = 2. | |
|
474 | 544 |
|
|
475 |
|
|
|
545 | amplitude0 = firstamp | |
|
476 | 546 |
|
|
477 | 547 |
|
|
478 | 548 |
|
|
479 |
|
|
|
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 | 550 |
|
|
481 | 551 | |
|
552 | # print ('stop 10') | |
|
482 | 553 |
|
|
483 | 554 | |
|
555 | # print ('stop 11') | |
|
556 | chiSq2 = lsq2[1] | |
|
484 | 557 | |
|
485 | chiSq2=lsq2[1]; | |
|
486 | ||
|
487 | ||
|
558 | # print ('stop 12') | |
|
488 | 559 | |
|
489 | 560 |
|
|
490 | 561 | |
|
562 | # print ('stop 13') | |
|
491 | 563 |
|
|
492 | 564 |
|
|
493 | 565 |
|
@@ -495,8 +567,8 class GaussianFit(Operation): | |||
|
495 | 567 |
|
|
496 | 568 |
|
|
497 | 569 |
|
|
498 |
|
|
|
499 |
|
|
|
570 | s1 = (2**(1+1./p1))*scipy.special.gamma(1./p1)/p1 | |
|
571 | s2 = (2**(1+1./p2))*scipy.special.gamma(1./p2)/p2 | |
|
500 | 572 |
|
|
501 | 573 | |
|
502 | 574 |
|
@@ -517,16 +589,19 class GaussianFit(Operation): | |||
|
517 | 589 |
|
|
518 | 590 |
|
|
519 | 591 | |
|
592 | # print ('stop 14') | |
|
593 | shift0 = lsq2[0][0] | |
|
594 | vel0 = Vrange[0] + shift0 * deltav | |
|
595 | shift1 = lsq2[0][4] | |
|
596 | # vel1=Vrange[0] + shift1 * deltav | |
|
520 | 597 | |
|
521 | shift0=lsq2[0][0]; | |
|
522 | vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0]) | |
|
523 | shift1=lsq2[0][4]; | |
|
524 | vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0]) | |
|
525 | ||
|
526 | max_vel = 1.0 | |
|
527 | ||
|
598 | # max_vel = 1.0 | |
|
599 | # Va = max(Vrange) | |
|
600 | # deltav = Vrange[1]-Vrange[0] | |
|
601 | # print ('stop 15') | |
|
528 | 602 |
|
|
529 |
|
|
|
603 | # if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range # Commented by D.Scipión 19.03.2021 | |
|
604 | if vel0 > -Va and vel0 < Va : #first peak is in the correct range | |
|
530 | 605 |
|
|
531 | 606 |
|
|
532 | 607 |
|
@@ -550,38 +625,47 class GaussianFit(Operation): | |||
|
550 | 625 |
|
|
551 | 626 | |
|
552 | 627 |
|
|
553 |
|
|
|
628 | shift0,width0,Amplitude0,p0 = 4*[numpy.NaN] | |
|
554 | 629 |
|
|
555 |
|
|
|
556 | ||
|
557 | ||
|
558 |
|
|
|
559 |
|
|
|
560 |
|
|
|
561 | ||
|
562 | ||
|
563 | return GauSPC | |
|
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 | |
|
564 | 653 | |
|
565 | 654 |
|
|
566 | 655 |
|
|
567 | 656 |
|
|
568 | ||
|
569 | 657 |
|
|
570 | ||
|
571 | 658 |
|
|
572 | 659 |
|
|
573 | 660 | |
|
574 | 661 |
|
|
575 | 662 |
|
|
576 | 663 |
|
|
577 | ||
|
578 | 664 |
|
|
579 | ||
|
580 | 665 |
|
|
581 | model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1) | |
|
582 | 666 | |
|
667 | model1 = amplitude1*numpy.exp(-0.5*abs((x - shift1)/width1)**power1) | |
|
583 | 668 |
|
|
584 | ||
|
585 | 669 |
|
|
586 | 670 |
|
|
587 | 671 | |
@@ -593,6 +677,236 class GaussianFit(Operation): | |||
|
593 | 677 |
|
|
594 | 678 | |
|
595 | 679 | |
|
680 | class Oblique_Gauss_Fit(Operation): | |
|
681 | ||
|
682 | def __init__(self): | |
|
683 | Operation.__init__(self) | |
|
684 | ||
|
685 | ||
|
686 | ||
|
687 | def Gauss_fit(self,spc,x,nGauss): | |
|
688 | ||
|
689 | ||
|
690 | def gaussian(x, a, b, c, d): | |
|
691 | val = a * numpy.exp(-(x - b)**2 / (2*c**2)) + d | |
|
692 | return val | |
|
693 | ||
|
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 | |
|
907 | ||
|
908 | ||
|
909 | ||
|
596 | 910 | |
|
597 | 911 |
|
|
598 | 912 | |
@@ -3998,3 +4312,55 class SMOperations(): | |||
|
3998 | 4312 |
|
|
3999 | 4313 |
|
|
4000 | 4314 |
|
|
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 |
|
1 | NO CONTENT: modified file |
|
1 | NO CONTENT: modified file |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file |
General Comments 0
You need to be logged in to leave comments.
Login now