def rsfMRI_filtering_pipeline(self, **name_maps): pipeline = self.new_pipeline( name='rsfMRI_filtering', desc=("Spatial and temporal rsfMRI filtering"), citations=[fsl_cite], name_maps=name_maps) afni_mc = pipeline.add( 'AFNI_MC', Volreg( zpad=1, out_file='rsfmri_mc.nii.gz', oned_file='prefiltered_func_data_mcf.par'), inputs={ 'in_file': ('series_preproc', nifti_gz_format)}, outputs={ 'mc_par': ('oned_file', par_format)}, wall_time=5, requirements=[afni_req.v('16.2.10')]) filt = pipeline.add( 'Tproject', Tproject( stopband=(0, 0.01), polort=3, blur=3, out_file='filtered_func_data.nii.gz'), inputs={ 'delta_t': ('tr', float), 'mask': ('brain_mask', nifti_gz_format), 'in_file': (afni_mc, 'out_file')}, wall_time=5, requirements=[afni_req.v('16.2.10')]) meanfunc = pipeline.add( 'meanfunc', ImageMaths( op_string='-Tmean', suffix='_mean', output_type='NIFTI_GZ'), wall_time=5, inputs={ 'in_file': (afni_mc, 'out_file')}, requirements=[fsl_req.v('5.0.10')]) pipeline.add( 'add_mean', ImageMaths( op_string='-add', output_type='NIFTI_GZ'), inputs={ 'in_file': (filt, 'out_file'), 'in_file2': (meanfunc, 'out_file')}, outputs={ 'filtered_data': ('out_file', nifti_gz_format)}, wall_time=5, requirements=[fsl_req.v('5.0.10')]) return pipeline
def rsfMRI_filtering_pipeline(self, **kwargs): pipeline = self.create_pipeline( name='rsfMRI_filtering', inputs=[ DatasetSpec('preproc', nifti_gz_format), DatasetSpec('brain_mask', nifti_gz_format), DatasetSpec('coreg_ref_brain', nifti_gz_format), FieldSpec('tr', float) ], outputs=[ DatasetSpec('filtered_data', nifti_gz_format), DatasetSpec('mc_par', par_format) ], desc=("Spatial and temporal rsfMRI filtering"), version=1, citations=[fsl_cite], **kwargs) afni_mc = pipeline.create_node(Volreg(), name='AFNI_MC', wall_time=5, requirements=[afni_req]) afni_mc.inputs.zpad = 1 afni_mc.inputs.out_file = 'rsfmri_mc.nii.gz' afni_mc.inputs.oned_file = 'prefiltered_func_data_mcf.par' pipeline.connect_input('preproc', afni_mc, 'in_file') filt = pipeline.create_node(Tproject(), name='Tproject', wall_time=5, requirements=[afni_req]) filt.inputs.stopband = (0, 0.01) filt.inputs.polort = 3 filt.inputs.blur = 3 filt.inputs.out_file = 'filtered_func_data.nii.gz' pipeline.connect_input('tr', filt, 'delta_t') pipeline.connect(afni_mc, 'out_file', filt, 'in_file') pipeline.connect_input('brain_mask', filt, 'mask') meanfunc = pipeline.create_node(ImageMaths(op_string='-Tmean', suffix='_mean'), name='meanfunc', wall_time=5, requirements=[fsl5_req]) pipeline.connect(afni_mc, 'out_file', meanfunc, 'in_file') add_mean = pipeline.create_node(ImageMaths(op_string='-add'), name='add_mean', wall_time=5, requirements=[fsl5_req]) pipeline.connect(filt, 'out_file', add_mean, 'in_file') pipeline.connect(meanfunc, 'out_file', add_mean, 'in_file2') pipeline.connect_output('filtered_data', add_mean, 'out_file') pipeline.connect_output('mc_par', afni_mc, 'oned_file') return pipeline
def test_Volreg_inputs(): input_map = dict( args=dict(argstr='%s', ), basefile=dict( argstr='-base %s', position=-6, ), copyorigin=dict(argstr='-twodup', ), environ=dict( nohash=True, usedefault=True, ), ignore_exception=dict( nohash=True, usedefault=True, ), in_file=dict( argstr='%s', copyfile=False, mandatory=True, position=-1, ), md1d_file=dict( argstr='-maxdisp1D %s', keep_extension=True, name_source='in_file', name_template='%s_md.1D', position=-4, ), oned_file=dict( argstr='-1Dfile %s', keep_extension=True, name_source='in_file', name_template='%s.1D', ), out_file=dict( argstr='-prefix %s', name_source='in_file', name_template='%s_volreg', ), outputtype=dict(), terminal_output=dict( mandatory=True, nohash=True, ), timeshift=dict(argstr='-tshift 0', ), verbose=dict(argstr='-verbose', ), zpad=dict( argstr='-zpad %d', position=-5, ), ) inputs = Volreg.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_Volreg_inputs(): input_map = dict(args=dict(argstr='%s', ), basefile=dict(argstr='-base %s', position=-6, ), copyorigin=dict(argstr='-twodup', ), environ=dict(nohash=True, usedefault=True, ), ignore_exception=dict(nohash=True, usedefault=True, ), in_file=dict(argstr='%s', copyfile=False, mandatory=True, position=-1, ), md1d_file=dict(argstr='-maxdisp1D %s', keep_extension=True, name_source='in_file', name_template='%s_md.1D', position=-4, ), oned_file=dict(argstr='-1Dfile %s', keep_extension=True, name_source='in_file', name_template='%s.1D', ), oned_matrix_save=dict(argstr='-1Dmatrix_save %s', keep_extension=True, name_source='in_file', name_template='%s.aff12.1D', ), out_file=dict(argstr='-prefix %s', name_source='in_file', name_template='%s_volreg', ), outputtype=dict(), terminal_output=dict(mandatory=True, nohash=True, ), timeshift=dict(argstr='-tshift 0', ), verbose=dict(argstr='-verbose', ), zpad=dict(argstr='-zpad %d', position=-5, ), ) inputs = Volreg.input_spec() for key, metadata in input_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_Volreg_outputs(): output_map = dict(oned_file=dict(), md1d_file=dict(), out_file=dict(), ) outputs = Volreg.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def test_Volreg_outputs(): output_map = dict( md1d_file=dict(), oned_file=dict(), out_file=dict(), ) outputs = Volreg.output_spec() for key, metadata in output_map.items(): for metakey, value in metadata.items(): yield assert_equal, getattr(outputs.traits()[key], metakey), value
def init_topup_wf( grid_reference=0, omp_nthreads=1, sloppy=False, debug=False, name="pepolar_estimate_wf", ): """ Create the PEPOLAR field estimation workflow based on FSL's ``topup``. Workflow Graph .. workflow :: :graph2use: orig :simple_form: yes from sdcflows.workflows.fit.pepolar import init_topup_wf wf = init_topup_wf() Parameters ---------- grid_reference : :obj:`int` Index of the volume (after flattening) that will be taken for gridding reference. sloppy : :obj:`bool` Whether a fast configuration of topup (less accurate) should be applied. debug : :obj:`bool` Run in debug mode name : :obj:`str` Name for this workflow omp_nthreads : :obj:`int` Parallelize internal tasks across the number of CPUs given by this option. Inputs ------ in_data : :obj:`list` of :obj:`str` A list of EPI files that will be fed into TOPUP. metadata : :obj:`list` of :obj:`dict` A list of dictionaries containing the metadata corresponding to each file in ``in_data``. Outputs ------- fmap : :obj:`str` The path of the estimated fieldmap. fmap_ref : :obj:`str` The path of an unwarped conversion of files in ``in_data``. fmap_mask : :obj:`str` The path of mask corresponding to the ``fmap_ref`` output. fmap_coeff : :obj:`str` or :obj:`list` of :obj:`str` The path(s) of the B-Spline coefficients supporting the fieldmap. method: :obj:`str` Short description of the estimation method that was run. """ from nipype.interfaces.fsl.epi import TOPUP from niworkflows.interfaces.nibabel import MergeSeries from niworkflows.interfaces.images import RobustAverage from ...utils.misc import front as _front from ...interfaces.epi import GetReadoutTime from ...interfaces.utils import Flatten, UniformGrid, PadSlices from ...interfaces.bspline import TOPUPCoeffReorient from ..ancillary import init_brainextraction_wf workflow = Workflow(name=name) workflow.__desc__ = f"""\ {_PEPOLAR_DESC} with `topup` (@topup; FSL {TOPUP().version}). """ inputnode = pe.Node(niu.IdentityInterface(fields=INPUT_FIELDS), name="inputnode") outputnode = pe.Node( niu.IdentityInterface(fields=[ "fmap", "fmap_ref", "fmap_coeff", "fmap_mask", "jacobians", "xfms", "out_warps", "method", ]), name="outputnode", ) outputnode.inputs.method = "PEB/PEPOLAR (phase-encoding based / PE-POLARity)" flatten = pe.Node(Flatten(), name="flatten") regrid = pe.Node(UniformGrid(reference=grid_reference), name="regrid") concat_blips = pe.Node(MergeSeries(), name="concat_blips") readout_time = pe.MapNode( GetReadoutTime(), name="readout_time", iterfield=["metadata", "in_file"], run_without_submitting=True, ) pad_blip_slices = pe.Node(PadSlices(), name="pad_blip_slices") pad_ref_slices = pe.Node(PadSlices(), name="pad_ref_slices") topup = pe.Node( TOPUP(config=_pkg_fname( "sdcflows", f"data/flirtsch/b02b0{'_quick' * sloppy}.cnf")), name="topup", ) ref_average = pe.Node(RobustAverage(), name="ref_average") fix_coeff = pe.Node(TOPUPCoeffReorient(), name="fix_coeff", run_without_submitting=True) brainextraction_wf = init_brainextraction_wf() # fmt: off workflow.connect([ (inputnode, flatten, [("in_data", "in_data"), ("metadata", "in_meta")]), (flatten, readout_time, [("out_data", "in_file"), ("out_meta", "metadata")]), (flatten, regrid, [("out_data", "in_data")]), (regrid, concat_blips, [("out_data", "in_files")]), (readout_time, topup, [("readout_time", "readout_times"), ("pe_dir_fsl", "encoding_direction")]), (regrid, pad_ref_slices, [("reference", "in_file")]), (pad_ref_slices, fix_coeff, [("out_file", "fmap_ref")]), (readout_time, fix_coeff, [(("pe_direction", _front), "pe_dir")]), (topup, fix_coeff, [("out_fieldcoef", "in_coeff")]), (topup, outputnode, [("out_jacs", "jacobians"), ("out_mats", "xfms")]), (ref_average, brainextraction_wf, [("out_file", "inputnode.in_file")]), (brainextraction_wf, outputnode, [("outputnode.out_file", "fmap_ref"), ("outputnode.out_mask", "fmap_mask") ]), (fix_coeff, outputnode, [("out_coeff", "fmap_coeff")]), ]) # fmt: on if not debug: # fmt: off workflow.connect([ (concat_blips, pad_blip_slices, [("out_file", "in_file")]), (pad_blip_slices, topup, [("out_file", "in_file")]), (topup, ref_average, [("out_corrected", "in_file")]), (topup, outputnode, [("out_field", "fmap"), ("out_warps", "out_warps")]), ]) # fmt: on return workflow from nipype.interfaces.afni.preprocess import Volreg from niworkflows.interfaces.nibabel import SplitSeries from ...interfaces.bspline import ApplyCoeffsField realign = pe.Node( Volreg(args=f"-base {grid_reference}", outputtype="NIFTI_GZ"), name="realign_blips", ) split_blips = pe.Node(SplitSeries(), name="split_blips") unwarp = pe.Node(ApplyCoeffsField(), name="unwarp") unwarp.interface._always_run = True concat_corrected = pe.Node(MergeSeries(), name="concat_corrected") # fmt:off workflow.connect([ (concat_blips, realign, [("out_file", "in_file")]), (realign, pad_blip_slices, [("out_file", "in_file")]), (pad_blip_slices, topup, [("out_file", "in_file")]), (fix_coeff, unwarp, [("out_coeff", "in_coeff")]), (realign, split_blips, [("out_file", "in_file")]), (split_blips, unwarp, [("out_files", "in_data")]), (readout_time, unwarp, [("readout_time", "ro_time"), ("pe_direction", "pe_dir")]), (unwarp, outputnode, [("out_warp", "out_warps"), ("out_field", "fmap")]), (unwarp, concat_corrected, [("out_corrected", "in_files")]), (concat_corrected, ref_average, [("out_file", "in_file")]), ]) # fmt:on return workflow