コード例 #1
0
ファイル: test_auto_FitGLM.py プロジェクト: adamatus/nipype
def test_FitGLM_inputs():
    input_map = dict(ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    session_info=dict(mandatory=True,
    ),
    drift_model=dict(usedefault=True,
    ),
    normalize_design_matrix=dict(usedefault=True,
    ),
    TR=dict(mandatory=True,
    ),
    mask=dict(),
    save_residuals=dict(usedefault=True,
    ),
    plot_design_matrix=dict(usedefault=True,
    ),
    hrf_model=dict(usedefault=True,
    ),
    model=dict(usedefault=True,
    ),
    method=dict(usedefault=True,
    ),
    )
    inputs = FitGLM.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
コード例 #2
0
ファイル: test_auto_FitGLM.py プロジェクト: adamatus/nipype
def test_FitGLM_outputs():
    output_map = dict(a=dict(),
    nvbeta=dict(),
    s2=dict(),
    dof=dict(),
    beta=dict(),
    residuals=dict(),
    reg_names=dict(),
    constants=dict(),
    axis=dict(),
    )
    outputs = FitGLM.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
コード例 #3
0
ファイル: test_auto_FitGLM.py プロジェクト: wanderine/nipype
def test_FitGLM_outputs():
    output_map = dict(
        a=dict(),
        axis=dict(),
        beta=dict(),
        constants=dict(),
        dof=dict(),
        nvbeta=dict(),
        reg_names=dict(),
        residuals=dict(),
        s2=dict(),
    )
    outputs = FitGLM.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
コード例 #4
0
ファイル: test_auto_FitGLM.py プロジェクト: wanderine/nipype
def test_FitGLM_inputs():
    input_map = dict(
        TR=dict(mandatory=True, ),
        drift_model=dict(usedefault=True, ),
        hrf_model=dict(usedefault=True, ),
        ignore_exception=dict(
            nohash=True,
            usedefault=True,
        ),
        mask=dict(),
        method=dict(usedefault=True, ),
        model=dict(usedefault=True, ),
        normalize_design_matrix=dict(usedefault=True, ),
        plot_design_matrix=dict(usedefault=True, ),
        save_residuals=dict(usedefault=True, ),
        session_info=dict(mandatory=True, ),
    )
    inputs = FitGLM.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
コード例 #5
0
ファイル: fmri_nipy_glm.py プロジェクト: wanderine/nipype
contrasts = [cont1, cont2]
"""Generate design information using
:class:`nipype.interfaces.spm.SpecifyModel`. nipy accepts only design specified
in seconds so "output_units" has always have to be set to "secs".
"""

modelspec = pe.Node(interface=model.SpecifySPMModel(), name="modelspec")
modelspec.inputs.concatenate_runs = True
modelspec.inputs.input_units = 'secs'
modelspec.inputs.output_units = 'secs'
modelspec.inputs.time_repetition = 3.
modelspec.inputs.high_pass_filter_cutoff = 120
"""Fit the GLM model using nipy and ordinary least square method
"""

model_estimate = pe.Node(interface=FitGLM(), name="model_estimate")
model_estimate.inputs.TR = 3.
model_estimate.inputs.model = "spherical"
model_estimate.inputs.method = "ols"
"""Estimate the contrasts. The format of the contrasts definition is the same as
for FSL and SPM
"""

contrast_estimate = pe.Node(interface=EstimateContrast(),
                            name="contrast_estimate")
