Sparse hemodynamic deconvolution of fMRI data with scikit-learn compatible estimators.
Project description
pySPFM
A Python package for sparse hemodynamic deconvolution of fMRI data with scikit-learn compatible estimators.
pySPFM provides estimators for Paradigm Free Mapping (PFM) and related sparse deconvolution methods for fMRI analysis. The package follows scikit-learn conventions, making it easy to integrate with existing machine learning pipelines.
Features
- scikit-learn compatible API: Use familiar
fit(),transform(),fit_transform()methods - Multiple deconvolution methods:
SparseDeconvolution: Sparse Paradigm Free Mapping (SPFM) using LARS or FISTALowRankPlusSparse: SPLORA algorithm separating global and neuronal signalsStabilitySelection: Robust feature selection via bootstrap resampling
- Multi-echo fMRI support: Native support for multi-echo acquisitions
- Flexible regularization: Multiple lambda selection criteria (BIC, AIC, MAD, etc.)
- Command-line interface: Easy-to-use CLI for batch processing
Installation
pip install pySPFM
For development:
git clone https://github.com/Paradigm-Free-Mapping/pySPFM.git
cd pySPFM
pip install -e ".[dev,tests]"
Quick Start
Python API
from pySPFM import SparseDeconvolution
import numpy as np
# Load your fMRI data (n_timepoints, n_voxels)
X = np.random.randn(200, 1000) # Example data
# Create and fit the model
model = SparseDeconvolution(tr=2.0, criterion='bic')
model.fit(X)
# Get the deconvolved activity-inducing signals
activity = model.coef_
# Get the fitted (reconstructed) signal
fitted = model.get_fitted_signal()
# Compute explained variance
score = model.score(X)
print(f"Explained variance: {score:.2%}")
Low-Rank + Sparse Decomposition (SPLORA)
from pySPFM import LowRankPlusSparse
model = LowRankPlusSparse(tr=2.0, eigval_threshold=0.1)
model.fit(X)
# Separate components
sparse_activity = model.coef_ # Neuronal activity
global_signal = model.low_rank_ # Global/structured component
Command-Line Interface
# Sparse deconvolution
pySPFM sparse -i data.nii.gz -m mask.nii.gz -o output --tr 2.0
# Low-rank + sparse decomposition
pySPFM lowrank -i data.nii.gz -m mask.nii.gz -o output --tr 2.0
# Stability selection
pySPFM stability -i data.nii.gz -m mask.nii.gz -o output --tr 2.0 --n-surrogates 50
Estimators
| Estimator | Description | Use Case |
|---|---|---|
SparseDeconvolution |
Sparse PFM using LARS/FISTA | General deconvolution |
LowRankPlusSparse |
SPLORA algorithm | Separating global signals |
StabilitySelection |
Bootstrap-based selection | Robust feature detection |
API Reference
All estimators follow scikit-learn conventions:
fit(X): Fit the model to datatransform(X): Return deconvolved signalsfit_transform(X): Fit and transform in one stepscore(X): Return explained variance ratioget_params()/set_params(): Parameter accessclone(): Create unfitted copy
Development
This project uses uv for dependency management and tox for testing.
Running tests
# Current Python version
pytest pySPFM/tests/
# All supported versions (3.10, 3.11, 3.12)
tox
# Specific version
tox -e py310
References
- Caballero-Gaudes, C., Moia, S., Panwar, P., Bandettini, P. A., & Gonzalez-Castillo, J. (2019). A deconvolution algorithm for multi-echo functional MRI: Multi-echo Sparse Paradigm Free Mapping. NeuroImage, 202, 116081–116081. https://doi.org/10.1016/j.neuroimage.2019.116081
- Caballero Gaudes, C., Petridou, N., Francis, S. T., Dryden, I. L., & Gowland, P. A. (2013). Paradigm free mapping with sparse regression automatically detects single-trial functional magnetic resonance imaging blood oxygenation level dependent responses. Human Brain Mapping. https://doi.org/10.1002/hbm.21452
- Karahanoǧlu, F. I., Caballero-Gaudes, C., Lazeyras, F., & Van De Ville, D. (2013). Total activation: FMRI deconvolution through spatio-temporal regularization. NeuroImage. https://doi.org/10.1016/j.neuroimage.2013.01.067
- Uruñuela, E., Bolton, T. A., Van De Ville, D., & Caballero-Gaudes, C. (2023). Hemodynamic Deconvolution Demystified: Sparsity-Driven Regularization at Work. Aperture Neuro, 3, 1-25. https://doi.org/10.52294/001c.87574
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyspfm-2.0.2.tar.gz.
File metadata
- Download URL: pyspfm-2.0.2.tar.gz
- Upload date:
- Size: 6.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0f2c7c3fd3c7f6e0f2514ec950b1667f1dbb3b291219333d9f40dd93cdaabd
|
|
| MD5 |
49d760a64f543659a78ed88e6d8ac493
|
|
| BLAKE2b-256 |
cb5743fe8c178e5a13aabb3055e6bed9af04c4e851142d1761e489f6e934e37c
|
Provenance
The following attestation bundles were made for pyspfm-2.0.2.tar.gz:
Publisher:
python-publish.yml on Paradigm-Free-Mapping/pySPFM
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspfm-2.0.2.tar.gz -
Subject digest:
1d0f2c7c3fd3c7f6e0f2514ec950b1667f1dbb3b291219333d9f40dd93cdaabd - Sigstore transparency entry: 825054811
- Sigstore integration time:
-
Permalink:
Paradigm-Free-Mapping/pySPFM@03950c153093290693f9411d8675ff35026c881e -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/Paradigm-Free-Mapping
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@03950c153093290693f9411d8675ff35026c881e -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyspfm-2.0.2-py3-none-any.whl.
File metadata
- Download URL: pyspfm-2.0.2-py3-none-any.whl
- Upload date:
- Size: 102.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10a82f073783b0c13e7c61f078fdfa278bfb0e79746abe120e1d7a1b97000505
|
|
| MD5 |
4b9fb67abd602440e2b23c0074d78229
|
|
| BLAKE2b-256 |
3b89a9e67c07f75477785be1b7aa4fcf68b04ab3dda967b64d0991d2c3561045
|
Provenance
The following attestation bundles were made for pyspfm-2.0.2-py3-none-any.whl:
Publisher:
python-publish.yml on Paradigm-Free-Mapping/pySPFM
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspfm-2.0.2-py3-none-any.whl -
Subject digest:
10a82f073783b0c13e7c61f078fdfa278bfb0e79746abe120e1d7a1b97000505 - Sigstore transparency entry: 825054875
- Sigstore integration time:
-
Permalink:
Paradigm-Free-Mapping/pySPFM@03950c153093290693f9411d8675ff35026c881e -
Branch / Tag:
refs/tags/v2.0.2 - Owner: https://github.com/Paradigm-Free-Mapping
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@03950c153093290693f9411d8675ff35026c881e -
Trigger Event:
release
-
Statement type: