##// END OF EJS Templates
First faraday ops review #TODO: fix plots
jespinoza -
r1381:3afd912ddcce
parent child
Show More
@@ -1,1254 +1,1229
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Classes to plot Spectra data
5 """Classes to plot Spectra data
6
6
7 """
7 """
8
8
9 import os
9 import os
10 import numpy
10 import numpy
11
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
13
13
14
14
15 class SpectraPlot(Plot):
15 class SpectraPlot(Plot):
16 '''
16 '''
17 Plot for Spectra data
17 Plot for Spectra data
18 '''
18 '''
19
19
20 CODE = 'spc'
20 CODE = 'spc'
21 colormap = 'jet'
21 colormap = 'jet'
22 plot_type = 'pcolor'
22 plot_type = 'pcolor'
23 buffering = False
23 buffering = False
24
24
25 def setup(self):
25 def setup(self):
26
26
27 self.nplots = len(self.data.channels)
27 self.nplots = len(self.data.channels)
28 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
28 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
29 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
29 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
30 self.height = 2.6 * self.nrows
30 self.height = 2.6 * self.nrows
31 self.cb_label = 'dB'
31 self.cb_label = 'dB'
32 if self.showprofile:
32 if self.showprofile:
33 self.width = 4 * self.ncols
33 self.width = 4 * self.ncols
34 else:
34 else:
35 self.width = 3.5 * self.ncols
35 self.width = 3.5 * self.ncols
36 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
36 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
37 self.ylabel = 'Range [km]'
37 self.ylabel = 'Range [km]'
38
38
39 def update(self, dataOut):
39 def update(self, dataOut):
40
40
41 data = {}
41 data = {}
42 meta = {}
42 meta = {}
43 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
43 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
44 data['spc'] = spc
44 data['spc'] = spc
45 data['rti'] = dataOut.getPower()
45 data['rti'] = dataOut.getPower()
46 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
46 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
47 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
47 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
48
48
49 if self.CODE == 'spc_moments':
49 if self.CODE == 'spc_moments':
50 data['moments'] = dataOut.moments
50 data['moments'] = dataOut.moments
51 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
52 if self.CODE == 'gaussian_fit':
51 if self.CODE == 'gaussian_fit':
53 # data['moments'] = dataOut.moments
54 data['gaussfit'] = dataOut.DGauFitParams
52 data['gaussfit'] = dataOut.DGauFitParams
55 # data['spc'] = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
56
53
57 return data, meta
54 return data, meta
58
55
59 def plot(self):
56 def plot(self):
60
57
61 #print(self.xaxis)
62 #exit(1)
63 if self.xaxis == "frequency":
58 if self.xaxis == "frequency":
64 x = self.data.xrange[0]
59 x = self.data.xrange[0]
65 self.xlabel = "Frequency (kHz)"
60 self.xlabel = "Frequency (kHz)"
66 elif self.xaxis == "time":
61 elif self.xaxis == "time":
67 x = self.data.xrange[1]
62 x = self.data.xrange[1]
68 self.xlabel = "Time (ms)"
63 self.xlabel = "Time (ms)"
69 else:
64 else:
70 x = self.data.xrange[2]
65 x = self.data.xrange[2]
71 self.xlabel = "Velocity (m/s)"
66 self.xlabel = "Velocity (m/s)"
72
67
73 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
68 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
74 x = self.data.xrange[2]
69 x = self.data.xrange[2]
75 self.xlabel = "Velocity (m/s)"
70 self.xlabel = "Velocity (m/s)"
76
71
77 self.titles = []
72 self.titles = []
78
73
79 y = self.data.yrange
74 y = self.data.yrange
80 self.y = y
75 self.y = y
81
76
82 data = self.data[-1]
77 data = self.data[-1]
83 z = data['spc']
78 z = data['spc']
84
79
85 self.CODE2 = 'spc_oblique'
80 self.CODE2 = 'spc_oblique'
86
81
87
82
88 for n, ax in enumerate(self.axes):
83 for n, ax in enumerate(self.axes):
89 noise = data['noise'][n]
84 noise = data['noise'][n]
90 if self.CODE == 'spc_moments':
85 if self.CODE == 'spc_moments':
91 mean = data['moments'][n, 1]
86 mean = data['moments'][n, 1]
92 if self.CODE == 'gaussian_fit':
87 if self.CODE == 'gaussian_fit':
93 # mean = data['moments'][n, 1]
94 gau0 = data['gaussfit'][n][2,:,0]
88 gau0 = data['gaussfit'][n][2,:,0]
95 gau1 = data['gaussfit'][n][2,:,1]
89 gau1 = data['gaussfit'][n][2,:,1]
96 if ax.firsttime:
90 if ax.firsttime:
97 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
91 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
98 self.xmin = self.xmin if self.xmin else -self.xmax
92 self.xmin = self.xmin if self.xmin else -self.xmax
99 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
93 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
100 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
94 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
101 #print(numpy.shape(x))
102 ax.plt = ax.pcolormesh(x, y, z[n].T,
95 ax.plt = ax.pcolormesh(x, y, z[n].T,
103 vmin=self.zmin,
96 vmin=self.zmin,
104 vmax=self.zmax,
97 vmax=self.zmax,
105 cmap=plt.get_cmap(self.colormap)
98 cmap=plt.get_cmap(self.colormap)
106 )
99 )
107
100
108 if self.showprofile:
101 if self.showprofile:
109 ax.plt_profile = self.pf_axes[n].plot(
102 ax.plt_profile = self.pf_axes[n].plot(
110 data['rti'][n], y)[0]
103 data['rti'][n], y)[0]
111 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
104 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
112 color="k", linestyle="dashed", lw=1)[0]
105 color="k", linestyle="dashed", lw=1)[0]
113 if self.CODE == 'spc_moments':
106 if self.CODE == 'spc_moments':
114 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
107 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
115 if self.CODE == 'gaussian_fit':
108 if self.CODE == 'gaussian_fit':
116 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
109 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
117 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
110 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
118 else:
111 else:
119 ax.plt.set_array(z[n].T.ravel())
112 ax.plt.set_array(z[n].T.ravel())
120 if self.showprofile:
113 if self.showprofile:
121 ax.plt_profile.set_data(data['rti'][n], y)
114 ax.plt_profile.set_data(data['rti'][n], y)
122 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
115 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
123 if self.CODE == 'spc_moments':
116 if self.CODE == 'spc_moments':
124 ax.plt_mean.set_data(mean, y)
117 ax.plt_mean.set_data(mean, y)
125 if self.CODE == 'gaussian_fit':
118 if self.CODE == 'gaussian_fit':
126 ax.plt_gau0.set_data(gau0, y)
119 ax.plt_gau0.set_data(gau0, y)
127 ax.plt_gau1.set_data(gau1, y)
120 ax.plt_gau1.set_data(gau1, y)
128 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
121 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
129
122
130 class SpectraObliquePlot(Plot):
123 class SpectraObliquePlot(Plot):
131 '''
124 '''
132 Plot for Spectra data
125 Plot for Spectra data
133 '''
126 '''
134
127
135 CODE = 'spc'
128 CODE = 'spc_oblique'
136 colormap = 'jet'
129 colormap = 'jet'
137 plot_type = 'pcolor'
130 plot_type = 'pcolor'
138
131
139 def setup(self):
132 def setup(self):
140 self.xaxis = "oblique"
133 self.xaxis = "oblique"
141 self.nplots = len(self.data.channels)
134 self.nplots = len(self.data.channels)
142 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
135 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
143 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
136 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
144 self.height = 2.6 * self.nrows
137 self.height = 2.6 * self.nrows
145 self.cb_label = 'dB'
138 self.cb_label = 'dB'
146 if self.showprofile:
139 if self.showprofile:
147 self.width = 4 * self.ncols
140 self.width = 4 * self.ncols
148 else:
141 else:
149 self.width = 3.5 * self.ncols
142 self.width = 3.5 * self.ncols
150 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
143 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
151 self.ylabel = 'Range [km]'
144 self.ylabel = 'Range [km]'
152
145
146 def update(self, dataOut):
147
148 data = {}
149 meta = {}
150 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
151 data['spc'] = spc
152 data['rti'] = dataOut.getPower()
153 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
154 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
155
156 data['shift1'] = dataOut.Oblique_params[0][1]
157 data['shift2'] = dataOut.Oblique_params[0][4]
158 data['shift1_error'] = dataOut.Oblique_param_errors[0][1]
159 data['shift2_error'] = dataOut.Oblique_param_errors[0][4]
160
161 return data, meta
162
153 def plot(self):
163 def plot(self):
154
164
155 #print(self.xaxis)
156 #exit(1)
157 if self.xaxis == "frequency":
165 if self.xaxis == "frequency":
158 x = self.data.xrange[0]
166 x = self.data.xrange[0]
159 self.xlabel = "Frequency (kHz)"
167 self.xlabel = "Frequency (kHz)"
160 elif self.xaxis == "time":
168 elif self.xaxis == "time":
161 x = self.data.xrange[1]
169 x = self.data.xrange[1]
162 self.xlabel = "Time (ms)"
170 self.xlabel = "Time (ms)"
163 else:
171 else:
164 x = self.data.xrange[2]
172 x = self.data.xrange[2]
165 self.xlabel = "Velocity (m/s)"
173 self.xlabel = "Velocity (m/s)"
166
174
167 if self.CODE == 'spc_moments':
168 x = self.data.xrange[2]
169 self.xlabel = "Velocity (m/s)"
170
171 self.titles = []
175 self.titles = []
172 #self.xlabel = "Velocidad (m/s)"
173 #self.ylabel = 'Rango (km)'
174
175
176
176 y = self.data.heights
177 y = self.data.yrange
177 self.y = y
178 self.y = y
178 z = self.data['spc']
179 z = self.data['spc']
179
180
180 self.CODE2 = 'spc_oblique'
181
182
183 for n, ax in enumerate(self.axes):
181 for n, ax in enumerate(self.axes):
184 noise = self.data['noise'][n][-1]
182 noise = self.data['noise'][n][-1]
185 if self.CODE == 'spc_moments':
183 shift1 = self.data['shift1']
186 mean = self.data['moments'][n, :, 1, :][-1]
184 shift2 = self.data['shift2']
187 if self.CODE2 == 'spc_oblique':
185 err1 = self.data['shift1_error']
188 shift1 = self.data.shift1
186 err2 = self.data['shift2_error']
189 shift2 = self.data.shift2
190 if ax.firsttime:
187 if ax.firsttime:
191 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
188 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
192 self.xmin = self.xmin if self.xmin else -self.xmax
189 self.xmin = self.xmin if self.xmin else -self.xmax
193 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
190 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
194 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
191 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
195 #print(numpy.shape(x))
196 ax.plt = ax.pcolormesh(x, y, z[n].T,
192 ax.plt = ax.pcolormesh(x, y, z[n].T,
197 vmin=self.zmin,
193 vmin=self.zmin,
198 vmax=self.zmax,
194 vmax=self.zmax,
199 cmap=plt.get_cmap(self.colormap)
195 cmap=plt.get_cmap(self.colormap)
200 )
196 )
201
197
202 if self.showprofile:
198 if self.showprofile:
203 ax.plt_profile = self.pf_axes[n].plot(
199 ax.plt_profile = self.pf_axes[n].plot(
204 self.data['rti'][n][-1], y)[0]
200 self.data['rti'][n][-1], y)[0]
205 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
201 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
206 color="k", linestyle="dashed", lw=1)[0]
202 color="k", linestyle="dashed", lw=1)[0]
207 if self.CODE == 'spc_moments':
203
208 ax.plt_mean = ax.plot(mean, y, color='k')[0]
204 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=0.2, marker='x', linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
209
205 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
210 if self.CODE2 == 'spc_oblique':
211 #ax.plt_shift1 = ax.plot(shift1, y, color='k', marker='x', linestyle='None', markersize=0.5)[0]
212 #ax.plt_shift2 = ax.plot(shift2, y, color='m', marker='x', linestyle='None', markersize=0.5)[0]
213 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)
214 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)
215
216 else:
206 else:
217 self.ploterr1.remove()
207 self.ploterr1.remove()
218 self.ploterr2.remove()
208 self.ploterr2.remove()
219 ax.plt.set_array(z[n].T.ravel())
209 ax.plt.set_array(z[n].T.ravel())
220 if self.showprofile:
210 if self.showprofile:
221 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
211 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
222 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
212 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
223 if self.CODE == 'spc_moments':
213 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
224 ax.plt_mean.set_data(mean, y)
214 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
225 if self.CODE2 == 'spc_oblique':
226 #ax.plt_shift1.set_data(shift1, y)
227 #ax.plt_shift2.set_data(shift2, y)
228 #ax.clf()
229 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)
230 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)
231
215
232 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
216 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
233 #self.titles.append('{}'.format('Velocidad Doppler'))
217
234
218
235 class CrossSpectraPlot(Plot):
219 class CrossSpectraPlot(Plot):
236
220
237 CODE = 'cspc'
221 CODE = 'cspc'
238 colormap = 'jet'
222 colormap = 'jet'
239 plot_type = 'pcolor'
223 plot_type = 'pcolor'
240 zmin_coh = None
224 zmin_coh = None
241 zmax_coh = None
225 zmax_coh = None
242 zmin_phase = None
226 zmin_phase = None
243 zmax_phase = None
227 zmax_phase = None
244
228
245 def setup(self):
229 def setup(self):
246
230
247 self.ncols = 4
231 self.ncols = 4
248 self.nplots = len(self.data.pairs) * 2
232 self.nplots = len(self.data.pairs) * 2
249 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
233 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
250 self.width = 3.1 * self.ncols
234 self.width = 3.1 * self.ncols
251 self.height = 5 * self.nrows
235 self.height = 5 * self.nrows
252 self.ylabel = 'Range [km]'
236 self.ylabel = 'Range [km]'
253 self.showprofile = False
237 self.showprofile = False
254 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
238 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
255
239
256 def update(self, dataOut):
240 def update(self, dataOut):
257
241
258 data = {}
242 data = {}
259 meta = {}
243 meta = {}
260
244
261 spc = dataOut.data_spc
245 spc = dataOut.data_spc
262 cspc = dataOut.data_cspc
246 cspc = dataOut.data_cspc
263 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
247 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
264 meta['pairs'] = dataOut.pairsList
248 meta['pairs'] = dataOut.pairsList
265
249
266 tmp = []
250 tmp = []
267
251
268 for n, pair in enumerate(meta['pairs']):
252 for n, pair in enumerate(meta['pairs']):
269 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
253 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
270 coh = numpy.abs(out)
254 coh = numpy.abs(out)
271 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
255 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
272 tmp.append(coh)
256 tmp.append(coh)
273 tmp.append(phase)
257 tmp.append(phase)
274
258
275 data['cspc'] = numpy.array(tmp)
259 data['cspc'] = numpy.array(tmp)
276
260
277 return data, meta
261 return data, meta
278
262
279 def plot(self):
263 def plot(self):
280
264
281 if self.xaxis == "frequency":
265 if self.xaxis == "frequency":
282 x = self.data.xrange[0]
266 x = self.data.xrange[0]
283 self.xlabel = "Frequency (kHz)"
267 self.xlabel = "Frequency (kHz)"
284 elif self.xaxis == "time":
268 elif self.xaxis == "time":
285 x = self.data.xrange[1]
269 x = self.data.xrange[1]
286 self.xlabel = "Time (ms)"
270 self.xlabel = "Time (ms)"
287 else:
271 else:
288 x = self.data.xrange[2]
272 x = self.data.xrange[2]
289 self.xlabel = "Velocity (m/s)"
273 self.xlabel = "Velocity (m/s)"
290
274
291 self.titles = []
275 self.titles = []
292
276
293 y = self.data.yrange
277 y = self.data.yrange
294 self.y = y
278 self.y = y
295
279
296 data = self.data[-1]
280 data = self.data[-1]
297 cspc = data['cspc']
281 cspc = data['cspc']
298
282
299 for n in range(len(self.data.pairs)):
283 for n in range(len(self.data.pairs)):
300 pair = self.data.pairs[n]
284 pair = self.data.pairs[n]
301 coh = cspc[n*2]
285 coh = cspc[n*2]
302 phase = cspc[n*2+1]
286 phase = cspc[n*2+1]
303 ax = self.axes[2 * n]
287 ax = self.axes[2 * n]
304 if ax.firsttime:
288 if ax.firsttime:
305 ax.plt = ax.pcolormesh(x, y, coh.T,
289 ax.plt = ax.pcolormesh(x, y, coh.T,
306 vmin=0,
290 vmin=0,
307 vmax=1,
291 vmax=1,
308 cmap=plt.get_cmap(self.colormap_coh)
292 cmap=plt.get_cmap(self.colormap_coh)
309 )
293 )
310 else:
294 else:
311 ax.plt.set_array(coh.T.ravel())
295 ax.plt.set_array(coh.T.ravel())
312 self.titles.append(
296 self.titles.append(
313 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
297 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
314
298
315 ax = self.axes[2 * n + 1]
299 ax = self.axes[2 * n + 1]
316 if ax.firsttime:
300 if ax.firsttime:
317 ax.plt = ax.pcolormesh(x, y, phase.T,
301 ax.plt = ax.pcolormesh(x, y, phase.T,
318 vmin=-180,
302 vmin=-180,
319 vmax=180,
303 vmax=180,
320 cmap=plt.get_cmap(self.colormap_phase)
304 cmap=plt.get_cmap(self.colormap_phase)
321 )
305 )
322 else:
306 else:
323 ax.plt.set_array(phase.T.ravel())
307 ax.plt.set_array(phase.T.ravel())
324 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
308 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
325
309
326
310
327 class CrossSpectra4Plot(Plot):
311 class CrossSpectra4Plot(Plot):
328
312
329 CODE = 'cspc'
313 CODE = 'cspc'
330 colormap = 'jet'
314 colormap = 'jet'
331 plot_type = 'pcolor'
315 plot_type = 'pcolor'
332 zmin_coh = None
316 zmin_coh = None
333 zmax_coh = None
317 zmax_coh = None
334 zmin_phase = None
318 zmin_phase = None
335 zmax_phase = None
319 zmax_phase = None
336
320
337 def setup(self):
321 def setup(self):
338
322
339 self.ncols = 4
323 self.ncols = 4
340 self.nrows = len(self.data.pairs)
324 self.nrows = len(self.data.pairs)
341 self.nplots = self.nrows * 4
325 self.nplots = self.nrows * 4
342 self.width = 3.1 * self.ncols
326 self.width = 3.1 * self.ncols
343 self.height = 5 * self.nrows
327 self.height = 5 * self.nrows
344 self.ylabel = 'Range [km]'
328 self.ylabel = 'Range [km]'
345 self.showprofile = False
329 self.showprofile = False
346 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
330 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
347
331
348 def plot(self):
332 def plot(self):
349
333
350 if self.xaxis == "frequency":
334 if self.xaxis == "frequency":
351 x = self.data.xrange[0]
335 x = self.data.xrange[0]
352 self.xlabel = "Frequency (kHz)"
336 self.xlabel = "Frequency (kHz)"
353 elif self.xaxis == "time":
337 elif self.xaxis == "time":
354 x = self.data.xrange[1]
338 x = self.data.xrange[1]
355 self.xlabel = "Time (ms)"
339 self.xlabel = "Time (ms)"
356 else:
340 else:
357 x = self.data.xrange[2]
341 x = self.data.xrange[2]
358 self.xlabel = "Velocity (m/s)"
342 self.xlabel = "Velocity (m/s)"
359
343
360 self.titles = []
344 self.titles = []
361
345
362
346
363 y = self.data.heights
347 y = self.data.heights
364 self.y = y
348 self.y = y
365 nspc = self.data['spc']
349 nspc = self.data['spc']
366 #print(numpy.shape(self.data['spc']))
350 #print(numpy.shape(self.data['spc']))
367 spc = self.data['cspc'][0]
351 spc = self.data['cspc'][0]
368 #print(numpy.shape(nspc))
352 #print(numpy.shape(nspc))
369 #exit()
353 #exit()
370 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
354 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
371 #print(numpy.shape(spc))
355 #print(numpy.shape(spc))
372 #exit()
356 #exit()
373 cspc = self.data['cspc'][1]
357 cspc = self.data['cspc'][1]
374
358
375 #xflip=numpy.flip(x)
359 #xflip=numpy.flip(x)
376 #print(numpy.shape(cspc))
360 #print(numpy.shape(cspc))
377 #exit()
361 #exit()
378
362
379 for n in range(self.nrows):
363 for n in range(self.nrows):
380 noise = self.data['noise'][:,-1]
364 noise = self.data['noise'][:,-1]
381 pair = self.data.pairs[n]
365 pair = self.data.pairs[n]
382 #print(pair)
366 #print(pair)
383 #exit()
367 #exit()
384 ax = self.axes[4 * n]
368 ax = self.axes[4 * n]
385 if ax.firsttime:
369 if ax.firsttime:
386 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
370 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
387 self.xmin = self.xmin if self.xmin else -self.xmax
371 self.xmin = self.xmin if self.xmin else -self.xmax
388 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
372 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
389 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
373 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
390 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
374 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
391 vmin=self.zmin,
375 vmin=self.zmin,
392 vmax=self.zmax,
376 vmax=self.zmax,
393 cmap=plt.get_cmap(self.colormap)
377 cmap=plt.get_cmap(self.colormap)
394 )
378 )
395 else:
379 else:
396 #print(numpy.shape(nspc[pair[0]].T))
380 #print(numpy.shape(nspc[pair[0]].T))
397 #exit()
381 #exit()
398 ax.plt.set_array(nspc[pair[0]].T.ravel())
382 ax.plt.set_array(nspc[pair[0]].T.ravel())
399 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
383 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
400
384
401 ax = self.axes[4 * n + 1]
385 ax = self.axes[4 * n + 1]
402
386
403 if ax.firsttime:
387 if ax.firsttime:
404 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
388 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
405 vmin=self.zmin,
389 vmin=self.zmin,
406 vmax=self.zmax,
390 vmax=self.zmax,
407 cmap=plt.get_cmap(self.colormap)
391 cmap=plt.get_cmap(self.colormap)
408 )
392 )
409 else:
393 else:
410
394
411 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
395 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
412 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
396 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
413
397
414 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
398 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
415 coh = numpy.abs(out)
399 coh = numpy.abs(out)
416 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
400 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
417
401
418 ax = self.axes[4 * n + 2]
402 ax = self.axes[4 * n + 2]
419 if ax.firsttime:
403 if ax.firsttime:
420 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
404 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
421 vmin=0,
405 vmin=0,
422 vmax=1,
406 vmax=1,
423 cmap=plt.get_cmap(self.colormap_coh)
407 cmap=plt.get_cmap(self.colormap_coh)
424 )
408 )
425 else:
409 else:
426 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
410 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
427 self.titles.append(
411 self.titles.append(
428 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
412 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
429
413
430 ax = self.axes[4 * n + 3]
414 ax = self.axes[4 * n + 3]
431 if ax.firsttime:
415 if ax.firsttime:
432 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
416 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
433 vmin=-180,
417 vmin=-180,
434 vmax=180,
418 vmax=180,
435 cmap=plt.get_cmap(self.colormap_phase)
419 cmap=plt.get_cmap(self.colormap_phase)
436 )
420 )
437 else:
421 else:
438 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
422 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
439 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
423 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
440
424
441
425
442 class CrossSpectra2Plot(Plot):
426 class CrossSpectra2Plot(Plot):
443
427
444 CODE = 'cspc'
428 CODE = 'cspc'
445 colormap = 'jet'
429 colormap = 'jet'
446 plot_type = 'pcolor'
430 plot_type = 'pcolor'
447 zmin_coh = None
431 zmin_coh = None
448 zmax_coh = None
432 zmax_coh = None
449 zmin_phase = None
433 zmin_phase = None
450 zmax_phase = None
434 zmax_phase = None
451
435
452 def setup(self):
436 def setup(self):
453
437
454 self.ncols = 1
438 self.ncols = 1
455 self.nrows = len(self.data.pairs)
439 self.nrows = len(self.data.pairs)
456 self.nplots = self.nrows * 1
440 self.nplots = self.nrows * 1
457 self.width = 3.1 * self.ncols
441 self.width = 3.1 * self.ncols
458 self.height = 5 * self.nrows
442 self.height = 5 * self.nrows
459 self.ylabel = 'Range [km]'
443 self.ylabel = 'Range [km]'
460 self.showprofile = False
444 self.showprofile = False
461 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
445 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
462
446
463 def plot(self):
447 def plot(self):
464
448
465 if self.xaxis == "frequency":
449 if self.xaxis == "frequency":
466 x = self.data.xrange[0]
450 x = self.data.xrange[0]
467 self.xlabel = "Frequency (kHz)"
451 self.xlabel = "Frequency (kHz)"
468 elif self.xaxis == "time":
452 elif self.xaxis == "time":
469 x = self.data.xrange[1]
453 x = self.data.xrange[1]
470 self.xlabel = "Time (ms)"
454 self.xlabel = "Time (ms)"
471 else:
455 else:
472 x = self.data.xrange[2]
456 x = self.data.xrange[2]
473 self.xlabel = "Velocity (m/s)"
457 self.xlabel = "Velocity (m/s)"
474
458
475 self.titles = []
459 self.titles = []
476
460
477
461
478 y = self.data.heights
462 y = self.data.heights
479 self.y = y
463 self.y = y
480 #nspc = self.data['spc']
464 #nspc = self.data['spc']
481 #print(numpy.shape(self.data['spc']))
465 #print(numpy.shape(self.data['spc']))
482 #spc = self.data['cspc'][0]
466 #spc = self.data['cspc'][0]
483 #print(numpy.shape(spc))
467 #print(numpy.shape(spc))
484 #exit()
468 #exit()
485 cspc = self.data['cspc'][1]
469 cspc = self.data['cspc'][1]
486 #print(numpy.shape(cspc))
470 #print(numpy.shape(cspc))
487 #exit()
471 #exit()
488
472
489 for n in range(self.nrows):
473 for n in range(self.nrows):
490 noise = self.data['noise'][:,-1]
474 noise = self.data['noise'][:,-1]
491 pair = self.data.pairs[n]
475 pair = self.data.pairs[n]
492 #print(pair) #exit()
476 #print(pair) #exit()
493
477
494
478
495
479
496 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
480 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
497
481
498 #print(out[:,53])
482 #print(out[:,53])
499 #exit()
483 #exit()
500 cross = numpy.abs(out)
484 cross = numpy.abs(out)
501 z = cross/self.data.nFactor
485 z = cross/self.data.nFactor
502 #print("here")
486 #print("here")
503 #print(dataOut.data_spc[0,0,0])
487 #print(dataOut.data_spc[0,0,0])
504 #exit()
488 #exit()
505
489
506 cross = 10*numpy.log10(z)
490 cross = 10*numpy.log10(z)
507 #print(numpy.shape(cross))
491 #print(numpy.shape(cross))
508 #print(cross[0,:])
492 #print(cross[0,:])
509 #print(self.data.nFactor)
493 #print(self.data.nFactor)
510 #exit()
494 #exit()
511 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
495 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
512
496
513 ax = self.axes[1 * n]
497 ax = self.axes[1 * n]
514 if ax.firsttime:
498 if ax.firsttime:
515 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
499 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
516 self.xmin = self.xmin if self.xmin else -self.xmax
500 self.xmin = self.xmin if self.xmin else -self.xmax
517 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
501 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
518 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
502 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
519 ax.plt = ax.pcolormesh(x, y, cross.T,
503 ax.plt = ax.pcolormesh(x, y, cross.T,
520 vmin=self.zmin,
504 vmin=self.zmin,
521 vmax=self.zmax,
505 vmax=self.zmax,
522 cmap=plt.get_cmap(self.colormap)
506 cmap=plt.get_cmap(self.colormap)
523 )
507 )
524 else:
508 else:
525 ax.plt.set_array(cross.T.ravel())
509 ax.plt.set_array(cross.T.ravel())
526 self.titles.append(
510 self.titles.append(
527 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
511 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
528
512
529
513
530 class CrossSpectra3Plot(Plot):
514 class CrossSpectra3Plot(Plot):
531
515
532 CODE = 'cspc'
516 CODE = 'cspc'
533 colormap = 'jet'
517 colormap = 'jet'
534 plot_type = 'pcolor'
518 plot_type = 'pcolor'
535 zmin_coh = None
519 zmin_coh = None
536 zmax_coh = None
520 zmax_coh = None
537 zmin_phase = None
521 zmin_phase = None
538 zmax_phase = None
522 zmax_phase = None
539
523
540 def setup(self):
524 def setup(self):
541
525
542 self.ncols = 3
526 self.ncols = 3
543 self.nrows = len(self.data.pairs)
527 self.nrows = len(self.data.pairs)
544 self.nplots = self.nrows * 3
528 self.nplots = self.nrows * 3
545 self.width = 3.1 * self.ncols
529 self.width = 3.1 * self.ncols
546 self.height = 5 * self.nrows
530 self.height = 5 * self.nrows
547 self.ylabel = 'Range [km]'
531 self.ylabel = 'Range [km]'
548 self.showprofile = False
532 self.showprofile = False
549 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
533 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
550
534
551 def plot(self):
535 def plot(self):
552
536
553 if self.xaxis == "frequency":
537 if self.xaxis == "frequency":
554 x = self.data.xrange[0]
538 x = self.data.xrange[0]
555 self.xlabel = "Frequency (kHz)"
539 self.xlabel = "Frequency (kHz)"
556 elif self.xaxis == "time":
540 elif self.xaxis == "time":
557 x = self.data.xrange[1]
541 x = self.data.xrange[1]
558 self.xlabel = "Time (ms)"
542 self.xlabel = "Time (ms)"
559 else:
543 else:
560 x = self.data.xrange[2]
544 x = self.data.xrange[2]
561 self.xlabel = "Velocity (m/s)"
545 self.xlabel = "Velocity (m/s)"
562
546
563 self.titles = []
547 self.titles = []
564
548
565
549
566 y = self.data.heights
550 y = self.data.heights
567 self.y = y
551 self.y = y
568 #nspc = self.data['spc']
552 #nspc = self.data['spc']
569 #print(numpy.shape(self.data['spc']))
553 #print(numpy.shape(self.data['spc']))
570 #spc = self.data['cspc'][0]
554 #spc = self.data['cspc'][0]
571 #print(numpy.shape(spc))
555 #print(numpy.shape(spc))
572 #exit()
556 #exit()
573 cspc = self.data['cspc'][1]
557 cspc = self.data['cspc'][1]
574 #print(numpy.shape(cspc))
558 #print(numpy.shape(cspc))
575 #exit()
559 #exit()
576
560
577 for n in range(self.nrows):
561 for n in range(self.nrows):
578 noise = self.data['noise'][:,-1]
562 noise = self.data['noise'][:,-1]
579 pair = self.data.pairs[n]
563 pair = self.data.pairs[n]
580 #print(pair) #exit()
564 #print(pair) #exit()
581
565
582
566
583
567
584 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
568 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
585
569
586 #print(out[:,53])
570 #print(out[:,53])
587 #exit()
571 #exit()
588 cross = numpy.abs(out)
572 cross = numpy.abs(out)
589 z = cross/self.data.nFactor
573 z = cross/self.data.nFactor
590 cross = 10*numpy.log10(z)
574 cross = 10*numpy.log10(z)
591
575
592 out_r= out.real/self.data.nFactor
576 out_r= out.real/self.data.nFactor
593 #out_r = 10*numpy.log10(out_r)
577 #out_r = 10*numpy.log10(out_r)
594
578
595 out_i= out.imag/self.data.nFactor
579 out_i= out.imag/self.data.nFactor
596 #out_i = 10*numpy.log10(out_i)
580 #out_i = 10*numpy.log10(out_i)
597 #print(numpy.shape(cross))
581 #print(numpy.shape(cross))
598 #print(cross[0,:])
582 #print(cross[0,:])
599 #print(self.data.nFactor)
583 #print(self.data.nFactor)
600 #exit()
584 #exit()
601 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
585 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
602
586
603 ax = self.axes[3 * n]
587 ax = self.axes[3 * n]
604 if ax.firsttime:
588 if ax.firsttime:
605 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
589 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
606 self.xmin = self.xmin if self.xmin else -self.xmax
590 self.xmin = self.xmin if self.xmin else -self.xmax
607 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
591 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
608 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
592 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
609 ax.plt = ax.pcolormesh(x, y, cross.T,
593 ax.plt = ax.pcolormesh(x, y, cross.T,
610 vmin=self.zmin,
594 vmin=self.zmin,
611 vmax=self.zmax,
595 vmax=self.zmax,
612 cmap=plt.get_cmap(self.colormap)
596 cmap=plt.get_cmap(self.colormap)
613 )
597 )
614 else:
598 else:
615 ax.plt.set_array(cross.T.ravel())
599 ax.plt.set_array(cross.T.ravel())
616 self.titles.append(
600 self.titles.append(
617 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
601 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
618
602
619 ax = self.axes[3 * n + 1]
603 ax = self.axes[3 * n + 1]
620 if ax.firsttime:
604 if ax.firsttime:
621 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
605 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
622 self.xmin = self.xmin if self.xmin else -self.xmax
606 self.xmin = self.xmin if self.xmin else -self.xmax
623 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
607 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
624 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
608 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
625 ax.plt = ax.pcolormesh(x, y, out_r.T,
609 ax.plt = ax.pcolormesh(x, y, out_r.T,
626 vmin=-1.e6,
610 vmin=-1.e6,
627 vmax=0,
611 vmax=0,
628 cmap=plt.get_cmap(self.colormap)
612 cmap=plt.get_cmap(self.colormap)
629 )
613 )
630 else:
614 else:
631 ax.plt.set_array(out_r.T.ravel())
615 ax.plt.set_array(out_r.T.ravel())
632 self.titles.append(
616 self.titles.append(
633 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
617 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
634
618
635 ax = self.axes[3 * n + 2]
619 ax = self.axes[3 * n + 2]
636
620
637
621
638 if ax.firsttime:
622 if ax.firsttime:
639 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
623 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
640 self.xmin = self.xmin if self.xmin else -self.xmax
624 self.xmin = self.xmin if self.xmin else -self.xmax
641 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
625 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
642 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
626 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
643 ax.plt = ax.pcolormesh(x, y, out_i.T,
627 ax.plt = ax.pcolormesh(x, y, out_i.T,
644 vmin=-1.e6,
628 vmin=-1.e6,
645 vmax=1.e6,
629 vmax=1.e6,
646 cmap=plt.get_cmap(self.colormap)
630 cmap=plt.get_cmap(self.colormap)
647 )
631 )
648 else:
632 else:
649 ax.plt.set_array(out_i.T.ravel())
633 ax.plt.set_array(out_i.T.ravel())
650 self.titles.append(
634 self.titles.append(
651 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
635 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
652
636
653 class RTIPlot(Plot):
637 class RTIPlot(Plot):
654 '''
638 '''
655 Plot for RTI data
639 Plot for RTI data
656 '''
640 '''
657
641
658 CODE = 'rti'
642 CODE = 'rti'
659 colormap = 'jet'
643 colormap = 'jet'
660 plot_type = 'pcolorbuffer'
644 plot_type = 'pcolorbuffer'
661
645
662 def setup(self):
646 def setup(self):
663 self.xaxis = 'time'
647 self.xaxis = 'time'
664 self.ncols = 1
648 self.ncols = 1
665 self.nrows = len(self.data.channels)
649 self.nrows = len(self.data.channels)
666 self.nplots = len(self.data.channels)
650 self.nplots = len(self.data.channels)
667 self.ylabel = 'Range [km]'
651 self.ylabel = 'Range [km]'
668 self.xlabel = 'Time'
652 self.xlabel = 'Time'
669 self.cb_label = 'dB'
653 self.cb_label = 'dB'
670 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
654 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
671 self.titles = ['{} Channel {}'.format(
655 self.titles = ['{} Channel {}'.format(
672 self.CODE.upper(), x) for x in range(self.nrows)]
656 self.CODE.upper(), x) for x in range(self.nrows)]
673
657
674 def update(self, dataOut):
658 def update(self, dataOut):
675
659
676 data = {}
660 data = {}
677 meta = {}
661 meta = {}
678 data['rti'] = dataOut.getPower()
662 data['rti'] = dataOut.getPower()
679 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
663 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
680
664
681 return data, meta
665 return data, meta
682
666
683 def plot(self):
667 def plot(self):
684 self.x = self.data.times
668 self.x = self.data.times
685 self.y = self.data.yrange
669 self.y = self.data.yrange
686 self.z = self.data[self.CODE]
670 self.z = self.data[self.CODE]
687
671
688 self.z = numpy.ma.masked_invalid(self.z)
672 self.z = numpy.ma.masked_invalid(self.z)
689
673
690 if self.decimation is None:
674 if self.decimation is None:
691 x, y, z = self.fill_gaps(self.x, self.y, self.z)
675 x, y, z = self.fill_gaps(self.x, self.y, self.z)
692 else:
676 else:
693 x, y, z = self.fill_gaps(*self.decimate())
677 x, y, z = self.fill_gaps(*self.decimate())
694
678
695 for n, ax in enumerate(self.axes):
679 for n, ax in enumerate(self.axes):
696 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
680 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
697 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
681 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
698 if ax.firsttime:
682 if ax.firsttime:
699 ax.plt = ax.pcolormesh(x, y, z[n].T,
683 ax.plt = ax.pcolormesh(x, y, z[n].T,
700 vmin=self.zmin,
684 vmin=self.zmin,
701 vmax=self.zmax,
685 vmax=self.zmax,
702 cmap=plt.get_cmap(self.colormap)
686 cmap=plt.get_cmap(self.colormap)
703 )
687 )
704 if self.showprofile:
688 if self.showprofile:
705 ax.plot_profile = self.pf_axes[n].plot(
689 ax.plot_profile = self.pf_axes[n].plot(
706 self.data['rti'][n][-1], self.y)[0]
690 self.data['rti'][n][-1], self.y)[0]
707 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
691 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
708 color="k", linestyle="dashed", lw=1)[0]
692 color="k", linestyle="dashed", lw=1)[0]
709 else:
693 else:
710 ax.collections.remove(ax.collections[0])
694 ax.collections.remove(ax.collections[0])
711 ax.plt = ax.pcolormesh(x, y, z[n].T,
695 ax.plt = ax.pcolormesh(x, y, z[n].T,
712 vmin=self.zmin,
696 vmin=self.zmin,
713 vmax=self.zmax,
697 vmax=self.zmax,
714 cmap=plt.get_cmap(self.colormap)
698 cmap=plt.get_cmap(self.colormap)
715 )
699 )
716 if self.showprofile:
700 if self.showprofile:
717 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
701 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
718 ax.plot_noise.set_data(numpy.repeat(
702 ax.plot_noise.set_data(numpy.repeat(
719 self.data['noise'][n][-1], len(self.y)), self.y)
703 self.data['noise'][n][-1], len(self.y)), self.y)
720
704
721
705
722 class SpectrogramPlot(Plot):
706 class SpectrogramPlot(Plot):
723 '''
707 '''
724 Plot for Spectrogram data
708 Plot for Spectrogram data
725 '''
709 '''
726
710
727 CODE = 'spectrogram'
711 CODE = 'spectrogram'
728 colormap = 'binary'
712 colormap = 'binary'
729 plot_type = 'pcolorbuffer'
713 plot_type = 'pcolorbuffer'
730
714
731 def setup(self):
715 def setup(self):
732 self.xaxis = 'time'
716 self.xaxis = 'time'
733 self.ncols = 1
717 self.ncols = 1
734 self.nrows = len(self.data.channels)
718 self.nrows = len(self.data.channels)
735 self.nplots = len(self.data.channels)
719 self.nplots = len(self.data.channels)
736 #print(self.dataOut.heightList)
737 #self.ylabel = 'Range [km]'
738 self.xlabel = 'Time'
720 self.xlabel = 'Time'
739 self.cb_label = 'dB'
721 self.cb_label = 'dB'
740 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
722 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
741 self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
723 self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
742 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)]
724 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)]
743
725
744 def plot(self):
726 def plot(self):
727
745 self.x = self.data.times
728 self.x = self.data.times
746 #self.y = self.data.heights
747 self.z = self.data[self.CODE]
729 self.z = self.data[self.CODE]
748 self.y = self.data.xrange[0]
730 self.y = self.data.xrange[0]
749 #import time
731
750 #print(time.ctime(self.x))
751
752 '''
753 print(numpy.shape(self.x))
754 print(numpy.shape(self.y))
755 print(numpy.shape(self.z))
756 '''
757 self.ylabel = "Frequency (kHz)"
732 self.ylabel = "Frequency (kHz)"
758
733
759 self.z = numpy.ma.masked_invalid(self.z)
734 self.z = numpy.ma.masked_invalid(self.z)
760
735
761 if self.decimation is None:
736 if self.decimation is None:
762 x, y, z = self.fill_gaps(self.x, self.y, self.z)
737 x, y, z = self.fill_gaps(self.x, self.y, self.z)
763 else:
738 else:
764 x, y, z = self.fill_gaps(*self.decimate())
739 x, y, z = self.fill_gaps(*self.decimate())
765
740
766 for n, ax in enumerate(self.axes):
741 for n, ax in enumerate(self.axes):
767 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
742 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
768 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
743 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
769 data = self.data[-1]
744 data = self.data[-1]
770 if ax.firsttime:
745 if ax.firsttime:
771 ax.plt = ax.pcolormesh(x, y, z[n].T,
746 ax.plt = ax.pcolormesh(x, y, z[n].T,
772 vmin=self.zmin,
747 vmin=self.zmin,
773 vmax=self.zmax,
748 vmax=self.zmax,
774 cmap=plt.get_cmap(self.colormap)
749 cmap=plt.get_cmap(self.colormap)
775 )
750 )
776 if self.showprofile:
751 if self.showprofile:
777 ax.plot_profile = self.pf_axes[n].plot(
752 ax.plot_profile = self.pf_axes[n].plot(
778 data['rti'][n], self.y)[0]
753 data['rti'][n], self.y)[0]
779 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
754 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
780 color="k", linestyle="dashed", lw=1)[0]
755 color="k", linestyle="dashed", lw=1)[0]
781 else:
756 else:
782 ax.collections.remove(ax.collections[0])
757 ax.collections.remove(ax.collections[0])
783 ax.plt = ax.pcolormesh(x, y, z[n].T,
758 ax.plt = ax.pcolormesh(x, y, z[n].T,
784 vmin=self.zmin,
759 vmin=self.zmin,
785 vmax=self.zmax,
760 vmax=self.zmax,
786 cmap=plt.get_cmap(self.colormap)
761 cmap=plt.get_cmap(self.colormap)
787 )
762 )
788 if self.showprofile:
763 if self.showprofile:
789 ax.plot_profile.set_data(data['rti'][n], self.y)
764 ax.plot_profile.set_data(data['rti'][n], self.y)
790 ax.plot_noise.set_data(numpy.repeat(
765 ax.plot_noise.set_data(numpy.repeat(
791 data['noise'][n], len(self.y)), self.y)
766 data['noise'][n], len(self.y)), self.y)
792
767
793
768
794 class CoherencePlot(RTIPlot):
769 class CoherencePlot(RTIPlot):
795 '''
770 '''
796 Plot for Coherence data
771 Plot for Coherence data
797 '''
772 '''
798
773
799 CODE = 'coh'
774 CODE = 'coh'
800
775
801 def setup(self):
776 def setup(self):
802 self.xaxis = 'time'
777 self.xaxis = 'time'
803 self.ncols = 1
778 self.ncols = 1
804 self.nrows = len(self.data.pairs)
779 self.nrows = len(self.data.pairs)
805 self.nplots = len(self.data.pairs)
780 self.nplots = len(self.data.pairs)
806 self.ylabel = 'Range [km]'
781 self.ylabel = 'Range [km]'
807 self.xlabel = 'Time'
782 self.xlabel = 'Time'
808 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
783 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
809 if self.CODE == 'coh':
784 if self.CODE == 'coh':
810 self.cb_label = ''
785 self.cb_label = ''
811 self.titles = [
786 self.titles = [
812 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
787 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
813 else:
788 else:
814 self.cb_label = 'Degrees'
789 self.cb_label = 'Degrees'
815 self.titles = [
790 self.titles = [
816 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
791 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
817
792
818 def update(self, dataOut):
793 def update(self, dataOut):
819
794
820 data = {}
795 data = {}
821 meta = {}
796 meta = {}
822 data['coh'] = dataOut.getCoherence()
797 data['coh'] = dataOut.getCoherence()
823 meta['pairs'] = dataOut.pairsList
798 meta['pairs'] = dataOut.pairsList
824
799
825 return data, meta
800 return data, meta
826
801
827 class PhasePlot(CoherencePlot):
802 class PhasePlot(CoherencePlot):
828 '''
803 '''
829 Plot for Phase map data
804 Plot for Phase map data
830 '''
805 '''
831
806
832 CODE = 'phase'
807 CODE = 'phase'
833 colormap = 'seismic'
808 colormap = 'seismic'
834
809
835 def update(self, dataOut):
810 def update(self, dataOut):
836
811
837 data = {}
812 data = {}
838 meta = {}
813 meta = {}
839 data['phase'] = dataOut.getCoherence(phase=True)
814 data['phase'] = dataOut.getCoherence(phase=True)
840 meta['pairs'] = dataOut.pairsList
815 meta['pairs'] = dataOut.pairsList
841
816
842 return data, meta
817 return data, meta
843
818
844 class NoisePlot(Plot):
819 class NoisePlot(Plot):
845 '''
820 '''
846 Plot for noise
821 Plot for noise
847 '''
822 '''
848
823
849 CODE = 'noise'
824 CODE = 'noise'
850 plot_type = 'scatterbuffer'
825 plot_type = 'scatterbuffer'
851
826
852 def setup(self):
827 def setup(self):
853 self.xaxis = 'time'
828 self.xaxis = 'time'
854 self.ncols = 1
829 self.ncols = 1
855 self.nrows = 1
830 self.nrows = 1
856 self.nplots = 1
831 self.nplots = 1
857 self.ylabel = 'Intensity [dB]'
832 self.ylabel = 'Intensity [dB]'
858 self.xlabel = 'Time'
833 self.xlabel = 'Time'
859 self.titles = ['Noise']
834 self.titles = ['Noise']
860 self.colorbar = False
835 self.colorbar = False
861 self.plots_adjust.update({'right': 0.85 })
836 self.plots_adjust.update({'right': 0.85 })
862
837
863 def update(self, dataOut):
838 def update(self, dataOut):
864
839
865 data = {}
840 data = {}
866 meta = {}
841 meta = {}
867 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
842 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
868 meta['yrange'] = numpy.array([])
843 meta['yrange'] = numpy.array([])
869
844
870 return data, meta
845 return data, meta
871
846
872 def plot(self):
847 def plot(self):
873
848
874 x = self.data.times
849 x = self.data.times
875 xmin = self.data.min_time
850 xmin = self.data.min_time
876 xmax = xmin + self.xrange * 60 * 60
851 xmax = xmin + self.xrange * 60 * 60
877 Y = self.data['noise']
852 Y = self.data['noise']
878
853
879 if self.axes[0].firsttime:
854 if self.axes[0].firsttime:
880 self.ymin = numpy.nanmin(Y) - 5
855 self.ymin = numpy.nanmin(Y) - 5
881 self.ymax = numpy.nanmax(Y) + 5
856 self.ymax = numpy.nanmax(Y) + 5
882 for ch in self.data.channels:
857 for ch in self.data.channels:
883 y = Y[ch]
858 y = Y[ch]
884 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
859 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
885 plt.legend(bbox_to_anchor=(1.18, 1.0))
860 plt.legend(bbox_to_anchor=(1.18, 1.0))
886 else:
861 else:
887 for ch in self.data.channels:
862 for ch in self.data.channels:
888 y = Y[ch]
863 y = Y[ch]
889 self.axes[0].lines[ch].set_data(x, y)
864 self.axes[0].lines[ch].set_data(x, y)
890
865
891 self.ymin = numpy.nanmin(Y) - 5
866 self.ymin = numpy.nanmin(Y) - 5
892 self.ymax = numpy.nanmax(Y) + 10
867 self.ymax = numpy.nanmax(Y) + 10
893
868
894
869
895 class PowerProfilePlot(Plot):
870 class PowerProfilePlot(Plot):
896
871
897 CODE = 'pow_profile'
872 CODE = 'pow_profile'
898 plot_type = 'scatter'
873 plot_type = 'scatter'
899
874
900 def setup(self):
875 def setup(self):
901
876
902 self.ncols = 1
877 self.ncols = 1
903 self.nrows = 1
878 self.nrows = 1
904 self.nplots = 1
879 self.nplots = 1
905 self.height = 4
880 self.height = 4
906 self.width = 3
881 self.width = 3
907 self.ylabel = 'Range [km]'
882 self.ylabel = 'Range [km]'
908 self.xlabel = 'Intensity [dB]'
883 self.xlabel = 'Intensity [dB]'
909 self.titles = ['Power Profile']
884 self.titles = ['Power Profile']
910 self.colorbar = False
885 self.colorbar = False
911
886
912 def update(self, dataOut):
887 def update(self, dataOut):
913
888
914 data = {}
889 data = {}
915 meta = {}
890 meta = {}
916 data[self.CODE] = dataOut.getPower()
891 data[self.CODE] = dataOut.getPower()
917
892
918 return data, meta
893 return data, meta
919
894
920 def plot(self):
895 def plot(self):
921
896
922 y = self.data.yrange
897 y = self.data.yrange
923 self.y = y
898 self.y = y
924
899
925 x = self.data[-1][self.CODE]
900 x = self.data[-1][self.CODE]
926
901
927 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
902 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
928 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
903 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
929
904
930 if self.axes[0].firsttime:
905 if self.axes[0].firsttime:
931 for ch in self.data.channels:
906 for ch in self.data.channels:
932 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
907 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
933 plt.legend()
908 plt.legend()
934 else:
909 else:
935 for ch in self.data.channels:
910 for ch in self.data.channels:
936 self.axes[0].lines[ch].set_data(x[ch], y)
911 self.axes[0].lines[ch].set_data(x[ch], y)
937
912
938
913
939 class SpectraCutPlot(Plot):
914 class SpectraCutPlot(Plot):
940
915
941 CODE = 'spc_cut'
916 CODE = 'spc_cut'
942 plot_type = 'scatter'
917 plot_type = 'scatter'
943 buffering = False
918 buffering = False
944
919
945 def setup(self):
920 def setup(self):
946
921
947 self.nplots = len(self.data.channels)
922 self.nplots = len(self.data.channels)
948 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
923 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
949 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
924 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
950 self.width = 3.4 * self.ncols + 1.5
925 self.width = 3.4 * self.ncols + 1.5
951 self.height = 3 * self.nrows
926 self.height = 3 * self.nrows
952 self.ylabel = 'Power [dB]'
927 self.ylabel = 'Power [dB]'
953 self.colorbar = False
928 self.colorbar = False
954 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
929 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
955
930
956 def update(self, dataOut):
931 def update(self, dataOut):
957
932
958 data = {}
933 data = {}
959 meta = {}
934 meta = {}
960 spc = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
935 spc = 10*numpy.log10(dataOut.data_pre[0]/dataOut.normFactor)
961 data['spc'] = spc
936 data['spc'] = spc
962 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
937 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
963 if self.CODE == 'cut_gaussian_fit':
938 if self.CODE == 'cut_gaussian_fit':
964 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
939 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
965 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
940 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
966 return data, meta
941 return data, meta
967
942
968 def plot(self):
943 def plot(self):
969 if self.xaxis == "frequency":
944 if self.xaxis == "frequency":
970 x = self.data.xrange[0][1:]
945 x = self.data.xrange[0][1:]
971 self.xlabel = "Frequency (kHz)"
946 self.xlabel = "Frequency (kHz)"
972 elif self.xaxis == "time":
947 elif self.xaxis == "time":
973 x = self.data.xrange[1]
948 x = self.data.xrange[1]
974 self.xlabel = "Time (ms)"
949 self.xlabel = "Time (ms)"
975 else:
950 else:
976 x = self.data.xrange[2][:-1]
951 x = self.data.xrange[2][:-1]
977 self.xlabel = "Velocity (m/s)"
952 self.xlabel = "Velocity (m/s)"
978
953
979 if self.CODE == 'cut_gaussian_fit':
954 if self.CODE == 'cut_gaussian_fit':
980 x = self.data.xrange[2][:-1]
955 x = self.data.xrange[2][:-1]
981 self.xlabel = "Velocity (m/s)"
956 self.xlabel = "Velocity (m/s)"
982
957
983 self.titles = []
958 self.titles = []
984
959
985 y = self.data.yrange
960 y = self.data.yrange
986 data = self.data[-1]
961 data = self.data[-1]
987 z = data['spc']
962 z = data['spc']
988
963
989 if self.height_index:
964 if self.height_index:
990 index = numpy.array(self.height_index)
965 index = numpy.array(self.height_index)
991 else:
966 else:
992 index = numpy.arange(0, len(y), int((len(y))/9))
967 index = numpy.arange(0, len(y), int((len(y))/9))
993
968
994 for n, ax in enumerate(self.axes):
969 for n, ax in enumerate(self.axes):
995 if self.CODE == 'cut_gaussian_fit':
970 if self.CODE == 'cut_gaussian_fit':
996 gau0 = data['gauss_fit0']
971 gau0 = data['gauss_fit0']
997 gau1 = data['gauss_fit1']
972 gau1 = data['gauss_fit1']
998 if ax.firsttime:
973 if ax.firsttime:
999 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
974 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1000 self.xmin = self.xmin if self.xmin else -self.xmax
975 self.xmin = self.xmin if self.xmin else -self.xmax
1001 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
976 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
1002 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
977 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
1003 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
978 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
1004 if self.CODE == 'cut_gaussian_fit':
979 if self.CODE == 'cut_gaussian_fit':
1005 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
980 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
1006 for i, line in enumerate(ax.plt_gau0):
981 for i, line in enumerate(ax.plt_gau0):
1007 line.set_color(ax.plt[i].get_color())
982 line.set_color(ax.plt[i].get_color())
1008 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
983 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
1009 for i, line in enumerate(ax.plt_gau1):
984 for i, line in enumerate(ax.plt_gau1):
1010 line.set_color(ax.plt[i].get_color())
985 line.set_color(ax.plt[i].get_color())
1011 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
986 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
1012 self.figures[0].legend(ax.plt, labels, loc='center right')
987 self.figures[0].legend(ax.plt, labels, loc='center right')
1013 else:
988 else:
1014 for i, line in enumerate(ax.plt):
989 for i, line in enumerate(ax.plt):
1015 line.set_data(x, z[n, :, index[i]].T)
990 line.set_data(x, z[n, :, index[i]].T)
1016 for i, line in enumerate(ax.plt_gau0):
991 for i, line in enumerate(ax.plt_gau0):
1017 line.set_data(x, gau0[n, :, index[i]].T)
992 line.set_data(x, gau0[n, :, index[i]].T)
1018 line.set_color(ax.plt[i].get_color())
993 line.set_color(ax.plt[i].get_color())
1019 for i, line in enumerate(ax.plt_gau1):
994 for i, line in enumerate(ax.plt_gau1):
1020 line.set_data(x, gau1[n, :, index[i]].T)
995 line.set_data(x, gau1[n, :, index[i]].T)
1021 line.set_color(ax.plt[i].get_color())
996 line.set_color(ax.plt[i].get_color())
1022 self.titles.append('CH {}'.format(n))
997 self.titles.append('CH {}'.format(n))
1023
998
1024
999
1025 class BeaconPhase(Plot):
1000 class BeaconPhase(Plot):
1026
1001
1027 __isConfig = None
1002 __isConfig = None
1028 __nsubplots = None
1003 __nsubplots = None
1029
1004
1030 PREFIX = 'beacon_phase'
1005 PREFIX = 'beacon_phase'
1031
1006
1032 def __init__(self):
1007 def __init__(self):
1033 Plot.__init__(self)
1008 Plot.__init__(self)
1034 self.timerange = 24*60*60
1009 self.timerange = 24*60*60
1035 self.isConfig = False
1010 self.isConfig = False
1036 self.__nsubplots = 1
1011 self.__nsubplots = 1
1037 self.counter_imagwr = 0
1012 self.counter_imagwr = 0
1038 self.WIDTH = 800
1013 self.WIDTH = 800
1039 self.HEIGHT = 400
1014 self.HEIGHT = 400
1040 self.WIDTHPROF = 120
1015 self.WIDTHPROF = 120
1041 self.HEIGHTPROF = 0
1016 self.HEIGHTPROF = 0
1042 self.xdata = None
1017 self.xdata = None
1043 self.ydata = None
1018 self.ydata = None
1044
1019
1045 self.PLOT_CODE = BEACON_CODE
1020 self.PLOT_CODE = BEACON_CODE
1046
1021
1047 self.FTP_WEI = None
1022 self.FTP_WEI = None
1048 self.EXP_CODE = None
1023 self.EXP_CODE = None
1049 self.SUB_EXP_CODE = None
1024 self.SUB_EXP_CODE = None
1050 self.PLOT_POS = None
1025 self.PLOT_POS = None
1051
1026
1052 self.filename_phase = None
1027 self.filename_phase = None
1053
1028
1054 self.figfile = None
1029 self.figfile = None
1055
1030
1056 self.xmin = None
1031 self.xmin = None
1057 self.xmax = None
1032 self.xmax = None
1058
1033
1059 def getSubplots(self):
1034 def getSubplots(self):
1060
1035
1061 ncol = 1
1036 ncol = 1
1062 nrow = 1
1037 nrow = 1
1063
1038
1064 return nrow, ncol
1039 return nrow, ncol
1065
1040
1066 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1041 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1067
1042
1068 self.__showprofile = showprofile
1043 self.__showprofile = showprofile
1069 self.nplots = nplots
1044 self.nplots = nplots
1070
1045
1071 ncolspan = 7
1046 ncolspan = 7
1072 colspan = 6
1047 colspan = 6
1073 self.__nsubplots = 2
1048 self.__nsubplots = 2
1074
1049
1075 self.createFigure(id = id,
1050 self.createFigure(id = id,
1076 wintitle = wintitle,
1051 wintitle = wintitle,
1077 widthplot = self.WIDTH+self.WIDTHPROF,
1052 widthplot = self.WIDTH+self.WIDTHPROF,
1078 heightplot = self.HEIGHT+self.HEIGHTPROF,
1053 heightplot = self.HEIGHT+self.HEIGHTPROF,
1079 show=show)
1054 show=show)
1080
1055
1081 nrow, ncol = self.getSubplots()
1056 nrow, ncol = self.getSubplots()
1082
1057
1083 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1058 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1084
1059
1085 def save_phase(self, filename_phase):
1060 def save_phase(self, filename_phase):
1086 f = open(filename_phase,'w+')
1061 f = open(filename_phase,'w+')
1087 f.write('\n\n')
1062 f.write('\n\n')
1088 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1063 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1089 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1064 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1090 f.close()
1065 f.close()
1091
1066
1092 def save_data(self, filename_phase, data, data_datetime):
1067 def save_data(self, filename_phase, data, data_datetime):
1093 f=open(filename_phase,'a')
1068 f=open(filename_phase,'a')
1094 timetuple_data = data_datetime.timetuple()
1069 timetuple_data = data_datetime.timetuple()
1095 day = str(timetuple_data.tm_mday)
1070 day = str(timetuple_data.tm_mday)
1096 month = str(timetuple_data.tm_mon)
1071 month = str(timetuple_data.tm_mon)
1097 year = str(timetuple_data.tm_year)
1072 year = str(timetuple_data.tm_year)
1098 hour = str(timetuple_data.tm_hour)
1073 hour = str(timetuple_data.tm_hour)
1099 minute = str(timetuple_data.tm_min)
1074 minute = str(timetuple_data.tm_min)
1100 second = str(timetuple_data.tm_sec)
1075 second = str(timetuple_data.tm_sec)
1101 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1076 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1102 f.close()
1077 f.close()
1103
1078
1104 def plot(self):
1079 def plot(self):
1105 log.warning('TODO: Not yet implemented...')
1080 log.warning('TODO: Not yet implemented...')
1106
1081
1107 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1082 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1108 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1083 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1109 timerange=None,
1084 timerange=None,
1110 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1085 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1111 server=None, folder=None, username=None, password=None,
1086 server=None, folder=None, username=None, password=None,
1112 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1087 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1113
1088
1114 if dataOut.flagNoData:
1089 if dataOut.flagNoData:
1115 return dataOut
1090 return dataOut
1116
1091
1117 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1092 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1118 return
1093 return
1119
1094
1120 if pairsList == None:
1095 if pairsList == None:
1121 pairsIndexList = dataOut.pairsIndexList[:10]
1096 pairsIndexList = dataOut.pairsIndexList[:10]
1122 else:
1097 else:
1123 pairsIndexList = []
1098 pairsIndexList = []
1124 for pair in pairsList:
1099 for pair in pairsList:
1125 if pair not in dataOut.pairsList:
1100 if pair not in dataOut.pairsList:
1126 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1101 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1127 pairsIndexList.append(dataOut.pairsList.index(pair))
1102 pairsIndexList.append(dataOut.pairsList.index(pair))
1128
1103
1129 if pairsIndexList == []:
1104 if pairsIndexList == []:
1130 return
1105 return
1131
1106
1132 # if len(pairsIndexList) > 4:
1107 # if len(pairsIndexList) > 4:
1133 # pairsIndexList = pairsIndexList[0:4]
1108 # pairsIndexList = pairsIndexList[0:4]
1134
1109
1135 hmin_index = None
1110 hmin_index = None
1136 hmax_index = None
1111 hmax_index = None
1137
1112
1138 if hmin != None and hmax != None:
1113 if hmin != None and hmax != None:
1139 indexes = numpy.arange(dataOut.nHeights)
1114 indexes = numpy.arange(dataOut.nHeights)
1140 hmin_list = indexes[dataOut.heightList >= hmin]
1115 hmin_list = indexes[dataOut.heightList >= hmin]
1141 hmax_list = indexes[dataOut.heightList <= hmax]
1116 hmax_list = indexes[dataOut.heightList <= hmax]
1142
1117
1143 if hmin_list.any():
1118 if hmin_list.any():
1144 hmin_index = hmin_list[0]
1119 hmin_index = hmin_list[0]
1145
1120
1146 if hmax_list.any():
1121 if hmax_list.any():
1147 hmax_index = hmax_list[-1]+1
1122 hmax_index = hmax_list[-1]+1
1148
1123
1149 x = dataOut.getTimeRange()
1124 x = dataOut.getTimeRange()
1150
1125
1151 thisDatetime = dataOut.datatime
1126 thisDatetime = dataOut.datatime
1152
1127
1153 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1128 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1154 xlabel = "Local Time"
1129 xlabel = "Local Time"
1155 ylabel = "Phase (degrees)"
1130 ylabel = "Phase (degrees)"
1156
1131
1157 update_figfile = False
1132 update_figfile = False
1158
1133
1159 nplots = len(pairsIndexList)
1134 nplots = len(pairsIndexList)
1160 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1135 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1161 phase_beacon = numpy.zeros(len(pairsIndexList))
1136 phase_beacon = numpy.zeros(len(pairsIndexList))
1162 for i in range(nplots):
1137 for i in range(nplots):
1163 pair = dataOut.pairsList[pairsIndexList[i]]
1138 pair = dataOut.pairsList[pairsIndexList[i]]
1164 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1139 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1165 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1140 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1166 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1141 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1167 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1142 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1168 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1143 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1169
1144
1170 if dataOut.beacon_heiIndexList:
1145 if dataOut.beacon_heiIndexList:
1171 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1146 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1172 else:
1147 else:
1173 phase_beacon[i] = numpy.average(phase)
1148 phase_beacon[i] = numpy.average(phase)
1174
1149
1175 if not self.isConfig:
1150 if not self.isConfig:
1176
1151
1177 nplots = len(pairsIndexList)
1152 nplots = len(pairsIndexList)
1178
1153
1179 self.setup(id=id,
1154 self.setup(id=id,
1180 nplots=nplots,
1155 nplots=nplots,
1181 wintitle=wintitle,
1156 wintitle=wintitle,
1182 showprofile=showprofile,
1157 showprofile=showprofile,
1183 show=show)
1158 show=show)
1184
1159
1185 if timerange != None:
1160 if timerange != None:
1186 self.timerange = timerange
1161 self.timerange = timerange
1187
1162
1188 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1163 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1189
1164
1190 if ymin == None: ymin = 0
1165 if ymin == None: ymin = 0
1191 if ymax == None: ymax = 360
1166 if ymax == None: ymax = 360
1192
1167
1193 self.FTP_WEI = ftp_wei
1168 self.FTP_WEI = ftp_wei
1194 self.EXP_CODE = exp_code
1169 self.EXP_CODE = exp_code
1195 self.SUB_EXP_CODE = sub_exp_code
1170 self.SUB_EXP_CODE = sub_exp_code
1196 self.PLOT_POS = plot_pos
1171 self.PLOT_POS = plot_pos
1197
1172
1198 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1173 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1199 self.isConfig = True
1174 self.isConfig = True
1200 self.figfile = figfile
1175 self.figfile = figfile
1201 self.xdata = numpy.array([])
1176 self.xdata = numpy.array([])
1202 self.ydata = numpy.array([])
1177 self.ydata = numpy.array([])
1203
1178
1204 update_figfile = True
1179 update_figfile = True
1205
1180
1206 #open file beacon phase
1181 #open file beacon phase
1207 path = '%s%03d' %(self.PREFIX, self.id)
1182 path = '%s%03d' %(self.PREFIX, self.id)
1208 beacon_file = os.path.join(path,'%s.txt'%self.name)
1183 beacon_file = os.path.join(path,'%s.txt'%self.name)
1209 self.filename_phase = os.path.join(figpath,beacon_file)
1184 self.filename_phase = os.path.join(figpath,beacon_file)
1210 #self.save_phase(self.filename_phase)
1185 #self.save_phase(self.filename_phase)
1211
1186
1212
1187
1213 #store data beacon phase
1188 #store data beacon phase
1214 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1189 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1215
1190
1216 self.setWinTitle(title)
1191 self.setWinTitle(title)
1217
1192
1218
1193
1219 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1194 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1220
1195
1221 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1196 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1222
1197
1223 axes = self.axesList[0]
1198 axes = self.axesList[0]
1224
1199
1225 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1200 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1226
1201
1227 if len(self.ydata)==0:
1202 if len(self.ydata)==0:
1228 self.ydata = phase_beacon.reshape(-1,1)
1203 self.ydata = phase_beacon.reshape(-1,1)
1229 else:
1204 else:
1230 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1205 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1231
1206
1232
1207
1233 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1208 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1234 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1235 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1210 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1236 XAxisAsTime=True, grid='both'
1211 XAxisAsTime=True, grid='both'
1237 )
1212 )
1238
1213
1239 self.draw()
1214 self.draw()
1240
1215
1241 if dataOut.ltctime >= self.xmax:
1216 if dataOut.ltctime >= self.xmax:
1242 self.counter_imagwr = wr_period
1217 self.counter_imagwr = wr_period
1243 self.isConfig = False
1218 self.isConfig = False
1244 update_figfile = True
1219 update_figfile = True
1245
1220
1246 self.save(figpath=figpath,
1221 self.save(figpath=figpath,
1247 figfile=figfile,
1222 figfile=figfile,
1248 save=save,
1223 save=save,
1249 ftp=ftp,
1224 ftp=ftp,
1250 wr_period=wr_period,
1225 wr_period=wr_period,
1251 thisDatetime=thisDatetime,
1226 thisDatetime=thisDatetime,
1252 update_figfile=update_figfile)
1227 update_figfile=update_figfile)
1253
1228
1254 return dataOut
1229 return dataOut
@@ -1,1156 +1,1126
1
1
2 import os
2 import os
3 import time
4 import math
3 import datetime
5 import datetime
4 import numpy
6 import numpy
5 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
7 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG
6
8
7 from .jroplot_spectra import RTIPlot, NoisePlot
9 from .jroplot_spectra import RTIPlot, NoisePlot
8
10
9 from schainpy.utils import log
11 from schainpy.utils import log
10 from .plotting_codes import *
12 from .plotting_codes import *
11
13
12 from schainpy.model.graphics.jroplot_base import Plot, plt
14 from schainpy.model.graphics.jroplot_base import Plot, plt
13
15
14 import matplotlib.pyplot as plt
16 import matplotlib.pyplot as plt
15 import matplotlib.colors as colors
17 import matplotlib.colors as colors
16
17 import time
18 import math
19
20
21 from matplotlib.ticker import MultipleLocator
18 from matplotlib.ticker import MultipleLocator
22
19
23
20
24
25 class RTIDPPlot(RTIPlot):
21 class RTIDPPlot(RTIPlot):
26
22
27 '''
23 '''Plot for RTI Double Pulse Experiment
28 Plot for RTI Double Pulse Experiment
29 '''
24 '''
30
25
31 CODE = 'RTIDP'
26 CODE = 'RTIDP'
32 colormap = 'jro'
27 colormap = 'jro'
33 plot_name = 'RTI'
28 plot_name = 'RTI'
34
29
35 #cb_label = 'Ne Electron Density (1/cm3)'
36
37 def setup(self):
30 def setup(self):
38 self.xaxis = 'time'
31 self.xaxis = 'time'
39 self.ncols = 1
32 self.ncols = 1
40 self.nrows = 3
33 self.nrows = 3
41 self.nplots = self.nrows
34 self.nplots = self.nrows
42 #self.height=10
35 #self.height=10
43 if self.showSNR:
36 if self.showSNR:
44 self.nrows += 1
37 self.nrows += 1
45 self.nplots += 1
38 self.nplots += 1
46
39
47 self.ylabel = 'Height [km]'
40 self.ylabel = 'Height [km]'
48 self.xlabel = 'Time (LT)'
41 self.xlabel = 'Time (LT)'
49
42
50 self.cb_label = 'Intensity (dB)'
43 self.cb_label = 'Intensity (dB)'
51
44
52
53 #self.cb_label = cb_label
54
55 self.titles = ['{} Channel {}'.format(
45 self.titles = ['{} Channel {}'.format(
56 self.plot_name.upper(), '0x1'),'{} Channel {}'.format(
46 self.plot_name.upper(), '0x1'),'{} Channel {}'.format(
57 self.plot_name.upper(), '0'),'{} Channel {}'.format(
47 self.plot_name.upper(), '0'),'{} Channel {}'.format(
58 self.plot_name.upper(), '1')]
48 self.plot_name.upper(), '1')]
59
49
50 def update(self, dataOut):
60
51
61 def plot(self):
52 data = {}
62
53 meta = {}
63 self.data.normalize_heights()
54 data[self.CODE] = dataOut.data_for_RTI_DP
64 self.x = self.data.times
55 data['NRANGE'] = dataOut.NDP
65 self.y = self.data.heights[0:self.data.NDP]
66
56
67 if self.showSNR:
57 return data, meta
68 self.z = numpy.concatenate(
69 (self.data[self.CODE], self.data['snr'])
70 )
71 else:
72
58
73 self.z = self.data[self.CODE]
59 def plot(self):
74 #print(numpy.max(self.z[0,0:]))
75
60
61 self.x = self.data.times
62 self.y = self.data.yrange[0: self.data['NRANGE']]
63 self.z = self.data[self.CODE]
76 self.z = numpy.ma.masked_invalid(self.z)
64 self.z = numpy.ma.masked_invalid(self.z)
77
65
78 if self.decimation is None:
66 if self.decimation is None:
79 x, y, z = self.fill_gaps(self.x, self.y, self.z)
67 x, y, z = self.fill_gaps(self.x, self.y, self.z)
80 else:
68 else:
81 x, y, z = self.fill_gaps(*self.decimate())
69 x, y, z = self.fill_gaps(*self.decimate())
82
70
83 for n, ax in enumerate(self.axes):
71 for n, ax in enumerate(self.axes):
84
72
85
86 self.zmax = self.zmax if self.zmax is not None else numpy.max(
73 self.zmax = self.zmax if self.zmax is not None else numpy.max(
87 self.z[1][0,12:40])
74 self.z[1][0,12:40])
88 self.zmin = self.zmin if self.zmin is not None else numpy.min(
75 self.zmin = self.zmin if self.zmin is not None else numpy.min(
89 self.z[1][0,12:40])
76 self.z[1][0,12:40])
90
77
91
92
93 if ax.firsttime:
78 if ax.firsttime:
94
79
95 if self.zlimits is not None:
80 if self.zlimits is not None:
96 self.zmin, self.zmax = self.zlimits[n]
81 self.zmin, self.zmax = self.zlimits[n]
97
82
98
99 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
83 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
100 vmin=self.zmin,
84 vmin=self.zmin,
101 vmax=self.zmax,
85 vmax=self.zmax,
102 cmap=self.cmaps[n]
86 cmap=self.cmaps[n]
103 )
87 )
104 #plt.tight_layout()
105 else:
88 else:
106 if self.zlimits is not None:
89 if self.zlimits is not None:
107 self.zmin, self.zmax = self.zlimits[n]
90 self.zmin, self.zmax = self.zlimits[n]
108 ax.collections.remove(ax.collections[0])
91 ax.collections.remove(ax.collections[0])
109 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
92 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
110 vmin=self.zmin,
93 vmin=self.zmin,
111 vmax=self.zmax,
94 vmax=self.zmax,
112 cmap=self.cmaps[n]
95 cmap=self.cmaps[n]
113 )
96 )
114 #plt.tight_layout()
115
97
116
98
117 class RTILPPlot(RTIPlot):
99 class RTILPPlot(RTIPlot):
118
100
119 '''
101 '''
120 Plot for RTI Long Pulse
102 Plot for RTI Long Pulse
121 '''
103 '''
122
104
123 CODE = 'RTILP'
105 CODE = 'RTILP'
124 colormap = 'jro'
106 colormap = 'jro'
125 plot_name = 'RTI LP'
107 plot_name = 'RTI LP'
126
108
127 #cb_label = 'Ne Electron Density (1/cm3)'
128
129 def setup(self):
109 def setup(self):
130 self.xaxis = 'time'
110 self.xaxis = 'time'
131 self.ncols = 1
111 self.ncols = 1
132 self.nrows = 4
112 self.nrows = 4
133 self.nplots = self.nrows
113 self.nplots = self.nrows
134 if self.showSNR:
114 if self.showSNR:
135 self.nrows += 1
115 self.nrows += 1
136 self.nplots += 1
116 self.nplots += 1
137
117
138 self.ylabel = 'Height [km]'
118 self.ylabel = 'Height [km]'
139 self.xlabel = 'Time (LT)'
119 self.xlabel = 'Time (LT)'
140
120
141 self.cb_label = 'Intensity (dB)'
121 self.cb_label = 'Intensity (dB)'
142
122
143
144
145 #self.cb_label = cb_label
146
147 self.titles = ['{} Channel {}'.format(
123 self.titles = ['{} Channel {}'.format(
148 self.plot_name.upper(), '0'),'{} Channel {}'.format(
124 self.plot_name.upper(), '0'),'{} Channel {}'.format(
149 self.plot_name.upper(), '1'),'{} Channel {}'.format(
125 self.plot_name.upper(), '1'),'{} Channel {}'.format(
150 self.plot_name.upper(), '2'),'{} Channel {}'.format(
126 self.plot_name.upper(), '2'),'{} Channel {}'.format(
151 self.plot_name.upper(), '3')]
127 self.plot_name.upper(), '3')]
152
128
153
129
154 def plot(self):
130 def plot(self):
155
131
156 self.data.normalize_heights()
132 self.data.normalize_heights()
157 self.x = self.data.times
133 self.x = self.data.times
158 self.y = self.data.heights[0:self.data.NRANGE]
134 self.y = self.data.heights[0:self.data.NRANGE]
159
135
160 if self.showSNR:
136 if self.showSNR:
161 self.z = numpy.concatenate(
137 self.z = numpy.concatenate(
162 (self.data[self.CODE], self.data['snr'])
138 (self.data[self.CODE], self.data['snr'])
163 )
139 )
164 else:
140 else:
165
141
166 self.z = self.data[self.CODE]
142 self.z = self.data[self.CODE]
167 #print(numpy.max(self.z[0,0:]))
143 #print(numpy.max(self.z[0,0:]))
168
144
169 self.z = numpy.ma.masked_invalid(self.z)
145 self.z = numpy.ma.masked_invalid(self.z)
170
146
171 if self.decimation is None:
147 if self.decimation is None:
172 x, y, z = self.fill_gaps(self.x, self.y, self.z)
148 x, y, z = self.fill_gaps(self.x, self.y, self.z)
173 else:
149 else:
174 x, y, z = self.fill_gaps(*self.decimate())
150 x, y, z = self.fill_gaps(*self.decimate())
175
151
176 for n, ax in enumerate(self.axes):
152 for n, ax in enumerate(self.axes):
177
153
178
179 self.zmax = self.zmax if self.zmax is not None else numpy.max(
154 self.zmax = self.zmax if self.zmax is not None else numpy.max(
180 self.z[1][0,12:40])
155 self.z[1][0,12:40])
181 self.zmin = self.zmin if self.zmin is not None else numpy.min(
156 self.zmin = self.zmin if self.zmin is not None else numpy.min(
182 self.z[1][0,12:40])
157 self.z[1][0,12:40])
183
158
184 if ax.firsttime:
159 if ax.firsttime:
185
160
186 if self.zlimits is not None:
161 if self.zlimits is not None:
187 self.zmin, self.zmax = self.zlimits[n]
162 self.zmin, self.zmax = self.zlimits[n]
188
163
189
164
190 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
165 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
191 vmin=self.zmin,
166 vmin=self.zmin,
192 vmax=self.zmax,
167 vmax=self.zmax,
193 cmap=self.cmaps[n]
168 cmap=self.cmaps[n]
194 )
169 )
195 #plt.tight_layout()
170 #plt.tight_layout()
196 else:
171 else:
197 if self.zlimits is not None:
172 if self.zlimits is not None:
198 self.zmin, self.zmax = self.zlimits[n]
173 self.zmin, self.zmax = self.zlimits[n]
199 ax.collections.remove(ax.collections[0])
174 ax.collections.remove(ax.collections[0])
200 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
175 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
201 vmin=self.zmin,
176 vmin=self.zmin,
202 vmax=self.zmax,
177 vmax=self.zmax,
203 cmap=self.cmaps[n]
178 cmap=self.cmaps[n]
204 )
179 )
205 #plt.tight_layout()
180 #plt.tight_layout()
206
181
207
182
208 class DenRTIPlot(RTIPlot):
183 class DenRTIPlot(RTIPlot):
209
184
210 '''
185 '''
211 Plot for Den
186 Plot for Den
212 '''
187 '''
213
188
214 CODE = 'denrti'
189 CODE = 'denrti'
215 colormap = 'jro'
190 colormap = 'jro'
216 plot_name = 'Electron Density'
191 plot_name = 'Electron Density'
217
192
218 #cb_label = 'Ne Electron Density (1/cm3)'
193 #cb_label = 'Ne Electron Density (1/cm3)'
219
194
220 def setup(self):
195 def setup(self):
221 self.xaxis = 'time'
196 self.xaxis = 'time'
222 self.ncols = 1
197 self.ncols = 1
223 self.nrows = self.data.shape(self.CODE)[0]
198 self.nrows = self.data.shape(self.CODE)[0]
224 self.nplots = self.nrows
199 self.nplots = self.nrows
225 if self.showSNR:
200 if self.showSNR:
226 self.nrows += 1
201 self.nrows += 1
227 self.nplots += 1
202 self.nplots += 1
228
203
229 self.ylabel = 'Height [km]'
204 self.ylabel = 'Height [km]'
230 self.xlabel = 'Time (LT)'
205 self.xlabel = 'Time (LT)'
231
206
232 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
207 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
233
208
234 if self.CODE == 'denrti' or self.CODE=='denrtiLP':
209 if self.CODE == 'denrti' or self.CODE=='denrtiLP':
235 self.cb_label = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
210 self.cb_label = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
236
211
237 #self.cb_label = cb_label
212 #self.cb_label = cb_label
238 if not self.titles:
213 if not self.titles:
239 self.titles = self.data.parameters \
214 self.titles = self.data.parameters \
240 if self.data.parameters else ['{}'.format(self.plot_name)]
215 if self.data.parameters else ['{}'.format(self.plot_name)]
241 if self.showSNR:
216 if self.showSNR:
242 self.titles.append('SNR')
217 self.titles.append('SNR')
243
218
244 def plot(self):
219 def plot(self):
245
220
246 self.data.normalize_heights()
221 self.data.normalize_heights()
247 self.x = self.data.times
222 self.x = self.data.times
248 self.y = self.data.heights
223 self.y = self.data.heights
249
224
250
225
251
226
252 if self.showSNR:
227 if self.showSNR:
253 self.z = numpy.concatenate(
228 self.z = numpy.concatenate(
254 (self.data[self.CODE], self.data['snr'])
229 (self.data[self.CODE], self.data['snr'])
255 )
230 )
256 else:
231 else:
257 self.z = self.data[self.CODE]
232 self.z = self.data[self.CODE]
258
233
259 self.z = numpy.ma.masked_invalid(self.z)
234 self.z = numpy.ma.masked_invalid(self.z)
260
235
261 if self.decimation is None:
236 if self.decimation is None:
262 x, y, z = self.fill_gaps(self.x, self.y, self.z)
237 x, y, z = self.fill_gaps(self.x, self.y, self.z)
263 else:
238 else:
264 x, y, z = self.fill_gaps(*self.decimate())
239 x, y, z = self.fill_gaps(*self.decimate())
265
240
266 for n, ax in enumerate(self.axes):
241 for n, ax in enumerate(self.axes):
267
242
268 self.zmax = self.zmax if self.zmax is not None else numpy.max(
243 self.zmax = self.zmax if self.zmax is not None else numpy.max(
269 self.z[n])
244 self.z[n])
270 self.zmin = self.zmin if self.zmin is not None else numpy.min(
245 self.zmin = self.zmin if self.zmin is not None else numpy.min(
271 self.z[n])
246 self.z[n])
272
247
273 if ax.firsttime:
248 if ax.firsttime:
274
249
275 if self.zlimits is not None:
250 if self.zlimits is not None:
276 self.zmin, self.zmax = self.zlimits[n]
251 self.zmin, self.zmax = self.zlimits[n]
277 if numpy.log10(self.zmin)<0:
252 if numpy.log10(self.zmin)<0:
278 self.zmin=1
253 self.zmin=1
279 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
254 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
280 vmin=self.zmin,
255 vmin=self.zmin,
281 vmax=self.zmax,
256 vmax=self.zmax,
282 cmap=self.cmaps[n],
257 cmap=self.cmaps[n],
283 norm=colors.LogNorm()
258 norm=colors.LogNorm()
284 )
259 )
285 #plt.tight_layout()
260 #plt.tight_layout()
286
261
287 else:
262 else:
288 if self.zlimits is not None:
263 if self.zlimits is not None:
289 self.zmin, self.zmax = self.zlimits[n]
264 self.zmin, self.zmax = self.zlimits[n]
290 ax.collections.remove(ax.collections[0])
265 ax.collections.remove(ax.collections[0])
291 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
266 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
292 vmin=self.zmin,
267 vmin=self.zmin,
293 vmax=self.zmax,
268 vmax=self.zmax,
294 cmap=self.cmaps[n],
269 cmap=self.cmaps[n],
295 norm=colors.LogNorm()
270 norm=colors.LogNorm()
296 )
271 )
297 #plt.tight_layout()
272 #plt.tight_layout()
298
273
299
274
300
275
301 class DenRTILPPlot(DenRTIPlot):
276 class DenRTILPPlot(DenRTIPlot):
302
277
303 '''
278 '''
304 Plot for Electron Temperature
279 Plot for Electron Temperature
305 '''
280 '''
306
281
307 CODE = 'denrtiLP'
282 CODE = 'denrtiLP'
308 colormap = 'jro'
283 colormap = 'jro'
309 plot_name = 'Electron Density'
284 plot_name = 'Electron Density'
310
285
311
286
312 class ETempRTIPlot(RTIPlot):
287 class ETempRTIPlot(RTIPlot):
313
288
314 '''
289 '''
315 Plot for Electron Temperature
290 Plot for Electron Temperature
316 '''
291 '''
317
292
318 CODE = 'ETemp'
293 CODE = 'ETemp'
319 colormap = 'jet'
294 colormap = 'jet'
320 plot_name = 'Electron Temperature'
295 plot_name = 'Electron Temperature'
321
296
322 #cb_label = 'Ne Electron Density (1/cm3)'
297 #cb_label = 'Ne Electron Density (1/cm3)'
323
298
324 def setup(self):
299 def setup(self):
325 self.xaxis = 'time'
300 self.xaxis = 'time'
326 self.ncols = 1
301 self.ncols = 1
327 self.nrows = self.data.shape(self.CODE)[0]
302 self.nrows = self.data.shape(self.CODE)[0]
328 self.nplots = self.nrows
303 self.nplots = self.nrows
329 if self.showSNR:
304 if self.showSNR:
330 self.nrows += 1
305 self.nrows += 1
331 self.nplots += 1
306 self.nplots += 1
332
307
333 self.ylabel = 'Height [km]'
308 self.ylabel = 'Height [km]'
334 self.xlabel = 'Time (LT)'
309 self.xlabel = 'Time (LT)'
335 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
310 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':
311 if self.CODE == 'ETemp' or self.CODE == 'ETempLP':
337 self.cb_label = 'Electron Temperature (K)'
312 self.cb_label = 'Electron Temperature (K)'
338 if self.CODE == 'ITemp' or self.CODE == 'ITempLP':
313 if self.CODE == 'ITemp' or self.CODE == 'ITempLP':
339 self.cb_label = 'Ion Temperature (K)'
314 self.cb_label = 'Ion Temperature (K)'
340
315
341
316
342 if not self.titles:
317 if not self.titles:
343 self.titles = self.data.parameters \
318 self.titles = self.data.parameters \
344 if self.data.parameters else ['{}'.format(self.plot_name)]
319 if self.data.parameters else ['{}'.format(self.plot_name)]
345 if self.showSNR:
320 if self.showSNR:
346 self.titles.append('SNR')
321 self.titles.append('SNR')
347
322
348 def plot(self):
323 def plot(self):
349
324
350 self.data.normalize_heights()
325 self.data.normalize_heights()
351 self.x = self.data.times
326 self.x = self.data.times
352 self.y = self.data.heights
327 self.y = self.data.heights
353
328
354 if self.showSNR:
329 if self.showSNR:
355 self.z = numpy.concatenate(
330 self.z = numpy.concatenate(
356 (self.data[self.CODE], self.data['snr'])
331 (self.data[self.CODE], self.data['snr'])
357 )
332 )
358 else:
333 else:
359 self.z = self.data[self.CODE]
334 self.z = self.data[self.CODE]
360
335
361 self.z = numpy.ma.masked_invalid(self.z)
336 self.z = numpy.ma.masked_invalid(self.z)
362
337
363 if self.decimation is None:
338 if self.decimation is None:
364 x, y, z = self.fill_gaps(self.x, self.y, self.z)
339 x, y, z = self.fill_gaps(self.x, self.y, self.z)
365 else:
340 else:
366 x, y, z = self.fill_gaps(*self.decimate())
341 x, y, z = self.fill_gaps(*self.decimate())
367
342
368 for n, ax in enumerate(self.axes):
343 for n, ax in enumerate(self.axes):
369
344
370 self.zmax = self.zmax if self.zmax is not None else numpy.max(
345 self.zmax = self.zmax if self.zmax is not None else numpy.max(
371 self.z[n])
346 self.z[n])
372 self.zmin = self.zmin if self.zmin is not None else numpy.min(
347 self.zmin = self.zmin if self.zmin is not None else numpy.min(
373 self.z[n])
348 self.z[n])
374
349
375 if ax.firsttime:
350 if ax.firsttime:
376
351
377 if self.zlimits is not None:
352 if self.zlimits is not None:
378 self.zmin, self.zmax = self.zlimits[n]
353 self.zmin, self.zmax = self.zlimits[n]
379
354
380 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
355 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
381 vmin=self.zmin,
356 vmin=self.zmin,
382 vmax=self.zmax,
357 vmax=self.zmax,
383 cmap=self.cmaps[n]
358 cmap=self.cmaps[n]
384 )
359 )
385 #plt.tight_layout()
360 #plt.tight_layout()
386
361
387 else:
362 else:
388 if self.zlimits is not None:
363 if self.zlimits is not None:
389 self.zmin, self.zmax = self.zlimits[n]
364 self.zmin, self.zmax = self.zlimits[n]
390 ax.collections.remove(ax.collections[0])
365 ax.collections.remove(ax.collections[0])
391 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
366 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
392 vmin=self.zmin,
367 vmin=self.zmin,
393 vmax=self.zmax,
368 vmax=self.zmax,
394 cmap=self.cmaps[n]
369 cmap=self.cmaps[n]
395 )
370 )
396 #plt.tight_layout()
371 #plt.tight_layout()
397
372
398
373
399
374
400 class ITempRTIPlot(ETempRTIPlot):
375 class ITempRTIPlot(ETempRTIPlot):
401
376
402 '''
377 '''
403 Plot for Ion Temperature
378 Plot for Ion Temperature
404 '''
379 '''
405
380
406 CODE = 'ITemp'
381 CODE = 'ITemp'
407 colormap = 'jet'
382 colormap = 'jet'
408 plot_name = 'Ion Temperature'
383 plot_name = 'Ion Temperature'
409
384
410
385
411 class ElectronTempLPPlot(ETempRTIPlot):
386 class ElectronTempLPPlot(ETempRTIPlot):
412
387
413 '''
388 '''
414 Plot for Electron Temperature LP
389 Plot for Electron Temperature LP
415 '''
390 '''
416
391
417 CODE = 'ETempLP'
392 CODE = 'ETempLP'
418 colormap = 'jet'
393 colormap = 'jet'
419 plot_name = 'Electron Temperature'
394 plot_name = 'Electron Temperature'
420
395
421
396
422 class IonTempLPPlot(ETempRTIPlot):
397 class IonTempLPPlot(ETempRTIPlot):
423
398
424 '''
399 '''
425 Plot for Ion Temperature LP
400 Plot for Ion Temperature LP
426 '''
401 '''
427
402
428 CODE = 'ITempLP'
403 CODE = 'ITempLP'
429 colormap = 'jet'
404 colormap = 'jet'
430 plot_name = 'Ion Temperature'
405 plot_name = 'Ion Temperature'
431
406
432
407
433 class HFracRTIPlot(ETempRTIPlot):
408 class HFracRTIPlot(ETempRTIPlot):
434
409
435 '''
410 '''
436 Plot for H+ LP
411 Plot for H+ LP
437 '''
412 '''
438
413
439 CODE = 'HFracLP'
414 CODE = 'HFracLP'
440 colormap = 'jet'
415 colormap = 'jet'
441 plot_name = 'H+ Frac'
416 plot_name = 'H+ Frac'
442
417
443
418
444 class HeFracRTIPlot(ETempRTIPlot):
419 class HeFracRTIPlot(ETempRTIPlot):
445
420
446 '''
421 '''
447 Plot for He+ LP
422 Plot for He+ LP
448 '''
423 '''
449
424
450 CODE = 'HeFracLP'
425 CODE = 'HeFracLP'
451 colormap = 'jet'
426 colormap = 'jet'
452 plot_name = 'He+ Frac'
427 plot_name = 'He+ Frac'
453
428
454
429
455 class TempsDPPlot(Plot):
430 class TempsDPPlot(Plot):
456 '''
431 '''
457 Plot for Electron - Ion Temperatures
432 Plot for Electron - Ion Temperatures
458 '''
433 '''
459
434
460 CODE = 'tempsDP'
435 CODE = 'tempsDP'
461 plot_name = 'Temperatures'
436 plot_name = 'Temperatures'
462 plot_type = 'scatterbuffer'
437 plot_type = 'scatterbuffer'
463
438
464
439
465 def setup(self):
440 def setup(self):
466
441
467 self.ncols = 1
442 self.ncols = 1
468 self.nrows = 1
443 self.nrows = 1
469 self.nplots = 1
444 self.nplots = 1
470 self.ylabel = 'Range [km]'
445 self.ylabel = 'Range [km]'
471 self.xlabel = 'Temperature (K)'
446 self.xlabel = 'Temperature (K)'
472 self.width = 3.5
447 self.width = 3.5
473 self.height = 5.5
448 self.height = 5.5
474 self.colorbar = False
449 self.colorbar = False
475 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
450 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
476 if not self.titles:
451 if not self.titles:
477 self.titles = self.data.parameters \
452 self.titles = self.data.parameters \
478 if self.data.parameters else ['{}'.format(self.CODE.upper())]
453 if self.data.parameters else ['{}'.format(self.CODE.upper())]
479
454
480 def plot(self):
455 def plot(self):
481
456
482 self.x = self.data['tempsDP'][:,-1]
457 self.x = self.data['tempsDP'][:,-1]
483 self.y = self.data.heights[0:self.data.NSHTS]
458 self.y = self.data.heights[0:self.data.NSHTS]
484
459
485 self.xmin = -100
460 self.xmin = -100
486 self.xmax = 5000
461 self.xmax = 5000
487 ax = self.axes[0]
462 ax = self.axes[0]
488
463
489 if ax.firsttime:
464 if ax.firsttime:
490
465
491 ax.errorbar(self.x, self.y, xerr=self.data.ete2, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
466 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')
467 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')
468 plt.legend(loc='lower right')
494 self.ystep_given = 50
469 self.ystep_given = 50
495 ax.yaxis.set_minor_locator(MultipleLocator(15))
470 ax.yaxis.set_minor_locator(MultipleLocator(15))
496 ax.grid(which='minor')
471 ax.grid(which='minor')
497 #plt.tight_layout()
472 #plt.tight_layout()
498
473
499
474
500 else:
475 else:
501 self.clear_figures()
476 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')
477 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')
478 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')
479 plt.legend(loc='lower right')
505 ax.yaxis.set_minor_locator(MultipleLocator(15))
480 ax.yaxis.set_minor_locator(MultipleLocator(15))
506 #plt.tight_layout()
481 #plt.tight_layout()
507
482
508
483
509 class TempsHPPlot(Plot):
484 class TempsHPPlot(Plot):
510 '''
485 '''
511 Plot for Temperatures Hybrid Experiment
486 Plot for Temperatures Hybrid Experiment
512 '''
487 '''
513
488
514 CODE = 'temps_LP'
489 CODE = 'temps_LP'
515 plot_name = 'Temperatures'
490 plot_name = 'Temperatures'
516 plot_type = 'scatterbuffer'
491 plot_type = 'scatterbuffer'
517
492
518
493
519 def setup(self):
494 def setup(self):
520
495
521 self.ncols = 1
496 self.ncols = 1
522 self.nrows = 1
497 self.nrows = 1
523 self.nplots = 1
498 self.nplots = 1
524 self.ylabel = 'Range [km]'
499 self.ylabel = 'Range [km]'
525 self.xlabel = 'Temperature (K)'
500 self.xlabel = 'Temperature (K)'
526 self.width = 3.5
501 self.width = 3.5
527 self.height = 6.5
502 self.height = 6.5
528 self.colorbar = False
503 self.colorbar = False
529 if not self.titles:
504 if not self.titles:
530 self.titles = self.data.parameters \
505 self.titles = self.data.parameters \
531 if self.data.parameters else ['{}'.format(self.CODE.upper())]
506 if self.data.parameters else ['{}'.format(self.CODE.upper())]
532
507
533 def plot(self):
508 def plot(self):
534
509
535 self.x = self.data['temps_LP'][:,-1]
510 self.x = self.data['temps_LP'][:,-1]
536 self.y = self.data.heights[0:self.data.NACF]
511 self.y = self.data.heights[0:self.data.NACF]
537 self.xmin = -100
512 self.xmin = -100
538 self.xmax = 4500
513 self.xmax = 4500
539 ax = self.axes[0]
514 ax = self.axes[0]
540
515
541 if ax.firsttime:
516 if ax.firsttime:
542
517
543 ax.errorbar(self.x, self.y, xerr=self.data.ete, fmt='r^',elinewidth=1.0,color='b',linewidth=2.0, label='Te')
518 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')
519 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')
520 plt.legend(loc='lower right')
546 self.ystep_given = 200
521 self.ystep_given = 200
547 ax.yaxis.set_minor_locator(MultipleLocator(15))
522 ax.yaxis.set_minor_locator(MultipleLocator(15))
548 ax.grid(which='minor')
523 ax.grid(which='minor')
549 #plt.tight_layout()
524 #plt.tight_layout()
550
525
551
526
552 else:
527 else:
553 self.clear_figures()
528 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')
529 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')
530 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')
531 plt.legend(loc='lower right')
557 ax.yaxis.set_minor_locator(MultipleLocator(15))
532 ax.yaxis.set_minor_locator(MultipleLocator(15))
558 #plt.tight_layout()
533 #plt.tight_layout()
559
534
560
535
561 class FracsHPPlot(Plot):
536 class FracsHPPlot(Plot):
562 '''
537 '''
563 Plot for Composition LP
538 Plot for Composition LP
564 '''
539 '''
565
540
566 CODE = 'fracs_LP'
541 CODE = 'fracs_LP'
567 plot_name = 'Composition'
542 plot_name = 'Composition'
568 plot_type = 'scatterbuffer'
543 plot_type = 'scatterbuffer'
569
544
570
545
571 def setup(self):
546 def setup(self):
572
547
573 self.ncols = 1
548 self.ncols = 1
574 self.nrows = 1
549 self.nrows = 1
575 self.nplots = 1
550 self.nplots = 1
576 self.ylabel = 'Range [km]'
551 self.ylabel = 'Range [km]'
577 self.xlabel = 'Frac'
552 self.xlabel = 'Frac'
578 self.width = 3.5
553 self.width = 3.5
579 self.height = 6.5
554 self.height = 6.5
580 self.colorbar = False
555 self.colorbar = False
581 if not self.titles:
556 if not self.titles:
582 self.titles = self.data.parameters \
557 self.titles = self.data.parameters \
583 if self.data.parameters else ['{}'.format(self.CODE.upper())]
558 if self.data.parameters else ['{}'.format(self.CODE.upper())]
584
559
585 def plot(self):
560 def plot(self):
586
561
587 self.x = self.data['fracs_LP'][:,-1]
562 self.x = self.data['fracs_LP'][:,-1]
588 self.y = self.data.heights[0:self.data.NACF]
563 self.y = self.data.heights[0:self.data.NACF]
589
564
590 self.xmin = 0
565 self.xmin = 0
591 self.xmax = 1
566 self.xmax = 1
592 ax = self.axes[0]
567 ax = self.axes[0]
593
568
594 if ax.firsttime:
569 if ax.firsttime:
595
570
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+')
571 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+')
572 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')
573 plt.legend(loc='lower right')
599 self.xstep_given = 0.2
574 self.xstep_given = 0.2
600 self.ystep_given = 200
575 self.ystep_given = 200
601 ax.yaxis.set_minor_locator(MultipleLocator(15))
576 ax.yaxis.set_minor_locator(MultipleLocator(15))
602 ax.grid(which='minor')
577 ax.grid(which='minor')
603 #plt.tight_layout()
578 #plt.tight_layout()
604
579
605
580
606 else:
581 else:
607 self.clear_figures()
582 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+')
583 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+')
584 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')
585 plt.legend(loc='lower right')
611 ax.yaxis.set_minor_locator(MultipleLocator(15))
586 ax.yaxis.set_minor_locator(MultipleLocator(15))
612 #plt.tight_layout()
587 #plt.tight_layout()
613
588
614
589
615
590
616 class EDensityPlot(Plot):
591 class EDensityPlot(Plot):
617 '''
592 '''
618 Plot for electron density
593 Plot for electron density
619 '''
594 '''
620
595
621 CODE = 'den'
596 CODE = 'den'
622 plot_name = 'Electron Density'
597 plot_name = 'Electron Density'
623 plot_type = 'scatterbuffer'
598 plot_type = 'scatterbuffer'
624
599
625
600
626 def setup(self):
601 def setup(self):
627
602
628 self.ncols = 1
603 self.ncols = 1
629 self.nrows = 1
604 self.nrows = 1
630 self.nplots = 1
605 self.nplots = 1
631 self.ylabel = 'Range [km]'
606 self.ylabel = 'Range [km]'
632 self.xlabel = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
607 self.xlabel = r'$\mathrm{N_e}$ Electron Density ($\mathrm{1/cm^3}$)'
633 self.width = 4
608 self.width = 4
634 self.height = 6.5
609 self.height = 6.5
635 self.colorbar = False
610 self.colorbar = False
636 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
611 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
637 if not self.titles:
612 if not self.titles:
638 self.titles = self.data.parameters \
613 self.titles = self.data.parameters \
639 if self.data.parameters else ['{}'.format(self.CODE.upper())]
614 if self.data.parameters else ['{}'.format(self.CODE.upper())]
640
615
641 def plot(self):
616 def plot(self):
642
617
643
618
644 self.x = self.data[self.CODE]
619 self.x = self.data[self.CODE]
645 self.y = self.data.heights
620 self.y = self.data.heights
646 self.xmin = 1000
621 self.xmin = 1000
647 self.xmax = 10000000
622 self.xmax = 10000000
648 ax = self.axes[0]
623 ax = self.axes[0]
649
624
650 if ax.firsttime:
625 if ax.firsttime:
651 self.autoxticks=False
626 self.autoxticks=False
652 #if self.CODE=='den':
627 #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)
628 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)
629 #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
630
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)
631 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:
632 #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)
633 #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)
634 #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
635
661 if self.CODE=='denLP':
636 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)
637 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
638
664 plt.legend(loc='upper right')
639 plt.legend(loc='upper right')
665 ax.set_xscale("log", nonposx='clip')
640 ax.set_xscale("log", nonposx='clip')
666 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
641 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
667 self.ystep_given=100
642 self.ystep_given=100
668 if self.CODE=='denLP':
643 if self.CODE=='denLP':
669 self.ystep_given=200
644 self.ystep_given=200
670 ax.set_yticks(grid_y_ticks,minor=True)
645 ax.set_yticks(grid_y_ticks,minor=True)
671 ax.grid(which='minor')
646 ax.grid(which='minor')
672 #plt.tight_layout()
647 #plt.tight_layout()
673
648
674
649
675
650
676 else:
651 else:
677
652
678 self.clear_figures()
653 self.clear_figures()
679 #if self.CODE=='den':
654 #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)
655 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)
656 #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
657
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)
658 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")
659 ax.errorbar(self.x[:,-2], self.y[:self.data.NSHTS], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed")
685 #else:
660 #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)
661 #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)
662 #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")
663 #ax.errorbar(self.x[:self.data.cut,-2], self.y[:self.data.cut], elinewidth=1.0,color='r',linewidth=0.5,linestyle="dashed")
689
664
690 if self.CODE=='denLP':
665 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)
666 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
667
693 ax.set_xscale("log", nonposx='clip')
668 ax.set_xscale("log", nonposx='clip')
694 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
669 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
695 ax.set_yticks(grid_y_ticks,minor=True)
670 ax.set_yticks(grid_y_ticks,minor=True)
696 ax.grid(which='minor')
671 ax.grid(which='minor')
697 plt.legend(loc='upper right')
672 plt.legend(loc='upper right')
698 #plt.tight_layout()
673 #plt.tight_layout()
699
674
700 class FaradayAnglePlot(Plot):
675 class FaradayAnglePlot(Plot):
701 '''
676 '''
702 Plot for electron density
677 Plot for electron density
703 '''
678 '''
704
679
705 CODE = 'FaradayAngle'
680 CODE = 'FaradayAngle'
706 plot_name = 'Faraday Angle'
681 plot_name = 'Faraday Angle'
707 plot_type = 'scatterbuffer'
682 plot_type = 'scatterbuffer'
708
683
709
684
710 def setup(self):
685 def setup(self):
711
686
712 self.ncols = 1
687 self.ncols = 1
713 self.nrows = 1
688 self.nrows = 1
714 self.nplots = 1
689 self.nplots = 1
715 self.ylabel = 'Range [km]'
690 self.ylabel = 'Range [km]'
716 self.xlabel = 'Faraday Angle (ΒΊ)'
691 self.xlabel = 'Faraday Angle (ΒΊ)'
717 self.width = 4
692 self.width = 4
718 self.height = 6.5
693 self.height = 6.5
719 self.colorbar = False
694 self.colorbar = False
720 if not self.titles:
695 if not self.titles:
721 self.titles = self.data.parameters \
696 self.titles = self.data.parameters \
722 if self.data.parameters else ['{}'.format(self.CODE.upper())]
697 if self.data.parameters else ['{}'.format(self.CODE.upper())]
723
698
724 def plot(self):
699 def plot(self):
725
700
726
701
727 self.x = self.data[self.CODE]
702 self.x = self.data[self.CODE]
728 self.y = self.data.heights
703 self.y = self.data.heights
729 self.xmin = -180
704 self.xmin = -180
730 self.xmax = 180
705 self.xmax = 180
731 ax = self.axes[0]
706 ax = self.axes[0]
732
707
733 if ax.firsttime:
708 if ax.firsttime:
734 self.autoxticks=False
709 self.autoxticks=False
735 #if self.CODE=='den':
710 #if self.CODE=='den':
736 ax.plot(self.x, self.y,marker='o',color='g',linewidth=1.0,markersize=2)
711 ax.plot(self.x, self.y,marker='o',color='g',linewidth=1.0,markersize=2)
737
712
738 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
713 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
739 self.ystep_given=100
714 self.ystep_given=100
740 if self.CODE=='denLP':
715 if self.CODE=='denLP':
741 self.ystep_given=200
716 self.ystep_given=200
742 ax.set_yticks(grid_y_ticks,minor=True)
717 ax.set_yticks(grid_y_ticks,minor=True)
743 ax.grid(which='minor')
718 ax.grid(which='minor')
744 #plt.tight_layout()
719 #plt.tight_layout()
745 else:
720 else:
746
721
747 self.clear_figures()
722 self.clear_figures()
748 #if self.CODE=='den':
723 #if self.CODE=='den':
749 #print(numpy.shape(self.x))
724 #print(numpy.shape(self.x))
750 ax.plot(self.x[:,-1], self.y, marker='o',color='g',linewidth=1.0, markersize=2)
725 ax.plot(self.x[:,-1], self.y, marker='o',color='g',linewidth=1.0, markersize=2)
751
726
752 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
727 grid_y_ticks=numpy.arange(numpy.nanmin(self.y),numpy.nanmax(self.y),50)
753 ax.set_yticks(grid_y_ticks,minor=True)
728 ax.set_yticks(grid_y_ticks,minor=True)
754 ax.grid(which='minor')
729 ax.grid(which='minor')
755
730
756 class EDensityHPPlot(EDensityPlot):
731 class EDensityHPPlot(EDensityPlot):
757
732
758 '''
733 '''
759 Plot for Electron Density Hybrid Experiment
734 Plot for Electron Density Hybrid Experiment
760 '''
735 '''
761
736
762 CODE = 'denLP'
737 CODE = 'denLP'
763 plot_name = 'Electron Density'
738 plot_name = 'Electron Density'
764 plot_type = 'scatterbuffer'
739 plot_type = 'scatterbuffer'
765
740
766
741
767 class ACFsPlot(Plot):
742 class ACFsPlot(Plot):
768 '''
743 '''
769 Plot for ACFs Double Pulse Experiment
744 Plot for ACFs Double Pulse Experiment
770 '''
745 '''
771
746
772 CODE = 'acfs'
747 CODE = 'acfs'
773 plot_name = 'ACF'
748 plot_name = 'ACF'
774 plot_type = 'scatterbuffer'
749 plot_type = 'scatterbuffer'
775
750
776
751
777 def setup(self):
752 def setup(self):
778 #self.xaxis = 'time'
753 #self.xaxis = 'time'
779 self.ncols = 1
754 self.ncols = 1
780 self.nrows = 1
755 self.nrows = 1
781 self.nplots = 1
756 self.nplots = 1
782 self.ylabel = 'Range [km]'
757 self.ylabel = 'Range [km]'
783 self.xlabel = 'lags (ms)'
758 self.xlabel = 'lags (ms)'
784 self.width = 3.5
759 self.width = 3.5
785 self.height = 6
760 self.height = 6
786 self.colorbar = False
761 self.colorbar = False
787 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
762 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
788 if not self.titles:
763 if not self.titles:
789 self.titles = self.data.parameters \
764 self.titles = self.data.parameters \
790 if self.data.parameters else ['{}'.format(self.CODE.upper())]
765 if self.data.parameters else ['{}'.format(self.CODE.upper())]
791
766
792 def plot(self):
767 def plot(self):
793
768
794 self.x = self.data.lags_to_plot
769 self.x = self.data.lags_to_plot
795 self.y = self.data['acfs'][:,-1]
770 self.y = self.data['acfs'][:,-1]
796
771
797
772
798 self.xmin = 0.0
773 self.xmin = 0.0
799 self.xmax = 2.0
774 self.xmax = 2.0
800
775
801 ax = self.axes[0]
776 ax = self.axes[0]
802
777
803 if ax.firsttime:
778 if ax.firsttime:
804
779
805 for i in range(self.data.NSHTS):
780 for i in range(self.data.NSHTS):
806 x_aux = numpy.isfinite(self.x[i,:])
781 x_aux = numpy.isfinite(self.x[i,:])
807 y_aux = numpy.isfinite(self.y[i,:])
782 y_aux = numpy.isfinite(self.y[i,:])
808 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
783 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
809 x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:])
784 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,:])
785 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,:])
786 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,:])
787 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:
788 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)
789 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)
790 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)
791 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
792
818 self.xstep_given = (self.xmax-self.xmin)/(self.data.DPL-1)
793 self.xstep_given = (self.xmax-self.xmin)/(self.data.DPL-1)
819 self.ystep_given = 50
794 self.ystep_given = 50
820 ax.yaxis.set_minor_locator(MultipleLocator(15))
795 ax.yaxis.set_minor_locator(MultipleLocator(15))
821 ax.grid(which='minor')
796 ax.grid(which='minor')
822
797
823
798
824
799
825 else:
800 else:
826 self.clear_figures()
801 self.clear_figures()
827
802
828 for i in range(self.data.NSHTS):
803 for i in range(self.data.NSHTS):
829 x_aux = numpy.isfinite(self.x[i,:])
804 x_aux = numpy.isfinite(self.x[i,:])
830 y_aux = numpy.isfinite(self.y[i,:])
805 y_aux = numpy.isfinite(self.y[i,:])
831 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
806 yerr_aux = numpy.isfinite(self.data.acfs_error_to_plot[i,:])
832 x_igcej_aux = numpy.isfinite(self.data.x_igcej_to_plot[i,:])
807 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,:])
808 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,:])
809 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,:])
810 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:
811 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')
812 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)
813 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)
814 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))
815 ax.yaxis.set_minor_locator(MultipleLocator(15))
841
816
842
817
843
818
844
819
845 class ACFsLPPlot(Plot):
820 class ACFsLPPlot(Plot):
846 '''
821 '''
847 Plot for ACFs Double Pulse Experiment
822 Plot for ACFs Double Pulse Experiment
848 '''
823 '''
849
824
850 CODE = 'acfs_LP'
825 CODE = 'acfs_LP'
851 plot_name = 'ACF'
826 plot_name = 'ACF'
852 plot_type = 'scatterbuffer'
827 plot_type = 'scatterbuffer'
853
828
854
829
855 def setup(self):
830 def setup(self):
856 #self.xaxis = 'time'
831 #self.xaxis = 'time'
857 self.ncols = 1
832 self.ncols = 1
858 self.nrows = 1
833 self.nrows = 1
859 self.nplots = 1
834 self.nplots = 1
860 self.ylabel = 'Range [km]'
835 self.ylabel = 'Range [km]'
861 self.xlabel = 'lags (ms)'
836 self.xlabel = 'lags (ms)'
862 self.width = 3.5
837 self.width = 3.5
863 self.height = 7
838 self.height = 7
864 self.colorbar = False
839 self.colorbar = False
865 if not self.titles:
840 if not self.titles:
866 self.titles = self.data.parameters \
841 self.titles = self.data.parameters \
867 if self.data.parameters else ['{}'.format(self.CODE.upper())]
842 if self.data.parameters else ['{}'.format(self.CODE.upper())]
868
843
869
844
870
845
871 def plot(self):
846 def plot(self):
872
847
873 self.x = self.data.lags_LP_to_plot
848 self.x = self.data.lags_LP_to_plot
874 self.y = self.data['acfs_LP'][:,-1]
849 self.y = self.data['acfs_LP'][:,-1]
875
850
876 self.xmin = 0.0
851 self.xmin = 0.0
877 self.xmax = 1.5
852 self.xmax = 1.5
878
853
879 ax = self.axes[0]
854 ax = self.axes[0]
880
855
881 if ax.firsttime:
856 if ax.firsttime:
882
857
883 for i in range(self.data.NACF):
858 for i in range(self.data.NACF):
884 x_aux = numpy.isfinite(self.x[i,:])
859 x_aux = numpy.isfinite(self.x[i,:])
885 y_aux = numpy.isfinite(self.y[i,:])
860 y_aux = numpy.isfinite(self.y[i,:])
886 yerr_aux = numpy.isfinite(self.data.errors[i,:])
861 yerr_aux = numpy.isfinite(self.data.errors[i,:])
887
862
888 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
863 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')
864 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
865
891 #self.xstep_given = (self.xmax-self.xmin)/(self.data.NLAG-1)
866 #self.xstep_given = (self.xmax-self.xmin)/(self.data.NLAG-1)
892 self.xstep_given=0.3
867 self.xstep_given=0.3
893 self.ystep_given = 200
868 self.ystep_given = 200
894 ax.yaxis.set_minor_locator(MultipleLocator(15))
869 ax.yaxis.set_minor_locator(MultipleLocator(15))
895 ax.grid(which='minor')
870 ax.grid(which='minor')
896
871
897 else:
872 else:
898 self.clear_figures()
873 self.clear_figures()
899
874
900 for i in range(self.data.NACF):
875 for i in range(self.data.NACF):
901 x_aux = numpy.isfinite(self.x[i,:])
876 x_aux = numpy.isfinite(self.x[i,:])
902 y_aux = numpy.isfinite(self.y[i,:])
877 y_aux = numpy.isfinite(self.y[i,:])
903 yerr_aux = numpy.isfinite(self.data.errors[i,:])
878 yerr_aux = numpy.isfinite(self.data.errors[i,:])
904
879
905 if self.x[i,:][~numpy.isnan(self.x[i,:])].shape[0]>2:
880 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')
881 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
882
908 ax.yaxis.set_minor_locator(MultipleLocator(15))
883 ax.yaxis.set_minor_locator(MultipleLocator(15))
909
884
910
885
911 class CrossProductsPlot(Plot):
886 class CrossProductsPlot(Plot):
912 '''
887 '''
913 Plot for cross products
888 Plot for cross products
914 '''
889 '''
915
890
916 CODE = 'crossprod'
891 CODE = 'crossprod'
917 plot_name = 'Cross Products'
892 plot_name = 'Cross Products'
918 plot_type = 'scatterbuffer'
893 plot_type = 'scatterbuffer'
919
894
920
921 def setup(self):
895 def setup(self):
922
896
923 self.ncols = 3
897 self.ncols = 3
924 self.nrows = 1
898 self.nrows = 1
925 self.nplots = 3
899 self.nplots = 3
926 self.ylabel = 'Range [km]'
900 self.ylabel = 'Range [km]'
927
928 self.width = 3.5*self.nplots
901 self.width = 3.5*self.nplots
929 self.height = 5.5
902 self.height = 5.5
930 self.colorbar = False
903 self.colorbar = False
931 self.titles = []
904 self.titles = []
932
905
933 def plot(self):
906 def update(self, dataOut):
934
935 self.x = self.data['crossprod'][:,-1,:,:,:,:]
936
937
907
908 data = {}
909 meta = {}
938
910
911 data['crossprod'] = dataOut.crossprods
912 data['NDP'] = dataOut.NDP
939
913
940 self.y = self.data.heights[0:self.data.NDP]
914 return data, meta
941
915
916 def plot(self):
942
917
918 self.x = self.data['crossprod'][:,-1,:,:,:,:]
919 self.y = self.data.heights[0:self.data['NDP']]
943
920
944 for n, ax in enumerate(self.axes):
921 for n, ax in enumerate(self.axes):
945
922
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])))
923 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])))
924 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
925
949
950 if ax.firsttime:
926 if ax.firsttime:
951
927
952 self.autoxticks=False
928 self.autoxticks=False
953 if n==0:
929 if n==0:
954 label1='kax'
930 label1='kax'
955 label2='kay'
931 label2='kay'
956 label3='kbx'
932 label3='kbx'
957 label4='kby'
933 label4='kby'
958 self.xlimits=[(self.xmin,self.xmax)]
934 self.xlimits=[(self.xmin,self.xmax)]
959 elif n==1:
935 elif n==1:
960 label1='kax2'
936 label1='kax2'
961 label2='kay2'
937 label2='kay2'
962 label3='kbx2'
938 label3='kbx2'
963 label4='kby2'
939 label4='kby2'
964 self.xlimits.append((self.xmin,self.xmax))
940 self.xlimits.append((self.xmin,self.xmax))
965 elif n==2:
941 elif n==2:
966 label1='kaxay'
942 label1='kaxay'
967 label2='kbxby'
943 label2='kbxby'
968 label3='kaxbx'
944 label3='kaxbx'
969 label4='kaxby'
945 label4='kaxby'
970 self.xlimits.append((self.xmin,self.xmax))
946 self.xlimits.append((self.xmin,self.xmax))
971
947
972
973 ax.plotline1 = ax.plot(self.x[n][0,:,0,0], self.y, color='r',linewidth=2.0, label=label1)
948 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)
949 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)
950 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)
951 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')
952 ax.legend(loc='upper right')
978 ax.set_xlim(self.xmin, self.xmax)
953 ax.set_xlim(self.xmin, self.xmax)
979 self.titles.append('{}'.format(self.plot_name.upper()))
954 self.titles.append('{}'.format(self.plot_name.upper()))
980 #plt.tight_layout()
981
982
955
983 else:
956 else:
984
957
985 if n==0:
958 if n==0:
986 self.xlimits=[(self.xmin,self.xmax)]
959 self.xlimits=[(self.xmin,self.xmax)]
987 else:
960 else:
988 self.xlimits.append((self.xmin,self.xmax))
961 self.xlimits.append((self.xmin,self.xmax))
989
962
990 ax.set_xlim(self.xmin, self.xmax)
963 ax.set_xlim(self.xmin, self.xmax)
991
964
992
993 ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y)
965 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)
966 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)
967 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)
968 ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y)
997 self.titles.append('{}'.format(self.plot_name.upper()))
969 self.titles.append('{}'.format(self.plot_name.upper()))
998 #plt.tight_layout()
999
1000
970
1001
971
1002 class CrossProductsLPPlot(Plot):
972 class CrossProductsLPPlot(Plot):
1003 '''
973 '''
1004 Plot for cross products LP
974 Plot for cross products LP
1005 '''
975 '''
1006
976
1007 CODE = 'crossprodlp'
977 CODE = 'crossprodlp'
1008 plot_name = 'Cross Products LP'
978 plot_name = 'Cross Products LP'
1009 plot_type = 'scatterbuffer'
979 plot_type = 'scatterbuffer'
1010
980
1011
981
1012 def setup(self):
982 def setup(self):
1013
983
1014 self.ncols = 2
984 self.ncols = 2
1015 self.nrows = 1
985 self.nrows = 1
1016 self.nplots = 2
986 self.nplots = 2
1017 self.ylabel = 'Range [km]'
987 self.ylabel = 'Range [km]'
1018 self.xlabel = 'dB'
988 self.xlabel = 'dB'
1019 self.width = 3.5*self.nplots
989 self.width = 3.5*self.nplots
1020 self.height = 5.5
990 self.height = 5.5
1021 self.colorbar = False
991 self.colorbar = False
1022 self.titles = []
992 self.titles = []
1023 self.plotline_array=numpy.zeros((2,self.data.NLAG),dtype=object)
993 self.plotline_array=numpy.zeros((2,self.data.NLAG),dtype=object)
1024 def plot(self):
994 def plot(self):
1025
995
1026
996
1027 self.x = self.data[self.CODE][:,-1,:,:]
997 self.x = self.data[self.CODE][:,-1,:,:]
1028
998
1029
999
1030 self.y = self.data.heights[0:self.data.NRANGE]
1000 self.y = self.data.heights[0:self.data.NRANGE]
1031
1001
1032
1002
1033 label_array=numpy.array(['lag '+ str(x) for x in range(self.data.NLAG)])
1003 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']
1004 color_array=['r','k','g','b','c','m','y','orange','steelblue','purple','peru','darksalmon','grey','limegreen','olive','midnightblue']
1035
1005
1036
1006
1037 for n, ax in enumerate(self.axes):
1007 for n, ax in enumerate(self.axes):
1038
1008
1039 self.xmin=30
1009 self.xmin=30
1040 self.xmax=70
1010 self.xmax=70
1041 #print(self.x[0,12:15,n])
1011 #print(self.x[0,12:15,n])
1042 #input()
1012 #input()
1043 #self.xmin=numpy.min(numpy.concatenate((self.x[0,:,n],self.x[1,:,n])))
1013 #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])))
1014 #self.xmax=numpy.max(numpy.concatenate((self.x[0,:,n],self.x[1,:,n])))
1045
1015
1046 #print("before",self.plotline_array)
1016 #print("before",self.plotline_array)
1047
1017
1048 if ax.firsttime:
1018 if ax.firsttime:
1049
1019
1050 self.autoxticks=False
1020 self.autoxticks=False
1051
1021
1052
1022
1053 for i in range(self.data.NLAG):
1023 for i in range(self.data.NLAG):
1054 #print(i)
1024 #print(i)
1055 #print(numpy.shape(self.x))
1025 #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])
1026 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])
1027 #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)
1028 #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)
1029 #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)
1030 #ax.plotline4 = ax.plot(self.x[n][3,:,0,0], self.y, color='m',linewidth=2.0, label=label4)
1061
1031
1062
1032
1063 #print(self.plotline_array)
1033 #print(self.plotline_array)
1064
1034
1065
1035
1066
1036
1067 ax.legend(loc='upper right')
1037 ax.legend(loc='upper right')
1068 ax.set_xlim(self.xmin, self.xmax)
1038 ax.set_xlim(self.xmin, self.xmax)
1069 if n==0:
1039 if n==0:
1070 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1040 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1071 if n==1:
1041 if n==1:
1072 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1042 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1073
1043
1074 #plt.tight_layout()
1044 #plt.tight_layout()
1075
1045
1076 else:
1046 else:
1077 #print(self.plotline_array)
1047 #print(self.plotline_array)
1078 for i in range(self.data.NLAG):
1048 for i in range(self.data.NLAG):
1079
1049
1080 self.plotline_array[n,i].set_data(self.x[i,:,n],self.y)
1050 self.plotline_array[n,i].set_data(self.x[i,:,n],self.y)
1081
1051
1082
1052
1083
1053
1084 #ax.plotline1[0].set_data(self.x[n][0,:,0,0],self.y)
1054 #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)
1055 #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)
1056 #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)
1057 #ax.plotline4[0].set_data(self.x[n][3,:,0,0],self.y)
1088
1058
1089 if n==0:
1059 if n==0:
1090 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1060 self.titles.append('{} CH0'.format(self.plot_name.upper()))
1091 if n==1:
1061 if n==1:
1092 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1062 self.titles.append('{} CH1'.format(self.plot_name.upper()))
1093
1063
1094 #plt.tight_layout()
1064 #plt.tight_layout()
1095
1065
1096
1066
1097 class NoiseDPPlot(NoisePlot):
1067 class NoiseDPPlot(NoisePlot):
1098 '''
1068 '''
1099 Plot for noise Double Pulse
1069 Plot for noise Double Pulse
1100 '''
1070 '''
1101
1071
1102 CODE = 'noisedp'
1072 CODE = 'noisedp'
1103 plot_name = 'Noise'
1073 plot_name = 'Noise'
1104 plot_type = 'scatterbuffer'
1074 plot_type = 'scatterbuffer'
1105
1075
1106
1076
1107 class XmitWaveformPlot(Plot):
1077 class XmitWaveformPlot(Plot):
1108 '''
1078 '''
1109 Plot for xmit waveform
1079 Plot for xmit waveform
1110 '''
1080 '''
1111
1081
1112 CODE = 'xmit'
1082 CODE = 'xmit'
1113 plot_name = 'Xmit Waveform'
1083 plot_name = 'Xmit Waveform'
1114 plot_type = 'scatterbuffer'
1084 plot_type = 'scatterbuffer'
1115
1085
1116
1086
1117 def setup(self):
1087 def setup(self):
1118
1088
1119 self.ncols = 1
1089 self.ncols = 1
1120 self.nrows = 1
1090 self.nrows = 1
1121 self.nplots = 1
1091 self.nplots = 1
1122 self.ylabel = ''
1092 self.ylabel = ''
1123 self.xlabel = 'Number of Lag'
1093 self.xlabel = 'Number of Lag'
1124 self.width = 5.5
1094 self.width = 5.5
1125 self.height = 3.5
1095 self.height = 3.5
1126 self.colorbar = False
1096 self.colorbar = False
1127 if not self.titles:
1097 if not self.titles:
1128 self.titles = self.data.parameters \
1098 self.titles = self.data.parameters \
1129 if self.data.parameters else ['{}'.format(self.plot_name.upper())]
1099 if self.data.parameters else ['{}'.format(self.plot_name.upper())]
1130
1100
1131 def plot(self):
1101 def plot(self):
1132
1102
1133 self.x = numpy.arange(0,self.data.NLAG,1,'float32')
1103 self.x = numpy.arange(0,self.data.NLAG,1,'float32')
1134 self.y = self.data['xmit'][:,-1,:]
1104 self.y = self.data['xmit'][:,-1,:]
1135
1105
1136 self.xmin = 0
1106 self.xmin = 0
1137 self.xmax = self.data.NLAG-1
1107 self.xmax = self.data.NLAG-1
1138 self.ymin = -1.0
1108 self.ymin = -1.0
1139 self.ymax = 1.0
1109 self.ymax = 1.0
1140 ax = self.axes[0]
1110 ax = self.axes[0]
1141
1111
1142 if ax.firsttime:
1112 if ax.firsttime:
1143 ax.plotline0=ax.plot(self.x,self.y[0,:],color='blue')
1113 ax.plotline0=ax.plot(self.x,self.y[0,:],color='blue')
1144 ax.plotline1=ax.plot(self.x,self.y[1,:],color='red')
1114 ax.plotline1=ax.plot(self.x,self.y[1,:],color='red')
1145 secax=ax.secondary_xaxis(location=0.5)
1115 secax=ax.secondary_xaxis(location=0.5)
1146 secax.xaxis.tick_bottom()
1116 secax.xaxis.tick_bottom()
1147 secax.tick_params( labelleft=False, labeltop=False,
1117 secax.tick_params( labelleft=False, labeltop=False,
1148 labelright=False, labelbottom=False)
1118 labelright=False, labelbottom=False)
1149
1119
1150 self.xstep_given = 3
1120 self.xstep_given = 3
1151 self.ystep_given = .25
1121 self.ystep_given = .25
1152 secax.set_xticks(numpy.linspace(self.xmin, self.xmax, 6)) #only works on matplotlib.version>3.2
1122 secax.set_xticks(numpy.linspace(self.xmin, self.xmax, 6)) #only works on matplotlib.version>3.2
1153
1123
1154 else:
1124 else:
1155 ax.plotline0[0].set_data(self.x,self.y[0,:])
1125 ax.plotline0[0].set_data(self.x,self.y[0,:])
1156 ax.plotline1[0].set_data(self.x,self.y[1,:])
1126 ax.plotline1[0].set_data(self.x,self.y[1,:])
@@ -1,22 +1,22
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z murco $
5 '''
5 '''
6
6
7 from .jroproc_voltage import *
7 from .jroproc_voltage import *
8 from .jroproc_spectra import *
8 from .jroproc_spectra import *
9 from .jroproc_heispectra import *
9 from .jroproc_heispectra import *
10 from .jroproc_amisr import *
10 from .jroproc_amisr import *
11 from .jroproc_correlation import *
11 from .jroproc_correlation import *
12 from .jroproc_parameters import *
12 from .jroproc_parameters import *
13 from .jroproc_spectra_lags import *
13 from .jroproc_spectra_lags import *
14 from .jroproc_spectra_acf import *
14 from .jroproc_spectra_acf import *
15 from .bltrproc_parameters import *
15 from .bltrproc_parameters import *
16 from .pxproc_parameters import *
16 from .pxproc_parameters import *
17
17
18
18
19 ###########DP###########
19 ###########DP###########
20 from .jroproc_voltage_lags import *
20 from .jroproc_voltage_lags import *
21 ###########DP###########
21 ###########DP###########
22 from .jroproc_spectra_lags_faraday import *
22 # from .jroproc_spectra_lags_faraday import *
@@ -1,6256 +1,6260
1
2 import os
1 import sys
3 import sys
2 import numpy,math
4 import numpy, math
3 from scipy import interpolate
5 from scipy import interpolate
6 from scipy.optimize import nnls
4 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
7 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
5 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
8 from schainpy.model.data.jrodata import Voltage,hildebrand_sekhon
6 from schainpy.utils import log
9 from schainpy.utils import log
7 from time import time, mktime, strptime, gmtime, ctime
10 from time import time, mktime, strptime, gmtime, ctime
8 import os
9
11
12 try:
13 from schainpy.model.proc import fitacf_guess
14 from schainpy.model.proc import fitacf_fit_short
15 from schainpy.model.proc import fitacf_acf2
16 from schainpy.model.proc import full_profile_profile
17 except:
18 log.warning('Missing Faraday fortran libs')
10
19
11 class VoltageProc(ProcessingUnit):
20 class VoltageProc(ProcessingUnit):
12
21
13 def __init__(self):
22 def __init__(self):
14
23
15 ProcessingUnit.__init__(self)
24 ProcessingUnit.__init__(self)
16
25
17 self.dataOut = Voltage()
26 self.dataOut = Voltage()
18 self.flip = 1
27 self.flip = 1
19 self.setupReq = False
28 self.setupReq = False
20 #self.dataOut.test=1
29 #self.dataOut.test=1
21
30
22
31
23 def run(self):
32 def run(self):
24 #import time
33 #import time
25 #time.sleep(3)
34 #time.sleep(3)
26
35
27 if self.dataIn.type == 'AMISR':
36 if self.dataIn.type == 'AMISR':
28 self.__updateObjFromAmisrInput()
37 self.__updateObjFromAmisrInput()
29
38
30 if self.dataIn.type == 'Voltage':
39 if self.dataIn.type == 'Voltage':
31 self.dataOut.copy(self.dataIn)
40 self.dataOut.copy(self.dataIn)
32
41
33
42
34 #self.dataOut.flagNoData=True
43 #self.dataOut.flagNoData=True
35 #print(self.dataOut.data[-1,:])
44 #print(self.dataOut.data[-1,:])
36 #print(ctime(self.dataOut.utctime))
45 #print(ctime(self.dataOut.utctime))
37 #print(self.dataOut.heightList)
46 #print(self.dataOut.heightList)
38 #print(self.dataOut.nHeights)
47 #print(self.dataOut.nHeights)
39 #exit(1)
48 #exit(1)
40 #print(self.dataOut.data[6,:32])
49 #print(self.dataOut.data[6,:32])
41 #print(self.dataOut.data[0,320-5:320+5-5])
50 #print(self.dataOut.data[0,320-5:320+5-5])
42 ##print(self.dataOut.heightList[-20:])
51 ##print(self.dataOut.heightList[-20:])
43 #print(numpy.shape(self.dataOut.data))
52 #print(numpy.shape(self.dataOut.data))
44 #print(self.dataOut.code)
53 #print(self.dataOut.code)
45 #print(numpy.shape(self.dataOut.code))
54 #print(numpy.shape(self.dataOut.code))
46 #exit(1)
55 #exit(1)
47 #print(self.dataOut.CurrentBlock)
56 #print(self.dataOut.CurrentBlock)
48 #print(self.dataOut.data[0,:,0])
57 #print(self.dataOut.data[0,:,0])
49
58
50 #print(numpy.shape(self.dataOut.data))
59 #print(numpy.shape(self.dataOut.data))
51 #print(self.dataOut.data[0,:,1666:1666+320])
60 #print(self.dataOut.data[0,:,1666:1666+320])
52 #exit(1)
61 #exit(1)
53
62
54 #print(self.dataOut.utctime)
63 #print(self.dataOut.utctime)
55 #self.dataOut.test+=1
64 #self.dataOut.test+=1
56
65
57
66
58 def __updateObjFromAmisrInput(self):
67 def __updateObjFromAmisrInput(self):
59
68
60 self.dataOut.timeZone = self.dataIn.timeZone
69 self.dataOut.timeZone = self.dataIn.timeZone
61 self.dataOut.dstFlag = self.dataIn.dstFlag
70 self.dataOut.dstFlag = self.dataIn.dstFlag
62 self.dataOut.errorCount = self.dataIn.errorCount
71 self.dataOut.errorCount = self.dataIn.errorCount
63 self.dataOut.useLocalTime = self.dataIn.useLocalTime
72 self.dataOut.useLocalTime = self.dataIn.useLocalTime
64
73
65 self.dataOut.flagNoData = self.dataIn.flagNoData
74 self.dataOut.flagNoData = self.dataIn.flagNoData
66 self.dataOut.data = self.dataIn.data
75 self.dataOut.data = self.dataIn.data
67 self.dataOut.utctime = self.dataIn.utctime
76 self.dataOut.utctime = self.dataIn.utctime
68 self.dataOut.channelList = self.dataIn.channelList
77 self.dataOut.channelList = self.dataIn.channelList
69 #self.dataOut.timeInterval = self.dataIn.timeInterval
78 #self.dataOut.timeInterval = self.dataIn.timeInterval
70 self.dataOut.heightList = self.dataIn.heightList
79 self.dataOut.heightList = self.dataIn.heightList
71 self.dataOut.nProfiles = self.dataIn.nProfiles
80 self.dataOut.nProfiles = self.dataIn.nProfiles
72
81
73 self.dataOut.nCohInt = self.dataIn.nCohInt
82 self.dataOut.nCohInt = self.dataIn.nCohInt
74 self.dataOut.ippSeconds = self.dataIn.ippSeconds
83 self.dataOut.ippSeconds = self.dataIn.ippSeconds
75 self.dataOut.frequency = self.dataIn.frequency
84 self.dataOut.frequency = self.dataIn.frequency
76
85
77 self.dataOut.azimuth = self.dataIn.azimuth
86 self.dataOut.azimuth = self.dataIn.azimuth
78 self.dataOut.zenith = self.dataIn.zenith
87 self.dataOut.zenith = self.dataIn.zenith
79
88
80 self.dataOut.beam.codeList = self.dataIn.beam.codeList
89 self.dataOut.beam.codeList = self.dataIn.beam.codeList
81 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
90 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
82 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
91 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
83
92
84 class selectChannels(Operation):
93 class selectChannels(Operation):
85
94
86 def run(self, dataOut, channelList):
95 def run(self, dataOut, channelList):
87
96
88
97
89
98
90
99
91 channelIndexList = []
100 channelIndexList = []
92 self.dataOut = dataOut
101 self.dataOut = dataOut
93 for channel in channelList:
102 for channel in channelList:
94 if channel not in self.dataOut.channelList:
103 if channel not in self.dataOut.channelList:
95 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
104 raise ValueError("Channel %d is not in %s" %(channel, str(self.dataOut.channelList)))
96
105
97 index = self.dataOut.channelList.index(channel)
106 index = self.dataOut.channelList.index(channel)
98 channelIndexList.append(index)
107 channelIndexList.append(index)
99 self.selectChannelsByIndex(channelIndexList)
108 self.selectChannelsByIndex(channelIndexList)
100
109
101 return self.dataOut
110 return self.dataOut
102
111
103
112
104 def selectChannelsByIndex(self, channelIndexList):
113 def selectChannelsByIndex(self, channelIndexList):
105 """
114 """
106 Selecciona un bloque de datos en base a canales segun el channelIndexList
115 Selecciona un bloque de datos en base a canales segun el channelIndexList
107
116
108 Input:
117 Input:
109 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
118 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
110
119
111 Affected:
120 Affected:
112 self.dataOut.data
121 self.dataOut.data
113 self.dataOut.channelIndexList
122 self.dataOut.channelIndexList
114 self.dataOut.nChannels
123 self.dataOut.nChannels
115 self.dataOut.m_ProcessingHeader.totalSpectra
124 self.dataOut.m_ProcessingHeader.totalSpectra
116 self.dataOut.systemHeaderObj.numChannels
125 self.dataOut.systemHeaderObj.numChannels
117 self.dataOut.m_ProcessingHeader.blockSize
126 self.dataOut.m_ProcessingHeader.blockSize
118
127
119 Return:
128 Return:
120 None
129 None
121 """
130 """
122
131
123 for channelIndex in channelIndexList:
132 for channelIndex in channelIndexList:
124 if channelIndex not in self.dataOut.channelIndexList:
133 if channelIndex not in self.dataOut.channelIndexList:
125 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
134 raise ValueError("The value %d in channelIndexList is not valid" %channelIndex)
126
135
127 if self.dataOut.type == 'Voltage':
136 if self.dataOut.type == 'Voltage':
128 if self.dataOut.flagDataAsBlock:
137 if self.dataOut.flagDataAsBlock:
129 """
138 """
130 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
139 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
131 """
140 """
132 data = self.dataOut.data[channelIndexList,:,:]
141 data = self.dataOut.data[channelIndexList,:,:]
133 else:
142 else:
134 data = self.dataOut.data[channelIndexList,:]
143 data = self.dataOut.data[channelIndexList,:]
135
144
136 self.dataOut.data = data
145 self.dataOut.data = data
137 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
146 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
138 self.dataOut.channelList = range(len(channelIndexList))
147 self.dataOut.channelList = range(len(channelIndexList))
139
148
140 elif self.dataOut.type == 'Spectra':
149 elif self.dataOut.type == 'Spectra':
141 data_spc = self.dataOut.data_spc[channelIndexList, :]
150 data_spc = self.dataOut.data_spc[channelIndexList, :]
142 data_dc = self.dataOut.data_dc[channelIndexList, :]
151 data_dc = self.dataOut.data_dc[channelIndexList, :]
143
152
144 self.dataOut.data_spc = data_spc
153 self.dataOut.data_spc = data_spc
145 self.dataOut.data_dc = data_dc
154 self.dataOut.data_dc = data_dc
146
155
147 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
156 # self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
148 self.dataOut.channelList = range(len(channelIndexList))
157 self.dataOut.channelList = range(len(channelIndexList))
149 self.__selectPairsByChannel(channelIndexList)
158 self.__selectPairsByChannel(channelIndexList)
150
159
151 return 1
160 return 1
152
161
153 def __selectPairsByChannel(self, channelList=None):
162 def __selectPairsByChannel(self, channelList=None):
154
163
155 if channelList == None:
164 if channelList == None:
156 return
165 return
157
166
158 pairsIndexListSelected = []
167 pairsIndexListSelected = []
159 for pairIndex in self.dataOut.pairsIndexList:
168 for pairIndex in self.dataOut.pairsIndexList:
160 # First pair
169 # First pair
161 if self.dataOut.pairsList[pairIndex][0] not in channelList:
170 if self.dataOut.pairsList[pairIndex][0] not in channelList:
162 continue
171 continue
163 # Second pair
172 # Second pair
164 if self.dataOut.pairsList[pairIndex][1] not in channelList:
173 if self.dataOut.pairsList[pairIndex][1] not in channelList:
165 continue
174 continue
166
175
167 pairsIndexListSelected.append(pairIndex)
176 pairsIndexListSelected.append(pairIndex)
168
177
169 if not pairsIndexListSelected:
178 if not pairsIndexListSelected:
170 self.dataOut.data_cspc = None
179 self.dataOut.data_cspc = None
171 self.dataOut.pairsList = []
180 self.dataOut.pairsList = []
172 return
181 return
173
182
174 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
183 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
175 self.dataOut.pairsList = [self.dataOut.pairsList[i]
184 self.dataOut.pairsList = [self.dataOut.pairsList[i]
176 for i in pairsIndexListSelected]
185 for i in pairsIndexListSelected]
177
186
178 return
187 return
179
188
180 class selectHeights(Operation):
189 class selectHeights(Operation):
181
190
182 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
191 def run(self, dataOut, minHei=None, maxHei=None, minIndex=None, maxIndex=None):
183 """
192 """
184 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
193 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
185 minHei <= height <= maxHei
194 minHei <= height <= maxHei
186
195
187 Input:
196 Input:
188 minHei : valor minimo de altura a considerar
197 minHei : valor minimo de altura a considerar
189 maxHei : valor maximo de altura a considerar
198 maxHei : valor maximo de altura a considerar
190
199
191 Affected:
200 Affected:
192 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
201 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
193
202
194 Return:
203 Return:
195 1 si el metodo se ejecuto con exito caso contrario devuelve 0
204 1 si el metodo se ejecuto con exito caso contrario devuelve 0
196 """
205 """
197
206
198 self.dataOut = dataOut
207 self.dataOut = dataOut
199
208
200 if minHei and maxHei:
209 if minHei and maxHei:
201
210
202 if (minHei < self.dataOut.heightList[0]):
211 if (minHei < self.dataOut.heightList[0]):
203 minHei = self.dataOut.heightList[0]
212 minHei = self.dataOut.heightList[0]
204
213
205 if (maxHei > self.dataOut.heightList[-1]):
214 if (maxHei > self.dataOut.heightList[-1]):
206 maxHei = self.dataOut.heightList[-1]
215 maxHei = self.dataOut.heightList[-1]
207
216
208 minIndex = 0
217 minIndex = 0
209 maxIndex = 0
218 maxIndex = 0
210 heights = self.dataOut.heightList
219 heights = self.dataOut.heightList
211
220
212 inda = numpy.where(heights >= minHei)
221 inda = numpy.where(heights >= minHei)
213 indb = numpy.where(heights <= maxHei)
222 indb = numpy.where(heights <= maxHei)
214
223
215 try:
224 try:
216 minIndex = inda[0][0]
225 minIndex = inda[0][0]
217 except:
226 except:
218 minIndex = 0
227 minIndex = 0
219
228
220 try:
229 try:
221 maxIndex = indb[0][-1]
230 maxIndex = indb[0][-1]
222 except:
231 except:
223 maxIndex = len(heights)
232 maxIndex = len(heights)
224
233
225 self.selectHeightsByIndex(minIndex, maxIndex)
234 self.selectHeightsByIndex(minIndex, maxIndex)
226 #print(self.dataOut.nHeights)
235 #print(self.dataOut.nHeights)
227
236
228
237
229 return self.dataOut
238 return self.dataOut
230
239
231 def selectHeightsByIndex(self, minIndex, maxIndex):
240 def selectHeightsByIndex(self, minIndex, maxIndex):
232 """
241 """
233 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
242 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
234 minIndex <= index <= maxIndex
243 minIndex <= index <= maxIndex
235
244
236 Input:
245 Input:
237 minIndex : valor de indice minimo de altura a considerar
246 minIndex : valor de indice minimo de altura a considerar
238 maxIndex : valor de indice maximo de altura a considerar
247 maxIndex : valor de indice maximo de altura a considerar
239
248
240 Affected:
249 Affected:
241 self.dataOut.data
250 self.dataOut.data
242 self.dataOut.heightList
251 self.dataOut.heightList
243
252
244 Return:
253 Return:
245 1 si el metodo se ejecuto con exito caso contrario devuelve 0
254 1 si el metodo se ejecuto con exito caso contrario devuelve 0
246 """
255 """
247
256
248 if self.dataOut.type == 'Voltage':
257 if self.dataOut.type == 'Voltage':
249 if (minIndex < 0) or (minIndex > maxIndex):
258 if (minIndex < 0) or (minIndex > maxIndex):
250 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
259 raise ValueError("Height index range (%d,%d) is not valid" % (minIndex, maxIndex))
251
260
252 if (maxIndex >= self.dataOut.nHeights):
261 if (maxIndex >= self.dataOut.nHeights):
253 maxIndex = self.dataOut.nHeights
262 maxIndex = self.dataOut.nHeights
254
263
255 #voltage
264 #voltage
256 if self.dataOut.flagDataAsBlock:
265 if self.dataOut.flagDataAsBlock:
257 """
266 """
258 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
267 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
259 """
268 """
260 data = self.dataOut.data[:,:, minIndex:maxIndex]
269 data = self.dataOut.data[:,:, minIndex:maxIndex]
261 else:
270 else:
262 data = self.dataOut.data[:, minIndex:maxIndex]
271 data = self.dataOut.data[:, minIndex:maxIndex]
263
272
264 # firstHeight = self.dataOut.heightList[minIndex]
273 # firstHeight = self.dataOut.heightList[minIndex]
265
274
266 self.dataOut.data = data
275 self.dataOut.data = data
267 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
276 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex]
268
277
269 if self.dataOut.nHeights <= 1:
278 if self.dataOut.nHeights <= 1:
270 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
279 raise ValueError("selectHeights: Too few heights. Current number of heights is %d" %(self.dataOut.nHeights))
271 elif self.dataOut.type == 'Spectra':
280 elif self.dataOut.type == 'Spectra':
272 if (minIndex < 0) or (minIndex > maxIndex):
281 if (minIndex < 0) or (minIndex > maxIndex):
273 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
282 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (
274 minIndex, maxIndex))
283 minIndex, maxIndex))
275
284
276 if (maxIndex >= self.dataOut.nHeights):
285 if (maxIndex >= self.dataOut.nHeights):
277 maxIndex = self.dataOut.nHeights - 1
286 maxIndex = self.dataOut.nHeights - 1
278
287
279 # Spectra
288 # Spectra
280 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
289 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
281
290
282 data_cspc = None
291 data_cspc = None
283 if self.dataOut.data_cspc is not None:
292 if self.dataOut.data_cspc is not None:
284 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
293 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
285
294
286 data_dc = None
295 data_dc = None
287 if self.dataOut.data_dc is not None:
296 if self.dataOut.data_dc is not None:
288 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
297 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
289
298
290 self.dataOut.data_spc = data_spc
299 self.dataOut.data_spc = data_spc
291 self.dataOut.data_cspc = data_cspc
300 self.dataOut.data_cspc = data_cspc
292 self.dataOut.data_dc = data_dc
301 self.dataOut.data_dc = data_dc
293
302
294 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
303 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
295
304
296 return 1
305 return 1
297
306
298
307
299 class filterByHeights(Operation):
308 class filterByHeights(Operation):
300
309
301 def run(self, dataOut, window):
310 def run(self, dataOut, window):
302
311
303 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
312 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
304
313
305 if window == None:
314 if window == None:
306 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
315 window = (dataOut.radarControllerHeaderObj.txA/dataOut.radarControllerHeaderObj.nBaud) / deltaHeight
307
316
308 newdelta = deltaHeight * window
317 newdelta = deltaHeight * window
309 r = dataOut.nHeights % window
318 r = dataOut.nHeights % window
310 newheights = (dataOut.nHeights-r)/window
319 newheights = (dataOut.nHeights-r)/window
311
320
312 if newheights <= 1:
321 if newheights <= 1:
313 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
322 raise ValueError("filterByHeights: Too few heights. Current number of heights is %d and window is %d" %(dataOut.nHeights, window))
314
323
315 if dataOut.flagDataAsBlock:
324 if dataOut.flagDataAsBlock:
316 """
325 """
317 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
326 Si la data es obtenida por bloques, dimension = [nChannels, nProfiles, nHeis]
318 """
327 """
319 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
328 buffer = dataOut.data[:, :, 0:int(dataOut.nHeights-r)]
320 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
329 buffer = buffer.reshape(dataOut.nChannels, dataOut.nProfiles, int(dataOut.nHeights/window), window)
321 buffer = numpy.sum(buffer,3)
330 buffer = numpy.sum(buffer,3)
322
331
323 else:
332 else:
324 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
333 buffer = dataOut.data[:,0:int(dataOut.nHeights-r)]
325 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
334 buffer = buffer.reshape(dataOut.nChannels,int(dataOut.nHeights/window),int(window))
326 buffer = numpy.sum(buffer,2)
335 buffer = numpy.sum(buffer,2)
327
336
328 dataOut.data = buffer
337 dataOut.data = buffer
329 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
338 dataOut.heightList = dataOut.heightList[0] + numpy.arange( newheights )*newdelta
330 dataOut.windowOfFilter = window
339 dataOut.windowOfFilter = window
331
340
332 return dataOut
341 return dataOut
333
342
334
343
335 class setH0(Operation):
344 class setH0(Operation):
336
345
337 def run(self, dataOut, h0, deltaHeight = None):
346 def run(self, dataOut, h0, deltaHeight = None):
338
347
339 if not deltaHeight:
348 if not deltaHeight:
340 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
349 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
341
350
342 nHeights = dataOut.nHeights
351 nHeights = dataOut.nHeights
343
352
344 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
353 newHeiRange = h0 + numpy.arange(nHeights)*deltaHeight
345
354
346 dataOut.heightList = newHeiRange
355 dataOut.heightList = newHeiRange
347
356
348 return dataOut
357 return dataOut
349
358
350
359
351 class deFlip(Operation):
360 class deFlip(Operation):
352 def __init__(self):
361 def __init__(self):
353
362
354 self.flip = 1
363 self.flip = 1
355
364
356 def run(self, dataOut, channelList = []):
365 def run(self, dataOut, channelList = []):
357
366
358 data = dataOut.data.copy()
367 data = dataOut.data.copy()
359 #print(dataOut.channelList)
368 #print(dataOut.channelList)
360 #exit()
369 #exit()
361
370
362 if channelList==1: #PARCHE
371 if channelList==1: #PARCHE
363 channelList=[1]
372 channelList=[1]
364
373
365
374
366 dataOut.FlipChannels=channelList
375 dataOut.FlipChannels=channelList
367 if dataOut.flagDataAsBlock:
376 if dataOut.flagDataAsBlock:
368 flip = self.flip
377 flip = self.flip
369 profileList = list(range(dataOut.nProfiles))
378 profileList = list(range(dataOut.nProfiles))
370
379
371 if not channelList:
380 if not channelList:
372 for thisProfile in profileList:
381 for thisProfile in profileList:
373 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
382 data[:,thisProfile,:] = data[:,thisProfile,:]*flip
374 flip *= -1.0
383 flip *= -1.0
375 else:
384 else:
376 for thisChannel in channelList:
385 for thisChannel in channelList:
377 if thisChannel not in dataOut.channelList:
386 if thisChannel not in dataOut.channelList:
378 continue
387 continue
379
388
380 for thisProfile in profileList:
389 for thisProfile in profileList:
381 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
390 data[thisChannel,thisProfile,:] = data[thisChannel,thisProfile,:]*flip
382 flip *= -1.0
391 flip *= -1.0
383
392
384 self.flip = flip
393 self.flip = flip
385
394
386
395
387
396
388
397
389 else:
398 else:
390 if not channelList:
399 if not channelList:
391 data[:,:] = data[:,:]*self.flip
400 data[:,:] = data[:,:]*self.flip
392 else:
401 else:
393 channelList=[1]
402 channelList=[1]
394 #print(self.flip)
403 #print(self.flip)
395 for thisChannel in channelList:
404 for thisChannel in channelList:
396 if thisChannel not in dataOut.channelList:
405 if thisChannel not in dataOut.channelList:
397 continue
406 continue
398
407
399 data[thisChannel,:] = data[thisChannel,:]*self.flip
408 data[thisChannel,:] = data[thisChannel,:]*self.flip
400
409
401 self.flip *= -1.
410 self.flip *= -1.
402
411
403
412
404 dataOut.data = data
413 dataOut.data = data
405
414
406 return dataOut
415 return dataOut
407
416
408
417
409 class setAttribute(Operation):
418 class setAttribute(Operation):
410 '''
419 '''
411 Set an arbitrary attribute(s) to dataOut
420 Set an arbitrary attribute(s) to dataOut
412 '''
421 '''
413
422
414 def __init__(self):
423 def __init__(self):
415
424
416 Operation.__init__(self)
425 Operation.__init__(self)
417 self._ready = False
426 self._ready = False
418
427
419 def run(self, dataOut, **kwargs):
428 def run(self, dataOut, **kwargs):
420
429
421 for key, value in kwargs.items():
430 for key, value in kwargs.items():
422 setattr(dataOut, key, value)
431 setattr(dataOut, key, value)
423
432
424 return dataOut
433 return dataOut
425
434
426
435
427 @MPDecorator
436 @MPDecorator
428 class printAttribute(Operation):
437 class printAttribute(Operation):
429 '''
438 '''
430 Print an arbitrary attribute of dataOut
439 Print an arbitrary attribute of dataOut
431 '''
440 '''
432
441
433 def __init__(self):
442 def __init__(self):
434
443
435 Operation.__init__(self)
444 Operation.__init__(self)
436
445
437 def run(self, dataOut, attributes):
446 def run(self, dataOut, attributes):
438
447
439 if isinstance(attributes, str):
448 if isinstance(attributes, str):
440 attributes = [attributes]
449 attributes = [attributes]
441 for attr in attributes:
450 for attr in attributes:
442 if hasattr(dataOut, attr):
451 if hasattr(dataOut, attr):
443 log.log(getattr(dataOut, attr), attr)
452 log.log(getattr(dataOut, attr), attr)
444
453
445
454
446 class interpolateHeights(Operation):
455 class interpolateHeights(Operation):
447
456
448 def run(self, dataOut, topLim, botLim):
457 def run(self, dataOut, topLim, botLim):
449 #69 al 72 para julia
458 #69 al 72 para julia
450 #82-84 para meteoros
459 #82-84 para meteoros
451 if len(numpy.shape(dataOut.data))==2:
460 if len(numpy.shape(dataOut.data))==2:
452 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
461 sampInterp = (dataOut.data[:,botLim-1] + dataOut.data[:,topLim+1])/2
453 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
462 sampInterp = numpy.transpose(numpy.tile(sampInterp,(topLim-botLim + 1,1)))
454 #dataOut.data[:,botLim:limSup+1] = sampInterp
463 #dataOut.data[:,botLim:limSup+1] = sampInterp
455 dataOut.data[:,botLim:topLim+1] = sampInterp
464 dataOut.data[:,botLim:topLim+1] = sampInterp
456 else:
465 else:
457 nHeights = dataOut.data.shape[2]
466 nHeights = dataOut.data.shape[2]
458 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
467 x = numpy.hstack((numpy.arange(botLim),numpy.arange(topLim+1,nHeights)))
459 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
468 y = dataOut.data[:,:,list(range(botLim))+list(range(topLim+1,nHeights))]
460 f = interpolate.interp1d(x, y, axis = 2)
469 f = interpolate.interp1d(x, y, axis = 2)
461 xnew = numpy.arange(botLim,topLim+1)
470 xnew = numpy.arange(botLim,topLim+1)
462 ynew = f(xnew)
471 ynew = f(xnew)
463 dataOut.data[:,:,botLim:topLim+1] = ynew
472 dataOut.data[:,:,botLim:topLim+1] = ynew
464
473
465 return dataOut
474 return dataOut
466
475
467
476
468 class LagsReshape(Operation):
477 class LagsReshape(Operation):
469 """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction.
478 """Operation to reshape input data into (Channels,Profiles(with same lag),Heights,Lags) and heights reconstruction.
470
479
471 Parameters:
480 Parameters:
472 -----------
481 -----------
473
482
474
483
475 Example
484 Example
476 --------
485 --------
477
486
478 op = proc_unit.addOperation(name='LagsReshape')
487 op = proc_unit.addOperation(name='LagsReshape')
479
488
480
489
481 """
490 """
482
491
483 def __init__(self, **kwargs):
492 def __init__(self, **kwargs):
484
493
485 Operation.__init__(self, **kwargs)
494 Operation.__init__(self, **kwargs)
486
495
487 self.buffer=None
496 self.buffer=None
488 self.buffer_HR=None
497 self.buffer_HR=None
489 self.buffer_HRonelag=None
498 self.buffer_HRonelag=None
490
499
491 def LagDistribution(self,dataOut):
500 def LagDistribution(self,dataOut):
492
501
493 dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:])
502 dataOut.datapure=numpy.copy(dataOut.data[:,0:dataOut.NSCAN,:])
494 self.buffer = numpy.zeros((dataOut.nChannels,
503 self.buffer = numpy.zeros((dataOut.nChannels,
495 int(dataOut.NSCAN/dataOut.DPL),
504 int(dataOut.NSCAN/dataOut.DPL),
496 dataOut.nHeights,dataOut.DPL),
505 dataOut.nHeights,dataOut.DPL),
497 dtype='complex')
506 dtype='complex')
498
507
499 for j in range(int(self.buffer.shape[1]/2)):
508 for j in range(int(self.buffer.shape[1]/2)):
500 for i in range(dataOut.DPL):
509 for i in range(dataOut.DPL):
501 if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL:
510 if j+1==int(self.buffer.shape[1]/2) and i+1==dataOut.DPL:
502 self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:]
511 self.buffer[:,2*j:,:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):,:]
503 else:
512 else:
504 self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:]
513 self.buffer[:,2*j:2*(j+1),:,i]=dataOut.datapure[:,2*i+int(2*j*dataOut.DPL):2*(i+1)+int(2*j*dataOut.DPL),:]
505
514
506 return self.buffer
515 return self.buffer
507
516
508 def HeightReconstruction(self,dataOut):
517 def HeightReconstruction(self,dataOut):
509
518
510 self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
519 self.buffer_HR = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
511 dataOut.nHeights,dataOut.DPL),
520 dataOut.nHeights,dataOut.DPL),
512 dtype='complex')
521 dtype='complex')
513
522
514 #self.buffer_HR[0,:,:,:]=dataOut.datalags[0,:,:,:] #No Lags
523 #self.buffer_HR[0,:,:,:]=dataOut.datalags[0,:,:,:] #No Lags
515
524
516 for i in range(int(dataOut.DPL)): #Only channel B
525 for i in range(int(dataOut.DPL)): #Only channel B
517 if i==0:
526 if i==0:
518 self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i]
527 self.buffer_HR[:,:,i]=dataOut.datalags[1,:,:,i]
519 else:
528 else:
520 self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i)
529 self.buffer_HR[:,:,i]=self.HRonelag(dataOut,i)
521
530
522 return self.buffer_HR
531 return self.buffer_HR
523
532
524
533
525 def HRonelag(self,dataOut,whichlag):
534 def HRonelag(self,dataOut,whichlag):
526 self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
535 self.buffer_HRonelag = numpy.zeros((int(dataOut.NSCAN/dataOut.DPL),
527 dataOut.nHeights),
536 dataOut.nHeights),
528 dtype='complex')
537 dtype='complex')
529
538
530 for i in range(self.buffer_HRonelag.shape[0]):
539 for i in range(self.buffer_HRonelag.shape[0]):
531 for j in range(dataOut.nHeights):
540 for j in range(dataOut.nHeights):
532 if j+int(2*whichlag)<dataOut.nHeights:
541 if j+int(2*whichlag)<dataOut.nHeights:
533 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag]
542 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,j+2*whichlag,whichlag]
534 else:
543 else:
535 if whichlag!=10:
544 if whichlag!=10:
536 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1]
545 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag+1]
537 else:
546 else:
538 if i+2<self.buffer_HRonelag.shape[0]:
547 if i+2<self.buffer_HRonelag.shape[0]:
539 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0]
548 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i+2,(j+2*whichlag)%dataOut.nHeights,0]
540 else: #i+1==self.buffer_HRonelag.shape[0]:
549 else: #i+1==self.buffer_HRonelag.shape[0]:
541 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag]
550 self.buffer_HRonelag[i,j]=dataOut.datalags[1,i,(j+2*whichlag)%dataOut.nHeights,whichlag]
542
551
543 return self.buffer_HRonelag
552 return self.buffer_HRonelag
544
553
545
554
546
555
547 def run(self,dataOut,DPL=11,NSCAN=132):
556 def run(self,dataOut,DPL=11,NSCAN=132):
548
557
549 dataOut.DPL=DPL
558 dataOut.DPL=DPL
550 dataOut.NSCAN=NSCAN
559 dataOut.NSCAN=NSCAN
551 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
560 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
552 dataOut.lat=-11.95
561 dataOut.lat=-11.95
553 dataOut.lon=-76.87
562 dataOut.lon=-76.87
554 dataOut.datalags=None
563 dataOut.datalags=None
555 #print(dataOut.NSCAN)
564 #print(dataOut.NSCAN)
556
565
557 dataOut.datalags=numpy.copy(self.LagDistribution(dataOut))
566 dataOut.datalags=numpy.copy(self.LagDistribution(dataOut))
558 dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut)
567 dataOut.datalags[1,:,:,:]=self.HeightReconstruction(dataOut)
559
568
560 return dataOut
569 return dataOut
561
570
562
571
563
572
564
573
565 class CrossProdDP(Operation):
574 class CrossProdDP(Operation):
566 """Operation to calculate cross products of the Double Pulse Experiment.
575 """Operation to calculate cross products of the Double Pulse Experiment.
567
576
568 Parameters:
577 Parameters:
569 -----------
578 -----------
570 NLAG : int
579 NLAG : int
571 Number of lags Long Pulse.
580 Number of lags Long Pulse.
572 NRANGE : int
581 NRANGE : int
573 Number of samples for Long Pulse.
582 Number of samples for Long Pulse.
574 NCAL : int
583 NCAL : int
575 .*
584 .*
576 DPL : int
585 DPL : int
577 Number of lags Double Pulse.
586 Number of lags Double Pulse.
578 NDN : int
587 NDN : int
579 .*
588 .*
580 NDT : int
589 NDT : int
581 Number of heights for Double Pulse.*
590 Number of heights for Double Pulse.*
582 NDP : int
591 NDP : int
583 Number of heights for Double Pulse.*
592 Number of heights for Double Pulse.*
584 NSCAN : int
593 NSCAN : int
585 Number of profiles when the transmitter is on.
594 Number of profiles when the transmitter is on.
586 flags_array : intlist
595 flags_array : intlist
587 .*
596 .*
588 NAVG : int
597 NAVG : int
589 Number of blocks to be "averaged".
598 Number of blocks to be "averaged".
590 nkill : int
599 nkill : int
591 Number of blocks not to be considered when averaging.
600 Number of blocks not to be considered when averaging.
592
601
593 Example
602 Example
594 --------
603 --------
595
604
596 op = proc_unit.addOperation(name='CrossProdDP', optype='other')
605 op = proc_unit.addOperation(name='CrossProdDP', optype='other')
597 op.addParameter(name='NLAG', value='16', format='int')
606 op.addParameter(name='NLAG', value='16', format='int')
598 op.addParameter(name='NRANGE', value='0', format='int')
607 op.addParameter(name='NRANGE', value='0', format='int')
599 op.addParameter(name='NCAL', value='0', format='int')
608 op.addParameter(name='NCAL', value='0', format='int')
600 op.addParameter(name='DPL', value='11', format='int')
609 op.addParameter(name='DPL', value='11', format='int')
601 op.addParameter(name='NDN', value='0', format='int')
610 op.addParameter(name='NDN', value='0', format='int')
602 op.addParameter(name='NDT', value='66', format='int')
611 op.addParameter(name='NDT', value='66', format='int')
603 op.addParameter(name='NDP', value='66', format='int')
612 op.addParameter(name='NDP', value='66', format='int')
604 op.addParameter(name='NSCAN', value='132', format='int')
613 op.addParameter(name='NSCAN', value='132', format='int')
605 op.addParameter(name='flags_array', value='(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)', format='intlist')
614 op.addParameter(name='flags_array', value='(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300)', format='intlist')
606 op.addParameter(name='NAVG', value='16', format='int')
615 op.addParameter(name='NAVG', value='16', format='int')
607 op.addParameter(name='nkill', value='6', format='int')
616 op.addParameter(name='nkill', value='6', format='int')
608
617
609 """
618 """
610
619
611 def __init__(self, **kwargs):
620 def __init__(self, **kwargs):
612
621
613 Operation.__init__(self, **kwargs)
622 Operation.__init__(self, **kwargs)
614 self.bcounter=0
623 self.bcounter=0
615 self.aux=1
624 self.aux=1
616 self.lag_products_LP_median_estimates_aux=0
625 self.lag_products_LP_median_estimates_aux=0
617
626
618 def set_header_output(self,dataOut):
627 def set_header_output(self,dataOut):
619
628
620 dataOut.read_samples=len(dataOut.heightList)#int(dataOut.systemHeaderObj.nSamples/dataOut.windowOfFilter)
629 dataOut.read_samples=len(dataOut.heightList)#int(dataOut.systemHeaderObj.nSamples/dataOut.windowOfFilter)
621 padding=numpy.zeros(1,'int32')
630 padding=numpy.zeros(1,'int32')
622 hsize=numpy.zeros(1,'int32')
631 hsize=numpy.zeros(1,'int32')
623 bufsize=numpy.zeros(1,'int32')
632 bufsize=numpy.zeros(1,'int32')
624 nr=numpy.zeros(1,'int32')
633 nr=numpy.zeros(1,'int32')
625 ngates=numpy.zeros(1,'int32') ### ### ### 2
634 ngates=numpy.zeros(1,'int32') ### ### ### 2
626 time1=numpy.zeros(1,'uint64') # pos 3
635 time1=numpy.zeros(1,'uint64') # pos 3
627 time2=numpy.zeros(1,'uint64') # pos 4
636 time2=numpy.zeros(1,'uint64') # pos 4
628 lcounter=numpy.zeros(1,'int32')
637 lcounter=numpy.zeros(1,'int32')
629 groups=numpy.zeros(1,'int32')
638 groups=numpy.zeros(1,'int32')
630 system=numpy.zeros(4,'int8') # pos 7
639 system=numpy.zeros(4,'int8') # pos 7
631 h0=numpy.zeros(1,'float32')
640 h0=numpy.zeros(1,'float32')
632 dh=numpy.zeros(1,'float32')
641 dh=numpy.zeros(1,'float32')
633 ipp=numpy.zeros(1,'float32')
642 ipp=numpy.zeros(1,'float32')
634 process=numpy.zeros(1,'int32')
643 process=numpy.zeros(1,'int32')
635 tx=numpy.zeros(1,'int32')
644 tx=numpy.zeros(1,'int32')
636 ngates1=numpy.zeros(1,'int32') ### ### ### 13
645 ngates1=numpy.zeros(1,'int32') ### ### ### 13
637 time0=numpy.zeros(1,'uint64') # pos 14
646 time0=numpy.zeros(1,'uint64') # pos 14
638 nlags=numpy.zeros(1,'int32')
647 nlags=numpy.zeros(1,'int32')
639 nlags1=numpy.zeros(1,'int32')
648 nlags1=numpy.zeros(1,'int32')
640 txb=numpy.zeros(1,'float32') ### ### ### 17
649 txb=numpy.zeros(1,'float32') ### ### ### 17
641 time3=numpy.zeros(1,'uint64') # pos 18
650 time3=numpy.zeros(1,'uint64') # pos 18
642 time4=numpy.zeros(1,'uint64') # pos 19
651 time4=numpy.zeros(1,'uint64') # pos 19
643 h0_=numpy.zeros(1,'float32')
652 h0_=numpy.zeros(1,'float32')
644 dh_=numpy.zeros(1,'float32')
653 dh_=numpy.zeros(1,'float32')
645 ipp_=numpy.zeros(1,'float32')
654 ipp_=numpy.zeros(1,'float32')
646 txa_=numpy.zeros(1,'float32')
655 txa_=numpy.zeros(1,'float32')
647 pad=numpy.zeros(100,'int32')
656 pad=numpy.zeros(100,'int32')
648 nbytes=numpy.zeros(1,'int32')
657 nbytes=numpy.zeros(1,'int32')
649 limits=numpy.zeros(1,'int32')
658 limits=numpy.zeros(1,'int32')
650 ngroups=numpy.zeros(1,'int32') ### ### ### 27
659 ngroups=numpy.zeros(1,'int32') ### ### ### 27
651
660
652 dataOut.header=[hsize,bufsize,nr,ngates,time1,time2,
661 dataOut.header=[hsize,bufsize,nr,ngates,time1,time2,
653 lcounter,groups,system,h0,dh,ipp,
662 lcounter,groups,system,h0,dh,ipp,
654 process,tx,ngates1,padding,time0,nlags,
663 process,tx,ngates1,padding,time0,nlags,
655 nlags1,padding,txb,time3,time4,h0_,dh_,
664 nlags1,padding,txb,time3,time4,h0_,dh_,
656 ipp_,txa_,pad,nbytes,limits,padding,ngroups]
665 ipp_,txa_,pad,nbytes,limits,padding,ngroups]
657
666
658
667
659 #dataOut.header[1][0]=81864
668 #dataOut.header[1][0]=81864
660 dataOut.FirstHeight=int(dataOut.heightList[0])
669 dataOut.FirstHeight=int(dataOut.heightList[0])
661 dataOut.MAXNRANGENDT=max(dataOut.NRANGE,dataOut.NDT)
670 dataOut.MAXNRANGENDT=max(dataOut.NRANGE,dataOut.NDT)
662 dataOut.header[3][0]=max(dataOut.NRANGE,dataOut.NDT)
671 dataOut.header[3][0]=max(dataOut.NRANGE,dataOut.NDT)
663 dataOut.header[7][0]=dataOut.NAVG
672 dataOut.header[7][0]=dataOut.NAVG
664 dataOut.header[9][0]=int(dataOut.heightList[0])
673 dataOut.header[9][0]=int(dataOut.heightList[0])
665 dataOut.header[10][0]=dataOut.DH
674 dataOut.header[10][0]=dataOut.DH
666 dataOut.header[17][0]=dataOut.DPL
675 dataOut.header[17][0]=dataOut.DPL
667 dataOut.header[18][0]=dataOut.NLAG
676 dataOut.header[18][0]=dataOut.NLAG
668 #self.header[5][0]=0
677 #self.header[5][0]=0
669 dataOut.header[15][0]=dataOut.NDP
678 dataOut.header[15][0]=dataOut.NDP
670 dataOut.header[2][0]=dataOut.NR
679 dataOut.header[2][0]=dataOut.NR
671
680
672
681
673 def get_products_cabxys(self,dataOut):
682 def get_products_cabxys(self,dataOut):
674
683
675 if self.aux==1:
684 if self.aux==1:
676 self.set_header_output(dataOut)
685 self.set_header_output(dataOut)
677 self.aux=0
686 self.aux=0
678
687
679
688
680 dataOut.lags_array=[x / dataOut.DH for x in dataOut.flags_array]
689 dataOut.lags_array=[x / dataOut.DH for x in dataOut.flags_array]
681 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
690 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
682 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
691 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
683 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
692 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
684 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
693 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
685 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
694 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
686 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
695 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
687 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
696 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
688 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
697 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
689 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
698 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
690 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
699 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
691 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
700 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
692 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
701 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
693 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
702 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
694 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
703 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
695
704
696 for i in range(2):
705 for i in range(2):
697 for j in range(dataOut.NDP):
706 for j in range(dataOut.NDP):
698 for k in range(int(dataOut.NSCAN/2)):
707 for k in range(int(dataOut.NSCAN/2)):
699 n=k%dataOut.DPL
708 n=k%dataOut.DPL
700 ax=dataOut.data[0,2*k+i,j].real
709 ax=dataOut.data[0,2*k+i,j].real
701 ay=dataOut.data[0,2*k+i,j].imag
710 ay=dataOut.data[0,2*k+i,j].imag
702 if j+dataOut.lags_array[n]<dataOut.NDP:
711 if j+dataOut.lags_array[n]<dataOut.NDP:
703 bx=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].real
712 bx=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].real
704 by=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].imag
713 by=dataOut.data[1,2*k+i,j+int(dataOut.lags_array[n])].imag
705 else:
714 else:
706 if k+1<int(dataOut.NSCAN/2):
715 if k+1<int(dataOut.NSCAN/2):
707 bx=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
716 bx=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
708 by=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
717 by=dataOut.data[1,2*(k+1)+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
709
718
710 if k+1==int(dataOut.NSCAN/2):
719 if k+1==int(dataOut.NSCAN/2):
711 bx=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
720 bx=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].real
712 by=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
721 by=dataOut.data[1,2*k+i,(dataOut.NRANGE+dataOut.NCAL+j+int(dataOut.lags_array[n]))%dataOut.NDP].imag
713
722
714 if(k<dataOut.DPL):
723 if(k<dataOut.DPL):
715 self.cax[j][n][i]=ax
724 self.cax[j][n][i]=ax
716 self.cay[j][n][i]=ay
725 self.cay[j][n][i]=ay
717 self.cbx[j][n][i]=bx
726 self.cbx[j][n][i]=bx
718 self.cby[j][n][i]=by
727 self.cby[j][n][i]=by
719 self.cax2[j][n][i]=ax*ax
728 self.cax2[j][n][i]=ax*ax
720 self.cay2[j][n][i]=ay*ay
729 self.cay2[j][n][i]=ay*ay
721 self.cbx2[j][n][i]=bx*bx
730 self.cbx2[j][n][i]=bx*bx
722 self.cby2[j][n][i]=by*by
731 self.cby2[j][n][i]=by*by
723 self.caxbx[j][n][i]=ax*bx
732 self.caxbx[j][n][i]=ax*bx
724 self.caxby[j][n][i]=ax*by
733 self.caxby[j][n][i]=ax*by
725 self.caybx[j][n][i]=ay*bx
734 self.caybx[j][n][i]=ay*bx
726 self.cayby[j][n][i]=ay*by
735 self.cayby[j][n][i]=ay*by
727 self.caxay[j][n][i]=ax*ay
736 self.caxay[j][n][i]=ax*ay
728 self.cbxby[j][n][i]=bx*by
737 self.cbxby[j][n][i]=bx*by
729 else:
738 else:
730 self.cax[j][n][i]+=ax
739 self.cax[j][n][i]+=ax
731 self.cay[j][n][i]+=ay
740 self.cay[j][n][i]+=ay
732 self.cbx[j][n][i]+=bx
741 self.cbx[j][n][i]+=bx
733 self.cby[j][n][i]+=by
742 self.cby[j][n][i]+=by
734 self.cax2[j][n][i]+=ax*ax
743 self.cax2[j][n][i]+=ax*ax
735 self.cay2[j][n][i]+=ay*ay
744 self.cay2[j][n][i]+=ay*ay
736 self.cbx2[j][n][i]+=bx*bx
745 self.cbx2[j][n][i]+=bx*bx
737 self.cby2[j][n][i]+=by*by
746 self.cby2[j][n][i]+=by*by
738 self.caxbx[j][n][i]+=ax*bx
747 self.caxbx[j][n][i]+=ax*bx
739 self.caxby[j][n][i]+=ax*by
748 self.caxby[j][n][i]+=ax*by
740 self.caybx[j][n][i]+=ay*bx
749 self.caybx[j][n][i]+=ay*bx
741 self.cayby[j][n][i]+=ay*by
750 self.cayby[j][n][i]+=ay*by
742 self.caxay[j][n][i]+=ax*ay
751 self.caxay[j][n][i]+=ax*ay
743 self.cbxby[j][n][i]+=bx*by
752 self.cbxby[j][n][i]+=bx*by
744
753
745
754
746 def medi(self,data_navg,NAVG,nkill):
755 def medi(self,data_navg,NAVG,nkill):
747 sorts=sorted(data_navg)
756 sorts=sorted(data_navg)
748 rsorts=numpy.arange(NAVG)
757 rsorts=numpy.arange(NAVG)
749 result=0.0
758 result=0.0
750 for k in range(NAVG):
759 for k in range(NAVG):
751 if k>=nkill/2 and k<NAVG-nkill/2:
760 if k>=nkill/2 and k<NAVG-nkill/2:
752 result+=sorts[k]*float(NAVG)/(float)(NAVG-nkill)
761 result+=sorts[k]*float(NAVG)/(float)(NAVG-nkill)
753 return result
762 return result
754
763
755
764
756 def get_dc(self,dataOut):
765 def get_dc(self,dataOut):
757 if self.bcounter==0:
766 if self.bcounter==0:
758 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
767 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
759 def cabxys_navg(self,dataOut):
768 def cabxys_navg(self,dataOut):
760
769
761
770
762 #dataOut.header[5][0]=mktime(strptime(dataOut.TimeBlockDate))
771 #dataOut.header[5][0]=mktime(strptime(dataOut.TimeBlockDate))
763 dataOut.header[5][0]=dataOut.TimeBlockSeconds
772 dataOut.header[5][0]=dataOut.TimeBlockSeconds
764 #print(dataOut.TimeBlockDate)
773 #print(dataOut.TimeBlockDate)
765 #print(dataOut.utctime)
774 #print(dataOut.utctime)
766 #print(dataOut.datatime)
775 #print(dataOut.datatime)
767 #print(mktime(strptime(dataOut.TimeBlockDate)))
776 #print(mktime(strptime(dataOut.TimeBlockDate)))
768 #print(dataOut.header[5][0])
777 #print(dataOut.header[5][0])
769
778
770 #dataOut.LastAVGDate=mktime(strptime(dataOut.TimeBlockDate))
779 #dataOut.LastAVGDate=mktime(strptime(dataOut.TimeBlockDate))
771 dataOut.LastAVGDate=dataOut.TimeBlockSeconds
780 dataOut.LastAVGDate=dataOut.TimeBlockSeconds
772 #print(dataOut.TimeBlockDate)
781 #print(dataOut.TimeBlockDate)
773 #print(TimeBlockSeconds)
782 #print(TimeBlockSeconds)
774 #input()
783 #input()
775 if self.bcounter==0:
784 if self.bcounter==0:
776 #dataOut.FirstAVGDate=mktime(strptime(dataOut.TimeBlockDate))
785 #dataOut.FirstAVGDate=mktime(strptime(dataOut.TimeBlockDate))
777 dataOut.FirstAVGDate=dataOut.TimeBlockSeconds
786 dataOut.FirstAVGDate=dataOut.TimeBlockSeconds
778 dataOut.header[4][0]=dataOut.header[5][0]#firsttimeofNAVG
787 dataOut.header[4][0]=dataOut.header[5][0]#firsttimeofNAVG
779 if dataOut.CurrentBlock==1:
788 if dataOut.CurrentBlock==1:
780 #dataOut.FirstBlockDate=mktime(strptime(dataOut.TimeBlockDate))
789 #dataOut.FirstBlockDate=mktime(strptime(dataOut.TimeBlockDate))
781 dataOut.FirstBlockDate=dataOut.TimeBlockSeconds
790 dataOut.FirstBlockDate=dataOut.TimeBlockSeconds
782 dataOut.header[16][0]=dataOut.header[5][0]#FirsTimeOfTotalBlocks
791 dataOut.header[16][0]=dataOut.header[5][0]#FirsTimeOfTotalBlocks
783
792
784 self.cax_navg=[]
793 self.cax_navg=[]
785 self.cay_navg=[]
794 self.cay_navg=[]
786 self.cbx_navg=[]
795 self.cbx_navg=[]
787 self.cby_navg=[]
796 self.cby_navg=[]
788 self.cax2_navg=[]
797 self.cax2_navg=[]
789 self.cay2_navg=[]
798 self.cay2_navg=[]
790 self.cbx2_navg=[]
799 self.cbx2_navg=[]
791 self.cby2_navg=[]
800 self.cby2_navg=[]
792 self.caxbx_navg=[]
801 self.caxbx_navg=[]
793 self.caxby_navg=[]
802 self.caxby_navg=[]
794 self.caybx_navg=[]
803 self.caybx_navg=[]
795 self.cayby_navg=[]
804 self.cayby_navg=[]
796 self.caxay_navg=[]
805 self.caxay_navg=[]
797 self.cbxby_navg=[]
806 self.cbxby_navg=[]
798
807
799 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') #30/03/2020
808 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32') #30/03/2020
800
809
801 dataOut.noisevector_=numpy.zeros((dataOut.read_samples,dataOut.NR,dataOut.NAVG),'float32')
810 dataOut.noisevector_=numpy.zeros((dataOut.read_samples,dataOut.NR,dataOut.NAVG),'float32')
802 #dataOut.dc=numpy.zeros(dataOut.NR,dtype=numpy.complex_) #30/03/2020
811 #dataOut.dc=numpy.zeros(dataOut.NR,dtype=numpy.complex_) #30/03/2020
803 #self.dataOut.noisevector=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
812 #self.dataOut.noisevector=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
804 #self.dataOut.noisevector_=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
813 #self.dataOut.noisevector_=numpy.zeros((self.dataOut.read_samples,2,self.dataOut.NAVG),'float32') #31/03/2020
805 #dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
814 #dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
806 #self.dataOut.dc=numpy.zeros(2,dtype=numpy.complex_) #31/03/2020
815 #self.dataOut.dc=numpy.zeros(2,dtype=numpy.complex_) #31/03/2020
807 #self.dataOut.processingHeaderObj.profilesPerBlock
816 #self.dataOut.processingHeaderObj.profilesPerBlock
808
817
809 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
818 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
810
819
811 #print(self.dataOut.noisevector[:,:,:])
820 #print(self.dataOut.noisevector[:,:,:])
812
821
813 self.cax_navg.append(self.cax)
822 self.cax_navg.append(self.cax)
814 self.cay_navg.append(self.cay)
823 self.cay_navg.append(self.cay)
815 self.cbx_navg.append(self.cbx)
824 self.cbx_navg.append(self.cbx)
816 self.cby_navg.append(self.cby)
825 self.cby_navg.append(self.cby)
817 self.cax2_navg.append(self.cax2)
826 self.cax2_navg.append(self.cax2)
818 self.cay2_navg.append(self.cay2)
827 self.cay2_navg.append(self.cay2)
819 self.cbx2_navg.append(self.cbx2)
828 self.cbx2_navg.append(self.cbx2)
820 self.cby2_navg.append(self.cby2)
829 self.cby2_navg.append(self.cby2)
821 self.caxbx_navg.append(self.caxbx)
830 self.caxbx_navg.append(self.caxbx)
822 self.caxby_navg.append(self.caxby)
831 self.caxby_navg.append(self.caxby)
823 self.caybx_navg.append(self.caybx)
832 self.caybx_navg.append(self.caybx)
824 self.cayby_navg.append(self.cayby)
833 self.cayby_navg.append(self.cayby)
825 self.caxay_navg.append(self.caxay)
834 self.caxay_navg.append(self.caxay)
826 self.cbxby_navg.append(self.cbxby)
835 self.cbxby_navg.append(self.cbxby)
827 self.bcounter+=1
836 self.bcounter+=1
828
837
829 def noise_estimation4x_DP(self,dataOut):
838 def noise_estimation4x_DP(self,dataOut):
830 if self.bcounter==dataOut.NAVG:
839 if self.bcounter==dataOut.NAVG:
831 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
840 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
832 snoise=numpy.zeros((dataOut.NR,dataOut.NAVG),'float32')
841 snoise=numpy.zeros((dataOut.NR,dataOut.NAVG),'float32')
833 nvector1=numpy.zeros((dataOut.NR,dataOut.NAVG,dataOut.MAXNRANGENDT),'float32')
842 nvector1=numpy.zeros((dataOut.NR,dataOut.NAVG,dataOut.MAXNRANGENDT),'float32')
834 for i in range(dataOut.NR):
843 for i in range(dataOut.NR):
835 dataOut.noise_final[i]=0.0
844 dataOut.noise_final[i]=0.0
836 for k in range(dataOut.NAVG):
845 for k in range(dataOut.NAVG):
837 snoise[i][k]=0.0
846 snoise[i][k]=0.0
838 for j in range(dataOut.MAXNRANGENDT):
847 for j in range(dataOut.MAXNRANGENDT):
839 nvector1[i][k][j]= dataOut.noisevector[j][i][k];
848 nvector1[i][k][j]= dataOut.noisevector[j][i][k];
840 snoise[i][k]=self.noise_hs4x(dataOut.MAXNRANGENDT, nvector1[i][k])
849 snoise[i][k]=self.noise_hs4x(dataOut.MAXNRANGENDT, nvector1[i][k])
841 #print("snoise",snoise[3,k])
850 #print("snoise",snoise[3,k])
842 dataOut.noise_final[i]=self.noise_hs4x(dataOut.NAVG, snoise[i])
851 dataOut.noise_final[i]=self.noise_hs4x(dataOut.NAVG, snoise[i])
843
852
844
853
845
854
846
855
847
856
848
857
849
858
850
859
851 def kabxys(self,dataOut):
860 def kabxys(self,dataOut):
852
861
853
862
854 #self.cabxys_navg(dataOut)
863 #self.cabxys_navg(dataOut)
855
864
856
865
857 if self.bcounter==dataOut.NAVG:
866 if self.bcounter==dataOut.NAVG:
858
867
859 dataOut.flagNoData = False
868 dataOut.flagNoData = False
860
869
861
870
862 #dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') #30/03/2020
871 #dataOut.noise_final=numpy.zeros(dataOut.NR,'float32') #30/03/2020
863 #self.dataOut.noise_final=numpy.zeros(2,'float32') #31/03/2020
872 #self.dataOut.noise_final=numpy.zeros(2,'float32') #31/03/2020
864
873
865
874
866 self.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
875 self.kax=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
867 self.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
876 self.kay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
868 self.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
877 self.kbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
869 self.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
878 self.kby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
870 self.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
879 self.kax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
871 self.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
880 self.kay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
872 self.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
881 self.kbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
873 self.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
882 self.kby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
874 self.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
883 self.kaxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
875 self.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
884 self.kaxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
876 self.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
885 self.kaybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
877 self.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
886 self.kayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
878 self.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
887 self.kaxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
879 self.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
888 self.kbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
880
889
881 for i in range(self.cax_navg[0].shape[0]):
890 for i in range(self.cax_navg[0].shape[0]):
882 for j in range(self.cax_navg[0].shape[1]):
891 for j in range(self.cax_navg[0].shape[1]):
883 for k in range(self.cax_navg[0].shape[2]):
892 for k in range(self.cax_navg[0].shape[2]):
884 data_navg=[item[i,j,k] for item in self.cax_navg]
893 data_navg=[item[i,j,k] for item in self.cax_navg]
885 self.kax[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
894 self.kax[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
886 data_navg=[item[i,j,k] for item in self.cay_navg]
895 data_navg=[item[i,j,k] for item in self.cay_navg]
887 self.kay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
896 self.kay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
888 data_navg=[item[i,j,k] for item in self.cbx_navg]
897 data_navg=[item[i,j,k] for item in self.cbx_navg]
889 self.kbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
898 self.kbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
890 data_navg=[item[i,j,k] for item in self.cby_navg]
899 data_navg=[item[i,j,k] for item in self.cby_navg]
891 self.kby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
900 self.kby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
892 data_navg=[item[i,j,k] for item in self.cax2_navg]
901 data_navg=[item[i,j,k] for item in self.cax2_navg]
893 self.kax2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
902 self.kax2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
894 data_navg=[item[i,j,k] for item in self.cay2_navg]
903 data_navg=[item[i,j,k] for item in self.cay2_navg]
895 self.kay2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
904 self.kay2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
896 data_navg=[item[i,j,k] for item in self.cbx2_navg]
905 data_navg=[item[i,j,k] for item in self.cbx2_navg]
897 self.kbx2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
906 self.kbx2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
898 data_navg=[item[i,j,k] for item in self.cby2_navg]
907 data_navg=[item[i,j,k] for item in self.cby2_navg]
899 self.kby2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
908 self.kby2[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
900 data_navg=[item[i,j,k] for item in self.caxbx_navg]
909 data_navg=[item[i,j,k] for item in self.caxbx_navg]
901 self.kaxbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
910 self.kaxbx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
902 data_navg=[item[i,j,k] for item in self.caxby_navg]
911 data_navg=[item[i,j,k] for item in self.caxby_navg]
903 self.kaxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
912 self.kaxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
904 data_navg=[item[i,j,k] for item in self.caybx_navg]
913 data_navg=[item[i,j,k] for item in self.caybx_navg]
905 self.kaybx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
914 self.kaybx[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
906 data_navg=[item[i,j,k] for item in self.cayby_navg]
915 data_navg=[item[i,j,k] for item in self.cayby_navg]
907 self.kayby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
916 self.kayby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
908 data_navg=[item[i,j,k] for item in self.caxay_navg]
917 data_navg=[item[i,j,k] for item in self.caxay_navg]
909 self.kaxay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
918 self.kaxay[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
910 data_navg=[item[i,j,k] for item in self.cbxby_navg]
919 data_navg=[item[i,j,k] for item in self.cbxby_navg]
911 self.kbxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
920 self.kbxby[i,j,k]=self.medi(data_navg,dataOut.NAVG,dataOut.nkill)
912
921
913
922
914 dataOut.kax=self.kax
923 dataOut.kax=self.kax
915 dataOut.kay=self.kay
924 dataOut.kay=self.kay
916 dataOut.kbx=self.kbx
925 dataOut.kbx=self.kbx
917 dataOut.kby=self.kby
926 dataOut.kby=self.kby
918 dataOut.kax2=self.kax2
927 dataOut.kax2=self.kax2
919 dataOut.kay2=self.kay2
928 dataOut.kay2=self.kay2
920 dataOut.kbx2=self.kbx2
929 dataOut.kbx2=self.kbx2
921 dataOut.kby2=self.kby2
930 dataOut.kby2=self.kby2
922 dataOut.kaxbx=self.kaxbx
931 dataOut.kaxbx=self.kaxbx
923 dataOut.kaxby=self.kaxby
932 dataOut.kaxby=self.kaxby
924 dataOut.kaybx=self.kaybx
933 dataOut.kaybx=self.kaybx
925 dataOut.kayby=self.kayby
934 dataOut.kayby=self.kayby
926 dataOut.kaxay=self.kaxay
935 dataOut.kaxay=self.kaxay
927 dataOut.kbxby=self.kbxby
936 dataOut.kbxby=self.kbxby
928
937
929 self.bcounter=0
938 self.bcounter=0
930
939
931 dataOut.crossprods=numpy.zeros((3,4,numpy.shape(dataOut.kax)[0],numpy.shape(dataOut.kax)[1],numpy.shape(dataOut.kax)[2]))
940 dataOut.crossprods=numpy.zeros((3,4,numpy.shape(dataOut.kax)[0],numpy.shape(dataOut.kax)[1],numpy.shape(dataOut.kax)[2]))
932
941
933 dataOut.crossprods[0]=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby]
942 dataOut.crossprods[0]=[dataOut.kax,dataOut.kay,dataOut.kbx,dataOut.kby]
934 dataOut.crossprods[1]=[dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2]
943 dataOut.crossprods[1]=[dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2]
935 dataOut.crossprods[2]=[dataOut.kaxay,dataOut.kbxby,dataOut.kaxbx,dataOut.kaxby]
944 dataOut.crossprods[2]=[dataOut.kaxay,dataOut.kbxby,dataOut.kaxbx,dataOut.kaxby]
936 #print("before: ",self.dataOut.noise_final)
945 #print("before: ",self.dataOut.noise_final)
937 dataOut.data_for_RTI_DP=numpy.zeros((3,dataOut.NDP))
946 dataOut.data_for_RTI_DP=numpy.zeros((3,dataOut.NDP))
938 dataOut.data_for_RTI_DP[0],dataOut.data_for_RTI_DP[1],dataOut.data_for_RTI_DP[2]=self.RTI_COLUMN(dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kayby,dataOut.kaybx,dataOut.kaxby, dataOut.NDP)
947 dataOut.data_for_RTI_DP[0],dataOut.data_for_RTI_DP[1],dataOut.data_for_RTI_DP[2]=self.RTI_COLUMN(dataOut.kax2,dataOut.kay2,dataOut.kbx2,dataOut.kby2,dataOut.kaxbx,dataOut.kayby,dataOut.kaybx,dataOut.kaxby, dataOut.NDP)
939
948
940
949
941
950
942 def RTI_COLUMN(self,kax2,kay2,kbx2,kby2,kaxbx,kayby,kaybx,kaxby, NDP):
951 def RTI_COLUMN(self,kax2,kay2,kbx2,kby2,kaxbx,kayby,kaybx,kaxby, NDP):
943 x00=numpy.zeros(NDP,dtype='float32')
952 x00=numpy.zeros(NDP,dtype='float32')
944 x01=numpy.zeros(NDP,dtype='float32')
953 x01=numpy.zeros(NDP,dtype='float32')
945 x02=numpy.zeros(NDP,dtype='float32')
954 x02=numpy.zeros(NDP,dtype='float32')
946 for j in range(2):# first couple lags
955 for j in range(2):# first couple lags
947 for k in range(2): #flip
956 for k in range(2): #flip
948 for i in range(NDP): #
957 for i in range(NDP): #
949 fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
958 fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
950 x00[i]=x00[i]+(kax2[i,j,k]+kay2[i,j,k])
959 x00[i]=x00[i]+(kax2[i,j,k]+kay2[i,j,k])
951 x01[i]=x01[i]+(kbx2[i,j,k]+kby2[i,j,k])
960 x01[i]=x01[i]+(kbx2[i,j,k]+kby2[i,j,k])
952 x02[i]=x02[i]+fx
961 x02[i]=x02[i]+fx
953
962
954 x00[i]=10.0*numpy.log10(x00[i]/4.)
963 x00[i]=10.0*numpy.log10(x00[i]/4.)
955 x01[i]=10.0*numpy.log10(x01[i]/4.)
964 x01[i]=10.0*numpy.log10(x01[i]/4.)
956 x02[i]=10.0*numpy.log10(x02[i])
965 x02[i]=10.0*numpy.log10(x02[i])
957 return x02,x00,x01
966 return x02,x00,x01
958
967
959
968
960
969
961
970
962
971
963
972
964 #30/03/2020:
973 #30/03/2020:
965 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
974 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
966
975
967 rnormalizer= 1./(float(nProfiles - NSCAN))
976 rnormalizer= 1./(float(nProfiles - NSCAN))
968 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
977 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
969 for i in range(NR):
978 for i in range(NR):
970 for j in range(MAXNRANGENDT):
979 for j in range(MAXNRANGENDT):
971 for k in range(NSCAN,nProfiles):
980 for k in range(NSCAN,nProfiles):
972 #TODO:integrate just 2nd quartile gates
981 #TODO:integrate just 2nd quartile gates
973 if k==NSCAN:
982 if k==NSCAN:
974 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
983 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
975 else:
984 else:
976 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
985 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
977
986
978
987
979
988
980
989
981 def noise_hs4x(self, ndatax, datax):
990 def noise_hs4x(self, ndatax, datax):
982 divider=10#divider was originally 10
991 divider=10#divider was originally 10
983 noise=0.0
992 noise=0.0
984 data=numpy.zeros(ndatax,'float32')
993 data=numpy.zeros(ndatax,'float32')
985 ndata1=int(ndatax/4)
994 ndata1=int(ndatax/4)
986 ndata2=int(2.5*(ndatax/4.))
995 ndata2=int(2.5*(ndatax/4.))
987 ndata=int(ndata2-ndata1)
996 ndata=int(ndata2-ndata1)
988 sorts=sorted(datax)
997 sorts=sorted(datax)
989
998
990 for k in range(ndata2): # select just second quartile
999 for k in range(ndata2): # select just second quartile
991 data[k]=sorts[k+ndata1]
1000 data[k]=sorts[k+ndata1]
992 nums_min= int(ndata/divider)
1001 nums_min= int(ndata/divider)
993 if(int(ndata/divider)> 2):
1002 if(int(ndata/divider)> 2):
994 nums_min= int(ndata/divider)
1003 nums_min= int(ndata/divider)
995 else:
1004 else:
996 nums_min=2
1005 nums_min=2
997 sump=0.0
1006 sump=0.0
998 sumq=0.0
1007 sumq=0.0
999 j=0
1008 j=0
1000 cont=1
1009 cont=1
1001 while ( (cont==1) and (j<ndata)):
1010 while ( (cont==1) and (j<ndata)):
1002 sump+=data[j]
1011 sump+=data[j]
1003 sumq+= data[j]*data[j]
1012 sumq+= data[j]*data[j]
1004 j=j+1
1013 j=j+1
1005 if (j> nums_min):
1014 if (j> nums_min):
1006 rtest= float(j/(j-1)) +1.0/ndata
1015 rtest= float(j/(j-1)) +1.0/ndata
1007 if( (sumq*j) > (rtest*sump*sump ) ):
1016 if( (sumq*j) > (rtest*sump*sump ) ):
1008 j=j-1
1017 j=j-1
1009 sump-= data[j]
1018 sump-= data[j]
1010 sumq-=data[j]*data[j]
1019 sumq-=data[j]*data[j]
1011 cont= 0
1020 cont= 0
1012 noise= (sump/j)
1021 noise= (sump/j)
1013
1022
1014 return noise
1023 return noise
1015
1024
1016
1025
1017
1026
1018 def run(self, dataOut, NLAG=16, NRANGE=0, NCAL=0, DPL=11,
1027 def run(self, dataOut, NLAG=16, NRANGE=0, NCAL=0, DPL=11,
1019 NDN=0, NDT=66, NDP=66, NSCAN=132,
1028 NDN=0, NDT=66, NDP=66, NSCAN=132,
1020 flags_array=(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300), NAVG=16, nkill=6, **kwargs):
1029 flags_array=(0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300), NAVG=16, nkill=6, **kwargs):
1021
1030
1022 dataOut.NLAG=NLAG
1031 dataOut.NLAG=NLAG
1023 dataOut.NR=len(dataOut.channelList)
1032 dataOut.NR=len(dataOut.channelList)
1024 dataOut.NRANGE=NRANGE
1033 dataOut.NRANGE=NRANGE
1025 dataOut.NCAL=NCAL
1034 dataOut.NCAL=NCAL
1026 dataOut.DPL=DPL
1035 dataOut.DPL=DPL
1027 dataOut.NDN=NDN
1036 dataOut.NDN=NDN
1028 dataOut.NDT=NDT
1037 dataOut.NDT=NDT
1029 dataOut.NDP=NDP
1038 dataOut.NDP=NDP
1030 dataOut.NSCAN=NSCAN
1039 dataOut.NSCAN=NSCAN
1031 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
1040 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
1032 dataOut.H0=int(dataOut.heightList[0])
1041 dataOut.H0=int(dataOut.heightList[0])
1033 dataOut.flags_array=flags_array
1042 dataOut.flags_array=flags_array
1034 dataOut.NAVG=NAVG
1043 dataOut.NAVG=NAVG
1035 dataOut.nkill=nkill
1044 dataOut.nkill=nkill
1036 dataOut.flagNoData = True
1045 dataOut.flagNoData = True
1037
1046
1038 self.get_dc(dataOut)
1047 self.get_dc(dataOut)
1039 self.get_products_cabxys(dataOut)
1048 self.get_products_cabxys(dataOut)
1040 self.cabxys_navg(dataOut)
1049 self.cabxys_navg(dataOut)
1041 self.noise_estimation4x_DP(dataOut)
1050 self.noise_estimation4x_DP(dataOut)
1042 self.kabxys(dataOut)
1051 self.kabxys(dataOut)
1043
1052
1044 return dataOut
1053 return dataOut
1045
1054
1046
1055
1047
1056
1048 class IntegrationDP(Operation):
1057 class IntegrationDP(Operation):
1049 """Operation to integrate the Double Pulse data.
1058 """Operation to integrate the Double Pulse data.
1050
1059
1051 Parameters:
1060 Parameters:
1052 -----------
1061 -----------
1053 nint : int
1062 nint : int
1054 Number of integrations.
1063 Number of integrations.
1055
1064
1056 Example
1065 Example
1057 --------
1066 --------
1058
1067
1059 op = proc_unit.addOperation(name='IntegrationDP', optype='other')
1068 op = proc_unit.addOperation(name='IntegrationDP', optype='other')
1060 op.addParameter(name='nint', value='30', format='int')
1069 op.addParameter(name='nint', value='30', format='int')
1061
1070
1062 """
1071 """
1063
1072
1064 def __init__(self, **kwargs):
1073 def __init__(self, **kwargs):
1065
1074
1066 Operation.__init__(self, **kwargs)
1075 Operation.__init__(self, **kwargs)
1067
1076
1068 self.counter=0
1077 self.counter=0
1069 self.aux=0
1078 self.aux=0
1070 self.init_time=None
1079 self.init_time=None
1071
1080
1072 def integration_for_double_pulse(self,dataOut):
1081 def integration_for_double_pulse(self,dataOut):
1073 #print("inside")
1082 #print("inside")
1074 #print(self.aux)
1083 #print(self.aux)
1075 if self.aux==1:
1084 if self.aux==1:
1076 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
1085 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
1077 #print(dataOut.datatime)
1086 #print(dataOut.datatime)
1078
1087
1079 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1088 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1080 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
1089 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
1081 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
1090 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
1082
1091
1083 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
1092 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
1084 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
1093 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
1085 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
1094 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
1086 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
1095 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
1087 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
1096 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
1088 #print(dataOut.bd_time)
1097 #print(dataOut.bd_time)
1089 #exit()
1098 #exit()
1090 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
1099 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
1091 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
1100 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
1092 #print("date: ", dataOut.TimeBlockDate)
1101 #print("date: ", dataOut.TimeBlockDate)
1093
1102
1094
1103
1095 self.aux=0
1104 self.aux=0
1096
1105
1097 #print("after")
1106 #print("after")
1098
1107
1099 if self.counter==0:
1108 if self.counter==0:
1100
1109
1101 tmpx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1110 tmpx=numpy.zeros((dataOut.NDP,dataOut.DPL,2),'float32')
1102 dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx]
1111 dataOut.kabxys_integrated=[tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx,tmpx]
1103 self.init_time=dataOut.utctime
1112 self.init_time=dataOut.utctime
1104
1113
1105 if self.counter < dataOut.nint:
1114 if self.counter < dataOut.nint:
1106 #print("HERE")
1115 #print("HERE")
1107
1116
1108 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]
1117 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]
1109
1118
1110 for ind in range(len(dataOut.kabxys_integrated)): #final cross products
1119 for ind in range(len(dataOut.kabxys_integrated)): #final cross products
1111 dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind]
1120 dataOut.kabxys_integrated[ind]=dataOut.kabxys_integrated[ind]+dataOut.final_cross_products[ind]
1112
1121
1113 self.counter+=1
1122 self.counter+=1
1114
1123
1115 if self.counter==dataOut.nint-1:
1124 if self.counter==dataOut.nint-1:
1116 self.aux=1
1125 self.aux=1
1117 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1126 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
1118 if self.counter==dataOut.nint:
1127 if self.counter==dataOut.nint:
1119
1128
1120 dataOut.flagNoData=False
1129 dataOut.flagNoData=False
1121 dataOut.utctime=self.init_time
1130 dataOut.utctime=self.init_time
1122 self.counter=0
1131 self.counter=0
1123
1132
1124
1133
1125 def run(self,dataOut,nint=20):
1134 def run(self,dataOut,nint=20):
1126
1135
1127 dataOut.flagNoData=True
1136 dataOut.flagNoData=True
1128 dataOut.nint=nint
1137 dataOut.nint=nint
1129 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
1138 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
1130 dataOut.lat=-11.95
1139 dataOut.lat=-11.95
1131 dataOut.lon=-76.87
1140 dataOut.lon=-76.87
1132
1141
1133 self.integration_for_double_pulse(dataOut)
1142 self.integration_for_double_pulse(dataOut)
1134
1143
1135 return dataOut
1144 return dataOut
1136
1145
1137
1146
1138 class SumFlips(Operation):
1147 class SumFlips(Operation):
1139 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
1148 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
1140
1149
1141 Parameters:
1150 Parameters:
1142 -----------
1151 -----------
1143 None
1152 None
1144
1153
1145 Example
1154 Example
1146 --------
1155 --------
1147
1156
1148 op = proc_unit.addOperation(name='SumFlips', optype='other')
1157 op = proc_unit.addOperation(name='SumFlips', optype='other')
1149
1158
1150 """
1159 """
1151
1160
1152 def __init__(self, **kwargs):
1161 def __init__(self, **kwargs):
1153
1162
1154 Operation.__init__(self, **kwargs)
1163 Operation.__init__(self, **kwargs)
1155
1164
1156
1165
1157 def rint2DP(self,dataOut):
1166 def rint2DP(self,dataOut):
1158
1167
1159 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
1168 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
1160
1169
1161 for l in range(dataOut.DPL):
1170 for l in range(dataOut.DPL):
1162
1171
1163 dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.NAVG*12.0)
1172 dataOut.rnint2[l]=1.0/(dataOut.nint*dataOut.NAVG*12.0)
1164
1173
1165
1174
1166 def SumLags(self,dataOut):
1175 def SumLags(self,dataOut):
1167
1176
1168 for l in range(dataOut.DPL):
1177 for l in range(dataOut.DPL):
1169
1178
1170 dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l]
1179 dataOut.kabxys_integrated[4][:,l,0]=(dataOut.kabxys_integrated[4][:,l,0]+dataOut.kabxys_integrated[4][:,l,1])*dataOut.rnint2[l]
1171 dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l]
1180 dataOut.kabxys_integrated[5][:,l,0]=(dataOut.kabxys_integrated[5][:,l,0]+dataOut.kabxys_integrated[5][:,l,1])*dataOut.rnint2[l]
1172 dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l]
1181 dataOut.kabxys_integrated[6][:,l,0]=(dataOut.kabxys_integrated[6][:,l,0]+dataOut.kabxys_integrated[6][:,l,1])*dataOut.rnint2[l]
1173 dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l]
1182 dataOut.kabxys_integrated[7][:,l,0]=(dataOut.kabxys_integrated[7][:,l,0]+dataOut.kabxys_integrated[7][:,l,1])*dataOut.rnint2[l]
1174
1183
1175 dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l]
1184 dataOut.kabxys_integrated[8][:,l,0]=(dataOut.kabxys_integrated[8][:,l,0]-dataOut.kabxys_integrated[8][:,l,1])*dataOut.rnint2[l]
1176 dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l]
1185 dataOut.kabxys_integrated[9][:,l,0]=(dataOut.kabxys_integrated[9][:,l,0]-dataOut.kabxys_integrated[9][:,l,1])*dataOut.rnint2[l]
1177 dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l]
1186 dataOut.kabxys_integrated[10][:,l,0]=(dataOut.kabxys_integrated[10][:,l,0]-dataOut.kabxys_integrated[10][:,l,1])*dataOut.rnint2[l]
1178 dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l]
1187 dataOut.kabxys_integrated[11][:,l,0]=(dataOut.kabxys_integrated[11][:,l,0]-dataOut.kabxys_integrated[11][:,l,1])*dataOut.rnint2[l]
1179
1188
1180
1189
1181 def run(self,dataOut):
1190 def run(self,dataOut):
1182
1191
1183 self.rint2DP(dataOut)
1192 self.rint2DP(dataOut)
1184 self.SumLags(dataOut)
1193 self.SumLags(dataOut)
1185
1194
1186 return dataOut
1195 return dataOut
1187
1196
1188
1197
1189 class FlagBadHeights(Operation):
1198 class FlagBadHeights(Operation):
1190 """Operation to flag bad heights (bad data) of the Double Pulse.
1199 """Operation to flag bad heights (bad data) of the Double Pulse.
1191
1200
1192 Parameters:
1201 Parameters:
1193 -----------
1202 -----------
1194 None
1203 None
1195
1204
1196 Example
1205 Example
1197 --------
1206 --------
1198
1207
1199 op = proc_unit.addOperation(name='FlagBadHeights', optype='other')
1208 op = proc_unit.addOperation(name='FlagBadHeights', optype='other')
1200
1209
1201 """
1210 """
1202
1211
1203 def __init__(self, **kwargs):
1212 def __init__(self, **kwargs):
1204
1213
1205 Operation.__init__(self, **kwargs)
1214 Operation.__init__(self, **kwargs)
1206
1215
1207 def run(self,dataOut):
1216 def run(self,dataOut):
1208
1217
1209 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1218 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1210
1219
1211 for j in range(dataOut.NDP):
1220 for j in range(dataOut.NDP):
1212 for l in range(dataOut.DPL):
1221 for l in range(dataOut.DPL):
1213 ip1=j+dataOut.NDP*(0+2*l)
1222 ip1=j+dataOut.NDP*(0+2*l)
1214
1223
1215 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.)):
1224 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.)):
1216 dataOut.ibad[j][l]=1
1225 dataOut.ibad[j][l]=1
1217 else:
1226 else:
1218 dataOut.ibad[j][l]=0
1227 dataOut.ibad[j][l]=0
1219
1228
1220 return dataOut
1229 return dataOut
1221
1230
1222 class FlagBadHeightsSpectra(Operation):
1231 class FlagBadHeightsSpectra(Operation):
1223 """Operation to flag bad heights (bad data) of the Double Pulse.
1232 """Operation to flag bad heights (bad data) of the Double Pulse.
1224
1233
1225 Parameters:
1234 Parameters:
1226 -----------
1235 -----------
1227 None
1236 None
1228
1237
1229 Example
1238 Example
1230 --------
1239 --------
1231
1240
1232 op = proc_unit.addOperation(name='FlagBadHeightsSpectra', optype='other')
1241 op = proc_unit.addOperation(name='FlagBadHeightsSpectra', optype='other')
1233
1242
1234 """
1243 """
1235
1244
1236 def __init__(self, **kwargs):
1245 def __init__(self, **kwargs):
1237
1246
1238 Operation.__init__(self, **kwargs)
1247 Operation.__init__(self, **kwargs)
1239
1248
1240 def run(self,dataOut):
1249 def run(self,dataOut):
1241
1250
1242 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1251 dataOut.ibad=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1243
1252
1244 for j in range(dataOut.NDP):
1253 for j in range(dataOut.NDP):
1245 for l in range(dataOut.DPL):
1254 for l in range(dataOut.DPL):
1246 ip1=j+dataOut.NDP*(0+2*l)
1255 ip1=j+dataOut.NDP*(0+2*l)
1247
1256
1248 if( (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)):
1257 if( (dataOut.kabxys_integrated[4][j,l,0] <= 0.) or (dataOut.kabxys_integrated[6][j,l,0] <= 0.)):
1249 dataOut.ibad[j][l]=1
1258 dataOut.ibad[j][l]=1
1250 else:
1259 else:
1251 dataOut.ibad[j][l]=0
1260 dataOut.ibad[j][l]=0
1252
1261
1253 return dataOut
1262 return dataOut
1254
1263
1255 class NoisePower(Operation):
1264 class NoisePower(Operation):
1256 """Operation to get noise power from the integrated data of the Double Pulse.
1265 """Operation to get noise power from the integrated data of the Double Pulse.
1257
1266
1258 Parameters:
1267 Parameters:
1259 -----------
1268 -----------
1260 None
1269 None
1261
1270
1262 Example
1271 Example
1263 --------
1272 --------
1264
1273
1265 op = proc_unit.addOperation(name='NoisePower', optype='other')
1274 op = proc_unit.addOperation(name='NoisePower', optype='other')
1266
1275
1267 """
1276 """
1268
1277
1269 def __init__(self, **kwargs):
1278 def __init__(self, **kwargs):
1270
1279
1271 Operation.__init__(self, **kwargs)
1280 Operation.__init__(self, **kwargs)
1272
1281
1273 def hildebrand(self,dataOut,data):
1282 def hildebrand(self,dataOut,data):
1274
1283
1275 divider=10 # divider was originally 10
1284 divider=10 # divider was originally 10
1276 noise=0.0
1285 noise=0.0
1277 n1=0
1286 n1=0
1278 n2=int(dataOut.NDP/2)
1287 n2=int(dataOut.NDP/2)
1279 sorts= sorted(data)
1288 sorts= sorted(data)
1280 nums_min= dataOut.NDP/divider
1289 nums_min= dataOut.NDP/divider
1281 if((dataOut.NDP/divider)> 2):
1290 if((dataOut.NDP/divider)> 2):
1282 nums_min= int(dataOut.NDP/divider)
1291 nums_min= int(dataOut.NDP/divider)
1283
1292
1284 else:
1293 else:
1285 nums_min=2
1294 nums_min=2
1286 sump=0.0
1295 sump=0.0
1287 sumq=0.0
1296 sumq=0.0
1288 j=0
1297 j=0
1289 cont=1
1298 cont=1
1290 while( (cont==1) and (j<n2)):
1299 while( (cont==1) and (j<n2)):
1291 sump+=sorts[j+n1]
1300 sump+=sorts[j+n1]
1292 sumq+= sorts[j+n1]*sorts[j+n1]
1301 sumq+= sorts[j+n1]*sorts[j+n1]
1293 t3= sump/(j+1)
1302 t3= sump/(j+1)
1294 j=j+1
1303 j=j+1
1295 if(j> nums_min):
1304 if(j> nums_min):
1296 rtest= float(j/(j-1)) +1.0/dataOut.NAVG
1305 rtest= float(j/(j-1)) +1.0/dataOut.NAVG
1297 t1= (sumq*j)
1306 t1= (sumq*j)
1298 t2=(rtest*sump*sump)
1307 t2=(rtest*sump*sump)
1299 if( (t1/t2) > 0.990):
1308 if( (t1/t2) > 0.990):
1300 j=j-1
1309 j=j-1
1301 sump-= sorts[j+n1]
1310 sump-= sorts[j+n1]
1302 sumq-=sorts[j+n1]*sorts[j+n1]
1311 sumq-=sorts[j+n1]*sorts[j+n1]
1303 cont= 0
1312 cont= 0
1304
1313
1305 noise= sump/j
1314 noise= sump/j
1306 stdv=numpy.sqrt((sumq- noise*noise)/(j-1))
1315 stdv=numpy.sqrt((sumq- noise*noise)/(j-1))
1307 return noise
1316 return noise
1308
1317
1309 def run(self,dataOut):
1318 def run(self,dataOut):
1310
1319
1311 p=numpy.zeros((dataOut.NR,dataOut.NDP,dataOut.DPL),'float32')
1320 p=numpy.zeros((dataOut.NR,dataOut.NDP,dataOut.DPL),'float32')
1312 av=numpy.zeros(dataOut.NDP,'float32')
1321 av=numpy.zeros(dataOut.NDP,'float32')
1313 dataOut.pnoise=numpy.zeros(dataOut.NR,'float32')
1322 dataOut.pnoise=numpy.zeros(dataOut.NR,'float32')
1314
1323
1315 p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip
1324 p[0,:,:]=dataOut.kabxys_integrated[4][:,:,0]+dataOut.kabxys_integrated[5][:,:,0] #total power for channel 0, just pulse with non-flip
1316 p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1
1325 p[1,:,:]=dataOut.kabxys_integrated[6][:,:,0]+dataOut.kabxys_integrated[7][:,:,0] #total power for channel 1
1317
1326
1318 for i in range(dataOut.NR):
1327 for i in range(dataOut.NR):
1319 dataOut.pnoise[i]=0.0
1328 dataOut.pnoise[i]=0.0
1320 for k in range(dataOut.DPL):
1329 for k in range(dataOut.DPL):
1321 dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k])
1330 dataOut.pnoise[i]+= self.hildebrand(dataOut,p[i,:,k])
1322
1331
1323 dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.DPL
1332 dataOut.pnoise[i]=dataOut.pnoise[i]/dataOut.DPL
1324
1333
1325
1334
1326 dataOut.pan=1.0*dataOut.pnoise[0] # weights could change
1335 dataOut.pan=1.0*dataOut.pnoise[0] # weights could change
1327 dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change
1336 dataOut.pbn=1.0*dataOut.pnoise[1] # weights could change
1328
1337
1329 return dataOut
1338 return dataOut
1330
1339
1331
1340
1332 class DoublePulseACFs(Operation):
1341 class DoublePulseACFs(Operation):
1333 """Operation to get the ACFs of the Double Pulse.
1342 """Operation to get the ACFs of the Double Pulse.
1334
1343
1335 Parameters:
1344 Parameters:
1336 -----------
1345 -----------
1337 None
1346 None
1338
1347
1339 Example
1348 Example
1340 --------
1349 --------
1341
1350
1342 op = proc_unit.addOperation(name='DoublePulseACFs', optype='other')
1351 op = proc_unit.addOperation(name='DoublePulseACFs', optype='other')
1343
1352
1344 """
1353 """
1345
1354
1346 def __init__(self, **kwargs):
1355 def __init__(self, **kwargs):
1347
1356
1348 Operation.__init__(self, **kwargs)
1357 Operation.__init__(self, **kwargs)
1349 self.aux=1
1358 self.aux=1
1350
1359
1351 def run(self,dataOut):
1360 def run(self,dataOut):
1352
1361
1353 dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1362 dataOut.igcej=numpy.zeros((dataOut.NDP,dataOut.DPL),'int32')
1354
1363
1355 if self.aux==1:
1364 if self.aux==1:
1356 dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1365 dataOut.rhor=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1357 dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1366 dataOut.rhoi=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1358 dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1367 dataOut.sdp=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1359 dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1368 dataOut.sd=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1360 dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1369 dataOut.p=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1361 dataOut.alag=numpy.zeros(dataOut.NDP,'float32')
1370 dataOut.alag=numpy.zeros(dataOut.NDP,'float32')
1362 for l in range(dataOut.DPL):
1371 for l in range(dataOut.DPL):
1363 dataOut.alag[l]=l*dataOut.DH*2.0/150.0
1372 dataOut.alag[l]=l*dataOut.DH*2.0/150.0
1364 self.aux=0
1373 self.aux=0
1365 sn4=dataOut.pan*dataOut.pbn
1374 sn4=dataOut.pan*dataOut.pbn
1366 rhorn=0
1375 rhorn=0
1367 rhoin=0
1376 rhoin=0
1368 panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1377 panrm=numpy.zeros((dataOut.NDP,dataOut.DPL), dtype=float)
1369
1378
1370 for i in range(dataOut.NDP):
1379 for i in range(dataOut.NDP):
1371 for j in range(dataOut.DPL):
1380 for j in range(dataOut.DPL):
1372 ################# Total power
1381 ################# Total power
1373 pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0])
1382 pa=numpy.abs(dataOut.kabxys_integrated[4][i,j,0]+dataOut.kabxys_integrated[5][i,j,0])
1374 pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0])
1383 pb=numpy.abs(dataOut.kabxys_integrated[6][i,j,0]+dataOut.kabxys_integrated[7][i,j,0])
1375 st4=pa*pb
1384 st4=pa*pb
1376 dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn)
1385 dataOut.p[i,j]=pa+pb-(dataOut.pan+dataOut.pbn)
1377 dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb))
1386 dataOut.sdp[i,j]=2*dataOut.rnint2[j]*((pa+pb)*(pa+pb))
1378 ## ACF
1387 ## ACF
1379 rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0]
1388 rhorp=dataOut.kabxys_integrated[8][i,j,0]+dataOut.kabxys_integrated[11][i,j,0]
1380 rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0]
1389 rhoip=dataOut.kabxys_integrated[10][i,j,0]-dataOut.kabxys_integrated[9][i,j,0]
1381 if ((pa>dataOut.pan)&(pb>dataOut.pbn)):
1390 if ((pa>dataOut.pan)&(pb>dataOut.pbn)):
1382
1391
1383 ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn))
1392 ss4=numpy.abs((pa-dataOut.pan)*(pb-dataOut.pbn))
1384 panrm[i,j]=math.sqrt(ss4)
1393 panrm[i,j]=math.sqrt(ss4)
1385 rnorm=1/panrm[i,j]
1394 rnorm=1/panrm[i,j]
1386 ## ACF
1395 ## ACF
1387 dataOut.rhor[i,j]=rhorp*rnorm
1396 dataOut.rhor[i,j]=rhorp*rnorm
1388 dataOut.rhoi[i,j]=rhoip*rnorm
1397 dataOut.rhoi[i,j]=rhoip*rnorm
1389 ############# Compute standard error for ACF
1398 ############# Compute standard error for ACF
1390 stoss4=st4/ss4
1399 stoss4=st4/ss4
1391 snoss4=sn4/ss4
1400 snoss4=sn4/ss4
1392 rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4
1401 rp2=((rhorp*rhorp)+(rhoip*rhoip))/st4
1393 rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4
1402 rn2=((rhorn*rhorn)+(rhoin*rhoin))/sn4
1394 rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j])
1403 rs2=(dataOut.rhor[i,j]*dataOut.rhor[i,j])+(dataOut.rhoi[i,j]*dataOut.rhoi[i,j])
1395 st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4)))
1404 st=1.0+rs2*(stoss4-(2*math.sqrt(stoss4*snoss4)))
1396 stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4)))
1405 stn=1.0+rs2*(snoss4-(2*math.sqrt(stoss4*snoss4)))
1397 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]
1406 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]
1398 dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j])
1407 dataOut.sd[i,j]=numpy.abs(dataOut.sd[i,j])
1399
1408
1400 else: #default values for bad points
1409 else: #default values for bad points
1401 rnorm=1/math.sqrt(st4)
1410 rnorm=1/math.sqrt(st4)
1402 dataOut.sd[i,j]=1.e30
1411 dataOut.sd[i,j]=1.e30
1403 dataOut.ibad[i,j]=4
1412 dataOut.ibad[i,j]=4
1404 dataOut.rhor[i,j]=rhorp*rnorm
1413 dataOut.rhor[i,j]=rhorp*rnorm
1405 dataOut.rhoi[i,j]=rhoip*rnorm
1414 dataOut.rhoi[i,j]=rhoip*rnorm
1406
1415
1407 if ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)):
1416 if ((pa/dataOut.pan-1.0)>2.25*(pb/dataOut.pbn-1.0)):
1408 dataOut.igcej[i,j]=1
1417 dataOut.igcej[i,j]=1
1409
1418
1410 return dataOut
1419 return dataOut
1411
1420
1412
1421
1413 class FaradayAngleAndDPPower(Operation):
1422 class FaradayAngleAndDPPower(Operation):
1414 """Operation to calculate Faraday angle and Double Pulse power.
1423 """Operation to calculate Faraday angle and Double Pulse power.
1415
1424
1416 Parameters:
1425 Parameters:
1417 -----------
1426 -----------
1418 None
1427 None
1419
1428
1420 Example
1429 Example
1421 --------
1430 --------
1422
1431
1423 op = proc_unit.addOperation(name='FaradayAngleAndDPPower', optype='other')
1432 op = proc_unit.addOperation(name='FaradayAngleAndDPPower', optype='other')
1424
1433
1425 """
1434 """
1426
1435
1427 def __init__(self, **kwargs):
1436 def __init__(self, **kwargs):
1428
1437
1429 Operation.__init__(self, **kwargs)
1438 Operation.__init__(self, **kwargs)
1430 self.aux=1
1439 self.aux=1
1431
1440
1432 def run(self,dataOut):
1441 def run(self,dataOut):
1433
1442
1434 if self.aux==1:
1443 if self.aux==1:
1435 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
1444 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
1436 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
1445 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
1437 dataOut.sdn2=numpy.zeros(dataOut.NDP,'float32')
1446 dataOut.sdn2=numpy.zeros(dataOut.NDP,'float32')
1438 dataOut.ph2=numpy.zeros(dataOut.NDP,'float32')
1447 dataOut.ph2=numpy.zeros(dataOut.NDP,'float32')
1439 dataOut.sdp2=numpy.zeros(dataOut.NDP,'float32')
1448 dataOut.sdp2=numpy.zeros(dataOut.NDP,'float32')
1440 dataOut.ibd=numpy.zeros(dataOut.NDP,'float32')
1449 dataOut.ibd=numpy.zeros(dataOut.NDP,'float32')
1441 dataOut.phi=numpy.zeros(dataOut.NDP,'float32')
1450 dataOut.phi=numpy.zeros(dataOut.NDP,'float32')
1442
1451
1443 self.aux=0
1452 self.aux=0
1444
1453
1445 for i in range(dataOut.MAXNRANGENDT):
1454 for i in range(dataOut.MAXNRANGENDT):
1446 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
1455 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
1447 dataOut.h2[i]=dataOut.range1[i]**2
1456 dataOut.h2[i]=dataOut.range1[i]**2
1448
1457
1449 for j in range(dataOut.NDP):
1458 for j in range(dataOut.NDP):
1450 dataOut.ph2[j]=0.
1459 dataOut.ph2[j]=0.
1451 dataOut.sdp2[j]=0.
1460 dataOut.sdp2[j]=0.
1452 ri=dataOut.rhoi[j][0]/dataOut.sd[j][0]
1461 ri=dataOut.rhoi[j][0]/dataOut.sd[j][0]
1453 rr=dataOut.rhor[j][0]/dataOut.sd[j][0]
1462 rr=dataOut.rhor[j][0]/dataOut.sd[j][0]
1454 dataOut.sdn2[j]=1./dataOut.sd[j][0]
1463 dataOut.sdn2[j]=1./dataOut.sd[j][0]
1455
1464
1456 pt=0.# // total power
1465 pt=0.# // total power
1457 st=0.# // total signal
1466 st=0.# // total signal
1458 ibt=0# // bad lags
1467 ibt=0# // bad lags
1459 ns=0# // no. good lags
1468 ns=0# // no. good lags
1460 for l in range(dataOut.DPL):
1469 for l in range(dataOut.DPL):
1461 #add in other lags if outside of e-jet contamination
1470 #add in other lags if outside of e-jet contamination
1462 if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ):
1471 if( (dataOut.igcej[j][l] == 0) and (dataOut.ibad[j][l] == 0) ):
1463
1472
1464 dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l]
1473 dataOut.ph2[j]+=dataOut.p[j][l]/dataOut.sdp[j][l]
1465 dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l]
1474 dataOut.sdp2[j]=dataOut.sdp2[j]+1./dataOut.sdp[j][l]
1466 ns+=1
1475 ns+=1
1467
1476
1468
1477
1469 pt+=dataOut.p[j][l]/dataOut.sdp[j][l]
1478 pt+=dataOut.p[j][l]/dataOut.sdp[j][l]
1470 st+=1./dataOut.sdp[j][l]
1479 st+=1./dataOut.sdp[j][l]
1471 ibt|=dataOut.ibad[j][l];
1480 ibt|=dataOut.ibad[j][l];
1472 if(ns!= 0):
1481 if(ns!= 0):
1473 dataOut.ibd[j]=0
1482 dataOut.ibd[j]=0
1474 dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j]
1483 dataOut.ph2[j]=dataOut.ph2[j]/dataOut.sdp2[j]
1475 dataOut.sdp2[j]=1./dataOut.sdp2[j]
1484 dataOut.sdp2[j]=1./dataOut.sdp2[j]
1476 else:
1485 else:
1477 dataOut.ibd[j]=ibt
1486 dataOut.ibd[j]=ibt
1478 dataOut.ph2[j]=pt/st
1487 dataOut.ph2[j]=pt/st
1479 dataOut.sdp2[j]=1./st
1488 dataOut.sdp2[j]=1./st
1480
1489
1481 dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j]
1490 dataOut.ph2[j]=dataOut.ph2[j]*dataOut.h2[j]
1482 dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j]
1491 dataOut.sdp2[j]=numpy.sqrt(dataOut.sdp2[j])*dataOut.h2[j]
1483 rr=rr/dataOut.sdn2[j]
1492 rr=rr/dataOut.sdn2[j]
1484 ri=ri/dataOut.sdn2[j]
1493 ri=ri/dataOut.sdn2[j]
1485 #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program
1494 #rm[j]=np.sqrt(rr*rr + ri*ri) it is not used in c program
1486 dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri))
1495 dataOut.sdn2[j]=1./(dataOut.sdn2[j]*(rr*rr + ri*ri))
1487 if( (ri == 0.) and (rr == 0.) ):
1496 if( (ri == 0.) and (rr == 0.) ):
1488 dataOut.phi[j]=0.
1497 dataOut.phi[j]=0.
1489 else:
1498 else:
1490 dataOut.phi[j]=math.atan2( ri , rr )
1499 dataOut.phi[j]=math.atan2( ri , rr )
1491
1500
1492 return dataOut
1501 return dataOut
1493
1502
1494
1503
1495 class ElectronDensityFaraday(Operation):
1504 class ElectronDensityFaraday(Operation):
1496 """Operation to calculate electron density from Faraday angle.
1505 """Operation to calculate electron density from Faraday angle.
1497
1506
1498 Parameters:
1507 Parameters:
1499 -----------
1508 -----------
1500 NSHTS : int
1509 NSHTS : int
1501 .*
1510 .*
1502 RATE : float
1511 RATE : float
1503 .*
1512 .*
1504
1513
1505 Example
1514 Example
1506 --------
1515 --------
1507
1516
1508 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1517 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1509 op.addParameter(name='NSHTS', value='50', format='int')
1518 op.addParameter(name='NSHTS', value='50', format='int')
1510 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1519 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1511
1520
1512 """
1521 """
1513
1522
1514 def __init__(self, **kwargs):
1523 def __init__(self, **kwargs):
1515
1524
1516 Operation.__init__(self, **kwargs)
1525 Operation.__init__(self, **kwargs)
1517 self.aux=1
1526 self.aux=1
1518
1527
1519 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1528 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1520
1529
1521 #print(ctime(dataOut.utctime))
1530 #print(ctime(dataOut.utctime))
1522 #3print("Faraday Angle",dataOut.phi)
1531 #3print("Faraday Angle",dataOut.phi)
1523
1532
1524 dataOut.NSHTS=NSHTS
1533 dataOut.NSHTS=NSHTS
1525 dataOut.RATE=RATE
1534 dataOut.RATE=RATE
1526
1535
1527 if self.aux==1:
1536 if self.aux==1:
1528 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1537 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1529 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1538 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1530 self.aux=0
1539 self.aux=0
1531 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1540 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1532 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1541 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1533 # use complex numbers for phase
1542 # use complex numbers for phase
1534 for i in range(dataOut.NSHTS):
1543 for i in range(dataOut.NSHTS):
1535 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1544 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1536 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1545 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1537
1546
1538 # differentiate and convert to number density
1547 # differentiate and convert to number density
1539 ndphi=dataOut.NSHTS-4
1548 ndphi=dataOut.NSHTS-4
1540 for i in range(2,dataOut.NSHTS-2):
1549 for i in range(2,dataOut.NSHTS-2):
1541 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1550 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1542 #four-point derivative, no phase unwrapping necessary
1551 #four-point derivative, no phase unwrapping necessary
1543 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1552 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1544 dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1553 dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1545
1554
1546 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1555 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1547 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1556 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1548 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1557 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1549
1558
1550 return dataOut
1559 return dataOut
1551
1560
1552 class ElectronDensityRobertoTestFaraday(Operation):
1561 class ElectronDensityRobertoTestFaraday(Operation):
1553 """Operation to calculate electron density from Faraday angle.
1562 """Operation to calculate electron density from Faraday angle.
1554
1563
1555 Parameters:
1564 Parameters:
1556 -----------
1565 -----------
1557 NSHTS : int
1566 NSHTS : int
1558 .*
1567 .*
1559 RATE : float
1568 RATE : float
1560 .*
1569 .*
1561
1570
1562 Example
1571 Example
1563 --------
1572 --------
1564
1573
1565 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1574 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1566 op.addParameter(name='NSHTS', value='50', format='int')
1575 op.addParameter(name='NSHTS', value='50', format='int')
1567 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1576 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1568
1577
1569 """
1578 """
1570
1579
1571 def __init__(self, **kwargs):
1580 def __init__(self, **kwargs):
1572
1581
1573 Operation.__init__(self, **kwargs)
1582 Operation.__init__(self, **kwargs)
1574 self.aux=1
1583 self.aux=1
1575
1584
1576 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1585 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1577
1586
1578 #print(ctime(dataOut.utctime))
1587 #print(ctime(dataOut.utctime))
1579 #print("Faraday Angle",dataOut.phi)
1588 #print("Faraday Angle",dataOut.phi)
1580
1589
1581 dataOut.NSHTS=NSHTS
1590 dataOut.NSHTS=NSHTS
1582 dataOut.RATE=RATE
1591 dataOut.RATE=RATE
1583
1592
1584 if self.aux==1:
1593 if self.aux==1:
1585 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1594 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1586 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1595 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1587 self.aux=0
1596 self.aux=0
1588 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1597 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1589 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1598 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1590 # use complex numbers for phase
1599 # use complex numbers for phase
1591 '''
1600 '''
1592 for i in range(dataOut.NSHTS):
1601 for i in range(dataOut.NSHTS):
1593 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1602 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1594 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1603 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1595 '''
1604 '''
1596
1605
1597 # differentiate and convert to number density
1606 # differentiate and convert to number density
1598 ndphi=dataOut.NSHTS-4
1607 ndphi=dataOut.NSHTS-4
1599
1608
1600 dataOut.phi=numpy.unwrap(dataOut.phi)
1609 dataOut.phi=numpy.unwrap(dataOut.phi)
1601
1610
1602 for i in range(2,dataOut.NSHTS-2):
1611 for i in range(2,dataOut.NSHTS-2):
1603 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1612 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1604 #four-point derivative, no phase unwrapping necessary
1613 #four-point derivative, no phase unwrapping necessary
1605 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1614 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1606 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1615 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1607 dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
1616 dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
1608
1617
1609 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1618 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1610 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1619 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1611 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1620 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1612
1621
1613 return dataOut
1622 return dataOut
1614
1623
1615 class ElectronDensityRobertoTest2Faraday(Operation):
1624 class ElectronDensityRobertoTest2Faraday(Operation):
1616 """Operation to calculate electron density from Faraday angle.
1625 """Operation to calculate electron density from Faraday angle.
1617
1626
1618 Parameters:
1627 Parameters:
1619 -----------
1628 -----------
1620 NSHTS : int
1629 NSHTS : int
1621 .*
1630 .*
1622 RATE : float
1631 RATE : float
1623 .*
1632 .*
1624
1633
1625 Example
1634 Example
1626 --------
1635 --------
1627
1636
1628 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1637 op = proc_unit.addOperation(name='ElectronDensityFaraday', optype='other')
1629 op.addParameter(name='NSHTS', value='50', format='int')
1638 op.addParameter(name='NSHTS', value='50', format='int')
1630 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1639 op.addParameter(name='RATE', value='1.8978873e-6', format='float')
1631
1640
1632 """
1641 """
1633
1642
1634 def __init__(self, **kwargs):
1643 def __init__(self, **kwargs):
1635
1644
1636 Operation.__init__(self, **kwargs)
1645 Operation.__init__(self, **kwargs)
1637 self.aux=1
1646 self.aux=1
1638
1647
1639 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1648 def run(self,dataOut,NSHTS=50,RATE=1.8978873e-6):
1640
1649
1641 #print(ctime(dataOut.utctime))
1650 #print(ctime(dataOut.utctime))
1642 #print("Faraday Angle",dataOut.phi)
1651 #print("Faraday Angle",dataOut.phi)
1643
1652
1644 dataOut.NSHTS=NSHTS
1653 dataOut.NSHTS=NSHTS
1645 dataOut.RATE=RATE
1654 dataOut.RATE=RATE
1646
1655
1647 if self.aux==1:
1656 if self.aux==1:
1648 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1657 dataOut.dphi=numpy.zeros(dataOut.NDP,'float32')
1649 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1658 dataOut.sdn1=numpy.zeros(dataOut.NDP,'float32')
1650 self.aux=0
1659 self.aux=0
1651 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1660 theta=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1652 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1661 thetai=numpy.zeros(dataOut.NDP,dtype=numpy.complex_)
1653 # use complex numbers for phase
1662 # use complex numbers for phase
1654 '''
1663 '''
1655 for i in range(dataOut.NSHTS):
1664 for i in range(dataOut.NSHTS):
1656 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1665 theta[i]=math.cos(dataOut.phi[i])+math.sin(dataOut.phi[i])*1j
1657 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1666 thetai[i]=-math.sin(dataOut.phi[i])+math.cos(dataOut.phi[i])*1j
1658 '''
1667 '''
1659
1668
1660 # differentiate and convert to number density
1669 # differentiate and convert to number density
1661 ndphi=dataOut.NSHTS-4
1670 ndphi=dataOut.NSHTS-4
1662
1671
1663 #dataOut.phi=numpy.unwrap(dataOut.phi)
1672 #dataOut.phi=numpy.unwrap(dataOut.phi)
1664 f1=numpy.exp((dataOut.phi*1.j)/10)
1673 f1=numpy.exp((dataOut.phi*1.j)/10)
1665 f2=numpy.exp((dataOut.phi*2.j)/10)
1674 f2=numpy.exp((dataOut.phi*2.j)/10)
1666
1675
1667 for i in range(2,dataOut.NSHTS-2):
1676 for i in range(2,dataOut.NSHTS-2):
1668 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1677 fact=(-0.5/(dataOut.RATE*dataOut.DH))*dataOut.bki[i]
1669 #four-point derivative, no phase unwrapping necessary
1678 #four-point derivative, no phase unwrapping necessary
1670 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1679 ####dataOut.dphi[i]=((((theta[i+1]-theta[i-1])+(2.0*(theta[i+2]-theta[i-2])))/thetai[i])).real/10.0
1671 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1680 ##dataOut.dphi[i]=((((theta[i-2]-theta[i+2])+(8.0*(theta[i+1]-theta[i-1])))/thetai[i])).real/12.0
1672 ##dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
1681 ##dataOut.dphi[i]=((dataOut.phi[i+1]-dataOut.phi[i-1])+(2.0*(dataOut.phi[i+2]-dataOut.phi[i-2])))/10.0
1673
1682
1674 dataOut.dphi[i]=numpy.angle(f1[i+1]*numpy.conjugate(f1[i-1])*f2[i+2]*numpy.conjugate(f2[i-2]))
1683 dataOut.dphi[i]=numpy.angle(f1[i+1]*numpy.conjugate(f1[i-1])*f2[i+2]*numpy.conjugate(f2[i-2]))
1675
1684
1676
1685
1677 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1686 dataOut.dphi[i]=abs(dataOut.dphi[i]*fact)
1678 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1687 dataOut.sdn1[i]=(4.*(dataOut.sdn2[i-2]+dataOut.sdn2[i+2])+dataOut.sdn2[i-1]+dataOut.sdn2[i+1])
1679 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1688 dataOut.sdn1[i]=numpy.sqrt(dataOut.sdn1[i])*fact
1680
1689
1681 return dataOut
1690 return dataOut
1682
1691
1683 class NormalizeDPPower(Operation):
1692 class NormalizeDPPower(Operation):
1684 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1693 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1685
1694
1686 Parameters:
1695 Parameters:
1687 -----------
1696 -----------
1688 None
1697 None
1689
1698
1690 Example
1699 Example
1691 --------
1700 --------
1692
1701
1693 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1702 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1694
1703
1695 """
1704 """
1696
1705
1697 def __init__(self, **kwargs):
1706 def __init__(self, **kwargs):
1698
1707
1699 Operation.__init__(self, **kwargs)
1708 Operation.__init__(self, **kwargs)
1700 self.aux=1
1709 self.aux=1
1701
1710
1702 def normal(self,a,b,n,m):
1711 def normal(self,a,b,n,m):
1703 chmin=1.0e30
1712 chmin=1.0e30
1704 chisq=numpy.zeros(150,'float32')
1713 chisq=numpy.zeros(150,'float32')
1705 temp=numpy.zeros(150,'float32')
1714 temp=numpy.zeros(150,'float32')
1706
1715
1707 for i in range(2*m-1):
1716 for i in range(2*m-1):
1708 an=al=be=chisq[i]=0.0
1717 an=al=be=chisq[i]=0.0
1709 for j in range(int(n/m)):
1718 for j in range(int(n/m)):
1710 k=int(j+i*n/(2*m))
1719 k=int(j+i*n/(2*m))
1711 if(a[k]>0.0 and b[k]>0.0):
1720 if(a[k]>0.0 and b[k]>0.0):
1712 al+=a[k]*b[k]
1721 al+=a[k]*b[k]
1713 be+=b[k]*b[k]
1722 be+=b[k]*b[k]
1714
1723
1715 if(be>0.0):
1724 if(be>0.0):
1716 temp[i]=al/be
1725 temp[i]=al/be
1717 else:
1726 else:
1718 temp[i]=1.0
1727 temp[i]=1.0
1719
1728
1720 for j in range(int(n/m)):
1729 for j in range(int(n/m)):
1721 k=int(j+i*n/(2*m))
1730 k=int(j+i*n/(2*m))
1722 if(a[k]>0.0 and b[k]>0.0):
1731 if(a[k]>0.0 and b[k]>0.0):
1723 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1732 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1724 an=an+1
1733 an=an+1
1725
1734
1726 if(chisq[i]>0.0):
1735 if(chisq[i]>0.0):
1727 chisq[i]/=an
1736 chisq[i]/=an
1728
1737
1729 for i in range(int(2*m-1)):
1738 for i in range(int(2*m-1)):
1730 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1739 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1731 chmin=chisq[i]
1740 chmin=chisq[i]
1732 cf=temp[i]
1741 cf=temp[i]
1733 return cf
1742 return cf
1734
1743
1735 def normalize(self,dataOut):
1744 def normalize(self,dataOut):
1736
1745
1737 if self.aux==1:
1746 if self.aux==1:
1738 dataOut.cf=numpy.zeros(1,'float32')
1747 dataOut.cf=numpy.zeros(1,'float32')
1739 dataOut.cflast=numpy.zeros(1,'float32')
1748 dataOut.cflast=numpy.zeros(1,'float32')
1740 self.aux=0
1749 self.aux=0
1741
1750
1742 night_first=300.0
1751 night_first=300.0
1743 night_first1= 310.0
1752 night_first1= 310.0
1744 night_end= 450.0
1753 night_end= 450.0
1745 day_first=250.0
1754 day_first=250.0
1746 day_end=400.0
1755 day_end=400.0
1747 day_first_sunrise=190.0
1756 day_first_sunrise=190.0
1748 day_end_sunrise=280.0
1757 day_end_sunrise=280.0
1749
1758
1750 print(dataOut.ut_Faraday)
1759 print(dataOut.ut_Faraday)
1751 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1760 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1752 print("EARLY")
1761 print("EARLY")
1753 i2=(night_end-dataOut.range1[0])/dataOut.DH
1762 i2=(night_end-dataOut.range1[0])/dataOut.DH
1754 i1=(night_first -dataOut.range1[0])/dataOut.DH
1763 i1=(night_first -dataOut.range1[0])/dataOut.DH
1755 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1764 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1756 print("NIGHT")
1765 print("NIGHT")
1757 i2=(night_end-dataOut.range1[0])/dataOut.DH
1766 i2=(night_end-dataOut.range1[0])/dataOut.DH
1758 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1767 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1759 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1768 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1760 print("SUNRISE")
1769 print("SUNRISE")
1761 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1770 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1762 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
1771 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
1763 else:
1772 else:
1764 print("ELSE")
1773 print("ELSE")
1765 i2=(day_end-dataOut.range1[0])/dataOut.DH
1774 i2=(day_end-dataOut.range1[0])/dataOut.DH
1766 i1=(day_first -dataOut.range1[0])/dataOut.DH
1775 i1=(day_first -dataOut.range1[0])/dataOut.DH
1767 #print(i1*dataOut.DH)
1776 #print(i1*dataOut.DH)
1768 #print(i2*dataOut.DH)
1777 #print(i2*dataOut.DH)
1769
1778
1770 i1=int(i1)
1779 i1=int(i1)
1771 i2=int(i2)
1780 i2=int(i2)
1772
1781
1773 try:
1782 try:
1774 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1783 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1775 except:
1784 except:
1776 pass
1785 pass
1777
1786
1778 #print(dataOut.ph2)
1787 #print(dataOut.ph2)
1779 #input()
1788 #input()
1780 # in case of spread F, normalize much higher
1789 # in case of spread F, normalize much higher
1781 if(dataOut.cf<dataOut.cflast[0]/10.0):
1790 if(dataOut.cf<dataOut.cflast[0]/10.0):
1782 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1791 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1783 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1792 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1784 i1=int(i1)
1793 i1=int(i1)
1785 i2=int(i2)
1794 i2=int(i2)
1786 try:
1795 try:
1787 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1796 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1788 except:
1797 except:
1789 pass
1798 pass
1790
1799
1791 dataOut.cflast[0]=dataOut.cf
1800 dataOut.cflast[0]=dataOut.cf
1792
1801
1793 ## normalize double pulse power and error bars to Faraday
1802 ## normalize double pulse power and error bars to Faraday
1794 for i in range(dataOut.NSHTS):
1803 for i in range(dataOut.NSHTS):
1795 dataOut.ph2[i]*=dataOut.cf
1804 dataOut.ph2[i]*=dataOut.cf
1796 dataOut.sdp2[i]*=dataOut.cf
1805 dataOut.sdp2[i]*=dataOut.cf
1797 #print(dataOut.ph2)
1806 #print(dataOut.ph2)
1798 #input()
1807 #input()
1799
1808
1800 for i in range(dataOut.NSHTS):
1809 for i in range(dataOut.NSHTS):
1801 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1810 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1802 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1811 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1803
1812
1804
1813
1805 def run(self,dataOut):
1814 def run(self,dataOut):
1806
1815
1807 self.normalize(dataOut)
1816 self.normalize(dataOut)
1808 #print(dataOut.ph2)
1817 #print(dataOut.ph2)
1809 #print(dataOut.sdp2)
1818 #print(dataOut.sdp2)
1810 #input()
1819 #input()
1811
1820
1812
1821
1813 return dataOut
1822 return dataOut
1814
1823
1815 class NormalizeDPPowerRoberto(Operation):
1824 class NormalizeDPPowerRoberto(Operation):
1816 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1825 """Operation to normalize relative electron density from power with total electron density from Farday angle.
1817
1826
1818 Parameters:
1827 Parameters:
1819 -----------
1828 -----------
1820 None
1829 None
1821
1830
1822 Example
1831 Example
1823 --------
1832 --------
1824
1833
1825 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1834 op = proc_unit.addOperation(name='NormalizeDPPower', optype='other')
1826
1835
1827 """
1836 """
1828
1837
1829 def __init__(self, **kwargs):
1838 def __init__(self, **kwargs):
1830
1839
1831 Operation.__init__(self, **kwargs)
1840 Operation.__init__(self, **kwargs)
1832 self.aux=1
1841 self.aux=1
1833
1842
1834 def normal(self,a,b,n,m):
1843 def normal(self,a,b,n,m):
1835 chmin=1.0e30
1844 chmin=1.0e30
1836 chisq=numpy.zeros(150,'float32')
1845 chisq=numpy.zeros(150,'float32')
1837 temp=numpy.zeros(150,'float32')
1846 temp=numpy.zeros(150,'float32')
1838
1847
1839 for i in range(2*m-1):
1848 for i in range(2*m-1):
1840 an=al=be=chisq[i]=0.0
1849 an=al=be=chisq[i]=0.0
1841 for j in range(int(n/m)):
1850 for j in range(int(n/m)):
1842 k=int(j+i*n/(2*m))
1851 k=int(j+i*n/(2*m))
1843 if(a[k]>0.0 and b[k]>0.0):
1852 if(a[k]>0.0 and b[k]>0.0):
1844 al+=a[k]*b[k]
1853 al+=a[k]*b[k]
1845 be+=b[k]*b[k]
1854 be+=b[k]*b[k]
1846
1855
1847 if(be>0.0):
1856 if(be>0.0):
1848 temp[i]=al/be
1857 temp[i]=al/be
1849 else:
1858 else:
1850 temp[i]=1.0
1859 temp[i]=1.0
1851
1860
1852 for j in range(int(n/m)):
1861 for j in range(int(n/m)):
1853 k=int(j+i*n/(2*m))
1862 k=int(j+i*n/(2*m))
1854 if(a[k]>0.0 and b[k]>0.0):
1863 if(a[k]>0.0 and b[k]>0.0):
1855 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1864 chisq[i]+=(numpy.log10(b[k]*temp[i]/a[k]))**2
1856 an=an+1
1865 an=an+1
1857
1866
1858 if(chisq[i]>0.0):
1867 if(chisq[i]>0.0):
1859 chisq[i]/=an
1868 chisq[i]/=an
1860
1869
1861 for i in range(int(2*m-1)):
1870 for i in range(int(2*m-1)):
1862 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1871 if(chisq[i]<chmin and chisq[i]>1.0e-6):
1863 chmin=chisq[i]
1872 chmin=chisq[i]
1864 cf=temp[i]
1873 cf=temp[i]
1865 return cf
1874 return cf
1866
1875
1867 def normalize(self,dataOut):
1876 def normalize(self,dataOut):
1868
1877
1869 if self.aux==1:
1878 if self.aux==1:
1870 dataOut.cf=numpy.zeros(1,'float32')
1879 dataOut.cf=numpy.zeros(1,'float32')
1871 dataOut.cflast=numpy.zeros(1,'float32')
1880 dataOut.cflast=numpy.zeros(1,'float32')
1872 self.aux=0
1881 self.aux=0
1873
1882
1874 night_first=300.0
1883 night_first=300.0
1875 night_first1= 310.0
1884 night_first1= 310.0
1876 night_end= 450.0
1885 night_end= 450.0
1877 day_first=250.0
1886 day_first=250.0
1878 day_end=400.0
1887 day_end=400.0
1879 day_first_sunrise=190.0
1888 day_first_sunrise=190.0
1880 day_end_sunrise=350.0
1889 day_end_sunrise=350.0
1881
1890
1882 print(dataOut.ut_Faraday)
1891 print(dataOut.ut_Faraday)
1883 '''
1892 '''
1884 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1893 if(dataOut.ut_Faraday>4.0 and dataOut.ut_Faraday<11.0): #early
1885 print("EARLY")
1894 print("EARLY")
1886 i2=(night_end-dataOut.range1[0])/dataOut.DH
1895 i2=(night_end-dataOut.range1[0])/dataOut.DH
1887 i1=(night_first -dataOut.range1[0])/dataOut.DH
1896 i1=(night_first -dataOut.range1[0])/dataOut.DH
1888 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1897 elif (dataOut.ut_Faraday>0.0 and dataOut.ut_Faraday<4.0): #night
1889 print("NIGHT")
1898 print("NIGHT")
1890 i2=(night_end-dataOut.range1[0])/dataOut.DH
1899 i2=(night_end-dataOut.range1[0])/dataOut.DH
1891 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1900 i1=(night_first1 -dataOut.range1[0])/dataOut.DH
1892 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1901 elif (dataOut.ut_Faraday>=11.0 and dataOut.ut_Faraday<13.5): #sunrise
1893 print("SUNRISE")
1902 print("SUNRISE")
1894 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1903 i2=( day_end_sunrise-dataOut.range1[0])/dataOut.DH
1895 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
1904 i1=(day_first_sunrise - dataOut.range1[0])/dataOut.DH
1896 else:
1905 else:
1897 print("ELSE")
1906 print("ELSE")
1898 i2=(day_end-dataOut.range1[0])/dataOut.DH
1907 i2=(day_end-dataOut.range1[0])/dataOut.DH
1899 i1=(day_first -dataOut.range1[0])/dataOut.DH
1908 i1=(day_first -dataOut.range1[0])/dataOut.DH
1900 '''
1909 '''
1901 i2=(420-dataOut.range1[0])/dataOut.DH
1910 i2=(420-dataOut.range1[0])/dataOut.DH
1902 i1=(200 -dataOut.range1[0])/dataOut.DH
1911 i1=(200 -dataOut.range1[0])/dataOut.DH
1903 print(i1*dataOut.DH)
1912 print(i1*dataOut.DH)
1904 print(i2*dataOut.DH)
1913 print(i2*dataOut.DH)
1905
1914
1906 i1=int(i1)
1915 i1=int(i1)
1907 i2=int(i2)
1916 i2=int(i2)
1908
1917
1909 try:
1918 try:
1910 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1919 dataOut.cf=self.normal(dataOut.dphi[i1::], dataOut.ph2[i1::], i2-i1, 1)
1911 except:
1920 except:
1912 pass
1921 pass
1913
1922
1914 #print(dataOut.ph2)
1923 #print(dataOut.ph2)
1915 #input()
1924 #input()
1916 # in case of spread F, normalize much higher
1925 # in case of spread F, normalize much higher
1917 if(dataOut.cf<dataOut.cflast[0]/10.0):
1926 if(dataOut.cf<dataOut.cflast[0]/10.0):
1918 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1927 i1=(night_first1+100.-dataOut.range1[0])/dataOut.DH
1919 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1928 i2=(night_end+100.0-dataOut.range1[0])/dataOut.DH
1920 i1=int(i1)
1929 i1=int(i1)
1921 i2=int(i2)
1930 i2=int(i2)
1922 try:
1931 try:
1923 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1932 dataOut.cf=self.normal(dataOut.dphi[int(i1)::], dataOut.ph2[int(i1)::], int(i2-i1), 1)
1924 except:
1933 except:
1925 pass
1934 pass
1926
1935
1927 dataOut.cflast[0]=dataOut.cf
1936 dataOut.cflast[0]=dataOut.cf
1928
1937
1929 ## normalize double pulse power and error bars to Faraday
1938 ## normalize double pulse power and error bars to Faraday
1930 for i in range(dataOut.NSHTS):
1939 for i in range(dataOut.NSHTS):
1931 dataOut.ph2[i]*=dataOut.cf
1940 dataOut.ph2[i]*=dataOut.cf
1932 dataOut.sdp2[i]*=dataOut.cf
1941 dataOut.sdp2[i]*=dataOut.cf
1933 #print(dataOut.ph2)
1942 #print(dataOut.ph2)
1934 #input()
1943 #input()
1935
1944
1936 for i in range(dataOut.NSHTS):
1945 for i in range(dataOut.NSHTS):
1937 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1946 dataOut.ph2[i]=(max(1.0, dataOut.ph2[i]))
1938 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1947 dataOut.dphi[i]=(max(1.0, dataOut.dphi[i]))
1939
1948
1940
1949
1941 def run(self,dataOut):
1950 def run(self,dataOut):
1942
1951
1943 self.normalize(dataOut)
1952 self.normalize(dataOut)
1944 #print(dataOut.ph2)
1953 #print(dataOut.ph2)
1945 #print(dataOut.sdp2)
1954 #print(dataOut.sdp2)
1946 #input()
1955 #input()
1947
1956
1948
1957
1949 return dataOut
1958 return dataOut
1950
1959
1951
1960
1952 class suppress_stdout_stderr(object):
1961 class suppress_stdout_stderr(object):
1953 '''
1962 '''
1954 A context manager for doing a "deep suppression" of stdout and stderr in
1963 A context manager for doing a "deep suppression" of stdout and stderr in
1955 Python, i.e. will suppress all print, even if the print originates in a
1964 Python, i.e. will suppress all print, even if the print originates in a
1956 compiled C/Fortran sub-function.
1965 compiled C/Fortran sub-function.
1957 This will not suppress raised exceptions, since exceptions are printed
1966 This will not suppress raised exceptions, since exceptions are printed
1958 to stderr just before a script exits, and after the context manager has
1967 to stderr just before a script exits, and after the context manager has
1959 exited (at least, I think that is why it lets exceptions through).
1968 exited (at least, I think that is why it lets exceptions through).
1960
1969
1961 '''
1970 '''
1962 def __init__(self):
1971 def __init__(self):
1963 # Open a pair of null files
1972 # Open a pair of null files
1964 self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)]
1973 self.null_fds = [os.open(os.devnull,os.O_RDWR) for x in range(2)]
1965 # Save the actual stdout (1) and stderr (2) file descriptors.
1974 # Save the actual stdout (1) and stderr (2) file descriptors.
1966 self.save_fds = [os.dup(1), os.dup(2)]
1975 self.save_fds = [os.dup(1), os.dup(2)]
1967
1976
1968 def __enter__(self):
1977 def __enter__(self):
1969 # Assign the null pointers to stdout and stderr.
1978 # Assign the null pointers to stdout and stderr.
1970 os.dup2(self.null_fds[0],1)
1979 os.dup2(self.null_fds[0],1)
1971 os.dup2(self.null_fds[1],2)
1980 os.dup2(self.null_fds[1],2)
1972
1981
1973 def __exit__(self, *_):
1982 def __exit__(self, *_):
1974 # Re-assign the real stdout/stderr back to (1) and (2)
1983 # Re-assign the real stdout/stderr back to (1) and (2)
1975 os.dup2(self.save_fds[0],1)
1984 os.dup2(self.save_fds[0],1)
1976 os.dup2(self.save_fds[1],2)
1985 os.dup2(self.save_fds[1],2)
1977 # Close all file descriptors
1986 # Close all file descriptors
1978 for fd in self.null_fds + self.save_fds:
1987 for fd in self.null_fds + self.save_fds:
1979 os.close(fd)
1988 os.close(fd)
1980
1989
1981
1990
1982 from schainpy.model.proc import fitacf_guess
1983 from schainpy.model.proc import fitacf_fit_short
1984 class DPTemperaturesEstimation(Operation):
1991 class DPTemperaturesEstimation(Operation):
1985 """Operation to estimate temperatures for Double Pulse data.
1992 """Operation to estimate temperatures for Double Pulse data.
1986
1993
1987 Parameters:
1994 Parameters:
1988 -----------
1995 -----------
1989 IBITS : int
1996 IBITS : int
1990 .*
1997 .*
1991
1998
1992 Example
1999 Example
1993 --------
2000 --------
1994
2001
1995 op = proc_unit.addOperation(name='DPTemperaturesEstimation', optype='other')
2002 op = proc_unit.addOperation(name='DPTemperaturesEstimation', optype='other')
1996 op.addParameter(name='IBITS', value='16', format='int')
2003 op.addParameter(name='IBITS', value='16', format='int')
1997
2004
1998 """
2005 """
1999
2006
2000 def __init__(self, **kwargs):
2007 def __init__(self, **kwargs):
2001
2008
2002 Operation.__init__(self, **kwargs)
2009 Operation.__init__(self, **kwargs)
2003
2010
2004 self.aux=1
2011 self.aux=1
2005
2012
2006 def Estimation(self,dataOut):
2013 def Estimation(self,dataOut):
2007 with suppress_stdout_stderr():
2014 with suppress_stdout_stderr():
2008 #if True:
2015 #if True:
2009
2016
2010 if self.aux==1:
2017 if self.aux==1:
2011 dataOut.ifit=numpy.zeros(5,order='F',dtype='int32')
2018 dataOut.ifit=numpy.zeros(5,order='F',dtype='int32')
2012 dataOut.m=numpy.zeros(1,order='F',dtype='int32')
2019 dataOut.m=numpy.zeros(1,order='F',dtype='int32')
2013 dataOut.te2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2020 dataOut.te2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2014 dataOut.ti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2021 dataOut.ti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2015 dataOut.ete2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2022 dataOut.ete2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2016 dataOut.eti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2023 dataOut.eti2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2017
2024
2018 self.aux=0
2025 self.aux=0
2019
2026
2020 dataOut.phy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2027 dataOut.phy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2021 dataOut.ephy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2028 dataOut.ephy2=numpy.zeros(dataOut.NSHTS,order='F',dtype='float32')
2022 dataOut.info2=numpy.zeros(dataOut.NDP,order='F',dtype='float32')
2029 dataOut.info2=numpy.zeros(dataOut.NDP,order='F',dtype='float32')
2023 dataOut.params=numpy.zeros(10,order='F',dtype='float32')
2030 dataOut.params=numpy.zeros(10,order='F',dtype='float32')
2024 dataOut.cov=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2031 dataOut.cov=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2025 dataOut.covinv=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2032 dataOut.covinv=numpy.zeros(dataOut.IBITS*dataOut.IBITS,order='F',dtype='float32')
2026
2033
2027 #null_fd = os.open(os.devnull, os.O_RDWR)
2034 #null_fd = os.open(os.devnull, os.O_RDWR)
2028 #os.dup2(null_fd, 1)
2035 #os.dup2(null_fd, 1)
2029
2036
2030 for i in range(10,dataOut.NSHTS): #no point below 150 km
2037 for i in range(10,dataOut.NSHTS): #no point below 150 km
2031
2038
2032 #some definitions
2039 #some definitions
2033 iflag=0 # inicializado a cero?
2040 iflag=0 # inicializado a cero?
2034 wl = 3.0
2041 wl = 3.0
2035 x=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2042 x=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2036 y=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2043 y=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2037 e=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2044 e=numpy.zeros(dataOut.DPL+dataOut.IBITS,order='F',dtype='float32')
2038 eb=numpy.zeros(5,order='F',dtype='float32')
2045 eb=numpy.zeros(5,order='F',dtype='float32')
2039 zero=numpy.zeros(1,order='F',dtype='float32')
2046 zero=numpy.zeros(1,order='F',dtype='float32')
2040 depth=numpy.zeros(1,order='F',dtype='float32')
2047 depth=numpy.zeros(1,order='F',dtype='float32')
2041 t1=numpy.zeros(1,order='F',dtype='float32')
2048 t1=numpy.zeros(1,order='F',dtype='float32')
2042 t2=numpy.zeros(1,order='F',dtype='float32')
2049 t2=numpy.zeros(1,order='F',dtype='float32')
2043
2050
2044 if i>10 and l1>=0:
2051 if i>10 and l1>=0:
2045 if l1==0:
2052 if l1==0:
2046 l1=1
2053 l1=1
2047
2054
2048 dataOut.cov=numpy.reshape(dataOut.cov,l1*l1)
2055 dataOut.cov=numpy.reshape(dataOut.cov,l1*l1)
2049 dataOut.cov=numpy.resize(dataOut.cov,dataOut.DPL*dataOut.DPL)
2056 dataOut.cov=numpy.resize(dataOut.cov,dataOut.DPL*dataOut.DPL)
2050 dataOut.covinv=numpy.reshape(dataOut.covinv,l1*l1)
2057 dataOut.covinv=numpy.reshape(dataOut.covinv,l1*l1)
2051 dataOut.covinv=numpy.resize(dataOut.covinv,dataOut.DPL*dataOut.DPL)
2058 dataOut.covinv=numpy.resize(dataOut.covinv,dataOut.DPL*dataOut.DPL)
2052
2059
2053 for l in range(dataOut.DPL*dataOut.DPL):
2060 for l in range(dataOut.DPL*dataOut.DPL):
2054 dataOut.cov[l]=0.0
2061 dataOut.cov[l]=0.0
2055 acfm= (dataOut.rhor[i][0])**2 + (dataOut.rhoi[i][0])**2
2062 acfm= (dataOut.rhor[i][0])**2 + (dataOut.rhoi[i][0])**2
2056 if acfm> 0.0:
2063 if acfm> 0.0:
2057 cc=dataOut.rhor[i][0]/acfm
2064 cc=dataOut.rhor[i][0]/acfm
2058 ss=dataOut.rhoi[i][0]/acfm
2065 ss=dataOut.rhoi[i][0]/acfm
2059 else:
2066 else:
2060 cc=1.
2067 cc=1.
2061 ss=0.
2068 ss=0.
2062 # keep only uncontaminated data, don't pass zero lag to fitter
2069 # keep only uncontaminated data, don't pass zero lag to fitter
2063 l1=0
2070 l1=0
2064 for l in range(0+1,dataOut.DPL):
2071 for l in range(0+1,dataOut.DPL):
2065 if dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0:
2072 if dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0:
2066 y[l1]=dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss
2073 y[l1]=dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss
2067 x[l1]=dataOut.alag[l]*1.0e-3
2074 x[l1]=dataOut.alag[l]*1.0e-3
2068 dataOut.sd[i][l]=dataOut.sd[i][l]/((acfm)**2)# important
2075 dataOut.sd[i][l]=dataOut.sd[i][l]/((acfm)**2)# important
2069 e[l1]=dataOut.sd[i][l] #this is the variance, not the st. dev.
2076 e[l1]=dataOut.sd[i][l] #this is the variance, not the st. dev.
2070 l1=l1+1
2077 l1=l1+1
2071
2078
2072 for l in range(l1*(l1+1)):
2079 for l in range(l1*(l1+1)):
2073 dataOut.cov[l]=0.0
2080 dataOut.cov[l]=0.0
2074 for l in range(l1):
2081 for l in range(l1):
2075 dataOut.cov[l*(1+l1)]=e[l]
2082 dataOut.cov[l*(1+l1)]=e[l]
2076 angle=dataOut.thb[i]*0.01745
2083 angle=dataOut.thb[i]*0.01745
2077 bm=dataOut.bfm[i]
2084 bm=dataOut.bfm[i]
2078 dataOut.params[0]=1.0 #norm
2085 dataOut.params[0]=1.0 #norm
2079 dataOut.params[1]=1000.0 #te
2086 dataOut.params[1]=1000.0 #te
2080 dataOut.params[2]=800.0 #ti
2087 dataOut.params[2]=800.0 #ti
2081 dataOut.params[3]=0.00 #ph
2088 dataOut.params[3]=0.00 #ph
2082 dataOut.params[4]=0.00 #phe
2089 dataOut.params[4]=0.00 #phe
2083
2090
2084 if l1!=0:
2091 if l1!=0:
2085 x=numpy.resize(x,l1)
2092 x=numpy.resize(x,l1)
2086 y=numpy.resize(y,l1)
2093 y=numpy.resize(y,l1)
2087 else:
2094 else:
2088 x=numpy.resize(x,1)
2095 x=numpy.resize(x,1)
2089 y=numpy.resize(y,1)
2096 y=numpy.resize(y,1)
2090
2097
2091 if True: #len(y)!=0:
2098 if True: #len(y)!=0:
2092
2099
2093 fitacf_guess.guess(y,x,zero,depth,t1,t2,len(y))
2100 fitacf_guess.guess(y,x,zero,depth,t1,t2,len(y))
2094 t2=t1/t2
2101 t2=t1/t2
2095
2102
2096
2103
2097
2104
2098
2105
2099 if (t1<5000.0 and t1> 600.0):
2106 if (t1<5000.0 and t1> 600.0):
2100 dataOut.params[1]=t1
2107 dataOut.params[1]=t1
2101 dataOut.params[2]=min(t2,t1)
2108 dataOut.params[2]=min(t2,t1)
2102 dataOut.ifit[1]=dataOut.ifit[2]=1
2109 dataOut.ifit[1]=dataOut.ifit[2]=1
2103 dataOut.ifit[0]=dataOut.ifit[3]=dataOut.ifit[4]=0
2110 dataOut.ifit[0]=dataOut.ifit[3]=dataOut.ifit[4]=0
2104 #print(dataOut.ut_Faraday)
2111 #print(dataOut.ut_Faraday)
2105 if dataOut.ut_Faraday<10.0 and dataOut.ut_Faraday>=0.5:
2112 if dataOut.ut_Faraday<10.0 and dataOut.ut_Faraday>=0.5:
2106 dataOut.ifit[2]=0
2113 dataOut.ifit[2]=0
2107
2114
2108 den=dataOut.ph2[i]
2115 den=dataOut.ph2[i]
2109
2116
2110 if l1!=0:
2117 if l1!=0:
2111 dataOut.covinv=dataOut.covinv[0:l1*l1].reshape((l1,l1))
2118 dataOut.covinv=dataOut.covinv[0:l1*l1].reshape((l1,l1))
2112 dataOut.cov=dataOut.cov[0:l1*l1].reshape((l1,l1))
2119 dataOut.cov=dataOut.cov[0:l1*l1].reshape((l1,l1))
2113 e=numpy.resize(e,l1)
2120 e=numpy.resize(e,l1)
2114 else:
2121 else:
2115 dataOut.covinv=numpy.resize(dataOut.covinv,1)
2122 dataOut.covinv=numpy.resize(dataOut.covinv,1)
2116 dataOut.cov=numpy.resize(dataOut.cov,1)
2123 dataOut.cov=numpy.resize(dataOut.cov,1)
2117 e=numpy.resize(e,1)
2124 e=numpy.resize(e,1)
2118
2125
2119 eb=numpy.resize(eb,10)
2126 eb=numpy.resize(eb,10)
2120 dataOut.ifit=numpy.resize(dataOut.ifit,10)
2127 dataOut.ifit=numpy.resize(dataOut.ifit,10)
2121
2128
2122
2129
2123
2130
2124 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2131 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2125
2132
2126 #exit()
2133 #exit()
2127
2134
2128 if dataOut.params[2]>dataOut.params[1]*1.05:
2135 if dataOut.params[2]>dataOut.params[1]*1.05:
2129 dataOut.ifit[2]=0
2136 dataOut.ifit[2]=0
2130 dataOut.params[1]=dataOut.params[2]=t1
2137 dataOut.params[1]=dataOut.params[2]=t1
2131 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2138 dataOut.covinv,e,dataOut.params,eb,dataOut.m=fitacf_fit_short.fit(wl,x,y,dataOut.cov,dataOut.covinv,e,dataOut.params,bm,angle,den,dataOut.range1[i],dataOut.year,dataOut.ifit,dataOut.m,l1) #
2132
2139
2133 if (dataOut.ifit[2]==0):
2140 if (dataOut.ifit[2]==0):
2134 dataOut.params[2]=dataOut.params[1]
2141 dataOut.params[2]=dataOut.params[1]
2135 if (dataOut.ifit[3]==0 and iflag==0):
2142 if (dataOut.ifit[3]==0 and iflag==0):
2136 dataOut.params[3]=0.0
2143 dataOut.params[3]=0.0
2137 if (dataOut.ifit[4]==0):
2144 if (dataOut.ifit[4]==0):
2138 dataOut.params[4]=0.0
2145 dataOut.params[4]=0.0
2139 dataOut.te2[i]=dataOut.params[1]
2146 dataOut.te2[i]=dataOut.params[1]
2140 dataOut.ti2[i]=dataOut.params[2]
2147 dataOut.ti2[i]=dataOut.params[2]
2141 dataOut.ete2[i]=eb[1]
2148 dataOut.ete2[i]=eb[1]
2142 dataOut.eti2[i]=eb[2]
2149 dataOut.eti2[i]=eb[2]
2143
2150
2144 if dataOut.eti2[i]==0:
2151 if dataOut.eti2[i]==0:
2145 dataOut.eti2[i]=dataOut.ete2[i]
2152 dataOut.eti2[i]=dataOut.ete2[i]
2146
2153
2147 dataOut.phy2[i]=dataOut.params[3]
2154 dataOut.phy2[i]=dataOut.params[3]
2148 dataOut.ephy2[i]=eb[3]
2155 dataOut.ephy2[i]=eb[3]
2149 if(iflag==1):
2156 if(iflag==1):
2150 dataOut.ephy2[i]=0.0
2157 dataOut.ephy2[i]=0.0
2151
2158
2152 if (dataOut.m<=3 and dataOut.m!= 0 and dataOut.te2[i]>400.0):
2159 if (dataOut.m<=3 and dataOut.m!= 0 and dataOut.te2[i]>400.0):
2153 dataOut.info2[i]=1
2160 dataOut.info2[i]=1
2154 else:
2161 else:
2155 dataOut.info2[i]=0
2162 dataOut.info2[i]=0
2156
2163
2157 def run(self,dataOut,IBITS=16):
2164 def run(self,dataOut,IBITS=16):
2158
2165
2159 dataOut.IBITS = IBITS
2166 dataOut.IBITS = IBITS
2160
2167
2161 self.Estimation(dataOut)
2168 self.Estimation(dataOut)
2162
2169
2163
2170
2164 return dataOut
2171 return dataOut
2165
2172
2166 class NeTeTiRecal(NormalizeDPPower,DPTemperaturesEstimation):
2173 class NeTeTiRecal(NormalizeDPPower,DPTemperaturesEstimation):
2167
2174
2168 def __init__(self, **kwargs):
2175 def __init__(self, **kwargs):
2169
2176
2170 Operation.__init__(self, **kwargs)
2177 Operation.__init__(self, **kwargs)
2171 self.aux=0
2178 self.aux=0
2172
2179
2173 def run(self,dataOut):
2180 def run(self,dataOut):
2174
2181
2175 for i in range(dataOut.NSHTS):
2182 for i in range(dataOut.NSHTS):
2176 print("H: ",i*15)
2183 print("H: ",i*15)
2177 print(1+(dataOut.te2[i]/dataOut.ti2[i]))
2184 print(1+(dataOut.te2[i]/dataOut.ti2[i]))
2178 dataOut.ph2[i]*=1+(dataOut.te2[i]/dataOut.ti2[i])
2185 dataOut.ph2[i]*=1+(dataOut.te2[i]/dataOut.ti2[i])
2179
2186
2180 self.normalize(dataOut)
2187 self.normalize(dataOut)
2181 self.Estimation(dataOut)
2188 self.Estimation(dataOut)
2182
2189
2183
2190
2184 return dataOut
2191 return dataOut
2185
2192
2186
2193
2187 from schainpy.model.proc import fitacf_acf2
2188 class DenCorrection(Operation):
2194 class DenCorrection(Operation):
2189
2195
2190 def __init__(self, **kwargs):
2196 def __init__(self, **kwargs):
2191
2197
2192 Operation.__init__(self, **kwargs)
2198 Operation.__init__(self, **kwargs)
2193
2199
2194
2200
2195 def run(self,dataOut):
2201 def run(self,dataOut):
2196
2202
2197 y=numpy.zeros(dataOut.DPL,order='F',dtype='float32')
2203 y=numpy.zeros(dataOut.DPL,order='F',dtype='float32')
2198 #y_aux = numpy.zeros(1,,dtype='float32')
2204 #y_aux = numpy.zeros(1,,dtype='float32')
2199 for i in range(dataOut.NSHTS):
2205 for i in range(dataOut.NSHTS):
2200 y[0]=y[1]=dataOut.range1[i]
2206 y[0]=y[1]=dataOut.range1[i]
2201
2207
2202 y = y.astype(dtype='float64',order='F')
2208 y = y.astype(dtype='float64',order='F')
2203 three=int(3)
2209 three=int(3)
2204 wl = 3.0
2210 wl = 3.0
2205 tion=numpy.zeros(three,order='F',dtype='float32')
2211 tion=numpy.zeros(three,order='F',dtype='float32')
2206 fion=numpy.zeros(three,order='F',dtype='float32')
2212 fion=numpy.zeros(three,order='F',dtype='float32')
2207 nui=numpy.zeros(three,order='F',dtype='float32')
2213 nui=numpy.zeros(three,order='F',dtype='float32')
2208 wion=numpy.zeros(three,order='F',dtype='int32')
2214 wion=numpy.zeros(three,order='F',dtype='int32')
2209 bline=0.0
2215 bline=0.0
2210 #bline=numpy.zeros(1,order='F',dtype='float32')
2216 #bline=numpy.zeros(1,order='F',dtype='float32')
2211
2217
2212
2218
2213 #print("**** ACF2 WRAPPER ***** ",fitacf_acf2.acf2.__doc__ )
2219 #print("**** ACF2 WRAPPER ***** ",fitacf_acf2.acf2.__doc__ )
2214 print("BEFORE",dataOut.ph2[10:35])
2220 print("BEFORE",dataOut.ph2[10:35])
2215 for i in range(dataOut.NSHTS):
2221 for i in range(dataOut.NSHTS):
2216 if dataOut.info2[i]==1:
2222 if dataOut.info2[i]==1:
2217 angle=dataOut.thb[i]*0.01745
2223 angle=dataOut.thb[i]*0.01745
2218 nue=nui[0]=nui[1]=nui[2]=0.0#nui[3]=0.0
2224 nue=nui[0]=nui[1]=nui[2]=0.0#nui[3]=0.0
2219 wion[0]=16
2225 wion[0]=16
2220 wion[1]=1
2226 wion[1]=1
2221 wion[2]=4
2227 wion[2]=4
2222 tion[0]=tion[1]=tion[2]=dataOut.ti2[i]
2228 tion[0]=tion[1]=tion[2]=dataOut.ti2[i]
2223 fion[0]=1.0-dataOut.phy2[i]
2229 fion[0]=1.0-dataOut.phy2[i]
2224 fion[1]=dataOut.phy2[i]
2230 fion[1]=dataOut.phy2[i]
2225 fion[2]=0.0
2231 fion[2]=0.0
2226 for j in range(dataOut.DPL):
2232 for j in range(dataOut.DPL):
2227 tau=dataOut.alag[j]*1.0e-3
2233 tau=dataOut.alag[j]*1.0e-3
2228
2234
2229 '''
2235 '''
2230 print("**** input from acf2 ***** ")
2236 print("**** input from acf2 ***** ")
2231 print("wl ",wl)
2237 print("wl ",wl)
2232 print("tau ",tau)
2238 print("tau ",tau)
2233 print("te2[i] ",dataOut.te2[i])
2239 print("te2[i] ",dataOut.te2[i])
2234 print("tion ",tion)
2240 print("tion ",tion)
2235 print("fion ",fion)
2241 print("fion ",fion)
2236 print("nue ",nue)
2242 print("nue ",nue)
2237 print("nui ",nui)
2243 print("nui ",nui)
2238 print("wion ",wion)
2244 print("wion ",wion)
2239 print("angle ",angle)
2245 print("angle ",angle)
2240 print("ph2[i] ",dataOut.ph2[i])
2246 print("ph2[i] ",dataOut.ph2[i])
2241 print("bfm[i] ",dataOut.bfm[i])
2247 print("bfm[i] ",dataOut.bfm[i])
2242 print("y[j] ",y[j])
2248 print("y[j] ",y[j])
2243 '''
2249 '''
2244 print("Before y[j] ",y[j])
2250 print("Before y[j] ",y[j])
2245 #with suppress_stdout_stderr():
2251 #with suppress_stdout_stderr():
2246 y[j]=fitacf_acf2.acf2(wl,tau,dataOut.te2[i],tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],y[j],three)
2252 y[j]=fitacf_acf2.acf2(wl,tau,dataOut.te2[i],tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],y[j],three)
2247 #print("l",l)
2253 #print("l",l)
2248 print("After y[j] ",y[j])
2254 print("After y[j] ",y[j])
2249 '''
2255 '''
2250 print("**** output from acf2 ***** ")
2256 print("**** output from acf2 ***** ")
2251 print("wl ",wl)
2257 print("wl ",wl)
2252 print("tau ",tau)
2258 print("tau ",tau)
2253 print("te2[i] ",dataOut.te2[i])
2259 print("te2[i] ",dataOut.te2[i])
2254 print("tion ",tion)
2260 print("tion ",tion)
2255 print("fion ",fion)
2261 print("fion ",fion)
2256 print("nue ",nue)
2262 print("nue ",nue)
2257 print("nui ",nui)
2263 print("nui ",nui)
2258 print("wion ",wion)
2264 print("wion ",wion)
2259 print("angle ",angle)
2265 print("angle ",angle)
2260 print("ph2[i] ",dataOut.ph2[i])
2266 print("ph2[i] ",dataOut.ph2[i])
2261 print("bfm[i] ",dataOut.bfm[i])
2267 print("bfm[i] ",dataOut.bfm[i])
2262 print("y[j] ",y[j])
2268 print("y[j] ",y[j])
2263 print("i ",i , " j ",j , "y[j] ",y[j])
2269 print("i ",i , " j ",j , "y[j] ",y[j])
2264 '''
2270 '''
2265
2271
2266
2272
2267 #exit(1)
2273 #exit(1)
2268 if dataOut.ut_Faraday>11.0 and dataOut.range1[i]>150.0 and dataOut.range1[i]<400.0:
2274 if dataOut.ut_Faraday>11.0 and dataOut.range1[i]>150.0 and dataOut.range1[i]<400.0:
2269 tau=0.0
2275 tau=0.0
2270 #with suppress_stdout_stderr():
2276 #with suppress_stdout_stderr():
2271 bline=fitacf_acf2.acf2(wl,tau,tion,tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],bline,three)
2277 bline=fitacf_acf2.acf2(wl,tau,tion,tion,fion,nue,nui,wion,angle,dataOut.ph2[i],dataOut.bfm[i],bline,three)
2272 cf=min(1.2,max(1.0,bline/y[0]))
2278 cf=min(1.2,max(1.0,bline/y[0]))
2273 print("bline: ",bline)
2279 print("bline: ",bline)
2274 if cf != 1.0:
2280 if cf != 1.0:
2275 print("bline: ",bline)
2281 print("bline: ",bline)
2276 print("cf: ",cf)
2282 print("cf: ",cf)
2277 #exit(1)
2283 #exit(1)
2278 #print("cf: ",cf)
2284 #print("cf: ",cf)
2279 dataOut.ph2[i]=cf*dataOut.ph2[i]
2285 dataOut.ph2[i]=cf*dataOut.ph2[i]
2280 dataOut.sdp2[i]=cf*dataOut.sdp2[i]
2286 dataOut.sdp2[i]=cf*dataOut.sdp2[i]
2281 for j in range(1,dataOut.DPL):
2287 for j in range(1,dataOut.DPL):
2282 y[j]=(y[j]/y[0])*dataOut.DH+dataOut.range1[i]
2288 y[j]=(y[j]/y[0])*dataOut.DH+dataOut.range1[i]
2283 y[0]=dataOut.range1[i]+dataOut.DH
2289 y[0]=dataOut.range1[i]+dataOut.DH
2284 #exit(1)
2290 #exit(1)
2285
2291
2286
2292
2287 #exit(1)
2293 #exit(1)
2288 print("AFTER",dataOut.ph2[10:35])
2294 print("AFTER",dataOut.ph2[10:35])
2289 #exit(1)
2295 #exit(1)
2290
2296
2291
2297
2292
2298
2293
2299
2294
2300
2295 return dataOut
2301 return dataOut
2296
2302
2297 class DataPlotCleaner(Operation):
2303 class DataPlotCleaner(Operation):
2298 def __init__(self, **kwargs):
2304 def __init__(self, **kwargs):
2299
2305
2300 Operation.__init__(self, **kwargs)
2306 Operation.__init__(self, **kwargs)
2301
2307
2302 def run(self,dataOut):
2308 def run(self,dataOut):
2303
2309
2304
2310
2305 THRESH_MIN_POW=10000
2311 THRESH_MIN_POW=10000
2306 THRESH_MAX_POW=10000000
2312 THRESH_MAX_POW=10000000
2307 THRESH_MIN_TEMP=500
2313 THRESH_MIN_TEMP=500
2308 THRESH_MAX_TEMP=4000
2314 THRESH_MAX_TEMP=4000
2309 dataOut.DensityClean=numpy.zeros((1,dataOut.NDP))
2315 dataOut.DensityClean=numpy.zeros((1,dataOut.NDP))
2310 dataOut.EDensityClean=numpy.zeros((1,dataOut.NDP))
2316 dataOut.EDensityClean=numpy.zeros((1,dataOut.NDP))
2311 dataOut.ElecTempClean=numpy.zeros((1,dataOut.NDP))
2317 dataOut.ElecTempClean=numpy.zeros((1,dataOut.NDP))
2312 dataOut.EElecTempClean=numpy.zeros((1,dataOut.NDP))
2318 dataOut.EElecTempClean=numpy.zeros((1,dataOut.NDP))
2313 dataOut.IonTempClean=numpy.zeros((1,dataOut.NDP))
2319 dataOut.IonTempClean=numpy.zeros((1,dataOut.NDP))
2314 dataOut.EIonTempClean=numpy.zeros((1,dataOut.NDP))
2320 dataOut.EIonTempClean=numpy.zeros((1,dataOut.NDP))
2315
2321
2316 dataOut.DensityClean[0]=numpy.copy(dataOut.ph2)
2322 dataOut.DensityClean[0]=numpy.copy(dataOut.ph2)
2317 dataOut.EDensityClean[0]=numpy.copy(dataOut.sdp2)
2323 dataOut.EDensityClean[0]=numpy.copy(dataOut.sdp2)
2318 dataOut.ElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2324 dataOut.ElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2319 dataOut.EElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2325 dataOut.EElecTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2320 dataOut.IonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2326 dataOut.IonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2321 dataOut.EIonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2327 dataOut.EIonTempClean[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2322
2328
2323 for i in range(dataOut.NDP):
2329 for i in range(dataOut.NDP):
2324 if dataOut.DensityClean[0,i]<THRESH_MIN_POW:
2330 if dataOut.DensityClean[0,i]<THRESH_MIN_POW:
2325 dataOut.DensityClean[0,i]=THRESH_MIN_POW
2331 dataOut.DensityClean[0,i]=THRESH_MIN_POW
2326
2332
2327 for i in range(dataOut.NDP):
2333 for i in range(dataOut.NDP):
2328 if dataOut.DensityClean[0,i]>THRESH_MAX_POW:
2334 if dataOut.DensityClean[0,i]>THRESH_MAX_POW:
2329 dataOut.DensityClean[0,i]=THRESH_MAX_POW
2335 dataOut.DensityClean[0,i]=THRESH_MAX_POW
2330
2336
2331 for i in range(dataOut.NSHTS):
2337 for i in range(dataOut.NSHTS):
2332 dataOut.ElecTempClean[0,i]=(max(1.0, dataOut.ElecTempClean[0,i]))
2338 dataOut.ElecTempClean[0,i]=(max(1.0, dataOut.ElecTempClean[0,i]))
2333 dataOut.IonTempClean[0,i]=(max(1.0, dataOut.IonTempClean[0,i]))
2339 dataOut.IonTempClean[0,i]=(max(1.0, dataOut.IonTempClean[0,i]))
2334 for i in range(dataOut.NSHTS):
2340 for i in range(dataOut.NSHTS):
2335 if dataOut.ElecTempClean[0,i]<THRESH_MIN_TEMP:
2341 if dataOut.ElecTempClean[0,i]<THRESH_MIN_TEMP:
2336 dataOut.ElecTempClean[0,i]=THRESH_MIN_TEMP
2342 dataOut.ElecTempClean[0,i]=THRESH_MIN_TEMP
2337 if dataOut.IonTempClean[0,i]<THRESH_MIN_TEMP:
2343 if dataOut.IonTempClean[0,i]<THRESH_MIN_TEMP:
2338 dataOut.IonTempClean[0,i]=THRESH_MIN_TEMP
2344 dataOut.IonTempClean[0,i]=THRESH_MIN_TEMP
2339 for i in range(dataOut.NSHTS):
2345 for i in range(dataOut.NSHTS):
2340 if dataOut.ElecTempClean[0,i]>THRESH_MAX_TEMP:
2346 if dataOut.ElecTempClean[0,i]>THRESH_MAX_TEMP:
2341 dataOut.ElecTempClean[0,i]=THRESH_MAX_TEMP
2347 dataOut.ElecTempClean[0,i]=THRESH_MAX_TEMP
2342 if dataOut.IonTempClean[0,i]>THRESH_MAX_TEMP:
2348 if dataOut.IonTempClean[0,i]>THRESH_MAX_TEMP:
2343 dataOut.IonTempClean[0,i]=THRESH_MAX_TEMP
2349 dataOut.IonTempClean[0,i]=THRESH_MAX_TEMP
2344 for i in range(dataOut.NSHTS):
2350 for i in range(dataOut.NSHTS):
2345 if dataOut.EElecTempClean[0,i]>500:#
2351 if dataOut.EElecTempClean[0,i]>500:#
2346 dataOut.ElecTempClean[0,i]=500
2352 dataOut.ElecTempClean[0,i]=500
2347 if dataOut.EIonTempClean[0,i]>500:#
2353 if dataOut.EIonTempClean[0,i]>500:#
2348 dataOut.IonTempClean[0,i]=500
2354 dataOut.IonTempClean[0,i]=500
2349
2355
2350 missing=numpy.nan
2356 missing=numpy.nan
2351
2357
2352 for i in range(dataOut.NSHTS,dataOut.NDP):
2358 for i in range(dataOut.NSHTS,dataOut.NDP):
2353
2359
2354 dataOut.ElecTempClean[0,i]=missing
2360 dataOut.ElecTempClean[0,i]=missing
2355 dataOut.EElecTempClean[0,i]=missing
2361 dataOut.EElecTempClean[0,i]=missing
2356 dataOut.IonTempClean[0,i]=missing
2362 dataOut.IonTempClean[0,i]=missing
2357 dataOut.EIonTempClean[0,i]=missing
2363 dataOut.EIonTempClean[0,i]=missing
2358
2364
2359 return dataOut
2365 return dataOut
2360
2366
2361
2367
2362 class DataSaveCleaner(Operation):
2368 class DataSaveCleaner(Operation):
2363 def __init__(self, **kwargs):
2369 def __init__(self, **kwargs):
2364
2370
2365 Operation.__init__(self, **kwargs)
2371 Operation.__init__(self, **kwargs)
2366
2372
2367
2373
2368 def run(self,dataOut):
2374 def run(self,dataOut):
2369
2375
2370 dataOut.DensityFinal=numpy.zeros((1,dataOut.NDP))
2376 dataOut.DensityFinal=numpy.zeros((1,dataOut.NDP))
2371 dataOut.EDensityFinal=numpy.zeros((1,dataOut.NDP))
2377 dataOut.EDensityFinal=numpy.zeros((1,dataOut.NDP))
2372 dataOut.ElecTempFinal=numpy.zeros((1,dataOut.NDP))
2378 dataOut.ElecTempFinal=numpy.zeros((1,dataOut.NDP))
2373 dataOut.EElecTempFinal=numpy.zeros((1,dataOut.NDP))
2379 dataOut.EElecTempFinal=numpy.zeros((1,dataOut.NDP))
2374 dataOut.IonTempFinal=numpy.zeros((1,dataOut.NDP))
2380 dataOut.IonTempFinal=numpy.zeros((1,dataOut.NDP))
2375 dataOut.EIonTempFinal=numpy.zeros((1,dataOut.NDP))
2381 dataOut.EIonTempFinal=numpy.zeros((1,dataOut.NDP))
2376 dataOut.PhyFinal=numpy.zeros((1,dataOut.NDP))
2382 dataOut.PhyFinal=numpy.zeros((1,dataOut.NDP))
2377 dataOut.EPhyFinal=numpy.zeros((1,dataOut.NDP))
2383 dataOut.EPhyFinal=numpy.zeros((1,dataOut.NDP))
2378
2384
2379 dataOut.DensityFinal[0]=numpy.copy(dataOut.ph2)
2385 dataOut.DensityFinal[0]=numpy.copy(dataOut.ph2)
2380 dataOut.EDensityFinal[0]=numpy.copy(dataOut.sdp2)
2386 dataOut.EDensityFinal[0]=numpy.copy(dataOut.sdp2)
2381 dataOut.ElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2387 dataOut.ElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.te2)
2382 dataOut.EElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2388 dataOut.EElecTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ete2)
2383 dataOut.IonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2389 dataOut.IonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ti2)
2384 dataOut.EIonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2390 dataOut.EIonTempFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.eti2)
2385 dataOut.PhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.phy2)
2391 dataOut.PhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.phy2)
2386 dataOut.EPhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ephy2)
2392 dataOut.EPhyFinal[0,:dataOut.NSHTS]=numpy.copy(dataOut.ephy2)
2387
2393
2388 missing=numpy.nan
2394 missing=numpy.nan
2389
2395
2390 temp_min=100.0
2396 temp_min=100.0
2391 temp_max=3000.0#6000.0e
2397 temp_max=3000.0#6000.0e
2392
2398
2393 for i in range(dataOut.NSHTS):
2399 for i in range(dataOut.NSHTS):
2394
2400
2395 if dataOut.info2[i]!=1:
2401 if dataOut.info2[i]!=1:
2396 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2402 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2397
2403
2398 if dataOut.ElecTempFinal[0,i]<=temp_min or dataOut.ElecTempFinal[0,i]>temp_max or dataOut.EElecTempFinal[0,i]>temp_max:
2404 if dataOut.ElecTempFinal[0,i]<=temp_min or dataOut.ElecTempFinal[0,i]>temp_max or dataOut.EElecTempFinal[0,i]>temp_max:
2399
2405
2400 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2406 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2401
2407
2402
2408
2403 if dataOut.IonTempFinal[0,i]<=temp_min or dataOut.IonTempFinal[0,i]>temp_max or dataOut.EIonTempFinal[0,i]>temp_max:
2409 if dataOut.IonTempFinal[0,i]<=temp_min or dataOut.IonTempFinal[0,i]>temp_max or dataOut.EIonTempFinal[0,i]>temp_max:
2404 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2410 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2405
2411
2406 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2412 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2407 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2413 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2408
2414
2409 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2415 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2410 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2416 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2411 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2417 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2412
2418
2413 if dataOut.EPhyFinal[0,i]<0.0 or dataOut.EPhyFinal[0,i]>1.0:
2419 if dataOut.EPhyFinal[0,i]<0.0 or dataOut.EPhyFinal[0,i]>1.0:
2414 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2420 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2415 if dataOut.EDensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]<9.9e6:
2421 if dataOut.EDensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]>0.0 and dataOut.DensityFinal[0,i]<9.9e6:
2416 dataOut.EDensityFinal[0,i]=max(dataOut.EDensityFinal[0,i],1000.0)
2422 dataOut.EDensityFinal[0,i]=max(dataOut.EDensityFinal[0,i],1000.0)
2417 else:
2423 else:
2418 dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing
2424 dataOut.DensityFinal[0,i]=dataOut.EDensityFinal[0,i]=missing
2419 if dataOut.PhyFinal[0,i]==0 or dataOut.PhyFinal[0,i]>0.4:
2425 if dataOut.PhyFinal[0,i]==0 or dataOut.PhyFinal[0,i]>0.4:
2420 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2426 dataOut.PhyFinal[0,i]=dataOut.EPhyFinal[0,i]=missing
2421 if dataOut.ElecTempFinal[0,i]==dataOut.IonTempFinal[0,i]:
2427 if dataOut.ElecTempFinal[0,i]==dataOut.IonTempFinal[0,i]:
2422 dataOut.EElecTempFinal[0,i]=dataOut.EIonTempFinal[0,i]
2428 dataOut.EElecTempFinal[0,i]=dataOut.EIonTempFinal[0,i]
2423 if numpy.isnan(dataOut.ElecTempFinal[0,i]):
2429 if numpy.isnan(dataOut.ElecTempFinal[0,i]):
2424 dataOut.EElecTempFinal[0,i]=missing
2430 dataOut.EElecTempFinal[0,i]=missing
2425 if numpy.isnan(dataOut.IonTempFinal[0,i]):
2431 if numpy.isnan(dataOut.IonTempFinal[0,i]):
2426 dataOut.EIonTempFinal[0,i]=missing
2432 dataOut.EIonTempFinal[0,i]=missing
2427 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2433 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2428 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2434 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2429
2435
2430 for i in range(12,dataOut.NSHTS-1):
2436 for i in range(12,dataOut.NSHTS-1):
2431
2437
2432 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2438 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2433 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2439 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2434
2440
2435 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2441 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2436 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2442 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2437
2443
2438 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2444 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2439
2445
2440 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+3]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2446 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+2]) and numpy.isnan(dataOut.ElecTempFinal[0,i+3]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2441
2447
2442 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2448 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2443 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i+2]) and numpy.isnan(dataOut.IonTempFinal[0,i+3]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2449 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i+2]) and numpy.isnan(dataOut.IonTempFinal[0,i+3]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2444
2450
2445 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2451 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2446
2452
2447
2453
2448
2454
2449 if i>25:
2455 if i>25:
2450 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i-3]) and numpy.isnan(dataOut.ElecTempFinal[0,i-4]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2456 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i-2]) and numpy.isnan(dataOut.ElecTempFinal[0,i-3]) and numpy.isnan(dataOut.ElecTempFinal[0,i-4]): #and numpy.isnan(dataOut.ElecTempFinal[0,i-5]):
2451 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2457 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2452 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i-3]) and numpy.isnan(dataOut.IonTempFinal[0,i-4]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2458 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i-2]) and numpy.isnan(dataOut.IonTempFinal[0,i-3]) and numpy.isnan(dataOut.IonTempFinal[0,i-4]): #and numpy.isnan(dataOut.IonTempFinal[0,i-5]):
2453
2459
2454 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2460 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2455
2461
2456 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2462 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2457
2463
2458 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2464 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2459
2465
2460 for i in range(12,dataOut.NSHTS-1):
2466 for i in range(12,dataOut.NSHTS-1):
2461
2467
2462 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2468 if numpy.isnan(dataOut.ElecTempFinal[0,i-1]) and numpy.isnan(dataOut.ElecTempFinal[0,i+1]):
2463 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2469 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=missing
2464
2470
2465 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2471 if numpy.isnan(dataOut.IonTempFinal[0,i-1]) and numpy.isnan(dataOut.IonTempFinal[0,i+1]):
2466 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2472 dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2467
2473
2468
2474
2469 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2475 if numpy.isnan(dataOut.ElecTempFinal[0,i]) or numpy.isnan(dataOut.EElecTempFinal[0,i]):
2470
2476
2471 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2477 dataOut.ElecTempFinal[0,i]=dataOut.EElecTempFinal[0,i]=dataOut.IonTempFinal[0,i]=dataOut.EIonTempFinal[0,i]=missing
2472
2478
2473 if numpy.count_nonzero(~numpy.isnan(dataOut.ElecTempFinal[0,12:50]))<5:
2479 if numpy.count_nonzero(~numpy.isnan(dataOut.ElecTempFinal[0,12:50]))<5:
2474 dataOut.ElecTempFinal[0,:]=dataOut.EElecTempFinal[0,:]=missing
2480 dataOut.ElecTempFinal[0,:]=dataOut.EElecTempFinal[0,:]=missing
2475 if numpy.count_nonzero(~numpy.isnan(dataOut.IonTempFinal[0,12:50]))<5:
2481 if numpy.count_nonzero(~numpy.isnan(dataOut.IonTempFinal[0,12:50]))<5:
2476 dataOut.IonTempFinal[0,:]=dataOut.EIonTempFinal[0,:]=missing
2482 dataOut.IonTempFinal[0,:]=dataOut.EIonTempFinal[0,:]=missing
2477
2483
2478 for i in range(dataOut.NSHTS,dataOut.NDP):
2484 for i in range(dataOut.NSHTS,dataOut.NDP):
2479
2485
2480 dataOut.ElecTempFinal[0,i]=missing
2486 dataOut.ElecTempFinal[0,i]=missing
2481 dataOut.EElecTempFinal[0,i]=missing
2487 dataOut.EElecTempFinal[0,i]=missing
2482 dataOut.IonTempFinal[0,i]=missing
2488 dataOut.IonTempFinal[0,i]=missing
2483 dataOut.EIonTempFinal[0,i]=missing
2489 dataOut.EIonTempFinal[0,i]=missing
2484 dataOut.PhyFinal[0,i]=missing
2490 dataOut.PhyFinal[0,i]=missing
2485 dataOut.EPhyFinal[0,i]=missing
2491 dataOut.EPhyFinal[0,i]=missing
2486
2492
2487 return dataOut
2493 return dataOut
2488
2494
2489
2495
2490 class DataSaveCleanerHP(Operation):
2496 class DataSaveCleanerHP(Operation):
2491 def __init__(self, **kwargs):
2497 def __init__(self, **kwargs):
2492
2498
2493 Operation.__init__(self, **kwargs)
2499 Operation.__init__(self, **kwargs)
2494
2500
2495 def run(self,dataOut):
2501 def run(self,dataOut):
2496
2502
2497 dataOut.Density_DP=numpy.zeros(dataOut.cut)
2503 dataOut.Density_DP=numpy.zeros(dataOut.cut)
2498 dataOut.EDensity_DP=numpy.zeros(dataOut.cut)
2504 dataOut.EDensity_DP=numpy.zeros(dataOut.cut)
2499 dataOut.ElecTemp_DP=numpy.zeros(dataOut.cut)
2505 dataOut.ElecTemp_DP=numpy.zeros(dataOut.cut)
2500 dataOut.EElecTemp_DP=numpy.zeros(dataOut.cut)
2506 dataOut.EElecTemp_DP=numpy.zeros(dataOut.cut)
2501 dataOut.IonTemp_DP=numpy.zeros(dataOut.cut)
2507 dataOut.IonTemp_DP=numpy.zeros(dataOut.cut)
2502 dataOut.EIonTemp_DP=numpy.zeros(dataOut.cut)
2508 dataOut.EIonTemp_DP=numpy.zeros(dataOut.cut)
2503 dataOut.Phy_DP=numpy.zeros(dataOut.cut)
2509 dataOut.Phy_DP=numpy.zeros(dataOut.cut)
2504 dataOut.EPhy_DP=numpy.zeros(dataOut.cut)
2510 dataOut.EPhy_DP=numpy.zeros(dataOut.cut)
2505 dataOut.Phe_DP=numpy.empty(dataOut.cut)
2511 dataOut.Phe_DP=numpy.empty(dataOut.cut)
2506 dataOut.EPhe_DP=numpy.empty(dataOut.cut)
2512 dataOut.EPhe_DP=numpy.empty(dataOut.cut)
2507
2513
2508 dataOut.Density_DP[:]=numpy.copy(dataOut.ph2[:dataOut.cut])
2514 dataOut.Density_DP[:]=numpy.copy(dataOut.ph2[:dataOut.cut])
2509 dataOut.EDensity_DP[:]=numpy.copy(dataOut.sdp2[:dataOut.cut])
2515 dataOut.EDensity_DP[:]=numpy.copy(dataOut.sdp2[:dataOut.cut])
2510 dataOut.ElecTemp_DP[:]=numpy.copy(dataOut.te2[:dataOut.cut])
2516 dataOut.ElecTemp_DP[:]=numpy.copy(dataOut.te2[:dataOut.cut])
2511 dataOut.EElecTemp_DP[:]=numpy.copy(dataOut.ete2[:dataOut.cut])
2517 dataOut.EElecTemp_DP[:]=numpy.copy(dataOut.ete2[:dataOut.cut])
2512 dataOut.IonTemp_DP[:]=numpy.copy(dataOut.ti2[:dataOut.cut])
2518 dataOut.IonTemp_DP[:]=numpy.copy(dataOut.ti2[:dataOut.cut])
2513 dataOut.EIonTemp_DP[:]=numpy.copy(dataOut.eti2[:dataOut.cut])
2519 dataOut.EIonTemp_DP[:]=numpy.copy(dataOut.eti2[:dataOut.cut])
2514 dataOut.Phy_DP[:]=numpy.copy(dataOut.phy2[:dataOut.cut])
2520 dataOut.Phy_DP[:]=numpy.copy(dataOut.phy2[:dataOut.cut])
2515 dataOut.EPhy_DP[:]=numpy.copy(dataOut.ephy2[:dataOut.cut])
2521 dataOut.EPhy_DP[:]=numpy.copy(dataOut.ephy2[:dataOut.cut])
2516 dataOut.Phe_DP[:]=numpy.nan
2522 dataOut.Phe_DP[:]=numpy.nan
2517 dataOut.EPhe_DP[:]=numpy.nan
2523 dataOut.EPhe_DP[:]=numpy.nan
2518
2524
2519 missing=numpy.nan
2525 missing=numpy.nan
2520 temp_min=100.0
2526 temp_min=100.0
2521 temp_max_dp=3000.0
2527 temp_max_dp=3000.0
2522
2528
2523 for i in range(dataOut.cut):
2529 for i in range(dataOut.cut):
2524 if dataOut.info2[i]!=1:
2530 if dataOut.info2[i]!=1:
2525 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2531 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2526
2532
2527 if dataOut.ElecTemp_DP[i]<=temp_min or dataOut.ElecTemp_DP[i]>temp_max_dp or dataOut.EElecTemp_DP[i]>temp_max_dp:
2533 if dataOut.ElecTemp_DP[i]<=temp_min or dataOut.ElecTemp_DP[i]>temp_max_dp or dataOut.EElecTemp_DP[i]>temp_max_dp:
2528
2534
2529 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=missing
2535 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=missing
2530
2536
2531 if dataOut.IonTemp_DP[i]<=temp_min or dataOut.IonTemp_DP[i]>temp_max_dp or dataOut.EIonTemp_DP[i]>temp_max_dp:
2537 if dataOut.IonTemp_DP[i]<=temp_min or dataOut.IonTemp_DP[i]>temp_max_dp or dataOut.EIonTemp_DP[i]>temp_max_dp:
2532 dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2538 dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2533
2539
2534 ####################################################################################### CHECK THIS
2540 ####################################################################################### CHECK THIS
2535 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2541 if dataOut.lags_to_plot[i,:][~numpy.isnan(dataOut.lags_to_plot[i,:])].shape[0]<6:
2536 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2542 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2537
2543
2538 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2544 if dataOut.ut_Faraday>4 and dataOut.ut_Faraday<11:
2539 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2545 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10:
2540 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2546 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2541 #######################################################################################
2547 #######################################################################################
2542
2548
2543 if dataOut.EPhy_DP[i]<0.0 or dataOut.EPhy_DP[i]>1.0:
2549 if dataOut.EPhy_DP[i]<0.0 or dataOut.EPhy_DP[i]>1.0:
2544 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2550 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2545 if dataOut.EDensity_DP[i]>0.0 and dataOut.Density_DP[i]>0.0 and dataOut.Density_DP[i]<9.9e6:
2551 if dataOut.EDensity_DP[i]>0.0 and dataOut.Density_DP[i]>0.0 and dataOut.Density_DP[i]<9.9e6:
2546 dataOut.EDensity_DP[i]=max(dataOut.EDensity_DP[i],1000.0)
2552 dataOut.EDensity_DP[i]=max(dataOut.EDensity_DP[i],1000.0)
2547 else:
2553 else:
2548 dataOut.Density_DP[i]=dataOut.EDensity_DP[i]=missing
2554 dataOut.Density_DP[i]=dataOut.EDensity_DP[i]=missing
2549 if dataOut.Phy_DP[i]==0 or dataOut.Phy_DP[i]>0.4:
2555 if dataOut.Phy_DP[i]==0 or dataOut.Phy_DP[i]>0.4:
2550 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2556 dataOut.Phy_DP[i]=dataOut.EPhy_DP[i]=missing
2551 if dataOut.ElecTemp_DP[i]==dataOut.IonTemp_DP[i]:
2557 if dataOut.ElecTemp_DP[i]==dataOut.IonTemp_DP[i]:
2552 dataOut.EElecTemp_DP[i]=dataOut.EIonTemp_DP[i]
2558 dataOut.EElecTemp_DP[i]=dataOut.EIonTemp_DP[i]
2553 if numpy.isnan(dataOut.ElecTemp_DP[i]):
2559 if numpy.isnan(dataOut.ElecTemp_DP[i]):
2554 dataOut.EElecTemp_DP[i]=missing
2560 dataOut.EElecTemp_DP[i]=missing
2555 if numpy.isnan(dataOut.IonTemp_DP[i]):
2561 if numpy.isnan(dataOut.IonTemp_DP[i]):
2556 dataOut.EIonTemp_DP[i]=missing
2562 dataOut.EIonTemp_DP[i]=missing
2557 if numpy.isnan(dataOut.ElecTemp_DP[i]) or numpy.isnan(dataOut.EElecTemp_DP[i]):
2563 if numpy.isnan(dataOut.ElecTemp_DP[i]) or numpy.isnan(dataOut.EElecTemp_DP[i]):
2558 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2564 dataOut.ElecTemp_DP[i]=dataOut.EElecTemp_DP[i]=dataOut.IonTemp_DP[i]=dataOut.EIonTemp_DP[i]=missing
2559
2565
2560
2566
2561
2567
2562 dataOut.Density_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2568 dataOut.Density_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2563 dataOut.EDensity_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2569 dataOut.EDensity_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2564 dataOut.ElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2570 dataOut.ElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2565 dataOut.EElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2571 dataOut.EElecTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2566 dataOut.IonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2572 dataOut.IonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2567 dataOut.EIonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2573 dataOut.EIonTemp_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2568 dataOut.Phy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2574 dataOut.Phy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2569 dataOut.EPhy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2575 dataOut.EPhy_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2570 dataOut.Phe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2576 dataOut.Phe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2571 dataOut.EPhe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2577 dataOut.EPhe_LP=numpy.zeros(dataOut.NACF-dataOut.cut)
2572
2578
2573 dataOut.Density_LP[:]=numpy.copy(dataOut.ne[dataOut.cut:dataOut.NACF])
2579 dataOut.Density_LP[:]=numpy.copy(dataOut.ne[dataOut.cut:dataOut.NACF])
2574 dataOut.EDensity_LP[:]=numpy.copy(dataOut.ene[dataOut.cut:dataOut.NACF])
2580 dataOut.EDensity_LP[:]=numpy.copy(dataOut.ene[dataOut.cut:dataOut.NACF])
2575 dataOut.ElecTemp_LP[:]=numpy.copy(dataOut.te[dataOut.cut:dataOut.NACF])
2581 dataOut.ElecTemp_LP[:]=numpy.copy(dataOut.te[dataOut.cut:dataOut.NACF])
2576 dataOut.EElecTemp_LP[:]=numpy.copy(dataOut.ete[dataOut.cut:dataOut.NACF])
2582 dataOut.EElecTemp_LP[:]=numpy.copy(dataOut.ete[dataOut.cut:dataOut.NACF])
2577 dataOut.IonTemp_LP[:]=numpy.copy(dataOut.ti[dataOut.cut:dataOut.NACF])
2583 dataOut.IonTemp_LP[:]=numpy.copy(dataOut.ti[dataOut.cut:dataOut.NACF])
2578 dataOut.EIonTemp_LP[:]=numpy.copy(dataOut.eti[dataOut.cut:dataOut.NACF])
2584 dataOut.EIonTemp_LP[:]=numpy.copy(dataOut.eti[dataOut.cut:dataOut.NACF])
2579 dataOut.Phy_LP[:]=numpy.copy(dataOut.ph[dataOut.cut:dataOut.NACF])
2585 dataOut.Phy_LP[:]=numpy.copy(dataOut.ph[dataOut.cut:dataOut.NACF])
2580 dataOut.EPhy_LP[:]=numpy.copy(dataOut.eph[dataOut.cut:dataOut.NACF])
2586 dataOut.EPhy_LP[:]=numpy.copy(dataOut.eph[dataOut.cut:dataOut.NACF])
2581 dataOut.Phe_LP[:]=numpy.copy(dataOut.phe[dataOut.cut:dataOut.NACF])
2587 dataOut.Phe_LP[:]=numpy.copy(dataOut.phe[dataOut.cut:dataOut.NACF])
2582 dataOut.EPhe_LP[:]=numpy.copy(dataOut.ephe[dataOut.cut:dataOut.NACF])
2588 dataOut.EPhe_LP[:]=numpy.copy(dataOut.ephe[dataOut.cut:dataOut.NACF])
2583
2589
2584 temp_max_lp=6000.0
2590 temp_max_lp=6000.0
2585
2591
2586 for i in range(dataOut.NACF-dataOut.cut):
2592 for i in range(dataOut.NACF-dataOut.cut):
2587
2593
2588 if dataOut.ElecTemp_LP[i]<=temp_min or dataOut.ElecTemp_LP[i]>temp_max_lp or dataOut.EElecTemp_LP[i]>temp_max_lp:
2594 if dataOut.ElecTemp_LP[i]<=temp_min or dataOut.ElecTemp_LP[i]>temp_max_lp or dataOut.EElecTemp_LP[i]>temp_max_lp:
2589
2595
2590 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=missing
2596 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=missing
2591
2597
2592 if dataOut.IonTemp_LP[i]<=temp_min or dataOut.IonTemp_LP[i]>temp_max_lp or dataOut.EIonTemp_LP[i]>temp_max_lp:
2598 if dataOut.IonTemp_LP[i]<=temp_min or dataOut.IonTemp_LP[i]>temp_max_lp or dataOut.EIonTemp_LP[i]>temp_max_lp:
2593 dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2599 dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2594 if dataOut.EPhy_LP[i]<0.0 or dataOut.EPhy_LP[i]>1.0:
2600 if dataOut.EPhy_LP[i]<0.0 or dataOut.EPhy_LP[i]>1.0:
2595 dataOut.Phy_LP[i]=dataOut.EPhy_LP[i]=missing
2601 dataOut.Phy_LP[i]=dataOut.EPhy_LP[i]=missing
2596
2602
2597 if dataOut.EPhe_LP[i]<0.0 or dataOut.EPhe_LP[i]>1.0:
2603 if dataOut.EPhe_LP[i]<0.0 or dataOut.EPhe_LP[i]>1.0:
2598 dataOut.Phe_LP[i]=dataOut.EPhe_LP[i]=missing
2604 dataOut.Phe_LP[i]=dataOut.EPhe_LP[i]=missing
2599 if dataOut.EDensity_LP[i]>0.0 and dataOut.Density_LP[i]>0.0 and dataOut.Density_LP[i]<9.9e6 and dataOut.EDensity_LP[i]*dataOut.Density_LP[i]<9.9e6:
2605 if dataOut.EDensity_LP[i]>0.0 and dataOut.Density_LP[i]>0.0 and dataOut.Density_LP[i]<9.9e6 and dataOut.EDensity_LP[i]*dataOut.Density_LP[i]<9.9e6:
2600 dataOut.EDensity_LP[i]=max(dataOut.EDensity_LP[i],1000.0/dataOut.Density_LP[i])
2606 dataOut.EDensity_LP[i]=max(dataOut.EDensity_LP[i],1000.0/dataOut.Density_LP[i])
2601 else:
2607 else:
2602 dataOut.Density_LP[i]=missing
2608 dataOut.Density_LP[i]=missing
2603 dataOut.EDensity_LP[i]=1.0
2609 dataOut.EDensity_LP[i]=1.0
2604
2610
2605 if numpy.isnan(dataOut.Phy_LP[i]):
2611 if numpy.isnan(dataOut.Phy_LP[i]):
2606 dataOut.EPhy_LP[i]=missing
2612 dataOut.EPhy_LP[i]=missing
2607
2613
2608 if numpy.isnan(dataOut.Phe_LP[i]):
2614 if numpy.isnan(dataOut.Phe_LP[i]):
2609 dataOut.EPhe_LP[i]=missing
2615 dataOut.EPhe_LP[i]=missing
2610
2616
2611
2617
2612 if dataOut.ElecTemp_LP[i]==dataOut.IonTemp_LP[i]:
2618 if dataOut.ElecTemp_LP[i]==dataOut.IonTemp_LP[i]:
2613 dataOut.EElecTemp_LP[i]=dataOut.EIonTemp_LP[i]
2619 dataOut.EElecTemp_LP[i]=dataOut.EIonTemp_LP[i]
2614 if numpy.isnan(dataOut.ElecTemp_LP[i]):
2620 if numpy.isnan(dataOut.ElecTemp_LP[i]):
2615 dataOut.EElecTemp_LP[i]=missing
2621 dataOut.EElecTemp_LP[i]=missing
2616 if numpy.isnan(dataOut.IonTemp_LP[i]):
2622 if numpy.isnan(dataOut.IonTemp_LP[i]):
2617 dataOut.EIonTemp_LP[i]=missing
2623 dataOut.EIonTemp_LP[i]=missing
2618 if numpy.isnan(dataOut.ElecTemp_LP[i]) or numpy.isnan(dataOut.EElecTemp_LP[i]):
2624 if numpy.isnan(dataOut.ElecTemp_LP[i]) or numpy.isnan(dataOut.EElecTemp_LP[i]):
2619 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2625 dataOut.ElecTemp_LP[i]=dataOut.EElecTemp_LP[i]=dataOut.IonTemp_LP[i]=dataOut.EIonTemp_LP[i]=missing
2620
2626
2621
2627
2622 dataOut.DensityFinal=numpy.reshape(numpy.concatenate((dataOut.Density_DP,dataOut.Density_LP)),(1,-1))
2628 dataOut.DensityFinal=numpy.reshape(numpy.concatenate((dataOut.Density_DP,dataOut.Density_LP)),(1,-1))
2623 dataOut.EDensityFinal=numpy.reshape(numpy.concatenate((dataOut.EDensity_DP,dataOut.EDensity_LP)),(1,-1))
2629 dataOut.EDensityFinal=numpy.reshape(numpy.concatenate((dataOut.EDensity_DP,dataOut.EDensity_LP)),(1,-1))
2624 dataOut.ElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.ElecTemp_DP,dataOut.ElecTemp_LP)),(1,-1))
2630 dataOut.ElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.ElecTemp_DP,dataOut.ElecTemp_LP)),(1,-1))
2625 dataOut.EElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.EElecTemp_DP,dataOut.EElecTemp_LP)),(1,-1))
2631 dataOut.EElecTempFinal=numpy.reshape(numpy.concatenate((dataOut.EElecTemp_DP,dataOut.EElecTemp_LP)),(1,-1))
2626 dataOut.IonTempFinal=numpy.reshape(numpy.concatenate((dataOut.IonTemp_DP,dataOut.IonTemp_LP)),(1,-1))
2632 dataOut.IonTempFinal=numpy.reshape(numpy.concatenate((dataOut.IonTemp_DP,dataOut.IonTemp_LP)),(1,-1))
2627 dataOut.EIonTempFinal=numpy.reshape(numpy.concatenate((dataOut.EIonTemp_DP,dataOut.EIonTemp_LP)),(1,-1))
2633 dataOut.EIonTempFinal=numpy.reshape(numpy.concatenate((dataOut.EIonTemp_DP,dataOut.EIonTemp_LP)),(1,-1))
2628 dataOut.PhyFinal=numpy.reshape(numpy.concatenate((dataOut.Phy_DP,dataOut.Phy_LP)),(1,-1))
2634 dataOut.PhyFinal=numpy.reshape(numpy.concatenate((dataOut.Phy_DP,dataOut.Phy_LP)),(1,-1))
2629 dataOut.EPhyFinal=numpy.reshape(numpy.concatenate((dataOut.EPhy_DP,dataOut.EPhy_LP)),(1,-1))
2635 dataOut.EPhyFinal=numpy.reshape(numpy.concatenate((dataOut.EPhy_DP,dataOut.EPhy_LP)),(1,-1))
2630 dataOut.PheFinal=numpy.reshape(numpy.concatenate((dataOut.Phe_DP,dataOut.Phe_LP)),(1,-1))
2636 dataOut.PheFinal=numpy.reshape(numpy.concatenate((dataOut.Phe_DP,dataOut.Phe_LP)),(1,-1))
2631 dataOut.EPheFinal=numpy.reshape(numpy.concatenate((dataOut.EPhe_DP,dataOut.EPhe_LP)),(1,-1))
2637 dataOut.EPheFinal=numpy.reshape(numpy.concatenate((dataOut.EPhe_DP,dataOut.EPhe_LP)),(1,-1))
2632
2638
2633 nan_array_2=numpy.empty(dataOut.NACF-dataOut.NDP)
2639 nan_array_2=numpy.empty(dataOut.NACF-dataOut.NDP)
2634 nan_array_2[:]=numpy.nan
2640 nan_array_2[:]=numpy.nan
2635
2641
2636 dataOut.acfs_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2642 dataOut.acfs_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2637 dataOut.acfs_error_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2643 dataOut.acfs_error_DP=numpy.zeros((dataOut.NACF,dataOut.DPL),'float32')
2638 acfs_dp_aux=dataOut.acfs_to_save.transpose()
2644 acfs_dp_aux=dataOut.acfs_to_save.transpose()
2639 acfs_error_dp_aux=dataOut.acfs_error_to_save.transpose()
2645 acfs_error_dp_aux=dataOut.acfs_error_to_save.transpose()
2640 for i in range(dataOut.DPL):
2646 for i in range(dataOut.DPL):
2641 dataOut.acfs_DP[:,i]=numpy.concatenate((acfs_dp_aux[:,i],nan_array_2))
2647 dataOut.acfs_DP[:,i]=numpy.concatenate((acfs_dp_aux[:,i],nan_array_2))
2642 dataOut.acfs_error_DP[:,i]=numpy.concatenate((acfs_error_dp_aux[:,i],nan_array_2))
2648 dataOut.acfs_error_DP[:,i]=numpy.concatenate((acfs_error_dp_aux[:,i],nan_array_2))
2643 dataOut.acfs_DP=dataOut.acfs_DP.transpose()
2649 dataOut.acfs_DP=dataOut.acfs_DP.transpose()
2644 dataOut.acfs_error_DP=dataOut.acfs_error_DP.transpose()
2650 dataOut.acfs_error_DP=dataOut.acfs_error_DP.transpose()
2645
2651
2646 dataOut.acfs_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2652 dataOut.acfs_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2647 dataOut.acfs_error_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2653 dataOut.acfs_error_LP=numpy.zeros((dataOut.NACF,dataOut.IBITS),'float32')
2648
2654
2649 for i in range(dataOut.NACF):
2655 for i in range(dataOut.NACF):
2650 for j in range(dataOut.IBITS):
2656 for j in range(dataOut.IBITS):
2651 if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0:
2657 if numpy.abs(dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0])<1.0:
2652 dataOut.acfs_LP[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0]
2658 dataOut.acfs_LP[i,j]=dataOut.output_LP_integrated.real[j,i,0]/dataOut.output_LP_integrated.real[0,i,0]
2653 dataOut.acfs_LP[i,j]=max(min(dataOut.acfs_LP[i,j],1.0),-1.0)
2659 dataOut.acfs_LP[i,j]=max(min(dataOut.acfs_LP[i,j],1.0),-1.0)
2654
2660
2655 dataOut.acfs_error_LP[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0]
2661 dataOut.acfs_error_LP[i,j]=dataOut.errors[j,i]/dataOut.output_LP_integrated.real[0,i,0]
2656 else:
2662 else:
2657 dataOut.acfs_LP[i,j]=numpy.nan
2663 dataOut.acfs_LP[i,j]=numpy.nan
2658
2664
2659 dataOut.acfs_error_LP[i,j]=numpy.nan
2665 dataOut.acfs_error_LP[i,j]=numpy.nan
2660
2666
2661 dataOut.acfs_LP=dataOut.acfs_LP.transpose()
2667 dataOut.acfs_LP=dataOut.acfs_LP.transpose()
2662 dataOut.acfs_error_LP=dataOut.acfs_error_LP.transpose()
2668 dataOut.acfs_error_LP=dataOut.acfs_error_LP.transpose()
2663
2669
2664 return dataOut
2670 return dataOut
2665
2671
2666
2672
2667 class ACFs(Operation):
2673 class ACFs(Operation):
2668 def __init__(self, **kwargs):
2674 def __init__(self, **kwargs):
2669
2675
2670 Operation.__init__(self, **kwargs)
2676 Operation.__init__(self, **kwargs)
2671
2677
2672 self.aux=1
2678 self.aux=1
2673
2679
2674 def run(self,dataOut):
2680 def run(self,dataOut):
2675
2681
2676 if self.aux:
2682 if self.aux:
2677 self.taup=numpy.zeros(dataOut.DPL,'float32')
2683 self.taup=numpy.zeros(dataOut.DPL,'float32')
2678 self.pacf=numpy.zeros(dataOut.DPL,'float32')
2684 self.pacf=numpy.zeros(dataOut.DPL,'float32')
2679 self.sacf=numpy.zeros(dataOut.DPL,'float32')
2685 self.sacf=numpy.zeros(dataOut.DPL,'float32')
2680
2686
2681 self.taup_full=numpy.zeros(dataOut.DPL,'float32')
2687 self.taup_full=numpy.zeros(dataOut.DPL,'float32')
2682 self.pacf_full=numpy.zeros(dataOut.DPL,'float32')
2688 self.pacf_full=numpy.zeros(dataOut.DPL,'float32')
2683 self.sacf_full=numpy.zeros(dataOut.DPL,'float32')
2689 self.sacf_full=numpy.zeros(dataOut.DPL,'float32')
2684 self.x_igcej=numpy.zeros(dataOut.DPL,'float32')
2690 self.x_igcej=numpy.zeros(dataOut.DPL,'float32')
2685 self.y_igcej=numpy.zeros(dataOut.DPL,'float32')
2691 self.y_igcej=numpy.zeros(dataOut.DPL,'float32')
2686 self.x_ibad=numpy.zeros(dataOut.DPL,'float32')
2692 self.x_ibad=numpy.zeros(dataOut.DPL,'float32')
2687 self.y_ibad=numpy.zeros(dataOut.DPL,'float32')
2693 self.y_ibad=numpy.zeros(dataOut.DPL,'float32')
2688 self.aux=0
2694 self.aux=0
2689
2695
2690 dataOut.acfs_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2696 dataOut.acfs_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2691 dataOut.acfs_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2697 dataOut.acfs_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2692 dataOut.acfs_error_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2698 dataOut.acfs_error_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2693 dataOut.acfs_error_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2699 dataOut.acfs_error_to_save=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2694 dataOut.lags_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2700 dataOut.lags_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2695 dataOut.x_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2701 dataOut.x_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2696 dataOut.x_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2702 dataOut.x_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2697 dataOut.y_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2703 dataOut.y_igcej_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2698 dataOut.y_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2704 dataOut.y_ibad_to_plot=numpy.zeros((dataOut.NDP,dataOut.DPL),'float32')
2699
2705
2700 for i in range(dataOut.NSHTS):
2706 for i in range(dataOut.NSHTS):
2701
2707
2702 acfm=dataOut.rhor[i][0]**2+dataOut.rhoi[i][0]**2
2708 acfm=dataOut.rhor[i][0]**2+dataOut.rhoi[i][0]**2
2703
2709
2704 if acfm>0:
2710 if acfm>0:
2705 cc=dataOut.rhor[i][0]/acfm
2711 cc=dataOut.rhor[i][0]/acfm
2706 ss=dataOut.rhoi[i][0]/acfm
2712 ss=dataOut.rhoi[i][0]/acfm
2707 else:
2713 else:
2708 cc=1.
2714 cc=1.
2709 ss=0.
2715 ss=0.
2710
2716
2711 # keep only uncontaminated data
2717 # keep only uncontaminated data
2712 for l in range(dataOut.DPL):
2718 for l in range(dataOut.DPL):
2713 fact=dataOut.DH
2719 fact=dataOut.DH
2714 if (dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0):
2720 if (dataOut.igcej[i][l]==0 and dataOut.ibad[i][l]==0):
2715
2721
2716 self.pacf_full[l]=min(1.0,max(-1.0,(dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss)))*fact+dataOut.range1[i]
2722 self.pacf_full[l]=min(1.0,max(-1.0,(dataOut.rhor[i][l]*cc + dataOut.rhoi[i][l]*ss)))*fact+dataOut.range1[i]
2717 self.sacf_full[l]=min(1.0,numpy.sqrt(dataOut.sd[i][l]))*fact
2723 self.sacf_full[l]=min(1.0,numpy.sqrt(dataOut.sd[i][l]))*fact
2718 self.taup_full[l]=dataOut.alag[l]
2724 self.taup_full[l]=dataOut.alag[l]
2719 self.x_igcej[l]=numpy.nan
2725 self.x_igcej[l]=numpy.nan
2720 self.y_igcej[l]=numpy.nan
2726 self.y_igcej[l]=numpy.nan
2721 self.x_ibad[l]=numpy.nan
2727 self.x_ibad[l]=numpy.nan
2722 self.y_ibad[l]=numpy.nan
2728 self.y_ibad[l]=numpy.nan
2723
2729
2724 else:
2730 else:
2725 self.pacf_full[l]=numpy.nan
2731 self.pacf_full[l]=numpy.nan
2726 self.sacf_full[l]=numpy.nan
2732 self.sacf_full[l]=numpy.nan
2727 self.taup_full[l]=numpy.nan
2733 self.taup_full[l]=numpy.nan
2728
2734
2729 if dataOut.igcej[i][l]:
2735 if dataOut.igcej[i][l]:
2730 self.x_igcej[l]=dataOut.alag[l]
2736 self.x_igcej[l]=dataOut.alag[l]
2731 self.y_igcej[l]=dataOut.range1[i]
2737 self.y_igcej[l]=dataOut.range1[i]
2732 self.x_ibad[l]=numpy.nan
2738 self.x_ibad[l]=numpy.nan
2733 self.y_ibad[l]=numpy.nan
2739 self.y_ibad[l]=numpy.nan
2734
2740
2735 if dataOut.ibad[i][l]:
2741 if dataOut.ibad[i][l]:
2736 self.x_igcej[l]=numpy.nan
2742 self.x_igcej[l]=numpy.nan
2737 self.y_igcej[l]=numpy.nan
2743 self.y_igcej[l]=numpy.nan
2738 self.x_ibad[l]=dataOut.alag[l]
2744 self.x_ibad[l]=dataOut.alag[l]
2739 self.y_ibad[l]=dataOut.range1[i]
2745 self.y_ibad[l]=dataOut.range1[i]
2740
2746
2741 pacf_new=numpy.copy((self.pacf_full-dataOut.range1[i])/dataOut.DH)
2747 pacf_new=numpy.copy((self.pacf_full-dataOut.range1[i])/dataOut.DH)
2742 sacf_new=numpy.copy(self.sacf_full/dataOut.DH)
2748 sacf_new=numpy.copy(self.sacf_full/dataOut.DH)
2743 dataOut.acfs_to_save[i,:]=numpy.copy(pacf_new)
2749 dataOut.acfs_to_save[i,:]=numpy.copy(pacf_new)
2744 dataOut.acfs_error_to_save[i,:]=numpy.copy(sacf_new)
2750 dataOut.acfs_error_to_save[i,:]=numpy.copy(sacf_new)
2745 dataOut.acfs_to_plot[i,:]=numpy.copy(self.pacf_full)
2751 dataOut.acfs_to_plot[i,:]=numpy.copy(self.pacf_full)
2746 dataOut.acfs_error_to_plot[i,:]=numpy.copy(self.sacf_full)
2752 dataOut.acfs_error_to_plot[i,:]=numpy.copy(self.sacf_full)
2747 dataOut.lags_to_plot[i,:]=numpy.copy(self.taup_full)
2753 dataOut.lags_to_plot[i,:]=numpy.copy(self.taup_full)
2748 dataOut.x_igcej_to_plot[i,:]=numpy.copy(self.x_igcej)
2754 dataOut.x_igcej_to_plot[i,:]=numpy.copy(self.x_igcej)
2749 dataOut.x_ibad_to_plot[i,:]=numpy.copy(self.x_ibad)
2755 dataOut.x_ibad_to_plot[i,:]=numpy.copy(self.x_ibad)
2750 dataOut.y_igcej_to_plot[i,:]=numpy.copy(self.y_igcej)
2756 dataOut.y_igcej_to_plot[i,:]=numpy.copy(self.y_igcej)
2751 dataOut.y_ibad_to_plot[i,:]=numpy.copy(self.y_ibad)
2757 dataOut.y_ibad_to_plot[i,:]=numpy.copy(self.y_ibad)
2752
2758
2753 missing=numpy.nan#-32767
2759 missing=numpy.nan#-32767
2754
2760
2755 for i in range(dataOut.NSHTS,dataOut.NDP):
2761 for i in range(dataOut.NSHTS,dataOut.NDP):
2756 for j in range(dataOut.DPL):
2762 for j in range(dataOut.DPL):
2757 dataOut.acfs_to_save[i,j]=missing
2763 dataOut.acfs_to_save[i,j]=missing
2758 dataOut.acfs_error_to_save[i,j]=missing
2764 dataOut.acfs_error_to_save[i,j]=missing
2759 dataOut.acfs_to_plot[i,j]=missing
2765 dataOut.acfs_to_plot[i,j]=missing
2760 dataOut.acfs_error_to_plot[i,j]=missing
2766 dataOut.acfs_error_to_plot[i,j]=missing
2761 dataOut.lags_to_plot[i,j]=missing
2767 dataOut.lags_to_plot[i,j]=missing
2762 dataOut.x_igcej_to_plot[i,j]=missing
2768 dataOut.x_igcej_to_plot[i,j]=missing
2763 dataOut.x_ibad_to_plot[i,j]=missing
2769 dataOut.x_ibad_to_plot[i,j]=missing
2764 dataOut.y_igcej_to_plot[i,j]=missing
2770 dataOut.y_igcej_to_plot[i,j]=missing
2765 dataOut.y_ibad_to_plot[i,j]=missing
2771 dataOut.y_ibad_to_plot[i,j]=missing
2766
2772
2767 dataOut.acfs_to_save=dataOut.acfs_to_save.transpose()
2773 dataOut.acfs_to_save=dataOut.acfs_to_save.transpose()
2768 dataOut.acfs_error_to_save=dataOut.acfs_error_to_save.transpose()
2774 dataOut.acfs_error_to_save=dataOut.acfs_error_to_save.transpose()
2769
2775
2770 return dataOut
2776 return dataOut
2771
2777
2772
2778
2773 class CohInt(Operation):
2779 class CohInt(Operation):
2774
2780
2775 isConfig = False
2781 isConfig = False
2776 __profIndex = 0
2782 __profIndex = 0
2777 __byTime = False
2783 __byTime = False
2778 __initime = None
2784 __initime = None
2779 __lastdatatime = None
2785 __lastdatatime = None
2780 __integrationtime = None
2786 __integrationtime = None
2781 __buffer = None
2787 __buffer = None
2782 __bufferStride = []
2788 __bufferStride = []
2783 __dataReady = False
2789 __dataReady = False
2784 __profIndexStride = 0
2790 __profIndexStride = 0
2785 __dataToPutStride = False
2791 __dataToPutStride = False
2786 n = None
2792 n = None
2787
2793
2788 def __init__(self, **kwargs):
2794 def __init__(self, **kwargs):
2789
2795
2790 Operation.__init__(self, **kwargs)
2796 Operation.__init__(self, **kwargs)
2791
2797
2792 # self.isConfig = False
2798 # self.isConfig = False
2793
2799
2794 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
2800 def setup(self, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False):
2795 """
2801 """
2796 Set the parameters of the integration class.
2802 Set the parameters of the integration class.
2797
2803
2798 Inputs:
2804 Inputs:
2799
2805
2800 n : Number of coherent integrations
2806 n : Number of coherent integrations
2801 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
2807 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
2802 overlapping :
2808 overlapping :
2803 """
2809 """
2804
2810
2805 self.__initime = None
2811 self.__initime = None
2806 self.__lastdatatime = 0
2812 self.__lastdatatime = 0
2807 self.__buffer = None
2813 self.__buffer = None
2808 self.__dataReady = False
2814 self.__dataReady = False
2809 self.byblock = byblock
2815 self.byblock = byblock
2810 self.stride = stride
2816 self.stride = stride
2811
2817
2812 if n == None and timeInterval == None:
2818 if n == None and timeInterval == None:
2813 raise ValueError("n or timeInterval should be specified ...")
2819 raise ValueError("n or timeInterval should be specified ...")
2814
2820
2815 if n != None:
2821 if n != None:
2816 self.n = n
2822 self.n = n
2817 self.__byTime = False
2823 self.__byTime = False
2818 else:
2824 else:
2819 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
2825 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
2820 self.n = 9999
2826 self.n = 9999
2821 self.__byTime = True
2827 self.__byTime = True
2822
2828
2823 if overlapping:
2829 if overlapping:
2824 self.__withOverlapping = True
2830 self.__withOverlapping = True
2825 self.__buffer = None
2831 self.__buffer = None
2826 else:
2832 else:
2827 self.__withOverlapping = False
2833 self.__withOverlapping = False
2828 self.__buffer = 0
2834 self.__buffer = 0
2829
2835
2830 self.__profIndex = 0
2836 self.__profIndex = 0
2831
2837
2832 def putData(self, data):
2838 def putData(self, data):
2833
2839
2834 """
2840 """
2835 Add a profile to the __buffer and increase in one the __profileIndex
2841 Add a profile to the __buffer and increase in one the __profileIndex
2836
2842
2837 """
2843 """
2838
2844
2839 if not self.__withOverlapping:
2845 if not self.__withOverlapping:
2840 self.__buffer += data.copy()
2846 self.__buffer += data.copy()
2841 self.__profIndex += 1
2847 self.__profIndex += 1
2842 return
2848 return
2843
2849
2844 #Overlapping data
2850 #Overlapping data
2845 nChannels, nHeis = data.shape
2851 nChannels, nHeis = data.shape
2846 data = numpy.reshape(data, (1, nChannels, nHeis))
2852 data = numpy.reshape(data, (1, nChannels, nHeis))
2847
2853
2848 #If the buffer is empty then it takes the data value
2854 #If the buffer is empty then it takes the data value
2849 if self.__buffer is None:
2855 if self.__buffer is None:
2850 self.__buffer = data
2856 self.__buffer = data
2851 self.__profIndex += 1
2857 self.__profIndex += 1
2852 return
2858 return
2853
2859
2854 #If the buffer length is lower than n then stakcing the data value
2860 #If the buffer length is lower than n then stakcing the data value
2855 if self.__profIndex < self.n:
2861 if self.__profIndex < self.n:
2856 self.__buffer = numpy.vstack((self.__buffer, data))
2862 self.__buffer = numpy.vstack((self.__buffer, data))
2857 self.__profIndex += 1
2863 self.__profIndex += 1
2858 return
2864 return
2859
2865
2860 #If the buffer length is equal to n then replacing the last buffer value with the data value
2866 #If the buffer length is equal to n then replacing the last buffer value with the data value
2861 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
2867 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
2862 self.__buffer[self.n-1] = data
2868 self.__buffer[self.n-1] = data
2863 self.__profIndex = self.n
2869 self.__profIndex = self.n
2864 return
2870 return
2865
2871
2866
2872
2867 def pushData(self):
2873 def pushData(self):
2868 """
2874 """
2869 Return the sum of the last profiles and the profiles used in the sum.
2875 Return the sum of the last profiles and the profiles used in the sum.
2870
2876
2871 Affected:
2877 Affected:
2872
2878
2873 self.__profileIndex
2879 self.__profileIndex
2874
2880
2875 """
2881 """
2876
2882
2877 if not self.__withOverlapping:
2883 if not self.__withOverlapping:
2878 data = self.__buffer
2884 data = self.__buffer
2879 n = self.__profIndex
2885 n = self.__profIndex
2880
2886
2881 self.__buffer = 0
2887 self.__buffer = 0
2882 self.__profIndex = 0
2888 self.__profIndex = 0
2883
2889
2884 return data, n
2890 return data, n
2885
2891
2886 #Integration with Overlapping
2892 #Integration with Overlapping
2887 data = numpy.sum(self.__buffer, axis=0)
2893 data = numpy.sum(self.__buffer, axis=0)
2888 # print data
2894 # print data
2889 # raise
2895 # raise
2890 n = self.__profIndex
2896 n = self.__profIndex
2891
2897
2892 return data, n
2898 return data, n
2893
2899
2894 def byProfiles(self, data):
2900 def byProfiles(self, data):
2895
2901
2896 self.__dataReady = False
2902 self.__dataReady = False
2897 avgdata = None
2903 avgdata = None
2898 # n = None
2904 # n = None
2899 # print data
2905 # print data
2900 # raise
2906 # raise
2901 self.putData(data)
2907 self.putData(data)
2902
2908
2903 if self.__profIndex == self.n:
2909 if self.__profIndex == self.n:
2904 avgdata, n = self.pushData()
2910 avgdata, n = self.pushData()
2905 self.__dataReady = True
2911 self.__dataReady = True
2906
2912
2907 return avgdata
2913 return avgdata
2908
2914
2909 def byTime(self, data, datatime):
2915 def byTime(self, data, datatime):
2910
2916
2911 self.__dataReady = False
2917 self.__dataReady = False
2912 avgdata = None
2918 avgdata = None
2913 n = None
2919 n = None
2914
2920
2915 self.putData(data)
2921 self.putData(data)
2916
2922
2917 if (datatime - self.__initime) >= self.__integrationtime:
2923 if (datatime - self.__initime) >= self.__integrationtime:
2918 avgdata, n = self.pushData()
2924 avgdata, n = self.pushData()
2919 self.n = n
2925 self.n = n
2920 self.__dataReady = True
2926 self.__dataReady = True
2921
2927
2922 return avgdata
2928 return avgdata
2923
2929
2924 def integrateByStride(self, data, datatime):
2930 def integrateByStride(self, data, datatime):
2925 # print data
2931 # print data
2926 if self.__profIndex == 0:
2932 if self.__profIndex == 0:
2927 self.__buffer = [[data.copy(), datatime]]
2933 self.__buffer = [[data.copy(), datatime]]
2928 else:
2934 else:
2929 self.__buffer.append([data.copy(),datatime])
2935 self.__buffer.append([data.copy(),datatime])
2930 self.__profIndex += 1
2936 self.__profIndex += 1
2931 self.__dataReady = False
2937 self.__dataReady = False
2932
2938
2933 if self.__profIndex == self.n * self.stride :
2939 if self.__profIndex == self.n * self.stride :
2934 self.__dataToPutStride = True
2940 self.__dataToPutStride = True
2935 self.__profIndexStride = 0
2941 self.__profIndexStride = 0
2936 self.__profIndex = 0
2942 self.__profIndex = 0
2937 self.__bufferStride = []
2943 self.__bufferStride = []
2938 for i in range(self.stride):
2944 for i in range(self.stride):
2939 current = self.__buffer[i::self.stride]
2945 current = self.__buffer[i::self.stride]
2940 data = numpy.sum([t[0] for t in current], axis=0)
2946 data = numpy.sum([t[0] for t in current], axis=0)
2941 avgdatatime = numpy.average([t[1] for t in current])
2947 avgdatatime = numpy.average([t[1] for t in current])
2942 # print data
2948 # print data
2943 self.__bufferStride.append((data, avgdatatime))
2949 self.__bufferStride.append((data, avgdatatime))
2944
2950
2945 if self.__dataToPutStride:
2951 if self.__dataToPutStride:
2946 self.__dataReady = True
2952 self.__dataReady = True
2947 self.__profIndexStride += 1
2953 self.__profIndexStride += 1
2948 if self.__profIndexStride == self.stride:
2954 if self.__profIndexStride == self.stride:
2949 self.__dataToPutStride = False
2955 self.__dataToPutStride = False
2950 # print self.__bufferStride[self.__profIndexStride - 1]
2956 # print self.__bufferStride[self.__profIndexStride - 1]
2951 # raise
2957 # raise
2952 return self.__bufferStride[self.__profIndexStride - 1]
2958 return self.__bufferStride[self.__profIndexStride - 1]
2953
2959
2954
2960
2955 return None, None
2961 return None, None
2956
2962
2957 def integrate(self, data, datatime=None):
2963 def integrate(self, data, datatime=None):
2958
2964
2959 if self.__initime == None:
2965 if self.__initime == None:
2960 self.__initime = datatime
2966 self.__initime = datatime
2961
2967
2962 if self.__byTime:
2968 if self.__byTime:
2963 avgdata = self.byTime(data, datatime)
2969 avgdata = self.byTime(data, datatime)
2964 else:
2970 else:
2965 avgdata = self.byProfiles(data)
2971 avgdata = self.byProfiles(data)
2966
2972
2967
2973
2968 self.__lastdatatime = datatime
2974 self.__lastdatatime = datatime
2969
2975
2970 if avgdata is None:
2976 if avgdata is None:
2971 return None, None
2977 return None, None
2972
2978
2973 avgdatatime = self.__initime
2979 avgdatatime = self.__initime
2974
2980
2975 deltatime = datatime - self.__lastdatatime
2981 deltatime = datatime - self.__lastdatatime
2976
2982
2977 if not self.__withOverlapping:
2983 if not self.__withOverlapping:
2978 self.__initime = datatime
2984 self.__initime = datatime
2979 else:
2985 else:
2980 self.__initime += deltatime
2986 self.__initime += deltatime
2981
2987
2982 return avgdata, avgdatatime
2988 return avgdata, avgdatatime
2983
2989
2984 def integrateByBlock(self, dataOut):
2990 def integrateByBlock(self, dataOut):
2985
2991
2986 times = int(dataOut.data.shape[1]/self.n)
2992 times = int(dataOut.data.shape[1]/self.n)
2987 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
2993 avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex)
2988
2994
2989 id_min = 0
2995 id_min = 0
2990 id_max = self.n
2996 id_max = self.n
2991
2997
2992 for i in range(times):
2998 for i in range(times):
2993 junk = dataOut.data[:,id_min:id_max,:]
2999 junk = dataOut.data[:,id_min:id_max,:]
2994 avgdata[:,i,:] = junk.sum(axis=1)
3000 avgdata[:,i,:] = junk.sum(axis=1)
2995 id_min += self.n
3001 id_min += self.n
2996 id_max += self.n
3002 id_max += self.n
2997
3003
2998 timeInterval = dataOut.ippSeconds*self.n
3004 timeInterval = dataOut.ippSeconds*self.n
2999 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
3005 avgdatatime = (times - 1) * timeInterval + dataOut.utctime
3000 self.__dataReady = True
3006 self.__dataReady = True
3001 return avgdata, avgdatatime
3007 return avgdata, avgdatatime
3002
3008
3003 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
3009 def run(self, dataOut, n=None, timeInterval=None, stride=None, overlapping=False, byblock=False, **kwargs):
3004
3010
3005 if not self.isConfig:
3011 if not self.isConfig:
3006 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
3012 self.setup(n=n, stride=stride, timeInterval=timeInterval, overlapping=overlapping, byblock=byblock, **kwargs)
3007 self.isConfig = True
3013 self.isConfig = True
3008 print("inside")
3014 print("inside")
3009 if dataOut.flagDataAsBlock:
3015 if dataOut.flagDataAsBlock:
3010 """
3016 """
3011 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
3017 Si la data es leida por bloques, dimension = [nChannels, nProfiles, nHeis]
3012 """
3018 """
3013
3019
3014 avgdata, avgdatatime = self.integrateByBlock(dataOut)
3020 avgdata, avgdatatime = self.integrateByBlock(dataOut)
3015 dataOut.nProfiles /= self.n
3021 dataOut.nProfiles /= self.n
3016 else:
3022 else:
3017 if stride is None:
3023 if stride is None:
3018 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
3024 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
3019 else:
3025 else:
3020 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
3026 avgdata, avgdatatime = self.integrateByStride(dataOut.data, dataOut.utctime)
3021
3027
3022
3028
3023 # dataOut.timeInterval *= n
3029 # dataOut.timeInterval *= n
3024 dataOut.flagNoData = True
3030 dataOut.flagNoData = True
3025
3031
3026 if self.__dataReady:
3032 if self.__dataReady:
3027 dataOut.data = avgdata
3033 dataOut.data = avgdata
3028 if not dataOut.flagCohInt:
3034 if not dataOut.flagCohInt:
3029 dataOut.nCohInt *= self.n
3035 dataOut.nCohInt *= self.n
3030 dataOut.flagCohInt = True
3036 dataOut.flagCohInt = True
3031 dataOut.utctime = avgdatatime
3037 dataOut.utctime = avgdatatime
3032 # print avgdata, avgdatatime
3038 # print avgdata, avgdatatime
3033 # raise
3039 # raise
3034 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
3040 # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
3035 dataOut.flagNoData = False
3041 dataOut.flagNoData = False
3036 return dataOut
3042 return dataOut
3037
3043
3038 class TimesCode(Operation):
3044 class TimesCode(Operation):
3039 """
3045 """
3040
3046
3041 """
3047 """
3042
3048
3043 def __init__(self, **kwargs):
3049 def __init__(self, **kwargs):
3044
3050
3045 Operation.__init__(self, **kwargs)
3051 Operation.__init__(self, **kwargs)
3046
3052
3047
3053
3048
3054
3049 def run(self,dataOut,code):
3055 def run(self,dataOut,code):
3050
3056
3051 #code = numpy.repeat(code, repeats=osamp, axis=1)
3057 #code = numpy.repeat(code, repeats=osamp, axis=1)
3052 nCodes = numpy.shape(code)[1]
3058 nCodes = numpy.shape(code)[1]
3053 #nprofcode = dataOut.nProfiles//nCodes
3059 #nprofcode = dataOut.nProfiles//nCodes
3054 code = numpy.array(code)
3060 code = numpy.array(code)
3055 #print("nHeights",dataOut.nHeights)
3061 #print("nHeights",dataOut.nHeights)
3056 #print("nheicode",nheicode)
3062 #print("nheicode",nheicode)
3057 #print("Code.Shape",numpy.shape(code))
3063 #print("Code.Shape",numpy.shape(code))
3058 #print("Code",code[0,:])
3064 #print("Code",code[0,:])
3059 nheicode = dataOut.nHeights//nCodes
3065 nheicode = dataOut.nHeights//nCodes
3060 res = dataOut.nHeights%nCodes
3066 res = dataOut.nHeights%nCodes
3061 '''
3067 '''
3062 buffer = numpy.zeros((dataOut.nChannels,
3068 buffer = numpy.zeros((dataOut.nChannels,
3063 nprofcode,
3069 nprofcode,
3064 nCodes,
3070 nCodes,
3065 ndataOut.nHeights),
3071 ndataOut.nHeights),
3066 dtype='complex')
3072 dtype='complex')
3067 '''
3073 '''
3068 #exit(1)
3074 #exit(1)
3069 #for ipr in range(dataOut.nProfiles):
3075 #for ipr in range(dataOut.nProfiles):
3070 #print(dataOut.nHeights)
3076 #print(dataOut.nHeights)
3071 #print(dataOut.data[0,384-2:])
3077 #print(dataOut.data[0,384-2:])
3072 #print(dataOut.profileIndex)
3078 #print(dataOut.profileIndex)
3073 #print(dataOut.data[0,:2])
3079 #print(dataOut.data[0,:2])
3074 #print(dataOut.data[0,0:64])
3080 #print(dataOut.data[0,0:64])
3075 #print(dataOut.data[0,64:64+64])
3081 #print(dataOut.data[0,64:64+64])
3076 #exit(1)
3082 #exit(1)
3077 for ich in range(dataOut.nChannels):
3083 for ich in range(dataOut.nChannels):
3078 for ihe in range(nheicode):
3084 for ihe in range(nheicode):
3079 #print(ihe*nCodes)
3085 #print(ihe*nCodes)
3080 #print((ihe+1)*nCodes)
3086 #print((ihe+1)*nCodes)
3081 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]
3087 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)]
3082 #code[ipr,:]
3088 #code[ipr,:]
3083 #print("before",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3089 #print("before",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3084 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)],code[ipr,:]],axis=0)
3090 #dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)],code[ipr,:]],axis=0)
3085 dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)],code[dataOut.profileIndex,:]],axis=0)
3091 dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)] = numpy.prod([dataOut.data[ich,ihe*nCodes:nCodes*(ihe+1)],code[dataOut.profileIndex,:]],axis=0)
3086
3092
3087 #print("after",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3093 #print("after",dataOut.data[ich,ipr,ihe*nCodes:nCodes*(ihe+1)])
3088 #exit(1)
3094 #exit(1)
3089 #print(dataOut.data[0,:2])
3095 #print(dataOut.data[0,:2])
3090 #exit(1)
3096 #exit(1)
3091 #print(nheicode)
3097 #print(nheicode)
3092 #print((nheicode)*nCodes)
3098 #print((nheicode)*nCodes)
3093 #print(((nheicode)*nCodes)+res)
3099 #print(((nheicode)*nCodes)+res)
3094 if res != 0:
3100 if res != 0:
3095 for ich in range(dataOut.nChannels):
3101 for ich in range(dataOut.nChannels):
3096 dataOut.data[ich,nheicode*nCodes:] = numpy.prod([dataOut.data[ich,nheicode*nCodes:],code[dataOut.profileIndex,:res]],axis=0)
3102 dataOut.data[ich,nheicode*nCodes:] = numpy.prod([dataOut.data[ich,nheicode*nCodes:],code[dataOut.profileIndex,:res]],axis=0)
3097
3103
3098 #pass
3104 #pass
3099 #print(dataOut.data[0,384-2:])
3105 #print(dataOut.data[0,384-2:])
3100 #exit(1)
3106 #exit(1)
3101 #dataOut.data = numpy.mean(buffer,axis=1)
3107 #dataOut.data = numpy.mean(buffer,axis=1)
3102 #print(numpy.shape(dataOut.data))
3108 #print(numpy.shape(dataOut.data))
3103 #print(dataOut.nHeights)
3109 #print(dataOut.nHeights)
3104 #dataOut.heightList = dataOut.heightList[0:nheicode]
3110 #dataOut.heightList = dataOut.heightList[0:nheicode]
3105 #print(dataOut.nHeights)
3111 #print(dataOut.nHeights)
3106 #dataOut.nHeights = numpy.shape(dataOut.data)[2]
3112 #dataOut.nHeights = numpy.shape(dataOut.data)[2]
3107 #print(numpy.shape(dataOut.data))
3113 #print(numpy.shape(dataOut.data))
3108 #exit(1)
3114 #exit(1)
3109
3115
3110 return dataOut
3116 return dataOut
3111
3117
3112 '''
3118 '''
3113 class Spectrogram(Operation):
3119 class Spectrogram(Operation):
3114 """
3120 """
3115
3121
3116 """
3122 """
3117
3123
3118 def __init__(self, **kwargs):
3124 def __init__(self, **kwargs):
3119
3125
3120 Operation.__init__(self, **kwargs)
3126 Operation.__init__(self, **kwargs)
3121
3127
3122
3128
3123
3129
3124 def run(self,dataOut):
3130 def run(self,dataOut):
3125
3131
3126 import scipy
3132 import scipy
3127
3133
3128
3134
3129
3135
3130 fs = 3200*1e-6
3136 fs = 3200*1e-6
3131 fs = fs/64
3137 fs = fs/64
3132 fs = 1/fs
3138 fs = 1/fs
3133
3139
3134 nperseg=64
3140 nperseg=64
3135 noverlap=48
3141 noverlap=48
3136
3142
3137 f, t, Sxx = signal.spectrogram(x, fs, return_onesided=False, nperseg=nperseg, noverlap=noverlap, mode='complex')
3143 f, t, Sxx = signal.spectrogram(x, fs, return_onesided=False, nperseg=nperseg, noverlap=noverlap, mode='complex')
3138
3144
3139
3145
3140 for ich in range(dataOut.nChannels):
3146 for ich in range(dataOut.nChannels):
3141 for ihe in range(nheicode):
3147 for ihe in range(nheicode):
3142
3148
3143
3149
3144 return dataOut
3150 return dataOut
3145 '''
3151 '''
3146
3152
3147
3153
3148 class RemoveDcHae(Operation):
3154 class RemoveDcHae(Operation):
3149
3155
3150 def __init__(self, **kwargs):
3156 def __init__(self, **kwargs):
3151
3157
3152 Operation.__init__(self, **kwargs)
3158 Operation.__init__(self, **kwargs)
3153 self.DcCounter = 0
3159 self.DcCounter = 0
3154
3160
3155 def run(self, dataOut):
3161 def run(self, dataOut):
3156
3162
3157 if self.DcCounter == 0:
3163 if self.DcCounter == 0:
3158 dataOut.DcHae = numpy.zeros((dataOut.data.shape[0],320),dtype='complex')
3164 dataOut.DcHae = numpy.zeros((dataOut.data.shape[0],320),dtype='complex')
3159 #dataOut.DcHae = []
3165 #dataOut.DcHae = []
3160 self.DcCounter = 1
3166 self.DcCounter = 1
3161
3167
3162 dataOut.dataaux = numpy.copy(dataOut.data)
3168 dataOut.dataaux = numpy.copy(dataOut.data)
3163
3169
3164 #dataOut.DcHae += dataOut.dataaux[:,1666:1666+320]
3170 #dataOut.DcHae += dataOut.dataaux[:,1666:1666+320]
3165 dataOut.DcHae += dataOut.dataaux[:,0:0+320]
3171 dataOut.DcHae += dataOut.dataaux[:,0:0+320]
3166 hei = 1666
3172 hei = 1666
3167 hei = 2000
3173 hei = 2000
3168 hei = 1000
3174 hei = 1000
3169 hei = 0
3175 hei = 0
3170 #dataOut.DcHae = numpy.concatenate([dataOut.DcHae,dataOut.dataaux[0,hei]],axis = None)
3176 #dataOut.DcHae = numpy.concatenate([dataOut.DcHae,dataOut.dataaux[0,hei]],axis = None)
3171
3177
3172
3178
3173
3179
3174 return dataOut
3180 return dataOut
3175
3181
3176
3182
3177 class SSheightProfiles(Operation):
3183 class SSheightProfiles(Operation):
3178
3184
3179 step = None
3185 step = None
3180 nsamples = None
3186 nsamples = None
3181 bufferShape = None
3187 bufferShape = None
3182 profileShape = None
3188 profileShape = None
3183 sshProfiles = None
3189 sshProfiles = None
3184 profileIndex = None
3190 profileIndex = None
3185
3191
3186 def __init__(self, **kwargs):
3192 def __init__(self, **kwargs):
3187
3193
3188 Operation.__init__(self, **kwargs)
3194 Operation.__init__(self, **kwargs)
3189 self.isConfig = False
3195 self.isConfig = False
3190
3196
3191 def setup(self,dataOut ,step = None , nsamples = None):
3197 def setup(self,dataOut ,step = None , nsamples = None):
3192
3198
3193 if step == None and nsamples == None:
3199 if step == None and nsamples == None:
3194 #pass
3200 #pass
3195 raise ValueError("step or nheights should be specified ...")
3201 raise ValueError("step or nheights should be specified ...")
3196
3202
3197 self.step = step
3203 self.step = step
3198 self.nsamples = nsamples
3204 self.nsamples = nsamples
3199 self.__nChannels = dataOut.nChannels
3205 self.__nChannels = dataOut.nChannels
3200 self.__nProfiles = dataOut.nProfiles
3206 self.__nProfiles = dataOut.nProfiles
3201 self.__nHeis = dataOut.nHeights
3207 self.__nHeis = dataOut.nHeights
3202 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
3208 shape = dataOut.data.shape #nchannels, nprofiles, nsamples
3203 '''
3209 '''
3204 print "input nChannels",self.__nChannels
3210 print "input nChannels",self.__nChannels
3205 print "input nProfiles",self.__nProfiles
3211 print "input nProfiles",self.__nProfiles
3206 print "input nHeis",self.__nHeis
3212 print "input nHeis",self.__nHeis
3207 print "input Shape",shape
3213 print "input Shape",shape
3208 '''
3214 '''
3209
3215
3210
3216
3211 residue = (shape[1] - self.nsamples) % self.step
3217 residue = (shape[1] - self.nsamples) % self.step
3212 if residue != 0:
3218 if residue != 0:
3213 print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue))
3219 print("The residue is %d, step=%d should be multiple of %d to avoid loss of %d samples"%(residue,step,shape[1] - self.nsamples,residue))
3214
3220
3215 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3221 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3216 numberProfile = self.nsamples
3222 numberProfile = self.nsamples
3217 numberSamples = (shape[1] - self.nsamples)/self.step
3223 numberSamples = (shape[1] - self.nsamples)/self.step
3218 '''
3224 '''
3219 print "new numberProfile",numberProfile
3225 print "new numberProfile",numberProfile
3220 print "new numberSamples",numberSamples
3226 print "new numberSamples",numberSamples
3221
3227
3222 print "New number of profile: %d, number of height: %d, Resolution %f Km"%(numberProfile,numberSamples,deltaHeight*self.step)
3228 print "New number of profile: %d, number of height: %d, Resolution %f Km"%(numberProfile,numberSamples,deltaHeight*self.step)
3223 '''
3229 '''
3224 self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles
3230 self.bufferShape = int(shape[0]), int(numberSamples), int(numberProfile) # nchannels, nsamples , nprofiles
3225 self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples
3231 self.profileShape = int(shape[0]), int(numberProfile), int(numberSamples) # nchannels, nprofiles, nsamples
3226
3232
3227 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
3233 self.buffer = numpy.zeros(self.bufferShape , dtype=numpy.complex)
3228 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
3234 self.sshProfiles = numpy.zeros(self.profileShape, dtype=numpy.complex)
3229
3235
3230 def run(self, dataOut, step, nsamples, code = None, repeat = None):
3236 def run(self, dataOut, step, nsamples, code = None, repeat = None):
3231 #print(dataOut.profileIndex)
3237 #print(dataOut.profileIndex)
3232 dataOut.flagNoData = True
3238 dataOut.flagNoData = True
3233 dataOut.flagDataAsBlock = False
3239 dataOut.flagDataAsBlock = False
3234 profileIndex = None
3240 profileIndex = None
3235
3241
3236 #code = numpy.array(code)
3242 #code = numpy.array(code)
3237 #print(dataOut.data[0,:])
3243 #print(dataOut.data[0,:])
3238 #exit(1)
3244 #exit(1)
3239
3245
3240
3246
3241 if not self.isConfig:
3247 if not self.isConfig:
3242 #print("STEP",step)
3248 #print("STEP",step)
3243 self.setup(dataOut, step=step , nsamples=nsamples)
3249 self.setup(dataOut, step=step , nsamples=nsamples)
3244 self.isConfig = True
3250 self.isConfig = True
3245 #print(code[dataOut.profileIndex,:])
3251 #print(code[dataOut.profileIndex,:])
3246
3252
3247 #DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3253 #DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3248 DC_Hae = numpy.array([ 0.001025 +0.0516375j, 0.03485 +0.20923125j, -0.168 -0.02720625j,
3254 DC_Hae = numpy.array([ 0.001025 +0.0516375j, 0.03485 +0.20923125j, -0.168 -0.02720625j,
3249 -0.1105375 +0.0707125j, -0.20309375-0.09670625j, 0.189775 +0.02716875j])*(-3.5)
3255 -0.1105375 +0.0707125j, -0.20309375-0.09670625j, 0.189775 +0.02716875j])*(-3.5)
3250
3256
3251 DC_Hae = numpy.array([ -32.26 +8.66j, -32.26 +8.66j])
3257 DC_Hae = numpy.array([ -32.26 +8.66j, -32.26 +8.66j])
3252
3258
3253 DC_Hae = numpy.array([-2.78500000e-01 -1.39175j, -6.63237294e+02+210.4268625j])
3259 DC_Hae = numpy.array([-2.78500000e-01 -1.39175j, -6.63237294e+02+210.4268625j])
3254
3260
3255
3261
3256
3262
3257
3263
3258
3264
3259
3265
3260 #print(dataOut.data[0,13:15])
3266 #print(dataOut.data[0,13:15])
3261 dataOut.data = dataOut.data - DC_Hae[:,None]
3267 dataOut.data = dataOut.data - DC_Hae[:,None]
3262 #print(dataOut.data[0,13:15])
3268 #print(dataOut.data[0,13:15])
3263 #exit(1)
3269 #exit(1)
3264
3270
3265
3271
3266
3272
3267 code = numpy.array(code)
3273 code = numpy.array(code)
3268 roll = 0
3274 roll = 0
3269 code = numpy.roll(code,roll,axis=0)
3275 code = numpy.roll(code,roll,axis=0)
3270 code = numpy.reshape(code,(5,100,64))
3276 code = numpy.reshape(code,(5,100,64))
3271 block = dataOut.CurrentBlock%5
3277 block = dataOut.CurrentBlock%5
3272 #print(block)
3278 #print(block)
3273
3279
3274 #code_block = code[block-1-2,:,:]
3280 #code_block = code[block-1-2,:,:]
3275 day_dif = 1 #day_12
3281 day_dif = 1 #day_12
3276 code_block = code[block-1-0,:,:]
3282 code_block = code[block-1-0,:,:]
3277
3283
3278 if repeat is not None:
3284 if repeat is not None:
3279 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3285 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3280
3286
3281
3287
3282
3288
3283 #print(dataOut.data[0:2,13])
3289 #print(dataOut.data[0:2,13])
3284 for i in range(self.buffer.shape[1]):
3290 for i in range(self.buffer.shape[1]):
3285 #self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3291 #self.buffer[:,i] = numpy.flip(dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3286 '''
3292 '''
3287 print(dataOut.profileIndex)
3293 print(dataOut.profileIndex)
3288 print(code[dataOut.profileIndex,:])
3294 print(code[dataOut.profileIndex,:])
3289 print("before",dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3295 print("before",dataOut.data[:,i*self.step:i*self.step + self.nsamples])
3290 print("after",dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code[dataOut.profileIndex,:])
3296 print("after",dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code[dataOut.profileIndex,:])
3291 exit(1)
3297 exit(1)
3292 '''
3298 '''
3293
3299
3294 #dif = numpy.copy(code)
3300 #dif = numpy.copy(code)
3295 if code is not None:
3301 if code is not None:
3296 '''
3302 '''
3297 code = numpy.array(code)
3303 code = numpy.array(code)
3298 #print(code[0,:])
3304 #print(code[0,:])
3299
3305
3300 #print("There is Code")
3306 #print("There is Code")
3301 #exit(1)
3307 #exit(1)
3302 #code = dataOut.code
3308 #code = dataOut.code
3303 #print(code[0,:])
3309 #print(code[0,:])
3304 #exit(1)
3310 #exit(1)
3305
3311
3306 roll = 0
3312 roll = 0
3307 code = numpy.roll(code,roll,axis=0)
3313 code = numpy.roll(code,roll,axis=0)
3308 code = numpy.reshape(code,(5,100,64))
3314 code = numpy.reshape(code,(5,100,64))
3309 block = dataOut.CurrentBlock%5
3315 block = dataOut.CurrentBlock%5
3310 #print(block)
3316 #print(block)
3311
3317
3312 #code_block = code[block-1-2,:,:]
3318 #code_block = code[block-1-2,:,:]
3313 day_dif = 1 #day_12
3319 day_dif = 1 #day_12
3314 code_block = code[block-1-0,:,:]
3320 code_block = code[block-1-0,:,:]
3315
3321
3316
3322
3317
3323
3318 if repeat is not None:
3324 if repeat is not None:
3319 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3325 code_block = numpy.repeat(code_block, repeats=repeat, axis=1)
3320 '''
3326 '''
3321
3327
3322
3328
3323
3329
3324 #code_block = code[0,:,:]
3330 #code_block = code[0,:,:]
3325
3331
3326 #print(code_block[2,:])
3332 #print(code_block[2,:])
3327 #for l in range(dataOut.data.shape[1]):
3333 #for l in range(dataOut.data.shape[1]):
3328 #dataOut.data[:,l] = dataOut.data[:,l] - numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3334 #dataOut.data[:,l] = dataOut.data[:,l] - numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3329
3335
3330 ##DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3336 ##DC_Hae = numpy.array([0.398+0.588j, -0.926+0.306j, -0.536-0.682j, -0.072+0.53j, 0.368-0.356j, 0.996+0.362j])
3331
3337
3332 #print(dataOut.data[0:2,13])
3338 #print(dataOut.data[0:2,13])
3333 ##dataOut.data = dataOut.data - DC_Hae[:,None]
3339 ##dataOut.data = dataOut.data - DC_Hae[:,None]
3334 #print(dataOut.data[0:2,13])
3340 #print(dataOut.data[0:2,13])
3335 #exit(1)
3341 #exit(1)
3336 #print(dataOut.data[0,i*self.step:i*self.step + self.nsamples])
3342 #print(dataOut.data[0,i*self.step:i*self.step + self.nsamples])
3337 #print(dataOut.data[1,i*self.step:i*self.step + self.nsamples])
3343 #print(dataOut.data[1,i*self.step:i*self.step + self.nsamples])
3338 #print(code_block[dataOut.profileIndex,:])
3344 #print(code_block[dataOut.profileIndex,:])
3339 #print(numpy.shape(code_block[dataOut.profileIndex,:]))
3345 #print(numpy.shape(code_block[dataOut.profileIndex,:]))
3340 #exit(1)
3346 #exit(1)
3341 ###aux = numpy.mean(dataOut.data[:,i*self.step:i*self.step + self.nsamples],axis=1)
3347 ###aux = numpy.mean(dataOut.data[:,i*self.step:i*self.step + self.nsamples],axis=1)
3342 ###self.buffer[:,i] = (dataOut.data[:,i*self.step:i*self.step + self.nsamples]-aux[:,None])*code_block[dataOut.profileIndex,:]
3348 ###self.buffer[:,i] = (dataOut.data[:,i*self.step:i*self.step + self.nsamples]-aux[:,None])*code_block[dataOut.profileIndex,:]
3343 '''
3349 '''
3344 if i == 18:
3350 if i == 18:
3345 buffer = dataOut.data[0,i*self.step:i*self.step + self.nsamples]
3351 buffer = dataOut.data[0,i*self.step:i*self.step + self.nsamples]
3346 import matplotlib.pyplot as plt
3352 import matplotlib.pyplot as plt
3347 fig, axes = plt.subplots(figsize=(14, 10))
3353 fig, axes = plt.subplots(figsize=(14, 10))
3348 x = numpy.linspace(0,20,numpy.shape(buffer)[0])
3354 x = numpy.linspace(0,20,numpy.shape(buffer)[0])
3349 x = numpy.fft.fftfreq(numpy.shape(buffer)[0],0.00005)
3355 x = numpy.fft.fftfreq(numpy.shape(buffer)[0],0.00005)
3350 x = numpy.fft.fftshift(x)
3356 x = numpy.fft.fftshift(x)
3351
3357
3352 plt.plot(x,buffer)
3358 plt.plot(x,buffer)
3353 plt.show()
3359 plt.show()
3354 import time
3360 import time
3355 time.sleep(50)
3361 time.sleep(50)
3356 '''
3362 '''
3357 #for k in range(dataOut.nChannels):
3363 #for k in range(dataOut.nChannels):
3358 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block[dataOut.profileIndex,:]
3364 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]*code_block[dataOut.profileIndex,:]
3359 #print(dataOut.data[0,:])
3365 #print(dataOut.data[0,:])
3360 #print(code_block[0,:])
3366 #print(code_block[0,:])
3361 #print(self.buffer[1,i])
3367 #print(self.buffer[1,i])
3362 #exit(1)
3368 #exit(1)
3363 else:
3369 else:
3364 #print("There is no Code")
3370 #print("There is no Code")
3365 #exit(1)
3371 #exit(1)
3366 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:]
3372 self.buffer[:,i] = dataOut.data[:,i*self.step:i*self.step + self.nsamples]#*code[dataOut.profileIndex,:]
3367
3373
3368 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
3374 #self.buffer[:,j,self.__nHeis-j*self.step - self.nheights:self.__nHeis-j*self.step] = numpy.flip(dataOut.data[:,j*self.step:j*self.step + self.nheights])
3369
3375
3370 for j in range(self.buffer.shape[0]):
3376 for j in range(self.buffer.shape[0]):
3371 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
3377 self.sshProfiles[j] = numpy.transpose(self.buffer[j])
3372
3378
3373 profileIndex = self.nsamples
3379 profileIndex = self.nsamples
3374 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3380 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3375 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
3381 ippSeconds = (deltaHeight*1.0e-6)/(0.15)
3376 #print "ippSeconds",ippSeconds
3382 #print "ippSeconds",ippSeconds
3377 try:
3383 try:
3378 if dataOut.concat_m is not None:
3384 if dataOut.concat_m is not None:
3379 ippSeconds= ippSeconds/float(dataOut.concat_m)
3385 ippSeconds= ippSeconds/float(dataOut.concat_m)
3380 #print "Profile concat %d"%dataOut.concat_m
3386 #print "Profile concat %d"%dataOut.concat_m
3381 except:
3387 except:
3382 pass
3388 pass
3383
3389
3384
3390
3385
3391
3386 dataOut.data = self.sshProfiles
3392 dataOut.data = self.sshProfiles
3387 dataOut.flagNoData = False
3393 dataOut.flagNoData = False
3388 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
3394 dataOut.heightList = numpy.arange(self.buffer.shape[1]) *self.step*deltaHeight + dataOut.heightList[0]
3389 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
3395 dataOut.nProfiles = int(dataOut.nProfiles*self.nsamples)
3390
3396
3391 '''
3397 '''
3392 print(dataOut.profileIndex)
3398 print(dataOut.profileIndex)
3393 if dataOut.profileIndex == 0:
3399 if dataOut.profileIndex == 0:
3394 dataOut.data = dataOut.data*1.e5
3400 dataOut.data = dataOut.data*1.e5
3395
3401
3396 buffer_prom =
3402 buffer_prom =
3397 '''
3403 '''
3398 #dataOut.utctime = dataOut.utctime - dataOut.profileIndex
3404 #dataOut.utctime = dataOut.utctime - dataOut.profileIndex
3399 #print(dataOut.profileIndex)
3405 #print(dataOut.profileIndex)
3400 #print(dataOut.data[0,0,0])
3406 #print(dataOut.data[0,0,0])
3401 '''
3407 '''
3402 if dataOut.profileIndex == 0:
3408 if dataOut.profileIndex == 0:
3403 self.buffer_prom = numpy.copy(dataOut.data)
3409 self.buffer_prom = numpy.copy(dataOut.data)
3404
3410
3405 else:
3411 else:
3406 self.buffer_prom = dataOut.data+self.buffer_prom
3412 self.buffer_prom = dataOut.data+self.buffer_prom
3407 if dataOut.profileIndex == 99:
3413 if dataOut.profileIndex == 99:
3408 dataOut.data = self.buffer_prom/100
3414 dataOut.data = self.buffer_prom/100
3409 '''
3415 '''
3410
3416
3411 #print(dataOut.data[0,0,0])
3417 #print(dataOut.data[0,0,0])
3412 #print(dataOut.profileIndex)
3418 #print(dataOut.profileIndex)
3413 dataOut.profileIndex = profileIndex
3419 dataOut.profileIndex = profileIndex
3414 dataOut.flagDataAsBlock = True
3420 dataOut.flagDataAsBlock = True
3415 dataOut.ippSeconds = ippSeconds
3421 dataOut.ippSeconds = ippSeconds
3416 dataOut.step = self.step
3422 dataOut.step = self.step
3417 #print(dataOut.profileIndex)
3423 #print(dataOut.profileIndex)
3418 #print(dataOut.heightList)
3424 #print(dataOut.heightList)
3419 #exit(1)
3425 #exit(1)
3420
3426
3421 #print(dataOut.times)
3427 #print(dataOut.times)
3422
3428
3423 return dataOut
3429 return dataOut
3424
3430
3425 class Decoder(Operation):
3431 class Decoder(Operation):
3426
3432
3427 isConfig = False
3433 isConfig = False
3428 __profIndex = 0
3434 __profIndex = 0
3429
3435
3430 code = None
3436 code = None
3431
3437
3432 nCode = None
3438 nCode = None
3433 nBaud = None
3439 nBaud = None
3434
3440
3435 def __init__(self, **kwargs):
3441 def __init__(self, **kwargs):
3436
3442
3437 Operation.__init__(self, **kwargs)
3443 Operation.__init__(self, **kwargs)
3438
3444
3439 self.times = None
3445 self.times = None
3440 self.osamp = None
3446 self.osamp = None
3441 # self.__setValues = False
3447 # self.__setValues = False
3442 self.isConfig = False
3448 self.isConfig = False
3443 self.setupReq = False
3449 self.setupReq = False
3444 def setup(self, code, osamp, dataOut):
3450 def setup(self, code, osamp, dataOut):
3445
3451
3446 self.__profIndex = 0
3452 self.__profIndex = 0
3447
3453
3448 self.code = code
3454 self.code = code
3449
3455
3450 self.nCode = len(code)
3456 self.nCode = len(code)
3451 self.nBaud = len(code[0])
3457 self.nBaud = len(code[0])
3452
3458
3453 if (osamp != None) and (osamp >1):
3459 if (osamp != None) and (osamp >1):
3454 self.osamp = osamp
3460 self.osamp = osamp
3455 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3461 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3456 self.nBaud = self.nBaud*self.osamp
3462 self.nBaud = self.nBaud*self.osamp
3457
3463
3458 self.__nChannels = dataOut.nChannels
3464 self.__nChannels = dataOut.nChannels
3459 self.__nProfiles = dataOut.nProfiles
3465 self.__nProfiles = dataOut.nProfiles
3460 self.__nHeis = dataOut.nHeights
3466 self.__nHeis = dataOut.nHeights
3461
3467
3462 if self.__nHeis < self.nBaud:
3468 if self.__nHeis < self.nBaud:
3463 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3469 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3464
3470
3465 #Frequency
3471 #Frequency
3466 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3472 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3467
3473
3468 __codeBuffer[:,0:self.nBaud] = self.code
3474 __codeBuffer[:,0:self.nBaud] = self.code
3469
3475
3470 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3476 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3471
3477
3472 if dataOut.flagDataAsBlock:
3478 if dataOut.flagDataAsBlock:
3473
3479
3474 self.ndatadec = self.__nHeis #- self.nBaud + 1
3480 self.ndatadec = self.__nHeis #- self.nBaud + 1
3475
3481
3476 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3482 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3477
3483
3478 else:
3484 else:
3479
3485
3480 #Time
3486 #Time
3481 self.ndatadec = self.__nHeis #- self.nBaud + 1
3487 self.ndatadec = self.__nHeis #- self.nBaud + 1
3482
3488
3483
3489
3484 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3490 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3485
3491
3486 def __convolutionInFreq(self, data):
3492 def __convolutionInFreq(self, data):
3487
3493
3488 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3494 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3489
3495
3490 fft_data = numpy.fft.fft(data, axis=1)
3496 fft_data = numpy.fft.fft(data, axis=1)
3491
3497
3492 conv = fft_data*fft_code
3498 conv = fft_data*fft_code
3493
3499
3494 data = numpy.fft.ifft(conv,axis=1)
3500 data = numpy.fft.ifft(conv,axis=1)
3495
3501
3496 return data
3502 return data
3497
3503
3498 def __convolutionInFreqOpt(self, data):
3504 def __convolutionInFreqOpt(self, data):
3499
3505
3500 raise NotImplementedError
3506 raise NotImplementedError
3501
3507
3502 def __convolutionInTime(self, data):
3508 def __convolutionInTime(self, data):
3503
3509
3504 code = self.code[self.__profIndex]
3510 code = self.code[self.__profIndex]
3505 for i in range(self.__nChannels):
3511 for i in range(self.__nChannels):
3506 #aux=numpy.correlate(data[i,:], code, mode='full')
3512 #aux=numpy.correlate(data[i,:], code, mode='full')
3507 #print(numpy.shape(aux))
3513 #print(numpy.shape(aux))
3508 #print(numpy.shape(data[i,:]))
3514 #print(numpy.shape(data[i,:]))
3509 #print(numpy.shape(code))
3515 #print(numpy.shape(code))
3510 #exit(1)
3516 #exit(1)
3511 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3517 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3512
3518
3513 return self.datadecTime
3519 return self.datadecTime
3514
3520
3515 def __convolutionByBlockInTime(self, data):
3521 def __convolutionByBlockInTime(self, data):
3516
3522
3517 repetitions = int(self.__nProfiles / self.nCode)
3523 repetitions = int(self.__nProfiles / self.nCode)
3518 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3524 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3519 junk = junk.flatten()
3525 junk = junk.flatten()
3520 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3526 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3521 profilesList = range(self.__nProfiles)
3527 profilesList = range(self.__nProfiles)
3522 #print(numpy.shape(self.datadecTime))
3528 #print(numpy.shape(self.datadecTime))
3523 #print(numpy.shape(data))
3529 #print(numpy.shape(data))
3524 for i in range(self.__nChannels):
3530 for i in range(self.__nChannels):
3525 for j in profilesList:
3531 for j in profilesList:
3526 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3532 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3527 return self.datadecTime
3533 return self.datadecTime
3528
3534
3529 def __convolutionByBlockInFreq(self, data):
3535 def __convolutionByBlockInFreq(self, data):
3530
3536
3531 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3537 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3532
3538
3533
3539
3534 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3540 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3535
3541
3536 fft_data = numpy.fft.fft(data, axis=2)
3542 fft_data = numpy.fft.fft(data, axis=2)
3537
3543
3538 conv = fft_data*fft_code
3544 conv = fft_data*fft_code
3539
3545
3540 data = numpy.fft.ifft(conv,axis=2)
3546 data = numpy.fft.ifft(conv,axis=2)
3541
3547
3542 return data
3548 return data
3543
3549
3544
3550
3545 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3551 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3546
3552
3547 if dataOut.flagDecodeData:
3553 if dataOut.flagDecodeData:
3548 print("This data is already decoded, recoding again ...")
3554 print("This data is already decoded, recoding again ...")
3549
3555
3550 if not self.isConfig:
3556 if not self.isConfig:
3551
3557
3552 if code is None:
3558 if code is None:
3553 if dataOut.code is None:
3559 if dataOut.code is None:
3554 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3560 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3555
3561
3556 code = dataOut.code
3562 code = dataOut.code
3557 else:
3563 else:
3558 code = numpy.array(code).reshape(nCode,nBaud)
3564 code = numpy.array(code).reshape(nCode,nBaud)
3559 self.setup(code, osamp, dataOut)
3565 self.setup(code, osamp, dataOut)
3560
3566
3561 self.isConfig = True
3567 self.isConfig = True
3562
3568
3563 if mode == 3:
3569 if mode == 3:
3564 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3570 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3565
3571
3566 if times != None:
3572 if times != None:
3567 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3573 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3568
3574
3569 if self.code is None:
3575 if self.code is None:
3570 print("Fail decoding: Code is not defined.")
3576 print("Fail decoding: Code is not defined.")
3571 return
3577 return
3572
3578
3573 self.__nProfiles = dataOut.nProfiles
3579 self.__nProfiles = dataOut.nProfiles
3574 datadec = None
3580 datadec = None
3575
3581
3576 if mode == 3:
3582 if mode == 3:
3577 mode = 0
3583 mode = 0
3578
3584
3579 if dataOut.flagDataAsBlock:
3585 if dataOut.flagDataAsBlock:
3580 """
3586 """
3581 Decoding when data have been read as block,
3587 Decoding when data have been read as block,
3582 """
3588 """
3583
3589
3584 if mode == 0:
3590 if mode == 0:
3585 datadec = self.__convolutionByBlockInTime(dataOut.data)
3591 datadec = self.__convolutionByBlockInTime(dataOut.data)
3586 if mode == 1:
3592 if mode == 1:
3587 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3593 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3588 else:
3594 else:
3589 """
3595 """
3590 Decoding when data have been read profile by profile
3596 Decoding when data have been read profile by profile
3591 """
3597 """
3592 if mode == 0:
3598 if mode == 0:
3593 datadec = self.__convolutionInTime(dataOut.data)
3599 datadec = self.__convolutionInTime(dataOut.data)
3594
3600
3595 if mode == 1:
3601 if mode == 1:
3596 datadec = self.__convolutionInFreq(dataOut.data)
3602 datadec = self.__convolutionInFreq(dataOut.data)
3597
3603
3598 if mode == 2:
3604 if mode == 2:
3599 datadec = self.__convolutionInFreqOpt(dataOut.data)
3605 datadec = self.__convolutionInFreqOpt(dataOut.data)
3600
3606
3601 if datadec is None:
3607 if datadec is None:
3602 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3608 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3603
3609
3604 dataOut.code = self.code
3610 dataOut.code = self.code
3605 dataOut.nCode = self.nCode
3611 dataOut.nCode = self.nCode
3606 dataOut.nBaud = self.nBaud
3612 dataOut.nBaud = self.nBaud
3607
3613
3608 dataOut.data = datadec
3614 dataOut.data = datadec
3609 #print("before",dataOut.heightList)
3615 #print("before",dataOut.heightList)
3610 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3616 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3611 #print("after",dataOut.heightList)
3617 #print("after",dataOut.heightList)
3612
3618
3613 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3619 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3614
3620
3615 if self.__profIndex == self.nCode-1:
3621 if self.__profIndex == self.nCode-1:
3616 self.__profIndex = 0
3622 self.__profIndex = 0
3617 return dataOut
3623 return dataOut
3618
3624
3619 self.__profIndex += 1
3625 self.__profIndex += 1
3620
3626
3621 #print("SHAPE",numpy.shape(dataOut.data))
3627 #print("SHAPE",numpy.shape(dataOut.data))
3622
3628
3623 return dataOut
3629 return dataOut
3624 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
3630 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
3625
3631
3626 class DecoderRoll(Operation):
3632 class DecoderRoll(Operation):
3627
3633
3628 isConfig = False
3634 isConfig = False
3629 __profIndex = 0
3635 __profIndex = 0
3630
3636
3631 code = None
3637 code = None
3632
3638
3633 nCode = None
3639 nCode = None
3634 nBaud = None
3640 nBaud = None
3635
3641
3636 def __init__(self, **kwargs):
3642 def __init__(self, **kwargs):
3637
3643
3638 Operation.__init__(self, **kwargs)
3644 Operation.__init__(self, **kwargs)
3639
3645
3640 self.times = None
3646 self.times = None
3641 self.osamp = None
3647 self.osamp = None
3642 # self.__setValues = False
3648 # self.__setValues = False
3643 self.isConfig = False
3649 self.isConfig = False
3644 self.setupReq = False
3650 self.setupReq = False
3645 def setup(self, code, osamp, dataOut):
3651 def setup(self, code, osamp, dataOut):
3646
3652
3647 self.__profIndex = 0
3653 self.__profIndex = 0
3648
3654
3649
3655
3650 self.code = code
3656 self.code = code
3651
3657
3652 self.nCode = len(code)
3658 self.nCode = len(code)
3653 self.nBaud = len(code[0])
3659 self.nBaud = len(code[0])
3654
3660
3655 if (osamp != None) and (osamp >1):
3661 if (osamp != None) and (osamp >1):
3656 self.osamp = osamp
3662 self.osamp = osamp
3657 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3663 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3658 self.nBaud = self.nBaud*self.osamp
3664 self.nBaud = self.nBaud*self.osamp
3659
3665
3660 self.__nChannels = dataOut.nChannels
3666 self.__nChannels = dataOut.nChannels
3661 self.__nProfiles = dataOut.nProfiles
3667 self.__nProfiles = dataOut.nProfiles
3662 self.__nHeis = dataOut.nHeights
3668 self.__nHeis = dataOut.nHeights
3663
3669
3664 if self.__nHeis < self.nBaud:
3670 if self.__nHeis < self.nBaud:
3665 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3671 raise ValueError('Number of heights (%d) should be greater than number of bauds (%d)' %(self.__nHeis, self.nBaud))
3666
3672
3667 #Frequency
3673 #Frequency
3668 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3674 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
3669
3675
3670 __codeBuffer[:,0:self.nBaud] = self.code
3676 __codeBuffer[:,0:self.nBaud] = self.code
3671
3677
3672 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3678 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
3673
3679
3674 if dataOut.flagDataAsBlock:
3680 if dataOut.flagDataAsBlock:
3675
3681
3676 self.ndatadec = self.__nHeis #- self.nBaud + 1
3682 self.ndatadec = self.__nHeis #- self.nBaud + 1
3677
3683
3678 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3684 self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex)
3679
3685
3680 else:
3686 else:
3681
3687
3682 #Time
3688 #Time
3683 self.ndatadec = self.__nHeis #- self.nBaud + 1
3689 self.ndatadec = self.__nHeis #- self.nBaud + 1
3684
3690
3685
3691
3686 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3692 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
3687
3693
3688 def __convolutionInFreq(self, data):
3694 def __convolutionInFreq(self, data):
3689
3695
3690 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3696 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3691
3697
3692 fft_data = numpy.fft.fft(data, axis=1)
3698 fft_data = numpy.fft.fft(data, axis=1)
3693
3699
3694 conv = fft_data*fft_code
3700 conv = fft_data*fft_code
3695
3701
3696 data = numpy.fft.ifft(conv,axis=1)
3702 data = numpy.fft.ifft(conv,axis=1)
3697
3703
3698 return data
3704 return data
3699
3705
3700 def __convolutionInFreqOpt(self, data):
3706 def __convolutionInFreqOpt(self, data):
3701
3707
3702 raise NotImplementedError
3708 raise NotImplementedError
3703
3709
3704 def __convolutionInTime(self, data):
3710 def __convolutionInTime(self, data):
3705
3711
3706 code = self.code[self.__profIndex]
3712 code = self.code[self.__profIndex]
3707 #print("code",code[0,0])
3713 #print("code",code[0,0])
3708 for i in range(self.__nChannels):
3714 for i in range(self.__nChannels):
3709 #aux=numpy.correlate(data[i,:], code, mode='full')
3715 #aux=numpy.correlate(data[i,:], code, mode='full')
3710 #print(numpy.shape(aux))
3716 #print(numpy.shape(aux))
3711 #print(numpy.shape(data[i,:]))
3717 #print(numpy.shape(data[i,:]))
3712 #print(numpy.shape(code))
3718 #print(numpy.shape(code))
3713 #exit(1)
3719 #exit(1)
3714 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3720 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
3715
3721
3716 return self.datadecTime
3722 return self.datadecTime
3717
3723
3718 def __convolutionByBlockInTime(self, data):
3724 def __convolutionByBlockInTime(self, data):
3719
3725
3720 repetitions = int(self.__nProfiles / self.nCode)
3726 repetitions = int(self.__nProfiles / self.nCode)
3721 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3727 junk = numpy.lib.stride_tricks.as_strided(self.code, (repetitions, self.code.size), (0, self.code.itemsize))
3722 junk = junk.flatten()
3728 junk = junk.flatten()
3723 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3729 code_block = numpy.reshape(junk, (self.nCode*repetitions, self.nBaud))
3724 profilesList = range(self.__nProfiles)
3730 profilesList = range(self.__nProfiles)
3725 #print(numpy.shape(self.datadecTime))
3731 #print(numpy.shape(self.datadecTime))
3726 #print(numpy.shape(data))
3732 #print(numpy.shape(data))
3727 for i in range(self.__nChannels):
3733 for i in range(self.__nChannels):
3728 for j in profilesList:
3734 for j in profilesList:
3729 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3735 self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='full')[self.nBaud-1:]
3730 return self.datadecTime
3736 return self.datadecTime
3731
3737
3732 def __convolutionByBlockInFreq(self, data):
3738 def __convolutionByBlockInFreq(self, data):
3733
3739
3734 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3740 raise NotImplementedError("Decoder by frequency fro Blocks not implemented")
3735
3741
3736
3742
3737 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3743 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
3738
3744
3739 fft_data = numpy.fft.fft(data, axis=2)
3745 fft_data = numpy.fft.fft(data, axis=2)
3740
3746
3741 conv = fft_data*fft_code
3747 conv = fft_data*fft_code
3742
3748
3743 data = numpy.fft.ifft(conv,axis=2)
3749 data = numpy.fft.ifft(conv,axis=2)
3744
3750
3745 return data
3751 return data
3746
3752
3747
3753
3748 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3754 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, osamp=None, times=None):
3749
3755
3750 if dataOut.flagDecodeData:
3756 if dataOut.flagDecodeData:
3751 print("This data is already decoded, recoding again ...")
3757 print("This data is already decoded, recoding again ...")
3752
3758
3753
3759
3754
3760
3755 #print(dataOut.ippSeconds)
3761 #print(dataOut.ippSeconds)
3756 #exit(1)
3762 #exit(1)
3757 roll = 0
3763 roll = 0
3758
3764
3759 if self.isConfig:
3765 if self.isConfig:
3760 code = numpy.array(code)
3766 code = numpy.array(code)
3761
3767
3762 #roll = 29
3768 #roll = 29
3763 code = numpy.roll(code,roll,axis=0)
3769 code = numpy.roll(code,roll,axis=0)
3764 code = numpy.reshape(code,(5,100,64))
3770 code = numpy.reshape(code,(5,100,64))
3765 block = dataOut.CurrentBlock%5
3771 block = dataOut.CurrentBlock%5
3766 #code = code[block-1,:,:] #NormalizeDPPower
3772 #code = code[block-1,:,:] #NormalizeDPPower
3767 code = code[block-1-1,:,:] #Next Day
3773 code = code[block-1-1,:,:] #Next Day
3768 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3774 self.code = numpy.repeat(code, repeats=self.osamp, axis=1)
3769
3775
3770
3776
3771 if not self.isConfig:
3777 if not self.isConfig:
3772
3778
3773 if code is None:
3779 if code is None:
3774 if dataOut.code is None:
3780 if dataOut.code is None:
3775 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3781 raise ValueError("Code could not be read from %s instance. Enter a value in Code parameter" %dataOut.type)
3776
3782
3777 code = dataOut.code
3783 code = dataOut.code
3778 else:
3784 else:
3779 code = numpy.array(code)
3785 code = numpy.array(code)
3780
3786
3781 #roll = 29
3787 #roll = 29
3782 code = numpy.roll(code,roll,axis=0)
3788 code = numpy.roll(code,roll,axis=0)
3783 code = numpy.reshape(code,(5,100,64))
3789 code = numpy.reshape(code,(5,100,64))
3784 block = dataOut.CurrentBlock%5
3790 block = dataOut.CurrentBlock%5
3785 code = code[block-1-1,:,:]
3791 code = code[block-1-1,:,:]
3786 #print(code.shape())
3792 #print(code.shape())
3787 #exit(1)
3793 #exit(1)
3788
3794
3789 code = numpy.array(code).reshape(nCode,nBaud)
3795 code = numpy.array(code).reshape(nCode,nBaud)
3790 self.setup(code, osamp, dataOut)
3796 self.setup(code, osamp, dataOut)
3791
3797
3792 self.isConfig = True
3798 self.isConfig = True
3793
3799
3794 if mode == 3:
3800 if mode == 3:
3795 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3801 sys.stderr.write("Decoder Warning: mode=%d is not valid, using mode=0\n" %mode)
3796
3802
3797 if times != None:
3803 if times != None:
3798 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3804 sys.stderr.write("Decoder Warning: Argument 'times' in not used anymore\n")
3799
3805
3800 if self.code is None:
3806 if self.code is None:
3801 print("Fail decoding: Code is not defined.")
3807 print("Fail decoding: Code is not defined.")
3802 return
3808 return
3803
3809
3804 self.__nProfiles = dataOut.nProfiles
3810 self.__nProfiles = dataOut.nProfiles
3805 datadec = None
3811 datadec = None
3806
3812
3807 if mode == 3:
3813 if mode == 3:
3808 mode = 0
3814 mode = 0
3809
3815
3810 if dataOut.flagDataAsBlock:
3816 if dataOut.flagDataAsBlock:
3811 """
3817 """
3812 Decoding when data have been read as block,
3818 Decoding when data have been read as block,
3813 """
3819 """
3814
3820
3815 if mode == 0:
3821 if mode == 0:
3816 datadec = self.__convolutionByBlockInTime(dataOut.data)
3822 datadec = self.__convolutionByBlockInTime(dataOut.data)
3817 if mode == 1:
3823 if mode == 1:
3818 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3824 datadec = self.__convolutionByBlockInFreq(dataOut.data)
3819 else:
3825 else:
3820 """
3826 """
3821 Decoding when data have been read profile by profile
3827 Decoding when data have been read profile by profile
3822 """
3828 """
3823 if mode == 0:
3829 if mode == 0:
3824 datadec = self.__convolutionInTime(dataOut.data)
3830 datadec = self.__convolutionInTime(dataOut.data)
3825
3831
3826 if mode == 1:
3832 if mode == 1:
3827 datadec = self.__convolutionInFreq(dataOut.data)
3833 datadec = self.__convolutionInFreq(dataOut.data)
3828
3834
3829 if mode == 2:
3835 if mode == 2:
3830 datadec = self.__convolutionInFreqOpt(dataOut.data)
3836 datadec = self.__convolutionInFreqOpt(dataOut.data)
3831
3837
3832 if datadec is None:
3838 if datadec is None:
3833 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3839 raise ValueError("Codification mode selected is not valid: mode=%d. Try selecting 0 or 1" %mode)
3834
3840
3835 dataOut.code = self.code
3841 dataOut.code = self.code
3836 dataOut.nCode = self.nCode
3842 dataOut.nCode = self.nCode
3837 dataOut.nBaud = self.nBaud
3843 dataOut.nBaud = self.nBaud
3838
3844
3839 dataOut.data = datadec
3845 dataOut.data = datadec
3840 #print("before",dataOut.heightList)
3846 #print("before",dataOut.heightList)
3841 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3847 dataOut.heightList = dataOut.heightList[0:datadec.shape[-1]]
3842 #print("after",dataOut.heightList)
3848 #print("after",dataOut.heightList)
3843
3849
3844 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3850 dataOut.flagDecodeData = True #asumo q la data esta decodificada
3845
3851
3846 if self.__profIndex == self.nCode-1:
3852 if self.__profIndex == self.nCode-1:
3847 self.__profIndex = 0
3853 self.__profIndex = 0
3848 return dataOut
3854 return dataOut
3849
3855
3850 self.__profIndex += 1
3856 self.__profIndex += 1
3851
3857
3852 #print("SHAPE",numpy.shape(dataOut.data))
3858 #print("SHAPE",numpy.shape(dataOut.data))
3853
3859
3854 return dataOut
3860 return dataOut
3855
3861
3856
3862
3857
3863
3858
3864
3859
3865
3860
3866
3861 class ProfileConcat(Operation):
3867 class ProfileConcat(Operation):
3862
3868
3863 isConfig = False
3869 isConfig = False
3864 buffer = None
3870 buffer = None
3865
3871
3866 def __init__(self, **kwargs):
3872 def __init__(self, **kwargs):
3867
3873
3868 Operation.__init__(self, **kwargs)
3874 Operation.__init__(self, **kwargs)
3869 self.profileIndex = 0
3875 self.profileIndex = 0
3870
3876
3871 def reset(self):
3877 def reset(self):
3872 self.buffer = numpy.zeros_like(self.buffer)
3878 self.buffer = numpy.zeros_like(self.buffer)
3873 self.start_index = 0
3879 self.start_index = 0
3874 self.times = 1
3880 self.times = 1
3875
3881
3876 def setup(self, data, m, n=1):
3882 def setup(self, data, m, n=1):
3877 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
3883 self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0]))
3878 self.nHeights = data.shape[1]#.nHeights
3884 self.nHeights = data.shape[1]#.nHeights
3879 self.start_index = 0
3885 self.start_index = 0
3880 self.times = 1
3886 self.times = 1
3881
3887
3882 def concat(self, data):
3888 def concat(self, data):
3883
3889
3884 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
3890 self.buffer[:,self.start_index:self.nHeights*self.times] = data.copy()
3885 self.start_index = self.start_index + self.nHeights
3891 self.start_index = self.start_index + self.nHeights
3886
3892
3887 def run(self, dataOut, m):
3893 def run(self, dataOut, m):
3888 dataOut.flagNoData = True
3894 dataOut.flagNoData = True
3889
3895
3890 if not self.isConfig:
3896 if not self.isConfig:
3891 self.setup(dataOut.data, m, 1)
3897 self.setup(dataOut.data, m, 1)
3892 self.isConfig = True
3898 self.isConfig = True
3893
3899
3894 if dataOut.flagDataAsBlock:
3900 if dataOut.flagDataAsBlock:
3895 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
3901 raise ValueError("ProfileConcat can only be used when voltage have been read profile by profile, getBlock = False")
3896
3902
3897 else:
3903 else:
3898 self.concat(dataOut.data)
3904 self.concat(dataOut.data)
3899 self.times += 1
3905 self.times += 1
3900 if self.times > m:
3906 if self.times > m:
3901 dataOut.data = self.buffer
3907 dataOut.data = self.buffer
3902 self.reset()
3908 self.reset()
3903 dataOut.flagNoData = False
3909 dataOut.flagNoData = False
3904 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
3910 # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas
3905 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3911 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
3906 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
3912 xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * m
3907 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
3913 dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight)
3908 dataOut.ippSeconds *= m
3914 dataOut.ippSeconds *= m
3909 return dataOut
3915 return dataOut
3910
3916
3911 class ProfileSelector(Operation):
3917 class ProfileSelector(Operation):
3912
3918
3913 profileIndex = None
3919 profileIndex = None
3914 # Tamanho total de los perfiles
3920 # Tamanho total de los perfiles
3915 nProfiles = None
3921 nProfiles = None
3916
3922
3917 def __init__(self, **kwargs):
3923 def __init__(self, **kwargs):
3918
3924
3919 Operation.__init__(self, **kwargs)
3925 Operation.__init__(self, **kwargs)
3920 self.profileIndex = 0
3926 self.profileIndex = 0
3921
3927
3922 def incProfileIndex(self):
3928 def incProfileIndex(self):
3923
3929
3924 self.profileIndex += 1
3930 self.profileIndex += 1
3925
3931
3926 if self.profileIndex >= self.nProfiles:
3932 if self.profileIndex >= self.nProfiles:
3927 self.profileIndex = 0
3933 self.profileIndex = 0
3928
3934
3929 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
3935 def isThisProfileInRange(self, profileIndex, minIndex, maxIndex):
3930
3936
3931 if profileIndex < minIndex:
3937 if profileIndex < minIndex:
3932 return False
3938 return False
3933
3939
3934 if profileIndex > maxIndex:
3940 if profileIndex > maxIndex:
3935 return False
3941 return False
3936
3942
3937 return True
3943 return True
3938
3944
3939 def isThisProfileInList(self, profileIndex, profileList):
3945 def isThisProfileInList(self, profileIndex, profileList):
3940
3946
3941 if profileIndex not in profileList:
3947 if profileIndex not in profileList:
3942 return False
3948 return False
3943
3949
3944 return True
3950 return True
3945
3951
3946 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
3952 def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False, rangeList = None, nProfiles=None):
3947
3953
3948 """
3954 """
3949 ProfileSelector:
3955 ProfileSelector:
3950
3956
3951 Inputs:
3957 Inputs:
3952 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
3958 profileList : Index of profiles selected. Example: profileList = (0,1,2,7,8)
3953
3959
3954 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
3960 profileRangeList : Minimum and maximum profile indexes. Example: profileRangeList = (4, 30)
3955
3961
3956 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
3962 rangeList : List of profile ranges. Example: rangeList = ((4, 30), (32, 64), (128, 256))
3957
3963
3958 """
3964 """
3959
3965
3960 if rangeList is not None:
3966 if rangeList is not None:
3961 if type(rangeList[0]) not in (tuple, list):
3967 if type(rangeList[0]) not in (tuple, list):
3962 rangeList = [rangeList]
3968 rangeList = [rangeList]
3963
3969
3964 dataOut.flagNoData = True
3970 dataOut.flagNoData = True
3965
3971
3966 if dataOut.flagDataAsBlock:
3972 if dataOut.flagDataAsBlock:
3967 """
3973 """
3968 data dimension = [nChannels, nProfiles, nHeis]
3974 data dimension = [nChannels, nProfiles, nHeis]
3969 """
3975 """
3970 if profileList != None:
3976 if profileList != None:
3971 dataOut.data = dataOut.data[:,profileList,:]
3977 dataOut.data = dataOut.data[:,profileList,:]
3972
3978
3973 if profileRangeList != None:
3979 if profileRangeList != None:
3974 minIndex = profileRangeList[0]
3980 minIndex = profileRangeList[0]
3975 maxIndex = profileRangeList[1]
3981 maxIndex = profileRangeList[1]
3976 profileList = list(range(minIndex, maxIndex+1))
3982 profileList = list(range(minIndex, maxIndex+1))
3977
3983
3978 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
3984 dataOut.data = dataOut.data[:,minIndex:maxIndex+1,:]
3979
3985
3980 if rangeList != None:
3986 if rangeList != None:
3981
3987
3982 profileList = []
3988 profileList = []
3983
3989
3984 for thisRange in rangeList:
3990 for thisRange in rangeList:
3985 minIndex = thisRange[0]
3991 minIndex = thisRange[0]
3986 maxIndex = thisRange[1]
3992 maxIndex = thisRange[1]
3987
3993
3988 profileList.extend(list(range(minIndex, maxIndex+1)))
3994 profileList.extend(list(range(minIndex, maxIndex+1)))
3989
3995
3990 dataOut.data = dataOut.data[:,profileList,:]
3996 dataOut.data = dataOut.data[:,profileList,:]
3991
3997
3992 dataOut.nProfiles = len(profileList)
3998 dataOut.nProfiles = len(profileList)
3993 dataOut.profileIndex = dataOut.nProfiles - 1
3999 dataOut.profileIndex = dataOut.nProfiles - 1
3994 dataOut.flagNoData = False
4000 dataOut.flagNoData = False
3995
4001
3996 return dataOut
4002 return dataOut
3997
4003
3998 """
4004 """
3999 data dimension = [nChannels, nHeis]
4005 data dimension = [nChannels, nHeis]
4000 """
4006 """
4001
4007
4002 if profileList != None:
4008 if profileList != None:
4003
4009
4004 if self.isThisProfileInList(dataOut.profileIndex, profileList):
4010 if self.isThisProfileInList(dataOut.profileIndex, profileList):
4005
4011
4006 self.nProfiles = len(profileList)
4012 self.nProfiles = len(profileList)
4007 dataOut.nProfiles = self.nProfiles
4013 dataOut.nProfiles = self.nProfiles
4008 dataOut.profileIndex = self.profileIndex
4014 dataOut.profileIndex = self.profileIndex
4009 dataOut.flagNoData = False
4015 dataOut.flagNoData = False
4010
4016
4011 self.incProfileIndex()
4017 self.incProfileIndex()
4012 return dataOut
4018 return dataOut
4013
4019
4014 if profileRangeList != None:
4020 if profileRangeList != None:
4015
4021
4016 minIndex = profileRangeList[0]
4022 minIndex = profileRangeList[0]
4017 maxIndex = profileRangeList[1]
4023 maxIndex = profileRangeList[1]
4018
4024
4019 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4025 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4020
4026
4021 self.nProfiles = maxIndex - minIndex + 1
4027 self.nProfiles = maxIndex - minIndex + 1
4022 dataOut.nProfiles = self.nProfiles
4028 dataOut.nProfiles = self.nProfiles
4023 dataOut.profileIndex = self.profileIndex
4029 dataOut.profileIndex = self.profileIndex
4024 dataOut.flagNoData = False
4030 dataOut.flagNoData = False
4025
4031
4026 self.incProfileIndex()
4032 self.incProfileIndex()
4027 return dataOut
4033 return dataOut
4028
4034
4029 if rangeList != None:
4035 if rangeList != None:
4030
4036
4031 nProfiles = 0
4037 nProfiles = 0
4032
4038
4033 for thisRange in rangeList:
4039 for thisRange in rangeList:
4034 minIndex = thisRange[0]
4040 minIndex = thisRange[0]
4035 maxIndex = thisRange[1]
4041 maxIndex = thisRange[1]
4036
4042
4037 nProfiles += maxIndex - minIndex + 1
4043 nProfiles += maxIndex - minIndex + 1
4038
4044
4039 for thisRange in rangeList:
4045 for thisRange in rangeList:
4040
4046
4041 minIndex = thisRange[0]
4047 minIndex = thisRange[0]
4042 maxIndex = thisRange[1]
4048 maxIndex = thisRange[1]
4043
4049
4044 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4050 if self.isThisProfileInRange(dataOut.profileIndex, minIndex, maxIndex):
4045
4051
4046 self.nProfiles = nProfiles
4052 self.nProfiles = nProfiles
4047 dataOut.nProfiles = self.nProfiles
4053 dataOut.nProfiles = self.nProfiles
4048 dataOut.profileIndex = self.profileIndex
4054 dataOut.profileIndex = self.profileIndex
4049 dataOut.flagNoData = False
4055 dataOut.flagNoData = False
4050
4056
4051 self.incProfileIndex()
4057 self.incProfileIndex()
4052
4058
4053 break
4059 break
4054
4060
4055 return dataOut
4061 return dataOut
4056
4062
4057
4063
4058 if beam != None: #beam is only for AMISR data
4064 if beam != None: #beam is only for AMISR data
4059 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
4065 if self.isThisProfileInList(dataOut.profileIndex, dataOut.beamRangeDict[beam]):
4060 dataOut.flagNoData = False
4066 dataOut.flagNoData = False
4061 dataOut.profileIndex = self.profileIndex
4067 dataOut.profileIndex = self.profileIndex
4062
4068
4063 self.incProfileIndex()
4069 self.incProfileIndex()
4064
4070
4065 return dataOut
4071 return dataOut
4066
4072
4067 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
4073 raise ValueError("ProfileSelector needs profileList, profileRangeList or rangeList parameter")
4068
4074
4069 #return False
4075 #return False
4070 return dataOut
4076 return dataOut
4071
4077
4072 class Reshaper(Operation):
4078 class Reshaper(Operation):
4073
4079
4074 def __init__(self, **kwargs):
4080 def __init__(self, **kwargs):
4075
4081
4076 Operation.__init__(self, **kwargs)
4082 Operation.__init__(self, **kwargs)
4077
4083
4078 self.__buffer = None
4084 self.__buffer = None
4079 self.__nitems = 0
4085 self.__nitems = 0
4080
4086
4081 def __appendProfile(self, dataOut, nTxs):
4087 def __appendProfile(self, dataOut, nTxs):
4082
4088
4083 if self.__buffer is None:
4089 if self.__buffer is None:
4084 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
4090 shape = (dataOut.nChannels, int(dataOut.nHeights/nTxs) )
4085 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
4091 self.__buffer = numpy.empty(shape, dtype = dataOut.data.dtype)
4086
4092
4087 ini = dataOut.nHeights * self.__nitems
4093 ini = dataOut.nHeights * self.__nitems
4088 end = ini + dataOut.nHeights
4094 end = ini + dataOut.nHeights
4089
4095
4090 self.__buffer[:, ini:end] = dataOut.data
4096 self.__buffer[:, ini:end] = dataOut.data
4091
4097
4092 self.__nitems += 1
4098 self.__nitems += 1
4093
4099
4094 return int(self.__nitems*nTxs)
4100 return int(self.__nitems*nTxs)
4095
4101
4096 def __getBuffer(self):
4102 def __getBuffer(self):
4097
4103
4098 if self.__nitems == int(1./self.__nTxs):
4104 if self.__nitems == int(1./self.__nTxs):
4099
4105
4100 self.__nitems = 0
4106 self.__nitems = 0
4101
4107
4102 return self.__buffer.copy()
4108 return self.__buffer.copy()
4103
4109
4104 return None
4110 return None
4105
4111
4106 def __checkInputs(self, dataOut, shape, nTxs):
4112 def __checkInputs(self, dataOut, shape, nTxs):
4107
4113
4108 if shape is None and nTxs is None:
4114 if shape is None and nTxs is None:
4109 raise ValueError("Reshaper: shape of factor should be defined")
4115 raise ValueError("Reshaper: shape of factor should be defined")
4110
4116
4111 if nTxs:
4117 if nTxs:
4112 if nTxs < 0:
4118 if nTxs < 0:
4113 raise ValueError("nTxs should be greater than 0")
4119 raise ValueError("nTxs should be greater than 0")
4114
4120
4115 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
4121 if nTxs < 1 and dataOut.nProfiles % (1./nTxs) != 0:
4116 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
4122 raise ValueError("nProfiles= %d is not divisibled by (1./nTxs) = %f" %(dataOut.nProfiles, (1./nTxs)))
4117
4123
4118 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
4124 shape = [dataOut.nChannels, dataOut.nProfiles*nTxs, dataOut.nHeights/nTxs]
4119
4125
4120 return shape, nTxs
4126 return shape, nTxs
4121
4127
4122 if len(shape) != 2 and len(shape) != 3:
4128 if len(shape) != 2 and len(shape) != 3:
4123 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
4129 raise ValueError("shape dimension should be equal to 2 or 3. shape = (nProfiles, nHeis) or (nChannels, nProfiles, nHeis). Actually shape = (%d, %d, %d)" %(dataOut.nChannels, dataOut.nProfiles, dataOut.nHeights))
4124
4130
4125 if len(shape) == 2:
4131 if len(shape) == 2:
4126 shape_tuple = [dataOut.nChannels]
4132 shape_tuple = [dataOut.nChannels]
4127 shape_tuple.extend(shape)
4133 shape_tuple.extend(shape)
4128 else:
4134 else:
4129 shape_tuple = list(shape)
4135 shape_tuple = list(shape)
4130
4136
4131 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
4137 nTxs = 1.0*shape_tuple[1]/dataOut.nProfiles
4132
4138
4133 return shape_tuple, nTxs
4139 return shape_tuple, nTxs
4134
4140
4135 def run(self, dataOut, shape=None, nTxs=None):
4141 def run(self, dataOut, shape=None, nTxs=None):
4136
4142
4137 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
4143 shape_tuple, self.__nTxs = self.__checkInputs(dataOut, shape, nTxs)
4138
4144
4139 dataOut.flagNoData = True
4145 dataOut.flagNoData = True
4140 profileIndex = None
4146 profileIndex = None
4141
4147
4142 if dataOut.flagDataAsBlock:
4148 if dataOut.flagDataAsBlock:
4143
4149
4144 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
4150 dataOut.data = numpy.reshape(dataOut.data, shape_tuple)
4145 dataOut.flagNoData = False
4151 dataOut.flagNoData = False
4146
4152
4147 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
4153 profileIndex = int(dataOut.nProfiles*self.__nTxs) - 1
4148
4154
4149 else:
4155 else:
4150
4156
4151
4157
4152 if self.__nTxs < 1:
4158 if self.__nTxs < 1:
4153
4159
4154 self.__appendProfile(dataOut, self.__nTxs)
4160 self.__appendProfile(dataOut, self.__nTxs)
4155 new_data = self.__getBuffer()
4161 new_data = self.__getBuffer()
4156
4162
4157 if new_data is not None:
4163 if new_data is not None:
4158 dataOut.data = new_data
4164 dataOut.data = new_data
4159 dataOut.flagNoData = False
4165 dataOut.flagNoData = False
4160
4166
4161 profileIndex = dataOut.profileIndex*nTxs
4167 profileIndex = dataOut.profileIndex*nTxs
4162
4168
4163 else:
4169 else:
4164 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
4170 raise ValueError("nTxs should be greater than 0 and lower than 1, or use VoltageReader(..., getblock=True)")
4165
4171
4166 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4172 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4167
4173
4168 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
4174 dataOut.heightList = numpy.arange(dataOut.nHeights/self.__nTxs) * deltaHeight + dataOut.heightList[0]
4169
4175
4170 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
4176 dataOut.nProfiles = int(dataOut.nProfiles*self.__nTxs)
4171
4177
4172 dataOut.profileIndex = profileIndex
4178 dataOut.profileIndex = profileIndex
4173
4179
4174 dataOut.ippSeconds /= self.__nTxs
4180 dataOut.ippSeconds /= self.__nTxs
4175
4181
4176 return dataOut
4182 return dataOut
4177
4183
4178 class SplitProfiles(Operation):
4184 class SplitProfiles(Operation):
4179
4185
4180 def __init__(self, **kwargs):
4186 def __init__(self, **kwargs):
4181
4187
4182 Operation.__init__(self, **kwargs)
4188 Operation.__init__(self, **kwargs)
4183
4189
4184 def run(self, dataOut, n):
4190 def run(self, dataOut, n):
4185
4191
4186 dataOut.flagNoData = True
4192 dataOut.flagNoData = True
4187 profileIndex = None
4193 profileIndex = None
4188
4194
4189 if dataOut.flagDataAsBlock:
4195 if dataOut.flagDataAsBlock:
4190
4196
4191 #nchannels, nprofiles, nsamples
4197 #nchannels, nprofiles, nsamples
4192 shape = dataOut.data.shape
4198 shape = dataOut.data.shape
4193
4199
4194 if shape[2] % n != 0:
4200 if shape[2] % n != 0:
4195 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
4201 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[2]))
4196
4202
4197 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
4203 new_shape = shape[0], shape[1]*n, int(shape[2]/n)
4198
4204
4199 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4205 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4200 dataOut.flagNoData = False
4206 dataOut.flagNoData = False
4201
4207
4202 profileIndex = int(dataOut.nProfiles/n) - 1
4208 profileIndex = int(dataOut.nProfiles/n) - 1
4203
4209
4204 else:
4210 else:
4205
4211
4206 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
4212 raise ValueError("Could not split the data when is read Profile by Profile. Use VoltageReader(..., getblock=True)")
4207
4213
4208 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4214 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4209
4215
4210 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
4216 dataOut.heightList = numpy.arange(dataOut.nHeights/n) * deltaHeight + dataOut.heightList[0]
4211
4217
4212 dataOut.nProfiles = int(dataOut.nProfiles*n)
4218 dataOut.nProfiles = int(dataOut.nProfiles*n)
4213
4219
4214 dataOut.profileIndex = profileIndex
4220 dataOut.profileIndex = profileIndex
4215
4221
4216 dataOut.ippSeconds /= n
4222 dataOut.ippSeconds /= n
4217
4223
4218 return dataOut
4224 return dataOut
4219
4225
4220 class CombineProfiles(Operation):
4226 class CombineProfiles(Operation):
4221 def __init__(self, **kwargs):
4227 def __init__(self, **kwargs):
4222
4228
4223 Operation.__init__(self, **kwargs)
4229 Operation.__init__(self, **kwargs)
4224
4230
4225 self.__remData = None
4231 self.__remData = None
4226 self.__profileIndex = 0
4232 self.__profileIndex = 0
4227
4233
4228 def run(self, dataOut, n):
4234 def run(self, dataOut, n):
4229
4235
4230 dataOut.flagNoData = True
4236 dataOut.flagNoData = True
4231 profileIndex = None
4237 profileIndex = None
4232
4238
4233 if dataOut.flagDataAsBlock:
4239 if dataOut.flagDataAsBlock:
4234
4240
4235 #nchannels, nprofiles, nsamples
4241 #nchannels, nprofiles, nsamples
4236 shape = dataOut.data.shape
4242 shape = dataOut.data.shape
4237 new_shape = shape[0], shape[1]/n, shape[2]*n
4243 new_shape = shape[0], shape[1]/n, shape[2]*n
4238
4244
4239 if shape[1] % n != 0:
4245 if shape[1] % n != 0:
4240 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
4246 raise ValueError("Could not split the data, n=%d has to be multiple of %d" %(n, shape[1]))
4241
4247
4242 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4248 dataOut.data = numpy.reshape(dataOut.data, new_shape)
4243 dataOut.flagNoData = False
4249 dataOut.flagNoData = False
4244
4250
4245 profileIndex = int(dataOut.nProfiles*n) - 1
4251 profileIndex = int(dataOut.nProfiles*n) - 1
4246
4252
4247 else:
4253 else:
4248
4254
4249 #nchannels, nsamples
4255 #nchannels, nsamples
4250 if self.__remData is None:
4256 if self.__remData is None:
4251 newData = dataOut.data
4257 newData = dataOut.data
4252 else:
4258 else:
4253 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
4259 newData = numpy.concatenate((self.__remData, dataOut.data), axis=1)
4254
4260
4255 self.__profileIndex += 1
4261 self.__profileIndex += 1
4256
4262
4257 if self.__profileIndex < n:
4263 if self.__profileIndex < n:
4258 self.__remData = newData
4264 self.__remData = newData
4259 #continue
4265 #continue
4260 return
4266 return
4261
4267
4262 self.__profileIndex = 0
4268 self.__profileIndex = 0
4263 self.__remData = None
4269 self.__remData = None
4264
4270
4265 dataOut.data = newData
4271 dataOut.data = newData
4266 dataOut.flagNoData = False
4272 dataOut.flagNoData = False
4267
4273
4268 profileIndex = dataOut.profileIndex/n
4274 profileIndex = dataOut.profileIndex/n
4269
4275
4270
4276
4271 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4277 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4272
4278
4273 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
4279 dataOut.heightList = numpy.arange(dataOut.nHeights*n) * deltaHeight + dataOut.heightList[0]
4274
4280
4275 dataOut.nProfiles = int(dataOut.nProfiles/n)
4281 dataOut.nProfiles = int(dataOut.nProfiles/n)
4276
4282
4277 dataOut.profileIndex = profileIndex
4283 dataOut.profileIndex = profileIndex
4278
4284
4279 dataOut.ippSeconds *= n
4285 dataOut.ippSeconds *= n
4280
4286
4281 return dataOut
4287 return dataOut
4282 # import collections
4288 # import collections
4283 # from scipy.stats import mode
4289 # from scipy.stats import mode
4284 #
4290 #
4285 # class Synchronize(Operation):
4291 # class Synchronize(Operation):
4286 #
4292 #
4287 # isConfig = False
4293 # isConfig = False
4288 # __profIndex = 0
4294 # __profIndex = 0
4289 #
4295 #
4290 # def __init__(self, **kwargs):
4296 # def __init__(self, **kwargs):
4291 #
4297 #
4292 # Operation.__init__(self, **kwargs)
4298 # Operation.__init__(self, **kwargs)
4293 # # self.isConfig = False
4299 # # self.isConfig = False
4294 # self.__powBuffer = None
4300 # self.__powBuffer = None
4295 # self.__startIndex = 0
4301 # self.__startIndex = 0
4296 # self.__pulseFound = False
4302 # self.__pulseFound = False
4297 #
4303 #
4298 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
4304 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
4299 #
4305 #
4300 # #Read data
4306 # #Read data
4301 #
4307 #
4302 # powerdB = dataOut.getPower(channel = channel)
4308 # powerdB = dataOut.getPower(channel = channel)
4303 # noisedB = dataOut.getNoise(channel = channel)[0]
4309 # noisedB = dataOut.getNoise(channel = channel)[0]
4304 #
4310 #
4305 # self.__powBuffer.extend(powerdB.flatten())
4311 # self.__powBuffer.extend(powerdB.flatten())
4306 #
4312 #
4307 # dataArray = numpy.array(self.__powBuffer)
4313 # dataArray = numpy.array(self.__powBuffer)
4308 #
4314 #
4309 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
4315 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
4310 #
4316 #
4311 # maxValue = numpy.nanmax(filteredPower)
4317 # maxValue = numpy.nanmax(filteredPower)
4312 #
4318 #
4313 # if maxValue < noisedB + 10:
4319 # if maxValue < noisedB + 10:
4314 # #No se encuentra ningun pulso de transmision
4320 # #No se encuentra ningun pulso de transmision
4315 # return None
4321 # return None
4316 #
4322 #
4317 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
4323 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
4318 #
4324 #
4319 # if len(maxValuesIndex) < 2:
4325 # if len(maxValuesIndex) < 2:
4320 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
4326 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
4321 # return None
4327 # return None
4322 #
4328 #
4323 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
4329 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
4324 #
4330 #
4325 # #Seleccionar solo valores con un espaciamiento de nSamples
4331 # #Seleccionar solo valores con un espaciamiento de nSamples
4326 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
4332 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
4327 #
4333 #
4328 # if len(pulseIndex) < 2:
4334 # if len(pulseIndex) < 2:
4329 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4335 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4330 # return None
4336 # return None
4331 #
4337 #
4332 # spacing = pulseIndex[1:] - pulseIndex[:-1]
4338 # spacing = pulseIndex[1:] - pulseIndex[:-1]
4333 #
4339 #
4334 # #remover senales que se distancien menos de 10 unidades o muestras
4340 # #remover senales que se distancien menos de 10 unidades o muestras
4335 # #(No deberian existir IPP menor a 10 unidades)
4341 # #(No deberian existir IPP menor a 10 unidades)
4336 #
4342 #
4337 # realIndex = numpy.where(spacing > 10 )[0]
4343 # realIndex = numpy.where(spacing > 10 )[0]
4338 #
4344 #
4339 # if len(realIndex) < 2:
4345 # if len(realIndex) < 2:
4340 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4346 # #Solo se encontro un pulso de transmision con ancho mayor a 1
4341 # return None
4347 # return None
4342 #
4348 #
4343 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
4349 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
4344 # realPulseIndex = pulseIndex[realIndex]
4350 # realPulseIndex = pulseIndex[realIndex]
4345 #
4351 #
4346 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
4352 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
4347 #
4353 #
4348 # print "IPP = %d samples" %period
4354 # print "IPP = %d samples" %period
4349 #
4355 #
4350 # self.__newNSamples = dataOut.nHeights #int(period)
4356 # self.__newNSamples = dataOut.nHeights #int(period)
4351 # self.__startIndex = int(realPulseIndex[0])
4357 # self.__startIndex = int(realPulseIndex[0])
4352 #
4358 #
4353 # return 1
4359 # return 1
4354 #
4360 #
4355 #
4361 #
4356 # def setup(self, nSamples, nChannels, buffer_size = 4):
4362 # def setup(self, nSamples, nChannels, buffer_size = 4):
4357 #
4363 #
4358 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
4364 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
4359 # maxlen = buffer_size*nSamples)
4365 # maxlen = buffer_size*nSamples)
4360 #
4366 #
4361 # bufferList = []
4367 # bufferList = []
4362 #
4368 #
4363 # for i in range(nChannels):
4369 # for i in range(nChannels):
4364 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
4370 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
4365 # maxlen = buffer_size*nSamples)
4371 # maxlen = buffer_size*nSamples)
4366 #
4372 #
4367 # bufferList.append(bufferByChannel)
4373 # bufferList.append(bufferByChannel)
4368 #
4374 #
4369 # self.__nSamples = nSamples
4375 # self.__nSamples = nSamples
4370 # self.__nChannels = nChannels
4376 # self.__nChannels = nChannels
4371 # self.__bufferList = bufferList
4377 # self.__bufferList = bufferList
4372 #
4378 #
4373 # def run(self, dataOut, channel = 0):
4379 # def run(self, dataOut, channel = 0):
4374 #
4380 #
4375 # if not self.isConfig:
4381 # if not self.isConfig:
4376 # nSamples = dataOut.nHeights
4382 # nSamples = dataOut.nHeights
4377 # nChannels = dataOut.nChannels
4383 # nChannels = dataOut.nChannels
4378 # self.setup(nSamples, nChannels)
4384 # self.setup(nSamples, nChannels)
4379 # self.isConfig = True
4385 # self.isConfig = True
4380 #
4386 #
4381 # #Append new data to internal buffer
4387 # #Append new data to internal buffer
4382 # for thisChannel in range(self.__nChannels):
4388 # for thisChannel in range(self.__nChannels):
4383 # bufferByChannel = self.__bufferList[thisChannel]
4389 # bufferByChannel = self.__bufferList[thisChannel]
4384 # bufferByChannel.extend(dataOut.data[thisChannel])
4390 # bufferByChannel.extend(dataOut.data[thisChannel])
4385 #
4391 #
4386 # if self.__pulseFound:
4392 # if self.__pulseFound:
4387 # self.__startIndex -= self.__nSamples
4393 # self.__startIndex -= self.__nSamples
4388 #
4394 #
4389 # #Finding Tx Pulse
4395 # #Finding Tx Pulse
4390 # if not self.__pulseFound:
4396 # if not self.__pulseFound:
4391 # indexFound = self.__findTxPulse(dataOut, channel)
4397 # indexFound = self.__findTxPulse(dataOut, channel)
4392 #
4398 #
4393 # if indexFound == None:
4399 # if indexFound == None:
4394 # dataOut.flagNoData = True
4400 # dataOut.flagNoData = True
4395 # return
4401 # return
4396 #
4402 #
4397 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
4403 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
4398 # self.__pulseFound = True
4404 # self.__pulseFound = True
4399 # self.__startIndex = indexFound
4405 # self.__startIndex = indexFound
4400 #
4406 #
4401 # #If pulse was found ...
4407 # #If pulse was found ...
4402 # for thisChannel in range(self.__nChannels):
4408 # for thisChannel in range(self.__nChannels):
4403 # bufferByChannel = self.__bufferList[thisChannel]
4409 # bufferByChannel = self.__bufferList[thisChannel]
4404 # #print self.__startIndex
4410 # #print self.__startIndex
4405 # x = numpy.array(bufferByChannel)
4411 # x = numpy.array(bufferByChannel)
4406 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
4412 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
4407 #
4413 #
4408 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4414 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
4409 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
4415 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
4410 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
4416 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
4411 #
4417 #
4412 # dataOut.data = self.__arrayBuffer
4418 # dataOut.data = self.__arrayBuffer
4413 #
4419 #
4414 # self.__startIndex += self.__newNSamples
4420 # self.__startIndex += self.__newNSamples
4415 #
4421 #
4416 # return
4422 # return
4417
4423
4418
4424
4419
4425
4420
4426
4421
4427
4422
4428
4423
4429
4424 ##############################LONG PULSE##############################
4430 ##############################LONG PULSE##############################
4425
4431
4426
4432
4427
4433
4428 class CrossProdHybrid(CrossProdDP):
4434 class CrossProdHybrid(CrossProdDP):
4429 """Operation to calculate cross products of the Hybrid Experiment.
4435 """Operation to calculate cross products of the Hybrid Experiment.
4430
4436
4431 Parameters:
4437 Parameters:
4432 -----------
4438 -----------
4433 NLAG : int
4439 NLAG : int
4434 Number of lags for Long Pulse.
4440 Number of lags for Long Pulse.
4435 NRANGE : int
4441 NRANGE : int
4436 Number of samples (heights) for Long Pulse.
4442 Number of samples (heights) for Long Pulse.
4437 NCAL : int
4443 NCAL : int
4438 .*
4444 .*
4439 DPL : int
4445 DPL : int
4440 Number of lags for Double Pulse.
4446 Number of lags for Double Pulse.
4441 NDN : int
4447 NDN : int
4442 .*
4448 .*
4443 NDT : int
4449 NDT : int
4444 Number of heights for Double Pulse.*
4450 Number of heights for Double Pulse.*
4445 NDP : int
4451 NDP : int
4446 Number of heights for Double Pulse.*
4452 Number of heights for Double Pulse.*
4447 NSCAN : int
4453 NSCAN : int
4448 Number of profiles when the transmitter is on.
4454 Number of profiles when the transmitter is on.
4449 lagind : intlist
4455 lagind : intlist
4450 .*
4456 .*
4451 lagfirst : intlist
4457 lagfirst : intlist
4452 .*
4458 .*
4453 NAVG : int
4459 NAVG : int
4454 Number of blocks to be "averaged".
4460 Number of blocks to be "averaged".
4455 nkill : int
4461 nkill : int
4456 Number of blocks not to be considered when averaging.
4462 Number of blocks not to be considered when averaging.
4457
4463
4458 Example
4464 Example
4459 --------
4465 --------
4460
4466
4461 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4467 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4462 op.addParameter(name='NLAG', value='16', format='int')
4468 op.addParameter(name='NLAG', value='16', format='int')
4463 op.addParameter(name='NRANGE', value='200', format='int')
4469 op.addParameter(name='NRANGE', value='200', format='int')
4464 op.addParameter(name='NCAL', value='0', format='int')
4470 op.addParameter(name='NCAL', value='0', format='int')
4465 op.addParameter(name='DPL', value='11', format='int')
4471 op.addParameter(name='DPL', value='11', format='int')
4466 op.addParameter(name='NDN', value='0', format='int')
4472 op.addParameter(name='NDN', value='0', format='int')
4467 op.addParameter(name='NDT', value='67', format='int')
4473 op.addParameter(name='NDT', value='67', format='int')
4468 op.addParameter(name='NDP', value='67', format='int')
4474 op.addParameter(name='NDP', value='67', format='int')
4469 op.addParameter(name='NSCAN', value='128', format='int')
4475 op.addParameter(name='NSCAN', value='128', format='int')
4470 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4476 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4471 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4477 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4472 op.addParameter(name='NAVG', value='16', format='int')
4478 op.addParameter(name='NAVG', value='16', format='int')
4473 op.addParameter(name='nkill', value='6', format='int')
4479 op.addParameter(name='nkill', value='6', format='int')
4474
4480
4475 """
4481 """
4476
4482
4477 def __init__(self, **kwargs):
4483 def __init__(self, **kwargs):
4478
4484
4479 Operation.__init__(self, **kwargs)
4485 Operation.__init__(self, **kwargs)
4480 self.bcounter=0
4486 self.bcounter=0
4481 self.aux=1
4487 self.aux=1
4482 self.aux_cross_lp=1
4488 self.aux_cross_lp=1
4483 self.lag_products_LP_median_estimates_aux=1
4489 self.lag_products_LP_median_estimates_aux=1
4484
4490
4485 def get_products_cabxys_HP(self,dataOut):
4491 def get_products_cabxys_HP(self,dataOut):
4486
4492
4487 if self.aux==1:
4493 if self.aux==1:
4488 self.set_header_output(dataOut)
4494 self.set_header_output(dataOut)
4489 self.aux=0
4495 self.aux=0
4490
4496
4491 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2
4497 self.cax=numpy.zeros((dataOut.NDP,dataOut.DPL,2))# hp:67x11x2 dp: 66x11x2
4492 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4498 self.cay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4493 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4499 self.cbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4494 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4500 self.cby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4495 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4501 self.cax2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4496 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4502 self.cay2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4497 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4503 self.cbx2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4498 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4504 self.cby2=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4499 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4505 self.caxbx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4500 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4506 self.caxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4501 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4507 self.caybx=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4502 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4508 self.cayby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4503 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4509 self.caxay=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4504 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4510 self.cbxby=numpy.zeros((dataOut.NDP,dataOut.DPL,2))
4505 for i in range(2): # flipped and unflipped
4511 for i in range(2): # flipped and unflipped
4506 for j in range(dataOut.NDP): # loop over true ranges # 67
4512 for j in range(dataOut.NDP): # loop over true ranges # 67
4507 for k in range(int(dataOut.NSCAN)): # 128
4513 for k in range(int(dataOut.NSCAN)): # 128
4508
4514
4509 n=dataOut.lagind[k%dataOut.NLAG] # 128=16x8
4515 n=dataOut.lagind[k%dataOut.NLAG] # 128=16x8
4510
4516
4511 ax=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].real-dataOut.dc.real[0]
4517 ax=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].real-dataOut.dc.real[0]
4512 ay=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].imag-dataOut.dc.imag[0]
4518 ay=dataOut.data[0,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT].imag-dataOut.dc.imag[0]
4513
4519
4514 if dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n<dataOut.read_samples:
4520 if dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n<dataOut.read_samples:
4515
4521
4516 bx=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].real-dataOut.dc.real[1]
4522 bx=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].real-dataOut.dc.real[1]
4517 by=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].imag-dataOut.dc.imag[1]
4523 by=dataOut.data[1,k,dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n].imag-dataOut.dc.imag[1]
4518
4524
4519 else:
4525 else:
4520
4526
4521 if k+1<int(dataOut.NSCAN):
4527 if k+1<int(dataOut.NSCAN):
4522 bx=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4528 bx=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4523 by=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4529 by=dataOut.data[1,k+1,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4524
4530
4525 if k+1==int(dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE
4531 if k+1==int(dataOut.NSCAN):## ESTO ES UN PARCHE PUES NO SE TIENE EL SIGUIENTE BLOQUE
4526 bx=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4532 bx=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].real
4527 by=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4533 by=dataOut.data[1,k,(dataOut.NRANGE+dataOut.NCAL+j+i*dataOut.NDT+2*n)%dataOut.NDP].imag
4528
4534
4529 if(k<dataOut.NLAG and dataOut.lagfirst[k%dataOut.NLAG]==1):# if(k<16 && lagfirst[k%16]==1)
4535 if(k<dataOut.NLAG and dataOut.lagfirst[k%dataOut.NLAG]==1):# if(k<16 && lagfirst[k%16]==1)
4530 self.cax[j][n][i]=ax
4536 self.cax[j][n][i]=ax
4531 self.cay[j][n][i]=ay
4537 self.cay[j][n][i]=ay
4532 self.cbx[j][n][i]=bx
4538 self.cbx[j][n][i]=bx
4533 self.cby[j][n][i]=by
4539 self.cby[j][n][i]=by
4534 self.cax2[j][n][i]=ax*ax
4540 self.cax2[j][n][i]=ax*ax
4535 self.cay2[j][n][i]=ay*ay
4541 self.cay2[j][n][i]=ay*ay
4536 self.cbx2[j][n][i]=bx*bx
4542 self.cbx2[j][n][i]=bx*bx
4537 self.cby2[j][n][i]=by*by
4543 self.cby2[j][n][i]=by*by
4538 self.caxbx[j][n][i]=ax*bx
4544 self.caxbx[j][n][i]=ax*bx
4539 self.caxby[j][n][i]=ax*by
4545 self.caxby[j][n][i]=ax*by
4540 self.caybx[j][n][i]=ay*bx
4546 self.caybx[j][n][i]=ay*bx
4541 self.cayby[j][n][i]=ay*by
4547 self.cayby[j][n][i]=ay*by
4542 self.caxay[j][n][i]=ax*ay
4548 self.caxay[j][n][i]=ax*ay
4543 self.cbxby[j][n][i]=bx*by
4549 self.cbxby[j][n][i]=bx*by
4544 else:
4550 else:
4545 self.cax[j][n][i]+=ax
4551 self.cax[j][n][i]+=ax
4546 self.cay[j][n][i]+=ay
4552 self.cay[j][n][i]+=ay
4547 self.cbx[j][n][i]+=bx
4553 self.cbx[j][n][i]+=bx
4548 self.cby[j][n][i]+=by
4554 self.cby[j][n][i]+=by
4549 self.cax2[j][n][i]+=ax*ax
4555 self.cax2[j][n][i]+=ax*ax
4550 self.cay2[j][n][i]+=ay*ay
4556 self.cay2[j][n][i]+=ay*ay
4551 self.cbx2[j][n][i]+=bx*bx
4557 self.cbx2[j][n][i]+=bx*bx
4552 self.cby2[j][n][i]+=by*by
4558 self.cby2[j][n][i]+=by*by
4553 self.caxbx[j][n][i]+=ax*bx
4559 self.caxbx[j][n][i]+=ax*bx
4554 self.caxby[j][n][i]+=ax*by
4560 self.caxby[j][n][i]+=ax*by
4555 self.caybx[j][n][i]+=ay*bx
4561 self.caybx[j][n][i]+=ay*bx
4556 self.cayby[j][n][i]+=ay*by
4562 self.cayby[j][n][i]+=ay*by
4557 self.caxay[j][n][i]+=ax*ay
4563 self.caxay[j][n][i]+=ax*ay
4558 self.cbxby[j][n][i]+=bx*by
4564 self.cbxby[j][n][i]+=bx*by
4559
4565
4560
4566
4561 #print(self.cax2[2,0,1])
4567 #print(self.cax2[2,0,1])
4562 #input()
4568 #input()
4563
4569
4564
4570
4565 def lag_products_LP(self,dataOut):
4571 def lag_products_LP(self,dataOut):
4566
4572
4567
4573
4568 buffer=dataOut.data
4574 buffer=dataOut.data
4569 if self.aux_cross_lp==1:
4575 if self.aux_cross_lp==1:
4570
4576
4571 #self.dataOut.nptsfft2=150
4577 #self.dataOut.nptsfft2=150
4572 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4578 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4573 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4579 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4574 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4580 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4575 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4581 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4576 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4582 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4577
4583
4578 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4584 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4579 self.aux_cross_lp=0
4585 self.aux_cross_lp=0
4580
4586
4581 #print(self.dataOut.data[0,0,0])
4587 #print(self.dataOut.data[0,0,0])
4582
4588
4583 for i in range(dataOut.NR):
4589 for i in range(dataOut.NR):
4584 #print("inside i",i)
4590 #print("inside i",i)
4585 buffer_dc=dataOut.dc[i]
4591 buffer_dc=dataOut.dc[i]
4586 for j in range(dataOut.NRANGE):
4592 for j in range(dataOut.NRANGE):
4587
4593
4588 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4594 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4589
4595
4590 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4596 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4591 for n in range(range_for_n):
4597 for n in range(range_for_n):
4592
4598
4593 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4599 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4594
4600
4595 if i==0:
4601 if i==0:
4596 self.lagp0[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4602 self.lagp0[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4597 self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4603 self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4598 elif i==1:
4604 elif i==1:
4599 self.lagp1[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4605 self.lagp1[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4600 elif i==2:
4606 elif i==2:
4601 self.lagp2[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4607 self.lagp2[n][j][self.bcounter-1]=numpy.sum(c[:dataOut.NSCAN])
4602
4608
4603
4609
4604 self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1])
4610 self.lagp0[:,:,self.bcounter-1]=numpy.conj(self.lagp0[:,:,self.bcounter-1])
4605 self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1])
4611 self.lagp1[:,:,self.bcounter-1]=numpy.conj(self.lagp1[:,:,self.bcounter-1])
4606 self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1])
4612 self.lagp2[:,:,self.bcounter-1]=numpy.conj(self.lagp2[:,:,self.bcounter-1])
4607 self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1])
4613 self.lagp3[:,:,self.bcounter-1]=numpy.conj(self.lagp3[:,:,self.bcounter-1])
4608
4614
4609
4615
4610 def LP_median_estimates(self,dataOut):
4616 def LP_median_estimates(self,dataOut):
4611
4617
4612 if self.bcounter==dataOut.NAVG:
4618 if self.bcounter==dataOut.NAVG:
4613
4619
4614 if self.lag_products_LP_median_estimates_aux==1:
4620 if self.lag_products_LP_median_estimates_aux==1:
4615 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4621 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4616 self.lag_products_LP_median_estimates_aux=0
4622 self.lag_products_LP_median_estimates_aux=0
4617
4623
4618
4624
4619 for i in range(dataOut.NLAG):
4625 for i in range(dataOut.NLAG):
4620 for j in range(dataOut.NRANGE):
4626 for j in range(dataOut.NRANGE):
4621 for l in range(4): #four outputs
4627 for l in range(4): #four outputs
4622
4628
4623 for k in range(dataOut.NAVG):
4629 for k in range(dataOut.NAVG):
4624
4630
4625
4631
4626 if k==0:
4632 if k==0:
4627 self.output[i,j,l]=0.0+0.j
4633 self.output[i,j,l]=0.0+0.j
4628
4634
4629 if l==0:
4635 if l==0:
4630 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4636 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4631
4637
4632 if l==1:
4638 if l==1:
4633 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4639 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4634
4640
4635 if l==2:
4641 if l==2:
4636 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4642 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4637
4643
4638 if l==3:
4644 if l==3:
4639 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4645 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4640
4646
4641
4647
4642
4648
4643 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4649 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4644 if l==0:
4650 if l==0:
4645
4651
4646 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4652 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4647 if l==1:
4653 if l==1:
4648 #print("lagp1: ",self.lagp1[0,0,:])
4654 #print("lagp1: ",self.lagp1[0,0,:])
4649 #input()
4655 #input()
4650 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4656 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4651 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4657 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4652 #input()
4658 #input()
4653 if l==2:
4659 if l==2:
4654 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4660 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4655 if l==3:
4661 if l==3:
4656
4662
4657 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4663 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4658
4664
4659
4665
4660 dataOut.output_LP=self.output
4666 dataOut.output_LP=self.output
4661 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4667 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4662 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4668 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4663
4669
4664
4670
4665 def get_dc(self,dataOut):
4671 def get_dc(self,dataOut):
4666
4672
4667 if self.bcounter==0:
4673 if self.bcounter==0:
4668 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4674 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4669
4675
4670 #print(numpy.shape(dataOut.data))
4676 #print(numpy.shape(dataOut.data))
4671 #input()
4677 #input()
4672
4678
4673 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4679 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4674
4680
4675 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4681 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4676
4682
4677
4683
4678 #print("dc:",dataOut.dc[0])
4684 #print("dc:",dataOut.dc[0])
4679
4685
4680 def get_dc_new(self,dataOut):
4686 def get_dc_new(self,dataOut):
4681
4687
4682 if self.bcounter==0:
4688 if self.bcounter==0:
4683 dataOut.dc_dp=numpy.zeros(dataOut.NR,dtype='complex64')
4689 dataOut.dc_dp=numpy.zeros(dataOut.NR,dtype='complex64')
4684 dataOut.dc_lp=numpy.zeros(dataOut.NR,dtype='complex64')
4690 dataOut.dc_lp=numpy.zeros(dataOut.NR,dtype='complex64')
4685
4691
4686 #print(numpy.shape(dataOut.data))
4692 #print(numpy.shape(dataOut.data))
4687 #input()
4693 #input()
4688
4694
4689 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4695 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4690
4696
4691 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4697 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4692
4698
4693
4699
4694 #print("dc:",dataOut.dc[0])
4700 #print("dc:",dataOut.dc[0])
4695
4701
4696
4702
4697 def noise_estimation4x_HP(self,dataOut):
4703 def noise_estimation4x_HP(self,dataOut):
4698 if self.bcounter==dataOut.NAVG:
4704 if self.bcounter==dataOut.NAVG:
4699 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4705 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4700 #snoise=numpy.zeros((NR,NAVG),'float32')
4706 #snoise=numpy.zeros((NR,NAVG),'float32')
4701 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4707 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4702 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4708 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4703 for i in range(dataOut.NR):
4709 for i in range(dataOut.NR):
4704 dataOut.noise_final[i]=0.0
4710 dataOut.noise_final[i]=0.0
4705 for j in range(dataOut.MAXNRANGENDT):
4711 for j in range(dataOut.MAXNRANGENDT):
4706 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
4712 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
4707 #print(sorted(noisevector[j,i,:]))
4713 #print(sorted(noisevector[j,i,:]))
4708 #input()
4714 #input()
4709 l=dataOut.MAXNRANGENDT-2
4715 l=dataOut.MAXNRANGENDT-2
4710 for k in range(dataOut.NAVG):
4716 for k in range(dataOut.NAVG):
4711 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4717 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4712 #print(k)
4718 #print(k)
4713 #print(sorted_data[min(j,l),i,k])
4719 #print(sorted_data[min(j,l),i,k])
4714 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
4720 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
4715 #print(dataOut.noise_final[i])
4721 #print(dataOut.noise_final[i])
4716 #input()
4722 #input()
4717 #print(dataOut.noise_final)
4723 #print(dataOut.noise_final)
4718 #input()
4724 #input()
4719
4725
4720 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
4726 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
4721
4727
4722 #rnormalizer= 1./(float(nProfiles - NSCAN))
4728 #rnormalizer= 1./(float(nProfiles - NSCAN))
4723 rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
4729 rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
4724 for i in range(NR):
4730 for i in range(NR):
4725 for j in range(MAXNRANGENDT):
4731 for j in range(MAXNRANGENDT):
4726 for k in range(NSCAN,nProfiles):
4732 for k in range(NSCAN,nProfiles):
4727 #TODO:integrate just 2nd quartile gates
4733 #TODO:integrate just 2nd quartile gates
4728 if k==NSCAN:
4734 if k==NSCAN:
4729 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4735 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4730 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
4736 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
4731 else:
4737 else:
4732 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4738 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
4733
4739
4734
4740
4735 def RTI_LP(self,output,NRANGE):
4741 def RTI_LP(self,output,NRANGE):
4736 x00=numpy.zeros(NRANGE,dtype='float32')
4742 x00=numpy.zeros(NRANGE,dtype='float32')
4737 x01=numpy.zeros(NRANGE,dtype='float32')
4743 x01=numpy.zeros(NRANGE,dtype='float32')
4738 x02=numpy.zeros(NRANGE,dtype='float32')
4744 x02=numpy.zeros(NRANGE,dtype='float32')
4739 x03=numpy.zeros(NRANGE,dtype='float32')
4745 x03=numpy.zeros(NRANGE,dtype='float32')
4740
4746
4741 for i in range(2): #first couple of lags
4747 for i in range(2): #first couple of lags
4742 for j in range(NRANGE): #
4748 for j in range(NRANGE): #
4743 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
4749 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
4744 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
4750 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
4745 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
4751 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
4746 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
4752 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
4747 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
4753 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
4748 #x02[i]=x02[i]+fx
4754 #x02[i]=x02[i]+fx
4749
4755
4750 x00[j]=10.0*numpy.log10(x00[j]/4.)
4756 x00[j]=10.0*numpy.log10(x00[j]/4.)
4751 x01[j]=10.0*numpy.log10(x01[j]/4.)
4757 x01[j]=10.0*numpy.log10(x01[j]/4.)
4752 x02[j]=10.0*numpy.log10(x02[j]/4.)
4758 x02[j]=10.0*numpy.log10(x02[j]/4.)
4753 x03[j]=10.0*numpy.log10(x03[j]/4.)
4759 x03[j]=10.0*numpy.log10(x03[j]/4.)
4754 #x02[i]=10.0*numpy.log10(x02[i])
4760 #x02[i]=10.0*numpy.log10(x02[i])
4755 return x00,x01,x02,x03
4761 return x00,x01,x02,x03
4756
4762
4757 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
4763 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
4758 NDN=None, NDT=None, NDP=None, NSCAN=None,
4764 NDN=None, NDT=None, NDP=None, NSCAN=None,
4759 lagind=None, lagfirst=None,
4765 lagind=None, lagfirst=None,
4760 NAVG=None, nkill=None):
4766 NAVG=None, nkill=None):
4761
4767
4762 dataOut.NLAG=NLAG
4768 dataOut.NLAG=NLAG
4763 dataOut.NR=len(dataOut.channelList)
4769 dataOut.NR=len(dataOut.channelList)
4764 dataOut.NRANGE=NRANGE
4770 dataOut.NRANGE=NRANGE
4765 dataOut.NCAL=NCAL
4771 dataOut.NCAL=NCAL
4766 dataOut.DPL=DPL
4772 dataOut.DPL=DPL
4767 dataOut.NDN=NDN
4773 dataOut.NDN=NDN
4768 dataOut.NDT=NDT
4774 dataOut.NDT=NDT
4769 dataOut.NDP=NDP
4775 dataOut.NDP=NDP
4770 dataOut.NSCAN=NSCAN
4776 dataOut.NSCAN=NSCAN
4771 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
4777 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
4772 dataOut.H0=int(dataOut.heightList[0])
4778 dataOut.H0=int(dataOut.heightList[0])
4773 dataOut.lagind=lagind
4779 dataOut.lagind=lagind
4774 dataOut.lagfirst=lagfirst
4780 dataOut.lagfirst=lagfirst
4775 dataOut.NAVG=NAVG
4781 dataOut.NAVG=NAVG
4776 dataOut.nkill=nkill
4782 dataOut.nkill=nkill
4777
4783
4778 dataOut.flagNoData = True
4784 dataOut.flagNoData = True
4779
4785
4780 self.get_dc(dataOut)
4786 self.get_dc(dataOut)
4781 self.get_products_cabxys_HP(dataOut)
4787 self.get_products_cabxys_HP(dataOut)
4782 self.cabxys_navg(dataOut)
4788 self.cabxys_navg(dataOut)
4783 self.lag_products_LP(dataOut)
4789 self.lag_products_LP(dataOut)
4784 self.LP_median_estimates(dataOut)
4790 self.LP_median_estimates(dataOut)
4785 self.noise_estimation4x_HP(dataOut)
4791 self.noise_estimation4x_HP(dataOut)
4786 self.kabxys(dataOut)
4792 self.kabxys(dataOut)
4787
4793
4788 return dataOut
4794 return dataOut
4789
4795
4790
4796
4791 class CrossProdLP(CrossProdDP):
4797 class CrossProdLP(CrossProdDP):
4792 """Operation to calculate cross products of the Hybrid Experiment.
4798 """Operation to calculate cross products of the Hybrid Experiment.
4793
4799
4794 Parameters:
4800 Parameters:
4795 -----------
4801 -----------
4796 NLAG : int
4802 NLAG : int
4797 Number of lags for Long Pulse.
4803 Number of lags for Long Pulse.
4798 NRANGE : int
4804 NRANGE : int
4799 Number of samples (heights) for Long Pulse.
4805 Number of samples (heights) for Long Pulse.
4800 NCAL : int
4806 NCAL : int
4801 .*
4807 .*
4802 DPL : int
4808 DPL : int
4803 Number of lags for Double Pulse.
4809 Number of lags for Double Pulse.
4804 NDN : int
4810 NDN : int
4805 .*
4811 .*
4806 NDT : int
4812 NDT : int
4807 Number of heights for Double Pulse.*
4813 Number of heights for Double Pulse.*
4808 NDP : int
4814 NDP : int
4809 Number of heights for Double Pulse.*
4815 Number of heights for Double Pulse.*
4810 NSCAN : int
4816 NSCAN : int
4811 Number of profiles when the transmitter is on.
4817 Number of profiles when the transmitter is on.
4812 lagind : intlist
4818 lagind : intlist
4813 .*
4819 .*
4814 lagfirst : intlist
4820 lagfirst : intlist
4815 .*
4821 .*
4816 NAVG : int
4822 NAVG : int
4817 Number of blocks to be "averaged".
4823 Number of blocks to be "averaged".
4818 nkill : int
4824 nkill : int
4819 Number of blocks not to be considered when averaging.
4825 Number of blocks not to be considered when averaging.
4820
4826
4821 Example
4827 Example
4822 --------
4828 --------
4823
4829
4824 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4830 op = proc_unit.addOperation(name='CrossProdHybrid', optype='other')
4825 op.addParameter(name='NLAG', value='16', format='int')
4831 op.addParameter(name='NLAG', value='16', format='int')
4826 op.addParameter(name='NRANGE', value='200', format='int')
4832 op.addParameter(name='NRANGE', value='200', format='int')
4827 op.addParameter(name='NCAL', value='0', format='int')
4833 op.addParameter(name='NCAL', value='0', format='int')
4828 op.addParameter(name='DPL', value='11', format='int')
4834 op.addParameter(name='DPL', value='11', format='int')
4829 op.addParameter(name='NDN', value='0', format='int')
4835 op.addParameter(name='NDN', value='0', format='int')
4830 op.addParameter(name='NDT', value='67', format='int')
4836 op.addParameter(name='NDT', value='67', format='int')
4831 op.addParameter(name='NDP', value='67', format='int')
4837 op.addParameter(name='NDP', value='67', format='int')
4832 op.addParameter(name='NSCAN', value='128', format='int')
4838 op.addParameter(name='NSCAN', value='128', format='int')
4833 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4839 op.addParameter(name='lagind', value='(0,1,2,3,4,5,6,7,0,3,4,5,6,8,9,10)', format='intlist')
4834 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4840 op.addParameter(name='lagfirst', value='(1,1,1,1,1,1,1,1,0,0,0,0,0,1,1,1)', format='intlist')
4835 op.addParameter(name='NAVG', value='16', format='int')
4841 op.addParameter(name='NAVG', value='16', format='int')
4836 op.addParameter(name='nkill', value='6', format='int')
4842 op.addParameter(name='nkill', value='6', format='int')
4837
4843
4838 """
4844 """
4839
4845
4840 def __init__(self, **kwargs):
4846 def __init__(self, **kwargs):
4841
4847
4842 Operation.__init__(self, **kwargs)
4848 Operation.__init__(self, **kwargs)
4843 self.bcounter=0
4849 self.bcounter=0
4844 self.aux=1
4850 self.aux=1
4845 self.aux_cross_lp=1
4851 self.aux_cross_lp=1
4846 self.lag_products_LP_median_estimates_aux=1
4852 self.lag_products_LP_median_estimates_aux=1
4847
4853
4848
4854
4849
4855
4850 #print(self.cax2[2,0,1])
4856 #print(self.cax2[2,0,1])
4851 #input()
4857 #input()
4852
4858
4853
4859
4854 def lag_products_LP(self,dataOut):
4860 def lag_products_LP(self,dataOut):
4855
4861
4856
4862
4857 buffer=dataOut.data
4863 buffer=dataOut.data
4858 if self.aux_cross_lp==1:
4864 if self.aux_cross_lp==1:
4859
4865
4860 #self.dataOut.nptsfft2=150
4866 #self.dataOut.nptsfft2=150
4861 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4867 self.cnorm=float((dataOut.nProfiles-dataOut.NSCAN)/dataOut.NSCAN)
4862 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4868 self.lagp0=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4863 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4869 self.lagp1=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4864 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4870 self.lagp2=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4865 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4871 self.lagp3=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4866 self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4872 self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4867 self.lagp5=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4873 self.lagp5=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4868
4874
4869 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4875 #self.lagp4=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NAVG),'complex64')
4870 self.aux_cross_lp=0
4876 self.aux_cross_lp=0
4871
4877
4872 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4878 dataOut.noisevector=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4873
4879
4874 #print(self.dataOut.data[0,0,0])
4880 #print(self.dataOut.data[0,0,0])
4875 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
4881 self.noisevectorizer(dataOut.NSCAN,dataOut.nProfiles,dataOut.NR,dataOut.MAXNRANGENDT,dataOut.noisevector,dataOut.data,dataOut.dc) #30/03/2020
4876
4882
4877
4883
4878 for i in range(dataOut.NR):
4884 for i in range(dataOut.NR):
4879 #print("inside i",i)
4885 #print("inside i",i)
4880 buffer_dc=dataOut.dc[i]
4886 buffer_dc=dataOut.dc[i]
4881 for j in range(dataOut.NRANGE):
4887 for j in range(dataOut.NRANGE):
4882
4888
4883 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4889 range_for_n=numpy.min((dataOut.NRANGE-j,dataOut.NLAG))
4884
4890
4885 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4891 buffer_aux=numpy.conj(buffer[i,:dataOut.nProfiles,j]-buffer_dc)
4886 for n in range(range_for_n):
4892 for n in range(range_for_n):
4887
4893
4888 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4894 c=(buffer_aux)*(buffer[i,:dataOut.nProfiles,j+n]-buffer_dc)
4889
4895
4890 if i==0:
4896 if i==0:
4891 self.lagp0[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4897 self.lagp0[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4892 #self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4898 #self.lagp3[n][j][self.bcounter-1]=numpy.sum(c[dataOut.NSCAN:]/self.cnorm)
4893 elif i==1:
4899 elif i==1:
4894 self.lagp1[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4900 self.lagp1[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4895 elif i==2:
4901 elif i==2:
4896 self.lagp2[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4902 self.lagp2[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4897 elif i==3:
4903 elif i==3:
4898 self.lagp3[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4904 self.lagp3[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4899 elif i==4:
4905 elif i==4:
4900 self.lagp4[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4906 self.lagp4[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4901 elif i==5:
4907 elif i==5:
4902 self.lagp5[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4908 self.lagp5[n][j][self.bcounter]=numpy.sum(c[:dataOut.NSCAN])
4903
4909
4904
4910
4905 self.lagp0[:,:,self.bcounter]=numpy.conj(self.lagp0[:,:,self.bcounter])
4911 self.lagp0[:,:,self.bcounter]=numpy.conj(self.lagp0[:,:,self.bcounter])
4906 self.lagp1[:,:,self.bcounter]=numpy.conj(self.lagp1[:,:,self.bcounter])
4912 self.lagp1[:,:,self.bcounter]=numpy.conj(self.lagp1[:,:,self.bcounter])
4907 self.lagp2[:,:,self.bcounter]=numpy.conj(self.lagp2[:,:,self.bcounter])
4913 self.lagp2[:,:,self.bcounter]=numpy.conj(self.lagp2[:,:,self.bcounter])
4908 self.lagp3[:,:,self.bcounter]=numpy.conj(self.lagp3[:,:,self.bcounter])
4914 self.lagp3[:,:,self.bcounter]=numpy.conj(self.lagp3[:,:,self.bcounter])
4909
4915
4910 self.bcounter += 1
4916 self.bcounter += 1
4911
4917
4912
4918
4913 def LP_median_estimates(self,dataOut):
4919 def LP_median_estimates(self,dataOut):
4914
4920
4915 if self.bcounter==dataOut.NAVG:
4921 if self.bcounter==dataOut.NAVG:
4916 dataOut.flagNoData = False
4922 dataOut.flagNoData = False
4917
4923
4918 if self.lag_products_LP_median_estimates_aux==1:
4924 if self.lag_products_LP_median_estimates_aux==1:
4919 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4925 self.output=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),'complex64')
4920 self.lag_products_LP_median_estimates_aux=0
4926 self.lag_products_LP_median_estimates_aux=0
4921
4927
4922
4928
4923 for i in range(dataOut.NLAG):
4929 for i in range(dataOut.NLAG):
4924 for j in range(dataOut.NRANGE):
4930 for j in range(dataOut.NRANGE):
4925 for l in range(4): #four outputs
4931 for l in range(4): #four outputs
4926
4932
4927 for k in range(dataOut.NAVG):
4933 for k in range(dataOut.NAVG):
4928
4934
4929
4935
4930 if k==0:
4936 if k==0:
4931 self.output[i,j,l]=0.0+0.j
4937 self.output[i,j,l]=0.0+0.j
4932
4938
4933 if l==0:
4939 if l==0:
4934 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4940 self.lagp0[i,j,:]=sorted(self.lagp0[i,j,:], key=lambda x: x.real) #sorted(self.lagp0[i,j,:].real)
4935
4941
4936 if l==1:
4942 if l==1:
4937 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4943 self.lagp1[i,j,:]=sorted(self.lagp1[i,j,:], key=lambda x: x.real) #sorted(self.lagp1[i,j,:].real)
4938
4944
4939 if l==2:
4945 if l==2:
4940 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4946 self.lagp2[i,j,:]=sorted(self.lagp2[i,j,:], key=lambda x: x.real) #sorted(self.lagp2[i,j,:].real)
4941
4947
4942 if l==3:
4948 if l==3:
4943 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4949 self.lagp3[i,j,:]=sorted(self.lagp3[i,j,:], key=lambda x: x.real) #sorted(self.lagp3[i,j,:].real)
4944
4950
4945
4951
4946
4952
4947 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4953 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
4948 if l==0:
4954 if l==0:
4949
4955
4950 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4956 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp0[i,j,k])
4951 if l==1:
4957 if l==1:
4952 #print("lagp1: ",self.lagp1[0,0,:])
4958 #print("lagp1: ",self.lagp1[0,0,:])
4953 #input()
4959 #input()
4954 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4960 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp1[i,j,k])
4955 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4961 #print("self.lagp1[i,j,k]: ",self.lagp1[i,j,k])
4956 #input()
4962 #input()
4957 if l==2:
4963 if l==2:
4958 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4964 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp2[i,j,k])
4959 if l==3:
4965 if l==3:
4960
4966
4961 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4967 self.output[i,j,l]=self.output[i,j,l]+((float(dataOut.NAVG)/(float)(dataOut.NAVG-dataOut.nkill))*self.lagp3[i,j,k])
4962
4968
4963
4969
4964 dataOut.output_LP=self.output
4970 dataOut.output_LP=self.output
4965 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4971 dataOut.data_for_RTI_LP=numpy.zeros((4,dataOut.NRANGE))
4966 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4972 dataOut.data_for_RTI_LP[0],dataOut.data_for_RTI_LP[1],dataOut.data_for_RTI_LP[2],dataOut.data_for_RTI_LP[3]=self.RTI_LP(dataOut.output_LP,dataOut.NRANGE)
4967
4973
4968 self.bcounter = 0
4974 self.bcounter = 0
4969
4975
4970 def get_dc(self,dataOut):
4976 def get_dc(self,dataOut):
4971
4977
4972 if self.bcounter==0:
4978 if self.bcounter==0:
4973 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4979 dataOut.dc=numpy.zeros(dataOut.NR,dtype='complex64')
4974
4980
4975 #print(numpy.shape(dataOut.data))
4981 #print(numpy.shape(dataOut.data))
4976 #input()
4982 #input()
4977
4983
4978 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4984 dataOut.dc+=numpy.sum(dataOut.data[:,:,2*dataOut.NLAG:dataOut.NRANGE],axis=(1,2))
4979
4985
4980 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4986 dataOut.dc=dataOut.dc/float(dataOut.nProfiles*(dataOut.NRANGE-2*dataOut.NLAG))
4981
4987
4982
4988
4983 #print("dc:",dataOut.dc[0])
4989 #print("dc:",dataOut.dc[0])
4984
4990
4985
4991
4986
4992
4987
4993
4988 def noise_estimation4x_HP(self,dataOut):
4994 def noise_estimation4x_HP(self,dataOut):
4989 if self.bcounter==dataOut.NAVG:
4995 if self.bcounter==dataOut.NAVG:
4990 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4996 dataOut.noise_final=numpy.zeros(dataOut.NR,'float32')
4991 #snoise=numpy.zeros((NR,NAVG),'float32')
4997 #snoise=numpy.zeros((NR,NAVG),'float32')
4992 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4998 #nvector1=numpy.zeros((NR,NAVG,MAXNRANGENDT),'float32')
4993 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4999 sorted_data=numpy.zeros((dataOut.MAXNRANGENDT,dataOut.NR,dataOut.NAVG),'float32')
4994 for i in range(dataOut.NR):
5000 for i in range(dataOut.NR):
4995 dataOut.noise_final[i]=0.0
5001 dataOut.noise_final[i]=0.0
4996 for j in range(dataOut.MAXNRANGENDT):
5002 for j in range(dataOut.MAXNRANGENDT):
4997 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
5003 sorted_data[j,i,:]=numpy.copy(sorted(dataOut.noisevector[j,i,:]))
4998 #print(sorted(noisevector[j,i,:]))
5004 #print(sorted(noisevector[j,i,:]))
4999 #input()
5005 #input()
5000 l=dataOut.MAXNRANGENDT-2
5006 l=dataOut.MAXNRANGENDT-2
5001 for k in range(dataOut.NAVG):
5007 for k in range(dataOut.NAVG):
5002 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
5008 if k>=dataOut.nkill/2 and k<dataOut.NAVG-dataOut.nkill/2:
5003 #print(k)
5009 #print(k)
5004 #print(sorted_data[min(j,l),i,k])
5010 #print(sorted_data[min(j,l),i,k])
5005 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
5011 dataOut.noise_final[i]+=sorted_data[min(j,l),i,k]*float(dataOut.NAVG)/float(dataOut.NAVG-dataOut.nkill)
5006 #print(dataOut.noise_final[i])
5012 #print(dataOut.noise_final[i])
5007 #input()
5013 #input()
5008 #print(dataOut.noise_final)
5014 #print(dataOut.noise_final)
5009 #input()
5015 #input()
5010
5016
5011 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
5017 def noisevectorizer(self,NSCAN,nProfiles,NR,MAXNRANGENDT,noisevector,data,dc):
5012
5018
5013 #rnormalizer= 1./(float(nProfiles - NSCAN))
5019 #rnormalizer= 1./(float(nProfiles - NSCAN))
5014 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
5020 #rnormalizer= float(NSCAN)/((float(nProfiles - NSCAN))*float(MAXNRANGENDT))
5015 rnormalizer= float(NSCAN)/((float(1))*float(MAXNRANGENDT))
5021 rnormalizer= float(NSCAN)/((float(1))*float(MAXNRANGENDT))
5016 for i in range(NR):
5022 for i in range(NR):
5017 for j in range(MAXNRANGENDT):
5023 for j in range(MAXNRANGENDT):
5018 for k in range(NSCAN,nProfiles):
5024 for k in range(NSCAN,nProfiles):
5019 #TODO:integrate just 2nd quartile gates
5025 #TODO:integrate just 2nd quartile gates
5020 if k==NSCAN:
5026 if k==NSCAN:
5021 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5027 noisevector[j][i][self.bcounter]=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5022 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
5028 ##noisevector[j][i][iavg]=(abs(cdata[k][j][i])**2)*rnormalizer
5023 else:
5029 else:
5024 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5030 noisevector[j][i][self.bcounter]+=(abs(data[i][k][j]-dc[i])**2)*rnormalizer
5025
5031
5026
5032
5027 def RTI_LP(self,output,NRANGE):
5033 def RTI_LP(self,output,NRANGE):
5028 x00=numpy.zeros(NRANGE,dtype='float32')
5034 x00=numpy.zeros(NRANGE,dtype='float32')
5029 x01=numpy.zeros(NRANGE,dtype='float32')
5035 x01=numpy.zeros(NRANGE,dtype='float32')
5030 x02=numpy.zeros(NRANGE,dtype='float32')
5036 x02=numpy.zeros(NRANGE,dtype='float32')
5031 x03=numpy.zeros(NRANGE,dtype='float32')
5037 x03=numpy.zeros(NRANGE,dtype='float32')
5032
5038
5033 for i in range(1): #first couple of lags
5039 for i in range(1): #first couple of lags
5034 for j in range(NRANGE): #
5040 for j in range(NRANGE): #
5035 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
5041 #fx=numpy.sqrt((kaxbx[i,j,k]+kayby[i,j,k])**2+(kaybx[i,j,k]-kaxby[i,j,k])**2)
5036 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
5042 x00[j]+=numpy.abs(output[i,j,0]) #Ch0
5037 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
5043 x01[j]+=numpy.abs(output[i,j,1]) #Ch1
5038 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
5044 x02[j]+=numpy.abs(output[i,j,2]) #Ch2
5039 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
5045 x03[j]+=numpy.abs(output[i,j,3]) #Ch3
5040 #x02[i]=x02[i]+fx
5046 #x02[i]=x02[i]+fx
5041
5047
5042 x00[j]=10.0*numpy.log10(x00[j]/4.)
5048 x00[j]=10.0*numpy.log10(x00[j]/4.)
5043 x01[j]=10.0*numpy.log10(x01[j]/4.)
5049 x01[j]=10.0*numpy.log10(x01[j]/4.)
5044 x02[j]=10.0*numpy.log10(x02[j]/4.)
5050 x02[j]=10.0*numpy.log10(x02[j]/4.)
5045 x03[j]=10.0*numpy.log10(x03[j]/4.)
5051 x03[j]=10.0*numpy.log10(x03[j]/4.)
5046 #x02[i]=10.0*numpy.log10(x02[i])
5052 #x02[i]=10.0*numpy.log10(x02[i])
5047 return x00,x01,x02,x03
5053 return x00,x01,x02,x03
5048
5054
5049 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
5055 def run(self, dataOut, NLAG=None, NRANGE=None, NCAL=None, DPL=None,
5050 NDN=None, NDT=None, NDP=None, NSCAN=None,
5056 NDN=None, NDT=None, NDP=None, NSCAN=None,
5051 lagind=None, lagfirst=None,
5057 lagind=None, lagfirst=None,
5052 NAVG=None, nkill=None):
5058 NAVG=None, nkill=None):
5053
5059
5054 dataOut.NLAG=NLAG
5060 dataOut.NLAG=NLAG
5055 dataOut.NR=len(dataOut.channelList)
5061 dataOut.NR=len(dataOut.channelList)
5056 #dataOut.NRANGE=NRANGE
5062 #dataOut.NRANGE=NRANGE
5057 dataOut.NRANGE=dataOut.nHeights
5063 dataOut.NRANGE=dataOut.nHeights
5058 dataOut.NCAL=NCAL
5064 dataOut.NCAL=NCAL
5059 dataOut.DPL=DPL
5065 dataOut.DPL=DPL
5060 dataOut.NDN=NDN
5066 dataOut.NDN=NDN
5061 dataOut.NDT=NDT
5067 dataOut.NDT=NDT
5062 dataOut.NDP=NDP
5068 dataOut.NDP=NDP
5063 dataOut.NSCAN=NSCAN
5069 dataOut.NSCAN=NSCAN
5064 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
5070 dataOut.DH=dataOut.heightList[1]-dataOut.heightList[0]
5065 dataOut.H0=int(dataOut.heightList[0])
5071 dataOut.H0=int(dataOut.heightList[0])
5066 dataOut.lagind=lagind
5072 dataOut.lagind=lagind
5067 dataOut.lagfirst=lagfirst
5073 dataOut.lagfirst=lagfirst
5068 dataOut.NAVG=NAVG
5074 dataOut.NAVG=NAVG
5069 dataOut.nkill=nkill
5075 dataOut.nkill=nkill
5070
5076
5071 dataOut.MAXNRANGENDT = dataOut.NRANGE
5077 dataOut.MAXNRANGENDT = dataOut.NRANGE
5072
5078
5073 dataOut.flagNoData = True
5079 dataOut.flagNoData = True
5074
5080
5075 print(self.bcounter)
5081 print(self.bcounter)
5076
5082
5077 self.get_dc(dataOut)
5083 self.get_dc(dataOut)
5078 self.lag_products_LP(dataOut)
5084 self.lag_products_LP(dataOut)
5079 self.noise_estimation4x_HP(dataOut)
5085 self.noise_estimation4x_HP(dataOut)
5080 self.LP_median_estimates(dataOut)
5086 self.LP_median_estimates(dataOut)
5081
5087
5082 print("******************DONE******************")
5088 print("******************DONE******************")
5083
5089
5084
5090
5085
5091
5086 return dataOut
5092 return dataOut
5087
5093
5088
5094
5089 class RemoveDebris(Operation):
5095 class RemoveDebris(Operation):
5090 """Operation to remove blocks where an outlier is found for Double (Long) Pulse.
5096 """Operation to remove blocks where an outlier is found for Double (Long) Pulse.
5091
5097
5092 Parameters:
5098 Parameters:
5093 -----------
5099 -----------
5094 None
5100 None
5095
5101
5096 Example
5102 Example
5097 --------
5103 --------
5098
5104
5099 op = proc_unit.addOperation(name='RemoveDebris', optype='other')
5105 op = proc_unit.addOperation(name='RemoveDebris', optype='other')
5100
5106
5101 """
5107 """
5102
5108
5103 def __init__(self, **kwargs):
5109 def __init__(self, **kwargs):
5104
5110
5105 Operation.__init__(self, **kwargs)
5111 Operation.__init__(self, **kwargs)
5106
5112
5107 def run(self,dataOut):
5113 def run(self,dataOut):
5108 print("init_debris",dataOut.flagNoData)
5114 print("init_debris",dataOut.flagNoData)
5109 #dataOut.debris_activated=0
5115 #dataOut.debris_activated=0
5110 debris=numpy.zeros(dataOut.NRANGE,'float32')
5116 debris=numpy.zeros(dataOut.NRANGE,'float32')
5111
5117
5112 for j in range(0,3):
5118 for j in range(0,3):
5113 for i in range(dataOut.NRANGE):
5119 for i in range(dataOut.NRANGE):
5114 if j==0:
5120 if j==0:
5115 debris[i]=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5121 debris[i]=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5116 else:
5122 else:
5117 debris[i]+=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5123 debris[i]+=10*numpy.log10(numpy.abs(dataOut.output_LP[j,i,0]))
5118
5124
5119 thresh=8.0+4+4+4
5125 thresh=8.0+4+4+4
5120 for i in range(47,100):
5126 for i in range(47,100):
5121 if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])>
5127 if ((debris[i-2]+debris[i-1]+debris[i]+debris[i+1])>
5122 ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+
5128 ((debris[i-12]+debris[i-11]+debris[i-10]+debris[i-9]+
5123 debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+
5129 debris[i+12]+debris[i+11]+debris[i+10]+debris[i+9])/2.0+
5124 thresh)):
5130 thresh)):
5125
5131
5126 dataOut.flagNoData=True
5132 dataOut.flagNoData=True
5127 print("LP Debris detected at",i*15,"km")
5133 print("LP Debris detected at",i*15,"km")
5128
5134
5129 debris=numpy.zeros(dataOut.NDP,dtype='float32')
5135 debris=numpy.zeros(dataOut.NDP,dtype='float32')
5130 Range=numpy.arange(0,3000,15)
5136 Range=numpy.arange(0,3000,15)
5131 for k in range(2): #flip
5137 for k in range(2): #flip
5132 for i in range(dataOut.NDP): #
5138 for i in range(dataOut.NDP): #
5133 debris[i]+=numpy.sqrt((dataOut.kaxbx[i,0,k]+dataOut.kayby[i,0,k])**2+(dataOut.kaybx[i,0,k]-dataOut.kaxby[i,0,k])**2)
5139 debris[i]+=numpy.sqrt((dataOut.kaxbx[i,0,k]+dataOut.kayby[i,0,k])**2+(dataOut.kaybx[i,0,k]-dataOut.kaxby[i,0,k])**2)
5134
5140
5135 if gmtime(dataOut.utctime).tm_hour > 11:
5141 if gmtime(dataOut.utctime).tm_hour > 11:
5136 for i in range(2,dataOut.NDP-2):
5142 for i in range(2,dataOut.NDP-2):
5137 if (debris[i]>3.0*debris[i-2] and
5143 if (debris[i]>3.0*debris[i-2] and
5138 debris[i]>3.0*debris[i+2] and
5144 debris[i]>3.0*debris[i+2] and
5139 Range[i]>200.0 and Range[i]<=540.0):
5145 Range[i]>200.0 and Range[i]<=540.0):
5140 dataOut.flagNoData=True
5146 dataOut.flagNoData=True
5141 print("DP Debris detected at",i*15,"km")
5147 print("DP Debris detected at",i*15,"km")
5142
5148
5143 print("inside debris",dataOut.flagNoData)
5149 print("inside debris",dataOut.flagNoData)
5144 return dataOut
5150 return dataOut
5145
5151
5146
5152
5147 class IntegrationHP(IntegrationDP):
5153 class IntegrationHP(IntegrationDP):
5148 """Operation to integrate Double Pulse and Long Pulse data.
5154 """Operation to integrate Double Pulse and Long Pulse data.
5149
5155
5150 Parameters:
5156 Parameters:
5151 -----------
5157 -----------
5152 nint : int
5158 nint : int
5153 Number of integrations.
5159 Number of integrations.
5154
5160
5155 Example
5161 Example
5156 --------
5162 --------
5157
5163
5158 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
5164 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
5159 op.addParameter(name='nint', value='30', format='int')
5165 op.addParameter(name='nint', value='30', format='int')
5160
5166
5161 """
5167 """
5162
5168
5163 def __init__(self, **kwargs):
5169 def __init__(self, **kwargs):
5164
5170
5165 Operation.__init__(self, **kwargs)
5171 Operation.__init__(self, **kwargs)
5166
5172
5167 self.counter = 0
5173 self.counter = 0
5168 self.aux = 0
5174 self.aux = 0
5169
5175
5170 def integration_noise(self,dataOut):
5176 def integration_noise(self,dataOut):
5171
5177
5172 if self.counter == 0:
5178 if self.counter == 0:
5173 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
5179 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
5174
5180
5175 dataOut.tnoise+=dataOut.noise_final
5181 dataOut.tnoise+=dataOut.noise_final
5176
5182
5177 def integration_for_long_pulse(self,dataOut):
5183 def integration_for_long_pulse(self,dataOut):
5178
5184
5179 if self.counter == 0:
5185 if self.counter == 0:
5180 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5186 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5181
5187
5182 dataOut.output_LP_integrated+=dataOut.output_LP
5188 dataOut.output_LP_integrated+=dataOut.output_LP
5183
5189
5184 def run(self,dataOut,nint=None):
5190 def run(self,dataOut,nint=None):
5185
5191
5186 dataOut.flagNoData=True
5192 dataOut.flagNoData=True
5187
5193
5188 #print("flag_inside",dataOut.flagNoData)
5194 #print("flag_inside",dataOut.flagNoData)
5189 dataOut.nint=nint
5195 dataOut.nint=nint
5190 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
5196 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
5191 dataOut.lat=-11.95
5197 dataOut.lat=-11.95
5192 dataOut.lon=-76.87
5198 dataOut.lon=-76.87
5193
5199
5194 self.integration_for_long_pulse(dataOut)
5200 self.integration_for_long_pulse(dataOut)
5195
5201
5196 self.integration_noise(dataOut)
5202 self.integration_noise(dataOut)
5197
5203
5198
5204
5199 if self.counter==dataOut.nint-1:
5205 if self.counter==dataOut.nint-1:
5200
5206
5201 dataOut.tnoise[0]*=0.995
5207 dataOut.tnoise[0]*=0.995
5202 dataOut.tnoise[1]*=0.995
5208 dataOut.tnoise[1]*=0.995
5203 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5209 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5204 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5210 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5205
5211
5206 self.integration_for_double_pulse(dataOut)
5212 self.integration_for_double_pulse(dataOut)
5207
5213
5208
5214
5209
5215
5210 return dataOut
5216 return dataOut
5211
5217
5212
5218
5213 class IntegrationLP(Operation):
5219 class IntegrationLP(Operation):
5214 """Operation to integrate Double Pulse and Long Pulse data.
5220 """Operation to integrate Double Pulse and Long Pulse data.
5215
5221
5216 Parameters:
5222 Parameters:
5217 -----------
5223 -----------
5218 nint : int
5224 nint : int
5219 Number of integrations.
5225 Number of integrations.
5220
5226
5221 Example
5227 Example
5222 --------
5228 --------
5223
5229
5224 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
5230 op = proc_unit.addOperation(name='IntegrationHP', optype='other')
5225 op.addParameter(name='nint', value='30', format='int')
5231 op.addParameter(name='nint', value='30', format='int')
5226
5232
5227 """
5233 """
5228
5234
5229 def __init__(self, **kwargs):
5235 def __init__(self, **kwargs):
5230
5236
5231 Operation.__init__(self, **kwargs)
5237 Operation.__init__(self, **kwargs)
5232
5238
5233 self.counter = 0
5239 self.counter = 0
5234 self.aux = 0
5240 self.aux = 0
5235
5241
5236 def integration_noise(self,dataOut):
5242 def integration_noise(self,dataOut):
5237
5243
5238 if self.counter == 0:
5244 if self.counter == 0:
5239 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
5245 dataOut.tnoise=numpy.zeros((dataOut.NR),dtype='float32')
5240
5246
5241 dataOut.tnoise+=dataOut.noise_final
5247 dataOut.tnoise+=dataOut.noise_final
5242 '''
5248 '''
5243 def integration_for_long_pulse(self,dataOut):
5249 def integration_for_long_pulse(self,dataOut):
5244
5250
5245 if self.counter == 0:
5251 if self.counter == 0:
5246 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5252 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5247
5253
5248 dataOut.output_LP_integrated+=dataOut.output_LP
5254 dataOut.output_LP_integrated+=dataOut.output_LP
5249 '''
5255 '''
5250 def integration_for_long_pulse(self,dataOut):
5256 def integration_for_long_pulse(self,dataOut):
5251 #print("inside")
5257 #print("inside")
5252 #print(self.aux)
5258 #print(self.aux)
5253
5259
5254 if self.counter == 0:
5260 if self.counter == 0:
5255 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5261 dataOut.output_LP_integrated=numpy.zeros((dataOut.NLAG,dataOut.NRANGE,dataOut.NR),order='F',dtype='complex64')
5256
5262
5257 dataOut.output_LP_integrated+=dataOut.output_LP
5263 dataOut.output_LP_integrated+=dataOut.output_LP
5258
5264
5259 if self.aux==1:
5265 if self.aux==1:
5260 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
5266 #print("CurrentBlockBBBBB: ",dataOut.CurrentBlock)
5261 #print(dataOut.datatime)
5267 #print(dataOut.datatime)
5262
5268
5263 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5269 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5264 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5270 ########dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5265 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
5271 #print("Date: ",dataOut.TimeBlockDate_for_dp_power)
5266
5272
5267 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
5273 #dataOut.TimeBlockSeconds_for_dp_power=mktime(strptime(dataOut.TimeBlockDate_for_dp_power))
5268 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
5274 dataOut.TimeBlockSeconds_for_dp_power=dataOut.utctime#dataOut.TimeBlockSeconds-18000
5269 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5275 #dataOut.TimeBlockSeconds_for_dp_power=dataOut.LastAVGDate
5270 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
5276 #print("Seconds: ",dataOut.TimeBlockSeconds_for_dp_power)
5271 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
5277 dataOut.bd_time=gmtime(dataOut.TimeBlockSeconds_for_dp_power)
5272 #print(dataOut.bd_time)
5278 #print(dataOut.bd_time)
5273 #exit()
5279 #exit()
5274 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
5280 dataOut.year=dataOut.bd_time.tm_year+(dataOut.bd_time.tm_yday-1)/364.0
5275 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
5281 dataOut.ut_Faraday=dataOut.bd_time.tm_hour+dataOut.bd_time.tm_min/60.0+dataOut.bd_time.tm_sec/3600.0
5276 #print("date: ", dataOut.TimeBlockDate)
5282 #print("date: ", dataOut.TimeBlockDate)
5277
5283
5278
5284
5279 self.aux=0
5285 self.aux=0
5280
5286
5281 #print("after")
5287 #print("after")
5282
5288
5283 self.integration_noise(dataOut)
5289 self.integration_noise(dataOut)
5284
5290
5285 if self.counter==0:
5291 if self.counter==0:
5286
5292
5287 self.init_time=dataOut.utctime
5293 self.init_time=dataOut.utctime
5288
5294
5289 if self.counter < dataOut.nint:
5295 if self.counter < dataOut.nint:
5290 #print("HERE")
5296 #print("HERE")
5291
5297
5292
5298
5293
5299
5294 self.counter+=1
5300 self.counter+=1
5295
5301
5296 if self.counter==dataOut.nint-1:
5302 if self.counter==dataOut.nint-1:
5297 self.aux=1
5303 self.aux=1
5298 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5304 #dataOut.TimeBlockDate_for_dp_power=dataOut.TimeBlockDate
5299 if self.counter==dataOut.nint:
5305 if self.counter==dataOut.nint:
5300
5306
5301 dataOut.flagNoData=False
5307 dataOut.flagNoData=False
5302 dataOut.utctime=self.init_time
5308 dataOut.utctime=self.init_time
5303 self.counter=0
5309 self.counter=0
5304
5310
5305 def run(self,dataOut,nint=None):
5311 def run(self,dataOut,nint=None):
5306
5312
5307 dataOut.flagNoData=True
5313 dataOut.flagNoData=True
5308
5314
5309 #print("flag_inside",dataOut.flagNoData)
5315 #print("flag_inside",dataOut.flagNoData)
5310 dataOut.nint=nint
5316 dataOut.nint=nint
5311 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
5317 dataOut.paramInterval=0#int(dataOut.nint*dataOut.header[7][0]*2 )
5312 dataOut.lat=-11.95
5318 dataOut.lat=-11.95
5313 dataOut.lon=-76.87
5319 dataOut.lon=-76.87
5314
5320
5315 self.integration_for_long_pulse(dataOut)
5321 self.integration_for_long_pulse(dataOut)
5316
5322
5317
5323
5318 if self.counter==dataOut.nint:
5324 if self.counter==dataOut.nint:
5319
5325
5320 dataOut.tnoise[0]*=0.995
5326 dataOut.tnoise[0]*=0.995
5321 dataOut.tnoise[1]*=0.995
5327 dataOut.tnoise[1]*=0.995
5322 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5328 dataOut.pan=dataOut.tnoise[0]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5323 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5329 dataOut.pbn=dataOut.tnoise[1]/float(dataOut.NSCAN*dataOut.nint*dataOut.NAVG)
5324
5330
5325 #self.integration_for_double_pulse(dataOut)
5331 #self.integration_for_double_pulse(dataOut)
5326 print("HERE2")
5332 print("HERE2")
5327
5333
5328
5334
5329
5335
5330 return dataOut
5336 return dataOut
5331
5337
5332
5338
5333 class SumFlipsHP(SumFlips):
5339 class SumFlipsHP(SumFlips):
5334 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
5340 """Operation to sum the flip and unflip part of certain cross products of the Double Pulse.
5335
5341
5336 Parameters:
5342 Parameters:
5337 -----------
5343 -----------
5338 None
5344 None
5339
5345
5340 Example
5346 Example
5341 --------
5347 --------
5342
5348
5343 op = proc_unit.addOperation(name='SumFlipsHP', optype='other')
5349 op = proc_unit.addOperation(name='SumFlipsHP', optype='other')
5344
5350
5345 """
5351 """
5346
5352
5347 def __init__(self, **kwargs):
5353 def __init__(self, **kwargs):
5348
5354
5349 Operation.__init__(self, **kwargs)
5355 Operation.__init__(self, **kwargs)
5350
5356
5351 def rint2HP(self,dataOut):
5357 def rint2HP(self,dataOut):
5352
5358
5353 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
5359 dataOut.rnint2=numpy.zeros(dataOut.DPL,'float32')
5354
5360
5355 for l in range(dataOut.DPL):
5361 for l in range(dataOut.DPL):
5356 if(l==0 or (l>=3 and l <=6)):
5362 if(l==0 or (l>=3 and l <=6)):
5357 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*16.0)
5363 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*16.0)
5358 else:
5364 else:
5359 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*8.0)
5365 dataOut.rnint2[l]=0.5/float(dataOut.nint*dataOut.NAVG*8.0)
5360
5366
5361 def run(self,dataOut):
5367 def run(self,dataOut):
5362
5368
5363 self.rint2HP(dataOut)
5369 self.rint2HP(dataOut)
5364 self.SumLags(dataOut)
5370 self.SumLags(dataOut)
5365
5371
5366 return dataOut
5372 return dataOut
5367
5373
5368
5374
5369 from schainpy.model.proc import full_profile_profile
5370 from scipy.optimize import nnls
5371 class LongPulseAnalysis(Operation):
5375 class LongPulseAnalysis(Operation):
5372 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
5376 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
5373
5377
5374 Parameters:
5378 Parameters:
5375 -----------
5379 -----------
5376 NACF : int
5380 NACF : int
5377 .*
5381 .*
5378
5382
5379 Example
5383 Example
5380 --------
5384 --------
5381
5385
5382 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5386 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5383 op.addParameter(name='NACF', value='16', format='int')
5387 op.addParameter(name='NACF', value='16', format='int')
5384
5388
5385 """
5389 """
5386
5390
5387 def __init__(self, **kwargs):
5391 def __init__(self, **kwargs):
5388
5392
5389 Operation.__init__(self, **kwargs)
5393 Operation.__init__(self, **kwargs)
5390 self.aux=1
5394 self.aux=1
5391
5395
5392 def run(self,dataOut,NACF):
5396 def run(self,dataOut,NACF):
5393
5397
5394 dataOut.NACF=NACF
5398 dataOut.NACF=NACF
5395 dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5399 dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5396 anoise0=dataOut.tnoise[0]
5400 anoise0=dataOut.tnoise[0]
5397 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5401 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5398
5402
5399 if self.aux:
5403 if self.aux:
5400 #dataOut.cut=31#26#height=31*15=465
5404 #dataOut.cut=31#26#height=31*15=465
5401 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5405 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5402 self.drift=numpy.zeros((200),'float32')
5406 self.drift=numpy.zeros((200),'float32')
5403 self.rdrift=numpy.zeros((200),'float32')
5407 self.rdrift=numpy.zeros((200),'float32')
5404 self.ddrift=numpy.zeros((200),'float32')
5408 self.ddrift=numpy.zeros((200),'float32')
5405 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5409 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5406 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5410 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5407 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5411 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5408 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5412 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5409 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5413 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5410 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5414 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5411 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5415 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5412 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5416 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5413 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5417 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5414 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5418 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5415 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5419 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5416 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5420 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5417 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5421 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5418 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5422 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5419 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5423 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5420 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5424 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5421 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5425 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5422 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5426 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5423 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5427 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5424 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32')
5428 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,dataOut.NSHTS)),order='F',dtype='float32')
5425 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32')
5429 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,dataOut.NSHTS),dataOut.NLAG),order='F',dtype='float32')
5426 dataOut.status=numpy.zeros(1,'float32')
5430 dataOut.status=numpy.zeros(1,'float32')
5427 dataOut.tx=240.0 #deberΓ­a provenir del header #hybrid
5431 dataOut.tx=240.0 #deberΓ­a provenir del header #hybrid
5428
5432
5429 for i in range(dataOut.IBITS):
5433 for i in range(dataOut.IBITS):
5430 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5434 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5431
5435
5432 self.aux=0
5436 self.aux=0
5433
5437
5434 dataOut.cut=30
5438 dataOut.cut=30
5435 for i in range(30,15,-1):
5439 for i in range(30,15,-1):
5436 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5440 if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5437 dataOut.cut=i-1
5441 dataOut.cut=i-1
5438 #print(dataOut.cut)
5442 #print(dataOut.cut)
5439 #print(dataOut.info2[:])
5443 #print(dataOut.info2[:])
5440 #print(dataOut.te2[:])
5444 #print(dataOut.te2[:])
5441 #print(dataOut.ti2[:])
5445 #print(dataOut.ti2[:])
5442 for i in range(dataOut.NLAG):
5446 for i in range(dataOut.NLAG):
5443 self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5447 self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5444
5448
5445
5449
5446 self.cal/=float(dataOut.NRANGE)
5450 self.cal/=float(dataOut.NRANGE)
5447
5451
5448 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
5452 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
5449
5453
5450 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5454 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5451 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
5455 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
5452
5456
5453 for i in range(1,dataOut.NLAG): #remove cal data from certain lags
5457 for i in range(1,dataOut.NLAG): #remove cal data from certain lags
5454 dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5458 dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5455 k=max(j,26) #constant power below range 26
5459 k=max(j,26) #constant power below range 26
5456 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
5460 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
5457
5461
5458 ## examine drifts here - based on 60 'indep.' estimates
5462 ## examine drifts here - based on 60 'indep.' estimates
5459
5463
5460 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
5464 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
5461 alpha=beta=delta=0.0
5465 alpha=beta=delta=0.0
5462 nest=0
5466 nest=0
5463 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5467 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5464 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5468 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5465 for i in range(1,3):
5469 for i in range(1,3):
5466 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5470 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5467 for j in range(34,44):
5471 for j in range(34,44):
5468 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5472 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5469 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5473 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5470 dataOut.dphi2*=gamma**2
5474 dataOut.dphi2*=gamma**2
5471 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
5475 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
5472
5476
5473 self.drift[nest]=pest
5477 self.drift[nest]=pest
5474 self.ddrift[nest]=dataOut.dphi2
5478 self.ddrift[nest]=dataOut.dphi2
5475 self.rdrift[nest]=float(nest)
5479 self.rdrift[nest]=float(nest)
5476 nest+=1
5480 nest+=1
5477
5481
5478 sorted(self.drift[:nest])
5482 sorted(self.drift[:nest])
5479
5483
5480 for j in range(int(nest/4),int(3*nest/4)):
5484 for j in range(int(nest/4),int(3*nest/4)):
5481 #i=int(self.rdrift[j])
5485 #i=int(self.rdrift[j])
5482 alpha+=self.drift[j]/self.ddrift[j]
5486 alpha+=self.drift[j]/self.ddrift[j]
5483 delta+=1.0/self.ddrift[j]
5487 delta+=1.0/self.ddrift[j]
5484
5488
5485 alpha/=delta
5489 alpha/=delta
5486 delta=1./numpy.sqrt(delta)
5490 delta=1./numpy.sqrt(delta)
5487 vdrift=alpha-beta
5491 vdrift=alpha-beta
5488 dvdrift=delta
5492 dvdrift=delta
5489
5493
5490 #need to develop estimate of complete density profile using all
5494 #need to develop estimate of complete density profile using all
5491 #available data
5495 #available data
5492
5496
5493 #estimate sample variances for long-pulse power profile
5497 #estimate sample variances for long-pulse power profile
5494
5498
5495 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
5499 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
5496
5500
5497 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5501 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5498
5502
5499 ioff=1
5503 ioff=1
5500
5504
5501 #deconvolve rectangular pulse shape from profile ==> powerb, perror
5505 #deconvolve rectangular pulse shape from profile ==> powerb, perror
5502
5506
5503
5507
5504 ############# START nnlswrap#############
5508 ############# START nnlswrap#############
5505
5509
5506 if dataOut.ut_Faraday>14.0:
5510 if dataOut.ut_Faraday>14.0:
5507 alpha_nnlswrap=20.0
5511 alpha_nnlswrap=20.0
5508 else:
5512 else:
5509 alpha_nnlswrap=30.0
5513 alpha_nnlswrap=30.0
5510
5514
5511 range1_nnls=dataOut.NACF
5515 range1_nnls=dataOut.NACF
5512 range2_nnls=dataOut.NACF+dataOut.IBITS-1
5516 range2_nnls=dataOut.NACF+dataOut.IBITS-1
5513
5517
5514 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
5518 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
5515 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
5519 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
5516
5520
5517 for i in range(range1_nnls):
5521 for i in range(range1_nnls):
5518 for j in range(range2_nnls):
5522 for j in range(range2_nnls):
5519 if j>=i and j<i+dataOut.IBITS:
5523 if j>=i and j<i+dataOut.IBITS:
5520 g_nnlswrap[i,j]=1.0
5524 g_nnlswrap[i,j]=1.0
5521 else:
5525 else:
5522 g_nnlswrap[i,j]=0.0
5526 g_nnlswrap[i,j]=0.0
5523
5527
5524 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
5528 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
5525
5529
5526 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
5530 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
5527
5531
5528 #ERROR ANALYSIS#
5532 #ERROR ANALYSIS#
5529
5533
5530 self.perror[:range2_nnls]=0.0
5534 self.perror[:range2_nnls]=0.0
5531 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5535 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5532 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5536 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5533 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
5537 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
5534
5538
5535 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5539 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5536 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
5540 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
5537
5541
5538 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
5542 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
5539 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
5543 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
5540
5544
5541 self.powerb[:range2_nnls]=x_nnlswrap
5545 self.powerb[:range2_nnls]=x_nnlswrap
5542
5546
5543 #############END nnlswrap#############
5547 #############END nnlswrap#############
5544
5548
5545 #estimate relative error for deconvolved profile (scaling irrelevant)
5549 #estimate relative error for deconvolved profile (scaling irrelevant)
5546
5550
5547 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
5551 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
5548
5552
5549 aux=0
5553 aux=0
5550
5554
5551 for i in range(dataOut.IBITS,dataOut.NACF):
5555 for i in range(dataOut.IBITS,dataOut.NACF):
5552 self.dpulse[i]=self.lpulse[i]=0.0
5556 self.dpulse[i]=self.lpulse[i]=0.0
5553 for j in range(dataOut.IBITS):
5557 for j in range(dataOut.IBITS):
5554 k=int(i-j)
5558 k=int(i-j)
5555 if k<36-aux and k>16:
5559 if k<36-aux and k>16:
5556 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5560 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5557 elif k>=36-aux:
5561 elif k>=36-aux:
5558 self.lpulse[i]+=self.powerb[k]
5562 self.lpulse[i]+=self.powerb[k]
5559 self.lagp[i]=self.powera[i]
5563 self.lagp[i]=self.powera[i]
5560
5564
5561 #find scale factor that best merges profiles
5565 #find scale factor that best merges profiles
5562
5566
5563 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5567 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5564 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5568 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5565 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5569 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5566 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5570 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5567 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5571 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5568
5572
5569 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
5573 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
5570 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
5574 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
5571
5575
5572 #form density profile estimate, merging rescaled power profiles
5576 #form density profile estimate, merging rescaled power profiles
5573
5577
5574 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
5578 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
5575 self.powerb[36-aux:dataOut.NACF]*=beta
5579 self.powerb[36-aux:dataOut.NACF]*=beta
5576
5580
5577 #form Ne estimate, fill in error estimate at low altitudes
5581 #form Ne estimate, fill in error estimate at low altitudes
5578
5582
5579 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5583 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5580 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
5584 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
5581
5585
5582 #now do error propagation: store zero lag error covariance in u
5586 #now do error propagation: store zero lag error covariance in u
5583
5587
5584 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
5588 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
5585
5589
5586 for i in range(dataOut.NACF):
5590 for i in range(dataOut.NACF):
5587 for j in range(i,dataOut.NACF):
5591 for j in range(i,dataOut.NACF):
5588 if j-i>=dataOut.IBITS:
5592 if j-i>=dataOut.IBITS:
5589 self.u[i,j]=0.0
5593 self.u[i,j]=0.0
5590 else:
5594 else:
5591 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5595 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5592 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5596 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5593 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5597 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5594
5598
5595 self.u[j,i]=self.u[i,j]
5599 self.u[j,i]=self.u[i,j]
5596
5600
5597 #now error analyis for lag product matrix (diag), place in acf_err
5601 #now error analyis for lag product matrix (diag), place in acf_err
5598
5602
5599 for i in range(dataOut.NACF):
5603 for i in range(dataOut.NACF):
5600 for j in range(dataOut.IBITS):
5604 for j in range(dataOut.IBITS):
5601 if j==0:
5605 if j==0:
5602 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5606 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5603 else:
5607 else:
5604 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5608 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5605
5609
5606 #with suppress_stdout_stderr():
5610 #with suppress_stdout_stderr():
5607 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5611 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5608
5612
5609 if dataOut.status>=3.5:
5613 if dataOut.status>=3.5:
5610 dataOut.te[:]=numpy.nan
5614 dataOut.te[:]=numpy.nan
5611 dataOut.ete[:]=numpy.nan
5615 dataOut.ete[:]=numpy.nan
5612 dataOut.ti[:]=numpy.nan
5616 dataOut.ti[:]=numpy.nan
5613 dataOut.eti[:]=numpy.nan
5617 dataOut.eti[:]=numpy.nan
5614 dataOut.ph[:]=numpy.nan
5618 dataOut.ph[:]=numpy.nan
5615 dataOut.eph[:]=numpy.nan
5619 dataOut.eph[:]=numpy.nan
5616 dataOut.phe[:]=numpy.nan
5620 dataOut.phe[:]=numpy.nan
5617 dataOut.ephe[:]=numpy.nan
5621 dataOut.ephe[:]=numpy.nan
5618
5622
5619 return dataOut
5623 return dataOut
5620
5624
5621
5625
5622 class LongPulseAnalysisLP(Operation):
5626 class LongPulseAnalysisLP(Operation):
5623 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
5627 """Operation to estimate ACFs, temperatures, total electron density and Hydrogen/Helium fractions from the Long Pulse data.
5624
5628
5625 Parameters:
5629 Parameters:
5626 -----------
5630 -----------
5627 NACF : int
5631 NACF : int
5628 .*
5632 .*
5629
5633
5630 Example
5634 Example
5631 --------
5635 --------
5632
5636
5633 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5637 op = proc_unit.addOperation(name='LongPulseAnalysis', optype='other')
5634 op.addParameter(name='NACF', value='16', format='int')
5638 op.addParameter(name='NACF', value='16', format='int')
5635
5639
5636 """
5640 """
5637
5641
5638 def __init__(self, **kwargs):
5642 def __init__(self, **kwargs):
5639
5643
5640 Operation.__init__(self, **kwargs)
5644 Operation.__init__(self, **kwargs)
5641 self.aux=1
5645 self.aux=1
5642
5646
5643 def run(self,dataOut,NACF=None):
5647 def run(self,dataOut,NACF=None):
5644
5648
5645
5649
5646 dataOut.IBITS = 64
5650 dataOut.IBITS = 64
5647 dataOut.NACF = dataOut.nHeights# - (2*dataOut.IBITS+5)
5651 dataOut.NACF = dataOut.nHeights# - (2*dataOut.IBITS+5)
5648 #print(dataOut.heightList[int(dataOut.NACF)])
5652 #print(dataOut.heightList[int(dataOut.NACF)])
5649 #exit(1)
5653 #exit(1)
5650
5654
5651 #dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5655 #dataOut.heightList=dataOut.DH*(numpy.arange(dataOut.NACF))
5652 anoise0=dataOut.tnoise[0]
5656 anoise0=dataOut.tnoise[0]
5653 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5657 anoise1=anoise0*0.0 #seems to be noise in 1st lag 0.015 before '14
5654
5658
5655 if self.aux:
5659 if self.aux:
5656 #dataOut.cut=31#26#height=31*15=465
5660 #dataOut.cut=31#26#height=31*15=465
5657 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5661 self.cal=numpy.zeros((dataOut.NLAG),'float32')
5658 self.drift=numpy.zeros((200),'float32')
5662 self.drift=numpy.zeros((200),'float32')
5659 self.rdrift=numpy.zeros((200),'float32')
5663 self.rdrift=numpy.zeros((200),'float32')
5660 self.ddrift=numpy.zeros((200),'float32')
5664 self.ddrift=numpy.zeros((200),'float32')
5661 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5665 self.sigma=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5662 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5666 self.powera=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5663 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5667 self.powerb=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5664 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5668 self.perror=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5665 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5669 dataOut.ene=numpy.zeros((dataOut.NRANGE),'float32')
5666 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5670 self.dpulse=numpy.zeros((dataOut.NACF),'float32')
5667 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5671 self.lpulse=numpy.zeros((dataOut.NACF),'float32')
5668 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5672 dataOut.lags_LP=numpy.zeros((dataOut.IBITS),order='F',dtype='float32')
5669 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5673 self.lagp=numpy.zeros((dataOut.NACF),'float32')
5670 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5674 self.u=numpy.zeros((2*dataOut.NACF,2*dataOut.NACF),'float32')
5671 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5675 dataOut.ne=numpy.zeros((dataOut.NRANGE),order='F',dtype='float32')
5672 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5676 dataOut.te=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5673 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5677 dataOut.ete=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5674 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5678 dataOut.ti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5675 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5679 dataOut.eti=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5676 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5680 dataOut.ph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5677 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5681 dataOut.eph=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5678 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5682 dataOut.phe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5679 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5683 dataOut.ephe=numpy.zeros((dataOut.NACF),order='F',dtype='float32')
5680 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,1)),order='F',dtype='float32')
5684 dataOut.errors=numpy.zeros((dataOut.IBITS,max(dataOut.NRANGE,1)),order='F',dtype='float32')
5681 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,1),dataOut.NLAG),order='F',dtype='float32')
5685 dataOut.fit_array_real=numpy.zeros((max(dataOut.NRANGE,1),dataOut.NLAG),order='F',dtype='float32')
5682 dataOut.status=numpy.zeros(1,'float32')
5686 dataOut.status=numpy.zeros(1,'float32')
5683 dataOut.tx=480.0 #deberΓ­a provenir del header #HAE
5687 dataOut.tx=480.0 #deberΓ­a provenir del header #HAE
5684
5688
5685 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
5689 dataOut.h2=numpy.zeros(dataOut.MAXNRANGENDT,'float32')
5686 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
5690 dataOut.range1=numpy.zeros(dataOut.MAXNRANGENDT,order='F',dtype='float32')
5687
5691
5688
5692
5689
5693
5690 for i in range(dataOut.IBITS):
5694 for i in range(dataOut.IBITS):
5691 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5695 dataOut.lags_LP[i]=float(i)*(dataOut.tx/150.0)/float(dataOut.IBITS) # (float)i*(header.tx/150.0)/(float)IBITS;
5692
5696
5693 self.aux=0
5697 self.aux=0
5694
5698
5695
5699
5696
5700
5697 for i in range(dataOut.MAXNRANGENDT):
5701 for i in range(dataOut.MAXNRANGENDT):
5698 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
5702 dataOut.range1[i]=dataOut.H0 + i*dataOut.DH
5699 dataOut.h2[i]=dataOut.range1[i]**2
5703 dataOut.h2[i]=dataOut.range1[i]**2
5700
5704
5701 dataOut.cut=30
5705 dataOut.cut=30
5702 #for i in range(30,15,-1):
5706 #for i in range(30,15,-1):
5703 # if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5707 # if numpy.nanmax(dataOut.acfs_error_to_plot[i,:])>=10 or dataOut.info2[i]==0:
5704 # dataOut.cut=i-1
5708 # dataOut.cut=i-1
5705 #print(dataOut.cut)
5709 #print(dataOut.cut)
5706 #print(dataOut.info2[:])
5710 #print(dataOut.info2[:])
5707 #print(dataOut.te2[:])
5711 #print(dataOut.te2[:])
5708 #print(dataOut.ti2[:])
5712 #print(dataOut.ti2[:])
5709 #for i in range(dataOut.NLAG):
5713 #for i in range(dataOut.NLAG):
5710 # self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5714 # self.cal[i]=sum(dataOut.output_LP_integrated[i,:,3].real)
5711
5715
5712
5716
5713 #self.cal/=float(dataOut.NRANGE)
5717 #self.cal/=float(dataOut.NRANGE)
5714
5718
5715 for j in range(dataOut.NACF):#+2*dataOut.IBITS+2):
5719 for j in range(dataOut.NACF):#+2*dataOut.IBITS+2):
5716
5720
5717 self.powera[j]=dataOut.output_LP_integrated.real[0,j,0]
5721 self.powera[j]=dataOut.output_LP_integrated.real[0,j,0]
5718
5722
5719
5723
5720 print(dataOut.heightList[:dataOut.NACF])
5724 print(dataOut.heightList[:dataOut.NACF])
5721 import matplotlib.pyplot as plt
5725 import matplotlib.pyplot as plt
5722 fig, axes = plt.subplots(figsize=(14, 10))
5726 fig, axes = plt.subplots(figsize=(14, 10))
5723 axes.plot(self.powera[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5727 axes.plot(self.powera[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5724 axes.set_xscale("log", nonposx='clip')
5728 axes.set_xscale("log", nonposx='clip')
5725 #axes.set_xlim(1e18,2e19)
5729 #axes.set_xlim(1e18,2e19)
5726 axes.set_ylim(180,470)
5730 axes.set_ylim(180,470)
5727 import time
5731 import time
5728
5732
5729 plt.title(time.ctime(dataOut.utctime))
5733 plt.title(time.ctime(dataOut.utctime))
5730 plt.show()
5734 plt.show()
5731 time.sleep(50)
5735 time.sleep(50)
5732 exit(1)
5736 exit(1)
5733 '''
5737 '''
5734 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
5738 for j in range(dataOut.NACF+2*dataOut.IBITS+2):
5735
5739
5736 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5740 dataOut.output_LP_integrated.real[0,j,0]-=anoise0 #lag0 ch0
5737 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
5741 dataOut.output_LP_integrated.real[1,j,0]-=anoise1 #lag1 ch0
5738
5742
5739 #for i in range(1,dataOut.NLAG): #remove cal data from certain lags
5743 #for i in range(1,dataOut.NLAG): #remove cal data from certain lags
5740 # dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5744 # dataOut.output_LP_integrated.real[i,j,0]-=self.cal[i]
5741 k=max(j,26) #constant power below range 26
5745 k=max(j,26) #constant power below range 26
5742 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
5746 self.powera[j]=dataOut.output_LP_integrated.real[0,k,0]
5743
5747
5744 ## examine drifts here - based on 60 'indep.' estimates
5748 ## examine drifts here - based on 60 'indep.' estimates
5745
5749
5746 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
5750 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint*10
5747 alpha=beta=delta=0.0
5751 alpha=beta=delta=0.0
5748 nest=0
5752 nest=0
5749 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5753 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[1]*1.0e-3)
5750 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5754 beta=gamma*(math.atan2(dataOut.output_LP_integrated.imag[14,0,2],dataOut.output_LP_integrated.real[14,0,2])-math.atan2(dataOut.output_LP_integrated.imag[1,0,2],dataOut.output_LP_integrated.real[1,0,2]))/13.0
5751 for i in range(1,3):
5755 for i in range(1,3):
5752 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5756 gamma=3.0/(2.0*numpy.pi*dataOut.lags_LP[i]*1.0e-3)
5753 for j in range(34,44):
5757 for j in range(34,44):
5754 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5758 rho2=numpy.abs(dataOut.output_LP_integrated[i,j,0])/numpy.abs(dataOut.output_LP_integrated[0,j,0])
5755 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5759 dataOut.dphi2=(1.0/rho2-1.0)/(float(2*nis))
5756 dataOut.dphi2*=gamma**2
5760 dataOut.dphi2*=gamma**2
5757 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
5761 pest=gamma*math.atan(dataOut.output_LP_integrated.imag[i,j,0]/dataOut.output_LP_integrated.real[i,j,0])
5758
5762
5759 self.drift[nest]=pest
5763 self.drift[nest]=pest
5760 self.ddrift[nest]=dataOut.dphi2
5764 self.ddrift[nest]=dataOut.dphi2
5761 self.rdrift[nest]=float(nest)
5765 self.rdrift[nest]=float(nest)
5762 nest+=1
5766 nest+=1
5763
5767
5764 sorted(self.drift[:nest])
5768 sorted(self.drift[:nest])
5765
5769
5766 for j in range(int(nest/4),int(3*nest/4)):
5770 for j in range(int(nest/4),int(3*nest/4)):
5767 #i=int(self.rdrift[j])
5771 #i=int(self.rdrift[j])
5768 alpha+=self.drift[j]/self.ddrift[j]
5772 alpha+=self.drift[j]/self.ddrift[j]
5769 delta+=1.0/self.ddrift[j]
5773 delta+=1.0/self.ddrift[j]
5770
5774
5771 alpha/=delta
5775 alpha/=delta
5772 delta=1./numpy.sqrt(delta)
5776 delta=1./numpy.sqrt(delta)
5773 vdrift=alpha-beta
5777 vdrift=alpha-beta
5774 dvdrift=delta
5778 dvdrift=delta
5775
5779
5776 #need to develop estimate of complete density profile using all
5780 #need to develop estimate of complete density profile using all
5777 #available data
5781 #available data
5778
5782
5779 #estimate sample variances for long-pulse power profile
5783 #estimate sample variances for long-pulse power profile
5780
5784
5781 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
5785 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint
5782
5786
5783 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5787 self.sigma[:dataOut.NACF+2*dataOut.IBITS+2]=((anoise0+self.powera[:dataOut.NACF+2*dataOut.IBITS+2])**2)/float(nis)
5784 '''
5788 '''
5785 ioff=1
5789 ioff=1
5786
5790
5787 #deconvolve rectangular pulse shape from profile ==> powerb, perror
5791 #deconvolve rectangular pulse shape from profile ==> powerb, perror
5788
5792
5789
5793
5790 ############# START nnlswrap#############
5794 ############# START nnlswrap#############
5791
5795
5792 if dataOut.ut_Faraday>14.0:
5796 if dataOut.ut_Faraday>14.0:
5793 alpha_nnlswrap=20.0
5797 alpha_nnlswrap=20.0
5794 else:
5798 else:
5795 alpha_nnlswrap=30.0
5799 alpha_nnlswrap=30.0
5796
5800
5797 range1_nnls=dataOut.NACF
5801 range1_nnls=dataOut.NACF
5798 range2_nnls=dataOut.NACF+dataOut.IBITS-1
5802 range2_nnls=dataOut.NACF+dataOut.IBITS-1
5799
5803
5800 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
5804 g_nnlswrap=numpy.zeros((range1_nnls,range2_nnls),'float32')
5801 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
5805 a_nnlswrap=numpy.zeros((range2_nnls,range2_nnls),'float64')
5802
5806
5803 for i in range(range1_nnls):
5807 for i in range(range1_nnls):
5804 for j in range(range2_nnls):
5808 for j in range(range2_nnls):
5805 if j>=i and j<i+dataOut.IBITS:
5809 if j>=i and j<i+dataOut.IBITS:
5806 g_nnlswrap[i,j]=1.0
5810 g_nnlswrap[i,j]=1.0
5807 else:
5811 else:
5808 g_nnlswrap[i,j]=0.0
5812 g_nnlswrap[i,j]=0.0
5809
5813
5810 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
5814 a_nnlswrap[:]=numpy.matmul(numpy.transpose(g_nnlswrap),g_nnlswrap)
5811
5815
5812 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
5816 numpy.fill_diagonal(a_nnlswrap,a_nnlswrap.diagonal()+alpha_nnlswrap**2)
5813
5817
5814 #ERROR ANALYSIS#
5818 #ERROR ANALYSIS#
5815 '''
5819 '''
5816 self.perror[:range2_nnls]=0.0
5820 self.perror[:range2_nnls]=0.0
5817 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5821 self.perror[:range2_nnls]=numpy.matmul(1./(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff]),g_nnlswrap**2)
5818 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5822 self.perror[:range1_nnls]+=(alpha_nnlswrap**2)/(self.sigma[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff])
5819 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
5823 self.perror[:range2_nnls]=1.00/self.perror[:range2_nnls]
5820 '''
5824 '''
5821 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5825 b_nnlswrap=numpy.zeros(range2_nnls,'float64')
5822 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
5826 b_nnlswrap[:]=numpy.matmul(self.powera[dataOut.IBITS+ioff:range1_nnls+dataOut.IBITS+ioff],g_nnlswrap)
5823
5827
5824 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
5828 x_nnlswrap=numpy.zeros(range2_nnls,'float64')
5825 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
5829 x_nnlswrap[:]=nnls(a_nnlswrap,b_nnlswrap)[0]
5826
5830
5827 self.powerb[:range2_nnls]=x_nnlswrap
5831 self.powerb[:range2_nnls]=x_nnlswrap
5828
5832
5829
5833
5830 import matplotlib.pyplot as plt
5834 import matplotlib.pyplot as plt
5831 fig, axes = plt.subplots(figsize=(14, 10))
5835 fig, axes = plt.subplots(figsize=(14, 10))
5832 axes.plot(self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5836 axes.plot(self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF],dataOut.heightList[:dataOut.NACF])
5833 axes.set_xscale("log", nonposx='clip')
5837 axes.set_xscale("log", nonposx='clip')
5834 #axes.set_xlim(1e10,8e12)
5838 #axes.set_xlim(1e10,8e12)
5835 axes.set_ylim(0,300)
5839 axes.set_ylim(0,300)
5836 plt.show()
5840 plt.show()
5837 import time
5841 import time
5838 time.sleep(60)
5842 time.sleep(60)
5839 exit(1)
5843 exit(1)
5840
5844
5841
5845
5842 #############END nnlswrap#############
5846 #############END nnlswrap#############
5843
5847
5844 #estimate relative error for deconvolved profile (scaling irrelevant)
5848 #estimate relative error for deconvolved profile (scaling irrelevant)
5845
5849
5846 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
5850 dataOut.ene[0:dataOut.NACF]=numpy.sqrt(self.perror[0:dataOut.NACF])/self.powerb[0:dataOut.NACF]
5847
5851
5848 aux=0
5852 aux=0
5849
5853
5850 for i in range(dataOut.IBITS,dataOut.NACF):
5854 for i in range(dataOut.IBITS,dataOut.NACF):
5851 self.dpulse[i]=self.lpulse[i]=0.0
5855 self.dpulse[i]=self.lpulse[i]=0.0
5852 for j in range(dataOut.IBITS):
5856 for j in range(dataOut.IBITS):
5853 k=int(i-j)
5857 k=int(i-j)
5854 if k<36-aux and k>16:
5858 if k<36-aux and k>16:
5855 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5859 self.dpulse[i]+=dataOut.ph2[k]/dataOut.h2[k]
5856 elif k>=36-aux:
5860 elif k>=36-aux:
5857 self.lpulse[i]+=self.powerb[k]
5861 self.lpulse[i]+=self.powerb[k]
5858 self.lagp[i]=self.powera[i]
5862 self.lagp[i]=self.powera[i]
5859
5863
5860 #find scale factor that best merges profiles
5864 #find scale factor that best merges profiles
5861
5865
5862 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5866 qi=sum(self.dpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5863 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5867 ri=sum((self.dpulse[32:dataOut.NACF]*self.lpulse[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5864 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5868 si=sum((self.dpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5865 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5869 ui=sum(self.lpulse[32:dataOut.NACF]**2/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5866 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5870 vi=sum((self.lpulse[32:dataOut.NACF]*self.lagp[32:dataOut.NACF])/(self.lagp[32:dataOut.NACF]+anoise0)**2)
5867
5871
5868 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
5872 alpha=(si*ui-vi*ri)/(qi*ui-ri*ri)
5869 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
5873 beta=(qi*vi-ri*si)/(qi*ui-ri*ri)
5870
5874
5871 #form density profile estimate, merging rescaled power profiles
5875 #form density profile estimate, merging rescaled power profiles
5872
5876
5873 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
5877 self.powerb[16:36-aux]=alpha*dataOut.ph2[16:36-aux]/dataOut.h2[16:36-aux]
5874 self.powerb[36-aux:dataOut.NACF]*=beta
5878 self.powerb[36-aux:dataOut.NACF]*=beta
5875
5879
5876 #form Ne estimate, fill in error estimate at low altitudes
5880 #form Ne estimate, fill in error estimate at low altitudes
5877
5881
5878 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5882 dataOut.ene[0:36-aux]=dataOut.sdp2[0:36-aux]/dataOut.ph2[0:36-aux]
5879 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
5883 dataOut.ne[:dataOut.NACF]=self.powerb[:dataOut.NACF]*dataOut.h2[:dataOut.NACF]/alpha
5880
5884
5881 #now do error propagation: store zero lag error covariance in u
5885 #now do error propagation: store zero lag error covariance in u
5882
5886
5883 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
5887 nis=dataOut.NSCAN*dataOut.NAVG*dataOut.nint/1 # DLH serious debris removal
5884
5888
5885 for i in range(dataOut.NACF):
5889 for i in range(dataOut.NACF):
5886 for j in range(i,dataOut.NACF):
5890 for j in range(i,dataOut.NACF):
5887 if j-i>=dataOut.IBITS:
5891 if j-i>=dataOut.IBITS:
5888 self.u[i,j]=0.0
5892 self.u[i,j]=0.0
5889 else:
5893 else:
5890 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5894 self.u[i,j]=dataOut.output_LP_integrated.real[j-i,i,0]**2/float(nis)
5891 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5895 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,i,0])/dataOut.output_LP_integrated.real[0,i,0]
5892 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5896 self.u[i,j]*=(anoise0+dataOut.output_LP_integrated.real[0,j,0])/dataOut.output_LP_integrated.real[0,j,0]
5893
5897
5894 self.u[j,i]=self.u[i,j]
5898 self.u[j,i]=self.u[i,j]
5895
5899
5896 #now error analyis for lag product matrix (diag), place in acf_err
5900 #now error analyis for lag product matrix (diag), place in acf_err
5897
5901
5898 for i in range(dataOut.NACF):
5902 for i in range(dataOut.NACF):
5899 for j in range(dataOut.IBITS):
5903 for j in range(dataOut.IBITS):
5900 if j==0:
5904 if j==0:
5901 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5905 dataOut.errors[0,i]=numpy.sqrt(self.u[i,i])
5902 else:
5906 else:
5903 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5907 dataOut.errors[j,i]=numpy.sqrt(((dataOut.output_LP_integrated.real[0,i,0]+anoise0)*(dataOut.output_LP_integrated.real[0,i+j,0]+anoise0)+dataOut.output_LP_integrated.real[j,i,0]**2)/float(2*nis))
5904
5908
5905 #with suppress_stdout_stderr():
5909 #with suppress_stdout_stderr():
5906 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5910 #full_profile_profile.profile(numpy.transpose(dataOut.output_LP_integrated,(2,1,0)),numpy.transpose(dataOut.errors),self.powerb,dataOut.ne,dataOut.lags_LP,dataOut.thb,dataOut.bfm,dataOut.te,dataOut.ete,dataOut.ti,dataOut.eti,dataOut.ph,dataOut.eph,dataOut.phe,dataOut.ephe,dataOut.range1,dataOut.ut,dataOut.NACF,dataOut.fit_array_real,dataOut.status,dataOut.NRANGE,dataOut.IBITS)
5907 '''
5911 '''
5908 if dataOut.status>=3.5:
5912 if dataOut.status>=3.5:
5909 dataOut.te[:]=numpy.nan
5913 dataOut.te[:]=numpy.nan
5910 dataOut.ete[:]=numpy.nan
5914 dataOut.ete[:]=numpy.nan
5911 dataOut.ti[:]=numpy.nan
5915 dataOut.ti[:]=numpy.nan
5912 dataOut.eti[:]=numpy.nan
5916 dataOut.eti[:]=numpy.nan
5913 dataOut.ph[:]=numpy.nan
5917 dataOut.ph[:]=numpy.nan
5914 dataOut.eph[:]=numpy.nan
5918 dataOut.eph[:]=numpy.nan
5915 dataOut.phe[:]=numpy.nan
5919 dataOut.phe[:]=numpy.nan
5916 dataOut.ephe[:]=numpy.nan
5920 dataOut.ephe[:]=numpy.nan
5917 '''
5921 '''
5918 return dataOut
5922 return dataOut
5919
5923
5920
5924
5921 class PulsePairVoltage(Operation):
5925 class PulsePairVoltage(Operation):
5922 '''
5926 '''
5923 Function PulsePair(Signal Power, Velocity)
5927 Function PulsePair(Signal Power, Velocity)
5924 The real component of Lag[0] provides Intensity Information
5928 The real component of Lag[0] provides Intensity Information
5925 The imag component of Lag[1] Phase provides Velocity Information
5929 The imag component of Lag[1] Phase provides Velocity Information
5926
5930
5927 Configuration Parameters:
5931 Configuration Parameters:
5928 nPRF = Number of Several PRF
5932 nPRF = Number of Several PRF
5929 theta = Degree Azimuth angel Boundaries
5933 theta = Degree Azimuth angel Boundaries
5930
5934
5931 Input:
5935 Input:
5932 self.dataOut
5936 self.dataOut
5933 lag[N]
5937 lag[N]
5934 Affected:
5938 Affected:
5935 self.dataOut.spc
5939 self.dataOut.spc
5936 '''
5940 '''
5937 isConfig = False
5941 isConfig = False
5938 __profIndex = 0
5942 __profIndex = 0
5939 __initime = None
5943 __initime = None
5940 __lastdatatime = None
5944 __lastdatatime = None
5941 __buffer = None
5945 __buffer = None
5942 noise = None
5946 noise = None
5943 __dataReady = False
5947 __dataReady = False
5944 n = None
5948 n = None
5945 __nch = 0
5949 __nch = 0
5946 __nHeis = 0
5950 __nHeis = 0
5947 removeDC = False
5951 removeDC = False
5948 ipp = None
5952 ipp = None
5949 lambda_ = 0
5953 lambda_ = 0
5950
5954
5951 def __init__(self,**kwargs):
5955 def __init__(self,**kwargs):
5952 Operation.__init__(self,**kwargs)
5956 Operation.__init__(self,**kwargs)
5953
5957
5954 def setup(self, dataOut, n = None, removeDC=False):
5958 def setup(self, dataOut, n = None, removeDC=False):
5955 '''
5959 '''
5956 n= Numero de PRF's de entrada
5960 n= Numero de PRF's de entrada
5957 '''
5961 '''
5958 self.__initime = None
5962 self.__initime = None
5959 self.__lastdatatime = 0
5963 self.__lastdatatime = 0
5960 self.__dataReady = False
5964 self.__dataReady = False
5961 self.__buffer = 0
5965 self.__buffer = 0
5962 self.__profIndex = 0
5966 self.__profIndex = 0
5963 self.noise = None
5967 self.noise = None
5964 self.__nch = dataOut.nChannels
5968 self.__nch = dataOut.nChannels
5965 self.__nHeis = dataOut.nHeights
5969 self.__nHeis = dataOut.nHeights
5966 self.removeDC = removeDC
5970 self.removeDC = removeDC
5967 self.lambda_ = 3.0e8/(9345.0e6)
5971 self.lambda_ = 3.0e8/(9345.0e6)
5968 self.ippSec = dataOut.ippSeconds
5972 self.ippSec = dataOut.ippSeconds
5969 self.nCohInt = dataOut.nCohInt
5973 self.nCohInt = dataOut.nCohInt
5970 print("IPPseconds",dataOut.ippSeconds)
5974 print("IPPseconds",dataOut.ippSeconds)
5971
5975
5972 print("ELVALOR DE n es:", n)
5976 print("ELVALOR DE n es:", n)
5973 if n == None:
5977 if n == None:
5974 raise ValueError("n should be specified.")
5978 raise ValueError("n should be specified.")
5975
5979
5976 if n != None:
5980 if n != None:
5977 if n<2:
5981 if n<2:
5978 raise ValueError("n should be greater than 2")
5982 raise ValueError("n should be greater than 2")
5979
5983
5980 self.n = n
5984 self.n = n
5981 self.__nProf = n
5985 self.__nProf = n
5982
5986
5983 self.__buffer = numpy.zeros((dataOut.nChannels,
5987 self.__buffer = numpy.zeros((dataOut.nChannels,
5984 n,
5988 n,
5985 dataOut.nHeights),
5989 dataOut.nHeights),
5986 dtype='complex')
5990 dtype='complex')
5987
5991
5988 def putData(self,data):
5992 def putData(self,data):
5989 '''
5993 '''
5990 Add a profile to he __buffer and increase in one the __profiel Index
5994 Add a profile to he __buffer and increase in one the __profiel Index
5991 '''
5995 '''
5992 self.__buffer[:,self.__profIndex,:]= data
5996 self.__buffer[:,self.__profIndex,:]= data
5993 self.__profIndex += 1
5997 self.__profIndex += 1
5994 return
5998 return
5995
5999
5996 def pushData(self,dataOut):
6000 def pushData(self,dataOut):
5997 '''
6001 '''
5998 Return the PULSEPAIR and the profiles used in the operation
6002 Return the PULSEPAIR and the profiles used in the operation
5999 Affected : self.__profileIndex
6003 Affected : self.__profileIndex
6000 '''
6004 '''
6001 #----------------- Remove DC-----------------------------------
6005 #----------------- Remove DC-----------------------------------
6002 if self.removeDC==True:
6006 if self.removeDC==True:
6003 mean = numpy.mean(self.__buffer,1)
6007 mean = numpy.mean(self.__buffer,1)
6004 tmp = mean.reshape(self.__nch,1,self.__nHeis)
6008 tmp = mean.reshape(self.__nch,1,self.__nHeis)
6005 dc= numpy.tile(tmp,[1,self.__nProf,1])
6009 dc= numpy.tile(tmp,[1,self.__nProf,1])
6006 self.__buffer = self.__buffer - dc
6010 self.__buffer = self.__buffer - dc
6007 #------------------Calculo de Potencia ------------------------
6011 #------------------Calculo de Potencia ------------------------
6008 pair0 = self.__buffer*numpy.conj(self.__buffer)
6012 pair0 = self.__buffer*numpy.conj(self.__buffer)
6009 pair0 = pair0.real
6013 pair0 = pair0.real
6010 lag_0 = numpy.sum(pair0,1)
6014 lag_0 = numpy.sum(pair0,1)
6011 #------------------Calculo de Ruido x canal--------------------
6015 #------------------Calculo de Ruido x canal--------------------
6012 self.noise = numpy.zeros(self.__nch)
6016 self.noise = numpy.zeros(self.__nch)
6013 for i in range(self.__nch):
6017 for i in range(self.__nch):
6014 daux = numpy.sort(pair0[i,:,:],axis= None)
6018 daux = numpy.sort(pair0[i,:,:],axis= None)
6015 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
6019 self.noise[i]=hildebrand_sekhon( daux ,self.nCohInt)
6016
6020
6017 self.noise = self.noise.reshape(self.__nch,1)
6021 self.noise = self.noise.reshape(self.__nch,1)
6018 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
6022 self.noise = numpy.tile(self.noise,[1,self.__nHeis])
6019 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
6023 noise_buffer = self.noise.reshape(self.__nch,1,self.__nHeis)
6020 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
6024 noise_buffer = numpy.tile(noise_buffer,[1,self.__nProf,1])
6021 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
6025 #------------------ Potencia recibida= P , Potencia senal = S , Ruido= N--
6022 #------------------ P= S+N ,P=lag_0/N ---------------------------------
6026 #------------------ P= S+N ,P=lag_0/N ---------------------------------
6023 #-------------------- Power --------------------------------------------------
6027 #-------------------- Power --------------------------------------------------
6024 data_power = lag_0/(self.n*self.nCohInt)
6028 data_power = lag_0/(self.n*self.nCohInt)
6025 #------------------ Senal ---------------------------------------------------
6029 #------------------ Senal ---------------------------------------------------
6026 data_intensity = pair0 - noise_buffer
6030 data_intensity = pair0 - noise_buffer
6027 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
6031 data_intensity = numpy.sum(data_intensity,axis=1)*(self.n*self.nCohInt)#*self.nCohInt)
6028 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
6032 #data_intensity = (lag_0-self.noise*self.n)*(self.n*self.nCohInt)
6029 for i in range(self.__nch):
6033 for i in range(self.__nch):
6030 for j in range(self.__nHeis):
6034 for j in range(self.__nHeis):
6031 if data_intensity[i][j] < 0:
6035 if data_intensity[i][j] < 0:
6032 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
6036 data_intensity[i][j] = numpy.min(numpy.absolute(data_intensity[i][j]))
6033
6037
6034 #----------------- Calculo de Frecuencia y Velocidad doppler--------
6038 #----------------- Calculo de Frecuencia y Velocidad doppler--------
6035 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
6039 pair1 = self.__buffer[:,:-1,:]*numpy.conjugate(self.__buffer[:,1:,:])
6036 lag_1 = numpy.sum(pair1,1)
6040 lag_1 = numpy.sum(pair1,1)
6037 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
6041 data_freq = (-1/(2.0*math.pi*self.ippSec*self.nCohInt))*numpy.angle(lag_1)
6038 data_velocity = (self.lambda_/2.0)*data_freq
6042 data_velocity = (self.lambda_/2.0)*data_freq
6039
6043
6040 #---------------- Potencia promedio estimada de la Senal-----------
6044 #---------------- Potencia promedio estimada de la Senal-----------
6041 lag_0 = lag_0/self.n
6045 lag_0 = lag_0/self.n
6042 S = lag_0-self.noise
6046 S = lag_0-self.noise
6043
6047
6044 #---------------- Frecuencia Doppler promedio ---------------------
6048 #---------------- Frecuencia Doppler promedio ---------------------
6045 lag_1 = lag_1/(self.n-1)
6049 lag_1 = lag_1/(self.n-1)
6046 R1 = numpy.abs(lag_1)
6050 R1 = numpy.abs(lag_1)
6047
6051
6048 #---------------- Calculo del SNR----------------------------------
6052 #---------------- Calculo del SNR----------------------------------
6049 data_snrPP = S/self.noise
6053 data_snrPP = S/self.noise
6050 for i in range(self.__nch):
6054 for i in range(self.__nch):
6051 for j in range(self.__nHeis):
6055 for j in range(self.__nHeis):
6052 if data_snrPP[i][j] < 1.e-20:
6056 if data_snrPP[i][j] < 1.e-20:
6053 data_snrPP[i][j] = 1.e-20
6057 data_snrPP[i][j] = 1.e-20
6054
6058
6055 #----------------- Calculo del ancho espectral ----------------------
6059 #----------------- Calculo del ancho espectral ----------------------
6056 L = S/R1
6060 L = S/R1
6057 L = numpy.where(L<0,1,L)
6061 L = numpy.where(L<0,1,L)
6058 L = numpy.log(L)
6062 L = numpy.log(L)
6059 tmp = numpy.sqrt(numpy.absolute(L))
6063 tmp = numpy.sqrt(numpy.absolute(L))
6060 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
6064 data_specwidth = (self.lambda_/(2*math.sqrt(2)*math.pi*self.ippSec*self.nCohInt))*tmp*numpy.sign(L)
6061 n = self.__profIndex
6065 n = self.__profIndex
6062
6066
6063 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
6067 self.__buffer = numpy.zeros((self.__nch, self.__nProf,self.__nHeis), dtype='complex')
6064 self.__profIndex = 0
6068 self.__profIndex = 0
6065 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
6069 return data_power,data_intensity,data_velocity,data_snrPP,data_specwidth,n
6066
6070
6067
6071
6068 def pulsePairbyProfiles(self,dataOut):
6072 def pulsePairbyProfiles(self,dataOut):
6069
6073
6070 self.__dataReady = False
6074 self.__dataReady = False
6071 data_power = None
6075 data_power = None
6072 data_intensity = None
6076 data_intensity = None
6073 data_velocity = None
6077 data_velocity = None
6074 data_specwidth = None
6078 data_specwidth = None
6075 data_snrPP = None
6079 data_snrPP = None
6076 self.putData(data=dataOut.data)
6080 self.putData(data=dataOut.data)
6077 if self.__profIndex == self.n:
6081 if self.__profIndex == self.n:
6078 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
6082 data_power,data_intensity, data_velocity,data_snrPP,data_specwidth, n = self.pushData(dataOut=dataOut)
6079 self.__dataReady = True
6083 self.__dataReady = True
6080
6084
6081 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
6085 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth
6082
6086
6083
6087
6084 def pulsePairOp(self, dataOut, datatime= None):
6088 def pulsePairOp(self, dataOut, datatime= None):
6085
6089
6086 if self.__initime == None:
6090 if self.__initime == None:
6087 self.__initime = datatime
6091 self.__initime = datatime
6088 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
6092 data_power, data_intensity, data_velocity, data_snrPP, data_specwidth = self.pulsePairbyProfiles(dataOut)
6089 self.__lastdatatime = datatime
6093 self.__lastdatatime = datatime
6090
6094
6091 if data_power is None:
6095 if data_power is None:
6092 return None, None, None,None,None,None
6096 return None, None, None,None,None,None
6093
6097
6094 avgdatatime = self.__initime
6098 avgdatatime = self.__initime
6095 deltatime = datatime - self.__lastdatatime
6099 deltatime = datatime - self.__lastdatatime
6096 self.__initime = datatime
6100 self.__initime = datatime
6097
6101
6098 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
6102 return data_power, data_intensity, data_velocity, data_snrPP, data_specwidth, avgdatatime
6099
6103
6100 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
6104 def run(self, dataOut,n = None,removeDC= False, overlapping= False,**kwargs):
6101
6105
6102 if not self.isConfig:
6106 if not self.isConfig:
6103 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
6107 self.setup(dataOut = dataOut, n = n , removeDC=removeDC , **kwargs)
6104 self.isConfig = True
6108 self.isConfig = True
6105 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
6109 data_power, data_intensity, data_velocity,data_snrPP,data_specwidth, avgdatatime = self.pulsePairOp(dataOut, dataOut.utctime)
6106 dataOut.flagNoData = True
6110 dataOut.flagNoData = True
6107
6111
6108 if self.__dataReady:
6112 if self.__dataReady:
6109 dataOut.nCohInt *= self.n
6113 dataOut.nCohInt *= self.n
6110 dataOut.dataPP_POW = data_intensity # S
6114 dataOut.dataPP_POW = data_intensity # S
6111 dataOut.dataPP_POWER = data_power # P
6115 dataOut.dataPP_POWER = data_power # P
6112 dataOut.dataPP_DOP = data_velocity
6116 dataOut.dataPP_DOP = data_velocity
6113 dataOut.dataPP_SNR = data_snrPP
6117 dataOut.dataPP_SNR = data_snrPP
6114 dataOut.dataPP_WIDTH = data_specwidth
6118 dataOut.dataPP_WIDTH = data_specwidth
6115 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
6119 dataOut.PRFbyAngle = self.n #numero de PRF*cada angulo rotado que equivale a un tiempo.
6116 dataOut.utctime = avgdatatime
6120 dataOut.utctime = avgdatatime
6117 dataOut.flagNoData = False
6121 dataOut.flagNoData = False
6118 return dataOut
6122 return dataOut
6119
6123
6120
6124
6121
6125
6122 # import collections
6126 # import collections
6123 # from scipy.stats import mode
6127 # from scipy.stats import mode
6124 #
6128 #
6125 # class Synchronize(Operation):
6129 # class Synchronize(Operation):
6126 #
6130 #
6127 # isConfig = False
6131 # isConfig = False
6128 # __profIndex = 0
6132 # __profIndex = 0
6129 #
6133 #
6130 # def __init__(self, **kwargs):
6134 # def __init__(self, **kwargs):
6131 #
6135 #
6132 # Operation.__init__(self, **kwargs)
6136 # Operation.__init__(self, **kwargs)
6133 # # self.isConfig = False
6137 # # self.isConfig = False
6134 # self.__powBuffer = None
6138 # self.__powBuffer = None
6135 # self.__startIndex = 0
6139 # self.__startIndex = 0
6136 # self.__pulseFound = False
6140 # self.__pulseFound = False
6137 #
6141 #
6138 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
6142 # def __findTxPulse(self, dataOut, channel=0, pulse_with = None):
6139 #
6143 #
6140 # #Read data
6144 # #Read data
6141 #
6145 #
6142 # powerdB = dataOut.getPower(channel = channel)
6146 # powerdB = dataOut.getPower(channel = channel)
6143 # noisedB = dataOut.getNoise(channel = channel)[0]
6147 # noisedB = dataOut.getNoise(channel = channel)[0]
6144 #
6148 #
6145 # self.__powBuffer.extend(powerdB.flatten())
6149 # self.__powBuffer.extend(powerdB.flatten())
6146 #
6150 #
6147 # dataArray = numpy.array(self.__powBuffer)
6151 # dataArray = numpy.array(self.__powBuffer)
6148 #
6152 #
6149 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
6153 # filteredPower = numpy.correlate(dataArray, dataArray[0:self.__nSamples], "same")
6150 #
6154 #
6151 # maxValue = numpy.nanmax(filteredPower)
6155 # maxValue = numpy.nanmax(filteredPower)
6152 #
6156 #
6153 # if maxValue < noisedB + 10:
6157 # if maxValue < noisedB + 10:
6154 # #No se encuentra ningun pulso de transmision
6158 # #No se encuentra ningun pulso de transmision
6155 # return None
6159 # return None
6156 #
6160 #
6157 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
6161 # maxValuesIndex = numpy.where(filteredPower > maxValue - 0.1*abs(maxValue))[0]
6158 #
6162 #
6159 # if len(maxValuesIndex) < 2:
6163 # if len(maxValuesIndex) < 2:
6160 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
6164 # #Solo se encontro un solo pulso de transmision de un baudio, esperando por el siguiente TX
6161 # return None
6165 # return None
6162 #
6166 #
6163 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
6167 # phasedMaxValuesIndex = maxValuesIndex - self.__nSamples
6164 #
6168 #
6165 # #Seleccionar solo valores con un espaciamiento de nSamples
6169 # #Seleccionar solo valores con un espaciamiento de nSamples
6166 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
6170 # pulseIndex = numpy.intersect1d(maxValuesIndex, phasedMaxValuesIndex)
6167 #
6171 #
6168 # if len(pulseIndex) < 2:
6172 # if len(pulseIndex) < 2:
6169 # #Solo se encontro un pulso de transmision con ancho mayor a 1
6173 # #Solo se encontro un pulso de transmision con ancho mayor a 1
6170 # return None
6174 # return None
6171 #
6175 #
6172 # spacing = pulseIndex[1:] - pulseIndex[:-1]
6176 # spacing = pulseIndex[1:] - pulseIndex[:-1]
6173 #
6177 #
6174 # #remover senales que se distancien menos de 10 unidades o muestras
6178 # #remover senales que se distancien menos de 10 unidades o muestras
6175 # #(No deberian existir IPP menor a 10 unidades)
6179 # #(No deberian existir IPP menor a 10 unidades)
6176 #
6180 #
6177 # realIndex = numpy.where(spacing > 10 )[0]
6181 # realIndex = numpy.where(spacing > 10 )[0]
6178 #
6182 #
6179 # if len(realIndex) < 2:
6183 # if len(realIndex) < 2:
6180 # #Solo se encontro un pulso de transmision con ancho mayor a 1
6184 # #Solo se encontro un pulso de transmision con ancho mayor a 1
6181 # return None
6185 # return None
6182 #
6186 #
6183 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
6187 # #Eliminar pulsos anchos (deja solo la diferencia entre IPPs)
6184 # realPulseIndex = pulseIndex[realIndex]
6188 # realPulseIndex = pulseIndex[realIndex]
6185 #
6189 #
6186 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
6190 # period = mode(realPulseIndex[1:] - realPulseIndex[:-1])[0][0]
6187 #
6191 #
6188 # print "IPP = %d samples" %period
6192 # print "IPP = %d samples" %period
6189 #
6193 #
6190 # self.__newNSamples = dataOut.nHeights #int(period)
6194 # self.__newNSamples = dataOut.nHeights #int(period)
6191 # self.__startIndex = int(realPulseIndex[0])
6195 # self.__startIndex = int(realPulseIndex[0])
6192 #
6196 #
6193 # return 1
6197 # return 1
6194 #
6198 #
6195 #
6199 #
6196 # def setup(self, nSamples, nChannels, buffer_size = 4):
6200 # def setup(self, nSamples, nChannels, buffer_size = 4):
6197 #
6201 #
6198 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
6202 # self.__powBuffer = collections.deque(numpy.zeros( buffer_size*nSamples,dtype=numpy.float),
6199 # maxlen = buffer_size*nSamples)
6203 # maxlen = buffer_size*nSamples)
6200 #
6204 #
6201 # bufferList = []
6205 # bufferList = []
6202 #
6206 #
6203 # for i in range(nChannels):
6207 # for i in range(nChannels):
6204 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
6208 # bufferByChannel = collections.deque(numpy.zeros( buffer_size*nSamples, dtype=numpy.complex) + numpy.NAN,
6205 # maxlen = buffer_size*nSamples)
6209 # maxlen = buffer_size*nSamples)
6206 #
6210 #
6207 # bufferList.append(bufferByChannel)
6211 # bufferList.append(bufferByChannel)
6208 #
6212 #
6209 # self.__nSamples = nSamples
6213 # self.__nSamples = nSamples
6210 # self.__nChannels = nChannels
6214 # self.__nChannels = nChannels
6211 # self.__bufferList = bufferList
6215 # self.__bufferList = bufferList
6212 #
6216 #
6213 # def run(self, dataOut, channel = 0):
6217 # def run(self, dataOut, channel = 0):
6214 #
6218 #
6215 # if not self.isConfig:
6219 # if not self.isConfig:
6216 # nSamples = dataOut.nHeights
6220 # nSamples = dataOut.nHeights
6217 # nChannels = dataOut.nChannels
6221 # nChannels = dataOut.nChannels
6218 # self.setup(nSamples, nChannels)
6222 # self.setup(nSamples, nChannels)
6219 # self.isConfig = True
6223 # self.isConfig = True
6220 #
6224 #
6221 # #Append new data to internal buffer
6225 # #Append new data to internal buffer
6222 # for thisChannel in range(self.__nChannels):
6226 # for thisChannel in range(self.__nChannels):
6223 # bufferByChannel = self.__bufferList[thisChannel]
6227 # bufferByChannel = self.__bufferList[thisChannel]
6224 # bufferByChannel.extend(dataOut.data[thisChannel])
6228 # bufferByChannel.extend(dataOut.data[thisChannel])
6225 #
6229 #
6226 # if self.__pulseFound:
6230 # if self.__pulseFound:
6227 # self.__startIndex -= self.__nSamples
6231 # self.__startIndex -= self.__nSamples
6228 #
6232 #
6229 # #Finding Tx Pulse
6233 # #Finding Tx Pulse
6230 # if not self.__pulseFound:
6234 # if not self.__pulseFound:
6231 # indexFound = self.__findTxPulse(dataOut, channel)
6235 # indexFound = self.__findTxPulse(dataOut, channel)
6232 #
6236 #
6233 # if indexFound == None:
6237 # if indexFound == None:
6234 # dataOut.flagNoData = True
6238 # dataOut.flagNoData = True
6235 # return
6239 # return
6236 #
6240 #
6237 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
6241 # self.__arrayBuffer = numpy.zeros((self.__nChannels, self.__newNSamples), dtype = numpy.complex)
6238 # self.__pulseFound = True
6242 # self.__pulseFound = True
6239 # self.__startIndex = indexFound
6243 # self.__startIndex = indexFound
6240 #
6244 #
6241 # #If pulse was found ...
6245 # #If pulse was found ...
6242 # for thisChannel in range(self.__nChannels):
6246 # for thisChannel in range(self.__nChannels):
6243 # bufferByChannel = self.__bufferList[thisChannel]
6247 # bufferByChannel = self.__bufferList[thisChannel]
6244 # #print self.__startIndex
6248 # #print self.__startIndex
6245 # x = numpy.array(bufferByChannel)
6249 # x = numpy.array(bufferByChannel)
6246 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
6250 # self.__arrayBuffer[thisChannel] = x[self.__startIndex:self.__startIndex+self.__newNSamples]
6247 #
6251 #
6248 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
6252 # deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
6249 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
6253 # dataOut.heightList = numpy.arange(self.__newNSamples)*deltaHeight
6250 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
6254 # # dataOut.ippSeconds = (self.__newNSamples / deltaHeight)/1e6
6251 #
6255 #
6252 # dataOut.data = self.__arrayBuffer
6256 # dataOut.data = self.__arrayBuffer
6253 #
6257 #
6254 # self.__startIndex += self.__newNSamples
6258 # self.__startIndex += self.__newNSamples
6255 #
6259 #
6256 # return
6260 # return
General Comments 0
You need to be logged in to leave comments. Login now