##// END OF EJS Templates
RTI plots only last channel with 'Time' label
joabAM -
r1592:60f9ebea7e3b
parent child
Show More
@@ -1,1464 +1,1470
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 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 from itertools import combinations
13 from itertools import combinations
14 from matplotlib.ticker import LinearLocator
14 from matplotlib.ticker import LinearLocator
15
15
16 from matplotlib import __version__ as plt_version
16 from matplotlib import __version__ as plt_version
17
17
18 if plt_version >='3.3.4':
18 if plt_version >='3.3.4':
19 EXTRA_POINTS = 0
19 EXTRA_POINTS = 0
20 else:
20 else:
21 EXTRA_POINTS = 1
21 EXTRA_POINTS = 1
22
22
23 class SpectraPlot(Plot):
23 class SpectraPlot(Plot):
24 '''
24 '''
25 Plot for Spectra data
25 Plot for Spectra data
26 '''
26 '''
27
27
28 CODE = 'spc'
28 CODE = 'spc'
29 colormap = 'jet'
29 colormap = 'jet'
30 plot_type = 'pcolor'
30 plot_type = 'pcolor'
31 buffering = False
31 buffering = False
32 channelList = []
32 channelList = []
33 elevationList = []
33 elevationList = []
34 azimuthList = []
34 azimuthList = []
35
35
36 def setup(self):
36 def setup(self):
37
37
38 self.nplots = len(self.data.channels)
38 self.nplots = len(self.data.channels)
39 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
39 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
40 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
40 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
41 self.height = 3.4 * self.nrows
41 self.height = 3.4 * self.nrows
42
42
43 self.cb_label = 'dB'
43 self.cb_label = 'dB'
44 if self.showprofile:
44 if self.showprofile:
45 self.width = 5.2 * self.ncols
45 self.width = 5.2 * self.ncols
46 else:
46 else:
47 self.width = 4.2* self.ncols
47 self.width = 4.2* self.ncols
48 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.12})
48 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.12})
49 self.ylabel = 'Range [km]'
49 self.ylabel = 'Range [km]'
50
50
51
51
52 def update_list(self,dataOut):
52 def update_list(self,dataOut):
53 if len(self.channelList) == 0:
53 if len(self.channelList) == 0:
54 self.channelList = dataOut.channelList
54 self.channelList = dataOut.channelList
55 if len(self.elevationList) == 0:
55 if len(self.elevationList) == 0:
56 self.elevationList = dataOut.elevationList
56 self.elevationList = dataOut.elevationList
57 if len(self.azimuthList) == 0:
57 if len(self.azimuthList) == 0:
58 self.azimuthList = dataOut.azimuthList
58 self.azimuthList = dataOut.azimuthList
59
59
60 def update(self, dataOut):
60 def update(self, dataOut):
61
61
62 self.update_list(dataOut)
62 self.update_list(dataOut)
63 data = {}
63 data = {}
64 meta = {}
64 meta = {}
65
65
66 #data['rti'] = dataOut.getPower()
66 #data['rti'] = dataOut.getPower()
67 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
67 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
68 noise = 10*numpy.log10(dataOut.getNoise()/norm)
68 noise = 10*numpy.log10(dataOut.getNoise()/norm)
69
69
70
70
71 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
71 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
72 for ch in range(dataOut.nChannels):
72 for ch in range(dataOut.nChannels):
73 if hasattr(dataOut.normFactor,'ndim'):
73 if hasattr(dataOut.normFactor,'ndim'):
74 if dataOut.normFactor.ndim > 1:
74 if dataOut.normFactor.ndim > 1:
75 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
75 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
76
76
77 else:
77 else:
78 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
78 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
79 else:
79 else:
80 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
80 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
81
81
82
82
83 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
83 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
84 spc = 10*numpy.log10(z)
84 spc = 10*numpy.log10(z)
85
85
86 data['spc'] = spc
86 data['spc'] = spc
87 #print(spc[0].shape)
87 #print(spc[0].shape)
88 data['rti'] = spc.mean(axis=1)
88 data['rti'] = spc.mean(axis=1)
89 data['noise'] = noise
89 data['noise'] = noise
90 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
90 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
91 if self.CODE == 'spc_moments':
91 if self.CODE == 'spc_moments':
92 data['moments'] = dataOut.moments
92 data['moments'] = dataOut.moments
93
93
94 return data, meta
94 return data, meta
95
95
96 def plot(self):
96 def plot(self):
97 if self.xaxis == "frequency":
97 if self.xaxis == "frequency":
98 x = self.data.xrange[0]
98 x = self.data.xrange[0]
99 self.xlabel = "Frequency (kHz)"
99 self.xlabel = "Frequency (kHz)"
100 elif self.xaxis == "time":
100 elif self.xaxis == "time":
101 x = self.data.xrange[1]
101 x = self.data.xrange[1]
102 self.xlabel = "Time (ms)"
102 self.xlabel = "Time (ms)"
103 else:
103 else:
104 x = self.data.xrange[2]
104 x = self.data.xrange[2]
105 self.xlabel = "Velocity (m/s)"
105 self.xlabel = "Velocity (m/s)"
106
106
107 if self.CODE == 'spc_moments':
107 if self.CODE == 'spc_moments':
108 x = self.data.xrange[2]
108 x = self.data.xrange[2]
109 self.xlabel = "Velocity (m/s)"
109 self.xlabel = "Velocity (m/s)"
110
110
111 self.titles = []
111 self.titles = []
112 y = self.data.yrange
112 y = self.data.yrange
113 self.y = y
113 self.y = y
114
114
115 data = self.data[-1]
115 data = self.data[-1]
116 z = data['spc']
116 z = data['spc']
117 #print(z.shape, x.shape, y.shape)
117 #print(z.shape, x.shape, y.shape)
118 for n, ax in enumerate(self.axes):
118 for n, ax in enumerate(self.axes):
119 noise = self.data['noise'][n][0]
119 noise = self.data['noise'][n][0]
120 #print(noise)
120 #print(noise)
121 if self.CODE == 'spc_moments':
121 if self.CODE == 'spc_moments':
122 mean = data['moments'][n, 1]
122 mean = data['moments'][n, 1]
123 if ax.firsttime:
123 if ax.firsttime:
124 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
124 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
125 self.xmin = self.xmin if self.xmin else -self.xmax
125 self.xmin = self.xmin if self.xmin else -self.xmax
126 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
126 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
127 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
127 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
128 ax.plt = ax.pcolormesh(x, y, z[n].T,
128 ax.plt = ax.pcolormesh(x, y, z[n].T,
129 vmin=self.zmin,
129 vmin=self.zmin,
130 vmax=self.zmax,
130 vmax=self.zmax,
131 cmap=plt.get_cmap(self.colormap)
131 cmap=plt.get_cmap(self.colormap)
132 )
132 )
133
133
134 if self.showprofile:
134 if self.showprofile:
135 ax.plt_profile = self.pf_axes[n].plot(
135 ax.plt_profile = self.pf_axes[n].plot(
136 data['rti'][n], y)[0]
136 data['rti'][n], y)[0]
137 # ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
137 # ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
138 # color="k", linestyle="dashed", lw=1)[0]
138 # color="k", linestyle="dashed", lw=1)[0]
139 if self.CODE == 'spc_moments':
139 if self.CODE == 'spc_moments':
140 ax.plt_mean = ax.plot(mean, y, color='k')[0]
140 ax.plt_mean = ax.plot(mean, y, color='k')[0]
141 else:
141 else:
142 ax.plt.set_array(z[n].T.ravel())
142 ax.plt.set_array(z[n].T.ravel())
143 if self.showprofile:
143 if self.showprofile:
144 ax.plt_profile.set_data(data['rti'][n], y)
144 ax.plt_profile.set_data(data['rti'][n], y)
145 #ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
145 #ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
146 if self.CODE == 'spc_moments':
146 if self.CODE == 'spc_moments':
147 ax.plt_mean.set_data(mean, y)
147 ax.plt_mean.set_data(mean, y)
148 if len(self.azimuthList) > 0 and len(self.elevationList) > 0:
148 if len(self.azimuthList) > 0 and len(self.elevationList) > 0:
149 self.titles.append('CH {}: {:2.1f}elv {:2.1f}az {:3.2f}dB'.format(self.channelList[n], noise, self.elevationList[n], self.azimuthList[n]))
149 self.titles.append('CH {}: {:2.1f}elv {:2.1f}az {:3.2f}dB'.format(self.channelList[n], noise, self.elevationList[n], self.azimuthList[n]))
150 else:
150 else:
151 self.titles.append('CH {}: {:3.2f}dB'.format(self.channelList[n], noise))
151 self.titles.append('CH {}: {:3.2f}dB'.format(self.channelList[n], noise))
152
152
153
153
154 class CrossSpectraPlot(Plot):
154 class CrossSpectraPlot(Plot):
155
155
156 CODE = 'cspc'
156 CODE = 'cspc'
157 colormap = 'jet'
157 colormap = 'jet'
158 plot_type = 'pcolor'
158 plot_type = 'pcolor'
159 zmin_coh = None
159 zmin_coh = None
160 zmax_coh = None
160 zmax_coh = None
161 zmin_phase = None
161 zmin_phase = None
162 zmax_phase = None
162 zmax_phase = None
163 realChannels = None
163 realChannels = None
164 crossPairs = None
164 crossPairs = None
165
165
166 def setup(self):
166 def setup(self):
167
167
168 self.ncols = 4
168 self.ncols = 4
169 self.nplots = len(self.data.pairs) * 2
169 self.nplots = len(self.data.pairs) * 2
170 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
170 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
171 self.width = 3.1 * self.ncols
171 self.width = 3.1 * self.ncols
172 self.height = 2.6 * self.nrows
172 self.height = 2.6 * self.nrows
173 self.ylabel = 'Range [km]'
173 self.ylabel = 'Range [km]'
174 self.showprofile = False
174 self.showprofile = False
175 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
175 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
176
176
177 def update(self, dataOut):
177 def update(self, dataOut):
178
178
179 data = {}
179 data = {}
180 meta = {}
180 meta = {}
181
181
182 spc = dataOut.data_spc
182 spc = dataOut.data_spc
183 cspc = dataOut.data_cspc
183 cspc = dataOut.data_cspc
184 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
184 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
185 rawPairs = list(combinations(list(range(dataOut.nChannels)), 2))
185 rawPairs = list(combinations(list(range(dataOut.nChannels)), 2))
186 meta['pairs'] = rawPairs
186 meta['pairs'] = rawPairs
187
187
188 if self.crossPairs == None:
188 if self.crossPairs == None:
189 self.crossPairs = dataOut.pairsList
189 self.crossPairs = dataOut.pairsList
190
190
191 tmp = []
191 tmp = []
192
192
193 for n, pair in enumerate(meta['pairs']):
193 for n, pair in enumerate(meta['pairs']):
194
194
195 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
195 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
196 coh = numpy.abs(out)
196 coh = numpy.abs(out)
197 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
197 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
198 tmp.append(coh)
198 tmp.append(coh)
199 tmp.append(phase)
199 tmp.append(phase)
200
200
201 data['cspc'] = numpy.array(tmp)
201 data['cspc'] = numpy.array(tmp)
202
202
203 return data, meta
203 return data, meta
204
204
205 def plot(self):
205 def plot(self):
206
206
207 if self.xaxis == "frequency":
207 if self.xaxis == "frequency":
208 x = self.data.xrange[0]
208 x = self.data.xrange[0]
209 self.xlabel = "Frequency (kHz)"
209 self.xlabel = "Frequency (kHz)"
210 elif self.xaxis == "time":
210 elif self.xaxis == "time":
211 x = self.data.xrange[1]
211 x = self.data.xrange[1]
212 self.xlabel = "Time (ms)"
212 self.xlabel = "Time (ms)"
213 else:
213 else:
214 x = self.data.xrange[2]
214 x = self.data.xrange[2]
215 self.xlabel = "Velocity (m/s)"
215 self.xlabel = "Velocity (m/s)"
216
216
217 self.titles = []
217 self.titles = []
218
218
219 y = self.data.yrange
219 y = self.data.yrange
220 self.y = y
220 self.y = y
221
221
222 data = self.data[-1]
222 data = self.data[-1]
223 cspc = data['cspc']
223 cspc = data['cspc']
224
224
225 for n in range(len(self.data.pairs)):
225 for n in range(len(self.data.pairs)):
226
226
227 pair = self.crossPairs[n]
227 pair = self.crossPairs[n]
228
228
229 coh = cspc[n*2]
229 coh = cspc[n*2]
230 phase = cspc[n*2+1]
230 phase = cspc[n*2+1]
231 ax = self.axes[2 * n]
231 ax = self.axes[2 * n]
232
232
233 if ax.firsttime:
233 if ax.firsttime:
234 ax.plt = ax.pcolormesh(x, y, coh.T,
234 ax.plt = ax.pcolormesh(x, y, coh.T,
235 vmin=self.zmin_coh,
235 vmin=self.zmin_coh,
236 vmax=self.zmax_coh,
236 vmax=self.zmax_coh,
237 cmap=plt.get_cmap(self.colormap_coh)
237 cmap=plt.get_cmap(self.colormap_coh)
238 )
238 )
239 else:
239 else:
240 ax.plt.set_array(coh.T.ravel())
240 ax.plt.set_array(coh.T.ravel())
241 self.titles.append(
241 self.titles.append(
242 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
242 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
243
243
244 ax = self.axes[2 * n + 1]
244 ax = self.axes[2 * n + 1]
245 if ax.firsttime:
245 if ax.firsttime:
246 ax.plt = ax.pcolormesh(x, y, phase.T,
246 ax.plt = ax.pcolormesh(x, y, phase.T,
247 vmin=-180,
247 vmin=-180,
248 vmax=180,
248 vmax=180,
249 cmap=plt.get_cmap(self.colormap_phase)
249 cmap=plt.get_cmap(self.colormap_phase)
250 )
250 )
251 else:
251 else:
252 ax.plt.set_array(phase.T.ravel())
252 ax.plt.set_array(phase.T.ravel())
253
253
254 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
254 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
255
255
256
256
257 class RTIPlot(Plot):
257 class RTIPlot(Plot):
258 '''
258 '''
259 Plot for RTI data
259 Plot for RTI data
260 '''
260 '''
261
261
262 CODE = 'rti'
262 CODE = 'rti'
263 colormap = 'jet'
263 colormap = 'jet'
264 plot_type = 'pcolorbuffer'
264 plot_type = 'pcolorbuffer'
265 titles = None
265 titles = None
266 channelList = []
266 channelList = []
267 elevationList = []
267 elevationList = []
268 azimuthList = []
268 azimuthList = []
269
269
270 def setup(self):
270 def setup(self):
271 self.xaxis = 'time'
271 self.xaxis = 'time'
272 self.ncols = 1
272 self.ncols = 1
273 #print("dataChannels ",self.data.channels)
273 #print("dataChannels ",self.data.channels)
274 self.nrows = len(self.data.channels)
274 self.nrows = len(self.data.channels)
275 self.nplots = len(self.data.channels)
275 self.nplots = len(self.data.channels)
276 self.ylabel = 'Range [km]'
276 self.ylabel = 'Range [km]'
277 self.xlabel = 'Time'
277 #self.xlabel = 'Time'
278 self.cb_label = 'dB'
278 self.cb_label = 'dB'
279 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
279 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
280 self.titles = ['{} Channel {}'.format(
280 self.titles = ['{} Channel {}'.format(
281 self.CODE.upper(), x) for x in range(self.nplots)]
281 self.CODE.upper(), x) for x in range(self.nplots)]
282
282
283 def update_list(self,dataOut):
283 def update_list(self,dataOut):
284
284
285 if len(self.channelList) == 0:
285 if len(self.channelList) == 0:
286 self.channelList = dataOut.channelList
286 self.channelList = dataOut.channelList
287 if len(self.elevationList) == 0:
287 if len(self.elevationList) == 0:
288 self.elevationList = dataOut.elevationList
288 self.elevationList = dataOut.elevationList
289 if len(self.azimuthList) == 0:
289 if len(self.azimuthList) == 0:
290 self.azimuthList = dataOut.azimuthList
290 self.azimuthList = dataOut.azimuthList
291
291
292
292
293 def update(self, dataOut):
293 def update(self, dataOut):
294 if len(self.channelList) == 0:
294 if len(self.channelList) == 0:
295 self.update_list(dataOut)
295 self.update_list(dataOut)
296 data = {}
296 data = {}
297 meta = {}
297 meta = {}
298
298
299 data['rti'] = dataOut.getPower()
299 data['rti'] = dataOut.getPower()
300
300
301 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
301 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
302 noise = 10*numpy.log10(dataOut.getNoise()/norm)
302 noise = 10*numpy.log10(dataOut.getNoise()/norm)
303 data['noise'] = noise
303 data['noise'] = noise
304
304
305 return data, meta
305 return data, meta
306
306
307 def plot(self):
307 def plot(self):
308
308
309 self.x = self.data.times
309 self.x = self.data.times
310 self.y = self.data.yrange
310 self.y = self.data.yrange
311 #print(" x, y: ",self.x, self.y)
311 #print(" x, y: ",self.x, self.y)
312 self.z = self.data[self.CODE]
312 self.z = self.data[self.CODE]
313 self.z = numpy.array(self.z, dtype=float)
313 self.z = numpy.array(self.z, dtype=float)
314 self.z = numpy.ma.masked_invalid(self.z)
314 self.z = numpy.ma.masked_invalid(self.z)
315
315
316 try:
316 try:
317 if self.channelList != None:
317 if self.channelList != None:
318 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
318 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
319 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
319 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
320 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
320 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
321 else:
321 else:
322 self.titles = ['{} Channel {}'.format(
322 self.titles = ['{} Channel {}'.format(
323 self.CODE.upper(), x) for x in self.channelList]
323 self.CODE.upper(), x) for x in self.channelList]
324 except:
324 except:
325 if self.channelList.any() != None:
325 if self.channelList.any() != None:
326 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
326 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
327 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
327 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
328 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
328 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
329 else:
329 else:
330 self.titles = ['{} Channel {}'.format(
330 self.titles = ['{} Channel {}'.format(
331 self.CODE.upper(), x) for x in self.channelList]
331 self.CODE.upper(), x) for x in self.channelList]
332
332
333 if self.decimation is None:
333 if self.decimation is None:
334 x, y, z = self.fill_gaps(self.x, self.y, self.z)
334 x, y, z = self.fill_gaps(self.x, self.y, self.z)
335 else:
335 else:
336 x, y, z = self.fill_gaps(*self.decimate())
336 x, y, z = self.fill_gaps(*self.decimate())
337
337
338 #dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
338 #dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
339 for n, ax in enumerate(self.axes):
339 for n, ax in enumerate(self.axes):
340 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
340 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
341 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
341 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
342 data = self.data[-1]
342 data = self.data[-1]
343
343
344 if ax.firsttime:
344 if ax.firsttime:
345 if (n+1) == len(self.channelList):
346 ax.set_xlabel('Time')
345 ax.plt = ax.pcolormesh(x, y, z[n].T,
347 ax.plt = ax.pcolormesh(x, y, z[n].T,
346 vmin=self.zmin,
348 vmin=self.zmin,
347 vmax=self.zmax,
349 vmax=self.zmax,
348 cmap=plt.get_cmap(self.colormap)
350 cmap=plt.get_cmap(self.colormap)
349 )
351 )
350 if self.showprofile:
352 if self.showprofile:
351 ax.plot_profile = self.pf_axes[n].plot(data[self.CODE][n], self.y)[0]
353 ax.plot_profile = self.pf_axes[n].plot(data[self.CODE][n], self.y)[0]
352 if "noise" in self.data:
354 if "noise" in self.data:
353
355
354 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
356 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(data['noise'][n], len(self.y)), self.y,
355 color="k", linestyle="dashed", lw=1)[0]
357 color="k", linestyle="dashed", lw=1)[0]
356 else:
358 else:
357 ax.collections.remove(ax.collections[0])
359 ax.collections.remove(ax.collections[0])
358 ax.plt = ax.pcolormesh(x, y, z[n].T,
360 ax.plt = ax.pcolormesh(x, y, z[n].T,
359 vmin=self.zmin,
361 vmin=self.zmin,
360 vmax=self.zmax,
362 vmax=self.zmax,
361 cmap=plt.get_cmap(self.colormap)
363 cmap=plt.get_cmap(self.colormap)
362 )
364 )
363 if self.showprofile:
365 if self.showprofile:
364 ax.plot_profile.set_data(data[self.CODE][n], self.y)
366 ax.plot_profile.set_data(data[self.CODE][n], self.y)
365 if "noise" in self.data:
367 if "noise" in self.data:
366 ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
368 ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
367
369
368
370
369 class CoherencePlot(RTIPlot):
371 class CoherencePlot(RTIPlot):
370 '''
372 '''
371 Plot for Coherence data
373 Plot for Coherence data
372 '''
374 '''
373
375
374 CODE = 'coh'
376 CODE = 'coh'
375 titles = None
377 titles = None
376
378
377 def setup(self):
379 def setup(self):
378 self.xaxis = 'time'
380 self.xaxis = 'time'
379 self.ncols = 1
381 self.ncols = 1
380 self.nrows = len(self.data.pairs)
382 self.nrows = len(self.data.pairs)
381 self.nplots = len(self.data.pairs)
383 self.nplots = len(self.data.pairs)
382 self.ylabel = 'Range [km]'
384 self.ylabel = 'Range [km]'
383 self.xlabel = 'Time'
385 #self.xlabel = 'Time'
384 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
386 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
385 if self.CODE == 'coh':
387 if self.CODE == 'coh':
386 self.cb_label = ''
388 self.cb_label = ''
387 self.titles = [
389 self.titles = [
388 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
390 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
389 else:
391 else:
390 self.cb_label = 'Degrees'
392 self.cb_label = 'Degrees'
391 self.titles = [
393 self.titles = [
392 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
394 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
393
395
394
396
395 def update(self, dataOut):
397 def update(self, dataOut):
396
398
397 data = {}
399 data = {}
398 meta = {}
400 meta = {}
399 data['coh'] = dataOut.getCoherence()
401 data['coh'] = dataOut.getCoherence()
400 meta['pairs'] = dataOut.pairsList
402 meta['pairs'] = dataOut.pairsList
401
403
402
404
403 return data, meta
405 return data, meta
404
406
405 def plot(self):
407 def plot(self):
406
408
407 self.x = self.data.times
409 self.x = self.data.times
408 self.y = self.data.yrange
410 self.y = self.data.yrange
409 self.z = self.data[self.CODE]
411 self.z = self.data[self.CODE]
410
412
411 self.z = numpy.ma.masked_invalid(self.z)
413 self.z = numpy.ma.masked_invalid(self.z)
412
414
413 if self.decimation is None:
415 if self.decimation is None:
414 x, y, z = self.fill_gaps(self.x, self.y, self.z)
416 x, y, z = self.fill_gaps(self.x, self.y, self.z)
415 else:
417 else:
416 x, y, z = self.fill_gaps(*self.decimate())
418 x, y, z = self.fill_gaps(*self.decimate())
417
419
418 for n, ax in enumerate(self.axes):
420 for n, ax in enumerate(self.axes):
419 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
421 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
420 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
422 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
421 if ax.firsttime:
423 if ax.firsttime:
424 if (n+1) == len(self.channelList):
425 ax.set_xlabel('Time')
422 ax.plt = ax.pcolormesh(x, y, z[n].T,
426 ax.plt = ax.pcolormesh(x, y, z[n].T,
423 vmin=self.zmin,
427 vmin=self.zmin,
424 vmax=self.zmax,
428 vmax=self.zmax,
425 cmap=plt.get_cmap(self.colormap)
429 cmap=plt.get_cmap(self.colormap)
426 )
430 )
427 if self.showprofile:
431 if self.showprofile:
428 ax.plot_profile = self.pf_axes[n].plot(
432 ax.plot_profile = self.pf_axes[n].plot(
429 self.data[self.CODE][n][-1], self.y)[0]
433 self.data[self.CODE][n][-1], self.y)[0]
430 # ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
434 # ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
431 # color="k", linestyle="dashed", lw=1)[0]
435 # color="k", linestyle="dashed", lw=1)[0]
432 else:
436 else:
433 ax.collections.remove(ax.collections[0])
437 ax.collections.remove(ax.collections[0])
434 ax.plt = ax.pcolormesh(x, y, z[n].T,
438 ax.plt = ax.pcolormesh(x, y, z[n].T,
435 vmin=self.zmin,
439 vmin=self.zmin,
436 vmax=self.zmax,
440 vmax=self.zmax,
437 cmap=plt.get_cmap(self.colormap)
441 cmap=plt.get_cmap(self.colormap)
438 )
442 )
439 if self.showprofile:
443 if self.showprofile:
440 ax.plot_profile.set_data(self.data[self.CODE][n][-1], self.y)
444 ax.plot_profile.set_data(self.data[self.CODE][n][-1], self.y)
441 # ax.plot_noise.set_data(numpy.repeat(
445 # ax.plot_noise.set_data(numpy.repeat(
442 # self.data['noise'][n][-1], len(self.y)), self.y)
446 # self.data['noise'][n][-1], len(self.y)), self.y)
443
447
444
448
445
449
446 class PhasePlot(CoherencePlot):
450 class PhasePlot(CoherencePlot):
447 '''
451 '''
448 Plot for Phase map data
452 Plot for Phase map data
449 '''
453 '''
450
454
451 CODE = 'phase'
455 CODE = 'phase'
452 colormap = 'seismic'
456 colormap = 'seismic'
453
457
454 def update(self, dataOut):
458 def update(self, dataOut):
455
459
456 data = {}
460 data = {}
457 meta = {}
461 meta = {}
458 data['phase'] = dataOut.getCoherence(phase=True)
462 data['phase'] = dataOut.getCoherence(phase=True)
459 meta['pairs'] = dataOut.pairsList
463 meta['pairs'] = dataOut.pairsList
460
464
461 return data, meta
465 return data, meta
462
466
463 class NoisePlot(Plot):
467 class NoisePlot(Plot):
464 '''
468 '''
465 Plot for noise
469 Plot for noise
466 '''
470 '''
467
471
468 CODE = 'noise'
472 CODE = 'noise'
469 plot_type = 'scatterbuffer'
473 plot_type = 'scatterbuffer'
470
474
471 def setup(self):
475 def setup(self):
472 self.xaxis = 'time'
476 self.xaxis = 'time'
473 self.ncols = 1
477 self.ncols = 1
474 self.nrows = 1
478 self.nrows = 1
475 self.nplots = 1
479 self.nplots = 1
476 self.ylabel = 'Intensity [dB]'
480 self.ylabel = 'Intensity [dB]'
477 self.xlabel = 'Time'
481 self.xlabel = 'Time'
478 self.titles = ['Noise']
482 self.titles = ['Noise']
479 self.colorbar = False
483 self.colorbar = False
480 self.plots_adjust.update({'right': 0.85 })
484 self.plots_adjust.update({'right': 0.85 })
481 #if not self.titles:
485 #if not self.titles:
482 self.titles = ['Noise Plot']
486 self.titles = ['Noise Plot']
483
487
484 def update(self, dataOut):
488 def update(self, dataOut):
485
489
486 data = {}
490 data = {}
487 meta = {}
491 meta = {}
488 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
492 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
489 noise = 10*numpy.log10(dataOut.getNoise())
493 noise = 10*numpy.log10(dataOut.getNoise())
490 noise = noise.reshape(dataOut.nChannels, 1)
494 noise = noise.reshape(dataOut.nChannels, 1)
491 data['noise'] = noise
495 data['noise'] = noise
492 meta['yrange'] = numpy.array([])
496 meta['yrange'] = numpy.array([])
493
497
494 return data, meta
498 return data, meta
495
499
496 def plot(self):
500 def plot(self):
497
501
498 x = self.data.times
502 x = self.data.times
499 xmin = self.data.min_time
503 xmin = self.data.min_time
500 xmax = xmin + self.xrange * 60 * 60
504 xmax = xmin + self.xrange * 60 * 60
501 Y = self.data['noise']
505 Y = self.data['noise']
502
506
503 if self.axes[0].firsttime:
507 if self.axes[0].firsttime:
504 if self.ymin is None: self.ymin = numpy.nanmin(Y) - 5
508 if self.ymin is None: self.ymin = numpy.nanmin(Y) - 5
505 if self.ymax is None: self.ymax = numpy.nanmax(Y) + 5
509 if self.ymax is None: self.ymax = numpy.nanmax(Y) + 5
506 for ch in self.data.channels:
510 for ch in self.data.channels:
507 y = Y[ch]
511 y = Y[ch]
508 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
512 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
509 plt.legend(bbox_to_anchor=(1.18, 1.0))
513 plt.legend(bbox_to_anchor=(1.18, 1.0))
510 else:
514 else:
511 for ch in self.data.channels:
515 for ch in self.data.channels:
512 y = Y[ch]
516 y = Y[ch]
513 self.axes[0].lines[ch].set_data(x, y)
517 self.axes[0].lines[ch].set_data(x, y)
514
518
515
519
516 class PowerProfilePlot(Plot):
520 class PowerProfilePlot(Plot):
517
521
518 CODE = 'pow_profile'
522 CODE = 'pow_profile'
519 plot_type = 'scatter'
523 plot_type = 'scatter'
520
524
521 def setup(self):
525 def setup(self):
522
526
523 self.ncols = 1
527 self.ncols = 1
524 self.nrows = 1
528 self.nrows = 1
525 self.nplots = 1
529 self.nplots = 1
526 self.height = 4
530 self.height = 4
527 self.width = 3
531 self.width = 3
528 self.ylabel = 'Range [km]'
532 self.ylabel = 'Range [km]'
529 self.xlabel = 'Intensity [dB]'
533 self.xlabel = 'Intensity [dB]'
530 self.titles = ['Power Profile']
534 self.titles = ['Power Profile']
531 self.colorbar = False
535 self.colorbar = False
532
536
533 def update(self, dataOut):
537 def update(self, dataOut):
534
538
535 data = {}
539 data = {}
536 meta = {}
540 meta = {}
537 data[self.CODE] = dataOut.getPower()
541 data[self.CODE] = dataOut.getPower()
538
542
539 return data, meta
543 return data, meta
540
544
541 def plot(self):
545 def plot(self):
542
546
543 y = self.data.yrange
547 y = self.data.yrange
544 self.y = y
548 self.y = y
545
549
546 x = self.data[-1][self.CODE]
550 x = self.data[-1][self.CODE]
547
551
548 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
552 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
549 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
553 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
550
554
551 if self.axes[0].firsttime:
555 if self.axes[0].firsttime:
552 for ch in self.data.channels:
556 for ch in self.data.channels:
553 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
557 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
554 plt.legend()
558 plt.legend()
555 else:
559 else:
556 for ch in self.data.channels:
560 for ch in self.data.channels:
557 self.axes[0].lines[ch].set_data(x[ch], y)
561 self.axes[0].lines[ch].set_data(x[ch], y)
558
562
559
563
560 class SpectraCutPlot(Plot):
564 class SpectraCutPlot(Plot):
561
565
562 CODE = 'spc_cut'
566 CODE = 'spc_cut'
563 plot_type = 'scatter'
567 plot_type = 'scatter'
564 buffering = False
568 buffering = False
565 heights = []
569 heights = []
566 channelList = []
570 channelList = []
567 maintitle = "Spectra Cuts"
571 maintitle = "Spectra Cuts"
568 flag_setIndex = False
572 flag_setIndex = False
569
573
570 def setup(self):
574 def setup(self):
571
575
572 self.nplots = len(self.data.channels)
576 self.nplots = len(self.data.channels)
573 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
577 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
574 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
578 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
575 self.width = 4.5 * self.ncols + 2.5
579 self.width = 4.5 * self.ncols + 2.5
576 self.height = 4.8 * self.nrows
580 self.height = 4.8 * self.nrows
577 self.ylabel = 'Power [dB]'
581 self.ylabel = 'Power [dB]'
578 self.colorbar = False
582 self.colorbar = False
579 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.9, 'bottom':0.08})
583 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.9, 'bottom':0.08})
580
584
581 if len(self.selectedHeightsList) > 0:
585 if len(self.selectedHeightsList) > 0:
582 self.maintitle = "Spectra Cut"# for %d km " %(int(self.selectedHeight))
586 self.maintitle = "Spectra Cut"# for %d km " %(int(self.selectedHeight))
583
587
584
588
585
589
586 def update(self, dataOut):
590 def update(self, dataOut):
587 if len(self.channelList) == 0:
591 if len(self.channelList) == 0:
588 self.channelList = dataOut.channelList
592 self.channelList = dataOut.channelList
589
593
590 self.heights = dataOut.heightList
594 self.heights = dataOut.heightList
591 #print("sels: ",self.selectedHeightsList)
595 #print("sels: ",self.selectedHeightsList)
592 if len(self.selectedHeightsList)>0 and not self.flag_setIndex:
596 if len(self.selectedHeightsList)>0 and not self.flag_setIndex:
593
597
594 for sel_height in self.selectedHeightsList:
598 for sel_height in self.selectedHeightsList:
595 index_list = numpy.where(self.heights >= sel_height)
599 index_list = numpy.where(self.heights >= sel_height)
596 index_list = index_list[0]
600 index_list = index_list[0]
597 self.height_index.append(index_list[0])
601 self.height_index.append(index_list[0])
598 #print("sels i:"", self.height_index)
602 #print("sels i:"", self.height_index)
599 self.flag_setIndex = True
603 self.flag_setIndex = True
600 #print(self.height_index)
604 #print(self.height_index)
601 data = {}
605 data = {}
602 meta = {}
606 meta = {}
603
607
604 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter#*dataOut.nFFTPoints
608 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter#*dataOut.nFFTPoints
605 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
609 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
606 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
610 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
607
611
608
612
609 z = []
613 z = []
610 for ch in range(dataOut.nChannels):
614 for ch in range(dataOut.nChannels):
611 if hasattr(dataOut.normFactor,'shape'):
615 if hasattr(dataOut.normFactor,'shape'):
612 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
616 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
613 else:
617 else:
614 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
618 z.append(numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
615
619
616 z = numpy.asarray(z)
620 z = numpy.asarray(z)
617 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
621 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
618 spc = 10*numpy.log10(z)
622 spc = 10*numpy.log10(z)
619
623
620
624
621 data['spc'] = spc - noise
625 data['spc'] = spc - noise
622 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
626 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
623
627
624 return data, meta
628 return data, meta
625
629
626 def plot(self):
630 def plot(self):
627 if self.xaxis == "frequency":
631 if self.xaxis == "frequency":
628 x = self.data.xrange[0][1:]
632 x = self.data.xrange[0][1:]
629 self.xlabel = "Frequency (kHz)"
633 self.xlabel = "Frequency (kHz)"
630 elif self.xaxis == "time":
634 elif self.xaxis == "time":
631 x = self.data.xrange[1]
635 x = self.data.xrange[1]
632 self.xlabel = "Time (ms)"
636 self.xlabel = "Time (ms)"
633 else:
637 else:
634 x = self.data.xrange[2]
638 x = self.data.xrange[2]
635 self.xlabel = "Velocity (m/s)"
639 self.xlabel = "Velocity (m/s)"
636
640
637 self.titles = []
641 self.titles = []
638
642
639 y = self.data.yrange
643 y = self.data.yrange
640 z = self.data[-1]['spc']
644 z = self.data[-1]['spc']
641 #print(z.shape)
645 #print(z.shape)
642 if len(self.height_index) > 0:
646 if len(self.height_index) > 0:
643 index = self.height_index
647 index = self.height_index
644 else:
648 else:
645 index = numpy.arange(0, len(y), int((len(y))/9))
649 index = numpy.arange(0, len(y), int((len(y))/9))
646 #print("inde x ", index, self.axes)
650 #print("inde x ", index, self.axes)
647
651
648 for n, ax in enumerate(self.axes):
652 for n, ax in enumerate(self.axes):
649
653
650 if ax.firsttime:
654 if ax.firsttime:
651
655
652
656
653 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
657 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
654 self.xmin = self.xmin if self.xmin else -self.xmax
658 self.xmin = self.xmin if self.xmin else -self.xmax
655 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
659 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
656 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
660 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
657
661
658
662
659 ax.plt = ax.plot(x, z[n, :, index].T)
663 ax.plt = ax.plot(x, z[n, :, index].T)
660 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
664 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
661 self.figures[0].legend(ax.plt, labels, loc='center right', prop={'size': 8})
665 self.figures[0].legend(ax.plt, labels, loc='center right', prop={'size': 8})
662 ax.minorticks_on()
666 ax.minorticks_on()
663 ax.grid(which='major', axis='both')
667 ax.grid(which='major', axis='both')
664 ax.grid(which='minor', axis='x')
668 ax.grid(which='minor', axis='x')
665 else:
669 else:
666 for i, line in enumerate(ax.plt):
670 for i, line in enumerate(ax.plt):
667 line.set_data(x, z[n, :, index[i]])
671 line.set_data(x, z[n, :, index[i]])
668
672
669
673
670 self.titles.append('CH {}'.format(self.channelList[n]))
674 self.titles.append('CH {}'.format(self.channelList[n]))
671 plt.suptitle(self.maintitle, fontsize=10)
675 plt.suptitle(self.maintitle, fontsize=10)
672
676
673
677
674 class BeaconPhase(Plot):
678 class BeaconPhase(Plot):
675
679
676 __isConfig = None
680 __isConfig = None
677 __nsubplots = None
681 __nsubplots = None
678
682
679 PREFIX = 'beacon_phase'
683 PREFIX = 'beacon_phase'
680
684
681 def __init__(self):
685 def __init__(self):
682 Plot.__init__(self)
686 Plot.__init__(self)
683 self.timerange = 24*60*60
687 self.timerange = 24*60*60
684 self.isConfig = False
688 self.isConfig = False
685 self.__nsubplots = 1
689 self.__nsubplots = 1
686 self.counter_imagwr = 0
690 self.counter_imagwr = 0
687 self.WIDTH = 800
691 self.WIDTH = 800
688 self.HEIGHT = 400
692 self.HEIGHT = 400
689 self.WIDTHPROF = 120
693 self.WIDTHPROF = 120
690 self.HEIGHTPROF = 0
694 self.HEIGHTPROF = 0
691 self.xdata = None
695 self.xdata = None
692 self.ydata = None
696 self.ydata = None
693
697
694 self.PLOT_CODE = BEACON_CODE
698 self.PLOT_CODE = BEACON_CODE
695
699
696 self.FTP_WEI = None
700 self.FTP_WEI = None
697 self.EXP_CODE = None
701 self.EXP_CODE = None
698 self.SUB_EXP_CODE = None
702 self.SUB_EXP_CODE = None
699 self.PLOT_POS = None
703 self.PLOT_POS = None
700
704
701 self.filename_phase = None
705 self.filename_phase = None
702
706
703 self.figfile = None
707 self.figfile = None
704
708
705 self.xmin = None
709 self.xmin = None
706 self.xmax = None
710 self.xmax = None
707
711
708 def getSubplots(self):
712 def getSubplots(self):
709
713
710 ncol = 1
714 ncol = 1
711 nrow = 1
715 nrow = 1
712
716
713 return nrow, ncol
717 return nrow, ncol
714
718
715 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
719 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
716
720
717 self.__showprofile = showprofile
721 self.__showprofile = showprofile
718 self.nplots = nplots
722 self.nplots = nplots
719
723
720 ncolspan = 7
724 ncolspan = 7
721 colspan = 6
725 colspan = 6
722 self.__nsubplots = 2
726 self.__nsubplots = 2
723
727
724 self.createFigure(id = id,
728 self.createFigure(id = id,
725 wintitle = wintitle,
729 wintitle = wintitle,
726 widthplot = self.WIDTH+self.WIDTHPROF,
730 widthplot = self.WIDTH+self.WIDTHPROF,
727 heightplot = self.HEIGHT+self.HEIGHTPROF,
731 heightplot = self.HEIGHT+self.HEIGHTPROF,
728 show=show)
732 show=show)
729
733
730 nrow, ncol = self.getSubplots()
734 nrow, ncol = self.getSubplots()
731
735
732 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
736 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
733
737
734 def save_phase(self, filename_phase):
738 def save_phase(self, filename_phase):
735 f = open(filename_phase,'w+')
739 f = open(filename_phase,'w+')
736 f.write('\n\n')
740 f.write('\n\n')
737 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
741 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
738 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
742 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
739 f.close()
743 f.close()
740
744
741 def save_data(self, filename_phase, data, data_datetime):
745 def save_data(self, filename_phase, data, data_datetime):
742 f=open(filename_phase,'a')
746 f=open(filename_phase,'a')
743 timetuple_data = data_datetime.timetuple()
747 timetuple_data = data_datetime.timetuple()
744 day = str(timetuple_data.tm_mday)
748 day = str(timetuple_data.tm_mday)
745 month = str(timetuple_data.tm_mon)
749 month = str(timetuple_data.tm_mon)
746 year = str(timetuple_data.tm_year)
750 year = str(timetuple_data.tm_year)
747 hour = str(timetuple_data.tm_hour)
751 hour = str(timetuple_data.tm_hour)
748 minute = str(timetuple_data.tm_min)
752 minute = str(timetuple_data.tm_min)
749 second = str(timetuple_data.tm_sec)
753 second = str(timetuple_data.tm_sec)
750 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
754 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
751 f.close()
755 f.close()
752
756
753 def plot(self):
757 def plot(self):
754 log.warning('TODO: Not yet implemented...')
758 log.warning('TODO: Not yet implemented...')
755
759
756 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
760 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
757 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
761 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
758 timerange=None,
762 timerange=None,
759 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
763 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
760 server=None, folder=None, username=None, password=None,
764 server=None, folder=None, username=None, password=None,
761 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
765 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
762
766
763 if dataOut.flagNoData:
767 if dataOut.flagNoData:
764 return dataOut
768 return dataOut
765
769
766 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
770 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
767 return
771 return
768
772
769 if pairsList == None:
773 if pairsList == None:
770 pairsIndexList = dataOut.pairsIndexList[:10]
774 pairsIndexList = dataOut.pairsIndexList[:10]
771 else:
775 else:
772 pairsIndexList = []
776 pairsIndexList = []
773 for pair in pairsList:
777 for pair in pairsList:
774 if pair not in dataOut.pairsList:
778 if pair not in dataOut.pairsList:
775 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
779 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
776 pairsIndexList.append(dataOut.pairsList.index(pair))
780 pairsIndexList.append(dataOut.pairsList.index(pair))
777
781
778 if pairsIndexList == []:
782 if pairsIndexList == []:
779 return
783 return
780
784
781 # if len(pairsIndexList) > 4:
785 # if len(pairsIndexList) > 4:
782 # pairsIndexList = pairsIndexList[0:4]
786 # pairsIndexList = pairsIndexList[0:4]
783
787
784 hmin_index = None
788 hmin_index = None
785 hmax_index = None
789 hmax_index = None
786
790
787 if hmin != None and hmax != None:
791 if hmin != None and hmax != None:
788 indexes = numpy.arange(dataOut.nHeights)
792 indexes = numpy.arange(dataOut.nHeights)
789 hmin_list = indexes[dataOut.heightList >= hmin]
793 hmin_list = indexes[dataOut.heightList >= hmin]
790 hmax_list = indexes[dataOut.heightList <= hmax]
794 hmax_list = indexes[dataOut.heightList <= hmax]
791
795
792 if hmin_list.any():
796 if hmin_list.any():
793 hmin_index = hmin_list[0]
797 hmin_index = hmin_list[0]
794
798
795 if hmax_list.any():
799 if hmax_list.any():
796 hmax_index = hmax_list[-1]+1
800 hmax_index = hmax_list[-1]+1
797
801
798 x = dataOut.getTimeRange()
802 x = dataOut.getTimeRange()
799
803
800 thisDatetime = dataOut.datatime
804 thisDatetime = dataOut.datatime
801
805
802 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
806 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
803 xlabel = "Local Time"
807 xlabel = "Local Time"
804 ylabel = "Phase (degrees)"
808 ylabel = "Phase (degrees)"
805
809
806 update_figfile = False
810 update_figfile = False
807
811
808 nplots = len(pairsIndexList)
812 nplots = len(pairsIndexList)
809 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
813 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
810 phase_beacon = numpy.zeros(len(pairsIndexList))
814 phase_beacon = numpy.zeros(len(pairsIndexList))
811 for i in range(nplots):
815 for i in range(nplots):
812 pair = dataOut.pairsList[pairsIndexList[i]]
816 pair = dataOut.pairsList[pairsIndexList[i]]
813 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
817 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
814 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
818 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
815 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
819 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
816 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
820 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
817 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
821 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
818
822
819 if dataOut.beacon_heiIndexList:
823 if dataOut.beacon_heiIndexList:
820 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
824 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
821 else:
825 else:
822 phase_beacon[i] = numpy.average(phase)
826 phase_beacon[i] = numpy.average(phase)
823
827
824 if not self.isConfig:
828 if not self.isConfig:
825
829
826 nplots = len(pairsIndexList)
830 nplots = len(pairsIndexList)
827
831
828 self.setup(id=id,
832 self.setup(id=id,
829 nplots=nplots,
833 nplots=nplots,
830 wintitle=wintitle,
834 wintitle=wintitle,
831 showprofile=showprofile,
835 showprofile=showprofile,
832 show=show)
836 show=show)
833
837
834 if timerange != None:
838 if timerange != None:
835 self.timerange = timerange
839 self.timerange = timerange
836
840
837 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
841 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
838
842
839 if ymin == None: ymin = 0
843 if ymin == None: ymin = 0
840 if ymax == None: ymax = 360
844 if ymax == None: ymax = 360
841
845
842 self.FTP_WEI = ftp_wei
846 self.FTP_WEI = ftp_wei
843 self.EXP_CODE = exp_code
847 self.EXP_CODE = exp_code
844 self.SUB_EXP_CODE = sub_exp_code
848 self.SUB_EXP_CODE = sub_exp_code
845 self.PLOT_POS = plot_pos
849 self.PLOT_POS = plot_pos
846
850
847 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
851 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
848 self.isConfig = True
852 self.isConfig = True
849 self.figfile = figfile
853 self.figfile = figfile
850 self.xdata = numpy.array([])
854 self.xdata = numpy.array([])
851 self.ydata = numpy.array([])
855 self.ydata = numpy.array([])
852
856
853 update_figfile = True
857 update_figfile = True
854
858
855 #open file beacon phase
859 #open file beacon phase
856 path = '%s%03d' %(self.PREFIX, self.id)
860 path = '%s%03d' %(self.PREFIX, self.id)
857 beacon_file = os.path.join(path,'%s.txt'%self.name)
861 beacon_file = os.path.join(path,'%s.txt'%self.name)
858 self.filename_phase = os.path.join(figpath,beacon_file)
862 self.filename_phase = os.path.join(figpath,beacon_file)
859 #self.save_phase(self.filename_phase)
863 #self.save_phase(self.filename_phase)
860
864
861
865
862 #store data beacon phase
866 #store data beacon phase
863 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
867 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
864
868
865 self.setWinTitle(title)
869 self.setWinTitle(title)
866
870
867
871
868 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
872 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
869
873
870 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
874 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
871
875
872 axes = self.axesList[0]
876 axes = self.axesList[0]
873
877
874 self.xdata = numpy.hstack((self.xdata, x[0:1]))
878 self.xdata = numpy.hstack((self.xdata, x[0:1]))
875
879
876 if len(self.ydata)==0:
880 if len(self.ydata)==0:
877 self.ydata = phase_beacon.reshape(-1,1)
881 self.ydata = phase_beacon.reshape(-1,1)
878 else:
882 else:
879 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
883 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
880
884
881
885
882 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
886 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
883 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
887 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
884 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
888 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
885 XAxisAsTime=True, grid='both'
889 XAxisAsTime=True, grid='both'
886 )
890 )
887
891
888 self.draw()
892 self.draw()
889
893
890 if dataOut.ltctime >= self.xmax:
894 if dataOut.ltctime >= self.xmax:
891 self.counter_imagwr = wr_period
895 self.counter_imagwr = wr_period
892 self.isConfig = False
896 self.isConfig = False
893 update_figfile = True
897 update_figfile = True
894
898
895 self.save(figpath=figpath,
899 self.save(figpath=figpath,
896 figfile=figfile,
900 figfile=figfile,
897 save=save,
901 save=save,
898 ftp=ftp,
902 ftp=ftp,
899 wr_period=wr_period,
903 wr_period=wr_period,
900 thisDatetime=thisDatetime,
904 thisDatetime=thisDatetime,
901 update_figfile=update_figfile)
905 update_figfile=update_figfile)
902
906
903 return dataOut
907 return dataOut
904
908
905 class NoiselessSpectraPlot(Plot):
909 class NoiselessSpectraPlot(Plot):
906 '''
910 '''
907 Plot for Spectra data, subtracting
911 Plot for Spectra data, subtracting
908 the noise in all channels, using for
912 the noise in all channels, using for
909 amisr-14 data
913 amisr-14 data
910 '''
914 '''
911
915
912 CODE = 'noiseless_spc'
916 CODE = 'noiseless_spc'
913 colormap = 'jet'
917 colormap = 'jet'
914 plot_type = 'pcolor'
918 plot_type = 'pcolor'
915 buffering = False
919 buffering = False
916 channelList = []
920 channelList = []
917 last_noise = None
921 last_noise = None
918
922
919 def setup(self):
923 def setup(self):
920
924
921 self.nplots = len(self.data.channels)
925 self.nplots = len(self.data.channels)
922 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
926 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
923 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
927 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
924 self.height = 3.5 * self.nrows
928 self.height = 3.5 * self.nrows
925
929
926 self.cb_label = 'dB'
930 self.cb_label = 'dB'
927 if self.showprofile:
931 if self.showprofile:
928 self.width = 5.8 * self.ncols
932 self.width = 5.8 * self.ncols
929 else:
933 else:
930 self.width = 4.8* self.ncols
934 self.width = 4.8* self.ncols
931 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.92, 'bottom': 0.12})
935 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.92, 'bottom': 0.12})
932
936
933 self.ylabel = 'Range [km]'
937 self.ylabel = 'Range [km]'
934
938
935
939
936 def update_list(self,dataOut):
940 def update_list(self,dataOut):
937 if len(self.channelList) == 0:
941 if len(self.channelList) == 0:
938 self.channelList = dataOut.channelList
942 self.channelList = dataOut.channelList
939
943
940 def update(self, dataOut):
944 def update(self, dataOut):
941
945
942 self.update_list(dataOut)
946 self.update_list(dataOut)
943 data = {}
947 data = {}
944 meta = {}
948 meta = {}
945
949
946 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
950 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
947 n0 = (dataOut.getNoise()/norm)
951 n0 = (dataOut.getNoise()/norm)
948 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
952 noise = numpy.repeat(n0,(dataOut.nFFTPoints*dataOut.nHeights)).reshape(dataOut.nChannels,dataOut.nFFTPoints,dataOut.nHeights)
949 noise = 10*numpy.log10(noise)
953 noise = 10*numpy.log10(noise)
950
954
951 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
955 z = numpy.zeros((dataOut.nChannels, dataOut.nFFTPoints, dataOut.nHeights))
952 for ch in range(dataOut.nChannels):
956 for ch in range(dataOut.nChannels):
953 if hasattr(dataOut.normFactor,'ndim'):
957 if hasattr(dataOut.normFactor,'ndim'):
954 if dataOut.normFactor.ndim > 1:
958 if dataOut.normFactor.ndim > 1:
955 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
959 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor[ch]))
956 else:
960 else:
957 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
961 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
958 else:
962 else:
959 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
963 z[ch] = (numpy.divide(dataOut.data_spc[ch],dataOut.normFactor))
960
964
961 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
965 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
962 spc = 10*numpy.log10(z)
966 spc = 10*numpy.log10(z)
963
967
964
968
965 data['spc'] = spc - noise
969 data['spc'] = spc - noise
966 #print(spc.shape)
970 #print(spc.shape)
967 data['rti'] = spc.mean(axis=1)
971 data['rti'] = spc.mean(axis=1)
968 data['noise'] = noise
972 data['noise'] = noise
969
973
970
974
971
975
972 # data['noise'] = noise
976 # data['noise'] = noise
973 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
977 meta['xrange'] = (dataOut.getFreqRange(EXTRA_POINTS)/1000., dataOut.getAcfRange(EXTRA_POINTS), dataOut.getVelRange(EXTRA_POINTS))
974
978
975 return data, meta
979 return data, meta
976
980
977 def plot(self):
981 def plot(self):
978 if self.xaxis == "frequency":
982 if self.xaxis == "frequency":
979 x = self.data.xrange[0]
983 x = self.data.xrange[0]
980 self.xlabel = "Frequency (kHz)"
984 self.xlabel = "Frequency (kHz)"
981 elif self.xaxis == "time":
985 elif self.xaxis == "time":
982 x = self.data.xrange[1]
986 x = self.data.xrange[1]
983 self.xlabel = "Time (ms)"
987 self.xlabel = "Time (ms)"
984 else:
988 else:
985 x = self.data.xrange[2]
989 x = self.data.xrange[2]
986 self.xlabel = "Velocity (m/s)"
990 self.xlabel = "Velocity (m/s)"
987
991
988 self.titles = []
992 self.titles = []
989 y = self.data.yrange
993 y = self.data.yrange
990 self.y = y
994 self.y = y
991
995
992 data = self.data[-1]
996 data = self.data[-1]
993 z = data['spc']
997 z = data['spc']
994
998
995 for n, ax in enumerate(self.axes):
999 for n, ax in enumerate(self.axes):
996 #noise = data['noise'][n]
1000 #noise = data['noise'][n]
997
1001
998 if ax.firsttime:
1002 if ax.firsttime:
999 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1003 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
1000 self.xmin = self.xmin if self.xmin else -self.xmax
1004 self.xmin = self.xmin if self.xmin else -self.xmax
1001 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1005 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
1002 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1006 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
1003 ax.plt = ax.pcolormesh(x, y, z[n].T,
1007 ax.plt = ax.pcolormesh(x, y, z[n].T,
1004 vmin=self.zmin,
1008 vmin=self.zmin,
1005 vmax=self.zmax,
1009 vmax=self.zmax,
1006 cmap=plt.get_cmap(self.colormap)
1010 cmap=plt.get_cmap(self.colormap)
1007 )
1011 )
1008
1012
1009 if self.showprofile:
1013 if self.showprofile:
1010 ax.plt_profile = self.pf_axes[n].plot(
1014 ax.plt_profile = self.pf_axes[n].plot(
1011 data['rti'][n], y)[0]
1015 data['rti'][n], y)[0]
1012
1016
1013
1017
1014 else:
1018 else:
1015 ax.plt.set_array(z[n].T.ravel())
1019 ax.plt.set_array(z[n].T.ravel())
1016 if self.showprofile:
1020 if self.showprofile:
1017 ax.plt_profile.set_data(data['rti'][n], y)
1021 ax.plt_profile.set_data(data['rti'][n], y)
1018
1022
1019
1023
1020 self.titles.append('CH {}'.format(self.channelList[n]))
1024 self.titles.append('CH {}'.format(self.channelList[n]))
1021
1025
1022
1026
1023 class NoiselessRTIPlot(RTIPlot):
1027 class NoiselessRTIPlot(RTIPlot):
1024 '''
1028 '''
1025 Plot for RTI data
1029 Plot for RTI data
1026 '''
1030 '''
1027
1031
1028 CODE = 'noiseless_rti'
1032 CODE = 'noiseless_rti'
1029 colormap = 'jet'
1033 colormap = 'jet'
1030 plot_type = 'pcolorbuffer'
1034 plot_type = 'pcolorbuffer'
1031 titles = None
1035 titles = None
1032 channelList = []
1036 channelList = []
1033 elevationList = []
1037 elevationList = []
1034 azimuthList = []
1038 azimuthList = []
1035 last_noise = None
1039 last_noise = None
1036
1040
1037 def setup(self):
1041 def setup(self):
1038 self.xaxis = 'time'
1042 self.xaxis = 'time'
1039 self.ncols = 1
1043 self.ncols = 1
1040 #print("dataChannels ",self.data.channels)
1044 #print("dataChannels ",self.data.channels)
1041 self.nrows = len(self.data.channels)
1045 self.nrows = len(self.data.channels)
1042 self.nplots = len(self.data.channels)
1046 self.nplots = len(self.data.channels)
1043 self.ylabel = 'Range [km]'
1047 self.ylabel = 'Range [km]'
1044 self.xlabel = 'Time'
1048 #self.xlabel = 'Time'
1045 self.cb_label = 'dB'
1049 self.cb_label = 'dB'
1046 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1050 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1047 self.titles = ['{} Channel {}'.format(
1051 self.titles = ['{} Channel {}'.format(
1048 self.CODE.upper(), x) for x in range(self.nplots)]
1052 self.CODE.upper(), x) for x in range(self.nplots)]
1049
1053
1050 def update_list(self,dataOut):
1054 def update_list(self,dataOut):
1051 if len(self.channelList) == 0:
1055 if len(self.channelList) == 0:
1052 self.channelList = dataOut.channelList
1056 self.channelList = dataOut.channelList
1053 if len(self.elevationList) == 0:
1057 if len(self.elevationList) == 0:
1054 self.elevationList = dataOut.elevationList
1058 self.elevationList = dataOut.elevationList
1055 if len(self.azimuthList) == 0:
1059 if len(self.azimuthList) == 0:
1056 self.azimuthList = dataOut.azimuthList
1060 self.azimuthList = dataOut.azimuthList
1057
1061
1058 def update(self, dataOut):
1062 def update(self, dataOut):
1059 if len(self.channelList) == 0:
1063 if len(self.channelList) == 0:
1060 self.update_list(dataOut)
1064 self.update_list(dataOut)
1061
1065
1062 data = {}
1066 data = {}
1063 meta = {}
1067 meta = {}
1064 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1068 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1065 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt
1069 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt
1066 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1070 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1067 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1071 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1068 data['noise'] = n0
1072 data['noise'] = n0
1069 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1073 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1070 noiseless_data = dataOut.getPower() - noise
1074 noiseless_data = dataOut.getPower() - noise
1071
1075
1072 #print("power, noise:", dataOut.getPower(), n0)
1076 #print("power, noise:", dataOut.getPower(), n0)
1073 #print(noise)
1077 #print(noise)
1074 #print(noiseless_data)
1078 #print(noiseless_data)
1075
1079
1076 data['noiseless_rti'] = noiseless_data
1080 data['noiseless_rti'] = noiseless_data
1077
1081
1078 return data, meta
1082 return data, meta
1079
1083
1080 def plot(self):
1084 def plot(self):
1081 from matplotlib import pyplot as plt
1085 from matplotlib import pyplot as plt
1082 self.x = self.data.times
1086 self.x = self.data.times
1083 self.y = self.data.yrange
1087 self.y = self.data.yrange
1084 self.z = self.data['noiseless_rti']
1088 self.z = self.data['noiseless_rti']
1085 self.z = numpy.array(self.z, dtype=float)
1089 self.z = numpy.array(self.z, dtype=float)
1086 self.z = numpy.ma.masked_invalid(self.z)
1090 self.z = numpy.ma.masked_invalid(self.z)
1087
1091
1088
1092
1089 try:
1093 try:
1090 if self.channelList != None:
1094 if self.channelList != None:
1091 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1095 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1092 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1096 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1093 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1097 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1094 else:
1098 else:
1095 self.titles = ['{} Channel {}'.format(
1099 self.titles = ['{} Channel {}'.format(
1096 self.CODE.upper(), x) for x in self.channelList]
1100 self.CODE.upper(), x) for x in self.channelList]
1097 except:
1101 except:
1098 if self.channelList.any() != None:
1102 if self.channelList.any() != None:
1099 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1103 if len(self.elevationList) > 0 and len(self.azimuthList) > 0:
1100 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1104 self.titles = ['{} Channel {} ({:2.1f} Elev, {:2.1f} Azth)'.format(
1101 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1105 self.CODE.upper(), x, self.elevationList[x], self.azimuthList[x]) for x in self.channelList]
1102 else:
1106 else:
1103 self.titles = ['{} Channel {}'.format(
1107 self.titles = ['{} Channel {}'.format(
1104 self.CODE.upper(), x) for x in self.channelList]
1108 self.CODE.upper(), x) for x in self.channelList]
1105
1109
1106
1110
1107 if self.decimation is None:
1111 if self.decimation is None:
1108 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1112 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1109 else:
1113 else:
1110 x, y, z = self.fill_gaps(*self.decimate())
1114 x, y, z = self.fill_gaps(*self.decimate())
1111
1115
1112 dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
1116 dummy_var = self.axes #ExtraΓ±amente esto actualiza el valor axes
1113 #print("plot shapes ", z.shape, x.shape, y.shape)
1117 #print("plot shapes ", z.shape, x.shape, y.shape)
1114 #print(self.axes)
1118 #print(self.axes)
1115 for n, ax in enumerate(self.axes):
1119 for n, ax in enumerate(self.axes):
1116
1120
1117
1121
1118 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
1122 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
1119 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
1123 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
1120 data = self.data[-1]
1124 data = self.data[-1]
1121 if ax.firsttime:
1125 if ax.firsttime:
1126 if (n+1) == len(self.channelList):
1127 ax.set_xlabel('Time')
1122 ax.plt = ax.pcolormesh(x, y, z[n].T,
1128 ax.plt = ax.pcolormesh(x, y, z[n].T,
1123 vmin=self.zmin,
1129 vmin=self.zmin,
1124 vmax=self.zmax,
1130 vmax=self.zmax,
1125 cmap=plt.get_cmap(self.colormap)
1131 cmap=plt.get_cmap(self.colormap)
1126 )
1132 )
1127 if self.showprofile:
1133 if self.showprofile:
1128 ax.plot_profile = self.pf_axes[n].plot(data['noiseless_rti'][n], self.y)[0]
1134 ax.plot_profile = self.pf_axes[n].plot(data['noiseless_rti'][n], self.y)[0]
1129
1135
1130 else:
1136 else:
1131 ax.collections.remove(ax.collections[0])
1137 ax.collections.remove(ax.collections[0])
1132 ax.plt = ax.pcolormesh(x, y, z[n].T,
1138 ax.plt = ax.pcolormesh(x, y, z[n].T,
1133 vmin=self.zmin,
1139 vmin=self.zmin,
1134 vmax=self.zmax,
1140 vmax=self.zmax,
1135 cmap=plt.get_cmap(self.colormap)
1141 cmap=plt.get_cmap(self.colormap)
1136 )
1142 )
1137 if self.showprofile:
1143 if self.showprofile:
1138 ax.plot_profile.set_data(data['noiseless_rti'][n], self.y)
1144 ax.plot_profile.set_data(data['noiseless_rti'][n], self.y)
1139 # if "noise" in self.data:
1145 # if "noise" in self.data:
1140 # #ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
1146 # #ax.plot_noise.set_data(numpy.repeat(data['noise'][n], len(self.y)), self.y)
1141 # ax.plot_noise.set_data(data['noise'][n], self.y)
1147 # ax.plot_noise.set_data(data['noise'][n], self.y)
1142
1148
1143
1149
1144 class OutliersRTIPlot(Plot):
1150 class OutliersRTIPlot(Plot):
1145 '''
1151 '''
1146 Plot for data_xxxx object
1152 Plot for data_xxxx object
1147 '''
1153 '''
1148
1154
1149 CODE = 'outlier_rtc' # Range Time Counts
1155 CODE = 'outlier_rtc' # Range Time Counts
1150 colormap = 'cool'
1156 colormap = 'cool'
1151 plot_type = 'pcolorbuffer'
1157 plot_type = 'pcolorbuffer'
1152
1158
1153 def setup(self):
1159 def setup(self):
1154 self.xaxis = 'time'
1160 self.xaxis = 'time'
1155 self.ncols = 1
1161 self.ncols = 1
1156 self.nrows = self.data.shape('outlier_rtc')[0]
1162 self.nrows = self.data.shape('outlier_rtc')[0]
1157 self.nplots = self.nrows
1163 self.nplots = self.nrows
1158 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1164 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1159
1165
1160
1166
1161 if not self.xlabel:
1167 if not self.xlabel:
1162 self.xlabel = 'Time'
1168 self.xlabel = 'Time'
1163
1169
1164 self.ylabel = 'Height [km]'
1170 self.ylabel = 'Height [km]'
1165 if not self.titles:
1171 if not self.titles:
1166 self.titles = ['Outliers Ch:{}'.format(x) for x in range(self.nrows)]
1172 self.titles = ['Outliers Ch:{}'.format(x) for x in range(self.nrows)]
1167
1173
1168 def update(self, dataOut):
1174 def update(self, dataOut):
1169
1175
1170 data = {}
1176 data = {}
1171 data['outlier_rtc'] = dataOut.data_outlier
1177 data['outlier_rtc'] = dataOut.data_outlier
1172
1178
1173 meta = {}
1179 meta = {}
1174
1180
1175 return data, meta
1181 return data, meta
1176
1182
1177 def plot(self):
1183 def plot(self):
1178 # self.data.normalize_heights()
1184 # self.data.normalize_heights()
1179 self.x = self.data.times
1185 self.x = self.data.times
1180 self.y = self.data.yrange
1186 self.y = self.data.yrange
1181 self.z = self.data['outlier_rtc']
1187 self.z = self.data['outlier_rtc']
1182
1188
1183 #self.z = numpy.ma.masked_invalid(self.z)
1189 #self.z = numpy.ma.masked_invalid(self.z)
1184
1190
1185 if self.decimation is None:
1191 if self.decimation is None:
1186 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1192 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1187 else:
1193 else:
1188 x, y, z = self.fill_gaps(*self.decimate())
1194 x, y, z = self.fill_gaps(*self.decimate())
1189
1195
1190 for n, ax in enumerate(self.axes):
1196 for n, ax in enumerate(self.axes):
1191
1197
1192 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1198 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1193 self.z[n])
1199 self.z[n])
1194 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1200 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1195 self.z[n])
1201 self.z[n])
1196 data = self.data[-1]
1202 data = self.data[-1]
1197 if ax.firsttime:
1203 if ax.firsttime:
1198 if self.zlimits is not None:
1204 if self.zlimits is not None:
1199 self.zmin, self.zmax = self.zlimits[n]
1205 self.zmin, self.zmax = self.zlimits[n]
1200
1206
1201 ax.plt = ax.pcolormesh(x, y, z[n].T,
1207 ax.plt = ax.pcolormesh(x, y, z[n].T,
1202 vmin=self.zmin,
1208 vmin=self.zmin,
1203 vmax=self.zmax,
1209 vmax=self.zmax,
1204 cmap=self.cmaps[n]
1210 cmap=self.cmaps[n]
1205 )
1211 )
1206 if self.showprofile:
1212 if self.showprofile:
1207 ax.plot_profile = self.pf_axes[n].plot(data['outlier_rtc'][n], self.y)[0]
1213 ax.plot_profile = self.pf_axes[n].plot(data['outlier_rtc'][n], self.y)[0]
1208 self.pf_axes[n].set_xlabel('')
1214 self.pf_axes[n].set_xlabel('')
1209 else:
1215 else:
1210 if self.zlimits is not None:
1216 if self.zlimits is not None:
1211 self.zmin, self.zmax = self.zlimits[n]
1217 self.zmin, self.zmax = self.zlimits[n]
1212 ax.collections.remove(ax.collections[0])
1218 ax.collections.remove(ax.collections[0])
1213 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1219 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1214 vmin=self.zmin,
1220 vmin=self.zmin,
1215 vmax=self.zmax,
1221 vmax=self.zmax,
1216 cmap=self.cmaps[n]
1222 cmap=self.cmaps[n]
1217 )
1223 )
1218 if self.showprofile:
1224 if self.showprofile:
1219 ax.plot_profile.set_data(data['outlier_rtc'][n], self.y)
1225 ax.plot_profile.set_data(data['outlier_rtc'][n], self.y)
1220 self.pf_axes[n].set_xlabel('')
1226 self.pf_axes[n].set_xlabel('')
1221
1227
1222 class NIncohIntRTIPlot(Plot):
1228 class NIncohIntRTIPlot(Plot):
1223 '''
1229 '''
1224 Plot for data_xxxx object
1230 Plot for data_xxxx object
1225 '''
1231 '''
1226
1232
1227 CODE = 'integrations_rtc' # Range Time Counts
1233 CODE = 'integrations_rtc' # Range Time Counts
1228 colormap = 'BuGn'
1234 colormap = 'BuGn'
1229 plot_type = 'pcolorbuffer'
1235 plot_type = 'pcolorbuffer'
1230
1236
1231 def setup(self):
1237 def setup(self):
1232 self.xaxis = 'time'
1238 self.xaxis = 'time'
1233 self.ncols = 1
1239 self.ncols = 1
1234 self.nrows = self.data.shape('integrations_rtc')[0]
1240 self.nrows = self.data.shape('integrations_rtc')[0]
1235 self.nplots = self.nrows
1241 self.nplots = self.nrows
1236 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1242 self.plots_adjust.update({'hspace':0.8, 'left': 0.08, 'bottom': 0.2, 'right':0.94})
1237
1243
1238
1244
1239 if not self.xlabel:
1245 if not self.xlabel:
1240 self.xlabel = 'Time'
1246 self.xlabel = 'Time'
1241
1247
1242 self.ylabel = 'Height [km]'
1248 self.ylabel = 'Height [km]'
1243 if not self.titles:
1249 if not self.titles:
1244 self.titles = ['Integration Ch:{}'.format(x) for x in range(self.nrows)]
1250 self.titles = ['Integration Ch:{}'.format(x) for x in range(self.nrows)]
1245
1251
1246 def update(self, dataOut):
1252 def update(self, dataOut):
1247
1253
1248 data = {}
1254 data = {}
1249 data['integrations_rtc'] = dataOut.nIncohInt
1255 data['integrations_rtc'] = dataOut.nIncohInt
1250
1256
1251 meta = {}
1257 meta = {}
1252
1258
1253 return data, meta
1259 return data, meta
1254
1260
1255 def plot(self):
1261 def plot(self):
1256 # self.data.normalize_heights()
1262 # self.data.normalize_heights()
1257 self.x = self.data.times
1263 self.x = self.data.times
1258 self.y = self.data.yrange
1264 self.y = self.data.yrange
1259 self.z = self.data['integrations_rtc']
1265 self.z = self.data['integrations_rtc']
1260
1266
1261 #self.z = numpy.ma.masked_invalid(self.z)
1267 #self.z = numpy.ma.masked_invalid(self.z)
1262
1268
1263 if self.decimation is None:
1269 if self.decimation is None:
1264 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1270 x, y, z = self.fill_gaps(self.x, self.y, self.z)
1265 else:
1271 else:
1266 x, y, z = self.fill_gaps(*self.decimate())
1272 x, y, z = self.fill_gaps(*self.decimate())
1267
1273
1268 for n, ax in enumerate(self.axes):
1274 for n, ax in enumerate(self.axes):
1269
1275
1270 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1276 self.zmax = self.zmax if self.zmax is not None else numpy.max(
1271 self.z[n])
1277 self.z[n])
1272 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1278 self.zmin = self.zmin if self.zmin is not None else numpy.min(
1273 self.z[n])
1279 self.z[n])
1274 data = self.data[-1]
1280 data = self.data[-1]
1275 if ax.firsttime:
1281 if ax.firsttime:
1276 if self.zlimits is not None:
1282 if self.zlimits is not None:
1277 self.zmin, self.zmax = self.zlimits[n]
1283 self.zmin, self.zmax = self.zlimits[n]
1278
1284
1279 ax.plt = ax.pcolormesh(x, y, z[n].T,
1285 ax.plt = ax.pcolormesh(x, y, z[n].T,
1280 vmin=self.zmin,
1286 vmin=self.zmin,
1281 vmax=self.zmax,
1287 vmax=self.zmax,
1282 cmap=self.cmaps[n]
1288 cmap=self.cmaps[n]
1283 )
1289 )
1284 if self.showprofile:
1290 if self.showprofile:
1285 ax.plot_profile = self.pf_axes[n].plot(data['integrations_rtc'][n], self.y)[0]
1291 ax.plot_profile = self.pf_axes[n].plot(data['integrations_rtc'][n], self.y)[0]
1286 self.pf_axes[n].set_xlabel('')
1292 self.pf_axes[n].set_xlabel('')
1287 else:
1293 else:
1288 if self.zlimits is not None:
1294 if self.zlimits is not None:
1289 self.zmin, self.zmax = self.zlimits[n]
1295 self.zmin, self.zmax = self.zlimits[n]
1290 ax.collections.remove(ax.collections[0])
1296 ax.collections.remove(ax.collections[0])
1291 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1297 ax.plt = ax.pcolormesh(x, y, z[n].T ,
1292 vmin=self.zmin,
1298 vmin=self.zmin,
1293 vmax=self.zmax,
1299 vmax=self.zmax,
1294 cmap=self.cmaps[n]
1300 cmap=self.cmaps[n]
1295 )
1301 )
1296 if self.showprofile:
1302 if self.showprofile:
1297 ax.plot_profile.set_data(data['integrations_rtc'][n], self.y)
1303 ax.plot_profile.set_data(data['integrations_rtc'][n], self.y)
1298 self.pf_axes[n].set_xlabel('')
1304 self.pf_axes[n].set_xlabel('')
1299
1305
1300
1306
1301 import datetime
1307 import datetime
1302 class NoiselessRTILinePlot(Plot):
1308 class NoiselessRTILinePlot(Plot):
1303 '''
1309 '''
1304 Plot for RTI data
1310 Plot for RTI data
1305 '''
1311 '''
1306
1312
1307 CODE = 'noiseless_rtiLine'
1313 CODE = 'noiseless_rtiLine'
1308
1314
1309 plot_type = 'scatter'
1315 plot_type = 'scatter'
1310 titles = None
1316 titles = None
1311 channelList = []
1317 channelList = []
1312 elevationList = []
1318 elevationList = []
1313 azimuthList = []
1319 azimuthList = []
1314 last_noise = None
1320 last_noise = None
1315
1321
1316 def setup(self):
1322 def setup(self):
1317 self.xaxis = 'Range (Km)'
1323 self.xaxis = 'Range (Km)'
1318 self.nplots = len(self.data.channels)
1324 self.nplots = len(self.data.channels)
1319 self.nrows = int(numpy.ceil(self.nplots/2))
1325 self.nrows = int(numpy.ceil(self.nplots/2))
1320 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1326 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1321 self.ylabel = 'Intensity [dB]'
1327 self.ylabel = 'Intensity [dB]'
1322 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1328 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1323 self.colorbar = False
1329 self.colorbar = False
1324 self.width = 6
1330 self.width = 6
1325 self.height = 4
1331 self.height = 4
1326
1332
1327 def update_list(self,dataOut):
1333 def update_list(self,dataOut):
1328 if len(self.channelList) == 0:
1334 if len(self.channelList) == 0:
1329 self.channelList = dataOut.channelList
1335 self.channelList = dataOut.channelList
1330 if len(self.elevationList) == 0:
1336 if len(self.elevationList) == 0:
1331 self.elevationList = dataOut.elevationList
1337 self.elevationList = dataOut.elevationList
1332 if len(self.azimuthList) == 0:
1338 if len(self.azimuthList) == 0:
1333 self.azimuthList = dataOut.azimuthList
1339 self.azimuthList = dataOut.azimuthList
1334
1340
1335 def update(self, dataOut):
1341 def update(self, dataOut):
1336 if len(self.channelList) == 0:
1342 if len(self.channelList) == 0:
1337 self.update_list(dataOut)
1343 self.update_list(dataOut)
1338
1344
1339 data = {}
1345 data = {}
1340 meta = {}
1346 meta = {}
1341 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1347 #print(dataOut.max_nIncohInt, dataOut.nIncohInt)
1342 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt)
1348 #print(dataOut.windowOfFilter,dataOut.nCohInt,dataOut.nProfiles,dataOut.max_nIncohInt,dataOut.nIncohInt)
1343 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1349 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1344
1350
1345 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1351 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1346 data['noise'] = n0
1352 data['noise'] = n0
1347
1353
1348 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1354 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1349 noiseless_data = dataOut.getPower() - noise
1355 noiseless_data = dataOut.getPower() - noise
1350
1356
1351 #print("power, noise:", dataOut.getPower(), n0)
1357 #print("power, noise:", dataOut.getPower(), n0)
1352 #print(noise)
1358 #print(noise)
1353 #print(noiseless_data)
1359 #print(noiseless_data)
1354
1360
1355 data['noiseless_rtiLine'] = noiseless_data
1361 data['noiseless_rtiLine'] = noiseless_data
1356
1362
1357 #print(noiseless_data.shape, self.name)
1363 #print(noiseless_data.shape, self.name)
1358 data['time'] = dataOut.utctime
1364 data['time'] = dataOut.utctime
1359
1365
1360 return data, meta
1366 return data, meta
1361
1367
1362 def plot(self):
1368 def plot(self):
1363
1369
1364 self.x = self.data.times
1370 self.x = self.data.times
1365 self.y = self.data.yrange
1371 self.y = self.data.yrange
1366 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1372 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1367 #ts = self.data['time'][0].squeeze()
1373 #ts = self.data['time'][0].squeeze()
1368 if len(self.data['noiseless_rtiLine'])>2 :
1374 if len(self.data['noiseless_rtiLine'])>2 :
1369 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1375 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1370 else:
1376 else:
1371 self.z = self.data['noiseless_rtiLine']
1377 self.z = self.data['noiseless_rtiLine']
1372 #print(self.z.shape, self.y.shape, ts)
1378 #print(self.z.shape, self.y.shape, ts)
1373 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1379 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1374
1380
1375 for i,ax in enumerate(self.axes):
1381 for i,ax in enumerate(self.axes):
1376 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1382 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1377
1383
1378
1384
1379 if ax.firsttime:
1385 if ax.firsttime:
1380 #self.xmin = min(self.z)
1386 #self.xmin = min(self.z)
1381 #self.xmax = max(self.z)
1387 #self.xmax = max(self.z)
1382 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1388 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1383 else:
1389 else:
1384 ax.plt_r.set_data(self.z[i], self.y)
1390 ax.plt_r.set_data(self.z[i], self.y)
1385
1391
1386
1392
1387
1393
1388 class GeneralProfilePlot(Plot):
1394 class GeneralProfilePlot(Plot):
1389 '''
1395 '''
1390 Plot for RTI data
1396 Plot for RTI data
1391 '''
1397 '''
1392
1398
1393 CODE = 'general_profilePlot'
1399 CODE = 'general_profilePlot'
1394
1400
1395 plot_type = 'scatter'
1401 plot_type = 'scatter'
1396 titles = None
1402 titles = None
1397 channelList = []
1403 channelList = []
1398 elevationList = []
1404 elevationList = []
1399 azimuthList = []
1405 azimuthList = []
1400 last_noise = None
1406 last_noise = None
1401
1407
1402 def setup(self):
1408 def setup(self):
1403 self.xaxis = 'Range (Km)'
1409 self.xaxis = 'Range (Km)'
1404 self.nplots = len(self.data.channels)
1410 self.nplots = len(self.data.channels)
1405 self.nrows = int(numpy.ceil(self.nplots/2))
1411 self.nrows = int(numpy.ceil(self.nplots/2))
1406 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1412 self.ncols = int(numpy.ceil(self.nplots/self.nrows))
1407 self.ylabel = 'Intensity [dB]'
1413 self.ylabel = 'Intensity [dB]'
1408 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1414 self.titles = ['Channel '+str(self.data.channels[i])+" " for i in self.data.channels]
1409 self.colorbar = False
1415 self.colorbar = False
1410 self.width = 6
1416 self.width = 6
1411 self.height = 4
1417 self.height = 4
1412
1418
1413 def update_list(self,dataOut):
1419 def update_list(self,dataOut):
1414 if len(self.channelList) == 0:
1420 if len(self.channelList) == 0:
1415 self.channelList = dataOut.channelList
1421 self.channelList = dataOut.channelList
1416 if len(self.elevationList) == 0:
1422 if len(self.elevationList) == 0:
1417 self.elevationList = dataOut.elevationList
1423 self.elevationList = dataOut.elevationList
1418 if len(self.azimuthList) == 0:
1424 if len(self.azimuthList) == 0:
1419 self.azimuthList = dataOut.azimuthList
1425 self.azimuthList = dataOut.azimuthList
1420
1426
1421 def update(self, dataOut):
1427 def update(self, dataOut):
1422 if len(self.channelList) == 0:
1428 if len(self.channelList) == 0:
1423 self.update_list(dataOut)
1429 self.update_list(dataOut)
1424
1430
1425 data = {}
1431 data = {}
1426 meta = {}
1432 meta = {}
1427
1433
1428 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1434 norm = dataOut.nProfiles * dataOut.max_nIncohInt * dataOut.nCohInt * dataOut.windowOfFilter
1429 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1435 n0 = 10*numpy.log10(dataOut.getNoise()/norm)
1430 data['noise'] = n0
1436 data['noise'] = n0
1431
1437
1432 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1438 noise = numpy.repeat(n0,dataOut.nHeights).reshape(dataOut.nChannels,dataOut.nHeights)
1433 noiseless_data = dataOut.getPower() - noise
1439 noiseless_data = dataOut.getPower() - noise
1434
1440
1435 data['noiseless_rtiLine'] = noiseless_data
1441 data['noiseless_rtiLine'] = noiseless_data
1436
1442
1437 #print(noiseless_data.shape, self.name)
1443 #print(noiseless_data.shape, self.name)
1438 data['time'] = dataOut.utctime
1444 data['time'] = dataOut.utctime
1439
1445
1440 return data, meta
1446 return data, meta
1441
1447
1442 def plot(self):
1448 def plot(self):
1443
1449
1444 self.x = self.data.times
1450 self.x = self.data.times
1445 self.y = self.data.yrange
1451 self.y = self.data.yrange
1446 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1452 #print(self.data['noiseless_rtiLine'].shape, self.y.shape, self.name)
1447 #ts = self.data['time'][0].squeeze()
1453 #ts = self.data['time'][0].squeeze()
1448 if len(self.data['noiseless_rtiLine'])>2 :
1454 if len(self.data['noiseless_rtiLine'])>2 :
1449 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1455 self.z = self.data['noiseless_rtiLine'][:, -1,:]
1450 else:
1456 else:
1451 self.z = self.data['noiseless_rtiLine']
1457 self.z = self.data['noiseless_rtiLine']
1452 #print(self.z.shape, self.y.shape, ts)
1458 #print(self.z.shape, self.y.shape, ts)
1453 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1459 #thisDatetime = datetime.datetime.utcfromtimestamp(ts)
1454
1460
1455 for i,ax in enumerate(self.axes):
1461 for i,ax in enumerate(self.axes):
1456 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1462 #self.titles[i] = "Channel {} {}".format(i, thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1457
1463
1458
1464
1459 if ax.firsttime:
1465 if ax.firsttime:
1460 #self.xmin = min(self.z)
1466 #self.xmin = min(self.z)
1461 #self.xmax = max(self.z)
1467 #self.xmax = max(self.z)
1462 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1468 ax.plt_r = ax.plot(self.z[i], self.y)[0]
1463 else:
1469 else:
1464 ax.plt_r.set_data(self.z[i], self.y) No newline at end of file
1470 ax.plt_r.set_data(self.z[i], self.y)
General Comments 0
You need to be logged in to leave comments. Login now