How to use phylib - 10 common examples

To help you get started, we’ve selected a few phylib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cortex-lab / phy / phy / cluster / views / waveform.py View on Github external
color=self.ax_color,
            data_bounds=ax_db,
            box_index=box_index,
        )

        # Vertical ticks every millisecond.
        steps = np.arange(np.round(self.wave_duration * 1000))
        # A vline every millisecond.
        x = .001 * steps
        # Scale to [-1, 1], same coordinates as the waveform points.
        x = -1 + 2 * x / self.wave_duration
        # Take overlap into account.
        x = _overlap_transform(x, offset=bunch.offset, n=bunch.n_clu, overlap=self.overlap)
        x = np.tile(x, len(channel_ids_loc))
        # Generate the box index.
        box_index = _index_of(channel_ids_loc, self.channel_ids)
        box_index = np.repeat(box_index, x.size // len(box_index))
        assert x.size == box_index.size
        self.tick_visual.add_batch_data(
            x=x, y=np.zeros_like(x),
            data_bounds=ax_db,
            box_index=box_index,
        )
github cortex-lab / phy / phy / plot / base.py View on Github external
# in insert_into_shaders() below.
        v_inserter += self.inserter

        # Now, we insert the transforms GLSL into the shaders.
        vs, fs = visual.vertex_shader, visual.fragment_shader
        vs, fs = v_inserter.insert_into_shaders(vs, fs, exclude_origins=exclude_origins)

        # Finally, we create the visual's program.
        visual.program = LazyProgram(vs, fs)
        logger.log(5, "Vertex shader: %s", vs)
        logger.log(5, "Fragment shader: %s", fs)

        # Initialize the size.
        visual.on_resize(self.size().width(), self.size().height())
        # Register the visual in the list of visuals in the canvas.
        self.visuals.append(Bunch(visual=visual, **kwargs))
        emit('visual_added', self, visual)
        return visual
github cortex-lab / phy / phy / apps / base.py View on Github external
        @connect(sender=v)
        def on_select_channel(sender, channel_id=None, key=None, button=None):
            # Update the Selection object with the channel id clicked in the waveform view.
            self.selection.channel_id = channel_id
            emit('selected_channel_changed', v)
github cortex-lab / phy / phy / gui / widgets.py View on Github external
var data = %s;

            var options = {
              valueNames: %s,
              columns: %s,
              sort: %s,
            };

            var table = new Table('table', options, data);

        
        ''' % (data_json, value_names_json, columns_json, sort_json)
        self.build(lambda html: emit('ready', self))

        connect(event='select', sender=self, func=lambda *args: self.update(), last=True)
        connect(event='ready', sender=self, func=lambda *args: self._set_ready())
github cortex-lab / phy / phy / gui / widgets.py View on Github external
''' % (data_json, value_names_json, columns_json, sort_json)
        self.build(lambda html: emit('ready', self))

        connect(event='select', sender=self, func=lambda *args: self.update(), last=True)
        connect(event='ready', sender=self, func=lambda *args: self._set_ready())
github cortex-lab / phy / phy / cluster / views / base.py View on Github external
# Freeze and unfreeze the view when selecting clusters.
        self.actions.add(
            self.toggle_auto_update, checkable=True, checked=self.auto_update, show_shortcut=False)
        self.actions.add(self.screenshot, show_shortcut=False)
        self.actions.add(self.close, show_shortcut=False)
        self.actions.separator()

        # Color scheme actions.
        self.actions.add(self.next_color_scheme)
        self.actions.add(self.previous_color_scheme)
        self.actions.separator()

        emit('view_actions_created', self)

        on_select = partial(self.on_select_threaded, gui=gui)
        connect(on_select, event='select')

        # Save the view state in the GUI state.
        @connect(sender=gui)
        def on_close_view(sender, view):
            if view != self:
                return
            logger.debug("Close view %s.", self.name)
            self._closed = True
            gui.remove_menu(self.name)
            unconnect(on_select)
            gui.state.update_view_state(self, self.state)
            self.canvas.close()
            gc.collect(0)

        @connect(sender=gui)
        def on_close(sender):
github cortex-lab / phy / phy / plot / panzoom.py View on Github external
def emit_update_events(self):
        """Emit the pan and zoom events to update views after a pan zoom manual update."""
        emit('pan', self, self.pan)
        emit('zoom', self, self.zoom)
github cortex-lab / phy / phy / plot / panzoom.py View on Github external
def zoom(self, value):
        """Zoom level."""
        if isinstance(value, (int, float)):
            value = (value, value)
        assert len(value) == 2
        old = tuple(self.zoom)
        self._zoom = np.clip(value, self._zmin, self._zmax)

        # Constrain bounding box.
        self._constrain_pan()
        self._constrain_zoom()

        new = tuple(self.zoom)
        if new != old:
            emit('zoom', self, new)
        self.update()
github cortex-lab / phy / phy / cluster / views / raster.py View on Github external
def on_mouse_click(self, e):
        """Select a cluster by clicking in the raster plot."""
        b = e.button
        if 'Control' in e.modifiers or 'Shift' in e.modifiers:
            # Get mouse position in NDC.
            cluster_idx, _ = self.canvas.stacked.box_map(e.pos)
            cluster_id = self.all_cluster_ids[cluster_idx]
            logger.debug("Click on cluster %d with button %s.", cluster_id, b)
            if 'Shift' in e.modifiers:
                emit('select_more', self, [cluster_id])
            else:
                emit('request_select', self, [cluster_id])
github cortex-lab / phy / phy / cluster / views / base.py View on Github external
gui, name=self.name, menu='&View', submenu=self.name,
            default_shortcuts=shortcuts, default_snippets=self.default_snippets)

        # Freeze and unfreeze the view when selecting clusters.
        self.actions.add(
            self.toggle_auto_update, checkable=True, checked=self.auto_update, show_shortcut=False)
        self.actions.add(self.screenshot, show_shortcut=False)
        self.actions.add(self.close, show_shortcut=False)
        self.actions.separator()

        # Color scheme actions.
        self.actions.add(self.next_color_scheme)
        self.actions.add(self.previous_color_scheme)
        self.actions.separator()

        emit('view_actions_created', self)

        on_select = partial(self.on_select_threaded, gui=gui)
        connect(on_select, event='select')

        # Save the view state in the GUI state.
        @connect(sender=gui)
        def on_close_view(sender, view):
            if view != self:
                return
            logger.debug("Close view %s.", self.name)
            self._closed = True
            gui.remove_menu(self.name)
            unconnect(on_select)
            gui.state.update_view_state(self, self.state)
            self.canvas.close()
            gc.collect(0)