def test_ni_parcellate_mult_conn_comps(clust_type):
    """
    Test for ni_parcellate with multiple connected components
    """
    import tempfile

    base_dir = str(Path(__file__).parent/"examples")
    out_dir = f"{base_dir}/outputs/sub-25659/ses-1/func"
    tmpdir = tempfile.TemporaryDirectory()

    k = 150
    if clust_type != 'ncut':
        local_corr = 'allcorr'
    else:
        local_corr = 'tcorr'
    clust_mask = f"{base_dir}/miscellaneous/pDMN_3_bin.nii.gz"
    mask = f"{base_dir}/BIDS/sub-25659/ses-1/anat/sub-25659_desc-brain_" \
           f"mask.nii.gz"
    func_file = f"{base_dir}/BIDS/sub-25659/ses-1/func/sub-25659_ses-1_task-" \
                f"rest_space-MNI152NLin6Asym_desc-" \
        f"smoothAROMAnonaggr_bold_short.nii.gz"
    conf = f"{base_dir}/BIDS/sub-25659/ses-1/func/" \
           f"sub-25659_ses-1_task-rest_desc-confounds_regressors.tsv"
    func_img = nib.load(func_file)
    nip = clustools.NiParcellate(func_file=func_file, clust_mask=clust_mask,
                                 k=k, clust_type=clust_type,
                                 local_corr=local_corr, outdir=out_dir,
                                 conf=conf, mask=mask)

    atlas = nip.create_clean_mask()

    if not nip.uatlas:
        nip.uatlas = f"{tmpdir.name}/clust-{clust_type}_k{str(k)}.nii.gz"
    nip._clust_mask_corr_img = nib.load(clust_mask)
    nip.create_local_clustering(overwrite=True, r_thresh=0.4)
    out_path = f"{str(tmpdir.name)}/parc_tmp.nii.gz"

    parcellation = clustools.parcellate(func_img, local_corr,
                              clust_type, nip._local_conn_mat_path,
                              nip.num_conn_comps,
                              nip._clust_mask_corr_img,
                              nip._standardize,
                              nip._detrending, nip.k, nip._local_conn,
                              nip.conf, tmpdir.name,
                              nip._conn_comps)

    nib.save(parcellation, out_path)
    assert atlas is not None
    assert os.path.isfile(out_path)
示例#2
0
def test_ni_parcellate(clust_type):
    """
    Test for ni_parcellate
    """
    import tempfile

    k = 20
    base_dir = str(Path(__file__).parent/"examples")
    out_dir = f"{base_dir}/outputs/sub-25659/ses-1/func"
    tmpdir = tempfile.TemporaryDirectory()
    if clust_type != 'ncut':
        local_corr = 'allcorr'
    else:
        local_corr = 'tcorr'
    clust_mask = f"{base_dir}/miscellaneous/rMFG_node6mm.nii.gz"
    mask = f"{base_dir}/BIDS/sub-25659/ses-1/anat/sub-25659_desc-brain_" \
           f"mask.nii.gz"
    func_file = f"{base_dir}/BIDS/sub-25659/ses-1/func/sub-25659_ses-1_" \
                f"task-rest_space-MNI152NLin6Asym_desc-" \
        f"smoothAROMAnonaggr_bold_short.nii.gz"
    func_img = nib.load(func_file)
    nip = clustools.NiParcellate(func_file=func_file, clust_mask=clust_mask,
                                 k=k, clust_type=clust_type,
                                 local_corr=local_corr, outdir=out_dir,
                                 conf=None, mask=mask)
    atlas = nip.create_clean_mask()
    nip.create_local_clustering(overwrite=True, r_thresh=0.4)
    out_path = f"{str(tmpdir.name)}/parc_tmp.nii.gz"
    parcellation = clustools.parcellate(func_img, local_corr,
                              clust_type, nip._local_conn_mat_path,
                              nip.num_conn_comps,
                              nip._clust_mask_corr_img,
                              nip._standardize,
                              nip._detrending, nip.k, nip._local_conn,
                              nip.conf, tmpdir.name,
                              nip._conn_comps)

    nib.save(parcellation, out_path)
    assert out_path is not None
    assert atlas is not None