##// 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 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 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 class PlotData(Operation, Process):
29 class PlotData(Operation, Process):
24 '''
30 '''
@@ -59,9 +65,7 class PlotData(Operation, Process):
59 self.zmin = kwargs.get('zmin', None)
65 self.zmin = kwargs.get('zmin', None)
60 self.zmax = kwargs.get('zmax', None)
66 self.zmax = kwargs.get('zmax', None)
61 self.zlimits = kwargs.get('zlimits', None)
67 self.zlimits = kwargs.get('zlimits', None)
62 self.xmin = kwargs.get('xmin', None)
68 self.xmin = kwargs.get('xmin', None)
63 if self.xmin is not None:
64 self.xmin += 5
65 self.xmax = kwargs.get('xmax', None)
69 self.xmax = kwargs.get('xmax', None)
66 self.xrange = kwargs.get('xrange', 24)
70 self.xrange = kwargs.get('xrange', 24)
67 self.ymin = kwargs.get('ymin', None)
71 self.ymin = kwargs.get('ymin', None)
@@ -83,6 +87,8 class PlotData(Operation, Process):
83
87
84 self.setup()
88 self.setup()
85
89
90 self.time_label = 'LT' if self.localtime else 'UTC'
91
86 if self.width is None:
92 if self.width is None:
87 self.width = 8
93 self.width = 8
88
94
@@ -106,6 +112,7 class PlotData(Operation, Process):
106 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
112 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
107 ax.tick_params(labelsize=8)
113 ax.tick_params(labelsize=8)
108 ax.firsttime = True
114 ax.firsttime = True
115 ax.index = 0
109 self.axes.append(ax)
116 self.axes.append(ax)
110 if self.showprofile:
117 if self.showprofile:
111 cax = self.__add_axes(ax, size=size, pad=pad)
118 cax = self.__add_axes(ax, size=size, pad=pad)
@@ -121,6 +128,7 class PlotData(Operation, Process):
121 ax = fig.add_subplot(1, 1, 1)
128 ax = fig.add_subplot(1, 1, 1)
122 ax.tick_params(labelsize=8)
129 ax.tick_params(labelsize=8)
123 ax.firsttime = True
130 ax.firsttime = True
131 ax.index = 0
124 self.figures.append(fig)
132 self.figures.append(fig)
125 self.axes.append(ax)
133 self.axes.append(ax)
126 if self.showprofile:
134 if self.showprofile:
@@ -136,6 +144,29 class PlotData(Operation, Process):
136 cmap.set_bad(self.bgcolor, 1.)
144 cmap.set_bad(self.bgcolor, 1.)
137 self.cmaps.append(cmap)
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 def __add_axes(self, ax, size='30%', pad='8%'):
170 def __add_axes(self, ax, size='30%', pad='8%'):
140 '''
171 '''
141 Add new axes to the given figure
172 Add new axes to the given figure
@@ -204,7 +235,7 class PlotData(Operation, Process):
204 if self.xaxis is 'time':
235 if self.xaxis is 'time':
205 dt = datetime.datetime.fromtimestamp(self.min_time)
236 dt = datetime.datetime.fromtimestamp(self.min_time)
206 xmin = (datetime.datetime.combine(dt.date(),
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 else:
239 else:
209 xmin = self.xmin
240 xmin = self.xmin
210
241
@@ -214,7 +245,7 class PlotData(Operation, Process):
214 if self.xaxis is 'time':
245 if self.xaxis is 'time':
215 dt = datetime.datetime.fromtimestamp(self.min_time)
246 dt = datetime.datetime.fromtimestamp(self.min_time)
216 xmax = (datetime.datetime.combine(dt.date(),
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 else:
249 else:
219 xmax = self.xmax
250 xmax = self.xmax
220
251
@@ -241,20 +272,20 class PlotData(Operation, Process):
241 self.pf_axes[n].grid(b=True, axis='x')
272 self.pf_axes[n].grid(b=True, axis='x')
242 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
273 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
243 if self.colorbar:
274 if self.colorbar:
244 cb = plt.colorbar(ax.plt, ax=ax, pad=0.02)
275 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
245 cb.ax.tick_params(labelsize=8)
276 ax.cbar.ax.tick_params(labelsize=8)
246 if self.cb_label:
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 elif self.cb_labels:
279 elif self.cb_labels:
249 cb.set_label(self.cb_labels[n], size=8)
280 ax.cbar.set_label(self.cb_labels[n], size=8)
250
281
251 ax.set_title('{} - {} UTC'.format(
282 ax.set_title('{} - {} {}'.format(
252 self.titles[n],
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 size=8)
286 size=8)
255 ax.set_xlim(xmin, xmax)
287 ax.set_xlim(xmin, xmax)
256 ax.set_ylim(ymin, ymax)
288 ax.set_ylim(ymin, ymax)
257
258
289
259 def __plot(self):
290 def __plot(self):
260 '''
291 '''
@@ -314,10 +345,15 class PlotData(Operation, Process):
314
345
315 while True:
346 while True:
316 try:
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]
355 self.min_time = self.times[0]
320 self.max_time = self.data.times[-1]
356 self.max_time = self.times[-1]
321
357
322 if self.isConfig is False:
358 if self.isConfig is False:
323 self.__setup()
359 self.__setup()
@@ -532,7 +568,7 class PlotRTIData(PlotData):
532 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
568 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
533
569
534 def plot(self):
570 def plot(self):
535 self.x = self.data.times
571 self.x = self.times
536 self.y = self.data.heights
572 self.y = self.data.heights
537 self.z = self.data[self.CODE]
573 self.z = self.data[self.CODE]
538 self.z = numpy.ma.masked_invalid(self.z)
574 self.z = numpy.ma.masked_invalid(self.z)
@@ -613,7 +649,7 class PlotNoiseData(PlotData):
613
649
614 def plot(self):
650 def plot(self):
615
651
616 x = self.data.times
652 x = self.times
617 xmin = self.min_time
653 xmin = self.min_time
618 xmax = xmin+self.xrange*60*60
654 xmax = xmin+self.xrange*60*60
619 Y = self.data[self.CODE]
655 Y = self.data[self.CODE]
@@ -681,7 +717,7 class PlotSkyMapData(PlotData):
681
717
682 def plot(self):
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 error = arrayParameters[:,-1]
721 error = arrayParameters[:,-1]
686 indValid = numpy.where(error == 0)[0]
722 indValid = numpy.where(error == 0)[0]
687 finalMeteor = arrayParameters[indValid,:]
723 finalMeteor = arrayParameters[indValid,:]
@@ -737,7 +773,7 class PlotParamData(PlotRTIData):
737
773
738 def plot(self):
774 def plot(self):
739 self.data.normalize_heights()
775 self.data.normalize_heights()
740 self.x = self.data.times
776 self.x = self.times
741 self.y = self.data.heights
777 self.y = self.data.heights
742 if self.showSNR:
778 if self.showSNR:
743 self.z = numpy.concatenate(
779 self.z = numpy.concatenate(
General Comments 0
You need to be logged in to leave comments. Login now