@@ -20,9 +20,7 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15 | |||
|
20 | 20 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) |
|
21 | 21 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
22 | 22 | |
|
23 | func = lambda x, pos: '{}'.format(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | |
|
24 | ||
|
25 | UT1970 = datetime.datetime(1970, 1, 1) - datetime.timedelta(seconds=time.timezone) | |
|
23 | func = lambda x, pos: '{}'.format(datetime.datetime.utcfromtimestamp(x).strftime('%H:%M')) | |
|
26 | 24 | |
|
27 | 25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')] |
|
28 | 26 | |
@@ -113,6 +111,7 class PlotData(Operation, Process): | |||
|
113 | 111 | ax.tick_params(labelsize=8) |
|
114 | 112 | ax.firsttime = True |
|
115 | 113 | ax.index = 0 |
|
114 | ax.press = None | |
|
116 | 115 | self.axes.append(ax) |
|
117 | 116 | if self.showprofile: |
|
118 | 117 | cax = self.__add_axes(ax, size=size, pad=pad) |
@@ -129,6 +128,7 class PlotData(Operation, Process): | |||
|
129 | 128 | ax.tick_params(labelsize=8) |
|
130 | 129 | ax.firsttime = True |
|
131 | 130 | ax.index = 0 |
|
131 | ax.press = None | |
|
132 | 132 | self.figures.append(fig) |
|
133 | 133 | self.axes.append(ax) |
|
134 | 134 | if self.showprofile: |
@@ -145,27 +145,101 class PlotData(Operation, Process): | |||
|
145 | 145 | self.cmaps.append(cmap) |
|
146 | 146 | |
|
147 | 147 | for fig in self.figures: |
|
148 |
fig.canvas.mpl_connect('key_press_event', self. |
|
|
148 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
|
149 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
|
150 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
|
151 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
|
152 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
|
153 | ||
|
154 | def OnKeyPress(self, event): | |
|
155 | ''' | |
|
156 | Event for pressing keys (up, down) change colormap | |
|
157 | ''' | |
|
158 | ax = event.inaxes | |
|
159 | if ax in self.axes: | |
|
160 | if event.key == 'down': | |
|
161 | ax.index += 1 | |
|
162 | elif event.key == 'up': | |
|
163 | ax.index -= 1 | |
|
164 | if ax.index < 0: | |
|
165 | ax.index = len(CMAPS) - 1 | |
|
166 | elif ax.index == len(CMAPS): | |
|
167 | ax.index = 0 | |
|
168 | cmap = CMAPS[ax.index] | |
|
169 | ax.cbar.set_cmap(cmap) | |
|
170 | ax.cbar.draw_all() | |
|
171 | ax.plt.set_cmap(cmap) | |
|
172 | ax.cbar.patch.figure.canvas.draw() | |
|
149 | 173 | |
|
150 |
def |
|
|
174 | def OnBtnScroll(self, event): | |
|
151 | 175 | ''' |
|
176 | Event for scrolling, scale figure | |
|
152 | 177 | ''' |
|
178 | cb_ax = event.inaxes | |
|
179 | if cb_ax in [ax.cbar.ax for ax in self.axes]: | |
|
180 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
181 | pt = ax.cbar.ax.bbox.get_points()[:,1] | |
|
182 | nrm = ax.cbar.norm | |
|
183 | vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |
|
184 | scale = 2 if event.step == 1 else 0.5 | |
|
185 | point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0) | |
|
186 | ax.cbar.norm.vmin = point - scale*(point - vmin) | |
|
187 | ax.cbar.norm.vmax = point - scale*(point - vmax) | |
|
188 | ax.plt.set_norm(ax.cbar.norm) | |
|
189 | ax.cbar.draw_all() | |
|
190 | ax.cbar.patch.figure.canvas.draw() | |
|
191 | ||
|
192 | def onBtnPress(self, event): | |
|
193 | ''' | |
|
194 | Event for mouse button press | |
|
195 | ''' | |
|
196 | cb_ax = event.inaxes | |
|
197 | if cb_ax is None: | |
|
198 | return | |
|
153 | 199 | |
|
154 | for ax in self.axes: | |
|
155 |
|
|
|
156 | if event.key == 'down': | |
|
157 |
|
|
|
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() | |
|
200 | if cb_ax in [ax.cbar.ax for ax in self.axes]: | |
|
201 | cb_ax.press = event.x, event.y | |
|
202 | else: | |
|
203 | cb_ax.press = None | |
|
204 | ||
|
205 | def onMotion(self, event): | |
|
206 | ''' | |
|
207 | Event for move inside colorbar | |
|
208 | ''' | |
|
209 | cb_ax = event.inaxes | |
|
210 | if cb_ax is None: | |
|
211 | return | |
|
212 | if cb_ax not in [ax.cbar.ax for ax in self.axes]: | |
|
213 | return | |
|
214 | if cb_ax.press is None: | |
|
215 | return | |
|
216 | ||
|
217 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
218 | xprev, yprev = cb_ax.press | |
|
219 | dx = event.x - xprev | |
|
220 | dy = event.y - yprev | |
|
221 | cb_ax.press = event.x, event.y | |
|
222 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
|
223 | perc = 0.03 | |
|
224 | ||
|
225 | if event.button == 1: | |
|
226 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) | |
|
227 | ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy) | |
|
228 | elif event.button == 3: | |
|
229 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) | |
|
230 | ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy) | |
|
231 | ||
|
232 | ax.cbar.draw_all() | |
|
233 | ax.plt.set_norm(ax.cbar.norm) | |
|
234 | ax.cbar.patch.figure.canvas.draw() | |
|
235 | ||
|
236 | def onBtnRelease(self, event): | |
|
237 | ''' | |
|
238 | Event for mouse button release | |
|
239 | ''' | |
|
240 | cb_ax = event.inaxes | |
|
241 | if cb_ax is not None: | |
|
242 | cb_ax.press = None | |
|
169 | 243 | |
|
170 | 244 | def __add_axes(self, ax, size='30%', pad='8%'): |
|
171 | 245 | ''' |
@@ -233,9 +307,8 class PlotData(Operation, Process): | |||
|
233 | 307 | xmin = self.min_time |
|
234 | 308 | else: |
|
235 | 309 | if self.xaxis is 'time': |
|
236 | dt = datetime.datetime.fromtimestamp(self.min_time) | |
|
237 | xmin = (datetime.datetime.combine(dt.date(), | |
|
238 | datetime.time(int(self.xmin), 0, 0))-UT1970).total_seconds() | |
|
310 | dt = datetime.datetime.utcfromtimestamp(self.min_time) | |
|
311 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
|
239 | 312 | else: |
|
240 | 313 | xmin = self.xmin |
|
241 | 314 | |
@@ -243,16 +316,17 class PlotData(Operation, Process): | |||
|
243 | 316 | xmax = xmin+self.xrange*60*60 |
|
244 | 317 | else: |
|
245 | 318 | if self.xaxis is 'time': |
|
246 | dt = datetime.datetime.fromtimestamp(self.min_time) | |
|
247 | xmax = (datetime.datetime.combine(dt.date(), | |
|
248 | datetime.time(int(self.xmax), 0, 0))-UT1970).total_seconds() | |
|
319 | dt = datetime.datetime.utcfromtimestamp(self.min_time) | |
|
320 | xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
|
249 | 321 | else: |
|
250 | 322 | xmax = self.xmax |
|
251 | ||
|
323 | ||
|
252 | 324 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) |
|
253 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
254 | ||
|
255 | ystep = 200 if ymax>= 800 else 100 if ymax>=400 else 50 if ymax>=200 else 20 | |
|
325 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
326 | ||
|
327 | Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000]) | |
|
328 | i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0] | |
|
329 | ystep = Y[i-1]/5 | |
|
256 | 330 | |
|
257 | 331 | for n, ax in enumerate(self.axes): |
|
258 | 332 | if ax.firsttime: |
@@ -274,6 +348,7 class PlotData(Operation, Process): | |||
|
274 | 348 | if self.colorbar: |
|
275 | 349 | ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10) |
|
276 | 350 | ax.cbar.ax.tick_params(labelsize=8) |
|
351 | ax.cbar.ax.press = None | |
|
277 | 352 | if self.cb_label: |
|
278 | 353 | ax.cbar.set_label(self.cb_label, size=8) |
|
279 | 354 | elif self.cb_labels: |
@@ -281,7 +356,7 class PlotData(Operation, Process): | |||
|
281 | 356 | |
|
282 | 357 | ax.set_title('{} - {} {}'.format( |
|
283 | 358 | self.titles[n], |
|
284 | datetime.datetime.fromtimestamp(self.max_time).strftime('%H:%M:%S'), | |
|
359 | datetime.datetime.utcfromtimestamp(self.max_time).strftime('%H:%M:%S'), | |
|
285 | 360 | self.time_label), |
|
286 | 361 | size=8) |
|
287 | 362 | ax.set_xlim(xmin, xmax) |
@@ -304,7 +379,7 class PlotData(Operation, Process): | |||
|
304 | 379 | |
|
305 | 380 | fig.tight_layout() |
|
306 | 381 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
307 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
|
382 | datetime.datetime.utcfromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
|
308 | 383 | # fig.canvas.draw() |
|
309 | 384 | |
|
310 | 385 | if self.save and self.data.ended: |
@@ -318,7 +393,7 class PlotData(Operation, Process): | |||
|
318 | 393 | '{}{}_{}.png'.format( |
|
319 | 394 | self.CODE, |
|
320 | 395 | label, |
|
321 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S') | |
|
396 | datetime.datetime.utcfromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S') | |
|
322 | 397 | ) |
|
323 | 398 | ) |
|
324 | 399 | print 'Saving figure: {}'.format(figname) |
@@ -739,8 +814,8 class PlotSkyMapData(PlotData): | |||
|
739 | 814 | self.ax.plot.set_data(x, y) |
|
740 | 815 | |
|
741 | 816 | |
|
742 | dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
|
743 | dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
|
817 | dt1 = datetime.datetime.utcfromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
|
818 | dt2 = datetime.datetime.utcfromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
|
744 | 819 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
745 | 820 | dt2, |
|
746 | 821 | len(x)) |
@@ -787,13 +862,14 class PlotParamData(PlotRTIData): | |||
|
787 | 862 | for n, ax in enumerate(self.axes): |
|
788 | 863 | |
|
789 | 864 | x, y, z = self.fill_gaps(*self.decimate()) |
|
790 | ||
|
865 | self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n]) | |
|
866 | self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n]) | |
|
867 | ||
|
791 | 868 | if ax.firsttime: |
|
792 | 869 | if self.zlimits is not None: |
|
793 | 870 | self.zmin, self.zmax = self.zlimits[n] |
|
794 | self.zmax = self.zmax if self.zmax is not None else numpy.nanmax(abs(self.z[:-1, :])) | |
|
795 | self.zmin = self.zmin if self.zmin is not None else -self.zmax | |
|
796 | ax.plt = ax.pcolormesh(x, y, z[n, :, :].T*self.factors[n], | |
|
871 | ||
|
872 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], | |
|
797 | 873 | vmin=self.zmin, |
|
798 | 874 | vmax=self.zmax, |
|
799 | 875 | cmap=self.cmaps[n] |
@@ -802,7 +878,7 class PlotParamData(PlotRTIData): | |||
|
802 | 878 | if self.zlimits is not None: |
|
803 | 879 | self.zmin, self.zmax = self.zlimits[n] |
|
804 | 880 | ax.collections.remove(ax.collections[0]) |
|
805 |
ax.plt = ax.pcolormesh(x, y, z[n |
|
|
881 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], | |
|
806 | 882 | vmin=self.zmin, |
|
807 | 883 | vmax=self.zmax, |
|
808 | 884 | cmap=self.cmaps[n] |
@@ -810,7 +886,7 class PlotParamData(PlotRTIData): | |||
|
810 | 886 | |
|
811 | 887 | self.saveTime = self.min_time |
|
812 | 888 | |
|
813 | class PlotOuputData(PlotParamData): | |
|
889 | class PlotOutputData(PlotParamData): | |
|
814 | 890 | ''' |
|
815 | 891 | Plot data_output object |
|
816 | 892 | ''' |
@@ -142,7 +142,7 class Data(object): | |||
|
142 | 142 | self.channels = dataOut.channelList |
|
143 | 143 | self.interval = dataOut.getTimeInterval() |
|
144 | 144 | if 'spc' in self.plottypes or 'cspc' in self.plottypes: |
|
145 |
self.xrange = (dataOut.getFreqRange(1)/1000. |
|
|
145 | self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |
|
146 | 146 | self.__heights.append(dataOut.heightList) |
|
147 | 147 | self.__all_heights.update(dataOut.heightList) |
|
148 | 148 | self.__times.append(tm) |
@@ -560,7 +560,7 class PlotterReceiver(ProcessingUnit, Process): | |||
|
560 | 560 | |
|
561 | 561 | while True: |
|
562 | 562 | dataOut = self.receiver.recv_pyobj() |
|
563 | dt = datetime.datetime.fromtimestamp(dataOut.utctime).date() | |
|
563 | dt = datetime.datetime.utcfromtimestamp(dataOut.utctime).date() | |
|
564 | 564 | sended = False |
|
565 | 565 | if dt not in self.dates: |
|
566 | 566 | if self.data: |
General Comments 0
You need to be logged in to leave comments.
Login now