##// END OF EJS Templates
extrapoint=1: This way, develop similar to master.
imanay -
r1693:bfd516acb20d
parent child
Show More
@@ -1,1228 +1,1229
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2021 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Classes to plot Spectra data
5 """Classes to plot Spectra data
6
6
7 """
7 """
8
8
9 import os
9 import os
10 import numpy
10 import numpy
11
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
12 from schainpy.model.graphics.jroplot_base import Plot, plt, log
13
13
14
14
15 class SpectraPlot(Plot):
15 class SpectraPlot(Plot):
16 '''
16 '''
17 Plot for Spectra data
17 Plot for Spectra data
18 '''
18 '''
19
19
20 CODE = 'spc'
20 CODE = 'spc'
21 colormap = 'jet'
21 colormap = 'jet'
22 plot_type = 'pcolor'
22 plot_type = 'pcolor'
23 buffering = False
23 buffering = False
24
24
25 def setup(self):
25 def setup(self):
26
26
27 self.nplots = len(self.data.channels)
27 self.nplots = len(self.data.channels)
28 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
28 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
29 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
29 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
30 self.height = 2.6 * self.nrows
30 self.height = 2.6 * self.nrows
31 self.cb_label = 'dB'
31 self.cb_label = 'dB'
32 if self.showprofile:
32 if self.showprofile:
33 self.width = 4 * self.ncols
33 self.width = 4 * self.ncols
34 else:
34 else:
35 self.width = 3.5 * self.ncols
35 self.width = 3.5 * self.ncols
36 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
36 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
37 self.ylabel = 'Range [km]'
37 self.ylabel = 'Range [km]'
38
38
39 def update(self, dataOut):
39 def update(self, dataOut):
40
40
41 data = {}
41 data = {}
42 meta = {}
42 meta = {}
43 spc = 10 * numpy.log10(dataOut.data_spc / dataOut.normFactor)
43 spc = 10 * numpy.log10(dataOut.data_spc / dataOut.normFactor)
44 data['spc'] = spc
44 data['spc'] = spc
45 data['rti'] = dataOut.getPower()
45 data['rti'] = dataOut.getPower()
46 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor)
46 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor)
47 extrapoints = spc.shape[1] % dataOut.nFFTPoints
47 extrapoints = spc.shape[1] % dataOut.nFFTPoints
48 extrapoints=1
48 meta['xrange'] = (dataOut.getFreqRange(extrapoints) / 1000., dataOut.getAcfRange(extrapoints), dataOut.getVelRange(extrapoints))
49 meta['xrange'] = (dataOut.getFreqRange(extrapoints) / 1000., dataOut.getAcfRange(extrapoints), dataOut.getVelRange(extrapoints))
49 if self.CODE == 'spc_moments':
50 if self.CODE == 'spc_moments':
50 data['moments'] = dataOut.moments
51 data['moments'] = dataOut.moments
51 if self.CODE == 'gaussian_fit':
52 if self.CODE == 'gaussian_fit':
52 data['gaussfit'] = dataOut.DGauFitParams
53 data['gaussfit'] = dataOut.DGauFitParams
53
54
54 return data, meta
55 return data, meta
55
56
56 def plot(self):
57 def plot(self):
57
58
58 if self.xaxis == "frequency":
59 if self.xaxis == "frequency":
59 x = self.data.xrange[0]
60 x = self.data.xrange[0]
60 self.xlabel = "Frequency (kHz)"
61 self.xlabel = "Frequency (kHz)"
61 elif self.xaxis == "time":
62 elif self.xaxis == "time":
62 x = self.data.xrange[1]
63 x = self.data.xrange[1]
63 self.xlabel = "Time (ms)"
64 self.xlabel = "Time (ms)"
64 else:
65 else:
65 x = self.data.xrange[2]
66 x = self.data.xrange[2]
66 self.xlabel = "Velocity (m/s)"
67 self.xlabel = "Velocity (m/s)"
67
68
68 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
69 if (self.CODE == 'spc_moments') | (self.CODE == 'gaussian_fit'):
69 x = self.data.xrange[2]
70 x = self.data.xrange[2]
70 self.xlabel = "Velocity (m/s)"
71 self.xlabel = "Velocity (m/s)"
71
72
72 self.titles = []
73 self.titles = []
73
74
74 y = self.data.yrange
75 y = self.data.yrange
75 self.y = y
76 self.y = y
76
77
77 data = self.data[-1]
78 data = self.data[-1]
78 z = data['spc']
79 z = data['spc']
79
80
80 for n, ax in enumerate(self.axes):
81 for n, ax in enumerate(self.axes):
81 noise = data['noise'][n]
82 noise = data['noise'][n]
82
83
83 if self.CODE == 'spc_moments':
84 if self.CODE == 'spc_moments':
84 mean = data['moments'][n, 1]
85 mean = data['moments'][n, 1]
85 if self.CODE == 'gaussian_fit':
86 if self.CODE == 'gaussian_fit':
86 gau0 = data['gaussfit'][n][2,:,0]
87 gau0 = data['gaussfit'][n][2,:,0]
87 gau1 = data['gaussfit'][n][2,:,1]
88 gau1 = data['gaussfit'][n][2,:,1]
88 if ax.firsttime:
89 if ax.firsttime:
89 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
90 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
90 self.xmin = self.xmin if self.xmin else -self.xmax
91 self.xmin = self.xmin if self.xmin else -self.xmax
91 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
92 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
92 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
93 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
93 ax.plt = ax.pcolormesh(x, y, z[n].T,
94 ax.plt = ax.pcolormesh(x, y, z[n].T,
94 vmin=self.zmin,
95 vmin=self.zmin,
95 vmax=self.zmax,
96 vmax=self.zmax,
96 cmap=plt.get_cmap(self.colormap)
97 cmap=plt.get_cmap(self.colormap)
97 )
98 )
98
99
99 if self.showprofile:
100 if self.showprofile:
100 ax.plt_profile = self.pf_axes[n].plot(
101 ax.plt_profile = self.pf_axes[n].plot(
101 data['rti'][n], y)[0]
102 data['rti'][n], y)[0]
102 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
103 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
103 color="k", linestyle="dashed", lw=1)[0]
104 color="k", linestyle="dashed", lw=1)[0]
104 if self.CODE == 'spc_moments':
105 if self.CODE == 'spc_moments':
105 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
106 ax.plt_mean = ax.plot(mean, y, color='k', lw=1)[0]
106 if self.CODE == 'gaussian_fit':
107 if self.CODE == 'gaussian_fit':
107 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
108 ax.plt_gau0 = ax.plot(gau0, y, color='r', lw=1)[0]
108 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
109 ax.plt_gau1 = ax.plot(gau1, y, color='y', lw=1)[0]
109 else:
110 else:
110 ax.plt.set_array(z[n].T.ravel())
111 ax.plt.set_array(z[n].T.ravel())
111 if self.showprofile:
112 if self.showprofile:
112 ax.plt_profile.set_data(data['rti'][n], y)
113 ax.plt_profile.set_data(data['rti'][n], y)
113 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
114 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
114 if self.CODE == 'spc_moments':
115 if self.CODE == 'spc_moments':
115 ax.plt_mean.set_data(mean, y)
116 ax.plt_mean.set_data(mean, y)
116 if self.CODE == 'gaussian_fit':
117 if self.CODE == 'gaussian_fit':
117 ax.plt_gau0.set_data(gau0, y)
118 ax.plt_gau0.set_data(gau0, y)
118 ax.plt_gau1.set_data(gau1, y)
119 ax.plt_gau1.set_data(gau1, y)
119 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
120 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
120
121
121 class SpectraObliquePlot(Plot):
122 class SpectraObliquePlot(Plot):
122 '''
123 '''
123 Plot for Spectra data
124 Plot for Spectra data
124 '''
125 '''
125
126
126 CODE = 'spc_oblique'
127 CODE = 'spc_oblique'
127 colormap = 'jet'
128 colormap = 'jet'
128 plot_type = 'pcolor'
129 plot_type = 'pcolor'
129
130
130 def setup(self):
131 def setup(self):
131 self.xaxis = "oblique"
132 self.xaxis = "oblique"
132 self.nplots = len(self.data.channels)
133 self.nplots = len(self.data.channels)
133 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
134 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
134 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
135 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
135 self.height = 2.6 * self.nrows
136 self.height = 2.6 * self.nrows
136 self.cb_label = 'dB'
137 self.cb_label = 'dB'
137 if self.showprofile:
138 if self.showprofile:
138 self.width = 4 * self.ncols
139 self.width = 4 * self.ncols
139 else:
140 else:
140 self.width = 3.5 * self.ncols
141 self.width = 3.5 * self.ncols
141 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
142 self.plots_adjust.update({'wspace': 0.8, 'hspace':0.2, 'left': 0.2, 'right': 0.9, 'bottom': 0.18})
142 self.ylabel = 'Range [km]'
143 self.ylabel = 'Range [km]'
143
144
144 def update(self, dataOut):
145 def update(self, dataOut):
145
146
146 data = {}
147 data = {}
147 meta = {}
148 meta = {}
148 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
149 spc = 10*numpy.log10(dataOut.data_spc/dataOut.normFactor)
149 data['spc'] = spc
150 data['spc'] = spc
150 data['rti'] = dataOut.getPower()
151 data['rti'] = dataOut.getPower()
151 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
152 data['noise'] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
152 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
153 meta['xrange'] = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
153
154
154 data['shift1'] = dataOut.Oblique_params[0][1]
155 data['shift1'] = dataOut.Oblique_params[0][1]
155 data['shift2'] = dataOut.Oblique_params[0][4]
156 data['shift2'] = dataOut.Oblique_params[0][4]
156 data['shift1_error'] = dataOut.Oblique_param_errors[0][1]
157 data['shift1_error'] = dataOut.Oblique_param_errors[0][1]
157 data['shift2_error'] = dataOut.Oblique_param_errors[0][4]
158 data['shift2_error'] = dataOut.Oblique_param_errors[0][4]
158
159
159 return data, meta
160 return data, meta
160
161
161 def plot(self):
162 def plot(self):
162
163
163 if self.xaxis == "frequency":
164 if self.xaxis == "frequency":
164 x = self.data.xrange[0]
165 x = self.data.xrange[0]
165 self.xlabel = "Frequency (kHz)"
166 self.xlabel = "Frequency (kHz)"
166 elif self.xaxis == "time":
167 elif self.xaxis == "time":
167 x = self.data.xrange[1]
168 x = self.data.xrange[1]
168 self.xlabel = "Time (ms)"
169 self.xlabel = "Time (ms)"
169 else:
170 else:
170 x = self.data.xrange[2]
171 x = self.data.xrange[2]
171 self.xlabel = "Velocity (m/s)"
172 self.xlabel = "Velocity (m/s)"
172
173
173 self.titles = []
174 self.titles = []
174
175
175 y = self.data.yrange
176 y = self.data.yrange
176 self.y = y
177 self.y = y
177 z = self.data['spc']
178 z = self.data['spc']
178
179
179 for n, ax in enumerate(self.axes):
180 for n, ax in enumerate(self.axes):
180 noise = self.data['noise'][n][-1]
181 noise = self.data['noise'][n][-1]
181 shift1 = self.data['shift1']
182 shift1 = self.data['shift1']
182 shift2 = self.data['shift2']
183 shift2 = self.data['shift2']
183 err1 = self.data['shift1_error']
184 err1 = self.data['shift1_error']
184 err2 = self.data['shift2_error']
185 err2 = self.data['shift2_error']
185 if ax.firsttime:
186 if ax.firsttime:
186 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
187 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
187 self.xmin = self.xmin if self.xmin else -self.xmax
188 self.xmin = self.xmin if self.xmin else -self.xmax
188 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
189 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
189 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
190 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
190 ax.plt = ax.pcolormesh(x, y, z[n].T,
191 ax.plt = ax.pcolormesh(x, y, z[n].T,
191 vmin=self.zmin,
192 vmin=self.zmin,
192 vmax=self.zmax,
193 vmax=self.zmax,
193 cmap=plt.get_cmap(self.colormap)
194 cmap=plt.get_cmap(self.colormap)
194 )
195 )
195
196
196 if self.showprofile:
197 if self.showprofile:
197 ax.plt_profile = self.pf_axes[n].plot(
198 ax.plt_profile = self.pf_axes[n].plot(
198 self.data['rti'][n][-1], y)[0]
199 self.data['rti'][n][-1], y)[0]
199 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
200 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
200 color="k", linestyle="dashed", lw=1)[0]
201 color="k", linestyle="dashed", lw=1)[0]
201
202
202 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=0.2, marker='x', linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
203 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^', elinewidth=0.2, marker='x', linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
203 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
204 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
204 else:
205 else:
205 self.ploterr1.remove()
206 self.ploterr1.remove()
206 self.ploterr2.remove()
207 self.ploterr2.remove()
207 ax.plt.set_array(z[n].T.ravel())
208 ax.plt.set_array(z[n].T.ravel())
208 if self.showprofile:
209 if self.showprofile:
209 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
210 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
210 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
211 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
211 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
212 self.ploterr1 = ax.errorbar(shift1, y, xerr=err1, fmt='k^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
212 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
213 self.ploterr2 = ax.errorbar(shift2, y, xerr=err2, fmt='m^',elinewidth=0.2,marker='x',linestyle='None',markersize=0.5,capsize=0.3,markeredgewidth=0.2)
213
214
214 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
215 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
215
216
216
217
217 class CrossSpectraPlot(Plot):
218 class CrossSpectraPlot(Plot):
218
219
219 CODE = 'cspc'
220 CODE = 'cspc'
220 colormap = 'jet'
221 colormap = 'jet'
221 plot_type = 'pcolor'
222 plot_type = 'pcolor'
222 zmin_coh = None
223 zmin_coh = None
223 zmax_coh = None
224 zmax_coh = None
224 zmin_phase = None
225 zmin_phase = None
225 zmax_phase = None
226 zmax_phase = None
226
227
227 def setup(self):
228 def setup(self):
228
229
229 self.ncols = 4
230 self.ncols = 4
230 self.nplots = len(self.data.pairs) * 2
231 self.nplots = len(self.data.pairs) * 2
231 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
232 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
232 self.width = 3.1 * self.ncols
233 self.width = 3.1 * self.ncols
233 self.height = 5 * self.nrows
234 self.height = 5 * self.nrows
234 self.ylabel = 'Range [km]'
235 self.ylabel = 'Range [km]'
235 self.showprofile = False
236 self.showprofile = False
236 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
237 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
237
238
238 def update(self, dataOut):
239 def update(self, dataOut):
239
240
240 data = {}
241 data = {}
241 meta = {}
242 meta = {}
242
243
243 spc = dataOut.data_spc
244 spc = dataOut.data_spc
244 cspc = dataOut.data_cspc
245 cspc = dataOut.data_cspc
245 extrapoints = spc.shape[1] % dataOut.nFFTPoints
246 extrapoints = spc.shape[1] % dataOut.nFFTPoints
246 meta['xrange'] = (dataOut.getFreqRange(extrapoints) / 1000., dataOut.getAcfRange(extrapoints), dataOut.getVelRange(extrapoints))
247 meta['xrange'] = (dataOut.getFreqRange(extrapoints) / 1000., dataOut.getAcfRange(extrapoints), dataOut.getVelRange(extrapoints))
247 meta['pairs'] = dataOut.pairsList
248 meta['pairs'] = dataOut.pairsList
248
249
249 tmp = []
250 tmp = []
250
251
251 for n, pair in enumerate(meta['pairs']):
252 for n, pair in enumerate(meta['pairs']):
252 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
253 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
253 coh = numpy.abs(out)
254 coh = numpy.abs(out)
254 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
255 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
255 tmp.append(coh)
256 tmp.append(coh)
256 tmp.append(phase)
257 tmp.append(phase)
257
258
258 data['cspc'] = numpy.array(tmp)
259 data['cspc'] = numpy.array(tmp)
259
260
260 return data, meta
261 return data, meta
261
262
262 def plot(self):
263 def plot(self):
263
264
264 if self.xaxis == "frequency":
265 if self.xaxis == "frequency":
265 x = self.data.xrange[0]
266 x = self.data.xrange[0]
266 self.xlabel = "Frequency (kHz)"
267 self.xlabel = "Frequency (kHz)"
267 elif self.xaxis == "time":
268 elif self.xaxis == "time":
268 x = self.data.xrange[1]
269 x = self.data.xrange[1]
269 self.xlabel = "Time (ms)"
270 self.xlabel = "Time (ms)"
270 else:
271 else:
271 x = self.data.xrange[2]
272 x = self.data.xrange[2]
272 self.xlabel = "Velocity (m/s)"
273 self.xlabel = "Velocity (m/s)"
273
274
274 self.titles = []
275 self.titles = []
275
276
276 y = self.data.yrange
277 y = self.data.yrange
277 self.y = y
278 self.y = y
278
279
279 data = self.data[-1]
280 data = self.data[-1]
280 cspc = data['cspc']
281 cspc = data['cspc']
281
282
282 for n in range(len(self.data.pairs)):
283 for n in range(len(self.data.pairs)):
283 pair = self.data.pairs[n]
284 pair = self.data.pairs[n]
284 coh = cspc[n * 2]
285 coh = cspc[n * 2]
285 phase = cspc[n * 2 + 1]
286 phase = cspc[n * 2 + 1]
286 ax = self.axes[2 * n]
287 ax = self.axes[2 * n]
287 if ax.firsttime:
288 if ax.firsttime:
288 ax.plt = ax.pcolormesh(x, y, coh.T,
289 ax.plt = ax.pcolormesh(x, y, coh.T,
289 vmin=0,
290 vmin=0,
290 vmax=1,
291 vmax=1,
291 cmap=plt.get_cmap(self.colormap_coh)
292 cmap=plt.get_cmap(self.colormap_coh)
292 )
293 )
293 else:
294 else:
294 ax.plt.set_array(coh.T.ravel())
295 ax.plt.set_array(coh.T.ravel())
295 self.titles.append(
296 self.titles.append(
296 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
297 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
297
298
298 ax = self.axes[2 * n + 1]
299 ax = self.axes[2 * n + 1]
299 if ax.firsttime:
300 if ax.firsttime:
300 ax.plt = ax.pcolormesh(x, y, phase.T,
301 ax.plt = ax.pcolormesh(x, y, phase.T,
301 vmin=-180,
302 vmin=-180,
302 vmax=180,
303 vmax=180,
303 cmap=plt.get_cmap(self.colormap_phase)
304 cmap=plt.get_cmap(self.colormap_phase)
304 )
305 )
305 else:
306 else:
306 ax.plt.set_array(phase.T.ravel())
307 ax.plt.set_array(phase.T.ravel())
307 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
308 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
308
309
309
310
310 class CrossSpectra4Plot(Plot):
311 class CrossSpectra4Plot(Plot):
311
312
312 CODE = 'cspc'
313 CODE = 'cspc'
313 colormap = 'jet'
314 colormap = 'jet'
314 plot_type = 'pcolor'
315 plot_type = 'pcolor'
315 zmin_coh = None
316 zmin_coh = None
316 zmax_coh = None
317 zmax_coh = None
317 zmin_phase = None
318 zmin_phase = None
318 zmax_phase = None
319 zmax_phase = None
319
320
320 def setup(self):
321 def setup(self):
321
322
322 self.ncols = 4
323 self.ncols = 4
323 self.nrows = len(self.data.pairs)
324 self.nrows = len(self.data.pairs)
324 self.nplots = self.nrows * 4
325 self.nplots = self.nrows * 4
325 self.width = 3.1 * self.ncols
326 self.width = 3.1 * self.ncols
326 self.height = 5 * self.nrows
327 self.height = 5 * self.nrows
327 self.ylabel = 'Range [km]'
328 self.ylabel = 'Range [km]'
328 self.showprofile = False
329 self.showprofile = False
329 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
330 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
330
331
331 def plot(self):
332 def plot(self):
332
333
333 if self.xaxis == "frequency":
334 if self.xaxis == "frequency":
334 x = self.data.xrange[0]
335 x = self.data.xrange[0]
335 self.xlabel = "Frequency (kHz)"
336 self.xlabel = "Frequency (kHz)"
336 elif self.xaxis == "time":
337 elif self.xaxis == "time":
337 x = self.data.xrange[1]
338 x = self.data.xrange[1]
338 self.xlabel = "Time (ms)"
339 self.xlabel = "Time (ms)"
339 else:
340 else:
340 x = self.data.xrange[2]
341 x = self.data.xrange[2]
341 self.xlabel = "Velocity (m/s)"
342 self.xlabel = "Velocity (m/s)"
342
343
343 self.titles = []
344 self.titles = []
344
345
345
346
346 y = self.data.heights
347 y = self.data.heights
347 self.y = y
348 self.y = y
348 nspc = self.data['spc']
349 nspc = self.data['spc']
349 #print(numpy.shape(self.data['spc']))
350 #print(numpy.shape(self.data['spc']))
350 spc = self.data['cspc'][0]
351 spc = self.data['cspc'][0]
351 #print(numpy.shape(nspc))
352 #print(numpy.shape(nspc))
352 #exit()
353 #exit()
353 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
354 #nspc[1,:,:] = numpy.flip(nspc[1,:,:],axis=0)
354 #print(numpy.shape(spc))
355 #print(numpy.shape(spc))
355 #exit()
356 #exit()
356 cspc = self.data['cspc'][1]
357 cspc = self.data['cspc'][1]
357
358
358 #xflip=numpy.flip(x)
359 #xflip=numpy.flip(x)
359 #print(numpy.shape(cspc))
360 #print(numpy.shape(cspc))
360 #exit()
361 #exit()
361
362
362 for n in range(self.nrows):
363 for n in range(self.nrows):
363 noise = self.data['noise'][:,-1]
364 noise = self.data['noise'][:,-1]
364 pair = self.data.pairs[n]
365 pair = self.data.pairs[n]
365 #print(pair)
366 #print(pair)
366 #exit()
367 #exit()
367 ax = self.axes[4 * n]
368 ax = self.axes[4 * n]
368 if ax.firsttime:
369 if ax.firsttime:
369 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
370 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
370 self.xmin = self.xmin if self.xmin else -self.xmax
371 self.xmin = self.xmin if self.xmin else -self.xmax
371 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
372 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
372 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
373 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
373 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
374 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
374 vmin=self.zmin,
375 vmin=self.zmin,
375 vmax=self.zmax,
376 vmax=self.zmax,
376 cmap=plt.get_cmap(self.colormap)
377 cmap=plt.get_cmap(self.colormap)
377 )
378 )
378 else:
379 else:
379 #print(numpy.shape(nspc[pair[0]].T))
380 #print(numpy.shape(nspc[pair[0]].T))
380 #exit()
381 #exit()
381 ax.plt.set_array(nspc[pair[0]].T.ravel())
382 ax.plt.set_array(nspc[pair[0]].T.ravel())
382 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
383 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
383
384
384 ax = self.axes[4 * n + 1]
385 ax = self.axes[4 * n + 1]
385
386
386 if ax.firsttime:
387 if ax.firsttime:
387 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
388 ax.plt = ax.pcolormesh(x , y, numpy.flip(nspc[pair[1]],axis=0).T,
388 vmin=self.zmin,
389 vmin=self.zmin,
389 vmax=self.zmax,
390 vmax=self.zmax,
390 cmap=plt.get_cmap(self.colormap)
391 cmap=plt.get_cmap(self.colormap)
391 )
392 )
392 else:
393 else:
393
394
394 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
395 ax.plt.set_array(numpy.flip(nspc[pair[1]],axis=0).T.ravel())
395 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
396 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
396
397
397 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
398 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
398 coh = numpy.abs(out)
399 coh = numpy.abs(out)
399 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
400 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
400
401
401 ax = self.axes[4 * n + 2]
402 ax = self.axes[4 * n + 2]
402 if ax.firsttime:
403 if ax.firsttime:
403 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
404 ax.plt = ax.pcolormesh(x, y, numpy.flip(coh,axis=0).T,
404 vmin=0,
405 vmin=0,
405 vmax=1,
406 vmax=1,
406 cmap=plt.get_cmap(self.colormap_coh)
407 cmap=plt.get_cmap(self.colormap_coh)
407 )
408 )
408 else:
409 else:
409 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
410 ax.plt.set_array(numpy.flip(coh,axis=0).T.ravel())
410 self.titles.append(
411 self.titles.append(
411 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
412 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
412
413
413 ax = self.axes[4 * n + 3]
414 ax = self.axes[4 * n + 3]
414 if ax.firsttime:
415 if ax.firsttime:
415 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
416 ax.plt = ax.pcolormesh(x, y, numpy.flip(phase,axis=0).T,
416 vmin=-180,
417 vmin=-180,
417 vmax=180,
418 vmax=180,
418 cmap=plt.get_cmap(self.colormap_phase)
419 cmap=plt.get_cmap(self.colormap_phase)
419 )
420 )
420 else:
421 else:
421 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
422 ax.plt.set_array(numpy.flip(phase,axis=0).T.ravel())
422 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
423 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
423
424
424
425
425 class CrossSpectra2Plot(Plot):
426 class CrossSpectra2Plot(Plot):
426
427
427 CODE = 'cspc'
428 CODE = 'cspc'
428 colormap = 'jet'
429 colormap = 'jet'
429 plot_type = 'pcolor'
430 plot_type = 'pcolor'
430 zmin_coh = None
431 zmin_coh = None
431 zmax_coh = None
432 zmax_coh = None
432 zmin_phase = None
433 zmin_phase = None
433 zmax_phase = None
434 zmax_phase = None
434
435
435 def setup(self):
436 def setup(self):
436
437
437 self.ncols = 1
438 self.ncols = 1
438 self.nrows = len(self.data.pairs)
439 self.nrows = len(self.data.pairs)
439 self.nplots = self.nrows * 1
440 self.nplots = self.nrows * 1
440 self.width = 3.1 * self.ncols
441 self.width = 3.1 * self.ncols
441 self.height = 5 * self.nrows
442 self.height = 5 * self.nrows
442 self.ylabel = 'Range [km]'
443 self.ylabel = 'Range [km]'
443 self.showprofile = False
444 self.showprofile = False
444 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
445 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
445
446
446 def plot(self):
447 def plot(self):
447
448
448 if self.xaxis == "frequency":
449 if self.xaxis == "frequency":
449 x = self.data.xrange[0]
450 x = self.data.xrange[0]
450 self.xlabel = "Frequency (kHz)"
451 self.xlabel = "Frequency (kHz)"
451 elif self.xaxis == "time":
452 elif self.xaxis == "time":
452 x = self.data.xrange[1]
453 x = self.data.xrange[1]
453 self.xlabel = "Time (ms)"
454 self.xlabel = "Time (ms)"
454 else:
455 else:
455 x = self.data.xrange[2]
456 x = self.data.xrange[2]
456 self.xlabel = "Velocity (m/s)"
457 self.xlabel = "Velocity (m/s)"
457
458
458 self.titles = []
459 self.titles = []
459
460
460
461
461 y = self.data.heights
462 y = self.data.heights
462 self.y = y
463 self.y = y
463 #nspc = self.data['spc']
464 #nspc = self.data['spc']
464 #print(numpy.shape(self.data['spc']))
465 #print(numpy.shape(self.data['spc']))
465 #spc = self.data['cspc'][0]
466 #spc = self.data['cspc'][0]
466 #print(numpy.shape(spc))
467 #print(numpy.shape(spc))
467 #exit()
468 #exit()
468 cspc = self.data['cspc'][1]
469 cspc = self.data['cspc'][1]
469 #print(numpy.shape(cspc))
470 #print(numpy.shape(cspc))
470 #exit()
471 #exit()
471
472
472 for n in range(self.nrows):
473 for n in range(self.nrows):
473 noise = self.data['noise'][:,-1]
474 noise = self.data['noise'][:,-1]
474 pair = self.data.pairs[n]
475 pair = self.data.pairs[n]
475 #print(pair) #exit()
476 #print(pair) #exit()
476
477
477
478
478
479
479 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
480 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
480
481
481 #print(out[:,53])
482 #print(out[:,53])
482 #exit()
483 #exit()
483 cross = numpy.abs(out)
484 cross = numpy.abs(out)
484 z = cross/self.data.nFactor
485 z = cross/self.data.nFactor
485 #print("here")
486 #print("here")
486 #print(dataOut.data_spc[0,0,0])
487 #print(dataOut.data_spc[0,0,0])
487 #exit()
488 #exit()
488
489
489 cross = 10*numpy.log10(z)
490 cross = 10*numpy.log10(z)
490 #print(numpy.shape(cross))
491 #print(numpy.shape(cross))
491 #print(cross[0,:])
492 #print(cross[0,:])
492 #print(self.data.nFactor)
493 #print(self.data.nFactor)
493 #exit()
494 #exit()
494 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
495 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
495
496
496 ax = self.axes[1 * n]
497 ax = self.axes[1 * n]
497 if ax.firsttime:
498 if ax.firsttime:
498 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
499 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
499 self.xmin = self.xmin if self.xmin else -self.xmax
500 self.xmin = self.xmin if self.xmin else -self.xmax
500 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
501 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
501 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
502 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
502 ax.plt = ax.pcolormesh(x, y, cross.T,
503 ax.plt = ax.pcolormesh(x, y, cross.T,
503 vmin=self.zmin,
504 vmin=self.zmin,
504 vmax=self.zmax,
505 vmax=self.zmax,
505 cmap=plt.get_cmap(self.colormap)
506 cmap=plt.get_cmap(self.colormap)
506 )
507 )
507 else:
508 else:
508 ax.plt.set_array(cross.T.ravel())
509 ax.plt.set_array(cross.T.ravel())
509 self.titles.append(
510 self.titles.append(
510 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
511 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
511
512
512
513
513 class CrossSpectra3Plot(Plot):
514 class CrossSpectra3Plot(Plot):
514
515
515 CODE = 'cspc'
516 CODE = 'cspc'
516 colormap = 'jet'
517 colormap = 'jet'
517 plot_type = 'pcolor'
518 plot_type = 'pcolor'
518 zmin_coh = None
519 zmin_coh = None
519 zmax_coh = None
520 zmax_coh = None
520 zmin_phase = None
521 zmin_phase = None
521 zmax_phase = None
522 zmax_phase = None
522
523
523 def setup(self):
524 def setup(self):
524
525
525 self.ncols = 3
526 self.ncols = 3
526 self.nrows = len(self.data.pairs)
527 self.nrows = len(self.data.pairs)
527 self.nplots = self.nrows * 3
528 self.nplots = self.nrows * 3
528 self.width = 3.1 * self.ncols
529 self.width = 3.1 * self.ncols
529 self.height = 5 * self.nrows
530 self.height = 5 * self.nrows
530 self.ylabel = 'Range [km]'
531 self.ylabel = 'Range [km]'
531 self.showprofile = False
532 self.showprofile = False
532 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
533 self.plots_adjust.update({'left': 0.22, 'right': .90, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
533
534
534 def plot(self):
535 def plot(self):
535
536
536 if self.xaxis == "frequency":
537 if self.xaxis == "frequency":
537 x = self.data.xrange[0]
538 x = self.data.xrange[0]
538 self.xlabel = "Frequency (kHz)"
539 self.xlabel = "Frequency (kHz)"
539 elif self.xaxis == "time":
540 elif self.xaxis == "time":
540 x = self.data.xrange[1]
541 x = self.data.xrange[1]
541 self.xlabel = "Time (ms)"
542 self.xlabel = "Time (ms)"
542 else:
543 else:
543 x = self.data.xrange[2]
544 x = self.data.xrange[2]
544 self.xlabel = "Velocity (m/s)"
545 self.xlabel = "Velocity (m/s)"
545
546
546 self.titles = []
547 self.titles = []
547
548
548
549
549 y = self.data.heights
550 y = self.data.heights
550 self.y = y
551 self.y = y
551 #nspc = self.data['spc']
552 #nspc = self.data['spc']
552 #print(numpy.shape(self.data['spc']))
553 #print(numpy.shape(self.data['spc']))
553 #spc = self.data['cspc'][0]
554 #spc = self.data['cspc'][0]
554 #print(numpy.shape(spc))
555 #print(numpy.shape(spc))
555 #exit()
556 #exit()
556 cspc = self.data['cspc'][1]
557 cspc = self.data['cspc'][1]
557 #print(numpy.shape(cspc))
558 #print(numpy.shape(cspc))
558 #exit()
559 #exit()
559
560
560 for n in range(self.nrows):
561 for n in range(self.nrows):
561 noise = self.data['noise'][:,-1]
562 noise = self.data['noise'][:,-1]
562 pair = self.data.pairs[n]
563 pair = self.data.pairs[n]
563 #print(pair) #exit()
564 #print(pair) #exit()
564
565
565
566
566
567
567 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
568 out = cspc[n]# / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
568
569
569 #print(out[:,53])
570 #print(out[:,53])
570 #exit()
571 #exit()
571 cross = numpy.abs(out)
572 cross = numpy.abs(out)
572 z = cross/self.data.nFactor
573 z = cross/self.data.nFactor
573 cross = 10*numpy.log10(z)
574 cross = 10*numpy.log10(z)
574
575
575 out_r= out.real/self.data.nFactor
576 out_r= out.real/self.data.nFactor
576 #out_r = 10*numpy.log10(out_r)
577 #out_r = 10*numpy.log10(out_r)
577
578
578 out_i= out.imag/self.data.nFactor
579 out_i= out.imag/self.data.nFactor
579 #out_i = 10*numpy.log10(out_i)
580 #out_i = 10*numpy.log10(out_i)
580 #print(numpy.shape(cross))
581 #print(numpy.shape(cross))
581 #print(cross[0,:])
582 #print(cross[0,:])
582 #print(self.data.nFactor)
583 #print(self.data.nFactor)
583 #exit()
584 #exit()
584 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
585 #phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
585
586
586 ax = self.axes[3 * n]
587 ax = self.axes[3 * n]
587 if ax.firsttime:
588 if ax.firsttime:
588 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
589 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
589 self.xmin = self.xmin if self.xmin else -self.xmax
590 self.xmin = self.xmin if self.xmin else -self.xmax
590 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
591 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
591 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
592 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
592 ax.plt = ax.pcolormesh(x, y, cross.T,
593 ax.plt = ax.pcolormesh(x, y, cross.T,
593 vmin=self.zmin,
594 vmin=self.zmin,
594 vmax=self.zmax,
595 vmax=self.zmax,
595 cmap=plt.get_cmap(self.colormap)
596 cmap=plt.get_cmap(self.colormap)
596 )
597 )
597 else:
598 else:
598 ax.plt.set_array(cross.T.ravel())
599 ax.plt.set_array(cross.T.ravel())
599 self.titles.append(
600 self.titles.append(
600 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
601 'Cross Spectra Power Ch{} * Ch{}'.format(pair[0], pair[1]))
601
602
602 ax = self.axes[3 * n + 1]
603 ax = self.axes[3 * n + 1]
603 if ax.firsttime:
604 if ax.firsttime:
604 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
605 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
605 self.xmin = self.xmin if self.xmin else -self.xmax
606 self.xmin = self.xmin if self.xmin else -self.xmax
606 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
607 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
607 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
608 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
608 ax.plt = ax.pcolormesh(x, y, out_r.T,
609 ax.plt = ax.pcolormesh(x, y, out_r.T,
609 vmin=-1.e6,
610 vmin=-1.e6,
610 vmax=0,
611 vmax=0,
611 cmap=plt.get_cmap(self.colormap)
612 cmap=plt.get_cmap(self.colormap)
612 )
613 )
613 else:
614 else:
614 ax.plt.set_array(out_r.T.ravel())
615 ax.plt.set_array(out_r.T.ravel())
615 self.titles.append(
616 self.titles.append(
616 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
617 'Cross Spectra Real Ch{} * Ch{}'.format(pair[0], pair[1]))
617
618
618 ax = self.axes[3 * n + 2]
619 ax = self.axes[3 * n + 2]
619
620
620
621
621 if ax.firsttime:
622 if ax.firsttime:
622 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
623 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
623 self.xmin = self.xmin if self.xmin else -self.xmax
624 self.xmin = self.xmin if self.xmin else -self.xmax
624 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
625 self.zmin = self.zmin if self.zmin else numpy.nanmin(cross)
625 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
626 self.zmax = self.zmax if self.zmax else numpy.nanmax(cross)
626 ax.plt = ax.pcolormesh(x, y, out_i.T,
627 ax.plt = ax.pcolormesh(x, y, out_i.T,
627 vmin=-1.e6,
628 vmin=-1.e6,
628 vmax=1.e6,
629 vmax=1.e6,
629 cmap=plt.get_cmap(self.colormap)
630 cmap=plt.get_cmap(self.colormap)
630 )
631 )
631 else:
632 else:
632 ax.plt.set_array(out_i.T.ravel())
633 ax.plt.set_array(out_i.T.ravel())
633 self.titles.append(
634 self.titles.append(
634 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
635 'Cross Spectra Imag Ch{} * Ch{}'.format(pair[0], pair[1]))
635
636
636 class RTIPlot(Plot):
637 class RTIPlot(Plot):
637 '''
638 '''
638 Plot for RTI data
639 Plot for RTI data
639 '''
640 '''
640
641
641 CODE = 'rti'
642 CODE = 'rti'
642 colormap = 'jet'
643 colormap = 'jet'
643 plot_type = 'pcolorbuffer'
644 plot_type = 'pcolorbuffer'
644
645
645 def setup(self):
646 def setup(self):
646 self.xaxis = 'time'
647 self.xaxis = 'time'
647 self.ncols = 1
648 self.ncols = 1
648 self.nrows = len(self.data.channels)
649 self.nrows = len(self.data.channels)
649 self.nplots = len(self.data.channels)
650 self.nplots = len(self.data.channels)
650 self.ylabel = 'Range [km]'
651 self.ylabel = 'Range [km]'
651 self.xlabel = 'Time'
652 self.xlabel = 'Time'
652 self.cb_label = 'dB'
653 self.cb_label = 'dB'
653 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
654 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
654 self.titles = ['{} Channel {}'.format(
655 self.titles = ['{} Channel {}'.format(
655 self.CODE.upper(), x) for x in range(self.nrows)]
656 self.CODE.upper(), x) for x in range(self.nrows)]
656
657
657 def update(self, dataOut):
658 def update(self, dataOut):
658
659
659 data = {}
660 data = {}
660 meta = {}
661 meta = {}
661 data['rti'] = dataOut.getPower()
662 data['rti'] = dataOut.getPower()
662 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor)
663 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor)
663
664
664 return data, meta
665 return data, meta
665
666
666 def plot(self):
667 def plot(self):
667 self.x = self.data.times
668 self.x = self.data.times
668 self.y = self.data.yrange
669 self.y = self.data.yrange
669 self.z = self.data[self.CODE]
670 self.z = self.data[self.CODE]
670
671
671 self.z = numpy.ma.masked_invalid(self.z)
672 self.z = numpy.ma.masked_invalid(self.z)
672
673
673 if self.decimation is None:
674 if self.decimation is None:
674 x, y, z = self.fill_gaps(self.x, self.y, self.z)
675 x, y, z = self.fill_gaps(self.x, self.y, self.z)
675 else:
676 else:
676 x, y, z = self.fill_gaps(*self.decimate())
677 x, y, z = self.fill_gaps(*self.decimate())
677
678
678 for n, ax in enumerate(self.axes):
679 for n, ax in enumerate(self.axes):
679 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
680 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
680 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
681 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
681 if ax.firsttime:
682 if ax.firsttime:
682 ax.plt = ax.pcolormesh(x, y, z[n].T,
683 ax.plt = ax.pcolormesh(x, y, z[n].T,
683 vmin=self.zmin,
684 vmin=self.zmin,
684 vmax=self.zmax,
685 vmax=self.zmax,
685 cmap=plt.get_cmap(self.colormap)
686 cmap=plt.get_cmap(self.colormap)
686 )
687 )
687 if self.showprofile:
688 if self.showprofile:
688 ax.plot_profile = self.pf_axes[n].plot(
689 ax.plot_profile = self.pf_axes[n].plot(
689 self.data['rti'][n][-1], self.y)[0]
690 self.data['rti'][n][-1], self.y)[0]
690 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
691 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
691 color="k", linestyle="dashed", lw=1)[0]
692 color="k", linestyle="dashed", lw=1)[0]
692 else:
693 else:
693 ax.plt.remove()
694 ax.plt.remove()
694 ax.plt = ax.pcolormesh(x, y, z[n].T,
695 ax.plt = ax.pcolormesh(x, y, z[n].T,
695 vmin=self.zmin,
696 vmin=self.zmin,
696 vmax=self.zmax,
697 vmax=self.zmax,
697 cmap=plt.get_cmap(self.colormap)
698 cmap=plt.get_cmap(self.colormap)
698 )
699 )
699 if self.showprofile:
700 if self.showprofile:
700 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
701 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
701 ax.plot_noise.set_data(numpy.repeat(
702 ax.plot_noise.set_data(numpy.repeat(
702 self.data['noise'][n][-1], len(self.y)), self.y)
703 self.data['noise'][n][-1], len(self.y)), self.y)
703
704
704
705
705 class SpectrogramPlot(Plot):
706 class SpectrogramPlot(Plot):
706 '''
707 '''
707 Plot for Spectrogram data
708 Plot for Spectrogram data
708 '''
709 '''
709
710
710 CODE = 'spectrogram'
711 CODE = 'spectrogram'
711 colormap = 'binary'
712 colormap = 'binary'
712 plot_type = 'pcolorbuffer'
713 plot_type = 'pcolorbuffer'
713
714
714 def setup(self):
715 def setup(self):
715 self.xaxis = 'time'
716 self.xaxis = 'time'
716 self.ncols = 1
717 self.ncols = 1
717 self.nrows = len(self.data.channels)
718 self.nrows = len(self.data.channels)
718 self.nplots = len(self.data.channels)
719 self.nplots = len(self.data.channels)
719 self.xlabel = 'Time'
720 self.xlabel = 'Time'
720 self.cb_label = 'dB'
721 self.cb_label = 'dB'
721 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
722 self.plots_adjust.update({'hspace':1.2, 'left': 0.1, 'bottom': 0.12, 'right':0.95})
722 self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
723 self.titles = ['{} Channel {} \n H = {} km ({} - {})'.format(
723 self.CODE.upper(), x, self.data.heightList[self.data.hei], self.data.heightList[self.data.hei],self.data.heightList[self.data.hei]+(self.data.DH*self.data.nProfiles)) for x in range(self.nrows)]
724 self.CODE.upper(), x, self.data.heightList[self.data.hei], self.data.heightList[self.data.hei],self.data.heightList[self.data.hei]+(self.data.DH*self.data.nProfiles)) for x in range(self.nrows)]
724
725
725 def plot(self):
726 def plot(self):
726
727
727 self.x = self.data.times
728 self.x = self.data.times
728 self.z = self.data[self.CODE]
729 self.z = self.data[self.CODE]
729 self.y = self.data.xrange[0]
730 self.y = self.data.xrange[0]
730
731
731 self.ylabel = "Frequency (kHz)"
732 self.ylabel = "Frequency (kHz)"
732
733
733 self.z = numpy.ma.masked_invalid(self.z)
734 self.z = numpy.ma.masked_invalid(self.z)
734
735
735 if self.decimation is None:
736 if self.decimation is None:
736 x, y, z = self.fill_gaps(self.x, self.y, self.z)
737 x, y, z = self.fill_gaps(self.x, self.y, self.z)
737 else:
738 else:
738 x, y, z = self.fill_gaps(*self.decimate())
739 x, y, z = self.fill_gaps(*self.decimate())
739
740
740 for n, ax in enumerate(self.axes):
741 for n, ax in enumerate(self.axes):
741 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
742 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
742 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
743 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
743 data = self.data[-1]
744 data = self.data[-1]
744 if ax.firsttime:
745 if ax.firsttime:
745 ax.plt = ax.pcolormesh(x, y, z[n].T,
746 ax.plt = ax.pcolormesh(x, y, z[n].T,
746 vmin=self.zmin,
747 vmin=self.zmin,
747 vmax=self.zmax,
748 vmax=self.zmax,
748 cmap=plt.get_cmap(self.colormap)
749 cmap=plt.get_cmap(self.colormap)
749 )
750 )
750 if self.showprofile:
751 if self.showprofile:
751 ax.plot_profile = self.pf_axes[n].plot(
752 ax.plot_profile = self.pf_axes[n].plot(
752 data['rti'][n], self.y)[0]
753 data['rti'][n], self.y)[0]
753 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
754 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
754 color="k", linestyle="dashed", lw=1)[0]
755 color="k", linestyle="dashed", lw=1)[0]
755 else:
756 else:
756 ax.plt.remove()
757 ax.plt.remove()
757 ax.plt = ax.pcolormesh(x, y, z[n].T,
758 ax.plt = ax.pcolormesh(x, y, z[n].T,
758 vmin=self.zmin,
759 vmin=self.zmin,
759 vmax=self.zmax,
760 vmax=self.zmax,
760 cmap=plt.get_cmap(self.colormap)
761 cmap=plt.get_cmap(self.colormap)
761 )
762 )
762 if self.showprofile:
763 if self.showprofile:
763 ax.plot_profile.set_data(data['rti'][n], self.y)
764 ax.plot_profile.set_data(data['rti'][n], self.y)
764 ax.plot_noise.set_data(numpy.repeat(
765 ax.plot_noise.set_data(numpy.repeat(
765 data['noise'][n], len(self.y)), self.y)
766 data['noise'][n], len(self.y)), self.y)
766
767
767
768
768 class CoherencePlot(RTIPlot):
769 class CoherencePlot(RTIPlot):
769 '''
770 '''
770 Plot for Coherence data
771 Plot for Coherence data
771 '''
772 '''
772
773
773 CODE = 'coh'
774 CODE = 'coh'
774
775
775 def setup(self):
776 def setup(self):
776 self.xaxis = 'time'
777 self.xaxis = 'time'
777 self.ncols = 1
778 self.ncols = 1
778 self.nrows = len(self.data.pairs)
779 self.nrows = len(self.data.pairs)
779 self.nplots = len(self.data.pairs)
780 self.nplots = len(self.data.pairs)
780 self.ylabel = 'Range [km]'
781 self.ylabel = 'Range [km]'
781 self.xlabel = 'Time'
782 self.xlabel = 'Time'
782 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
783 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1, 'right':0.95})
783 if self.CODE == 'coh':
784 if self.CODE == 'coh':
784 self.cb_label = ''
785 self.cb_label = ''
785 self.titles = [
786 self.titles = [
786 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
787 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
787 else:
788 else:
788 self.cb_label = 'Degrees'
789 self.cb_label = 'Degrees'
789 self.titles = [
790 self.titles = [
790 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
791 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
791
792
792 def update(self, dataOut):
793 def update(self, dataOut):
793
794
794 data = {}
795 data = {}
795 meta = {}
796 meta = {}
796 data['coh'] = dataOut.getCoherence()
797 data['coh'] = dataOut.getCoherence()
797 meta['pairs'] = dataOut.pairsList
798 meta['pairs'] = dataOut.pairsList
798
799
799 return data, meta
800 return data, meta
800
801
801 class PhasePlot(CoherencePlot):
802 class PhasePlot(CoherencePlot):
802 '''
803 '''
803 Plot for Phase map data
804 Plot for Phase map data
804 '''
805 '''
805
806
806 CODE = 'phase'
807 CODE = 'phase'
807 colormap = 'seismic'
808 colormap = 'seismic'
808
809
809 def update(self, dataOut):
810 def update(self, dataOut):
810
811
811 data = {}
812 data = {}
812 meta = {}
813 meta = {}
813 data['phase'] = dataOut.getCoherence(phase=True)
814 data['phase'] = dataOut.getCoherence(phase=True)
814 meta['pairs'] = dataOut.pairsList
815 meta['pairs'] = dataOut.pairsList
815
816
816 return data, meta
817 return data, meta
817
818
818 class NoisePlot(Plot):
819 class NoisePlot(Plot):
819 '''
820 '''
820 Plot for noise
821 Plot for noise
821 '''
822 '''
822
823
823 CODE = 'noise'
824 CODE = 'noise'
824 plot_type = 'scatterbuffer'
825 plot_type = 'scatterbuffer'
825
826
826 def setup(self):
827 def setup(self):
827 self.xaxis = 'time'
828 self.xaxis = 'time'
828 self.ncols = 1
829 self.ncols = 1
829 self.nrows = 1
830 self.nrows = 1
830 self.nplots = 1
831 self.nplots = 1
831 self.ylabel = 'Intensity [dB]'
832 self.ylabel = 'Intensity [dB]'
832 self.xlabel = 'Time'
833 self.xlabel = 'Time'
833 self.titles = ['Noise']
834 self.titles = ['Noise']
834 self.colorbar = False
835 self.colorbar = False
835 self.plots_adjust.update({'right': 0.85 })
836 self.plots_adjust.update({'right': 0.85 })
836
837
837 def update(self, dataOut):
838 def update(self, dataOut):
838
839
839 data = {}
840 data = {}
840 meta = {}
841 meta = {}
841 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor).reshape(dataOut.nChannels, 1)
842 data['noise'] = 10 * numpy.log10(dataOut.getNoise() / dataOut.normFactor).reshape(dataOut.nChannels, 1)
842 meta['yrange'] = numpy.array([])
843 meta['yrange'] = numpy.array([])
843
844
844 return data, meta
845 return data, meta
845
846
846 def plot(self):
847 def plot(self):
847
848
848 x = self.data.times
849 x = self.data.times
849 xmin = self.data.min_time
850 xmin = self.data.min_time
850 xmax = xmin + self.xrange * 60 * 60
851 xmax = xmin + self.xrange * 60 * 60
851 Y = self.data['noise']
852 Y = self.data['noise']
852
853
853 if self.axes[0].firsttime:
854 if self.axes[0].firsttime:
854 self.ymin = numpy.nanmin(Y) - 5
855 self.ymin = numpy.nanmin(Y) - 5
855 self.ymax = numpy.nanmax(Y) + 5
856 self.ymax = numpy.nanmax(Y) + 5
856 for ch in self.data.channels:
857 for ch in self.data.channels:
857 y = Y[ch]
858 y = Y[ch]
858 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
859 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
859 plt.legend(bbox_to_anchor=(1.18, 1.0))
860 plt.legend(bbox_to_anchor=(1.18, 1.0))
860 else:
861 else:
861 for ch in self.data.channels:
862 for ch in self.data.channels:
862 y = Y[ch]
863 y = Y[ch]
863 self.axes[0].lines[ch].set_data(x, y)
864 self.axes[0].lines[ch].set_data(x, y)
864
865
865 self.ymin = numpy.nanmin(Y) - 5
866 self.ymin = numpy.nanmin(Y) - 5
866 self.ymax = numpy.nanmax(Y) + 10
867 self.ymax = numpy.nanmax(Y) + 10
867
868
868
869
869 class PowerProfilePlot(Plot):
870 class PowerProfilePlot(Plot):
870
871
871 CODE = 'pow_profile'
872 CODE = 'pow_profile'
872 plot_type = 'scatter'
873 plot_type = 'scatter'
873
874
874 def setup(self):
875 def setup(self):
875
876
876 self.ncols = 1
877 self.ncols = 1
877 self.nrows = 1
878 self.nrows = 1
878 self.nplots = 1
879 self.nplots = 1
879 self.height = 4
880 self.height = 4
880 self.width = 3
881 self.width = 3
881 self.ylabel = 'Range [km]'
882 self.ylabel = 'Range [km]'
882 self.xlabel = 'Intensity [dB]'
883 self.xlabel = 'Intensity [dB]'
883 self.titles = ['Power Profile']
884 self.titles = ['Power Profile']
884 self.colorbar = False
885 self.colorbar = False
885
886
886 def update(self, dataOut):
887 def update(self, dataOut):
887
888
888 data = {}
889 data = {}
889 meta = {}
890 meta = {}
890 data[self.CODE] = dataOut.getPower()
891 data[self.CODE] = dataOut.getPower()
891
892
892 return data, meta
893 return data, meta
893
894
894 def plot(self):
895 def plot(self):
895
896
896 y = self.data.yrange
897 y = self.data.yrange
897 self.y = y
898 self.y = y
898
899
899 x = self.data[-1][self.CODE]
900 x = self.data[-1][self.CODE]
900
901
901 if self.xmin is None: self.xmin = numpy.nanmin(x) * 0.9
902 if self.xmin is None: self.xmin = numpy.nanmin(x) * 0.9
902 if self.xmax is None: self.xmax = numpy.nanmax(x) * 1.1
903 if self.xmax is None: self.xmax = numpy.nanmax(x) * 1.1
903
904
904 if self.axes[0].firsttime:
905 if self.axes[0].firsttime:
905 for ch in self.data.channels:
906 for ch in self.data.channels:
906 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
907 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
907 plt.legend()
908 plt.legend()
908 else:
909 else:
909 for ch in self.data.channels:
910 for ch in self.data.channels:
910 self.axes[0].lines[ch].set_data(x[ch], y)
911 self.axes[0].lines[ch].set_data(x[ch], y)
911
912
912
913
913 class SpectraCutPlot(Plot):
914 class SpectraCutPlot(Plot):
914
915
915 CODE = 'spc_cut'
916 CODE = 'spc_cut'
916 plot_type = 'scatter'
917 plot_type = 'scatter'
917 buffering = False
918 buffering = False
918
919
919 def setup(self):
920 def setup(self):
920
921
921 self.nplots = len(self.data.channels)
922 self.nplots = len(self.data.channels)
922 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
923 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
923 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
924 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
924 self.width = 3.4 * self.ncols + 1.5
925 self.width = 3.4 * self.ncols + 1.5
925 self.height = 3 * self.nrows
926 self.height = 3 * self.nrows
926 self.ylabel = 'Power [dB]'
927 self.ylabel = 'Power [dB]'
927 self.colorbar = False
928 self.colorbar = False
928 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
929 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
929
930
930 def update(self, dataOut):
931 def update(self, dataOut):
931
932
932 data = {}
933 data = {}
933 meta = {}
934 meta = {}
934 spc = 10 * numpy.log10(dataOut.data_pre[0] / dataOut.normFactor)
935 spc = 10 * numpy.log10(dataOut.data_pre[0] / dataOut.normFactor)
935 data['spc'] = spc
936 data['spc'] = spc
936 meta['xrange'] = (dataOut.getFreqRange(1) / 1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
937 meta['xrange'] = (dataOut.getFreqRange(1) / 1000., dataOut.getAcfRange(1), dataOut.getVelRange(1))
937 if self.CODE == 'cut_gaussian_fit':
938 if self.CODE == 'cut_gaussian_fit':
938 data['gauss_fit0'] = 10 * numpy.log10(dataOut.GaussFit0 / dataOut.normFactor)
939 data['gauss_fit0'] = 10 * numpy.log10(dataOut.GaussFit0 / dataOut.normFactor)
939 data['gauss_fit1'] = 10 * numpy.log10(dataOut.GaussFit1 / dataOut.normFactor)
940 data['gauss_fit1'] = 10 * numpy.log10(dataOut.GaussFit1 / dataOut.normFactor)
940 return data, meta
941 return data, meta
941
942
942 def plot(self):
943 def plot(self):
943 if self.xaxis == "frequency":
944 if self.xaxis == "frequency":
944 x = self.data.xrange[0][1:]
945 x = self.data.xrange[0][1:]
945 self.xlabel = "Frequency (kHz)"
946 self.xlabel = "Frequency (kHz)"
946 elif self.xaxis == "time":
947 elif self.xaxis == "time":
947 x = self.data.xrange[1]
948 x = self.data.xrange[1]
948 self.xlabel = "Time (ms)"
949 self.xlabel = "Time (ms)"
949 else:
950 else:
950 x = self.data.xrange[2][:-1]
951 x = self.data.xrange[2][:-1]
951 self.xlabel = "Velocity (m/s)"
952 self.xlabel = "Velocity (m/s)"
952
953
953 if self.CODE == 'cut_gaussian_fit':
954 if self.CODE == 'cut_gaussian_fit':
954 x = self.data.xrange[2][:-1]
955 x = self.data.xrange[2][:-1]
955 self.xlabel = "Velocity (m/s)"
956 self.xlabel = "Velocity (m/s)"
956
957
957 self.titles = []
958 self.titles = []
958
959
959 y = self.data.yrange
960 y = self.data.yrange
960 data = self.data[-1]
961 data = self.data[-1]
961 z = data['spc']
962 z = data['spc']
962
963
963 if self.height_index:
964 if self.height_index:
964 index = numpy.array(self.height_index)
965 index = numpy.array(self.height_index)
965 else:
966 else:
966 index = numpy.arange(0, len(y), int((len(y)) / 9))
967 index = numpy.arange(0, len(y), int((len(y)) / 9))
967
968
968 for n, ax in enumerate(self.axes):
969 for n, ax in enumerate(self.axes):
969 if self.CODE == 'cut_gaussian_fit':
970 if self.CODE == 'cut_gaussian_fit':
970 gau0 = data['gauss_fit0']
971 gau0 = data['gauss_fit0']
971 gau1 = data['gauss_fit1']
972 gau1 = data['gauss_fit1']
972 if ax.firsttime:
973 if ax.firsttime:
973 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
974 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
974 self.xmin = self.xmin if self.xmin else -self.xmax
975 self.xmin = self.xmin if self.xmin else -self.xmax
975 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
976 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
976 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
977 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
977 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
978 ax.plt = ax.plot(x, z[n, :, index].T, lw=0.25)
978 if self.CODE == 'cut_gaussian_fit':
979 if self.CODE == 'cut_gaussian_fit':
979 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
980 ax.plt_gau0 = ax.plot(x, gau0[n, :, index].T, lw=1, linestyle='-.')
980 for i, line in enumerate(ax.plt_gau0):
981 for i, line in enumerate(ax.plt_gau0):
981 line.set_color(ax.plt[i].get_color())
982 line.set_color(ax.plt[i].get_color())
982 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
983 ax.plt_gau1 = ax.plot(x, gau1[n, :, index].T, lw=1, linestyle='--')
983 for i, line in enumerate(ax.plt_gau1):
984 for i, line in enumerate(ax.plt_gau1):
984 line.set_color(ax.plt[i].get_color())
985 line.set_color(ax.plt[i].get_color())
985 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
986 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
986 self.figures[0].legend(ax.plt, labels, loc='center right')
987 self.figures[0].legend(ax.plt, labels, loc='center right')
987 else:
988 else:
988 for i, line in enumerate(ax.plt):
989 for i, line in enumerate(ax.plt):
989 line.set_data(x, z[n, :, index[i]].T)
990 line.set_data(x, z[n, :, index[i]].T)
990 for i, line in enumerate(ax.plt_gau0):
991 for i, line in enumerate(ax.plt_gau0):
991 line.set_data(x, gau0[n, :, index[i]].T)
992 line.set_data(x, gau0[n, :, index[i]].T)
992 line.set_color(ax.plt[i].get_color())
993 line.set_color(ax.plt[i].get_color())
993 for i, line in enumerate(ax.plt_gau1):
994 for i, line in enumerate(ax.plt_gau1):
994 line.set_data(x, gau1[n, :, index[i]].T)
995 line.set_data(x, gau1[n, :, index[i]].T)
995 line.set_color(ax.plt[i].get_color())
996 line.set_color(ax.plt[i].get_color())
996 self.titles.append('CH {}'.format(n))
997 self.titles.append('CH {}'.format(n))
997
998
998
999
999 class BeaconPhase(Plot):
1000 class BeaconPhase(Plot):
1000
1001
1001 __isConfig = None
1002 __isConfig = None
1002 __nsubplots = None
1003 __nsubplots = None
1003
1004
1004 PREFIX = 'beacon_phase'
1005 PREFIX = 'beacon_phase'
1005
1006
1006 def __init__(self):
1007 def __init__(self):
1007 Plot.__init__(self)
1008 Plot.__init__(self)
1008 self.timerange = 24 * 60 * 60
1009 self.timerange = 24 * 60 * 60
1009 self.isConfig = False
1010 self.isConfig = False
1010 self.__nsubplots = 1
1011 self.__nsubplots = 1
1011 self.counter_imagwr = 0
1012 self.counter_imagwr = 0
1012 self.WIDTH = 800
1013 self.WIDTH = 800
1013 self.HEIGHT = 400
1014 self.HEIGHT = 400
1014 self.WIDTHPROF = 120
1015 self.WIDTHPROF = 120
1015 self.HEIGHTPROF = 0
1016 self.HEIGHTPROF = 0
1016 self.xdata = None
1017 self.xdata = None
1017 self.ydata = None
1018 self.ydata = None
1018
1019
1019 self.PLOT_CODE = BEACON_CODE
1020 self.PLOT_CODE = BEACON_CODE
1020
1021
1021 self.FTP_WEI = None
1022 self.FTP_WEI = None
1022 self.EXP_CODE = None
1023 self.EXP_CODE = None
1023 self.SUB_EXP_CODE = None
1024 self.SUB_EXP_CODE = None
1024 self.PLOT_POS = None
1025 self.PLOT_POS = None
1025
1026
1026 self.filename_phase = None
1027 self.filename_phase = None
1027
1028
1028 self.figfile = None
1029 self.figfile = None
1029
1030
1030 self.xmin = None
1031 self.xmin = None
1031 self.xmax = None
1032 self.xmax = None
1032
1033
1033 def getSubplots(self):
1034 def getSubplots(self):
1034
1035
1035 ncol = 1
1036 ncol = 1
1036 nrow = 1
1037 nrow = 1
1037
1038
1038 return nrow, ncol
1039 return nrow, ncol
1039
1040
1040 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1041 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1041
1042
1042 self.__showprofile = showprofile
1043 self.__showprofile = showprofile
1043 self.nplots = nplots
1044 self.nplots = nplots
1044
1045
1045 ncolspan = 7
1046 ncolspan = 7
1046 colspan = 6
1047 colspan = 6
1047 self.__nsubplots = 2
1048 self.__nsubplots = 2
1048
1049
1049 self.createFigure(id=id,
1050 self.createFigure(id=id,
1050 wintitle=wintitle,
1051 wintitle=wintitle,
1051 widthplot=self.WIDTH + self.WIDTHPROF,
1052 widthplot=self.WIDTH + self.WIDTHPROF,
1052 heightplot=self.HEIGHT + self.HEIGHTPROF,
1053 heightplot=self.HEIGHT + self.HEIGHTPROF,
1053 show=show)
1054 show=show)
1054
1055
1055 nrow, ncol = self.getSubplots()
1056 nrow, ncol = self.getSubplots()
1056
1057
1057 self.addAxes(nrow, ncol * ncolspan, 0, 0, colspan, 1)
1058 self.addAxes(nrow, ncol * ncolspan, 0, 0, colspan, 1)
1058
1059
1059 def save_phase(self, filename_phase):
1060 def save_phase(self, filename_phase):
1060 f = open(filename_phase, 'w+')
1061 f = open(filename_phase, 'w+')
1061 f.write('\n\n')
1062 f.write('\n\n')
1062 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1063 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1063 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n')
1064 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n')
1064 f.close()
1065 f.close()
1065
1066
1066 def save_data(self, filename_phase, data, data_datetime):
1067 def save_data(self, filename_phase, data, data_datetime):
1067 f = open(filename_phase, 'a')
1068 f = open(filename_phase, 'a')
1068 timetuple_data = data_datetime.timetuple()
1069 timetuple_data = data_datetime.timetuple()
1069 day = str(timetuple_data.tm_mday)
1070 day = str(timetuple_data.tm_mday)
1070 month = str(timetuple_data.tm_mon)
1071 month = str(timetuple_data.tm_mon)
1071 year = str(timetuple_data.tm_year)
1072 year = str(timetuple_data.tm_year)
1072 hour = str(timetuple_data.tm_hour)
1073 hour = str(timetuple_data.tm_hour)
1073 minute = str(timetuple_data.tm_min)
1074 minute = str(timetuple_data.tm_min)
1074 second = str(timetuple_data.tm_sec)
1075 second = str(timetuple_data.tm_sec)
1075 f.write(day + ' ' + month + ' ' + year + ' ' + hour + ' ' + minute + ' ' + second + ' ' + str(data[0]) + ' ' + str(data[1]) + ' ' + str(data[2]) + ' ' + str(data[3]) + '\n')
1076 f.write(day + ' ' + month + ' ' + year + ' ' + hour + ' ' + minute + ' ' + second + ' ' + str(data[0]) + ' ' + str(data[1]) + ' ' + str(data[2]) + ' ' + str(data[3]) + '\n')
1076 f.close()
1077 f.close()
1077
1078
1078 def plot(self):
1079 def plot(self):
1079 log.warning('TODO: Not yet implemented...')
1080 log.warning('TODO: Not yet implemented...')
1080
1081
1081 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1082 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1082 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1083 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1083 timerange=None,
1084 timerange=None,
1084 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1085 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1085 server=None, folder=None, username=None, password=None,
1086 server=None, folder=None, username=None, password=None,
1086 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1087 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1087
1088
1088 if dataOut.flagNoData:
1089 if dataOut.flagNoData:
1089 return dataOut
1090 return dataOut
1090
1091
1091 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1092 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1092 return
1093 return
1093
1094
1094 if pairsList == None:
1095 if pairsList == None:
1095 pairsIndexList = dataOut.pairsIndexList[:10]
1096 pairsIndexList = dataOut.pairsIndexList[:10]
1096 else:
1097 else:
1097 pairsIndexList = []
1098 pairsIndexList = []
1098 for pair in pairsList:
1099 for pair in pairsList:
1099 if pair not in dataOut.pairsList:
1100 if pair not in dataOut.pairsList:
1100 raise ValueError("Pair %s is not in dataOut.pairsList" % (pair))
1101 raise ValueError("Pair %s is not in dataOut.pairsList" % (pair))
1101 pairsIndexList.append(dataOut.pairsList.index(pair))
1102 pairsIndexList.append(dataOut.pairsList.index(pair))
1102
1103
1103 if pairsIndexList == []:
1104 if pairsIndexList == []:
1104 return
1105 return
1105
1106
1106 # if len(pairsIndexList) > 4:
1107 # if len(pairsIndexList) > 4:
1107 # pairsIndexList = pairsIndexList[0:4]
1108 # pairsIndexList = pairsIndexList[0:4]
1108
1109
1109 hmin_index = None
1110 hmin_index = None
1110 hmax_index = None
1111 hmax_index = None
1111
1112
1112 if hmin != None and hmax != None:
1113 if hmin != None and hmax != None:
1113 indexes = numpy.arange(dataOut.nHeights)
1114 indexes = numpy.arange(dataOut.nHeights)
1114 hmin_list = indexes[dataOut.heightList >= hmin]
1115 hmin_list = indexes[dataOut.heightList >= hmin]
1115 hmax_list = indexes[dataOut.heightList <= hmax]
1116 hmax_list = indexes[dataOut.heightList <= hmax]
1116
1117
1117 if hmin_list.any():
1118 if hmin_list.any():
1118 hmin_index = hmin_list[0]
1119 hmin_index = hmin_list[0]
1119
1120
1120 if hmax_list.any():
1121 if hmax_list.any():
1121 hmax_index = hmax_list[-1] + 1
1122 hmax_index = hmax_list[-1] + 1
1122
1123
1123 x = dataOut.getTimeRange()
1124 x = dataOut.getTimeRange()
1124
1125
1125 thisDatetime = dataOut.datatime
1126 thisDatetime = dataOut.datatime
1126
1127
1127 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1128 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1128 xlabel = "Local Time"
1129 xlabel = "Local Time"
1129 ylabel = "Phase (degrees)"
1130 ylabel = "Phase (degrees)"
1130
1131
1131 update_figfile = False
1132 update_figfile = False
1132
1133
1133 nplots = len(pairsIndexList)
1134 nplots = len(pairsIndexList)
1134 # phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1135 # phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1135 phase_beacon = numpy.zeros(len(pairsIndexList))
1136 phase_beacon = numpy.zeros(len(pairsIndexList))
1136 for i in range(nplots):
1137 for i in range(nplots):
1137 pair = dataOut.pairsList[pairsIndexList[i]]
1138 pair = dataOut.pairsList[pairsIndexList[i]]
1138 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1139 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1139 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1140 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1140 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1141 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1141 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
1142 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
1142 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real) * 180 / numpy.pi
1143 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real) * 180 / numpy.pi
1143
1144
1144 if dataOut.beacon_heiIndexList:
1145 if dataOut.beacon_heiIndexList:
1145 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1146 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1146 else:
1147 else:
1147 phase_beacon[i] = numpy.average(phase)
1148 phase_beacon[i] = numpy.average(phase)
1148
1149
1149 if not self.isConfig:
1150 if not self.isConfig:
1150
1151
1151 nplots = len(pairsIndexList)
1152 nplots = len(pairsIndexList)
1152
1153
1153 self.setup(id=id,
1154 self.setup(id=id,
1154 nplots=nplots,
1155 nplots=nplots,
1155 wintitle=wintitle,
1156 wintitle=wintitle,
1156 showprofile=showprofile,
1157 showprofile=showprofile,
1157 show=show)
1158 show=show)
1158
1159
1159 if timerange != None:
1160 if timerange != None:
1160 self.timerange = timerange
1161 self.timerange = timerange
1161
1162
1162 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1163 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1163
1164
1164 if ymin == None: ymin = 0
1165 if ymin == None: ymin = 0
1165 if ymax == None: ymax = 360
1166 if ymax == None: ymax = 360
1166
1167
1167 self.FTP_WEI = ftp_wei
1168 self.FTP_WEI = ftp_wei
1168 self.EXP_CODE = exp_code
1169 self.EXP_CODE = exp_code
1169 self.SUB_EXP_CODE = sub_exp_code
1170 self.SUB_EXP_CODE = sub_exp_code
1170 self.PLOT_POS = plot_pos
1171 self.PLOT_POS = plot_pos
1171
1172
1172 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1173 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1173 self.isConfig = True
1174 self.isConfig = True
1174 self.figfile = figfile
1175 self.figfile = figfile
1175 self.xdata = numpy.array([])
1176 self.xdata = numpy.array([])
1176 self.ydata = numpy.array([])
1177 self.ydata = numpy.array([])
1177
1178
1178 update_figfile = True
1179 update_figfile = True
1179
1180
1180 # open file beacon phase
1181 # open file beacon phase
1181 path = '%s%03d' % (self.PREFIX, self.id)
1182 path = '%s%03d' % (self.PREFIX, self.id)
1182 beacon_file = os.path.join(path, '%s.txt' % self.name)
1183 beacon_file = os.path.join(path, '%s.txt' % self.name)
1183 self.filename_phase = os.path.join(figpath, beacon_file)
1184 self.filename_phase = os.path.join(figpath, beacon_file)
1184 # self.save_phase(self.filename_phase)
1185 # self.save_phase(self.filename_phase)
1185
1186
1186
1187
1187 # store data beacon phase
1188 # store data beacon phase
1188 # self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1189 # self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1189
1190
1190 self.setWinTitle(title)
1191 self.setWinTitle(title)
1191
1192
1192
1193
1193 title = "Phase Plot %s" % (thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1194 title = "Phase Plot %s" % (thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1194
1195
1195 legendlabels = ["Pair (%d,%d)" % (pair[0], pair[1]) for pair in dataOut.pairsList]
1196 legendlabels = ["Pair (%d,%d)" % (pair[0], pair[1]) for pair in dataOut.pairsList]
1196
1197
1197 axes = self.axesList[0]
1198 axes = self.axesList[0]
1198
1199
1199 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1200 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1200
1201
1201 if len(self.ydata) == 0:
1202 if len(self.ydata) == 0:
1202 self.ydata = phase_beacon.reshape(-1, 1)
1203 self.ydata = phase_beacon.reshape(-1, 1)
1203 else:
1204 else:
1204 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1, 1)))
1205 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1, 1)))
1205
1206
1206
1207
1207 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1208 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1208 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1209 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1209 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1210 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1210 XAxisAsTime=True, grid='both'
1211 XAxisAsTime=True, grid='both'
1211 )
1212 )
1212
1213
1213 self.draw()
1214 self.draw()
1214
1215
1215 if dataOut.ltctime >= self.xmax:
1216 if dataOut.ltctime >= self.xmax:
1216 self.counter_imagwr = wr_period
1217 self.counter_imagwr = wr_period
1217 self.isConfig = False
1218 self.isConfig = False
1218 update_figfile = True
1219 update_figfile = True
1219
1220
1220 self.save(figpath=figpath,
1221 self.save(figpath=figpath,
1221 figfile=figfile,
1222 figfile=figfile,
1222 save=save,
1223 save=save,
1223 ftp=ftp,
1224 ftp=ftp,
1224 wr_period=wr_period,
1225 wr_period=wr_period,
1225 thisDatetime=thisDatetime,
1226 thisDatetime=thisDatetime,
1226 update_figfile=update_figfile)
1227 update_figfile=update_figfile)
1227
1228
1228 return dataOut
1229 return dataOut
General Comments 0
You need to be logged in to leave comments. Login now