Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/spikeinterface/sorters/external/kilosort4.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,15 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):
cluster_spikes,
save_sorting,
get_run_parameters,
setup_logger,
)
from kilosort.io import load_probe, RecordingExtractorAsArray, BinaryFiltered, save_preprocessing
from kilosort.parameters import DEFAULT_SETTINGS

import time
import torch
import numpy as np

if verbose:
import logging

logging.basicConfig(level=logging.INFO)
import logging

if version.parse(cls.get_sorter_version()) < version.parse("4.0.16"):
raise RuntimeError(
Expand All @@ -183,6 +180,37 @@ def _run_from_folder(cls, sorter_output_folder, params, verbose):
"Please upgrade Kilosort version."
)

# setup kilosort's console and file log handlers
setup_logger_takes_verbose_console = version.parse(cls.get_sorter_version()) > version.parse("4.0.18")
logger_is_named = version.parse(cls.get_sorter_version()) > version.parse("4.0.20")

if setup_logger_takes_verbose_console:
# v4.0.19 and higher
setup_logger(sorter_output_folder, verbose_console=False)
else:
# v4.0.16, v4.0.17, v4.0.18
setup_logger(sorter_output_folder)

# if verbose is False, set the stream handler's log
# level to logging.WARNING to preserve original
# behavior prior to addition of setup_logger() above
if not verbose:
if logger_is_named:
# v4.0.21 and above
logger = logging.getLogger("kilosort")
else:
# v4.0.16, v4.0.17, v4.0.18, v4.0.19, v4.0.20
logger = logging.getLogger("")

# find the stream handler
stream_handler = None
for handler in logger.handlers:
if type(handler) == logging.StreamHandler:
stream_handler = handler
break

stream_handler.setLevel(logging.WARNING)

sorter_output_folder = sorter_output_folder.absolute()

probe_filename = sorter_output_folder / "chanMap.json"
Expand Down