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