Skip to content

Extend docstrings for amplitude scaling and collisions#2893

Merged
alejoe91 merged 29 commits intoSpikeInterface:mainfrom
JoeZiminski:amplitude_scaling_collisions_fix
Jun 6, 2024
Merged

Extend docstrings for amplitude scaling and collisions#2893
alejoe91 merged 29 commits intoSpikeInterface:mainfrom
JoeZiminski:amplitude_scaling_collisions_fix

Conversation

@JoeZiminski
Copy link
Copy Markdown
Collaborator

@JoeZiminski JoeZiminski commented May 21, 2024

In investigating #2882 I had some trouble understanding what the code around amplitude scalings and fit collisions. The code itself is easy to follow, but there is a lack of context and supporting information on data structures which can make it tricky to understand what is going on without breaking into the code. I think I'll add the fix for #2882 in a different PR so the scope does not become too large.

This PR:

  1. does some minor variable renamings for clarity
  2. extends docstrings for find_collisions, fit_collision and AmplitudeScaling classes and adds a few extra explanatory comments.
  3. Uncomments the plot-debugging code, makes functions private and add short docstring.

Some questions:

  1. A lot of the computations depend on the first entry into the collisions structure being the spike of interest. If the code is refactored in a way that changes this by accident, it will be difficult to track down but have major negative affect (all amplitude scalings will be wrong). Make the structure of collisions can be changed, so this has two entries (spike) and (colliding_spikes). This imo would make this more robust in future.
  2. The spikes structure is an array with entries An array of spikes (sample_index, channel_index, amplitude, segment_index, unit_index, in_margin). I had added this explicitly to docstrings (initially, I just assumed it was array of indexes). But, there is now some duplication in the docstring, personally I don't think this too bad a thing, but might be a point for discussion.

Update before merge

  • tests were not adressed here but can be later, based on this comment
  • the implicit spike-of-interest required to be in the first position of the collisions (1 above) dict is quite fiddly to address, and it would be easy to design a test to catch this case, this can be open in a new PR.

@JoeZiminski JoeZiminski changed the title Extend documentation for amplitude scaling and collisions Extend docstrings for amplitude scaling and collisions May 21, 2024
Copy link
Copy Markdown
Member

@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.

Just a few initial comments.

Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
@alejoe91 alejoe91 added the documentation Improvements or additions to documentation label May 23, 2024
@alejoe91
Copy link
Copy Markdown
Member

Thanks Joe! I'd be happy to discuss about this during the hackahton.

I brief comment about the _plot_* tests. These are designed as debug plotting routines, so I don't think they should be tested here. If we want to make a proper plotting routine for collisions (which might be cool for testing sorters and debugging), it's a better idea to port them to the widgets module

Copy link
Copy Markdown
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

Thanks a lot for doing this. I learn from these efforts as I have not used the methods myself.

Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py
@JoeZiminski
Copy link
Copy Markdown
Collaborator Author

Thanks @h-mayorquin! I've addressed the points and used a bullet-point approach for the definitions I agree much clearer now, let me know what you think!

Cheers @alejoe91 I agree if these are not really in-use functions it does not make as much sense to add to the maintainability burden by adding tests for them. Do you think these would be useful enough to add as general widgets? Happy to do this, otherwise, do you think they could be moved to a personal repo? I'm conflicted, as I can see the use of having quick debugging functions in the main codebase, but if they are in the main codebase they should have some tests to check they don't become stale / unusable. But then, this adds maintainability burden 🤔

Copy link
Copy Markdown
Collaborator

@h-mayorquin h-mayorquin left a comment

Choose a reason for hiding this comment

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

To me this is clearly an improvement. Some final comments but this is good to go for me.

Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py Outdated
Comment thread src/spikeinterface/postprocessing/amplitude_scalings.py
@JoeZiminski
Copy link
Copy Markdown
Collaborator Author

Thanks everyone for their feedback! @alejoe91 I think this is good to go, currently the _plot_collisions function is broken, it wants a sac._extension_data attribute which I think was deprecated, and sac.collissions attribute is currently not used. I left a note on this. Let me know if it needs anything further, cheers!

@JoeZiminski JoeZiminski requested review from alejoe91 and zm711 June 6, 2024 08:28
@alejoe91
Copy link
Copy Markdown
Member

alejoe91 commented Jun 6, 2024

Thanks for the clarifications @JoeZiminski! I agree that this function was a bit obscure..it's very nice to see additional eyes on it!

We can keep the TODOs for a follow up, ok?

@alejoe91 alejoe91 merged commit a8ed7c8 into SpikeInterface:main Jun 6, 2024
@JoeZiminski
Copy link
Copy Markdown
Collaborator Author

Sure sounds good @alejoe91, thanks for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants