Skip to content

Instantly share code, notes, and snippets.

@carlohamalainen
Last active December 26, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlohamalainen/7132447 to your computer and use it in GitHub Desktop.
Save carlohamalainen/7132447 to your computer and use it in GitHub Desktop.
Test workflow for the new MINC interface in Nipype.
# Artificial example (averaging and then dumping) using the new
# MINC interface in Nipype.
#
# Carlo Hamalainen <carlo@carlo-hamalainen.net>
import os
import nipype.interfaces.minc as minc
import nipype.interfaces.io as nio
import nipype.interfaces.utility as util
import nipype.pipeline.engine as pe
import nipype.interfaces.base as base
# Our top level working directory.
experiment_dir = '/home/carlo/work/vmwork/experiment'
# Averaging node. Note that this node accepts
# a list of files (input_files) and produces
# a single output file (output_file, seen in avg.outputs).
avg = pe.Node(interface=minc.AverageTask(), name='mincaverage')
# Dump node.
dump = pe.Node(interface=minc.DumpTask(), name='mincdump')
# Top level workflow.
main_workflow = pe.Workflow(name='main_workflow')
main_workflow.base_dir = experiment_dir
# Source data: glob for the test 2D files.
datagrabber = nio.DataGrabber(sort_filelist=True,
outfields=['testfiles'],
base_directory = experiment_dir,
template = 'data/minc_test_2D_??.mnc')
datasource = pe.Node(interface=datagrabber, name='testinputfiles')
# Output directory:
datasink = pe.Node(interface=nio.DataSink(), name='datasink')
datasink.inputs.base_directory = os.path.abspath(os.path.join(experiment_dir, 'output'))
main_workflow.add_nodes([avg, dump])
main_workflow.connect(datasource, 'testfiles', avg, 'input_files')
main_workflow.connect(avg, 'output_file', dump, 'input_file')
main_workflow.connect(dump, 'output_file', datasink, 'average_file')
main_workflow.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment