Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subwidget parameters for UnitSummaryWidget #3242

Merged

Conversation

florian6973
Copy link
Contributor

Hi,

As discussed in #3222, here is a very small PR to add this feature. Please let me know if you would like any changes before merging.

To test:

import spikeinterface.full as si
import spikeinterface.widgets as sw
rec, sort = si.generate_ground_truth_recording(num_channels=4)
sa = si.create_sorting_analyzer(sort, rec)
sa.compute(["random_spikes", "templates", "spike_amplitudes", "waveforms"])
sw.plot_unit_summary(sa, 0, unitwaveformswidget_params={"plot_channels": True}, amplitudeswidget_params={"bins": 20})

Best,

@zm711
Copy link
Collaborator

zm711 commented Jul 23, 2024

Maybe @samuelgarcia would feel differently, but I would actually like the idea of a nested dict instead of multiple dicts. Maybe @h-mayorquin would also like to weigh in on the design choice. So it would be something like

widget_param_dict = dict(amplitude_params=xx, etc)

And then if None you make an empty dict and just iterate through the keys to create your sub dictionaries. That way if we changes the widgets it would be easy to change that internally without breaking the external API.

@zm711 zm711 added the widgets Related to widgets module label Jul 24, 2024
@florian6973
Copy link
Contributor Author

Thanks for your feedback! I just did the change to a nested dict :)

Copy link
Member

@alejoe91 alejoe91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @florian6973

I have a suggestion on the naming of the additional params

@florian6973
Copy link
Contributor Author

Thanks for your suggestion! Just implemented the changes.

Example:

import spikeinterface.full as si
import spikeinterface.widgets as sw
rec, sort = si.generate_ground_truth_recording(num_channels=4)
sa = si.create_sorting_analyzer(sort, rec)
sa.compute(["random_spikes", "templates", "spike_amplitudes", "waveforms"])
sw.plot_unit_summary(sa, 0, widget_params=dict(unit_waveforms={"plot_channels": True}, amplitudes={"bins": 5}))

@@ -70,6 +81,13 @@ def plot_matplotlib(self, data_plot, **backend_kwargs):
unit_colors = dp.unit_colors
sparsity = dp.sparsity

widget_params = defaultdict(lambda: dict(), dp.widget_params)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! I did not know about that defaultdict. Might be adding a quick comment like # Returns an empty dict if the key is not in passed in dp.widget_params, but maybe this is quite widely known and doesn't need the comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a comment :)

@JoeZiminski
Copy link
Collaborator

Hey @florian6973 this is really cool! I played around with it and it was working well. I had one small point above and two below, please feel free to ignore them they are minor.

  • the widget_params could be renamed to widget_kwargs which I think (?) is usually the convention in SI for kwargs that are passed down the call chain to subfunctions / classes. Maybe this could also be subwidget_kwargs to distinguish it from the other arguments of the function (technically all of the params passed are 'widget params', for the UnitSummaryWidget).
  • I naively tried to pass unit_colors to one of the subwidget and it raised a slightly confusing error (the subwidget received two duplicate unit_colors arguments), as that is already handled by the UnitSummaryWidget. So it's not possible to override this in the widget_params. Some options would be to raise an error saying this is not supported, or just add to the docstring to that effect, or to override the unit_colors for the subwidget if it is passed in the dict. This is an edge-case so docstring is probably easiest!

@JoeZiminski JoeZiminski self-requested a review September 10, 2024 16:14
@florian6973
Copy link
Contributor Author

Thanks for your feedback! Just pushed some changes to rename the variables and add a clearer error message for this edge case.

import spikeinterface.full as si
import spikeinterface.widgets as sw
rec, sort = si.generate_ground_truth_recording(num_channels=4)
sa = si.create_sorting_analyzer(sort, rec)
sa.compute(["random_spikes", "templates", "spike_amplitudes", "waveforms"])
sw.plot_unit_summary(sa, 0, unit_colors=['r'], subwidget_kwargs=dict(unit_waveforms={"plot_channels": True}, amplitudes={"bins": 5}))
                     
from matplotlib import pyplot as plt
plt.show()

Copy link
Member

@alejoe91 alejoe91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space before colon

@alejoe91 alejoe91 added this to the 0.101.1 milestone Sep 11, 2024
@florian6973
Copy link
Contributor Author

florian6973 commented Sep 11, 2024

Oh so sorry! Thank you for adding them again

Copy link
Collaborator

@zm711 zm711 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Florent!

@alejoe91 alejoe91 merged commit 48b2131 into SpikeInterface:main Sep 12, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
widgets Related to widgets module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants