Skip to main content

DREDge: Decentralized Registration for Electrophysiology Data (... ge)

Project description

Published in Nature Methods: https://www.nature.com/articles/s41592-025-02614-5

Free PDF link: https://rdcu.be/ecqZf

DREDge: Decentralized Registration of Electrophysiology Data

DREDge is an algorithm for estimating the relative motion of a high-density microelectode array (e.g., Neuropixels) relative to the brain tissue. DREDge can estimate this motion both from local field potentials and from spike data, and the motion estimate can be rigid (i.e., the motion does not change along the probe) or nonrigid (different channels on the probe may undergo different motion).

:point_right: We now recommend using SpikeInterface to run DREDge (both the AP and LFP methods) and integrate it with downstream interpolation and spike sorting pipelines. SpikeInterface's correct_motion() function implements DREDge under the presets "dredge", "dredge_fast", as well as older versions of DREDge under the name "decentralized" (the presets "nonrigid_accurate", "nonrigid_fast_and_accurate", and "rigid_fast"). For information, see the tutorial pages:

and the module documentation:

This repo contains our original implementation of DREDge as well as some extra utility functions. For most users, SpikeInterface would make more sense, but this code is still maintained and you can feel free to open issues here with questions.

Check out our preprint for more details and experiments! https://www.biorxiv.org/content/10.1101/2023.10.24.563768v1

Questions? Issues?

We want to make this tool as easy to use as it can be. Feel free to open an issue here or email ciw2107@columbia.edu if you have questions or get stuck.

Python instructions

Introduction

This library contains Python code for motion estimation and correction for high density LFP and spiking data. Demo notebooks are available to see how to use this code on your data:

Requirements

Since DREDge is written in Python and PyTorch, it runs on Python versions after 3.8 and any system supported by PyTorch, including most recent Linux, Mac, and Windows versions. PyTorch supports both CPU and GPU-based workflows, and we suggest using the GPU version if you have a compatible graphics card (e.g., NVIDIA) since this can be much faster. See https://pytorch.org for supported operating systems. DREDge has been tested on Linux (Ubuntu 20.04) and recent MacOS; collaborators have tested it on Windows as well.

The suggested setup below should take 5-10 minutes on a typical computer and internet connection when installing everything including Python from scratch in a new mamba environment.

Installation with Conda (or Mamba) (recommended)

Setting up your conda environment

If you are new to conda, we recommend using mamba's Mambaforge distribution to install Python and DREDge. These tools manage GPU runtime dependencies in addition to python dependencies in an easy way, so that you won't have to deal with installing the CUDA runtime yourself. Install instructions are at that link -- look for an installation script under the heading Mambaforge for your platform.

Conda/mamba lets us have multiple Python environments on our system so that package versions don't conflict across your different projects. Here's how to set up an example environment that will support everything DREDge needs. If you used conda instead of mamba, replace mamba with conda in the instructions below.

# make the environment (feel free to use another name or install into your environment of choice)
# and, of course, feel free to add other packages that you like to use here!
# note, I'm adding some of the spikeinterface dependencies here so that mamba manages them
$ mamba create -n dredge python=3.11 numpy scipy h5py tqdm jupyterlab seaborn numba scikit-learn

# activate this environment!
$ mamba activate dredge
# now, you should see (dredge) in your terminal prompt

Get our code

(dredge) $ git clone git@github.com:evarol/dredge.git # (or https://github.com/evarol/dredge.git)
(dredge) $ cd dredge /

Install PyTorch

Go to pytorch.org and follow the installation instructions there under the Conda tab for your platform. [!!!] if you are using mamba rather than conda, be sure to replace conda with mamba in the commands given by pytorch.org's instructions!

Install pip dependencies and DREDge

Note, this step installs spikeinterface.

# make sure we're in the right folder:
(dredge) $ pwd
# => .../dredge/
(dredge) $ pip install -r requirements.txt
(dredge) $ pip install .

Installation with pip

If you prefer to avoid conda/mamba and you already have Python installed, you can clone the repo and run the last two commands above to install DREDge. We'd recommend first following the install instructions at https://pytorch.org under the pip heading to install a GPU version of PyTorch. Since Jupyter is not listed in requirements.txt, you can also pip install jupyterlab if you'd like to view our demo notebooks.

Trying out the demos

After installing as above, you can open Jupyter Lab and checkout the demo notebooks:

# make sure we're in the right folder:
(reglib) $ pwd
# => .../dredge/
(reglib) $ jupyter lab

This should open your browser. Use the file explorer on the left to navigate to notebook/ap_registration.ipynb

Related information

We're also porting an updated AP version and the LFP version of this code into spikeinterface. We'll update this README accordingly, as SpikeInterface will eventually be the recommended way to use DREDge for most users.

Code structure in python/dredge/

  • dredgelib.py
    • Library code (cross-correlations and linear algebra to solve batch and online centralization problems)
  • motion_util.py
    • MotionEstimate objects. The function get_motion_estimate takes the matrix of displacement vectors and the corresponding time and spatial bin edges or centers, and returns a RigidMotionEstimate or NonrigidMotionEstimate. These classes implement disp_at_s() and correct_s which take in times and depths and return the corresponding estimated displacements or motion-corrected positions
    • spike_raster, which takes spike times, depths, and amplitudes, and returns a 2d raster map
    • Binning and window helpers
    • Plotting helpers (e.g., show_spike_raster, plot_me_traces, ...)
  • dredge_ap: register() function registers spike data
  • dredge_lfp: register_online_lfp() function implements online algorithm for LFP data

Matlab instructions

To run

  1. Download demo files from dropbox link (too big for github) : a. https://www.dropbox.com/s/jfr450rpjf6bew5/Pt03.h5?dl=0 b. https://www.dropbox.com/s/uf5j75jqkyisesh/Pt02_2.h5?dl=0
  2. Put file in same directory as all this code.
  3. Run main.m

Example results from 2 human neuropixels recordings from Paulk et al. (https://www.biorxiv.org/content/10.1101/2021.06.20.449152v2)

Dataset1

Dataset2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dredge_ephys-0.3.0.tar.gz (44.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dredge_ephys-0.3.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file dredge_ephys-0.3.0.tar.gz.

File metadata

  • Download URL: dredge_ephys-0.3.0.tar.gz
  • Upload date:
  • Size: 44.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dredge_ephys-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0e1aab6ad798f44b29465a1d18a481f6cfe7dca1fc2f81fe0421c1a518254c7d
MD5 b215146e197e4343a7a364533f462f39
BLAKE2b-256 63f7886c8836edceb66f0f9e260d691cfb0e01e8ba8176cb718660d098a88ec2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dredge_ephys-0.3.0.tar.gz:

Publisher: deploy.yml on cwindolf/dredge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dredge_ephys-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: dredge_ephys-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dredge_ephys-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 850c76a59f38b89a079814b366a0ff9883e48e4a4ef82430a50ed5909eaf2496
MD5 3ea5ad2ce297f09255a6e46723f35382
BLAKE2b-256 6d876d38bb872eee148e62fdc91da13da20f18a9fc52be3cb34677fa4d9c72a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for dredge_ephys-0.3.0-py3-none-any.whl:

Publisher: deploy.yml on cwindolf/dredge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page