How to add your own unit filter
This guide shows you how to add an entry to the Filter Plots menu that shows only the units
matching your own criterion. The example keeps units firing at more than 5 spikes per second.
How filters work
A filter is a function that takes the clusters.metrics table, one row per unit, and returns a
boolean array of the units to keep. Filters are registered by name in
ibl_alignment_gui.loaders.plot_loader.CUSTOM_FILTERS, which the Filter Plots menu is built from
when a session is loaded.
Steps
Create
ibl_alignment_gui/plugins/my_filters.py:import numpy as np from ibl_alignment_gui.loaders import plot_loader from iblutil.util import Bunch PLUGIN_NAME = 'My Filters' def setup(controller): """Register the plugin, and the function that adds its filters when data is loaded.""" controller.plugins[PLUGIN_NAME] = Bunch() controller.plugins[PLUGIN_NAME]['activated'] = True controller.plugins[PLUGIN_NAME]['load_data'] = add_filters def add_filters(_): """Add the filters to the Filter Plots menu.""" plot_loader.CUSTOM_FILTERS['High firing rate'] = filter_high_firing_rate def filter_high_firing_rate(metrics): """Keep the units firing at more than 5 spikes per second.""" return np.asarray(metrics['firing_rate'] > 5)
Change
firing_rateto a column that is in yourclusters.metricsfile.Register the plugin in
ibl_alignment_gui/plugins/add_plugins.py, as for a plot:from ibl_alignment_gui.plugins.my_filters import setup as setup_my_filters class Plugins: def __init__(self, controller): ... setup_my_filters(controller)
Start the GUI and load a session.
High firing rateis in theFilter Plotsmenu.
If the column is missing, or the function raises an error, a warning is logged and every unit is shown.