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