cont1 = ('Task>Baseline', 'T', ['Task-Odd', 'Task-Even'], [0.5, 0.5])
cont2 = ('Task-Odd>Task-Even', 'T', ['Task-Odd', 'Task-Even'], [1, -1])
contrast_estimate.inputs.contrasts = [cont1, cont2]
"""
Setup the pipeline
------------------
コード例 #6
0
def create_model_fit_pipeline(high_pass_filter_cutoff=128,
                              nipy=False,
                              ar1=True,
                              name="model",
                              save_residuals=False):
    inputnode = pe.Node(interface=util.IdentityInterface(fields=[
        'outlier_files', "realignment_parameters", "functional_runs", "mask",
        'conditions', 'onsets', 'durations', 'TR', 'contrasts', 'units',
        'sparse'
    ]),
                        name="inputnode")

    modelspec = pe.Node(interface=model.SpecifySPMModel(), name="modelspec")
    if high_pass_filter_cutoff:
        modelspec.inputs.high_pass_filter_cutoff = high_pass_filter_cutoff

    create_subject_info = pe.Node(interface=util.Function(
        input_names=['conditions', 'onsets', 'durations'],
        output_names=['subject_info'],
        function=create_subject_inf),
                                  name="create_subject_info")

    modelspec.inputs.concatenate_runs = True
    #modelspec.inputs.input_units             = units
    modelspec.inputs.output_units = "secs"
    #modelspec.inputs.time_repetition         = tr
    #modelspec.inputs.subject_info = subjectinfo

    model_pipeline = pe.Workflow(name=name)

    model_pipeline.connect([
        (inputnode, create_subject_info, [('conditions', 'conditions'),
                                          ('onsets', 'onsets'),
                                          ('durations', 'durations')]),
        (inputnode, modelspec, [('realignment_parameters',
                                 'realignment_parameters'),
                                ('functional_runs', 'functional_runs'),
                                ('outlier_files', 'outlier_files'),
                                ('units', 'input_units'),
                                ('TR', 'time_repetition')]),
        (create_subject_info, modelspec, [('subject_info', 'subject_info')]),
    ])

    if nipy:
        model_estimate = pe.Node(interface=FitGLM(), name="level1estimate")
        model_estimate.inputs.TR = tr
        model_estimate.inputs.normalize_design_matrix = True
        model_estimate.inputs.save_residuals = save_residuals
        if ar1:
            model_estimate.inputs.model = "ar1"
            model_estimate.inputs.method = "kalman"
        else:
            model_estimate.inputs.model = "spherical"
            model_estimate.inputs.method = "ols"

        model_pipeline.connect([
            (modelspec, model_estimate, [('session_info', 'session_info')]),
            (inputnode, model_estimate, [('mask', 'mask')])
        ])

        if contrasts:
            contrast_estimate = pe.Node(interface=EstimateContrast(),
                                        name="contrastestimate")
            contrast_estimate.inputs.contrasts = contrasts
            model_pipeline.connect([
                (model_estimate, contrast_estimate,
                 [("beta", "beta"), ("nvbeta", "nvbeta"), ("s2", "s2"),
                  ("dof", "dof"), ("axis", "axis"), ("constants", "constants"),
                  ("reg_names", "reg_names")]),
                (inputnode, contrast_estimate, [('mask', 'mask')]),
            ])
    else:
        level1design = pe.Node(interface=spm.Level1Design(),
                               name="level1design")
        level1design.inputs.bases = {'hrf': {'derivs': [0, 0]}}
        if ar1:
            level1design.inputs.model_serial_correlations = "AR(1)"
        else:
            level1design.inputs.model_serial_correlations = "none"

        level1design.inputs.timing_units = modelspec.inputs.output_units

        #level1design.inputs.interscan_interval = modelspec.inputs.time_repetition
        #        if sparse:
        #            level1design.inputs.microtime_resolution = n_slices*2
        #        else:
        #            level1design.inputs.microtime_resolution = n_slices
        #level1design.inputs.microtime_onset = ref_slice

        microtime_resolution = pe.Node(interface=util.Function(
            input_names=['volume', 'sparse'],
            output_names=['microtime_resolution'],
            function=_get_microtime_resolution),
                                       name="microtime_resolution")

        level1estimate = pe.Node(interface=spm.EstimateModel(),
                                 name="level1estimate")
        level1estimate.inputs.estimation_method = {'Classical': 1}

        contrastestimate = pe.Node(interface=spm.EstimateContrast(),
                                   name="contrastestimate")
        #contrastestimate.inputs.contrasts = contrasts

        threshold = pe.MapNode(interface=spm.Threshold(),
                               name="threshold",
                               iterfield=['contrast_index', 'stat_image'])
        #threshold.inputs.contrast_index = range(1,len(contrasts)+1)

        threshold_topo_ggmm = neuroutils.CreateTopoFDRwithGGMM(
            "threshold_topo_ggmm")
        #threshold_topo_ggmm.inputs.inputnode.contrast_index = range(1,len(contrasts)+1)

        model_pipeline.connect([
            (modelspec, level1design, [('session_info', 'session_info')]),
            (inputnode, level1design, [('mask', 'mask_image'),
                                       ('TR', 'interscan_interval'),
                                       (("functional_runs", get_ref_slice),
                                        "microtime_onset")]),
            (inputnode, microtime_resolution, [("functional_runs", "volume"),
                                               ("sparse", "sparse")]),
            (microtime_resolution, level1design, [("microtime_resolution",
                                                   "microtime_resolution")]),
            (level1design, level1estimate, [('spm_mat_file', 'spm_mat_file')]),
            (inputnode, contrastestimate, [('contrasts', 'contrasts')]),
            (level1estimate, contrastestimate,
             [('spm_mat_file', 'spm_mat_file'), ('beta_images', 'beta_images'),
              ('residual_image', 'residual_image')]),
            (contrastestimate, threshold, [('spm_mat_file', 'spm_mat_file'),
                                           ('spmT_images', 'stat_image')]),
            (inputnode, threshold, [(('contrasts', _get_contrast_index),
                                     'contrast_index')]),
            (level1estimate, threshold_topo_ggmm, [('mask_image',
                                                    'inputnode.mask_file')]),
            (contrastestimate, threshold_topo_ggmm,
             [('spm_mat_file', 'inputnode.spm_mat_file'),
              ('spmT_images', 'inputnode.stat_image')]),
            (inputnode, threshold_topo_ggmm,
             [(('contrasts', _get_contrast_index), 'inputnode.contrast_index')
              ]),
        ])

    return model_pipeline