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 BaseRasterWidget #3661

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

Conversation

chrishalcrow
Copy link
Collaborator

Added BaseRasterWidget widget, and re-factored AmplitudeWidget, RasterWidget and DriftRasterMapWidget to use it.

Following on from @JoeZiminski's comment in #3649, I’ve made a BaseRasterWidget, which can be used to make spike times vs anything plots. Some advantages:

  • Unifies the plotting logic for AmplitudeWidget, RasterWidget and DriftRasterMapWidget (and later LocationsWidget)
  • Plotting kwargs from some widgets can now be used by others. E.g. y_lim and scatter_decimate from DriftRasterMapWidget is now available for AmplitudeWidget.

Now users (and devs!) can easily make custom raster plots, e.g. if you have a sorting analyzer called sa with spike_amplitudes computed, you can do:

all_spiketrains = {
    unit_id: sa.sorting.get_unit_spike_train(unit_id, segment_index=0, return_times=True) 
for unit_id in sa.sorting.unit_ids}

locations = sa.get_extension("spike_amplitudes").get_data(outputs="by_unit")[0]
x_locs_squares = {
    unit_id: pow(locations[unit_id],2)
for unit_id in sa.sorting.unit_ids}

BaseRasterWidget(spike_train_data=all_spiketrains, y_axis_data=x_locs_squares, unit_ids=[2,6], backend="matplotlib", y_lim=[0,50_000], title="Amplitudes Squared!!!", y_label="I love axis labels")

which makes this:
amp_squared

The goal was for this to be totally backend and not change any plots, but when doing it, I think it was a chance to unify some widget style choices. E.g. drawing just the left and bottom axes, and making the data fill the plot. It's a little difficult to test all this stuff. Here's a bunch of plots using main and this PR. I've also checking that SortingView can still do an amplitudes plot and played with ipywidgets a lot.

OLD vs NEW

lotsa_plots

@chrishalcrow chrishalcrow added widgets Related to widgets module refactor Refactor of code, with no change to functionality labels Jan 31, 2025
@zm711
Copy link
Collaborator

zm711 commented Feb 3, 2025

I have to admit I like your style better with the edges removed. Looking classier to me. Something I've been meaning to suggest for a long time!

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.

first round of comments. I think the main thing is actually making sure the segment handling is working as expected. I think a bug from before this refactor was being propagated.

@chrishalcrow
Copy link
Collaborator Author

There's currently different behaviour for plot_rasters and plot_amplitudes for a multi-segment analyzers.

  • For plot_rasters, an error is raised if you forget to supply a segment_index (for a multi-segment recording).
  • For plot_amplitudes, the 0th segment is chosen by default if no segment index is chosen.

Should we keep the different behaviours? Or unify the behaviour?

@samuelgarcia @zm711

@alejoe91
Copy link
Member

There's currently different behaviour for plot_rasters and plot_amplitudes for a multi-segment analyzers.

  • For plot_rasters, an error is raised if you forget to supply a segment_index (for a multi-segment recording).
  • For plot_amplitudes, the 0th segment is chosen by default if no segment index is chosen.

Should we keep the different behaviours? Or unify the behaviour?

@samuelgarcia @zm711

Maybe warn and plot the first one?

@zm711
Copy link
Collaborator

zm711 commented Feb 18, 2025

I would say unify the behaviors in general. I only deal in mono segments so if Alessio is good with warn and do the first then that works for me for everything. I think I would lean toward error to force people to specify a segment so they realize this is only plotting one segment, but I'm also okay with a warning.

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.

I'm sorry for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor of code, with no change to functionality widgets Related to widgets module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants