How to convert SpikeGLX and kilosort output
This guide shows you how to create the spike sorting, RMS and power spectrum files the GUI reads, from a SpikeGLX recording sorted with kilosort, pykilosort or iblsorter.
Prerequisites
The
iblextra installed (see How to install the optional extras).The spike sorting output folder from kilosort, pykilosort or iblsorter, and the folder with the SpikeGLX
.ap.bin(or.ap.cbin) and.metafiles. Neuropixels 1.0 recordings also need the.lf.bin; Neuropixels 2.0 probes record the LF band in the AP file, so it is computed from there.
Steps
Choose an output folder that is not the spike sorting output folder, so that none of the spike sorter’s files are overwritten.
Run:
import logging from pathlib import Path from ibl_alignment_gui.convertors.extract_ephys import extract_data # Progress is reported through the logger logging.basicConfig(level=logging.INFO) ks_path = Path('/path/to/spike/sorting/output') ephys_path = Path('/path/to/raw/ephys/data') out_path = Path('/path/to/output') extract_data(ks_path, ephys_path, out_path)
The RMS and power spectra are computed on samples taken through the recording, in parallel threads, so an hour-long recording takes a few minutes. To read the whole recording instead, or to use fewer threads on a shared machine, compute them with
extract_rmsmapafterextract_data:from ibl_alignment_gui.convertors.extract_ephys import extract_rmsmap ap_file = ephys_path / 'my_recording_g0_t0.imec0.ap.bin' extract_rmsmap(ap_file, out_folder=out_path, spectra=False, sample_spacing_secs=None, n_workers=2)
Check that the output folder holds
spikes.*,clusters.*andchannels.*files, and the_iblqc_ephysTimeRms*and_iblqc_ephysSpectralDensityLF.*files, each with arawIndfile.In the session YAML, use
out_pathas both thespike_sortingand theprocessed_ephysfolder, andephys_pathasraw_ephys(see How to write a session YAML for one probe).
Files made with an older version
Older versions of extract_ephys saved the RMS and power spectra with the channels sorted by
their position on the probe, and without the rawInd files that record the order. Recompute them
with the steps above when:
the GUI warns that the channels of these files may be in the wrong order. It does so when the raw file does not store the channels in shank and depth order, as on Neuropixels 2.0 four shank probes, where the plots then show the wrong channels;
the probe is a Neuropixels 2.0. Even without the warning, the left and right columns of sites may be swapped in the probe plots.