##// END OF EJS Templates
add NoisePlot
jespinoza -
r907:4034368d1421
parent child
Show More
@@ -1,377 +1,427
1
1
2 import os
2 import os
3 import zmq
3 import zmq
4 import time
4 import time
5 import numpy
5 import numpy
6 import datetime
6 import datetime
7 import numpy as np
7 import numpy as np
8 import matplotlib.pyplot as plt
8 import matplotlib.pyplot as plt
9 from mpl_toolkits.axes_grid1 import make_axes_locatable
9 from mpl_toolkits.axes_grid1 import make_axes_locatable
10 from matplotlib.ticker import FuncFormatter, LinearLocator
10 from matplotlib.ticker import FuncFormatter, LinearLocator
11 from multiprocessing import Process
11 from multiprocessing import Process
12
12
13 from schainpy.model.proc.jroproc_base import Operation
13 from schainpy.model.proc.jroproc_base import Operation
14
14
15 #plt.ion()
15 #plt.ion()
16
16
17 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M'))
17 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M'))
18
18
19 d1970 = datetime.datetime(1970,1,1)
19 d1970 = datetime.datetime(1970,1,1)
20
20
21 class PlotData(Operation, Process):
21 class PlotData(Operation, Process):
22
22
23 CODE = 'Figure'
23 CODE = 'Figure'
24 colormap = 'jet'
24 colormap = 'jet'
25 CONFLATE = True
25 CONFLATE = True
26 __MAXNUMX = 80
26 __MAXNUMX = 80
27 __MAXNUMY = 80
27 __MAXNUMY = 80
28 __missing = 1E30
28 __missing = 1E30
29
29
30 def __init__(self, **kwargs):
30 def __init__(self, **kwargs):
31
31
32 Operation.__init__(self, **kwargs)
32 Operation.__init__(self, **kwargs)
33 Process.__init__(self)
33 Process.__init__(self)
34 self.mp = False
34 self.mp = False
35 self.dataOut = None
35 self.dataOut = None
36 self.isConfig = False
36 self.isConfig = False
37 self.figure = None
37 self.figure = None
38 self.axes = []
38 self.axes = []
39 self.localtime = kwargs.pop('localtime', True)
39 self.localtime = kwargs.pop('localtime', True)
40 self.show = kwargs.get('show', True)
40 self.show = kwargs.get('show', True)
41 self.save = kwargs.get('save', False)
41 self.save = kwargs.get('save', False)
42 self.colormap = kwargs.get('colormap', self.colormap)
42 self.colormap = kwargs.get('colormap', self.colormap)
43 self.showprofile = kwargs.get('showprofile', False)
43 self.showprofile = kwargs.get('showprofile', True)
44 self.title = kwargs.get('wintitle', '')
44 self.title = kwargs.get('wintitle', '')
45 self.xaxis = kwargs.get('xaxis', 'time')
45 self.xaxis = kwargs.get('xaxis', 'time')
46 self.zmin = kwargs.get('zmin', None)
46 self.zmin = kwargs.get('zmin', None)
47 self.zmax = kwargs.get('zmax', None)
47 self.zmax = kwargs.get('zmax', None)
48 self.xmin = kwargs.get('xmin', None)
48 self.xmin = kwargs.get('xmin', None)
49 self.xmax = kwargs.get('xmax', None)
49 self.xmax = kwargs.get('xmax', None)
50 self.xrange = kwargs.get('xrange', 24)
50 self.xrange = kwargs.get('xrange', 24)
51 self.ymin = kwargs.get('ymin', None)
51 self.ymin = kwargs.get('ymin', None)
52 self.ymax = kwargs.get('ymax', None)
52 self.ymax = kwargs.get('ymax', None)
53 self.throttle_value = 1
53 self.throttle_value = 1
54 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
54 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
55
55
56 if x_buffer.shape[0] < 2:
56 if x_buffer.shape[0] < 2:
57 return x_buffer, y_buffer, z_buffer
57 return x_buffer, y_buffer, z_buffer
58
58
59 deltas = x_buffer[1:] - x_buffer[0:-1]
59 deltas = x_buffer[1:] - x_buffer[0:-1]
60 x_median = np.median(deltas)
60 x_median = np.median(deltas)
61
61
62 index = np.where(deltas > 5*x_median)
62 index = np.where(deltas > 5*x_median)
63
63
64 if len(index[0]) != 0:
64 if len(index[0]) != 0:
65 z_buffer[::, index[0], ::] = self.__missing
65 z_buffer[::, index[0], ::] = self.__missing
66 z_buffer = np.ma.masked_inside(z_buffer,
66 z_buffer = np.ma.masked_inside(z_buffer,
67 0.99*self.__missing,
67 0.99*self.__missing,
68 1.01*self.__missing)
68 1.01*self.__missing)
69
69
70 return x_buffer, y_buffer, z_buffer
70 return x_buffer, y_buffer, z_buffer
71
71
72 def decimate(self):
72 def decimate(self):
73
73
74 # dx = int(len(self.x)/self.__MAXNUMX) + 1
74 # dx = int(len(self.x)/self.__MAXNUMX) + 1
75 dy = int(len(self.y)/self.__MAXNUMY) + 1
75 dy = int(len(self.y)/self.__MAXNUMY) + 1
76
76
77 # x = self.x[::dx]
77 # x = self.x[::dx]
78 x = self.x
78 x = self.x
79 y = self.y[::dy]
79 y = self.y[::dy]
80 z = self.z[::, ::, ::dy]
80 z = self.z[::, ::, ::dy]
81
81
82 return x, y, z
82 return x, y, z
83
83
84 def __plot(self):
84 def __plot(self):
85
85
86 print 'plotting...{}'.format(self.CODE)
86 print 'plotting...{}'.format(self.CODE)
87
87
88 self.plot()
88 self.plot()
89 self.figure.suptitle('{} {} - Date:{}'.format(self.title, self.CODE.upper(),
89 self.figure.suptitle('{} {} - Date:{}'.format(self.title, self.CODE.upper(),
90 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')))
90 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')))
91
91
92 if self.save:
92 if self.save:
93 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
93 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
94 datetime.datetime.utcfromtimestamp(self.times[0]).strftime('%y%m%d_%H%M%S')))
94 datetime.datetime.utcfromtimestamp(self.times[0]).strftime('%y%m%d_%H%M%S')))
95 print 'Saving figure: {}'.format(figname)
95 print 'Saving figure: {}'.format(figname)
96 self.figure.savefig(figname)
96 self.figure.savefig(figname)
97
97
98 self.figure.canvas.draw()
98 self.figure.canvas.draw()
99
99
100 def plot(self):
100 def plot(self):
101
101
102 print 'plotting...{}'.format(self.CODE.upper())
102 print 'plotting...{}'.format(self.CODE.upper())
103 return
103 return
104
104
105 def run(self):
105 def run(self):
106
106
107 print '[Starting] {}'.format(self.name)
107 print '[Starting] {}'.format(self.name)
108 context = zmq.Context()
108 context = zmq.Context()
109 receiver = context.socket(zmq.SUB)
109 receiver = context.socket(zmq.SUB)
110 receiver.setsockopt(zmq.SUBSCRIBE, '')
110 receiver.setsockopt(zmq.SUBSCRIBE, '')
111 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
111 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
112 receiver.connect("ipc:///tmp/zmq.plots")
112 receiver.connect("ipc:///tmp/zmq.plots")
113
113
114 while True:
114 while True:
115 try:
115 try:
116 #if True:
116 #if True:
117 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
117 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
118 self.dataOut = self.data['dataOut']
118 self.dataOut = self.data['dataOut']
119 self.times = self.data['times']
119 self.times = self.data['times']
120 self.times.sort()
120 self.times.sort()
121 self.throttle_value = self.data['throttle']
121 self.throttle_value = self.data['throttle']
122 self.min_time = self.times[0]
122 self.min_time = self.times[0]
123 self.max_time = self.times[-1]
123 self.max_time = self.times[-1]
124
124
125 if self.isConfig is False:
125 if self.isConfig is False:
126 self.setup()
126 self.setup()
127 self.isConfig = True
127 self.isConfig = True
128 self.__plot()
128 self.__plot()
129
129
130 if self.data['ENDED'] is True:
130 if self.data['ENDED'] is True:
131 # self.__plot()
131 # self.__plot()
132 self.isConfig = False
132 self.isConfig = False
133
133
134 except zmq.Again as e:
134 except zmq.Again as e:
135 print 'Waiting for data...'
135 print 'Waiting for data...'
136 plt.pause(self.throttle_value)
136 plt.pause(self.throttle_value)
137 # time.sleep(3)
137 # time.sleep(3)
138
138
139 def close(self):
139 def close(self):
140 if self.dataOut:
140 if self.dataOut:
141 self._plot()
141 self._plot()
142
142
143
143
144 class PlotSpectraData(PlotData):
144 class PlotSpectraData(PlotData):
145
145
146 CODE = 'spc'
146 CODE = 'spc'
147 colormap = 'jro'
147 colormap = 'jro'
148 CONFLATE = False
148 CONFLATE = False
149 def setup(self):
149 def setup(self):
150
150
151 ncolspan = 1
151 ncolspan = 1
152 colspan = 1
152 colspan = 1
153 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
153 self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9)
154 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
154 self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9)
155 self.width = 3.6*self.ncols
155 self.width = 3.6*self.ncols
156 self.height = 3.2*self.nrows
156 self.height = 3.2*self.nrows
157 if self.showprofile:
157 if self.showprofile:
158 ncolspan = 3
158 ncolspan = 3
159 colspan = 2
159 colspan = 2
160 self.width += 1.2*self.ncols
160 self.width += 1.2*self.ncols
161
161
162 self.ylabel = 'Range [Km]'
162 self.ylabel = 'Range [Km]'
163 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
163 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
164
164
165 if self.figure is None:
165 if self.figure is None:
166 self.figure = plt.figure(figsize=(self.width, self.height),
166 self.figure = plt.figure(figsize=(self.width, self.height),
167 edgecolor='k',
167 edgecolor='k',
168 facecolor='w')
168 facecolor='w')
169 else:
169 else:
170 self.figure.clf()
170 self.figure.clf()
171
171
172 n = 0
172 n = 0
173 for y in range(self.nrows):
173 for y in range(self.nrows):
174 for x in range(self.ncols):
174 for x in range(self.ncols):
175 if n >= self.dataOut.nChannels:
175 if n >= self.dataOut.nChannels:
176 break
176 break
177 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
177 ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan)
178 if self.showprofile:
178 if self.showprofile:
179 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
179 ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1)
180
180
181 ax.firsttime = True
181 ax.firsttime = True
182 self.axes.append(ax)
182 self.axes.append(ax)
183 n += 1
183 n += 1
184
184
185 self.figure.subplots_adjust(wspace=0.9, hspace=0.5)
185 self.figure.subplots_adjust(left=0.1, right=0.95, bottom=0.15, top=0.85, wspace=0.9, hspace=0.5)
186 self.figure.show()
186 self.figure.show()
187
187
188 def plot(self):
188 def plot(self):
189
189
190 if self.xaxis == "frequency":
190 if self.xaxis == "frequency":
191 x = self.dataOut.getFreqRange(1)/1000.
191 x = self.dataOut.getFreqRange(1)/1000.
192 xlabel = "Frequency (kHz)"
192 xlabel = "Frequency (kHz)"
193 elif self.xaxis == "time":
193 elif self.xaxis == "time":
194 x = self.dataOut.getAcfRange(1)
194 x = self.dataOut.getAcfRange(1)
195 xlabel = "Time (ms)"
195 xlabel = "Time (ms)"
196 else:
196 else:
197 x = self.dataOut.getVelRange(1)
197 x = self.dataOut.getVelRange(1)
198 xlabel = "Velocity (m/s)"
198 xlabel = "Velocity (m/s)"
199
199
200 y = self.dataOut.getHeiRange()
200 y = self.dataOut.getHeiRange()
201 z = self.data[self.CODE]
201 z = self.data[self.CODE]
202
202
203 for n, ax in enumerate(self.axes):
203 for n, ax in enumerate(self.axes):
204
204
205 if ax.firsttime:
205 if ax.firsttime:
206 self.xmax = self.xmax if self.xmax else np.nanmax(x)
206 self.xmax = self.xmax if self.xmax else np.nanmax(x)
207 self.xmin = self.xmin if self.xmin else -self.xmax
207 self.xmin = self.xmin if self.xmin else -self.xmax
208 self.ymin = self.ymin if self.ymin else np.nanmin(y)
208 self.ymin = self.ymin if self.ymin else np.nanmin(y)
209 self.ymax = self.ymax if self.ymax else np.nanmax(y)
209 self.ymax = self.ymax if self.ymax else np.nanmax(y)
210 self.zmin = self.zmin if self.zmin else np.nanmin(z)
210 self.zmin = self.zmin if self.zmin else np.nanmin(z)
211 self.zmax = self.zmax if self.zmax else np.nanmax(z)
211 self.zmax = self.zmax if self.zmax else np.nanmax(z)
212 ax.plot = ax.pcolormesh(x, y, z[n].T,
212 ax.plot = ax.pcolormesh(x, y, z[n].T,
213 vmin=self.zmin,
213 vmin=self.zmin,
214 vmax=self.zmax,
214 vmax=self.zmax,
215 cmap=plt.get_cmap(self.colormap)
215 cmap=plt.get_cmap(self.colormap)
216 )
216 )
217 divider = make_axes_locatable(ax)
217 divider = make_axes_locatable(ax)
218 cax = divider.new_horizontal(size='3%', pad=0.05)
218 cax = divider.new_horizontal(size='3%', pad=0.05)
219 self.figure.add_axes(cax)
219 self.figure.add_axes(cax)
220 plt.colorbar(ax.plot, cax)
220 plt.colorbar(ax.plot, cax)
221
221
222 ax.set_xlim(self.xmin, self.xmax)
222 ax.set_xlim(self.xmin, self.xmax)
223 ax.set_ylim(self.ymin, self.ymax)
223 ax.set_ylim(self.ymin, self.ymax)
224
224
225 ax.xaxis.set_major_locator(LinearLocator(5))
225 ax.xaxis.set_major_locator(LinearLocator(5))
226 #ax.yaxis.set_major_locator(LinearLocator(4))
226 #ax.yaxis.set_major_locator(LinearLocator(4))
227
227
228 ax.set_ylabel(self.ylabel)
228 ax.set_ylabel(self.ylabel)
229 ax.set_xlabel(xlabel)
229 ax.set_xlabel(xlabel)
230
230
231 ax.firsttime = False
231 ax.firsttime = False
232
232
233 if self.showprofile:
233 if self.showprofile:
234 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
234 ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0]
235 ax.ax_profile.set_xlim(self.zmin, self.zmax)
235 ax.ax_profile.set_xlim(self.zmin, self.zmax)
236 ax.ax_profile.set_ylim(self.ymin, self.ymax)
236 ax.ax_profile.set_ylim(self.ymin, self.ymax)
237 ax.ax_profile.set_xlabel('dB')
237 ax.ax_profile.set_xlabel('dB')
238 ax.ax_profile.grid(b=True, axis='x')
238 ax.ax_profile.grid(b=True, axis='x')
239 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
239 ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y,
240 color="k", linestyle="dashed", lw=2)[0]
240 color="k", linestyle="dashed", lw=2)[0]
241 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
241 [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()]
242 else:
242 else:
243 ax.plot.set_array(z[n].T.ravel())
243 ax.plot.set_array(z[n].T.ravel())
244 if self.showprofile:
244 if self.showprofile:
245 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
245 ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y)
246 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
246 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y)
247
247
248 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
248 ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]),
249 size=8)
249 size=8)
250
250
251 class PlotRTIData(PlotData):
251 class PlotRTIData(PlotData):
252
252
253 CODE = 'rti'
253 CODE = 'rti'
254 colormap = 'jro'
254 colormap = 'jro'
255
255
256 def setup(self):
256 def setup(self):
257 self.ncols = 1
257 self.ncols = 1
258 self.nrows = self.dataOut.nChannels
258 self.nrows = self.dataOut.nChannels
259 self.width = 10
259 self.width = 10
260 self.height = 2.2*self.nrows
260 self.height = 2.2*self.nrows
261 if self.nrows==1:
262 self.height += 1
261 self.ylabel = 'Range [Km]'
263 self.ylabel = 'Range [Km]'
262 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
264 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
263
265
264 if self.figure is None:
266 if self.figure is None:
265 self.figure = plt.figure(figsize=(self.width, self.height),
267 self.figure = plt.figure(figsize=(self.width, self.height),
266 edgecolor='k',
268 edgecolor='k',
267 facecolor='w')
269 facecolor='w')
268 else:
270 else:
269 self.figure.clf()
271 self.figure.clf()
270 self.axes = []
272 self.axes = []
271
273
272 for n in range(self.nrows):
274 for n in range(self.nrows):
273 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
275 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
274 ax.firsttime = True
276 ax.firsttime = True
275 self.axes.append(ax)
277 self.axes.append(ax)
276 self.figure.subplots_adjust(hspace=0.5)
278 self.figure.subplots_adjust(hspace=0.5)
277 self.figure.show()
279 self.figure.show()
278
280
279 def plot(self):
281 def plot(self):
280
282
281 self.x = np.array(self.times)
283 self.x = np.array(self.times)
282 self.y = self.dataOut.getHeiRange()
284 self.y = self.dataOut.getHeiRange()
283 self.z = []
285 self.z = []
284
286
285 for ch in range(self.nrows):
287 for ch in range(self.nrows):
286 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
288 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
287
289
288 self.z = np.array(self.z)
290 self.z = np.array(self.z)
289 for n, ax in enumerate(self.axes):
291 for n, ax in enumerate(self.axes):
290
292
291 x, y, z = self.fill_gaps(*self.decimate())
293 x, y, z = self.fill_gaps(*self.decimate())
292 xmin = self.min_time
294 xmin = self.min_time
293 xmax = xmin+self.xrange*60*60
295 xmax = xmin+self.xrange*60*60
294 if ax.firsttime:
296 if ax.firsttime:
295 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
297 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
296 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
298 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
297 self.zmin = self.zmin if self.zmin else np.nanmin(self.z)
299 self.zmin = self.zmin if self.zmin else np.nanmin(self.z)
298 self.zmax = self.zmax if self.zmax else np.nanmax(self.z)
300 self.zmax = self.zmax if self.zmax else np.nanmax(self.z)
299 plot = ax.pcolormesh(x, y, z[n].T,
301 plot = ax.pcolormesh(x, y, z[n].T,
300 vmin=self.zmin,
302 vmin=self.zmin,
301 vmax=self.zmax,
303 vmax=self.zmax,
302 cmap=plt.get_cmap(self.colormap)
304 cmap=plt.get_cmap(self.colormap)
303 )
305 )
304 divider = make_axes_locatable(ax)
306 divider = make_axes_locatable(ax)
305 cax = divider.new_horizontal(size='2%', pad=0.05)
307 cax = divider.new_horizontal(size='2%', pad=0.05)
306 self.figure.add_axes(cax)
308 self.figure.add_axes(cax)
307 plt.colorbar(plot, cax)
309 plt.colorbar(plot, cax)
308 ax.set_ylim(self.ymin, self.ymax)
310 ax.set_ylim(self.ymin, self.ymax)
309 if self.xaxis == 'time':
311 if self.xaxis == 'time':
310 ax.xaxis.set_major_formatter(FuncFormatter(func))
312 ax.xaxis.set_major_formatter(FuncFormatter(func))
311 ax.xaxis.set_major_locator(LinearLocator(6))
313 ax.xaxis.set_major_locator(LinearLocator(6))
312
314
313 # ax.yaxis.set_major_locator(LinearLocator(4))
315 # ax.yaxis.set_major_locator(LinearLocator(4))
314
316
315 ax.set_ylabel(self.ylabel)
317 ax.set_ylabel(self.ylabel)
316
318
317 # if self.xmin is None:
319 # if self.xmin is None:
318 # xmin = self.min_time
320 # xmin = self.min_time
319 # else:
321 # else:
320 # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
322 # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
321 # datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
323 # datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
322
324
323 ax.set_xlim(xmin, xmax)
325 ax.set_xlim(xmin, xmax)
324 ax.firsttime = False
326 ax.firsttime = False
325 else:
327 else:
326 ax.collections.remove(ax.collections[0])
328 ax.collections.remove(ax.collections[0])
327 ax.set_xlim(xmin, xmax)
329 ax.set_xlim(xmin, xmax)
328 plot = ax.pcolormesh(x, y, z[n].T,
330 plot = ax.pcolormesh(x, y, z[n].T,
329 vmin=self.zmin,
331 vmin=self.zmin,
330 vmax=self.zmax,
332 vmax=self.zmax,
331 cmap=plt.get_cmap(self.colormap)
333 cmap=plt.get_cmap(self.colormap)
332 )
334 )
333 ax.set_title('{} {}'.format(self.titles[n],
335 ax.set_title('{} {}'.format(self.titles[n],
334 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
336 datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
335 size=8)
337 size=8)
336
338
337
339
338 class PlotCOHData(PlotRTIData):
340 class PlotCOHData(PlotRTIData):
339
341
340 CODE = 'coh'
342 CODE = 'coh'
341
343
342 def setup(self):
344 def setup(self):
343
345
344 self.ncols = 1
346 self.ncols = 1
345 self.nrows = self.dataOut.nPairs
347 self.nrows = self.dataOut.nPairs
346 self.width = 10
348 self.width = 10
347 self.height = 2.2*self.nrows
349 self.height = 2.2*self.nrows
350 if self.nrows==1:
351 self.height += 1
348 self.ylabel = 'Range [Km]'
352 self.ylabel = 'Range [Km]'
349 self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList]
353 self.titles = ['Channels {}'.format(x) for x in self.dataOut.pairsList]
350
354
351 if self.figure is None:
355 if self.figure is None:
352 self.figure = plt.figure(figsize=(self.width, self.height),
356 self.figure = plt.figure(figsize=(self.width, self.height),
353 edgecolor='k',
357 edgecolor='k',
354 facecolor='w')
358 facecolor='w')
355 else:
359 else:
356 self.figure.clf()
360 self.figure.clf()
361 self.axes = []
357
362
358 for n in range(self.nrows):
363 for n in range(self.nrows):
359 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
364 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
360 ax.firsttime = True
365 ax.firsttime = True
361 self.axes.append(ax)
366 self.axes.append(ax)
362
367
363 self.figure.subplots_adjust(hspace=0.5)
368 self.figure.subplots_adjust(hspace=0.5)
364 self.figure.show()
369 self.figure.show()
365
370
366 class PlotSNRData(PlotRTIData):
371 class PlotNoiseData(PlotData):
372 CODE = 'noise'
373
374 def setup(self):
375
376 self.ncols = 1
377 self.nrows = 1
378 self.width = 10
379 self.height = 3.2
380 self.ylabel = 'Intensity [dB]'
381 self.titles = ['Noise']
367
382
383 if self.figure is None:
384 self.figure = plt.figure(figsize=(self.width, self.height),
385 edgecolor='k',
386 facecolor='w')
387 else:
388 self.figure.clf()
389 self.axes = []
390
391 self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1)
392 self.ax.firsttime = True
393
394 self.figure.show()
395
396 def plot(self):
397
398 x = self.times
399 xmin = self.min_time
400 xmax = xmin+self.xrange*60*60
401 if self.ax.firsttime:
402 for ch in self.dataOut.channelList:
403 y = [self.data[self.CODE][t][ch] for t in self.times]
404 self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch))
405 self.ax.firsttime = False
406 self.ax.xaxis.set_major_formatter(FuncFormatter(func))
407 self.ax.xaxis.set_major_locator(LinearLocator(6))
408 self.ax.set_ylabel(self.ylabel)
409 plt.legend()
410 else:
411 for ch in self.dataOut.channelList:
412 y = [self.data[self.CODE][t][ch] for t in self.times]
413 self.ax.lines[ch].set_data(x, y)
414
415 self.ax.set_xlim(xmin, xmax)
416 self.ax.set_ylim(min(y)-5, max(y)+5)
417
418 class PlotSNRData(PlotRTIData):
368 CODE = 'snr'
419 CODE = 'snr'
369
420
370 class PlotDOPData(PlotRTIData):
421 class PlotDOPData(PlotRTIData):
371 CODE = 'dop'
422 CODE = 'dop'
372 colormap = 'jet'
423 colormap = 'jet'
373
424
374 class PlotPHASEData(PlotCOHData):
425 class PlotPHASEData(PlotCOHData):
375
376 CODE = 'phase'
426 CODE = 'phase'
377 colormap = 'seismic'
427 colormap = 'seismic'
General Comments 0
You need to be logged in to leave comments. Login now