Single-subject data (two runs) in native space#

The example shows the analysis of an SPM dataset studying face perception. The analysis is performed in native space. Realignment parameters are provided with the input images, but those have not been resampled to a common space.

The experimental paradigm is simple, with two conditions; viewing a face image or a scrambled face image, supposedly with the same low-level statistical properties, to find face-specific responses.

For details on the data, please see Henson et al.[1].

This example takes a lot of time because the input are lists of 3D images sampled in different positions (encoded by different affine functions).

Fetch the SPM multimodal_faces data.

Dataset created in /home/runner/work/nilearn/nilearn/nilearn_data/spm_multimodal_fmri

Missing 390 functional scans for session 1.
Data absent, downloading...
Downloading data from https://www.fil.ion.ucl.ac.uk/spm/download/data/mmfaces/multimodal_fmri.zip ...

Downloaded 1105920 of 134263085 bytes (0.8%,  2.2min remaining)
Downloaded 2514944 of 134263085 bytes (1.9%,  1.9min remaining)
Downloaded 3203072 of 134263085 bytes (2.4%,  2.2min remaining)
Downloaded 3579904 of 134263085 bytes (2.7%,  2.6min remaining)
Downloaded 3809280 of 134263085 bytes (2.8%,  3.0min remaining)
Downloaded 4079616 of 134263085 bytes (3.0%,  3.4min remaining)
Downloaded 4325376 of 134263085 bytes (3.2%,  3.7min remaining)
Downloaded 4595712 of 134263085 bytes (3.4%,  3.9min remaining)
Downloaded 4898816 of 134263085 bytes (3.6%,  4.1min remaining)
Downloaded 5226496 of 134263085 bytes (3.9%,  4.3min remaining)
Downloaded 5529600 of 134263085 bytes (4.1%,  4.4min remaining)
Downloaded 5865472 of 134263085 bytes (4.4%,  4.6min remaining)
Downloaded 6160384 of 134263085 bytes (4.6%,  4.7min remaining)
Downloaded 6479872 of 134263085 bytes (4.8%,  4.8min remaining)
Downloaded 6848512 of 134263085 bytes (5.1%,  4.8min remaining)
Downloaded 7208960 of 134263085 bytes (5.4%,  4.9min remaining)
Downloaded 7520256 of 134263085 bytes (5.6%,  4.9min remaining)
Downloaded 7847936 of 134263085 bytes (5.8%,  5.0min remaining)
Downloaded 8200192 of 134263085 bytes (6.1%,  5.0min remaining)
Downloaded 8560640 of 134263085 bytes (6.4%,  5.1min remaining)
Downloaded 8912896 of 134263085 bytes (6.6%,  5.1min remaining)
Downloaded 9216000 of 134263085 bytes (6.9%,  5.1min remaining)
Downloaded 9568256 of 134263085 bytes (7.1%,  5.2min remaining)
Downloaded 9863168 of 134263085 bytes (7.3%,  5.2min remaining)
Downloaded 10215424 of 134263085 bytes (7.6%,  5.2min remaining)
Downloaded 10559488 of 134263085 bytes (7.9%,  5.2min remaining)
Downloaded 10854400 of 134263085 bytes (8.1%,  5.3min remaining)
Downloaded 11214848 of 134263085 bytes (8.4%,  5.3min remaining)
Downloaded 11575296 of 134263085 bytes (8.6%,  5.3min remaining)
Downloaded 11902976 of 134263085 bytes (8.9%,  5.3min remaining)
Downloaded 12230656 of 134263085 bytes (9.1%,  5.3min remaining)
Downloaded 12591104 of 134263085 bytes (9.4%,  5.3min remaining)
Downloaded 12861440 of 134263085 bytes (9.6%,  5.3min remaining)
Downloaded 13090816 of 134263085 bytes (9.8%,  5.4min remaining)
Downloaded 13336576 of 134263085 bytes (9.9%,  5.4min remaining)
Downloaded 13606912 of 134263085 bytes (10.1%,  5.5min remaining)
Downloaded 13910016 of 134263085 bytes (10.4%,  5.5min remaining)
Downloaded 14245888 of 134263085 bytes (10.6%,  5.5min remaining)
Downloaded 14614528 of 134263085 bytes (10.9%,  5.5min remaining)
Downloaded 15114240 of 134263085 bytes (11.3%,  5.4min remaining)
Downloaded 15671296 of 134263085 bytes (11.7%,  5.3min remaining)
Downloaded 16187392 of 134263085 bytes (12.1%,  5.2min remaining)
Downloaded 16670720 of 134263085 bytes (12.4%,  5.2min remaining)
Downloaded 17186816 of 134263085 bytes (12.8%,  5.1min remaining)
Downloaded 17702912 of 134263085 bytes (13.2%,  5.1min remaining)
Downloaded 18235392 of 134263085 bytes (13.6%,  5.0min remaining)
Downloaded 18726912 of 134263085 bytes (13.9%,  5.0min remaining)
Downloaded 19202048 of 134263085 bytes (14.3%,  4.9min remaining)
Downloaded 19759104 of 134263085 bytes (14.7%,  4.9min remaining)
Downloaded 20267008 of 134263085 bytes (15.1%,  4.8min remaining)
Downloaded 20742144 of 134263085 bytes (15.4%,  4.8min remaining)
Downloaded 21282816 of 134263085 bytes (15.9%,  4.7min remaining)
Downloaded 21848064 of 134263085 bytes (16.3%,  4.7min remaining)
Downloaded 22413312 of 134263085 bytes (16.7%,  4.6min remaining)
Downloaded 22978560 of 134263085 bytes (17.1%,  4.5min remaining)
Downloaded 23576576 of 134263085 bytes (17.6%,  4.5min remaining)
Downloaded 24240128 of 134263085 bytes (18.1%,  4.4min remaining)
Downloaded 24838144 of 134263085 bytes (18.5%,  4.4min remaining)
Downloaded 25493504 of 134263085 bytes (19.0%,  4.3min remaining)
Downloaded 26173440 of 134263085 bytes (19.5%,  4.2min remaining)
Downloaded 26812416 of 134263085 bytes (20.0%,  4.2min remaining)
Downloaded 27443200 of 134263085 bytes (20.4%,  4.1min remaining)
Downloaded 27975680 of 134263085 bytes (20.8%,  4.1min remaining)
Downloaded 28540928 of 134263085 bytes (21.3%,  4.0min remaining)
Downloaded 28958720 of 134263085 bytes (21.6%,  4.0min remaining)
Downloaded 29401088 of 134263085 bytes (21.9%,  4.0min remaining)
Downloaded 29712384 of 134263085 bytes (22.1%,  4.0min remaining)
Downloaded 30040064 of 134263085 bytes (22.4%,  4.0min remaining)
Downloaded 30384128 of 134263085 bytes (22.6%,  4.0min remaining)
Downloaded 30744576 of 134263085 bytes (22.9%,  4.0min remaining)
Downloaded 30998528 of 134263085 bytes (23.1%,  4.0min remaining)
Downloaded 31252480 of 134263085 bytes (23.3%,  4.0min remaining)
Downloaded 31522816 of 134263085 bytes (23.5%,  4.1min remaining)
Downloaded 31817728 of 134263085 bytes (23.7%,  4.1min remaining)
Downloaded 32137216 of 134263085 bytes (23.9%,  4.1min remaining)
Downloaded 32473088 of 134263085 bytes (24.2%,  4.1min remaining)
Downloaded 32817152 of 134263085 bytes (24.4%,  4.1min remaining)
Downloaded 33169408 of 134263085 bytes (24.7%,  4.1min remaining)
Downloaded 33480704 of 134263085 bytes (24.9%,  4.1min remaining)
Downloaded 33800192 of 134263085 bytes (25.2%,  4.1min remaining)
Downloaded 34168832 of 134263085 bytes (25.4%,  4.1min remaining)
Downloaded 34537472 of 134263085 bytes (25.7%,  4.0min remaining)
Downloaded 34906112 of 134263085 bytes (26.0%,  4.0min remaining)
Downloaded 35299328 of 134263085 bytes (26.3%,  4.0min remaining)
Downloaded 35741696 of 134263085 bytes (26.6%,  4.0min remaining)
Downloaded 36290560 of 134263085 bytes (27.0%,  4.0min remaining)
Downloaded 36913152 of 134263085 bytes (27.5%,  3.9min remaining)
Downloaded 37543936 of 134263085 bytes (28.0%,  3.9min remaining)
Downloaded 38043648 of 134263085 bytes (28.3%,  3.8min remaining)
Downloaded 38404096 of 134263085 bytes (28.6%,  3.8min remaining)
Downloaded 38715392 of 134263085 bytes (28.8%,  3.8min remaining)
Downloaded 38977536 of 134263085 bytes (29.0%,  3.8min remaining)
Downloaded 39264256 of 134263085 bytes (29.2%,  3.8min remaining)
Downloaded 39583744 of 134263085 bytes (29.5%,  3.8min remaining)
Downloaded 39919616 of 134263085 bytes (29.7%,  3.8min remaining)
Downloaded 40255488 of 134263085 bytes (30.0%,  3.8min remaining)
Downloaded 40574976 of 134263085 bytes (30.2%,  3.8min remaining)
Downloaded 40951808 of 134263085 bytes (30.5%,  3.8min remaining)
Downloaded 41320448 of 134263085 bytes (30.8%,  3.8min remaining)
Downloaded 41680896 of 134263085 bytes (31.0%,  3.8min remaining)
Downloaded 42033152 of 134263085 bytes (31.3%,  3.8min remaining)
Downloaded 42409984 of 134263085 bytes (31.6%,  3.8min remaining)
Downloaded 42795008 of 134263085 bytes (31.9%,  3.8min remaining)
Downloaded 43114496 of 134263085 bytes (32.1%,  3.8min remaining)
Downloaded 43458560 of 134263085 bytes (32.4%,  3.7min remaining)
Downloaded 43769856 of 134263085 bytes (32.6%,  3.7min remaining)
Downloaded 44113920 of 134263085 bytes (32.9%,  3.7min remaining)
Downloaded 44425216 of 134263085 bytes (33.1%,  3.7min remaining)
Downloaded 44736512 of 134263085 bytes (33.3%,  3.7min remaining)
Downloaded 45056000 of 134263085 bytes (33.6%,  3.7min remaining)
Downloaded 45400064 of 134263085 bytes (33.8%,  3.7min remaining)
Downloaded 45776896 of 134263085 bytes (34.1%,  3.7min remaining)
Downloaded 46112768 of 134263085 bytes (34.3%,  3.7min remaining)
Downloaded 46473216 of 134263085 bytes (34.6%,  3.7min remaining)
Downloaded 46792704 of 134263085 bytes (34.9%,  3.7min remaining)
Downloaded 47112192 of 134263085 bytes (35.1%,  3.7min remaining)
Downloaded 47439872 of 134263085 bytes (35.3%,  3.7min remaining)
Downloaded 47800320 of 134263085 bytes (35.6%,  3.6min remaining)
Downloaded 48185344 of 134263085 bytes (35.9%,  3.6min remaining)
Downloaded 48529408 of 134263085 bytes (36.1%,  3.6min remaining)
Downloaded 48857088 of 134263085 bytes (36.4%,  3.6min remaining)
Downloaded 49160192 of 134263085 bytes (36.6%,  3.6min remaining)
Downloaded 49487872 of 134263085 bytes (36.9%,  3.6min remaining)
Downloaded 49823744 of 134263085 bytes (37.1%,  3.6min remaining)
Downloaded 50110464 of 134263085 bytes (37.3%,  3.6min remaining)
Downloaded 50446336 of 134263085 bytes (37.6%,  3.6min remaining)
Downloaded 50806784 of 134263085 bytes (37.8%,  3.6min remaining)
Downloaded 51175424 of 134263085 bytes (38.1%,  3.5min remaining)
Downloaded 51535872 of 134263085 bytes (38.4%,  3.5min remaining)
Downloaded 51847168 of 134263085 bytes (38.6%,  3.5min remaining)
Downloaded 52158464 of 134263085 bytes (38.8%,  3.5min remaining)
Downloaded 52445184 of 134263085 bytes (39.1%,  3.5min remaining)
Downloaded 52740096 of 134263085 bytes (39.3%,  3.5min remaining)
Downloaded 53059584 of 134263085 bytes (39.5%,  3.5min remaining)
Downloaded 53379072 of 134263085 bytes (39.8%,  3.5min remaining)
Downloaded 53608448 of 134263085 bytes (39.9%,  3.5min remaining)
Downloaded 53854208 of 134263085 bytes (40.1%,  3.5min remaining)
Downloaded 54067200 of 134263085 bytes (40.3%,  3.5min remaining)
Downloaded 54296576 of 134263085 bytes (40.4%,  3.5min remaining)
Downloaded 54550528 of 134263085 bytes (40.6%,  3.5min remaining)
Downloaded 54779904 of 134263085 bytes (40.8%,  3.5min remaining)
Downloaded 55001088 of 134263085 bytes (41.0%,  3.5min remaining)
Downloaded 55271424 of 134263085 bytes (41.2%,  3.5min remaining)
Downloaded 55533568 of 134263085 bytes (41.4%,  3.5min remaining)
Downloaded 55812096 of 134263085 bytes (41.6%,  3.5min remaining)
Downloaded 56123392 of 134263085 bytes (41.8%,  3.5min remaining)
Downloaded 56475648 of 134263085 bytes (42.1%,  3.5min remaining)
Downloaded 56934400 of 134263085 bytes (42.4%,  3.4min remaining)
Downloaded 57475072 of 134263085 bytes (42.8%,  3.4min remaining)
Downloaded 58032128 of 134263085 bytes (43.2%,  3.4min remaining)
Downloaded 58671104 of 134263085 bytes (43.7%,  3.3min remaining)
Downloaded 59301888 of 134263085 bytes (44.2%,  3.3min remaining)
Downloaded 59826176 of 134263085 bytes (44.6%,  3.2min remaining)
Downloaded 60440576 of 134263085 bytes (45.0%,  3.2min remaining)
Downloaded 61104128 of 134263085 bytes (45.5%,  3.2min remaining)
Downloaded 61767680 of 134263085 bytes (46.0%,  3.1min remaining)
Downloaded 62291968 of 134263085 bytes (46.4%,  3.1min remaining)
Downloaded 62865408 of 134263085 bytes (46.8%,  3.1min remaining)
Downloaded 63504384 of 134263085 bytes (47.3%,  3.0min remaining)
Downloaded 64167936 of 134263085 bytes (47.8%,  3.0min remaining)
Downloaded 64708608 of 134263085 bytes (48.2%,  3.0min remaining)
Downloaded 65077248 of 134263085 bytes (48.5%,  2.9min remaining)
Downloaded 65380352 of 134263085 bytes (48.7%,  2.9min remaining)
Downloaded 65699840 of 134263085 bytes (48.9%,  2.9min remaining)
Downloaded 65986560 of 134263085 bytes (49.1%,  2.9min remaining)
Downloaded 66289664 of 134263085 bytes (49.4%,  2.9min remaining)
Downloaded 66625536 of 134263085 bytes (49.6%,  2.9min remaining)
Downloaded 66969600 of 134263085 bytes (49.9%,  2.9min remaining)
Downloaded 67321856 of 134263085 bytes (50.1%,  2.9min remaining)
Downloaded 67698688 of 134263085 bytes (50.4%,  2.8min remaining)
Downloaded 68116480 of 134263085 bytes (50.7%,  2.8min remaining)
Downloaded 68624384 of 134263085 bytes (51.1%,  2.8min remaining)
Downloaded 69255168 of 134263085 bytes (51.6%,  2.8min remaining)
Downloaded 69861376 of 134263085 bytes (52.0%,  2.7min remaining)
Downloaded 70369280 of 134263085 bytes (52.4%,  2.7min remaining)
Downloaded 70836224 of 134263085 bytes (52.8%,  2.7min remaining)
Downloaded 71270400 of 134263085 bytes (53.1%,  2.7min remaining)
Downloaded 71729152 of 134263085 bytes (53.4%,  2.6min remaining)
Downloaded 72155136 of 134263085 bytes (53.7%,  2.6min remaining)
Downloaded 72605696 of 134263085 bytes (54.1%,  2.6min remaining)
Downloaded 73048064 of 134263085 bytes (54.4%,  2.6min remaining)
Downloaded 73433088 of 134263085 bytes (54.7%,  2.6min remaining)
Downloaded 73875456 of 134263085 bytes (55.0%,  2.6min remaining)
Downloaded 74350592 of 134263085 bytes (55.4%,  2.5min remaining)
Downloaded 74825728 of 134263085 bytes (55.7%,  2.5min remaining)
Downloaded 75218944 of 134263085 bytes (56.0%,  2.5min remaining)
Downloaded 75653120 of 134263085 bytes (56.3%,  2.5min remaining)
Downloaded 76120064 of 134263085 bytes (56.7%,  2.4min remaining)
Downloaded 76603392 of 134263085 bytes (57.1%,  2.4min remaining)
Downloaded 77086720 of 134263085 bytes (57.4%,  2.4min remaining)
Downloaded 77545472 of 134263085 bytes (57.8%,  2.4min remaining)
Downloaded 78012416 of 134263085 bytes (58.1%,  2.4min remaining)
Downloaded 78495744 of 134263085 bytes (58.5%,  2.3min remaining)
Downloaded 78970880 of 134263085 bytes (58.8%,  2.3min remaining)
Downloaded 79380480 of 134263085 bytes (59.1%,  2.3min remaining)
Downloaded 79863808 of 134263085 bytes (59.5%,  2.3min remaining)
Downloaded 80322560 of 134263085 bytes (59.8%,  2.3min remaining)
Downloaded 80748544 of 134263085 bytes (60.1%,  2.2min remaining)
Downloaded 81166336 of 134263085 bytes (60.5%,  2.2min remaining)
Downloaded 81551360 of 134263085 bytes (60.7%,  2.2min remaining)
Downloaded 81960960 of 134263085 bytes (61.0%,  2.2min remaining)
Downloaded 82296832 of 134263085 bytes (61.3%,  2.2min remaining)
Downloaded 82681856 of 134263085 bytes (61.6%,  2.2min remaining)
Downloaded 83091456 of 134263085 bytes (61.9%,  2.1min remaining)
Downloaded 83509248 of 134263085 bytes (62.2%,  2.1min remaining)
Downloaded 83902464 of 134263085 bytes (62.5%,  2.1min remaining)
Downloaded 84246528 of 134263085 bytes (62.7%,  2.1min remaining)
Downloaded 84566016 of 134263085 bytes (63.0%,  2.1min remaining)
Downloaded 84885504 of 134263085 bytes (63.2%,  2.1min remaining)
Downloaded 85213184 of 134263085 bytes (63.5%,  2.1min remaining)
Downloaded 85573632 of 134263085 bytes (63.7%,  2.0min remaining)
Downloaded 85958656 of 134263085 bytes (64.0%,  2.0min remaining)
Downloaded 86368256 of 134263085 bytes (64.3%,  2.0min remaining)
Downloaded 86851584 of 134263085 bytes (64.7%,  2.0min remaining)
Downloaded 87408640 of 134263085 bytes (65.1%,  2.0min remaining)
Downloaded 88104960 of 134263085 bytes (65.6%,  1.9min remaining)
Downloaded 88686592 of 134263085 bytes (66.1%,  1.9min remaining)
Downloaded 89227264 of 134263085 bytes (66.5%,  1.9min remaining)
Downloaded 89784320 of 134263085 bytes (66.9%,  1.9min remaining)
Downloaded 90324992 of 134263085 bytes (67.3%,  1.8min remaining)
Downloaded 90865664 of 134263085 bytes (67.7%,  1.8min remaining)
Downloaded 91447296 of 134263085 bytes (68.1%,  1.8min remaining)
Downloaded 92028928 of 134263085 bytes (68.5%,  1.7min remaining)
Downloaded 92610560 of 134263085 bytes (69.0%,  1.7min remaining)
Downloaded 93208576 of 134263085 bytes (69.4%,  1.7min remaining)
Downloaded 93831168 of 134263085 bytes (69.9%,  1.7min remaining)
Downloaded 94371840 of 134263085 bytes (70.3%,  1.6min remaining)
Downloaded 94863360 of 134263085 bytes (70.7%,  1.6min remaining)
Downloaded 95363072 of 134263085 bytes (71.0%,  1.6min remaining)
Downloaded 95879168 of 134263085 bytes (71.4%,  1.6min remaining)
Downloaded 96395264 of 134263085 bytes (71.8%,  1.5min remaining)
Downloaded 96886784 of 134263085 bytes (72.2%,  1.5min remaining)
Downloaded 97337344 of 134263085 bytes (72.5%,  1.5min remaining)
Downloaded 97869824 of 134263085 bytes (72.9%,  1.5min remaining)
Downloaded 98418688 of 134263085 bytes (73.3%,  1.5min remaining)
Downloaded 98967552 of 134263085 bytes (73.7%,  1.4min remaining)
Downloaded 99467264 of 134263085 bytes (74.1%,  1.4min remaining)
Downloaded 99868672 of 134263085 bytes (74.4%,  1.4min remaining)
Downloaded 100245504 of 134263085 bytes (74.7%,  1.4min remaining)
Downloaded 100638720 of 134263085 bytes (75.0%,  1.4min remaining)
Downloaded 101031936 of 134263085 bytes (75.2%,  1.4min remaining)
Downloaded 101392384 of 134263085 bytes (75.5%,  1.3min remaining)
Downloaded 101785600 of 134263085 bytes (75.8%,  1.3min remaining)
Downloaded 102170624 of 134263085 bytes (76.1%,  1.3min remaining)
Downloaded 102514688 of 134263085 bytes (76.4%,  1.3min remaining)
Downloaded 102924288 of 134263085 bytes (76.7%,  1.3min remaining)
Downloaded 103342080 of 134263085 bytes (77.0%,  1.3min remaining)
Downloaded 103759872 of 134263085 bytes (77.3%,  1.2min remaining)
Downloaded 104153088 of 134263085 bytes (77.6%,  1.2min remaining)
Downloaded 104529920 of 134263085 bytes (77.9%,  1.2min remaining)
Downloaded 104824832 of 134263085 bytes (78.1%,  1.2min remaining)
Downloaded 105127936 of 134263085 bytes (78.3%,  1.2min remaining)
Downloaded 105431040 of 134263085 bytes (78.5%,  1.2min remaining)
Downloaded 105734144 of 134263085 bytes (78.8%,  1.2min remaining)
Downloaded 106053632 of 134263085 bytes (79.0%,  1.2min remaining)
Downloaded 106381312 of 134263085 bytes (79.2%,  1.1min remaining)
Downloaded 106635264 of 134263085 bytes (79.4%,  1.1min remaining)
Downloaded 106946560 of 134263085 bytes (79.7%,  1.1min remaining)
Downloaded 107282432 of 134263085 bytes (79.9%,  1.1min remaining)
Downloaded 107610112 of 134263085 bytes (80.1%,  1.1min remaining)
Downloaded 107962368 of 134263085 bytes (80.4%,  1.1min remaining)
Downloaded 108339200 of 134263085 bytes (80.7%,  1.1min remaining)
Downloaded 108781568 of 134263085 bytes (81.0%,  1.1min remaining)
Downloaded 109346816 of 134263085 bytes (81.4%,  1.0min remaining)
Downloaded 110108672 of 134263085 bytes (82.0%,   59.5s remaining)
Downloaded 110723072 of 134263085 bytes (82.5%,   57.9s remaining)
Downloaded 111280128 of 134263085 bytes (82.9%,   56.5s remaining)
Downloaded 111886336 of 134263085 bytes (83.3%,   54.9s remaining)
Downloaded 112500736 of 134263085 bytes (83.8%,   53.3s remaining)
Downloaded 113000448 of 134263085 bytes (84.2%,   52.0s remaining)
Downloaded 113541120 of 134263085 bytes (84.6%,   50.6s remaining)
Downloaded 114139136 of 134263085 bytes (85.0%,   49.1s remaining)
Downloaded 114630656 of 134263085 bytes (85.4%,   47.9s remaining)
Downloaded 115122176 of 134263085 bytes (85.7%,   46.6s remaining)
Downloaded 115556352 of 134263085 bytes (86.1%,   45.6s remaining)
Downloaded 115982336 of 134263085 bytes (86.4%,   44.5s remaining)
Downloaded 116391936 of 134263085 bytes (86.7%,   43.5s remaining)
Downloaded 116785152 of 134263085 bytes (87.0%,   42.6s remaining)
Downloaded 117153792 of 134263085 bytes (87.3%,   41.7s remaining)
Downloaded 117538816 of 134263085 bytes (87.5%,   40.8s remaining)
Downloaded 117940224 of 134263085 bytes (87.8%,   39.8s remaining)
Downloaded 118374400 of 134263085 bytes (88.2%,   38.7s remaining)
Downloaded 118767616 of 134263085 bytes (88.5%,   37.8s remaining)
Downloaded 119160832 of 134263085 bytes (88.8%,   36.8s remaining)
Downloaded 119611392 of 134263085 bytes (89.1%,   35.7s remaining)
Downloaded 119922688 of 134263085 bytes (89.3%,   35.0s remaining)
Downloaded 120168448 of 134263085 bytes (89.5%,   34.5s remaining)
Downloaded 120414208 of 134263085 bytes (89.7%,   33.9s remaining)
Downloaded 120659968 of 134263085 bytes (89.9%,   33.4s remaining)
Downloaded 120946688 of 134263085 bytes (90.1%,   32.7s remaining)
Downloaded 121257984 of 134263085 bytes (90.3%,   32.0s remaining)
Downloaded 121610240 of 134263085 bytes (90.6%,   31.1s remaining)
Downloaded 122093568 of 134263085 bytes (90.9%,   29.9s remaining)
Downloaded 122601472 of 134263085 bytes (91.3%,   28.6s remaining)
Downloaded 123158528 of 134263085 bytes (91.7%,   27.2s remaining)
Downloaded 123559936 of 134263085 bytes (92.0%,   26.3s remaining)
Downloaded 123904000 of 134263085 bytes (92.3%,   25.4s remaining)
Downloaded 124272640 of 134263085 bytes (92.6%,   24.5s remaining)
Downloaded 124657664 of 134263085 bytes (92.8%,   23.6s remaining)
Downloaded 125075456 of 134263085 bytes (93.2%,   22.6s remaining)
Downloaded 125501440 of 134263085 bytes (93.5%,   21.5s remaining)
Downloaded 125927424 of 134263085 bytes (93.8%,   20.5s remaining)
Downloaded 126353408 of 134263085 bytes (94.1%,   19.4s remaining)
Downloaded 126820352 of 134263085 bytes (94.5%,   18.3s remaining)
Downloaded 127279104 of 134263085 bytes (94.8%,   17.1s remaining)
Downloaded 127737856 of 134263085 bytes (95.1%,   16.0s remaining)
Downloaded 128229376 of 134263085 bytes (95.5%,   14.8s remaining)
Downloaded 128770048 of 134263085 bytes (95.9%,   13.5s remaining)
Downloaded 129245184 of 134263085 bytes (96.3%,   12.3s remaining)
Downloaded 129794048 of 134263085 bytes (96.7%,   10.9s remaining)
Downloaded 130260992 of 134263085 bytes (97.0%,    9.8s remaining)
Downloaded 130727936 of 134263085 bytes (97.4%,    8.6s remaining)
Downloaded 131227648 of 134263085 bytes (97.7%,    7.4s remaining)
Downloaded 131735552 of 134263085 bytes (98.1%,    6.2s remaining)
Downloaded 132259840 of 134263085 bytes (98.5%,    4.9s remaining)
Downloaded 132816896 of 134263085 bytes (98.9%,    3.5s remaining)
Downloaded 133300224 of 134263085 bytes (99.3%,    2.3s remaining)
Downloaded 133734400 of 134263085 bytes (99.6%,    1.3s remaining)
Downloaded 134078464 of 134263085 bytes (99.9%,    0.4s remaining) ...done. (328 seconds, 5 min)
Extracting data from /home/runner/work/nilearn/nilearn/nilearn_data/spm_multimodal_fmri/sub001/multimodal_fmri.zip..... done.
Downloading data from https://www.fil.ion.ucl.ac.uk/spm/download/data/mmfaces/multimodal_smri.zip ...

