Skip to content

Commit efcde09

Browse files
committed
[Enh] Generate code with __all__ and no private import
1 parent 077ce06 commit efcde09

4,024 files changed

Lines changed: 87879 additions & 96215 deletions

File tree

Some content is hidden

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

.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+
"""

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: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"metadata": {},
88
"outputs": [],
99
"source": [
10-
"from spm import * \n",
10+
"from spm import *\n",
1111
"\n",
1212
"import numpy as np\n",
1313
"import os.path as op"
@@ -38,15 +38,20 @@
3838
"metadata": {},
3939
"outputs": [],
4040
"source": [
41-
"data_path = op.join('data', 'attention')\n",
42-
"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",
4343
"if not op.isdir(data_path):\n",
4444
" if not op.isfile(zip_path):\n",
4545
" import wget\n",
46-
" 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",
4751
"\n",
4852
" import shutil\n",
49-
" shutil.unpack_archive(zip_path, 'data', 'zip')"
53+
"\n",
54+
" shutil.unpack_archive(zip_path, \"data\", \"zip\")"
5055
]
5156
},
5257
{
@@ -77,8 +82,8 @@
7782
}
7883
],
7984
"source": [
80-
"spm('Defaults','fMRI')\n",
81-
"spm_jobman('initcfg', nargout=0)"
85+
"spm(\"Defaults\", \"fMRI\")\n",
86+
"spm_jobman(\"initcfg\", nargout=0)"
8287
]
8388
},
8489
{
@@ -106,7 +111,7 @@
106111
"metadata": {},
107112
"outputs": [],
108113
"source": [
109-
"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\"]"
110115
]
111116
},
112117
{
@@ -116,11 +121,11 @@
116121
"metadata": {},
117122
"outputs": [],
118123
"source": [
119-
"DCM = Struct() \n",
124+
"DCM = Struct()\n",
120125
"\n",
121-
"xY1 = Runtime.call('load', op.join(data_path,'GLM','VOI_V1_1.mat'))['xY']\n",
122-
"xY2 = Runtime.call('load', op.join(data_path,'GLM','VOI_V5_1.mat'))['xY']\n",
123-
"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",
124129
"\n",
125130
"DCM.xY = StructArray(xY1, xY2, xY3)"
126131
]
@@ -132,8 +137,8 @@
132137
"metadata": {},
133138
"outputs": [],
134139
"source": [
135-
"DCM.n = 3 \n",
136-
"DCM.v = xY1['u'].shape[0]; "
140+
"DCM.n = 3\n",
141+
"DCM.v = xY1[\"u\"].shape[0]"
137142
]
138143
},
139144
{
@@ -163,13 +168,13 @@
163168
"outputs": [],
164169
"source": [
165170
"DCM.Y = Struct()\n",
166-
"DCM.Y.dt = SPM.xY.RT\n",
167-
"DCM.Y.X0 = xY1.X0\n",
171+
"DCM.Y.dt = SPM.xY.RT\n",
172+
"DCM.Y.X0 = xY1.X0\n",
168173
"\n",
169174
"DCM.Y.y = np.concatenate([xY.u for xY in (xY1, xY2, xY3)], axis=1)\n",
170-
"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",
171176
"\n",
172-
"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)"
173178
]
174179
},
175180
{
@@ -196,11 +201,9 @@
196201
"outputs": [],
197202
"source": [
198203
"DCM.U = Struct()\n",
199-
"DCM.U.dt = SPM.Sess.U[0].dt\n",
204+
"DCM.U.dt = SPM.Sess.U[0].dt\n",
200205
"DCM.U.name = [u.name for u in SPM.Sess.U]\n",
201-
"DCM.U.u = np.concatenate([\n",
202-
" u.u[32:] for u in SPM.Sess.U\n",
203-
" ], axis=1);"
206+
"DCM.U.u = np.concatenate([u.u[32:] for u in SPM.Sess.U], axis=1)"
204207
]
205208
},
206209
{
@@ -228,14 +231,14 @@
228231
"metadata": {},
229232
"outputs": [],
230233
"source": [
231-
"DCM.delays = np.repeat([[SPM['xY']['RT']/2]], DCM.n, 1)\n",
232-
"DCM.TE = 0.04\n",
234+
"DCM.delays = np.repeat([[SPM[\"xY\"][\"RT\"] / 2]], DCM.n, 1)\n",
235+
"DCM.TE = 0.04\n",
233236
"\n",
234237
"DCM.options = Struct()\n",
235-
"DCM.options.nonlinear = 0\n",
236-
"DCM.options.two_state = 0\n",
238+
"DCM.options.nonlinear = 0\n",
239+
"DCM.options.two_state = 0\n",
237240
"DCM.options.stochastic = 0\n",
238-
"DCM.options.nograph = 1;"
241+
"DCM.options.nograph = 1"
239242
]
240243
},
241244
{
@@ -263,11 +266,11 @@
263266
"outputs": [],
264267
"source": [
265268
"DCM.a = np.array([[1, 1, 0], [1, 1, 1], [0, 1, 1]])\n",
266-
"DCM.b = np.zeros((3,3,3)) \n",
267-
"DCM.b[1,0,1] = 1 \n",
268-
"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",
269272
"DCM.c = np.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]])\n",
270-
"DCM.d = np.zeros((3,3,0))\n",
273+
"DCM.d = np.zeros((3, 3, 0))\n",
271274
"\n",
272275
"DCMbwd = spm_dcm_estimate(DCM)"
273276
]
@@ -293,9 +296,9 @@
293296
"metadata": {},
294297
"outputs": [],
295298
"source": [
296-
"DCM.b = np.zeros((3,3,3)) \n",
297-
"DCM.b[1,0,1] = 1 \n",
298-
"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",
299302
"\n",
300303
"DCMfwd = spm_dcm_estimate(DCM)"
301304
]

0 commit comments

Comments
 (0)