Exemple #1
0
def test_get_voxel_dims():
    data = np.zeros((91, 91, 60))
    affine = 3 * np.eye(4)
    affine[:, 3] = np.ones(4)
    in_file = '/tmp/file1.nii'
    nibabel.Nifti1Image(data, affine).to_filename(in_file)
    assert_array_equal(_utils.get_voxel_dims(in_file), [3., 3., 3.])
Exemple #2
0
def test_get_voxel_dims():
    data = np.zeros((91, 91, 60))
    affine = 3 * np.eye(4)
    affine[:, 3] = np.ones(4)
    in_file = '/tmp/file1.nii'
    nibabel.Nifti1Image(data, affine).to_filename(in_file)
    assert_array_equal(_utils.get_voxel_dims(in_file), [3., 3., 3.])
        perfusion_file=perfusion_file,
        m0_file=out_smooth_m0.outputs.smoothed_files,
        tr=2500.,
        t1_gm=1331.)

    # Compute brain mask
    brain_mask_file = preprocessing.compute_brain_mask(
        out_coregister_anat.outputs.coregistered_source, frac=.2)

    # Normalize CBF
    normalize = mem.cache(spm.Normalize)
    out_normalize = normalize(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[out_quantify.outputs.cbf_file,
                        brain_mask_file],
        write_voxel_sizes=_utils.get_voxel_dims(func_file),
        write_interp=2,
        jobtype='write')

    # Mask CBF map with brain mask
    cbf_map = preprocessing.apply_mask(
        out_normalize.outputs.normalized_files[0],
        out_normalize.outputs.normalized_files[1])

    # Plot CBF map on top of MNI template
    plotting.plot_stat_map(
        cbf_map,
        bg_img='/usr/share/fsl/5.0/data/standard/MNI152_T1_2mm.nii.gz',
        threshold=.1, vmax=150.,
        display_mode='z')
    plt.show()
Exemple #4
0
                                jobtype='estimate')

    # Segment anat
    segment = mem.cache(spm.Segment)
    out_segment = segment(data=anat_file,
                          gm_output_type=[True, False, True],
                          wm_output_type=[True, False, True],
                          csf_output_type=[True, False, True],
                          save_bias_corrected=True)

    # Normalize anat
    normalize_anat = mem.cache(spm.Normalize)
    out_normalize_anat = normalize_anat(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[out_coregister.outputs.coregistered_source],
        write_voxel_sizes=_utils.get_voxel_dims(anat_file),
        write_interp=1,
        jobtype='write')

    # Normalize EPIs
    normalize_func = mem.cache(spm.Normalize)
    out_normalize_func = normalize_func(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[
            out_realign.outputs.realigned_files,
            out_segment.outputs.native_gm_image,
            out_segment.outputs.native_wm_image,
            out_segment.outputs.native_csf_image
        ],
        write_voxel_sizes=_utils.get_voxel_dims(func_file),
        write_interp=1,
        csf_output_type=[True, False, True],
        save_bias_corrected=True)

    # Coregister anat to mean ASL
    coregister_anat = mem.cache(spm.Coregister)
    out_coregister_anat = coregister_anat(
        target=out_average.outputs.mean_image,
        source=anat_file,
        apply_to_files=[out_segment.outputs.native_gm_image,
                        out_segment.outputs.native_wm_image],
        write_interp=3,
        jobtype='estwrite')

    # Normalize func
    normalize = mem.cache(spm.Normalize)
    write_voxel_sizes = np.round(_utils.get_voxel_dims(func_file), 2).tolist()
    out_normalize = normalize(
        parameter_file=out_segment.outputs.transformation_mat,
        apply_to_files=[out_realign.outputs.realigned_files,
                        out_average.outputs.mean_image],
        write_voxel_sizes=write_voxel_sizes,
        write_interp=2,
        jobtype='write')

    # Smooth func
    smooth = mem.cache(spm.Smooth)
    out_smooth = smooth(
        in_files=out_normalize.outputs.normalized_files,
        fwhm=[5., 5., 5.])

os.chdir(current_directory)