Note
Go to the end to download the full example code or to run this example in your browser via Binder.
Single-subject data (two runs) in native space¶
The example shows the analysis of an SPM dataset, with two conditions: viewing a face image or a scrambled face image.
This example takes a lot of time because the input are lists of 3D images sampled in different positions (encoded by different affine functions).
See also
For more information see the dataset description.
Fetch and inspect the data¶
Fetch the SPM multimodal_faces data.
from nilearn.datasets import fetch_spm_multimodal_fmri
subject_data = fetch_spm_multimodal_fmri()
[fetch_spm_multimodal_fmri] Dataset created in
/home/runner/nilearn_data/spm_multimodal_fmri
[fetch_spm_multimodal_fmri] Missing 390 functional scans for session 1.
[fetch_spm_multimodal_fmri] Data absent, downloading...
[fetch_spm_multimodal_fmri] Downloading data from
https://www.fil.ion.ucl.ac.uk/spm/download/data/mmfaces/multimodal_fmri.zip ...
[fetch_spm_multimodal_fmri] Downloaded 3571712 of 134263085 bytes (2.7%%,
39.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 6135808 of 134263085 bytes (4.6%%,
43.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 8134656 of 134263085 bytes (6.1%%,
47.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 9388032 of 134263085 bytes (7.0%%,
54.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 10043392 of 134263085 bytes (7.5%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 10436608 of 134263085 bytes (7.8%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 10821632 of 134263085 bytes (8.1%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 11173888 of 134263085 bytes (8.3%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 11509760 of 134263085 bytes (8.6%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 11796480 of 134263085 bytes (8.8%%,
1.8min remaining)
[fetch_spm_multimodal_fmri] Downloaded 12173312 of 134263085 bytes (9.1%%,
1.9min remaining)
[fetch_spm_multimodal_fmri] Downloaded 12541952 of 134263085 bytes (9.3%%,
2.0min remaining)
[fetch_spm_multimodal_fmri] Downloaded 12967936 of 134263085 bytes (9.7%%,
2.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 13467648 of 134263085 bytes (10.0%%,
2.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 14057472 of 134263085 bytes (10.5%%,
2.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 14761984 of 134263085 bytes (11.0%%,
2.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 15564800 of 134263085 bytes (11.6%%,
2.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 16474112 of 134263085 bytes (12.3%%,
2.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 17489920 of 134263085 bytes (13.0%%,
2.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 18743296 of 134263085 bytes (14.0%%,
2.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 20561920 of 134263085 bytes (15.3%%,
2.0min remaining)
[fetch_spm_multimodal_fmri] Downloaded 22994944 of 134263085 bytes (17.1%%,
1.8min remaining)
[fetch_spm_multimodal_fmri] Downloaded 24862720 of 134263085 bytes (18.5%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 26238976 of 134263085 bytes (19.5%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 27607040 of 134263085 bytes (20.6%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 29065216 of 134263085 bytes (21.6%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 30294016 of 134263085 bytes (22.6%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 31612928 of 134263085 bytes (23.5%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 32677888 of 134263085 bytes (24.3%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 33742848 of 134263085 bytes (25.1%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 34578432 of 134263085 bytes (25.8%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 35373056 of 134263085 bytes (26.3%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 36151296 of 134263085 bytes (26.9%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 36814848 of 134263085 bytes (27.4%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 37494784 of 134263085 bytes (27.9%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 37928960 of 134263085 bytes (28.2%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 38445056 of 134263085 bytes (28.6%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 38797312 of 134263085 bytes (28.9%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 39174144 of 134263085 bytes (29.2%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 39575552 of 134263085 bytes (29.5%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 40017920 of 134263085 bytes (29.8%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 40443904 of 134263085 bytes (30.1%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 40820736 of 134263085 bytes (30.4%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 41123840 of 134263085 bytes (30.6%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 41517056 of 134263085 bytes (30.9%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 41934848 of 134263085 bytes (31.2%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 42229760 of 134263085 bytes (31.5%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 42631168 of 134263085 bytes (31.8%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 43130880 of 134263085 bytes (32.1%%,
1.8min remaining)
[fetch_spm_multimodal_fmri] Downloaded 43704320 of 134263085 bytes (32.6%%,
1.8min remaining)
[fetch_spm_multimodal_fmri] Downloaded 44400640 of 134263085 bytes (33.1%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 45219840 of 134263085 bytes (33.7%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 46178304 of 134263085 bytes (34.4%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 47570944 of 134263085 bytes (35.4%%,
1.7min remaining)
[fetch_spm_multimodal_fmri] Downloaded 49594368 of 134263085 bytes (36.9%%,
1.6min remaining)
[fetch_spm_multimodal_fmri] Downloaded 51527680 of 134263085 bytes (38.4%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 53338112 of 134263085 bytes (39.7%%,
1.5min remaining)
[fetch_spm_multimodal_fmri] Downloaded 54722560 of 134263085 bytes (40.8%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 55828480 of 134263085 bytes (41.6%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 56885248 of 134263085 bytes (42.4%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 57860096 of 134263085 bytes (43.1%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 58753024 of 134263085 bytes (43.8%%,
1.4min remaining)
[fetch_spm_multimodal_fmri] Downloaded 59539456 of 134263085 bytes (44.3%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 60383232 of 134263085 bytes (45.0%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 60981248 of 134263085 bytes (45.4%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 61595648 of 134263085 bytes (45.9%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 62275584 of 134263085 bytes (46.4%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 63086592 of 134263085 bytes (47.0%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 63954944 of 134263085 bytes (47.6%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 64528384 of 134263085 bytes (48.1%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 64921600 of 134263085 bytes (48.4%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 65388544 of 134263085 bytes (48.7%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 65986560 of 134263085 bytes (49.1%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 66707456 of 134263085 bytes (49.7%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 67493888 of 134263085 bytes (50.3%%,
1.3min remaining)
[fetch_spm_multimodal_fmri] Downloaded 68386816 of 134263085 bytes (50.9%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 69328896 of 134263085 bytes (51.6%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 70221824 of 134263085 bytes (52.3%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 70893568 of 134263085 bytes (52.8%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 71483392 of 134263085 bytes (53.2%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 72146944 of 134263085 bytes (53.7%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 72925184 of 134263085 bytes (54.3%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 73793536 of 134263085 bytes (55.0%%,
1.2min remaining)
[fetch_spm_multimodal_fmri] Downloaded 74620928 of 134263085 bytes (55.6%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 75481088 of 134263085 bytes (56.2%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 76406784 of 134263085 bytes (56.9%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 77365248 of 134263085 bytes (57.6%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 78086144 of 134263085 bytes (58.2%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 78422016 of 134263085 bytes (58.4%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 78766080 of 134263085 bytes (58.7%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 79159296 of 134263085 bytes (59.0%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 79593472 of 134263085 bytes (59.3%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 80035840 of 134263085 bytes (59.6%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 80412672 of 134263085 bytes (59.9%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 80773120 of 134263085 bytes (60.2%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 81068032 of 134263085 bytes (60.4%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 81387520 of 134263085 bytes (60.6%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 81829888 of 134263085 bytes (60.9%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 82354176 of 134263085 bytes (61.3%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 82845696 of 134263085 bytes (61.7%%,
1.1min remaining)
[fetch_spm_multimodal_fmri] Downloaded 83410944 of 134263085 bytes (62.1%%,
1.0min remaining)
[fetch_spm_multimodal_fmri] Downloaded 84049920 of 134263085 bytes (62.6%%,
1.0min remaining)
[fetch_spm_multimodal_fmri] Downloaded 84795392 of 134263085 bytes (63.2%%,
1.0min remaining)
[fetch_spm_multimodal_fmri] Downloaded 85622784 of 134263085 bytes (63.8%%,
60.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 86425600 of 134263085 bytes (64.4%%,
59.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 87138304 of 134263085 bytes (64.9%%,
58.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 87818240 of 134263085 bytes (65.4%%,
57.5s remaining)
[fetch_spm_multimodal_fmri] Downloaded 88571904 of 134263085 bytes (66.0%%,
56.6s remaining)
[fetch_spm_multimodal_fmri] Downloaded 89423872 of 134263085 bytes (66.6%%,
55.5s remaining)
[fetch_spm_multimodal_fmri] Downloaded 90382336 of 134263085 bytes (67.3%%,
54.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 91136000 of 134263085 bytes (67.9%%,
53.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 91955200 of 134263085 bytes (68.5%%,
52.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 92495872 of 134263085 bytes (68.9%%,
51.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 92831744 of 134263085 bytes (69.1%%,
51.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 93102080 of 134263085 bytes (69.3%%,
51.6s remaining)
[fetch_spm_multimodal_fmri] Downloaded 93454336 of 134263085 bytes (69.6%%,
51.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 93863936 of 134263085 bytes (69.9%%,
51.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 94281728 of 134263085 bytes (70.2%%,
50.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 94781440 of 134263085 bytes (70.6%%,
50.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 95297536 of 134263085 bytes (71.0%%,
49.9s remaining)
[fetch_spm_multimodal_fmri] Downloaded 95780864 of 134263085 bytes (71.3%%,
49.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 96337920 of 134263085 bytes (71.8%%,
48.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 96952320 of 134263085 bytes (72.2%%,
48.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 97361920 of 134263085 bytes (72.5%%,
47.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 97828864 of 134263085 bytes (72.9%%,
47.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 98238464 of 134263085 bytes (73.2%%,
47.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 98738176 of 134263085 bytes (73.5%%,
46.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 99311616 of 134263085 bytes (74.0%%,
45.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 99975168 of 134263085 bytes (74.5%%,
45.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 100548608 of 134263085 bytes (74.9%%,
44.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 101138432 of 134263085 bytes (75.3%%,
43.6s remaining)
[fetch_spm_multimodal_fmri] Downloaded 101515264 of 134263085 bytes (75.6%%,
43.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 101761024 of 134263085 bytes (75.8%%,
43.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 102055936 of 134263085 bytes (76.0%%,
43.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 102416384 of 134263085 bytes (76.3%%,
42.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 102735872 of 134263085 bytes (76.5%%,
42.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 103006208 of 134263085 bytes (76.7%%,
42.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 103309312 of 134263085 bytes (76.9%%,
42.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 103677952 of 134263085 bytes (77.2%%,
41.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 104103936 of 134263085 bytes (77.5%%,
41.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 104562688 of 134263085 bytes (77.9%%,
40.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 105046016 of 134263085 bytes (78.2%%,
40.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 105611264 of 134263085 bytes (78.7%%,
39.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 105955328 of 134263085 bytes (78.9%%,
39.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 106135552 of 134263085 bytes (79.1%%,
39.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 106332160 of 134263085 bytes (79.2%%,
39.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 106520576 of 134263085 bytes (79.3%%,
38.9s remaining)
[fetch_spm_multimodal_fmri] Downloaded 106692608 of 134263085 bytes (79.5%%,
38.9s remaining)
[fetch_spm_multimodal_fmri] Downloaded 106946560 of 134263085 bytes (79.7%%,
38.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 107290624 of 134263085 bytes (79.9%%,
38.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 107732992 of 134263085 bytes (80.2%%,
37.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 108281856 of 134263085 bytes (80.6%%,
37.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 108920832 of 134263085 bytes (81.1%%,
36.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 109715456 of 134263085 bytes (81.7%%,
35.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 110804992 of 134263085 bytes (82.5%%,
33.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 112050176 of 134263085 bytes (83.5%%,
31.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 113426432 of 134263085 bytes (84.5%%,
29.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 114909184 of 134263085 bytes (85.6%%,
27.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 116178944 of 134263085 bytes (86.5%%,
25.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 117440512 of 134263085 bytes (87.5%%,
23.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 118800384 of 134263085 bytes (88.5%%,
21.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 119889920 of 134263085 bytes (89.3%%,
19.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 121061376 of 134263085 bytes (90.2%%,
18.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 121651200 of 134263085 bytes (90.6%%,
17.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 122159104 of 134263085 bytes (91.0%%,
16.6s remaining)
[fetch_spm_multimodal_fmri] Downloaded 122748928 of 134263085 bytes (91.4%%,
15.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 123469824 of 134263085 bytes (92.0%%,
14.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 124092416 of 134263085 bytes (92.4%%,
14.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 124813312 of 134263085 bytes (93.0%%,
13.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 125329408 of 134263085 bytes (93.3%%,
12.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 125779968 of 134263085 bytes (93.7%%,
11.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 126337024 of 134263085 bytes (94.1%%,
11.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 126828544 of 134263085 bytes (94.5%%,
10.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 127287296 of 134263085 bytes (94.8%%,
9.7s remaining)
[fetch_spm_multimodal_fmri] Downloaded 127696896 of 134263085 bytes (95.1%%,
9.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 128139264 of 134263085 bytes (95.4%%,
8.5s remaining)
[fetch_spm_multimodal_fmri] Downloaded 128655360 of 134263085 bytes (95.8%%,
7.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 129212416 of 134263085 bytes (96.2%%,
7.1s remaining)
[fetch_spm_multimodal_fmri] Downloaded 129695744 of 134263085 bytes (96.6%%,
6.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 130146304 of 134263085 bytes (96.9%%,
5.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 130539520 of 134263085 bytes (97.2%%,
5.2s remaining)
[fetch_spm_multimodal_fmri] Downloaded 130883584 of 134263085 bytes (97.5%%,
4.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 131244032 of 134263085 bytes (97.8%%,
4.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 131604480 of 134263085 bytes (98.0%%,
3.8s remaining)
[fetch_spm_multimodal_fmri] Downloaded 131956736 of 134263085 bytes (98.3%%,
3.3s remaining)
[fetch_spm_multimodal_fmri] Downloaded 132407296 of 134263085 bytes (98.6%%,
2.6s remaining)
[fetch_spm_multimodal_fmri] Downloaded 132833280 of 134263085 bytes (98.9%%,
2.0s remaining)
[fetch_spm_multimodal_fmri] Downloaded 133308416 of 134263085 bytes (99.3%%,
1.4s remaining)
[fetch_spm_multimodal_fmri] Downloaded 133849088 of 134263085 bytes (99.7%%,
0.6s remaining)
[fetch_spm_multimodal_fmri] ...done. (194 seconds, 3 min)
[fetch_spm_multimodal_fmri] Extracting data from
/home/runner/nilearn_data/spm_multimodal_fmri/sub001/multimodal_fmri.zip...
[fetch_spm_multimodal_fmri] .. done.
[fetch_spm_multimodal_fmri] Downloading data from
https://www.fil.ion.ucl.ac.uk/spm/download/data/mmfaces/multimodal_smri.zip ...
[fetch_spm_multimodal_fmri] Downloaded 3563520 of 6852766 bytes (52.0%%, 1.0s
remaining)
[fetch_spm_multimodal_fmri] ...done. (2 seconds, 0 min)
[fetch_spm_multimodal_fmri] Extracting data from
/home/runner/nilearn_data/spm_multimodal_fmri/sub001/multimodal_smri.zip...
[fetch_spm_multimodal_fmri] .. done.
Let’s inspect one of the event files before using them.
import pandas as pd
events = [subject_data.events1, subject_data.events2]
events_dataframe = pd.read_csv(events[0], sep="\t")
events_dataframe["trial_type"].value_counts()
trial_type
scrambled 86
faces 64
Name: count, dtype: int64
We can confirm there are only 2 conditions in the dataset.
from nilearn.plotting import plot_event, show
plot_event(events)
show()

Resample the images:
this is achieved by the concat_imgs function of Nilearn.
import warnings
from nilearn.image import concat_imgs, mean_img, resample_img
# Avoid getting too many warnings due to resampling
with warnings.catch_warnings():
warnings.simplefilter("ignore")
fmri_img = [
concat_imgs(subject_data.func1, auto_resample=True),
concat_imgs(subject_data.func2, auto_resample=True),
]
affine, shape = fmri_img[0].affine, fmri_img[0].shape
print("Resampling the second image (this takes time)...")
fmri_img[1] = resample_img(fmri_img[1], affine, shape[:3])
Resampling the second image (this takes time)...
Let’s create mean image for display purposes.
Fit the model¶
Fit the GLM for the 2 runs by specifying a FirstLevelModel and then fitting it.
# Sample at the beginning of each acquisition.
slice_time_ref = 0.0
# We use a discrete cosine transform to model signal drifts.
drift_model = "cosine"
# The cutoff for the drift model is 0.01 Hz.
high_pass = 0.01
# The hemodynamic response function
hrf_model = "spm + derivative"
from nilearn.glm.first_level import FirstLevelModel
print("Fitting a GLM")
fmri_glm = FirstLevelModel(
smoothing_fwhm=None,
t_r=subject_data.t_r,
hrf_model=hrf_model,
drift_model=drift_model,
high_pass=high_pass,
verbose=1,
)
fmri_glm = fmri_glm.fit(fmri_img, events=events)
Fitting a GLM
[FirstLevelModel.fit] Loading data from <nibabel.nifti1.Nifti1Image object at
0x7f30c6b15030>
[FirstLevelModel.fit] Computing mask
[FirstLevelModel.fit] Resampling mask
[FirstLevelModel.fit] Finished fit
[FirstLevelModel.fit] Computing run 1 out of 2 runs (go take a coffee, a big
one).
[FirstLevelModel.fit] Performing mask computation.
[FirstLevelModel.fit] Loading data from <nibabel.nifti1.Nifti1Image object at
0x7f30c6b15030>
[FirstLevelModel.fit] Extracting region signals
[FirstLevelModel.fit] Cleaning extracted signals
[FirstLevelModel.fit] Masking took 1 seconds.
[FirstLevelModel.fit] Performing GLM computation.
[FirstLevelModel.fit] GLM took 1 seconds.
[FirstLevelModel.fit] Computing run 2 out of 2 runs (3 seconds remaining).
[FirstLevelModel.fit] Performing mask computation.
[FirstLevelModel.fit] Loading data from <nibabel.nifti1.Nifti1Image object at
0x7f30a2ebe7a0>
[FirstLevelModel.fit] Extracting region signals
[FirstLevelModel.fit] Cleaning extracted signals
[FirstLevelModel.fit] Masking took 1 seconds.
[FirstLevelModel.fit] Performing GLM computation.
[FirstLevelModel.fit] GLM took 1 seconds.
[FirstLevelModel.fit] Computation of 2 runs done in 6 seconds.
View the results¶
Now we can compute contrast-related statistical maps (in z-scale), and plot them.
from nilearn.plotting import plot_stat_map
print("Computing contrasts")
Computing contrasts
We actually want more interesting contrasts. The simplest contrast just makes the difference between the two main conditions. We define the two opposite versions to run one-tailed t-tests.
contrasts = ["faces - scrambled", "scrambled - faces"]
Let’s store common parameters for all plots.
We plot the contrasts values overlaid on the mean fMRI image and we will use the z-score values as transparency, with any voxel with | Z-score | > 3 being fully opaque and any voxel with 0 < | Z-score | < 1.96 being partly transparent.
plot_param = {
"vmin": 0,
"display_mode": "z",
"cut_coords": 3,
"black_bg": True,
"bg_img": mean_image,
"cmap": "inferno",
"transparency_range": [0, 3],
}
# Iterate on contrasts to compute and plot them.
for contrast_id in contrasts:
print(f"\tcontrast id: {contrast_id}")
results = fmri_glm.compute_contrast(contrast_id, output_type="all")
plot_stat_map(
results["stat"],
title=contrast_id,
transparency=results["z_score"],
**plot_param,
)
contrast id: faces - scrambled
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:134: RuntimeWarning: The same contrast will be used for all 2 runs. If the design matrices are not the same for all runs, (for example with different column names or column order across runs) you should pass contrast as an expression using the name of the conditions as they appear in the design matrices.
results = fmri_glm.compute_contrast(contrast_id, output_type="all")
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
contrast id: scrambled - faces
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:134: RuntimeWarning: The same contrast will be used for all 2 runs. If the design matrices are not the same for all runs, (for example with different column names or column order across runs) you should pass contrast as an expression using the name of the conditions as they appear in the design matrices.
results = fmri_glm.compute_contrast(contrast_id, output_type="all")
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
We also define the effects of interest contrast, a 2-dimensional contrasts spanning the two conditions.
import numpy as np
contrasts = np.eye(2)
results = fmri_glm.compute_contrast(contrasts, output_type="all")
plot_stat_map(
results["stat"],
title="effects of interest",
transparency=results["z_score"],
**plot_param,
)
show()

/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:151: RuntimeWarning: The same contrast will be used for all 2 runs. If the design matrices are not the same for all runs, (for example with different column names or column order across runs) you should pass contrast as an expression using the name of the conditions as they appear in the design matrices.
results = fmri_glm.compute_contrast(contrasts, output_type="all")
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:151: UserWarning: F contrasts should have 20 columns, but it has only 2. The rest of the contrast was padded with zeros.
results = fmri_glm.compute_contrast(contrasts, output_type="all")
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:151: UserWarning: Running approximate fixed effects on F statistics.
results = fmri_glm.compute_contrast(contrasts, output_type="all")
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
[FirstLevelModel.compute_contrast] Computing image from signals
Based on the resulting maps we observe that the analysis results in wide activity for the ‘effects of interest’ contrast, showing the implications of large portions of the visual cortex in the conditions. By contrast, the differential effect between “faces” and “scrambled” involves sparser, more anterior and lateral regions. It also displays some responses in the frontal lobe.
Total running time of the script: (4 minutes 30.494 seconds)
Estimated memory usage: 1028 MB

