from one.api import ONE
from brainbox.io.one import SpikeSortingLoader
# ONE = Open Neurophysiology Environment, the IBL data access layer.
# The public endpoint lets anyone download data with those public credentials.
one_kwargs = dict(
base_url='https://openalyx.internationalbrainlab.org',
username='intbrainlab',
password='international',
silent=True,
)
one = ONE(**one_kwargs)
# Probe insertion IDs (pids) from the IBL Benchmarks dataset — a curated set of high-quality recordings.
pids = [
'1a276285-8b0e-4cc9-9f0a-a3a002978724', # 00 - Benchmark PIDS start
'1e104bf4-7a24-4624-a5b2-c2c8289c0de7',
'6638cfb3-3831-4fc2-9327-194b76cf22e1',
'749cb2b7-e57e-4453-a794-f6230e4d0226',
'd7ec0892-0a6c-4f4f-9d8f-72083692af5c',
'da8dfec1-d265-44e8-84ce-6ae9c109b8bd',
'dab512bd-a02d-4c1f-8dbc-9155a163efc0',
'dc7e9403-19f7-409f-9240-05ee57cb7aea',
'e8f9fba4-d151-4b00-bee7-447f0f3e752c',
'eebcaf65-7fa4-4118-869d-a084e84530e2',
'fe380793-8035-414e-b000-09bfe5ece92a', # Benchmark PIDS stop
]
pid = pids[-1]
# SpikeSortingLoader is a convenience object that bundles the probe geometry,
# spike-sorting results, and raw data access for a single insertion.
ss = SpikeSortingLoader(pid=pid, one=one)7 Explore the IBL dataset with viewephys
In this tutorial, we will download data from the International Brain Laboratory (IBL) and visualize it in viewephys.
The IBL is a consortium of neuroscience labs that collaborated to run a large, standardized set of behavioral and electrophysiology experiments, generating a huge open dataset. The IBL’s Brainwide Map includes nearly 700 Neuropixels recordings collected across 12 labs, covering 279 brain areas.
7.1 Access the IBL data
The code below can be used to stream snippets of IBL recordings and can be adjusted to download entire recordings. It lists a selection of 11 benchmark probe insertion IDs (PIDs) and selects one insertion.
You can access other recordings by changing the IDs, using the list of Brainwide Map PIDs.
ss is a SpikeSortingLoader: an object that gives us access to the selected probe insertion’s raw recordings, channel locations and spike-sorting results. Creating it does not download the full raw recording.
You can use this object to stream snippets of the recording or download the entire recording.
Below, we will stream snippets rather than download the entire recording. This reduces the amount of data transferred. However, you can use the code below to save the full recording to disk if you want to explore the dataset further:
# Optional: download the full AP-band recording to ONE's local cache.
files = ss.download_raw_electrophysiology(band='ap')
print(files)This downloads the .cbin voltage file and its .ch and .meta companion files, and returns their paths.
Here we use the selected PID as an example, but you could loop over the list of pids to download multiple datasets.
7.2 Visualizing in viewephys
Next we will visualize the IBL data by streaming directly from the ss object we created above. Run the viewing code in the same session as the setup code, for example by adding it to the same Jupyter notebook or Python script.
Show the shared viewing code
# Run prepare_ibl_loader.py first, in the same Python session.
import scipy.signal
import ibldsp.voltage
from viewephys.gui import viewephys
from iblatlas.atlas import BrainRegions
# get the histology information
channels = ss.load_channels()
# stream=True fetches only the requested chunk on-the-fly — no need to download the full recording.
# band='ap' selects the action-potential band (300 Hz high-pass, 30 kHz sample rate).
sr = ss.raw_electrophysiology(band='ap', stream=True)
sr_lf = ss.raw_electrophysiology(band='lf', stream=True)
# %%
# ---------------------------------------------------------------------------
# Load a short snippet of raw voltage data
# ---------------------------------------------------------------------------
T0 = 500 # start time in seconds — pick a quiet moment well into the recording
# sr[samples, channels] — slice to get 0.5 s of data.
# We transpose (.T) so the result is (n_channels, n_samples): the convention expected by ibldsp.
# The last channel is the sync/TTL channel; dropping it keeps only the 384 neural channels.
raw = sr[int(T0 * sr.fs):int((T0 + 0.5) * sr.fs), :-1].T
# %%
# ---------------------------------------------------------------------------
# Step 1 — Butterworth high-pass filter
# ---------------------------------------------------------------------------
# A 3rd-order Butterworth filter at 300 Hz removes slow LFP oscillations and
# DC drift while preserving the sharp transients caused by action potentials.
# sosfiltfilt applies the filter twice (forward + backward) for zero phase distortion.
butter_kwargs = {'N': 3, 'Wn': 300, 'btype': 'highpass', 'fs': sr.fs}
sos = scipy.signal.butter(**butter_kwargs, output='sos')
butt = scipy.signal.sosfiltfilt(sos, raw)
# ---------------------------------------------------------------------------
# Step 2 — Full IBL destriping pipeline
# ---------------------------------------------------------------------------
# ibldsp.voltage.destripe runs the complete IBL pre-processing chain:
# • High-pass Butterworth (same as above)
# • ADC sample-shift correction (Neuropixels channels are not sampled simultaneously)
# • Spatial k-filter (removes stripe artifacts correlated across channels)
#
# Use the channel labels loaded for this insertion to identify bad channels.
destriped = ibldsp.voltage.destripe(raw, fs=sr.fs, h=sr.geometry,
neuropixel_version=sr.major_version,
channel_labels=channels['labels'])
# ---------------------------------------------------------------------------
# Display all three stages in viewephys for side-by-side comparison
# ---------------------------------------------------------------------------
# viewephys is an IBL interactive viewer: scroll with the mouse wheel,
# adjust gain with the viewer controls, and pan by clicking and dragging.
regions = BrainRegions()
eqcs = {}
eqcs['raw'] = viewephys(raw, sr.fs, channels=channels, title='Raw (unfiltered)', t0=T0, br=regions)
eqcs['butt'] = viewephys(butt, sr.fs, channels=channels, title='Butterworth high-pass 300 Hz', t0=T0, br=regions)
eqcs['destriped'] = viewephys(destriped, sr.fs, channels=channels, title='Destriped (butter + ADC + k-filter)', t0=T0, br=regions)
Copy the visualization code into your favorite IDE. Note that you will need to make a small adjustment to the code depending on whether you are running in a notebook or through a script:
Run this in a cell before running the shared viewing code above. It keeps the viewer windows responsive while you continue working in the notebook or IPython session.
%gui qtAdd this before the shared viewing code in your .py file to create the Qt application:
from viewephys.gui import create_app
app = create_app()Then add this at the end of the file, after the shared viewing code, to keep the windows open until you close them:
app.exec()Add code for the later exercises before app.exec().
7.2.2 Cycling through the different preprocessing steps
After using Propagate (Ctrl+P), all three windows should be synchronized.
- Cycle through the windows using
Alt+Tab. How different are they? - On the raw display, right-click on the data and look at individual traces. What can you say about the DC offset and grounding? The units are µV, and these probes saturate at 1200 µV. Can you spot any saturation events in the raw data?
7.2.3 Looking at different recordings in different brain regions
You can select different probe insertions by changing the index i in pid = pids[i] to visualize different brain regions. Then recreate ss and rerun the viewing code for the selected insertion.
What can you see for different insertions? Are there any quality issues with the data? How do the signal characteristics differ between regions?
You can also browse plots of several of these insertions online.
7.2.4 Looking at the LFP
Let’s stream 5 seconds of raw LFP and print the folder in which the data is stored:
raw_lf = sr_lf[int(T0 * sr_lf.fs):int((T0 + 5) * sr_lf.fs), :-1].T
eqcs['raw_lf'] = viewephys(raw_lf, sr_lf.fs, channels=channels, title='Raw LFP', t0=T0, br=regions)
print(sr_lf.target_dir)In a shell, with the environment active, type viewephys. Select raw and LFP, then open File > Open and select the .cbin file in the folder above.
How close is the raw voltage to saturation? What is the shape of the spectrum if you right-click and compute the PSD?
7.2.5 Other IBL
The IBL produce many useful tools for extracellular electrophysiology. For example, see these presentations which explore probe histology reconstruction with electrophysiological landmarks (Pranav Rai, ~20 mins), an electrophysiological atlas (Olivier Winter, ~20 mins), and going further with LFP (Olivier Winter, ~20 mins).