Skip to content

Add group by preprocessing conveneience function. - #2299

Closed
JoeZiminski wants to merge 2 commits into
SpikeInterface:mainfrom
JoeZiminski:add_group_by_recording
Closed

JoeZiminski wants to merge 2 commits into
SpikeInterface:mainfrom
JoeZiminski:add_group_by_recording

Conversation

@JoeZiminski

@JoeZiminski JoeZiminski commented Dec 6, 2023 •

Copy link
Copy Markdown
Contributor

This PR creates a convenience function to run all preprocessing by a property (currently just "group") as discussed in #2033. @alejoe91 @h-mayorquin

In this draft implementation, first all preprocesing steps and associated kwargs are iteratively discovered from the recordings _kwargs property. Then these are re-applied to the base recording.

However, testing shows this approach is brittle because often, the _kwargs parameters do not contain only the user-passed kwargs but additional logic based on the recording. For example, in whiten the whitening matrix is computed based on the passed recording and stored in kwargs W parameter. Then, trying to apply this to smaller subsets of recordings fails. This kind of pattern occurs a number of times across preprocessors.

A possible solutions to the current implementation is to somehow ensure all preprocessors only store user-passed kwargs in their _kwargs option, but this seems like a bad idea. Maybe there is another way to get these user-passed kwargs.

Alternatively, the preprocessing steps and associated kwargs could be explicitly passed to the function as suggested in #2033. In this case though if I have understood correctly the user would have to reformat all inputs like:

group_by_preprocessing(recording, [PreprocessingClass1, PreprocessingClass2, ...], [preprocessing_kwargs_1, preprocessing_kwargs_2])

But personally if this is correct it feels easier to use the existing method of wrap standard preprocessing API in the split for-loop then aggregate rather than having to reformat the pipeline.

To summarise my thoughts on possible approaches for this convenience function / class are:

  1. It is difficult to have this as a class / function applied at the end of preprocessing chain due to the issue mentioned above.
  2. It does not seem possible to insert this at the start of the preproecssing chain, such that all following preprocessing steps are split. The get_traces() of the first-applied class should output as a single array not multiple arrays (i.e. it cannot somehow return 1 array per shank for later preprocessing). My understanding is a class that holds a split version of the recording and applies all subsequent preprocessing steps to each would still need to be handled at the level of each individual preprocessing class.
  3. It would be possible to apply a user-defined list of preprocessing steps and parameters, but I'm not sure if it's use is much easier than the existing API.

Now I wonder if adding a bit more documentation to the existing API (e.g. a short tutorial 'preprocessing by shank') would be a better approach (happy to do this).

An aside

During testing I found two cases where the API of some preprocessors does not match what seems to be standard.

  • ZeroChannelPaddedRecording saves it's parent recording to a parent_recording kwarg not a recording kwarg that seems to be used elsewhere.
  • ZeroSilencePeriods stores the parent recording as a dict not a recording.
    Is it worth standardising these? Maybe there are some practicalities to consider that make this not possible.

@zm711

zm711 commented Dec 6, 2023

Copy link
Copy Markdown
Member

I will also add @JoeZiminski CurationSorting; also used a parent_sorting rather than sorting (outside of the scope of a preprocessing PR, but a similar problem). I think I tried briefly to regularize with a super naive fix and saw that tests were failing when I did that. Then I dropped trying to regularize and decided to just delete my branch since I was going to need to carefully fix the disconnect for those. But I'm definitely in favor of regularizing parameter naming in general. (I think folder vs output_folder vs working_folder is one of the biggest naming issues I run into bouncing between functions at the argument level). Maybe this is worth an issue to fully discuss?

@alejoe91 alejoe91 added the preprocessing Related to preprocessing module label Dec 6, 2023
@JoeZiminski

Copy link
Copy Markdown
Contributor Author

Thanks @zm711 I agree it is worth an issue as these changes could have some strange unexpected downstream effects!

I will close this PR and open a new one to introduce some additional documentation for split / aggregate recordings.

@h-mayorquin

h-mayorquin commented Dec 19, 2023 •

Copy link
Copy Markdown
Contributor

To summarise my thoughts on possible approaches for this convenience function / class are:

  1. It is difficult to have this as a class / function applied at the end of preprocessing chain due to the issue mentioned above.
  2. It does not seem possible to insert this at the start of the preproecssing chain, such that all following preprocessing steps are split. The get_traces() of the first-applied class should output as a single array not multiple arrays (i.e. it cannot somehow return 1 array per shank for later preprocessing). My understanding is a class that holds a split version of the recording and applies all subsequent preprocessing steps to each would still need to be handled at the level of each individual preprocessing class.
  3. It would be possible to apply a user-defined list of preprocessing steps and parameters, but I'm not sure if it's use is much easier than the existing API.

@JoeZiminski
This summary is very good. Thanks for writing it.

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

Labels

preprocessing Related to preprocessing module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants