In [2]:
import nibabel as nib
import nilearn
from nilearn import image
import numpy as np
import pandas as pd
import os.path as osp
from glob import glob
from nilearn import plotting


/home/grg/jupyter/local/lib/python2.7/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
  "This module will be removed in 0.20.", DeprecationWarning)

In [17]:
c1dir = '/media/Projects/ALFA_VBM_processed/c1/'
mddir = '/home/grg/data/ALFA_DWI/'
jacdir = '/home/grg/spm/Jacobians/'
perdir = '/home/grg/spm/ROIvent'
dm = pd.read_excel('/home/grg/spm/designmatrix3.xls')
vv = pd.read_excel('/home/grg/spm/data/Ventricular volumes.xlsx')
fsvol = pd.read_excel('/home/grg/spm/data/aseg FS ALFA.xlsx')
subjects_fp = '/home/grg/spm/data/subjects.json'
import json

allsubjects = json.load(open(subjects_fp))
ages = json.load(open('/home/grg/spm/data/age.json'))
educyears = dict([(str(int(e)), v) for e, v in dm[['Subj_ID', 'Years of Education']].to_dict(orient='split')['data']])
genders = dict([(str(int(e)), v) for e, v in dm[['Subj_ID', 'Gender(0=female)']].to_dict(orient='split')['data']])
tivs = dict([(str(int(str(e)[:5])), v) for e, v in vv[['subject', 'Total Intracranial Volume']].to_dict(orient='split')['data']])

c1fp = '/media/Projects/ALFA_VBM_processed/c1/c1t1_10013.nii'
perfp = osp.join(perdir, '10013_latvent_dilated.nii.gz')

fsvol = fsvol.loc[fsvol['StructName'].isin(['Left-Lateral-Ventricle', 'Right-Lateral-Ventricle', 'Left-Inf-Lat-Vent', 'Right-Inf-Lat-Vent'])][['subject', 'Volume_mm3', 'StructName']]
dm[dm['Subj_ID'] == 10070]


Out[17]:
Subj_ID MD MD_corr MD_pred Jacobians FA L1 RD Apoe2-3 Apoe2-4 ... agesq44 ventricles_FS ventricles_JDG Years of Education Gender(0=female) qc_fa qc_md qc_l1 qc_rd is_bad
15 10070 /home/grg/spm/MD/10070_MD_MNIspace_s.nii /home/grg/spm/MD_corr/10070_MD_corr.nii /home/grg/spm/MD_pred/10070_MD_pred.nii /home/grg/spm/Jacobians/s6j_t1_10070.nii /home/grg/spm/FA/10070_FA_MNIspace_s.nii /home/grg/spm/L1/10070_L1_MNIspace_s.nii /home/grg/spm/RD/10070_RD_MNIspace_s.nii 1 0 ... 0.0 4.520876 4.066362 10 0 4 4 4 4 0

1 rows × 32 columns


In [ ]:


In [ ]:


In [18]:
data = []
subjects = allsubjects #[0:100]
groups = ['Apoe2-2', 'Apoe2-3', 'Apoe2-4', 'Apoe3-3', 'Apoe3-4', 'Apoe4-4']
agegroups = ['Apoe2-3','Apoe2-4','Apoe3-3','Apoe3-4','Apoe4-4','age23',
             'age24','age33','age34','age44','agesq23','agesq24','agesq33','agesq34','agesq44']

for j, s in enumerate(subjects):
    print j, s 
    #try:
    mdfp = glob(osp.join(mddir, '%s*'%s, 'DWI', '%s*_MD_t1space.nii.gz'%s))[0]
    jacfp = glob(osp.join(jacdir, '*%s*nii'%s))[0]
    perfp = glob(osp.join(perdir, '%s*.nii.gz'%s))[0]
    md = np.array(nib.load(mdfp).dataobj, copy=True)
    peri = np.array(nib.load(perfp).dataobj, copy=True)
    mdl = np.mean(md[peri==1])
    mdr = np.mean(md[peri==2])
    vvol = dm[dm['Subj_ID'] == s]['ventricles_FS'].tolist()[0]
    age = ages[str(s)]
    agesq = age * age
    tiv = tivs[str(s)]
    sex = genders[str(s)]
    ey = educyears[str(s)]
    #for group, g in enumerate(groups):
    #    if s in dm[dm[g] == 1]['Subj_ID'].tolist():
    #        break
    #apo = [dm[dm['Subj_ID'] == s][x].tolist()[0] for x in agegroups]
    data.append([mdl, mdr, vvol, age, agesq, sex, ey]) #, tiv, group])
    #data[-1].extend(apo)
    #except:
    #    print 'skipping', s


0 10070
1 10102
2 10108
3 10235
4 10365
5 10419
6 10463
7 10530
8 10551
9 10563
10 10576
11 10630
12 10668
13 10692
14 10693
15 10703
16 10725
17 10737
18 10756
19 10809
20 11045
21 11047
22 11048
23 11133
24 11180
25 11225
26 11262
27 11305
28 11351
29 11360
30 11387
31 11407
32 11414
33 11416
34 11550
35 11610
36 11614
37 11638
38 11658
39 11691
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-18-b6c258900a77> in <module>()
     15     mdl = np.mean(md[peri==1])
     16     mdr = np.mean(md[peri==2])
---> 17     vvol = dm[dm['Subj_ID'] == s]['ventricles_FS'].tolist()[0]
     18     age = ages[str(s)]
     19     agesq = age * age

IndexError: list index out of range

In [19]:
columns = ['mdl', 'mdr', 'vvol', 'age', 'agesq', 'gender', 'educyears']
#columns.extend([e.replace('-','') for e in agegroups])
data


Out[19]:
[[nan, 0.0011878841, 4.5208758718505049, 18548, 344028304, 0, 10],
 [nan, 0.001244281, 16.507218636070277, 23400, 547560000, 1, 18],
 [nan, 0.0011122163, 10.421615504084253, 21434, 459416356, 0, 15],
 [nan, 0.0011755184, 7.5642007937396167, 22370, 500416900, 0, 8],
 [nan, 0.0011601257, 7.7704774303601152, 17795, 316662025, 0, 12],
 [nan, 0.0011398428, 3.484048540407541, 18593, 345699649, 0, 8],
 [nan, 0.0011420994, 7.4018040935183169, 21335, 455182225, 0, 18],
 [nan, 0.0011118628, 7.5218160926679287, 20613, 424895769, 0, 15],
 [nan, 0.0011736506, 17.226243157568582, 21322, 454627684, 1, 12],
 [nan, 0.0011772668, 6.4445513092762621, 18568, 344770624, 0, 12],
 [nan, 0.0012284343, 12.612239376363361, 17246, 297424516, 0, 18],
 [nan, 0.0011213743, 5.3789359114244499, 19505, 380445025, 0, 12],
 [nan, 0.0012068965, 11.353391521719567, 21156, 447576336, 1, 18],
 [nan, 0.0012838787, 29.332879028473339, 23593, 556629649, 0, 15],
 [nan, 0.0012959318, 17.758220629463903, 24142, 582836164, 0, 15],
 [nan, 0.0012133931, 10.11962682481869, 17702, 313360804, 1, 18],
 [nan, 0.0011776297, 3.7619115847428359, 20726, 429567076, 0, 10],
 [nan, 0.0011766521, 12.264827329819299, 17963, 322669369, 0, 15],
 [nan, 0.0011747829, 8.5619949592154061, 19146, 366569316, 0, 12],
 [nan, 0.0011676148, 17.55547519773684, 21881, 478778161, 0, 17],
 [nan, 0.0011683373, 9.6127142608177465, 23687, 561073969, 1, 17],
 [nan, 0.0011864569, 8.2754752878703979, 21239, 451095121, 0, 14],
 [nan, 0.0011561315, 10.994051418977051, 21720, 471758400, 0, 16],
 [nan, 0.0011890159, 20.994771115307824, 18422, 339370084, 0, 14],
 [nan, 0.0011247842, 13.963317355389922, 22406, 502028836, 1, 18],
 [nan, 0.001182696, 9.9015367687318356, 17274, 298391076, 1, 18],
 [nan, 0.0012528528, 9.8247460135736091, 23617, 557762689, 1, 8],
 [nan, 0.0012548161, 16.99624301439254, 22898, 524318404, 0, 12],
 [nan, 0.0012072064, 21.928143472286674, 19712, 388562944, 0, 4],
 [nan, 0.0012339139, 12.47384660416138, 21395, 457746025, 0, 17],
 [nan, 0.0011697951, 13.422350213324478, 22457, 504316849, 0, 18],
 [nan, 0.0011557252, 10.086488494446083, 18264, 333573696, 1, 15],
 [nan, 0.001237183, 5.2964952350083703, 19398, 376282404, 0, 17],
 [nan, 0.0011951217, 19.034162999140317, 16840, 283585600, 0, 12],
 [nan, 0.0012781103, 11.114660219615434, 19372, 375274384, 1, 18],
 [nan, 0.0013180267, 14.448855540745509, 18469, 341103961, 1, 15],
 [nan, 0.0012159973, 7.7196010809401088, 22597, 510624409, 0, 18],
 [nan, 0.0013155477, 24.056246847149822, 19117, 365459689, 1, 10],
 [nan, 0.0011513351, 8.7916630933968918, 20726, 429567076, 1, 17]]

In [440]:
print apo
df = pd.DataFrame(data, columns=columns)
df


[0, 0, 0, 0, 1, 0.0, 0.0, 0.0, 0.0, 63.646817248459961, 0.0, 0.0, 0.0, 0.0, 4050.9173458588602]
Out[440]:
gml gmr mdl mdr md_ofcl md_ofcr jacl jacr vl vr age agesq gender educyears tiv apoe
0 3963.164551 4113.191406 0.000986 0.001015 0.001531 0.001611 1.102849 1.175650 3216.4 2375.7 50.781656 2578.776627 0 10 1266.989 1
1 4272.754395 4354.435547 0.001211 0.001277 0.001477 0.001781 0.962475 0.973429 13679.9 12859.2 64.065708 4104.414995 1 18 1633.134 1
2 4593.183105 4359.208008 0.001049 0.001097 0.001422 0.001536 0.989340 0.914207 8871.1 5986.2 58.683094 3443.705495 0 15 1473.831 1
3 4177.236328 4267.051758 0.001060 0.001042 0.001691 0.001761 1.045694 1.056951 6301.4 3957.7 61.245722 3751.038477 0 8 1393.908 1
4 4558.288086 4454.539062 0.001030 0.001076 0.001615 0.001723 1.057800 0.971311 5504.9 5765.6 48.720055 2373.643736 0 12 1510.126 1
5 4755.672852 4852.111328 0.000946 0.000985 0.001744 0.001843 1.051403 1.015576 2670.3 2158.7 50.904860 2591.304740 0 8 1452.563 1
6 4457.572266 4652.879883 0.001069 0.001036 0.001832 0.001958 1.052247 0.986023 6105.2 3719.2 58.412047 3411.967181 0 18 1493.825 1
7 4004.250000 4308.104492 0.001020 0.001045 0.001445 0.001827 1.062169 1.040964 5331.3 4213.4 56.435318 3184.945149 0 15 1288.040 1
8 4510.816895 4317.996582 0.001206 0.001177 0.001223 0.001329 1.019799 0.945167 13490.0 12191.5 58.376454 3407.810438 1 12 1510.428 1
9 4834.943848 4572.562500 0.001020 0.001079 0.001339 0.001301 1.060631 0.965717 4245.2 5230.6 50.836413 2584.340929 0 12 1495.139 1
10 4983.850586 4862.791992 0.001163 0.001203 0.001554 0.001892 1.046596 1.027123 10820.2 9610.2 47.216975 2229.442697 0 18 1655.836 1
11 4620.295898 4843.298828 0.000975 0.000978 0.001681 0.001462 1.015410 1.069514 4184.8 3467.5 53.401780 2851.750065 0 12 1485.647 1
12 5095.222656 4849.410156 0.001079 0.001132 0.001366 0.001388 1.038292 0.957065 9510.9 8738.8 57.921971 3354.954754 1 18 1622.546 1
13 3735.114502 3983.227295 0.001542 0.001499 0.002308 0.002485 0.934021 0.974726 23133.2 16193.8 64.594114 4172.399514 0 15 1399.941 1
14 4283.283203 4305.995117 0.001294 0.001366 0.002104 0.002192 0.979943 1.032991 14062.3 13629.2 66.097194 4368.839015 0 15 1589.416 1
15 4686.415527 4656.277344 0.001099 0.001171 0.001806 0.002041 1.081963 1.029303 6762.7 8407.7 48.465435 2348.898354 1 18 1560.018 1
16 3969.678223 3753.575928 0.000959 0.001024 0.001279 0.001427 1.032255 0.979054 2444.8 2248.2 56.744695 3219.960458 0 10 1277.223 1
17 4208.187500 4361.457031 0.001152 0.001241 0.001998 0.002305 1.119473 1.104708 9591.4 8715.7 49.180014 2418.673746 0 15 1506.340 1
18 4373.625000 4482.652344 0.001044 0.001041 0.001386 0.001343 1.014064 1.011631 6934.7 4368.3 52.418891 2747.740152 0 12 1389.863 1
19 4683.915039 4591.264160 0.001161 0.001335 0.001744 0.001908 1.129933 1.017166 10871.2 15009.2 59.906913 3588.838234 0 17 1501.617 1
20 4159.956055 4351.144531 0.001094 0.001141 0.001612 0.001865 1.014973 1.055154 7695.1 5549.6 64.851472 4205.713368 1 17 1423.032 1
21 4468.666016 4131.117676 0.001044 0.001106 0.001561 0.001560 1.131730 0.953141 5227.7 5994.0 58.149213 3381.330957 0 14 1408.620 1
22 3886.621826 4046.681641 0.001041 0.001164 0.001635 0.002068 1.038002 1.088666 6319.1 7516.2 59.466119 3536.219320 0 16 1270.387 1
23 3893.937500 4273.769531 0.001217 0.001324 0.001428 0.001532 1.001946 1.026643 11873.0 15793.4 50.436687 2543.859416 0 14 1332.789 1
24 4910.560059 5087.313477 0.001108 0.001193 0.001546 0.001909 1.028132 1.007750 10936.3 11646.4 61.344285 3763.121270 1 18 1651.026 1
25 4740.192383 4657.061523 0.001077 0.001053 0.001989 0.002188 0.963469 0.952164 9271.7 5035.7 47.293634 2236.687864 1 18 1519.552 1
26 4364.213867 4096.183594 0.001084 0.001185 0.001277 0.002136 1.022694 0.969395 7152.1 7822.4 64.659822 4180.892586 1 8 1566.127 1
27 3610.125977 3739.968994 0.001201 0.001254 0.001729 0.001655 0.955981 0.910894 10634.7 9722.2 62.691307 3930.200014 0 12 1244.881 1
28 4362.785645 4360.597656 0.001327 0.001350 0.001871 0.002113 1.094327 0.980406 17961.4 15178.1 53.968515 2912.600581 0 4 1545.051 1
29 4083.072266 4124.387207 0.001105 0.001157 0.001388 0.001632 0.983112 1.009491 8794.6 8436.3 58.576318 3431.184982 0 17 1407.561 1
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
486 4381.145508 4637.045898 0.001019 0.001059 0.001656 0.001837 1.118171 1.015471 4450.5 4351.2 48.873374 2388.606725 1 15 1472.077 5
487 4393.630859 3952.770020 0.001063 0.001081 0.001403 0.001596 1.111207 0.972650 8595.5 7429.9 50.976044 2598.557042 0 10 1451.116 5
488 4382.633789 4445.812500 0.001089 0.001150 0.001571 0.001661 1.014139 1.011741 8190.9 8536.7 50.921287 2592.977448 0 18 1490.918 5
489 4628.568848 4657.948242 0.001156 0.001108 0.001289 0.001223 1.065618 1.051482 10051.7 5725.6 55.928816 3128.032446 1 17 1528.086 5
490 4233.456055 3994.214111 0.000977 0.001016 0.001473 0.001811 1.034195 0.955805 4373.3 4507.2 45.694730 2088.008317 0 15 1344.477 5
491 4673.487305 4464.828613 0.001264 0.001311 0.001579 0.001670 1.004317 0.904828 10516.1 10490.0 61.765914 3815.028102 1 12 1657.956 5
492 4801.249023 4692.931641 0.001201 0.001276 0.001936 0.002367 1.021279 0.974318 14314.3 14435.9 50.732375 2573.773882 0 11 1682.281 5
493 4294.611328 4098.421387 0.001076 0.001133 0.001639 0.001799 0.961877 0.995812 7030.8 7792.4 53.374401 2848.826692 0 12 1436.171 5
494 4517.219238 4740.791992 0.001195 0.001155 0.001572 0.001712 1.018292 0.977005 11784.3 8365.6 63.367556 4015.447213 0 17 1498.810 5
495 4545.250977 4697.404785 0.001049 0.001125 0.001759 0.001821 1.052351 1.003360 5658.4 6819.9 53.210130 2831.317940 1 15 1620.221 5
496 4196.758789 4389.720703 0.001144 0.001177 0.001321 0.001590 0.936307 0.920529 11915.3 9809.7 63.296372 4006.430752 1 11 1501.891 5
497 4524.840332 4641.438477 0.000998 0.001039 0.001447 0.001602 1.025054 1.034497 7641.2 6886.7 62.165640 3864.566793 1 10 1516.663 5
498 3956.526855 4160.640137 0.001181 0.001227 0.001670 0.001809 0.975451 0.988514 11538.4 9936.1 50.272416 2527.315826 0 17 1310.522 5
499 4480.691406 4519.913086 0.001106 0.001150 0.001521 0.001538 1.001848 1.007566 6743.4 7214.5 47.707050 2275.962616 1 18 1491.334 5
500 4847.087891 4747.225586 0.000989 0.001015 0.001504 0.001459 1.135288 0.999451 4422.0 4045.5 53.029432 2812.120647 0 11 1499.021 5
501 4187.547363 4457.008789 0.001082 0.001163 0.001490 0.001549 0.944574 0.984275 7742.3 4752.0 64.936345 4216.728898 1 13 1455.578 5
502 4692.389160 4845.532715 0.001025 0.001023 0.001205 0.001332 0.970746 0.933283 7217.0 4136.2 51.255305 2627.106248 1 18 1698.851 5
503 4366.432617 4272.337891 0.001568 0.001534 0.001863 0.001946 1.008328 1.009928 22874.9 19442.0 62.565366 3914.425046 1 15 1630.553 5
504 4316.994141 4663.049316 0.001072 0.001106 0.001828 0.001836 1.003710 1.046516 5141.1 4022.5 49.894593 2489.470385 0 17 1320.054 5
505 4598.182617 4327.776855 0.001115 0.001127 0.001973 0.001891 1.011927 0.884670 9847.5 7658.7 49.292266 2429.727445 1 18 1577.174 5
506 4345.881836 4544.552734 0.001052 0.001057 0.001320 0.001676 1.062355 1.023037 6334.3 5811.1 50.433949 2543.583247 0 10 1363.237 5
507 3962.281494 4229.084961 0.000996 0.001056 0.001506 0.001926 0.919729 1.001603 7365.0 6579.9 53.117043 2821.420270 0 10 1464.558 5
508 4005.634277 3949.437256 0.001032 0.001096 0.001724 0.001886 0.990438 0.967797 4457.3 3844.1 57.902806 3352.734977 0 10 1388.351 5
509 4280.482910 4077.206787 0.001128 0.001187 0.001567 0.001886 0.991294 0.935342 7370.3 8136.4 62.009582 3845.188319 0 15 1387.227 5
510 4754.344238 4496.364746 0.001085 0.001169 0.001402 0.001812 1.073446 0.972890 8038.3 7004.8 54.360027 2955.012577 1 14 1494.467 5
511 4467.828125 4381.719727 0.001236 0.001312 0.001495 0.001914 1.030912 1.067873 11049.1 10597.5 67.718001 4585.727709 1 18 1604.927 5
512 4006.790039 4006.148438 0.001260 0.001224 0.001669 0.001924 1.021705 0.985548 12064.2 8950.4 65.875428 4339.571986 0 10 1499.167 5
513 3757.579590 3890.000732 0.001054 0.001126 0.001936 0.001996 0.994806 0.967322 4232.8 4967.8 61.982204 3841.793609 0 12 1236.780 5
514 3949.036377 3861.438477 0.001473 0.001707 0.001396 0.001413 0.998459 0.938538 18367.9 32796.6 67.479808 4553.524535 0 17 1592.450 5
515 4000.982910 4092.335938 0.001041 0.001064 0.001480 0.001975 1.069647 1.040697 6690.3 6393.7 63.646817 4050.917346 0 8 1448.559 5

