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