Exemplo n.º 1
0
def test_nodemaker_tools_masking_parlistfile_WB():
    """
    Test nodemaker_tools_masking_parlistfile_WB functionality
    """
    # Set example inputs
    base_dir = str(Path(__file__).parent / "examples")
    dir_path = f"{base_dir}/BIDS/sub-0025427/ses-1/func"
    parlistfile = f"{base_dir}/miscellaneous/whole_brain_cluster_labels_PCA200.nii.gz"
    atlas = 'whole_brain_cluster_labels_PCA200'
    roi = f"{base_dir}/miscellaneous/pDMN_3_bin.nii.gz"
    ID = '002'
    parc = True
    perc_overlap = 0.10

    start_time = time.time()
    [WB_coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
    print("%s%s%s" % (
        'get_names_and_coords_of_parcels (Masking whole-brain version) --> finished: ',
        str(np.round(time.time() - start_time, 1)), 's'))

    WB_labels = np.arange(len(WB_coords) +
                          1)[np.arange(len(WB_coords) + 1) != 0].tolist()

    start_time = time.time()
    WB_parcel_list = nodemaker.gen_img_list(parlistfile)
    [_, _, WB_parcel_list_masked
     ] = nodemaker.parcel_masker(roi, WB_coords, WB_parcel_list, WB_labels,
                                 dir_path, ID, perc_overlap)
    print("%s%s%s" %
          ('parcel_masker (Masking whole-brain version) --> finished: ',
           np.round(time.time() - start_time, 1), 's'))

    start_time = time.time()
    [WB_parcels_map_nifti,
     parcel_list_exp] = nodemaker.create_parcel_atlas(WB_parcel_list_masked)
    print("%s%s%s" %
          ('create_parcel_atlas (Masking whole-brain version) --> finished: ',
           np.round(time.time() - start_time, 1), 's'))

    start_time = time.time()
    [WB_net_parcels_map_nifti_unmasked, WB_coords_unmasked, _, _, _,
     dir_path] = nodemaker.node_gen(WB_coords, WB_parcel_list, WB_labels,
                                    dir_path, ID, parc, atlas, parlistfile)
    print("%s%s%s" % ('node_gen (Masking whole-brain version) --> finished: ',
                      np.round(time.time() - start_time, 1), 's'))

    start_time = time.time()
    [
        WB_net_parcels_map_nifti_masked, WB_coords_masked, WB_labels_masked, _,
        _, _
    ] = nodemaker.node_gen_masking(roi, WB_coords, WB_parcel_list, WB_labels,
                                   dir_path, ID, parc, atlas, parlistfile)

    print("%s%s%s" %
          ('node_gen_masking (Masking whole-brain version) --> finished: ',
           np.round(time.time() - start_time, 1), 's'))

    assert WB_coords is not None
    assert WB_labels is not None
    assert WB_parcel_list is not None
    assert WB_coords_masked is not None
    assert WB_labels_masked is not None
    assert WB_parcel_list_masked is not None
    assert WB_parcels_map_nifti is not None
    assert parcel_list_exp is not None
    assert WB_net_parcels_map_nifti_unmasked is not None
    assert WB_coords_unmasked is not None
    assert WB_net_parcels_map_nifti_masked is not None
    assert WB_coords_masked is not None
Exemplo n.º 2
0
def test_nodemaker_tools_masking_parlistfile_WB():
    """
    Test nodemaker_tools_masking_parlistfile_WB functionality
    """
    # Set example inputs
    parlistfile = pkg_resources.resource_filename(
        "pynets", "templates/atlases/whole_brain_cluster_labels_PCA200.nii.gz")
    dir_path = str(tempfile.TemporaryDirectory().name)
    os.makedirs(dir_path, exist_ok=True)
    shutil.copy2(parlistfile, f"{dir_path}/{os.path.basename(parlistfile)}")
    parlistfile = f"{dir_path}/{os.path.basename(parlistfile)}"

    atlas = "whole_brain_cluster_labels_PCA200"
    roi = tempfile.NamedTemporaryFile(mode="w+", suffix=".nii.gz").name
    data_gen.generate_mni_space_img()[1].to_filename(roi)
    ID = "002"
    parc = True
    perc_overlap = 0.10

    start_time = time.time()
    [WB_coords, _, _,
     _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
    print("%s%s%s" % (
        "get_names_and_coords_of_parcels (Masking whole-brain "
        "version) --> finished: ",
        str(np.round(time.time() - start_time, 1)),
        "s",
    ))

    WB_labels = np.arange(len(WB_coords) +
                          1)[np.arange(len(WB_coords) + 1) != 0].tolist()

    start_time = time.time()

    WB_parcel_list = nodemaker.three_to_four_parcellation(parlistfile)

    start_time = time.time()
    [
        WB_net_parcels_map_nifti_unmasked,
        WB_coords_unmasked,
        _,
        _,
        _,
        dir_path,
    ] = nodemaker.node_gen(WB_coords, WB_parcel_list, WB_labels, dir_path, ID,
                           parc, atlas, parlistfile)
    print("%s%s%s" % (
        "node_gen (Masking whole-brain version) --> finished: ",
        np.round(time.time() - start_time, 1),
        "s",
    ))

    start_time = time.time()
    WB_parcel_list = nodemaker.three_to_four_parcellation(parlistfile)
    [WB_parcels_map_nifti,
     parcel_list_exp] = nodemaker.create_parcel_atlas(WB_parcel_list)
    print("%s%s%s" % (
        "create_parcel_atlas (Masking whole-brain version) --> finished: ",
        np.round(time.time() - start_time, 1),
        "s",
    ))

    start_time = time.time()
    WB_parcel_list = nodemaker.three_to_four_parcellation(parlistfile)
    [
        WB_net_parcels_map_nifti_masked,
        WB_coords_masked,
        WB_labels_masked,
        _,
        _,
        _,
    ] = nodemaker.node_gen_masking(
        roi,
        WB_coords,
        WB_parcel_list,
        WB_labels,
        dir_path,
        ID,
        parc,
        atlas,
        parlistfile,
        vox_size="2mm",
    )

    WB_parcel_list = nodemaker.three_to_four_parcellation(parlistfile)
    WB_parcel_list_masked = nodemaker.parcel_masker(
        roi,
        WB_coords,
        WB_parcel_list,
        WB_labels,
        dir_path,
        ID,
        perc_overlap,
        vox_size="2mm",
    )[2]
    print("%s%s%s" % (
        "parcel_masker (Masking whole-brain version) --> "
        "finished: ",
        np.round(time.time() - start_time, 1),
        "s",
    ))

    print("%s%s%s" % (
        "node_gen_masking (Masking whole-brain version) --> "
        "finished: ",
        np.round(time.time() - start_time, 1),
        "s",
    ))

    assert WB_coords is not None
    assert WB_labels is not None
    assert WB_parcel_list is not None
    assert WB_coords_masked is not None
    assert WB_labels_masked is not None
    assert WB_parcel_list_masked is not None
    assert WB_parcels_map_nifti is not None
    assert parcel_list_exp is not None
    assert WB_net_parcels_map_nifti_unmasked is not None
    assert WB_coords_unmasked is not None
    assert WB_net_parcels_map_nifti_masked is not None
    assert WB_coords_masked is not None