516 rows × 16 columns


In [416]:
from pandas.tools.plotting import scatter_matrix
%matplotlib inline
import matplotlib.pyplot as plt
axes = scatter_matrix(df, figsize=(35,35))

corr = df.corr().as_matrix()
for i, j in zip(*plt.np.triu_indices_from(axes, k=1)):
    axes[i, j].annotate("%.3f" %corr[i,j], (0.8, 0.8), xycoords='axes fraction', ha='center', va='center')
plt.show()



In [16]:
from scipy import stats
import patsy
import statsmodels.api as sm
from statsmodels.formula.api import ols
print columns
f= 'md_ofcl ~ C(apoe) + age:C(apoe) + agesq:C(apoe) + C(gender) + educyears'
lm = ols( f, #Apoe23 + Apoe24 + Apoe33 + Apoe34 + Apoe44 + age23 + age24 + age33 + age34 + age44 + \
         #agesq23 + agesq24 + agesq33 + agesq34 + agesq44 + gender + educyears',
                    data=df).fit()
y,X = patsy.dmatrices(f, df, return_type='dataframe')
table = sm.stats.anova_lm(lm)
r = np.zeros_like(lm.params)
r[1] = 3
r[2]= -2
r[3] = 3
r[4] = -2
r[5] = -2
print lm.params
hypothese = 'C(apoe)[T.5] - (C(apoe)[T.4] + C(apoe)[T.3] + C(apoe)[T.2])'
lm.t_test(hypothese)


['mdl', 'mdr', 'vvol', 'age', 'agesq', 'gender', 'educyears']
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-16-755566c0514a> in <module>()
      7 lm = ols( f, #Apoe23 + Apoe24 + Apoe33 + Apoe34 + Apoe44 + age23 + age24 + age33 + age34 + age44 + \
      8          #agesq23 + agesq24 + agesq33 + agesq34 + agesq44 + gender + educyears',
----> 9                     data=df).fit()
     10 y,X = patsy.dmatrices(f, df, return_type='dataframe')
     11 table = sm.stats.anova_lm(lm)

NameError: name 'df' is not defined

In [403]:
box = [df[df['apoe'] == x]['md_ofcl'].tolist() for x in xrange(6)]
plt.boxplot(box)
plt.show(box)



In [391]:
from nistats.thresholding import map_threshold
im = np.array(nib.load('/tmp/ofc_mask2.nii.gz').dataobj, copy=True)
thresholded_map1, threshold1 = map_threshold('/tmp/output_FSvent/MD/analysis/estimatecontrasts/spmT_0006.nii', threshold=0.001, cluster_threshold=50)
im2 = np.array(thresholded_map1.dataobj, copy=True)
im[im2==0] =0 
from nilearn import plotting
plotting.plot_glass_brain(image.new_img_like('/tmp/ofc_mask.nii.gz', im))
image.new_img_like('/tmp/ofc_mask.nii.gz', im).to_filename('/tmp/ofc_mask2_shrinked.nii.gz')


Generating a periventricular mask


In [19]:
from skimage import morphology as morpho
from skimage.morphology import ball 
import numpy as np
import nibabel as nib
from nilearn import image
from nilearn import plotting
import os.path as osp
%matplotlib inline
%run /home/grg/git/alfa/nilearn-helper.py

In [52]:
vent_fp = '/home/grg/data/ALFA_DWI/10013/T1/10013_latvent.nii'
#t1_fp = '/home/grg/data/ALFA_DWI/10013/T1/10013_mabonlm_nobias.nii'
a1 = np.array(nib.load(vent_fp).dataobj)
a2 = morpho.dilation(a1, ball(6))
mit = a2.shape[0] /2
print mit
a2[a2<1] = 0
a2[mit:,:,:][a2[mit:,:,:] > 0.5] = 2
a2[a1 != 0] = 0
image.new_img_like(vent_fp, a2).to_filename('/tmp/test.nii.gz')

In [30]:
img = plotting.plot_roi(image.new_img_like(vent_fp, a), bg_img=t1_fp, display_mode='x', cut_coords=range(-10,10,2))

#dd_overlay(image.new_img_like(vent_fp, a))