Пример #1
0
def test_BrainExtractionRPT(monkeypatch, oasis_dir, moving, nthreads):
    """ test antsBrainExtraction with reports"""

    def _agg(objekt, runtime):
        outputs = Bunch(BrainExtractionMask=os.path.join(
            datadir, 'testBrainExtractionRPTBrainExtractionMask.nii.gz')
        )
        return outputs

    # Patch the _run_interface method
    monkeypatch.setattr(BrainExtractionRPT, '_run_interface',
                        _run_interface_mock)
    monkeypatch.setattr(BrainExtractionRPT, 'aggregate_outputs',
                        _agg)

    bex_rpt = BrainExtractionRPT(
        generate_report=True,
        dimension=3,
        use_floatingpoint_precision=1,
        anatomical_image=moving,
        brain_template=os.path.join(oasis_dir, 'T_template0.nii.gz'),
        brain_probability_mask=os.path.join(
            oasis_dir, 'T_template0_BrainCerebellumProbabilityMask.nii.gz'),
        extraction_registration_mask=os.path.join(
            oasis_dir, 'T_template0_BrainCerebellumRegistrationMask.nii.gz'),
        out_prefix='testBrainExtractionRPT',
        debug=True,  # run faster for testing purposes
        num_threads=nthreads
    )
    _smoke_test_report(bex_rpt, 'testANTSBrainExtraction.svg')
Пример #2
0
def init_skullstrip_ants_wf(debug, omp_nthreads, name='skullstrip_ants_wf'):
    from niworkflows.data import get_ants_oasis_template_ras

    workflow = pe.Workflow(name=name)

    inputnode = pe.Node(
        niu.IdentityInterface(fields=['in_file', 'source_file']),
        name='inputnode')
    outputnode = pe.Node(niu.IdentityInterface(
        fields=['bias_corrected', 'out_file', 'out_mask', 'out_report']),
                         name='outputnode')

    t1_skull_strip = pe.Node(BrainExtractionRPT(dimension=3,
                                                use_floatingpoint_precision=1,
                                                debug=debug,
                                                generate_report=True,
                                                num_threads=omp_nthreads,
                                                keep_temporary_files=1),
                             name='t1_skull_strip')

    # should not be necesssary byt does not hurt - make sure the multiproc
    # scheduler knows the resource limits
    t1_skull_strip.interface.num_threads = omp_nthreads

    t1_skull_strip.inputs.brain_template = op.join(
        get_ants_oasis_template_ras(), 'T_template0.nii.gz')
    t1_skull_strip.inputs.brain_probability_mask = op.join(
        get_ants_oasis_template_ras(),
        'T_template0_BrainCerebellumProbabilityMask.nii.gz')
    t1_skull_strip.inputs.extraction_registration_mask = op.join(
        get_ants_oasis_template_ras(),
        'T_template0_BrainCerebellumRegistrationMask.nii.gz')

    workflow.connect([
        (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]),
        (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'),
                                      ('BrainExtractionBrain', 'out_file'),
                                      ('N4Corrected0', 'bias_corrected'),
                                      ('out_report', 'out_report')])
    ])

    return workflow
Пример #3
0
def test_BrainExtractionRPT(monkeypatch, moving, nthreads):
    """ test antsBrainExtraction with reports"""
    def _agg(objekt, runtime):
        outputs = objekt.output_spec()
        outputs.BrainExtractionMask = os.path.join(
            datadir, "testBrainExtractionRPTBrainExtractionMask.nii.gz")
        outputs.out_report = os.path.join(runtime.cwd,
                                          objekt.inputs.out_report)
        return outputs

    # Patch the _run_interface method
    monkeypatch.setattr(BrainExtractionRPT, "_run_interface",
                        _run_interface_mock)
    monkeypatch.setattr(BrainExtractionRPT, "aggregate_outputs", _agg)

    bex_rpt = BrainExtractionRPT(
        generate_report=True,
        dimension=3,
        use_floatingpoint_precision=1,
        anatomical_image=moving,
        brain_template=str(
            get_template("OASIS30ANTs", resolution=1, desc=None,
                         suffix="T1w")),
        brain_probability_mask=str(
            get_template("OASIS30ANTs",
                         resolution=1,
                         label="brain",
                         suffix="probseg")),
        extraction_registration_mask=str(
            get_template(
                "OASIS30ANTs",
                resolution=1,
                desc="BrainCerebellumRegistration",
                suffix="mask",
            )),
        out_prefix="testBrainExtractionRPT",
        debug=True,  # run faster for testing purposes
        num_threads=nthreads,
    )
    _smoke_test_report(bex_rpt, "testANTSBrainExtraction.svg")
Пример #4
0
    def test_generate_report(self):
        ''' test of BrainExtractionRPT under basic conditions:
                - dimension=3
                - use_floatingpoint_precision=1,
                - brain_template, brain_probability_mask, extraction_registration_mask from get_ants_oasis_template_ras()
        '''

        _smoke_test_report(
            BrainExtractionRPT(
                generate_report=True,
                dimension=3,
                use_floatingpoint_precision=1,
                anatomical_image=MNI_2MM,
                brain_template=_template_name('T_template0.nii.gz'),
                brain_probability_mask=_template_name(
                    'T_template0_BrainCerebellumProbabilityMask.nii.gz'),
                extraction_registration_mask=_template_name(
                    'T_template0_BrainCerebellumRegistrationMask.nii.gz'),
                out_prefix='testBrainExtractionRPT',
                debug=True,  # run faster for testing purposes
                num_threads=cpu_count()),
            'testANTSBrainExtraction.html')
Пример #5
0
def init_skullstrip_ants_wf(debug, omp_nthreads, name='skullstrip_ants_wf'):
    r"""
    This workflow performs skull-stripping using ANTs' ``BrainExtraction.sh``

    .. workflow::
        :graph2use: orig
        :simple_form: yes

        from fmriprep.workflows.anatomical import init_skullstrip_ants_wf
        wf = init_skullstrip_ants_wf(debug=False, omp_nthreads=1)

    **Parameters**

        debug : bool
            Enable debugging outputs
        omp_nthreads : int
            Maximum number of threads an individual process may use

    **Inputs**

        in_file
            T1-weighted structural image to skull-strip

    **Outputs**

        bias_corrected
            Bias-corrected ``in_file``, before skull-stripping
        out_file
            Skull-stripped ``in_file``
        out_mask
            Binary mask of the skull-stripped ``in_file``
        out_report
            Reportlet visualizing quality of skull-stripping

    """
    from niworkflows.data import get_ants_oasis_template_ras

    workflow = pe.Workflow(name=name)

    inputnode = pe.Node(niu.IdentityInterface(fields=['in_file']),
                        name='inputnode')
    outputnode = pe.Node(niu.IdentityInterface(
        fields=['bias_corrected', 'out_file', 'out_mask', 'out_report']),
                         name='outputnode')

    t1_skull_strip = pe.Node(BrainExtractionRPT(dimension=3,
                                                use_floatingpoint_precision=1,
                                                debug=debug,
                                                generate_report=True,
                                                num_threads=omp_nthreads,
                                                keep_temporary_files=1),
                             name='t1_skull_strip',
                             n_procs=omp_nthreads)

    t1_skull_strip.inputs.brain_template = op.join(
        get_ants_oasis_template_ras(), 'T_template0.nii.gz')
    t1_skull_strip.inputs.brain_probability_mask = op.join(
        get_ants_oasis_template_ras(),
        'T_template0_BrainCerebellumProbabilityMask.nii.gz')
    t1_skull_strip.inputs.extraction_registration_mask = op.join(
        get_ants_oasis_template_ras(),
        'T_template0_BrainCerebellumRegistrationMask.nii.gz')

    workflow.connect([
        (inputnode, t1_skull_strip, [('in_file', 'anatomical_image')]),
        (t1_skull_strip, outputnode, [('BrainExtractionMask', 'out_mask'),
                                      ('BrainExtractionBrain', 'out_file'),
                                      ('N4Corrected0', 'bias_corrected'),
                                      ('out_report', 'out_report')])
    ])

    return workflow