def test_nodemaker_tools_nilearn_coords_RSN(atlas): """ Test nodemaker_tools_nilearn_coords_RSN functionality """ # Set example inputs template = pkg_resources.resource_filename( "pynets", f"templates/standard/MNI152_T1_brain_2mm.nii.gz") subnet = "Default" parc = False parcels_4d_img = None start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ( "fetch_nilearn_atlas_coords --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [net_coords, _, net_labels, subnet] = nodemaker.get_node_membership(subnet, template, coords, labels, parc, parcels_4d_img) print("%s%s%s" % ( "get_node_membership --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) assert coords is not None assert labels is not None assert net_coords is not None assert net_labels is not None assert subnet is not None
def test_nodemaker_tools_nilearn_coords_RSN(atlas): """ Test nodemaker_tools_nilearn_coords_RSN functionality """ # Set example inputs base_dir = str(Path(__file__).parent / "examples") func_file = f"{base_dir}/BIDS/sub-0025427/ses-1/func/sub-0025427_ses-1_task-rest_space-MNI152NLin2009cAsym_desc-smoothAROMAnonaggr_bold.nii.gz" network = 'Default' parc = False parcel_list = None start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ('fetch_nilearn_atlas_coords --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords, _, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert labels is not None assert net_coords is not None assert net_labels is not None assert network is not None
def test_nodemaker_tools_nilearn_coords_RSN(atlas): """ Test nodemaker_tools_nilearn_coords_RSN functionality """ # Set example inputs import pkg_resources template = pkg_resources.resource_filename( "pynets", f"templates/MNI152_T1_brain_2mm.nii.gz") network = 'Default' parc = False parcel_list = None start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ('fetch_nilearn_atlas_coords --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords, _, net_labels, network] = nodemaker.get_node_membership(network, template, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert labels is not None assert net_coords is not None assert net_labels is not None assert network is not None
def test_nodemaker_tools_nilearn_coords_RSN(atlas): """ Test nodemaker_tools_nilearn_coords_RSN functionality """ # Set example inputs base_dir = str(Path(__file__).parent/"examples") dir_path = base_dir + '/002/fmri' func_file = dir_path + '/002.nii.gz' network = 'Default' parc = False parcel_list = None start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ('fetch_nilearn_atlas_coords --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords, _, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert labels is not None assert net_coords is not None assert net_labels is not None assert network is not None
def test_nodemaker_tools_masking_parlistfile_RSN(): """ Test nodemaker_tools_masking_parlistfile_RSN functionality """ # Set example inputs base_dir = str(Path(__file__).parent/"examples") dir_path = base_dir + '/002/fmri' func_file = dir_path + '/002.nii.gz' parlistfile = base_dir + '/whole_brain_cluster_labels_PCA200.nii.gz' roi = base_dir + '/pDMN_3_bin.nii.gz' network = 'Default' ID = '002' perc_overlap = 0.10 parc = True start_time = time.time() [coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile) print("%s%s%s" % ('get_names_and_coords_of_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist() start_time = time.time() parcel_list = nodemaker.gen_img_list(parlistfile) [net_coords, net_parcel_list, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords_masked, net_labels_masked, net_parcel_list_masked] = nodemaker.parcel_masker(roi, net_coords, net_parcel_list, net_labels, dir_path, ID, perc_overlap) print("%s%s%s" % ('parcel_masker --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcel_list_masked) print("%s%s%s" % ('create_parcel_atlas --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() out_path = nodemaker.gen_network_parcels(parlistfile, network, net_labels_masked, dir_path) print("%s%s%s" % ('gen_network_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert net_coords is not None assert net_labels is not None assert net_parcel_list is not None assert net_coords_masked is not None assert net_labels_masked is not None assert net_parcel_list_masked is not None assert out_path is not None assert net_parcels_map_nifti is not None assert parcel_list_exp is not None assert network is not None
def test_nodemaker_tools_parlistfile_RSN(): """ Test nodemaker_tools_parlistfile_RSN functionality """ import pkg_resources # Set example inputs base_dir = str(Path(__file__).parent / "examples") template = pkg_resources.resource_filename( "pynets", f"templates/MNI152_T1_brain_2mm.nii.gz") dir_path = f"{base_dir}/BIDS/sub-25659/ses-1/func" parlistfile = f"{base_dir}/miscellaneous/whole_brain_cluster_labels_PCA200.nii.gz" network = 'Default' parc = True start_time = time.time() [coords, _, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile) print("%s%s%s" % ('get_names_and_coords_of_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist() start_time = time.time() parcel_list = nodemaker.gen_img_list(parlistfile) [net_coords, net_parcel_list, net_labels, network] = nodemaker.get_node_membership(network, template, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcel_list) print("%s%s%s" % ('create_parcel_atlas --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() out_path = nodemaker.gen_network_parcels(parlistfile, network, net_labels, dir_path) print("%s%s%s" % ('gen_network_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert net_coords is not None assert net_labels is not None assert net_parcel_list is not None assert out_path is not None assert net_parcels_map_nifti is not None assert parcel_list_exp is not None assert network is not None
def test_nodemaker_tools_masking_coords_RSN(atlas): """ Test nodemaker_tools_masking_coords_RSN functionality """ # Set example inputs template = pkg_resources.resource_filename( "pynets", f"templates/standard/MNI152_T1_brain_2mm.nii.gz") dir_path = str(tempfile.TemporaryDirectory().name) os.makedirs(dir_path, exist_ok=True) roi = tempfile.NamedTemporaryFile(mode="w+", suffix=".nii.gz").name data_gen.generate_mni_space_img()[1].to_filename(roi) subnet = "Default" parc = False parcels_4d_img = None error = 2 start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ( "fetch_nilearn_atlas_coords (Masking subnet version) --> " "finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [net_coords, _, net_labels, subnet] = nodemaker.get_node_membership(subnet, template, coords, labels, parc, parcels_4d_img) print("%s%s%s" % ( "get_node_membership (Masking subnet version) --> " "finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [net_coords_masked, net_labels_masked] = nodemaker.coords_masker(roi, net_coords, net_labels, error) print("%s%s%s" % ( "coords_masker (Masking subnet version) --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) assert coords is not None assert net_coords is not None assert net_coords_masked is not None assert net_labels is not None assert net_labels_masked is not None assert subnet is not None
def test_nodemaker_tools_parlistfile_RSN(): """ Test nodemaker_tools_parlistfile_RSN functionality """ # Set example inputs base_dir = str(Path(__file__).parent / "examples") func_file = f"{base_dir}/BIDS/sub-0025427/ses-1/func/sub-0025427_ses-1_task-rest_space-MNI152NLin2009cAsym_desc-smoothAROMAnonaggr_bold.nii.gz" dir_path = f"{base_dir}/BIDS/sub-0025427/ses-1/func" parlistfile = f"{base_dir}/miscellaneous/whole_brain_cluster_labels_PCA200.nii.gz" network = 'Default' parc = True start_time = time.time() [coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile) print("%s%s%s" % ('get_names_and_coords_of_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist() start_time = time.time() parcel_list = nodemaker.gen_img_list(parlistfile) [net_coords, net_parcel_list, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcel_list) print("%s%s%s" % ('create_parcel_atlas --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() out_path = nodemaker.gen_network_parcels(parlistfile, network, net_labels, dir_path) print("%s%s%s" % ('gen_network_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert net_coords is not None assert net_labels is not None assert net_parcel_list is not None assert out_path is not None assert net_parcels_map_nifti is not None assert parcel_list_exp is not None assert network is not None
def test_nodemaker_tools_masking_coords_RSN(atlas): """ Test nodemaker_tools_masking_coords_RSN functionality """ import pkg_resources # Set example inputs base_dir = str(Path(__file__).parent / "examples") template = pkg_resources.resource_filename( "pynets", f"templates/MNI152_T1_brain_2mm.nii.gz") roi = f"{base_dir}/miscellaneous/pDMN_3_bin.nii.gz" network = 'Default' parc = False parcel_list = None error = 2 start_time = time.time() [coords, _, _, labels] = nodemaker.fetch_nilearn_atlas_coords(atlas) print("%s%s%s" % ('fetch_nilearn_atlas_coords (Masking RSN version) --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords, _, net_labels, network] = nodemaker.get_node_membership(network, template, coords, labels, parc, parcel_list) print("%s%s%s" % ('get_node_membership (Masking RSN version) --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) start_time = time.time() [net_coords_masked, net_labels_masked] = nodemaker.coords_masker(roi, net_coords, net_labels, error) print("%s%s%s" % ('coords_masker (Masking RSN version) --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert coords is not None assert net_coords is not None assert net_coords_masked is not None assert net_labels is not None assert net_labels_masked is not None assert network is not None
def test_nodemaker_tools_parlistfile_RSN(): """ Test nodemaker_tools_parlistfile_RSN functionality """ # Set example inputs template = pkg_resources.resource_filename( "pynets", f"templates/standard/MNI152_T1_brain_2mm.nii.gz") dir_path = str(tempfile.TemporaryDirectory().name) parlistfile = pkg_resources.resource_filename( "pynets", "templates/atlases/whole_brain_cluster_labels_PCA200.nii.gz") 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)}" subnet = "Default" parc = True start_time = time.time() coords = nodemaker.get_names_and_coords_of_parcels(parlistfile)[0] print("%s%s%s" % ( "get_names_and_coords_of_parcels --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist() start_time = time.time() parcels_4d_img = nodemaker.three_to_four_parcellation(parlistfile) [net_coords, net_parcels_4d_img, net_labels, subnet] = \ nodemaker.get_node_membership(subnet, template, coords, labels, parc, parcels_4d_img ) print("%s%s%s" % ( "get_node_membership --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcels_4d_img) print("%s%s%s" % ( "create_parcel_atlas --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() out_path = nodemaker.gen_network_parcels(parlistfile, subnet, net_labels, dir_path) print("%s%s%s" % ( "gen_network_parcels --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) assert coords is not None assert net_coords is not None assert net_labels is not None assert net_parcels_4d_img is not None assert out_path is not None assert net_parcels_map_nifti is not None assert parcel_list_exp is not None assert subnet is not None
def test_nodemaker_tools_masking_parlistfile_RSN(): """ Test nodemaker_tools_masking_parlistfile_RSN functionality """ # Set example inputs template = pkg_resources.resource_filename( "pynets", f"templates/standard/MNI152_T1_brain_2mm.nii.gz") tmp = tempfile.TemporaryDirectory() dir_path = str(tmp.name) os.makedirs(dir_path, exist_ok=True) parlistfile = pkg_resources.resource_filename( "pynets", "templates/atlases/whole_brain_cluster_labels_PCA200.nii.gz") shutil.copy2(parlistfile, f"{dir_path}/{os.path.basename(parlistfile)}") parlistfile = f"{dir_path}/{os.path.basename(parlistfile)}" roi = tempfile.NamedTemporaryFile(mode="w+", suffix=".nii.gz").name data_gen.generate_mni_space_img()[1].to_filename(roi) subnet = "Default" ID = "002" perc_overlap = 0.75 parc = True start_time = time.time() coords = nodemaker.get_names_and_coords_of_parcels(parlistfile)[0] print("%s%s%s" % ( "get_names_and_coords_of_parcels --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist() start_time = time.time() parcels_4d_img = nodemaker.three_to_four_parcellation(parlistfile) [net_coords, net_parcels_4d_img, net_labels, subnet] = \ nodemaker.get_node_membership( subnet, template, coords, labels, parc, parcels_4d_img ) print("%s%s%s" % ( "get_node_membership --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [ net_coords_masked, net_labels_masked, net_parcels_4d_img_masked, ] = nodemaker.parcel_masker( roi, net_coords, net_parcels_4d_img, net_labels, dir_path, ID, perc_overlap, vox_size="2mm", ) print("%s%s%s" % ( "parcel_masker --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() [net_parcels_map_nifti, parcel_list_exp ] = nodemaker.create_parcel_atlas(net_parcels_4d_img_masked) print("%s%s%s" % ( "create_parcel_atlas --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) start_time = time.time() out_path = nodemaker.gen_network_parcels(parlistfile, subnet, net_labels_masked, dir_path) print("%s%s%s" % ( "gen_network_parcels --> finished: ", str(np.round(time.time() - start_time, 1)), "s", )) assert coords is not None assert net_coords is not None assert net_labels is not None assert net_parcels_4d_img is not None assert net_coords_masked is not None assert net_labels_masked is not None assert net_parcels_4d_img_masked is not None assert out_path is not None assert net_parcels_map_nifti is not None assert parcel_list_exp is not None assert subnet is not None tmp.cleanup()