##// END OF EJS Templates
update
rflores -
r1727:66f67e6e4b37
parent child
Show More

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

@@ -1,1348 +1,1349
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 #import collections.abc
11 #import collections.abc
12
12
13 from schainpy.model.graphics.jroplot_base import Plot, plt, log
13 from schainpy.model.graphics.jroplot_base import Plot, plt, log
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
43
44 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
44 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
45 #print("dataOut.normFactor: ", dataOut.normFactor)
45 #print("dataOut.normFactor: ", dataOut.normFactor)
46 #print("spc: ", dataOut.data_spc[0,0,0])
46 #print("spc: ", dataOut.data_spc[0,0,0])
47 #spc = 10*numpy.log10(dataOut.data_spc)
47 #spc = 10*numpy.log10(dataOut.data_spc)
48 #print("Spc: ",spc[0])
48 #print("Spc: ",spc[0])
49 #exit(1)
49 #exit(1)
50 data['spc'] = spc
50 data['spc'] = spc
51 data['rti'] = dataOut.getPower()
51 data['rti'] = dataOut.getPower()
52 #print(data['rti'][0])
52 #print(data['rti'][0])
53 #exit(1)
53 #exit(1)
54 #print("NormFactor: ",dataOut.normFactor)
54 #print("NormFactor: ",dataOut.normFactor)
55 #data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
55 #data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
56 if hasattr(dataOut, 'LagPlot'): #Double Pulse
56 if hasattr(dataOut, 'LagPlot'): #Double Pulse
57 max_hei_id = dataOut.nHeights - 2*dataOut.LagPlot
57 max_hei_id = dataOut.nHeights - 2*dataOut.LagPlot
58 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=46,ymax_index=max_hei_id)/dataOut.normFactor)
58 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=46,ymax_index=max_hei_id)/dataOut.normFactor)
59 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=40,ymax_index=max_hei_id)/dataOut.normFactor)
59 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=40,ymax_index=max_hei_id)/dataOut.normFactor)
60 data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=53,ymax_index=max_hei_id)/dataOut.normFactor)
60 data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=53,ymax_index=max_hei_id)/dataOut.normFactor)
61 data['noise'][0] = 10*numpy.log10(dataOut.getNoise(ymin_index=53)[0]/dataOut.normFactor)
61 data['noise'][0] = 10*numpy.log10(dataOut.getNoise(ymin_index=53)[0]/dataOut.normFactor)
62 #data['noise'][1] = 22.035507
62 #data['noise'][1] = 22.035507
63 else:
63 else:
64 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
64 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
65 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=26,ymax_index=44)/dataOut.normFactor)
65 #data['noise'] = 10*numpy.log10(dataOut.getNoise(ymin_index=26,ymax_index=44)/dataOut.normFactor)
66 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
66 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
67
67
68 if self.CODE == 'spc_moments':
68 if self.CODE == 'spc_moments':
69 data['moments'] = dataOut.moments
69 data['moments'] = dataOut.moments
70 if self.CODE == 'gaussian_fit':
70 if self.CODE == 'gaussian_fit':
71 data['gaussfit'] = dataOut.DGauFitParams
71 data['gaussfit'] = dataOut.DGauFitParams
72
72
73 return data, meta
73 return data, meta
74
74
75 def plot(self):
75 def plot(self):
76
76
77 if self.xaxis == "frequency":
77 if self.xaxis == "frequency":
78 x = self.data.xrange[0]
78 x = self.data.xrange[0]
79 self.xlabel = "Frequency (kHz)"
79 self.xlabel = "Frequency (kHz)"
80 elif self.xaxis == "time":
80 elif self.xaxis == "time":
81 x = self.data.xrange[1]
81 x = self.data.xrange[1]
82 self.xlabel = "Time (ms)"
82 self.xlabel = "Time (ms)"
83 else:
83 else:
84 x = self.data.xrange[2]
84 x = self.data.xrange[2]
85 self.xlabel = "Velocity (m/s)"
85 self.xlabel = "Velocity (m/s)"
86
86
87 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
87 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
88 x = self.data.xrange[2]
88 x = self.data.xrange[2]
89 self.xlabel = "Velocity (m/s)"
89 self.xlabel = "Velocity (m/s)"
90
90
91 self.titles = []
91 self.titles = []
92
92
93 y = self.data.yrange
93 y = self.data.yrange
94 self.y = y
94 self.y = y
95
95
96 data = self.data[-1]
96 data = self.data[-1]
97 z = data['spc']
97 z = data['spc']
98
98
99 self.CODE2 = 'spc_oblique'
99 self.CODE2 = 'spc_oblique'
100
100
101 for n, ax in enumerate(self.axes):
101 for n, ax in enumerate(self.axes):
102 noise = data['noise'][n]
102 noise = data['noise'][n]
103 if self.CODE == 'spc_moments':
103 if self.CODE == 'spc_moments':
104 mean = data['moments'][n, 1]
104 mean = data['moments'][n, 1]
105 if self.CODE == 'gaussian_fit':
105 if self.CODE == 'gaussian_fit':
106 gau0 = data['gaussfit'][n][2,:,0]
106 gau0 = data['gaussfit'][n][2,:,0]
107 gau1 = data['gaussfit'][n][2,:,1]
107 gau1 = data['gaussfit'][n][2,:,1]
108 if ax.firsttime:
108 if ax.firsttime:
109 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
109 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
110 self.xmin = self.xmin if self.xmin else numpy.nanmin(x)#-self.xmax
110 self.xmin = self.xmin if self.xmin else numpy.nanmin(x)#-self.xmax
111 #self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
111 #self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
112 #self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
112 #self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
113 if self.zlimits is not None:
113 if self.zlimits is not None:
114 self.zmin, self.zmax = self.zlimits[n]
114 self.zmin, self.zmax = self.zlimits[n]
115
115
116 ax.plt = ax.pcolormesh(x, y, z[n].T,
116 ax.plt = ax.pcolormesh(x, y, z[n].T,
117 vmin=self.zmin,
117 vmin=self.zmin,
118 vmax=self.zmax,
118 vmax=self.zmax,
119 cmap=plt.get_cmap(self.colormap),
119 cmap=plt.get_cmap(self.colormap),
120 )
120 )
121
121
122 if self.showprofile:
122 if self.showprofile:
123 ax.plt_profile = self.pf_axes[n].plot(
123 ax.plt_profile = self.pf_axes[n].plot(
124 data['rti'][n], y)[0]
124 data['rti'][n], y)[0]
125 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
125 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
126 color="k", linestyle="dashed", lw=1)[0]
126 color="k", linestyle="dashed", lw=1)[0]
127 if self.CODE == 'spc_moments':
127 if self.CODE == 'spc_moments':
128 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
128 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
129 if self.CODE == 'gaussian_fit':
129 if self.CODE == 'gaussian_fit':
130 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
130 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
131 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
131 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
132 else:
132 else:
133 if self.zlimits is not None:
133 if self.zlimits is not None:
134 self.zmin, self.zmax = self.zlimits[n]
134 self.zmin, self.zmax = self.zlimits[n]
135 ax.plt.set_array(z[n].T.ravel())
135 ax.plt.set_array(z[n].T.ravel())
136 if self.showprofile:
136 if self.showprofile:
137 ax.plt_profile.set_data(data['rti'][n], y)
137 ax.plt_profile.set_data(data['rti'][n], y)
138 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
138 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
139 if self.CODE == 'spc_moments':
139 if self.CODE == 'spc_moments':
140 ax.plt_mean.set_data(mean, y)
140 ax.plt_mean.set_data(mean, y)
141 if self.CODE == 'gaussian_fit':
141 if self.CODE == 'gaussian_fit':
142 ax.plt_gau0.set_data(gau0, y)
142 ax.plt_gau0.set_data(gau0, y)
143 ax.plt_gau1.set_data(gau1, y)
143 ax.plt_gau1.set_data(gau1, y)
144 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
144 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
145
145
146 class SpectraObliquePlot(Plot):
146 class SpectraObliquePlot(Plot):
147 '''
147 '''
148 Plot for Spectra data
148 Plot for Spectra data
149 '''
149 '''
150
150
151 CODE = 'spc_oblique'
151 CODE = 'spc_oblique'
152 colormap = 'jet'
152 colormap = 'jet'
153 plot_type = 'pcolor'
153 plot_type = 'pcolor'
154
154
155 def setup(self):
155 def setup(self):
156 self.xaxis = "oblique"
156 self.xaxis = "oblique"
157 self.nplots = len(self.data.channels)
157 self.nplots = len(self.data.channels)
158 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
158 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
159 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
159 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
160 self.height = 2.6 * self.nrows
160 self.height = 2.6 * self.nrows
161 self.cb_label = 'dB'
161 self.cb_label = 'dB'
162 if self.showprofile:
162 if self.showprofile:
163 self.width = 4 * self.ncols
163 self.width = 4 * self.ncols
164 else:
164 else:
165 self.width = 3.5 * self.ncols
165 self.width = 3.5 * self.ncols
166 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
166 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
167 self.ylabel = 'Range [km]'
167 self.ylabel = 'Range [km]'
168
168
169 def update(self, dataOut):
169 def update(self, dataOut):
170
170
171 data = {}
171 data = {}
172 meta = {}
172 meta = {}
173
173
174 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
174 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
175 data['spc'] = spc
175 data['spc'] = spc
176 data['rti'] = dataOut.getPower()
176 data['rti'] = dataOut.getPower()
177 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
177 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
178 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
178 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
179 '''
179 '''
180 data['shift1'] = dataOut.Oblique_params[0,-2,:]
180 data['shift1'] = dataOut.Oblique_params[0,-2,:]
181 data['shift2'] = dataOut.Oblique_params[0,-1,:]
181 data['shift2'] = dataOut.Oblique_params[0,-1,:]
182 data['shift1_error'] = dataOut.Oblique_param_errors[0,-2,:]
182 data['shift1_error'] = dataOut.Oblique_param_errors[0,-2,:]
183 data['shift2_error'] = dataOut.Oblique_param_errors[0,-1,:]
183 data['shift2_error'] = dataOut.Oblique_param_errors[0,-1,:]
184 '''
184 '''
185 '''
185 '''
186 data['shift1'] = dataOut.Oblique_params[0,1,:]
186 data['shift1'] = dataOut.Oblique_params[0,1,:]
187 data['shift2'] = dataOut.Oblique_params[0,4,:]
187 data['shift2'] = dataOut.Oblique_params[0,4,:]
188 data['shift1_error'] = dataOut.Oblique_param_errors[0,1,:]
188 data['shift1_error'] = dataOut.Oblique_param_errors[0,1,:]
189 data['shift2_error'] = dataOut.Oblique_param_errors[0,4,:]
189 data['shift2_error'] = dataOut.Oblique_param_errors[0,4,:]
190 '''
190 '''
191 data['shift1'] = dataOut.Dop_EEJ_T1[0]
191 data['shift1'] = dataOut.Dop_EEJ_T1[0]
192 data['shift2'] = dataOut.Dop_EEJ_T2[0]
192 data['shift2'] = dataOut.Dop_EEJ_T2[0]
193 data['max_val_2'] = dataOut.Oblique_params[0,-1,:]
193 data['max_val_2'] = dataOut.Oblique_params[0,-1,:]
194 data['shift1_error'] = dataOut.Err_Dop_EEJ_T1[0]
194 data['shift1_error'] = dataOut.Err_Dop_EEJ_T1[0]
195 data['shift2_error'] = dataOut.Err_Dop_EEJ_T2[0]
195 data['shift2_error'] = dataOut.Err_Dop_EEJ_T2[0]
196
196
197 return data, meta
197 return data, meta
198
198
199 def plot(self):
199 def plot(self):
200
200
201 if self.xaxis == "frequency":
201 if self.xaxis == "frequency":
202 x = self.data.xrange[0]
202 x = self.data.xrange[0]
203 self.xlabel = "Frequency (kHz)"
203 self.xlabel = "Frequency (kHz)"
204 elif self.xaxis == "time":
204 elif self.xaxis == "time":
205 x = self.data.xrange[1]
205 x = self.data.xrange[1]
206 self.xlabel = "Time (ms)"
206 self.xlabel = "Time (ms)"
207 else:
207 else:
208 x = self.data.xrange[2]
208 x = self.data.xrange[2]
209 self.xlabel = "Velocity (m/s)"
209 self.xlabel = "Velocity (m/s)"
210
210
211 self.titles = []
211 self.titles = []
212
212
213 y = self.data.yrange
213 y = self.data.yrange
214 self.y = y
214 self.y = y
215
215
216 data = self.data[-1]
216 data = self.data[-1]
217 z = data['spc']
217 z = data['spc']
218
218
219 for n, ax in enumerate(self.axes):
219 for n, ax in enumerate(self.axes):
220 noise = self.data['noise'][n][-1]
220 noise = self.data['noise'][n][-1]
221 shift1 = data['shift1']
221 shift1 = data['shift1']
222 #print(shift1)
222 #print(shift1)
223 shift2 = data['shift2']
223 shift2 = data['shift2']
224 max_val_2 = data['max_val_2']
224 max_val_2 = data['max_val_2']
225 err1 = data['shift1_error']
225 err1 = data['shift1_error']
226 err2 = data['shift2_error']
226 err2 = data['shift2_error']
227 if ax.firsttime:
227 if ax.firsttime:
228
228
229 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
229 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
230 self.xmin = self.xmin if self.xmin else -self.xmax
230 self.xmin = self.xmin if self.xmin else -self.xmax
231 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
231 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
232 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
232 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
233 ax.plt = ax.pcolormesh(x, y, z[n].T,
233 ax.plt = ax.pcolormesh(x, y, z[n].T,
234 vmin=self.zmin,
234 vmin=self.zmin,
235 vmax=self.zmax,
235 vmax=self.zmax,
236 cmap=plt.get_cmap(self.colormap)
236 cmap=plt.get_cmap(self.colormap)
237 )
237 )
238
238
239 if self.showprofile:
239 if self.showprofile:
240 ax.plt_profile = self.pf_axes[n].plot(
240 ax.plt_profile = self.pf_axes[n].plot(
241 self.data['rti'][n][-1], y)[0]
241 self.data['rti'][n][-1], y)[0]
242 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
242 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
243 color="k", linestyle="dashed", lw=1)[0]
243 color="k", linestyle="dashed", lw=1)[0]
244
244
245 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=2.2, marker='o', linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
245 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=2.2, marker='o', linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
246 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
246 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
247 self.ploterr3 = ax.errorbar(max_val_2, y, xerr=0, fmt='g^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
247 self.ploterr3 = ax.errorbar(max_val_2, y, xerr=0, fmt='g^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
248
248
249 #print("plotter1: ", self.ploterr1,shift1)
249 #print("plotter1: ", self.ploterr1,shift1)
250
250
251 else:
251 else:
252 #print("else plotter1: ", self.ploterr1,shift1)
252 #print("else plotter1: ", self.ploterr1,shift1)
253 self.ploterr1.remove()
253 self.ploterr1.remove()
254 self.ploterr2.remove()
254 self.ploterr2.remove()
255 self.ploterr3.remove()
255 self.ploterr3.remove()
256 ax.plt.set_array(z[n].T.ravel())
256 ax.plt.set_array(z[n].T.ravel())
257 if self.showprofile:
257 if self.showprofile:
258 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
258 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
259 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
259 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
260 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=2.2, marker='o', linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
260 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=2.2, marker='o', linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
261 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
261 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
262 self.ploterr3 = ax.errorbar(max_val_2, y, xerr=0, fmt='g^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
262 self.ploterr3 = ax.errorbar(max_val_2, y, xerr=0, fmt='g^',elinewidth=2.2,marker='o',linestyle='None',markersize=2.5,capsize=0.3,markeredgewidth=0.2)
263
263
264 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
264 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
265
265
266
266
267 class CrossSpectraPlot(Plot):
267 class CrossSpectraPlot(Plot):
268
268
269 CODE = 'cspc'
269 CODE = 'cspc'
270 colormap = 'jet'
270 colormap = 'jet'
271 plot_type = 'pcolor'
271 plot_type = 'pcolor'
272 zmin_coh = None
272 zmin_coh = None
273 zmax_coh = None
273 zmax_coh = None
274 zmin_phase = None
274 zmin_phase = None
275 zmax_phase = None
275 zmax_phase = None
276
276
277 def setup(self):
277 def setup(self):
278
278
279 self.ncols = 4
279 self.ncols = 4
280 self.nplots = len(self.data.pairs) * 2
280 self.nplots = len(self.data.pairs) * 2
281 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
281 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
282 self.width = 3.1 * self.ncols
282 self.width = 3.1 * self.ncols
283 self.height = 5 * self.nrows
283 self.height = 5 * self.nrows
284 self.ylabel = 'Range [km]'
284 self.ylabel = 'Range [km]'
285 self.showprofile = False
285 self.showprofile = False
286 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
286 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
287
287
288 def update(self, dataOut):
288 def update(self, dataOut):
289
289
290 data = {}
290 data = {}
291 meta = {}
291 meta = {}
292
292
293 spc = dataOut.data_spc
293 spc = dataOut.data_spc
294 cspc = dataOut.data_cspc
294 cspc = dataOut.data_cspc
295 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
295 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
296 meta['pairs'] = dataOut.pairsList
296 meta['pairs'] = dataOut.pairsList
297
297
298 tmp = []
298 tmp = []
299
299
300 for n, pair in enumerate(meta['pairs']):
300 for n, pair in enumerate(meta['pairs']):
301 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
301 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
302 coh = numpy.abs(out)
302 coh = numpy.abs(out)
303 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
303 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
304 tmp.append(coh)
304 tmp.append(coh)
305 tmp.append(phase)
305 tmp.append(phase)
306
306
307 data['cspc'] = numpy.array(tmp)
307 data['cspc'] = numpy.array(tmp)
308
308
309 return data, meta
309 return data, meta
310
310
311 def plot(self):
311 def plot(self):
312
312
313 if self.xaxis == "frequency":
313 if self.xaxis == "frequency":
314 x = self.data.xrange[0]
314 x = self.data.xrange[0]
315 self.xlabel = "Frequency (kHz)"
315 self.xlabel = "Frequency (kHz)"
316 elif self.xaxis == "time":
316 elif self.xaxis == "time":
317 x = self.data.xrange[1]
317 x = self.data.xrange[1]
318 self.xlabel = "Time (ms)"
318 self.xlabel = "Time (ms)"
319 else:
319 else:
320 x = self.data.xrange[2]
320 x = self.data.xrange[2]
321 self.xlabel = "Velocity (m/s)"
321 self.xlabel = "Velocity (m/s)"
322
322
323 self.titles = []
323 self.titles = []
324
324
325 y = self.data.yrange
325 y = self.data.yrange
326 self.y = y
326 self.y = y
327
327
328 data = self.data[-1]
328 data = self.data[-1]
329 cspc = data['cspc']
329 cspc = data['cspc']
330
330
331 for n in range(len(self.data.pairs)):
331 for n in range(len(self.data.pairs)):
332 pair = self.data.pairs[n]
332 pair = self.data.pairs[n]
333 coh = cspc[n*2]
333 coh = cspc[n*2]
334 phase = cspc[n*2+1]
334 phase = cspc[n*2+1]
335 ax = self.axes[2 * n]
335 ax = self.axes[2 * n]
336 if ax.firsttime:
336 if ax.firsttime:
337 ax.plt = ax.pcolormesh(x, y, coh.T,
337 ax.plt = ax.pcolormesh(x, y, coh.T,
338 vmin=0,
338 vmin=0,
339 vmax=1,
339 vmax=1,
340 cmap=plt.get_cmap(self.colormap_coh)
340 cmap=plt.get_cmap(self.colormap_coh)
341 )
341 )
342 else:
342 else:
343 ax.plt.set_array(coh.T.ravel())
343 ax.plt.set_array(coh.T.ravel())
344 self.titles.append(
344 self.titles.append(
345 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
345 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
346
346
347 ax = self.axes[2 * n + 1]
347 ax = self.axes[2 * n + 1]
348 if ax.firsttime:
348 if ax.firsttime:
349 ax.plt = ax.pcolormesh(x, y, phase.T,
349 ax.plt = ax.pcolormesh(x, y, phase.T,
350 vmin=-180,
350 vmin=-180,
351 vmax=180,
351 vmax=180,
352 cmap=plt.get_cmap(self.colormap_phase)
352 cmap=plt.get_cmap(self.colormap_phase)
353 )
353 )
354 else:
354 else:
355 ax.plt.set_array(phase.T.ravel())
355 ax.plt.set_array(phase.T.ravel())
356 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
356 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
357
357
358
358
359 class CrossSpectra4Plot(Plot):
359 class CrossSpectra4Plot(Plot):
360
360
361 CODE = 'cspc'
361 CODE = 'cspc'
362 colormap = 'jet'
362 colormap = 'jet'
363 plot_type = 'pcolor'
363 plot_type = 'pcolor'
364 zmin_coh = None
364 zmin_coh = None
365 zmax_coh = None
365 zmax_coh = None
366 zmin_phase = None
366 zmin_phase = None
367 zmax_phase = None
367 zmax_phase = None
368
368
369 def setup(self):
369 def setup(self):
370
370
371 self.ncols = 4
371 self.ncols = 4
372 self.nrows = len(self.data.pairs)
372 self.nrows = len(self.data.pairs)
373 self.nplots = self.nrows * 4
373 self.nplots = self.nrows * 4
374 self.width = 3.1 * self.ncols
374 self.width = 3.1 * self.ncols
375 self.height = 5 * self.nrows
375 self.height = 5 * self.nrows
376 self.ylabel = 'Range [km]'
376 self.ylabel = 'Range [km]'
377 self.showprofile = False
377 self.showprofile = False
378 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
378 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
379
379
380 def plot(self):
380 def plot(self):
381
381
382 if self.xaxis == "frequency":
382 if self.xaxis == "frequency":
383 x = self.data.xrange[0]
383 x = self.data.xrange[0]
384 self.xlabel = "Frequency (kHz)"
384 self.xlabel = "Frequency (kHz)"
385 elif self.xaxis == "time":
385 elif self.xaxis == "time":
386 x = self.data.xrange[1]
386 x = self.data.xrange[1]
387 self.xlabel = "Time (ms)"
387 self.xlabel = "Time (ms)"
388 else:
388 else:
389 x = self.data.xrange[2]
389 x = self.data.xrange[2]
390 self.xlabel = "Velocity (m/s)"
390 self.xlabel = "Velocity (m/s)"
391
391
392 self.titles = []
392 self.titles = []
393
393
394
394
395 y = self.data.heights
395 y = self.data.heights
396 self.y = y
396 self.y = y
397 nspc = self.data['spc']
397 nspc = self.data['spc']
398 #print(numpy.shape(self.data['spc']))
398 #print(numpy.shape(self.data['spc']))
399 spc = self.data['cspc'][0]
399 spc = self.data['cspc'][0]
400 #print(numpy.shape(nspc))
400 #print(numpy.shape(nspc))
401 #exit()
401 #exit()
402 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
402 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
403 #print(numpy.shape(spc))
403 #print(numpy.shape(spc))
404 #exit()
404 #exit()
405 cspc = self.data['cspc'][1]
405 cspc = self.data['cspc'][1]
406
406
407 #xflip=numpy.flip(x)
407 #xflip=numpy.flip(x)
408 #print(numpy.shape(cspc))
408 #print(numpy.shape(cspc))
409 #exit()
409 #exit()
410
410
411 for n in range(self.nrows):
411 for n in range(self.nrows):
412 noise = self.data['noise'][:,-1]
412 noise = self.data['noise'][:,-1]
413 pair = self.data.pairs[n]
413 pair = self.data.pairs[n]
414 #print(pair)
414 #print(pair)
415 #exit()
415 #exit()
416 ax = self.axes[4 * n]
416 ax = self.axes[4 * n]
417 if ax.firsttime:
417 if ax.firsttime:
418 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
418 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
419 self.xmin = self.xmin if self.xmin else -self.xmax
419 self.xmin = self.xmin if self.xmin else -self.xmax
420 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
420 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
421 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
421 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
422 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
422 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
423 vmin=self.zmin,
423 vmin=self.zmin,
424 vmax=self.zmax,
424 vmax=self.zmax,
425 cmap=plt.get_cmap(self.colormap)
425 cmap=plt.get_cmap(self.colormap)
426 )
426 )
427 else:
427 else:
428 #print(numpy.shape(nspc[pair[0]].T))
428 #print(numpy.shape(nspc[pair[0]].T))
429 #exit()
429 #exit()
430 ax.plt.set_array(nspc[pair[0]].T.ravel())
430 ax.plt.set_array(nspc[pair[0]].T.ravel())
431 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
431 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
432
432
433 ax = self.axes[4 * n + 1]
433 ax = self.axes[4 * n + 1]
434
434
435 if ax.firsttime:
435 if ax.firsttime:
436 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
436 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
437 vmin=self.zmin,
437 vmin=self.zmin,
438 vmax=self.zmax,
438 vmax=self.zmax,
439 cmap=plt.get_cmap(self.colormap)
439 cmap=plt.get_cmap(self.colormap)
440 )
440 )
441 else:
441 else:
442
442
443 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
443 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
444 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
444 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
445
445
446 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
446 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
447 coh = numpy.abs(out)
447 coh = numpy.abs(out)
448 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
448 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
449
449
450 ax = self.axes[4 * n + 2]
450 ax = self.axes[4 * n + 2]
451 if ax.firsttime:
451 if ax.firsttime:
452 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
452 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
453 vmin=0,
453 vmin=0,
454 vmax=1,
454 vmax=1,
455 cmap=plt.get_cmap(self.colormap_coh)
455 cmap=plt.get_cmap(self.colormap_coh)
456 )
456 )
457 else:
457 else:
458 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
458 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
459 self.titles.append(
459 self.titles.append(
460 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
460 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
461
461
462 ax = self.axes[4 * n + 3]
462 ax = self.axes[4 * n + 3]
463 if ax.firsttime:
463 if ax.firsttime:
464 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
464 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
465 vmin=-180,
465 vmin=-180,
466 vmax=180,
466 vmax=180,
467 cmap=plt.get_cmap(self.colormap_phase)
467 cmap=plt.get_cmap(self.colormap_phase)
468 )
468 )
469 else:
469 else:
470 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
470 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
471 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
471 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
472
472
473
473
474 class CrossSpectra2Plot(Plot):
474 class CrossSpectra2Plot(Plot):
475
475
476 CODE = 'cspc'
476 CODE = 'cspc'
477 colormap = 'jet'
477 colormap = 'jet'
478 plot_type = 'pcolor'
478 plot_type = 'pcolor'
479 zmin_coh = None
479 zmin_coh = None
480 zmax_coh = None
480 zmax_coh = None
481 zmin_phase = None
481 zmin_phase = None
482 zmax_phase = None
482 zmax_phase = None
483
483
484 def setup(self):
484 def setup(self):
485
485
486 self.ncols = 1
486 self.ncols = 1
487 self.nrows = len(self.data.pairs)
487 self.nrows = len(self.data.pairs)
488 self.nplots = self.nrows * 1
488 self.nplots = self.nrows * 1
489 self.width = 3.1 * self.ncols
489 self.width = 3.1 * self.ncols
490 self.height = 5 * self.nrows
490 self.height = 5 * self.nrows
491 self.ylabel = 'Range [km]'
491 self.ylabel = 'Range [km]'
492 self.showprofile = False
492 self.showprofile = False
493 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
493 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
494
494
495 def plot(self):
495 def plot(self):
496
496
497 if self.xaxis == "frequency":
497 if self.xaxis == "frequency":
498 x = self.data.xrange[0]
498 x = self.data.xrange[0]
499 self.xlabel = "Frequency (kHz)"
499 self.xlabel = "Frequency (kHz)"
500 elif self.xaxis == "time":
500 elif self.xaxis == "time":
501 x = self.data.xrange[1]
501 x = self.data.xrange[1]
502 self.xlabel = "Time (ms)"
502 self.xlabel = "Time (ms)"
503 else:
503 else:
504 x = self.data.xrange[2]
504 x = self.data.xrange[2]
505 self.xlabel = "Velocity (m/s)"
505 self.xlabel = "Velocity (m/s)"
506
506
507 self.titles = []
507 self.titles = []
508
508
509
509
510 y = self.data.heights
510 y = self.data.heights
511 self.y = y
511 self.y = y
512 #nspc = self.data['spc']
512 #nspc = self.data['spc']
513 #print(numpy.shape(self.data['spc']))
513 #print(numpy.shape(self.data['spc']))
514 #spc = self.data['cspc'][0]
514 #spc = self.data['cspc'][0]
515 #print(numpy.shape(spc))
515 #print(numpy.shape(spc))
516 #exit()
516 #exit()
517 cspc = self.data['cspc'][1]
517 cspc = self.data['cspc'][1]
518 #print(numpy.shape(cspc))
518 #print(numpy.shape(cspc))
519 #exit()
519 #exit()
520
520
521 for n in range(self.nrows):
521 for n in range(self.nrows):
522 noise = self.data['noise'][:,-1]
522 noise = self.data['noise'][:,-1]
523 pair = self.data.pairs[n]
523 pair = self.data.pairs[n]
524 #print(pair) #exit()
524 #print(pair) #exit()
525
525
526
526
527
527
528 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
528 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
529
529
530 #print(out[:,53])
530 #print(out[:,53])
531 #exit()
531 #exit()
532 cross = numpy.abs(out)
532 cross = numpy.abs(out)
533 z = cross/self.data.nFactor
533 z = cross/self.data.nFactor
534 #print("here")
534 #print("here")
535 #print(dataOut.data_spc[0,0,0])
535 #print(dataOut.data_spc[0,0,0])
536 #exit()
536 #exit()
537
537
538 cross = 10*numpy.log10(z)
538 cross = 10*numpy.log10(z)
539 #print(numpy.shape(cross))
539 #print(numpy.shape(cross))
540 #print(cross[0,:])
540 #print(cross[0,:])
541 #print(self.data.nFactor)
541 #print(self.data.nFactor)
542 #exit()
542 #exit()
543 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
543 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
544
544
545 ax = self.axes[1 * n]
545 ax = self.axes[1 * n]
546 if ax.firsttime:
546 if ax.firsttime:
547 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
547 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
548 self.xmin = self.xmin if self.xmin else -self.xmax
548 self.xmin = self.xmin if self.xmin else -self.xmax
549 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
549 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
550 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
550 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
551 ax.plt = ax.pcolormesh(x, y, cross.T,
551 ax.plt = ax.pcolormesh(x, y, cross.T,
552 vmin=self.zmin,
552 vmin=self.zmin,
553 vmax=self.zmax,
553 vmax=self.zmax,
554 cmap=plt.get_cmap(self.colormap)
554 cmap=plt.get_cmap(self.colormap)
555 )
555 )
556 else:
556 else:
557 ax.plt.set_array(cross.T.ravel())
557 ax.plt.set_array(cross.T.ravel())
558 self.titles.append(
558 self.titles.append(
559 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
559 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
560
560
561
561
562 class CrossSpectra3Plot(Plot):
562 class CrossSpectra3Plot(Plot):
563
563
564 CODE = 'cspc'
564 CODE = 'cspc'
565 colormap = 'jet'
565 colormap = 'jet'
566 plot_type = 'pcolor'
566 plot_type = 'pcolor'
567 zmin_coh = None
567 zmin_coh = None
568 zmax_coh = None
568 zmax_coh = None
569 zmin_phase = None
569 zmin_phase = None
570 zmax_phase = None
570 zmax_phase = None
571
571
572 def setup(self):
572 def setup(self):
573
573
574 self.ncols = 3
574 self.ncols = 3
575 self.nrows = len(self.data.pairs)
575 self.nrows = len(self.data.pairs)
576 self.nplots = self.nrows * 3
576 self.nplots = self.nrows * 3
577 self.width = 3.1 * self.ncols
577 self.width = 3.1 * self.ncols
578 self.height = 5 * self.nrows
578 self.height = 5 * self.nrows
579 self.ylabel = 'Range [km]'
579 self.ylabel = 'Range [km]'
580 self.showprofile = False
580 self.showprofile = False
581 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
581 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
582
582
583 def plot(self):
583 def plot(self):
584
584
585 if self.xaxis == "frequency":
585 if self.xaxis == "frequency":
586 x = self.data.xrange[0]
586 x = self.data.xrange[0]
587 self.xlabel = "Frequency (kHz)"
587 self.xlabel = "Frequency (kHz)"
588 elif self.xaxis == "time":
588 elif self.xaxis == "time":
589 x = self.data.xrange[1]
589 x = self.data.xrange[1]
590 self.xlabel = "Time (ms)"
590 self.xlabel = "Time (ms)"
591 else:
591 else:
592 x = self.data.xrange[2]
592 x = self.data.xrange[2]
593 self.xlabel = "Velocity (m/s)"
593 self.xlabel = "Velocity (m/s)"
594
594
595 self.titles = []
595 self.titles = []
596
596
597
597
598 y = self.data.heights
598 y = self.data.heights
599 self.y = y
599 self.y = y
600 #nspc = self.data['spc']
600 #nspc = self.data['spc']
601 #print(numpy.shape(self.data['spc']))
601 #print(numpy.shape(self.data['spc']))
602 #spc = self.data['cspc'][0]
602 #spc = self.data['cspc'][0]
603 #print(numpy.shape(spc))
603 #print(numpy.shape(spc))
604 #exit()
604 #exit()
605 cspc = self.data['cspc'][1]
605 cspc = self.data['cspc'][1]
606 #print(numpy.shape(cspc))
606 #print(numpy.shape(cspc))
607 #exit()
607 #exit()
608
608
609 for n in range(self.nrows):
609 for n in range(self.nrows):
610 noise = self.data['noise'][:,-1]
610 noise = self.data['noise'][:,-1]
611 pair = self.data.pairs[n]
611 pair = self.data.pairs[n]
612 #print(pair) #exit()
612 #print(pair) #exit()
613
613
614
614
615
615
616 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
616 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
617
617
618 #print(out[:,53])
618 #print(out[:,53])
619 #exit()
619 #exit()
620 cross = numpy.abs(out)
620 cross = numpy.abs(out)
621 z = cross/self.data.nFactor
621 z = cross/self.data.nFactor
622 cross = 10*numpy.log10(z)
622 cross = 10*numpy.log10(z)
623
623
624 out_r= out.real/self.data.nFactor
624 out_r= out.real/self.data.nFactor
625 #out_r = 10*numpy.log10(out_r)
625 #out_r = 10*numpy.log10(out_r)
626
626
627 out_i= out.imag/self.data.nFactor
627 out_i= out.imag/self.data.nFactor
628 #out_i = 10*numpy.log10(out_i)
628 #out_i = 10*numpy.log10(out_i)
629 #print(numpy.shape(cross))
629 #print(numpy.shape(cross))
630 #print(cross[0,:])
630 #print(cross[0,:])
631 #print(self.data.nFactor)
631 #print(self.data.nFactor)
632 #exit()
632 #exit()
633 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
633 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
634
634
635 ax = self.axes[3 * n]
635 ax = self.axes[3 * n]
636 if ax.firsttime:
636 if ax.firsttime:
637 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
637 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
638 self.xmin = self.xmin if self.xmin else -self.xmax
638 self.xmin = self.xmin if self.xmin else -self.xmax
639 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
639 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
640 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
640 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
641 ax.plt = ax.pcolormesh(x, y, cross.T,
641 ax.plt = ax.pcolormesh(x, y, cross.T,
642 vmin=self.zmin,
642 vmin=self.zmin,
643 vmax=self.zmax,
643 vmax=self.zmax,
644 cmap=plt.get_cmap(self.colormap)
644 cmap=plt.get_cmap(self.colormap)
645 )
645 )
646 else:
646 else:
647 ax.plt.set_array(cross.T.ravel())
647 ax.plt.set_array(cross.T.ravel())
648 self.titles.append(
648 self.titles.append(
649 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
649 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
650
650
651 ax = self.axes[3 * n + 1]
651 ax = self.axes[3 * n + 1]
652 if ax.firsttime:
652 if ax.firsttime:
653 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
653 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
654 self.xmin = self.xmin if self.xmin else -self.xmax
654 self.xmin = self.xmin if self.xmin else -self.xmax
655 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
655 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
656 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
656 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
657 ax.plt = ax.pcolormesh(x, y, out_r.T,
657 ax.plt = ax.pcolormesh(x, y, out_r.T,
658 vmin=-1.e6,
658 vmin=-1.e6,
659 vmax=0,
659 vmax=0,
660 cmap=plt.get_cmap(self.colormap)
660 cmap=plt.get_cmap(self.colormap)
661 )
661 )
662 else:
662 else:
663 ax.plt.set_array(out_r.T.ravel())
663 ax.plt.set_array(out_r.T.ravel())
664 self.titles.append(
664 self.titles.append(
665 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
665 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
666
666
667 ax = self.axes[3 * n + 2]
667 ax = self.axes[3 * n + 2]
668
668
669
669
670 if ax.firsttime:
670 if ax.firsttime:
671 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
671 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
672 self.xmin = self.xmin if self.xmin else -self.xmax
672 self.xmin = self.xmin if self.xmin else -self.xmax
673 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
673 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
674 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
674 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
675 ax.plt = ax.pcolormesh(x, y, out_i.T,
675 ax.plt = ax.pcolormesh(x, y, out_i.T,
676 vmin=-1.e6,
676 vmin=-1.e6,
677 vmax=1.e6,
677 vmax=1.e6,
678 cmap=plt.get_cmap(self.colormap)
678 cmap=plt.get_cmap(self.colormap)
679 )
679 )
680 else:
680 else:
681 ax.plt.set_array(out_i.T.ravel())
681 ax.plt.set_array(out_i.T.ravel())
682 self.titles.append(
682 self.titles.append(
683 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
683 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
684
684
685 class RTIPlot(Plot):
685 class RTIPlot(Plot):
686 '''
686 '''
687 Plot for RTI data
687 Plot for RTI data
688 '''
688 '''
689
689
690 CODE = 'rti'
690 CODE = 'rti'
691 colormap = 'jet'
691 colormap = 'jet'
692 plot_type = 'pcolorbuffer'
692 plot_type = 'pcolorbuffer'
693
693
694 def setup(self):
694 def setup(self):
695 self.xaxis = 'time'
695 self.xaxis = 'time'
696 self.ncols = 1
696 self.ncols = 1
697 self.nrows = len(self.data.channels)
697 self.nrows = len(self.data.channels)
698 self.nplots = len(self.data.channels)
698 self.nplots = len(self.data.channels)
699 self.ylabel = 'Range [km]'
699 self.ylabel = 'Range [km]'
700 self.xlabel = 'Time'
700 self.xlabel = 'Time'
701 self.cb_label = 'dB'
701 self.cb_label = 'dB'
702 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
702 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
703 self.titles = ['{} Channel {}'.format(
703 self.titles = ['{} Channel {}'.format(
704 self.CODE.upper(), x) for x in range(self.nrows)]
704 self.CODE.upper(), x) for x in range(self.nrows)]
705
705
706 def update(self, dataOut):
706 def update(self, dataOut):
707
707
708 data = {}
708 data = {}
709 meta = {}
709 meta = {}
710 data['rti'] = dataOut.getPower()
710 data['rti'] = dataOut.getPower()
711 #print(numpy.shape(data['rti']))
711 #print(numpy.shape(data['rti']))
712
712
713 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
713 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
714
714
715 return data, meta
715 return data, meta
716
716
717 def plot(self):
717 def plot(self):
718
718
719 self.x = self.data.times
719 self.x = self.data.times
720 self.y = self.data.yrange
720 self.y = self.data.yrange
721 self.z = self.data[self.CODE]
721 self.z = self.data[self.CODE]
722 #print("Inside RTI: ", self.z)
722 #print("Inside RTI: ", self.z)
723 self.z = numpy.ma.masked_invalid(self.z)
723 self.z = numpy.ma.masked_invalid(self.z)
724
724
725 if self.decimation is None:
725 if self.decimation is None:
726 x, y, z = self.fill_gaps(self.x, self.y, self.z)
726 x, y, z = self.fill_gaps(self.x, self.y, self.z)
727 else:
727 else:
728 x, y, z = self.fill_gaps(*self.decimate())
728 x, y, z = self.fill_gaps(*self.decimate())
729 #print("self.z: ", self.z)
729 #print("self.z: ", self.z)
730 #exit(1)
730 #exit(1)
731 '''
731 '''
732 if not isinstance(self.zmin, collections.abc.Sequence):
732 if not isinstance(self.zmin, collections.abc.Sequence):
733 if not self.zmin:
733 if not self.zmin:
734 self.zmin = [numpy.min(self.z)]*len(self.axes)
734 self.zmin = [numpy.min(self.z)]*len(self.axes)
735 else:
735 else:
736 self.zmin = [self.zmin]*len(self.axes)
736 self.zmin = [self.zmin]*len(self.axes)
737
737
738 if not isinstance(self.zmax, collections.abc.Sequence):
738 if not isinstance(self.zmax, collections.abc.Sequence):
739 if not self.zmax:
739 if not self.zmax:
740 self.zmax = [numpy.max(self.z)]*len(self.axes)
740 self.zmax = [numpy.max(self.z)]*len(self.axes)
741 else:
741 else:
742 self.zmax = [self.zmax]*len(self.axes)
742 self.zmax = [self.zmax]*len(self.axes)
743 '''
743 '''
744 for n, ax in enumerate(self.axes):
744 for n, ax in enumerate(self.axes):
745
745
746 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
746 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
747 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
747 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
748
748
749 if ax.firsttime:
749 if ax.firsttime:
750 if self.zlimits is not None:
750 if self.zlimits is not None:
751 self.zmin, self.zmax = self.zlimits[n]
751 self.zmin, self.zmax = self.zlimits[n]
752 ax.plt = ax.pcolormesh(x, y, z[n].T,
752 ax.plt = ax.pcolormesh(x, y, z[n].T,
753 vmin=self.zmin,
753 vmin=self.zmin,
754 vmax=self.zmax,
754 vmax=self.zmax,
755 cmap=plt.get_cmap(self.colormap)
755 cmap=plt.get_cmap(self.colormap)
756 )
756 )
757 if self.showprofile:
757 if self.showprofile:
758 ax.plot_profile = self.pf_axes[n].plot(
758 ax.plot_profile = self.pf_axes[n].plot(
759 self.data['rti'][n][-1], self.y)[0]
759 self.data['rti'][n][-1], self.y)[0]
760 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
760 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
761 color="k", linestyle="dashed", lw=1)[0]
761 color="k", linestyle="dashed", lw=1)[0]
762 else:
762 else:
763 if self.zlimits is not None:
763 if self.zlimits is not None:
764 self.zmin, self.zmax = self.zlimits[n]
764 self.zmin, self.zmax = self.zlimits[n]
765 ax.collections.remove(ax.collections[0])
765 ax.collections.remove(ax.collections[0])
766 ax.plt = ax.pcolormesh(x, y, z[n].T,
766 ax.plt = ax.pcolormesh(x, y, z[n].T,
767 vmin=self.zmin,
767 vmin=self.zmin,
768 vmax=self.zmax,
768 vmax=self.zmax,
769 cmap=plt.get_cmap(self.colormap)
769 cmap=plt.get_cmap(self.colormap)
770 )
770 )
771 if self.showprofile:
771 if self.showprofile:
772 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
772 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
773 ax.plot_noise.set_data(numpy.repeat(
773 ax.plot_noise.set_data(numpy.repeat(
774 self.data['noise'][n][-1], len(self.y)), self.y)
774 self.data['noise'][n][-1], len(self.y)), self.y)
775
775
776
776
777 class SpectrogramPlot(Plot):
777 class SpectrogramPlot(Plot):
778 '''
778 '''
779 Plot for Spectrogram data
779 Plot for Spectrogram data
780 '''
780 '''
781
781
782 CODE = 'Spectrogram_Profile'
782 CODE = 'Spectrogram_Profile'
783 colormap = 'binary'
783 colormap = 'binary'
784 plot_type = 'pcolorbuffer'
784 plot_type = 'pcolorbuffer'
785
785
786 def setup(self):
786 def setup(self):
787 self.xaxis = 'time'
787 self.xaxis = 'time'
788 self.ncols = 1
788 self.ncols = 1
789 self.nrows = len(self.data.channels)
789 self.nrows = len(self.data.channels)
790 self.nplots = len(self.data.channels)
790 self.nplots = len(self.data.channels)
791 self.xlabel = 'Time'
791 self.xlabel = 'Time'
792 #self.cb_label = 'dB'
792 #self.cb_label = 'dB'
793 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
793 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
794 self.titles = []
794 self.titles = []
795
795
796 #self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
796 #self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
797 #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)]
797 #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)]
798
798
799 self.titles = ['{} Channel {}'.format(
799 self.titles = ['{} Channel {}'.format(
800 self.CODE.upper(), x) for x in range(self.nrows)]
800 self.CODE.upper(), x) for x in range(self.nrows)]
801
801
802
802
803 def update(self, dataOut):
803 def update(self, dataOut):
804 data = {}
804 data = {}
805 meta = {}
805 meta = {}
806
806
807 maxHei = 1620#+12000
807 maxHei = 1620#+12000
808 maxHei = 1180
808 indb = numpy.where(dataOut.heightList <= maxHei)
809 indb = numpy.where(dataOut.heightList <= maxHei)
809 hei = indb[0][-1]
810 hei = indb[0][-1]
810 #print(dataOut.heightList)
811 #print(dataOut.heightList)
811
812
812 factor = dataOut.nIncohInt
813 factor = dataOut.nIncohInt
813 z = dataOut.data_spc[:,:,hei] / factor
814 z = dataOut.data_spc[:,:,hei] / factor
814 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
815 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
815 #buffer = 10 * numpy.log10(z)
816 #buffer = 10 * numpy.log10(z)
816
817
817 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
818 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
818
819
819
820
820 #self.hei = hei
821 #self.hei = hei
821 #self.heightList = dataOut.heightList
822 #self.heightList = dataOut.heightList
822 #self.DH = (dataOut.heightList[1] - dataOut.heightList[0])/dataOut.step
823 #self.DH = (dataOut.heightList[1] - dataOut.heightList[0])/dataOut.step
823 #self.nProfiles = dataOut.nProfiles
824 #self.nProfiles = dataOut.nProfiles
824
825
825 data['Spectrogram_Profile'] = 10 * numpy.log10(z)
826 data['Spectrogram_Profile'] = 10 * numpy.log10(z)
826
827
827 data['hei'] = hei
828 data['hei'] = hei
828 data['DH'] = (dataOut.heightList[1] - dataOut.heightList[0])/dataOut.step
829 data['DH'] = (dataOut.heightList[1] - dataOut.heightList[0])/dataOut.step
829 data['nProfiles'] = dataOut.nProfiles
830 data['nProfiles'] = dataOut.nProfiles
830 #meta['yrange'] = dataOut.heightList[0:dataOut.NSHTS]
831 #meta['yrange'] = dataOut.heightList[0:dataOut.NSHTS]
831 '''
832 '''
832 import matplotlib.pyplot as plt
833 import matplotlib.pyplot as plt
833 plt.plot(10 * numpy.log10(z[0,:]))
834 plt.plot(10 * numpy.log10(z[0,:]))
834 plt.show()
835 plt.show()
835
836
836 from time import sleep
837 from time import sleep
837 sleep(10)
838 sleep(10)
838 '''
839 '''
839 return data, meta
840 return data, meta
840
841
841 def plot(self):
842 def plot(self):
842
843
843 self.x = self.data.times
844 self.x = self.data.times
844 self.z = self.data[self.CODE]
845 self.z = self.data[self.CODE]
845 self.y = self.data.xrange[0]
846 self.y = self.data.xrange[0]
846
847
847 hei = self.data['hei'][-1]
848 hei = self.data['hei'][-1]
848 DH = self.data['DH'][-1]
849 DH = self.data['DH'][-1]
849 nProfiles = self.data['nProfiles'][-1]
850 nProfiles = self.data['nProfiles'][-1]
850
851
851 self.ylabel = "Frequency (kHz)"
852 self.ylabel = "Frequency (kHz)"
852
853
853 self.z = numpy.ma.masked_invalid(self.z)
854 self.z = numpy.ma.masked_invalid(self.z)
854
855
855 if self.decimation is None:
856 if self.decimation is None:
856 x, y, z = self.fill_gaps(self.x, self.y, self.z)
857 x, y, z = self.fill_gaps(self.x, self.y, self.z)
857 else:
858 else:
858 x, y, z = self.fill_gaps(*self.decimate())
859 x, y, z = self.fill_gaps(*self.decimate())
859
860
860 for n, ax in enumerate(self.axes):
861 for n, ax in enumerate(self.axes):
861 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
862 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
862 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
863 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
863 data = self.data[-1]
864 data = self.data[-1]
864 if ax.firsttime:
865 if ax.firsttime:
865 ax.plt = ax.pcolormesh(x, y, z[n].T,
866 ax.plt = ax.pcolormesh(x, y, z[n].T,
866 vmin=self.zmin,
867 vmin=self.zmin,
867 vmax=self.zmax,
868 vmax=self.zmax,
868 cmap=plt.get_cmap(self.colormap)
869 cmap=plt.get_cmap(self.colormap)
869 )
870 )
870 else:
871 else:
871 ax.collections.remove(ax.collections[0])
872 ax.collections.remove(ax.collections[0])
872 ax.plt = ax.pcolormesh(x, y, z[n].T,
873 ax.plt = ax.pcolormesh(x, y, z[n].T,
873 vmin=self.zmin,
874 vmin=self.zmin,
874 vmax=self.zmax,
875 vmax=self.zmax,
875 cmap=plt.get_cmap(self.colormap)
876 cmap=plt.get_cmap(self.colormap)
876 )
877 )
877
878
878 #self.titles.append('Spectrogram')
879 #self.titles.append('Spectrogram')
879
880
880 #self.titles.append('{} Channel {} \n H = {} km ({} - {})'.format(
881 #self.titles.append('{} Channel {} \n H = {} km ({} - {})'.format(
881 #self.CODE.upper(), x, y[hei], y[hei],y[hei]+(DH*nProfiles)))
882 #self.CODE.upper(), x, y[hei], y[hei],y[hei]+(DH*nProfiles)))
882
883
883
884
884
885
885
886
886 class CoherencePlot(RTIPlot):
887 class CoherencePlot(RTIPlot):
887 '''
888 '''
888 Plot for Coherence data
889 Plot for Coherence data
889 '''
890 '''
890
891
891 CODE = 'coh'
892 CODE = 'coh'
892
893
893 def setup(self):
894 def setup(self):
894 self.xaxis = 'time'
895 self.xaxis = 'time'
895 self.ncols = 1
896 self.ncols = 1
896 self.nrows = len(self.data.pairs)
897 self.nrows = len(self.data.pairs)
897 self.nplots = len(self.data.pairs)
898 self.nplots = len(self.data.pairs)
898 self.ylabel = 'Range [km]'
899 self.ylabel = 'Range [km]'
899 self.xlabel = 'Time'
900 self.xlabel = 'Time'
900 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
901 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
901 if self.CODE == 'coh':
902 if self.CODE == 'coh':
902 self.cb_label = ''
903 self.cb_label = ''
903 self.titles = [
904 self.titles = [
904 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
905 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
905 else:
906 else:
906 self.cb_label = 'Degrees'
907 self.cb_label = 'Degrees'
907 self.titles = [
908 self.titles = [
908 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
909 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
909
910
910 def update(self, dataOut):
911 def update(self, dataOut):
911
912
912 data = {}
913 data = {}
913 meta = {}
914 meta = {}
914 data['coh'] = dataOut.getCoherence()
915 data['coh'] = dataOut.getCoherence()
915 meta['pairs'] = dataOut.pairsList
916 meta['pairs'] = dataOut.pairsList
916
917
917 return data, meta
918 return data, meta
918
919
919 class PhasePlot(CoherencePlot):
920 class PhasePlot(CoherencePlot):
920 '''
921 '''
921 Plot for Phase map data
922 Plot for Phase map data
922 '''
923 '''
923
924
924 CODE = 'phase'
925 CODE = 'phase'
925 colormap = 'seismic'
926 colormap = 'seismic'
926
927
927 def update(self, dataOut):
928 def update(self, dataOut):
928
929
929 data = {}
930 data = {}
930 meta = {}
931 meta = {}
931 data['phase'] = dataOut.getCoherence(phase=True)
932 data['phase'] = dataOut.getCoherence(phase=True)
932 meta['pairs'] = dataOut.pairsList
933 meta['pairs'] = dataOut.pairsList
933
934
934 return data, meta
935 return data, meta
935
936
936 class NoisePlot(Plot):
937 class NoisePlot(Plot):
937 '''
938 '''
938 Plot for noise
939 Plot for noise
939 '''
940 '''
940
941
941 CODE = 'noise'
942 CODE = 'noise'
942 plot_type = 'scatterbuffer'
943 plot_type = 'scatterbuffer'
943
944
944 def setup(self):
945 def setup(self):
945 self.xaxis = 'time'
946 self.xaxis = 'time'
946 self.ncols = 1
947 self.ncols = 1
947 self.nrows = 1
948 self.nrows = 1
948 self.nplots = 1
949 self.nplots = 1
949 self.ylabel = 'Intensity [dB]'
950 self.ylabel = 'Intensity [dB]'
950 self.xlabel = 'Time'
951 self.xlabel = 'Time'
951 self.titles = ['Noise']
952 self.titles = ['Noise']
952 self.colorbar = False
953 self.colorbar = False
953 self.plots_adjust.update({'right': 0.85 })
954 self.plots_adjust.update({'right': 0.85 })
954
955
955 def update(self, dataOut):
956 def update(self, dataOut):
956
957
957 data = {}
958 data = {}
958 meta = {}
959 meta = {}
959 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
960 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor).reshape(dataOut.nChannels, 1)
960 meta['yrange'] = numpy.array([])
961 meta['yrange'] = numpy.array([])
961
962
962 return data, meta
963 return data, meta
963
964
964 def plot(self):
965 def plot(self):
965
966
966 x = self.data.times
967 x = self.data.times
967 xmin = self.data.min_time
968 xmin = self.data.min_time
968 xmax = xmin + self.xrange * 60 * 60
969 xmax = xmin + self.xrange * 60 * 60
969 Y = self.data['noise']
970 Y = self.data['noise']
970
971
971 if self.axes[0].firsttime:
972 if self.axes[0].firsttime:
972 self.ymin = numpy.nanmin(Y) - 5
973 self.ymin = numpy.nanmin(Y) - 5
973 self.ymax = numpy.nanmax(Y) + 5
974 self.ymax = numpy.nanmax(Y) + 5
974 for ch in self.data.channels:
975 for ch in self.data.channels:
975 y = Y[ch]
976 y = Y[ch]
976 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
977 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
977 plt.legend(bbox_to_anchor=(1.18, 1.0))
978 plt.legend(bbox_to_anchor=(1.18, 1.0))
978 else:
979 else:
979 for ch in self.data.channels:
980 for ch in self.data.channels:
980 y = Y[ch]
981 y = Y[ch]
981 self.axes[0].lines[ch].set_data(x, y)
982 self.axes[0].lines[ch].set_data(x, y)
982
983
983 self.ymin = numpy.nanmin(Y) - 5
984 self.ymin = numpy.nanmin(Y) - 5
984 self.ymax = numpy.nanmax(Y) + 10
985 self.ymax = numpy.nanmax(Y) + 10
985
986
986
987
987 class PowerProfilePlot(Plot):
988 class PowerProfilePlot(Plot):
988
989
989 CODE = 'pow_profile'
990 CODE = 'pow_profile'
990 plot_type = 'scatter'
991 plot_type = 'scatter'
991
992
992 def setup(self):
993 def setup(self):
993
994
994 self.ncols = 1
995 self.ncols = 1
995 self.nrows = 1
996 self.nrows = 1
996 self.nplots = 1
997 self.nplots = 1
997 self.height = 4
998 self.height = 4
998 self.width = 3
999 self.width = 3
999 self.ylabel = 'Range [km]'
1000 self.ylabel = 'Range [km]'
1000 self.xlabel = 'Intensity [dB]'
1001 self.xlabel = 'Intensity [dB]'
1001 self.titles = ['Power Profile']
1002 self.titles = ['Power Profile']
1002 self.colorbar = False
1003 self.colorbar = False
1003
1004
1004 def update(self, dataOut):
1005 def update(self, dataOut):
1005
1006
1006 data = {}
1007 data = {}
1007 meta = {}
1008 meta = {}
1008 data[self.CODE] = dataOut.getPower()
1009 data[self.CODE] = dataOut.getPower()
1009
1010
1010 return data, meta
1011 return data, meta
1011
1012
1012 def plot(self):
1013 def plot(self):
1013
1014
1014 y = self.data.yrange
1015 y = self.data.yrange
1015 self.y = y
1016 self.y = y
1016
1017
1017 x = self.data[-1][self.CODE]
1018 x = self.data[-1][self.CODE]
1018
1019
1019 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
1020 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
1020 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
1021 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
1021
1022
1022 if self.axes[0].firsttime:
1023 if self.axes[0].firsttime:
1023 for ch in self.data.channels:
1024 for ch in self.data.channels:
1024 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
1025 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
1025 plt.legend()
1026 plt.legend()
1026 else:
1027 else:
1027 for ch in self.data.channels:
1028 for ch in self.data.channels:
1028 self.axes[0].lines[ch].set_data(x[ch], y)
1029 self.axes[0].lines[ch].set_data(x[ch], y)
1029
1030
1030
1031
1031 class SpectraCutPlot(Plot):
1032 class SpectraCutPlot(Plot):
1032
1033
1033 CODE = 'spc_cut'
1034 CODE = 'spc_cut'
1034 plot_type = 'scatter'
1035 plot_type = 'scatter'
1035 buffering = False
1036 buffering = False
1036
1037
1037 def setup(self):
1038 def setup(self):
1038
1039
1039 self.nplots = len(self.data.channels)
1040 self.nplots = len(self.data.channels)
1040 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
1041 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
1041 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
1042 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
1042 self.width = 3.4 * self.ncols + 1.5
1043 self.width = 3.4 * self.ncols + 1.5
1043 self.height = 3 * self.nrows
1044 self.height = 3 * self.nrows
1044 self.ylabel = 'Power [dB]'
1045 self.ylabel = 'Power [dB]'
1045 self.colorbar = False
1046 self.colorbar = False
1046 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
1047 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
1047
1048
1048 def update(self, dataOut):
1049 def update(self, dataOut):
1049
1050
1050 data = {}
1051 data = {}
1051 meta = {}
1052 meta = {}
1052 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
1053 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
1053 data['spc'] = spc
1054 data['spc'] = spc
1054 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
1055 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
1055 if self.CODE == 'cut_gaussian_fit':
1056 if self.CODE == 'cut_gaussian_fit':
1056 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
1057 data['gauss_fit0'] = 10*numpy.log10(dataOut.GaussFit0/dataOut.normFactor)
1057 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
1058 data['gauss_fit1'] = 10*numpy.log10(dataOut.GaussFit1/dataOut.normFactor)
1058 return data, meta
1059 return data, meta
1059
1060
1060 def plot(self):
1061 def plot(self):
1061 if self.xaxis == "frequency":
1062 if self.xaxis == "frequency":
1062 x = self.data.xrange[0][1:]
1063 x = self.data.xrange[0][1:]
1063 self.xlabel = "Frequency (kHz)"
1064 self.xlabel = "Frequency (kHz)"
1064 elif self.xaxis == "time":
1065 elif self.xaxis == "time":
1065 x = self.data.xrange[1]
1066 x = self.data.xrange[1]
1066 self.xlabel = "Time (ms)"
1067 self.xlabel = "Time (ms)"
1067 else:
1068 else:
1068 x = self.data.xrange[2][:-1]
1069 x = self.data.xrange[2][:-1]
1069 self.xlabel = "Velocity (m/s)"
1070 self.xlabel = "Velocity (m/s)"
1070
1071
1071 if self.CODE == 'cut_gaussian_fit':
1072 if self.CODE == 'cut_gaussian_fit':
1072 x = self.data.xrange[2][:-1]
1073 x = self.data.xrange[2][:-1]
1073 self.xlabel = "Velocity (m/s)"
1074 self.xlabel = "Velocity (m/s)"
1074
1075
1075 self.titles = []
1076 self.titles = []
1076
1077
1077 y = self.data.yrange
1078 y = self.data.yrange
1078 data = self.data[-1]
1079 data = self.data[-1]
1079 z = data['spc']
1080 z = data['spc']
1080
1081
1081 if self.height_index:
1082 if self.height_index:
1082 index = numpy.array(self.height_index)
1083 index = numpy.array(self.height_index)
1083 else:
1084 else:
1084 index = numpy.arange(0, len(y), int((len(y))/9))
1085 index = numpy.arange(0, len(y), int((len(y))/9))
1085
1086
1086 for n, ax in enumerate(self.axes):
1087 for n, ax in enumerate(self.axes):
1087 if self.CODE == 'cut_gaussian_fit':
1088 if self.CODE == 'cut_gaussian_fit':
1088 gau0 = data['gauss_fit0']
1089 gau0 = data['gauss_fit0']
1089 gau1 = data['gauss_fit1']
1090 gau1 = data['gauss_fit1']
1090 if ax.firsttime:
1091 if ax.firsttime:
1091 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1092 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1092 self.xmin = self.xmin if self.xmin else -self.xmax
1093 self.xmin = self.xmin if self.xmin else -self.xmax
1093 self.ymin = self.ymin if self.ymin else numpy.nanmin(z[:,:,index])
1094 self.ymin = self.ymin if self.ymin else numpy.nanmin(z[:,:,index])
1094 self.ymax = self.ymax if self.ymax else numpy.nanmax(z[:,:,index])
1095 self.ymax = self.ymax if self.ymax else numpy.nanmax(z[:,:,index])
1095 #print(self.ymax)
1096 #print(self.ymax)
1096 #print(z[n, :, index])
1097 #print(z[n, :, index])
1097 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
1098 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
1098 if self.CODE == 'cut_gaussian_fit':
1099 if self.CODE == 'cut_gaussian_fit':
1099 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
1100 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
1100 for i, line in enumerate(ax.plt_gau0):
1101 for i, line in enumerate(ax.plt_gau0):
1101 line.set_color(ax.plt[i].get_color())
1102 line.set_color(ax.plt[i].get_color())
1102 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
1103 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
1103 for i, line in enumerate(ax.plt_gau1):
1104 for i, line in enumerate(ax.plt_gau1):
1104 line.set_color(ax.plt[i].get_color())
1105 line.set_color(ax.plt[i].get_color())
1105 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
1106 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
1106 self.figures[0].legend(ax.plt, labels, loc='center right')
1107 self.figures[0].legend(ax.plt, labels, loc='center right')
1107 else:
1108 else:
1108 for i, line in enumerate(ax.plt):
1109 for i, line in enumerate(ax.plt):
1109 line.set_data(x, z[n, :, index[i]].T)
1110 line.set_data(x, z[n, :, index[i]].T)
1110 for i, line in enumerate(ax.plt_gau0):
1111 for i, line in enumerate(ax.plt_gau0):
1111 line.set_data(x, gau0[n, :, index[i]].T)
1112 line.set_data(x, gau0[n, :, index[i]].T)
1112 line.set_color(ax.plt[i].get_color())
1113 line.set_color(ax.plt[i].get_color())
1113 for i, line in enumerate(ax.plt_gau1):
1114 for i, line in enumerate(ax.plt_gau1):
1114 line.set_data(x, gau1[n, :, index[i]].T)
1115 line.set_data(x, gau1[n, :, index[i]].T)
1115 line.set_color(ax.plt[i].get_color())
1116 line.set_color(ax.plt[i].get_color())
1116 self.titles.append('CH {}'.format(n))
1117 self.titles.append('CH {}'.format(n))
1117
1118
1118
1119
1119 class BeaconPhase(Plot):
1120 class BeaconPhase(Plot):
1120
1121
1121 __isConfig = None
1122 __isConfig = None
1122 __nsubplots = None
1123 __nsubplots = None
1123
1124
1124 PREFIX = 'beacon_phase'
1125 PREFIX = 'beacon_phase'
1125
1126
1126 def __init__(self):
1127 def __init__(self):
1127 Plot.__init__(self)
1128 Plot.__init__(self)
1128 self.timerange = 24*60*60
1129 self.timerange = 24*60*60
1129 self.isConfig = False
1130 self.isConfig = False
1130 self.__nsubplots = 1
1131 self.__nsubplots = 1
1131 self.counter_imagwr = 0
1132 self.counter_imagwr = 0
1132 self.WIDTH = 800
1133 self.WIDTH = 800
1133 self.HEIGHT = 400
1134 self.HEIGHT = 400
1134 self.WIDTHPROF = 120
1135 self.WIDTHPROF = 120
1135 self.HEIGHTPROF = 0
1136 self.HEIGHTPROF = 0
1136 self.xdata = None
1137 self.xdata = None
1137 self.ydata = None
1138 self.ydata = None
1138
1139
1139 self.PLOT_CODE = BEACON_CODE
1140 self.PLOT_CODE = BEACON_CODE
1140
1141
1141 self.FTP_WEI = None
1142 self.FTP_WEI = None
1142 self.EXP_CODE = None
1143 self.EXP_CODE = None
1143 self.SUB_EXP_CODE = None
1144 self.SUB_EXP_CODE = None
1144 self.PLOT_POS = None
1145 self.PLOT_POS = None
1145
1146
1146 self.filename_phase = None
1147 self.filename_phase = None
1147
1148
1148 self.figfile = None
1149 self.figfile = None
1149
1150
1150 self.xmin = None
1151 self.xmin = None
1151 self.xmax = None
1152 self.xmax = None
1152
1153
1153 def getSubplots(self):
1154 def getSubplots(self):
1154
1155
1155 ncol = 1
1156 ncol = 1
1156 nrow = 1
1157 nrow = 1
1157
1158
1158 return nrow, ncol
1159 return nrow, ncol
1159
1160
1160 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1161 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1161
1162
1162 self.__showprofile = showprofile
1163 self.__showprofile = showprofile
1163 self.nplots = nplots
1164 self.nplots = nplots
1164
1165
1165 ncolspan = 7
1166 ncolspan = 7
1166 colspan = 6
1167 colspan = 6
1167 self.__nsubplots = 2
1168 self.__nsubplots = 2
1168
1169
1169 self.createFigure(id = id,
1170 self.createFigure(id = id,
1170 wintitle = wintitle,
1171 wintitle = wintitle,
1171 widthplot = self.WIDTH+self.WIDTHPROF,
1172 widthplot = self.WIDTH+self.WIDTHPROF,
1172 heightplot = self.HEIGHT+self.HEIGHTPROF,
1173 heightplot = self.HEIGHT+self.HEIGHTPROF,
1173 show=show)
1174 show=show)
1174
1175
1175 nrow, ncol = self.getSubplots()
1176 nrow, ncol = self.getSubplots()
1176
1177
1177 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1178 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1178
1179
1179 def save_phase(self, filename_phase):
1180 def save_phase(self, filename_phase):
1180 f = open(filename_phase,'w+')
1181 f = open(filename_phase,'w+')
1181 f.write('\n\n')
1182 f.write('\n\n')
1182 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1183 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1183 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1184 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1184 f.close()
1185 f.close()
1185
1186
1186 def save_data(self, filename_phase, data, data_datetime):
1187 def save_data(self, filename_phase, data, data_datetime):
1187 f=open(filename_phase,'a')
1188 f=open(filename_phase,'a')
1188 timetuple_data = data_datetime.timetuple()
1189 timetuple_data = data_datetime.timetuple()
1189 day = str(timetuple_data.tm_mday)
1190 day = str(timetuple_data.tm_mday)
1190 month = str(timetuple_data.tm_mon)
1191 month = str(timetuple_data.tm_mon)
1191 year = str(timetuple_data.tm_year)
1192 year = str(timetuple_data.tm_year)
1192 hour = str(timetuple_data.tm_hour)
1193 hour = str(timetuple_data.tm_hour)
1193 minute = str(timetuple_data.tm_min)
1194 minute = str(timetuple_data.tm_min)
1194 second = str(timetuple_data.tm_sec)
1195 second = str(timetuple_data.tm_sec)
1195 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1196 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1196 f.close()
1197 f.close()
1197
1198
1198 def plot(self):
1199 def plot(self):
1199 log.warning('TODO: Not yet implemented...')
1200 log.warning('TODO: Not yet implemented...')
1200
1201
1201 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1202 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1202 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1203 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1203 timerange=None,
1204 timerange=None,
1204 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1205 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1205 server=None, folder=None, username=None, password=None,
1206 server=None, folder=None, username=None, password=None,
1206 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1207 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1207
1208
1208 if dataOut.flagNoData:
1209 if dataOut.flagNoData:
1209 return dataOut
1210 return dataOut
1210
1211
1211 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1212 return
1213 return
1213
1214
1214 if pairsList == None:
1215 if pairsList == None:
1215 pairsIndexList = dataOut.pairsIndexList[:10]
1216 pairsIndexList = dataOut.pairsIndexList[:10]
1216 else:
1217 else:
1217 pairsIndexList = []
1218 pairsIndexList = []
1218 for pair in pairsList:
1219 for pair in pairsList:
1219 if pair not in dataOut.pairsList:
1220 if pair not in dataOut.pairsList:
1220 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1221 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
1221 pairsIndexList.append(dataOut.pairsList.index(pair))
1222 pairsIndexList.append(dataOut.pairsList.index(pair))
1222
1223
1223 if pairsIndexList == []:
1224 if pairsIndexList == []:
1224 return
1225 return
1225
1226
1226 # if len(pairsIndexList) > 4:
1227 # if len(pairsIndexList) > 4:
1227 # pairsIndexList = pairsIndexList[0:4]
1228 # pairsIndexList = pairsIndexList[0:4]
1228
1229
1229 hmin_index = None
1230 hmin_index = None
1230 hmax_index = None
1231 hmax_index = None
1231
1232
1232 if hmin != None and hmax != None:
1233 if hmin != None and hmax != None:
1233 indexes = numpy.arange(dataOut.nHeights)
1234 indexes = numpy.arange(dataOut.nHeights)
1234 hmin_list = indexes[dataOut.heightList >= hmin]
1235 hmin_list = indexes[dataOut.heightList >= hmin]
1235 hmax_list = indexes[dataOut.heightList <= hmax]
1236 hmax_list = indexes[dataOut.heightList <= hmax]
1236
1237
1237 if hmin_list.any():
1238 if hmin_list.any():
1238 hmin_index = hmin_list[0]
1239 hmin_index = hmin_list[0]
1239
1240
1240 if hmax_list.any():
1241 if hmax_list.any():
1241 hmax_index = hmax_list[-1]+1
1242 hmax_index = hmax_list[-1]+1
1242
1243
1243 x = dataOut.getTimeRange()
1244 x = dataOut.getTimeRange()
1244
1245
1245 thisDatetime = dataOut.datatime
1246 thisDatetime = dataOut.datatime
1246
1247
1247 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1248 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1248 xlabel = "Local Time"
1249 xlabel = "Local Time"
1249 ylabel = "Phase (degrees)"
1250 ylabel = "Phase (degrees)"
1250
1251
1251 update_figfile = False
1252 update_figfile = False
1252
1253
1253 nplots = len(pairsIndexList)
1254 nplots = len(pairsIndexList)
1254 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1255 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1255 phase_beacon = numpy.zeros(len(pairsIndexList))
1256 phase_beacon = numpy.zeros(len(pairsIndexList))
1256 for i in range(nplots):
1257 for i in range(nplots):
1257 pair = dataOut.pairsList[pairsIndexList[i]]
1258 pair = dataOut.pairsList[pairsIndexList[i]]
1258 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1259 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1259 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1260 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1260 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1261 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1261 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1262 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1262 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1263 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1263
1264
1264 if dataOut.beacon_heiIndexList:
1265 if dataOut.beacon_heiIndexList:
1265 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1266 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1266 else:
1267 else:
1267 phase_beacon[i] = numpy.average(phase)
1268 phase_beacon[i] = numpy.average(phase)
1268
1269
1269 if not self.isConfig:
1270 if not self.isConfig:
1270
1271
1271 nplots = len(pairsIndexList)
1272 nplots = len(pairsIndexList)
1272
1273
1273 self.setup(id=id,
1274 self.setup(id=id,
1274 nplots=nplots,
1275 nplots=nplots,
1275 wintitle=wintitle,
1276 wintitle=wintitle,
1276 showprofile=showprofile,
1277 showprofile=showprofile,
1277 show=show)
1278 show=show)
1278
1279
1279 if timerange != None:
1280 if timerange != None:
1280 self.timerange = timerange
1281 self.timerange = timerange
1281
1282
1282 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1283 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1283
1284
1284 if ymin == None: ymin = 0
1285 if ymin == None: ymin = 0
1285 if ymax == None: ymax = 360
1286 if ymax == None: ymax = 360
1286
1287
1287 self.FTP_WEI = ftp_wei
1288 self.FTP_WEI = ftp_wei
1288 self.EXP_CODE = exp_code
1289 self.EXP_CODE = exp_code
1289 self.SUB_EXP_CODE = sub_exp_code
1290 self.SUB_EXP_CODE = sub_exp_code
1290 self.PLOT_POS = plot_pos
1291 self.PLOT_POS = plot_pos
1291
1292
1292 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1293 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1293 self.isConfig = True
1294 self.isConfig = True
1294 self.figfile = figfile
1295 self.figfile = figfile
1295 self.xdata = numpy.array([])
1296 self.xdata = numpy.array([])
1296 self.ydata = numpy.array([])
1297 self.ydata = numpy.array([])
1297
1298
1298 update_figfile = True
1299 update_figfile = True
1299
1300
1300 #open file beacon phase
1301 #open file beacon phase
1301 path = '%s%03d' %(self.PREFIX, self.id)
1302 path = '%s%03d' %(self.PREFIX, self.id)
1302 beacon_file = os.path.join(path,'%s.txt'%self.name)
1303 beacon_file = os.path.join(path,'%s.txt'%self.name)
1303 self.filename_phase = os.path.join(figpath,beacon_file)
1304 self.filename_phase = os.path.join(figpath,beacon_file)
1304 #self.save_phase(self.filename_phase)
1305 #self.save_phase(self.filename_phase)
1305
1306
1306
1307
1307 #store data beacon phase
1308 #store data beacon phase
1308 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1309 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1309
1310
1310 self.setWinTitle(title)
1311 self.setWinTitle(title)
1311
1312
1312
1313
1313 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1314 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1314
1315
1315 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1316 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1316
1317
1317 axes = self.axesList[0]
1318 axes = self.axesList[0]
1318
1319
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320
1321
1321 if len(self.ydata)==0:
1322 if len(self.ydata)==0:
1322 self.ydata = phase_beacon.reshape(-1,1)
1323 self.ydata = phase_beacon.reshape(-1,1)
1323 else:
1324 else:
1324 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1325 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1325
1326
1326
1327
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1329 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1330 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1330 XAxisAsTime=True, grid='both'
1331 XAxisAsTime=True, grid='both'
1331 )
1332 )
1332
1333
1333 self.draw()
1334 self.draw()
1334
1335
1335 if dataOut.ltctime >= self.xmax:
1336 if dataOut.ltctime >= self.xmax:
1336 self.counter_imagwr = wr_period
1337 self.counter_imagwr = wr_period
1337 self.isConfig = False
1338 self.isConfig = False
1338 update_figfile = True
1339 update_figfile = True
1339
1340
1340 self.save(figpath=figpath,
1341 self.save(figpath=figpath,
1341 figfile=figfile,
1342 figfile=figfile,
1342 save=save,
1343 save=save,
1343 ftp=ftp,
1344 ftp=ftp,
1344 wr_period=wr_period,
1345 wr_period=wr_period,
1345 thisDatetime=thisDatetime,
1346 thisDatetime=thisDatetime,
1346 update_figfile=update_figfile)
1347 update_figfile=update_figfile)
1347
1348
1348 return dataOut
1349 return dataOut
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,1049 +1,1049
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 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 """Spectra processing Unit and operations
5 """Spectra processing Unit and operations
6
6
7 Here you will find the processing unit `SpectraProc` and several operations
7 Here you will find the processing unit `SpectraProc` and several operations
8 to work with Spectra data type
8 to work with Spectra data type
9 """
9 """
10
10
11 import time
11 import time
12 import itertools
12 import itertools
13
13
14 import numpy
14 import numpy
15
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
16 from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator, Operation
17 from schainpy.model.data.jrodata import Spectra
17 from schainpy.model.data.jrodata import Spectra
18 from schainpy.model.data.jrodata import hildebrand_sekhon
18 from schainpy.model.data.jrodata import hildebrand_sekhon
19 from schainpy.utils import log
19 from schainpy.utils import log
20
20
21
21
22 class SpectraProc(ProcessingUnit):
22 class SpectraProc(ProcessingUnit):
23
23
24 def __init__(self):
24 def __init__(self):
25
25
26 ProcessingUnit.__init__(self)
26 ProcessingUnit.__init__(self)
27
27
28 self.buffer = None
28 self.buffer = None
29 self.firstdatatime = None
29 self.firstdatatime = None
30 self.profIndex = 0
30 self.profIndex = 0
31 self.dataOut = Spectra()
31 self.dataOut = Spectra()
32 self.id_min = None
32 self.id_min = None
33 self.id_max = None
33 self.id_max = None
34 self.setupReq = False #Agregar a todas las unidades de proc
34 self.setupReq = False #Agregar a todas las unidades de proc
35
35
36 def __updateSpecFromVoltage(self):
36 def __updateSpecFromVoltage(self):
37
37
38 self.dataOut.timeZone = self.dataIn.timeZone
38 self.dataOut.timeZone = self.dataIn.timeZone
39 self.dataOut.dstFlag = self.dataIn.dstFlag
39 self.dataOut.dstFlag = self.dataIn.dstFlag
40 self.dataOut.errorCount = self.dataIn.errorCount
40 self.dataOut.errorCount = self.dataIn.errorCount
41 self.dataOut.useLocalTime = self.dataIn.useLocalTime
41 self.dataOut.useLocalTime = self.dataIn.useLocalTime
42 try:
42 try:
43 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
43 self.dataOut.processingHeaderObj = self.dataIn.processingHeaderObj.copy()
44 except:
44 except:
45 pass
45 pass
46 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
46 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
47 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
47 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
48 self.dataOut.channelList = self.dataIn.channelList
48 self.dataOut.channelList = self.dataIn.channelList
49 self.dataOut.heightList = self.dataIn.heightList
49 self.dataOut.heightList = self.dataIn.heightList
50 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
50 self.dataOut.dtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
51 self.dataOut.nProfiles = self.dataOut.nFFTPoints
51 self.dataOut.nProfiles = self.dataOut.nFFTPoints
52 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
52 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
53 self.dataOut.utctime = self.firstdatatime
53 self.dataOut.utctime = self.firstdatatime
54 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
54 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData
55 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
55 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData
56 self.dataOut.flagShiftFFT = False
56 self.dataOut.flagShiftFFT = False
57 self.dataOut.nCohInt = self.dataIn.nCohInt
57 self.dataOut.nCohInt = self.dataIn.nCohInt
58 self.dataOut.nIncohInt = 1
58 self.dataOut.nIncohInt = 1
59 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
59 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
60 self.dataOut.frequency = self.dataIn.frequency
60 self.dataOut.frequency = self.dataIn.frequency
61 self.dataOut.realtime = self.dataIn.realtime
61 self.dataOut.realtime = self.dataIn.realtime
62 self.dataOut.azimuth = self.dataIn.azimuth
62 self.dataOut.azimuth = self.dataIn.azimuth
63 self.dataOut.zenith = self.dataIn.zenith
63 self.dataOut.zenith = self.dataIn.zenith
64 self.dataOut.beam.codeList = self.dataIn.beam.codeList
64 self.dataOut.beam.codeList = self.dataIn.beam.codeList
65 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
65 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
66 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
66 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
67 self.dataOut.runNextUnit = self.dataIn.runNextUnit
67 self.dataOut.runNextUnit = self.dataIn.runNextUnit
68 try:
68 try:
69 self.dataOut.step = self.dataIn.step
69 self.dataOut.step = self.dataIn.step
70 except:
70 except:
71 pass
71 pass
72
72
73 def __getFft(self):
73 def __getFft(self):
74 """
74 """
75 Convierte valores de Voltaje a Spectra
75 Convierte valores de Voltaje a Spectra
76
76
77 Affected:
77 Affected:
78 self.dataOut.data_spc
78 self.dataOut.data_spc
79 self.dataOut.data_cspc
79 self.dataOut.data_cspc
80 self.dataOut.data_dc
80 self.dataOut.data_dc
81 self.dataOut.heightList
81 self.dataOut.heightList
82 self.profIndex
82 self.profIndex
83 self.buffer
83 self.buffer
84 self.dataOut.flagNoData
84 self.dataOut.flagNoData
85 """
85 """
86 fft_volt = numpy.fft.fft(
86 fft_volt = numpy.fft.fft(
87 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
87 self.buffer, n=self.dataOut.nFFTPoints, axis=1)
88 fft_volt = fft_volt.astype(numpy.dtype('complex'))
88 fft_volt = fft_volt.astype(numpy.dtype('complex'))
89 dc = fft_volt[:, 0, :]
89 dc = fft_volt[:, 0, :]
90
90
91 # calculo de self-spectra
91 # calculo de self-spectra
92 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
92 fft_volt = numpy.fft.fftshift(fft_volt, axes=(1,))
93 spc = fft_volt * numpy.conjugate(fft_volt)
93 spc = fft_volt * numpy.conjugate(fft_volt)
94 spc = spc.real
94 spc = spc.real
95
95
96 blocksize = 0
96 blocksize = 0
97 blocksize += dc.size
97 blocksize += dc.size
98 blocksize += spc.size
98 blocksize += spc.size
99
99
100 cspc = None
100 cspc = None
101 pairIndex = 0
101 pairIndex = 0
102 if self.dataOut.pairsList != None:
102 if self.dataOut.pairsList != None:
103 # calculo de cross-spectra
103 # calculo de cross-spectra
104 cspc = numpy.zeros(
104 cspc = numpy.zeros(
105 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
105 (self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
106 for pair in self.dataOut.pairsList:
106 for pair in self.dataOut.pairsList:
107 if pair[0] not in self.dataOut.channelList:
107 if pair[0] not in self.dataOut.channelList:
108 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
108 raise ValueError("Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" % (
109 str(pair), str(self.dataOut.channelList)))
109 str(pair), str(self.dataOut.channelList)))
110 if pair[1] not in self.dataOut.channelList:
110 if pair[1] not in self.dataOut.channelList:
111 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
111 raise ValueError("Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" % (
112 str(pair), str(self.dataOut.channelList)))
112 str(pair), str(self.dataOut.channelList)))
113
113
114 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
114 cspc[pairIndex, :, :] = fft_volt[pair[0], :, :] * \
115 numpy.conjugate(fft_volt[pair[1], :, :])
115 numpy.conjugate(fft_volt[pair[1], :, :])
116 pairIndex += 1
116 pairIndex += 1
117 blocksize += cspc.size
117 blocksize += cspc.size
118
118
119 self.dataOut.data_spc = spc
119 self.dataOut.data_spc = spc
120 self.dataOut.data_cspc = cspc
120 self.dataOut.data_cspc = cspc
121 self.dataOut.data_dc = dc
121 self.dataOut.data_dc = dc
122 self.dataOut.blockSize = blocksize
122 self.dataOut.blockSize = blocksize
123 self.dataOut.flagShiftFFT = False
123 self.dataOut.flagShiftFFT = False
124
124
125 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
125 def run(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None, shift_fft=False, runNextUnit = 0):
126
126
127 self.dataIn.runNextUnit = runNextUnit
127 self.dataIn.runNextUnit = runNextUnit
128 if self.dataIn.type == "Spectra":
128 if self.dataIn.type == "Spectra":
129
129
130 self.dataOut.copy(self.dataIn)
130 self.dataOut.copy(self.dataIn)
131 if shift_fft:
131 if shift_fft:
132 #desplaza a la derecha en el eje 2 determinadas posiciones
132 #desplaza a la derecha en el eje 2 determinadas posiciones
133 shift = int(self.dataOut.nFFTPoints/2)
133 shift = int(self.dataOut.nFFTPoints/2)
134 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
134 self.dataOut.data_spc = numpy.roll(self.dataOut.data_spc, shift , axis=1)
135
135
136 if self.dataOut.data_cspc is not None:
136 if self.dataOut.data_cspc is not None:
137 #desplaza a la derecha en el eje 2 determinadas posiciones
137 #desplaza a la derecha en el eje 2 determinadas posiciones
138 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
138 self.dataOut.data_cspc = numpy.roll(self.dataOut.data_cspc, shift, axis=1)
139 if pairsList:
139 if pairsList:
140 self.__selectPairs(pairsList)
140 self.__selectPairs(pairsList)
141
141
142 elif self.dataIn.type == "Voltage":
142 elif self.dataIn.type == "Voltage":
143
143
144 self.dataOut.flagNoData = True
144 self.dataOut.flagNoData = True
145
145
146 if nFFTPoints == None:
146 if nFFTPoints == None:
147 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
147 raise ValueError("This SpectraProc.run() need nFFTPoints input variable")
148
148
149 if nProfiles == None:
149 if nProfiles == None:
150 nProfiles = nFFTPoints
150 nProfiles = nFFTPoints
151 #print(self.dataOut.ipp)
151 #print(self.dataOut.ipp)
152 #exit(1)
152 #exit(1)
153 if ippFactor == None:
153 if ippFactor == None:
154 self.dataOut.ippFactor = 1
154 self.dataOut.ippFactor = 1
155 #if ippFactor is not None:
155 #if ippFactor is not None:
156 #self.dataOut.ippFactor = ippFactor
156 #self.dataOut.ippFactor = ippFactor
157 #print(ippFactor)
157 #print(ippFactor)
158 #print(self.dataOut.ippFactor)
158 #print(self.dataOut.ippFactor)
159 #exit(1)
159 #exit(1)
160
160
161 self.dataOut.nFFTPoints = nFFTPoints
161 self.dataOut.nFFTPoints = nFFTPoints
162
162
163 if self.buffer is None:
163 if self.buffer is None:
164 self.buffer = numpy.zeros((self.dataIn.nChannels,
164 self.buffer = numpy.zeros((self.dataIn.nChannels,
165 nProfiles,
165 nProfiles,
166 self.dataIn.nHeights),
166 self.dataIn.nHeights),
167 dtype='complex')
167 dtype='complex')
168
168
169 if self.dataIn.flagDataAsBlock:
169 if self.dataIn.flagDataAsBlock:
170 nVoltProfiles = self.dataIn.data.shape[1]
170 nVoltProfiles = self.dataIn.data.shape[1]
171
171
172 if nVoltProfiles == nProfiles:
172 if nVoltProfiles == nProfiles:
173 self.buffer = self.dataIn.data.copy()
173 self.buffer = self.dataIn.data.copy()
174 self.profIndex = nVoltProfiles
174 self.profIndex = nVoltProfiles
175
175
176 elif nVoltProfiles < nProfiles:
176 elif nVoltProfiles < nProfiles:
177
177
178 if self.profIndex == 0:
178 if self.profIndex == 0:
179 self.id_min = 0
179 self.id_min = 0
180 self.id_max = nVoltProfiles
180 self.id_max = nVoltProfiles
181 #print(self.id_min)
181 #print(self.id_min)
182 #print(self.id_max)
182 #print(self.id_max)
183 #print(numpy.shape(self.buffer))
183 #print(numpy.shape(self.buffer))
184 self.buffer[:, self.id_min:self.id_max,
184 self.buffer[:, self.id_min:self.id_max,
185 :] = self.dataIn.data
185 :] = self.dataIn.data
186 self.profIndex += nVoltProfiles
186 self.profIndex += nVoltProfiles
187 self.id_min += nVoltProfiles
187 self.id_min += nVoltProfiles
188 self.id_max += nVoltProfiles
188 self.id_max += nVoltProfiles
189 else:
189 else:
190 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
190 raise ValueError("The type object %s has %d profiles, it should just has %d profiles" % (
191 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
191 self.dataIn.type, self.dataIn.data.shape[1], nProfiles))
192 self.dataOut.flagNoData = True
192 self.dataOut.flagNoData = True
193 else:
193 else:
194 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
194 self.buffer[:, self.profIndex, :] = self.dataIn.data.copy()
195 self.profIndex += 1
195 self.profIndex += 1
196
196
197 if self.firstdatatime == None:
197 if self.firstdatatime == None:
198 self.firstdatatime = self.dataIn.utctime
198 self.firstdatatime = self.dataIn.utctime
199
199
200 if self.profIndex == nProfiles:
200 if self.profIndex == nProfiles:
201 self.__updateSpecFromVoltage()
201 self.__updateSpecFromVoltage()
202 if pairsList == None:
202 if pairsList == None:
203 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
203 self.dataOut.pairsList = [pair for pair in itertools.combinations(self.dataOut.channelList, 2)]
204 else:
204 else:
205 self.dataOut.pairsList = pairsList
205 self.dataOut.pairsList = pairsList
206 self.__getFft()
206 self.__getFft()
207 self.dataOut.flagNoData = False
207 self.dataOut.flagNoData = False
208 self.firstdatatime = None
208 self.firstdatatime = None
209 self.profIndex = 0
209 self.profIndex = 0
210 else:
210 else:
211 raise ValueError("The type of input object '%s' is not valid".format(
211 raise ValueError("The type of input object '%s' is not valid".format(
212 self.dataIn.type))
212 self.dataIn.type))
213
213
214
214
215 def __selectPairs(self, pairsList):
215 def __selectPairs(self, pairsList):
216
216
217 if not pairsList:
217 if not pairsList:
218 return
218 return
219
219
220 pairs = []
220 pairs = []
221 pairsIndex = []
221 pairsIndex = []
222
222
223 for pair in pairsList:
223 for pair in pairsList:
224 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
224 if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList:
225 continue
225 continue
226 pairs.append(pair)
226 pairs.append(pair)
227 pairsIndex.append(pairs.index(pair))
227 pairsIndex.append(pairs.index(pair))
228
228
229 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
229 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
230 self.dataOut.pairsList = pairs
230 self.dataOut.pairsList = pairs
231
231
232 return
232 return
233
233
234 def selectFFTs(self, minFFT, maxFFT ):
234 def selectFFTs(self, minFFT, maxFFT ):
235 """
235 """
236 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
236 Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango
237 minFFT<= FFT <= maxFFT
237 minFFT<= FFT <= maxFFT
238 """
238 """
239
239
240 if (minFFT > maxFFT):
240 if (minFFT > maxFFT):
241 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
241 raise ValueError("Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT))
242
242
243 if (minFFT < self.dataOut.getFreqRange()[0]):
243 if (minFFT < self.dataOut.getFreqRange()[0]):
244 minFFT = self.dataOut.getFreqRange()[0]
244 minFFT = self.dataOut.getFreqRange()[0]
245
245
246 if (maxFFT > self.dataOut.getFreqRange()[-1]):
246 if (maxFFT > self.dataOut.getFreqRange()[-1]):
247 maxFFT = self.dataOut.getFreqRange()[-1]
247 maxFFT = self.dataOut.getFreqRange()[-1]
248
248
249 minIndex = 0
249 minIndex = 0
250 maxIndex = 0
250 maxIndex = 0
251 FFTs = self.dataOut.getFreqRange()
251 FFTs = self.dataOut.getFreqRange()
252
252
253 inda = numpy.where(FFTs >= minFFT)
253 inda = numpy.where(FFTs >= minFFT)
254 indb = numpy.where(FFTs <= maxFFT)
254 indb = numpy.where(FFTs <= maxFFT)
255
255
256 try:
256 try:
257 minIndex = inda[0][0]
257 minIndex = inda[0][0]
258 except:
258 except:
259 minIndex = 0
259 minIndex = 0
260
260
261 try:
261 try:
262 maxIndex = indb[0][-1]
262 maxIndex = indb[0][-1]
263 except:
263 except:
264 maxIndex = len(FFTs)
264 maxIndex = len(FFTs)
265
265
266 self.selectFFTsByIndex(minIndex, maxIndex)
266 self.selectFFTsByIndex(minIndex, maxIndex)
267
267
268 return 1
268 return 1
269
269
270 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
270 def getBeaconSignal(self, tauindex=0, channelindex=0, hei_ref=None):
271 newheis = numpy.where(
271 newheis = numpy.where(
272 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
272 self.dataOut.heightList > self.dataOut.radarControllerHeaderObj.Taus[tauindex])
273
273
274 if hei_ref != None:
274 if hei_ref != None:
275 newheis = numpy.where(self.dataOut.heightList > hei_ref)
275 newheis = numpy.where(self.dataOut.heightList > hei_ref)
276
276
277 minIndex = min(newheis[0])
277 minIndex = min(newheis[0])
278 maxIndex = max(newheis[0])
278 maxIndex = max(newheis[0])
279 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
279 data_spc = self.dataOut.data_spc[:, :, minIndex:maxIndex + 1]
280 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
280 heightList = self.dataOut.heightList[minIndex:maxIndex + 1]
281
281
282 # determina indices
282 # determina indices
283 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
283 nheis = int(self.dataOut.radarControllerHeaderObj.txB /
284 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
284 (self.dataOut.heightList[1] - self.dataOut.heightList[0]))
285 avg_dB = 10 * \
285 avg_dB = 10 * \
286 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
286 numpy.log10(numpy.sum(data_spc[channelindex, :, :], axis=0))
287 beacon_dB = numpy.sort(avg_dB)[-nheis:]
287 beacon_dB = numpy.sort(avg_dB)[-nheis:]
288 beacon_heiIndexList = []
288 beacon_heiIndexList = []
289 for val in avg_dB.tolist():
289 for val in avg_dB.tolist():
290 if val >= beacon_dB[0]:
290 if val >= beacon_dB[0]:
291 beacon_heiIndexList.append(avg_dB.tolist().index(val))
291 beacon_heiIndexList.append(avg_dB.tolist().index(val))
292
292
293 #data_spc = data_spc[:,:,beacon_heiIndexList]
293 #data_spc = data_spc[:,:,beacon_heiIndexList]
294 data_cspc = None
294 data_cspc = None
295 if self.dataOut.data_cspc is not None:
295 if self.dataOut.data_cspc is not None:
296 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
296 data_cspc = self.dataOut.data_cspc[:, :, minIndex:maxIndex + 1]
297 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
297 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
298
298
299 data_dc = None
299 data_dc = None
300 if self.dataOut.data_dc is not None:
300 if self.dataOut.data_dc is not None:
301 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
301 data_dc = self.dataOut.data_dc[:, minIndex:maxIndex + 1]
302 #data_dc = data_dc[:,beacon_heiIndexList]
302 #data_dc = data_dc[:,beacon_heiIndexList]
303
303
304 self.dataOut.data_spc = data_spc
304 self.dataOut.data_spc = data_spc
305 self.dataOut.data_cspc = data_cspc
305 self.dataOut.data_cspc = data_cspc
306 self.dataOut.data_dc = data_dc
306 self.dataOut.data_dc = data_dc
307 self.dataOut.heightList = heightList
307 self.dataOut.heightList = heightList
308 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
308 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
309
309
310 return 1
310 return 1
311
311
312 def selectFFTsByIndex(self, minIndex, maxIndex):
312 def selectFFTsByIndex(self, minIndex, maxIndex):
313 """
313 """
314
314
315 """
315 """
316
316
317 if (minIndex < 0) or (minIndex > maxIndex):
317 if (minIndex < 0) or (minIndex > maxIndex):
318 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
318 raise ValueError("Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex))
319
319
320 if (maxIndex >= self.dataOut.nProfiles):
320 if (maxIndex >= self.dataOut.nProfiles):
321 maxIndex = self.dataOut.nProfiles-1
321 maxIndex = self.dataOut.nProfiles-1
322
322
323 #Spectra
323 #Spectra
324 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
324 data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:]
325
325
326 data_cspc = None
326 data_cspc = None
327 if self.dataOut.data_cspc is not None:
327 if self.dataOut.data_cspc is not None:
328 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
328 data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:]
329
329
330 data_dc = None
330 data_dc = None
331 if self.dataOut.data_dc is not None:
331 if self.dataOut.data_dc is not None:
332 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
332 data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:]
333
333
334 self.dataOut.data_spc = data_spc
334 self.dataOut.data_spc = data_spc
335 self.dataOut.data_cspc = data_cspc
335 self.dataOut.data_cspc = data_cspc
336 self.dataOut.data_dc = data_dc
336 self.dataOut.data_dc = data_dc
337
337
338 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
338 self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1])
339 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
339 self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1]
340 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
340 self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1]
341
341
342 return 1
342 return 1
343
343
344 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
344 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
345 # validacion de rango
345 # validacion de rango
346 print("NOISeeee")
346 print("NOISeeee")
347 if minHei == None:
347 if minHei == None:
348 minHei = self.dataOut.heightList[0]
348 minHei = self.dataOut.heightList[0]
349
349
350 if maxHei == None:
350 if maxHei == None:
351 maxHei = self.dataOut.heightList[-1]
351 maxHei = self.dataOut.heightList[-1]
352
352
353 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
353 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
354 print('minHei: %.2f is out of the heights range' % (minHei))
354 print('minHei: %.2f is out of the heights range' % (minHei))
355 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
355 print('minHei is setting to %.2f' % (self.dataOut.heightList[0]))
356 minHei = self.dataOut.heightList[0]
356 minHei = self.dataOut.heightList[0]
357
357
358 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
358 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
359 print('maxHei: %.2f is out of the heights range' % (maxHei))
359 print('maxHei: %.2f is out of the heights range' % (maxHei))
360 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
360 print('maxHei is setting to %.2f' % (self.dataOut.heightList[-1]))
361 maxHei = self.dataOut.heightList[-1]
361 maxHei = self.dataOut.heightList[-1]
362
362
363 # validacion de velocidades
363 # validacion de velocidades
364 velrange = self.dataOut.getVelRange(1)
364 velrange = self.dataOut.getVelRange(1)
365
365
366 if minVel == None:
366 if minVel == None:
367 minVel = velrange[0]
367 minVel = velrange[0]
368
368
369 if maxVel == None:
369 if maxVel == None:
370 maxVel = velrange[-1]
370 maxVel = velrange[-1]
371
371
372 if (minVel < velrange[0]) or (minVel > maxVel):
372 if (minVel < velrange[0]) or (minVel > maxVel):
373 print('minVel: %.2f is out of the velocity range' % (minVel))
373 print('minVel: %.2f is out of the velocity range' % (minVel))
374 print('minVel is setting to %.2f' % (velrange[0]))
374 print('minVel is setting to %.2f' % (velrange[0]))
375 minVel = velrange[0]
375 minVel = velrange[0]
376
376
377 if (maxVel > velrange[-1]) or (maxVel < minVel):
377 if (maxVel > velrange[-1]) or (maxVel < minVel):
378 print('maxVel: %.2f is out of the velocity range' % (maxVel))
378 print('maxVel: %.2f is out of the velocity range' % (maxVel))
379 print('maxVel is setting to %.2f' % (velrange[-1]))
379 print('maxVel is setting to %.2f' % (velrange[-1]))
380 maxVel = velrange[-1]
380 maxVel = velrange[-1]
381
381
382 # seleccion de indices para rango
382 # seleccion de indices para rango
383 minIndex = 0
383 minIndex = 0
384 maxIndex = 0
384 maxIndex = 0
385 heights = self.dataOut.heightList
385 heights = self.dataOut.heightList
386
386
387 inda = numpy.where(heights >= minHei)
387 inda = numpy.where(heights >= minHei)
388 indb = numpy.where(heights <= maxHei)
388 indb = numpy.where(heights <= maxHei)
389
389
390 try:
390 try:
391 minIndex = inda[0][0]
391 minIndex = inda[0][0]
392 except:
392 except:
393 minIndex = 0
393 minIndex = 0
394
394
395 try:
395 try:
396 maxIndex = indb[0][-1]
396 maxIndex = indb[0][-1]
397 except:
397 except:
398 maxIndex = len(heights)
398 maxIndex = len(heights)
399
399
400 if (minIndex < 0) or (minIndex > maxIndex):
400 if (minIndex < 0) or (minIndex > maxIndex):
401 raise ValueError("some value in (%d,%d) is not valid" % (
401 raise ValueError("some value in (%d,%d) is not valid" % (
402 minIndex, maxIndex))
402 minIndex, maxIndex))
403
403
404 if (maxIndex >= self.dataOut.nHeights):
404 if (maxIndex >= self.dataOut.nHeights):
405 maxIndex = self.dataOut.nHeights - 1
405 maxIndex = self.dataOut.nHeights - 1
406
406
407 # seleccion de indices para velocidades
407 # seleccion de indices para velocidades
408 indminvel = numpy.where(velrange >= minVel)
408 indminvel = numpy.where(velrange >= minVel)
409 indmaxvel = numpy.where(velrange <= maxVel)
409 indmaxvel = numpy.where(velrange <= maxVel)
410 try:
410 try:
411 minIndexVel = indminvel[0][0]
411 minIndexVel = indminvel[0][0]
412 except:
412 except:
413 minIndexVel = 0
413 minIndexVel = 0
414
414
415 try:
415 try:
416 maxIndexVel = indmaxvel[0][-1]
416 maxIndexVel = indmaxvel[0][-1]
417 except:
417 except:
418 maxIndexVel = len(velrange)
418 maxIndexVel = len(velrange)
419
419
420 # seleccion del espectro
420 # seleccion del espectro
421 data_spc = self.dataOut.data_spc[:,
421 data_spc = self.dataOut.data_spc[:,
422 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
422 minIndexVel:maxIndexVel + 1, minIndex:maxIndex + 1]
423 # estimacion de ruido
423 # estimacion de ruido
424 noise = numpy.zeros(self.dataOut.nChannels)
424 noise = numpy.zeros(self.dataOut.nChannels)
425
425
426 for channel in range(self.dataOut.nChannels):
426 for channel in range(self.dataOut.nChannels):
427 daux = data_spc[channel, :, :]
427 daux = data_spc[channel, :, :]
428 sortdata = numpy.sort(daux, axis=None)
428 sortdata = numpy.sort(daux, axis=None)
429 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
429 noise[channel] = hildebrand_sekhon(sortdata, self.dataOut.nIncohInt)
430
430
431 self.dataOut.noise_estimation = noise.copy()
431 self.dataOut.noise_estimation = noise.copy()
432
432
433 return 1
433 return 1
434
434
435 class GetSNR(Operation):
435 class GetSNR(Operation):
436 '''
436 '''
437 Written by R. Flores
437 Written by R. Flores
438 '''
438 '''
439 """Operation to get SNR.
439 """Operation to get SNR.
440
440
441 Parameters:
441 Parameters:
442 -----------
442 -----------
443
443
444 Example
444 Example
445 --------
445 --------
446
446
447 op = proc_unit.addOperation(name='GetSNR', optype='other')
447 op = proc_unit.addOperation(name='GetSNR', optype='other')
448
448
449 """
449 """
450
450
451 def __init__(self, **kwargs):
451 def __init__(self, **kwargs):
452
452
453 Operation.__init__(self, **kwargs)
453 Operation.__init__(self, **kwargs)
454
454
455
455
456 def run(self,dataOut):
456 def run(self,dataOut):
457
457
458 #noise = dataOut.getNoise()
458 noise = dataOut.getNoise()
459 noise = dataOut.getNoise(ymin_index=-10) #Región superior donde solo debería de haber ruido
459 #noise = dataOut.getNoise(ymin_index=-10) #Región superior donde solo debería de haber ruido
460 #print("Noise: ", noise)
460 #print("Noise: ", noise)
461 #print("Noise_dB: ", 10*numpy.log10(noise/dataOut.normFactor))
461 #print("Noise_dB: ", 10*numpy.log10(noise/dataOut.normFactor))
462 #print("Heights: ", dataOut.heightList)
462 #print("Heights: ", dataOut.heightList)
463 #dataOut.data_snr = (dataOut.data_spc.sum(axis=1))/(noise[:,None]*dataOut.normFactor)
463 #dataOut.data_snr = (dataOut.data_spc.sum(axis=1))/(noise[:,None]*dataOut.normFactor)
464 ################dataOut.data_snr = (dataOut.data_spc.sum(axis=1))/(noise[:,None]*dataOut.nFFTPoints) #Before 12Jan2023
464 ################dataOut.data_snr = (dataOut.data_spc.sum(axis=1))/(noise[:,None]*dataOut.nFFTPoints) #Before 12Jan2023
465 #dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None])/(noise[:,None])
465 #dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None])/(noise[:,None])
466 dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None]*dataOut.nFFTPoints)/(noise[:,None]*dataOut.nFFTPoints) #It works apparently
466 dataOut.data_snr = (dataOut.data_spc.sum(axis=1)-noise[:,None]*dataOut.nFFTPoints)/(noise[:,None]*dataOut.nFFTPoints) #It works apparently
467 dataOut.snl = numpy.log10(dataOut.data_snr)
467 dataOut.snl = numpy.log10(dataOut.data_snr)
468 #print("snl: ", dataOut.snl)
468 #print("snl: ", dataOut.snl)
469 #exit(1)
469 #exit(1)
470 #print(dataOut.heightList[-11])
470 #print(dataOut.heightList[-11])
471 #print(numpy.shape(dataOut.heightList))
471 #print(numpy.shape(dataOut.heightList))
472 #print(dataOut.data_snr)
472 #print(dataOut.data_snr)
473 #print(dataOut.data_snr[0,-11])
473 #print(dataOut.data_snr[0,-11])
474 #exit(1)
474 #exit(1)
475 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.5, numpy.nan, dataOut.data_snr)
475 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.5, numpy.nan, dataOut.data_snr)
476 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.1, numpy.nan, dataOut.data_snr)
476 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.1, numpy.nan, dataOut.data_snr)
477 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.0, numpy.nan, dataOut.data_snr)
477 #dataOut.data_snr = numpy.where(10*numpy.log10(dataOut.data_snr)<.0, numpy.nan, dataOut.data_snr)
478 #dataOut.data_snr = numpy.where(dataOut.data_snr<.05, numpy.nan, dataOut.data_snr)
478 #dataOut.data_snr = numpy.where(dataOut.data_snr<.05, numpy.nan, dataOut.data_snr)
479 #dataOut.snl = numpy.where(dataOut.data_snr<.01, numpy.nan, dataOut.snl)
479 #dataOut.snl = numpy.where(dataOut.data_snr<.01, numpy.nan, dataOut.snl)
480 dataOut.snl = numpy.where(dataOut.snl<-1, numpy.nan, dataOut.snl)
480 dataOut.snl = numpy.where(dataOut.snl<-1, numpy.nan, dataOut.snl)
481 '''
481 '''
482 import matplotlib.pyplot as plt
482 import matplotlib.pyplot as plt
483 #plt.plot(10*numpy.log10(dataOut.data_snr[0]),dataOut.heightList)
483 #plt.plot(10*numpy.log10(dataOut.data_snr[0]),dataOut.heightList)
484 plt.plot(dataOut.data_snr[0],dataOut.heightList)#,marker='*')
484 plt.plot(dataOut.data_snr[0],dataOut.heightList)#,marker='*')
485 plt.xlim(-1,10)
485 plt.xlim(-1,10)
486 plt.axvline(1,color='k')
486 plt.axvline(1,color='k')
487 plt.axvline(.1,color='k',linestyle='--')
487 plt.axvline(.1,color='k',linestyle='--')
488 plt.grid()
488 plt.grid()
489 plt.show()
489 plt.show()
490 '''
490 '''
491 #dataOut.data_snr = 10*numpy.log10(dataOut.data_snr)
491 #dataOut.data_snr = 10*numpy.log10(dataOut.data_snr)
492 #dataOut.data_snr = numpy.expand_dims(dataOut.data_snr,axis=0)
492 #dataOut.data_snr = numpy.expand_dims(dataOut.data_snr,axis=0)
493 #print(dataOut.data_snr.shape)
493 #print(dataOut.data_snr.shape)
494 #exit(1)
494 #exit(1)
495 #print("Before: ", dataOut.data_snr[0])
495 #print("Before: ", dataOut.data_snr[0])
496
496
497
497
498 return dataOut
498 return dataOut
499
499
500 class removeDC(Operation):
500 class removeDC(Operation):
501
501
502 def run(self, dataOut, mode=2):
502 def run(self, dataOut, mode=2):
503 self.dataOut = dataOut
503 self.dataOut = dataOut
504 jspectra = self.dataOut.data_spc
504 jspectra = self.dataOut.data_spc
505 jcspectra = self.dataOut.data_cspc
505 jcspectra = self.dataOut.data_cspc
506
506
507 num_chan = jspectra.shape[0]
507 num_chan = jspectra.shape[0]
508 num_hei = jspectra.shape[2]
508 num_hei = jspectra.shape[2]
509
509
510 if jcspectra is not None:
510 if jcspectra is not None:
511 jcspectraExist = True
511 jcspectraExist = True
512 num_pairs = jcspectra.shape[0]
512 num_pairs = jcspectra.shape[0]
513 else:
513 else:
514 jcspectraExist = False
514 jcspectraExist = False
515
515
516 freq_dc = int(jspectra.shape[1] / 2)
516 freq_dc = int(jspectra.shape[1] / 2)
517 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
517 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
518 ind_vel = ind_vel.astype(int)
518 ind_vel = ind_vel.astype(int)
519
519
520 if ind_vel[0] < 0:
520 if ind_vel[0] < 0:
521 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
521 ind_vel[list(range(0, 1))] = ind_vel[list(range(0, 1))] + self.num_prof
522
522
523 if mode == 1:
523 if mode == 1:
524 jspectra[:, freq_dc, :] = (
524 jspectra[:, freq_dc, :] = (
525 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
525 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
526
526
527 if jcspectraExist:
527 if jcspectraExist:
528 jcspectra[:, freq_dc, :] = (
528 jcspectra[:, freq_dc, :] = (
529 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
529 jcspectra[:, ind_vel[1], :] + jcspectra[:, ind_vel[2], :]) / 2
530
530
531 if mode == 2:
531 if mode == 2:
532
532
533 vel = numpy.array([-2, -1, 1, 2])
533 vel = numpy.array([-2, -1, 1, 2])
534 xx = numpy.zeros([4, 4])
534 xx = numpy.zeros([4, 4])
535
535
536 for fil in range(4):
536 for fil in range(4):
537 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
537 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
538
538
539 xx_inv = numpy.linalg.inv(xx)
539 xx_inv = numpy.linalg.inv(xx)
540 xx_aux = xx_inv[0, :]
540 xx_aux = xx_inv[0, :]
541
541
542 for ich in range(num_chan):
542 for ich in range(num_chan):
543 yy = jspectra[ich, ind_vel, :]
543 yy = jspectra[ich, ind_vel, :]
544 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
544 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
545
545
546 junkid = jspectra[ich, freq_dc, :] <= 0
546 junkid = jspectra[ich, freq_dc, :] <= 0
547 cjunkid = sum(junkid)
547 cjunkid = sum(junkid)
548
548
549 if cjunkid.any():
549 if cjunkid.any():
550 jspectra[ich, freq_dc, junkid.nonzero()] = (
550 jspectra[ich, freq_dc, junkid.nonzero()] = (
551 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
551 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
552
552
553 if jcspectraExist:
553 if jcspectraExist:
554 for ip in range(num_pairs):
554 for ip in range(num_pairs):
555 yy = jcspectra[ip, ind_vel, :]
555 yy = jcspectra[ip, ind_vel, :]
556 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
556 jcspectra[ip, freq_dc, :] = numpy.dot(xx_aux, yy)
557
557
558 self.dataOut.data_spc = jspectra
558 self.dataOut.data_spc = jspectra
559 self.dataOut.data_cspc = jcspectra
559 self.dataOut.data_cspc = jcspectra
560
560
561 return self.dataOut
561 return self.dataOut
562
562
563 class removeInterference(Operation):
563 class removeInterference(Operation):
564
564
565 def removeInterference2(self):
565 def removeInterference2(self):
566
566
567 cspc = self.dataOut.data_cspc
567 cspc = self.dataOut.data_cspc
568 spc = self.dataOut.data_spc
568 spc = self.dataOut.data_spc
569 Heights = numpy.arange(cspc.shape[2])
569 Heights = numpy.arange(cspc.shape[2])
570 realCspc = numpy.abs(cspc)
570 realCspc = numpy.abs(cspc)
571
571
572 for i in range(cspc.shape[0]):
572 for i in range(cspc.shape[0]):
573 LinePower= numpy.sum(realCspc[i], axis=0)
573 LinePower= numpy.sum(realCspc[i], axis=0)
574 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
574 Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)]
575 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
575 SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ]
576 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
576 InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 )
577 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
577 InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)]
578 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
578 InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)]
579
579
580
580
581 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
581 InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) )
582 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
582 #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax]))
583 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
583 if len(InterferenceRange)<int(cspc.shape[1]*0.3):
584 cspc[i,InterferenceRange,:] = numpy.NaN
584 cspc[i,InterferenceRange,:] = numpy.NaN
585
585
586 self.dataOut.data_cspc = cspc
586 self.dataOut.data_cspc = cspc
587
587
588 def removeInterference(self, interf = 2, hei_interf = None, nhei_interf = None, offhei_interf = None):
588 def removeInterference(self, interf = 2, hei_interf = None, nhei_interf = None, offhei_interf = None):
589
589
590 jspectra = self.dataOut.data_spc
590 jspectra = self.dataOut.data_spc
591 jcspectra = self.dataOut.data_cspc
591 jcspectra = self.dataOut.data_cspc
592 jnoise = self.dataOut.getNoise()
592 jnoise = self.dataOut.getNoise()
593 num_incoh = self.dataOut.nIncohInt
593 num_incoh = self.dataOut.nIncohInt
594
594
595 num_channel = jspectra.shape[0]
595 num_channel = jspectra.shape[0]
596 num_prof = jspectra.shape[1]
596 num_prof = jspectra.shape[1]
597 num_hei = jspectra.shape[2]
597 num_hei = jspectra.shape[2]
598
598
599 # hei_interf
599 # hei_interf
600 if hei_interf is None:
600 if hei_interf is None:
601 count_hei = int(num_hei / 2)
601 count_hei = int(num_hei / 2)
602 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
602 hei_interf = numpy.asmatrix(list(range(count_hei))) + num_hei - count_hei
603 hei_interf = numpy.asarray(hei_interf)[0]
603 hei_interf = numpy.asarray(hei_interf)[0]
604 # nhei_interf
604 # nhei_interf
605 if (nhei_interf == None):
605 if (nhei_interf == None):
606 nhei_interf = 5
606 nhei_interf = 5
607 if (nhei_interf < 1):
607 if (nhei_interf < 1):
608 nhei_interf = 1
608 nhei_interf = 1
609 if (nhei_interf > count_hei):
609 if (nhei_interf > count_hei):
610 nhei_interf = count_hei
610 nhei_interf = count_hei
611 if (offhei_interf == None):
611 if (offhei_interf == None):
612 offhei_interf = 0
612 offhei_interf = 0
613
613
614 ind_hei = list(range(num_hei))
614 ind_hei = list(range(num_hei))
615 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
615 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
616 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
616 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
617 mask_prof = numpy.asarray(list(range(num_prof)))
617 mask_prof = numpy.asarray(list(range(num_prof)))
618 num_mask_prof = mask_prof.size
618 num_mask_prof = mask_prof.size
619 comp_mask_prof = [0, num_prof / 2]
619 comp_mask_prof = [0, num_prof / 2]
620
620
621 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
621 # noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
622 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
622 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
623 jnoise = numpy.nan
623 jnoise = numpy.nan
624 noise_exist = jnoise[0] < numpy.Inf
624 noise_exist = jnoise[0] < numpy.Inf
625
625
626 # Subrutina de Remocion de la Interferencia
626 # Subrutina de Remocion de la Interferencia
627 for ich in range(num_channel):
627 for ich in range(num_channel):
628 # Se ordena los espectros segun su potencia (menor a mayor)
628 # Se ordena los espectros segun su potencia (menor a mayor)
629 power = jspectra[ich, mask_prof, :]
629 power = jspectra[ich, mask_prof, :]
630 power = power[:, hei_interf]
630 power = power[:, hei_interf]
631 power = power.sum(axis=0)
631 power = power.sum(axis=0)
632 psort = power.ravel().argsort()
632 psort = power.ravel().argsort()
633
633
634 # Se estima la interferencia promedio en los Espectros de Potencia empleando
634 # Se estima la interferencia promedio en los Espectros de Potencia empleando
635 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
635 junkspc_interf = jspectra[ich, :, hei_interf[psort[list(range(
636 offhei_interf, nhei_interf + offhei_interf))]]]
636 offhei_interf, nhei_interf + offhei_interf))]]]
637
637
638 if noise_exist:
638 if noise_exist:
639 # tmp_noise = jnoise[ich] / num_prof
639 # tmp_noise = jnoise[ich] / num_prof
640 tmp_noise = jnoise[ich]
640 tmp_noise = jnoise[ich]
641 junkspc_interf = junkspc_interf - tmp_noise
641 junkspc_interf = junkspc_interf - tmp_noise
642 #junkspc_interf[:,comp_mask_prof] = 0
642 #junkspc_interf[:,comp_mask_prof] = 0
643
643
644 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
644 jspc_interf = junkspc_interf.sum(axis=0) / nhei_interf
645 jspc_interf = jspc_interf.transpose()
645 jspc_interf = jspc_interf.transpose()
646 # Calculando el espectro de interferencia promedio
646 # Calculando el espectro de interferencia promedio
647 noiseid = numpy.where(
647 noiseid = numpy.where(
648 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
648 jspc_interf <= tmp_noise / numpy.sqrt(num_incoh))
649 noiseid = noiseid[0]
649 noiseid = noiseid[0]
650 cnoiseid = noiseid.size
650 cnoiseid = noiseid.size
651 interfid = numpy.where(
651 interfid = numpy.where(
652 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
652 jspc_interf > tmp_noise / numpy.sqrt(num_incoh))
653 interfid = interfid[0]
653 interfid = interfid[0]
654 cinterfid = interfid.size
654 cinterfid = interfid.size
655
655
656 if (cnoiseid > 0):
656 if (cnoiseid > 0):
657 jspc_interf[noiseid] = 0
657 jspc_interf[noiseid] = 0
658
658
659 # Expandiendo los perfiles a limpiar
659 # Expandiendo los perfiles a limpiar
660 if (cinterfid > 0):
660 if (cinterfid > 0):
661 new_interfid = (
661 new_interfid = (
662 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
662 numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof) % num_prof
663 new_interfid = numpy.asarray(new_interfid)
663 new_interfid = numpy.asarray(new_interfid)
664 new_interfid = {x for x in new_interfid}
664 new_interfid = {x for x in new_interfid}
665 new_interfid = numpy.array(list(new_interfid))
665 new_interfid = numpy.array(list(new_interfid))
666 new_cinterfid = new_interfid.size
666 new_cinterfid = new_interfid.size
667 else:
667 else:
668 new_cinterfid = 0
668 new_cinterfid = 0
669
669
670 for ip in range(new_cinterfid):
670 for ip in range(new_cinterfid):
671 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
671 ind = junkspc_interf[:, new_interfid[ip]].ravel().argsort()
672 jspc_interf[new_interfid[ip]
672 jspc_interf[new_interfid[ip]
673 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
673 ] = junkspc_interf[ind[nhei_interf // 2], new_interfid[ip]]
674
674
675 jspectra[ich, :, ind_hei] = jspectra[ich, :,
675 jspectra[ich, :, ind_hei] = jspectra[ich, :,
676 ind_hei] - jspc_interf # Corregir indices
676 ind_hei] - jspc_interf # Corregir indices
677
677
678 # Removiendo la interferencia del punto de mayor interferencia
678 # Removiendo la interferencia del punto de mayor interferencia
679 ListAux = jspc_interf[mask_prof].tolist()
679 ListAux = jspc_interf[mask_prof].tolist()
680 maxid = ListAux.index(max(ListAux))
680 maxid = ListAux.index(max(ListAux))
681
681
682 if cinterfid > 0:
682 if cinterfid > 0:
683 for ip in range(cinterfid * (interf == 2) - 1):
683 for ip in range(cinterfid * (interf == 2) - 1):
684 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
684 ind = (jspectra[ich, interfid[ip], :] < tmp_noise *
685 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
685 (1 + 1 / numpy.sqrt(num_incoh))).nonzero()
686 cind = len(ind)
686 cind = len(ind)
687
687
688 if (cind > 0):
688 if (cind > 0):
689 jspectra[ich, interfid[ip], ind] = tmp_noise * \
689 jspectra[ich, interfid[ip], ind] = tmp_noise * \
690 (1 + (numpy.random.uniform(cind) - 0.5) /
690 (1 + (numpy.random.uniform(cind) - 0.5) /
691 numpy.sqrt(num_incoh))
691 numpy.sqrt(num_incoh))
692
692
693 ind = numpy.array([-2, -1, 1, 2])
693 ind = numpy.array([-2, -1, 1, 2])
694 xx = numpy.zeros([4, 4])
694 xx = numpy.zeros([4, 4])
695
695
696 for id1 in range(4):
696 for id1 in range(4):
697 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
697 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
698
698
699 xx_inv = numpy.linalg.inv(xx)
699 xx_inv = numpy.linalg.inv(xx)
700 xx = xx_inv[:, 0]
700 xx = xx_inv[:, 0]
701 ind = (ind + maxid + num_mask_prof) % num_mask_prof
701 ind = (ind + maxid + num_mask_prof) % num_mask_prof
702 yy = jspectra[ich, mask_prof[ind], :]
702 yy = jspectra[ich, mask_prof[ind], :]
703 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
703 jspectra[ich, mask_prof[maxid], :] = numpy.dot(
704 yy.transpose(), xx)
704 yy.transpose(), xx)
705
705
706 indAux = (jspectra[ich, :, :] < tmp_noise *
706 indAux = (jspectra[ich, :, :] < tmp_noise *
707 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
707 (1 - 1 / numpy.sqrt(num_incoh))).nonzero()
708 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
708 jspectra[ich, indAux[0], indAux[1]] = tmp_noise * \
709 (1 - 1 / numpy.sqrt(num_incoh))
709 (1 - 1 / numpy.sqrt(num_incoh))
710
710
711 # Remocion de Interferencia en el Cross Spectra
711 # Remocion de Interferencia en el Cross Spectra
712 if jcspectra is None:
712 if jcspectra is None:
713 return jspectra, jcspectra
713 return jspectra, jcspectra
714 num_pairs = int(jcspectra.size / (num_prof * num_hei))
714 num_pairs = int(jcspectra.size / (num_prof * num_hei))
715 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
715 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
716
716
717 for ip in range(num_pairs):
717 for ip in range(num_pairs):
718
718
719 #-------------------------------------------
719 #-------------------------------------------
720
720
721 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
721 cspower = numpy.abs(jcspectra[ip, mask_prof, :])
722 cspower = cspower[:, hei_interf]
722 cspower = cspower[:, hei_interf]
723 cspower = cspower.sum(axis=0)
723 cspower = cspower.sum(axis=0)
724
724
725 cspsort = cspower.ravel().argsort()
725 cspsort = cspower.ravel().argsort()
726 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
726 junkcspc_interf = jcspectra[ip, :, hei_interf[cspsort[list(range(
727 offhei_interf, nhei_interf + offhei_interf))]]]
727 offhei_interf, nhei_interf + offhei_interf))]]]
728 junkcspc_interf = junkcspc_interf.transpose()
728 junkcspc_interf = junkcspc_interf.transpose()
729 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
729 jcspc_interf = junkcspc_interf.sum(axis=1) / nhei_interf
730
730
731 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
731 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
732
732
733 median_real = int(numpy.median(numpy.real(
733 median_real = int(numpy.median(numpy.real(
734 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
734 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
735 median_imag = int(numpy.median(numpy.imag(
735 median_imag = int(numpy.median(numpy.imag(
736 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
736 junkcspc_interf[mask_prof[ind[list(range(3 * num_prof // 4))]], :])))
737 comp_mask_prof = [int(e) for e in comp_mask_prof]
737 comp_mask_prof = [int(e) for e in comp_mask_prof]
738 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
738 junkcspc_interf[comp_mask_prof, :] = numpy.complex(
739 median_real, median_imag)
739 median_real, median_imag)
740
740
741 for iprof in range(num_prof):
741 for iprof in range(num_prof):
742 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
742 ind = numpy.abs(junkcspc_interf[iprof, :]).ravel().argsort()
743 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
743 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf // 2]]
744
744
745 # Removiendo la Interferencia
745 # Removiendo la Interferencia
746 jcspectra[ip, :, ind_hei] = jcspectra[ip,
746 jcspectra[ip, :, ind_hei] = jcspectra[ip,
747 :, ind_hei] - jcspc_interf
747 :, ind_hei] - jcspc_interf
748
748
749 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
749 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
750 maxid = ListAux.index(max(ListAux))
750 maxid = ListAux.index(max(ListAux))
751
751
752 ind = numpy.array([-2, -1, 1, 2])
752 ind = numpy.array([-2, -1, 1, 2])
753 xx = numpy.zeros([4, 4])
753 xx = numpy.zeros([4, 4])
754
754
755 for id1 in range(4):
755 for id1 in range(4):
756 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
756 xx[:, id1] = ind[id1]**numpy.asarray(list(range(4)))
757
757
758 xx_inv = numpy.linalg.inv(xx)
758 xx_inv = numpy.linalg.inv(xx)
759 xx = xx_inv[:, 0]
759 xx = xx_inv[:, 0]
760
760
761 ind = (ind + maxid + num_mask_prof) % num_mask_prof
761 ind = (ind + maxid + num_mask_prof) % num_mask_prof
762 yy = jcspectra[ip, mask_prof[ind], :]
762 yy = jcspectra[ip, mask_prof[ind], :]
763 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
763 jcspectra[ip, mask_prof[maxid], :] = numpy.dot(yy.transpose(), xx)
764
764
765 # Guardar Resultados
765 # Guardar Resultados
766 self.dataOut.data_spc = jspectra
766 self.dataOut.data_spc = jspectra
767 self.dataOut.data_cspc = jcspectra
767 self.dataOut.data_cspc = jcspectra
768
768
769 return 1
769 return 1
770
770
771 def run(self, dataOut, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None, mode=1):
771 def run(self, dataOut, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None, mode=1):
772
772
773 self.dataOut = dataOut
773 self.dataOut = dataOut
774
774
775 if mode == 1:
775 if mode == 1:
776 self.removeInterference(interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None)
776 self.removeInterference(interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None)
777 elif mode == 2:
777 elif mode == 2:
778 self.removeInterference2()
778 self.removeInterference2()
779
779
780 return self.dataOut
780 return self.dataOut
781
781
782 class removeInterferenceAtFreq(Operation):
782 class removeInterferenceAtFreq(Operation):
783 '''
783 '''
784 Written by R. Flores
784 Written by R. Flores
785 '''
785 '''
786 """Operation to remove interfernce at a known frequency(s).
786 """Operation to remove interfernce at a known frequency(s).
787
787
788 Parameters:
788 Parameters:
789 -----------
789 -----------
790 None
790 None
791
791
792 Example
792 Example
793 --------
793 --------
794
794
795 op = proc_unit.addOperation(name='removeInterferenceAtFreq')
795 op = proc_unit.addOperation(name='removeInterferenceAtFreq')
796
796
797 """
797 """
798
798
799 def __init__(self):
799 def __init__(self):
800
800
801 Operation.__init__(self)
801 Operation.__init__(self)
802
802
803 def run(self, dataOut, freq = None, freqList = None):
803 def run(self, dataOut, freq = None, freqList = None):
804
804
805 VelRange = dataOut.getVelRange()
805 VelRange = dataOut.getVelRange()
806 #print("VelRange: ", VelRange)
806 #print("VelRange: ", VelRange)
807
807
808 freq_ids = []
808 freq_ids = []
809
809
810 if freq is not None:
810 if freq is not None:
811 #print("freq")
811 #print("freq")
812 #if freq < 0:
812 #if freq < 0:
813 inda = numpy.where(VelRange >= freq)
813 inda = numpy.where(VelRange >= freq)
814 minIndex = inda[0][0]
814 minIndex = inda[0][0]
815 #print(numpy.shape(dataOut.dataLag_spc))
815 #print(numpy.shape(dataOut.dataLag_spc))
816 dataOut.data_spc[:,minIndex,:] = numpy.nan
816 dataOut.data_spc[:,minIndex,:] = numpy.nan
817
817
818 #inda = numpy.where(VelRange >= ymin_noise)
818 #inda = numpy.where(VelRange >= ymin_noise)
819 #indb = numpy.where(VelRange <= ymax_noise)
819 #indb = numpy.where(VelRange <= ymax_noise)
820
820
821 #minIndex = inda[0][0]
821 #minIndex = inda[0][0]
822 #maxIndex = indb[0][-1]
822 #maxIndex = indb[0][-1]
823
823
824 elif freqList is not None:
824 elif freqList is not None:
825 #print("freqList")
825 #print("freqList")
826 for freq in freqList:
826 for freq in freqList:
827 #if freq < 0:
827 #if freq < 0:
828 inda = numpy.where(VelRange >= freq)
828 inda = numpy.where(VelRange >= freq)
829 minIndex = inda[0][0]
829 minIndex = inda[0][0]
830 #print(numpy.shape(dataOut.dataLag_spc))
830 #print(numpy.shape(dataOut.dataLag_spc))
831 if freq > 0:
831 if freq > 0:
832 #dataOut.data_spc[:,minIndex-1,:] = numpy.nan
832 #dataOut.data_spc[:,minIndex-1,:] = numpy.nan
833 freq_ids.append(minIndex-1)
833 freq_ids.append(minIndex-1)
834 else:
834 else:
835 #dataOut.data_spc[:,minIndex,:] = numpy.nan
835 #dataOut.data_spc[:,minIndex,:] = numpy.nan
836 freq_ids.append(minIndex)
836 freq_ids.append(minIndex)
837 else:
837 else:
838 raise ValueError("freq or freqList should be specified ...")
838 raise ValueError("freq or freqList should be specified ...")
839
839
840 #freq_ids = numpy.array(freq_ids).flatten()
840 #freq_ids = numpy.array(freq_ids).flatten()
841
841
842 avg = numpy.mean(dataOut.data_spc[:,[t for t in range(dataOut.data_spc.shape[0]) if t not in freq_ids],:],axis=1)
842 avg = numpy.mean(dataOut.data_spc[:,[t for t in range(dataOut.data_spc.shape[0]) if t not in freq_ids],:],axis=1)
843
843
844 for p in list(freq_ids):
844 for p in list(freq_ids):
845 dataOut.data_spc[:,p,:] = avg#numpy.nan
845 dataOut.data_spc[:,p,:] = avg#numpy.nan
846
846
847
847
848 return dataOut
848 return dataOut
849
849
850 class IncohInt(Operation):
850 class IncohInt(Operation):
851
851
852 __profIndex = 0
852 __profIndex = 0
853 __withOverapping = False
853 __withOverapping = False
854
854
855 __byTime = False
855 __byTime = False
856 __initime = None
856 __initime = None
857 __lastdatatime = None
857 __lastdatatime = None
858 __integrationtime = None
858 __integrationtime = None
859
859
860 __buffer_spc = None
860 __buffer_spc = None
861 __buffer_cspc = None
861 __buffer_cspc = None
862 __buffer_dc = None
862 __buffer_dc = None
863
863
864 __dataReady = False
864 __dataReady = False
865
865
866 __timeInterval = None
866 __timeInterval = None
867
867
868 n = None
868 n = None
869
869
870 def __init__(self):
870 def __init__(self):
871
871
872 Operation.__init__(self)
872 Operation.__init__(self)
873
873
874 def setup(self, n=None, timeInterval=None, overlapping=False):
874 def setup(self, n=None, timeInterval=None, overlapping=False):
875 """
875 """
876 Set the parameters of the integration class.
876 Set the parameters of the integration class.
877
877
878 Inputs:
878 Inputs:
879
879
880 n : Number of coherent integrations
880 n : Number of coherent integrations
881 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
881 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
882 overlapping :
882 overlapping :
883
883
884 """
884 """
885
885
886 self.__initime = None
886 self.__initime = None
887 self.__lastdatatime = 0
887 self.__lastdatatime = 0
888
888
889 self.__buffer_spc = 0
889 self.__buffer_spc = 0
890 self.__buffer_cspc = 0
890 self.__buffer_cspc = 0
891 self.__buffer_dc = 0
891 self.__buffer_dc = 0
892
892
893 self.__profIndex = 0
893 self.__profIndex = 0
894 self.__dataReady = False
894 self.__dataReady = False
895 self.__byTime = False
895 self.__byTime = False
896
896
897 if n is None and timeInterval is None:
897 if n is None and timeInterval is None:
898 raise ValueError("n or timeInterval should be specified ...")
898 raise ValueError("n or timeInterval should be specified ...")
899
899
900 if n is not None:
900 if n is not None:
901 self.n = int(n)
901 self.n = int(n)
902 else:
902 else:
903
903
904 self.__integrationtime = int(timeInterval)
904 self.__integrationtime = int(timeInterval)
905 self.n = None
905 self.n = None
906 self.__byTime = True
906 self.__byTime = True
907
907
908 def putData(self, data_spc, data_cspc, data_dc):
908 def putData(self, data_spc, data_cspc, data_dc):
909 """
909 """
910 Add a profile to the __buffer_spc and increase in one the __profileIndex
910 Add a profile to the __buffer_spc and increase in one the __profileIndex
911
911
912 """
912 """
913
913
914 self.__buffer_spc += data_spc
914 self.__buffer_spc += data_spc
915
915
916 if data_cspc is None:
916 if data_cspc is None:
917 self.__buffer_cspc = None
917 self.__buffer_cspc = None
918 else:
918 else:
919 self.__buffer_cspc += data_cspc
919 self.__buffer_cspc += data_cspc
920
920
921 if data_dc is None:
921 if data_dc is None:
922 self.__buffer_dc = None
922 self.__buffer_dc = None
923 else:
923 else:
924 self.__buffer_dc += data_dc
924 self.__buffer_dc += data_dc
925
925
926 self.__profIndex += 1
926 self.__profIndex += 1
927
927
928 return
928 return
929
929
930 def pushData(self):
930 def pushData(self):
931 """
931 """
932 Return the sum of the last profiles and the profiles used in the sum.
932 Return the sum of the last profiles and the profiles used in the sum.
933
933
934 Affected:
934 Affected:
935
935
936 self.__profileIndex
936 self.__profileIndex
937
937
938 """
938 """
939
939
940 data_spc = self.__buffer_spc
940 data_spc = self.__buffer_spc
941 data_cspc = self.__buffer_cspc
941 data_cspc = self.__buffer_cspc
942 data_dc = self.__buffer_dc
942 data_dc = self.__buffer_dc
943 n = self.__profIndex
943 n = self.__profIndex
944
944
945 self.__buffer_spc = 0
945 self.__buffer_spc = 0
946 self.__buffer_cspc = 0
946 self.__buffer_cspc = 0
947 self.__buffer_dc = 0
947 self.__buffer_dc = 0
948 self.__profIndex = 0
948 self.__profIndex = 0
949
949
950 return data_spc, data_cspc, data_dc, n
950 return data_spc, data_cspc, data_dc, n
951
951
952 def byProfiles(self, *args):
952 def byProfiles(self, *args):
953
953
954 self.__dataReady = False
954 self.__dataReady = False
955 avgdata_spc = None
955 avgdata_spc = None
956 avgdata_cspc = None
956 avgdata_cspc = None
957 avgdata_dc = None
957 avgdata_dc = None
958
958
959 self.putData(*args)
959 self.putData(*args)
960
960
961 if self.__profIndex == self.n:
961 if self.__profIndex == self.n:
962
962
963 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
963 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
964 self.n = n
964 self.n = n
965 self.__dataReady = True
965 self.__dataReady = True
966
966
967 return avgdata_spc, avgdata_cspc, avgdata_dc
967 return avgdata_spc, avgdata_cspc, avgdata_dc
968
968
969 def byTime(self, datatime, *args):
969 def byTime(self, datatime, *args):
970
970
971 self.__dataReady = False
971 self.__dataReady = False
972 avgdata_spc = None
972 avgdata_spc = None
973 avgdata_cspc = None
973 avgdata_cspc = None
974 avgdata_dc = None
974 avgdata_dc = None
975
975
976 self.putData(*args)
976 self.putData(*args)
977
977
978 if (datatime - self.__initime) >= self.__integrationtime:
978 if (datatime - self.__initime) >= self.__integrationtime:
979 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
979 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
980 self.n = n
980 self.n = n
981 self.__dataReady = True
981 self.__dataReady = True
982
982
983 return avgdata_spc, avgdata_cspc, avgdata_dc
983 return avgdata_spc, avgdata_cspc, avgdata_dc
984
984
985 def integrate(self, datatime, *args):
985 def integrate(self, datatime, *args):
986
986
987 if self.__profIndex == 0:
987 if self.__profIndex == 0:
988 self.__initime = datatime
988 self.__initime = datatime
989
989
990 if self.__byTime:
990 if self.__byTime:
991 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
991 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(
992 datatime, *args)
992 datatime, *args)
993 else:
993 else:
994 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
994 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
995
995
996 if not self.__dataReady:
996 if not self.__dataReady:
997 return None, None, None, None
997 return None, None, None, None
998
998
999 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
999 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
1000
1000
1001 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1001 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1002 if n == 1:
1002 if n == 1:
1003 return dataOut
1003 return dataOut
1004 print("JERE")
1004 print("JERE")
1005 dataOut.flagNoData = True
1005 dataOut.flagNoData = True
1006
1006
1007 if not self.isConfig:
1007 if not self.isConfig:
1008 self.setup(n, timeInterval, overlapping)
1008 self.setup(n, timeInterval, overlapping)
1009 self.isConfig = True
1009 self.isConfig = True
1010
1010
1011 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1011 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1012 dataOut.data_spc,
1012 dataOut.data_spc,
1013 dataOut.data_cspc,
1013 dataOut.data_cspc,
1014 dataOut.data_dc)
1014 dataOut.data_dc)
1015
1015
1016 if self.__dataReady:
1016 if self.__dataReady:
1017
1017
1018 dataOut.data_spc = avgdata_spc
1018 dataOut.data_spc = avgdata_spc
1019 print(numpy.sum(dataOut.data_spc))
1019 print(numpy.sum(dataOut.data_spc))
1020 exit(1)
1020 exit(1)
1021 dataOut.data_cspc = avgdata_cspc
1021 dataOut.data_cspc = avgdata_cspc
1022 dataOut.data_dc = avgdata_dc
1022 dataOut.data_dc = avgdata_dc
1023 dataOut.nIncohInt *= self.n
1023 dataOut.nIncohInt *= self.n
1024 dataOut.utctime = avgdatatime
1024 dataOut.utctime = avgdatatime
1025 dataOut.flagNoData = False
1025 dataOut.flagNoData = False
1026
1026
1027 return dataOut
1027 return dataOut
1028
1028
1029 class dopplerFlip(Operation):
1029 class dopplerFlip(Operation):
1030
1030
1031 def run(self, dataOut, chann = None):
1031 def run(self, dataOut, chann = None):
1032 # arreglo 1: (num_chan, num_profiles, num_heights)
1032 # arreglo 1: (num_chan, num_profiles, num_heights)
1033 self.dataOut = dataOut
1033 self.dataOut = dataOut
1034 # JULIA-oblicua, indice 2
1034 # JULIA-oblicua, indice 2
1035 # arreglo 2: (num_profiles, num_heights)
1035 # arreglo 2: (num_profiles, num_heights)
1036 jspectra = self.dataOut.data_spc[chann]
1036 jspectra = self.dataOut.data_spc[chann]
1037 jspectra_tmp = numpy.zeros(jspectra.shape)
1037 jspectra_tmp = numpy.zeros(jspectra.shape)
1038 num_profiles = jspectra.shape[0]
1038 num_profiles = jspectra.shape[0]
1039 freq_dc = int(num_profiles / 2)
1039 freq_dc = int(num_profiles / 2)
1040 # Flip con for
1040 # Flip con for
1041 for j in range(num_profiles):
1041 for j in range(num_profiles):
1042 jspectra_tmp[num_profiles-j-1]= jspectra[j]
1042 jspectra_tmp[num_profiles-j-1]= jspectra[j]
1043 # Intercambio perfil de DC con perfil inmediato anterior
1043 # Intercambio perfil de DC con perfil inmediato anterior
1044 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
1044 jspectra_tmp[freq_dc-1]= jspectra[freq_dc-1]
1045 jspectra_tmp[freq_dc]= jspectra[freq_dc]
1045 jspectra_tmp[freq_dc]= jspectra[freq_dc]
1046 # canal modificado es re-escrito en el arreglo de canales
1046 # canal modificado es re-escrito en el arreglo de canales
1047 self.dataOut.data_spc[chann] = jspectra_tmp
1047 self.dataOut.data_spc[chann] = jspectra_tmp
1048
1048
1049 return self.dataOut
1049 return self.dataOut
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now