Beispiel #1
0
def run_spike_sorting_ibl(bin_file):
    _logger = logging.getLogger("pykilosort")
    START_TIME = datetime.datetime.now()

    out_dir = Path("/datadisk/Data/spike_sorting/datasets").joinpath(
        '_'.join(list(bin_file.parts[-6:-3]) + [bin_file.parts[-2]]))
    out_dir.mkdir(exist_ok=True, parents=True)
    add_default_handler(level='DEBUG')
    add_default_handler(
        level='DEBUG',
        filename=out_dir.joinpath(f"{START_TIME.isoformat()}_kilosort.log"))
    files_chmap = Path(
        "/home/olivier/Documents/MATLAB/Kilosort2/configFiles/neuropixPhase3A_kilosortChanMap.mat"
    )
    matdata = Bunch(scipy.io.loadmat(files_chmap))

    probe = Bunch()
    probe.NchanTOT = 385
    # WARNING: indexing mismatch with MATLAB hence the -1
    probe.chanMap = (matdata.chanMap - 1).squeeze()
    probe.xc = matdata.xcoords.squeeze()
    probe.yc = matdata.ycoords.squeeze()
    probe.kcoords = probe.yc * 0 + 1

    try:
        _logger.info(f"Starting KS, output in {out_dir}")
        run(bin_file,
            probe=probe,
            dir_path=out_dir,
            n_channels=385,
            dtype=np.int16,
            sample_rate=3e4)
    except Exception as e:
        _logger.exception("Error in the main loop")

    [_logger.removeHandler(h) for h in _logger.handlers]
Beispiel #2
0
dat_path = Path("test/test.bin").absolute()
dir_path = dat_path.parent

ka.set_config(fr="default_readonly")
recording_path = "sha1dir://c0879a26f92e4c876cd608ca79192a84d4382868.manual_franklab/tetrode_600s/sorter1_1"
recording = AutoRecordingExtractor(recording_path, download=True)
recording.write_to_binary_dat_format(str(dat_path))
n_channels = len(recording.get_channel_ids())

probe = Bunch()
probe.NchanTOT = n_channels
probe.chanMap = np.array(range(0, n_channels))
probe.kcoords = np.ones(n_channels)
probe.xc = recording.get_channel_locations()[:, 0]
probe.yc = recording.get_channel_locations()[:, 1]

add_default_handler(level="DEBUG")

params = {"nfilt_factor": 8, "AUCsplit": 0.85, "nskip": 5}

run(
    dat_path,
    params=params,
    probe=probe,
    dir_path=dir_path,
    n_channels=probe.NchanTOT,
    dtype=np.int16,
    sample_rate=recording.get_sampling_frequency(),
)
        eng.workspace['rootZ'] = rootZ

    rez = eng.function_kilosort(rootZ, ops)
os.listdir(MATLAB_SORTING_RESULTS_DIR)

# ## Sort simulated data using pykilosort

# In[40]:

import pykilosort
from pathlib import Path
from importlib import reload
from pykilosort import main
reload(main)

pykilosort.add_default_handler()

# In[35]:

np.load(PYKILOSORT_SORTING_RESULTS_DIR +
        '/.kilosort/sim_binary.imec.ap/igood.npy')

# In[43]:

probe = pykilosort.Bunch()
probe.NchanTOT = int(opts['NchanTOT'])
probe.chanMap = np.load(BASE_PATH + '/chanMap.npy').flatten().astype(int)
probe.kcoords = np.ones(int(opts['NchanTOT']))
probe.xc = np.load(BASE_PATH + '/xc.npy').flatten()
probe.yc = np.load(BASE_PATH + '/yc.npy').flatten()
Beispiel #4
0
from math import ceil
from pathlib import Path
from pytest import fixture

import numpy as np

from pykilosort.utils import Bunch, read_data

from pykilosort import add_default_handler
add_default_handler(level='DEBUG')

from math import ceil
from pathlib import Path
from pytest import fixture

import numpy as np


@fixture
def data_path():
    path = (Path(__file__).parent / '../../data/').resolve()
    assert path.exists()
    return path


@fixture
def dat_path(data_path):
    return data_path / 'imec_385_100s.bin'


@fixture