@@ -1,707 +1,709 | |||||
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 |
|
8 | import matplotlib | |
9 | matplotlib.use('TkAgg') |
|
9 | matplotlib.use('TkAgg') | |
10 | import matplotlib.pyplot as plt |
|
10 | import matplotlib.pyplot as plt | |
11 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
11 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
12 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
12 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
13 | from multiprocessing import Process |
|
13 | from multiprocessing import Process | |
14 |
|
14 | |||
15 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
16 |
|
16 | |||
17 |
plt.io |
|
17 | plt.ion() | |
18 |
|
18 | |||
19 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
19 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | |
20 |
|
20 | |||
21 | d1970 = datetime.datetime(1970,1,1) |
|
21 | d1970 = datetime.datetime(1970,1,1) | |
22 |
|
22 | |||
23 | class PlotData(Operation, Process): |
|
23 | class PlotData(Operation, Process): | |
24 |
|
24 | |||
25 | CODE = 'Figure' |
|
25 | CODE = 'Figure' | |
26 | colormap = 'jro' |
|
26 | colormap = 'jro' | |
27 | CONFLATE = False |
|
27 | CONFLATE = False | |
28 | __MAXNUMX = 80 |
|
28 | __MAXNUMX = 80 | |
29 | __missing = 1E30 |
|
29 | __missing = 1E30 | |
30 |
|
30 | |||
31 | def __init__(self, **kwargs): |
|
31 | def __init__(self, **kwargs): | |
32 |
|
32 | |||
33 | Operation.__init__(self, plot=True, **kwargs) |
|
33 | Operation.__init__(self, plot=True, **kwargs) | |
34 | Process.__init__(self) |
|
34 | Process.__init__(self) | |
35 | self.kwargs['code'] = self.CODE |
|
35 | self.kwargs['code'] = self.CODE | |
36 | self.mp = False |
|
36 | self.mp = False | |
37 | self.dataOut = None |
|
37 | self.dataOut = None | |
38 | self.isConfig = False |
|
38 | self.isConfig = False | |
39 | self.figure = None |
|
39 | self.figure = None | |
40 | self.axes = [] |
|
40 | self.axes = [] | |
41 | self.localtime = kwargs.pop('localtime', True) |
|
41 | self.localtime = kwargs.pop('localtime', True) | |
42 | self.show = kwargs.get('show', True) |
|
42 | self.show = kwargs.get('show', True) | |
43 | self.save = kwargs.get('save', False) |
|
43 | self.save = kwargs.get('save', False) | |
44 | self.colormap = kwargs.get('colormap', self.colormap) |
|
44 | self.colormap = kwargs.get('colormap', self.colormap) | |
45 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
45 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
46 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
46 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
47 | self.showprofile = kwargs.get('showprofile', True) |
|
47 | self.showprofile = kwargs.get('showprofile', True) | |
48 | self.title = kwargs.get('wintitle', '') |
|
48 | self.title = kwargs.get('wintitle', '') | |
49 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
49 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
50 | self.zmin = kwargs.get('zmin', None) |
|
50 | self.zmin = kwargs.get('zmin', None) | |
51 | self.zmax = kwargs.get('zmax', None) |
|
51 | self.zmax = kwargs.get('zmax', None) | |
52 | self.xmin = kwargs.get('xmin', None) |
|
52 | self.xmin = kwargs.get('xmin', None) | |
53 | self.xmax = kwargs.get('xmax', None) |
|
53 | self.xmax = kwargs.get('xmax', None) | |
54 | self.xrange = kwargs.get('xrange', 24) |
|
54 | self.xrange = kwargs.get('xrange', 24) | |
55 | self.ymin = kwargs.get('ymin', None) |
|
55 | self.ymin = kwargs.get('ymin', None) | |
56 | self.ymax = kwargs.get('ymax', None) |
|
56 | self.ymax = kwargs.get('ymax', None) | |
57 | self.__MAXNUMY = kwargs.get('decimation', 80) |
|
57 | self.__MAXNUMY = kwargs.get('decimation', 80) | |
58 | self.throttle_value = 5 |
|
58 | self.throttle_value = 5 | |
59 | self.times = [] |
|
59 | self.times = [] | |
|
60 | #self.interactive = self.kwargs['parent'] | |||
|
61 | ||||
60 |
|
62 | |||
61 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
63 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
62 |
|
64 | |||
63 | if x_buffer.shape[0] < 2: |
|
65 | if x_buffer.shape[0] < 2: | |
64 | return x_buffer, y_buffer, z_buffer |
|
66 | return x_buffer, y_buffer, z_buffer | |
65 |
|
67 | |||
66 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
68 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
67 | x_median = np.median(deltas) |
|
69 | x_median = np.median(deltas) | |
68 |
|
70 | |||
69 | index = np.where(deltas > 5*x_median) |
|
71 | index = np.where(deltas > 5*x_median) | |
70 |
|
72 | |||
71 | if len(index[0]) != 0: |
|
73 | if len(index[0]) != 0: | |
72 | z_buffer[::, index[0], ::] = self.__missing |
|
74 | z_buffer[::, index[0], ::] = self.__missing | |
73 | z_buffer = np.ma.masked_inside(z_buffer, |
|
75 | z_buffer = np.ma.masked_inside(z_buffer, | |
74 | 0.99*self.__missing, |
|
76 | 0.99*self.__missing, | |
75 | 1.01*self.__missing) |
|
77 | 1.01*self.__missing) | |
76 |
|
78 | |||
77 | return x_buffer, y_buffer, z_buffer |
|
79 | return x_buffer, y_buffer, z_buffer | |
78 |
|
80 | |||
79 | def decimate(self): |
|
81 | def decimate(self): | |
80 |
|
82 | |||
81 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
83 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
82 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
84 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
83 |
|
85 | |||
84 | # x = self.x[::dx] |
|
86 | # x = self.x[::dx] | |
85 | x = self.x |
|
87 | x = self.x | |
86 | y = self.y[::dy] |
|
88 | y = self.y[::dy] | |
87 | z = self.z[::, ::, ::dy] |
|
89 | z = self.z[::, ::, ::dy] | |
88 |
|
90 | |||
89 | return x, y, z |
|
91 | return x, y, z | |
90 |
|
92 | |||
91 | def __plot(self): |
|
93 | def __plot(self): | |
92 |
|
94 | |||
93 | print 'plotting...{}'.format(self.CODE) |
|
95 | print 'plotting...{}'.format(self.CODE) | |
94 |
|
96 | |||
95 | if self.show: |
|
97 | if self.show: | |
96 | print 'showing' |
|
98 | print 'showing' | |
97 | self.figure.show() |
|
99 | self.figure.show() | |
98 |
|
100 | |||
99 | self.plot() |
|
101 | self.plot() | |
100 | plt.tight_layout() |
|
102 | plt.tight_layout() | |
101 | self.figure.canvas.manager.set_window_title('{} {} - Date:{}'.format(self.title, self.CODE.upper(), |
|
103 | self.figure.canvas.manager.set_window_title('{} {} - Date:{}'.format(self.title, self.CODE.upper(), | |
102 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S'))) |
|
104 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S'))) | |
103 |
|
105 | |||
104 | if self.save: |
|
106 | if self.save: | |
105 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
107 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
106 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
108 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
107 | print 'Saving figure: {}'.format(figname) |
|
109 | print 'Saving figure: {}'.format(figname) | |
108 | self.figure.savefig(figname) |
|
110 | self.figure.savefig(figname) | |
109 |
|
111 | |||
110 | self.figure.canvas.draw() |
|
112 | self.figure.canvas.draw() | |
111 |
|
113 | |||
112 | def plot(self): |
|
114 | def plot(self): | |
113 |
|
115 | |||
114 | print 'plotting...{}'.format(self.CODE.upper()) |
|
116 | print 'plotting...{}'.format(self.CODE.upper()) | |
115 | return |
|
117 | return | |
116 |
|
118 | |||
117 | def run(self): |
|
119 | def run(self): | |
118 |
|
120 | |||
119 | print '[Starting] {}'.format(self.name) |
|
121 | print '[Starting] {}'.format(self.name) | |
120 | context = zmq.Context() |
|
122 | context = zmq.Context() | |
121 | receiver = context.socket(zmq.SUB) |
|
123 | receiver = context.socket(zmq.SUB) | |
122 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
124 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
123 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
125 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
124 | receiver.connect("ipc:///tmp/zmq.plots") |
|
126 | receiver.connect("ipc:///tmp/zmq.plots") | |
125 | seconds_passed = 0 |
|
127 | seconds_passed = 0 | |
126 | while True: |
|
128 | while True: | |
127 | try: |
|
129 | try: | |
128 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK |
|
130 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK | |
129 | self.started = self.data['STARTED'] |
|
131 | self.started = self.data['STARTED'] | |
130 | self.dataOut = self.data['dataOut'] |
|
132 | self.dataOut = self.data['dataOut'] | |
131 |
|
133 | |||
132 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): |
|
134 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): | |
133 | continue |
|
135 | continue | |
134 |
|
136 | |||
135 | self.times = self.data['times'] |
|
137 | self.times = self.data['times'] | |
136 | self.times.sort() |
|
138 | self.times.sort() | |
137 | self.throttle_value = self.data['throttle'] |
|
139 | self.throttle_value = self.data['throttle'] | |
138 | self.min_time = self.times[0] |
|
140 | self.min_time = self.times[0] | |
139 | self.max_time = self.times[-1] |
|
141 | self.max_time = self.times[-1] | |
140 |
|
142 | |||
141 | if self.isConfig is False: |
|
143 | if self.isConfig is False: | |
142 | print 'setting up' |
|
144 | print 'setting up' | |
143 | self.setup() |
|
145 | self.setup() | |
144 | self.isConfig = True |
|
146 | self.isConfig = True | |
145 | self.__plot() |
|
147 | self.__plot() | |
146 |
|
148 | |||
147 | if self.data['ENDED'] is True: |
|
149 | if self.data['ENDED'] is True: | |
148 | print '********GRAPHIC ENDED********' |
|
150 | print '********GRAPHIC ENDED********' | |
149 | self.ended = True |
|
151 | self.ended = True | |
150 | self.isConfig = False |
|
152 | self.isConfig = False | |
151 | self.__plot() |
|
153 | self.__plot() | |
152 | elif seconds_passed >= self.data['throttle']: |
|
154 | elif seconds_passed >= self.data['throttle']: | |
153 | print 'passed', seconds_passed |
|
155 | print 'passed', seconds_passed | |
154 | self.__plot() |
|
156 | self.__plot() | |
155 | seconds_passed = 0 |
|
157 | seconds_passed = 0 | |
156 |
|
158 | |||
157 | except zmq.Again as e: |
|
159 | except zmq.Again as e: | |
158 | print 'Waiting for data...' |
|
160 | print 'Waiting for data...' | |
159 | plt.pause(2) |
|
161 | plt.pause(2) | |
160 | seconds_passed += 2 |
|
162 | seconds_passed += 2 | |
161 |
|
163 | |||
162 | def close(self): |
|
164 | def close(self): | |
163 | if self.dataOut: |
|
165 | if self.dataOut: | |
164 | self.__plot() |
|
166 | self.__plot() | |
165 |
|
167 | |||
166 |
|
168 | |||
167 | class PlotSpectraData(PlotData): |
|
169 | class PlotSpectraData(PlotData): | |
168 |
|
170 | |||
169 | CODE = 'spc' |
|
171 | CODE = 'spc' | |
170 | colormap = 'jro' |
|
172 | colormap = 'jro' | |
171 | CONFLATE = False |
|
173 | CONFLATE = False | |
172 |
|
174 | |||
173 | def setup(self): |
|
175 | def setup(self): | |
174 |
|
176 | |||
175 | ncolspan = 1 |
|
177 | ncolspan = 1 | |
176 | colspan = 1 |
|
178 | colspan = 1 | |
177 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
179 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) | |
178 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
180 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) | |
179 | self.width = 3.6*self.ncols |
|
181 | self.width = 3.6*self.ncols | |
180 | self.height = 3.2*self.nrows |
|
182 | self.height = 3.2*self.nrows | |
181 | if self.showprofile: |
|
183 | if self.showprofile: | |
182 | ncolspan = 3 |
|
184 | ncolspan = 3 | |
183 | colspan = 2 |
|
185 | colspan = 2 | |
184 | self.width += 1.2*self.ncols |
|
186 | self.width += 1.2*self.ncols | |
185 |
|
187 | |||
186 | self.ylabel = 'Range [Km]' |
|
188 | self.ylabel = 'Range [Km]' | |
187 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
189 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
188 |
|
190 | |||
189 | if self.figure is None: |
|
191 | if self.figure is None: | |
190 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
192 | self.figure = plt.figure(figsize=(self.width, self.height), | |
191 | edgecolor='k', |
|
193 | edgecolor='k', | |
192 | facecolor='w') |
|
194 | facecolor='w') | |
193 | else: |
|
195 | else: | |
194 | self.figure.clf() |
|
196 | self.figure.clf() | |
195 |
|
197 | |||
196 | n = 0 |
|
198 | n = 0 | |
197 | for y in range(self.nrows): |
|
199 | for y in range(self.nrows): | |
198 | for x in range(self.ncols): |
|
200 | for x in range(self.ncols): | |
199 | if n >= self.dataOut.nChannels: |
|
201 | if n >= self.dataOut.nChannels: | |
200 | break |
|
202 | break | |
201 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
203 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) | |
202 | if self.showprofile: |
|
204 | if self.showprofile: | |
203 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
205 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) | |
204 |
|
206 | |||
205 | ax.firsttime = True |
|
207 | ax.firsttime = True | |
206 | self.axes.append(ax) |
|
208 | self.axes.append(ax) | |
207 | n += 1 |
|
209 | n += 1 | |
208 |
|
210 | |||
209 | def plot(self): |
|
211 | def plot(self): | |
210 |
|
212 | |||
211 | if self.xaxis == "frequency": |
|
213 | if self.xaxis == "frequency": | |
212 | x = self.dataOut.getFreqRange(1)/1000. |
|
214 | x = self.dataOut.getFreqRange(1)/1000. | |
213 | xlabel = "Frequency (kHz)" |
|
215 | xlabel = "Frequency (kHz)" | |
214 | elif self.xaxis == "time": |
|
216 | elif self.xaxis == "time": | |
215 | x = self.dataOut.getAcfRange(1) |
|
217 | x = self.dataOut.getAcfRange(1) | |
216 | xlabel = "Time (ms)" |
|
218 | xlabel = "Time (ms)" | |
217 | else: |
|
219 | else: | |
218 | x = self.dataOut.getVelRange(1) |
|
220 | x = self.dataOut.getVelRange(1) | |
219 | xlabel = "Velocity (m/s)" |
|
221 | xlabel = "Velocity (m/s)" | |
220 |
|
222 | |||
221 | y = self.dataOut.getHeiRange() |
|
223 | y = self.dataOut.getHeiRange() | |
222 | z = self.data[self.CODE] |
|
224 | z = self.data[self.CODE] | |
223 |
|
225 | |||
224 | for n, ax in enumerate(self.axes): |
|
226 | for n, ax in enumerate(self.axes): | |
225 |
|
227 | |||
226 | if ax.firsttime: |
|
228 | if ax.firsttime: | |
227 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
229 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
228 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
230 | self.xmin = self.xmin if self.xmin else -self.xmax | |
229 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
231 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
230 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
232 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
231 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
233 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
232 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
234 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
233 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
235 | ax.plot = ax.pcolormesh(x, y, z[n].T, | |
234 | vmin=self.zmin, |
|
236 | vmin=self.zmin, | |
235 | vmax=self.zmax, |
|
237 | vmax=self.zmax, | |
236 | cmap=plt.get_cmap(self.colormap) |
|
238 | cmap=plt.get_cmap(self.colormap) | |
237 | ) |
|
239 | ) | |
238 | divider = make_axes_locatable(ax) |
|
240 | divider = make_axes_locatable(ax) | |
239 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
241 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
240 | self.figure.add_axes(cax) |
|
242 | self.figure.add_axes(cax) | |
241 | plt.colorbar(ax.plot, cax) |
|
243 | plt.colorbar(ax.plot, cax) | |
242 |
|
244 | |||
243 | ax.set_xlim(self.xmin, self.xmax) |
|
245 | ax.set_xlim(self.xmin, self.xmax) | |
244 | ax.set_ylim(self.ymin, self.ymax) |
|
246 | ax.set_ylim(self.ymin, self.ymax) | |
245 |
|
247 | |||
246 | ax.set_ylabel(self.ylabel) |
|
248 | ax.set_ylabel(self.ylabel) | |
247 | ax.set_xlabel(xlabel) |
|
249 | ax.set_xlabel(xlabel) | |
248 |
|
250 | |||
249 | ax.firsttime = False |
|
251 | ax.firsttime = False | |
250 |
|
252 | |||
251 | if self.showprofile: |
|
253 | if self.showprofile: | |
252 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
254 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
253 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
255 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
254 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
256 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
255 | ax.ax_profile.set_xlabel('dB') |
|
257 | ax.ax_profile.set_xlabel('dB') | |
256 | ax.ax_profile.grid(b=True, axis='x') |
|
258 | ax.ax_profile.grid(b=True, axis='x') | |
257 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
259 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
258 | color="k", linestyle="dashed", lw=2)[0] |
|
260 | color="k", linestyle="dashed", lw=2)[0] | |
259 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
261 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
260 | else: |
|
262 | else: | |
261 | ax.plot.set_array(z[n].T.ravel()) |
|
263 | ax.plot.set_array(z[n].T.ravel()) | |
262 | if self.showprofile: |
|
264 | if self.showprofile: | |
263 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
265 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) | |
264 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
266 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
265 |
|
267 | |||
266 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
268 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
267 | size=8) |
|
269 | size=8) | |
268 | self.saveTime = self.max_time |
|
270 | self.saveTime = self.max_time | |
269 |
|
271 | |||
270 |
|
272 | |||
271 | class PlotCrossSpectraData(PlotData): |
|
273 | class PlotCrossSpectraData(PlotData): | |
272 |
|
274 | |||
273 | CODE = 'cspc' |
|
275 | CODE = 'cspc' | |
274 | zmin_coh = None |
|
276 | zmin_coh = None | |
275 | zmax_coh = None |
|
277 | zmax_coh = None | |
276 | zmin_phase = None |
|
278 | zmin_phase = None | |
277 | zmax_phase = None |
|
279 | zmax_phase = None | |
278 | CONFLATE = False |
|
280 | CONFLATE = False | |
279 |
|
281 | |||
280 | def setup(self): |
|
282 | def setup(self): | |
281 |
|
283 | |||
282 | ncolspan = 1 |
|
284 | ncolspan = 1 | |
283 | colspan = 1 |
|
285 | colspan = 1 | |
284 | self.ncols = 2 |
|
286 | self.ncols = 2 | |
285 | self.nrows = self.dataOut.nPairs |
|
287 | self.nrows = self.dataOut.nPairs | |
286 | self.width = 3.6*self.ncols |
|
288 | self.width = 3.6*self.ncols | |
287 | self.height = 3.2*self.nrows |
|
289 | self.height = 3.2*self.nrows | |
288 |
|
290 | |||
289 | self.ylabel = 'Range [Km]' |
|
291 | self.ylabel = 'Range [Km]' | |
290 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
292 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
291 |
|
293 | |||
292 | if self.figure is None: |
|
294 | if self.figure is None: | |
293 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
295 | self.figure = plt.figure(figsize=(self.width, self.height), | |
294 | edgecolor='k', |
|
296 | edgecolor='k', | |
295 | facecolor='w') |
|
297 | facecolor='w') | |
296 | else: |
|
298 | else: | |
297 | self.figure.clf() |
|
299 | self.figure.clf() | |
298 |
|
300 | |||
299 | for y in range(self.nrows): |
|
301 | for y in range(self.nrows): | |
300 | for x in range(self.ncols): |
|
302 | for x in range(self.ncols): | |
301 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
303 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) | |
302 | ax.firsttime = True |
|
304 | ax.firsttime = True | |
303 | self.axes.append(ax) |
|
305 | self.axes.append(ax) | |
304 |
|
306 | |||
305 | def plot(self): |
|
307 | def plot(self): | |
306 |
|
308 | |||
307 | if self.xaxis == "frequency": |
|
309 | if self.xaxis == "frequency": | |
308 | x = self.dataOut.getFreqRange(1)/1000. |
|
310 | x = self.dataOut.getFreqRange(1)/1000. | |
309 | xlabel = "Frequency (kHz)" |
|
311 | xlabel = "Frequency (kHz)" | |
310 | elif self.xaxis == "time": |
|
312 | elif self.xaxis == "time": | |
311 | x = self.dataOut.getAcfRange(1) |
|
313 | x = self.dataOut.getAcfRange(1) | |
312 | xlabel = "Time (ms)" |
|
314 | xlabel = "Time (ms)" | |
313 | else: |
|
315 | else: | |
314 | x = self.dataOut.getVelRange(1) |
|
316 | x = self.dataOut.getVelRange(1) | |
315 | xlabel = "Velocity (m/s)" |
|
317 | xlabel = "Velocity (m/s)" | |
316 |
|
318 | |||
317 | y = self.dataOut.getHeiRange() |
|
319 | y = self.dataOut.getHeiRange() | |
318 | z_coh = self.data['cspc_coh'] |
|
320 | z_coh = self.data['cspc_coh'] | |
319 | z_phase = self.data['cspc_phase'] |
|
321 | z_phase = self.data['cspc_phase'] | |
320 |
|
322 | |||
321 | for n in range(self.nrows): |
|
323 | for n in range(self.nrows): | |
322 | ax = self.axes[2*n] |
|
324 | ax = self.axes[2*n] | |
323 | ax1 = self.axes[2*n+1] |
|
325 | ax1 = self.axes[2*n+1] | |
324 | if ax.firsttime: |
|
326 | if ax.firsttime: | |
325 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
327 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
326 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
328 | self.xmin = self.xmin if self.xmin else -self.xmax | |
327 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
329 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
328 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
330 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
329 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
331 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 | |
330 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
332 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 | |
331 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
333 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 | |
332 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
334 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 | |
333 |
|
335 | |||
334 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
336 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, | |
335 | vmin=self.zmin_coh, |
|
337 | vmin=self.zmin_coh, | |
336 | vmax=self.zmax_coh, |
|
338 | vmax=self.zmax_coh, | |
337 | cmap=plt.get_cmap(self.colormap_coh) |
|
339 | cmap=plt.get_cmap(self.colormap_coh) | |
338 | ) |
|
340 | ) | |
339 | divider = make_axes_locatable(ax) |
|
341 | divider = make_axes_locatable(ax) | |
340 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
342 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
341 | self.figure.add_axes(cax) |
|
343 | self.figure.add_axes(cax) | |
342 | plt.colorbar(ax.plot, cax) |
|
344 | plt.colorbar(ax.plot, cax) | |
343 |
|
345 | |||
344 | ax.set_xlim(self.xmin, self.xmax) |
|
346 | ax.set_xlim(self.xmin, self.xmax) | |
345 | ax.set_ylim(self.ymin, self.ymax) |
|
347 | ax.set_ylim(self.ymin, self.ymax) | |
346 |
|
348 | |||
347 | ax.set_ylabel(self.ylabel) |
|
349 | ax.set_ylabel(self.ylabel) | |
348 | ax.set_xlabel(xlabel) |
|
350 | ax.set_xlabel(xlabel) | |
349 | ax.firsttime = False |
|
351 | ax.firsttime = False | |
350 |
|
352 | |||
351 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
353 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, | |
352 | vmin=self.zmin_phase, |
|
354 | vmin=self.zmin_phase, | |
353 | vmax=self.zmax_phase, |
|
355 | vmax=self.zmax_phase, | |
354 | cmap=plt.get_cmap(self.colormap_phase) |
|
356 | cmap=plt.get_cmap(self.colormap_phase) | |
355 | ) |
|
357 | ) | |
356 | divider = make_axes_locatable(ax1) |
|
358 | divider = make_axes_locatable(ax1) | |
357 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
359 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
358 | self.figure.add_axes(cax) |
|
360 | self.figure.add_axes(cax) | |
359 | plt.colorbar(ax1.plot, cax) |
|
361 | plt.colorbar(ax1.plot, cax) | |
360 |
|
362 | |||
361 | ax1.set_xlim(self.xmin, self.xmax) |
|
363 | ax1.set_xlim(self.xmin, self.xmax) | |
362 | ax1.set_ylim(self.ymin, self.ymax) |
|
364 | ax1.set_ylim(self.ymin, self.ymax) | |
363 |
|
365 | |||
364 | ax1.set_ylabel(self.ylabel) |
|
366 | ax1.set_ylabel(self.ylabel) | |
365 | ax1.set_xlabel(xlabel) |
|
367 | ax1.set_xlabel(xlabel) | |
366 | ax1.firsttime = False |
|
368 | ax1.firsttime = False | |
367 | else: |
|
369 | else: | |
368 | ax.plot.set_array(z_coh[n].T.ravel()) |
|
370 | ax.plot.set_array(z_coh[n].T.ravel()) | |
369 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
371 | ax1.plot.set_array(z_phase[n].T.ravel()) | |
370 |
|
372 | |||
371 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
373 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
372 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
374 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
373 | self.saveTime = self.max_time |
|
375 | self.saveTime = self.max_time | |
374 |
|
376 | |||
375 |
|
377 | |||
376 | class PlotSpectraMeanData(PlotSpectraData): |
|
378 | class PlotSpectraMeanData(PlotSpectraData): | |
377 |
|
379 | |||
378 | CODE = 'spc_mean' |
|
380 | CODE = 'spc_mean' | |
379 | colormap = 'jet' |
|
381 | colormap = 'jet' | |
380 |
|
382 | |||
381 | def plot(self): |
|
383 | def plot(self): | |
382 |
|
384 | |||
383 | if self.xaxis == "frequency": |
|
385 | if self.xaxis == "frequency": | |
384 | x = self.dataOut.getFreqRange(1)/1000. |
|
386 | x = self.dataOut.getFreqRange(1)/1000. | |
385 | xlabel = "Frequency (kHz)" |
|
387 | xlabel = "Frequency (kHz)" | |
386 | elif self.xaxis == "time": |
|
388 | elif self.xaxis == "time": | |
387 | x = self.dataOut.getAcfRange(1) |
|
389 | x = self.dataOut.getAcfRange(1) | |
388 | xlabel = "Time (ms)" |
|
390 | xlabel = "Time (ms)" | |
389 | else: |
|
391 | else: | |
390 | x = self.dataOut.getVelRange(1) |
|
392 | x = self.dataOut.getVelRange(1) | |
391 | xlabel = "Velocity (m/s)" |
|
393 | xlabel = "Velocity (m/s)" | |
392 |
|
394 | |||
393 | y = self.dataOut.getHeiRange() |
|
395 | y = self.dataOut.getHeiRange() | |
394 | z = self.data['spc'] |
|
396 | z = self.data['spc'] | |
395 | mean = self.data['mean'][self.max_time] |
|
397 | mean = self.data['mean'][self.max_time] | |
396 |
|
398 | |||
397 | for n, ax in enumerate(self.axes): |
|
399 | for n, ax in enumerate(self.axes): | |
398 |
|
400 | |||
399 | if ax.firsttime: |
|
401 | if ax.firsttime: | |
400 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
402 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
401 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
403 | self.xmin = self.xmin if self.xmin else -self.xmax | |
402 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
404 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
403 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
405 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
404 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
406 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
405 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
407 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
406 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
408 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
407 | vmin=self.zmin, |
|
409 | vmin=self.zmin, | |
408 | vmax=self.zmax, |
|
410 | vmax=self.zmax, | |
409 | cmap=plt.get_cmap(self.colormap) |
|
411 | cmap=plt.get_cmap(self.colormap) | |
410 | ) |
|
412 | ) | |
411 | ax.plt_dop = ax.plot(mean[n], y, |
|
413 | ax.plt_dop = ax.plot(mean[n], y, | |
412 | color='k')[0] |
|
414 | color='k')[0] | |
413 |
|
415 | |||
414 | divider = make_axes_locatable(ax) |
|
416 | divider = make_axes_locatable(ax) | |
415 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
417 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
416 | self.figure.add_axes(cax) |
|
418 | self.figure.add_axes(cax) | |
417 | plt.colorbar(ax.plt, cax) |
|
419 | plt.colorbar(ax.plt, cax) | |
418 |
|
420 | |||
419 | ax.set_xlim(self.xmin, self.xmax) |
|
421 | ax.set_xlim(self.xmin, self.xmax) | |
420 | ax.set_ylim(self.ymin, self.ymax) |
|
422 | ax.set_ylim(self.ymin, self.ymax) | |
421 |
|
423 | |||
422 | ax.set_ylabel(self.ylabel) |
|
424 | ax.set_ylabel(self.ylabel) | |
423 | ax.set_xlabel(xlabel) |
|
425 | ax.set_xlabel(xlabel) | |
424 |
|
426 | |||
425 | ax.firsttime = False |
|
427 | ax.firsttime = False | |
426 |
|
428 | |||
427 | if self.showprofile: |
|
429 | if self.showprofile: | |
428 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
430 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
429 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
431 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
430 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
432 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
431 | ax.ax_profile.set_xlabel('dB') |
|
433 | ax.ax_profile.set_xlabel('dB') | |
432 | ax.ax_profile.grid(b=True, axis='x') |
|
434 | ax.ax_profile.grid(b=True, axis='x') | |
433 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
435 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
434 | color="k", linestyle="dashed", lw=2)[0] |
|
436 | color="k", linestyle="dashed", lw=2)[0] | |
435 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
437 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
436 | else: |
|
438 | else: | |
437 | ax.plt.set_array(z[n].T.ravel()) |
|
439 | ax.plt.set_array(z[n].T.ravel()) | |
438 | ax.plt_dop.set_data(mean[n], y) |
|
440 | ax.plt_dop.set_data(mean[n], y) | |
439 | if self.showprofile: |
|
441 | if self.showprofile: | |
440 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
442 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) | |
441 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
443 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
442 |
|
444 | |||
443 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
445 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
444 | size=8) |
|
446 | size=8) | |
445 | self.saveTime = self.max_time |
|
447 | self.saveTime = self.max_time | |
446 |
|
448 | |||
447 |
|
449 | |||
448 | class PlotRTIData(PlotData): |
|
450 | class PlotRTIData(PlotData): | |
449 |
|
451 | |||
450 | CODE = 'rti' |
|
452 | CODE = 'rti' | |
451 | colormap = 'jro' |
|
453 | colormap = 'jro' | |
452 |
|
454 | |||
453 | def setup(self): |
|
455 | def setup(self): | |
454 | self.ncols = 1 |
|
456 | self.ncols = 1 | |
455 | self.nrows = self.dataOut.nChannels |
|
457 | self.nrows = self.dataOut.nChannels | |
456 | self.width = 10 |
|
458 | self.width = 10 | |
457 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
459 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
458 | if self.nrows==1: |
|
460 | if self.nrows==1: | |
459 | self.height += 1 |
|
461 | self.height += 1 | |
460 | self.ylabel = 'Range [Km]' |
|
462 | self.ylabel = 'Range [Km]' | |
461 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
463 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
462 |
|
464 | |||
463 | if self.figure is None: |
|
465 | if self.figure is None: | |
464 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
466 | self.figure = plt.figure(figsize=(self.width, self.height), | |
465 | edgecolor='k', |
|
467 | edgecolor='k', | |
466 | facecolor='w') |
|
468 | facecolor='w') | |
467 | else: |
|
469 | else: | |
468 | self.figure.clf() |
|
470 | self.figure.clf() | |
469 | self.axes = [] |
|
471 | self.axes = [] | |
470 |
|
472 | |||
471 | for n in range(self.nrows): |
|
473 | for n in range(self.nrows): | |
472 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
474 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
473 | ax.firsttime = True |
|
475 | ax.firsttime = True | |
474 | self.axes.append(ax) |
|
476 | self.axes.append(ax) | |
475 |
|
477 | |||
476 | def plot(self): |
|
478 | def plot(self): | |
477 |
|
479 | |||
478 | self.x = np.array(self.times) |
|
480 | self.x = np.array(self.times) | |
479 | self.y = self.dataOut.getHeiRange() |
|
481 | self.y = self.dataOut.getHeiRange() | |
480 | self.z = [] |
|
482 | self.z = [] | |
481 |
|
483 | |||
482 | for ch in range(self.nrows): |
|
484 | for ch in range(self.nrows): | |
483 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
485 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
484 |
|
486 | |||
485 | self.z = np.array(self.z) |
|
487 | self.z = np.array(self.z) | |
486 | for n, ax in enumerate(self.axes): |
|
488 | for n, ax in enumerate(self.axes): | |
487 | x, y, z = self.fill_gaps(*self.decimate()) |
|
489 | x, y, z = self.fill_gaps(*self.decimate()) | |
488 | xmin = self.min_time |
|
490 | xmin = self.min_time | |
489 | xmax = xmin+self.xrange*60*60 |
|
491 | xmax = xmin+self.xrange*60*60 | |
490 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
492 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
491 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
493 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
492 | if ax.firsttime: |
|
494 | if ax.firsttime: | |
493 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
495 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
494 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
496 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
495 | plot = ax.pcolormesh(x, y, z[n].T, |
|
497 | plot = ax.pcolormesh(x, y, z[n].T, | |
496 | vmin=self.zmin, |
|
498 | vmin=self.zmin, | |
497 | vmax=self.zmax, |
|
499 | vmax=self.zmax, | |
498 | cmap=plt.get_cmap(self.colormap) |
|
500 | cmap=plt.get_cmap(self.colormap) | |
499 | ) |
|
501 | ) | |
500 | divider = make_axes_locatable(ax) |
|
502 | divider = make_axes_locatable(ax) | |
501 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
503 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
502 | self.figure.add_axes(cax) |
|
504 | self.figure.add_axes(cax) | |
503 | plt.colorbar(plot, cax) |
|
505 | plt.colorbar(plot, cax) | |
504 | ax.set_ylim(self.ymin, self.ymax) |
|
506 | ax.set_ylim(self.ymin, self.ymax) | |
505 |
|
507 | |||
506 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
508 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
507 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
509 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
508 |
|
510 | |||
509 | ax.set_ylabel(self.ylabel) |
|
511 | ax.set_ylabel(self.ylabel) | |
510 |
|
512 | |||
511 | # if self.xmin is None: |
|
513 | # if self.xmin is None: | |
512 | # xmin = self.min_time |
|
514 | # xmin = self.min_time | |
513 | # else: |
|
515 | # else: | |
514 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
516 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
515 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
517 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
516 |
|
518 | |||
517 | ax.set_xlim(xmin, xmax) |
|
519 | ax.set_xlim(xmin, xmax) | |
518 | ax.firsttime = False |
|
520 | ax.firsttime = False | |
519 | else: |
|
521 | else: | |
520 | ax.collections.remove(ax.collections[0]) |
|
522 | ax.collections.remove(ax.collections[0]) | |
521 | ax.set_xlim(xmin, xmax) |
|
523 | ax.set_xlim(xmin, xmax) | |
522 | plot = ax.pcolormesh(x, y, z[n].T, |
|
524 | plot = ax.pcolormesh(x, y, z[n].T, | |
523 | vmin=self.zmin, |
|
525 | vmin=self.zmin, | |
524 | vmax=self.zmax, |
|
526 | vmax=self.zmax, | |
525 | cmap=plt.get_cmap(self.colormap) |
|
527 | cmap=plt.get_cmap(self.colormap) | |
526 | ) |
|
528 | ) | |
527 | ax.set_title('{} {}'.format(self.titles[n], |
|
529 | ax.set_title('{} {}'.format(self.titles[n], | |
528 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
530 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
529 | size=8) |
|
531 | size=8) | |
530 |
|
532 | |||
531 | self.saveTime = self.min_time |
|
533 | self.saveTime = self.min_time | |
532 |
|
534 | |||
533 |
|
535 | |||
534 | class PlotCOHData(PlotRTIData): |
|
536 | class PlotCOHData(PlotRTIData): | |
535 |
|
537 | |||
536 | CODE = 'coh' |
|
538 | CODE = 'coh' | |
537 |
|
539 | |||
538 | def setup(self): |
|
540 | def setup(self): | |
539 |
|
541 | |||
540 | self.ncols = 1 |
|
542 | self.ncols = 1 | |
541 | self.nrows = self.dataOut.nPairs |
|
543 | self.nrows = self.dataOut.nPairs | |
542 | self.width = 10 |
|
544 | self.width = 10 | |
543 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
545 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
544 | if self.nrows==1: |
|
546 | if self.nrows==1: | |
545 | self.height += 1 |
|
547 | self.height += 1 | |
546 | self.ylabel = 'Range [Km]' |
|
548 | self.ylabel = 'Range [Km]' | |
547 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
549 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] | |
548 |
|
550 | |||
549 | if self.figure is None: |
|
551 | if self.figure is None: | |
550 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
552 | self.figure = plt.figure(figsize=(self.width, self.height), | |
551 | edgecolor='k', |
|
553 | edgecolor='k', | |
552 | facecolor='w') |
|
554 | facecolor='w') | |
553 | else: |
|
555 | else: | |
554 | self.figure.clf() |
|
556 | self.figure.clf() | |
555 | self.axes = [] |
|
557 | self.axes = [] | |
556 |
|
558 | |||
557 | for n in range(self.nrows): |
|
559 | for n in range(self.nrows): | |
558 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
560 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
559 | ax.firsttime = True |
|
561 | ax.firsttime = True | |
560 | self.axes.append(ax) |
|
562 | self.axes.append(ax) | |
561 |
|
563 | |||
562 |
|
564 | |||
563 | class PlotNoiseData(PlotData): |
|
565 | class PlotNoiseData(PlotData): | |
564 | CODE = 'noise' |
|
566 | CODE = 'noise' | |
565 |
|
567 | |||
566 | def setup(self): |
|
568 | def setup(self): | |
567 |
|
569 | |||
568 | self.ncols = 1 |
|
570 | self.ncols = 1 | |
569 | self.nrows = 1 |
|
571 | self.nrows = 1 | |
570 | self.width = 10 |
|
572 | self.width = 10 | |
571 | self.height = 3.2 |
|
573 | self.height = 3.2 | |
572 | self.ylabel = 'Intensity [dB]' |
|
574 | self.ylabel = 'Intensity [dB]' | |
573 | self.titles = ['Noise'] |
|
575 | self.titles = ['Noise'] | |
574 |
|
576 | |||
575 | if self.figure is None: |
|
577 | if self.figure is None: | |
576 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
578 | self.figure = plt.figure(figsize=(self.width, self.height), | |
577 | edgecolor='k', |
|
579 | edgecolor='k', | |
578 | facecolor='w') |
|
580 | facecolor='w') | |
579 | else: |
|
581 | else: | |
580 | self.figure.clf() |
|
582 | self.figure.clf() | |
581 | self.axes = [] |
|
583 | self.axes = [] | |
582 |
|
584 | |||
583 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
585 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) | |
584 | self.ax.firsttime = True |
|
586 | self.ax.firsttime = True | |
585 |
|
587 | |||
586 | def plot(self): |
|
588 | def plot(self): | |
587 |
|
589 | |||
588 | x = self.times |
|
590 | x = self.times | |
589 | xmin = self.min_time |
|
591 | xmin = self.min_time | |
590 | xmax = xmin+self.xrange*60*60 |
|
592 | xmax = xmin+self.xrange*60*60 | |
591 | if self.ax.firsttime: |
|
593 | if self.ax.firsttime: | |
592 | for ch in self.dataOut.channelList: |
|
594 | for ch in self.dataOut.channelList: | |
593 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
595 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
594 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
596 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
595 | self.ax.firsttime = False |
|
597 | self.ax.firsttime = False | |
596 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
598 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
597 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
599 | self.ax.xaxis.set_major_locator(LinearLocator(6)) | |
598 | self.ax.set_ylabel(self.ylabel) |
|
600 | self.ax.set_ylabel(self.ylabel) | |
599 | plt.legend() |
|
601 | plt.legend() | |
600 | else: |
|
602 | else: | |
601 | for ch in self.dataOut.channelList: |
|
603 | for ch in self.dataOut.channelList: | |
602 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
604 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
603 | self.ax.lines[ch].set_data(x, y) |
|
605 | self.ax.lines[ch].set_data(x, y) | |
604 |
|
606 | |||
605 | self.ax.set_xlim(xmin, xmax) |
|
607 | self.ax.set_xlim(xmin, xmax) | |
606 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
608 | self.ax.set_ylim(min(y)-5, max(y)+5) | |
607 | self.saveTime = self.min_time |
|
609 | self.saveTime = self.min_time | |
608 |
|
610 | |||
609 |
|
611 | |||
610 | class PlotWindProfilerData(PlotRTIData): |
|
612 | class PlotWindProfilerData(PlotRTIData): | |
611 | CODE = 'wind' |
|
613 | CODE = 'wind' | |
612 | colormap = 'seismic' |
|
614 | colormap = 'seismic' | |
613 |
|
615 | |||
614 | def setup(self): |
|
616 | def setup(self): | |
615 | self.ncols = 1 |
|
617 | self.ncols = 1 | |
616 | self.nrows = self.dataOut.data_output.shape[0] |
|
618 | self.nrows = self.dataOut.data_output.shape[0] | |
617 | self.width = 10 |
|
619 | self.width = 10 | |
618 | self.height = 2.2*self.nrows |
|
620 | self.height = 2.2*self.nrows | |
619 | self.ylabel = 'Height [Km]' |
|
621 | self.ylabel = 'Height [Km]' | |
620 | self.titles = ['Zonal' ,'Meridional', 'Vertical'] |
|
622 | self.titles = ['Zonal' ,'Meridional', 'Vertical'] | |
621 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
623 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
622 | self.windFactor = [1, 1, 100] |
|
624 | self.windFactor = [1, 1, 100] | |
623 |
|
625 | |||
624 | if self.figure is None: |
|
626 | if self.figure is None: | |
625 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
627 | self.figure = plt.figure(figsize=(self.width, self.height), | |
626 | edgecolor='k', |
|
628 | edgecolor='k', | |
627 | facecolor='w') |
|
629 | facecolor='w') | |
628 | else: |
|
630 | else: | |
629 | self.figure.clf() |
|
631 | self.figure.clf() | |
630 | self.axes = [] |
|
632 | self.axes = [] | |
631 |
|
633 | |||
632 | for n in range(self.nrows): |
|
634 | for n in range(self.nrows): | |
633 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
635 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
634 | ax.firsttime = True |
|
636 | ax.firsttime = True | |
635 | self.axes.append(ax) |
|
637 | self.axes.append(ax) | |
636 |
|
638 | |||
637 | def plot(self): |
|
639 | def plot(self): | |
638 |
|
640 | |||
639 | self.x = np.array(self.times) |
|
641 | self.x = np.array(self.times) | |
640 | self.y = self.dataOut.heightList |
|
642 | self.y = self.dataOut.heightList | |
641 | self.z = [] |
|
643 | self.z = [] | |
642 |
|
644 | |||
643 | for ch in range(self.nrows): |
|
645 | for ch in range(self.nrows): | |
644 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
646 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
645 |
|
647 | |||
646 | self.z = np.array(self.z) |
|
648 | self.z = np.array(self.z) | |
647 | self.z = numpy.ma.masked_invalid(self.z) |
|
649 | self.z = numpy.ma.masked_invalid(self.z) | |
648 |
|
650 | |||
649 | cmap=plt.get_cmap(self.colormap) |
|
651 | cmap=plt.get_cmap(self.colormap) | |
650 | cmap.set_bad('white', 1.) |
|
652 | cmap.set_bad('white', 1.) | |
651 |
|
653 | |||
652 | for n, ax in enumerate(self.axes): |
|
654 | for n, ax in enumerate(self.axes): | |
653 | x, y, z = self.fill_gaps(*self.decimate()) |
|
655 | x, y, z = self.fill_gaps(*self.decimate()) | |
654 | xmin = self.min_time |
|
656 | xmin = self.min_time | |
655 | xmax = xmin+self.xrange*60*60 |
|
657 | xmax = xmin+self.xrange*60*60 | |
656 | if ax.firsttime: |
|
658 | if ax.firsttime: | |
657 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
659 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
658 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
660 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
659 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
661 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) | |
660 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
662 | self.zmin = self.zmin if self.zmin else -self.zmax | |
661 |
|
663 | |||
662 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
664 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
663 | vmin=self.zmin, |
|
665 | vmin=self.zmin, | |
664 | vmax=self.zmax, |
|
666 | vmax=self.zmax, | |
665 | cmap=cmap |
|
667 | cmap=cmap | |
666 | ) |
|
668 | ) | |
667 | divider = make_axes_locatable(ax) |
|
669 | divider = make_axes_locatable(ax) | |
668 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
670 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
669 | cax.set_ylabel(self.clabels[n]) |
|
671 | cax.set_ylabel(self.clabels[n]) | |
670 | self.figure.add_axes(cax) |
|
672 | self.figure.add_axes(cax) | |
671 | plt.colorbar(plot, cax) |
|
673 | plt.colorbar(plot, cax) | |
672 | ax.set_ylim(self.ymin, self.ymax) |
|
674 | ax.set_ylim(self.ymin, self.ymax) | |
673 |
|
675 | |||
674 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
676 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
675 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
677 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
676 |
|
678 | |||
677 | ax.set_ylabel(self.ylabel) |
|
679 | ax.set_ylabel(self.ylabel) | |
678 |
|
680 | |||
679 | ax.set_xlim(xmin, xmax) |
|
681 | ax.set_xlim(xmin, xmax) | |
680 | ax.firsttime = False |
|
682 | ax.firsttime = False | |
681 | else: |
|
683 | else: | |
682 | ax.collections.remove(ax.collections[0]) |
|
684 | ax.collections.remove(ax.collections[0]) | |
683 | ax.set_xlim(xmin, xmax) |
|
685 | ax.set_xlim(xmin, xmax) | |
684 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
686 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
685 | vmin=self.zmin, |
|
687 | vmin=self.zmin, | |
686 | vmax=self.zmax, |
|
688 | vmax=self.zmax, | |
687 | cmap=plt.get_cmap(self.colormap) |
|
689 | cmap=plt.get_cmap(self.colormap) | |
688 | ) |
|
690 | ) | |
689 | ax.set_title('{} {}'.format(self.titles[n], |
|
691 | ax.set_title('{} {}'.format(self.titles[n], | |
690 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
692 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
691 | size=8) |
|
693 | size=8) | |
692 |
|
694 | |||
693 | self.saveTime = self.min_time |
|
695 | self.saveTime = self.min_time | |
694 |
|
696 | |||
695 |
|
697 | |||
696 | class PlotSNRData(PlotRTIData): |
|
698 | class PlotSNRData(PlotRTIData): | |
697 | CODE = 'snr' |
|
699 | CODE = 'snr' | |
698 | colormap = 'jet' |
|
700 | colormap = 'jet' | |
699 |
|
701 | |||
700 | class PlotDOPData(PlotRTIData): |
|
702 | class PlotDOPData(PlotRTIData): | |
701 | CODE = 'dop' |
|
703 | CODE = 'dop' | |
702 | colormap = 'jet' |
|
704 | colormap = 'jet' | |
703 |
|
705 | |||
704 |
|
706 | |||
705 | class PlotPHASEData(PlotCOHData): |
|
707 | class PlotPHASEData(PlotCOHData): | |
706 | CODE = 'phase' |
|
708 | CODE = 'phase' | |
707 | colormap = 'seismic' |
|
709 | colormap = 'seismic' |
@@ -1,457 +1,456 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Juan C. Espinoza |
|
2 | @author: Juan C. Espinoza | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import time |
|
5 | import time | |
6 | import json |
|
6 | import json | |
7 | import numpy |
|
7 | import numpy | |
8 | import paho.mqtt.client as mqtt |
|
8 | import paho.mqtt.client as mqtt | |
9 | import zmq |
|
9 | import zmq | |
10 | from profilehooks import profile |
|
10 | from profilehooks import profile | |
11 | import datetime |
|
11 | import datetime | |
12 | from zmq.utils.monitor import recv_monitor_message |
|
12 | from zmq.utils.monitor import recv_monitor_message | |
13 | from functools import wraps |
|
13 | from functools import wraps | |
14 | from threading import Thread |
|
14 | from threading import Thread | |
15 | from multiprocessing import Process |
|
15 | from multiprocessing import Process | |
16 |
|
16 | |||
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
17 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
18 |
|
18 | |||
19 | MAXNUMX = 100 |
|
19 | MAXNUMX = 100 | |
20 | MAXNUMY = 100 |
|
20 | MAXNUMY = 100 | |
21 |
|
21 | |||
22 | class PrettyFloat(float): |
|
22 | class PrettyFloat(float): | |
23 | def __repr__(self): |
|
23 | def __repr__(self): | |
24 | return '%.2f' % self |
|
24 | return '%.2f' % self | |
25 |
|
25 | |||
26 | def roundFloats(obj): |
|
26 | def roundFloats(obj): | |
27 | if isinstance(obj, list): |
|
27 | if isinstance(obj, list): | |
28 | return map(roundFloats, obj) |
|
28 | return map(roundFloats, obj) | |
29 | elif isinstance(obj, float): |
|
29 | elif isinstance(obj, float): | |
30 | return round(obj, 2) |
|
30 | return round(obj, 2) | |
31 |
|
31 | |||
32 | def decimate(z, MAXNUMY): |
|
32 | def decimate(z, MAXNUMY): | |
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
34 |
|
34 | |||
35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
35 | dy = int(len(z[0])/MAXNUMY) + 1 | |
36 |
|
36 | |||
37 | return z[::, ::dy] |
|
37 | return z[::, ::dy] | |
38 |
|
38 | |||
39 | class throttle(object): |
|
39 | class throttle(object): | |
40 | """Decorator that prevents a function from being called more than once every |
|
40 | """Decorator that prevents a function from being called more than once every | |
41 | time period. |
|
41 | time period. | |
42 | To create a function that cannot be called more than once a minute, but |
|
42 | To create a function that cannot be called more than once a minute, but | |
43 | will sleep until it can be called: |
|
43 | will sleep until it can be called: | |
44 | @throttle(minutes=1) |
|
44 | @throttle(minutes=1) | |
45 | def foo(): |
|
45 | def foo(): | |
46 | pass |
|
46 | pass | |
47 |
|
47 | |||
48 | for i in range(10): |
|
48 | for i in range(10): | |
49 | foo() |
|
49 | foo() | |
50 | print "This function has run %s times." % i |
|
50 | print "This function has run %s times." % i | |
51 | """ |
|
51 | """ | |
52 |
|
52 | |||
53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
53 | def __init__(self, seconds=0, minutes=0, hours=0): | |
54 | self.throttle_period = datetime.timedelta( |
|
54 | self.throttle_period = datetime.timedelta( | |
55 | seconds=seconds, minutes=minutes, hours=hours |
|
55 | seconds=seconds, minutes=minutes, hours=hours | |
56 | ) |
|
56 | ) | |
57 |
|
57 | |||
58 | self.time_of_last_call = datetime.datetime.min |
|
58 | self.time_of_last_call = datetime.datetime.min | |
59 |
|
59 | |||
60 | def __call__(self, fn): |
|
60 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
61 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
62 | def wrapper(*args, **kwargs): | |
63 | now = datetime.datetime.now() |
|
63 | now = datetime.datetime.now() | |
64 | time_since_last_call = now - self.time_of_last_call |
|
64 | time_since_last_call = now - self.time_of_last_call | |
65 | time_left = self.throttle_period - time_since_last_call |
|
65 | time_left = self.throttle_period - time_since_last_call | |
66 |
|
66 | |||
67 | if time_left > datetime.timedelta(seconds=0): |
|
67 | if time_left > datetime.timedelta(seconds=0): | |
68 | return |
|
68 | return | |
69 |
|
69 | |||
70 | self.time_of_last_call = datetime.datetime.now() |
|
70 | self.time_of_last_call = datetime.datetime.now() | |
71 | return fn(*args, **kwargs) |
|
71 | return fn(*args, **kwargs) | |
72 |
|
72 | |||
73 | return wrapper |
|
73 | return wrapper | |
74 |
|
74 | |||
75 |
|
75 | |||
76 | class PublishData(Operation): |
|
76 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
77 | """Clase publish.""" | |
78 |
|
78 | |||
79 | def __init__(self, **kwargs): |
|
79 | def __init__(self, **kwargs): | |
80 | """Inicio.""" |
|
80 | """Inicio.""" | |
81 | Operation.__init__(self, **kwargs) |
|
81 | Operation.__init__(self, **kwargs) | |
82 | self.isConfig = False |
|
82 | self.isConfig = False | |
83 | self.client = None |
|
83 | self.client = None | |
84 | self.zeromq = None |
|
84 | self.zeromq = None | |
85 | self.mqtt = None |
|
85 | self.mqtt = None | |
86 |
|
86 | |||
87 | def on_disconnect(self, client, userdata, rc): |
|
87 | def on_disconnect(self, client, userdata, rc): | |
88 | if rc != 0: |
|
88 | if rc != 0: | |
89 | print("Unexpected disconnection.") |
|
89 | print("Unexpected disconnection.") | |
90 | self.connect() |
|
90 | self.connect() | |
91 |
|
91 | |||
92 | def connect(self): |
|
92 | def connect(self): | |
93 | print 'trying to connect' |
|
93 | print 'trying to connect' | |
94 | try: |
|
94 | try: | |
95 | self.client.connect( |
|
95 | self.client.connect( | |
96 | host=self.host, |
|
96 | host=self.host, | |
97 | port=self.port, |
|
97 | port=self.port, | |
98 | keepalive=60*10, |
|
98 | keepalive=60*10, | |
99 | bind_address='') |
|
99 | bind_address='') | |
100 | self.client.loop_start() |
|
100 | self.client.loop_start() | |
101 | # self.client.publish( |
|
101 | # self.client.publish( | |
102 | # self.topic + 'SETUP', |
|
102 | # self.topic + 'SETUP', | |
103 | # json.dumps(setup), |
|
103 | # json.dumps(setup), | |
104 | # retain=True |
|
104 | # retain=True | |
105 | # ) |
|
105 | # ) | |
106 | except: |
|
106 | except: | |
107 | print "MQTT Conection error." |
|
107 | print "MQTT Conection error." | |
108 | self.client = False |
|
108 | self.client = False | |
109 |
|
109 | |||
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
|
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): | |
111 | self.counter = 0 |
|
111 | self.counter = 0 | |
112 | self.topic = kwargs.get('topic', 'schain') |
|
112 | self.topic = kwargs.get('topic', 'schain') | |
113 | self.delay = kwargs.get('delay', 0) |
|
113 | self.delay = kwargs.get('delay', 0) | |
114 | self.plottype = kwargs.get('plottype', 'spectra') |
|
114 | self.plottype = kwargs.get('plottype', 'spectra') | |
115 | self.host = kwargs.get('host', "10.10.10.82") |
|
115 | self.host = kwargs.get('host', "10.10.10.82") | |
116 | self.port = kwargs.get('port', 3000) |
|
116 | self.port = kwargs.get('port', 3000) | |
117 | self.clientId = clientId |
|
117 | self.clientId = clientId | |
118 | self.cnt = 0 |
|
118 | self.cnt = 0 | |
119 | self.zeromq = zeromq |
|
119 | self.zeromq = zeromq | |
120 | self.mqtt = kwargs.get('plottype', 0) |
|
120 | self.mqtt = kwargs.get('plottype', 0) | |
121 | self.client = None |
|
121 | self.client = None | |
122 | self.verbose = verbose |
|
122 | self.verbose = verbose | |
123 | self.dataOut.firstdata = True |
|
123 | self.dataOut.firstdata = True | |
124 | setup = [] |
|
124 | setup = [] | |
125 | if mqtt is 1: |
|
125 | if mqtt is 1: | |
126 | self.client = mqtt.Client( |
|
126 | self.client = mqtt.Client( | |
127 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
127 | client_id=self.clientId + self.topic + 'SCHAIN', | |
128 | clean_session=True) |
|
128 | clean_session=True) | |
129 | self.client.on_disconnect = self.on_disconnect |
|
129 | self.client.on_disconnect = self.on_disconnect | |
130 | self.connect() |
|
130 | self.connect() | |
131 | for plot in self.plottype: |
|
131 | for plot in self.plottype: | |
132 | setup.append({ |
|
132 | setup.append({ | |
133 | 'plot': plot, |
|
133 | 'plot': plot, | |
134 | 'topic': self.topic + plot, |
|
134 | 'topic': self.topic + plot, | |
135 | 'title': getattr(self, plot + '_' + 'title', False), |
|
135 | 'title': getattr(self, plot + '_' + 'title', False), | |
136 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
136 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), | |
137 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
137 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), | |
138 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
138 | 'xrange': getattr(self, plot + '_' + 'xrange', False), | |
139 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
139 | 'yrange': getattr(self, plot + '_' + 'yrange', False), | |
140 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
140 | 'zrange': getattr(self, plot + '_' + 'zrange', False), | |
141 | }) |
|
141 | }) | |
142 | if zeromq is 1: |
|
142 | if zeromq is 1: | |
143 | context = zmq.Context() |
|
143 | context = zmq.Context() | |
144 | self.zmq_socket = context.socket(zmq.PUSH) |
|
144 | self.zmq_socket = context.socket(zmq.PUSH) | |
145 | server = kwargs.get('server', 'zmq.pipe') |
|
145 | server = kwargs.get('server', 'zmq.pipe') | |
146 |
|
146 | |||
147 | if 'tcp://' in server: |
|
147 | if 'tcp://' in server: | |
148 | address = server |
|
148 | address = server | |
149 | else: |
|
149 | else: | |
150 | address = 'ipc:///tmp/%s' % server |
|
150 | address = 'ipc:///tmp/%s' % server | |
151 |
|
151 | |||
152 | self.zmq_socket.connect(address) |
|
152 | self.zmq_socket.connect(address) | |
153 | time.sleep(1) |
|
153 | time.sleep(1) | |
154 |
|
154 | |||
155 |
|
155 | |||
156 | def publish_data(self): |
|
156 | def publish_data(self): | |
157 | self.dataOut.finished = False |
|
157 | self.dataOut.finished = False | |
158 | if self.mqtt is 1: |
|
158 | if self.mqtt is 1: | |
159 | yData = self.dataOut.heightList[:2].tolist() |
|
159 | yData = self.dataOut.heightList[:2].tolist() | |
160 | if self.plottype == 'spectra': |
|
160 | if self.plottype == 'spectra': | |
161 | data = getattr(self.dataOut, 'data_spc') |
|
161 | data = getattr(self.dataOut, 'data_spc') | |
162 | z = data/self.dataOut.normFactor |
|
162 | z = data/self.dataOut.normFactor | |
163 | zdB = 10*numpy.log10(z) |
|
163 | zdB = 10*numpy.log10(z) | |
164 | xlen, ylen = zdB[0].shape |
|
164 | xlen, ylen = zdB[0].shape | |
165 | dx = int(xlen/MAXNUMX) + 1 |
|
165 | dx = int(xlen/MAXNUMX) + 1 | |
166 | dy = int(ylen/MAXNUMY) + 1 |
|
166 | dy = int(ylen/MAXNUMY) + 1 | |
167 | Z = [0 for i in self.dataOut.channelList] |
|
167 | Z = [0 for i in self.dataOut.channelList] | |
168 | for i in self.dataOut.channelList: |
|
168 | for i in self.dataOut.channelList: | |
169 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
169 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
170 | payload = { |
|
170 | payload = { | |
171 | 'timestamp': self.dataOut.utctime, |
|
171 | 'timestamp': self.dataOut.utctime, | |
172 | 'data': roundFloats(Z), |
|
172 | 'data': roundFloats(Z), | |
173 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
173 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
174 | 'interval': self.dataOut.getTimeInterval(), |
|
174 | 'interval': self.dataOut.getTimeInterval(), | |
175 | 'type': self.plottype, |
|
175 | 'type': self.plottype, | |
176 | 'yData': yData |
|
176 | 'yData': yData | |
177 | } |
|
177 | } | |
178 | # print payload |
|
178 | # print payload | |
179 |
|
179 | |||
180 | elif self.plottype in ('rti', 'power'): |
|
180 | elif self.plottype in ('rti', 'power'): | |
181 | data = getattr(self.dataOut, 'data_spc') |
|
181 | data = getattr(self.dataOut, 'data_spc') | |
182 | z = data/self.dataOut.normFactor |
|
182 | z = data/self.dataOut.normFactor | |
183 | avg = numpy.average(z, axis=1) |
|
183 | avg = numpy.average(z, axis=1) | |
184 | avgdB = 10*numpy.log10(avg) |
|
184 | avgdB = 10*numpy.log10(avg) | |
185 | xlen, ylen = z[0].shape |
|
185 | xlen, ylen = z[0].shape | |
186 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
186 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
187 | AVG = [0 for i in self.dataOut.channelList] |
|
187 | AVG = [0 for i in self.dataOut.channelList] | |
188 | for i in self.dataOut.channelList: |
|
188 | for i in self.dataOut.channelList: | |
189 | AVG[i] = avgdB[i][::dy].tolist() |
|
189 | AVG[i] = avgdB[i][::dy].tolist() | |
190 | payload = { |
|
190 | payload = { | |
191 | 'timestamp': self.dataOut.utctime, |
|
191 | 'timestamp': self.dataOut.utctime, | |
192 | 'data': roundFloats(AVG), |
|
192 | 'data': roundFloats(AVG), | |
193 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
193 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
194 | 'interval': self.dataOut.getTimeInterval(), |
|
194 | 'interval': self.dataOut.getTimeInterval(), | |
195 | 'type': self.plottype, |
|
195 | 'type': self.plottype, | |
196 | 'yData': yData |
|
196 | 'yData': yData | |
197 | } |
|
197 | } | |
198 | elif self.plottype == 'noise': |
|
198 | elif self.plottype == 'noise': | |
199 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
199 | noise = self.dataOut.getNoise()/self.dataOut.normFactor | |
200 | noisedB = 10*numpy.log10(noise) |
|
200 | noisedB = 10*numpy.log10(noise) | |
201 | payload = { |
|
201 | payload = { | |
202 | 'timestamp': self.dataOut.utctime, |
|
202 | 'timestamp': self.dataOut.utctime, | |
203 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
203 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), | |
204 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
204 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
205 | 'interval': self.dataOut.getTimeInterval(), |
|
205 | 'interval': self.dataOut.getTimeInterval(), | |
206 | 'type': self.plottype, |
|
206 | 'type': self.plottype, | |
207 | 'yData': yData |
|
207 | 'yData': yData | |
208 | } |
|
208 | } | |
209 | elif self.plottype == 'snr': |
|
209 | elif self.plottype == 'snr': | |
210 | data = getattr(self.dataOut, 'data_SNR') |
|
210 | data = getattr(self.dataOut, 'data_SNR') | |
211 | avgdB = 10*numpy.log10(data) |
|
211 | avgdB = 10*numpy.log10(data) | |
212 |
|
212 | |||
213 | ylen = data[0].size |
|
213 | ylen = data[0].size | |
214 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
214 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
215 | AVG = [0 for i in self.dataOut.channelList] |
|
215 | AVG = [0 for i in self.dataOut.channelList] | |
216 | for i in self.dataOut.channelList: |
|
216 | for i in self.dataOut.channelList: | |
217 | AVG[i] = avgdB[i][::dy].tolist() |
|
217 | AVG[i] = avgdB[i][::dy].tolist() | |
218 | payload = { |
|
218 | payload = { | |
219 | 'timestamp': self.dataOut.utctime, |
|
219 | 'timestamp': self.dataOut.utctime, | |
220 | 'data': roundFloats(AVG), |
|
220 | 'data': roundFloats(AVG), | |
221 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
221 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
222 | 'type': self.plottype, |
|
222 | 'type': self.plottype, | |
223 | 'yData': yData |
|
223 | 'yData': yData | |
224 | } |
|
224 | } | |
225 | else: |
|
225 | else: | |
226 | print "Tipo de grafico invalido" |
|
226 | print "Tipo de grafico invalido" | |
227 | payload = { |
|
227 | payload = { | |
228 | 'data': 'None', |
|
228 | 'data': 'None', | |
229 | 'timestamp': 'None', |
|
229 | 'timestamp': 'None', | |
230 | 'type': None |
|
230 | 'type': None | |
231 | } |
|
231 | } | |
232 | # print 'Publishing data to {}'.format(self.host) |
|
232 | # print 'Publishing data to {}'.format(self.host) | |
233 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
233 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
234 |
|
234 | |||
235 | if self.zeromq is 1: |
|
235 | if self.zeromq is 1: | |
236 | if self.verbose: |
|
236 | if self.verbose: | |
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) | |
238 | self.zmq_socket.send_pyobj(self.dataOut) |
|
238 | self.zmq_socket.send_pyobj(self.dataOut) | |
239 | self.dataOut.firstdata = False |
|
239 | self.dataOut.firstdata = False | |
240 |
|
240 | |||
241 |
|
241 | |||
242 | def run(self, dataOut, **kwargs): |
|
242 | def run(self, dataOut, **kwargs): | |
243 | self.dataOut = dataOut |
|
243 | self.dataOut = dataOut | |
244 | if not self.isConfig: |
|
244 | if not self.isConfig: | |
245 | self.setup(**kwargs) |
|
245 | self.setup(**kwargs) | |
246 | self.isConfig = True |
|
246 | self.isConfig = True | |
247 |
|
247 | |||
248 | self.publish_data() |
|
248 | self.publish_data() | |
249 | time.sleep(self.delay) |
|
249 | time.sleep(self.delay) | |
250 |
|
250 | |||
251 | def close(self): |
|
251 | def close(self): | |
252 | if self.zeromq is 1: |
|
252 | if self.zeromq is 1: | |
253 | self.dataOut.finished = True |
|
253 | self.dataOut.finished = True | |
254 | self.zmq_socket.send_pyobj(self.dataOut) |
|
254 | self.zmq_socket.send_pyobj(self.dataOut) | |
255 | self.zmq_socket.close() |
|
255 | self.zmq_socket.close() | |
256 | if self.client: |
|
256 | if self.client: | |
257 | self.client.loop_stop() |
|
257 | self.client.loop_stop() | |
258 | self.client.disconnect() |
|
258 | self.client.disconnect() | |
259 |
|
259 | |||
260 | class ReceiverData(ProcessingUnit, Process): |
|
260 | class ReceiverData(ProcessingUnit, Process): | |
261 |
|
261 | |||
262 | throttle_value = 5 |
|
262 | throttle_value = 5 | |
263 |
|
263 | |||
264 | def __init__(self, **kwargs): |
|
264 | def __init__(self, **kwargs): | |
265 |
|
265 | |||
266 | ProcessingUnit.__init__(self, **kwargs) |
|
266 | ProcessingUnit.__init__(self, **kwargs) | |
267 | Process.__init__(self) |
|
267 | Process.__init__(self) | |
268 | self.mp = False |
|
268 | self.mp = False | |
269 | self.isConfig = False |
|
269 | self.isConfig = False | |
270 | self.isWebConfig = False |
|
270 | self.isWebConfig = False | |
271 | self.plottypes =[] |
|
271 | self.plottypes =[] | |
272 | self.connections = 0 |
|
272 | self.connections = 0 | |
273 | server = kwargs.get('server', 'zmq.pipe') |
|
273 | server = kwargs.get('server', 'zmq.pipe') | |
274 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
274 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
275 | if 'tcp://' in server: |
|
275 | if 'tcp://' in server: | |
276 | address = server |
|
276 | address = server | |
277 | else: |
|
277 | else: | |
278 | address = 'ipc:///tmp/%s' % server |
|
278 | address = 'ipc:///tmp/%s' % server | |
279 |
|
279 | |||
280 | if 'tcp://' in plot_server: |
|
280 | if 'tcp://' in plot_server: | |
281 | plot_address = plot_server |
|
281 | plot_address = plot_server | |
282 | else: |
|
282 | else: | |
283 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
283 | plot_address = 'ipc:///tmp/%s' % plot_server | |
284 |
|
284 | |||
285 | self.address = address |
|
285 | self.address = address | |
286 | self.plot_address = plot_address |
|
286 | self.plot_address = plot_address | |
287 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
287 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |
288 | self.realtime = kwargs.get('realtime', False) |
|
288 | self.realtime = kwargs.get('realtime', False) | |
289 | self.throttle_value = kwargs.get('throttle', 5) |
|
289 | self.throttle_value = kwargs.get('throttle', 5) | |
290 | self.sendData = self.initThrottle(self.throttle_value) |
|
290 | self.sendData = self.initThrottle(self.throttle_value) | |
291 | self.setup() |
|
291 | self.setup() | |
292 |
|
292 | |||
293 | def setup(self): |
|
293 | def setup(self): | |
294 |
|
294 | |||
295 | self.data = {} |
|
295 | self.data = {} | |
296 | self.data['times'] = [] |
|
296 | self.data['times'] = [] | |
297 | for plottype in self.plottypes: |
|
297 | for plottype in self.plottypes: | |
298 | self.data[plottype] = {} |
|
298 | self.data[plottype] = {} | |
299 | self.data['noise'] = {} |
|
299 | self.data['noise'] = {} | |
300 | self.data['throttle'] = self.throttle_value |
|
300 | self.data['throttle'] = self.throttle_value | |
301 | self.data['ENDED'] = False |
|
301 | self.data['ENDED'] = False | |
302 | self.isConfig = True |
|
302 | self.isConfig = True | |
303 | self.data_web = {} |
|
303 | self.data_web = {} | |
304 |
|
304 | |||
305 | def event_monitor(self, monitor): |
|
305 | def event_monitor(self, monitor): | |
306 |
|
306 | |||
307 | events = {} |
|
307 | events = {} | |
308 |
|
308 | |||
309 | for name in dir(zmq): |
|
309 | for name in dir(zmq): | |
310 | if name.startswith('EVENT_'): |
|
310 | if name.startswith('EVENT_'): | |
311 | value = getattr(zmq, name) |
|
311 | value = getattr(zmq, name) | |
312 | events[value] = name |
|
312 | events[value] = name | |
313 |
|
313 | |||
314 | while monitor.poll(): |
|
314 | while monitor.poll(): | |
315 | evt = recv_monitor_message(monitor) |
|
315 | evt = recv_monitor_message(monitor) | |
316 | if evt['event'] == 32: |
|
316 | if evt['event'] == 32: | |
317 | self.connections += 1 |
|
317 | self.connections += 1 | |
318 | if evt['event'] == 512: |
|
318 | if evt['event'] == 512: | |
319 | pass |
|
319 | pass | |
320 | if self.connections == 0 and self.started is True: |
|
320 | if self.connections == 0 and self.started is True: | |
321 | self.ended = True |
|
321 | self.ended = True | |
322 |
|
322 | |||
323 | evt.update({'description': events[evt['event']]}) |
|
323 | evt.update({'description': events[evt['event']]}) | |
324 |
|
324 | |||
325 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
325 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
326 | break |
|
326 | break | |
327 | monitor.close() |
|
327 | monitor.close() | |
328 | print("event monitor thread done!") |
|
328 | print("event monitor thread done!") | |
329 |
|
329 | |||
330 | def initThrottle(self, throttle_value): |
|
330 | def initThrottle(self, throttle_value): | |
331 |
|
331 | |||
332 | @throttle(seconds=throttle_value) |
|
332 | @throttle(seconds=throttle_value) | |
333 | def sendDataThrottled(fn_sender, data): |
|
333 | def sendDataThrottled(fn_sender, data): | |
334 | fn_sender(data) |
|
334 | fn_sender(data) | |
335 |
|
335 | |||
336 | return sendDataThrottled |
|
336 | return sendDataThrottled | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | def send(self, data): |
|
339 | def send(self, data): | |
340 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
340 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) | |
341 | self.sender.send_pyobj(data) |
|
341 | self.sender.send_pyobj(data) | |
342 |
|
342 | |||
343 |
|
343 | |||
344 | def update(self): |
|
344 | def update(self): | |
345 | t = self.dataOut.utctime |
|
345 | t = self.dataOut.utctime | |
346 |
|
346 | |||
347 | if t in self.data['times']: |
|
347 | if t in self.data['times']: | |
348 | return |
|
348 | return | |
349 |
|
349 | |||
350 | self.data['times'].append(t) |
|
350 | self.data['times'].append(t) | |
351 | self.data['dataOut'] = self.dataOut |
|
351 | self.data['dataOut'] = self.dataOut | |
352 |
|
352 | |||
353 | for plottype in self.plottypes: |
|
353 | for plottype in self.plottypes: | |
354 | if plottype == 'spc': |
|
354 | if plottype == 'spc': | |
355 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
355 | z = self.dataOut.data_spc/self.dataOut.normFactor | |
356 | self.data[plottype] = 10*numpy.log10(z) |
|
356 | self.data[plottype] = 10*numpy.log10(z) | |
357 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
357 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) | |
358 | if plottype == 'cspc': |
|
358 | if plottype == 'cspc': | |
359 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
359 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) | |
360 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
360 | self.data['cspc_coh'] = numpy.abs(jcoherence) | |
361 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
361 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi | |
362 | if plottype == 'rti': |
|
362 | if plottype == 'rti': | |
363 | self.data[plottype][t] = self.dataOut.getPower() |
|
363 | self.data[plottype][t] = self.dataOut.getPower() | |
364 | if plottype == 'snr': |
|
364 | if plottype == 'snr': | |
365 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
365 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) | |
366 | if plottype == 'dop': |
|
366 | if plottype == 'dop': | |
367 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
367 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) | |
368 | if plottype == 'mean': |
|
368 | if plottype == 'mean': | |
369 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
369 | self.data[plottype][t] = self.dataOut.data_MEAN | |
370 | if plottype == 'std': |
|
370 | if plottype == 'std': | |
371 | self.data[plottype][t] = self.dataOut.data_STD |
|
371 | self.data[plottype][t] = self.dataOut.data_STD | |
372 | if plottype == 'coh': |
|
372 | if plottype == 'coh': | |
373 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
373 | self.data[plottype][t] = self.dataOut.getCoherence() | |
374 | if plottype == 'phase': |
|
374 | if plottype == 'phase': | |
375 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
375 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) | |
376 | if plottype == 'wind': |
|
376 | if plottype == 'wind': | |
377 | self.data[plottype][t] = self.dataOut.data_output |
|
377 | self.data[plottype][t] = self.dataOut.data_output | |
378 | if self.realtime: |
|
378 | if self.realtime: | |
379 | self.data_web['timestamp'] = t |
|
379 | self.data_web['timestamp'] = t | |
380 | if plottype == 'spc': |
|
380 | if plottype == 'spc': | |
381 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
381 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) | |
382 | elif plottype == 'cspc': |
|
382 | elif plottype == 'cspc': | |
383 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
383 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) | |
384 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
384 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) | |
385 | elif plottype == 'noise': |
|
385 | elif plottype == 'noise': | |
386 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
386 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) | |
387 | else: |
|
387 | else: | |
388 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
388 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) | |
389 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
389 | self.data_web['interval'] = self.dataOut.getTimeInterval() | |
390 | self.data_web['type'] = plottype |
|
390 | self.data_web['type'] = plottype | |
391 |
|
391 | |||
392 | def run(self): |
|
392 | def run(self): | |
393 |
|
393 | |||
394 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
394 | print '[Starting] {} from {}'.format(self.name, self.address) | |
395 |
|
395 | |||
396 | self.context = zmq.Context() |
|
396 | self.context = zmq.Context() | |
397 | self.receiver = self.context.socket(zmq.PULL) |
|
397 | self.receiver = self.context.socket(zmq.PULL) | |
398 | self.receiver.bind(self.address) |
|
398 | self.receiver.bind(self.address) | |
399 | monitor = self.receiver.get_monitor_socket() |
|
399 | monitor = self.receiver.get_monitor_socket() | |
400 | self.sender = self.context.socket(zmq.PUB) |
|
400 | self.sender = self.context.socket(zmq.PUB) | |
401 | if self.realtime: |
|
401 | if self.realtime: | |
402 | self.sender_web = self.context.socket(zmq.PUB) |
|
402 | self.sender_web = self.context.socket(zmq.PUB) | |
403 | self.sender_web.connect(self.plot_address) |
|
403 | self.sender_web.connect(self.plot_address) | |
404 | time.sleep(1) |
|
404 | time.sleep(1) | |
405 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
405 | self.sender.bind("ipc:///tmp/zmq.plots") | |
406 | time.sleep(3) |
|
406 | time.sleep(3) | |
407 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
407 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
408 | t.start() |
|
408 | t.start() | |
409 |
|
409 | |||
410 | while True: |
|
410 | while True: | |
411 | self.dataOut = self.receiver.recv_pyobj() |
|
411 | self.dataOut = self.receiver.recv_pyobj() | |
412 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
412 | # print '[Receiving] {} - {}'.format(self.dataOut.type, | |
413 | # self.dataOut.datatime.ctime()) |
|
413 | # self.dataOut.datatime.ctime()) | |
414 |
|
414 | |||
415 | self.update() |
|
415 | self.update() | |
416 |
|
416 | |||
417 | if self.dataOut.firstdata is True: |
|
417 | if self.dataOut.firstdata is True: | |
418 | self.data['STARTED'] = True |
|
418 | self.data['STARTED'] = True | |
419 |
|
419 | |||
420 |
|
||||
421 | if self.dataOut.finished is True: |
|
420 | if self.dataOut.finished is True: | |
422 | self.send(self.data) |
|
421 | self.send(self.data) | |
423 | self.connections -= 1 |
|
422 | self.connections -= 1 | |
424 | if self.connections == 0 and self.started: |
|
423 | if self.connections == 0 and self.started: | |
425 | self.ended = True |
|
424 | self.ended = True | |
426 | self.data['ENDED'] = True |
|
425 | self.data['ENDED'] = True | |
427 | self.send(self.data) |
|
426 | self.send(self.data) | |
428 | self.setup() |
|
427 | self.setup() | |
429 | self.started = False |
|
428 | self.started = False | |
430 | else: |
|
429 | else: | |
431 | if self.realtime: |
|
430 | if self.realtime: | |
432 | self.send(self.data) |
|
431 | self.send(self.data) | |
433 | self.sender_web.send_string(json.dumps(self.data_web)) |
|
432 | self.sender_web.send_string(json.dumps(self.data_web)) | |
434 | else: |
|
433 | else: | |
435 | self.sendData(self.send, self.data) |
|
434 | self.sendData(self.send, self.data) | |
436 | self.started = True |
|
435 | self.started = True | |
437 |
|
436 | |||
438 | self.data['STARTED'] = False |
|
437 | self.data['STARTED'] = False | |
439 | return |
|
438 | return | |
440 |
|
439 | |||
441 | def sendToWeb(self): |
|
440 | def sendToWeb(self): | |
442 |
|
441 | |||
443 | if not self.isWebConfig: |
|
442 | if not self.isWebConfig: | |
444 | context = zmq.Context() |
|
443 | context = zmq.Context() | |
445 | sender_web_config = context.socket(zmq.PUB) |
|
444 | sender_web_config = context.socket(zmq.PUB) | |
446 | if 'tcp://' in self.plot_address: |
|
445 | if 'tcp://' in self.plot_address: | |
447 | dum, address, port = self.plot_address.split(':') |
|
446 | dum, address, port = self.plot_address.split(':') | |
448 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
447 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) | |
449 | else: |
|
448 | else: | |
450 | conf_address = self.plot_address + '.config' |
|
449 | conf_address = self.plot_address + '.config' | |
451 | sender_web_config.bind(conf_address) |
|
450 | sender_web_config.bind(conf_address) | |
452 | time.sleep(1) |
|
451 | time.sleep(1) | |
453 | for kwargs in self.operationKwargs.values(): |
|
452 | for kwargs in self.operationKwargs.values(): | |
454 | if 'plot' in kwargs: |
|
453 | if 'plot' in kwargs: | |
455 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) |
|
454 | print '[Sending] Config data to web for {}'.format(kwargs['code'].upper()) | |
456 | sender_web_config.send_string(json.dumps(kwargs)) |
|
455 | sender_web_config.send_string(json.dumps(kwargs)) | |
457 | self.isWebConfig = True |
|
456 | self.isWebConfig = True |
@@ -1,58 +1,59 | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | ''' |
|
2 | ''' | |
3 | Created on Jul 7, 2014 |
|
3 | Created on Jul 7, 2014 | |
4 |
|
4 | |||
5 | @author: roj-idl71 |
|
5 | @author: roj-idl71 | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 |
|
8 | |||
9 | from schainpy.controller import Project |
|
9 | from schainpy.controller import Project | |
10 |
|
10 | |||
11 | if __name__ == '__main__': |
|
11 | if __name__ == '__main__': | |
12 | desc = "Segundo Test" |
|
12 | desc = "Segundo Test" | |
13 |
|
13 | |||
14 | controllerObj = Project() |
|
14 | controllerObj = Project() | |
15 | controllerObj.setup(id='191', name='test01', description=desc) |
|
15 | controllerObj.setup(id='191', name='test01', description=desc) | |
16 |
|
16 | |||
17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') |
|
17 | proc1 = controllerObj.addProcUnit(name='ReceiverData') | |
18 | proc1.addParameter(name='realtime', value='0', format='bool') |
|
18 | proc1.addParameter(name='realtime', value='0', format='bool') | |
19 | proc1.addParameter(name='plottypes', value='rti,coh,phase', format='str') |
|
19 | proc1.addParameter(name='plottypes', value='rti,coh,phase', format='str') | |
20 | proc1.addParameter(name='throttle', value='10', format='int') |
|
20 | proc1.addParameter(name='throttle', value='10', format='int') | |
|
21 | proc1.addParameter(name='interactive', value='0', format='bool') | |||
21 | # proc1.addParameter(name='server', value='tcp://10.10.10.82:7000', format='str') |
|
22 | # proc1.addParameter(name='server', value='tcp://10.10.10.82:7000', format='str') | |
22 | ## TODO Agregar direccion de server de publicacion a graficos como variable |
|
23 | ## TODO Agregar direccion de server de publicacion a graficos como variable | |
23 |
|
24 | |||
24 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') |
|
25 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') | |
25 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
26 | op1.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
26 | op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
27 | op1.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
27 | op1.addParameter(name='show', value='0', format='bool') |
|
28 | op1.addParameter(name='show', value='0', format='bool') | |
28 | op1.addParameter(name='colormap', value='jet', format='str') |
|
29 | op1.addParameter(name='colormap', value='jet', format='str') | |
29 | # |
|
30 | # | |
30 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') |
|
31 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') | |
31 | op2.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
32 | op2.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
32 | op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
33 | op2.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
33 | op2.addParameter(name='colormap', value='jet', format='str') |
|
34 | op2.addParameter(name='colormap', value='jet', format='str') | |
34 | op2.addParameter(name='show', value='0', format='bool') |
|
35 | op2.addParameter(name='show', value='0', format='bool') | |
35 | # # # |
|
36 | # # # | |
36 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') |
|
37 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') | |
37 | op6.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
38 | op6.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
38 | op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
39 | op6.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
39 | op6.addParameter(name='show', value='1', format='bool') |
|
40 | op6.addParameter(name='show', value='1', format='bool') | |
40 | # # |
|
41 | # # | |
41 | # # proc2 = controllerObj.addProcUnit(name='ReceiverData') |
|
42 | # # proc2 = controllerObj.addProcUnit(name='ReceiverData') | |
42 | # # proc2.addParameter(name='server', value='juanca', format='str') |
|
43 | # # proc2.addParameter(name='server', value='juanca', format='str') | |
43 | # # proc2.addParameter(name='plottypes', value='snr,dop', format='str') |
|
44 | # # proc2.addParameter(name='plottypes', value='snr,dop', format='str') | |
44 | # # |
|
45 | # # | |
45 | # op3 = proc1.addOperation(name='PlotSNRData', optype='other') |
|
46 | # op3 = proc1.addOperation(name='PlotSNRData', optype='other') | |
46 | # op3.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
47 | # op3.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
47 | # op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
48 | # op3.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
48 | # op3.addParameter(name='show', value='0', format='bool') |
|
49 | # op3.addParameter(name='show', value='0', format='bool') | |
49 | # # |
|
50 | # # | |
50 | # op4 = proc1.addOperation(name='PlotDOPData', optype='other') |
|
51 | # op4 = proc1.addOperation(name='PlotDOPData', optype='other') | |
51 | # op4.addParameter(name='wintitle', value='Julia 150Km', format='str') |
|
52 | # op4.addParameter(name='wintitle', value='Julia 150Km', format='str') | |
52 | # op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str') |
|
53 | # op4.addParameter(name='save', value='/home/nanosat/Pictures', format='str') | |
53 | # op4.addParameter(name='show', value='0', format='bool') |
|
54 | # op4.addParameter(name='show', value='0', format='bool') | |
54 | # op4.addParameter(name='colormap', value='jet', format='str') |
|
55 | # op4.addParameter(name='colormap', value='jet', format='str') | |
55 |
|
56 | |||
56 |
|
57 | |||
57 |
|
58 | |||
58 | controllerObj.start() |
|
59 | controllerObj.start() |
@@ -1,1 +1,1 | |||||
1 |
<Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value=" |
|
1 | <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="5" /><Parameter format="int" id="191119" name="skip" value="177" /><Parameter format="int" id="191120" name="walk" value="1" /><Parameter format="int" id="191121" name="verbose" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="ParametersProc" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="bool" id="191332" name="verbose" value="0" /><Parameter format="int" id="191333" name="delay" value="0" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now