[plotter] eventplotter
This commit is contained in:
parent
6d3cb44748
commit
5990d8c34e
@ -113,47 +113,95 @@ class Plotter(MplCanvas):
|
|||||||
|
|
||||||
class EventPlotter(Plotter):
|
class EventPlotter(Plotter):
|
||||||
|
|
||||||
def __init__(self, data_array, xdim=-1):
|
def __init__(self, file_handler, item, data_view, xdim=-1, parent=None):
|
||||||
self.array = data_array
|
super().__init__(file_handler, item, data_view, parent)
|
||||||
self.sc = None
|
self.dim_count = len(self._dataview.full_shape)
|
||||||
self.dim_count = len(data_array.dimensions)
|
|
||||||
"""
|
|
||||||
if xdim == -1:
|
if xdim == -1:
|
||||||
self.xdim = guess_best_xdim(self.array)
|
self.xdim = self._item.best_xdim
|
||||||
elif xdim > 1:
|
|
||||||
raise ValueError("EventPlotter: xdim is larger than 2! "
|
|
||||||
"Cannot plot that kind of data")
|
|
||||||
else:
|
else:
|
||||||
self.xdim = xdim
|
self.xdim = xdim
|
||||||
"""
|
self._abs_xmin = 0
|
||||||
|
self._abs_xmax = self._dataview.full_shape[self.xdim]
|
||||||
|
self._view_xmin = 0
|
||||||
|
self._view_xmax = 0
|
||||||
|
self._zoom_level = 0
|
||||||
|
self._segment_length = 0
|
||||||
|
self.sc = None
|
||||||
|
|
||||||
def plot(self, axis=None):
|
@property
|
||||||
if axis is None:
|
def is_full_view(self):
|
||||||
self.fig = plt.figure(figsize=[5.5, 2.])
|
full = self._data_xmin == self._view_xmin and self._data_xmax == self._view_xmax
|
||||||
self.axis = self.fig.add_axes([0.15, .2, 0.8, 0.75])
|
return full
|
||||||
self.axis.set_title(self.array.name)
|
|
||||||
else:
|
@property
|
||||||
self.fig = axis.figure
|
def can_pan_horizontally(self):
|
||||||
self.axis = axis
|
return self.can_pan_left or self.can_pan_right
|
||||||
if len(self.array.dimensions) == 1:
|
|
||||||
return self.plot_1d()
|
@property
|
||||||
|
def can_pan_left(self):
|
||||||
|
return self._view_xmin > self._abs_xmin
|
||||||
|
|
||||||
|
@property
|
||||||
|
def can_pan_right(self):
|
||||||
|
return self._view_xmax < self._abs_xmax
|
||||||
|
|
||||||
|
@property
|
||||||
|
def horizontal_pan_position(self):
|
||||||
|
return self._view_xmax/self._abs_xmax
|
||||||
|
|
||||||
|
def horizontal_pan_to_position(self, new_position, zoomlevel):
|
||||||
|
new_xmax = int(np.min([np.ceil(new_position * self._abs_xmax), self._abs_xmax]))
|
||||||
|
segment_length = zoomlevel * self._abs_xmax
|
||||||
|
start = np.max([0, new_xmax - segment_length])
|
||||||
|
while not self._dataview.fully_loaded and new_xmax < self._dataview.current_shape[self.xdim]:
|
||||||
|
self._dataview.request_more()
|
||||||
|
|
||||||
|
self.plot(start, zoomlevel)
|
||||||
|
|
||||||
|
def plot(self, start=0, zoomlevel=1.0):
|
||||||
|
if zoomlevel > 1:
|
||||||
|
zoomlevel = 1.0
|
||||||
|
self._segment_length = zoomlevel * self._abs_xmax
|
||||||
|
self._zoom_level = zoomlevel
|
||||||
|
|
||||||
|
if self.dim_count == 1:
|
||||||
|
return self.plot_1d(start)
|
||||||
else:
|
else:
|
||||||
return None
|
return None # FIXME 2D events?
|
||||||
|
|
||||||
def plot_1d(self):
|
def plot_1d(self, start=0, zoomlevel=1.0):
|
||||||
data = self.array[:]
|
if start < 0:
|
||||||
xlabel = create_label(self.array.dimensions[self.xdim])
|
start = 0
|
||||||
dim = self.array.dimensions[self.xdim]
|
end = start + self._segment_length
|
||||||
if dim.dimension_type == nix.DimensionType.Range and not dim.is_alias:
|
if end > self._dataview.current_shape[self.xdim]:
|
||||||
ylabel = create_label(self.array)
|
end = self._dataview.current_shape[self.xdim]
|
||||||
|
y_values = self._dataview._buffer[int(start):int(end)]
|
||||||
|
x_values = self._file_handler.request_axis(self._item.block_id, self._item.id, 0, len(y_values), int(start))
|
||||||
|
data = self._dataview._buffer[:]
|
||||||
|
dimensions = self._file_handler.request_dimensions(self._item.block_id, self._item.id)
|
||||||
|
|
||||||
|
xlabel = create_label(dimensions[self.xdim])
|
||||||
|
#dim = dimensions[self.xdim]
|
||||||
|
#if "Range"dim.type == dRange and not dim.is_alias:
|
||||||
|
# ylabel = create_label(self.array)
|
||||||
|
#else:
|
||||||
|
# ylabel = ""
|
||||||
|
if self.sc is None:
|
||||||
|
label = self._item.name
|
||||||
|
self.sc = self.axis.scatter(data, np.ones(data.shape))
|
||||||
|
self.sc.set_pickradius(5)
|
||||||
else:
|
else:
|
||||||
ylabel = ""
|
self.sc.set_data(data, np.ones(data.shape))
|
||||||
self.sc = self.axis.scatter(data, np.ones(data.shape))
|
self.figure.canvas.draw_idle()
|
||||||
|
# self.axis.set_ylim([np.min(y_values), np.max(y_values)])
|
||||||
|
self.axis.set_xlim([x_values[0], x_values[-1]])
|
||||||
|
|
||||||
self.axis.set_ylim([0.5, 1.5])
|
self.axis.set_ylim([0.5, 1.5])
|
||||||
self.axis.set_yticks([1.])
|
self.axis.set_yticks([1.])
|
||||||
self.axis.set_yticklabels([])
|
self.axis.set_yticklabels([])
|
||||||
self.axis.set_xlabel(xlabel)
|
self.axis.set_xlabel(xlabel)
|
||||||
self.axis.set_ylabel(ylabel)
|
# self.axis.set_ylabel(ylabel)
|
||||||
return self.axis
|
return self.axis
|
||||||
|
|
||||||
|
|
||||||
@ -556,9 +604,15 @@ class PlotScreen(QWidget):
|
|||||||
self._container.set_plotter(self.plotter)
|
self._container.set_plotter(self.plotter)
|
||||||
self.plotter.plot(zoomlevel=zoom_slider_position/1000.)
|
self.plotter.plot(zoomlevel=zoom_slider_position/1000.)
|
||||||
self._software_slide = False
|
self._software_slide = False
|
||||||
if item.suggested_plotter == PlotterTypes.ImagePlotter:
|
elif item.suggested_plotter == PlotterTypes.ImagePlotter:
|
||||||
self._zoom_slider.setEnabled(False)
|
self._zoom_slider.setEnabled(False)
|
||||||
self._pan_slider.setEnabled(False)
|
self._pan_slider.setEnabled(False)
|
||||||
self.plotter = ImagePlotter(self._file_handler, item, self._data_view)
|
self.plotter = ImagePlotter(self._file_handler, item, self._data_view)
|
||||||
self._container.set_plotter(self.plotter)
|
self._container.set_plotter(self.plotter)
|
||||||
self.plotter.plot()
|
self.plotter.plot()
|
||||||
|
elif item.suggested_plotter == PlotterTypes.EventPlotter:
|
||||||
|
self._zoom_slider.setEnabled(False)
|
||||||
|
self._pan_slider.setEnabled(False)
|
||||||
|
self.plotter = EventPlotter(self._file_handler, item, self._data_view)
|
||||||
|
self._container.set_plotter(self.plotter)
|
||||||
|
self.plotter.plot()
|
||||||
|
Loading…
Reference in New Issue
Block a user