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

Fix bug in plot templates #2850

Merged
merged 9 commits into from
Jul 15, 2024
Merged

Fix bug in plot templates #2850

merged 9 commits into from
Jul 15, 2024

Conversation

DradeAW
Copy link
Contributor

@DradeAW DradeAW commented May 15, 2024

Fixes a bug where specifying the channel_ids with a non-sparse analyzer would fail.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[45], line 1
----> 1 sw.plot_unit_templates(analyzer, unit_ids=pairs[0], channel_ids=np.arange(13, 18))

File /export/home1/users/nsr/wyngaard/dev/spikeinterface/spikeinterface/src/spikeinterface/widgets/unit_templates.py:12, in UnitTemplatesWidget.__init__(self, *args, **kargs)
     10 def __init__(self, *args, **kargs):
     11     kargs["plot_waveforms"] = False
---> 12     UnitWaveformsWidget.__init__(self, *args, **kargs)

File /export/home1/users/nsr/wyngaard/dev/spikeinterface/spikeinterface/src/spikeinterface/widgets/unit_waveforms.py:226, in UnitWaveformsWidget.__init__(self, sorting_analyzer, channel_ids, unit_ids, plot_waveforms, plot_templates, plot_channels, unit_colors, sparsity, ncols, scale, lw_waveforms, lw_templates, axis_equal, unit_selected_waveforms, max_spikes_per_unit, set_title, same_axis, shade_templates, templates_percentile_shading, x_offset_units, alpha_waveforms, alpha_templates, hide_unit_selector, plot_legend, backend, **backend_kwargs)
    189         wfs_by_ids[unit_id] = wfs
    191 plot_data = dict(
    192     sorting_analyzer=sorting_analyzer,
    193     sampling_frequency=sorting_analyzer.sampling_frequency,
   (...)
    224     plot_legend=plot_legend,
    225 )
--> 226 BaseWidget.__init__(self, plot_data, backend=backend, **backend_kwargs)

File /export/home1/users/nsr/wyngaard/dev/spikeinterface/spikeinterface/src/spikeinterface/widgets/base.py:87, in BaseWidget.__init__(self, data_plot, backend, immediate_plot, **backend_kwargs)
     84 self.backend_kwargs = backend_kwargs_
     86 if immediate_plot:
---> 87     self.do_plot()

File /export/home1/users/nsr/wyngaard/dev/spikeinterface/spikeinterface/src/spikeinterface/widgets/base.py:108, in BaseWidget.do_plot(self)
    106 def do_plot(self):
    107     func = getattr(self, f"plot_{self.backend}")
--> 108     func(self.data_plot, **self.backend_kwargs)

File /export/home1/users/nsr/wyngaard/dev/spikeinterface/spikeinterface/src/spikeinterface/widgets/unit_waveforms.py:256, in UnitWaveformsWidget.plot_matplotlib(self, data_plot, **backend_kwargs)
    253 color = dp.unit_colors[unit_id]
    255 chan_inds = dp.sparsity.unit_id_to_channel_indices[unit_id]
--> 256 xvectors_flat = dp.xvectors[:, chan_inds].T.flatten()
    258 # plot waveforms
    259 if dp.plot_waveforms:

IndexError: index 5 is out of bounds for axis 1 with size 5

Fixes a bug where specifying the `channel_ids` with a non-sparse analyzer would fail.
@alejoe91 alejoe91 added the widgets Related to widgets module label May 15, 2024
@samuelgarcia samuelgarcia added this to the 0.101.0 milestone Jun 12, 2024
@alejoe91
Copy link
Member

I propose we remove the channel_ids argument and suggest to use sparsity instead

@alejoe91
Copy link
Member

alejoe91 commented Jul 8, 2024

@samuelgarcia @DradeAW

Fixed it. Basically, when you pass channel_ids, you force the sparsity to be the channel_ids you passed for all units. I think this is the intended behavior.

@alejoe91
Copy link
Member

@samuelgarcia added the sparse slicing. Ready to review

Comment on lines 513 to 515
else:
wfs = wf_ext.get_waveforms_one_unit(unit_id)
wfs = wfs[:, :, sparsity.mask[unit_index]]
Copy link
Member

Choose a reason for hiding this comment

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

why this if not extra_sparsity ? does the sparsity represent the extra sparsity ?

Copy link
Member

Choose a reason for hiding this comment

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

extra sparsity is a bool, in that case the sparsity is the user provided sparsity (or from channel ids)

@samuelgarcia samuelgarcia merged commit ab59a93 into SpikeInterface:main Jul 15, 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.

3 participants