Пример #1
0
    def _run_from_folder(cls, output_folder, params, verbose):
        recording = load_extractor(output_folder / 'spikeinterface_recording.json')

        assert isinstance(recording, BinaryRecordingExtractor)
        assert recording.get_num_segments() == 1
        dat_path = recording._kwargs['file_paths'][0]
        print('dat_path', dat_path)

        num_chans = recording.get_num_channels()
        locations = recording.get_channel_locations()
        print(locations)
        print(type(locations))

        # ks_probe is not probeinterface Probe at all
        ks_probe = Bunch()
        ks_probe.NchanTOT = num_chans
        ks_probe.chanMap = np.arange(num_chans)
        ks_probe.kcoords = np.ones(num_chans)
        ks_probe.xc = locations[:, 0]
        ks_probe.yc = locations[:, 1]

        run(
            dat_path,
            params=params,
            probe=ks_probe,
            dir_path=output_folder,
            n_channels=num_chans,
            dtype=recording.get_dtype(),
            sample_rate=recording.get_sampling_frequency(),
        )
Пример #2
0
def import_matlab_chanmap(chanmap_matfile):
    '''Load a MATLAB channel map file.

    Parameters
    ----------
    chanmap_matfile (str): MATLAB file containing probe information

    Returns
    -------
    probe (pykilosort.Bunch):
        Object containing probe information
    '''
    # read MAT file and extract relevant info
    mat = loadmat(chanmap_matfile)
    chanmap_zeroidx = mat['chanMap'].squeeze().astype(np.int64) - 1 # 0-indexed
    xcoords = mat['xcoords'].squeeze().astype(np.float32)
    ycoords = mat['ycoords'].squeeze().astype(np.float32)

    # Create `probe` object
    probe = Bunch()
    probe.chanMap = chanmap_zeroidx
    probe.xc = xcoords
    probe.yc = ycoords
    probe.NchanTOT = len(chanmap_zeroidx)
    return probe
Пример #3
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]
Пример #4
0
import kachery as ka
from pykilosort import Bunch, add_default_handler, run
from spikeextractors.extractors import bindatrecordingextractor as dat
from spikeforest2_utils import AutoRecordingExtractor, AutoSortingExtractor

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,