Downloaded 622592 of 6852766 bytes (9.1%,   10.2s remaining)
Downloaded 1269760 of 6852766 bytes (18.5%,    9.0s remaining)
Downloaded 1736704 of 6852766 bytes (25.3%,    9.0s remaining)
Downloaded 2162688 of 6852766 bytes (31.6%,    8.8s remaining)
Downloaded 2449408 of 6852766 bytes (35.7%,    9.2s remaining)
Downloaded 2760704 of 6852766 bytes (40.3%,    9.1s remaining)
Downloaded 3088384 of 6852766 bytes (45.1%,    8.7s remaining)
Downloaded 3440640 of 6852766 bytes (50.2%,    8.1s remaining)
Downloaded 3817472 of 6852766 bytes (55.7%,    7.3s remaining)
Downloaded 4128768 of 6852766 bytes (60.2%,    6.7s remaining)
Downloaded 4513792 of 6852766 bytes (65.9%,    5.8s remaining)
Downloaded 4907008 of 6852766 bytes (71.6%,    4.9s remaining)
Downloaded 5308416 of 6852766 bytes (77.5%,    3.9s remaining)
Downloaded 5718016 of 6852766 bytes (83.4%,    2.8s remaining)
Downloaded 6144000 of 6852766 bytes (89.7%,    1.8s remaining)
Downloaded 6520832 of 6852766 bytes (95.2%,    0.8s remaining) ...done. (18 seconds, 0 min)
Extracting data from /home/runner/work/nilearn/nilearn/nilearn_data/spm_multimodal_fmri/sub001/multimodal_smri.zip..... done.

