Skip to main content

Torch implementation of the NoRMCorre motion correction algorithm.

Project description

PyCorre

Fast, GPU-accelerated rigid and piecewise-rigid motion correction for calcium-imaging recordings. PyCorre implements the NoRMCorre algorithm, which is the same phase-correlation + upsampled-DFT method used by CaImAn, but rewritten in PyTorch. The whole stack is corrected in batched operations that run on CPU or GPU from a single, dependency-light codebase.

Installation

pip install pycorre

The only runtime dependencies are torch, numpy, and tqdm. GPU support is whatever your PyTorch build provides (install the appropriate CUDA wheel of torch for your machine).

Quickstart

import numpy as np
from pycorre import RigidMotionCorrection, PWRigidMotionCorrection

# A recording of shape (n_frames, height, width); numpy array or torch tensor.
frames = ...

# Rigid correction on the GPU.
model = RigidMotionCorrection(device="cuda")  # or "cpu" / "auto"
corrected = model.fit_transform(frames)

# Piecewise-rigid (non-rigid) correction.
model = PWRigidMotionCorrection(device="cuda", strides=(96, 96), overlaps=(32, 32))
corrected = model.fit_transform(frames)

The API follows scikit-learn's fit / transform / fit_transform pattern. fit estimates the template (unless you pass one) and finds the per-frame shifts; transform applies them. Inputs may be numpy arrays or torch tensors; numpy in and numpy out.

Performance

The table below shows the rigid correction throughput on a real recording with resolution 360x640 for 1800 frames.

method device fps vs PyCorre (GPU)
PyCorre (torch) GPU ~2,285 1.0x
jnormcorre (NoRMCorre in JAX) GPU ~762 3.0x slower
PyCorre (torch) CPU ~468 4.9x slower
jnormcorre CPU ~162 14x slower
CaImAn reference CPU ~103 22x slower

On this sample, PyCorre is ~22x faster than CaImAn and ~3x faster than jnormcorre. On CPU alone, with no GPU at all, PyCorre still leads, running ~4.5x faster than the CaImAn reference and ~2.9x faster than jnormcorre.

The scaling curve can be seen here:

Author

PyCorre is written and maintained by Ryan 'RyanIRL' Peters (@ryanirl).

Citation

If you use PyCorre in your research, please cite it:

@software{peters_pycorre,
  author = {Peters, Ryan},
  title  = {{PyCorre}: GPU-accelerated rigid and piecewise-rigid motion correction for calcium imaging},
  url    = {https://github.com/ryanirl/pycorre},
  year   = {2026}
}

PyCorre implements the NoRMCorre algorithm; if you use it, please also cite the original method:

Pnevmatikakis, E. A., & Giovannucci, A. (2017). NoRMCorre: An online algorithm for piecewise rigid motion correction of calcium imaging data. Journal of Neuroscience Methods, 291, 83-94. https://doi.org/10.1016/j.jneumeth.2017.07.031

License

pycorre is released under the MIT License (see LICENSE).

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

pycorre-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

pycorre-0.1.1-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file pycorre-0.1.1.tar.gz.

File metadata

  • Download URL: pycorre-0.1.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for pycorre-0.1.1.tar.gz
Algorithm Hash digest
SHA256 187719d4329c3fedecff2f94a00b3adc574233d2314e079e71fefb7e1df269cb
MD5 ed7aea03864cd3d1ab8029b03ab0e1aa
BLAKE2b-256 c6f0055a6743f6b025d0c174f7eedecb9d5d9af91f1a74e260f9b238f7d7633a

See more details on using hashes here.

File details

Details for the file pycorre-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pycorre-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for pycorre-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65085e9fe8425dbed820bb98db4b677b6d9b9c4e9451bc610dcf4decd8ca30e4
MD5 c258f6cb12551af995d8a14dde72208c
BLAKE2b-256 b449c09287a44b690fd74fde08db70e30e966f72d637e12575596aff70e7e76b

See more details on using hashes here.

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