from __future__ import print_function %%bash for f in data/T1-a data/T1-b do bet $f ${f}_brain -m fslmaths $f -s 2 ${f}_smooth fslmaths ${f}_smooth -mas ${f}_brain_mask ${f}_smooth_mask done ls data/*_smooth_mask.nii.gz from nipype.interfaces import fsl from nipype import Workflow, Node skullstrip = Node(fsl.BET(mask=True), name="skullstrip") smooth = Node(fsl.IsotropicSmooth(fwhm=4), name="smooth") mask = Node(fsl.ApplyMask(), name="mask") wf = Workflow(name="smoothflow") wf.base_dir = "." wf.connect(skullstrip, "mask_file", mask, "mask_file") wf.connect(smooth, "out_file", mask, "in_file") from nipype import IdentityInterface inputs = Node(IdentityInterface(fields=["mri_file"]), name="inputs") wf.connect(inputs, "mri_file", skullstrip, "in_file") wf.connect(inputs, "mri_file", smooth, "in_file") from nipype import config, logging config.set('logging', 'workflow_level', 'CRITICAL') config.set('logging', 'interface_level', 'CRITICAL') logging.update_logging(config) from os.path import abspath files = ["data/T1-a.nii.gz", "data/T1-b.nii.gz"] files = map(abspath, files) for f in files: inputs.inputs.mri_file = f wf.run() inputs.iterables = ("mri_file", files) wf.run(plugin="MultiProc", plugin_args={"n_proc": 2}) ls smoothflow/_mri_file*/smooth/*.nii.gz from nipype import Function def square_func(x): return x ** 2 square = Function(["x"], ["f_x"], square_func) print(square.run(x=2).outputs.f_x) from nipype import MapNode square_node = MapNode(square, name="square", iterfield=["x"]) square_node.inputs.x = range(4) print(square_node.run().outputs.f_x) def power_func(x, y): return x ** y power = Function(["x", "y"], ["f_xy"], power_func) power_node = MapNode(power, name="power", iterfield=["x", "y"]) power_node.inputs.x = range(4) power_node.inputs.y = range(4) print(power_node.run().outputs.f_xy) power_node = MapNode(power, name="power", iterfield=["x"]) power_node.inputs.x = range(4) power_node.inputs.y = 3 print(power_node.run().outputs.f_xy) !make clean