##// END OF EJS Templates
Fix SkyMapPlot
Juan C. Espinoza -
r1095:c7ed06c70307
parent child
Show More
@@ -15,11 +15,11 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
15 from schainpy.model.proc.jroproc_base import Operation
15 from schainpy.model.proc.jroproc_base import Operation
16 from schainpy.utils import log
16 from schainpy.utils import log
17
17
18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
18 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
19 blu_values = matplotlib.pyplot.get_cmap(
19 blu_values = matplotlib.pyplot.get_cmap(
20 "seismic_r", 20)(numpy.arange(20))[10:15]
20 'seismic_r', 20)(numpy.arange(20))[10:15]
21 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
21 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
22 "jro", numpy.vstack((blu_values, jet_values)))
22 'jro', numpy.vstack((blu_values, jet_values)))
23 matplotlib.pyplot.register_cmap(cmap=ncmap)
23 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')]
@@ -88,6 +88,7 class PlotData(Operation, Process):
88 self.colorbar = kwargs.get('colorbar', True)
88 self.colorbar = kwargs.get('colorbar', True)
89 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
89 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
90 self.titles = ['' for __ in range(16)]
90 self.titles = ['' for __ in range(16)]
91 self.polar = False
91
92
92 def __fmtTime(self, x, pos):
93 def __fmtTime(self, x, pos):
93 '''
94 '''
@@ -99,6 +100,10 class PlotData(Operation, Process):
99 '''
100 '''
100 Common setup for all figures, here figures and axes are created
101 Common setup for all figures, here figures and axes are created
101 '''
102 '''
103
104 if self.CODE not in self.data:
105 raise ValueError(log.error('Missing data for {}'.format(self.CODE),
106 self.name))
102
107
103 self.setup()
108 self.setup()
104
109
@@ -128,7 +133,7 class PlotData(Operation, Process):
128 facecolor='w')
133 facecolor='w')
129 self.figures.append(fig)
134 self.figures.append(fig)
130 for n in range(self.nplots):
135 for n in range(self.nplots):
131 ax = fig.add_subplot(self.nrows, self.ncols, n + 1)
136 ax = fig.add_subplot(self.nrows, self.ncols, n + 1, polar=self.polar)
132 ax.tick_params(labelsize=8)
137 ax.tick_params(labelsize=8)
133 ax.firsttime = True
138 ax.firsttime = True
134 ax.index = 0
139 ax.index = 0
@@ -145,7 +150,7 class PlotData(Operation, Process):
145 fig = plt.figure(figsize=(self.width, self.height),
150 fig = plt.figure(figsize=(self.width, self.height),
146 edgecolor='k',
151 edgecolor='k',
147 facecolor='w')
152 facecolor='w')
148 ax = fig.add_subplot(1, 1, 1)
153 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
149 ax.tick_params(labelsize=8)
154 ax.tick_params(labelsize=8)
150 ax.firsttime = True
155 ax.firsttime = True
151 ax.index = 0
156 ax.index = 0
@@ -343,7 +348,7 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) - datetime.datetime(1970, 1, 1)).total_seconds()
351 xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - datetime.datetime(1970, 1, 1)).total_seconds()
347 if self.data.localtime:
352 if self.data.localtime:
348 xmax += time.timezone
353 xmax += time.timezone
349 else:
354 else:
@@ -356,8 +361,6 class PlotData(Operation, Process):
356 i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0]
361 i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0]
357 ystep = Y[i-1]/5
362 ystep = Y[i-1]/5
358
363
359 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
360
361 for n, ax in enumerate(self.axes):
364 for n, ax in enumerate(self.axes):
362 if ax.firsttime:
365 if ax.firsttime:
363 ax.set_facecolor(self.bgcolor)
366 ax.set_facecolor(self.bgcolor)
@@ -377,7 +380,7 class PlotData(Operation, Process):
377 [tick.set_visible(False)
380 [tick.set_visible(False)
378 for tick in self.pf_axes[n].get_yticklabels()]
381 for tick in self.pf_axes[n].get_yticklabels()]
379 if self.colorbar:
382 if self.colorbar:
380 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
383 ax.cbar = plt.colorbar(ax.plt, ax=ax, fraction=0.1, pad=0.02, aspect=10)
381 ax.cbar.ax.tick_params(labelsize=8)
384 ax.cbar.ax.tick_params(labelsize=8)
382 ax.cbar.ax.press = None
385 ax.cbar.ax.press = None
383 if self.cb_label:
386 if self.cb_label:
@@ -386,14 +389,21 class PlotData(Operation, Process):
386 ax.cbar.set_label(self.cb_labels[n], size=8)
389 ax.cbar.set_label(self.cb_labels[n], size=8)
387 else:
390 else:
388 ax.cbar = None
391 ax.cbar = None
389
392
390 ax.set_title('{} - {} {}'.format(
393 if not self.polar:
394 ax.set_xlim(xmin, xmax)
395 ax.set_ylim(ymin, ymax)
396 ax.set_title('{} - {} {}'.format(
391 self.titles[n],
397 self.titles[n],
392 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
398 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
393 self.time_label),
399 self.time_label),
394 size=8)
400 size=8)
395 ax.set_xlim(xmin, xmax)
401 else:
396 ax.set_ylim(ymin, ymax)
402 ax.set_title('{}'.format(self.titles[n]), size=8)
403 ax.set_ylim(0, 90)
404 ax.set_yticks(numpy.arange(0, 90, 20))
405 ax.yaxis.labelpad = 40
406
397
407
398 def __plot(self):
408 def __plot(self):
399 '''
409 '''
@@ -405,7 +415,7 class PlotData(Operation, Process):
405
415
406 for n, fig in enumerate(self.figures):
416 for n, fig in enumerate(self.figures):
407 if self.nrows == 0 or self.nplots == 0:
417 if self.nrows == 0 or self.nplots == 0:
408 log.warning('No data', self.name)
418 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
409 continue
419 continue
410
420
411 fig.tight_layout()
421 fig.tight_layout()
@@ -427,7 +437,7 class PlotData(Operation, Process):
427 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
437 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
428 )
438 )
429 )
439 )
430 print 'Saving figure: {}'.format(figname)
440 log.log('Saving figure: {}'.format(figname), self.name)
431 fig.savefig(figname)
441 fig.savefig(figname)
432
442
433 def plot(self):
443 def plot(self):
@@ -810,7 +820,7 class PlotSkyMapData(PlotData):
810 Plot for meteors detection data
820 Plot for meteors detection data
811 '''
821 '''
812
822
813 CODE = 'met'
823 CODE = 'param'
814
824
815 def setup(self):
825 def setup(self):
816
826
@@ -818,25 +828,17 class PlotSkyMapData(PlotData):
818 self.nrows = 1
828 self.nrows = 1
819 self.width = 7.2
829 self.width = 7.2
820 self.height = 7.2
830 self.height = 7.2
821
831 self.nplots = 1
822 self.xlabel = 'Zonal Zenith Angle (deg)'
832 self.xlabel = 'Zonal Zenith Angle (deg)'
823 self.ylabel = 'Meridional Zenith Angle (deg)'
833 self.ylabel = 'Meridional Zenith Angle (deg)'
824
834 self.polar = True
825 if self.figure is None:
835 self.ymin = -180
826 self.figure = plt.figure(figsize=(self.width, self.height),
836 self.ymax = 180
827 edgecolor='k',
837 self.colorbar = False
828 facecolor='w')
829 else:
830 self.figure.clf()
831
832 self.ax = plt.subplot2grid(
833 (self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
834 self.ax.firsttime = True
835
838
836 def plot(self):
839 def plot(self):
837
840
838 arrayParameters = numpy.concatenate(
841 arrayParameters = numpy.concatenate(self.data['param'])
839 [self.data['param'][t] for t in self.times])
840 error = arrayParameters[:, -1]
842 error = arrayParameters[:, -1]
841 indValid = numpy.where(error == 0)[0]
843 indValid = numpy.where(error == 0)[0]
842 finalMeteor = arrayParameters[indValid, :]
844 finalMeteor = arrayParameters[indValid, :]
@@ -844,26 +846,21 class PlotSkyMapData(PlotData):
844 finalZenith = finalMeteor[:, 4]
846 finalZenith = finalMeteor[:, 4]
845
847
846 x = finalAzimuth * numpy.pi / 180
848 x = finalAzimuth * numpy.pi / 180
847 y = finalZenith
849 y = finalZenith
848
849 if self.ax.firsttime:
850 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
851 self.ax.set_ylim(0, 90)
852 self.ax.set_yticks(numpy.arange(0, 90, 20))
853 self.ax.set_xlabel(self.xlabel)
854 self.ax.set_ylabel(self.ylabel)
855 self.ax.yaxis.labelpad = 40
856 self.ax.firsttime = False
857 else:
858 self.ax.plot.set_data(x, y)
859
850
851 ax = self.axes[0]
852
853 if ax.firsttime:
854 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
855 else:
856 ax.plot.set_data(x, y)
860
857
861 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
858 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')
859 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,
860 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
864 dt2,
861 dt2,
865 len(x))
862 len(x))
866 self.ax.set_title(title, size=8)
863 self.titles[0] = title
867 self.saveTime = self.max_time
864 self.saveTime = self.max_time
868
865
869
866
@@ -900,7 +897,7 class PlotParamData(PlotRTIData):
900 )
897 )
901 else:
898 else:
902 self.z = self.data[self.CODE]
899 self.z = self.data[self.CODE]
903
900
904 self.z = numpy.ma.masked_invalid(self.z)
901 self.z = numpy.ma.masked_invalid(self.z)
905
902
906 for n, ax in enumerate(self.axes):
903 for n, ax in enumerate(self.axes):
General Comments 0
You need to be logged in to leave comments. Login now