Default values and assertion
@@ -269,6 +269,7 @@ def append_sortings(*args, **kwargs):
append_sortings.__doc__ == AppendSegmentSorting.__doc__
+
class SplitSegmentSorting(BaseSorting):
"""Splits a sorting with a single segment to multiple segments
based on the given list of recordings (must be in order)
@@ -282,24 +283,27 @@ class SplitSegmentSorting(BaseSorting):
into smaller segments
If ConcatenateSegmentRecording, uses the associated list of recordings to split
the sorting into smaller segments
- If None, looks for the recording associated with the sorting
+ If None, looks for the recording associated with the sorting (default None)
"""
- def __init__(self, parent_sorting: BaseSorting, recording_or_recording_list):
+ def __init__(self, parent_sorting: BaseSorting, recording_or_recording_list=None):
assert parent_sorting.get_num_segments() != 1, "The sorting must have only one segment."
sampling_frequency = parent_sorting.get_sampling_frequency()
unit_ids = parent_sorting.unit_ids
BaseSorting.__init__(self, sampling_frequency, unit_ids)
parent_sorting.copy_metadata(self)
- if isinstance(recording_or_recording_list, list):
+ if recording_or_recording_list is None:
+ assert parent_sorting.has_recording(), ("There is no recording registered to the sorting object. "
+ "Please specify the 'recording_or_recording_list' argument.")
+ recording_list = [parent_sorting._recording]
+ elif isinstance(recording_or_recording_list, list):
# how to make sure this list only contains recordings (of possibly various types)?
recording_list = recording_or_recording_list
elif isinstance(recording_or_recording_list, ConcatenateSegmentRecording):
recording_list = recording_or_recording_list.recording_list
- elif recording_or_recording_list is None:
- recording_list = [parent_sorting._recording]
else:
- raise TypeError("`recording_or_recording_list` must be a list of recordings, ConcatenateSegmentRecording, or None")
+ raise TypeError("'recording_or_recording_list' must be a list of recordings, "
+ "ConcatenateSegmentRecording, or None")
num_samples = [0]
for recording in recording_list:
@@ -316,6 +320,7 @@ class SplitSegmentSorting(BaseSorting):
self._kwargs = {'parent_sorting': parent_sorting,
'recording_list': [recording.to_dict() for recording in recording_list]}
+
def split_sorting(*args, **kwargs):
return SplitSegmentSorting(*args, **kwargs)
