spikeinterface icon indicating copy to clipboard operation
spikeinterface copied to clipboard

Fix bug in plot templates

Open DradeAW opened this issue 1 year ago • 1 comments

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

DradeAW avatar May 15 '24 11:05 DradeAW

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

alejoe91 avatar Jun 19 '24 10:06 alejoe91

@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 avatar Jul 08 '24 10:07 alejoe91

@samuelgarcia added the sparse slicing. Ready to review

alejoe91 avatar Jul 12 '24 11:07 alejoe91