Project E: Large-scale neural data
Hundreds of neurons recorded at once from a mouse's visual cortex, downloaded free. Spike sorting, quality metrics, tuning curves, and the population view that Phase 3's decoders were pointing at.
You are skimming: the title, the first figure, and the short version. Switch to Read in the header for the full page, or Deep to open every deep dive.
The Allen Brain Observatory recorded thousands of neurons across the mouse visual system with NeuropixelsNeuropixelsSilicon probes with hundreds to thousands of recording sites along a thin shank, the current standard for large-scale animal recording. Glossary entry probes while the animals watched images and movies, and put all of it online with a Python SDK. It is the largest, cleanest, best-documented electrophysiology dataset there is, and an undergraduate can load it in an afternoon. Working with it is how you learn what “a population of neurons” means, what spike sorting produces and how much to trust it, and why the decoders in Phase 3 work at all.
A Neuropixels probe has 384 recording sites along a 1 cm shank. Roughly how many well-isolated neurons does one insertion yield?
A few hundred, typically 200 to 400 after quality filtering. Each neuron’s spike appears on several neighbouring sites, and each site hears several neurons; spike sorting untangles them and discards the units it cannot isolate. The count depends on the brain region and the sorting criteria, and the criteria are where honest analysis begins.
Get the data
The AllenSDK gives you a session as an object: spike times per unit, unit quality metrics, stimulus presentation times, running speed, pupil size, and the LFP. Start with one session from the “Brain Observatory 1.1” Neuropixels dataset.
from allensdk.brain_observatory.ecephys.ecephys_project_cache import EcephysProjectCache
cache = EcephysProjectCache.from_warehouse(manifest='./ecephys_cache/manifest.json')
sessions = cache.get_session_table()
session = cache.get_session_data(sessions.index[0])
units = session.units # one row per sorted unit with quality metrics
spikes = session.spike_times # dict: unit id -> array of spike times in seconds
Trust, but verify the units
Each unit comes with metrics: signal-to-noise, ISI violation rate (how often two spikes are closer than a neuron can fire, which means two neurons got merged), presence ratio, amplitude cutoff. Filter with the standard thresholds, then look at a few units’ waveforms and autocorrelograms yourself. A unit with a clean refractory gap in its autocorrelogram is a neuron. One without is a mixture. The practice of looking is what separates people who analyze spike data from people who analyze spreadsheets.
Tuning curves
Take the drifting-gratings stimulus: eight directions, several temporal frequencies. For each unit and each direction, count spikes in the stimulus window across repeats and average. Plot rate against direction. Some units have a clear preferred direction (a peak), some are orientation-selective (two peaks, 180 degrees apart), some are flat. Compute an orientation selectivity index. Plot the distribution across a few hundred units. You have reproduced the classical physiology of visual cortex from public data in an afternoon.
The population
Now stop looking at one neuron. Build a matrix: trials by neurons, each entry the spike count in a window. Run principal component analysis on it. The first few components capture most of the variance; the population’s activity lives on a low-dimensional manifold. Colour the trials by stimulus direction in the space of the first three components and watch them separate. Train a linear decoder (LDA, from Phase 3) to predict direction from the population vector, with honest cross-validation by trial block. Then reduce the number of neurons and plot accuracy against neuron count. That curve is the argument for recording more neurons, and it is why Neuropixels exist.
LFP versus spikes
The same probe recorded the local field potential. Plot its spectrogram around stimulus onset alongside the population firing rate. See the gamma increase during visual stimulation and its relation to spiking. This is the same relationship you will need in Phase 6 when intracortical recordings offer you both.
Spike sorting yourself
The Allen units are already sorted. To see what sorting does, take a raw Neuropixels recording (SpikeInterface’s tutorials point to short public ones), run Kilosort or Mountainsort through SpikeInterfaceSpike sortingDeciding which spikes on an electrode came from which neuron, by clustering their waveform shapes. Glossary entry, compute the same quality metrics, and look at what the sorter got right and what it merged or split. An hour with a raw recording teaches humility about every spike-based result you will ever read.
- Install AllenSDK, download one session, and list its units with quality metrics.
- Filter units by standard thresholds. Plot ten waveforms and autocorrelograms and judge them.
- Compute direction tuning curves for all units and the distribution of selectivity.
- Build the trials-by-neurons matrix, run PCA, plot trials in component space coloured by direction.
- Decode direction with LDA, cross-validated by block. Plot accuracy against neuron count.
- Run a spike sorter on a short raw recording via SpikeInterface and compare its output to the provided sorting.