Skip to content

Commit

Permalink
Merge pull request #2791 from zm711/ensure-analyzer-value-error
Browse files Browse the repository at this point in the history
Add errors to `ensure` functions  in `Base` of widgets
  • Loading branch information
samuelgarcia authored May 2, 2024
2 parents 1d88111 + 0c96661 commit fa710f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/spikeinterface/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,25 +109,25 @@ def do_plot(self):

@classmethod
def ensure_sorting_analyzer(cls, input):
# internal help to accept both SortingAnalyzer or MockWaveformExtractor for a ploter
# internal help to accept both SortingAnalyzer or MockWaveformExtractor for a plotter
if isinstance(input, SortingAnalyzer):
return input
elif isinstance(input, MockWaveformExtractor):
return input.sorting_analyzer
else:
return input
raise TypeError("input must be a SortingAnalyzer or MockWaveformExtractor")

@classmethod
def ensure_sorting(cls, input):
# internal help to accept both Sorting or SortingAnalyzer or MockWaveformExtractor for a ploter
# internal help to accept both Sorting or SortingAnalyzer or MockWaveformExtractor for a plotter
if isinstance(input, BaseSorting):
return input
elif isinstance(input, SortingAnalyzer):
return input.sorting
elif isinstance(input, MockWaveformExtractor):
return input.sorting_analyzer.sorting
else:
return input
raise TypeError("input must be a SortingAnalyzer, MockWaveformExtractor, or of type BaseSorting")

@staticmethod
def check_extensions(sorting_analyzer, extensions):
Expand Down
4 changes: 3 additions & 1 deletion src/spikeinterface/widgets/crosscorrelograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ def __init__(
backend=None,
**backend_kwargs,
):
sorting_analyzer_or_sorting = self.ensure_sorting_analyzer(sorting_analyzer_or_sorting)

if not isinstance(sorting_analyzer_or_sorting, BaseSorting):
sorting_analyzer_or_sorting = self.ensure_sorting_analyzer(sorting_analyzer_or_sorting)

if min_similarity_for_correlograms is None:
min_similarity_for_correlograms = 0
Expand Down

0 comments on commit fa710f1

Please sign in to comment.