Skip to main content

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

PyPI - Python Version PyPI - License PyPI - Version GitHub Actions Workflow Status

[!WARNING] This project is currently under construction and might contain bugs. If you experience any issues, please let us know!

Installation instructions:

  1. 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.

  1. Install Matlab Runtime 2024b
  2. Install SPM:
    pip install spm-python
    
  3. 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


Download files

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

Source Distribution

spm_python-25.1.2b1.tar.gz (81.8 MB view details)

Uploaded Source

Built Distributions

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

spm_python-25.1.2b1-py39.py310.py311.py312-none-any.whl (84.0 MB view details)

Uploaded Python 3.10Python 3.11Python 3.12Python 3.9

spm_python-25.1.2b1-py39.py310.py311-none-any.whl (84.0 MB view details)

Uploaded Python 3.10Python 3.11Python 3.9

spm_python-25.1.2b1-py38.py39.py310-none-any.whl (83.8 MB view details)

Uploaded Python 3.10Python 3.8Python 3.9

File details

Details for the file spm_python-25.1.2b1.tar.gz.

File metadata

  • Download URL: spm_python-25.1.2b1.tar.gz
  • Upload date:
  • Size: 81.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for spm_python-25.1.2b1.tar.gz
Algorithm Hash digest
SHA256 5c5dd8142ba48d80aefe762dd87e3a0c0befaa1ae92fc4fe60532fb03992805d
MD5 7966ffe134abd454145d23d8bef3e303
BLAKE2b-256 c20967907cf59d70bf0fa27ae1f90a16025764b590d7354374d3c24639395aa3

See more details on using hashes here.

File details

Details for the file spm_python-25.1.2b1-py39.py310.py311.py312-none-any.whl.

File metadata

File hashes

Hashes for spm_python-25.1.2b1-py39.py310.py311.py312-none-any.whl
Algorithm Hash digest
SHA256 1e65cbfb9f86e28bdef176d6caff1b164d8fa9c24b9c9e891672037e17117101
MD5 3c2817cd894e9a72e4ab14d55cbddf20
BLAKE2b-256 458306bcaa42cb8f7ea68e3d9796af8963726849f7e9a9773f33260fb438f42b

See more details on using hashes here.

File details

Details for the file spm_python-25.1.2b1-py39.py310.py311-none-any.whl.

File metadata

File hashes

Hashes for spm_python-25.1.2b1-py39.py310.py311-none-any.whl
Algorithm Hash digest
SHA256 751faeb588391000c381eda9585181773cce11abca81d127e8a9530ff7c08588
MD5 41a4939dd94e5c74862eca578e5d778d
BLAKE2b-256 e0b1935bce97aadfeef3fa973e5b69976197a64df546ecbc6444682e45982341

See more details on using hashes here.

File details

Details for the file spm_python-25.1.2b1-py38.py39.py310-none-any.whl.

File metadata

File hashes

Hashes for spm_python-25.1.2b1-py38.py39.py310-none-any.whl
Algorithm Hash digest
SHA256 3e6c0a9a1f5ec2958f65c89842dcbf6cf64a64df1e2089b491443489da2e95ed
MD5 e8b0817e9ea8f42eb10d7ac67ac96489
BLAKE2b-256 f63c5865763439fbb95f3586b1f0d5656c6aa6a0e6d28848d81e242ce019817a

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