Skip to main content

spikebias

tests PyPI

Measure the biases of spike sorting on dense extracellular recordings, such as Neuropixels, against the ground truth of a large-scale, detailed biophysical model of the rat cortex.

spikebias works on SpikeInterface extractors, so it applies to any sorter and any recording with a ground truth. It also streams the simulated recordings, ground truths and sortings of the paper from the DANDI Archive (dandiset 001250).

What it measures

Module Measure
spikebias.accuracy Sorting accuracy of each ground truth neuron: its best agreement score with a sorted unit
spikebias.biases Spike assignment bias of each sorted unit: good, overmerger, oversplitter, their mixtures, or false positive
spikebias.sampling Yield (isolated units per recording site, by layer) and selection biases (neuron types over- or under-represented among the sorted units)
spikebias.features, spikebias.model Model of the sorting accuracy of each neuron from its biological features (firing rate, layer, cell type, distance to the probe, spike amplitude and spatial extent)
spikebias.datasets Access to the recordings, ground truths and sortings of dandiset 001250

Install

pip install spikebias

Python 3.10 or later and SpikeInterface 0.101 or later.

Quick start

import spikebias as sb
from spikebias import datasets

# stream the ground truth and the Kilosort 4 sorting of the spontaneous Neuropixels simulation
ground_truth = sb.first_minutes(datasets.load_ground_truth("npx_spont"), minutes=10)
sorting = datasets.load_sorting("npx_spont", sorter="ks4")      # first 10 minutes

# sorting accuracy of each ground truth neuron
accuracy = sb.sorting_accuracy(ground_truth, sorting)
print(sb.count_well_sorted(accuracy), "of", len(accuracy), "neurons sorted with an accuracy >= 0.8")

# spike assignment bias of each sorted single-unit
biases = sb.classify_sorted_units(ground_truth, sorting, duration=600)
print(sb.bias_proportions(biases))

# yield per recording site, and selection biases by synapse class, layer and electrical type
recording = datasets.load_recording("npx_spont")                # streamed: only what is read is downloaded
print(sb.yield_per_site(sorting, recording))
print(sb.selection_biases(ground_truth, sorting))

Your own data work the same way: pass a SpikeInterface ground truth sorting and a sorting of the same period. The sampling and accuracy-model functions use the neurons' properties (layer, synapse_class, etype, x, y, z), which the biophysical datasets provide.

Model of the sorting accuracy

recording = sb.first_minutes(datasets.load_recording("npx_spont", local_folder="data"), minutes=10)
features = sb.neuron_features(ground_truth, recording, duration=600, n_jobs=8)
data = features.join(sb.sorting_accuracy(ground_truth, sorting)).dropna()   # drop neurons without spikes

model = sb.AccuracyModel(transform="rank")
r2 = sb.cross_validate(model, data.drop(columns="accuracy"), data["accuracy"], n_splits=100)
print(sb.summarize(r2))                       # McFadden pseudo R-squared on held-out neurons
print(model.fit(data.drop(columns="accuracy"), data["accuracy"]).weights)

neuron_features reads the spikes of every neuron from the recording, so download it first for large datasets (local_folder); the Neuropixels recordings are about 100 GB.

Definitions

  • Hit: a sorted spike within delta_time = 1.3 ms of a ground truth spike.
  • Agreement score of a ground truth neuron and a sorted unit: hits / (hits + misses + false positives).
  • Sorting accuracy of a ground truth neuron: its best agreement score with a sorted (single-)unit; it is well sorted at 0.8 or more.
  • Chance score of a pair: the agreement score expected from two independent Poisson spike trains with the units' firing rates.
  • Bias classes of a sorted unit: false positive if no agreement score is above chance; otherwise good (a score of at least 0.8), overmerger (more than one neuron matched above chance), oversplitter (a matched neuron is also matched above chance by another sorted unit), or a mixed combination.

Datasets

datasets.DATASETS lists the datasets of dandiset 001250, and datasets.list_assets(name) their files.

Name Content
npx_spont, npx_evoked, npx_evoked_40khz Biophysical simulations, Neuropixels 1.0 (spontaneous and evoked activity)
dense_probe1, dense_probe2, dense_probe3 Biophysical simulations, 128-site dense probe at three depths
npx_spont_disconnected Biophysical simulation of the disconnected circuit
buccino, buccino_rep, mearec_s2 to mearec_s5 Synthetic MEArec models
marques_smith, horvath_probe1 to horvath_probe3 In vivo recordings (no ground truth) with their sortings

Sorters: ks4, ks3, ks2.5, ks2, ks (Kilosort 4 to 1) and hs (Herdingspikes), on the first 10 minutes (minutes=10) or, for some datasets, the full recording (minutes=None).

Citation

If you use spikebias or the dataset, please cite:

The code that reproduces the paper's figures is at https://github.com/spikebias/spikebias-paper. For the curation of sorted single-units, see spikecurate.

License

GPL-3.0. Author: Steeve Laquitaine (laquitainesteeve@gmail.com).

Metadata

Release files for spikebias 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spikebias 0.1.0
File Size Uploaded Provenance Actions
spikebias-0.1.0.tar.gz 910.2 kB Without provenance Details for spikebias-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spikebias 0.1.0
File Interpreter ABI Platform Actions
spikebias-0.1.0-py3-none-any.whl Python 3 none any Details for spikebias-0.1.0-py3-none-any.whl

Total release size: 1.8 MB

Release files / spikebias-0.1.0.tar.gz

Download URL spikebias-0.1.0.tar.gz
Size 910.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f4e8cf3fd317e8102b418b7deab409f56a8bf8754be2e8e8561f4c2074a8833a
BLAKE2b-256 checksum
How to use checksums
b395e6e83c033067a6f29f93f07d0e2c29892ae08f595e355245912f3bb76c12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Release files / spikebias-0.1.0-py3-none-any.whl

Download URL spikebias-0.1.0-py3-none-any.whl
Size 906.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be19b4045828f14f94fcd6c062a02e1a9f723d5614730fc738272fff5d5dada2
BLAKE2b-256 checksum
How to use checksums
08153118780c0a782882fbca6151ad0b47b061046097178fb8408a3136f890fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.0

Security for spikebias 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page