Specify timing and design matrix parameters.

# repetition time, in seconds
tr = 2.0
# 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"

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.

Make the design matrices.

import numpy as np
import pandas as pd

from nilearn.glm.first_level import make_first_level_design_matrix

design_matrices = []

Loop over the two runs.

for idx, img in enumerate(fmri_img, start=1):
    # Build experimental paradigm
    n_scans = img.shape[-1]
    events = pd.read_table(subject_data[f"events{idx}"])
    # Define the sampling times for the design matrix
    frame_times = np.arange(n_scans) * tr
    # Build design matrix with the reviously defined parameters
    design_matrix = make_first_level_design_matrix(
        frame_times,
        events,
        hrf_model=hrf_model,
        drift_model=drift_model,
        high_pass=high_pass,
    )

    # put the design matrices in a list
    design_matrices.append(design_matrix)

We can specify basic contrasts (to get beta maps). We start by specifying canonical contrast that isolate design matrix columns.

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. We also define the effects of interest contrast, a 2-dimensional contrasts spanning the two conditions.

contrasts = {
    "faces-scrambled": basic_contrasts["faces"] - basic_contrasts["scrambled"],
    "scrambled-faces": -basic_contrasts["faces"]
    + basic_contrasts["scrambled"],
    "effects_of_interest": np.vstack(
        (basic_contrasts["faces"], basic_contrasts["scrambled"])
    ),
}

