Nipype caching


In [ ]:
from nipype.caching import Memory
mem = Memory('.')

Create cacheable objects


In [ ]:
from nipype.interfaces.spm import Realign
from nipype.interfaces.fsl import MCFLIRT

spm_realign = mem.cache(Realign)
fsl_realign = mem.cache(MCFLIRT)

Execute interfaces


In [ ]:
spm_results = spm_realign(in_files='ds107.nii', register_to_mean=False)
fsl_results = fsl_realign(in_file='ds107.nii', ref_vol=0, save_plots=True)

In [ ]:
subplot(211);plot(genfromtxt(fsl_results.outputs.par_file)[:, 3:])
subplot(212);plot(genfromtxt(spm_results.outputs.realignment_parameters)[:,:3])

In [ ]:
spm_results = spm_realign(in_files='ds107.nii', register_to_mean=False)
fsl_results = fsl_realign(in_file='ds107.nii', ref_vol=0, save_plots=True)

More caching


In [ ]:
from os.path import abspath as opap
files = [opap('../ds107/sub001/BOLD/task001_run001/bold.nii.gz'),
         opap('../ds107/sub001/BOLD/task001_run002/bold.nii.gz')]
converter = mem.cache(MRIConvert)
newfiles = []
for idx, fname in enumerate(files):
    newfiles.append(converter(in_file=fname,
                              out_type='nii').outputs.out_file)

In [ ]:
os.chdir(tutorial_dir)