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