Fit the GLM for the 2 runs by specifying a FirstLevelModel and then fitting it.

from nilearn.glm.first_level import FirstLevelModel

print("Fitting a GLM")
fmri_glm = FirstLevelModel()
fmri_glm = fmri_glm.fit(fmri_img, design_matrices=design_matrices)
Fitting a GLM

Now we can compute contrast-related statistical maps (in z-scale), and plot them.

from nilearn import plotting

print("Computing contrasts")

# Iterate on contrasts
for contrast_id, contrast_val in contrasts.items():
    print(f"\tcontrast id: {contrast_id}")
    # compute the contrasts
    z_map = fmri_glm.compute_contrast(contrast_val, output_type="z_score")
    # plot the contrasts as soon as they're generated
    # the display is overlaid on the mean fMRI image
    # a threshold of 3.0 is used, more sophisticated choices are possible
    plotting.plot_stat_map(
        z_map,
        bg_img=mean_image,
        threshold=3.0,
        display_mode="z",
        cut_coords=3,
        black_bg=True,
        title=contrast_id,
    )
    plotting.show()
  • plot spm multimodal faces
  • plot spm multimodal faces
  • plot spm multimodal faces
Computing contrasts
        contrast id: faces-scrambled
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:140: UserWarning:

One contrast given, assuming it for all 2 runs

        contrast id: scrambled-faces
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:140: UserWarning:

One contrast given, assuming it for all 2 runs

        contrast id: effects_of_interest
/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_spm_multimodal_faces.py:140: UserWarning:

One contrast given, assuming it for all 2 runs

/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/site-packages/nilearn/glm/contrasts.py:159: UserWarning:

Running approximate fixed effects on F statistics.

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.

References#

Total running time of the script: (7 minutes 32.666 seconds)

Estimated memory usage: 877 MB

Gallery generated by Sphinx-Gallery