Example #1
0
def test_ApplyVolTransform_outputs():
    output_map = dict(transformed_file=dict(), )
    outputs = ApplyVolTransform.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_ApplyVolTransform_outputs():
    output_map = dict(transformed_file=dict(),
    )
    outputs = ApplyVolTransform.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
Example #3
0
def plot_epi_T1_corregistration(
        mean_epi_file,
        reg_file,
        fssubjects_dir,
        subject_id,
        similarity_distribution=None,
        figsize=(11.7, 8.3),
):

    fig = plt.figure(figsize=figsize)

    if similarity_distribution:
        ax = plt.subplot(2, 1, 1)
        sns.distplot(similarity_distribution.values(), ax=ax)
        ax.set_xlabel(
            "EPI-T1 similarity after coregistration (over all subjects)")
        cur_similarity = similarity_distribution[subject_id]
        label = "similarity = %g" % cur_similarity
        plot_vline(cur_similarity, label, ax=ax)

        ax = plt.subplot(2, 1, 0)
    else:
        ax = plt.subplot(1, 1, 0)

    res = ApplyVolTransform(source_file=mean_epi_file,
                            reg_file=reg_file,
                            fs_target=True,
                            subjects_dir=fssubjects_dir,
                            terminal_output="none").run()

    func = nb.load(res.outputs.transformed_file).get_data()
    func_affine = nb.load(res.outputs.transformed_file).get_affine()

    ribbon_file = "%s/%s/mri/ribbon.mgz" % (fssubjects_dir, subject_id)
    ribbon_nii = nb.load(ribbon_file)
    ribbon_data = ribbon_nii.get_data()
    ribbon_data[ribbon_data > 1] = 1
    ribbon_affine = ribbon_nii.get_affine()

    slicer = viz.plot_anat(
        np.asarray(func),
        np.asarray(func_affine),
        black_bg=True,
        cmap=cm.Greys_r,  # @UndefinedVariable
        cut_coords=(-6, 3, 32),
        figure=fig,
        axes=ax,
        draw_cross=False)
    slicer.contour_map(np.asarray(ribbon_data),
                       np.asarray(ribbon_affine),
                       levels=[.51],
                       colors=[
                           'r',
                       ])

    return fig
def plot_epi_T1_corregistration(mean_epi_file,
                                wm_file,
                                reg_file,
                                fssubjects_dir,
                                subject_id,
                                figsize=(11.7, 8.3)):

    fig = plt.figure(figsize=figsize)

    ax = plt.subplot(1, 1, 1)
    print ax

    res = ApplyVolTransform(source_file=mean_epi_file,
                            reg_file=reg_file,
                            fs_target=True,
                            subjects_dir=fssubjects_dir,
                            terminal_output="none").run()

    func = nb.load(res.outputs.transformed_file).get_data()
    func_affine = nb.load(res.outputs.transformed_file).get_affine()

    #     ribbon_file = "%s/%s/mri/ribbon.mgz"%(fssubjects_dir, subject_id)
    #     ribbon_nii = nb.load(ribbon_file)
    #     ribbon_data = ribbon_nii.get_data()
    #     ribbon_data[ribbon_data > 1] = 1
    #     ribbon_affine = ribbon_nii.get_affine()

    wm_nii = nb.load(wm_file)
    wm_data = wm_nii.get_data()
    wm_data[wm_data > 1] = 1
    wm_affine = wm_nii.get_affine()

    slicer = viz.plot_anat(
        np.asarray(func),
        np.asarray(func_affine),
        black_bg=True,
        cmap=cm.Greys_r,  # @UndefinedVariable
        figure=fig,
        axes=ax,
        draw_cross=False)
    slicer.contour_map(np.asarray(wm_data),
                       np.asarray(wm_affine),
                       linewidths=[0.1],
                       colors=[
                           'r',
                       ])

    fig.suptitle('coregistration', fontsize='14')

    return fig

    plt.show(fig)
