@@ -1,934 +1,957 | |||
|
1 | 1 | |
|
2 | 2 | import os |
|
3 | 3 | import zmq |
|
4 | 4 | import time |
|
5 | 5 | import numpy |
|
6 | 6 | import datetime |
|
7 | 7 | import numpy as np |
|
8 | 8 | import matplotlib |
|
9 | 9 | import glob |
|
10 | 10 | matplotlib.use('TkAgg') |
|
11 | 11 | import matplotlib.pyplot as plt |
|
12 | 12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
13 | 13 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
14 | 14 | from multiprocessing import Process |
|
15 | 15 | |
|
16 | 16 | from schainpy.model.proc.jroproc_base import Operation |
|
17 | 17 | |
|
18 | 18 | plt.ion() |
|
19 | 19 | |
|
20 | 20 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
21 | 21 | |
|
22 | 22 | d1970 = datetime.datetime(1970,1,1) |
|
23 | 23 | |
|
24 | 24 | class PlotData(Operation, Process): |
|
25 | 25 | |
|
26 | 26 | CODE = 'Figure' |
|
27 | 27 | colormap = 'jro' |
|
28 | 28 | CONFLATE = False |
|
29 | 29 | __MAXNUMX = 80 |
|
30 | 30 | __missing = 1E30 |
|
31 | 31 | |
|
32 | 32 | def __init__(self, **kwargs): |
|
33 | 33 | |
|
34 | 34 | Operation.__init__(self, plot=True, **kwargs) |
|
35 | 35 | Process.__init__(self) |
|
36 | 36 | self.kwargs['code'] = self.CODE |
|
37 | 37 | self.mp = False |
|
38 | 38 | self.dataOut = None |
|
39 | 39 | self.isConfig = False |
|
40 | 40 | self.figure = None |
|
41 | 41 | self.axes = [] |
|
42 | 42 | self.localtime = kwargs.pop('localtime', True) |
|
43 | 43 | self.show = kwargs.get('show', True) |
|
44 | 44 | self.save = kwargs.get('save', False) |
|
45 | 45 | self.colormap = kwargs.get('colormap', self.colormap) |
|
46 | 46 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
47 | 47 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
48 | 48 | self.showprofile = kwargs.get('showprofile', True) |
|
49 | 49 | self.title = kwargs.get('wintitle', '') |
|
50 | 50 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
51 | 51 | self.zmin = kwargs.get('zmin', None) |
|
52 | 52 | self.zmax = kwargs.get('zmax', None) |
|
53 | 53 | self.xmin = kwargs.get('xmin', None) |
|
54 | 54 | self.xmax = kwargs.get('xmax', None) |
|
55 | 55 | self.xrange = kwargs.get('xrange', 24) |
|
56 | 56 | self.ymin = kwargs.get('ymin', None) |
|
57 | 57 | self.ymax = kwargs.get('ymax', None) |
|
58 | 58 | self.__MAXNUMY = kwargs.get('decimation', 80) |
|
59 | 59 | self.throttle_value = 5 |
|
60 | 60 | self.times = [] |
|
61 | 61 | #self.interactive = self.kwargs['parent'] |
|
62 | 62 | |
|
63 | 63 | ''' |
|
64 | 64 | this new parameter is created to plot data from varius channels at different figures |
|
65 | 65 | 1. crear una lista de figuras donde se puedan plotear las figuras, |
|
66 | 66 | 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras |
|
67 | 67 | 3. probar? |
|
68 | 68 | ''' |
|
69 | 69 | self.ind_plt_ch = kwargs.get('ind_plt_ch', False) |
|
70 | 70 | self.figurelist = None |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
74 | 74 | |
|
75 | 75 | if x_buffer.shape[0] < 2: |
|
76 | 76 | return x_buffer, y_buffer, z_buffer |
|
77 | 77 | |
|
78 | 78 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
79 | 79 | x_median = np.median(deltas) |
|
80 | 80 | |
|
81 | 81 | index = np.where(deltas > 5*x_median) |
|
82 | 82 | |
|
83 | 83 | if len(index[0]) != 0: |
|
84 | 84 | z_buffer[::, index[0], ::] = self.__missing |
|
85 | 85 | z_buffer = np.ma.masked_inside(z_buffer, |
|
86 | 86 | 0.99*self.__missing, |
|
87 | 87 | 1.01*self.__missing) |
|
88 | 88 | |
|
89 | 89 | return x_buffer, y_buffer, z_buffer |
|
90 | 90 | |
|
91 | 91 | def decimate(self): |
|
92 | 92 | |
|
93 | 93 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
94 | 94 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
95 | 95 | |
|
96 | 96 | # x = self.x[::dx] |
|
97 | 97 | x = self.x |
|
98 | 98 | y = self.y[::dy] |
|
99 | 99 | z = self.z[::, ::, ::dy] |
|
100 | 100 | |
|
101 | 101 | return x, y, z |
|
102 | 102 | |
|
103 | 103 | ''' |
|
104 | 104 | JM: |
|
105 | 105 | elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden |
|
106 | 106 | poner otro tiempo a la figura q no necesariamente es el ultimo. |
|
107 | 107 | Solo se realiza cuando termina la imagen. |
|
108 | 108 | Problemas: |
|
109 | -Aun no encuentro. | |
|
109 | ||
|
110 | File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot | |
|
111 | for n, eachfigure in enumerate(self.figurelist): | |
|
112 | TypeError: 'NoneType' object is not iterable | |
|
113 | ||
|
110 | 114 | ''' |
|
111 | 115 | def deleteanotherfiles(self): |
|
112 | 116 | figurenames=[] |
|
117 | if self.figurelist != None: | |
|
113 | 118 | for n, eachfigure in enumerate(self.figurelist): |
|
114 | 119 | #add specific name for each channel in channelList |
|
115 | 120 | ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE, |
|
116 | 121 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) |
|
117 | 122 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, |
|
118 | 123 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
119 | 124 | |
|
120 | 125 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures |
|
121 | 126 | if ghostfigure != figname: |
|
122 | 127 | os.remove(ghostfigure) |
|
123 | 128 | print 'Removing GhostFigures:' , figname |
|
129 | else : | |
|
130 | '''Erasing ghost images for just on******************''' | |
|
131 | ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) | |
|
132 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
133 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures | |
|
134 | if ghostfigure != figname: | |
|
135 | os.remove(ghostfigure) | |
|
136 | print 'Removing GhostFigures:' , figname | |
|
124 | 137 | |
|
125 | 138 | def __plot(self): |
|
126 | 139 | |
|
127 | 140 | print 'plotting...{}'.format(self.CODE) |
|
128 | 141 | if self.ind_plt_ch is False : #standard |
|
129 | 142 | if self.show: |
|
130 | 143 | self.figure.show() |
|
131 | 144 | self.plot() |
|
132 | 145 | plt.tight_layout() |
|
133 | 146 | self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(), |
|
134 | 147 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) |
|
135 | 148 | else : |
|
149 | print 'len(self.figurelist): ',len(self.figurelist) | |
|
136 | 150 | for n, eachfigure in enumerate(self.figurelist): |
|
137 | 151 | if self.show: |
|
138 | 152 | eachfigure.show() |
|
139 | 153 | |
|
140 | 154 | self.plot() # ok? como elijo que figura? |
|
141 | 155 | #eachfigure.subplots_adjust(left=0.2) |
|
142 | 156 | #eachfigure.subplots_adjuccst(right=0.2) |
|
143 | 157 | eachfigure.tight_layout() # ajuste de cada subplot |
|
144 | 158 | eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(), |
|
145 | 159 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) |
|
146 | 160 | |
|
147 | 161 | # if self.save: |
|
148 | 162 | # if self.ind_plt_ch is False : #standard |
|
149 | 163 | # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
150 | 164 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
151 | 165 | # print 'Saving figure: {}'.format(figname) |
|
152 | 166 | # self.figure.savefig(figname) |
|
153 | 167 | # else : |
|
154 | 168 | # for n, eachfigure in enumerate(self.figurelist): |
|
155 | 169 | # #add specific name for each channel in channelList |
|
156 | 170 | # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE, |
|
157 | 171 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
158 | 172 | # |
|
159 | 173 | # print 'Saving figure: {}'.format(figname) |
|
160 | 174 | # eachfigure.savefig(figname) |
|
161 | 175 | |
|
162 | 176 | if self.ind_plt_ch is False : |
|
163 | 177 | self.figure.canvas.draw() |
|
164 | 178 | else : |
|
165 | 179 | for eachfigure in self.figurelist: |
|
166 | 180 | eachfigure.canvas.draw() |
|
167 | 181 | |
|
168 | 182 | if self.save: |
|
169 | 183 | if self.ind_plt_ch is False : #standard |
|
170 | 184 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
171 | 185 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
172 | 186 | print 'Saving figure: {}'.format(figname) |
|
173 | 187 | self.figure.savefig(figname) |
|
174 | 188 | else : |
|
175 | 189 | for n, eachfigure in enumerate(self.figurelist): |
|
176 | 190 | #add specific name for each channel in channelList |
|
177 | 191 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, |
|
178 | 192 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
179 | 193 | |
|
180 | 194 | print 'Saving figure: {}'.format(figname) |
|
181 | 195 | eachfigure.savefig(figname) |
|
182 | 196 | |
|
183 | 197 | |
|
184 | 198 | def plot(self): |
|
185 | 199 | |
|
186 | 200 | print 'plotting...{}'.format(self.CODE.upper()) |
|
187 | 201 | return |
|
188 | 202 | |
|
189 | 203 | def run(self): |
|
190 | 204 | |
|
191 | 205 | print '[Starting] {}'.format(self.name) |
|
192 | 206 | |
|
193 | 207 | context = zmq.Context() |
|
194 | 208 | receiver = context.socket(zmq.SUB) |
|
195 | 209 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
196 | 210 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
197 | 211 | |
|
198 | 212 | if 'server' in self.kwargs['parent']: |
|
199 | 213 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
200 | 214 | else: |
|
201 | 215 | receiver.connect("ipc:///tmp/zmq.plots") |
|
202 | 216 | |
|
203 | 217 | seconds_passed = 0 |
|
204 | 218 | |
|
205 | 219 | while True: |
|
206 | 220 | try: |
|
207 | 221 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK |
|
208 | 222 | self.started = self.data['STARTED'] |
|
209 | 223 | self.dataOut = self.data['dataOut'] |
|
210 | 224 | |
|
211 | 225 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): |
|
212 | 226 | continue |
|
213 | 227 | |
|
214 | 228 | self.times = self.data['times'] |
|
215 | 229 | self.times.sort() |
|
216 | 230 | self.throttle_value = self.data['throttle'] |
|
217 | 231 | self.min_time = self.times[0] |
|
218 | 232 | self.max_time = self.times[-1] |
|
219 | 233 | |
|
220 | 234 | if self.isConfig is False: |
|
221 | 235 | print 'setting up' |
|
222 | 236 | self.setup() |
|
223 | 237 | self.isConfig = True |
|
224 | 238 | self.__plot() |
|
225 | 239 | |
|
226 | 240 | if self.data['ENDED'] is True: |
|
227 | 241 | print '********GRAPHIC ENDED********' |
|
228 | 242 | self.ended = True |
|
229 | 243 | self.isConfig = False |
|
230 | 244 | self.__plot() |
|
245 | #TODO : AUN NO FUNCIONA PARA COHERENCIA. | |
|
231 | 246 | self.deleteanotherfiles() #CLPDG |
|
232 | 247 | elif seconds_passed >= self.data['throttle']: |
|
233 | 248 | print 'passed', seconds_passed |
|
234 | 249 | self.__plot() |
|
235 | 250 | seconds_passed = 0 |
|
236 | 251 | |
|
237 | 252 | except zmq.Again as e: |
|
238 | 253 | print 'Waiting for data...' |
|
239 | 254 | plt.pause(2) |
|
240 | 255 | seconds_passed += 2 |
|
241 | 256 | |
|
242 | 257 | def close(self): |
|
243 | 258 | if self.dataOut: |
|
244 | 259 | self.__plot() |
|
245 | 260 | |
|
246 | 261 | |
|
247 | 262 | class PlotSpectraData(PlotData): |
|
248 | 263 | |
|
249 | 264 | CODE = 'spc' |
|
250 | 265 | colormap = 'jro' |
|
251 | 266 | CONFLATE = False |
|
252 | 267 | |
|
253 | 268 | def setup(self): |
|
254 | 269 | |
|
255 | 270 | ncolspan = 1 |
|
256 | 271 | colspan = 1 |
|
257 | 272 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
258 | 273 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
259 | 274 | self.width = 3.6*self.ncols |
|
260 | 275 | self.height = 3.2*self.nrows |
|
261 | 276 | if self.showprofile: |
|
262 | 277 | ncolspan = 3 |
|
263 | 278 | colspan = 2 |
|
264 | 279 | self.width += 1.2*self.ncols |
|
265 | 280 | |
|
266 | 281 | self.ylabel = 'Range [Km]' |
|
267 | 282 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
268 | 283 | |
|
269 | 284 | if self.figure is None: |
|
270 | 285 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
271 | 286 | edgecolor='k', |
|
272 | 287 | facecolor='w') |
|
273 | 288 | else: |
|
274 | 289 | self.figure.clf() |
|
275 | 290 | |
|
276 | 291 | n = 0 |
|
277 | 292 | for y in range(self.nrows): |
|
278 | 293 | for x in range(self.ncols): |
|
279 | 294 | if n >= self.dataOut.nChannels: |
|
280 | 295 | break |
|
281 | 296 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
282 | 297 | if self.showprofile: |
|
283 | 298 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
284 | 299 | |
|
285 | 300 | ax.firsttime = True |
|
286 | 301 | self.axes.append(ax) |
|
287 | 302 | n += 1 |
|
288 | 303 | |
|
289 | 304 | def plot(self): |
|
290 | 305 | |
|
291 | 306 | if self.xaxis == "frequency": |
|
292 | 307 | x = self.dataOut.getFreqRange(1)/1000. |
|
293 | 308 | xlabel = "Frequency (kHz)" |
|
294 | 309 | elif self.xaxis == "time": |
|
295 | 310 | x = self.dataOut.getAcfRange(1) |
|
296 | 311 | xlabel = "Time (ms)" |
|
297 | 312 | else: |
|
298 | 313 | x = self.dataOut.getVelRange(1) |
|
299 | 314 | xlabel = "Velocity (m/s)" |
|
300 | 315 | |
|
301 | 316 | y = self.dataOut.getHeiRange() |
|
302 | 317 | z = self.data[self.CODE] |
|
303 | 318 | |
|
304 | 319 | for n, ax in enumerate(self.axes): |
|
305 | 320 | if ax.firsttime: |
|
306 | 321 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
307 | 322 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
308 | 323 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
309 | 324 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
310 | 325 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
311 | 326 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
312 | 327 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
313 | 328 | vmin=self.zmin, |
|
314 | 329 | vmax=self.zmax, |
|
315 | 330 | cmap=plt.get_cmap(self.colormap) |
|
316 | 331 | ) |
|
317 | 332 | divider = make_axes_locatable(ax) |
|
318 | 333 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
319 | 334 | self.figure.add_axes(cax) |
|
320 | 335 | plt.colorbar(ax.plot, cax) |
|
321 | 336 | |
|
322 | 337 | ax.set_xlim(self.xmin, self.xmax) |
|
323 | 338 | ax.set_ylim(self.ymin, self.ymax) |
|
324 | 339 | |
|
325 | 340 | ax.set_ylabel(self.ylabel) |
|
326 | 341 | ax.set_xlabel(xlabel) |
|
327 | 342 | |
|
328 | 343 | ax.firsttime = False |
|
329 | 344 | |
|
330 | 345 | if self.showprofile: |
|
331 | 346 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
332 | 347 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
333 | 348 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
334 | 349 | ax.ax_profile.set_xlabel('dB') |
|
335 | 350 | ax.ax_profile.grid(b=True, axis='x') |
|
336 | 351 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
337 | 352 | color="k", linestyle="dashed", lw=2)[0] |
|
338 | 353 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
339 | 354 | else: |
|
340 | 355 | ax.plot.set_array(z[n].T.ravel()) |
|
341 | 356 | if self.showprofile: |
|
342 | 357 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
343 | 358 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
344 | 359 | |
|
345 | 360 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
346 | 361 | size=8) |
|
347 | 362 | self.saveTime = self.max_time |
|
348 | 363 | |
|
349 | 364 | |
|
350 | 365 | class PlotCrossSpectraData(PlotData): |
|
351 | 366 | |
|
352 | 367 | CODE = 'cspc' |
|
353 | 368 | zmin_coh = None |
|
354 | 369 | zmax_coh = None |
|
355 | 370 | zmin_phase = None |
|
356 | 371 | zmax_phase = None |
|
357 | 372 | CONFLATE = False |
|
358 | 373 | |
|
359 | 374 | def setup(self): |
|
360 | 375 | |
|
361 | 376 | ncolspan = 1 |
|
362 | 377 | colspan = 1 |
|
363 | 378 | self.ncols = 2 |
|
364 | 379 | self.nrows = self.dataOut.nPairs |
|
365 | 380 | self.width = 3.6*self.ncols |
|
366 | 381 | self.height = 3.2*self.nrows |
|
367 | 382 | |
|
368 | 383 | self.ylabel = 'Range [Km]' |
|
369 | 384 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
370 | 385 | |
|
371 | 386 | if self.figure is None: |
|
372 | 387 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
373 | 388 | edgecolor='k', |
|
374 | 389 | facecolor='w') |
|
375 | 390 | else: |
|
376 | 391 | self.figure.clf() |
|
377 | 392 | |
|
378 | 393 | for y in range(self.nrows): |
|
379 | 394 | for x in range(self.ncols): |
|
380 | 395 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
381 | 396 | ax.firsttime = True |
|
382 | 397 | self.axes.append(ax) |
|
383 | 398 | |
|
384 | 399 | def plot(self): |
|
385 | 400 | |
|
386 | 401 | if self.xaxis == "frequency": |
|
387 | 402 | x = self.dataOut.getFreqRange(1)/1000. |
|
388 | 403 | xlabel = "Frequency (kHz)" |
|
389 | 404 | elif self.xaxis == "time": |
|
390 | 405 | x = self.dataOut.getAcfRange(1) |
|
391 | 406 | xlabel = "Time (ms)" |
|
392 | 407 | else: |
|
393 | 408 | x = self.dataOut.getVelRange(1) |
|
394 | 409 | xlabel = "Velocity (m/s)" |
|
395 | 410 | |
|
396 | 411 | y = self.dataOut.getHeiRange() |
|
397 | 412 | z_coh = self.data['cspc_coh'] |
|
398 | 413 | z_phase = self.data['cspc_phase'] |
|
399 | 414 | |
|
400 | 415 | for n in range(self.nrows): |
|
401 | 416 | ax = self.axes[2*n] |
|
402 | 417 | ax1 = self.axes[2*n+1] |
|
403 | 418 | if ax.firsttime: |
|
404 | 419 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
405 | 420 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
406 | 421 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
407 | 422 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
408 | 423 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
409 | 424 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
410 | 425 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
411 | 426 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
412 | 427 | |
|
413 | 428 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
414 | 429 | vmin=self.zmin_coh, |
|
415 | 430 | vmax=self.zmax_coh, |
|
416 | 431 | cmap=plt.get_cmap(self.colormap_coh) |
|
417 | 432 | ) |
|
418 | 433 | divider = make_axes_locatable(ax) |
|
419 | 434 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
420 | 435 | self.figure.add_axes(cax) |
|
421 | 436 | plt.colorbar(ax.plot, cax) |
|
422 | 437 | |
|
423 | 438 | ax.set_xlim(self.xmin, self.xmax) |
|
424 | 439 | ax.set_ylim(self.ymin, self.ymax) |
|
425 | 440 | |
|
426 | 441 | ax.set_ylabel(self.ylabel) |
|
427 | 442 | ax.set_xlabel(xlabel) |
|
428 | 443 | ax.firsttime = False |
|
429 | 444 | |
|
430 | 445 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
431 | 446 | vmin=self.zmin_phase, |
|
432 | 447 | vmax=self.zmax_phase, |
|
433 | 448 | cmap=plt.get_cmap(self.colormap_phase) |
|
434 | 449 | ) |
|
435 | 450 | divider = make_axes_locatable(ax1) |
|
436 | 451 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
437 | 452 | self.figure.add_axes(cax) |
|
438 | 453 | plt.colorbar(ax1.plot, cax) |
|
439 | 454 | |
|
440 | 455 | ax1.set_xlim(self.xmin, self.xmax) |
|
441 | 456 | ax1.set_ylim(self.ymin, self.ymax) |
|
442 | 457 | |
|
443 | 458 | ax1.set_ylabel(self.ylabel) |
|
444 | 459 | ax1.set_xlabel(xlabel) |
|
445 | 460 | ax1.firsttime = False |
|
446 | 461 | else: |
|
447 | 462 | ax.plot.set_array(z_coh[n].T.ravel()) |
|
448 | 463 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
449 | 464 | |
|
450 | 465 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
451 | 466 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
452 | 467 | self.saveTime = self.max_time |
|
453 | 468 | |
|
454 | 469 | |
|
455 | 470 | class PlotSpectraMeanData(PlotSpectraData): |
|
456 | 471 | |
|
457 | 472 | CODE = 'spc_mean' |
|
458 | 473 | colormap = 'jet' |
|
459 | 474 | |
|
460 | 475 | def plot(self): |
|
461 | 476 | |
|
462 | 477 | if self.xaxis == "frequency": |
|
463 | 478 | x = self.dataOut.getFreqRange(1)/1000. |
|
464 | 479 | xlabel = "Frequency (kHz)" |
|
465 | 480 | elif self.xaxis == "time": |
|
466 | 481 | x = self.dataOut.getAcfRange(1) |
|
467 | 482 | xlabel = "Time (ms)" |
|
468 | 483 | else: |
|
469 | 484 | x = self.dataOut.getVelRange(1) |
|
470 | 485 | xlabel = "Velocity (m/s)" |
|
471 | 486 | |
|
472 | 487 | y = self.dataOut.getHeiRange() |
|
473 | 488 | z = self.data['spc'] |
|
474 | 489 | mean = self.data['mean'][self.max_time] |
|
475 | 490 | |
|
476 | 491 | for n, ax in enumerate(self.axes): |
|
477 | 492 | |
|
478 | 493 | if ax.firsttime: |
|
479 | 494 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
480 | 495 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
481 | 496 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
482 | 497 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
483 | 498 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
484 | 499 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
485 | 500 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
486 | 501 | vmin=self.zmin, |
|
487 | 502 | vmax=self.zmax, |
|
488 | 503 | cmap=plt.get_cmap(self.colormap) |
|
489 | 504 | ) |
|
490 | 505 | ax.plt_dop = ax.plot(mean[n], y, |
|
491 | 506 | color='k')[0] |
|
492 | 507 | |
|
493 | 508 | divider = make_axes_locatable(ax) |
|
494 | 509 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
495 | 510 | self.figure.add_axes(cax) |
|
496 | 511 | plt.colorbar(ax.plt, cax) |
|
497 | 512 | |
|
498 | 513 | ax.set_xlim(self.xmin, self.xmax) |
|
499 | 514 | ax.set_ylim(self.ymin, self.ymax) |
|
500 | 515 | |
|
501 | 516 | ax.set_ylabel(self.ylabel) |
|
502 | 517 | ax.set_xlabel(xlabel) |
|
503 | 518 | |
|
504 | 519 | ax.firsttime = False |
|
505 | 520 | |
|
506 | 521 | if self.showprofile: |
|
507 | 522 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
508 | 523 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
509 | 524 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
510 | 525 | ax.ax_profile.set_xlabel('dB') |
|
511 | 526 | ax.ax_profile.grid(b=True, axis='x') |
|
512 | 527 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
513 | 528 | color="k", linestyle="dashed", lw=2)[0] |
|
514 | 529 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
515 | 530 | else: |
|
516 | 531 | ax.plt.set_array(z[n].T.ravel()) |
|
517 | 532 | ax.plt_dop.set_data(mean[n], y) |
|
518 | 533 | if self.showprofile: |
|
519 | 534 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
520 | 535 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
521 | 536 | |
|
522 | 537 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
523 | 538 | size=8) |
|
524 | 539 | self.saveTime = self.max_time |
|
525 | 540 | |
|
526 | 541 | |
|
527 | 542 | class PlotRTIData(PlotData): |
|
528 | 543 | |
|
529 | 544 | CODE = 'rti' |
|
530 | 545 | colormap = 'jro' |
|
531 | 546 | |
|
532 | 547 | def setup(self): |
|
533 | 548 | self.ncols = 1 |
|
534 | 549 | self.nrows = self.dataOut.nChannels |
|
535 | 550 | self.width = 10 |
|
551 | #TODO : arreglar la altura de la figura, esta hardcodeada. | |
|
552 | #Se arreglo, testear! | |
|
553 | if self.ind_plt_ch: | |
|
554 | self.height = 3.2#*self.nrows if self.nrows<6 else 12 | |
|
555 | else: | |
|
536 | 556 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
557 | ||
|
558 | ''' | |
|
537 | 559 | if self.nrows==1: |
|
538 | 560 | self.height += 1 |
|
561 | ''' | |
|
539 | 562 | self.ylabel = 'Range [Km]' |
|
540 | 563 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
541 | 564 | |
|
542 | 565 | ''' |
|
543 | 566 | Logica: |
|
544 | 567 | 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura |
|
545 | 568 | 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el |
|
546 | 569 | axis dentro de "Figures" como un diccionario. |
|
547 | 570 | ''' |
|
548 | 571 | if self.ind_plt_ch is False: #standard mode |
|
549 | 572 | |
|
550 | 573 | if self.figure is None: #solo para la priemra vez |
|
551 | 574 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
552 | 575 | edgecolor='k', |
|
553 | 576 | facecolor='w') |
|
554 | 577 | else: |
|
555 | 578 | self.figure.clf() |
|
556 | 579 | self.axes = [] |
|
557 | 580 | |
|
558 | 581 | |
|
559 | 582 | for n in range(self.nrows): |
|
560 | 583 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
561 | 584 | #ax = self.figure(n+1) |
|
562 | 585 | ax.firsttime = True |
|
563 | 586 | self.axes.append(ax) |
|
564 | 587 | |
|
565 | 588 | else : #append one figure foreach channel in channelList |
|
566 | 589 | if self.figurelist == None: |
|
567 | 590 | self.figurelist = [] |
|
568 | 591 | for n in range(self.nrows): |
|
569 | 592 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
570 | 593 | edgecolor='k', |
|
571 | 594 | facecolor='w') |
|
572 | 595 | #add always one subplot |
|
573 | 596 | self.figurelist.append(self.figure) |
|
574 | 597 | |
|
575 | 598 | else : # cada dia nuevo limpia el axes, pero mantiene el figure |
|
576 | 599 | for eachfigure in self.figurelist: |
|
577 | 600 | eachfigure.clf() # eliminaria todas las figuras de la lista? |
|
578 | 601 | self.axes = [] |
|
579 | 602 | |
|
580 | 603 | for eachfigure in self.figurelist: |
|
581 | 604 | ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura |
|
582 | 605 | #ax = self.figure(n+1) |
|
583 | 606 | ax.firsttime = True |
|
584 | 607 | #Cada figura tiene un distinto puntero |
|
585 | 608 | self.axes.append(ax) |
|
586 | 609 | #plt.close(eachfigure) |
|
587 | 610 | |
|
588 | 611 | |
|
589 | 612 | def plot(self): |
|
590 | 613 | |
|
591 | 614 | if self.ind_plt_ch is False: #standard mode |
|
592 | 615 | self.x = np.array(self.times) |
|
593 | 616 | self.y = self.dataOut.getHeiRange() |
|
594 | 617 | self.z = [] |
|
595 | 618 | |
|
596 | 619 | for ch in range(self.nrows): |
|
597 | 620 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
598 | 621 | |
|
599 | 622 | self.z = np.array(self.z) |
|
600 | 623 | for n, ax in enumerate(self.axes): |
|
601 | 624 | x, y, z = self.fill_gaps(*self.decimate()) |
|
602 | 625 | xmin = self.min_time |
|
603 | 626 | xmax = xmin+self.xrange*60*60 |
|
604 | 627 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
605 | 628 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
606 | 629 | if ax.firsttime: |
|
607 | 630 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
608 | 631 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
609 | 632 | plot = ax.pcolormesh(x, y, z[n].T, |
|
610 | 633 | vmin=self.zmin, |
|
611 | 634 | vmax=self.zmax, |
|
612 | 635 | cmap=plt.get_cmap(self.colormap) |
|
613 | 636 | ) |
|
614 | 637 | divider = make_axes_locatable(ax) |
|
615 | 638 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
616 | 639 | self.figure.add_axes(cax) |
|
617 | 640 | plt.colorbar(plot, cax) |
|
618 | 641 | ax.set_ylim(self.ymin, self.ymax) |
|
619 | 642 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
620 | 643 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
621 | 644 | ax.set_ylabel(self.ylabel) |
|
622 | 645 | if self.xmin is None: |
|
623 | 646 | xmin = self.min_time |
|
624 | 647 | else: |
|
625 | 648 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
626 | 649 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
627 | 650 | ax.set_xlim(xmin, xmax) |
|
628 | 651 | ax.firsttime = False |
|
629 | 652 | else: |
|
630 | 653 | ax.collections.remove(ax.collections[0]) |
|
631 | 654 | ax.set_xlim(xmin, xmax) |
|
632 | 655 | plot = ax.pcolormesh(x, y, z[n].T, |
|
633 | 656 | vmin=self.zmin, |
|
634 | 657 | vmax=self.zmax, |
|
635 | 658 | cmap=plt.get_cmap(self.colormap) |
|
636 | 659 | ) |
|
637 | 660 | ax.set_title('{} {}'.format(self.titles[n], |
|
638 | 661 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
639 | 662 | size=8) |
|
640 | 663 | |
|
641 | 664 | self.saveTime = self.min_time |
|
642 | 665 | else : |
|
643 | 666 | self.x = np.array(self.times) |
|
644 | 667 | self.y = self.dataOut.getHeiRange() |
|
645 | 668 | self.z = [] |
|
646 | 669 | |
|
647 | 670 | for ch in range(self.nrows): |
|
648 | 671 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
649 | 672 | |
|
650 | 673 | self.z = np.array(self.z) |
|
651 | 674 | for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes |
|
652 | 675 | |
|
653 | 676 | x, y, z = self.fill_gaps(*self.decimate()) |
|
654 | 677 | xmin = self.min_time |
|
655 | 678 | xmax = xmin+self.xrange*60*60 |
|
656 | 679 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
657 | 680 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
658 | 681 | if self.axes[n].firsttime: |
|
659 | 682 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
660 | 683 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
661 | 684 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
662 | 685 | vmin=self.zmin, |
|
663 | 686 | vmax=self.zmax, |
|
664 | 687 | cmap=plt.get_cmap(self.colormap) |
|
665 | 688 | ) |
|
666 | 689 | divider = make_axes_locatable(self.axes[n]) |
|
667 | 690 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
668 | 691 | eachfigure.add_axes(cax) |
|
669 | 692 | #self.figure2.add_axes(cax) |
|
670 | 693 | plt.colorbar(plot, cax) |
|
671 | 694 | self.axes[n].set_ylim(self.ymin, self.ymax) |
|
672 | 695 | |
|
673 | 696 | self.axes[n].xaxis.set_major_formatter(FuncFormatter(func)) |
|
674 | 697 | self.axes[n].xaxis.set_major_locator(LinearLocator(6)) |
|
675 | 698 | |
|
676 | 699 | self.axes[n].set_ylabel(self.ylabel) |
|
677 | 700 | |
|
678 | 701 | if self.xmin is None: |
|
679 | 702 | xmin = self.min_time |
|
680 | 703 | else: |
|
681 | 704 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
682 | 705 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
683 | 706 | |
|
684 | 707 | self.axes[n].set_xlim(xmin, xmax) |
|
685 | 708 | self.axes[n].firsttime = False |
|
686 | 709 | else: |
|
687 | 710 | self.axes[n].collections.remove(self.axes[n].collections[0]) |
|
688 | 711 | self.axes[n].set_xlim(xmin, xmax) |
|
689 | 712 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
690 | 713 | vmin=self.zmin, |
|
691 | 714 | vmax=self.zmax, |
|
692 | 715 | cmap=plt.get_cmap(self.colormap) |
|
693 | 716 | ) |
|
694 | 717 | self.axes[n].set_title('{} {}'.format(self.titles[n], |
|
695 | 718 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
696 | 719 | size=8) |
|
697 | 720 | |
|
698 | 721 | self.saveTime = self.min_time |
|
699 | 722 | |
|
700 | 723 | |
|
701 | 724 | class PlotCOHData(PlotRTIData): |
|
702 | 725 | |
|
703 | 726 | CODE = 'coh' |
|
704 | 727 | |
|
705 | 728 | def setup(self): |
|
706 | 729 | |
|
707 | 730 | self.ncols = 1 |
|
708 | 731 | self.nrows = self.dataOut.nPairs |
|
709 | 732 | self.width = 10 |
|
710 | 733 | self.height = 2.2*self.nrows if self.nrows<6 else 12 |
|
711 | 734 | if self.nrows==1: |
|
712 | 735 | self.height += 1 |
|
713 | 736 | self.ylabel = 'Range [Km]' |
|
714 | 737 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
715 | 738 | |
|
716 | 739 | if self.figure is None: |
|
717 | 740 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
718 | 741 | edgecolor='k', |
|
719 | 742 | facecolor='w') |
|
720 | 743 | else: |
|
721 | 744 | self.figure.clf() |
|
722 | 745 | self.axes = [] |
|
723 | 746 | |
|
724 | 747 | for n in range(self.nrows): |
|
725 | 748 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
726 | 749 | ax.firsttime = True |
|
727 | 750 | self.axes.append(ax) |
|
728 | 751 | |
|
729 | 752 | |
|
730 | 753 | class PlotNoiseData(PlotData): |
|
731 | 754 | CODE = 'noise' |
|
732 | 755 | |
|
733 | 756 | def setup(self): |
|
734 | 757 | |
|
735 | 758 | self.ncols = 1 |
|
736 | 759 | self.nrows = 1 |
|
737 | 760 | self.width = 10 |
|
738 | 761 | self.height = 3.2 |
|
739 | 762 | self.ylabel = 'Intensity [dB]' |
|
740 | 763 | self.titles = ['Noise'] |
|
741 | 764 | |
|
742 | 765 | if self.figure is None: |
|
743 | 766 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
744 | 767 | edgecolor='k', |
|
745 | 768 | facecolor='w') |
|
746 | 769 | else: |
|
747 | 770 | self.figure.clf() |
|
748 | 771 | self.axes = [] |
|
749 | 772 | |
|
750 | 773 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
751 | 774 | self.ax.firsttime = True |
|
752 | 775 | |
|
753 | 776 | def plot(self): |
|
754 | 777 | |
|
755 | 778 | x = self.times |
|
756 | 779 | xmin = self.min_time |
|
757 | 780 | xmax = xmin+self.xrange*60*60 |
|
758 | 781 | if self.ax.firsttime: |
|
759 | 782 | for ch in self.dataOut.channelList: |
|
760 | 783 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
761 | 784 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
762 | 785 | self.ax.firsttime = False |
|
763 | 786 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
764 | 787 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
765 | 788 | self.ax.set_ylabel(self.ylabel) |
|
766 | 789 | plt.legend() |
|
767 | 790 | else: |
|
768 | 791 | for ch in self.dataOut.channelList: |
|
769 | 792 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
770 | 793 | self.ax.lines[ch].set_data(x, y) |
|
771 | 794 | |
|
772 | 795 | self.ax.set_xlim(xmin, xmax) |
|
773 | 796 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
774 | 797 | self.saveTime = self.min_time |
|
775 | 798 | |
|
776 | 799 | |
|
777 | 800 | class PlotWindProfilerData(PlotRTIData): |
|
778 | 801 | |
|
779 | 802 | CODE = 'wind' |
|
780 | 803 | colormap = 'seismic' |
|
781 | 804 | |
|
782 | 805 | def setup(self): |
|
783 | 806 | self.ncols = 1 |
|
784 | 807 | self.nrows = self.dataOut.data_output.shape[0] |
|
785 | 808 | self.width = 10 |
|
786 | 809 | self.height = 2.2*self.nrows |
|
787 | 810 | self.ylabel = 'Height [Km]' |
|
788 | 811 | self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind'] |
|
789 | 812 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
790 | 813 | self.windFactor = [1, 1, 100] |
|
791 | 814 | |
|
792 | 815 | if self.figure is None: |
|
793 | 816 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
794 | 817 | edgecolor='k', |
|
795 | 818 | facecolor='w') |
|
796 | 819 | else: |
|
797 | 820 | self.figure.clf() |
|
798 | 821 | self.axes = [] |
|
799 | 822 | |
|
800 | 823 | for n in range(self.nrows): |
|
801 | 824 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
802 | 825 | ax.firsttime = True |
|
803 | 826 | self.axes.append(ax) |
|
804 | 827 | |
|
805 | 828 | def plot(self): |
|
806 | 829 | |
|
807 | 830 | self.x = np.array(self.times) |
|
808 | 831 | self.y = self.dataOut.heightList |
|
809 | 832 | self.z = [] |
|
810 | 833 | |
|
811 | 834 | for ch in range(self.nrows): |
|
812 | 835 | self.z.append([self.data['output'][t][ch] for t in self.times]) |
|
813 | 836 | |
|
814 | 837 | self.z = np.array(self.z) |
|
815 | 838 | self.z = numpy.ma.masked_invalid(self.z) |
|
816 | 839 | |
|
817 | 840 | cmap=plt.get_cmap(self.colormap) |
|
818 | 841 | cmap.set_bad('black', 1.) |
|
819 | 842 | |
|
820 | 843 | for n, ax in enumerate(self.axes): |
|
821 | 844 | x, y, z = self.fill_gaps(*self.decimate()) |
|
822 | 845 | xmin = self.min_time |
|
823 | 846 | xmax = xmin+self.xrange*60*60 |
|
824 | 847 | if ax.firsttime: |
|
825 | 848 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
826 | 849 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
827 | 850 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
828 | 851 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
829 | 852 | |
|
830 | 853 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
831 | 854 | vmin=self.zmin, |
|
832 | 855 | vmax=self.zmax, |
|
833 | 856 | cmap=cmap |
|
834 | 857 | ) |
|
835 | 858 | divider = make_axes_locatable(ax) |
|
836 | 859 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
837 | 860 | self.figure.add_axes(cax) |
|
838 | 861 | cb = plt.colorbar(plot, cax) |
|
839 | 862 | cb.set_label(self.clabels[n]) |
|
840 | 863 | ax.set_ylim(self.ymin, self.ymax) |
|
841 | 864 | |
|
842 | 865 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
843 | 866 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
844 | 867 | |
|
845 | 868 | ax.set_ylabel(self.ylabel) |
|
846 | 869 | |
|
847 | 870 | ax.set_xlim(xmin, xmax) |
|
848 | 871 | ax.firsttime = False |
|
849 | 872 | else: |
|
850 | 873 | ax.collections.remove(ax.collections[0]) |
|
851 | 874 | ax.set_xlim(xmin, xmax) |
|
852 | 875 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
853 | 876 | vmin=self.zmin, |
|
854 | 877 | vmax=self.zmax, |
|
855 | 878 | cmap=plt.get_cmap(self.colormap) |
|
856 | 879 | ) |
|
857 | 880 | ax.set_title('{} {}'.format(self.titles[n], |
|
858 | 881 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
859 | 882 | size=8) |
|
860 | 883 | |
|
861 | 884 | self.saveTime = self.min_time |
|
862 | 885 | |
|
863 | 886 | |
|
864 | 887 | class PlotSNRData(PlotRTIData): |
|
865 | 888 | CODE = 'snr' |
|
866 | 889 | colormap = 'jet' |
|
867 | 890 | |
|
868 | 891 | class PlotDOPData(PlotRTIData): |
|
869 | 892 | CODE = 'dop' |
|
870 | 893 | colormap = 'jet' |
|
871 | 894 | |
|
872 | 895 | |
|
873 | 896 | class PlotPHASEData(PlotCOHData): |
|
874 | 897 | CODE = 'phase' |
|
875 | 898 | colormap = 'seismic' |
|
876 | 899 | |
|
877 | 900 | |
|
878 | 901 | class PlotSkyMapData(PlotData): |
|
879 | 902 | |
|
880 | 903 | CODE = 'met' |
|
881 | 904 | |
|
882 | 905 | def setup(self): |
|
883 | 906 | |
|
884 | 907 | self.ncols = 1 |
|
885 | 908 | self.nrows = 1 |
|
886 | 909 | self.width = 7.2 |
|
887 | 910 | self.height = 7.2 |
|
888 | 911 | |
|
889 | 912 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
890 | 913 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
891 | 914 | |
|
892 | 915 | if self.figure is None: |
|
893 | 916 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
894 | 917 | edgecolor='k', |
|
895 | 918 | facecolor='w') |
|
896 | 919 | else: |
|
897 | 920 | self.figure.clf() |
|
898 | 921 | |
|
899 | 922 | self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True) |
|
900 | 923 | self.ax.firsttime = True |
|
901 | 924 | |
|
902 | 925 | |
|
903 | 926 | def plot(self): |
|
904 | 927 | |
|
905 | 928 | arrayParameters = np.concatenate([self.data['param'][t] for t in self.times]) |
|
906 | 929 | error = arrayParameters[:,-1] |
|
907 | 930 | indValid = numpy.where(error == 0)[0] |
|
908 | 931 | finalMeteor = arrayParameters[indValid,:] |
|
909 | 932 | finalAzimuth = finalMeteor[:,3] |
|
910 | 933 | finalZenith = finalMeteor[:,4] |
|
911 | 934 | |
|
912 | 935 | x = finalAzimuth*numpy.pi/180 |
|
913 | 936 | y = finalZenith |
|
914 | 937 | |
|
915 | 938 | if self.ax.firsttime: |
|
916 | 939 | self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0] |
|
917 | 940 | self.ax.set_ylim(0,90) |
|
918 | 941 | self.ax.set_yticks(numpy.arange(0,90,20)) |
|
919 | 942 | self.ax.set_xlabel(self.xlabel) |
|
920 | 943 | self.ax.set_ylabel(self.ylabel) |
|
921 | 944 | self.ax.yaxis.labelpad = 40 |
|
922 | 945 | self.ax.firsttime = False |
|
923 | 946 | else: |
|
924 | 947 | self.ax.plot.set_data(x, y) |
|
925 | 948 | |
|
926 | 949 | |
|
927 | 950 | dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
928 | 951 | dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
929 | 952 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
930 | 953 | dt2, |
|
931 | 954 | len(x)) |
|
932 | 955 | self.ax.set_title(title, size=8) |
|
933 | 956 | |
|
934 | 957 | self.saveTime = self.max_time |
@@ -1,101 +1,109 | |||
|
1 | 1 | import argparse |
|
2 | ||
|
2 | import datetime | |
|
3 | 3 | from schainpy.controller import Project, multiSchain |
|
4 | 4 | |
|
5 | 5 | desc = "HF_EXAMPLE" |
|
6 | 6 | path='/home/ci-81/Documents/DATA/HFADATA/hfdata_2017/pdata/sp1_f0' |
|
7 | 7 | path = '/media/ci-81/Huancayo/DATA/hfradar_2016/pdata/sp1_f1' |
|
8 | 8 | path = '/media/ci-81/Huancayo/DATA/hfradar_2016/pdata/sp1_f1' |
|
9 | 9 | def fiber(cursor, skip, q, dt): |
|
10 | 10 | |
|
11 | 11 | controllerObj = Project() |
|
12 | 12 | |
|
13 | 13 | controllerObj.setup(id='191', name='test01', description=desc) |
|
14 | 14 | |
|
15 | 15 | readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader', |
|
16 | 16 | path=path, |
|
17 | 17 | startDate=dt, |
|
18 | 18 | endDate=dt, |
|
19 | 19 | startTime="00:00:00", |
|
20 | 20 | endTime="23:59:59", |
|
21 | 21 | online=0, |
|
22 | 22 | #set=1426485881, |
|
23 | 23 | delay=10, |
|
24 | 24 | walk=1, |
|
25 | 25 | queue=q, |
|
26 | 26 | cursor=cursor, |
|
27 | 27 | skip=skip, |
|
28 | 28 | #timezone=-5*3600 |
|
29 | 29 | ) |
|
30 | 30 | |
|
31 | 31 | # #opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
32 | 32 | # |
|
33 | 33 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
34 | 34 | opObj10 = procUnitConfObj2.addOperation(name='removeInterference') |
|
35 | 35 | |
|
36 | 36 | # procUnitConfObj2.addParameter(name='nipp', value='5', format='int') |
|
37 | 37 | |
|
38 | 38 | procUnitConfObj3 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=readUnitConfObj.getId()) |
|
39 | 39 | opObj11 = procUnitConfObj3.addOperation(name='SpectralMoments', optype='other') |
|
40 | 40 | |
|
41 | 41 | # |
|
42 | 42 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
43 | 43 | # opObj11.addParameter(name='id', value='1000', format='int') |
|
44 | 44 | # opObj11.addParameter(name='wintitle', value='HF_Jicamarca_Spc', format='str') |
|
45 | 45 | # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
46 | 46 | # opObj11.addParameter(name='zmin', value='-120', format='float') |
|
47 | 47 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
48 | 48 | # opObj11.addParameter(name='save', value='1', format='int') |
|
49 | 49 | # opObj11.addParameter(name='figpath', value=figpath, format='str') |
|
50 | 50 | |
|
51 | 51 | # opObj11 = procUnitConfObj3.addOperation(name='Parameters1Plot', optype='other') |
|
52 | 52 | # opObj11.addParameter(name='channelList', value='0', format='intList') |
|
53 | 53 | |
|
54 | 54 | # opObj11.addParameter(name='id', value='2000', format='int') |
|
55 | 55 | # opObj11.addParameter(name='colormap', value='0', format='bool') |
|
56 | 56 | # opObj11.addParameter(name='onlySNR', value='1', format='bool') |
|
57 | 57 | # opObj11.addParameter(name='DOP', value='0', format='bool') |
|
58 | 58 | # opObj11.addParameter(name='showSNR', value='1', format='bool') |
|
59 | 59 | # opObj11.addParameter(name='SNRthresh', value='0', format='int') |
|
60 | 60 | # opObj11.addParameter(name='SNRmin', value='-10', format='int') |
|
61 | 61 | # opObj11.addParameter(name='SNRmax', value='30', format='int') |
|
62 | 62 | |
|
63 | 63 | # opObj11.addParameter(name='showSNR', value='1', format='int') |
|
64 | 64 | # # opObj11.addParameter(name='channelList', value='0', format='intlist') |
|
65 | 65 | # # opObj11.addParameter(name='xmin', value='0', format='float') |
|
66 | 66 | # opObj11.addParameter(name='xmin', value='0', format='float') |
|
67 | 67 | # opObj11.addParameter(name='xmax', value='24', format='float') |
|
68 | 68 | |
|
69 | 69 | # opObj11.addParameter(name='zmin', value='-110', format='float') |
|
70 | 70 | # opObj11.addParameter(name='zmax', value='-70', format='float') |
|
71 | 71 | # opObj11.addParameter(name='save', value='0', format='int') |
|
72 | 72 | # # opObj11.addParameter(name='figpath', value='/tmp/', format='str') |
|
73 | 73 | # |
|
74 | 74 | opObj12 = procUnitConfObj3.addOperation(name='PublishData', optype='other') |
|
75 | 75 | #opObj12.addParameter(name='server', value='tcp://10.10.10.82:3001', format='int') |
|
76 | 76 | opObj12.addParameter(name='zeromq', value=1, format='int') |
|
77 | 77 | |
|
78 | 78 | |
|
79 | 79 | # opObj13 = procUnitConfObj3.addOperation(name='PublishData', optype='other') |
|
80 | 80 | # opObj13.addParameter(name='zeromq', value=1, format='int') |
|
81 | 81 | # opObj13.addParameter(name='server', value="juanca", format='str') |
|
82 | 82 | |
|
83 | 83 | # opObj12.addParameter(name='delay', value=1, format='int') |
|
84 | 84 | |
|
85 | 85 | |
|
86 | 86 | # print "Escribiendo el archivo XML" |
|
87 | 87 | # controllerObj.writeXml(filename) |
|
88 | 88 | # print "Leyendo el archivo XML" |
|
89 | 89 | # controllerObj.readXml(filename) |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | # timeit.timeit('controllerObj.run()', number=2) |
|
93 | 93 | |
|
94 | 94 | controllerObj.start() |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | if __name__ == '__main__': |
|
98 | ############################DATE########################################## | |
|
99 | doitnow = datetime.datetime.now() - datetime.timedelta(days=1) # Un dia antes | |
|
100 | y = doitnow.year | |
|
101 | m = doitnow.month | |
|
102 | d = int(doitnow.day) | |
|
103 | date = str(y)+"/"+str(m)+"/"+str(d) | |
|
104 | ########################################################################### | |
|
98 | 105 | parser = argparse.ArgumentParser(description='Set number of parallel processes') |
|
99 | 106 | parser.add_argument('--nProcess', default=1, type=int) |
|
100 | 107 | args = parser.parse_args() |
|
101 |
multiSchain(fiber, nProcess=8, startDate='2016/04/23', endDate='2016/04/2 |
|
|
108 | multiSchain(fiber, nProcess=8, startDate='2016/04/23', endDate='2016/04/23') | |
|
109 | #multiSchain(fiber, nProcess=4, startDate=date, endDate=date) #Plot automatico de un dia antes |
@@ -1,82 +1,89 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | ''' |
|
3 | 3 | Created on Jul 7, 2014 |
|
4 | 4 | |
|
5 | 5 | @author: roj-idl71 |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | |
|
9 | 9 | from schainpy.controller import Project |
|
10 | 10 | |
|
11 | 11 | if __name__ == '__main__': |
|
12 | 12 | desc = "Segundo Test" |
|
13 | 13 | |
|
14 | 14 | controllerObj = Project() |
|
15 | 15 | controllerObj.setup(id='191', name='test01', description=desc) |
|
16 | 16 | |
|
17 | 17 | proc1 = controllerObj.addProcUnit(name='PlotterReceiver') |
|
18 | 18 | # proc1.addParameter(name='realtime', value='0', format='bool') |
|
19 | 19 | #proc1.addParameter(name='plottypes', value='rti,coh,phase,snr,dop', format='str') |
|
20 | 20 | #proc1.addParameter(name='plottypes', value='rti,coh,phase,snr', format='str') |
|
21 | proc1.addParameter(name='plottypes', value='snr,dop', format='str') | |
|
21 | ||
|
22 | #proc1.addParameter(name='plottypes', value='snr,dop', format='str') | |
|
23 | proc1.addParameter(name='plottypes', value='rti,dop,snr,phase,coh', format='str') | |
|
24 | #proc1.addParameter(name='plottypes', value='phase,coh', format='str') | |
|
22 | 25 | |
|
23 | 26 | #proc1.addParameter(name='throttle', value='10', format='int') |
|
24 | 27 | |
|
25 | 28 | proc1.addParameter(name='interactive', value='0', format='bool') # ? PREGUNTAR |
|
26 | 29 | # proc1.addParameter(name='server', value='tcp://10.10.10.82:7000', format='str') |
|
27 | 30 | ## TODO Agregar direccion de server de publicacion a graficos como variable |
|
28 | 31 | |
|
29 | 32 | """ |
|
30 | 33 | op1 = proc1.addOperation(name='PlotRTIData', optype='other') |
|
31 | 34 | op1.addParameter(name='wintitle', value='HF System', format='str') |
|
32 | 35 | op1.addParameter(name='save', value='/home/ci-81/Pictures', format='str') |
|
33 | 36 | op1.addParameter(name='show', value='0', format='bool') |
|
34 | 37 | op1.addParameter(name='zmin', value='-110', format='float') |
|
35 | 38 | op1.addParameter(name='zmax', value='-50', format='float') |
|
36 | 39 | op1.addParameter(name='colormap', value='jet', format='str') |
|
37 | # | |
|
38 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') | |
|
39 | op2.addParameter(name='wintitle', value='HF System', format='str') | |
|
40 | op2.addParameter(name='zmin', value='0.001', format='float') | |
|
41 | op2.addParameter(name='zmax', value='1', format='float') | |
|
42 | op2.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
43 | op2.addParameter(name='colormap', value='jet', format='str') | |
|
44 | op2.addParameter(name='show', value='0', format='bool') | |
|
45 | # # | |
|
46 | 40 | |
|
47 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') | |
|
48 | op6.addParameter(name='wintitle', value='HF System', format='str') | |
|
49 | op6.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
50 | op6.addParameter(name='show', value='1', format='bool') | |
|
51 | # | |
|
52 | 41 | |
|
53 | 42 | # proc2 = controllerObj.addProcUnit(name='ReceiverData') |
|
54 | 43 | # proc2.addParameter(name='server', value='juanca', format='str') |
|
55 | 44 | # proc2.addParameter(name='plottypes', value='snr,dop', format='str') |
|
56 | 45 | # |
|
57 | 46 | """ |
|
47 | ||
|
48 | op2 = proc1.addOperation(name='PlotCOHData', optype='other') | |
|
49 | op2.addParameter(name='wintitle', value='HF System Coh', format='str') | |
|
50 | op2.addParameter(name='zmin', value='0.001', format='float') | |
|
51 | op2.addParameter(name='zmax', value='1', format='float') | |
|
52 | op2.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
53 | op2.addParameter(name='colormap', value='jet', format='str') | |
|
54 | op2.addParameter(name='show', value='1', format='bool') | |
|
55 | ||
|
58 | 56 | op3 = proc1.addOperation(name='PlotSNRData', optype='other') |
|
59 | 57 | op3.addParameter(name='wintitle', value='HF System SNR0', format='str') |
|
60 | 58 | op3.addParameter(name='save', value='/home/ci-81/Pictures', format='str') |
|
61 |
op3.addParameter(name='show', value=' |
|
|
59 | op3.addParameter(name='show', value='1', format='bool') | |
|
62 | 60 | op3.addParameter(name='zmin', value='-10', format='int') |
|
63 | 61 | op3.addParameter(name='zmax', value='30', format='int') |
|
64 | 62 | op3.addParameter(name='SNRthresh', value='0', format='float') |
|
65 | 63 | op3.addParameter(name='ind_plt_ch',value='1',format = 'bool') |
|
66 | 64 | |
|
67 | # | |
|
65 | ||
|
68 | 66 | op5 = proc1.addOperation(name='PlotDOPData', optype='other') |
|
69 | 67 | op5.addParameter(name='wintitle', value='HF System DOP', format='str') |
|
70 | 68 | op5.addParameter(name='save', value='/home/ci-81/Pictures', format='str') |
|
71 | 69 | op5.addParameter(name='show', value='1', format='bool') |
|
72 |
op5.addParameter(name='zmin', value='-1 |
|
|
73 |
op5.addParameter(name='zmax', value='1 |
|
|
70 | op5.addParameter(name='zmin', value='-140', format='float') | |
|
71 | op5.addParameter(name='zmax', value='140', format='float') | |
|
74 | 72 | op5.addParameter(name='colormap', value='RdBu_r', format='str') |
|
75 | 73 | op5.addParameter(name='ind_plt_ch',value='1',format = 'bool') |
|
76 | """ | |
|
77 | op4 = proc1.addOperation(name='PlotSNRData1', optype='other') | |
|
78 | op4.addParameter(name='wintitle', value='HF System SNR1', format='str') | |
|
79 | op4.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
80 | op4.addParameter(name='show', value='0', format='bool') | |
|
81 | """ | |
|
74 | ||
|
75 | # op4 = proc1.addOperation(name='PlotSNRData1', optype='other') | |
|
76 | # op4.addParameter(name='wintitle', value='HF System SNR1', format='str') | |
|
77 | # op4.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
78 | # op4.addParameter(name='show', value='0', format='bool') | |
|
79 | ||
|
80 | op6 = proc1.addOperation(name='PlotPHASEData', optype='other') | |
|
81 | op6.addParameter(name='wintitle', value='HF System', format='str') | |
|
82 | op6.addParameter(name='colormap', value='RdBu_r', format='str') | |
|
83 | op6.addParameter(name='zmin', value='-180', format='float') | |
|
84 | op6.addParameter(name='zmax', value='180', format='float') | |
|
85 | op6.addParameter(name='save', value='/home/ci-81/Pictures', format='str') | |
|
86 | op6.addParameter(name='show', value='1', format='bool') | |
|
87 | op6.addParameter(name='ind_plt_ch',value='0',format = 'bool') | |
|
88 | """ """ | |
|
82 | 89 | 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="/media/ci-81/Huancayo/DATA/hfradar_2016/pdata/sp1_f1" /><Parameter format="date" id="191113" name="startDate" value="2016/04/2 |
|
|
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="/media/ci-81/Huancayo/DATA/hfradar_2016/pdata/sp1_f1" /><Parameter format="date" id="191113" name="startDate" value="2016/04/23" /><Parameter format="date" id="191114" name="endDate" value="2016/04/23" /><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="8" /><Parameter format="int" id="191119" name="skip" value="16" /><Parameter format="int" id="191120" name="delay" value="10" /><Parameter format="int" id="191121" name="walk" 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" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="removeInterference" priority="2" type="self" /></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now