Skip to content
6 changes: 6 additions & 0 deletions src/spikeinterface/sorters/basesorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from spikeinterface.core import load, BaseRecordingSnippets, BaseRecording
from spikeinterface.core.core_tools import check_json
from spikeinterface.core.recording_tools import get_rec_attributes
from spikeinterface.core.globals import get_global_job_kwargs
from spikeinterface.core.job_tools import fix_job_kwargs, split_job_kwargs
from .utils import SpikeSortingError, ShellScript
Expand Down Expand Up @@ -154,6 +155,11 @@ def initialize_folder(cls, recording, output_folder, verbose, remove_existing_fo
"compatible binary file."
)

# save recording attributes in case the recording is not serializable or removed after sorting
rec_attributes = get_rec_attributes(recording)
rec_attributes_file = output_folder / "recording_attributes.json"
rec_attributes_file.write_text(json.dumps(check_json(rec_attributes), indent=4), encoding="utf8")
Comment on lines +158 to +161

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oooh ok this is very nice and simple.


return output_folder

@classmethod
Expand Down
11 changes: 9 additions & 2 deletions src/spikeinterface/sorters/external/kilosortbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,15 @@ def _get_result_from_folder(cls, sorter_output_folder):
with params_file.open("r") as f:
sorter_params = json.load(f)["sorter_params"]

recording = BaseSorter.load_recording_from_folder(sorter_output_folder.parent, with_warnings=False)
channel_ids = recording.channel_ids if recording is not None else None
channel_ids = None
recording_attributes_file = sorter_output_folder.parent / "recording_attributes.json"
if recording_attributes_file.is_file():
with open(recording_attributes_file, "r") as f:
rec_attributes = json.load(f)
channel_ids = rec_attributes.get("channel_ids")
Comment thread
chrishalcrow marked this conversation as resolved.
Comment thread
chrishalcrow marked this conversation as resolved.
else:
recording = BaseSorter.load_recording_from_folder(sorter_output_folder.parent, with_warnings=False)
channel_ids = recording.channel_ids if recording is not None else None

keep_good_only = sorter_params.get("keep_good_only", False)
sorting = KiloSortSortingExtractor(
Expand Down
Loading