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 LocationsWidget and plot_locations #3649

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

chrishalcrow
Copy link
Collaborator

Add a LocationsWidget and plot_locations, to complement the AmplitudesWidget and plot_amplitudes.

This plots the spike locations as a function of time, and is 99% the same as the plot_amplitudes function. You can control which direction you want to plot using e.g. directions_axis = 'x' and plot a histogram if you'd like.

An example:

import spikeinterface.full as si
_, drift_rec, sort = si.generate_drifting_recording(
    num_units=2, 
    duration=30,
    generate_displacement_vector_kwargs=dict(
        displacement_sampling_frequency=20.0,
        drift_start_um=[0, 50],
        drift_stop_um=[0, -50],
        drift_step_um=5,
        motion_list=[
            dict(
                drift_mode="zigzag",
                non_rigid_gradient=None,
                t_start_drift=0.0,
                t_end_drift=None,
                period_s=300,
            ),
        ],
    )
)

sorting_analyzer = si.create_sorting_analyzer(sorting=sort, recording=drift_rec)
sorting_analyzer.compute(['random_spikes', 'templates', 'spike_locations'])
si.plot_locations(sorting_analyzer, unit_ids=['0'])
Screenshot 2025-01-28 at 19 06 54

Or

si.plot_locations(sorting_analyzer, unit_ids=['0'], plot_histograms=True)
Screenshot 2025-01-28 at 19 06 30

Can plot multiple units, e.g.

si.plot_locations(sorting_analyzer, unit_ids=['0','1'])
Screenshot 2025-01-28 at 19 11 37

Up for debate:

  • is this a useful widget? I've been using it, so I think it is!
  • is a histogram useful?
  • Naming. We already have plot_spike_locations which plots the spike locations on the probe. This naming is designed to pair with plot_amplitudes.

@chrishalcrow chrishalcrow added widgets Related to widgets module enhancement New feature or request labels Jan 28, 2025
@zm711
Copy link
Collaborator

zm711 commented Jan 28, 2025

I can dig this at least. I would check this out if we had it.

@samuelgarcia
Copy link
Member

Good idea. I think it can be usefull.
Maybe we could move it to the same file than spike_location.

Another idea (not sure it is a good one) could be to move this logic in the spike_location widget using having options like:

  • along_times=True/False
  • with_histogram=True/False

@JoeZiminski
Copy link
Collaborator

Looks really nice! Under the hood this looks similar to the DriftRasterMapWidget as shown here but with the spikes coloured by unit membership rather than amplitude? In this case maybe there is scope to leverage the existing raster-plot backend and use the array of unit ids for colouring?

Incorporating this directly with DraftRasterMapWidget would be confusing but there might be scope for a common raster-plot backend (I don't think there is anything particularly drift-specific about the DriftRasterMapWidget, it is just spike depth x time) that these various functions could call, with different spike-colouring options. There is also a RasterWidget, I'm not sure the scope / intersection across these different widgets.

The histogram look really nice, just in case useful here is another version on this PR that I never got over the line.

@chrishalcrow
Copy link
Collaborator Author

Looks really nice! Under the hood this looks similar to the DriftRasterMapWidget as shown here but with the spikes coloured by unit membership rather than amplitude? In this case maybe there is scope to leverage the existing raster-plot backend and use the array of unit ids for colouring?

Incorporating this directly with DraftRasterMapWidget would be confusing but there might be scope for a common raster-plot backend (I don't think there is anything particularly drift-specific about the DriftRasterMapWidget, it is just spike depth x time) that these various functions could call, with different spike-colouring options. There is also a RasterWidget, I'm not sure the scope / intersection across these different widgets.

The histogram look really nice, just in case useful here is another version on this PR that I never got over the line.

That's a great idea, Joe! I just hacked together a 90%-the-same plot using DriftRasterMapWidget in a few lines. I think a common raster-plot backend is a good idea - I'll give it a go!

Thanks for the other feedback, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request widgets Related to widgets module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants