def test_compression(): """ the BET report capable test """ uncompressed = SimpleShowMaskRPT( generate_report=True, background_file=str( get_template('OASIS30ANTs', resolution=1, desc=None, suffix='T1w')), mask_file=str( get_template('OASIS30ANTs', resolution=1, desc='BrainCerebellumRegistration', suffix='mask')), compress_report=False).run().outputs.out_report compressed = SimpleShowMaskRPT( generate_report=True, background_file=str( get_template('OASIS30ANTs', resolution=1, desc=None, suffix='T1w')), mask_file=str( get_template('OASIS30ANTs', resolution=1, desc='BrainCerebellumRegistration', suffix='mask')), compress_report=True).run().outputs.out_report size = int(os.stat(uncompressed).st_size) size_compress = int(os.stat(compressed).st_size) assert size >= size_compress, ('The uncompressed report is smaller (%d)' 'than the compressed report (%d)' % (size, size_compress))
def test_compression(tmp_path): """ the BET report capable test """ uncompressed = (pe.Node( SimpleShowMaskRPT( generate_report=True, background_file=str( get_template("OASIS30ANTs", resolution=1, desc=None, suffix="T1w")), mask_file=str( get_template( "OASIS30ANTs", resolution=1, desc="BrainCerebellumRegistration", suffix="mask", )), compress_report=False, ), name="uncompressed", base_dir=str(tmp_path), ).run().outputs.out_report) compressed = (pe.Node( SimpleShowMaskRPT( generate_report=True, background_file=str( get_template("OASIS30ANTs", resolution=1, desc=None, suffix="T1w")), mask_file=str( get_template( "OASIS30ANTs", resolution=1, desc="BrainCerebellumRegistration", suffix="mask", )), compress_report=True, ), name="compressed", base_dir=str(tmp_path), ).run().outputs.out_report) size = int(os.stat(uncompressed).st_size) size_compress = int(os.stat(compressed).st_size) assert size >= size_compress, ("The uncompressed report is smaller (%d)" "than the compressed report (%d)" % (size, size_compress))
def init_reportlets_wf(reportlets_dir, name='reportlets_wf'): """Set up a battery of datasinks to store reports in the right location.""" from niworkflows.interfaces.masks import SimpleShowMaskRPT workflow = Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface( fields=['source_file', 'dwi_ref', 'dwi_mask', 'validation_report']), name='inputnode') mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') ds_report_mask = pe.Node( DerivativesDataSink(base_directory=reportlets_dir, desc='brain', suffix='mask'), name='ds_report_mask', run_without_submitting=True) ds_report_validation = pe.Node( DerivativesDataSink(base_directory=reportlets_dir, desc='validation', keep_dtype=True), name='ds_report_validation', run_without_submitting=True) workflow.connect([ (inputnode, mask_reportlet, [('dwi_ref', 'background_file'), ('dwi_mask', 'mask_file')]), (inputnode, ds_report_validation, [('source_file', 'source_file')]), (inputnode, ds_report_mask, [('source_file', 'source_file')]), (inputnode, ds_report_validation, [('validation_report', 'in_file')]), (mask_reportlet, ds_report_mask, [('out_report', 'in_file')]), ]) return workflow
def init_anat_report_wf(workdir=None, name="anat_report_wf", memcalc=MemoryCalculator()): workflow = pe.Workflow(name=name) fmriprepreports = ["t1w_dseg_mask", "std_t1w"] fmriprepreportdatasinks = [f"ds_{fr}_report" for fr in fmriprepreports] strfields = [ "t1w_preproc", "t1w_mask", "t1w_dseg", "std_preproc", "std_mask", *fmriprepreportdatasinks, ] inputnode = pe.Node( Exec( fieldtpls=[ ("tags", None), *[(field, "firststr") for field in strfields], ("std_dseg", "ravel"), ] ), name="inputnode", run_without_submitting=True ) # make_resultdicts = pe.Node( MakeResultdicts(reportkeys=["skull_strip_report", "t1_norm_rpt", *fmriprepreports]), name="make_resultdicts", run_without_submitting=True ) workflow.connect(inputnode, "tags", make_resultdicts, "tags") # resultdict_datasink = pe.Node( ResultdictDatasink(base_directory=workdir), name="resultdict_datasink" ) workflow.connect(make_resultdicts, "resultdicts", resultdict_datasink, "indicts") # for fr, frd in zip(fmriprepreports, fmriprepreportdatasinks): workflow.connect(inputnode, frd, make_resultdicts, fr) # T1w segmentation skull_strip_report = pe.Node(SimpleShowMaskRPT(), name="skull_strip_report") workflow.connect(inputnode, "t1w_preproc", skull_strip_report, "background_file") workflow.connect(inputnode, "t1w_mask", skull_strip_report, "mask_file") workflow.connect(skull_strip_report, "out_report", make_resultdicts, "skull_strip_report") # T1 -> mni t1_norm_rpt = pe.Node( PlotRegistration(template=config.workflow.spaces.get_spaces()[0]), name="t1_norm_rpt", mem_gb=0.1, ) workflow.connect(inputnode, "std_preproc", t1_norm_rpt, "in_file") workflow.connect(inputnode, "std_mask", t1_norm_rpt, "mask_file") workflow.connect(t1_norm_rpt, "out_report", make_resultdicts, "t1_norm_rpt") return workflow
def test_generate_report(self): ''' test of SimpleShowMaskRPT's report ''' _smoke_test_report( SimpleShowMaskRPT( background_file=_template_name('T_template0.nii.gz'), mask_file=_template_name( 'T_template0_BrainCerebellumRegistrationMask.nii.gz')), 'testSimpleShowMaskRPT.html')
def test_SimpleShowMaskRPT(oasis_dir): """ the BET report capable test """ msk_rpt = SimpleShowMaskRPT( generate_report=True, background_file=os.path.join(oasis_dir, 'T_template0.nii.gz'), mask_file=os.path.join(oasis_dir, 'T_template0_BrainCerebellumRegistrationMask.nii.gz') ) _smoke_test_report(msk_rpt, 'testSimpleMask.svg')
def init_reportlets_wf(output_dir, sdc_report=False, name="reportlets_wf"): """Set up a battery of datasinks to store reports in the right location.""" from niworkflows.interfaces.masks import SimpleShowMaskRPT workflow = Workflow(name=name) inputnode = pe.Node( niu.IdentityInterface(fields=[ "source_file", "dwi_ref", "dwi_mask", "validation_report", "sdc_report" ]), name="inputnode", ) mask_reportlet = pe.Node(SimpleShowMaskRPT(), name="mask_reportlet") ds_report_mask = pe.Node( DerivativesDataSink(base_directory=output_dir, desc="brain", suffix="mask", datatype="figures"), name="ds_report_mask", run_without_submitting=True, ) ds_report_validation = pe.Node( DerivativesDataSink(base_directory=output_dir, desc="validation", datatype="figures"), name="ds_report_validation", run_without_submitting=True, ) # fmt:off workflow.connect([ (inputnode, mask_reportlet, [("dwi_ref", "background_file"), ("dwi_mask", "mask_file")]), (inputnode, ds_report_validation, [("source_file", "source_file")]), (inputnode, ds_report_mask, [("source_file", "source_file")]), (inputnode, ds_report_validation, [("validation_report", "in_file")]), (mask_reportlet, ds_report_mask, [("out_report", "in_file")]), ]) # fmt:on if sdc_report: ds_report_sdc = pe.Node( DerivativesDataSink(base_directory=output_dir, desc="sdc", suffix="dwi", datatype="figures"), name="ds_report_sdc", run_without_submitting=True, ) # fmt:off workflow.connect([ (inputnode, ds_report_sdc, [("source_file", "source_file"), ("sdc_report", "in_file")]), ]) # fmt:on return workflow
def test_compression(oasis_dir): """ the BET report capable test """ uncompressed = SimpleShowMaskRPT( generate_report=True, background_file=os.path.join(oasis_dir, 'T_template0.nii.gz'), mask_file=os.path.join(oasis_dir, 'T_template0_BrainCerebellumRegistrationMask.nii.gz'), compress_report=False ).run().outputs.out_report compressed = SimpleShowMaskRPT( generate_report=True, background_file=os.path.join(oasis_dir, 'T_template0.nii.gz'), mask_file=os.path.join(oasis_dir, 'T_template0_BrainCerebellumRegistrationMask.nii.gz'), compress_report=True ).run().outputs.out_report size = int(os.stat(uncompressed).st_size) size_compress = int(os.stat(compressed).st_size) assert size >= size_compress, ('The uncompressed report is smaller (%d)' 'than the compressed report (%d)' % (size, size_compress))
def init_anat_report_wf(workdir=None, name="anat_report_wf", memcalc=MemoryCalculator()): workflow = pe.Workflow(name=name) # only input is the bold image inputnode = pe.Node( niu.IdentityInterface( fields=[*anat_in_attrs_from_anat_preproc_wf, "metadata"]), name="inputnode", ) # T1w segmentation skull_strip_report = pe.Node(SimpleShowMaskRPT(), name="skull_strip_report") workflow.connect([( inputnode, skull_strip_report, [("t1w_preproc", "background_file"), ("t1w_mask", "mask_file")], )]) # T1->mni t1_norm_rpt = pe.Node( PlotRegistration(template=config.workflow.spaces.get_spaces()[0]), name="t1_norm_rpt", mem_gb=0.1, ) workflow.connect([( inputnode, t1_norm_rpt, [("std_preproc", "in_file"), ("std_mask", "mask_file")], )]) mergereport = pe.Node( interface=niu.Merge(2), name="mergereport", run_without_submitting=True, ) workflow.connect([ (skull_strip_report, mergereport, [("out_report", "in1")]), (t1_norm_rpt, mergereport, [("out_report", "in2")]), ]) reportnode = pe.Node(interface=MakeResultdicts(keys=["desc", "report"]), name="reportnode") reportnode.inputs.desc = ["skull_strip_report", "t1_norm_rpt"] workflow.connect(inputnode, "metadata", reportnode, "basedict") workflow.connect(mergereport, "out", reportnode, "report") assert workdir is not None make_reportnode_datasink(workflow, workdir) return workflow
def test_brainmasker(tmpdir, datadir, workdir, outdir, folder): """Exercise the brain masking tool.""" tmpdir.chdir() wf = pe.Workflow(name=f"test_mask_{folder.replace('/', '_')}") if workdir: wf.base_dir = str(workdir) input_files = [ str(f) for f in (datadir / "brain-extraction-tests" / folder).glob("*.nii.gz") ] inputnode = pe.Node(niu.IdentityInterface(fields=("in_file", )), name="inputnode") inputnode.iterables = ("in_file", input_files) merger = pe.Node(niu.Function(function=_merge), name="merger") brainmask_wf = init_brainextraction_wf() # fmt:off wf.connect([ (inputnode, merger, [("in_file", "in_file")]), (merger, brainmask_wf, [("out", "inputnode.in_file")]), ]) # fmt:on if outdir: out_path = outdir / "masks" / folder.split("/")[-1] out_path.mkdir(exist_ok=True, parents=True) report = pe.Node(SimpleShowMaskRPT(), name="report") report.interface._always_run = True def _report_name(fname, out_path): from pathlib import Path return str(out_path / Path(fname).name.replace(".nii", "_mask.svg").replace( "_magnitude", "_desc-magnitude").replace(".gz", "")) # fmt: off wf.connect([ (inputnode, report, [(("in_file", _report_name, out_path), "out_report")]), (brainmask_wf, report, [("outputnode.out_mask", "mask_file"), ("outputnode.out_file", "background_file") ]), ]) # fmt: on wf.run()
def init_enhance_and_skullstrip_bold_wf(name='enhance_and_skullstrip_bold_wf', omp_nthreads=1): workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface(fields=[ 'mask_file', 'skull_stripped_file', 'bias_corrected_file', 'out_report' ]), name='outputnode') n4_correct = pe.Node(ants.N4BiasFieldCorrection(dimension=3, copy_header=True, num_threads=omp_nthreads), name='n4_correct', n_procs=omp_nthreads) skullstrip_first_pass = pe.Node(fsl.BET(frac=0.2, mask=True), name='skullstrip_first_pass') unifize = pe.Node(afni.Unifize(t2=True, outputtype='NIFTI_GZ', args='-clfrac 0.4', out_file="uni.nii.gz"), name='unifize') skullstrip_second_pass = pe.Node(afni.Automask(dilate=1, outputtype='NIFTI_GZ'), name='skullstrip_second_pass') combine_masks = pe.Node(fsl.BinaryMaths(operation='mul'), name='combine_masks') apply_mask = pe.Node(fsl.ApplyMask(), name='apply_mask') mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') workflow.connect([ (inputnode, n4_correct, [('in_file', 'input_image')]), (n4_correct, skullstrip_first_pass, [('output_image', 'in_file')]), (skullstrip_first_pass, unifize, [('out_file', 'in_file')]), (unifize, skullstrip_second_pass, [('out_file', 'in_file')]), (skullstrip_first_pass, combine_masks, [('mask_file', 'in_file')]), (skullstrip_second_pass, combine_masks, [('out_file', 'operand_file') ]), (unifize, apply_mask, [('out_file', 'in_file')]), (combine_masks, apply_mask, [('out_file', 'mask_file')]), (n4_correct, mask_reportlet, [('output_image', 'background_file')]), (combine_masks, mask_reportlet, [('out_file', 'mask_file')]), (combine_masks, outputnode, [('out_file', 'mask_file')]), (mask_reportlet, outputnode, [('out_report', 'out_report')]), (apply_mask, outputnode, [('out_file', 'skull_stripped_file')]), (n4_correct, outputnode, [('output_image', 'bias_corrected_file')]), ]) return workflow
def test_SimpleShowMaskRPT(): """ the BET report capable test """ msk_rpt = SimpleShowMaskRPT(generate_report=True, background_file=str( get_template('OASIS30ANTs', resolution=1, desc=None, suffix='T1w')), mask_file=str( get_template( 'OASIS30ANTs', resolution=1, desc='BrainCerebellumRegistration', suffix='mask'))) _smoke_test_report(msk_rpt, 'testSimpleMask.svg')
def test_SimpleShowMaskRPT(): """ the BET report capable test """ msk_rpt = SimpleShowMaskRPT( generate_report=True, background_file=str( get_template("OASIS30ANTs", resolution=1, desc=None, suffix="T1w")), mask_file=str( get_template( "OASIS30ANTs", resolution=1, desc="BrainCerebellumRegistration", suffix="mask", )), ) _smoke_test_report(msk_rpt, "testSimpleMask.svg")
def init_skullstrip_epi_wf(name='skullstrip_epi_wf'): workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['mask_file', 'skull_stripped_file', 'out_report']), name='outputnode') skullstrip_first_pass = pe.Node(fsl.BET(frac=0.2, mask=True), name='skullstrip_first_pass') skullstrip_second_pass = pe.Node(afni.Automask(dilate=1, outputtype='NIFTI_GZ'), name='skullstrip_second_pass') combine_masks = pe.Node(fsl.BinaryMaths(operation='mul'), name='combine_masks') apply_mask = pe.Node(fsl.ApplyMask(), name='apply_mask') mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') workflow.connect([ (inputnode, skullstrip_first_pass, [('in_file', 'in_file')]), (skullstrip_first_pass, skullstrip_second_pass, [('out_file', 'in_file')]), (skullstrip_first_pass, combine_masks, [('mask_file', 'in_file')]), (skullstrip_second_pass, combine_masks, [('out_file', 'operand_file') ]), (combine_masks, outputnode, [('out_file', 'mask_file')]), # Masked file (inputnode, apply_mask, [('in_file', 'in_file')]), (combine_masks, apply_mask, [('out_file', 'mask_file')]), (apply_mask, outputnode, [('out_file', 'skull_stripped_file')]), # Reportlet (inputnode, mask_reportlet, [('in_file', 'background_file')]), (combine_masks, mask_reportlet, [('out_file', 'mask_file')]), (mask_reportlet, outputnode, [('out_report', 'out_report')]), ]) return workflow
def init_skullstrip_bold_wf(name='skullstrip_bold_wf'): """ This workflow applies skull-stripping to a BOLD image. It is intended to be used on an image that has previously been bias-corrected with :py:func:`~fmriprep.workflows.bold.util.init_enhance_and_skullstrip_bold_wf` .. workflow :: :graph2use: orig :simple_form: yes from fmriprep.workflows.bold.util import init_skullstrip_bold_wf wf = init_skullstrip_bold_wf() Inputs in_file BOLD image (single volume) Outputs skull_stripped_file the ``in_file`` after skull-stripping mask_file mask of the skull-stripped input file out_report reportlet for the skull-stripping """ workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface( fields=['mask_file', 'skull_stripped_file', 'out_report']), name='outputnode') skullstrip_first_pass = pe.Node(fsl.BET(frac=0.2, mask=True), name='skullstrip_first_pass') skullstrip_second_pass = pe.Node(afni.Automask(dilate=1, outputtype='NIFTI_GZ'), name='skullstrip_second_pass') combine_masks = pe.Node(fsl.BinaryMaths(operation='mul'), name='combine_masks') apply_mask = pe.Node(fsl.ApplyMask(), name='apply_mask') mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') workflow.connect([ (inputnode, skullstrip_first_pass, [('in_file', 'in_file')]), (skullstrip_first_pass, skullstrip_second_pass, [('out_file', 'in_file')]), (skullstrip_first_pass, combine_masks, [('mask_file', 'in_file')]), (skullstrip_second_pass, combine_masks, [('out_file', 'operand_file') ]), (combine_masks, outputnode, [('out_file', 'mask_file')]), # Masked file (inputnode, apply_mask, [('in_file', 'in_file')]), (combine_masks, apply_mask, [('out_file', 'mask_file')]), (apply_mask, outputnode, [('out_file', 'skull_stripped_file')]), # Reportlet (inputnode, mask_reportlet, [('in_file', 'background_file')]), (combine_masks, mask_reportlet, [('out_file', 'mask_file')]), (mask_reportlet, outputnode, [('out_report', 'out_report')]), ]) return workflow
def init_enhance_and_skullstrip_bold_wf(name='enhance_and_skullstrip_bold_wf', omp_nthreads=1): """ This workflow takes in a BOLD volume, and attempts to enhance the contrast between gray and white matter, and skull-stripping the result. .. workflow :: :graph2use: orig :simple_form: yes from fmriprep.workflows.bold.util import init_enhance_and_skullstrip_bold_wf wf = init_enhance_and_skullstrip_bold_wf(omp_nthreads=1) Inputs in_file BOLD image (single volume) Outputs bias_corrected_file the ``in_file`` after `N4BiasFieldCorrection`_ skull_stripped_file the ``bias_corrected_file`` after skull-stripping mask_file mask of the skull-stripped input file out_report reportlet for the skull-stripping .. _N4BiasFieldCorrection: https://hdl.handle.net/10380/3053 """ workflow = pe.Workflow(name=name) inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']), name='inputnode') outputnode = pe.Node(niu.IdentityInterface(fields=[ 'mask_file', 'skull_stripped_file', 'bias_corrected_file', 'out_report' ]), name='outputnode') n4_correct = pe.Node(ants.N4BiasFieldCorrection(dimension=3, copy_header=True), name='n4_correct', n_procs=omp_nthreads) skullstrip_first_pass = pe.Node(fsl.BET(frac=0.2, mask=True), name='skullstrip_first_pass') unifize = pe.Node(afni.Unifize(t2=True, outputtype='NIFTI_GZ', args='-clfrac 0.4', out_file="uni.nii.gz"), name='unifize') skullstrip_second_pass = pe.Node(afni.Automask(dilate=1, outputtype='NIFTI_GZ'), name='skullstrip_second_pass') combine_masks = pe.Node(fsl.BinaryMaths(operation='mul'), name='combine_masks') apply_mask = pe.Node(fsl.ApplyMask(), name='apply_mask') copy_xform = pe.Node(CopyXForm(), name='copy_xform', mem_gb=0.1, run_without_submitting=True) mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') workflow.connect([ (inputnode, n4_correct, [('in_file', 'input_image')]), (inputnode, copy_xform, [('in_file', 'hdr_file')]), (n4_correct, skullstrip_first_pass, [('output_image', 'in_file')]), (skullstrip_first_pass, unifize, [('out_file', 'in_file')]), (unifize, skullstrip_second_pass, [('out_file', 'in_file')]), (skullstrip_first_pass, combine_masks, [('mask_file', 'in_file')]), (skullstrip_second_pass, combine_masks, [('out_file', 'operand_file') ]), (unifize, apply_mask, [('out_file', 'in_file')]), (combine_masks, apply_mask, [('out_file', 'mask_file')]), (n4_correct, mask_reportlet, [('output_image', 'background_file')]), (combine_masks, mask_reportlet, [('out_file', 'mask_file')]), (combine_masks, outputnode, [('out_file', 'mask_file')]), (mask_reportlet, outputnode, [('out_report', 'out_report')]), (apply_mask, copy_xform, [('out_file', 'in_file')]), (copy_xform, outputnode, [('out_file', 'skull_stripped_file')]), (n4_correct, outputnode, [('output_image', 'bias_corrected_file')]), ]) return workflow
def init_bold_reference_wf(omp_nthreads, bold_file=None, pre_mask=False, name='bold_reference_wf', gen_report=False): """ This workflow generates reference BOLD images for a series The raw reference image is the target of :abbr:`HMC (head motion correction)`, and a contrast-enhanced reference is the subject of distortion correction, as well as boundary-based registration to T1w and template spaces. .. workflow:: :graph2use: orig :simple_form: yes from fmriprep.workflows.bold import init_bold_reference_wf wf = init_bold_reference_wf(omp_nthreads=1) **Parameters** bold_file : str BOLD series NIfTI file omp_nthreads : int Maximum number of threads an individual process may use name : str Name of workflow (default: ``bold_reference_wf``) gen_report : bool Whether a mask report node should be appended in the end enhance_t2 : bool Perform logarithmic transform of input BOLD image to improve contrast before calculating the preliminary mask **Inputs** bold_file BOLD series NIfTI file bold_mask : bool A tentative brain mask to initialize the workflow (requires ``pre_mask`` parameter set ``True``). **Outputs** bold_file Validated BOLD series NIfTI file raw_ref_image Reference image to which BOLD series is motion corrected skip_vols Number of non-steady-state volumes detected at beginning of ``bold_file`` ref_image Contrast-enhanced reference image ref_image_brain Skull-stripped reference image bold_mask Skull-stripping mask of reference image validation_report HTML reportlet indicating whether ``bold_file`` had a valid affine **Subworkflows** * :py:func:`~fmriprep.workflows.bold.util.init_enhance_and_skullstrip_wf` """ workflow = Workflow(name=name) workflow.__desc__ = """\ First, a reference volume and its skull-stripped version were generated using a custom methodology of *fMRIPrep*. """ inputnode = pe.Node(niu.IdentityInterface(fields=['bold_file', 'sbref_file', 'bold_mask']), name='inputnode') outputnode = pe.Node( niu.IdentityInterface(fields=['bold_file', 'raw_ref_image', 'skip_vols', 'ref_image', 'ref_image_brain', 'bold_mask', 'validation_report', 'mask_report']), name='outputnode') # Simplify manually setting input image if bold_file is not None: inputnode.inputs.bold_file = bold_file validate = pe.Node(ValidateImage(), name='validate', mem_gb=DEFAULT_MEMORY_MIN_GB) gen_ref = pe.Node(EstimateReferenceImage(), name="gen_ref", mem_gb=1) # OE: 128x128x128x50 * 64 / 8 ~ 900MB. # Re-run validation; no effect if no sbref; otherwise apply same validation to sbref as bold validate_ref = pe.Node(ValidateImage(), name='validate_ref', mem_gb=DEFAULT_MEMORY_MIN_GB) enhance_and_skullstrip_bold_wf = init_enhance_and_skullstrip_bold_wf( omp_nthreads=omp_nthreads, pre_mask=pre_mask) workflow.connect([ (inputnode, enhance_and_skullstrip_bold_wf, [('bold_mask', 'inputnode.pre_mask')]), (inputnode, validate, [('bold_file', 'in_file')]), (inputnode, gen_ref, [('sbref_file', 'sbref_file')]), (validate, gen_ref, [('out_file', 'in_file')]), (gen_ref, validate_ref, [('ref_image', 'in_file')]), (validate_ref, enhance_and_skullstrip_bold_wf, [('out_file', 'inputnode.in_file')]), (validate, outputnode, [('out_file', 'bold_file'), ('out_report', 'validation_report')]), (gen_ref, outputnode, [('n_volumes_to_discard', 'skip_vols')]), (validate_ref, outputnode, [('out_file', 'raw_ref_image')]), (enhance_and_skullstrip_bold_wf, outputnode, [ ('outputnode.bias_corrected_file', 'ref_image'), ('outputnode.mask_file', 'bold_mask'), ('outputnode.skull_stripped_file', 'ref_image_brain')]), ]) if gen_report: mask_reportlet = pe.Node(SimpleShowMaskRPT(), name='mask_reportlet') workflow.connect([ (enhance_and_skullstrip_bold_wf, mask_reportlet, [ ('outputnode.bias_corrected_file', 'background_file'), ('outputnode.mask_file', 'mask_file'), ]), ]) return workflow
def init_anat_report_wf(workdir=None, name="anat_report_wf", memcalc=MemoryCalculator.default()): workflow = pe.Workflow(name=name) fmriprepreports = ["t1w_dseg_mask", "std_t1w"] fmriprepreportdatasinks = [f"ds_{fr}_report" for fr in fmriprepreports] inputnode = pe.Node( niu.IdentityInterface(fields=[ "standardized", "std_mask", "template", "t1w_preproc", "t1w_mask", "t1w_dseg", *fmriprepreportdatasinks, "tags", ]), name="inputnode", ) select_std = pe.Node( KeySelect(fields=["standardized", "std_mask"]), name="select_std", run_without_submitting=True, nohash=True, ) select_std.inputs.key = constants.reference_space workflow.connect(inputnode, "standardized", select_std, "standardized") workflow.connect(inputnode, "std_mask", select_std, "std_mask") workflow.connect(inputnode, "template", select_std, "keys") # make_resultdicts = pe.Node( MakeResultdicts( reportkeys=["skull_strip_report", "t1_norm_rpt", *fmriprepreports ]), name="make_resultdicts", ) workflow.connect(inputnode, "tags", make_resultdicts, "tags") # resultdict_datasink = pe.Node(ResultdictDatasink(base_directory=workdir), name="resultdict_datasink") workflow.connect(make_resultdicts, "resultdicts", resultdict_datasink, "indicts") # for fr, frd in zip(fmriprepreports, fmriprepreportdatasinks): workflow.connect(inputnode, frd, make_resultdicts, fr) # T1w segmentation skull_strip_report = pe.Node(SimpleShowMaskRPT(), name="skull_strip_report") workflow.connect(inputnode, "t1w_preproc", skull_strip_report, "background_file") workflow.connect(inputnode, "t1w_mask", skull_strip_report, "mask_file") workflow.connect(skull_strip_report, "out_report", make_resultdicts, "skull_strip_report") # T1 -> mni spaces = config.workflow.spaces assert isinstance(spaces, SpatialReferences) t1_norm_rpt = pe.Node( PlotRegistration(template=spaces.get_spaces()[0]), name="t1_norm_rpt", mem_gb=memcalc.min_gb, ) workflow.connect(select_std, "standardized", t1_norm_rpt, "in_file") workflow.connect(select_std, "std_mask", t1_norm_rpt, "mask_file") workflow.connect(t1_norm_rpt, "out_report", make_resultdicts, "t1_norm_rpt") return workflow