def test_ApplyVolTransform_inputs():
    input_map = dict(args=dict(argstr='%s',
    ),
    environ=dict(nohash=True,
    usedefault=True,
    ),
    fs_target=dict(argstr='--fstarg',
    mandatory=True,
    requires=['reg_file'],
    xor=('target_file', 'tal', 'fs_target'),
    ),
    fsl_reg_file=dict(argstr='--fsl %s',
    mandatory=True,
    xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header', 'subject'),
    ),
    ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    interp=dict(argstr='--interp %s',
    ),
    inverse=dict(argstr='--inv',
    ),
    invert_morph=dict(argstr='--inv-morph',
    requires=['m3z_file'],
    ),
    m3z_file=dict(argstr='--m3z %s',
    ),
    no_ded_m3z_path=dict(argstr='--noDefM3zPath',
    requires=['m3z_file'],
    ),
    no_resample=dict(argstr='--no-resample',
    ),
    reg_file=dict(argstr='--reg %s',
    mandatory=True,
    xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header', 'subject'),
    ),
    reg_header=dict(argstr='--regheader',
    mandatory=True,
    xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header', 'subject'),
    ),
    source_file=dict(argstr='--mov %s',
    copyfile=False,
    mandatory=True,
    ),
    subject=dict(argstr='--s %s',
    mandatory=True,
    xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header', 'subject'),
    ),
    subjects_dir=dict(),
    tal=dict(argstr='--tal',
    mandatory=True,
    xor=('target_file', 'tal', 'fs_target'),
    ),
    tal_resolution=dict(argstr='--talres %.10f',
    ),
    target_file=dict(argstr='--targ %s',
    mandatory=True,
    xor=('target_file', 'tal', 'fs_target'),
    ),
    terminal_output=dict(nohash=True,
    ),
    transformed_file=dict(argstr='--o %s',
    genfile=True,
    ),
    xfm_reg_file=dict(argstr='--xfm %s',
    mandatory=True,
    xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header', 'subject'),
    ),
    )
    inputs = ApplyVolTransform.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
Example #6
0
def test_ApplyVolTransform_inputs():
    input_map = dict(
        args=dict(argstr='%s', ),
        environ=dict(
            nohash=True,
            usedefault=True,
        ),
        fs_target=dict(
            argstr='--fstarg',
            mandatory=True,
            requires=['reg_file'],
            xor=('target_file', 'tal', 'fs_target'),
        ),
        fsl_reg_file=dict(
            argstr='--fsl %s',
            mandatory=True,
            xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header',
                 'subject'),
        ),
        ignore_exception=dict(
            nohash=True,
            usedefault=True,
        ),
        interp=dict(argstr='--interp %s', ),
        inverse=dict(argstr='--inv', ),
        invert_morph=dict(
            argstr='--inv-morph',
            requires=['m3z_file'],
        ),
        m3z_file=dict(argstr='--m3z %s', ),
        no_ded_m3z_path=dict(
            argstr='--noDefM3zPath',
            requires=['m3z_file'],
        ),
        no_resample=dict(argstr='--no-resample', ),
        reg_file=dict(
            argstr='--reg %s',
            mandatory=True,
            xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header',
                 'subject'),
        ),
        reg_header=dict(
            argstr='--regheader',
            mandatory=True,
            xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header',
                 'subject'),
        ),
        source_file=dict(
            argstr='--mov %s',
            copyfile=False,
            mandatory=True,
        ),
        subject=dict(
            argstr='--s %s',
            mandatory=True,
            xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header',
                 'subject'),
        ),
        subjects_dir=dict(),
        tal=dict(
            argstr='--tal',
            mandatory=True,
            xor=('target_file', 'tal', 'fs_target'),
        ),
        tal_resolution=dict(argstr='--talres %.10f', ),
        target_file=dict(
            argstr='--targ %s',
            mandatory=True,
            xor=('target_file', 'tal', 'fs_target'),
        ),
        terminal_output=dict(
            mandatory=True,
            nohash=True,
        ),
        transformed_file=dict(
            argstr='--o %s',
            genfile=True,
        ),
        xfm_reg_file=dict(
            argstr='--xfm %s',
            mandatory=True,
            xor=('reg_file', 'fsl_reg_file', 'xfm_reg_file', 'reg_header',
                 'subject'),
        ),
    )
    inputs = ApplyVolTransform.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value