##// END OF EJS Templates
Add interactive change of CMAP and localtime support
jespinoza -
r1071:0950cde3ae87
parent child
Show More
@@ -15,10 +15,16 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
15 15 from schainpy.model.proc.jroproc_base import Operation
16 16 from schainpy.utils import log
17 17
18 func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
19 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
20 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
21 matplotlib.pyplot.register_cmap(cmap=ncmap)
19 22
20 d1970 = datetime.datetime(1970, 1, 1)
23 func = lambda x, pos: '{}'.format(datetime.datetime.fromtimestamp(x).strftime('%H:%M'))
21 24
25 UT1970 = datetime.datetime(1970, 1, 1) - datetime.timedelta(seconds=time.timezone)
26
27 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
22 28
23 29 class PlotData(Operation, Process):
24 30 '''
@@ -59,9 +65,7 class PlotData(Operation, Process):
59 65 self.zmin = kwargs.get('zmin', None)
60 66 self.zmax = kwargs.get('zmax', None)
61 67 self.zlimits = kwargs.get('zlimits', None)
62 self.xmin = kwargs.get('xmin', None)
63 if self.xmin is not None:
64 self.xmin += 5
68 self.xmin = kwargs.get('xmin', None)
65 69 self.xmax = kwargs.get('xmax', None)
66 70 self.xrange = kwargs.get('xrange', 24)
67 71 self.ymin = kwargs.get('ymin', None)
@@ -83,6 +87,8 class PlotData(Operation, Process):
83 87
84 88 self.setup()
85 89
90 self.time_label = 'LT' if self.localtime else 'UTC'
91
86 92 if self.width is None:
87 93 self.width = 8
88 94
@@ -106,6 +112,7 class PlotData(Operation, Process):
106 112 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
107 113 ax.tick_params(labelsize=8)
108 114 ax.firsttime = True
115 ax.index = 0
109 116 self.axes.append(ax)
110 117 if self.showprofile:
111 118 cax = self.__add_axes(ax, size=size, pad=pad)
@@ -121,6 +128,7 class PlotData(Operation, Process):
121 128 ax = fig.add_subplot(1, 1, 1)
122 129 ax.tick_params(labelsize=8)
123 130 ax.firsttime = True
131 ax.index = 0
124 132 self.figures.append(fig)
125 133 self.axes.append(ax)
126 134 if self.showprofile:
@@ -136,6 +144,29 class PlotData(Operation, Process):
136 144 cmap.set_bad(self.bgcolor, 1.)
137 145 self.cmaps.append(cmap)
138 146
147 for fig in self.figures:
148 fig.canvas.mpl_connect('key_press_event', self.event_key_press)
149
150 def event_key_press(self, event):
151 '''
152 '''
153
154 for ax in self.axes:
155 if ax == event.inaxes:
156 if event.key == 'down':
157 ax.index += 1
158 elif event.key == 'up':
159 ax.index -= 1
160 if ax.index < 0:
161 ax.index = len(CMAPS) - 1
162 elif ax.index == len(CMAPS):
163 ax.index = 0
164 cmap = CMAPS[ax.index]
165 ax.cbar.set_cmap(cmap)
166 ax.cbar.draw_all()
167 ax.plt.set_cmap(cmap)
168 ax.cbar.patch.figure.canvas.draw()
169
139 170 def __add_axes(self, ax, size='30%', pad='8%'):
140 171 '''
141 172 Add new axes to the given figure
@@ -204,7 +235,7 class PlotData(Operation, Process):
204 235 if self.xaxis is 'time':
205 236 dt = datetime.datetime.fromtimestamp(self.min_time)
206 237 xmin = (datetime.datetime.combine(dt.date(),
207 datetime.time(int(self.xmin), 0, 0))-d1970).total_seconds()
238 datetime.time(int(self.xmin), 0, 0))-UT1970).total_seconds()
208 239 else:
209 240 xmin = self.xmin
210 241
@@ -214,7 +245,7 class PlotData(Operation, Process):
214 245 if self.xaxis is 'time':
215 246 dt = datetime.datetime.fromtimestamp(self.min_time)
216 247 xmax = (datetime.datetime.combine(dt.date(),
217 datetime.time(int(self.xmax), 0, 0))-d1970).total_seconds()
248 datetime.time(int(self.xmax), 0, 0))-UT1970).total_seconds()
218 249 else:
219 250 xmax = self.xmax
220 251
@@ -241,20 +272,20 class PlotData(Operation, Process):
241 272 self.pf_axes[n].grid(b=True, axis='x')
242 273 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
243 274 if self.colorbar:
244 cb = plt.colorbar(ax.plt, ax=ax, pad=0.02)
245 cb.ax.tick_params(labelsize=8)
275 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
276 ax.cbar.ax.tick_params(labelsize=8)
246 277 if self.cb_label:
247 cb.set_label(self.cb_label, size=8)
278 ax.cbar.set_label(self.cb_label, size=8)
248 279 elif self.cb_labels:
249 cb.set_label(self.cb_labels[n], size=8)
250
251 ax.set_title('{} - {} UTC'.format(
280 ax.cbar.set_label(self.cb_labels[n], size=8)
281
282 ax.set_title('{} - {} {}'.format(
252 283 self.titles[n],
253 datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S')),
284 datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S'),
285 self.time_label),
254 286 size=8)
255 287 ax.set_xlim(xmin, xmax)
256 288 ax.set_ylim(ymin, ymax)
257
258 289
259 290 def __plot(self):
260 291 '''
@@ -314,10 +345,15 class PlotData(Operation, Process):
314 345
315 346 while True:
316 347 try:
317 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
348 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
349
350 if self.localtime:
351 self.times = self.data.times - time.timezone
352 else:
353 self.times = self.data.times
318 354
319 self.min_time = self.data.times[0]
320 self.max_time = self.data.times[-1]
355 self.min_time = self.times[0]
356 self.max_time = self.times[-1]
321 357
322 358 if self.isConfig is False:
323 359 self.__setup()
@@ -532,7 +568,7 class PlotRTIData(PlotData):
532 568 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
533 569
534 570 def plot(self):
535 self.x = self.data.times
571 self.x = self.times
536 572 self.y = self.data.heights
537 573 self.z = self.data[self.CODE]
538 574 self.z = numpy.ma.masked_invalid(self.z)
@@ -613,7 +649,7 class PlotNoiseData(PlotData):
613 649
614 650 def plot(self):
615 651
616 x = self.data.times
652 x = self.times
617 653 xmin = self.min_time
618 654 xmax = xmin+self.xrange*60*60
619 655 Y = self.data[self.CODE]
@@ -681,7 +717,7 class PlotSkyMapData(PlotData):
681 717
682 718 def plot(self):
683 719
684 arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.data.times])
720 arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.times])
685 721 error = arrayParameters[:,-1]
686 722 indValid = numpy.where(error == 0)[0]
687 723 finalMeteor = arrayParameters[indValid,:]
@@ -737,7 +773,7 class PlotParamData(PlotRTIData):
737 773
738 774 def plot(self):
739 775 self.data.normalize_heights()
740 self.x = self.data.times
776 self.x = self.times
741 777 self.y = self.data.heights
742 778 if self.showSNR:
743 779 self.z = numpy.concatenate(
General Comments 0
You need to be logged in to leave comments. Login now