-
Notifications
You must be signed in to change notification settings - Fork 5
**MOVED** Adding Custom Plugins for Phy
- The phy user directory is
~/.phy/
, where~
is your home directory. On Linux, it is typically/home/username/.phy/
. - The phy user config file is
~/.phy/phy_config.py
. It is a Python file. A default file is automatically created if needed. This file is used to add functionality to existing Phy user interface.
You can write the code either:
- In your phy user config file
~/.phy/phy_config.py
- Or in a separate Python file saved in
~/.phy/plugins/myplugin.py
Add the following lines to ~/.phy/phy_config.py
:
c = get_config()
c.Plugins.dirs = [r'path/to/your/plugins/folder']
c.TemplateGUI.plugins= ['MyPlugin1','MyPlugin2','MyPlugin3'] #names of python classes that defines different plugins
save the code below in the plugins director with some name e.g. ExampleNspikesViews.py
.
"""Show how to change the number of displayed spikes in each view."""
from phy import IPlugin
class ExampleNspikesViewsPlugin(IPlugin):
def attach_to_controller(self, controller):
"""Feel free to keep below just the values you need to change."""
controller.n_spikes_waveforms = 100 # the number of waveforms displayed in the waveformview
controller.batch_size_waveforms = 1000 #
controller.n_spikes_features = 30000 #number of spikes shown in the featureview
controller.n_spikes_features_background = 1 # number of spikes shown (gray color) from other clusters in featureview (can not be zero)
controller.n_spikes_amplitudes = 5000 # number of spikes in the amplitudeview
controller.n_spikes_correlograms = 100000 # number of spikes used for calculating the correlograms
# Number of "best" channels kept for displaying the waveforms.
controller.model.n_closest_channels = 12
# The best channels are selected among the N closest to the best (peak) channel if their
# mean amplitude is greater than this fraction of the peak amplitude on the best channel.
# If zero, just the N closest channels are kept as the best channels.
controller.model.amplitude_threshold = 0
Then add the name of the class ExampleNspikesViewsPlugin
to your ~/.phy/phy_config.py
as below:
c.TemplateGUI.plugins = ['ExampleNspikesViewsPlugin']
save the code below in the plugins director with some name, e.g. ExampleCustomFeatureView.py
.
"""Show how to customize the subplot grid specifiction in the feature view."""
import re
from phy import IPlugin, connect
from phy.cluster.views import FeatureView
def my_grid():
"""In the grid specification, 0 corresponds to the best channel, 1
to the second best, and so on. A, B, C refer to the PC components."""
s = """
0A,1A 0B,1A 0C,1A time,1A 1A,1B
0A,1B 0B,1B 0C,1B time,1B 1B,1C
0A,1C 0B,1C 0C,1C time,1C 1C,1A
time,0A time,0B time,0C 0A,2A 0A,2B
0A,0B 0B,0C 0C,0A 1A,2A 1A,2B
""".strip()
return [[_ for _ in re.split(" +", line.strip())] for line in s.splitlines()]
class ExampleCustomFeatureViewPlugin(IPlugin):
def attach_to_controller(self, controller):
@connect
def on_view_attached(view, gui):
if isinstance(view, FeatureView):
# We change the specification of the subplots here.
view.set_grid_dim(my_grid())
Then add the name of the class ExampleCustomFeatureViewPlugin
to your ~/.phy/phy_config.py
as below:
c.TemplateGUI.plugins = ['ExampleCustomFeatureViewPlugin']
save the code below in the plugins directory with some name ExampleClusterViewStyling.py
.
"""Show how to customize the styling of the cluster view with CSS."""
from phy import IPlugin
from phy.cluster.supervisor import ClusterView
class ExampleClusterViewStylingPlugin(IPlugin):
def attach_to_controller(self, controller):
# We add a custom CSS style to the ClusterView.
ClusterView._styles += """
/* This CSS selector represents all rows for good clusters. */
table tr[data-group='mua'] {
/* We change the text color. Many other CSS attributes can be changed,
such as background-color, the font weight, etc. */
color: orange;
}
table tr[data-group='noise'] {
/* We change the text color. Many other CSS attributes can be changed,
such as background-color, the font weight, etc. */
color: red;
}
table tr[data-group='good'] {
/* We change the text color. Many other CSS attributes can be changed,
such as background-color, the font weight, etc. */
color: pink;
}
"""
Then add the name of the class ExampleClusterViewStylingPlugin
to your ~/.phy/phy_config.py
as below:
c.TemplateGUI.plugins = ['ExampleClusterViewStylingPlugin']