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