Skip to content

Conversation

@ecobost
Copy link
Contributor

@ecobost ecobost commented Dec 25, 2025

Currently, sw.plot_unit_waveforms_density_map(analyzer, unit_ids=[0], use_max_channel=True) produces this:
density_map_pre
The density map has some spurious high values on the very first row (more visible near the peaks) and also on the bottom although less visible in this example.

The issue comes from the clipping in

wf_bined = wf_bined.clip(0, bins.size - 1)

that counts any value with amplitude less than bin_min as belonging to the first bin and any value above bin_max as belonging to the last bin of the histogram, thus producing those lines on the plot.

This PR uses equal-sized bins from bin_min to bin_max and uses np.histogram to count occurrences. It produces:
density_map_post
without any artifacts. (Also tested it with multiple channels and multiple units)

Granted, it looks uglier but it's more correct. And it will look better for nicer data, this is a 2-minute recording just for testing.

Copy link
Collaborator

@yger yger left a comment

Choose a reason for hiding this comment

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

Not sure I like the idea of having a value hardcoded in the widget (num_bins=100), but it used to already be like that before, so we can leave it as it is. Thanks a lot for the patch! @samuelgarcia mayeb worth propagating in spikeinterface-gui also?

@alejoe91 alejoe91 added the widgets Related to widgets module label Dec 29, 2025
@samuelgarcia
Copy link
Member

Hi.
I am OK for moving from bin size to num bins for params.

About the histogram vs "devide and round" did you benchmark the speed ?

@ecobost
Copy link
Contributor Author

ecobost commented Jan 9, 2026

Hi @samuelgarcia. Just did some tests, newer solution becomes faster at around 1000-2000 spikes (both are under 20ms at that point anyway. For larger values numpy beats it.
Screenshot from 2026-01-09 03-11-14

@ecobost
Copy link
Contributor Author

ecobost commented Jan 9, 2026

Added a couple of commits, one is just code formatting (c30f587).

The other (87fdaa7) changes the x axis of the plot to show absolute time (msecs). I think it will be useful because no other plot shows the waveforms/templates in an absolute clock (plot_waveforms/templates has unitless x axis, it does have a scale bar but it only works under particular circumstances). It is nice to have the x axis as msec if you wanna estimate how wide a spike is or the distance between two peaks in the template or so on. I tested it with all params (1 vs many channels, and same_axis=True/False) and it works fine.

Here's what the plots look like:
density_map_one
density_map_allchannels
density_map_summary

Note: When all channels are plotted, rather than creating a different axes per channel, the concatenated image is plotted in a single axis and some vertical white lines are plotted to separate the channels. So the x axis still goes on real time but it is not separate per plot, not ideal but I think good enough.

@ecobost
Copy link
Contributor Author

ecobost commented Jan 9, 2026

Another possible improvement is to use a less aggresive colormap (currently hot). I did not change it yet because it seems pretty subjective so I would rather ask for comments first. Here are some candidates:
magma:
density_map_magma
copper:
density_map_copper
cubehelix:
density_map_cubehelix
grays:
density_map_grays

I particularly like Grays because it looks standard, avoids color clashing with unit colors and looks nicer in the UnitSummary (see below) but any would work
density_map_summary_white

Let me know which one you guys like and I'm happy to send a last commit with that change.

@samuelgarcia
Copy link
Member

Really cool.
I will read this in detail.

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.

4 participants