Skip to content

Commit 412b519

Browse files
authored
Merge pull request #39 from spm/dev-external-wrapper
Moved wrapper, cleaner imports
2 parents 3bd7a55 + db2b5a4 commit 412b519

File tree

4,047 files changed

+102871
-96170
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,047 files changed

+102871
-96170
lines changed

.github/workflows/create-tag.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
workflow_dispatch:
55
workflow_call:
66
push:
7+
branches:
8+
- main
79
paths:
810
- pyproject.toml
911

.mpython/templates/class_header.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from <pkgname>.__wrapper__ import Runtime, MatlabClass
1+
from mpython import Runtime, MatlabClass
22

33

44
class <classname>(MatlabClass):

.mpython/templates/docstring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
[Matlab code]( https://github.com/spm/spm/blob/main/<rfilepath> )
55
66
Copyright (C) 1995-2025 Functional Imaging Laboratory, Department of Imaging Neuroscience, UCL
7-
"""
7+
"""

.mpython/templates/setup.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
repos:
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.11.2
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: [ --fix, --ignore=F811]
9+
# Run the formatter.
10+
- id: ruff-format
11+

examples/DCM_ERP.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,43 @@
66
you have to change 'Pbase' to your own analysis-directory, and choose a name ('DCM.xY.Dfile')
77
of an existing SPM for M/EEG-file with at least two evoked responses.
88
"""
9+
910
import os
1011
import spm
1112

1213
num = spm.Array.from_any
1314

1415
# Please replace filenames etc. by your own.
1516
# ----------------------------------------------------------------------
16-
spm.spm('defaults', 'EEG')
17+
spm.spm("defaults", "EEG")
1718

1819
# Data and analysis directories
1920
# ----------------------------------------------------------------------
2021

21-
Pbase = os.path.dirname(__file__) # directory with your data,
22+
Pbase = os.path.dirname(__file__) # directory with your data,
2223

23-
Pdata = os.path.join(Pbase, '.') # data directory in Pbase
24-
Panalysis = os.path.join(Pbase, '.') # analysis directory in Pbase
24+
Pdata = os.path.join(Pbase, ".") # data directory in Pbase
25+
Panalysis = os.path.join(Pbase, ".") # analysis directory in Pbase
2526

2627
os.chdir(Pbase)
2728

2829
# Data filename
2930
# ----------------------------------------------------------------------
3031
DCM = spm.Struct()
31-
DCM.xY.Dfile = 'maeMdfspm8_subject1'
32+
DCM.xY.Dfile = "maeMdfspm8_subject1"
3233

3334
# Parameters and options used for setting up model
3435
# ----------------------------------------------------------------------
35-
DCM.options.analysis = 'ERP' # analyze evoked responses
36-
DCM.options.model = 'ERP' # ERP model
37-
DCM.options.spatial = 'IMG' # spatial model
38-
DCM.options.trials = num([1, 2]) # index of ERPs within ERP/ERF file
39-
DCM.options.Tdcm[0] = 0 # start of peri-stimulus time to be modelled
40-
DCM.options.Tdcm[1] = 200 # end of peri-stimulus time to be modelled
41-
DCM.options.Nmodes = 8 # nr of modes for data selection
42-
DCM.options.h = 1 # nr of DCT components
43-
DCM.options.onset = 60 # selection of onset (prior mean)
44-
DCM.options.D = 1 # downsampling
36+
DCM.options.analysis = "ERP" # analyze evoked responses
37+
DCM.options.model = "ERP" # ERP model
38+
DCM.options.spatial = "IMG" # spatial model
39+
DCM.options.trials = num([1, 2]) # index of ERPs within ERP/ERF file
40+
DCM.options.Tdcm[0] = 0 # start of peri-stimulus time to be modelled
41+
DCM.options.Tdcm[1] = 200 # end of peri-stimulus time to be modelled
42+
DCM.options.Nmodes = 8 # nr of modes for data selection
43+
DCM.options.h = 1 # nr of DCT components
44+
DCM.options.onset = 60 # selection of onset (prior mean)
45+
DCM.options.D = 1 # downsampling
4546

4647
# ----------------------------------------------------------------------
4748
# Data and spatial model
@@ -51,14 +52,10 @@
5152
# ----------------------------------------------------------------------
5253
# Location priors for dipoles
5354
# ----------------------------------------------------------------------
54-
DCM.Lpos = num([
55-
[-42, -22, 7],
56-
[46, -14, 8],
57-
[-61, -32, 8],
58-
[59, -25, 8],
59-
[46, 20, 8]
60-
]).T
61-
DCM.Sname = ['left AI', 'right A1', 'left STG', 'right STG', 'right IFG']
55+
DCM.Lpos = num(
56+
[[-42, -22, 7], [46, -14, 8], [-61, -32, 8], [59, -25, 8], [46, 20, 8]]
57+
).T
58+
DCM.Sname = ["left AI", "right A1", "left STG", "right STG", "right IFG"]
6259
Nareas = DCM.Lpos.shape[1]
6360

6461
# ----------------------------------------------------------------------
@@ -98,11 +95,11 @@
9895
# Between trial effects
9996
# ----------------------------------------------------------------------
10097
DCM.xU.X = num([[0, 1]]).T
101-
DCM.xU.name = ['rare']
98+
DCM.xU.name = ["rare"]
10299

103100
# ----------------------------------------------------------------------
104101
# Invert
105102
# ----------------------------------------------------------------------
106-
DCM.name = 'DCMexample'
103+
DCM.name = "DCMexample"
107104

108105
DCM = spm.spm_dcm_erp(DCM)

examples/DCM_fMRI_Attention.ipynb

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
"metadata": {},
88
"outputs": [],
99
"source": [
10-
"from spm import * \n",
10+
"from spm import *\n",
1111
"\n",
1212
"import numpy as np\n",
13-
"import os.path as op\n",
14-
"import os \n",
15-
"import scipy.io as sio"
13+
"import os.path as op"
1614
]
1715
},
1816
{
@@ -40,15 +38,20 @@
4038
"metadata": {},
4139
"outputs": [],
4240
"source": [
43-
"data_path = op.join('data', 'attention')\n",
44-
"zip_path = op.join('data', 'attention.zip')\n",
41+
"data_path = op.join(\"data\", \"attention\")\n",
42+
"zip_path = op.join(\"data\", \"attention.zip\")\n",
4543
"if not op.isdir(data_path):\n",
4644
" if not op.isfile(zip_path):\n",
4745
" import wget\n",
48-
" wget.download('https://www.fil.ion.ucl.ac.uk/spm/download/data/attention/attention.zip', 'data')\n",
46+
"\n",
47+
" wget.download(\n",
48+
" \"https://www.fil.ion.ucl.ac.uk/spm/download/data/attention/attention.zip\",\n",
49+
" \"data\",\n",
50+
" )\n",
4951
"\n",
5052
" import shutil\n",
51-
" shutil.unpack_archive(zip_path, 'data', 'zip')"
53+
"\n",
54+
" shutil.unpack_archive(zip_path, \"data\", \"zip\")"
5255
]
5356
},
5457
{
@@ -79,8 +82,8 @@
7982
}
8083
],
8184
"source": [
82-
"spm('Defaults','fMRI')\n",
83-
"spm_jobman('initcfg', nargout=0)"
85+
"spm(\"Defaults\", \"fMRI\")\n",
86+
"spm_jobman(\"initcfg\", nargout=0)"
8487
]
8588
},
8689
{
@@ -108,7 +111,7 @@
108111
"metadata": {},
109112
"outputs": [],
110113
"source": [
111-
"SPM = Runtime.call('load', op.join(data_path, 'GLM', 'SPM.mat'))['SPM']"
114+
"SPM = Runtime.call(\"load\", op.join(data_path, \"GLM\", \"SPM.mat\"))[\"SPM\"]"
112115
]
113116
},
114117
{
@@ -118,11 +121,11 @@
118121
"metadata": {},
119122
"outputs": [],
120123
"source": [
121-
"DCM = Struct() \n",
124+
"DCM = Struct()\n",
122125
"\n",
123-
"xY1 = Runtime.call('load', op.join(data_path,'GLM','VOI_V1_1.mat'))['xY'];\n",
124-
"xY2 = Runtime.call('load', op.join(data_path,'GLM','VOI_V5_1.mat'))['xY'];\n",
125-
"xY3 = Runtime.call('load', op.join(data_path,'GLM','VOI_SPC_1.mat'))['xY'];\n",
126+
"xY1 = Runtime.call(\"load\", op.join(data_path, \"GLM\", \"VOI_V1_1.mat\"))[\"xY\"]\n",
127+
"xY2 = Runtime.call(\"load\", op.join(data_path, \"GLM\", \"VOI_V5_1.mat\"))[\"xY\"]\n",
128+
"xY3 = Runtime.call(\"load\", op.join(data_path, \"GLM\", \"VOI_SPC_1.mat\"))[\"xY\"]\n",
126129
"\n",
127130
"DCM.xY = StructArray(xY1, xY2, xY3)"
128131
]
@@ -134,8 +137,8 @@
134137
"metadata": {},
135138
"outputs": [],
136139
"source": [
137-
"DCM.n = 3; \n",
138-
"DCM.v = xY1['u'].shape[0]; "
140+
"DCM.n = 3\n",
141+
"DCM.v = xY1[\"u\"].shape[0]"
139142
]
140143
},
141144
{
@@ -165,13 +168,13 @@
165168
"outputs": [],
166169
"source": [
167170
"DCM.Y = Struct()\n",
168-
"DCM.Y.dt = SPM.xY.RT;\n",
169-
"DCM.Y.X0 = xY1.X0;\n",
171+
"DCM.Y.dt = SPM.xY.RT\n",
172+
"DCM.Y.X0 = xY1.X0\n",
170173
"\n",
171174
"DCM.Y.y = np.concatenate([xY.u for xY in (xY1, xY2, xY3)], axis=1)\n",
172-
"DCM.Y.name = [xY.name for xY in (xY1, xY2, xY3)]\n",
175+
"DCM.Y.name = [xY.name for xY in (xY1, xY2, xY3)]\n",
173176
"\n",
174-
"DCM.Y.Q = spm_Ce(np.ones((1,DCM.n))*DCM.v);"
177+
"DCM.Y.Q = spm_Ce(np.ones((1, DCM.n)) * DCM.v)"
175178
]
176179
},
177180
{
@@ -198,11 +201,9 @@
198201
"outputs": [],
199202
"source": [
200203
"DCM.U = Struct()\n",
201-
"DCM.U.dt = SPM.Sess.U[0].dt;\n",
202-
"DCM.U.name = [u.name for u in SPM.Sess.U];\n",
203-
"DCM.U.u = np.concatenate([\n",
204-
" u.u[32:] for u in SPM.Sess.U\n",
205-
" ], axis=1);"
204+
"DCM.U.dt = SPM.Sess.U[0].dt\n",
205+
"DCM.U.name = [u.name for u in SPM.Sess.U]\n",
206+
"DCM.U.u = np.concatenate([u.u[32:] for u in SPM.Sess.U], axis=1)"
206207
]
207208
},
208209
{
@@ -230,14 +231,14 @@
230231
"metadata": {},
231232
"outputs": [],
232233
"source": [
233-
"DCM.delays = np.repeat([[SPM['xY']['RT']/2]], DCM.n, 1);\n",
234-
"DCM.TE = 0.04;\n",
234+
"DCM.delays = np.repeat([[SPM[\"xY\"][\"RT\"] / 2]], DCM.n, 1)\n",
235+
"DCM.TE = 0.04\n",
235236
"\n",
236237
"DCM.options = Struct()\n",
237-
"DCM.options.nonlinear = 0;\n",
238-
"DCM.options.two_state = 0;\n",
239-
"DCM.options.stochastic = 0;\n",
240-
"DCM.options.nograph = 1;"
238+
"DCM.options.nonlinear = 0\n",
239+
"DCM.options.two_state = 0\n",
240+
"DCM.options.stochastic = 0\n",
241+
"DCM.options.nograph = 1"
241242
]
242243
},
243244
{
@@ -265,11 +266,11 @@
265266
"outputs": [],
266267
"source": [
267268
"DCM.a = np.array([[1, 1, 0], [1, 1, 1], [0, 1, 1]])\n",
268-
"DCM.b = np.zeros((3,3,3)); \n",
269-
"DCM.b[1,0,1] = 1; \n",
270-
"DCM.b[1,2,2] = 1;\n",
269+
"DCM.b = np.zeros((3, 3, 3))\n",
270+
"DCM.b[1, 0, 1] = 1\n",
271+
"DCM.b[1, 2, 2] = 1\n",
271272
"DCM.c = np.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])\n",
272-
"DCM.d = np.zeros((3,3,0));\n",
273+
"DCM.d = np.zeros((3, 3, 0))\n",
273274
"\n",
274275
"DCMbwd = spm_dcm_estimate(DCM)"
275276
]
@@ -295,9 +296,9 @@
295296
"metadata": {},
296297
"outputs": [],
297298
"source": [
298-
"DCM.b = np.zeros((3,3,3)); \n",
299-
"DCM.b[1,0,1] = 1; \n",
300-
"DCM.b[1,0,2] = 1;\n",
299+
"DCM.b = np.zeros((3, 3, 3))\n",
300+
"DCM.b[1, 0, 1] = 1\n",
301+
"DCM.b[1, 0, 2] = 1\n",
301302
"\n",
302303
"DCMfwd = spm_dcm_estimate(DCM)"
303304
]

0 commit comments

Comments
 (0)