spikeinterface
spikeinterface copied to clipboard
Sort input extensions
Automatically sorts a list of extensions, for computation, so that all parents are “on the left” of their children. Improvement suggested by @alejoe91 .
For example, the SortingAnalyzer extension waveforms
depends on random_spikes
. If you run
sorting_analyzer.compute([“waveforms”, “random_spikes”])
this fails as the compute function scans left to right. It’s a bit annoying since the user has tried to include random_spikes
. It’s also easy to image a user running sorting_analyzer.compute([“waveforms”])
. si tells the user they need to have random_spikes
and they naturally add it on the right of the list. So: worth improving!
This change would automatically sort the inputted list so that all parents are on the left of their children. The function itself doesn’t check if the whole list is valid (i.e. it doesn’t return an error if random_spikes
isn’t there when calculating waveforms
), it only sorts it. These checks happen downstream.
The function I’ve written is a bit awkward, because the compute parameters are dictionaries (if you input a list, this gets converted to a dictionary internally, so kwargs can be easily handled.). And dictionaries aren’t really meant to have an order: so insertions at given indices are tricky etc. Here, I turn the dict into two lists, do the sorting, then zip. If anyone thinks of a cleaner algorithm, let me know.
Also added tests.