def __init__(self, *args, **kwargs): super(BaseColorView, self).__init__(*args, **kwargs) self.state_attrs += ('color_scheme',) # Color schemes. self.color_schemes = RotatingProperty() self.add_color_scheme(fun=0, name='blank', colormap='blank', categorical=True)
def __init__(self, waveforms=None, waveforms_type=None, sample_rate=None, **kwargs): self._overlap = False self.do_show_labels = True self.channel_ids = None self.filtered_tags = () self.wave_duration = 0. # updated in the plotting method self.data_bounds = None self.sample_rate = sample_rate self._status_suffix = '' assert sample_rate > 0., "The sample rate must be provided to the waveform view." # Initialize the view. super(WaveformView, self).__init__(**kwargs) self.state_attrs += ('waveforms_type', 'overlap', 'do_show_labels') self.local_state_attrs += ('box_scaling', 'probe_scaling') # Box and probe scaling. self.canvas.set_layout('boxed', box_pos=np.zeros((1, 2))) # Ensure waveforms is a dictionary, even if there is a single waveforms type. waveforms = waveforms or {} waveforms = waveforms if isinstance(waveforms, dict) else { 'waveforms': waveforms } self.waveforms = waveforms # Rotating property waveforms types. self.waveforms_types = RotatingProperty() for name, value in self.waveforms.items(): self.waveforms_types.add(name, value) # Current waveforms type. self.waveforms_types.set(waveforms_type) assert self.waveforms_type in self.waveforms self.text_visual = TextVisual() self.canvas.add_visual(self.text_visual) self.line_visual = LineVisual() self.canvas.add_visual(self.line_visual) self.tick_visual = UniformScatterVisual(marker='vbar', color=self.ax_color, size=self.tick_size) self.canvas.add_visual(self.tick_visual) # Two types of visuals: thin raw line visual for normal waveforms, thick antialiased # agg plot visual for mean and template waveforms. self.waveform_agg_visual = PlotAggVisual() self.waveform_visual = PlotVisual() self.canvas.add_visual(self.waveform_agg_visual) self.canvas.add_visual(self.waveform_visual)
def __init__(self, amplitudes=None, amplitudes_type=None, duration=None): super(AmplitudeView, self).__init__() self.state_attrs += ('amplitudes_type', ) self.canvas.enable_axes() self.canvas.enable_lasso() # Ensure amplitudes is a dictionary, even if there is a single amplitude. if not isinstance(amplitudes, dict): amplitudes = {'amplitude': amplitudes} assert amplitudes self.amplitudes = amplitudes # Rotating property amplitudes types. self.amplitudes_types = RotatingProperty() for name, value in self.amplitudes.items(): self.amplitudes_types.add(name, value) # Current amplitudes type. self.amplitudes_types.set(amplitudes_type) assert self.amplitudes_type in self.amplitudes self.cluster_ids = () self.duration = duration or 1. # Histogram visual. self.hist_visual = HistogramVisual() self.hist_visual.transforms.add([ Range(NDC, (-1, -1, 1, -1 + 2 * self.histogram_scale)), Rotate('cw'), Scale((1, -1)), Translate((2.05, 0)), ]) self.canvas.add_visual(self.hist_visual) self.canvas.panzoom.zoom = self.canvas.panzoom._default_zoom = (.75, 1) self.canvas.panzoom.pan = self.canvas.panzoom._default_pan = (-.25, 0) # Yellow vertical bar showing the selected time interval. self.patch_visual = PatchVisual(primitive_type='triangle_fan') self.patch_visual.inserter.insert_vert( ''' const float MIN_INTERVAL_SIZE = 0.01; uniform float u_interval_size; ''', 'header') self.patch_visual.inserter.insert_vert( ''' gl_Position.y = pos_orig.y; // The following is used to ensure that (1) the bar width increases with the zoom level // but also (2) there is a minimum absolute width so that the bar remains visible // at low zoom levels. float w = max(MIN_INTERVAL_SIZE, u_interval_size * u_zoom.x); // HACK: the z coordinate is used to store 0 or 1, depending on whether the current // vertex is on the left or right edge of the bar. gl_Position.x += w * (-1 + 2 * int(a_position.z == 0)); ''', 'after_transforms') self.canvas.add_visual(self.patch_visual) # Scatter plot. self.visual = ScatterVisual() self.canvas.add_visual(self.visual) self.canvas.panzoom.set_constrain_bounds((-2, -2, +2, +2))