kwikteam/phy-contrib

Custom matplotlib view does not work

Closed this issue · 3 comments

So, I've been trying to add custom matplotlib views to TemplateGUI. I've managed to get the new plugin window to show up (see screenshot), but after selecting a cluster, nothing is actually displayed in the window.

template-gui

I looked into the custom_view.py file in the examples folder, which is meant to be used to add a custom matplotlib view (see http://phy-contrib.readthedocs.io/en/latest/examples/). I slightly adapted the code to check if something actually happens when a cluster is selected (see code below).

"""Custom view plugin.

This plugin adds an interactive matplotlib figure showing the ISI of the
first selected cluster.

To activate the plugin, copy this file to `~/.phy/plugins/` and add this line
to your `~/.phy/phy_config.py`:

python
c.KwikGUI.plugins = ['CustomView']

"""

from phy import IPlugin
import numpy as np
import matplotlib.pyplot as plt


class CustomView(IPlugin):
	def attach_to_controller(self, c):

		# Create the figure when initializing the GUI.
		f, ax = plt.subplots()

		@c.connect
		def on_create_gui(gui):
			# Called when the GUI is created.

			# We add the matplotlib figure to the GUI.
			gui.add_view(f, name='ISI')

			# We connect this function to the "select" event triggered
			# by the controller at every cluster selection change.
			@c.connect
			def on_select(clusters, **kwargs):
                                # We update the figure.
				s = 'Display results' 
				print(s) # print something to command window

The message from the bottom two lines is never printed. Clearly, something goes wrong with one or both of these two instructions:

@c.connect
def on_select(clusters, **kwargs):

I've never worked with Python before, so excuse my ignorance. From the comment, it is clear there is supposed to be some "select event" that is triggered by the controller, but this signal is never received here apparently. Does anyone know from what part of the code the signal is sent? My guess would be somewhere in gui.py or controller.py, but I have no clue where to look.

@rossant would know better, but I think that the way on_select is used has been changed since that example was written. I wrote an ISI plugin that you should feel free to use as a starting point. You can find it here.

Thanks. I am able to receive the signal now using your plugin. I see you use @gui.connect_ instead of @c.connect, which solves this particular issue.

The plugin that you've linked still doesn't quite work, though. I'm getting the following error:
"An error has occurred : 'TemplateController' object has no attribute 'model'."

This occurs as line 68:
spikes = 1000*controller.model.spike_times[controller.model.spike_clusters == clusters[i]]

Any ideas? I'll try to do some investigating myself.

I had a look at the properties of the "controller" object and noticed that the "spike_times" and "spike_clusters" properties were there, so I simply removed the ".model" part and now the plugin works.

Issue can be closed.