The requested changes are too big and content was truncated. Show full diff
@@ -700,7 +700,7 class Spectra(JROData): | |||||
700 | for pair in pairsList: |
|
700 | for pair in pairsList: | |
701 | if pair not in self.pairsList: |
|
701 | if pair not in self.pairsList: | |
702 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
702 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
703 | pairsIndexList.append(self.pairsList.index(pair)) |
|
703 | pairsIndexList.append(self.pairsList.index(pair)) | |
704 | for i in range(len(pairsIndexList)): |
|
704 | for i in range(len(pairsIndexList)): | |
705 | pair = self.pairsList[pairsIndexList[i]] |
|
705 | pair = self.pairsList[pairsIndexList[i]] | |
706 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
706 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
This diff has been collapsed as it changes many lines, (1208 lines changed) Show them Hide them | |||||
@@ -1,32 +1,33 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import zmq |
|
|||
4 | import time |
|
3 | import time | |
5 |
import |
|
4 | import glob | |
6 | import datetime |
|
5 | import datetime | |
7 | import numpy as np |
|
6 | from multiprocessing import Process | |
|
7 | ||||
|
8 | import zmq | |||
|
9 | import numpy | |||
8 | import matplotlib |
|
10 | import matplotlib | |
9 | import glob |
|
|||
10 | matplotlib.use('TkAgg') |
|
|||
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 |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
14 | from multiprocessing import Process |
|
|||
15 |
|
14 | |||
16 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
17 |
|
16 | from schainpy.utils import log | ||
18 | plt.ion() |
|
|||
19 |
|
17 | |||
20 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
18 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | |
21 | fromtimestamp = lambda x, mintime : (datetime.datetime.utcfromtimestamp(mintime).replace(hour=(x + 5), minute=0) - d1970).total_seconds() |
|
|||
22 |
|
19 | |||
|
20 | d1970 = datetime.datetime(1970, 1, 1) | |||
23 |
|
21 | |||
24 | d1970 = datetime.datetime(1970,1,1) |
|
|||
25 |
|
22 | |||
26 | class PlotData(Operation, Process): |
|
23 | class PlotData(Operation, Process): | |
|
24 | ''' | |||
|
25 | Base class for Schain plotting operations | |||
|
26 | ''' | |||
27 |
|
27 | |||
28 | CODE = 'Figure' |
|
28 | CODE = 'Figure' | |
29 | colormap = 'jro' |
|
29 | colormap = 'jro' | |
|
30 | bgcolor = 'white' | |||
30 | CONFLATE = False |
|
31 | CONFLATE = False | |
31 | __MAXNUMX = 80 |
|
32 | __MAXNUMX = 80 | |
32 | __missing = 1E30 |
|
33 | __missing = 1E30 | |
@@ -37,54 +38,143 class PlotData(Operation, Process): | |||||
37 | Process.__init__(self) |
|
38 | Process.__init__(self) | |
38 | self.kwargs['code'] = self.CODE |
|
39 | self.kwargs['code'] = self.CODE | |
39 | self.mp = False |
|
40 | self.mp = False | |
40 |
self.data |
|
41 | self.data = None | |
41 | self.isConfig = False |
|
42 | self.isConfig = False | |
42 |
self.figure = |
|
43 | self.figures = [] | |
43 | self.axes = [] |
|
44 | self.axes = [] | |
|
45 | self.cb_axes = [] | |||
44 | self.localtime = kwargs.pop('localtime', True) |
|
46 | self.localtime = kwargs.pop('localtime', True) | |
45 | self.show = kwargs.get('show', True) |
|
47 | self.show = kwargs.get('show', True) | |
46 | self.save = kwargs.get('save', False) |
|
48 | self.save = kwargs.get('save', False) | |
47 | self.colormap = kwargs.get('colormap', self.colormap) |
|
49 | self.colormap = kwargs.get('colormap', self.colormap) | |
48 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
50 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
49 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
51 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
50 |
self. |
|
52 | self.colormaps = kwargs.get('colormaps', None) | |
51 |
self. |
|
53 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
|
54 | self.showprofile = kwargs.get('showprofile', False) | |||
|
55 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |||
|
56 | self.cb_label = kwargs.get('cb_label', None) | |||
|
57 | self.cb_labels = kwargs.get('cb_labels', None) | |||
52 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
58 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
53 | self.zmin = kwargs.get('zmin', None) |
|
59 | self.zmin = kwargs.get('zmin', None) | |
54 | self.zmax = kwargs.get('zmax', None) |
|
60 | self.zmax = kwargs.get('zmax', None) | |
|
61 | self.zlimits = kwargs.get('zlimits', None) | |||
55 | self.xmin = kwargs.get('xmin', None) |
|
62 | self.xmin = kwargs.get('xmin', None) | |
|
63 | if self.xmin is not None: | |||
|
64 | self.xmin += 5 | |||
56 | self.xmax = kwargs.get('xmax', None) |
|
65 | self.xmax = kwargs.get('xmax', None) | |
57 | self.xrange = kwargs.get('xrange', 24) |
|
66 | self.xrange = kwargs.get('xrange', 24) | |
58 | self.ymin = kwargs.get('ymin', None) |
|
67 | self.ymin = kwargs.get('ymin', None) | |
59 | self.ymax = kwargs.get('ymax', None) |
|
68 | self.ymax = kwargs.get('ymax', None) | |
60 |
self. |
|
69 | self.xlabel = kwargs.get('xlabel', None) | |
61 | self.throttle_value = 5 |
|
70 | self.__MAXNUMY = kwargs.get('decimation', 100) | |
62 | self.times = [] |
|
71 | self.showSNR = kwargs.get('showSNR', False) | |
63 | #self.interactive = self.kwargs['parent'] |
|
72 | self.oneFigure = kwargs.get('oneFigure', True) | |
|
73 | self.width = kwargs.get('width', None) | |||
|
74 | self.height = kwargs.get('height', None) | |||
|
75 | self.colorbar = kwargs.get('colorbar', True) | |||
|
76 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |||
|
77 | self.titles = ['' for __ in range(16)] | |||
|
78 | ||||
|
79 | def __setup(self): | |||
|
80 | ''' | |||
|
81 | Common setup for all figures, here figures and axes are created | |||
|
82 | ''' | |||
|
83 | ||||
|
84 | self.setup() | |||
|
85 | ||||
|
86 | if self.width is None: | |||
|
87 | self.width = 8 | |||
64 |
|
88 | |||
|
89 | self.figures = [] | |||
|
90 | self.axes = [] | |||
|
91 | self.cb_axes = [] | |||
|
92 | self.pf_axes = [] | |||
|
93 | self.cmaps = [] | |||
|
94 | ||||
|
95 | size = '15%' if self.ncols==1 else '30%' | |||
|
96 | pad = '4%' if self.ncols==1 else '8%' | |||
|
97 | ||||
|
98 | if self.oneFigure: | |||
|
99 | if self.height is None: | |||
|
100 | self.height = 1.4*self.nrows + 1 | |||
|
101 | fig = plt.figure(figsize=(self.width, self.height), | |||
|
102 | edgecolor='k', | |||
|
103 | facecolor='w') | |||
|
104 | self.figures.append(fig) | |||
|
105 | for n in range(self.nplots): | |||
|
106 | ax = fig.add_subplot(self.nrows, self.ncols, n+1) | |||
|
107 | ax.tick_params(labelsize=8) | |||
|
108 | ax.firsttime = True | |||
|
109 | self.axes.append(ax) | |||
|
110 | if self.showprofile: | |||
|
111 | cax = self.__add_axes(ax, size=size, pad=pad) | |||
|
112 | cax.tick_params(labelsize=8) | |||
|
113 | self.pf_axes.append(cax) | |||
|
114 | else: | |||
|
115 | if self.height is None: | |||
|
116 | self.height = 3 | |||
|
117 | for n in range(self.nplots): | |||
|
118 | fig = plt.figure(figsize=(self.width, self.height), | |||
|
119 | edgecolor='k', | |||
|
120 | facecolor='w') | |||
|
121 | ax = fig.add_subplot(1, 1, 1) | |||
|
122 | ax.tick_params(labelsize=8) | |||
|
123 | ax.firsttime = True | |||
|
124 | self.figures.append(fig) | |||
|
125 | self.axes.append(ax) | |||
|
126 | if self.showprofile: | |||
|
127 | cax = self.__add_axes(ax, size=size, pad=pad) | |||
|
128 | cax.tick_params(labelsize=8) | |||
|
129 | self.pf_axes.append(cax) | |||
|
130 | ||||
|
131 | for n in range(self.nrows): | |||
|
132 | if self.colormaps is not None: | |||
|
133 | cmap = plt.get_cmap(self.colormaps[n]) | |||
|
134 | else: | |||
|
135 | cmap = plt.get_cmap(self.colormap) | |||
|
136 | cmap.set_bad(self.bgcolor, 1.) | |||
|
137 | self.cmaps.append(cmap) | |||
|
138 | ||||
|
139 | def __add_axes(self, ax, size='30%', pad='8%'): | |||
65 | ''' |
|
140 | ''' | |
66 | this new parameter is created to plot data from varius channels at different figures |
|
141 | Add new axes to the given figure | |
67 | 1. crear una lista de figuras donde se puedan plotear las figuras, |
|
|||
68 | 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras |
|
|||
69 | 3. probar? |
|
|||
70 | ''' |
|
142 | ''' | |
71 | self.ind_plt_ch = kwargs.get('ind_plt_ch', False) |
|
143 | divider = make_axes_locatable(ax) | |
72 | self.figurelist = None |
|
144 | nax = divider.new_horizontal(size=size, pad=pad) | |
|
145 | ax.figure.add_axes(nax) | |||
|
146 | return nax | |||
73 |
|
147 | |||
74 |
|
148 | |||
75 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
149 | def setup(self): | |
|
150 | ''' | |||
|
151 | This method should be implemented in the child class, the following | |||
|
152 | attributes should be set: | |||
|
153 | ||||
|
154 | self.nrows: number of rows | |||
|
155 | self.ncols: number of cols | |||
|
156 | self.nplots: number of plots (channels or pairs) | |||
|
157 | self.ylabel: label for Y axes | |||
|
158 | self.titles: list of axes title | |||
|
159 | ||||
|
160 | ''' | |||
|
161 | raise(NotImplementedError, 'Implement this method in child class') | |||
76 |
|
162 | |||
|
163 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |||
|
164 | ''' | |||
|
165 | Create a masked array for missing data | |||
|
166 | ''' | |||
77 | if x_buffer.shape[0] < 2: |
|
167 | if x_buffer.shape[0] < 2: | |
78 | return x_buffer, y_buffer, z_buffer |
|
168 | return x_buffer, y_buffer, z_buffer | |
79 |
|
169 | |||
80 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
170 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
81 | x_median = np.median(deltas) |
|
171 | x_median = numpy.median(deltas) | |
82 |
|
172 | |||
83 | index = np.where(deltas > 5*x_median) |
|
173 | index = numpy.where(deltas > 5*x_median) | |
84 |
|
174 | |||
85 | if len(index[0]) != 0: |
|
175 | if len(index[0]) != 0: | |
86 | z_buffer[::, index[0], ::] = self.__missing |
|
176 | z_buffer[::, index[0], ::] = self.__missing | |
87 | z_buffer = np.ma.masked_inside(z_buffer, |
|
177 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
88 | 0.99*self.__missing, |
|
178 | 0.99*self.__missing, | |
89 | 1.01*self.__missing) |
|
179 | 1.01*self.__missing) | |
90 |
|
180 | |||
@@ -99,110 +189,117 class PlotData(Operation, Process): | |||||
99 | x = self.x |
|
189 | x = self.x | |
100 | y = self.y[::dy] |
|
190 | y = self.y[::dy] | |
101 | z = self.z[::, ::, ::dy] |
|
191 | z = self.z[::, ::, ::dy] | |
102 |
|
192 | |||
103 | return x, y, z |
|
193 | return x, y, z | |
104 |
|
194 | |||
105 | ''' |
|
195 | def format(self): | |
106 | JM: |
|
196 | ''' | |
107 | elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden |
|
197 | Set min and max values, labels, ticks and titles | |
108 | poner otro tiempo a la figura q no necesariamente es el ultimo. |
|
198 | ''' | |
109 | Solo se realiza cuando termina la imagen. |
|
|||
110 | Problemas: |
|
|||
111 |
|
199 | |||
112 | File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot |
|
200 | if self.xmin is None: | |
113 | for n, eachfigure in enumerate(self.figurelist): |
|
201 | xmin = self.min_time | |
114 | TypeError: 'NoneType' object is not iterable |
|
202 | else: | |
|
203 | if self.xaxis is 'time': | |||
|
204 | dt = datetime.datetime.fromtimestamp(self.min_time) | |||
|
205 | xmin = (datetime.datetime.combine(dt.date(), | |||
|
206 | datetime.time(int(self.xmin), 0, 0))-d1970).total_seconds() | |||
|
207 | else: | |||
|
208 | xmin = self.xmin | |||
115 |
|
209 | |||
116 | ''' |
|
210 | if self.xmax is None: | |
117 | def deleteanotherfiles(self): |
|
211 | xmax = xmin+self.xrange*60*60 | |
118 | figurenames=[] |
|
212 | else: | |
119 | if self.figurelist != None: |
|
213 | if self.xaxis is 'time': | |
120 | for n, eachfigure in enumerate(self.figurelist): |
|
214 | dt = datetime.datetime.fromtimestamp(self.min_time) | |
121 | #add specific name for each channel in channelList |
|
215 | xmax = (datetime.datetime.combine(dt.date(), | |
122 | ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE, |
|
216 | datetime.time(int(self.xmax), 0, 0))-d1970).total_seconds() | |
123 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) |
|
217 | else: | |
124 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, |
|
218 | xmax = self.xmax | |
125 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
219 | ||
126 |
|
220 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | ||
127 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures |
|
221 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
128 | if ghostfigure != figname: |
|
222 | ||
129 | os.remove(ghostfigure) |
|
223 | ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20 | |
130 | print 'Removing GhostFigures:' , figname |
|
224 | ||
131 | else : |
|
225 | for n, ax in enumerate(self.axes): | |
132 | '''Erasing ghost images for just on******************''' |
|
226 | if ax.firsttime: | |
133 | ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) |
|
227 | ax.set_facecolor(self.bgcolor) | |
134 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
228 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
135 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures |
|
229 | if self.xaxis is 'time': | |
136 | if ghostfigure != figname: |
|
230 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
137 | os.remove(ghostfigure) |
|
231 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
138 | print 'Removing GhostFigures:' , figname |
|
232 | if self.xlabel is not None: | |
|
233 | ax.set_xlabel(self.xlabel) | |||
|
234 | ax.set_ylabel(self.ylabel) | |||
|
235 | ax.firsttime = False | |||
|
236 | if self.showprofile: | |||
|
237 | self.pf_axes[n].set_ylim(ymin, ymax) | |||
|
238 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |||
|
239 | self.pf_axes[n].set_xlabel('dB') | |||
|
240 | self.pf_axes[n].grid(b=True, axis='x') | |||
|
241 | [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()] | |||
|
242 | if self.colorbar: | |||
|
243 | cb = plt.colorbar(ax.plt, ax=ax, pad=0.02) | |||
|
244 | cb.ax.tick_params(labelsize=8) | |||
|
245 | if self.cb_label: | |||
|
246 | cb.set_label(self.cb_label, size=8) | |||
|
247 | elif self.cb_labels: | |||
|
248 | cb.set_label(self.cb_labels[n], size=8) | |||
|
249 | ||||
|
250 | ax.set_title('{} - {} UTC'.format( | |||
|
251 | self.titles[n], | |||
|
252 | datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S')), | |||
|
253 | size=8) | |||
|
254 | ax.set_xlim(xmin, xmax) | |||
|
255 | ax.set_ylim(ymin, ymax) | |||
|
256 | ||||
139 |
|
257 | |||
140 | def __plot(self): |
|
258 | def __plot(self): | |
141 |
|
259 | ''' | ||
142 | print 'plotting...{}'.format(self.CODE) |
|
260 | ''' | |
143 | if self.ind_plt_ch is False : #standard |
|
261 | log.success('Plotting', self.name) | |
|
262 | ||||
|
263 | self.plot() | |||
|
264 | self.format() | |||
|
265 | ||||
|
266 | for n, fig in enumerate(self.figures): | |||
|
267 | if self.nrows == 0 or self.nplots == 0: | |||
|
268 | log.warning('No data', self.name) | |||
|
269 | continue | |||
144 | if self.show: |
|
270 | if self.show: | |
145 |
|
|
271 | fig.show() | |
146 |
|
|
272 | ||
147 |
|
|
273 | fig.tight_layout() | |
148 |
|
|
274 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
149 |
|
|
275 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
150 | else : |
|
276 | # fig.canvas.draw() | |
151 | print 'len(self.figurelist): ',len(self.figurelist) |
|
277 | ||
152 | for n, eachfigure in enumerate(self.figurelist): |
|
278 | if self.save and self.data.ended: | |
153 |
|
|
279 | channels = range(self.nrows) | |
154 |
|
|
280 | if self.oneFigure: | |
155 |
|
281 | label = '' | ||
156 |
|
|
282 | else: | |
157 | eachfigure.tight_layout() # ajuste de cada subplot |
|
283 | label = '_{}'.format(channels[n]) | |
158 | eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(), |
|
284 | figname = os.path.join( | |
159 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) |
|
285 | self.save, | |
160 |
|
286 | '{}{}_{}.png'.format( | ||
161 | # if self.save: |
|
287 | self.CODE, | |
162 | # if self.ind_plt_ch is False : #standard |
|
288 | label, | |
163 | # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
289 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S') | |
164 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
290 | ) | |
165 | # print 'Saving figure: {}'.format(figname) |
|
291 | ) | |
166 | # self.figure.savefig(figname) |
|
|||
167 | # else : |
|
|||
168 | # for n, eachfigure in enumerate(self.figurelist): |
|
|||
169 | # #add specific name for each channel in channelList |
|
|||
170 | # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE, |
|
|||
171 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
|||
172 | # |
|
|||
173 | # print 'Saving figure: {}'.format(figname) |
|
|||
174 | # eachfigure.savefig(figname) |
|
|||
175 |
|
||||
176 | if self.ind_plt_ch is False : |
|
|||
177 | self.figure.canvas.draw() |
|
|||
178 | else : |
|
|||
179 | for eachfigure in self.figurelist: |
|
|||
180 | eachfigure.canvas.draw() |
|
|||
181 |
|
||||
182 | if self.save: |
|
|||
183 | if self.ind_plt_ch is False : #standard |
|
|||
184 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
|||
185 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
|||
186 | print 'Saving figure: {}'.format(figname) |
|
292 | print 'Saving figure: {}'.format(figname) | |
187 |
|
|
293 | fig.savefig(figname) | |
188 | else : |
|
|||
189 | for n, eachfigure in enumerate(self.figurelist): |
|
|||
190 | #add specific name for each channel in channelList |
|
|||
191 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, |
|
|||
192 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
|||
193 |
|
||||
194 | print 'Saving figure: {}'.format(figname) |
|
|||
195 | eachfigure.savefig(figname) |
|
|||
196 |
|
||||
197 |
|
294 | |||
198 | def plot(self): |
|
295 | def plot(self): | |
199 |
|
296 | ''' | ||
200 | print 'plotting...{}'.format(self.CODE.upper()) |
|
297 | ''' | |
201 | return |
|
298 | raise(NotImplementedError, 'Implement this method in child class') | |
202 |
|
299 | |||
203 | def run(self): |
|
300 | def run(self): | |
204 |
|
301 | |||
205 |
|
|
302 | log.success('Starting', self.name) | |
206 |
|
303 | |||
207 | context = zmq.Context() |
|
304 | context = zmq.Context() | |
208 | receiver = context.socket(zmq.SUB) |
|
305 | receiver = context.socket(zmq.SUB) | |
@@ -212,152 +309,104 class PlotData(Operation, Process): | |||||
212 | if 'server' in self.kwargs['parent']: |
|
309 | if 'server' in self.kwargs['parent']: | |
213 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
310 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
214 | else: |
|
311 | else: | |
215 | receiver.connect("ipc:///tmp/zmq.plots") |
|
312 | receiver.connect("ipc:///tmp/zmq.plots") | |
216 |
|
||||
217 | seconds_passed = 0 |
|
|||
218 |
|
313 | |||
219 | while True: |
|
314 | while True: | |
220 | try: |
|
315 | try: | |
221 |
self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
316 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
222 | self.started = self.data['STARTED'] |
|
317 | ||
223 |
self. |
|
318 | self.min_time = self.data.times[0] | |
224 |
|
319 | self.max_time = self.data.times[-1] | ||
225 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): |
|
|||
226 | continue |
|
|||
227 |
|
||||
228 | self.times = self.data['times'] |
|
|||
229 | self.times.sort() |
|
|||
230 | self.throttle_value = self.data['throttle'] |
|
|||
231 | self.min_time = self.times[0] |
|
|||
232 | self.max_time = self.times[-1] |
|
|||
233 |
|
320 | |||
234 | if self.isConfig is False: |
|
321 | if self.isConfig is False: | |
235 |
|
|
322 | self.__setup() | |
236 | self.setup() |
|
|||
237 | self.isConfig = True |
|
323 | self.isConfig = True | |
238 | self.__plot() |
|
324 | ||
239 |
|
325 | self.__plot() | ||
240 | if self.data['ENDED'] is True: |
|
|||
241 | print '********GRAPHIC ENDED********' |
|
|||
242 | self.ended = True |
|
|||
243 | self.isConfig = False |
|
|||
244 | self.__plot() |
|
|||
245 | self.deleteanotherfiles() #CLPDG |
|
|||
246 | elif seconds_passed >= self.data['throttle']: |
|
|||
247 | print 'passed', seconds_passed |
|
|||
248 | self.__plot() |
|
|||
249 | seconds_passed = 0 |
|
|||
250 |
|
326 | |||
251 | except zmq.Again as e: |
|
327 | except zmq.Again as e: | |
252 |
|
|
328 | log.log('Waiting for data...') | |
253 |
|
|
329 | if self.data: | |
254 | seconds_passed += 2 |
|
330 | plt.pause(self.data.throttle) | |
|
331 | else: | |||
|
332 | time.sleep(2) | |||
255 |
|
333 | |||
256 | def close(self): |
|
334 | def close(self): | |
257 |
if self.data |
|
335 | if self.data: | |
258 | self.__plot() |
|
336 | self.__plot() | |
259 |
|
337 | |||
260 |
|
338 | |||
261 | class PlotSpectraData(PlotData): |
|
339 | class PlotSpectraData(PlotData): | |
|
340 | ''' | |||
|
341 | Plot for Spectra data | |||
|
342 | ''' | |||
262 |
|
343 | |||
263 | CODE = 'spc' |
|
344 | CODE = 'spc' | |
264 | colormap = 'jro' |
|
345 | colormap = 'jro' | |
265 | CONFLATE = False |
|
|||
266 |
|
346 | |||
267 | def setup(self): |
|
347 | def setup(self): | |
268 |
|
348 | self.nplots = len(self.data.channels) | ||
269 | ncolspan = 1 |
|
349 | self.ncols = int(numpy.sqrt(self.nplots)+ 0.9) | |
270 | colspan = 1 |
|
350 | self.nrows = int((1.0*self.nplots/self.ncols) + 0.9) | |
271 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
351 | self.width = 3.4*self.ncols | |
272 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
352 | self.height = 3*self.nrows | |
273 | self.width = 3.6*self.ncols |
|
353 | self.cb_label = 'dB' | |
274 | self.height = 3.2*self.nrows |
|
354 | if self.showprofile: | |
275 | if self.showprofile: |
|
355 | self.width += 0.8*self.ncols | |
276 | ncolspan = 3 |
|
|||
277 | colspan = 2 |
|
|||
278 | self.width += 1.2*self.ncols |
|
|||
279 |
|
356 | |||
280 | self.ylabel = 'Range [Km]' |
|
357 | self.ylabel = 'Range [Km]' | |
281 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
|||
282 |
|
||||
283 | if self.figure is None: |
|
|||
284 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
285 | edgecolor='k', |
|
|||
286 | facecolor='w') |
|
|||
287 | else: |
|
|||
288 | self.figure.clf() |
|
|||
289 |
|
||||
290 | n = 0 |
|
|||
291 | for y in range(self.nrows): |
|
|||
292 | for x in range(self.ncols): |
|
|||
293 | if n >= self.dataOut.nChannels: |
|
|||
294 | break |
|
|||
295 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
|||
296 | if self.showprofile: |
|
|||
297 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
|||
298 |
|
||||
299 | ax.firsttime = True |
|
|||
300 | self.axes.append(ax) |
|
|||
301 | n += 1 |
|
|||
302 |
|
358 | |||
303 | def plot(self): |
|
359 | def plot(self): | |
304 |
|
||||
305 | if self.xaxis == "frequency": |
|
360 | if self.xaxis == "frequency": | |
306 |
x = self.data |
|
361 | x = self.data.xrange[0] | |
307 | xlabel = "Frequency (kHz)" |
|
362 | self.xlabel = "Frequency (kHz)" | |
308 | elif self.xaxis == "time": |
|
363 | elif self.xaxis == "time": | |
309 |
x = self.data |
|
364 | x = self.data.xrange[1] | |
310 | xlabel = "Time (ms)" |
|
365 | self.xlabel = "Time (ms)" | |
311 | else: |
|
366 | else: | |
312 |
x = self.data |
|
367 | x = self.data.xrange[2] | |
313 | xlabel = "Velocity (m/s)" |
|
368 | self.xlabel = "Velocity (m/s)" | |
|
369 | ||||
|
370 | if self.CODE == 'spc_mean': | |||
|
371 | x = self.data.xrange[2] | |||
|
372 | self.xlabel = "Velocity (m/s)" | |||
314 |
|
373 | |||
315 | y = self.dataOut.getHeiRange() |
|
374 | self.titles = [] | |
316 | z = self.data[self.CODE] |
|
|||
317 |
|
375 | |||
|
376 | y = self.data.heights | |||
|
377 | self.y = y | |||
|
378 | z = self.data['spc'] | |||
|
379 | ||||
318 | for n, ax in enumerate(self.axes): |
|
380 | for n, ax in enumerate(self.axes): | |
|
381 | noise = self.data['noise'][n][-1] | |||
|
382 | if self.CODE == 'spc_mean': | |||
|
383 | mean = self.data['mean'][n][-1] | |||
319 | if ax.firsttime: |
|
384 | if ax.firsttime: | |
320 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
385 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
321 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
386 | self.xmin = self.xmin if self.xmin else -self.xmax | |
322 |
self. |
|
387 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
323 |
self. |
|
388 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
324 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
389 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
325 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
390 | vmin=self.zmin, | |
326 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
391 | vmax=self.zmax, | |
327 |
|
|
392 | cmap=plt.get_cmap(self.colormap) | |
328 |
|
|
393 | ) | |
329 | cmap=plt.get_cmap(self.colormap) |
|
|||
330 | ) |
|
|||
331 | divider = make_axes_locatable(ax) |
|
|||
332 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
|||
333 | self.figure.add_axes(cax) |
|
|||
334 | plt.colorbar(ax.plot, cax) |
|
|||
335 |
|
||||
336 | ax.set_xlim(self.xmin, self.xmax) |
|
|||
337 | ax.set_ylim(self.ymin, self.ymax) |
|
|||
338 |
|
||||
339 | ax.set_ylabel(self.ylabel) |
|
|||
340 | ax.set_xlabel(xlabel) |
|
|||
341 |
|
||||
342 | ax.firsttime = False |
|
|||
343 |
|
394 | |||
344 | if self.showprofile: |
|
395 | if self.showprofile: | |
345 |
ax.pl |
|
396 | ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], y)[0] | |
346 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
397 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
347 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
398 | color="k", linestyle="dashed", lw=1)[0] | |
348 | ax.ax_profile.set_xlabel('dB') |
|
399 | if self.CODE == 'spc_mean': | |
349 | ax.ax_profile.grid(b=True, axis='x') |
|
400 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
350 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
|||
351 | color="k", linestyle="dashed", lw=2)[0] |
|
|||
352 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
|||
353 | else: |
|
401 | else: | |
354 |
ax.pl |
|
402 | ax.plt.set_array(z[n].T.ravel()) | |
355 | if self.showprofile: |
|
403 | if self.showprofile: | |
356 |
ax.pl |
|
404 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
357 |
ax.pl |
|
405 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
|
406 | if self.CODE == 'spc_mean': | |||
|
407 | ax.plt_mean.set_data(mean, y) | |||
358 |
|
408 | |||
359 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
409 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
360 | size=8) |
|
|||
361 | self.saveTime = self.max_time |
|
410 | self.saveTime = self.max_time | |
362 |
|
411 | |||
363 |
|
412 | |||
@@ -367,545 +416,245 class PlotCrossSpectraData(PlotData): | |||||
367 | zmin_coh = None |
|
416 | zmin_coh = None | |
368 | zmax_coh = None |
|
417 | zmax_coh = None | |
369 | zmin_phase = None |
|
418 | zmin_phase = None | |
370 | zmax_phase = None |
|
419 | zmax_phase = None | |
371 | CONFLATE = False |
|
|||
372 |
|
420 | |||
373 | def setup(self): |
|
421 | def setup(self): | |
374 |
|
422 | |||
375 |
ncols |
|
423 | self.ncols = 4 | |
376 | colspan = 1 |
|
424 | self.nrows = len(self.data.pairs) | |
377 |
self.n |
|
425 | self.nplots = self.nrows*4 | |
378 |
self. |
|
426 | self.width = 3.4*self.ncols | |
379 |
self. |
|
427 | self.height = 3*self.nrows | |
380 | self.height = 3.2*self.nrows |
|
|||
381 |
|
||||
382 | self.ylabel = 'Range [Km]' |
|
428 | self.ylabel = 'Range [Km]' | |
383 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
429 | self.showprofile = False | |
384 |
|
||||
385 | if self.figure is None: |
|
|||
386 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
387 | edgecolor='k', |
|
|||
388 | facecolor='w') |
|
|||
389 | else: |
|
|||
390 | self.figure.clf() |
|
|||
391 |
|
||||
392 | for y in range(self.nrows): |
|
|||
393 | for x in range(self.ncols): |
|
|||
394 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
|||
395 | ax.firsttime = True |
|
|||
396 | self.axes.append(ax) |
|
|||
397 |
|
430 | |||
398 | def plot(self): |
|
431 | def plot(self): | |
399 |
|
432 | |||
400 | if self.xaxis == "frequency": |
|
433 | if self.xaxis == "frequency": | |
401 |
x = self.data |
|
434 | x = self.data.xrange[0] | |
402 | xlabel = "Frequency (kHz)" |
|
435 | self.xlabel = "Frequency (kHz)" | |
403 | elif self.xaxis == "time": |
|
436 | elif self.xaxis == "time": | |
404 |
x = self.data |
|
437 | x = self.data.xrange[1] | |
405 | xlabel = "Time (ms)" |
|
438 | self.xlabel = "Time (ms)" | |
406 | else: |
|
439 | else: | |
407 |
x = self.data |
|
440 | x = self.data.xrange[2] | |
408 | xlabel = "Velocity (m/s)" |
|
441 | self.xlabel = "Velocity (m/s)" | |
|
442 | ||||
|
443 | self.titles = [] | |||
409 |
|
444 | |||
410 |
y = self.data |
|
445 | y = self.data.heights | |
411 | z_coh = self.data['cspc_coh'] |
|
446 | self.y = y | |
412 |
|
|
447 | spc = self.data['spc'] | |
|
448 | cspc = self.data['cspc'] | |||
413 |
|
449 | |||
414 | for n in range(self.nrows): |
|
450 | for n in range(self.nrows): | |
415 |
|
|
451 | noise = self.data['noise'][n][-1] | |
416 |
|
|
452 | pair = self.data.pairs[n] | |
|
453 | ax = self.axes[4*n] | |||
|
454 | ax3 = self.axes[4*n+3] | |||
417 | if ax.firsttime: |
|
455 | if ax.firsttime: | |
418 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
456 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
419 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
457 | self.xmin = self.xmin if self.xmin else -self.xmax | |
420 |
self. |
|
458 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
421 |
self. |
|
459 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
422 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
460 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |
423 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
461 | vmin=self.zmin, | |
424 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
462 | vmax=self.zmax, | |
425 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
463 | cmap=plt.get_cmap(self.colormap) | |
426 |
|
464 | ) | ||
427 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
|||
428 | vmin=self.zmin_coh, |
|
|||
429 | vmax=self.zmax_coh, |
|
|||
430 | cmap=plt.get_cmap(self.colormap_coh) |
|
|||
431 | ) |
|
|||
432 | divider = make_axes_locatable(ax) |
|
|||
433 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
|||
434 | self.figure.add_axes(cax) |
|
|||
435 | plt.colorbar(ax.plot, cax) |
|
|||
436 |
|
||||
437 | ax.set_xlim(self.xmin, self.xmax) |
|
|||
438 | ax.set_ylim(self.ymin, self.ymax) |
|
|||
439 |
|
||||
440 | ax.set_ylabel(self.ylabel) |
|
|||
441 | ax.set_xlabel(xlabel) |
|
|||
442 | ax.firsttime = False |
|
|||
443 |
|
||||
444 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
|||
445 | vmin=self.zmin_phase, |
|
|||
446 | vmax=self.zmax_phase, |
|
|||
447 | cmap=plt.get_cmap(self.colormap_phase) |
|
|||
448 | ) |
|
|||
449 | divider = make_axes_locatable(ax1) |
|
|||
450 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
|||
451 | self.figure.add_axes(cax) |
|
|||
452 | plt.colorbar(ax1.plot, cax) |
|
|||
453 |
|
||||
454 | ax1.set_xlim(self.xmin, self.xmax) |
|
|||
455 | ax1.set_ylim(self.ymin, self.ymax) |
|
|||
456 |
|
||||
457 | ax1.set_ylabel(self.ylabel) |
|
|||
458 | ax1.set_xlabel(xlabel) |
|
|||
459 | ax1.firsttime = False |
|
|||
460 | else: |
|
465 | else: | |
461 |
ax.pl |
|
466 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
462 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
467 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
463 |
|
||||
464 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
|||
465 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
|||
466 | self.saveTime = self.max_time |
|
|||
467 |
|
||||
468 |
|
468 | |||
469 | class PlotSpectraMeanData(PlotSpectraData): |
|
469 | ax = self.axes[4*n+1] | |
470 |
|
470 | if ax.firsttime: | ||
471 | CODE = 'spc_mean' |
|
471 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, | |
472 | colormap = 'jet' |
|
|||
473 |
|
||||
474 | def plot(self): |
|
|||
475 |
|
||||
476 | if self.xaxis == "frequency": |
|
|||
477 | x = self.dataOut.getFreqRange(1)/1000. |
|
|||
478 | xlabel = "Frequency (kHz)" |
|
|||
479 | elif self.xaxis == "time": |
|
|||
480 | x = self.dataOut.getAcfRange(1) |
|
|||
481 | xlabel = "Time (ms)" |
|
|||
482 | else: |
|
|||
483 | x = self.dataOut.getVelRange(1) |
|
|||
484 | xlabel = "Velocity (m/s)" |
|
|||
485 |
|
||||
486 | y = self.dataOut.getHeiRange() |
|
|||
487 | z = self.data['spc'] |
|
|||
488 | mean = self.data['mean'][self.max_time] |
|
|||
489 |
|
||||
490 | for n, ax in enumerate(self.axes): |
|
|||
491 |
|
||||
492 | if ax.firsttime: |
|
|||
493 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
|||
494 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
|||
495 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
|||
496 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
|||
497 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
|||
498 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
|||
499 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
|||
500 | vmin=self.zmin, |
|
472 | vmin=self.zmin, | |
501 | vmax=self.zmax, |
|
473 | vmax=self.zmax, | |
502 | cmap=plt.get_cmap(self.colormap) |
|
474 | cmap=plt.get_cmap(self.colormap) | |
503 | ) |
|
475 | ) | |
504 | ax.plt_dop = ax.plot(mean[n], y, |
|
|||
505 | color='k')[0] |
|
|||
506 |
|
||||
507 | divider = make_axes_locatable(ax) |
|
|||
508 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
|||
509 | self.figure.add_axes(cax) |
|
|||
510 | plt.colorbar(ax.plt, cax) |
|
|||
511 |
|
||||
512 | ax.set_xlim(self.xmin, self.xmax) |
|
|||
513 | ax.set_ylim(self.ymin, self.ymax) |
|
|||
514 |
|
||||
515 | ax.set_ylabel(self.ylabel) |
|
|||
516 | ax.set_xlabel(xlabel) |
|
|||
517 |
|
||||
518 | ax.firsttime = False |
|
|||
519 |
|
||||
520 | if self.showprofile: |
|
|||
521 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
|||
522 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
|||
523 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
|||
524 | ax.ax_profile.set_xlabel('dB') |
|
|||
525 | ax.ax_profile.grid(b=True, axis='x') |
|
|||
526 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
|||
527 | color="k", linestyle="dashed", lw=2)[0] |
|
|||
528 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
|||
529 | else: |
|
476 | else: | |
530 |
ax.plt.set_array( |
|
477 | ax.plt.set_array(spc[pair[1]].T.ravel()) | |
531 | ax.plt_dop.set_data(mean[n], y) |
|
478 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
532 | if self.showprofile: |
|
479 | ||
533 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
480 | out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]]) | |
534 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
481 | coh = numpy.abs(out) | |
|
482 | phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi | |||
|
483 | ||||
|
484 | ax = self.axes[4*n+2] | |||
|
485 | if ax.firsttime: | |||
|
486 | ax.plt = ax.pcolormesh(x, y, coh.T, | |||
|
487 | vmin=0, | |||
|
488 | vmax=1, | |||
|
489 | cmap=plt.get_cmap(self.colormap_coh) | |||
|
490 | ) | |||
|
491 | else: | |||
|
492 | ax.plt.set_array(coh.T.ravel()) | |||
|
493 | self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |||
535 |
|
494 | |||
536 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
495 | ax = self.axes[4*n+3] | |
537 | size=8) |
|
496 | if ax.firsttime: | |
|
497 | ax.plt = ax.pcolormesh(x, y, phase.T, | |||
|
498 | vmin=-180, | |||
|
499 | vmax=180, | |||
|
500 | cmap=plt.get_cmap(self.colormap_phase) | |||
|
501 | ) | |||
|
502 | else: | |||
|
503 | ax.plt.set_array(phase.T.ravel()) | |||
|
504 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |||
|
505 | ||||
538 | self.saveTime = self.max_time |
|
506 | self.saveTime = self.max_time | |
539 |
|
507 | |||
540 |
|
508 | |||
|
509 | class PlotSpectraMeanData(PlotSpectraData): | |||
|
510 | ''' | |||
|
511 | Plot for Spectra and Mean | |||
|
512 | ''' | |||
|
513 | CODE = 'spc_mean' | |||
|
514 | colormap = 'jro' | |||
|
515 | ||||
|
516 | ||||
541 | class PlotRTIData(PlotData): |
|
517 | class PlotRTIData(PlotData): | |
|
518 | ''' | |||
|
519 | Plot for RTI data | |||
|
520 | ''' | |||
542 |
|
521 | |||
543 | CODE = 'rti' |
|
522 | CODE = 'rti' | |
544 | colormap = 'jro' |
|
523 | colormap = 'jro' | |
545 |
|
524 | |||
546 | def setup(self): |
|
525 | def setup(self): | |
547 |
self. |
|
526 | self.xaxis = 'time' | |
548 | self.nrows = self.dataOut.nChannels |
|
527 | self.ncols = 1 | |
549 | self.width = 10 |
|
528 | self.nrows = len(self.data.channels) | |
550 | #TODO : arreglar la altura de la figura, esta hardcodeada. |
|
529 | self.nplots = len(self.data.channels) | |
551 | #Se arreglo, testear! |
|
|||
552 | if self.ind_plt_ch: |
|
|||
553 | self.height = 3.2#*self.nrows if self.nrows<6 else 12 |
|
|||
554 | else: |
|
|||
555 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
|||
556 |
|
||||
557 | ''' |
|
|||
558 | if self.nrows==1: |
|
|||
559 | self.height += 1 |
|
|||
560 | ''' |
|
|||
561 | self.ylabel = 'Range [Km]' |
|
530 | self.ylabel = 'Range [Km]' | |
562 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
531 | self.cb_label = 'dB' | |
563 |
|
532 | self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)] | ||
564 | ''' |
|
|||
565 | Logica: |
|
|||
566 | 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura |
|
|||
567 | 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el |
|
|||
568 | axis dentro de "Figures" como un diccionario. |
|
|||
569 | ''' |
|
|||
570 | if self.ind_plt_ch is False: #standard mode |
|
|||
571 |
|
||||
572 | if self.figure is None: #solo para la priemra vez |
|
|||
573 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
574 | edgecolor='k', |
|
|||
575 | facecolor='w') |
|
|||
576 | else: |
|
|||
577 | self.figure.clf() |
|
|||
578 | self.axes = [] |
|
|||
579 |
|
||||
580 |
|
||||
581 | for n in range(self.nrows): |
|
|||
582 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
|||
583 | #ax = self.figure(n+1) |
|
|||
584 | ax.firsttime = True |
|
|||
585 | self.axes.append(ax) |
|
|||
586 |
|
||||
587 | else : #append one figure foreach channel in channelList |
|
|||
588 | if self.figurelist == None: |
|
|||
589 | self.figurelist = [] |
|
|||
590 | for n in range(self.nrows): |
|
|||
591 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
592 | edgecolor='k', |
|
|||
593 | facecolor='w') |
|
|||
594 | #add always one subplot |
|
|||
595 | self.figurelist.append(self.figure) |
|
|||
596 |
|
||||
597 | else : # cada dia nuevo limpia el axes, pero mantiene el figure |
|
|||
598 | for eachfigure in self.figurelist: |
|
|||
599 | eachfigure.clf() # eliminaria todas las figuras de la lista? |
|
|||
600 | self.axes = [] |
|
|||
601 |
|
||||
602 | for eachfigure in self.figurelist: |
|
|||
603 | ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura |
|
|||
604 | #ax = self.figure(n+1) |
|
|||
605 | ax.firsttime = True |
|
|||
606 | #Cada figura tiene un distinto puntero |
|
|||
607 | self.axes.append(ax) |
|
|||
608 | #plt.close(eachfigure) |
|
|||
609 |
|
||||
610 |
|
533 | |||
611 | def plot(self): |
|
534 | def plot(self): | |
|
535 | self.x = self.data.times | |||
|
536 | self.y = self.data.heights | |||
|
537 | self.z = self.data[self.CODE] | |||
|
538 | self.z = numpy.ma.masked_invalid(self.z) | |||
612 |
|
539 | |||
613 | if self.ind_plt_ch is False: #standard mode |
|
540 | for n, ax in enumerate(self.axes): | |
614 | self.x = np.array(self.times) |
|
541 | x, y, z = self.fill_gaps(*self.decimate()) | |
615 | self.y = self.dataOut.getHeiRange() |
|
542 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
616 | self.z = [] |
|
543 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
617 |
|
544 | if ax.firsttime: | ||
618 | for ch in range(self.nrows): |
|
545 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
619 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
546 | vmin=self.zmin, | |
620 |
|
547 | vmax=self.zmax, | ||
621 | self.z = np.array(self.z) |
|
548 | cmap=plt.get_cmap(self.colormap) | |
622 | for n, ax in enumerate(self.axes): |
|
549 | ) | |
623 | x, y, z = self.fill_gaps(*self.decimate()) |
|
550 | if self.showprofile: | |
624 | if self.xmin is None: |
|
551 | ax.plot_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], self.y)[0] | |
625 | xmin = self.min_time |
|
552 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, | |
626 | else: |
|
553 | color="k", linestyle="dashed", lw=1)[0] | |
627 | xmin = fromtimestamp(int(self.xmin), self.min_time) |
|
554 | else: | |
628 | if self.xmax is None: |
|
555 | ax.collections.remove(ax.collections[0]) | |
629 | xmax = xmin + self.xrange*60*60 |
|
556 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
630 | else: |
|
557 | vmin=self.zmin, | |
631 | xmax = xmin + (self.xmax - self.xmin) * 60 * 60 |
|
558 | vmax=self.zmax, | |
632 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
559 | cmap=plt.get_cmap(self.colormap) | |
633 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
560 | ) | |
634 |
if |
|
561 | if self.showprofile: | |
635 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
562 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |
636 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
563 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y) | |
637 | plot = ax.pcolormesh(x, y, z[n].T, |
|
|||
638 | vmin=self.zmin, |
|
|||
639 | vmax=self.zmax, |
|
|||
640 | cmap=plt.get_cmap(self.colormap) |
|
|||
641 | ) |
|
|||
642 | divider = make_axes_locatable(ax) |
|
|||
643 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
|||
644 | self.figure.add_axes(cax) |
|
|||
645 | plt.colorbar(plot, cax) |
|
|||
646 | ax.set_ylim(self.ymin, self.ymax) |
|
|||
647 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
|||
648 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
|||
649 | ax.set_ylabel(self.ylabel) |
|
|||
650 | # if self.xmin is None: |
|
|||
651 | # xmin = self.min_time |
|
|||
652 | # else: |
|
|||
653 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
|||
654 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
|||
655 |
|
||||
656 | ax.set_xlim(xmin, xmax) |
|
|||
657 | ax.firsttime = False |
|
|||
658 | else: |
|
|||
659 | ax.collections.remove(ax.collections[0]) |
|
|||
660 | ax.set_xlim(xmin, xmax) |
|
|||
661 | plot = ax.pcolormesh(x, y, z[n].T, |
|
|||
662 | vmin=self.zmin, |
|
|||
663 | vmax=self.zmax, |
|
|||
664 | cmap=plt.get_cmap(self.colormap) |
|
|||
665 | ) |
|
|||
666 | ax.set_title('{} {}'.format(self.titles[n], |
|
|||
667 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
|||
668 | size=8) |
|
|||
669 |
|
||||
670 | self.saveTime = self.min_time |
|
|||
671 | else : |
|
|||
672 | self.x = np.array(self.times) |
|
|||
673 | self.y = self.dataOut.getHeiRange() |
|
|||
674 | self.z = [] |
|
|||
675 |
|
||||
676 | for ch in range(self.nrows): |
|
|||
677 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
|||
678 |
|
||||
679 | self.z = np.array(self.z) |
|
|||
680 | for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes |
|
|||
681 |
|
||||
682 | x, y, z = self.fill_gaps(*self.decimate()) |
|
|||
683 | xmin = self.min_time |
|
|||
684 | xmax = xmin+self.xrange*60*60 |
|
|||
685 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
|||
686 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
|||
687 | if self.axes[n].firsttime: |
|
|||
688 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
|||
689 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
|||
690 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
|||
691 | vmin=self.zmin, |
|
|||
692 | vmax=self.zmax, |
|
|||
693 | cmap=plt.get_cmap(self.colormap) |
|
|||
694 | ) |
|
|||
695 | divider = make_axes_locatable(self.axes[n]) |
|
|||
696 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
|||
697 | eachfigure.add_axes(cax) |
|
|||
698 | #self.figure2.add_axes(cax) |
|
|||
699 | plt.colorbar(plot, cax) |
|
|||
700 | self.axes[n].set_ylim(self.ymin, self.ymax) |
|
|||
701 |
|
||||
702 | self.axes[n].xaxis.set_major_formatter(FuncFormatter(func)) |
|
|||
703 | self.axes[n].xaxis.set_major_locator(LinearLocator(6)) |
|
|||
704 |
|
||||
705 | self.axes[n].set_ylabel(self.ylabel) |
|
|||
706 |
|
||||
707 | if self.xmin is None: |
|
|||
708 | xmin = self.min_time |
|
|||
709 | else: |
|
|||
710 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
|||
711 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
|||
712 |
|
||||
713 | self.axes[n].set_xlim(xmin, xmax) |
|
|||
714 | self.axes[n].firsttime = False |
|
|||
715 | else: |
|
|||
716 | self.axes[n].collections.remove(self.axes[n].collections[0]) |
|
|||
717 | self.axes[n].set_xlim(xmin, xmax) |
|
|||
718 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
|||
719 | vmin=self.zmin, |
|
|||
720 | vmax=self.zmax, |
|
|||
721 | cmap=plt.get_cmap(self.colormap) |
|
|||
722 | ) |
|
|||
723 | self.axes[n].set_title('{} {}'.format(self.titles[n], |
|
|||
724 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
|||
725 | size=8) |
|
|||
726 |
|
564 | |||
727 |
|
|
565 | self.saveTime = self.min_time | |
728 |
|
566 | |||
729 |
|
567 | |||
730 | class PlotCOHData(PlotRTIData): |
|
568 | class PlotCOHData(PlotRTIData): | |
|
569 | ''' | |||
|
570 | Plot for Coherence data | |||
|
571 | ''' | |||
731 |
|
572 | |||
732 | CODE = 'coh' |
|
573 | CODE = 'coh' | |
733 |
|
574 | |||
734 | def setup(self): |
|
575 | def setup(self): | |
735 |
|
576 | self.xaxis = 'time' | ||
736 | self.ncols = 1 |
|
577 | self.ncols = 1 | |
737 |
self.nrows = self.data |
|
578 | self.nrows = len(self.data.pairs) | |
738 | self.width = 10 |
|
579 | self.nplots = len(self.data.pairs) | |
739 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
580 | self.ylabel = 'Range [Km]' | |
740 | self.ind_plt_ch = False #just for coherence and phase |
|
581 | if self.CODE == 'coh': | |
741 | if self.nrows==1: |
|
582 | self.cb_label = '' | |
742 | self.height += 1 |
|
583 | self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
743 | self.ylabel = 'Range [Km]' |
|
|||
744 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
|||
745 |
|
||||
746 | if self.figure is None: |
|
|||
747 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
748 | edgecolor='k', |
|
|||
749 | facecolor='w') |
|
|||
750 | else: |
|
584 | else: | |
751 |
self. |
|
585 | self.cb_label = 'Degrees' | |
752 | self.axes = [] |
|
586 | self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
753 |
|
587 | |||
754 | for n in range(self.nrows): |
|
588 | ||
755 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
589 | class PlotPHASEData(PlotCOHData): | |
756 | ax.firsttime = True |
|
590 | ''' | |
757 | self.axes.append(ax) |
|
591 | Plot for Phase map data | |
|
592 | ''' | |||
|
593 | ||||
|
594 | CODE = 'phase' | |||
|
595 | colormap = 'seismic' | |||
758 |
|
596 | |||
759 |
|
597 | |||
760 | class PlotNoiseData(PlotData): |
|
598 | class PlotNoiseData(PlotData): | |
|
599 | ''' | |||
|
600 | Plot for noise | |||
|
601 | ''' | |||
|
602 | ||||
761 | CODE = 'noise' |
|
603 | CODE = 'noise' | |
762 |
|
604 | |||
763 | def setup(self): |
|
605 | def setup(self): | |
764 |
|
606 | self.xaxis = 'time' | ||
765 | self.ncols = 1 |
|
607 | self.ncols = 1 | |
766 | self.nrows = 1 |
|
608 | self.nrows = 1 | |
767 |
self. |
|
609 | self.nplots = 1 | |
768 | self.height = 3.2 |
|
|||
769 | self.ylabel = 'Intensity [dB]' |
|
610 | self.ylabel = 'Intensity [dB]' | |
770 | self.titles = ['Noise'] |
|
611 | self.titles = ['Noise'] | |
771 |
|
612 | self.colorbar = False | ||
772 | if self.figure is None: |
|
|||
773 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
774 | edgecolor='k', |
|
|||
775 | facecolor='w') |
|
|||
776 | else: |
|
|||
777 | self.figure.clf() |
|
|||
778 | self.axes = [] |
|
|||
779 |
|
||||
780 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
|||
781 | self.ax.firsttime = True |
|
|||
782 |
|
613 | |||
783 | def plot(self): |
|
614 | def plot(self): | |
784 |
|
615 | |||
785 | x = self.times |
|
616 | x = self.data.times | |
786 | xmin = self.min_time |
|
617 | xmin = self.min_time | |
787 | xmax = xmin+self.xrange*60*60 |
|
618 | xmax = xmin+self.xrange*60*60 | |
788 | if self.ax.firsttime: |
|
619 | Y = self.data[self.CODE] | |
789 | for ch in self.dataOut.channelList: |
|
620 | ||
790 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
621 | if self.axes[0].firsttime: | |
791 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
622 | for ch in self.data.channels: | |
792 | self.ax.firsttime = False |
|
623 | y = Y[ch] | |
793 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
624 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
794 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
|||
795 | self.ax.set_ylabel(self.ylabel) |
|
|||
796 | plt.legend() |
|
625 | plt.legend() | |
797 | else: |
|
626 | else: | |
798 |
for ch in self.data |
|
627 | for ch in self.data.channels: | |
799 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
628 | y = Y[ch] | |
800 | self.ax.lines[ch].set_data(x, y) |
|
629 | self.axes[0].lines[ch].set_data(x, y) | |
801 |
|
630 | |||
802 | self.ax.set_xlim(xmin, xmax) |
|
631 | self.ymin = numpy.nanmin(Y) - 5 | |
803 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
632 | self.ymax = numpy.nanmax(Y) + 5 | |
804 | self.saveTime = self.min_time |
|
633 | self.saveTime = self.min_time | |
805 |
|
634 | |||
806 |
|
635 | |||
807 | class PlotWindProfilerData(PlotRTIData): |
|
|||
808 |
|
||||
809 | CODE = 'wind' |
|
|||
810 | colormap = 'seismic' |
|
|||
811 |
|
||||
812 | def setup(self): |
|
|||
813 | self.ncols = 1 |
|
|||
814 | self.nrows = self.dataOut.data_output.shape[0] |
|
|||
815 | self.width = 10 |
|
|||
816 | self.height = 2.2*self.nrows |
|
|||
817 | self.ylabel = 'Height [Km]' |
|
|||
818 | self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind'] |
|
|||
819 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
|||
820 | self.windFactor = [1, 1, 100] |
|
|||
821 |
|
||||
822 | if self.figure is None: |
|
|||
823 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
|||
824 | edgecolor='k', |
|
|||
825 | facecolor='w') |
|
|||
826 | else: |
|
|||
827 | self.figure.clf() |
|
|||
828 | self.axes = [] |
|
|||
829 |
|
||||
830 | for n in range(self.nrows): |
|
|||
831 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
|||
832 | ax.firsttime = True |
|
|||
833 | self.axes.append(ax) |
|
|||
834 |
|
||||
835 | def plot(self): |
|
|||
836 |
|
||||
837 | self.x = np.array(self.times) |
|
|||
838 | self.y = self.dataOut.heightList |
|
|||
839 | self.z = [] |
|
|||
840 |
|
||||
841 | for ch in range(self.nrows): |
|
|||
842 | self.z.append([self.data['output'][t][ch] for t in self.times]) |
|
|||
843 |
|
||||
844 | self.z = np.array(self.z) |
|
|||
845 | self.z = numpy.ma.masked_invalid(self.z) |
|
|||
846 |
|
||||
847 | cmap=plt.get_cmap(self.colormap) |
|
|||
848 | cmap.set_bad('black', 1.) |
|
|||
849 |
|
||||
850 | for n, ax in enumerate(self.axes): |
|
|||
851 | x, y, z = self.fill_gaps(*self.decimate()) |
|
|||
852 | xmin = self.min_time |
|
|||
853 | xmax = xmin+self.xrange*60*60 |
|
|||
854 | if ax.firsttime: |
|
|||
855 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
|||
856 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
|||
857 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
|||
858 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
|||
859 |
|
||||
860 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
|||
861 | vmin=self.zmin, |
|
|||
862 | vmax=self.zmax, |
|
|||
863 | cmap=cmap |
|
|||
864 | ) |
|
|||
865 | divider = make_axes_locatable(ax) |
|
|||
866 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
|||
867 | self.figure.add_axes(cax) |
|
|||
868 | cb = plt.colorbar(plot, cax) |
|
|||
869 | cb.set_label(self.clabels[n]) |
|
|||
870 | ax.set_ylim(self.ymin, self.ymax) |
|
|||
871 |
|
||||
872 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
|||
873 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
|||
874 |
|
||||
875 | ax.set_ylabel(self.ylabel) |
|
|||
876 |
|
||||
877 | ax.set_xlim(xmin, xmax) |
|
|||
878 | ax.firsttime = False |
|
|||
879 | else: |
|
|||
880 | ax.collections.remove(ax.collections[0]) |
|
|||
881 | ax.set_xlim(xmin, xmax) |
|
|||
882 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
|||
883 | vmin=self.zmin, |
|
|||
884 | vmax=self.zmax, |
|
|||
885 | cmap=plt.get_cmap(self.colormap) |
|
|||
886 | ) |
|
|||
887 | ax.set_title('{} {}'.format(self.titles[n], |
|
|||
888 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
|||
889 | size=8) |
|
|||
890 |
|
||||
891 | self.saveTime = self.min_time |
|
|||
892 |
|
||||
893 |
|
||||
894 | class PlotSNRData(PlotRTIData): |
|
636 | class PlotSNRData(PlotRTIData): | |
|
637 | ''' | |||
|
638 | Plot for SNR Data | |||
|
639 | ''' | |||
|
640 | ||||
895 | CODE = 'snr' |
|
641 | CODE = 'snr' | |
896 | colormap = 'jet' |
|
642 | colormap = 'jet' | |
897 |
|
643 | |||
|
644 | ||||
898 | class PlotDOPData(PlotRTIData): |
|
645 | class PlotDOPData(PlotRTIData): | |
|
646 | ''' | |||
|
647 | Plot for DOPPLER Data | |||
|
648 | ''' | |||
|
649 | ||||
899 | CODE = 'dop' |
|
650 | CODE = 'dop' | |
900 | colormap = 'jet' |
|
651 | colormap = 'jet' | |
901 |
|
652 | |||
902 |
|
653 | |||
903 | class PlotPHASEData(PlotCOHData): |
|
|||
904 | CODE = 'phase' |
|
|||
905 | colormap = 'seismic' |
|
|||
906 |
|
||||
907 |
|
||||
908 | class PlotSkyMapData(PlotData): |
|
654 | class PlotSkyMapData(PlotData): | |
|
655 | ''' | |||
|
656 | Plot for meteors detection data | |||
|
657 | ''' | |||
909 |
|
658 | |||
910 | CODE = 'met' |
|
659 | CODE = 'met' | |
911 |
|
660 | |||
@@ -932,7 +681,7 class PlotSkyMapData(PlotData): | |||||
932 |
|
681 | |||
933 | def plot(self): |
|
682 | def plot(self): | |
934 |
|
683 | |||
935 | arrayParameters = np.concatenate([self.data['param'][t] for t in self.times]) |
|
684 | arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.data.times]) | |
936 | error = arrayParameters[:,-1] |
|
685 | error = arrayParameters[:,-1] | |
937 | indValid = numpy.where(error == 0)[0] |
|
686 | indValid = numpy.where(error == 0)[0] | |
938 | finalMeteor = arrayParameters[indValid,:] |
|
687 | finalMeteor = arrayParameters[indValid,:] | |
@@ -962,3 +711,72 class PlotSkyMapData(PlotData): | |||||
962 | self.ax.set_title(title, size=8) |
|
711 | self.ax.set_title(title, size=8) | |
963 |
|
712 | |||
964 | self.saveTime = self.max_time |
|
713 | self.saveTime = self.max_time | |
|
714 | ||||
|
715 | class PlotParamData(PlotRTIData): | |||
|
716 | ''' | |||
|
717 | Plot for data_param object | |||
|
718 | ''' | |||
|
719 | ||||
|
720 | CODE = 'param' | |||
|
721 | colormap = 'seismic' | |||
|
722 | ||||
|
723 | def setup(self): | |||
|
724 | self.xaxis = 'time' | |||
|
725 | self.ncols = 1 | |||
|
726 | self.nrows = self.data.shape(self.CODE)[0] | |||
|
727 | self.nplots = self.nrows | |||
|
728 | if self.showSNR: | |||
|
729 | self.nrows += 1 | |||
|
730 | ||||
|
731 | self.ylabel = 'Height [Km]' | |||
|
732 | self.titles = self.data.parameters \ | |||
|
733 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] | |||
|
734 | if self.showSNR: | |||
|
735 | self.titles.append('SNR') | |||
|
736 | ||||
|
737 | def plot(self): | |||
|
738 | self.data.normalize_heights() | |||
|
739 | self.x = self.data.times | |||
|
740 | self.y = self.data.heights | |||
|
741 | if self.showSNR: | |||
|
742 | self.z = numpy.concatenate( | |||
|
743 | (self.data[self.CODE], self.data['snr']) | |||
|
744 | ) | |||
|
745 | else: | |||
|
746 | self.z = self.data[self.CODE] | |||
|
747 | ||||
|
748 | self.z = numpy.ma.masked_invalid(self.z) | |||
|
749 | ||||
|
750 | for n, ax in enumerate(self.axes): | |||
|
751 | ||||
|
752 | x, y, z = self.fill_gaps(*self.decimate()) | |||
|
753 | ||||
|
754 | if ax.firsttime: | |||
|
755 | if self.zlimits is not None: | |||
|
756 | self.zmin, self.zmax = self.zlimits[n] | |||
|
757 | self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :])) | |||
|
758 | self.zmin = self.zmin if self.zmin is not None else -self.zmax | |||
|
759 | ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |||
|
760 | vmin=self.zmin, | |||
|
761 | vmax=self.zmax, | |||
|
762 | cmap=self.cmaps[n] | |||
|
763 | ) | |||
|
764 | else: | |||
|
765 | if self.zlimits is not None: | |||
|
766 | self.zmin, self.zmax = self.zlimits[n] | |||
|
767 | ax.collections.remove(ax.collections[0]) | |||
|
768 | ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |||
|
769 | vmin=self.zmin, | |||
|
770 | vmax=self.zmax, | |||
|
771 | cmap=self.cmaps[n] | |||
|
772 | ) | |||
|
773 | ||||
|
774 | self.saveTime = self.min_time | |||
|
775 | ||||
|
776 | class PlotOuputData(PlotParamData): | |||
|
777 | ''' | |||
|
778 | Plot data_output object | |||
|
779 | ''' | |||
|
780 | ||||
|
781 | CODE = 'output' | |||
|
782 | colormap = 'seismic' No newline at end of file |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,3 +1,5 | |||||
|
1 | import itertools | |||
|
2 | ||||
1 | import numpy |
|
3 | import numpy | |
2 |
|
4 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
@@ -109,7 +111,10 class SpectraProc(ProcessingUnit): | |||||
109 |
|
111 | |||
110 | if self.dataIn.type == "Spectra": |
|
112 | if self.dataIn.type == "Spectra": | |
111 | self.dataOut.copy(self.dataIn) |
|
113 | self.dataOut.copy(self.dataIn) | |
112 |
|
|
114 | if not pairsList: | |
|
115 | pairsList = itertools.combinations(self.dataOut.channelList, 2) | |||
|
116 | if self.dataOut.data_cspc is not None: | |||
|
117 | self.__selectPairs(pairsList) | |||
113 | return True |
|
118 | return True | |
114 |
|
119 | |||
115 | if self.dataIn.type == "Voltage": |
|
120 | if self.dataIn.type == "Voltage": | |
@@ -178,27 +183,21 class SpectraProc(ProcessingUnit): | |||||
178 |
|
183 | |||
179 | def __selectPairs(self, pairsList): |
|
184 | def __selectPairs(self, pairsList): | |
180 |
|
185 | |||
181 | if channelList == None: |
|
186 | if not pairsList: | |
182 | return |
|
187 | return | |
183 |
|
188 | |||
184 |
pairs |
|
189 | pairs = [] | |
185 |
|
190 | pairsIndex = [] | ||
186 | for thisPair in pairsList: |
|
|||
187 |
|
191 | |||
188 |
|
|
192 | for pair in pairsList: | |
|
193 | if pair[0] not in self.dataOut.channelList or pair[1] not in self.dataOut.channelList: | |||
189 | continue |
|
194 | continue | |
190 |
|
195 | pairs.append(pair) | ||
191 |
pairIndex |
|
196 | pairsIndex.append(pairs.index(pair)) | |
192 |
|
197 | |||
193 | pairsIndexListSelected.append(pairIndex) |
|
198 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] | |
194 |
|
199 | self.dataOut.pairsList = pairs | ||
195 | if not pairsIndexListSelected: |
|
200 | self.dataOut.pairsIndexList = pairsIndex | |
196 | self.dataOut.data_cspc = None |
|
|||
197 | self.dataOut.pairsList = [] |
|
|||
198 | return |
|
|||
199 |
|
||||
200 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
|||
201 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
|||
202 |
|
201 | |||
203 | return |
|
202 | return | |
204 |
|
203 |
@@ -15,6 +15,7 from multiprocessing import Process | |||||
15 |
|
15 | |||
16 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
16 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
17 | from schainpy.model.data.jrodata import JROData |
|
17 | from schainpy.model.data.jrodata import JROData | |
|
18 | from schainpy.utils import log | |||
18 |
|
19 | |||
19 | MAXNUMX = 100 |
|
20 | MAXNUMX = 100 | |
20 | MAXNUMY = 100 |
|
21 | MAXNUMY = 100 | |
@@ -30,14 +31,13 def roundFloats(obj): | |||||
30 | return round(obj, 2) |
|
31 | return round(obj, 2) | |
31 |
|
32 | |||
32 | def decimate(z, MAXNUMY): |
|
33 | def decimate(z, MAXNUMY): | |
33 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
|||
34 |
|
||||
35 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
34 | dy = int(len(z[0])/MAXNUMY) + 1 | |
36 |
|
35 | |||
37 | return z[::, ::dy] |
|
36 | return z[::, ::dy] | |
38 |
|
37 | |||
39 | class throttle(object): |
|
38 | class throttle(object): | |
40 | """Decorator that prevents a function from being called more than once every |
|
39 | ''' | |
|
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: | |
@@ -48,7 +48,7 class throttle(object): | |||||
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( | |
@@ -72,9 +72,169 class throttle(object): | |||||
72 |
|
72 | |||
73 | return wrapper |
|
73 | return wrapper | |
74 |
|
74 | |||
|
75 | class Data(object): | |||
|
76 | ''' | |||
|
77 | Object to hold data to be plotted | |||
|
78 | ''' | |||
|
79 | ||||
|
80 | def __init__(self, plottypes, throttle_value): | |||
|
81 | self.plottypes = plottypes | |||
|
82 | self.throttle = throttle_value | |||
|
83 | self.ended = False | |||
|
84 | self.__times = [] | |||
|
85 | ||||
|
86 | def __str__(self): | |||
|
87 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |||
|
88 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) | |||
|
89 | ||||
|
90 | def __len__(self): | |||
|
91 | return len(self.__times) | |||
|
92 | ||||
|
93 | def __getitem__(self, key): | |||
|
94 | if key not in self.data: | |||
|
95 | raise KeyError(log.error('Missing key: {}'.format(key))) | |||
|
96 | ||||
|
97 | if 'spc' in key: | |||
|
98 | ret = self.data[key] | |||
|
99 | else: | |||
|
100 | ret = numpy.array([self.data[key][x] for x in self.times]) | |||
|
101 | if ret.ndim > 1: | |||
|
102 | ret = numpy.swapaxes(ret, 0, 1) | |||
|
103 | return ret | |||
|
104 | ||||
|
105 | def setup(self): | |||
|
106 | ''' | |||
|
107 | Configure object | |||
|
108 | ''' | |||
|
109 | ||||
|
110 | self.ended = False | |||
|
111 | self.data = {} | |||
|
112 | self.__times = [] | |||
|
113 | self.__heights = [] | |||
|
114 | self.__all_heights = set() | |||
|
115 | for plot in self.plottypes: | |||
|
116 | self.data[plot] = {} | |||
|
117 | ||||
|
118 | def shape(self, key): | |||
|
119 | ''' | |||
|
120 | Get the shape of the one-element data for the given key | |||
|
121 | ''' | |||
|
122 | ||||
|
123 | if len(self.data[key]): | |||
|
124 | if 'spc' in key: | |||
|
125 | return self.data[key].shape | |||
|
126 | return self.data[key][self.__times[0]].shape | |||
|
127 | return (0,) | |||
|
128 | ||||
|
129 | def update(self, dataOut): | |||
|
130 | ''' | |||
|
131 | Update data object with new dataOut | |||
|
132 | ''' | |||
|
133 | ||||
|
134 | tm = dataOut.utctime | |||
|
135 | if tm in self.__times: | |||
|
136 | return | |||
|
137 | ||||
|
138 | self.parameters = getattr(dataOut, 'parameters', []) | |||
|
139 | self.pairs = dataOut.pairsList | |||
|
140 | self.channels = dataOut.channelList | |||
|
141 | self.xrange = (dataOut.getFreqRange(1)/1000. , dataOut.getAcfRange(1) , dataOut.getVelRange(1)) | |||
|
142 | self.interval = dataOut.getTimeInterval() | |||
|
143 | self.__heights.append(dataOut.heightList) | |||
|
144 | self.__all_heights.update(dataOut.heightList) | |||
|
145 | self.__times.append(tm) | |||
|
146 | ||||
|
147 | for plot in self.plottypes: | |||
|
148 | if plot == 'spc': | |||
|
149 | z = dataOut.data_spc/dataOut.normFactor | |||
|
150 | self.data[plot] = 10*numpy.log10(z) | |||
|
151 | if plot == 'cspc': | |||
|
152 | self.data[plot] = dataOut.data_cspc | |||
|
153 | if plot == 'noise': | |||
|
154 | self.data[plot][tm] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |||
|
155 | if plot == 'rti': | |||
|
156 | self.data[plot][tm] = dataOut.getPower() | |||
|
157 | if plot == 'snr_db': | |||
|
158 | self.data['snr'][tm] = dataOut.data_SNR | |||
|
159 | if plot == 'snr': | |||
|
160 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_SNR) | |||
|
161 | if plot == 'dop': | |||
|
162 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_DOP) | |||
|
163 | if plot == 'mean': | |||
|
164 | self.data[plot][tm] = dataOut.data_MEAN | |||
|
165 | if plot == 'std': | |||
|
166 | self.data[plot][tm] = dataOut.data_STD | |||
|
167 | if plot == 'coh': | |||
|
168 | self.data[plot][tm] = dataOut.getCoherence() | |||
|
169 | if plot == 'phase': | |||
|
170 | self.data[plot][tm] = dataOut.getCoherence(phase=True) | |||
|
171 | if plot == 'output': | |||
|
172 | self.data[plot][tm] = dataOut.data_output | |||
|
173 | if plot == 'param': | |||
|
174 | self.data[plot][tm] = dataOut.data_param | |||
|
175 | ||||
|
176 | def normalize_heights(self): | |||
|
177 | ''' | |||
|
178 | Ensure same-dimension of the data for different heighList | |||
|
179 | ''' | |||
|
180 | ||||
|
181 | H = numpy.array(list(self.__all_heights)) | |||
|
182 | H.sort() | |||
|
183 | for key in self.data: | |||
|
184 | shape = self.shape(key)[:-1] + H.shape | |||
|
185 | for tm, obj in self.data[key].items(): | |||
|
186 | h = self.__heights[self.__times.index(tm)] | |||
|
187 | if H.size == h.size: | |||
|
188 | continue | |||
|
189 | index = numpy.where(numpy.in1d(H, h))[0] | |||
|
190 | dummy = numpy.zeros(shape) + numpy.nan | |||
|
191 | if len(shape) == 2: | |||
|
192 | dummy[:, index] = obj | |||
|
193 | else: | |||
|
194 | dummy[index] = obj | |||
|
195 | self.data[key][tm] = dummy | |||
|
196 | ||||
|
197 | self.__heights = [H for tm in self.__times] | |||
|
198 | ||||
|
199 | def jsonify(self, decimate=False): | |||
|
200 | ''' | |||
|
201 | Convert data to json | |||
|
202 | ''' | |||
|
203 | ||||
|
204 | ret = {} | |||
|
205 | tm = self.times[-1] | |||
|
206 | ||||
|
207 | for key, value in self.data: | |||
|
208 | if key in ('spc', 'cspc'): | |||
|
209 | ret[key] = roundFloats(self.data[key].to_list()) | |||
|
210 | else: | |||
|
211 | ret[key] = roundFloats(self.data[key][tm].to_list()) | |||
|
212 | ||||
|
213 | ret['timestamp'] = tm | |||
|
214 | ret['interval'] = self.interval | |||
|
215 | ||||
|
216 | @property | |||
|
217 | def times(self): | |||
|
218 | ''' | |||
|
219 | Return the list of times of the current data | |||
|
220 | ''' | |||
|
221 | ||||
|
222 | ret = numpy.array(self.__times) | |||
|
223 | ret.sort() | |||
|
224 | return ret | |||
|
225 | ||||
|
226 | @property | |||
|
227 | def heights(self): | |||
|
228 | ''' | |||
|
229 | Return the list of heights of the current data | |||
|
230 | ''' | |||
|
231 | ||||
|
232 | return numpy.array(self.__heights[-1]) | |||
75 |
|
233 | |||
76 | class PublishData(Operation): |
|
234 | class PublishData(Operation): | |
77 | """Clase publish.""" |
|
235 | ''' | |
|
236 | Operation to send data over zmq. | |||
|
237 | ''' | |||
78 |
|
238 | |||
79 | def __init__(self, **kwargs): |
|
239 | def __init__(self, **kwargs): | |
80 | """Inicio.""" |
|
240 | """Inicio.""" | |
@@ -86,11 +246,11 class PublishData(Operation): | |||||
86 |
|
246 | |||
87 | def on_disconnect(self, client, userdata, rc): |
|
247 | def on_disconnect(self, client, userdata, rc): | |
88 | if rc != 0: |
|
248 | if rc != 0: | |
89 |
|
|
249 | log.warning('Unexpected disconnection.') | |
90 | self.connect() |
|
250 | self.connect() | |
91 |
|
251 | |||
92 | def connect(self): |
|
252 | def connect(self): | |
93 |
|
|
253 | log.warning('trying to connect') | |
94 | try: |
|
254 | try: | |
95 | self.client.connect( |
|
255 | self.client.connect( | |
96 | host=self.host, |
|
256 | host=self.host, | |
@@ -104,7 +264,7 class PublishData(Operation): | |||||
104 | # retain=True |
|
264 | # retain=True | |
105 | # ) |
|
265 | # ) | |
106 | except: |
|
266 | except: | |
107 |
|
|
267 | log.error('MQTT Conection error.') | |
108 | self.client = False |
|
268 | self.client = False | |
109 |
|
269 | |||
110 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
|
270 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): | |
@@ -119,8 +279,7 class PublishData(Operation): | |||||
119 | self.zeromq = zeromq |
|
279 | self.zeromq = zeromq | |
120 | self.mqtt = kwargs.get('plottype', 0) |
|
280 | self.mqtt = kwargs.get('plottype', 0) | |
121 | self.client = None |
|
281 | self.client = None | |
122 | self.verbose = verbose |
|
282 | self.verbose = verbose | |
123 | self.dataOut.firstdata = True |
|
|||
124 | setup = [] |
|
283 | setup = [] | |
125 | if mqtt is 1: |
|
284 | if mqtt is 1: | |
126 | self.client = mqtt.Client( |
|
285 | self.client = mqtt.Client( | |
@@ -175,7 +334,6 class PublishData(Operation): | |||||
175 | 'type': self.plottype, |
|
334 | 'type': self.plottype, | |
176 | 'yData': yData |
|
335 | 'yData': yData | |
177 | } |
|
336 | } | |
178 | # print payload |
|
|||
179 |
|
337 | |||
180 | elif self.plottype in ('rti', 'power'): |
|
338 | elif self.plottype in ('rti', 'power'): | |
181 | data = getattr(self.dataOut, 'data_spc') |
|
339 | data = getattr(self.dataOut, 'data_spc') | |
@@ -229,15 +387,16 class PublishData(Operation): | |||||
229 | 'timestamp': 'None', |
|
387 | 'timestamp': 'None', | |
230 | 'type': None |
|
388 | 'type': None | |
231 | } |
|
389 | } | |
232 | # print 'Publishing data to {}'.format(self.host) |
|
390 | ||
233 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
391 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
234 |
|
392 | |||
235 | if self.zeromq is 1: |
|
393 | if self.zeromq is 1: | |
236 | if self.verbose: |
|
394 | if self.verbose: | |
237 | print '[Sending] {} - {}'.format(self.dataOut.type, self.dataOut.datatime) |
|
395 | log.log( | |
|
396 | '{} - {}'.format(self.dataOut.type, self.dataOut.datatime), | |||
|
397 | 'Sending' | |||
|
398 | ) | |||
238 | self.zmq_socket.send_pyobj(self.dataOut) |
|
399 | self.zmq_socket.send_pyobj(self.dataOut) | |
239 | self.dataOut.firstdata = False |
|
|||
240 |
|
||||
241 |
|
400 | |||
242 | def run(self, dataOut, **kwargs): |
|
401 | def run(self, dataOut, **kwargs): | |
243 | self.dataOut = dataOut |
|
402 | self.dataOut = dataOut | |
@@ -252,6 +411,7 class PublishData(Operation): | |||||
252 | if self.zeromq is 1: |
|
411 | if self.zeromq is 1: | |
253 | self.dataOut.finished = True |
|
412 | self.dataOut.finished = True | |
254 | self.zmq_socket.send_pyobj(self.dataOut) |
|
413 | self.zmq_socket.send_pyobj(self.dataOut) | |
|
414 | time.sleep(0.1) | |||
255 | self.zmq_socket.close() |
|
415 | self.zmq_socket.close() | |
256 | if self.client: |
|
416 | if self.client: | |
257 | self.client.loop_stop() |
|
417 | self.client.loop_stop() | |
@@ -280,7 +440,7 class ReceiverData(ProcessingUnit): | |||||
280 | self.receiver = self.context.socket(zmq.PULL) |
|
440 | self.receiver = self.context.socket(zmq.PULL) | |
281 | self.receiver.bind(self.address) |
|
441 | self.receiver.bind(self.address) | |
282 | time.sleep(0.5) |
|
442 | time.sleep(0.5) | |
283 |
|
|
443 | log.success('ReceiverData from {}'.format(self.address)) | |
284 |
|
444 | |||
285 |
|
445 | |||
286 | def run(self): |
|
446 | def run(self): | |
@@ -290,8 +450,9 class ReceiverData(ProcessingUnit): | |||||
290 | self.isConfig = True |
|
450 | self.isConfig = True | |
291 |
|
451 | |||
292 | self.dataOut = self.receiver.recv_pyobj() |
|
452 | self.dataOut = self.receiver.recv_pyobj() | |
293 |
|
|
453 | log.log('{} - {}'.format(self.dataOut.type, | |
294 |
|
|
454 | self.dataOut.datatime.ctime(),), | |
|
455 | 'Receiving') | |||
295 |
|
456 | |||
296 |
|
457 | |||
297 | class PlotterReceiver(ProcessingUnit, Process): |
|
458 | class PlotterReceiver(ProcessingUnit, Process): | |
@@ -305,7 +466,6 class PlotterReceiver(ProcessingUnit, Process): | |||||
305 | self.mp = False |
|
466 | self.mp = False | |
306 | self.isConfig = False |
|
467 | self.isConfig = False | |
307 | self.isWebConfig = False |
|
468 | self.isWebConfig = False | |
308 | self.plottypes = [] |
|
|||
309 | self.connections = 0 |
|
469 | self.connections = 0 | |
310 | server = kwargs.get('server', 'zmq.pipe') |
|
470 | server = kwargs.get('server', 'zmq.pipe') | |
311 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
471 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
@@ -325,19 +485,13 class PlotterReceiver(ProcessingUnit, Process): | |||||
325 | self.realtime = kwargs.get('realtime', False) |
|
485 | self.realtime = kwargs.get('realtime', False) | |
326 | self.throttle_value = kwargs.get('throttle', 5) |
|
486 | self.throttle_value = kwargs.get('throttle', 5) | |
327 | self.sendData = self.initThrottle(self.throttle_value) |
|
487 | self.sendData = self.initThrottle(self.throttle_value) | |
|
488 | self.dates = [] | |||
328 | self.setup() |
|
489 | self.setup() | |
329 |
|
490 | |||
330 | def setup(self): |
|
491 | def setup(self): | |
331 |
|
492 | |||
332 | self.data = {} |
|
493 | self.data = Data(self.plottypes, self.throttle_value) | |
333 | self.data['times'] = [] |
|
494 | self.isConfig = True | |
334 | for plottype in self.plottypes: |
|
|||
335 | self.data[plottype] = {} |
|
|||
336 | self.data['noise'] = {} |
|
|||
337 | self.data['throttle'] = self.throttle_value |
|
|||
338 | self.data['ENDED'] = False |
|
|||
339 | self.isConfig = True |
|
|||
340 | self.data_web = {} |
|
|||
341 |
|
495 | |||
342 | def event_monitor(self, monitor): |
|
496 | def event_monitor(self, monitor): | |
343 |
|
497 | |||
@@ -354,15 +508,13 class PlotterReceiver(ProcessingUnit, Process): | |||||
354 | self.connections += 1 |
|
508 | self.connections += 1 | |
355 | if evt['event'] == 512: |
|
509 | if evt['event'] == 512: | |
356 | pass |
|
510 | pass | |
357 | if self.connections == 0 and self.started is True: |
|
|||
358 | self.ended = True |
|
|||
359 |
|
511 | |||
360 | evt.update({'description': events[evt['event']]}) |
|
512 | evt.update({'description': events[evt['event']]}) | |
361 |
|
513 | |||
362 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
514 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
363 | break |
|
515 | break | |
364 | monitor.close() |
|
516 | monitor.close() | |
365 |
print( |
|
517 | print('event monitor thread done!') | |
366 |
|
518 | |||
367 | def initThrottle(self, throttle_value): |
|
519 | def initThrottle(self, throttle_value): | |
368 |
|
520 | |||
@@ -372,65 +524,16 class PlotterReceiver(ProcessingUnit, Process): | |||||
372 |
|
524 | |||
373 | return sendDataThrottled |
|
525 | return sendDataThrottled | |
374 |
|
526 | |||
375 |
|
||||
376 | def send(self, data): |
|
527 | def send(self, data): | |
377 | # print '[sending] data=%s size=%s' % (data.keys(), len(data['times'])) |
|
528 | log.success('Sending {}'.format(data), self.name) | |
378 | self.sender.send_pyobj(data) |
|
529 | self.sender.send_pyobj(data) | |
379 |
|
530 | |||
380 |
|
||||
381 | def update(self): |
|
|||
382 | t = self.dataOut.utctime |
|
|||
383 |
|
||||
384 | if t in self.data['times']: |
|
|||
385 | return |
|
|||
386 |
|
||||
387 | self.data['times'].append(t) |
|
|||
388 | self.data['dataOut'] = self.dataOut |
|
|||
389 |
|
||||
390 | for plottype in self.plottypes: |
|
|||
391 | if plottype == 'spc': |
|
|||
392 | z = self.dataOut.data_spc/self.dataOut.normFactor |
|
|||
393 | self.data[plottype] = 10*numpy.log10(z) |
|
|||
394 | self.data['noise'][t] = 10*numpy.log10(self.dataOut.getNoise()/self.dataOut.normFactor) |
|
|||
395 | if plottype == 'cspc': |
|
|||
396 | jcoherence = self.dataOut.data_cspc/numpy.sqrt(self.dataOut.data_spc*self.dataOut.data_spc) |
|
|||
397 | self.data['cspc_coh'] = numpy.abs(jcoherence) |
|
|||
398 | self.data['cspc_phase'] = numpy.arctan2(jcoherence.imag, jcoherence.real)*180/numpy.pi |
|
|||
399 | if plottype == 'rti': |
|
|||
400 | self.data[plottype][t] = self.dataOut.getPower() |
|
|||
401 | if plottype == 'snr': |
|
|||
402 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_SNR) |
|
|||
403 | if plottype == 'dop': |
|
|||
404 | self.data[plottype][t] = 10*numpy.log10(self.dataOut.data_DOP) |
|
|||
405 | if plottype == 'mean': |
|
|||
406 | self.data[plottype][t] = self.dataOut.data_MEAN |
|
|||
407 | if plottype == 'std': |
|
|||
408 | self.data[plottype][t] = self.dataOut.data_STD |
|
|||
409 | if plottype == 'coh': |
|
|||
410 | self.data[plottype][t] = self.dataOut.getCoherence() |
|
|||
411 | if plottype == 'phase': |
|
|||
412 | self.data[plottype][t] = self.dataOut.getCoherence(phase=True) |
|
|||
413 | if plottype == 'output': |
|
|||
414 | self.data[plottype][t] = self.dataOut.data_output |
|
|||
415 | if plottype == 'param': |
|
|||
416 | self.data[plottype][t] = self.dataOut.data_param |
|
|||
417 | if self.realtime: |
|
|||
418 | self.data_web['timestamp'] = t |
|
|||
419 | if plottype == 'spc': |
|
|||
420 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype]).tolist()) |
|
|||
421 | elif plottype == 'cspc': |
|
|||
422 | self.data_web['cspc_coh'] = roundFloats(decimate(self.data['cspc_coh']).tolist()) |
|
|||
423 | self.data_web['cspc_phase'] = roundFloats(decimate(self.data['cspc_phase']).tolist()) |
|
|||
424 | elif plottype == 'noise': |
|
|||
425 | self.data_web['noise'] = roundFloats(self.data['noise'][t].tolist()) |
|
|||
426 | else: |
|
|||
427 | self.data_web[plottype] = roundFloats(decimate(self.data[plottype][t]).tolist()) |
|
|||
428 | self.data_web['interval'] = self.dataOut.getTimeInterval() |
|
|||
429 | self.data_web['type'] = plottype |
|
|||
430 |
|
||||
431 | def run(self): |
|
531 | def run(self): | |
432 |
|
532 | |||
433 | print '[Starting] {} from {}'.format(self.name, self.address) |
|
533 | log.success( | |
|
534 | 'Starting from {}'.format(self.address), | |||
|
535 | self.name | |||
|
536 | ) | |||
434 |
|
537 | |||
435 | self.context = zmq.Context() |
|
538 | self.context = zmq.Context() | |
436 | self.receiver = self.context.socket(zmq.PULL) |
|
539 | self.receiver = self.context.socket(zmq.PULL) | |
@@ -447,39 +550,39 class PlotterReceiver(ProcessingUnit, Process): | |||||
447 | else: |
|
550 | else: | |
448 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
551 | self.sender.bind("ipc:///tmp/zmq.plots") | |
449 |
|
552 | |||
450 |
time.sleep( |
|
553 | time.sleep(2) | |
451 |
|
554 | |||
452 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
555 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
453 | t.start() |
|
556 | t.start() | |
454 |
|
557 | |||
455 | while True: |
|
558 | while True: | |
456 |
|
|
559 | dataOut = self.receiver.recv_pyobj() | |
457 | # print '[Receiving] {} - {}'.format(self.dataOut.type, |
|
560 | dt = datetime.datetime.fromtimestamp(dataOut.utctime).date() | |
458 | # self.dataOut.datatime.ctime()) |
|
561 | sended = False | |
459 |
|
562 | if dt not in self.dates: | ||
460 |
self. |
|
563 | if self.data: | |
|
564 | self.data.ended = True | |||
|
565 | self.send(self.data) | |||
|
566 | sended = True | |||
|
567 | self.data.setup() | |||
|
568 | self.dates.append(dt) | |||
461 |
|
569 | |||
462 |
|
|
570 | self.data.update(dataOut) | |
463 | self.data['STARTED'] = True |
|
|||
464 |
|
571 | |||
465 |
if |
|
572 | if dataOut.finished is True: | |
466 | self.send(self.data) |
|
|||
467 | self.connections -= 1 |
|
573 | self.connections -= 1 | |
468 |
if self.connections == 0 and self. |
|
574 | if self.connections == 0 and dt in self.dates: | |
469 | self.ended = True |
|
575 | self.data.ended = True | |
470 | self.data['ENDED'] = True |
|
|||
471 | self.send(self.data) |
|
576 | self.send(self.data) | |
472 | self.setup() |
|
577 | self.data.setup() | |
473 | self.started = False |
|
|||
474 | else: |
|
578 | else: | |
475 | if self.realtime: |
|
579 | if self.realtime: | |
476 | self.send(self.data) |
|
580 | self.send(self.data) | |
477 |
self.sender_web.send_string( |
|
581 | # self.sender_web.send_string(self.data.jsonify()) | |
478 | else: |
|
582 | else: | |
479 |
|
|
583 | if not sended: | |
480 | self.started = True |
|
584 | self.sendData(self.send, self.data) | |
481 |
|
585 | |||
482 | self.data['STARTED'] = False |
|
|||
483 | return |
|
586 | return | |
484 |
|
587 | |||
485 | def sendToWeb(self): |
|
588 | def sendToWeb(self): | |
@@ -496,6 +599,6 class PlotterReceiver(ProcessingUnit, Process): | |||||
496 | time.sleep(1) |
|
599 | time.sleep(1) | |
497 | for kwargs in self.operationKwargs.values(): |
|
600 | for kwargs in self.operationKwargs.values(): | |
498 | if 'plot' in kwargs: |
|
601 | if 'plot' in kwargs: | |
499 |
|
|
602 | log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper())) | |
500 | sender_web_config.send_string(json.dumps(kwargs)) |
|
603 | sender_web_config.send_string(json.dumps(kwargs)) | |
501 |
self.isWebConfig = True |
|
604 | self.isWebConfig = True No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now