Python bindings for the SPM software.
Project description
___ ____ __ __
/ __)( _ \( \/ )
\__ \ )___/ ) ( Statistical Parametric Mapping
(___/(__) (_/\/\_) SPM - https://www.fil.ion.ucl.ac.uk/spm/
Copyright (C) 1991,1994-2025 Wellcome Centre for Human Neuroimaging
The Python interface to SPM
[!WARNING] This project is currently under construction and might contain bugs. If you experience any issues, please let us know!
Installation instructions:
- Install Python and Pip. Python installation made from Microsoft Store on Windows will not work (raises DeclarativeService.dll not found), install it from Python website.
[!WARNING] spm-python currently requires Python 3.12.
- Install Matlab Runtime 2024b
- Install SPM:
pip install spm-python
- That's all!
Minimal example
Here is a minimal set of examples showcasing changes to do to use existing Matlab code in Python (taken from the OPM tutorial).
1. Importing and setting up SPM
In Matlab:
spm('defaults', 'eeg');
In Python:
from spm import *
spm('defaults', 'eeg')
2. Constructing objects
In Matlab:
S = [];
S.data = 'OPM_meg_001.cMEG';
S.positions = 'OPM_HelmConfig.tsv';
D = spm_opm_create(S);
In Python, create a Struct() instead of a struct:
S = Struct()
S.data='OPM_meg_001.cMEG'
S.positions='OPM_HelmConfig.tsv'
D = spm_opm_create(S)
Here, D will be a meeg object which contains a virtual representation of the Matlab object. Class methods should work as expected, e.g.:
D.fullfile()
>>> './OPM_meg_001.mat'
Note that the alternative call that exist in Matlab (i.e., fullfile(D)) will not work.
3. Creating and handling figures
In Matlab:
S = [];
S.triallength = 3000;
S.plot = 1;
S.D = D;
S.channels = 'MEG';
spm_opm_psd(S);
ylim([1,1e5])
In Python:
S = Struct()
S.triallength = 3000
S.plot = 1
S.D = D
S.channels = 'MEG'
spm_opm_psd(S)
This opens a Matlab figure, but we do not have the possibility of manipulating it yet (e.g., calling ylim). As of now, we can view the figures, have GUI interactions, but cannot manipulate figures with Python code.
4. Variable number of output arguments
In Matlab:
S = [];
S.triallength = 3000;
S.plot = 1;
S.D = mD;
[~,freq] = spm_opm_psd(S);
In Python, the number of output arguments must be specified by the nargout keyword argument:
S = Struct()
S.triallength = 3000
S.plot=1
S.D=mD
[_,freq] = spm_opm_psd(S, nargout=2)
5. Other examples
In Matlab:
S=[];
S.D=D;
S.freq=[10];
S.band = 'high';
fD = spm_eeg_ffilter(S);
S = [];
S.D = fD;
S.freq = [70];
S.band = 'low';
fD = spm_eeg_ffilter(S);
In Python:
S = Struct()
S.D = D
S.freq = 10
S.band = 'high'
fD = spm_eeg_ffilter(S)
S = Struct()
S.D = fD
S.freq = 70
S.band = 'low'
fD = spm_eeg_ffilter(S)
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 spm_python-25.1b1.post1.tar.gz.
File metadata
- Download URL: spm_python-25.1b1.post1.tar.gz
- Upload date:
- Size: 82.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b75a77b33258f296e2a2562045084d0bff4ffe12d9299f20c74df714f5af954f
|
|
| MD5 |
55f9ae7c87763b54ac0a4f80dd009f64
|
|
| BLAKE2b-256 |
b3abaa2200d27d8ec5ac035a2fac75c6e52ce977ba1c420aff01bf4d851e955c
|
File details
Details for the file spm_python-25.1b1.post1-py3-none-any.whl.
File metadata
- Download URL: spm_python-25.1b1.post1-py3-none-any.whl
- Upload date:
- Size: 84.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c9b879d84859490e333d2acbf68800c9daadf335fe333c78ffd4e7f354608ba
|
|
| MD5 |
8a2fc7b95d0a3285e61a66b23a2cbc81
|
|
| BLAKE2b-256 |
a84f85c782b8e32e117ff4acbfbfa468ac3f7ef9cdccc76d3548d1e5e115c006
|