@@ -1,1085 +1,1088 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import time |
|
3 | import time | |
4 | import glob |
|
4 | import glob | |
5 | import datetime |
|
5 | import datetime | |
6 | from multiprocessing import Process |
|
6 | from multiprocessing import Process | |
7 |
|
7 | |||
8 | import zmq |
|
8 | import zmq | |
9 | import numpy |
|
9 | import numpy | |
10 | import matplotlib |
|
10 | import matplotlib | |
11 | import matplotlib.pyplot as plt |
|
11 | import matplotlib.pyplot as plt | |
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
14 |
|
14 | |||
15 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
16 | from schainpy.utils import log |
|
16 | from schainpy.utils import log | |
17 |
|
17 | |||
18 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] |
|
18 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
19 | blu_values = matplotlib.pyplot.get_cmap( |
|
19 | blu_values = matplotlib.pyplot.get_cmap( | |
20 | 'seismic_r', 20)(numpy.arange(20))[10:15] |
|
20 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
21 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
21 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
22 | 'jro', numpy.vstack((blu_values, jet_values))) |
|
22 | 'jro', numpy.vstack((blu_values, jet_values))) | |
23 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
23 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
24 |
|
24 | |||
25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm', 'spectral')] |
|
25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm', 'spectral')] | |
26 |
|
26 | |||
|
27 | def ll2xy(lat1, lon1, lat2, lon2): | |||
|
28 | ||||
|
29 | p = 0.017453292519943295 | |||
|
30 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |||
|
31 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |||
|
32 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)*numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |||
|
33 | theta = -theta + numpy.pi/2 | |||
|
34 | return r*numpy.cos(theta), r*numpy.sin(theta) | |||
27 |
|
35 | |||
28 | def figpause(interval): |
|
36 | def figpause(interval): | |
29 | backend = plt.rcParams['backend'] |
|
37 | backend = plt.rcParams['backend'] | |
30 | if backend in matplotlib.rcsetup.interactive_bk: |
|
38 | if backend in matplotlib.rcsetup.interactive_bk: | |
31 | figManager = matplotlib._pylab_helpers.Gcf.get_active() |
|
39 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
32 | if figManager is not None: |
|
40 | if figManager is not None: | |
33 | canvas = figManager.canvas |
|
41 | canvas = figManager.canvas | |
34 | if canvas.figure.stale: |
|
42 | if canvas.figure.stale: | |
35 | canvas.draw() |
|
43 | canvas.draw() | |
36 | canvas.start_event_loop(interval) |
|
44 | canvas.start_event_loop(interval) | |
37 | return |
|
45 | return | |
38 |
|
46 | |||
39 |
|
47 | |||
40 | class PlotData(Operation, Process): |
|
48 | class PlotData(Operation, Process): | |
41 | ''' |
|
49 | ''' | |
42 | Base class for Schain plotting operations |
|
50 | Base class for Schain plotting operations | |
43 | ''' |
|
51 | ''' | |
44 |
|
52 | |||
45 | CODE = 'Figure' |
|
53 | CODE = 'Figure' | |
46 | colormap = 'jro' |
|
54 | colormap = 'jro' | |
47 | bgcolor = 'white' |
|
55 | bgcolor = 'white' | |
48 | CONFLATE = False |
|
56 | CONFLATE = False | |
49 | __missing = 1E30 |
|
57 | __missing = 1E30 | |
50 |
|
58 | |||
51 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', |
|
59 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', | |
52 | 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title', |
|
60 | 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title', | |
53 | 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', |
|
61 | 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', | |
54 | 'showprofile', 'decimation', 'ftp'] |
|
62 | 'showprofile', 'decimation', 'ftp'] | |
55 |
|
63 | |||
56 | def __init__(self, **kwargs): |
|
64 | def __init__(self, **kwargs): | |
57 |
|
65 | |||
58 | Operation.__init__(self, plot=True, **kwargs) |
|
66 | Operation.__init__(self, plot=True, **kwargs) | |
59 | Process.__init__(self) |
|
67 | Process.__init__(self) | |
60 |
|
68 | |||
61 | self.kwargs['code'] = self.CODE |
|
69 | self.kwargs['code'] = self.CODE | |
62 | self.mp = False |
|
70 | self.mp = False | |
63 | self.data = None |
|
71 | self.data = None | |
64 | self.isConfig = False |
|
72 | self.isConfig = False | |
65 | self.figures = [] |
|
73 | self.figures = [] | |
66 | self.axes = [] |
|
74 | self.axes = [] | |
67 | self.cb_axes = [] |
|
75 | self.cb_axes = [] | |
68 | self.localtime = kwargs.pop('localtime', True) |
|
76 | self.localtime = kwargs.pop('localtime', True) | |
69 | self.show = kwargs.get('show', True) |
|
77 | self.show = kwargs.get('show', True) | |
70 | self.save = kwargs.get('save', False) |
|
78 | self.save = kwargs.get('save', False) | |
71 | self.ftp = kwargs.get('ftp', False) |
|
79 | self.ftp = kwargs.get('ftp', False) | |
72 | self.colormap = kwargs.get('colormap', self.colormap) |
|
80 | self.colormap = kwargs.get('colormap', self.colormap) | |
73 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
81 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
74 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
82 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
75 | self.colormaps = kwargs.get('colormaps', None) |
|
83 | self.colormaps = kwargs.get('colormaps', None) | |
76 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) |
|
84 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
77 | self.showprofile = kwargs.get('showprofile', False) |
|
85 | self.showprofile = kwargs.get('showprofile', False) | |
78 | self.title = kwargs.get('wintitle', self.CODE.upper()) |
|
86 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
79 | self.cb_label = kwargs.get('cb_label', None) |
|
87 | self.cb_label = kwargs.get('cb_label', None) | |
80 | self.cb_labels = kwargs.get('cb_labels', None) |
|
88 | self.cb_labels = kwargs.get('cb_labels', None) | |
81 | self.labels = kwargs.get('labels', None) |
|
89 | self.labels = kwargs.get('labels', None) | |
82 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
90 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
83 | self.zmin = kwargs.get('zmin', None) |
|
91 | self.zmin = kwargs.get('zmin', None) | |
84 | self.zmax = kwargs.get('zmax', None) |
|
92 | self.zmax = kwargs.get('zmax', None) | |
85 | self.zlimits = kwargs.get('zlimits', None) |
|
93 | self.zlimits = kwargs.get('zlimits', None) | |
86 | self.xmin = kwargs.get('xmin', None) |
|
94 | self.xmin = kwargs.get('xmin', None) | |
87 | self.xmax = kwargs.get('xmax', None) |
|
95 | self.xmax = kwargs.get('xmax', None) | |
88 | self.xrange = kwargs.get('xrange', 24) |
|
96 | self.xrange = kwargs.get('xrange', 24) | |
89 | self.xscale = kwargs.get('xscale', None) |
|
97 | self.xscale = kwargs.get('xscale', None) | |
90 | self.ymin = kwargs.get('ymin', None) |
|
98 | self.ymin = kwargs.get('ymin', None) | |
91 | self.ymax = kwargs.get('ymax', None) |
|
99 | self.ymax = kwargs.get('ymax', None) | |
92 | self.yscale = kwargs.get('yscale', None) |
|
100 | self.yscale = kwargs.get('yscale', None) | |
93 | self.xlabel = kwargs.get('xlabel', None) |
|
101 | self.xlabel = kwargs.get('xlabel', None) | |
94 | self.decimation = kwargs.get('decimation', None) |
|
102 | self.decimation = kwargs.get('decimation', None) | |
95 | self.showSNR = kwargs.get('showSNR', False) |
|
103 | self.showSNR = kwargs.get('showSNR', False) | |
96 | self.oneFigure = kwargs.get('oneFigure', True) |
|
104 | self.oneFigure = kwargs.get('oneFigure', True) | |
97 | self.width = kwargs.get('width', None) |
|
105 | self.width = kwargs.get('width', None) | |
98 | self.height = kwargs.get('height', None) |
|
106 | self.height = kwargs.get('height', None) | |
99 | self.colorbar = kwargs.get('colorbar', True) |
|
107 | self.colorbar = kwargs.get('colorbar', True) | |
100 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) |
|
108 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
101 | self.channels = kwargs.get('channels', None) |
|
109 | self.channels = kwargs.get('channels', None) | |
102 | self.titles = kwargs.get('titles', []) |
|
110 | self.titles = kwargs.get('titles', []) | |
103 | self.polar = False |
|
111 | self.polar = False | |
104 |
|
112 | |||
105 | def __fmtTime(self, x, pos): |
|
113 | def __fmtTime(self, x, pos): | |
106 | ''' |
|
114 | ''' | |
107 | ''' |
|
115 | ''' | |
108 |
|
116 | |||
109 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) |
|
117 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
110 |
|
118 | |||
111 | def __setup(self): |
|
119 | def __setup(self): | |
112 | ''' |
|
120 | ''' | |
113 | Common setup for all figures, here figures and axes are created |
|
121 | Common setup for all figures, here figures and axes are created | |
114 | ''' |
|
122 | ''' | |
115 |
|
123 | |||
116 | if self.CODE not in self.data: |
|
124 | if self.CODE not in self.data: | |
117 | raise ValueError(log.error('Missing data for {}'.format(self.CODE), |
|
125 | raise ValueError(log.error('Missing data for {}'.format(self.CODE), | |
118 | self.name)) |
|
126 | self.name)) | |
119 |
|
127 | |||
120 | self.setup() |
|
128 | self.setup() | |
121 |
|
129 | |||
122 | self.time_label = 'LT' if self.localtime else 'UTC' |
|
130 | self.time_label = 'LT' if self.localtime else 'UTC' | |
123 | if self.data.localtime: |
|
131 | if self.data.localtime: | |
124 | self.getDateTime = datetime.datetime.fromtimestamp |
|
132 | self.getDateTime = datetime.datetime.fromtimestamp | |
125 | else: |
|
133 | else: | |
126 | self.getDateTime = datetime.datetime.utcfromtimestamp |
|
134 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
127 |
|
135 | |||
128 | if self.width is None: |
|
136 | if self.width is None: | |
129 | self.width = 8 |
|
137 | self.width = 8 | |
130 |
|
138 | |||
131 | self.figures = [] |
|
139 | self.figures = [] | |
132 | self.axes = [] |
|
140 | self.axes = [] | |
133 | self.cb_axes = [] |
|
141 | self.cb_axes = [] | |
134 | self.pf_axes = [] |
|
142 | self.pf_axes = [] | |
135 | self.cmaps = [] |
|
143 | self.cmaps = [] | |
136 |
|
144 | |||
137 | size = '15%' if self.ncols == 1 else '30%' |
|
145 | size = '15%' if self.ncols == 1 else '30%' | |
138 | pad = '4%' if self.ncols == 1 else '8%' |
|
146 | pad = '4%' if self.ncols == 1 else '8%' | |
139 |
|
147 | |||
140 | if self.oneFigure: |
|
148 | if self.oneFigure: | |
141 | if self.height is None: |
|
149 | if self.height is None: | |
142 | self.height = 1.4 * self.nrows + 1 |
|
150 | self.height = 1.4 * self.nrows + 1 | |
143 | fig = plt.figure(figsize=(self.width, self.height), |
|
151 | fig = plt.figure(figsize=(self.width, self.height), | |
144 | edgecolor='k', |
|
152 | edgecolor='k', | |
145 | facecolor='w') |
|
153 | facecolor='w') | |
146 | self.figures.append(fig) |
|
154 | self.figures.append(fig) | |
147 | for n in range(self.nplots): |
|
155 | for n in range(self.nplots): | |
148 | ax = fig.add_subplot(self.nrows, self.ncols, |
|
156 | ax = fig.add_subplot(self.nrows, self.ncols, | |
149 | n + 1, polar=self.polar) |
|
157 | n + 1, polar=self.polar) | |
150 | ax.tick_params(labelsize=8) |
|
158 | ax.tick_params(labelsize=8) | |
151 | ax.firsttime = True |
|
159 | ax.firsttime = True | |
152 | ax.index = 0 |
|
160 | ax.index = 0 | |
153 | ax.press = None |
|
161 | ax.press = None | |
154 | self.axes.append(ax) |
|
162 | self.axes.append(ax) | |
155 | if self.showprofile: |
|
163 | if self.showprofile: | |
156 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
164 | cax = self.__add_axes(ax, size=size, pad=pad) | |
157 | cax.tick_params(labelsize=8) |
|
165 | cax.tick_params(labelsize=8) | |
158 | self.pf_axes.append(cax) |
|
166 | self.pf_axes.append(cax) | |
159 | else: |
|
167 | else: | |
160 | if self.height is None: |
|
168 | if self.height is None: | |
161 | self.height = 3 |
|
169 | self.height = 3 | |
162 | for n in range(self.nplots): |
|
170 | for n in range(self.nplots): | |
163 | fig = plt.figure(figsize=(self.width, self.height), |
|
171 | fig = plt.figure(figsize=(self.width, self.height), | |
164 | edgecolor='k', |
|
172 | edgecolor='k', | |
165 | facecolor='w') |
|
173 | facecolor='w') | |
166 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) |
|
174 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
167 | ax.tick_params(labelsize=8) |
|
175 | ax.tick_params(labelsize=8) | |
168 | ax.firsttime = True |
|
176 | ax.firsttime = True | |
169 | ax.index = 0 |
|
177 | ax.index = 0 | |
170 | ax.press = None |
|
178 | ax.press = None | |
171 | self.figures.append(fig) |
|
179 | self.figures.append(fig) | |
172 | self.axes.append(ax) |
|
180 | self.axes.append(ax) | |
173 | if self.showprofile: |
|
181 | if self.showprofile: | |
174 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
182 | cax = self.__add_axes(ax, size=size, pad=pad) | |
175 | cax.tick_params(labelsize=8) |
|
183 | cax.tick_params(labelsize=8) | |
176 | self.pf_axes.append(cax) |
|
184 | self.pf_axes.append(cax) | |
177 |
|
185 | |||
178 | for n in range(self.nrows): |
|
186 | for n in range(self.nrows): | |
179 | if self.colormaps is not None: |
|
187 | if self.colormaps is not None: | |
180 | cmap = plt.get_cmap(self.colormaps[n]) |
|
188 | cmap = plt.get_cmap(self.colormaps[n]) | |
181 | else: |
|
189 | else: | |
182 | cmap = plt.get_cmap(self.colormap) |
|
190 | cmap = plt.get_cmap(self.colormap) | |
183 | cmap.set_bad(self.bgcolor, 1.) |
|
191 | cmap.set_bad(self.bgcolor, 1.) | |
184 | self.cmaps.append(cmap) |
|
192 | self.cmaps.append(cmap) | |
185 |
|
193 | |||
186 | for fig in self.figures: |
|
194 | for fig in self.figures: | |
187 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) |
|
195 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
188 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) |
|
196 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
189 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) |
|
197 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
190 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) |
|
198 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
191 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) |
|
199 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
192 | if self.show: |
|
200 | if self.show: | |
193 | fig.show() |
|
201 | fig.show() | |
194 |
|
202 | |||
195 | def OnKeyPress(self, event): |
|
203 | def OnKeyPress(self, event): | |
196 | ''' |
|
204 | ''' | |
197 | Event for pressing keys (up, down) change colormap |
|
205 | Event for pressing keys (up, down) change colormap | |
198 | ''' |
|
206 | ''' | |
199 | ax = event.inaxes |
|
207 | ax = event.inaxes | |
200 | if ax in self.axes: |
|
208 | if ax in self.axes: | |
201 | if event.key == 'down': |
|
209 | if event.key == 'down': | |
202 | ax.index += 1 |
|
210 | ax.index += 1 | |
203 | elif event.key == 'up': |
|
211 | elif event.key == 'up': | |
204 | ax.index -= 1 |
|
212 | ax.index -= 1 | |
205 | if ax.index < 0: |
|
213 | if ax.index < 0: | |
206 | ax.index = len(CMAPS) - 1 |
|
214 | ax.index = len(CMAPS) - 1 | |
207 | elif ax.index == len(CMAPS): |
|
215 | elif ax.index == len(CMAPS): | |
208 | ax.index = 0 |
|
216 | ax.index = 0 | |
209 | cmap = CMAPS[ax.index] |
|
217 | cmap = CMAPS[ax.index] | |
210 | ax.cbar.set_cmap(cmap) |
|
218 | ax.cbar.set_cmap(cmap) | |
211 | ax.cbar.draw_all() |
|
219 | ax.cbar.draw_all() | |
212 | ax.plt.set_cmap(cmap) |
|
220 | ax.plt.set_cmap(cmap) | |
213 | ax.cbar.patch.figure.canvas.draw() |
|
221 | ax.cbar.patch.figure.canvas.draw() | |
214 | self.colormap = cmap.name |
|
222 | self.colormap = cmap.name | |
215 |
|
223 | |||
216 | def OnBtnScroll(self, event): |
|
224 | def OnBtnScroll(self, event): | |
217 | ''' |
|
225 | ''' | |
218 | Event for scrolling, scale figure |
|
226 | Event for scrolling, scale figure | |
219 | ''' |
|
227 | ''' | |
220 | cb_ax = event.inaxes |
|
228 | cb_ax = event.inaxes | |
221 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
229 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
222 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] |
|
230 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
223 | pt = ax.cbar.ax.bbox.get_points()[:, 1] |
|
231 | pt = ax.cbar.ax.bbox.get_points()[:, 1] | |
224 | nrm = ax.cbar.norm |
|
232 | nrm = ax.cbar.norm | |
225 | vmin, vmax, p0, p1, pS = ( |
|
233 | vmin, vmax, p0, p1, pS = ( | |
226 | nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) |
|
234 | nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |
227 | scale = 2 if event.step == 1 else 0.5 |
|
235 | scale = 2 if event.step == 1 else 0.5 | |
228 | point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0) |
|
236 | point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0) | |
229 | ax.cbar.norm.vmin = point - scale * (point - vmin) |
|
237 | ax.cbar.norm.vmin = point - scale * (point - vmin) | |
230 | ax.cbar.norm.vmax = point - scale * (point - vmax) |
|
238 | ax.cbar.norm.vmax = point - scale * (point - vmax) | |
231 | ax.plt.set_norm(ax.cbar.norm) |
|
239 | ax.plt.set_norm(ax.cbar.norm) | |
232 | ax.cbar.draw_all() |
|
240 | ax.cbar.draw_all() | |
233 | ax.cbar.patch.figure.canvas.draw() |
|
241 | ax.cbar.patch.figure.canvas.draw() | |
234 |
|
242 | |||
235 | def onBtnPress(self, event): |
|
243 | def onBtnPress(self, event): | |
236 | ''' |
|
244 | ''' | |
237 | Event for mouse button press |
|
245 | Event for mouse button press | |
238 | ''' |
|
246 | ''' | |
239 | cb_ax = event.inaxes |
|
247 | cb_ax = event.inaxes | |
240 | if cb_ax is None: |
|
248 | if cb_ax is None: | |
241 | return |
|
249 | return | |
242 |
|
250 | |||
243 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
251 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
244 | cb_ax.press = event.x, event.y |
|
252 | cb_ax.press = event.x, event.y | |
245 | else: |
|
253 | else: | |
246 | cb_ax.press = None |
|
254 | cb_ax.press = None | |
247 |
|
255 | |||
248 | def onMotion(self, event): |
|
256 | def onMotion(self, event): | |
249 | ''' |
|
257 | ''' | |
250 | Event for move inside colorbar |
|
258 | Event for move inside colorbar | |
251 | ''' |
|
259 | ''' | |
252 | cb_ax = event.inaxes |
|
260 | cb_ax = event.inaxes | |
253 | if cb_ax is None: |
|
261 | if cb_ax is None: | |
254 | return |
|
262 | return | |
255 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
263 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
256 | return |
|
264 | return | |
257 | if cb_ax.press is None: |
|
265 | if cb_ax.press is None: | |
258 | return |
|
266 | return | |
259 |
|
267 | |||
260 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] |
|
268 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
261 | xprev, yprev = cb_ax.press |
|
269 | xprev, yprev = cb_ax.press | |
262 | dx = event.x - xprev |
|
270 | dx = event.x - xprev | |
263 | dy = event.y - yprev |
|
271 | dy = event.y - yprev | |
264 | cb_ax.press = event.x, event.y |
|
272 | cb_ax.press = event.x, event.y | |
265 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin |
|
273 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
266 | perc = 0.03 |
|
274 | perc = 0.03 | |
267 |
|
275 | |||
268 | if event.button == 1: |
|
276 | if event.button == 1: | |
269 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) |
|
277 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
270 | ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy) |
|
278 | ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy) | |
271 | elif event.button == 3: |
|
279 | elif event.button == 3: | |
272 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) |
|
280 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
273 | ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy) |
|
281 | ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy) | |
274 |
|
282 | |||
275 | ax.cbar.draw_all() |
|
283 | ax.cbar.draw_all() | |
276 | ax.plt.set_norm(ax.cbar.norm) |
|
284 | ax.plt.set_norm(ax.cbar.norm) | |
277 | ax.cbar.patch.figure.canvas.draw() |
|
285 | ax.cbar.patch.figure.canvas.draw() | |
278 |
|
286 | |||
279 | def onBtnRelease(self, event): |
|
287 | def onBtnRelease(self, event): | |
280 | ''' |
|
288 | ''' | |
281 | Event for mouse button release |
|
289 | Event for mouse button release | |
282 | ''' |
|
290 | ''' | |
283 | cb_ax = event.inaxes |
|
291 | cb_ax = event.inaxes | |
284 | if cb_ax is not None: |
|
292 | if cb_ax is not None: | |
285 | cb_ax.press = None |
|
293 | cb_ax.press = None | |
286 |
|
294 | |||
287 | def __add_axes(self, ax, size='30%', pad='8%'): |
|
295 | def __add_axes(self, ax, size='30%', pad='8%'): | |
288 | ''' |
|
296 | ''' | |
289 | Add new axes to the given figure |
|
297 | Add new axes to the given figure | |
290 | ''' |
|
298 | ''' | |
291 | divider = make_axes_locatable(ax) |
|
299 | divider = make_axes_locatable(ax) | |
292 | nax = divider.new_horizontal(size=size, pad=pad) |
|
300 | nax = divider.new_horizontal(size=size, pad=pad) | |
293 | ax.figure.add_axes(nax) |
|
301 | ax.figure.add_axes(nax) | |
294 | return nax |
|
302 | return nax | |
295 |
|
303 | |||
296 | self.setup() |
|
304 | self.setup() | |
297 |
|
305 | |||
298 | def setup(self): |
|
306 | def setup(self): | |
299 | ''' |
|
307 | ''' | |
300 | This method should be implemented in the child class, the following |
|
308 | This method should be implemented in the child class, the following | |
301 | attributes should be set: |
|
309 | attributes should be set: | |
302 |
|
310 | |||
303 | self.nrows: number of rows |
|
311 | self.nrows: number of rows | |
304 | self.ncols: number of cols |
|
312 | self.ncols: number of cols | |
305 | self.nplots: number of plots (channels or pairs) |
|
313 | self.nplots: number of plots (channels or pairs) | |
306 | self.ylabel: label for Y axes |
|
314 | self.ylabel: label for Y axes | |
307 | self.titles: list of axes title |
|
315 | self.titles: list of axes title | |
308 |
|
316 | |||
309 | ''' |
|
317 | ''' | |
310 | raise(NotImplementedError, 'Implement this method in child class') |
|
318 | raise(NotImplementedError, 'Implement this method in child class') | |
311 |
|
319 | |||
312 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
320 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
313 | ''' |
|
321 | ''' | |
314 | Create a masked array for missing data |
|
322 | Create a masked array for missing data | |
315 | ''' |
|
323 | ''' | |
316 | if x_buffer.shape[0] < 2: |
|
324 | if x_buffer.shape[0] < 2: | |
317 | return x_buffer, y_buffer, z_buffer |
|
325 | return x_buffer, y_buffer, z_buffer | |
318 |
|
326 | |||
319 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
327 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
320 | x_median = numpy.median(deltas) |
|
328 | x_median = numpy.median(deltas) | |
321 |
|
329 | |||
322 | index = numpy.where(deltas > 5 * x_median) |
|
330 | index = numpy.where(deltas > 5 * x_median) | |
323 |
|
331 | |||
324 | if len(index[0]) != 0: |
|
332 | if len(index[0]) != 0: | |
325 | z_buffer[::, index[0], ::] = self.__missing |
|
333 | z_buffer[::, index[0], ::] = self.__missing | |
326 | z_buffer = numpy.ma.masked_inside(z_buffer, |
|
334 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
327 | 0.99 * self.__missing, |
|
335 | 0.99 * self.__missing, | |
328 | 1.01 * self.__missing) |
|
336 | 1.01 * self.__missing) | |
329 |
|
337 | |||
330 | return x_buffer, y_buffer, z_buffer |
|
338 | return x_buffer, y_buffer, z_buffer | |
331 |
|
339 | |||
332 | def decimate(self): |
|
340 | def decimate(self): | |
333 |
|
341 | |||
334 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
342 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
335 | dy = int(len(self.y) / self.decimation) + 1 |
|
343 | dy = int(len(self.y) / self.decimation) + 1 | |
336 |
|
344 | |||
337 | # x = self.x[::dx] |
|
345 | # x = self.x[::dx] | |
338 | x = self.x |
|
346 | x = self.x | |
339 | y = self.y[::dy] |
|
347 | y = self.y[::dy] | |
340 | z = self.z[::, ::, ::dy] |
|
348 | z = self.z[::, ::, ::dy] | |
341 |
|
349 | |||
342 | return x, y, z |
|
350 | return x, y, z | |
343 |
|
351 | |||
344 | def format(self): |
|
352 | def format(self): | |
345 | ''' |
|
353 | ''' | |
346 | Set min and max values, labels, ticks and titles |
|
354 | Set min and max values, labels, ticks and titles | |
347 | ''' |
|
355 | ''' | |
348 |
|
356 | |||
349 | if self.xmin is None: |
|
357 | if self.xmin is None: | |
350 | xmin = self.min_time |
|
358 | xmin = self.min_time | |
351 | else: |
|
359 | else: | |
352 | if self.xaxis is 'time': |
|
360 | if self.xaxis is 'time': | |
353 | dt = self.getDateTime(self.min_time) |
|
361 | dt = self.getDateTime(self.min_time) | |
354 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - |
|
362 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - | |
355 | datetime.datetime(1970, 1, 1)).total_seconds() |
|
363 | datetime.datetime(1970, 1, 1)).total_seconds() | |
356 | if self.data.localtime: |
|
364 | if self.data.localtime: | |
357 | xmin += time.timezone |
|
365 | xmin += time.timezone | |
358 | else: |
|
366 | else: | |
359 | xmin = self.xmin |
|
367 | xmin = self.xmin | |
360 |
|
368 | |||
361 | if self.xmax is None: |
|
369 | if self.xmax is None: | |
362 | xmax = xmin + self.xrange * 60 * 60 |
|
370 | xmax = xmin + self.xrange * 60 * 60 | |
363 | else: |
|
371 | else: | |
364 | if self.xaxis is 'time': |
|
372 | if self.xaxis is 'time': | |
365 | dt = self.getDateTime(self.max_time) |
|
373 | dt = self.getDateTime(self.max_time) | |
366 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - |
|
374 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - | |
367 | datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds() |
|
375 | datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds() | |
368 | if self.data.localtime: |
|
376 | if self.data.localtime: | |
369 | xmax += time.timezone |
|
377 | xmax += time.timezone | |
370 | else: |
|
378 | else: | |
371 | xmax = self.xmax |
|
379 | xmax = self.xmax | |
372 |
|
380 | |||
373 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) |
|
381 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
374 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) |
|
382 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
375 |
|
383 | |||
376 | Y = numpy.array([5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) |
|
384 | Y = numpy.array([5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) | |
377 | i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] |
|
385 | i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] | |
378 | ystep = Y[i] / 5. |
|
386 | ystep = Y[i] / 5. | |
379 |
|
387 | |||
380 | for n, ax in enumerate(self.axes): |
|
388 | for n, ax in enumerate(self.axes): | |
381 | if ax.firsttime: |
|
389 | if ax.firsttime: | |
382 | ax.set_facecolor(self.bgcolor) |
|
390 | ax.set_facecolor(self.bgcolor) | |
383 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) |
|
391 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
384 | ax.xaxis.set_major_locator(MultipleLocator(ystep)) |
|
392 | ax.xaxis.set_major_locator(MultipleLocator(ystep)) | |
385 | if self.xscale: |
|
393 | if self.xscale: | |
386 | ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale))) |
|
394 | ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale))) | |
387 | if self.xscale: |
|
395 | if self.xscale: | |
388 | ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale))) |
|
396 | ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale))) | |
389 | if self.xaxis is 'time': |
|
397 | if self.xaxis is 'time': | |
390 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) |
|
398 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
391 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
399 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
392 | if self.xlabel is not None: |
|
400 | if self.xlabel is not None: | |
393 | ax.set_xlabel(self.xlabel) |
|
401 | ax.set_xlabel(self.xlabel) | |
394 | ax.set_ylabel(self.ylabel) |
|
402 | ax.set_ylabel(self.ylabel) | |
395 | ax.firsttime = False |
|
403 | ax.firsttime = False | |
396 | if self.showprofile: |
|
404 | if self.showprofile: | |
397 | self.pf_axes[n].set_ylim(ymin, ymax) |
|
405 | self.pf_axes[n].set_ylim(ymin, ymax) | |
398 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) |
|
406 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
399 | self.pf_axes[n].set_xlabel('dB') |
|
407 | self.pf_axes[n].set_xlabel('dB') | |
400 | self.pf_axes[n].grid(b=True, axis='x') |
|
408 | self.pf_axes[n].grid(b=True, axis='x') | |
401 | [tick.set_visible(False) |
|
409 | [tick.set_visible(False) | |
402 | for tick in self.pf_axes[n].get_yticklabels()] |
|
410 | for tick in self.pf_axes[n].get_yticklabels()] | |
403 | if self.colorbar: |
|
411 | if self.colorbar: | |
404 | ax.cbar = plt.colorbar( |
|
412 | ax.cbar = plt.colorbar( | |
405 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) |
|
413 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
406 | ax.cbar.ax.tick_params(labelsize=8) |
|
414 | ax.cbar.ax.tick_params(labelsize=8) | |
407 | ax.cbar.ax.press = None |
|
415 | ax.cbar.ax.press = None | |
408 | if self.cb_label: |
|
416 | if self.cb_label: | |
409 | ax.cbar.set_label(self.cb_label, size=8) |
|
417 | ax.cbar.set_label(self.cb_label, size=8) | |
410 | elif self.cb_labels: |
|
418 | elif self.cb_labels: | |
411 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
419 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
412 | else: |
|
420 | else: | |
413 | ax.cbar = None |
|
421 | ax.cbar = None | |
414 |
|
422 | |||
415 | if not self.polar: |
|
423 | if not self.polar: | |
416 | ax.set_xlim(xmin, xmax) |
|
424 | ax.set_xlim(xmin, xmax) | |
417 | ax.set_ylim(ymin, ymax) |
|
425 | ax.set_ylim(ymin, ymax) | |
418 | ax.set_title('{} {} {}'.format( |
|
426 | ax.set_title('{} {} {}'.format( | |
419 | self.titles[n], |
|
427 | self.titles[n], | |
420 | self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'), |
|
428 | self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'), | |
421 | self.time_label), |
|
429 | self.time_label), | |
422 | size=8) |
|
430 | size=8) | |
423 | else: |
|
431 | else: | |
424 | ax.set_title('{}'.format(self.titles[n]), size=8) |
|
432 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
425 | ax.set_ylim(0, 90) |
|
433 | ax.set_ylim(0, 90) | |
426 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
434 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
427 | ax.yaxis.labelpad = 40 |
|
435 | ax.yaxis.labelpad = 40 | |
428 |
|
436 | |||
429 | def __plot(self): |
|
437 | def __plot(self): | |
430 | ''' |
|
438 | ''' | |
431 | ''' |
|
439 | ''' | |
432 | log.log('Plotting', self.name) |
|
440 | log.log('Plotting', self.name) | |
433 |
|
441 | |||
434 | try: |
|
442 | try: | |
435 | self.plot() |
|
443 | self.plot() | |
436 | self.format() |
|
444 | self.format() | |
437 | except Exception as e: |
|
445 | except Exception as e: | |
438 | log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name) |
|
446 | log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name) | |
439 | log.error(str(e), '') |
|
447 | log.error(str(e), '') | |
440 | return |
|
448 | return | |
441 |
|
449 | |||
442 | for n, fig in enumerate(self.figures): |
|
450 | for n, fig in enumerate(self.figures): | |
443 | if self.nrows == 0 or self.nplots == 0: |
|
451 | if self.nrows == 0 or self.nplots == 0: | |
444 | log.warning('No data', self.name) |
|
452 | log.warning('No data', self.name) | |
445 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') |
|
453 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
446 | fig.canvas.manager.set_window_title(self.CODE) |
|
454 | fig.canvas.manager.set_window_title(self.CODE) | |
447 | continue |
|
455 | continue | |
448 |
|
456 | |||
449 | fig.tight_layout() |
|
457 | fig.tight_layout() | |
450 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
458 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
451 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) |
|
459 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) | |
452 | fig.canvas.draw() |
|
460 | fig.canvas.draw() | |
453 |
|
461 | |||
454 | if self.save and (self.data.ended or not self.data.buffering): |
|
462 | if self.save and (self.data.ended or not self.data.buffering): | |
455 |
|
463 | |||
456 | if self.save_labels: |
|
464 | if self.save_labels: | |
457 | labels = self.save_labels |
|
465 | labels = self.save_labels | |
458 | else: |
|
466 | else: | |
459 | labels = range(self.nrows) |
|
467 | labels = range(self.nrows) | |
460 |
|
468 | |||
461 | if self.oneFigure: |
|
469 | if self.oneFigure: | |
462 | label = '' |
|
470 | label = '' | |
463 | else: |
|
471 | else: | |
464 | label = '-{}'.format(labels[n]) |
|
472 | label = '-{}'.format(labels[n]) | |
465 | figname = os.path.join( |
|
473 | figname = os.path.join( | |
466 | self.save, |
|
474 | self.save, | |
467 | self.CODE, |
|
475 | self.CODE, | |
468 | '{}{}_{}.png'.format( |
|
476 | '{}{}_{}.png'.format( | |
469 | self.CODE, |
|
477 | self.CODE, | |
470 | label, |
|
478 | label, | |
471 | self.getDateTime(self.saveTime).strftime( |
|
479 | self.getDateTime(self.saveTime).strftime( | |
472 | '%Y%m%d_%H%M%S'), |
|
480 | '%Y%m%d_%H%M%S'), | |
473 | ) |
|
481 | ) | |
474 | ) |
|
482 | ) | |
475 | log.log('Saving figure: {}'.format(figname), self.name) |
|
483 | log.log('Saving figure: {}'.format(figname), self.name) | |
476 | if not os.path.isdir(os.path.dirname(figname)): |
|
484 | if not os.path.isdir(os.path.dirname(figname)): | |
477 | os.makedirs(os.path.dirname(figname)) |
|
485 | os.makedirs(os.path.dirname(figname)) | |
478 | fig.savefig(figname) |
|
486 | fig.savefig(figname) | |
479 |
|
487 | |||
480 | def plot(self): |
|
488 | def plot(self): | |
481 | ''' |
|
489 | ''' | |
482 | ''' |
|
490 | ''' | |
483 | raise(NotImplementedError, 'Implement this method in child class') |
|
491 | raise(NotImplementedError, 'Implement this method in child class') | |
484 |
|
492 | |||
485 | def run(self): |
|
493 | def run(self): | |
486 |
|
494 | |||
487 | log.log('Starting', self.name) |
|
495 | log.log('Starting', self.name) | |
488 |
|
496 | |||
489 | context = zmq.Context() |
|
497 | context = zmq.Context() | |
490 | receiver = context.socket(zmq.SUB) |
|
498 | receiver = context.socket(zmq.SUB) | |
491 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
499 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
492 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
500 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
493 |
|
501 | |||
494 | if 'server' in self.kwargs['parent']: |
|
502 | if 'server' in self.kwargs['parent']: | |
495 | receiver.connect( |
|
503 | receiver.connect( | |
496 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
504 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
497 | else: |
|
505 | else: | |
498 | receiver.connect("ipc:///tmp/zmq.plots") |
|
506 | receiver.connect("ipc:///tmp/zmq.plots") | |
499 |
|
507 | |||
500 | while True: |
|
508 | while True: | |
501 | try: |
|
509 | try: | |
502 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
510 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
503 | if self.data.localtime and self.localtime: |
|
511 | if self.data.localtime and self.localtime: | |
504 | self.times = self.data.times |
|
512 | self.times = self.data.times | |
505 | elif self.data.localtime and not self.localtime: |
|
513 | elif self.data.localtime and not self.localtime: | |
506 | self.times = self.data.times + time.timezone |
|
514 | self.times = self.data.times + time.timezone | |
507 | elif not self.data.localtime and self.localtime: |
|
515 | elif not self.data.localtime and self.localtime: | |
508 | self.times = self.data.times - time.timezone |
|
516 | self.times = self.data.times - time.timezone | |
509 | else: |
|
517 | else: | |
510 | self.times = self.data.times |
|
518 | self.times = self.data.times | |
511 |
|
519 | |||
512 | self.min_time = self.times[0] |
|
520 | self.min_time = self.times[0] | |
513 | self.max_time = self.times[-1] |
|
521 | self.max_time = self.times[-1] | |
514 |
|
522 | |||
515 | if self.isConfig is False: |
|
523 | if self.isConfig is False: | |
516 | self.__setup() |
|
524 | self.__setup() | |
517 | self.isConfig = True |
|
525 | self.isConfig = True | |
518 |
|
526 | |||
519 | self.__plot() |
|
527 | self.__plot() | |
520 |
|
528 | |||
521 | except zmq.Again as e: |
|
529 | except zmq.Again as e: | |
522 | # log.log('.', tag='', nl=False) |
|
530 | # log.log('.', tag='', nl=False) | |
523 | if self.data: |
|
531 | if self.data: | |
524 | figpause(self.data.throttle) |
|
532 | figpause(self.data.throttle) | |
525 | else: |
|
533 | else: | |
526 | time.sleep(2) |
|
534 | time.sleep(2) | |
527 |
|
535 | |||
528 | def close(self): |
|
536 | def close(self): | |
529 | if self.data: |
|
537 | if self.data: | |
530 | self.__plot() |
|
538 | self.__plot() | |
531 |
|
539 | |||
532 |
|
540 | |||
533 | class PlotSpectraData(PlotData): |
|
541 | class PlotSpectraData(PlotData): | |
534 | ''' |
|
542 | ''' | |
535 | Plot for Spectra data |
|
543 | Plot for Spectra data | |
536 | ''' |
|
544 | ''' | |
537 |
|
545 | |||
538 | CODE = 'spc' |
|
546 | CODE = 'spc' | |
539 | colormap = 'jro' |
|
547 | colormap = 'jro' | |
540 |
|
548 | |||
541 | def setup(self): |
|
549 | def setup(self): | |
542 | self.nplots = len(self.data.channels) |
|
550 | self.nplots = len(self.data.channels) | |
543 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
551 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
544 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
552 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
545 | self.width = 3.4 * self.ncols |
|
553 | self.width = 3.4 * self.ncols | |
546 | self.height = 3 * self.nrows |
|
554 | self.height = 3 * self.nrows | |
547 | self.cb_label = 'dB' |
|
555 | self.cb_label = 'dB' | |
548 | if self.showprofile: |
|
556 | if self.showprofile: | |
549 | self.width += 0.8 * self.ncols |
|
557 | self.width += 0.8 * self.ncols | |
550 |
|
558 | |||
551 | self.ylabel = 'Range [km]' |
|
559 | self.ylabel = 'Range [km]' | |
552 |
|
560 | |||
553 | def plot(self): |
|
561 | def plot(self): | |
554 | if self.xaxis == "frequency": |
|
562 | if self.xaxis == "frequency": | |
555 | x = self.data.xrange[0] |
|
563 | x = self.data.xrange[0] | |
556 | self.xlabel = "Frequency (kHz)" |
|
564 | self.xlabel = "Frequency (kHz)" | |
557 | elif self.xaxis == "time": |
|
565 | elif self.xaxis == "time": | |
558 | x = self.data.xrange[1] |
|
566 | x = self.data.xrange[1] | |
559 | self.xlabel = "Time (ms)" |
|
567 | self.xlabel = "Time (ms)" | |
560 | else: |
|
568 | else: | |
561 | x = self.data.xrange[2] |
|
569 | x = self.data.xrange[2] | |
562 | self.xlabel = "Velocity (m/s)" |
|
570 | self.xlabel = "Velocity (m/s)" | |
563 |
|
571 | |||
564 | if self.CODE == 'spc_mean': |
|
572 | if self.CODE == 'spc_mean': | |
565 | x = self.data.xrange[2] |
|
573 | x = self.data.xrange[2] | |
566 | self.xlabel = "Velocity (m/s)" |
|
574 | self.xlabel = "Velocity (m/s)" | |
567 |
|
575 | |||
568 | self.titles = [] |
|
576 | self.titles = [] | |
569 |
|
577 | |||
570 | y = self.data.heights |
|
578 | y = self.data.heights | |
571 | self.y = y |
|
579 | self.y = y | |
572 | z = self.data['spc'] |
|
580 | z = self.data['spc'] | |
573 |
|
581 | |||
574 | for n, ax in enumerate(self.axes): |
|
582 | for n, ax in enumerate(self.axes): | |
575 | noise = self.data['noise'][n][-1] |
|
583 | noise = self.data['noise'][n][-1] | |
576 | if self.CODE == 'spc_mean': |
|
584 | if self.CODE == 'spc_mean': | |
577 | mean = self.data['mean'][n][-1] |
|
585 | mean = self.data['mean'][n][-1] | |
578 | if ax.firsttime: |
|
586 | if ax.firsttime: | |
579 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
587 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
580 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
588 | self.xmin = self.xmin if self.xmin else -self.xmax | |
581 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
589 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
582 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
590 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
583 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
591 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
584 | vmin=self.zmin, |
|
592 | vmin=self.zmin, | |
585 | vmax=self.zmax, |
|
593 | vmax=self.zmax, | |
586 | cmap=plt.get_cmap(self.colormap) |
|
594 | cmap=plt.get_cmap(self.colormap) | |
587 | ) |
|
595 | ) | |
588 |
|
596 | |||
589 | if self.showprofile: |
|
597 | if self.showprofile: | |
590 | ax.plt_profile = self.pf_axes[n].plot( |
|
598 | ax.plt_profile = self.pf_axes[n].plot( | |
591 | self.data['rti'][n][-1], y)[0] |
|
599 | self.data['rti'][n][-1], y)[0] | |
592 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
600 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
593 | color="k", linestyle="dashed", lw=1)[0] |
|
601 | color="k", linestyle="dashed", lw=1)[0] | |
594 | if self.CODE == 'spc_mean': |
|
602 | if self.CODE == 'spc_mean': | |
595 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
603 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
596 | else: |
|
604 | else: | |
597 | ax.plt.set_array(z[n].T.ravel()) |
|
605 | ax.plt.set_array(z[n].T.ravel()) | |
598 | if self.showprofile: |
|
606 | if self.showprofile: | |
599 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) |
|
607 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
600 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
608 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
601 | if self.CODE == 'spc_mean': |
|
609 | if self.CODE == 'spc_mean': | |
602 | ax.plt_mean.set_data(mean, y) |
|
610 | ax.plt_mean.set_data(mean, y) | |
603 |
|
611 | |||
604 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
612 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
605 | self.saveTime = self.max_time |
|
613 | self.saveTime = self.max_time | |
606 |
|
614 | |||
607 |
|
615 | |||
608 | class PlotCrossSpectraData(PlotData): |
|
616 | class PlotCrossSpectraData(PlotData): | |
609 |
|
617 | |||
610 | CODE = 'cspc' |
|
618 | CODE = 'cspc' | |
611 | zmin_coh = None |
|
619 | zmin_coh = None | |
612 | zmax_coh = None |
|
620 | zmax_coh = None | |
613 | zmin_phase = None |
|
621 | zmin_phase = None | |
614 | zmax_phase = None |
|
622 | zmax_phase = None | |
615 |
|
623 | |||
616 | def setup(self): |
|
624 | def setup(self): | |
617 |
|
625 | |||
618 | self.ncols = 4 |
|
626 | self.ncols = 4 | |
619 | self.nrows = len(self.data.pairs) |
|
627 | self.nrows = len(self.data.pairs) | |
620 | self.nplots = self.nrows * 4 |
|
628 | self.nplots = self.nrows * 4 | |
621 | self.width = 3.4 * self.ncols |
|
629 | self.width = 3.4 * self.ncols | |
622 | self.height = 3 * self.nrows |
|
630 | self.height = 3 * self.nrows | |
623 | self.ylabel = 'Range [km]' |
|
631 | self.ylabel = 'Range [km]' | |
624 | self.showprofile = False |
|
632 | self.showprofile = False | |
625 |
|
633 | |||
626 | def plot(self): |
|
634 | def plot(self): | |
627 |
|
635 | |||
628 | if self.xaxis == "frequency": |
|
636 | if self.xaxis == "frequency": | |
629 | x = self.data.xrange[0] |
|
637 | x = self.data.xrange[0] | |
630 | self.xlabel = "Frequency (kHz)" |
|
638 | self.xlabel = "Frequency (kHz)" | |
631 | elif self.xaxis == "time": |
|
639 | elif self.xaxis == "time": | |
632 | x = self.data.xrange[1] |
|
640 | x = self.data.xrange[1] | |
633 | self.xlabel = "Time (ms)" |
|
641 | self.xlabel = "Time (ms)" | |
634 | else: |
|
642 | else: | |
635 | x = self.data.xrange[2] |
|
643 | x = self.data.xrange[2] | |
636 | self.xlabel = "Velocity (m/s)" |
|
644 | self.xlabel = "Velocity (m/s)" | |
637 |
|
645 | |||
638 | self.titles = [] |
|
646 | self.titles = [] | |
639 |
|
647 | |||
640 | y = self.data.heights |
|
648 | y = self.data.heights | |
641 | self.y = y |
|
649 | self.y = y | |
642 | spc = self.data['spc'] |
|
650 | spc = self.data['spc'] | |
643 | cspc = self.data['cspc'] |
|
651 | cspc = self.data['cspc'] | |
644 |
|
652 | |||
645 | for n in range(self.nrows): |
|
653 | for n in range(self.nrows): | |
646 | noise = self.data['noise'][n][-1] |
|
654 | noise = self.data['noise'][n][-1] | |
647 | pair = self.data.pairs[n] |
|
655 | pair = self.data.pairs[n] | |
648 | ax = self.axes[4 * n] |
|
656 | ax = self.axes[4 * n] | |
649 | ax3 = self.axes[4 * n + 3] |
|
657 | ax3 = self.axes[4 * n + 3] | |
650 | if ax.firsttime: |
|
658 | if ax.firsttime: | |
651 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
659 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
652 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
660 | self.xmin = self.xmin if self.xmin else -self.xmax | |
653 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) |
|
661 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
654 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) |
|
662 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
655 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, |
|
663 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |
656 | vmin=self.zmin, |
|
664 | vmin=self.zmin, | |
657 | vmax=self.zmax, |
|
665 | vmax=self.zmax, | |
658 | cmap=plt.get_cmap(self.colormap) |
|
666 | cmap=plt.get_cmap(self.colormap) | |
659 | ) |
|
667 | ) | |
660 | else: |
|
668 | else: | |
661 | ax.plt.set_array(spc[pair[0]].T.ravel()) |
|
669 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
662 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
670 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
663 |
|
671 | |||
664 | ax = self.axes[4 * n + 1] |
|
672 | ax = self.axes[4 * n + 1] | |
665 | if ax.firsttime: |
|
673 | if ax.firsttime: | |
666 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, |
|
674 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, | |
667 | vmin=self.zmin, |
|
675 | vmin=self.zmin, | |
668 | vmax=self.zmax, |
|
676 | vmax=self.zmax, | |
669 | cmap=plt.get_cmap(self.colormap) |
|
677 | cmap=plt.get_cmap(self.colormap) | |
670 | ) |
|
678 | ) | |
671 | else: |
|
679 | else: | |
672 | ax.plt.set_array(spc[pair[1]].T.ravel()) |
|
680 | ax.plt.set_array(spc[pair[1]].T.ravel()) | |
673 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
681 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
674 |
|
682 | |||
675 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) |
|
683 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |
676 | coh = numpy.abs(out) |
|
684 | coh = numpy.abs(out) | |
677 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi |
|
685 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |
678 |
|
686 | |||
679 | ax = self.axes[4 * n + 2] |
|
687 | ax = self.axes[4 * n + 2] | |
680 | if ax.firsttime: |
|
688 | if ax.firsttime: | |
681 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
689 | ax.plt = ax.pcolormesh(x, y, coh.T, | |
682 | vmin=0, |
|
690 | vmin=0, | |
683 | vmax=1, |
|
691 | vmax=1, | |
684 | cmap=plt.get_cmap(self.colormap_coh) |
|
692 | cmap=plt.get_cmap(self.colormap_coh) | |
685 | ) |
|
693 | ) | |
686 | else: |
|
694 | else: | |
687 | ax.plt.set_array(coh.T.ravel()) |
|
695 | ax.plt.set_array(coh.T.ravel()) | |
688 | self.titles.append( |
|
696 | self.titles.append( | |
689 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) |
|
697 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
690 |
|
698 | |||
691 | ax = self.axes[4 * n + 3] |
|
699 | ax = self.axes[4 * n + 3] | |
692 | if ax.firsttime: |
|
700 | if ax.firsttime: | |
693 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
701 | ax.plt = ax.pcolormesh(x, y, phase.T, | |
694 | vmin=-180, |
|
702 | vmin=-180, | |
695 | vmax=180, |
|
703 | vmax=180, | |
696 | cmap=plt.get_cmap(self.colormap_phase) |
|
704 | cmap=plt.get_cmap(self.colormap_phase) | |
697 | ) |
|
705 | ) | |
698 | else: |
|
706 | else: | |
699 | ax.plt.set_array(phase.T.ravel()) |
|
707 | ax.plt.set_array(phase.T.ravel()) | |
700 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
708 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |
701 |
|
709 | |||
702 | self.saveTime = self.max_time |
|
710 | self.saveTime = self.max_time | |
703 |
|
711 | |||
704 |
|
712 | |||
705 | class PlotSpectraMeanData(PlotSpectraData): |
|
713 | class PlotSpectraMeanData(PlotSpectraData): | |
706 | ''' |
|
714 | ''' | |
707 | Plot for Spectra and Mean |
|
715 | Plot for Spectra and Mean | |
708 | ''' |
|
716 | ''' | |
709 | CODE = 'spc_mean' |
|
717 | CODE = 'spc_mean' | |
710 | colormap = 'jro' |
|
718 | colormap = 'jro' | |
711 |
|
719 | |||
712 |
|
720 | |||
713 | class PlotRTIData(PlotData): |
|
721 | class PlotRTIData(PlotData): | |
714 | ''' |
|
722 | ''' | |
715 | Plot for RTI data |
|
723 | Plot for RTI data | |
716 | ''' |
|
724 | ''' | |
717 |
|
725 | |||
718 | CODE = 'rti' |
|
726 | CODE = 'rti' | |
719 | colormap = 'jro' |
|
727 | colormap = 'jro' | |
720 |
|
728 | |||
721 | def setup(self): |
|
729 | def setup(self): | |
722 | self.xaxis = 'time' |
|
730 | self.xaxis = 'time' | |
723 | self.ncols = 1 |
|
731 | self.ncols = 1 | |
724 | self.nrows = len(self.data.channels) |
|
732 | self.nrows = len(self.data.channels) | |
725 | self.nplots = len(self.data.channels) |
|
733 | self.nplots = len(self.data.channels) | |
726 | self.ylabel = 'Range [km]' |
|
734 | self.ylabel = 'Range [km]' | |
727 | self.cb_label = 'dB' |
|
735 | self.cb_label = 'dB' | |
728 | self.titles = ['{} Channel {}'.format( |
|
736 | self.titles = ['{} Channel {}'.format( | |
729 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
737 | self.CODE.upper(), x) for x in range(self.nrows)] | |
730 |
|
738 | |||
731 | def plot(self): |
|
739 | def plot(self): | |
732 | self.x = self.times |
|
740 | self.x = self.times | |
733 | self.y = self.data.heights |
|
741 | self.y = self.data.heights | |
734 | self.z = self.data[self.CODE] |
|
742 | self.z = self.data[self.CODE] | |
735 | self.z = numpy.ma.masked_invalid(self.z) |
|
743 | self.z = numpy.ma.masked_invalid(self.z) | |
736 |
|
744 | |||
737 | if self.decimation is None: |
|
745 | if self.decimation is None: | |
738 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
746 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
739 | else: |
|
747 | else: | |
740 | x, y, z = self.fill_gaps(*self.decimate()) |
|
748 | x, y, z = self.fill_gaps(*self.decimate()) | |
741 |
|
749 | |||
742 | for n, ax in enumerate(self.axes): |
|
750 | for n, ax in enumerate(self.axes): | |
743 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
751 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
744 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
752 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
745 | if ax.firsttime: |
|
753 | if ax.firsttime: | |
746 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
754 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
747 | vmin=self.zmin, |
|
755 | vmin=self.zmin, | |
748 | vmax=self.zmax, |
|
756 | vmax=self.zmax, | |
749 | cmap=plt.get_cmap(self.colormap) |
|
757 | cmap=plt.get_cmap(self.colormap) | |
750 | ) |
|
758 | ) | |
751 | if self.showprofile: |
|
759 | if self.showprofile: | |
752 | ax.plot_profile = self.pf_axes[n].plot( |
|
760 | ax.plot_profile = self.pf_axes[n].plot( | |
753 | self.data['rti'][n][-1], self.y)[0] |
|
761 | self.data['rti'][n][-1], self.y)[0] | |
754 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, |
|
762 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, | |
755 | color="k", linestyle="dashed", lw=1)[0] |
|
763 | color="k", linestyle="dashed", lw=1)[0] | |
756 | else: |
|
764 | else: | |
757 | ax.collections.remove(ax.collections[0]) |
|
765 | ax.collections.remove(ax.collections[0]) | |
758 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
766 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
759 | vmin=self.zmin, |
|
767 | vmin=self.zmin, | |
760 | vmax=self.zmax, |
|
768 | vmax=self.zmax, | |
761 | cmap=plt.get_cmap(self.colormap) |
|
769 | cmap=plt.get_cmap(self.colormap) | |
762 | ) |
|
770 | ) | |
763 | if self.showprofile: |
|
771 | if self.showprofile: | |
764 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) |
|
772 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |
765 | ax.plot_noise.set_data(numpy.repeat( |
|
773 | ax.plot_noise.set_data(numpy.repeat( | |
766 | self.data['noise'][n][-1], len(self.y)), self.y) |
|
774 | self.data['noise'][n][-1], len(self.y)), self.y) | |
767 |
|
775 | |||
768 | self.saveTime = self.min_time |
|
776 | self.saveTime = self.min_time | |
769 |
|
777 | |||
770 |
|
778 | |||
771 | class PlotCOHData(PlotRTIData): |
|
779 | class PlotCOHData(PlotRTIData): | |
772 | ''' |
|
780 | ''' | |
773 | Plot for Coherence data |
|
781 | Plot for Coherence data | |
774 | ''' |
|
782 | ''' | |
775 |
|
783 | |||
776 | CODE = 'coh' |
|
784 | CODE = 'coh' | |
777 |
|
785 | |||
778 | def setup(self): |
|
786 | def setup(self): | |
779 | self.xaxis = 'time' |
|
787 | self.xaxis = 'time' | |
780 | self.ncols = 1 |
|
788 | self.ncols = 1 | |
781 | self.nrows = len(self.data.pairs) |
|
789 | self.nrows = len(self.data.pairs) | |
782 | self.nplots = len(self.data.pairs) |
|
790 | self.nplots = len(self.data.pairs) | |
783 | self.ylabel = 'Range [km]' |
|
791 | self.ylabel = 'Range [km]' | |
784 | if self.CODE == 'coh': |
|
792 | if self.CODE == 'coh': | |
785 | self.cb_label = '' |
|
793 | self.cb_label = '' | |
786 | self.titles = [ |
|
794 | self.titles = [ | |
787 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
795 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
788 | else: |
|
796 | else: | |
789 | self.cb_label = 'Degrees' |
|
797 | self.cb_label = 'Degrees' | |
790 | self.titles = [ |
|
798 | self.titles = [ | |
791 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
799 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
792 |
|
800 | |||
793 |
|
801 | |||
794 | class PlotPHASEData(PlotCOHData): |
|
802 | class PlotPHASEData(PlotCOHData): | |
795 | ''' |
|
803 | ''' | |
796 | Plot for Phase map data |
|
804 | Plot for Phase map data | |
797 | ''' |
|
805 | ''' | |
798 |
|
806 | |||
799 | CODE = 'phase' |
|
807 | CODE = 'phase' | |
800 | colormap = 'seismic' |
|
808 | colormap = 'seismic' | |
801 |
|
809 | |||
802 |
|
810 | |||
803 | class PlotNoiseData(PlotData): |
|
811 | class PlotNoiseData(PlotData): | |
804 | ''' |
|
812 | ''' | |
805 | Plot for noise |
|
813 | Plot for noise | |
806 | ''' |
|
814 | ''' | |
807 |
|
815 | |||
808 | CODE = 'noise' |
|
816 | CODE = 'noise' | |
809 |
|
817 | |||
810 | def setup(self): |
|
818 | def setup(self): | |
811 | self.xaxis = 'time' |
|
819 | self.xaxis = 'time' | |
812 | self.ncols = 1 |
|
820 | self.ncols = 1 | |
813 | self.nrows = 1 |
|
821 | self.nrows = 1 | |
814 | self.nplots = 1 |
|
822 | self.nplots = 1 | |
815 | self.ylabel = 'Intensity [dB]' |
|
823 | self.ylabel = 'Intensity [dB]' | |
816 | self.titles = ['Noise'] |
|
824 | self.titles = ['Noise'] | |
817 | self.colorbar = False |
|
825 | self.colorbar = False | |
818 |
|
826 | |||
819 | def plot(self): |
|
827 | def plot(self): | |
820 |
|
828 | |||
821 | x = self.times |
|
829 | x = self.times | |
822 | xmin = self.min_time |
|
830 | xmin = self.min_time | |
823 | xmax = xmin + self.xrange * 60 * 60 |
|
831 | xmax = xmin + self.xrange * 60 * 60 | |
824 | Y = self.data[self.CODE] |
|
832 | Y = self.data[self.CODE] | |
825 |
|
833 | |||
826 | if self.axes[0].firsttime: |
|
834 | if self.axes[0].firsttime: | |
827 | for ch in self.data.channels: |
|
835 | for ch in self.data.channels: | |
828 | y = Y[ch] |
|
836 | y = Y[ch] | |
829 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
837 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
830 | plt.legend() |
|
838 | plt.legend() | |
831 | else: |
|
839 | else: | |
832 | for ch in self.data.channels: |
|
840 | for ch in self.data.channels: | |
833 | y = Y[ch] |
|
841 | y = Y[ch] | |
834 | self.axes[0].lines[ch].set_data(x, y) |
|
842 | self.axes[0].lines[ch].set_data(x, y) | |
835 |
|
843 | |||
836 | self.ymin = numpy.nanmin(Y) - 5 |
|
844 | self.ymin = numpy.nanmin(Y) - 5 | |
837 | self.ymax = numpy.nanmax(Y) + 5 |
|
845 | self.ymax = numpy.nanmax(Y) + 5 | |
838 | self.saveTime = self.min_time |
|
846 | self.saveTime = self.min_time | |
839 |
|
847 | |||
840 |
|
848 | |||
841 | class PlotSNRData(PlotRTIData): |
|
849 | class PlotSNRData(PlotRTIData): | |
842 | ''' |
|
850 | ''' | |
843 | Plot for SNR Data |
|
851 | Plot for SNR Data | |
844 | ''' |
|
852 | ''' | |
845 |
|
853 | |||
846 | CODE = 'snr' |
|
854 | CODE = 'snr' | |
847 | colormap = 'jet' |
|
855 | colormap = 'jet' | |
848 |
|
856 | |||
849 |
|
857 | |||
850 | class PlotDOPData(PlotRTIData): |
|
858 | class PlotDOPData(PlotRTIData): | |
851 | ''' |
|
859 | ''' | |
852 | Plot for DOPPLER Data |
|
860 | Plot for DOPPLER Data | |
853 | ''' |
|
861 | ''' | |
854 |
|
862 | |||
855 | CODE = 'dop' |
|
863 | CODE = 'dop' | |
856 | colormap = 'jet' |
|
864 | colormap = 'jet' | |
857 |
|
865 | |||
858 |
|
866 | |||
859 | class PlotSkyMapData(PlotData): |
|
867 | class PlotSkyMapData(PlotData): | |
860 | ''' |
|
868 | ''' | |
861 | Plot for meteors detection data |
|
869 | Plot for meteors detection data | |
862 | ''' |
|
870 | ''' | |
863 |
|
871 | |||
864 | CODE = 'param' |
|
872 | CODE = 'param' | |
865 |
|
873 | |||
866 | def setup(self): |
|
874 | def setup(self): | |
867 |
|
875 | |||
868 | self.ncols = 1 |
|
876 | self.ncols = 1 | |
869 | self.nrows = 1 |
|
877 | self.nrows = 1 | |
870 | self.width = 7.2 |
|
878 | self.width = 7.2 | |
871 | self.height = 7.2 |
|
879 | self.height = 7.2 | |
872 | self.nplots = 1 |
|
880 | self.nplots = 1 | |
873 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
881 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
874 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
882 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
875 | self.polar = True |
|
883 | self.polar = True | |
876 | self.ymin = -180 |
|
884 | self.ymin = -180 | |
877 | self.ymax = 180 |
|
885 | self.ymax = 180 | |
878 | self.colorbar = False |
|
886 | self.colorbar = False | |
879 |
|
887 | |||
880 | def plot(self): |
|
888 | def plot(self): | |
881 |
|
889 | |||
882 | arrayParameters = numpy.concatenate(self.data['param']) |
|
890 | arrayParameters = numpy.concatenate(self.data['param']) | |
883 | error = arrayParameters[:, -1] |
|
891 | error = arrayParameters[:, -1] | |
884 | indValid = numpy.where(error == 0)[0] |
|
892 | indValid = numpy.where(error == 0)[0] | |
885 | finalMeteor = arrayParameters[indValid, :] |
|
893 | finalMeteor = arrayParameters[indValid, :] | |
886 | finalAzimuth = finalMeteor[:, 3] |
|
894 | finalAzimuth = finalMeteor[:, 3] | |
887 | finalZenith = finalMeteor[:, 4] |
|
895 | finalZenith = finalMeteor[:, 4] | |
888 |
|
896 | |||
889 | x = finalAzimuth * numpy.pi / 180 |
|
897 | x = finalAzimuth * numpy.pi / 180 | |
890 | y = finalZenith |
|
898 | y = finalZenith | |
891 |
|
899 | |||
892 | ax = self.axes[0] |
|
900 | ax = self.axes[0] | |
893 |
|
901 | |||
894 | if ax.firsttime: |
|
902 | if ax.firsttime: | |
895 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
903 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
896 | else: |
|
904 | else: | |
897 | ax.plot.set_data(x, y) |
|
905 | ax.plot.set_data(x, y) | |
898 |
|
906 | |||
899 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
907 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
900 | dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
908 | dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
901 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
909 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
902 | dt2, |
|
910 | dt2, | |
903 | len(x)) |
|
911 | len(x)) | |
904 | self.titles[0] = title |
|
912 | self.titles[0] = title | |
905 | self.saveTime = self.max_time |
|
913 | self.saveTime = self.max_time | |
906 |
|
914 | |||
907 |
|
915 | |||
908 | class PlotParamData(PlotRTIData): |
|
916 | class PlotParamData(PlotRTIData): | |
909 | ''' |
|
917 | ''' | |
910 | Plot for data_param object |
|
918 | Plot for data_param object | |
911 | ''' |
|
919 | ''' | |
912 |
|
920 | |||
913 | CODE = 'param' |
|
921 | CODE = 'param' | |
914 | colormap = 'seismic' |
|
922 | colormap = 'seismic' | |
915 |
|
923 | |||
916 | def setup(self): |
|
924 | def setup(self): | |
917 | self.xaxis = 'time' |
|
925 | self.xaxis = 'time' | |
918 | self.ncols = 1 |
|
926 | self.ncols = 1 | |
919 | self.nrows = self.data.shape(self.CODE)[0] |
|
927 | self.nrows = self.data.shape(self.CODE)[0] | |
920 | self.nplots = self.nrows |
|
928 | self.nplots = self.nrows | |
921 | if self.showSNR: |
|
929 | if self.showSNR: | |
922 | self.nrows += 1 |
|
930 | self.nrows += 1 | |
923 | self.nplots += 1 |
|
931 | self.nplots += 1 | |
924 |
|
932 | |||
925 | self.ylabel = 'Height [km]' |
|
933 | self.ylabel = 'Height [km]' | |
926 | if not self.titles: |
|
934 | if not self.titles: | |
927 | self.titles = self.data.parameters \ |
|
935 | self.titles = self.data.parameters \ | |
928 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] |
|
936 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] | |
929 | if self.showSNR: |
|
937 | if self.showSNR: | |
930 | self.titles.append('SNR') |
|
938 | self.titles.append('SNR') | |
931 |
|
939 | |||
932 | def plot(self): |
|
940 | def plot(self): | |
933 | self.data.normalize_heights() |
|
941 | self.data.normalize_heights() | |
934 | self.x = self.times |
|
942 | self.x = self.times | |
935 | self.y = self.data.heights |
|
943 | self.y = self.data.heights | |
936 | if self.showSNR: |
|
944 | if self.showSNR: | |
937 | self.z = numpy.concatenate( |
|
945 | self.z = numpy.concatenate( | |
938 | (self.data[self.CODE], self.data['snr']) |
|
946 | (self.data[self.CODE], self.data['snr']) | |
939 | ) |
|
947 | ) | |
940 | else: |
|
948 | else: | |
941 | self.z = self.data[self.CODE] |
|
949 | self.z = self.data[self.CODE] | |
942 |
|
950 | |||
943 | self.z = numpy.ma.masked_invalid(self.z) |
|
951 | self.z = numpy.ma.masked_invalid(self.z) | |
944 |
|
952 | |||
945 | if self.decimation is None: |
|
953 | if self.decimation is None: | |
946 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
954 | x, y, z = self.fill_gaps(self.x, self.y, self.z) | |
947 | else: |
|
955 | else: | |
948 | x, y, z = self.fill_gaps(*self.decimate()) |
|
956 | x, y, z = self.fill_gaps(*self.decimate()) | |
949 |
|
957 | |||
950 | for n, ax in enumerate(self.axes): |
|
958 | for n, ax in enumerate(self.axes): | |
951 |
|
959 | |||
952 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
960 | self.zmax = self.zmax if self.zmax is not None else numpy.max( | |
953 | self.z[n]) |
|
961 | self.z[n]) | |
954 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
962 | self.zmin = self.zmin if self.zmin is not None else numpy.min( | |
955 | self.z[n]) |
|
963 | self.z[n]) | |
956 |
|
964 | |||
957 | if ax.firsttime: |
|
965 | if ax.firsttime: | |
958 | if self.zlimits is not None: |
|
966 | if self.zlimits is not None: | |
959 | self.zmin, self.zmax = self.zlimits[n] |
|
967 | self.zmin, self.zmax = self.zlimits[n] | |
960 |
|
968 | |||
961 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
969 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
962 | vmin=self.zmin, |
|
970 | vmin=self.zmin, | |
963 | vmax=self.zmax, |
|
971 | vmax=self.zmax, | |
964 | cmap=self.cmaps[n] |
|
972 | cmap=self.cmaps[n] | |
965 | ) |
|
973 | ) | |
966 | else: |
|
974 | else: | |
967 | if self.zlimits is not None: |
|
975 | if self.zlimits is not None: | |
968 | self.zmin, self.zmax = self.zlimits[n] |
|
976 | self.zmin, self.zmax = self.zlimits[n] | |
969 | ax.collections.remove(ax.collections[0]) |
|
977 | ax.collections.remove(ax.collections[0]) | |
970 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
978 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], | |
971 | vmin=self.zmin, |
|
979 | vmin=self.zmin, | |
972 | vmax=self.zmax, |
|
980 | vmax=self.zmax, | |
973 | cmap=self.cmaps[n] |
|
981 | cmap=self.cmaps[n] | |
974 | ) |
|
982 | ) | |
975 |
|
983 | |||
976 | self.saveTime = self.min_time |
|
984 | self.saveTime = self.min_time | |
977 |
|
985 | |||
978 |
|
986 | |||
979 | class PlotOutputData(PlotParamData): |
|
987 | class PlotOutputData(PlotParamData): | |
980 | ''' |
|
988 | ''' | |
981 | Plot data_output object |
|
989 | Plot data_output object | |
982 | ''' |
|
990 | ''' | |
983 |
|
991 | |||
984 | CODE = 'output' |
|
992 | CODE = 'output' | |
985 | colormap = 'seismic' |
|
993 | colormap = 'seismic' | |
986 |
|
994 | |||
987 |
|
995 | |||
988 | class PlotPolarMapData(PlotData): |
|
996 | class PlotPolarMapData(PlotData): | |
989 | ''' |
|
997 | ''' | |
990 | Plot for meteors detection data |
|
998 | Plot for meteors detection data | |
991 | ''' |
|
999 | ''' | |
992 |
|
1000 | |||
993 | CODE = 'param' |
|
1001 | CODE = 'param' | |
994 | colormap = 'seismic' |
|
1002 | colormap = 'seismic' | |
995 |
|
1003 | |||
996 | def setup(self): |
|
1004 | def setup(self): | |
997 | self.ncols = 1 |
|
1005 | self.ncols = 1 | |
998 | self.nrows = 1 |
|
1006 | self.nrows = 1 | |
999 | self.width = 9 |
|
1007 | self.width = 9 | |
1000 | self.height = 8 |
|
1008 | self.height = 8 | |
1001 | if self.channels is not None: |
|
1009 | if self.channels is not None: | |
1002 | self.nplots = len(self.channels) |
|
1010 | self.nplots = len(self.channels) | |
1003 | self.nrows = len(self.channels) |
|
1011 | self.nrows = len(self.channels) | |
1004 | else: |
|
1012 | else: | |
1005 | self.nplots = self.data.shape(self.CODE)[0] |
|
1013 | self.nplots = self.data.shape(self.CODE)[0] | |
1006 | self.nrows = self.nplots |
|
1014 | self.nrows = self.nplots | |
1007 | self.channels = range(self.nplots) |
|
1015 | self.channels = range(self.nplots) | |
1008 | if self.data.meta['mode'] == 'E': |
|
1016 | if self.data.meta['mode'] == 'E': | |
1009 | self.xlabel = 'Zonal Distance (km)' |
|
1017 | self.xlabel = 'Zonal Distance (km)' | |
1010 | self.ylabel = 'Meridional Distance (km)' |
|
1018 | self.ylabel = 'Meridional Distance (km)' | |
1011 | else: |
|
1019 | else: | |
1012 | self.xlabel = 'Range (km)' |
|
1020 | self.xlabel = 'Range (km)' | |
1013 | self.ylabel = 'Height (km)' |
|
1021 | self.ylabel = 'Height (km)' | |
1014 | self.bgcolor = 'white' |
|
1022 | self.bgcolor = 'white' | |
1015 | self.cb_labels = self.data.meta['units'] |
|
1023 | self.cb_labels = self.data.meta['units'] | |
1016 | # self.polar = True |
|
1024 | # self.polar = True | |
1017 |
|
1025 | |||
1018 | def plot(self): |
|
1026 | def plot(self): | |
1019 |
|
1027 | |||
1020 | for n, ax in enumerate(self.axes): |
|
1028 | for n, ax in enumerate(self.axes): | |
1021 | data = self.data['param'][self.channels[n]] |
|
1029 | data = self.data['param'][self.channels[n]] | |
1022 |
|
1030 | |||
1023 | zeniths = numpy.linspace(0, self.data.meta['max_range'], data.shape[1]) |
|
1031 | zeniths = numpy.linspace(0, self.data.meta['max_range'], data.shape[1]) | |
1024 | if self.data.meta['mode'] == 'E': |
|
1032 | if self.data.meta['mode'] == 'E': | |
1025 | azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 |
|
1033 | azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 | |
1026 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
1034 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
1027 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) |
|
1035 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
1028 | else: |
|
1036 | else: | |
1029 | azimuths = numpy.radians(self.data.heights) |
|
1037 | azimuths = numpy.radians(self.data.heights) | |
1030 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
1038 | r, theta = numpy.meshgrid(zeniths, azimuths) | |
1031 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
1039 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) | |
1032 | self.y = zeniths |
|
1040 | self.y = zeniths | |
1033 |
|
1041 | |||
1034 | if ax.firsttime: |
|
1042 | if ax.firsttime: | |
1035 | if self.zlimits is not None: |
|
1043 | if self.zlimits is not None: | |
1036 | self.zmin, self.zmax = self.zlimits[n] |
|
1044 | self.zmin, self.zmax = self.zlimits[n] | |
1037 | ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
1045 | ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
1038 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
1046 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
1039 | vmin=self.zmin, |
|
1047 | vmin=self.zmin, | |
1040 | vmax=self.zmax, |
|
1048 | vmax=self.zmax, | |
1041 | cmap=self.cmaps[n]) |
|
1049 | cmap=self.cmaps[n]) | |
1042 | else: |
|
1050 | else: | |
1043 | if self.zlimits is not None: |
|
1051 | if self.zlimits is not None: | |
1044 | self.zmin, self.zmax = self.zlimits[n] |
|
1052 | self.zmin, self.zmax = self.zlimits[n] | |
1045 | ax.collections.remove(ax.collections[0]) |
|
1053 | ax.collections.remove(ax.collections[0]) | |
1046 | ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
1054 | ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
1047 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), |
|
1055 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
1048 | vmin=self.zmin, |
|
1056 | vmin=self.zmin, | |
1049 | vmax=self.zmax, |
|
1057 | vmax=self.zmax, | |
1050 | cmap=self.cmaps[n]) |
|
1058 | cmap=self.cmaps[n]) | |
1051 |
|
1059 | |||
1052 | if self.data.meta['mode'] == 'A': |
|
1060 | if self.data.meta['mode'] == 'A': | |
1053 | continue |
|
1061 | continue | |
1054 |
|
|
1062 | ||
1055 |
f = open('/ |
|
1063 | f = open('/home/jespinoza/workspace/schain_scripts/distrito.csv') | |
1056 |
|
1064 | |||
1057 | lat1 = -11.96 |
|
1065 | lat1 = -11.96 | |
1058 | lon1 = -76.54 |
|
1066 | lon1 = -76.54 | |
1059 |
|
1067 | |||
1060 | for line in f: |
|
1068 | for line in f: | |
1061 |
label, |
|
1069 | label, lon, lat = [s.strip() for s in line.split(',') if s] | |
1062 |
lat |
|
1070 | lat = float(lat) | |
1063 |
lon |
|
1071 | lon = float(lon) | |
1064 |
|
1072 | x, y = ll2xy(lat1, lon1, lat, lon) | ||
1065 | dx = (lon2-lon1)*40000*numpy.cos((lat1+lat2)*numpy.pi/360)/360 |
|
1073 | ax.plot(x, y, '.b', ms=2) | |
1066 | dy = (lat1-lat2)*40000/360 |
|
1074 | ax.text(x, y, label.decode('utf8'), ha='center', va='bottom', size='8', color='black') | |
1067 | print label, dx, dy |
|
1075 | ||
1068 | if label == 'map': |
|
1076 | ||
1069 | print 'SDHSDHSDHSGHSDFHSDF' |
|
|||
1070 | ax.plot([dx], [dy],'--k') |
|
|||
1071 | else: |
|
|||
1072 | ax.plot([dx], [dy],'.b', ms=2) |
|
|||
1073 | ''' |
|
|||
1074 | if self.data.meta['mode'] == 'E': |
|
1077 | if self.data.meta['mode'] == 'E': | |
1075 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
1078 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) | |
1076 | label = 'E{:d}'.format(int(self.data.meta['elevation'])) |
|
1079 | label = 'E{:d}'.format(int(self.data.meta['elevation'])) | |
1077 | else: |
|
1080 | else: | |
1078 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
1081 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) | |
1079 | label = 'A{:d}'.format(int(self.data.meta['azimuth'])) |
|
1082 | label = 'A{:d}'.format(int(self.data.meta['azimuth'])) | |
1080 |
|
1083 | |||
1081 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] |
|
1084 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
1082 | self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels] |
|
1085 | self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels] | |
1083 | self.saveTime = self.max_time |
|
1086 | self.saveTime = self.max_time | |
1084 |
|
1087 | |||
1085 |
|
1088 |
General Comments 0
You need to be logged in to leave comments.
Login now