##// END OF EJS Templates
decimation a 300
José Chávez -
r1093:6f37ceb2e70a
parent child
Show More
@@ -24,6 +24,7 matplotlib.pyplot.register_cmap(cmap=ncmap)
24 24
25 25 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
26 26
27
27 28 def figpause(interval):
28 29 backend = plt.rcParams['backend']
29 30 if backend in matplotlib.rcsetup.interactive_bk:
@@ -35,6 +36,7 def figpause(interval):
35 36 canvas.start_event_loop(interval)
36 37 return
37 38
39
38 40 class PlotData(Operation, Process):
39 41 '''
40 42 Base class for Schain plotting operations
@@ -51,6 +53,7 class PlotData(Operation, Process):
51 53
52 54 Operation.__init__(self, plot=True, **kwargs)
53 55 Process.__init__(self)
56 self.contador = 0
54 57 self.kwargs['code'] = self.CODE
55 58 self.mp = False
56 59 self.data = None
@@ -80,7 +83,7 class PlotData(Operation, Process):
80 83 self.ymin = kwargs.get('ymin', None)
81 84 self.ymax = kwargs.get('ymax', None)
82 85 self.xlabel = kwargs.get('xlabel', None)
83 self.__MAXNUMY = kwargs.get('decimation', 100)
86 self.__MAXNUMY = kwargs.get('decimation', 300)
84 87 self.showSNR = kwargs.get('showSNR', False)
85 88 self.oneFigure = kwargs.get('oneFigure', True)
86 89 self.width = kwargs.get('width', None)
@@ -104,9 +107,9 class PlotData(Operation, Process):
104 107
105 108 self.time_label = 'LT' if self.localtime else 'UTC'
106 109 if self.data.localtime:
107 self.getDateTime = datetime.datetime.fromtimestamp
110 self.getDateTime = datetime.datetime.fromtimestamp
108 111 else:
109 self.getDateTime = datetime.datetime.utcfromtimestamp
112 self.getDateTime = datetime.datetime.utcfromtimestamp
110 113
111 114 if self.width is None:
112 115 self.width = 8
@@ -133,7 +136,7 class PlotData(Operation, Process):
133 136 ax.firsttime = True
134 137 ax.index = 0
135 138 ax.press = None
136 self.axes.append(ax)
139 self.axes.append(ax)
137 140 if self.showprofile:
138 141 cax = self.__add_axes(ax, size=size, pad=pad)
139 142 cax.tick_params(labelsize=8)
@@ -150,7 +153,7 class PlotData(Operation, Process):
150 153 ax.firsttime = True
151 154 ax.index = 0
152 155 ax.press = None
153 self.figures.append(fig)
156 self.figures.append(fig)
154 157 self.axes.append(ax)
155 158 if self.showprofile:
156 159 cax = self.__add_axes(ax, size=size, pad=pad)
@@ -179,19 +182,19 class PlotData(Operation, Process):
179 182 Event for pressing keys (up, down) change colormap
180 183 '''
181 184 ax = event.inaxes
182 if ax in self.axes:
185 if ax in self.axes:
183 186 if event.key == 'down':
184 187 ax.index += 1
185 188 elif event.key == 'up':
186 189 ax.index -= 1
187 190 if ax.index < 0:
188 ax.index = len(CMAPS) - 1
191 ax.index = len(CMAPS) - 1
189 192 elif ax.index == len(CMAPS):
190 193 ax.index = 0
191 cmap = CMAPS[ax.index]
194 cmap = CMAPS[ax.index]
192 195 ax.cbar.set_cmap(cmap)
193 196 ax.cbar.draw_all()
194 ax.plt.set_cmap(cmap)
197 ax.plt.set_cmap(cmap)
195 198 ax.cbar.patch.figure.canvas.draw()
196 199 self.colormap = cmap.name
197 200
@@ -202,13 +205,14 class PlotData(Operation, Process):
202 205 cb_ax = event.inaxes
203 206 if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]:
204 207 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
205 pt = ax.cbar.ax.bbox.get_points()[:,1]
208 pt = ax.cbar.ax.bbox.get_points()[:, 1]
206 209 nrm = ax.cbar.norm
207 vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
210 vmin, vmax, p0, p1, pS = (
211 nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
208 212 scale = 2 if event.step == 1 else 0.5
209 point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0)
210 ax.cbar.norm.vmin = point - scale*(point - vmin)
211 ax.cbar.norm.vmax = point - scale*(point - vmax)
213 point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0)
214 ax.cbar.norm.vmin = point - scale * (point - vmin)
215 ax.cbar.norm.vmax = point - scale * (point - vmax)
212 216 ax.plt.set_norm(ax.cbar.norm)
213 217 ax.cbar.draw_all()
214 218 ax.cbar.patch.figure.canvas.draw()
@@ -235,23 +239,23 class PlotData(Operation, Process):
235 239 return
236 240 if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]:
237 241 return
238 if cb_ax.press is None:
242 if cb_ax.press is None:
239 243 return
240 244
241 245 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
242 246 xprev, yprev = cb_ax.press
243 247 dx = event.x - xprev
244 248 dy = event.y - yprev
245 cb_ax.press = event.x, event.y
249 cb_ax.press = event.x, event.y
246 250 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
247 251 perc = 0.03
248 252
249 253 if event.button == 1:
250 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
251 ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy)
254 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
255 ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy)
252 256 elif event.button == 3:
253 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
254 ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy)
257 ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy)
258 ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy)
255 259
256 260 ax.cbar.draw_all()
257 261 ax.plt.set_norm(ax.cbar.norm)
@@ -331,8 +335,9 class PlotData(Operation, Process):
331 335 xmin = self.min_time
332 336 else:
333 337 if self.xaxis is 'time':
334 dt = self.getDateTime(self.min_time)
335 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
338 dt = self.getDateTime(self.min_time)
339 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) -
340 datetime.datetime(1970, 1, 1)).total_seconds()
336 341 if self.data.localtime:
337 342 xmin += time.timezone
338 343 else:
@@ -343,18 +348,20 class PlotData(Operation, Process):
343 348 else:
344 349 if self.xaxis is 'time':
345 350 dt = self.getDateTime(self.max_time)
346 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
351 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) -
352 datetime.datetime(1970, 1, 1)).total_seconds()
347 353 if self.data.localtime:
348 354 xmax += time.timezone
349 355 else:
350 356 xmax = self.xmax
351 357
352 358 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
353 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
359 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
354 360
355 361 Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000])
356 i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0]
357 ystep = Y[i-1]/5
362 i = 1 if numpy.where(ymax < Y)[
363 0][0] < 0 else numpy.where(ymax < Y)[0][0]
364 ystep = Y[i - 1] / 5
358 365
359 366 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
360 367
@@ -362,9 +369,9 class PlotData(Operation, Process):
362 369 if ax.firsttime:
363 370 ax.set_facecolor(self.bgcolor)
364 371 ax.yaxis.set_major_locator(MultipleLocator(ystep))
365 if self.xaxis is 'time':
372 if self.xaxis is 'time':
366 373 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
367 ax.xaxis.set_major_locator(LinearLocator(9))
374 ax.xaxis.set_major_locator(LinearLocator(9))
368 375 if self.xlabel is not None:
369 376 ax.set_xlabel(self.xlabel)
370 377 ax.set_ylabel(self.ylabel)
@@ -388,9 +395,9 class PlotData(Operation, Process):
388 395 ax.cbar = None
389 396
390 397 ax.set_title('{} - {} {}'.format(
391 self.titles[n],
392 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
393 self.time_label),
398 self.titles[n],
399 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
400 self.time_label),
394 401 size=8)
395 402 ax.set_xlim(xmin, xmax)
396 403 ax.set_ylim(ymin, ymax)
@@ -406,14 +413,15 class PlotData(Operation, Process):
406 413 for n, fig in enumerate(self.figures):
407 414 if self.nrows == 0 or self.nplots == 0:
408 415 log.warning('No data', self.name)
409 continue
410
416 continue
417
411 418 fig.tight_layout()
412 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
419 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
413 420 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
414 421 # fig.canvas.draw()
415 422
416 if self.save and self.data.ended:
423 if self.save: # and self.data.ended:
424 self.contador += 1
417 425 channels = range(self.nrows)
418 426 if self.oneFigure:
419 427 label = ''
@@ -421,10 +429,12 class PlotData(Operation, Process):
421 429 label = '_{}'.format(channels[n])
422 430 figname = os.path.join(
423 431 self.save,
424 '{}{}_{}.png'.format(
432 '{}{}_{}{}.png'.format(
425 433 self.CODE,
426 434 label,
427 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
435 self.getDateTime(self.saveTime).strftime(
436 '%y%m%d_%H%M%S'),
437 str(self.contador),
428 438 )
429 439 )
430 440 print 'Saving figure: {}'.format(figname)
@@ -857,7 +867,6 class PlotSkyMapData(PlotData):
857 867 else:
858 868 self.ax.plot.set_data(x, y)
859 869
860
861 870 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
862 871 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
863 872 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
@@ -906,14 +915,16 class PlotParamData(PlotRTIData):
906 915 for n, ax in enumerate(self.axes):
907 916
908 917 x, y, z = self.fill_gaps(*self.decimate())
909 self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n])
910 self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n])
911
918 self.zmax = self.zmax if self.zmax is not None else numpy.max(
919 self.z[n])
920 self.zmin = self.zmin if self.zmin is not None else numpy.min(
921 self.z[n])
922
912 923 if ax.firsttime:
913 924 if self.zlimits is not None:
914 925 self.zmin, self.zmax = self.zlimits[n]
915
916 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
926
927 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
917 928 vmin=self.zmin,
918 929 vmax=self.zmax,
919 930 cmap=self.cmaps[n]
@@ -922,7 +933,7 class PlotParamData(PlotRTIData):
922 933 if self.zlimits is not None:
923 934 self.zmin, self.zmax = self.zlimits[n]
924 935 ax.collections.remove(ax.collections[0])
925 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
936 ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n],
926 937 vmin=self.zmin,
927 938 vmax=self.zmax,
928 939 cmap=self.cmaps[n]
@@ -930,6 +941,7 class PlotParamData(PlotRTIData):
930 941
931 942 self.saveTime = self.min_time
932 943
944
933 945 class PlotOutputData(PlotParamData):
934 946 '''
935 947 Plot data_output object
General Comments 0
You need to be logged in to leave comments. Login now