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