Пример #1
0
def test_EddyCorrect_inputs():
    input_map = dict(ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    out_file=dict(hash_files=False,
    genfile=True,
    position=1,
    argstr='%s',
    ),
    args=dict(argstr='%s',
    ),
    ref_num=dict(position=2,
    mandatory=True,
    argstr='%d',
    ),
    terminal_output=dict(mandatory=True,
    nohash=True,
    ),
    environ=dict(nohash=True,
    usedefault=True,
    ),
    in_file=dict(position=0,
    mandatory=True,
    argstr='%s',
    ),
    output_type=dict(),
    )
    inputs = EddyCorrect.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
def test_EddyCorrect_inputs():
    input_map = dict(args=dict(argstr='%s',
    ),
    environ=dict(nohash=True,
    usedefault=True,
    ),
    ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    in_file=dict(argstr='%s',
    mandatory=True,
    position=0,
    ),
    out_file=dict(argstr='%s',
    name_source=['in_file'],
    name_template='%s_edc',
    output_name='eddy_corrected',
    position=1,
    ),
    output_type=dict(),
    ref_num=dict(argstr='%d',
    mandatory=True,
    position=2,
    usedefault=True,
    ),
    terminal_output=dict(mandatory=True,
    nohash=True,
    ),
    )
    inputs = EddyCorrect.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_EddyCorrect_outputs():
    output_map = dict(eddy_corrected=dict(), )
    outputs = EddyCorrect.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
def test_EddyCorrect_inputs():
    input_map = dict(args=dict(argstr='%s',
    ),
    environ=dict(nohash=True,
    usedefault=True,
    ),
    ignore_exception=dict(nohash=True,
    usedefault=True,
    ),
    in_file=dict(argstr='%s',
    mandatory=True,
    position=0,
    ),
    out_file=dict(argstr='%s',
    genfile=True,
    hash_files=False,
    position=1,
    ),
    output_type=dict(),
    ref_num=dict(argstr='%d',
    mandatory=True,
    position=2,
    ),
    terminal_output=dict(mandatory=True,
    nohash=True,
    ),
    )
    inputs = EddyCorrect.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
def test_EddyCorrect_outputs():
    output_map = dict(eddy_corrected=dict(),
    )
    outputs = EddyCorrect.output_spec()

    for key, metadata in output_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(outputs.traits()[key], metakey), value
Пример #6
0
def test_EddyCorrect_inputs():
    input_map = dict(
        args=dict(argstr='%s', ),
        environ=dict(
            nohash=True,
            usedefault=True,
        ),
        ignore_exception=dict(
            nohash=True,
            usedefault=True,
        ),
        in_file=dict(
            argstr='%s',
            mandatory=True,
            position=0,
        ),
        out_file=dict(
            argstr='%s',
            name_source=['in_file'],
            name_template='%s_edc',
            output_name='eddy_corrected',
            position=1,
        ),
        output_type=dict(),
        ref_num=dict(
            argstr='%d',
            mandatory=True,
            position=2,
            usedefault=True,
        ),
        terminal_output=dict(nohash=True, ),
    )
    inputs = EddyCorrect.input_spec()

    for key, metadata in input_map.items():
        for metakey, value in metadata.items():
            yield assert_equal, getattr(inputs.traits()[key], metakey), value
Пример #7
0
def dti_preprocessing(diff_dir,
                      output_dir,
                      denoise=True,
                      ref_slice=0,
                      median_radius=3,
                      numpass=1,
                      autocrop=False,
                      dilate=2,
                      selem=10,
                      output_type="NIFTI"):
    """Function to realign, eddy current correct and eventually denoise diffusion data        
        Parameters
        ----------
        diff_dir : absolute path pointing at directory sub-id_visit-id/dwi where dwi acquisition 
                    (as a single 4D nii or nii file), bvec and bval files are stored
        output_dir: absolute path of the directories were the indexes will be written
        denoise : boolean, should denoise using Marcenko-Pastur PCA algorithm be performed
        fill : boolean, sometimes oshu method create hole in the mask, especially if you are working with populations
                that may have very low values at B0 in certain structures. Fill use erosion based reconstruction methods
                to fill in-mask holes.
        output_type: ["NIFTI", "NIFTI_GZ"], the type of nifti output desired,
        ... : other parameters related to the nipype and dipy functions used
        """
    fdwi = glob("{}/*nii*".format(diff_dir))[0]
    output_base_name = get_base_name_all_type(fdwi)
    if output_type == "NIFTI":
        ext = ".nii"
    elif output_type == "NIFTI_GZ":
        ext = ".nii.gz"
    else:
        raise ValueError(
            "Output file type {} not recognized".format(output_type))
    ec_out_file = "{}/{}_ec{}".format(output_dir, output_base_name, ext)
    if not (isfile(ec_out_file)):
        ec = EddyCorrect(in_file=fdwi, out_file=ec_out_file)
        ec.inputs.output_type = output_type
        print("Eddy Correction")
        ec.run()
    else:
        print("Skipping EC")
    mask_name, masked_name = custom_brain_extraction(output_base_name,
                                                     ec_out_file, output_dir,
                                                     output_type,
                                                     median_radius, numpass,
                                                     autocrop, dilate, selem)
    if denoise:
        denoised_out_file = "{}/{}_denoised{}".format(output_dir,
                                                      output_base_name, ext)
        if not (isfile(denoised_out_file)):
            print("Denoising")
            fbval = glob("{}/*bval".format(diff_dir))[0]
            fbvec = glob("{}/*bvec".format(diff_dir))[0]
            bvals, bvecs = read_bvals_bvecs(fbval, fbvec)
            gtab = gradient_table(bvals, bvecs)
            img = nb.load(masked_name)
            mask = nb.load(mask_name)
            x_ix, y_ix, z_ix, mask_crop, maskdata_crop = crop_and_indexes(
                mask, img)
            sigma = pca_noise_estimate(maskdata_crop,
                                       gtab,
                                       correct_bias=True,
                                       smooth=3)
            denoised_arr = localpca(maskdata_crop,
                                    sigma,
                                    tau_factor=2.3,
                                    patch_radius=2)
            opt = np.zeros(img.shape)
            opt[x_ix, y_ix, z_ix, :] = denoised_arr
            den_img = nb.Nifti1Image(opt.astype(np.float32), img.affine)
            nb.save(den_img, denoised_out_file)