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